cortex-agents 4.1.2 → 5.0.1

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.
Files changed (59) hide show
  1. package/README.md +85 -16
  2. package/dist/cli.js +165 -13
  3. package/dist/engine/agents.d.ts +19 -0
  4. package/dist/engine/agents.d.ts.map +1 -0
  5. package/dist/engine/agents.js +69 -0
  6. package/dist/engine/db.d.ts +13 -0
  7. package/dist/engine/db.d.ts.map +1 -0
  8. package/dist/engine/db.js +28 -0
  9. package/dist/engine/index.d.ts +50 -0
  10. package/dist/engine/index.d.ts.map +1 -0
  11. package/dist/engine/index.js +135 -0
  12. package/dist/engine/models.d.ts +12 -0
  13. package/dist/engine/models.d.ts.map +1 -0
  14. package/dist/engine/models.js +23 -0
  15. package/dist/engine/renderers/claude.d.ts +18 -0
  16. package/dist/engine/renderers/claude.d.ts.map +1 -0
  17. package/dist/engine/renderers/claude.js +226 -0
  18. package/dist/engine/renderers/codex.d.ts +22 -0
  19. package/dist/engine/renderers/codex.d.ts.map +1 -0
  20. package/dist/engine/renderers/codex.js +115 -0
  21. package/dist/engine/renderers/gemini.d.ts +18 -0
  22. package/dist/engine/renderers/gemini.d.ts.map +1 -0
  23. package/dist/engine/renderers/gemini.js +203 -0
  24. package/dist/engine/renderers/index.d.ts +21 -0
  25. package/dist/engine/renderers/index.d.ts.map +1 -0
  26. package/dist/engine/renderers/index.js +13 -0
  27. package/dist/engine/renderers/opencode.d.ts +18 -0
  28. package/dist/engine/renderers/opencode.d.ts.map +1 -0
  29. package/dist/engine/renderers/opencode.js +119 -0
  30. package/dist/engine/schema.d.ts +13 -0
  31. package/dist/engine/schema.d.ts.map +1 -0
  32. package/dist/engine/schema.js +125 -0
  33. package/dist/engine/seed.d.ts +14 -0
  34. package/dist/engine/seed.d.ts.map +1 -0
  35. package/dist/engine/seed.js +398 -0
  36. package/dist/engine/skills.d.ts +11 -0
  37. package/dist/engine/skills.d.ts.map +1 -0
  38. package/dist/engine/skills.js +24 -0
  39. package/dist/engine/targets.d.ts +17 -0
  40. package/dist/engine/targets.d.ts.map +1 -0
  41. package/dist/engine/targets.js +79 -0
  42. package/dist/engine/types.d.ts +100 -0
  43. package/dist/engine/types.d.ts.map +1 -0
  44. package/dist/engine/types.js +5 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +53 -0
  47. package/dist/mcp-server.d.ts +2 -0
  48. package/dist/mcp-server.d.ts.map +1 -0
  49. package/dist/mcp-server.js +555 -0
  50. package/dist/tools/branch.d.ts +2 -2
  51. package/dist/tools/engine.d.ts +22 -0
  52. package/dist/tools/engine.d.ts.map +1 -0
  53. package/dist/tools/engine.js +56 -0
  54. package/dist/tools/plan.d.ts +4 -4
  55. package/dist/tools/worktree.d.ts +2 -2
  56. package/dist/utils/cortex-code-bridge.d.ts +21 -0
  57. package/dist/utils/cortex-code-bridge.d.ts.map +1 -0
  58. package/dist/utils/cortex-code-bridge.js +104 -0
  59. package/package.json +6 -3
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
  <img src="https://img.shields.io/badge/cortex-agents-111?style=for-the-badge&labelColor=111&color=4d96ff" alt="cortex-agents" height="40">
3
3
  </p>
4
4
 
5
- <h3 align="center">Structured AI development workflows for <a href="https://opencode.ai">OpenCode</a>.<br>Plan. Build. Ship. With discipline.</h3>
5
+ <h3 align="center">Structured AI development workflows for <a href="https://opencode.ai">OpenCode</a>, <a href="https://claude.ai">Claude Code</a>, <a href="https://github.com/openai/codex">Codex CLI</a>, and <a href="https://github.com/google-gemini/gemini-cli">Gemini CLI</a>.<br>Plan. Build. Ship. With discipline.</h3>
6
6
 
7
7
  <p align="center">
