@cortex-agent/server 2026.5.22-2 → 2026.5.23

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.
@@ -6,6 +6,7 @@
6
6
  "profile": "__active__",
7
7
  "persistSession": true,
8
8
  "promptTemplate": "{{input}}\n\nWrite your final reply to {{artifactPath}}.",
9
+ "systemPrompt": "file:direct.md",
9
10
  "tools": "Agent,AskUserQuestion,Bash,Edit,EnterPlanMode,ExitPlanMode,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
10
11
  "pluginDirs": [
11
12
  "plugins/cortex-common",
@@ -20,6 +21,7 @@
20
21
  "profile": "__active__",
21
22
  "persistSession": true,
22
23
  "promptTemplate": "{{input}}",
24
+ "systemPrompt": "file:direct.md",
23
25
  "tools": "Agent,AskUserQuestion,Bash,Edit,EnterPlanMode,ExitPlanMode,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
24
26
  "pluginDirs": [
25
27
  "plugins/cortex-common",
@@ -50,6 +52,7 @@
50
52
  "persistSession": false,
51
53
  "directive": "",
52
54
  "promptTemplate": "{{input}}\n\n{{previousOutput}}",
55
+ "systemPrompt": "file:worker.md",
53
56
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
54
57
  "pluginDirs": [
55
58
  "plugins/cortex-common",
@@ -64,6 +67,7 @@
64
67
  "profile": "__active__",
65
68
  "persistSession": false,
66
69
  "promptTemplate": "{{input}}",
70
+ "systemPrompt": "file:worker.md",
67
71
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
68
72
  "pluginDirs": [
69
73
  "plugins/cortex-common",
@@ -78,6 +82,7 @@
78
82
  "profile": "plan",
79
83
  "persistSession": true,
80
84
  "promptTemplate": "Write your plan to {{artifactPath}}.\n\nUser request:\n{{input}}",
85
+ "systemPrompt": "file:worker.md",
81
86
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
82
87
  "pluginDirs": [
83
88
  "plugins/cortex-common",
@@ -91,6 +96,7 @@
91
96
  "persistSession": true,
92
97
  "directive": "You are a strict reviewer. Evaluate the plan for correctness, completeness, and feasibility.",
93
98
  "promptTemplate": "Read the content in {{artifactPath}} and perform a review. Append your review to the ## Review section at the end of the file. If the content passes, write [APPROVED] at the end of the review. Otherwise provide specific suggestions for improvement.",
99
+ "systemPrompt": "file:worker.md",
94
100
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
95
101
  "pluginDirs": [
96
102
  "plugins/cortex-common",
@@ -104,6 +110,7 @@
104
110
  "persistSession": false,
105
111
  "directive": "file:plan-reviewer.md",
106
112
  "promptTemplate": "Execute the plan-phase audit per the plan-reviewer directive.\n\nTask / context (must declare plan path, phase under review, and where the phase's artifacts live):\n{{input}}\n\n---\n\nWrite the review to {{artifactPath}}. Walk every acceptance criterion of the phase explicitly (met / partially met / not met with a citation). End the artifact with a single line in the exact form: `Verdict: Approve | Revise | Reject` (one word, no modifiers).",
113
+ "systemPrompt": "file:worker.md",
107
114
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
108
115
  "pluginDirs": [
109
116
  "plugins/cortex-common",
@@ -117,6 +124,7 @@
117
124
  "persistSession": false,
118
125
  "directive": "file:plan-executor.md",
119
126
  "promptTemplate": "Translate Plan Reviewer's verdict into operations per the plan-executor directive.\n\nPlan Reviewer's report (previous step):\n{{previousOutput}}\n\n---\n\nOriginal task / context:\n{{input}}\n\n---\n\nReviewer's full artifact is at {{artifactPath}} \u2014 read it end-to-end first, extract the `Verdict:` word, then run the matching branch (Approve / Revise / Reject). All new tasks MUST carry `template:plan-gate` and full metadata; gate tasks always start `PLAN-GATE: `. Do NOT modify the plan file's structure or acceptance criteria.",
127
+ "systemPrompt": "file:worker.md",
120
128
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
121
129
  "pluginDirs": [
122
130
  "plugins/cortex-stage-gate"
@@ -129,6 +137,7 @@
129
137
  "persistSession": false,
130
138
  "directive": "file:milestone-reviewer.md",
131
139
  "promptTemplate": "Execute the milestone adversarial audit per the milestone-reviewer directive.\n\nTask / context:\n{{input}}\n\n---\n\nWrite the review to {{artifactPath}}. Cover every dimension the milestone's success criteria can be judged on. Each issue must carry a citation and a Blocker / Nice-to-have label. Do NOT issue a Director-style verdict \u2014 that belongs to Director.",
140
+ "systemPrompt": "file:worker.md",
132
141
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
133
142
  "pluginDirs": [
134
143
  "plugins/cortex-common",
@@ -142,6 +151,7 @@
142
151
  "persistSession": false,
143
152
  "directive": "file:director.md",
144
153
  "promptTemplate": "Execute the milestone verdict per the director directive.\n\nMilestone Reviewer's report (previous step):\n{{previousOutput}}\n\n---\n\nOriginal task / context:\n{{input}}\n\n---\n\nReviewer's full artifact is at {{artifactPath}} \u2014 read it end-to-end first. Write your analysis and the final `Verdict:` line back to the same artifact. Artifact MUST agree on verdict word and top reasons.",
154
+ "systemPrompt": "file:worker.md",
145
155
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
146
156
  "pluginDirs": [
147
157
  "plugins/cortex-common",
@@ -155,6 +165,7 @@
155
165
  "persistSession": false,
156
166
  "directive": "file:milestone-executor.md",
157
167
  "promptTemplate": "Translate Director's verdict into operations per the milestone-executor directive.\n\nDirector's analysis (previous step):\n{{previousOutput}}\n\n---\n\nOriginal task / context:\n{{input}}\n\n---\n\nDirector's full artifact is at {{artifactPath}} \u2014 read it end-to-end first and extract the `Verdict:` word. Then execute the matching branch (Proceed / Iterate / Pivot / Abort) per directive.",
168
+ "systemPrompt": "file:worker.md",
158
169
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
159
170
  "pluginDirs": [
160
171
  "plugins/cortex-stage-gate"
@@ -166,6 +177,7 @@
166
177
  "profile": "plan",
167
178
  "persistSession": true,
168
179
  "directive": "file:doc-writer.md",
180
+ "systemPrompt": "file:worker.md",
169
181
  "entryStage": "write",
170
182
  "stages": {
171
183
  "write": {
@@ -190,6 +202,7 @@
190
202
  "profile": "execute",
191
203
  "persistSession": true,
192
204
  "directive": "file:doc-reviewer.md",
205
+ "systemPrompt": "file:worker.md",
193
206
  "promptTemplate": "Audit Doc Writer's project-file changes (changes by other agents in the same files may appear \u2014 ignore those):\n{{modifiedFiles}}\n\nOriginal task:\n{{input}}\n\nApply the doc-reviewer directive and append your review to {{artifactPath}} under `## Review (iteration N)`. End the section with `[APPROVED]` if no Blockers remain; otherwise list the Blockers so Doc Writer can revise.",
194
207
  "tools": "Agent,Bash,Edit,Glob,Grep,Read,Skill,TaskStop,TodoWrite,WebFetch,WebSearch,Write",
195
208
  "pluginDirs": [
@@ -7,6 +7,16 @@ export declare function resolveFileRef(field: string, value: string | undefined)
7
7
  /** Resolve a plugin directory path. Absolute paths are returned as-is;
8
8
  * relative paths are resolved against DATA_DIR (plugins live under DATA_DIR/plugins/). */
9
9
  export declare function resolvePluginDir(dir: string): string;
10
+ /**
11
+ * Merge defaults thread-templates.json into the user's config.
12
+ * - Agents/templates not in user config → added from defaults.
13
+ * - Agents/templates already in user config → preserved as-is (never overwritten).
14
+ * - If user config doesn't exist → copy defaults in full.
15
+ * - Malformed user config → replace with defaults.
16
+ *
17
+ * @returns true if the user config file was written, false if no changes were needed.
18
+ */
19
+ export declare function mergeThreadTemplates(defaultsPath: string, userConfigPath: string): boolean;
10
20
  export declare function loadConfig(): {
11
21
  agents: Record<string, AgentDefinition>;
12
22
  templates: Record<string, ThreadTemplate>;
@@ -1,7 +1,7 @@
1
1
  // Thread template config loading and hot-reload.
2
2
  // input: DATA_DIR/thread-templates.json, prompts/ directory
3
3
  // output: loadConfig / startConfigWatcher / stopConfigWatcher / getTemplate / getAgent / listTemplates / listAgents / resolvePluginDir
4
- import { readFileSync, existsSync, watch } from 'fs';
4
+ import { readFileSync, writeFileSync, existsSync, mkdirSync, watch } from 'fs';
5
5
  import * as path from 'path';
6
6
  import { CONFIG_DIR, DATA_DIR, PROMPTS_DIR } from '../../core/utils.js';
7
7
  import { createLogger } from '../../core/log.js';
@@ -66,6 +66,76 @@ export function resolvePluginDir(dir) {
66
66
  return dir;
67
67
  return path.join(DATA_DIR, dir);
68
68
  }
69
+ // --- Config merging (init) ---
70
+ /**
71
+ * Merge defaults thread-templates.json into the user's config.
72
+ * - Agents/templates not in user config → added from defaults.
73
+ * - Agents/templates already in user config → preserved as-is (never overwritten).
74
+ * - If user config doesn't exist → copy defaults in full.
75
+ * - Malformed user config → replace with defaults.
76
+ *
77
+ * @returns true if the user config file was written, false if no changes were needed.
78
+ */
79
+ export function mergeThreadTemplates(defaultsPath, userConfigPath) {
80
+ // 1. Read defaults
81
+ let defaults;
82
+ try {
83
+ const raw = readFileSync(defaultsPath, 'utf8');
84
+ defaults = JSON.parse(raw);
85
+ }
86
+ catch (e) {
87
+ log.warn(`Cannot read default thread-templates.json from ${defaultsPath}: ${e.message}`);
88
+ return false;
89
+ }
90
+ const defaultAgents = defaults.agents || {};
91
+ const defaultTemplates = defaults.templates || {};
92
+ // 2. User config doesn't exist yet — copy defaults as-is
93
+ if (!existsSync(userConfigPath)) {
94
+ const dir = path.dirname(userConfigPath);
95
+ if (!existsSync(dir))
96
+ mkdirSync(dir, { recursive: true });
97
+ writeFileSync(userConfigPath, JSON.stringify(defaults, null, 2) + '\n', 'utf8');
98
+ log.info('thread-templates.json created from defaults');
99
+ return true;
100
+ }
101
+ // 3. Parse existing user config
102
+ let userConfig;
103
+ try {
104
+ const raw = readFileSync(userConfigPath, 'utf8');
105
+ userConfig = JSON.parse(raw);
106
+ }
107
+ catch (e) {
108
+ log.warn(`Failed to parse existing thread-templates.json (${e.message}), falling back to defaults`);
109
+ writeFileSync(userConfigPath, JSON.stringify(defaults, null, 2) + '\n', 'utf8');
110
+ return true;
111
+ }
112
+ const userAgents = { ...(userConfig.agents || {}) };
113
+ const userTemplates = { ...(userConfig.templates || {}) };
114
+ let changed = false;
115
+ // 4. Add new agents from defaults that don't exist in user config
116
+ for (const [name, agent] of Object.entries(defaultAgents)) {
117
+ if (!userAgents[name]) {
118
+ userAgents[name] = agent;
119
+ log.info(`Added new agent to thread-templates.json: ${name}`);
120
+ changed = true;
121
+ }
122
+ }
123
+ // 5. Add new templates from defaults that don't exist in user config
124
+ for (const [name, template] of Object.entries(defaultTemplates)) {
125
+ if (!userTemplates[name]) {
126
+ userTemplates[name] = template;
127
+ log.info(`Added new template to thread-templates.json: ${name}`);
128
+ changed = true;
129
+ }
130
+ }
131
+ // 6. Only write if something changed
132
+ if (changed) {
133
+ const merged = { agents: userAgents, templates: userTemplates };
134
+ writeFileSync(userConfigPath, JSON.stringify(merged, null, 2) + '\n', 'utf8');
135
+ log.info('thread-templates.json merged with defaults');
136
+ }
137
+ return changed;
138
+ }
69
139
  // --- Config loading ---
70
140
  export function loadConfig() {
71
141
  try {
@@ -19,6 +19,7 @@ import * as yaml from 'yaml';
19
19
  import { buildFullConfig, buildCoreConfig, buildTuiConfig } from '../core/config-generator.js';
20
20
  import { discoverEndpoints, generateGatewayYaml, writeGatewayYaml } from '../core/gateway-generator.js';
21
21
  import { generateProfiles, writeProfilesJson, listChoices } from '../core/profile-generator.js';
22
+ import { mergeThreadTemplates } from '../domain/threads/index.js';
22
23
  import { createLogger } from '../core/log.js';
23
24
  import { INSTALL_ROOT, DEFAULTS_DIR } from '../core/utils.js';
24
25
  // ─── Path computation (DATA_DIR resolved locally to support --home override) ──
@@ -1027,9 +1028,10 @@ function copyDefaults(paths, force) {
1027
1028
  safeCopy(path.join(DEFAULTS_DIR, 'context', 'scans', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'scans', 'CORTEX.md'), false, 'context/scans/CORTEX.md');
1028
1029
  safeCopy(path.join(DEFAULTS_DIR, 'context', 'ideas', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'ideas', 'CORTEX.md'), false, 'context/ideas/CORTEX.md');
1029
1030
  safeCopy(path.join(DEFAULTS_DIR, 'context', 'user', 'CORTEX.md'), path.join(paths.CONTEXT_DIR, 'user', 'CORTEX.md'), false, 'context/user/CORTEX.md');
1030
- // Config defaults — overwrite only with --force
1031
+ // Config defaults — budget and session-hooks overwrite only with --force;
1032
+ // thread-templates are merged (new agents/templates added, existing preserved)
1031
1033
  safeCopy(path.join(DEFAULTS_DIR, 'config', 'budget.json'), path.join(paths.CONFIG_DIR, 'budget.json'), force, 'budget.json');
1032
- safeCopy(path.join(DEFAULTS_DIR, 'config', 'thread-templates.json'), path.join(paths.CONFIG_DIR, 'thread-templates.json'), force, 'thread-templates.json');
1034
+ mergeThreadTemplates(path.join(DEFAULTS_DIR, 'config', 'thread-templates.json'), path.join(paths.CONFIG_DIR, 'thread-templates.json'));
1033
1035
  safeCopy(path.join(DEFAULTS_DIR, 'config', 'session-hooks.json'), path.join(paths.CONFIG_DIR, 'session-hooks.json'), force, 'session-hooks.json');
1034
1036
  // Seed asset trees — per-file safeCopy semantics: new files always added, existing files
1035
1037
  // preserved unless force=true. These directories are referenced at runtime; without them
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortex-agent/server",
3
- "version": "2026.5.22-2",
3
+ "version": "2026.5.23",
4
4
  "type": "module",
5
5
  "description": "Autonomous agent system for long-running projects — mission-driven, multi-agent pipelines, self-evolving skills.",
6
6
  "engines": {