8
8
  <a href="https://www.npmjs.com/package/cortex-agents"><img src="https://img.shields.io/npm/v/cortex-agents.svg?style=flat-square&color=4d96ff" alt="npm version"></a>
@@ -52,12 +52,28 @@ This ensures you get plans that actually solve the right problem — not AI hall
52
52
  ## Quick Start
53
53
 
54
54
  ```bash
55
- npx cortex-agents install # Add plugin + agents + skills
56
- npx cortex-agents configure # Pick your models interactively
57
- # Restart OpenCode done.
55
+ # OpenCode (default)
56
+ npx cortex-agents install # Add plugin + agents + skills
57
+ npx cortex-agents configure # Pick your models interactively
58
+
59
+ # Claude Code
60
+ npx cortex-agents install --target claude # Render agents + CLAUDE.md
61
+ npx cortex-agents sync --target claude # Re-sync after DB changes
62
+
63
+ # Codex CLI
64
+ npx cortex-agents install --target codex # Render AGENTS.md instructions
65
+
66
+ # Gemini CLI
67
+ npx cortex-agents install --target gemini # Render agents + GEMINI.md
68
+
69
+ # Multiple targets
70
+ npx cortex-agents install --target opencode
71
+ npx cortex-agents install --target claude
72
+ npx cortex-agents install --target codex
73
+ npx cortex-agents install --target gemini
58
74
  ```
59
75
 
60
- Your OpenCode session now has **12 specialized agents**, **33 tools**, and **17 domain skills**.
76
+ Your sessions now have **12 specialized agents**, **35 tools**, and **17 domain skills**.
61
77
 
62
78
  > **Built-in Agent Replacement** — Cortex automatically disables OpenCode's native `build` and `plan` agents (replaced by `implement` and `architect`). The `architect` agent becomes the default, promoting a planning-first workflow. Native agents are fully restored on `uninstall`.
63
79
 
@@ -125,6 +141,35 @@ Not every change needs a full audit. The quality gate scales with risk:
125
141
 
126
142
  ---
127
143
 
144
+ ## Cortex Engine
145
+
146
+ Cortex Agents is backed by a **SQLite data model** at `~/.config/cortex-agents/cortex.db`. Agents, skills, and model configurations are stored in a single source of truth. Target-specific **renderers** transform DB records into each CLI's native format on `install` or `sync`.
147
+
148
+ ```
149
+ ┌──────────────────────────────────────────────────────────────┐
150
+ │ CortexEngine │
151
+ │ AgentStore │ SkillStore │ Models │ Targets │
152
+ │ SQLite (cortex.db) │
153
+ │ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────────┐ │
154
+ │ │ Claude │ │ OpenCode │ │ Codex │ │ Gemini │ │
155
+ │ │ Renderer │ │ Renderer │ │ Renderer │ │ Renderer │ │
156
+ │ └──────────┘ └──────────┘ └──────────┘ └──────────────┘ │
157
+ └──────────────────────────────────────────────────────────────┘
158
+ ```
159
+
160
+ This means you can install once, then render to as many targets as you need. Four renderers ship out of the box:
161
+
162
+ | Target | Config Dir | Agent Format | Instructions File |
163
+ |--------|-----------|--------------|-------------------|
164
+ | **Claude Code** | `~/.claude` | Per-agent `.md` with Claude frontmatter | `CLAUDE.md` |
165
+ | **OpenCode** | `~/.config/opencode` | Per-agent `.md` with tools/permission YAML | — |
166
+ | **Codex CLI** | `~/.codex` | Single `agents/AGENTS.md` | `agents/AGENTS.md` |
167
+ | **Gemini CLI** | `~/.gemini` | Per-agent `.md` with Gemini frontmatter | `GEMINI.md` |
168
+
169
+ Changes to agents or skills in the DB are picked up by `sync` without re-downloading anything.
170
+
171
+ ---
172
+
128
173
  ## Agents
129
174
 
130
175
  ### Primary Agents (3)
@@ -181,7 +226,7 @@ This ensures visual consistency across all agents and sessions — no more one-o
181
226
 
182
227
  ## Tools
183
228
 
184
- 33 tools bundled and auto-registered. No configuration needed.
229
+ 35 tools bundled and auto-registered. No configuration needed.
185
230
 
186
231
  <table>
187
232
  <tr><td width="50%">
@@ -241,6 +286,13 @@ The architect uses these to browse your backlog and seed plans from real issues.
241
286
 
242
287
  State persists to `.cortex/repl-state.json` — survives context compaction, session restarts, and agent switches.
243
288
 
289
+ </td></tr>
290
+ <tr><td colspan="2">
291
+
292
+ **Engine (NEW)**
293
+ - `cortex_get_skill` — Retrieve domain skill content from DB
294
+ - `cortex_list_agents` — List all registered agents with tools
295
+
244
296
  </td></tr>
245
297
  </table>
246
298
 
@@ -410,20 +462,22 @@ your-project/
410
462
  ## CLI Reference
411
463
 
412
464
  ```bash
413
- npx cortex-agents install # Install plugin, agents, and skills
414
- npx cortex-agents configure # Global model selection
415
- npx cortex-agents configure --project # Per-project model selection
416
- npx cortex-agents configure --reset # Reset global models
417
- npx cortex-agents configure --project --reset # Reset per-project models
418
- npx cortex-agents uninstall # Clean removal of everything
419
- npx cortex-agents status # Show installation and model status
465
+ npx cortex-agents install # Install plugin, agents, and skills (OpenCode default)
466
+ npx cortex-agents install --target claude|opencode|codex|gemini # Install to specific CLI target
467
+ npx cortex-agents sync --target claude|opencode|codex|gemini # Re-render from DB to target
468
+ npx cortex-agents configure # Global model selection
469
+ npx cortex-agents configure --project # Per-project model selection
470
+ npx cortex-agents configure --reset # Reset global models
471
+ npx cortex-agents configure --project --reset # Reset per-project models
472
+ npx cortex-agents uninstall # Clean removal of everything
473
+ npx cortex-agents status # Show installation, model, and DB stats
420
474
  ```
421
475
 
422
476
  ---
423
477
 
424
478
  ## Requirements
425
479
 
426
- - [OpenCode](https://opencode.ai) >= 1.0.0
480
+ - [OpenCode](https://opencode.ai) >= 1.0.0, [Claude Code](https://claude.ai), [Codex CLI](https://github.com/openai/codex), or [Gemini CLI](https://github.com/google-gemini/gemini-cli)
427
481
  - Node.js >= 18.0.0
428
482
  - Git (for branch/worktree features)
429
483
  - [GitHub CLI](https://cli.github.com/) (optional — for PR creation and issue integration)
@@ -441,7 +495,7 @@ git clone https://github.com/ps-carvalho/cortex-agents.git
441
495
  cd cortex-agents
442
496
  npm install
443
497
  npm run build
444
- npm test # 447 tests, all should pass
498
+ npm test # All tests should pass
445
499
  ```
446
500
 
447
501
  ### Local Development
@@ -465,7 +519,22 @@ src/
465
519
  index.ts Plugin entry point, tool registration, event hooks
466
520
  registry.ts Agent/model registry constants
467
521
  cli.ts CLI (install, configure, uninstall, status)
522
+ engine/
523
+ index.ts CortexEngine facade
524
+ db.ts SQLite connection factory
525
+ schema.ts DDL, migrations
526
+ types.ts TypeScript interfaces
527
+ agents.ts / skills.ts Data stores
528
+ models.ts / targets.ts
529
+ seed.ts Import .opencode/ → DB
530
+ renderers/
531
+ index.ts Renderer interface + registry
532
+ claude.ts Claude Code renderer
533
+ opencode.ts OpenCode renderer
534
+ codex.ts Codex CLI renderer
535
+ gemini.ts Gemini CLI renderer
468
536
  tools/
537
+ engine.ts Engine-backed MCP tools
469
538
  repl.ts REPL loop tools (init, status, report, resume, summary)
470
539
  quality-gate.ts Quality gate aggregation tool
471
540
  cortex.ts Project initialization tools
@@ -545,5 +614,5 @@ test: add or update tests
545
614
 
546
615
  <p align="center">
547
616
  <br>
548
- <sub>Built for the <a href="https://opencode.ai">OpenCode</a> community</sub>
617
+ <sub>Built for the <a href="https://opencode.ai">OpenCode</a>, <a href="https://claude.ai">Claude Code</a>, <a href="https://github.com/openai/codex">Codex CLI</a>, and <a href="https://github.com/google-gemini/gemini-cli">Gemini CLI</a> communities</sub>
549
618
  </p>
package/dist/cli.js CHANGED
@@ -4,6 +4,8 @@ import * as path from "path";
4
4
  import { fileURLToPath } from "url";
5
5
  import prompts from "prompts";
6
6
  import { PRIMARY_AGENTS, SUBAGENTS, ALL_AGENTS, DISABLED_BUILTIN_AGENTS, STALE_AGENT_FILES, getPrimaryChoices, getSubagentChoices, } from "./registry.js";
7
+ import { CortexEngine } from "./engine/index.js";
8
+ import { startMCPServer } from "./mcp-server.js";
7
9
  const PLUGIN_NAME = "cortex-agents";
8
10
  const __filename = fileURLToPath(import.meta.url);
9
11
  const __dirname = path.dirname(__filename);
@@ -179,8 +181,96 @@ function removeAgentsAndSkills(targetDir) {
179
181
  }
180
182
  }
181
183
  }
184
+ // ─── Target flag parsing ─────────────────────────────────────────────────────
185
+ function parseTargetFlag() {
186
+ const args = process.argv.slice(3);
187
+ const idx = args.indexOf("--target");
188
+ if (idx === -1 || idx + 1 >= args.length)
189
+ return null;
190
+ return args[idx + 1];
191
+ }
192
+ function parseScopeFlag() {
193
+ const args = process.argv.slice(3);
194
+ if (args.includes("--project"))
195
+ return "project";
196
+ return "global";
197
+ }
198
+ // ─── Engine-backed sync command ─────────────────────────────────────────────
199
+ function sync() {
200
+ const target = parseTargetFlag();
201
+ if (!target) {
202
+ console.error("Error: --target flag is required for sync.");
203
+ console.error("Usage: npx cortex-agents sync --target claude|opencode|codex|gemini");
204
+ process.exit(1);
205
+ }
206
+ console.log(`\nSyncing to ${target}...\n`);
207
+ const engine = new CortexEngine();
208
+ engine.initialize();
209
+ try {
210
+ const result = engine.syncTarget(target);
211
+ console.log(` Agents written: ${result.agentsWritten.length}`);
212
+ for (const id of result.agentsWritten) {
213
+ console.log(` - ${id}`);
214
+ }
215
+ if (result.skillsWritten.length > 0) {
216
+ console.log(` Skills written: ${result.skillsWritten.length}`);
217
+ }
218
+ if (result.instructionsWritten) {
219
+ console.log(` Instructions file: written`);
220
+ }
221
+ if (result.errors.length > 0) {
222
+ console.log(`\n Errors:`);
223
+ for (const err of result.errors) {
224
+ console.log(` - ${err}`);
225
+ }
226
+ }
227
+ console.log(`\nDone! Sync complete for ${target}.\n`);
228
+ }
229
+ finally {
230
+ engine.close();
231
+ }
232
+ }
233
+ // ─── Engine-backed install for specific targets ─────────────────────────────
234
+ function installTarget(target) {
235
+ console.log(`\nInstalling ${PLUGIN_NAME} v${VERSION} for ${target}...\n`);
236
+ const engine = new CortexEngine();
237
+ const seedResult = engine.initialize();
238
+ if (seedResult) {
239
+ console.log(` Database seeded: ${seedResult.agents} agents, ${seedResult.skills} skills, ${seedResult.models} models`);
240
+ }
241
+ try {
242
+ const scope = parseScopeFlag();
243
+ const result = engine.syncTarget(target, { scope });
244
+ console.log(` Agents written: ${result.agentsWritten.length}`);
245
+ if (result.skillsWritten.length > 0) {
246
+ console.log(` Skills written: ${result.skillsWritten.length}`);
247
+ }
248
+ if (result.instructionsWritten) {
249
+ console.log(` Instructions file: written`);
250
+ }
251
+ // Record installation
252
+ const installPath = scope === "project" ? process.cwd() : "global";
253
+ engine.recordInstallation(target, scope, installPath, VERSION);
254
+ if (result.errors.length > 0) {
255
+ console.log(`\n Errors:`);
256
+ for (const err of result.errors) {
257
+ console.log(` - ${err}`);
258
+ }
259
+ }
260
+ console.log(`\nDone! ${target} target installed.\n`);
261
+ }
262
+ finally {
263
+ engine.close();
264
+ }
265
+ }
182
266
  // ─── Commands ────────────────────────────────────────────────────────────────
183
267
  function install() {
268
+ // Check for --target flag: use engine-backed install
269
+ const target = parseTargetFlag();
270
+ if (target) {
271
+ return installTarget(target);
272
+ }
273
+ // Default: original opencode install behavior
184
274
  console.log(`\nInstalling ${PLUGIN_NAME} v${VERSION}...\n`);
185
275
  const globalDir = getGlobalDir();
186
276
  const configInfo = findOpencodeConfig();
@@ -598,11 +688,58 @@ function status() {
598
688
  console.log(` Run 'npx ${PLUGIN_NAME} configure' for global config`);
599
689
  console.log(` Run 'npx ${PLUGIN_NAME} configure --project' for per-project config`);
600
690
  }
691
+ // Engine database status
692
+ try {
693
+ const engine = new CortexEngine();
694
+ engine.initialize();
695
+ const dbAgents = engine.listAgents();
696
+ const dbSkills = engine.listSkills();
697
+ const dbModels = engine.listModels();
698
+ const dbTargets = engine.listTargets();
699
+ const installations = engine.getInstallations();
700
+ console.log("\nEngine Database:");
701
+ console.log(` Agents: ${dbAgents.length} (${dbAgents.filter(a => a.mode === 'primary').length} primary, ${dbAgents.filter(a => a.mode === 'subagent').length} subagent)`);
702
+ console.log(` Skills: ${dbSkills.length}`);
703
+ console.log(` Models: ${dbModels.length}`);
704
+ console.log(` Targets: ${dbTargets.map(t => t.id).join(", ")}`);
705
+ if (installations.length > 0) {
706
+ console.log(` Installations:`);
707
+ for (const inst of installations) {
708
+ console.log(` - ${inst.target_id} (${inst.scope}) v${inst.version} at ${inst.path}`);
709
+ }
710
+ }
711
+ engine.close();
712
+ }
713
+ catch {
714
+ // Engine not yet initialized — skip silently
715
+ }
716
+ // Cortex Code integration detection
717
+ const cortexEventUrl = process.env.CORTEX_EVENT_URL;
718
+ const cortexTaskId = process.env.CORTEX_TASK_ID;
719
+ const cortexCode = process.env.CORTEX_CODE;
720
+ if (cortexEventUrl && cortexTaskId && cortexCode) {
721
+ console.log("\nCortex Code: DETECTED");
722
+ console.log(` Event URL: ${cortexEventUrl}`);
723
+ console.log(` Task ID: ${cortexTaskId}`);
724
+ }
725
+ else {
726
+ console.log("\nCortex Code: Not detected");
727
+ }
601
728
  if (!isInstalled) {
602
729
  console.log(`\nRun 'npx ${PLUGIN_NAME} install' to add to config.`);
603
730
  }
604
731
  console.log();
605
732
  }
733
+ // ─── MCP Server ──────────────────────────────────────────────────────────────
734
+ async function mcp() {
735
+ try {
736
+ await startMCPServer();
737
+ }
738
+ catch (error) {
739
+ console.error("MCP server error:", error);
740
+ process.exit(1);
741
+ }
742
+ }
606
743
  function help() {
607
744
  console.log(`${PLUGIN_NAME} v${VERSION}
608
745
 
@@ -613,22 +750,28 @@ USAGE:
613
750
  npx ${PLUGIN_NAME} <command> [options]
614
751
 
615
752
  COMMANDS:
616
- install Install plugin, agents, and skills into OpenCode config
617
- configure Interactive model selection (global)
618
- configure --project Interactive model selection (per-project, saves to .opencode/)
619
- configure --reset Reset model configuration to OpenCode defaults
620
- configure --project --reset Reset per-project model configuration
621
- uninstall Remove plugin, agents, skills, and model config
622
- status Show installation and model configuration status
623
- help Show this help message
753
+ install Install plugin, agents, and skills into OpenCode config
754
+ install --target <target> Install to a specific CLI target (engine-backed)
755
+ sync --target <target> Re-render agents from DB to target config dir
756
+ configure Interactive model selection (global)
757
+ configure --project Interactive model selection (per-project)
758
+ configure --reset Reset model configuration to defaults
759
+ uninstall Remove plugin, agents, skills, and model config
760
+ status Show installation, DB stats, and model configuration
761
+ mcp Start MCP server on stdio (for Gemini, Codex, Claude CLIs)
762
+ help Show this help message
624
763
 
625
764
  EXAMPLES:
626
- npx ${PLUGIN_NAME} install # Install plugin
765
+ npx ${PLUGIN_NAME} install # Install plugin (OpenCode default)
766
+ npx ${PLUGIN_NAME} install --target claude # Install to Claude Code
767
+ npx ${PLUGIN_NAME} install --target opencode # Install to OpenCode
768
+ npx ${PLUGIN_NAME} install --target codex # Install to Codex CLI
769
+ npx ${PLUGIN_NAME} install --target gemini # Install to Gemini CLI
770
+ npx ${PLUGIN_NAME} sync --target claude # Re-sync agents to Claude Code
627
771
  npx ${PLUGIN_NAME} configure # Global model selection
628
- npx ${PLUGIN_NAME} configure --project # Per-project models (.opencode/models.json)
629
- npx ${PLUGIN_NAME} configure --reset # Reset global models
630
- npx ${PLUGIN_NAME} configure --project --reset # Reset per-project models
631
- npx ${PLUGIN_NAME} status # Check status
772
+ npx ${PLUGIN_NAME} configure --project # Per-project models
773
+ npx ${PLUGIN_NAME} status # Check status + DB stats
774
+ npx ${PLUGIN_NAME} mcp # Start MCP server (stdio)
632
775
 
633
776
  AGENTS:
634
777
  Primary (architect, implement, fix):
@@ -670,6 +813,9 @@ switch (command) {
670
813
  case "install":
671
814
  install();
672
815
  break;
816
+ case "sync":
817
+ sync();
818
+ break;
673
819
  case "configure":
674
820
  configure().catch((err) => {
675
821
  console.error("Configuration failed:", err.message);
@@ -682,6 +828,12 @@ switch (command) {
682
828
  case "status":
683
829
  status();
684
830
  break;
831
+ case "mcp":
832
+ mcp().catch((err) => {
833
+ console.error("MCP server failed:", err.message);
834
+ process.exit(1);
835
+ });
836
+ break;
685
837
  case "help":
686
838
  case "--help":
687
839
  case "-h":
@@ -0,0 +1,19 @@
1
+ import type BetterSqlite3 from "better-sqlite3";
2
+ import type { Agent, AgentInput, AgentTool, BashPermission, AgentSkill } from "./types.js";
3
+ export declare class AgentStore {
4
+ private db;
5
+ constructor(db: BetterSqlite3.Database);
6
+ get(id: string): Agent | null;
7
+ list(filter?: {
8
+ mode?: string;
9
+ }): Agent[];
10
+ upsert(agent: AgentInput): void;
11
+ getTools(agentId: string): AgentTool[];
12
+ setTool(agentId: string, toolName: string, allowed: boolean): void;
13
+ setTools(agentId: string, tools: Record<string, boolean>): void;
14
+ getBashPermissions(agentId: string): BashPermission[];
15
+ setBashPermission(agentId: string, pattern: string, permission: string): void;
16
+ setBashPermissions(agentId: string, permissions: Record<string, string>): void;
17
+ getSkills(agentId: string): AgentSkill[];
18
+ }
19
+ //# sourceMappingURL=agents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents.d.ts","sourceRoot":"","sources":["../../src/engine/agents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,aAAa,MAAM,gBAAgB,CAAC;AAChD,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,UAAU,EACX,MAAM,YAAY,CAAC;AAEpB,qBAAa,UAAU;IACT,OAAO,CAAC,EAAE;gBAAF,EAAE,EAAE,aAAa,CAAC,QAAQ;IAE9C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAK7B,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,EAAE;IAWzC,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAc/B,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE;IAOtC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAQlE,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAmB/D,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE;IAOrD,iBAAiB,CACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,GACjB,IAAI;IAQP,kBAAkB,CAChB,OAAO,EAAE,MAAM,EACf,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,IAAI;IAmBP,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE;CAMzC"}
@@ -0,0 +1,69 @@
1
+ export class AgentStore {
2
+ db;
3
+ constructor(db) {
4
+ this.db = db;
5
+ }
6
+ get(id) {
7
+ const stmt = this.db.prepare("SELECT * FROM agents WHERE id = ?");
8
+ return stmt.get(id) ?? null;
9
+ }
10
+ list(filter) {
11
+ if (filter?.mode) {
12
+ const stmt = this.db.prepare("SELECT * FROM agents WHERE mode = ? ORDER BY id");
13
+ return stmt.all(filter.mode);
14
+ }
15
+ const stmt = this.db.prepare("SELECT * FROM agents ORDER BY id");
16
+ return stmt.all();
17
+ }
18
+ upsert(agent) {
19
+ const stmt = this.db.prepare(`INSERT OR REPLACE INTO agents (id, description, mode, temperature, system_prompt, updated_at)
20
+ VALUES (?, ?, ?, ?, ?, datetime('now'))`);
21
+ stmt.run(agent.id, agent.description, agent.mode, agent.temperature ?? 0, agent.system_prompt);
22
+ }
23
+ getTools(agentId) {
24
+ const stmt = this.db.prepare("SELECT * FROM agent_tools WHERE agent_id = ?");
25
+ return stmt.all(agentId);
26
+ }
27
+ setTool(agentId, toolName, allowed) {
28
+ const stmt = this.db.prepare(`INSERT OR REPLACE INTO agent_tools (agent_id, tool_name, allowed)
29
+ VALUES (?, ?, ?)`);
30
+ stmt.run(agentId, toolName, allowed ? 1 : 0);
31
+ }
32
+ setTools(agentId, tools) {
33
+ const deleteStmt = this.db.prepare("DELETE FROM agent_tools WHERE agent_id = ?");
34
+ const insertStmt = this.db.prepare(`INSERT INTO agent_tools (agent_id, tool_name, allowed)
35
+ VALUES (?, ?, ?)`);
36
+ const batch = this.db.transaction(() => {
37
+ deleteStmt.run(agentId);
38
+ for (const [toolName, allowed] of Object.entries(tools)) {
39
+ insertStmt.run(agentId, toolName, allowed ? 1 : 0);
40
+ }
41
+ });
42
+ batch();
43
+ }
44
+ getBashPermissions(agentId) {
45
+ const stmt = this.db.prepare("SELECT * FROM agent_bash_permissions WHERE agent_id = ?");
46
+ return stmt.all(agentId);
47
+ }
48
+ setBashPermission(agentId, pattern, permission) {
49
+ const stmt = this.db.prepare(`INSERT OR REPLACE INTO agent_bash_permissions (agent_id, pattern, permission)
50
+ VALUES (?, ?, ?)`);
51
+ stmt.run(agentId, pattern, permission);
52
+ }
53
+ setBashPermissions(agentId, permissions) {
54
+ const deleteStmt = this.db.prepare("DELETE FROM agent_bash_permissions WHERE agent_id = ?");
55
+ const insertStmt = this.db.prepare(`INSERT INTO agent_bash_permissions (agent_id, pattern, permission)
56
+ VALUES (?, ?, ?)`);
57
+ const batch = this.db.transaction(() => {
58
+ deleteStmt.run(agentId);
59
+ for (const [pattern, permission] of Object.entries(permissions)) {
60
+ insertStmt.run(agentId, pattern, permission);
61
+ }
62
+ });
63
+ batch();
64
+ }
65
+ getSkills(agentId) {
66
+ const stmt = this.db.prepare("SELECT * FROM agent_skills WHERE agent_id = ?");
67
+ return stmt.all(agentId);
68
+ }
69
+ }
@@ -0,0 +1,13 @@
1
+ import Database from "better-sqlite3";
2
+ /**
3
+ * Returns the default database path: ~/.config/cortex-agents/cortex.db
4
+ */
5
+ export declare function getDefaultDbPath(): string;
6
+ /**
7
+ * Creates (or opens) a better-sqlite3 database with WAL mode and foreign keys enabled.
8
+ *
9
+ * @param dbPath - Absolute path to the SQLite file. Defaults to ~/.config/cortex-agents/cortex.db
10
+ * @returns The configured Database instance
11
+ */
12
+ export declare function createDatabase(dbPath?: string): Database.Database;
13
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/engine/db.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAKtC;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,QAAQ,CAgBjE"}
@@ -0,0 +1,28 @@
1
+ import Database from "better-sqlite3";
2
+ import fs from "node:fs";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ /**
6
+ * Returns the default database path: ~/.config/cortex-agents/cortex.db
7
+ */
8
+ export function getDefaultDbPath() {
9
+ return path.join(os.homedir(), ".config", "cortex-agents", "cortex.db");
10
+ }
11
+ /**
12
+ * Creates (or opens) a better-sqlite3 database with WAL mode and foreign keys enabled.
13
+ *
14
+ * @param dbPath - Absolute path to the SQLite file. Defaults to ~/.config/cortex-agents/cortex.db
15
+ * @returns The configured Database instance
16
+ */
17
+ export function createDatabase(dbPath) {
18
+ const resolvedPath = dbPath ?? getDefaultDbPath();
19
+ // Ensure the parent directory exists
20
+ const dir = path.dirname(resolvedPath);
21
+ fs.mkdirSync(dir, { recursive: true });
22
+ const db = new Database(resolvedPath);
23
+ // Enable WAL mode for better concurrent read performance
24
+ db.pragma("journal_mode = WAL");
25
+ // Enforce foreign key constraints
26
+ db.pragma("foreign_keys = ON");
27
+ return db;
28
+ }
@@ -0,0 +1,50 @@
1
+ import { type SeedResult } from "./seed.js";
2
+ import "./renderers/claude.js";
3
+ import "./renderers/opencode.js";
4
+ import "./renderers/codex.js";
5
+ import "./renderers/gemini.js";
6
+ import type { Agent, AgentInput, AgentTool, BashPermission, AgentSkill, Skill, SkillInput, CliTarget, AgentTargetConfig, Model, Installation, SyncResult } from "./types.js";
7
+ export type { Agent, AgentInput, AgentTool, BashPermission, AgentSkill, Skill, SkillInput, CliTarget, AgentTargetConfig, Model, Installation, SyncResult, SeedResult, };
8
+ export declare class CortexEngine {
9
+ private db;
10
+ private _agents;
11
+ private _skills;
12
+ private _models;
13
+ private _targets;
14
+ constructor(dbPath?: string);
15
+ /** Create tables, run migrations, seed if empty. */
16
+ initialize(): SeedResult | null;
17
+ /** Re-seed the database from .opencode/ files. */
18
+ seed(opencodeDir?: string): SeedResult;
19
+ /** Close the database connection. */
20
+ close(): void;
21
+ getAgent(id: string): Agent | null;
22
+ listAgents(filter?: {
23
+ mode?: string;
24
+ }): Agent[];
25
+ upsertAgent(agent: AgentInput): void;
26
+ getAgentTools(agentId: string): AgentTool[];
27
+ getAgentBashPermissions(agentId: string): BashPermission[];
28
+ getSkill(id: string): Skill | null;
29
+ listSkills(): Skill[];
30
+ getSkillContent(id: string): string | null;
31
+ upsertSkill(skill: SkillInput): void;
32
+ getAgentSkills(agentId: string): AgentSkill[];
33
+ getTarget(id: string): CliTarget | null;
34
+ listTargets(): CliTarget[];
35
+ getAgentTargetConfig(agentId: string, targetId: string): AgentTargetConfig | null;
36
+ renderAgent(agentId: string, targetId: string): string;
37
+ renderInstructions(targetId: string): string;
38
+ syncTarget(targetId: string, opts?: {
39
+ scope?: string;
40
+ projectPath?: string;
41
+ }): SyncResult;
42
+ listModels(filter?: {
43
+ tier?: string;
44
+ }): Model[];
45
+ getConfig(key: string): string | null;
46
+ setConfig(key: string, value: string): void;
47
+ recordInstallation(targetId: string, scope: string, path: string, version: string): void;
48
+ getInstallations(): Installation[];
49
+ }
50
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/engine/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AAQ1D,OAAO,uBAAuB,CAAC;AAC/B,OAAO,yBAAyB,CAAC;AACjC,OAAO,sBAAsB,CAAC;AAC9B,OAAO,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,YAAY,EACZ,UAAU,EACX,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,cAAc,EACd,UAAU,EACV,KAAK,EACL,UAAU,EACV,SAAS,EACT,iBAAiB,EACjB,KAAK,EACL,YAAY,EACZ,UAAU,EACV,UAAU,GACX,CAAC;AAQF,qBAAa,YAAY;IACvB,OAAO,CAAC,EAAE,CAAyB;IACnC,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,OAAO,CAAa;IAC5B,OAAO,CAAC,QAAQ,CAAc;gBAElB,MAAM,CAAC,EAAE,MAAM;IAU3B,oDAAoD;IACpD,UAAU,IAAI,UAAU,GAAG,IAAI;IAW/B,kDAAkD;IAClD,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU;IAItC,qCAAqC;IACrC,KAAK,IAAI,IAAI;IAMb,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAIlC,UAAU,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,EAAE;IAI/C,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAIpC,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,EAAE;IAI3C,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,cAAc,EAAE;IAM1D,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAIlC,UAAU,IAAI,KAAK,EAAE;IAIrB,eAAe,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAI1C,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAIpC,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,EAAE;IAM7C,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;IAIvC,WAAW,IAAI,SAAS,EAAE;IAI1B,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAMjF,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAMtD,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAM5C,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,UAAU;IAQzF,UAAU,CAAC,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,KAAK,EAAE;IAM/C,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI;IAIrC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAM3C,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAIxF,gBAAgB,IAAI,YAAY,EAAE;CAGnC"}