@cortex-agent/server 2026.6.11 → 2026.6.15
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.
- package/dist/core/gateway-generator.js +24 -3
- package/dist/core/i18n.d.ts +19 -0
- package/dist/core/i18n.js +46 -0
- package/dist/core/locales/en.d.ts +438 -0
- package/dist/core/locales/en.js +24 -0
- package/dist/core/locales/slices/commands.d.ts +214 -0
- package/dist/core/locales/slices/commands.js +462 -0
- package/dist/core/locales/slices/init.d.ts +121 -0
- package/dist/core/locales/slices/init.js +380 -0
- package/dist/core/locales/slices/interactions.d.ts +47 -0
- package/dist/core/locales/slices/interactions.js +102 -0
- package/dist/core/locales/slices/lang.d.ts +8 -0
- package/dist/core/locales/slices/lang.js +18 -0
- package/dist/core/locales/slices/scheduling.d.ts +36 -0
- package/dist/core/locales/slices/scheduling.js +74 -0
- package/dist/core/locales/slices/startup.d.ts +6 -0
- package/dist/core/locales/slices/startup.js +14 -0
- package/dist/core/locales/slices/status.d.ts +20 -0
- package/dist/core/locales/slices/status.js +48 -0
- package/dist/core/locales/zh.d.ts +5 -0
- package/dist/core/locales/zh.js +23 -0
- package/dist/core/singleton-lock.d.ts +23 -0
- package/dist/core/singleton-lock.js +53 -0
- package/dist/core/status-format.js +2 -1
- package/dist/core/utils.d.ts +9 -1
- package/dist/core/utils.js +9 -1
- package/dist/domain/agents/config.d.ts +2 -1
- package/dist/domain/agents/config.js +25 -6
- package/dist/domain/scheduling/jobs/task-dispatch.js +6 -10
- package/dist/domain/scheduling/schedule-command.js +38 -37
- package/dist/domain/system/github-release.d.ts +18 -0
- package/dist/domain/system/github-release.js +106 -0
- package/dist/domain/system/preferences.d.ts +12 -0
- package/dist/domain/system/preferences.js +36 -0
- package/dist/domain/tasks/dispatcher.d.ts +11 -2
- package/dist/domain/tasks/dispatcher.js +37 -7
- package/dist/domain/threads/prompt-builder.d.ts +6 -0
- package/dist/domain/threads/prompt-builder.js +19 -2
- package/dist/entry/app.js +36 -3
- package/dist/entry/daemon.js +12 -30
- package/dist/entry/init.d.ts +4 -3
- package/dist/entry/init.js +151 -208
- package/dist/entry/startup-notify.js +6 -3
- package/dist/orchestration/interactions/interaction-handlers.js +12 -11
- package/dist/orchestration/interactions/update-prompt-slack.js +11 -10
- package/dist/orchestration/interactions/update-prompt.js +66 -11
- package/dist/orchestration/lifecycle.js +13 -12
- package/dist/orchestration/routing/commands/cancel.js +10 -9
- package/dist/orchestration/routing/commands/channel.js +27 -26
- package/dist/orchestration/routing/commands/cost.js +10 -2
- package/dist/orchestration/routing/commands/device.js +11 -9
- package/dist/orchestration/routing/commands/dispatch.js +10 -10
- package/dist/orchestration/routing/commands/index.js +6 -2
- package/dist/orchestration/routing/commands/lang.d.ts +3 -0
- package/dist/orchestration/routing/commands/lang.js +31 -0
- package/dist/orchestration/routing/commands/mode.js +28 -27
- package/dist/orchestration/routing/commands/nvtop.js +13 -12
- package/dist/orchestration/routing/commands/orient.js +2 -1
- package/dist/orchestration/routing/commands/schedule.js +23 -22
- package/dist/orchestration/routing/commands/sendfile.js +8 -7
- package/dist/orchestration/routing/commands/session.js +11 -10
- package/dist/orchestration/routing/commands/status.js +78 -71
- package/dist/orchestration/routing/commands/tail.js +6 -5
- package/dist/orchestration/routing/commands/task.js +23 -22
- package/dist/orchestration/routing/commands/thread-handlers.js +40 -39
- package/dist/orchestration/status-helpers.js +6 -5
- package/dist/platform/interactive-builder.js +19 -18
- package/dist/store/version-migrations.d.ts +7 -0
- package/dist/store/version-migrations.js +88 -0
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// pos: !schedule subcommand routing and profile pinning
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { Icons } from '../../core/icons.js';
|
|
6
|
+
import { t } from '../../core/i18n.js';
|
|
6
7
|
import { formatDuration, formatTimeUntil, parseDuration } from './scheduler.js';
|
|
7
8
|
import { channelToProjectId } from '../../store/schedule-repo.js';
|
|
8
9
|
import { listProfiles, resolveProfile, getDefaultProfileName } from '../agents/profile-manager.js';
|
|
@@ -13,16 +14,16 @@ function toDest(channel) {
|
|
|
13
14
|
function scheduleHelp() {
|
|
14
15
|
const profileNames = listProfiles().map(p => `\`${p.name}\``).join(', ');
|
|
15
16
|
return [
|
|
16
|
-
'
|
|
17
|
-
'
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
'
|
|
25
|
-
|
|
17
|
+
t('schedule.help.title'),
|
|
18
|
+
t('schedule.help.addInterval'),
|
|
19
|
+
t('schedule.help.addDaily'),
|
|
20
|
+
t('schedule.help.addWeekly'),
|
|
21
|
+
t('schedule.help.addOnce'),
|
|
22
|
+
t('schedule.help.list'),
|
|
23
|
+
t('schedule.help.pause'),
|
|
24
|
+
t('schedule.help.resume'),
|
|
25
|
+
t('schedule.help.remove'),
|
|
26
|
+
t('schedule.help.availableProfiles', { profileNames }),
|
|
26
27
|
].join('\n');
|
|
27
28
|
}
|
|
28
29
|
const DAY_MAP = { sun: 0, mon: 1, tue: 2, wed: 3, thu: 4, fri: 5, sat: 6 };
|
|
@@ -31,12 +32,12 @@ const fmtTime = (ts) => new Date(ts).toLocaleString('en-US', FMT_OPTS);
|
|
|
31
32
|
async function handleList(parts, channel, adapter, scheduler) {
|
|
32
33
|
const tasks = await scheduler.list();
|
|
33
34
|
if (tasks.length === 0) {
|
|
34
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
35
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.list.empty') });
|
|
35
36
|
return;
|
|
36
37
|
}
|
|
37
38
|
const now = Date.now();
|
|
38
|
-
const lines = tasks.map((
|
|
39
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
39
|
+
const lines = tasks.map((task) => formatTaskLine(task, now));
|
|
40
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.list.header', { count: tasks.length, lines: lines.join('\n') }) });
|
|
40
41
|
}
|
|
41
42
|
function formatTaskLine(t, now) {
|
|
42
43
|
const id = `\`${t.id}\``;
|
|
@@ -75,28 +76,28 @@ async function handleRemove(parts, channel, adapter, scheduler) {
|
|
|
75
76
|
const rawId = parts[2];
|
|
76
77
|
const id = normalizeTaskId(rawId);
|
|
77
78
|
if (!id) {
|
|
78
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
79
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.remove.usage') });
|
|
79
80
|
return;
|
|
80
81
|
}
|
|
81
82
|
const removed = await scheduler.remove(id);
|
|
82
83
|
await adapter.postMessage(toDest(channel), {
|
|
83
|
-
text: removed ? `${Icons.ok}
|
|
84
|
+
text: removed ? `${Icons.ok} ${t('schedule.remove.ok', { id })}` : `${Icons.error} ${t('schedule.taskNotFound', { id })}`,
|
|
84
85
|
});
|
|
85
86
|
}
|
|
86
87
|
async function handlePause(parts, channel, adapter, scheduler) {
|
|
87
88
|
const rawId = parts[2];
|
|
88
89
|
const id = normalizeTaskId(rawId);
|
|
89
90
|
if (!id) {
|
|
90
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
91
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.pause.usage') });
|
|
91
92
|
return;
|
|
92
93
|
}
|
|
93
94
|
try {
|
|
94
95
|
const task = await scheduler.pause(id);
|
|
95
96
|
if (!task) {
|
|
96
|
-
await adapter.postMessage(toDest(channel), { text: `${Icons.error}
|
|
97
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${t('schedule.taskNotFound', { id })}` });
|
|
97
98
|
return;
|
|
98
99
|
}
|
|
99
|
-
await adapter.postMessage(toDest(channel), { text: `${Icons.paused}
|
|
100
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.paused} ${t('schedule.pause.ok', { id })}` });
|
|
100
101
|
}
|
|
101
102
|
catch (error) {
|
|
102
103
|
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
@@ -106,17 +107,17 @@ async function handleResume(parts, channel, adapter, scheduler) {
|
|
|
106
107
|
const rawId = parts[2];
|
|
107
108
|
const id = normalizeTaskId(rawId);
|
|
108
109
|
if (!id) {
|
|
109
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
110
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.resume.usage') });
|
|
110
111
|
return;
|
|
111
112
|
}
|
|
112
113
|
try {
|
|
113
114
|
const task = await scheduler.resume(id);
|
|
114
115
|
if (!task) {
|
|
115
|
-
await adapter.postMessage(toDest(channel), { text: `${Icons.error}
|
|
116
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${t('schedule.taskNotFound', { id })}` });
|
|
116
117
|
return;
|
|
117
118
|
}
|
|
118
|
-
const nextAt = task.nextRun ?
|
|
119
|
-
await adapter.postMessage(toDest(channel), { text: `${Icons.resume}
|
|
119
|
+
const nextAt = task.nextRun ? t('schedule.resume.nextRun', { time: fmtTime(task.nextRun) }) : '';
|
|
120
|
+
await adapter.postMessage(toDest(channel), { text: `${Icons.resume} ${t('schedule.resume.ok', { id, nextAt })}` });
|
|
120
121
|
}
|
|
121
122
|
catch (error) {
|
|
122
123
|
await adapter.postMessage(toDest(channel), { text: `${Icons.error} ${error.message}` });
|
|
@@ -131,7 +132,7 @@ function parseProfileArgs(args, usage) {
|
|
|
131
132
|
}
|
|
132
133
|
const profileName = args[1];
|
|
133
134
|
if (!profileName)
|
|
134
|
-
throw new Error(
|
|
135
|
+
throw new Error(t('schedule.profileUsage', { usage }));
|
|
135
136
|
try {
|
|
136
137
|
resolveProfile(profileName);
|
|
137
138
|
}
|
|
@@ -157,17 +158,17 @@ async function handleAddInterval(parts, channel, adapter, scheduler) {
|
|
|
157
158
|
const msg = parsed.rest.join(' ');
|
|
158
159
|
const ms = parseDuration(durationStr);
|
|
159
160
|
if (!ms) {
|
|
160
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
161
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDuration', { duration: durationStr }) });
|
|
161
162
|
return;
|
|
162
163
|
}
|
|
163
164
|
if (!msg) {
|
|
164
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
165
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.intervalUsage') });
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
167
168
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
168
169
|
const task = await scheduler.add('interval', { intervalMs: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
169
170
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
170
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok}
|
|
171
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledInterval', { duration: formatDuration(ms), message: msg })}`, task, nextAt) });
|
|
171
172
|
}
|
|
172
173
|
async function handleAddDaily(parts, channel, adapter, scheduler) {
|
|
173
174
|
const time = parts[3];
|
|
@@ -181,17 +182,17 @@ async function handleAddDaily(parts, channel, adapter, scheduler) {
|
|
|
181
182
|
}
|
|
182
183
|
const msg = parsed.rest.join(' ');
|
|
183
184
|
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
184
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
185
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidTime', { time, example: '09:00' }) });
|
|
185
186
|
return;
|
|
186
187
|
}
|
|
187
188
|
if (!msg) {
|
|
188
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
189
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.dailyUsage') });
|
|
189
190
|
return;
|
|
190
191
|
}
|
|
191
192
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
192
193
|
const task = await scheduler.add('daily', { time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
193
194
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
194
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok}
|
|
195
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledDaily', { time, message: msg })}`, task, nextAt) });
|
|
195
196
|
}
|
|
196
197
|
async function handleAddWeekly(parts, channel, adapter, scheduler) {
|
|
197
198
|
const dayStr = (parts[3] || '').toLowerCase();
|
|
@@ -207,22 +208,22 @@ async function handleAddWeekly(parts, channel, adapter, scheduler) {
|
|
|
207
208
|
const msg = parsed.rest.join(' ');
|
|
208
209
|
const dayOfWeek = DAY_MAP[dayStr];
|
|
209
210
|
if (dayOfWeek == null) {
|
|
210
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
211
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDay', { day: parts[3] }) });
|
|
211
212
|
return;
|
|
212
213
|
}
|
|
213
214
|
if (!/^\d{2}:\d{2}$/.test(time)) {
|
|
214
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
215
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidTime', { time, example: '21:00' }) });
|
|
215
216
|
return;
|
|
216
217
|
}
|
|
217
218
|
if (!msg) {
|
|
218
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
219
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.weeklyUsage') });
|
|
219
220
|
return;
|
|
220
221
|
}
|
|
221
222
|
const dayNames = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
222
223
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
223
224
|
const task = await scheduler.add('weekly', { dayOfWeek, time, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
224
225
|
const nextAt = task.nextRun ? ` | first run: ${fmtTime(task.nextRun)}` : '';
|
|
225
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok}
|
|
226
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledWeekly', { day: dayNames[dayOfWeek], time, message: msg })}`, task, nextAt) });
|
|
226
227
|
}
|
|
227
228
|
async function handleAddOnce(parts, channel, adapter, scheduler) {
|
|
228
229
|
const durationStr = parts[3];
|
|
@@ -237,17 +238,17 @@ async function handleAddOnce(parts, channel, adapter, scheduler) {
|
|
|
237
238
|
const msg = parsed.rest.join(' ');
|
|
238
239
|
const ms = parseDuration(durationStr);
|
|
239
240
|
if (!ms) {
|
|
240
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
241
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.invalidDuration', { duration: durationStr }) });
|
|
241
242
|
return;
|
|
242
243
|
}
|
|
243
244
|
if (!msg) {
|
|
244
|
-
await adapter.postMessage(toDest(channel), { text: '
|
|
245
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.onceUsage') });
|
|
245
246
|
return;
|
|
246
247
|
}
|
|
247
248
|
const resolvedProjectId = channelToProjectId(channel) ?? 'general';
|
|
248
249
|
const task = await scheduler.add('once', { delay: ms, message: msg, projectId: resolvedProjectId, profile: parsed.profileName });
|
|
249
250
|
const runAt = task.runAt ? ` | runs at: ${fmtTime(task.runAt)}` : '';
|
|
250
|
-
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok}
|
|
251
|
+
await adapter.postMessage(toDest(channel), { text: buildScheduledConfirmation(`${Icons.ok} ${t('schedule.add.scheduledOnce', { duration: formatDuration(ms), message: msg })}`, task, runAt) });
|
|
251
252
|
}
|
|
252
253
|
const ADD_TYPE_HANDLERS = {
|
|
253
254
|
interval: handleAddInterval,
|
|
@@ -261,7 +262,7 @@ async function handleAdd(parts, channel, adapter, scheduler) {
|
|
|
261
262
|
if (handler)
|
|
262
263
|
return handler(parts, channel, adapter, scheduler);
|
|
263
264
|
if (type) {
|
|
264
|
-
await adapter.postMessage(toDest(channel), { text:
|
|
265
|
+
await adapter.postMessage(toDest(channel), { text: t('schedule.add.unknownType', { type }) });
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
267
268
|
await adapter.postMessage(toDest(channel), { text: scheduleHelp() });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface ReleaseInfo {
|
|
2
|
+
tagName: string;
|
|
3
|
+
version: string;
|
|
4
|
+
name: string;
|
|
5
|
+
body: string;
|
|
6
|
+
htmlUrl: string;
|
|
7
|
+
publishedAt: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Build GitHub Release web URL for a given version.
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildGitHubReleaseUrl(version: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Fetch release notes from GitHub API for a given version.
|
|
15
|
+
* Returns cached result if available and not expired.
|
|
16
|
+
* Returns null if fetch fails or release doesn't exist.
|
|
17
|
+
*/
|
|
18
|
+
export declare function fetchReleaseNote(version: string): Promise<ReleaseInfo | null>;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
// input: version string (CalVer format), fetch, file I/O
|
|
2
|
+
// output: ReleaseInfo | null, cached release notes
|
|
3
|
+
// pos: GitHub Release API client with local caching
|
|
4
|
+
import * as fs from 'node:fs';
|
|
5
|
+
import * as path from 'node:path';
|
|
6
|
+
import { STORE_DIR } from '../../core/paths.js';
|
|
7
|
+
import { createLogger } from '../../core/log.js';
|
|
8
|
+
const log = createLogger('github-release');
|
|
9
|
+
const GITHUB_API_BASE = 'https://api.github.com';
|
|
10
|
+
const REPO_OWNER = 'fangxm233';
|
|
11
|
+
const REPO_NAME = 'cortex-agent';
|
|
12
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000; // 24 hours
|
|
13
|
+
const CACHE_FILE = path.join(STORE_DIR, 'release-cache.json');
|
|
14
|
+
/**
|
|
15
|
+
* Load cache from disk, or return empty structure if missing/invalid.
|
|
16
|
+
*/
|
|
17
|
+
function loadCache() {
|
|
18
|
+
if (!fs.existsSync(CACHE_FILE)) {
|
|
19
|
+
return { releases: {} };
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
const data = fs.readFileSync(CACHE_FILE, 'utf8');
|
|
23
|
+
return JSON.parse(data);
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
log.warn(`Failed to load release cache: ${e.message}`);
|
|
27
|
+
return { releases: {} };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Save cache to disk.
|
|
32
|
+
*/
|
|
33
|
+
function saveCache(cache) {
|
|
34
|
+
try {
|
|
35
|
+
fs.writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
log.warn(`Failed to save release cache: ${e.message}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build GitHub Release API URL for a given version.
|
|
43
|
+
* GitHub tag format: server-v{version}
|
|
44
|
+
*/
|
|
45
|
+
function buildGitHubApiUrl(version) {
|
|
46
|
+
const tagName = `server-v${version}`;
|
|
47
|
+
return `${GITHUB_API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/releases/tags/${tagName}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Build GitHub Release web URL for a given version.
|
|
51
|
+
*/
|
|
52
|
+
export function buildGitHubReleaseUrl(version) {
|
|
53
|
+
const tagName = `server-v${version}`;
|
|
54
|
+
return `https://github.com/${REPO_OWNER}/${REPO_NAME}/releases/tag/${tagName}`;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Fetch release notes from GitHub API for a given version.
|
|
58
|
+
* Returns cached result if available and not expired.
|
|
59
|
+
* Returns null if fetch fails or release doesn't exist.
|
|
60
|
+
*/
|
|
61
|
+
export async function fetchReleaseNote(version) {
|
|
62
|
+
const cache = loadCache();
|
|
63
|
+
const cached = cache.releases[version];
|
|
64
|
+
// Check if cache is valid (not expired)
|
|
65
|
+
if (cached) {
|
|
66
|
+
const age = Date.now() - cached.fetchedAt;
|
|
67
|
+
if (age < CACHE_TTL_MS) {
|
|
68
|
+
log.debug(`Using cached release note for ${version}`);
|
|
69
|
+
return cached.info;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
// Fetch from GitHub API
|
|
73
|
+
const url = buildGitHubApiUrl(version);
|
|
74
|
+
try {
|
|
75
|
+
const response = await fetch(url);
|
|
76
|
+
if (!response.ok) {
|
|
77
|
+
if (response.status === 404) {
|
|
78
|
+
log.warn(`Release not found for version ${version}`);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
log.warn(`GitHub API error: ${response.status} ${response.statusText}`);
|
|
82
|
+
}
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
const data = (await response.json());
|
|
86
|
+
const releaseInfo = {
|
|
87
|
+
tagName: data.tag_name,
|
|
88
|
+
version,
|
|
89
|
+
name: data.name || `Release ${version}`,
|
|
90
|
+
body: data.body || '',
|
|
91
|
+
htmlUrl: data.html_url,
|
|
92
|
+
publishedAt: data.published_at,
|
|
93
|
+
};
|
|
94
|
+
// Update cache
|
|
95
|
+
cache.releases[version] = {
|
|
96
|
+
info: releaseInfo,
|
|
97
|
+
fetchedAt: Date.now(),
|
|
98
|
+
};
|
|
99
|
+
saveCache(cache);
|
|
100
|
+
return releaseInfo;
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
log.error(`Failed to fetch release note for ${version}: ${error.message}`);
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type Locale } from '../../core/i18n.js';
|
|
2
|
+
/** Operator display preferences. Extensible — language today, room for date/number formats etc. */
|
|
3
|
+
export interface Preferences {
|
|
4
|
+
lang?: Locale;
|
|
5
|
+
}
|
|
6
|
+
export declare function loadPreferences(): Preferences;
|
|
7
|
+
/** Resolve the persisted UI language, defaulting to 'en'. */
|
|
8
|
+
export declare function loadLang(): Locale;
|
|
9
|
+
/** Persist the UI language, preserving any other preference keys already on disk. */
|
|
10
|
+
export declare function setLang(loc: Locale): void;
|
|
11
|
+
/** Test-only: redirect the preferences file to an isolated temp location. */
|
|
12
|
+
export declare function _testSetPreferencesFile(p: string): void;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// input: CONFIG_DIR constant, core/i18n normalizeLocale
|
|
2
|
+
// output: loadPreferences / loadLang / setLang for config/preferences.json
|
|
3
|
+
// pos: operator-level display preferences (language, future UI prefs). Set-once + runtime
|
|
4
|
+
// switchable via !lang. Separate from mode.json (LLM execution state) by design.
|
|
5
|
+
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
6
|
+
import * as fs from 'fs';
|
|
7
|
+
import * as path from 'path';
|
|
8
|
+
import { CONFIG_DIR } from '../../core/utils.js';
|
|
9
|
+
import { normalizeLocale } from '../../core/i18n.js';
|
|
10
|
+
// Mutable for test isolation — tests redirect this via _testSetPreferencesFile.
|
|
11
|
+
let prefsFilePath = path.join(CONFIG_DIR, 'preferences.json');
|
|
12
|
+
export function loadPreferences() {
|
|
13
|
+
try {
|
|
14
|
+
const parsed = JSON.parse(fs.readFileSync(prefsFilePath, 'utf8'));
|
|
15
|
+
return parsed && typeof parsed === 'object' ? parsed : {};
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** Resolve the persisted UI language, defaulting to 'en'. */
|
|
22
|
+
export function loadLang() {
|
|
23
|
+
return normalizeLocale(loadPreferences().lang);
|
|
24
|
+
}
|
|
25
|
+
/** Persist the UI language, preserving any other preference keys already on disk. */
|
|
26
|
+
export function setLang(loc) {
|
|
27
|
+
const normalized = normalizeLocale(loc);
|
|
28
|
+
const current = loadPreferences();
|
|
29
|
+
const next = { ...current, lang: normalized };
|
|
30
|
+
fs.mkdirSync(path.dirname(prefsFilePath), { recursive: true });
|
|
31
|
+
fs.writeFileSync(prefsFilePath, JSON.stringify(next, null, 2) + '\n');
|
|
32
|
+
}
|
|
33
|
+
/** Test-only: redirect the preferences file to an isolated temp location. */
|
|
34
|
+
export function _testSetPreferencesFile(p) {
|
|
35
|
+
prefsFilePath = p;
|
|
36
|
+
}
|
|
@@ -31,18 +31,27 @@ interface DispatchOutcome {
|
|
|
31
31
|
interface FilterDeps {
|
|
32
32
|
findActiveDispatchMatch?: (task: any, scheduleTaskId: string) => DispatchMatch | null;
|
|
33
33
|
checkRealGpuOccupancy?: (machine: string) => Promise<GpuOccupancyResult>;
|
|
34
|
+
isTemplateRateLimited?: (templateName: string, dispatchProfile: string | null) => boolean;
|
|
35
|
+
/** Scheduler-resolved dispatch profile — used only to resolve `__active__` template slots. */
|
|
36
|
+
profileName?: string | null;
|
|
34
37
|
}
|
|
35
38
|
declare function isValidDispatchPrompt(value: unknown): boolean;
|
|
36
39
|
declare function filterLockedProjects(tasks: any[]): any[];
|
|
37
40
|
declare function checkRealGpuOccupancy(machine: string): Promise<GpuOccupancyResult>;
|
|
38
41
|
declare function selectTask(tasks: any[] | null): any | null;
|
|
39
42
|
declare function findActiveDispatchMatch(task: any, scheduleTaskId: string): DispatchMatch | null;
|
|
43
|
+
/** True when the task's template cannot run: ANY of its agents' profiles is fully
|
|
44
|
+
* rate-limited (a known-blocked later agent would fail the thread mid-pipeline and
|
|
45
|
+
* unclaim the task, discarding earlier agents' work). Empty resolution (unknown
|
|
46
|
+
* template / no concrete profiles) falls back to checking the dispatch profile. */
|
|
47
|
+
declare function isTemplateRateLimited(templateName: string, dispatchProfile: string | null, check?: (profile: string | null) => boolean): boolean;
|
|
40
48
|
declare function filterDispatchableTasks(tasks: any[] | null, scheduleTaskId: string, gpuBusyCounts?: Map<string, number>, deps?: FilterDeps): Promise<any[]>;
|
|
41
49
|
declare function computeNextInterval(outcome: DispatchOutcome): number;
|
|
42
50
|
declare function hasRunningExecutionForSchedule(records: Pick<ExecutionRecord, 'status' | 'kind' | 'scheduleTaskId'>[], scheduleTaskId: string): boolean;
|
|
43
51
|
declare function updateScheduleInterval(scheduler: any, scheduleTaskId: string, newIntervalMs: number): Promise<void>;
|
|
44
|
-
declare function selectAndClaimTask({ scheduleTaskId, dryRun }: {
|
|
52
|
+
declare function selectAndClaimTask({ scheduleTaskId, dryRun, profileName }: {
|
|
45
53
|
scheduleTaskId: string;
|
|
46
54
|
dryRun?: boolean;
|
|
55
|
+
profileName?: string | null;
|
|
47
56
|
}): Promise<SelectAndClaimResult | null>;
|
|
48
|
-
export { selectAndClaimTask, hasRunningExecutionForSchedule, computeNextInterval, updateScheduleInterval, isValidDispatchPrompt, selectTask, filterLockedProjects, filterDispatchableTasks, findActiveDispatchMatch, checkRealGpuOccupancy, };
|
|
57
|
+
export { selectAndClaimTask, hasRunningExecutionForSchedule, computeNextInterval, updateScheduleInterval, isValidDispatchPrompt, isTemplateRateLimited, selectTask, filterLockedProjects, filterDispatchableTasks, findActiveDispatchMatch, checkRealGpuOccupancy, };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// input: task-store, client-manager, execution-registry
|
|
2
|
-
// output: selectAndClaimTask + schedule/interval helpers
|
|
3
|
-
// pos: programmatic dispatch for task selection and claiming
|
|
1
|
+
// input: task-store, client-manager, execution-registry, threads (template profiles), agents facade (rate limits)
|
|
2
|
+
// output: selectAndClaimTask + isTemplateRateLimited + schedule/interval helpers
|
|
3
|
+
// pos: programmatic dispatch for task selection and claiming; rate-limit eligibility is per-task, resolved from each task's template profiles
|
|
4
4
|
// >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
|
|
5
5
|
import { createLogger } from '../../core/log.js';
|
|
6
6
|
import { isProjectLocked } from './system/task-lock.js';
|
|
@@ -13,6 +13,8 @@ import * as executionRegistry from '../executions/registry.js';
|
|
|
13
13
|
import { taskStore } from './store.js';
|
|
14
14
|
import { taskMutator } from './mutator.js';
|
|
15
15
|
import { listTemplateNames } from '../threads/template-loader.js';
|
|
16
|
+
import { resolveTemplateProfiles } from '../threads/index.js';
|
|
17
|
+
import { allConfigsRateLimited } from '../agents/facade.js';
|
|
16
18
|
// --- Null/empty prompt guard (ISS-CS-005 durable fix) ---
|
|
17
19
|
function isValidDispatchPrompt(value) {
|
|
18
20
|
if (!value || typeof value === 'object')
|
|
@@ -112,6 +114,22 @@ function findActiveDispatchMatch(task, scheduleTaskId) {
|
|
|
112
114
|
}
|
|
113
115
|
return null;
|
|
114
116
|
}
|
|
117
|
+
// --- Template-profile rate-limit eligibility ---
|
|
118
|
+
// A task's thread runs with its TEMPLATE's agent profiles (hardcoded profiles win;
|
|
119
|
+
// metadata.profileOverride only applies to __active__ slots — see threads/runner.ts).
|
|
120
|
+
// Gating on the scheduler-resolved dispatch profile was wrong in both directions:
|
|
121
|
+
// it over-blocked templates whose profiles were fine and under-blocked templates
|
|
122
|
+
// whose profiles were limited.
|
|
123
|
+
/** True when the task's template cannot run: ANY of its agents' profiles is fully
|
|
124
|
+
* rate-limited (a known-blocked later agent would fail the thread mid-pipeline and
|
|
125
|
+
* unclaim the task, discarding earlier agents' work). Empty resolution (unknown
|
|
126
|
+
* template / no concrete profiles) falls back to checking the dispatch profile. */
|
|
127
|
+
function isTemplateRateLimited(templateName, dispatchProfile, check = allConfigsRateLimited) {
|
|
128
|
+
const profiles = resolveTemplateProfiles(templateName, dispatchProfile);
|
|
129
|
+
if (profiles.length === 0)
|
|
130
|
+
return check(dispatchProfile);
|
|
131
|
+
return profiles.some((p) => check(p));
|
|
132
|
+
}
|
|
115
133
|
// --- Unknown-template warning dedup (per-process, per-(task_hash, template) pair) ---
|
|
116
134
|
const _unknownTemplateWarnedKeys = new Set();
|
|
117
135
|
function warnOnceUnknownTemplate(task) {
|
|
@@ -127,11 +145,14 @@ async function filterDispatchableTasks(tasks, scheduleTaskId, gpuBusyCounts = ne
|
|
|
127
145
|
return [];
|
|
128
146
|
const findDuplicate = deps.findActiveDispatchMatch || findActiveDispatchMatch;
|
|
129
147
|
const checkGpu = deps.checkRealGpuOccupancy || checkRealGpuOccupancy;
|
|
148
|
+
const checkTemplateRateLimited = deps.isTemplateRateLimited || isTemplateRateLimited;
|
|
149
|
+
const dispatchProfile = deps.profileName ?? null;
|
|
130
150
|
const gpuStatusCache = new Map();
|
|
131
151
|
// Fail-open if templates haven't been loaded yet (size === 0): let downstream
|
|
132
152
|
// createThread surface the error rather than silently dropping every task.
|
|
133
153
|
const validTemplates = new Set(listTemplateNames());
|
|
134
154
|
const eligible = [];
|
|
155
|
+
let rateLimitedCount = 0;
|
|
135
156
|
for (const task of tasks) {
|
|
136
157
|
if (!task.template) {
|
|
137
158
|
continue;
|
|
@@ -140,6 +161,12 @@ async function filterDispatchableTasks(tasks, scheduleTaskId, gpuBusyCounts = ne
|
|
|
140
161
|
warnOnceUnknownTemplate(task);
|
|
141
162
|
continue;
|
|
142
163
|
}
|
|
164
|
+
// Skip tasks whose template profiles are rate-limited; later tasks with
|
|
165
|
+
// usable templates still flow through (per-task gating, not whole-cycle).
|
|
166
|
+
if (checkTemplateRateLimited(task.template, dispatchProfile)) {
|
|
167
|
+
rateLimitedCount += 1;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
143
170
|
// Check remote GPU device is online (local machine is always reachable)
|
|
144
171
|
if (task.gpu && task.gpu !== getLocalMachine() && !isDeviceOnline(task.gpu)) {
|
|
145
172
|
continue;
|
|
@@ -173,6 +200,9 @@ async function filterDispatchableTasks(tasks, scheduleTaskId, gpuBusyCounts = ne
|
|
|
173
200
|
}
|
|
174
201
|
eligible.push(task);
|
|
175
202
|
}
|
|
203
|
+
if (rateLimitedCount > 0) {
|
|
204
|
+
log.info(`Skipped ${rateLimitedCount} task(s) — template profiles rate-limited`);
|
|
205
|
+
}
|
|
176
206
|
return eligible;
|
|
177
207
|
}
|
|
178
208
|
// --- Interval computation ---
|
|
@@ -259,15 +289,15 @@ function buildDispatchPrompt(task) {
|
|
|
259
289
|
return sections.join('\n\n');
|
|
260
290
|
}
|
|
261
291
|
// --- Main entry point: select and claim a task for local execution ---
|
|
262
|
-
async function selectAndClaimTask({ scheduleTaskId, dryRun = false }) {
|
|
292
|
+
async function selectAndClaimTask({ scheduleTaskId, dryRun = false, profileName = null }) {
|
|
263
293
|
log.info('Starting task selection cycle');
|
|
264
294
|
// Get actionable tasks + GPU busy machines
|
|
265
295
|
let tasks = taskStore.getActionable();
|
|
266
296
|
tasks = filterLockedProjects(tasks);
|
|
267
297
|
const gpuBusyMachines = taskStore.getGpuBusyMachines();
|
|
268
298
|
log.info(`Found ${tasks.length} actionable task(s)`);
|
|
269
|
-
// Filter to dispatchable tasks
|
|
270
|
-
const dispatchableTasks = await filterDispatchableTasks(tasks, scheduleTaskId, gpuBusyMachines);
|
|
299
|
+
// Filter to dispatchable tasks (incl. per-template rate-limit eligibility)
|
|
300
|
+
const dispatchableTasks = await filterDispatchableTasks(tasks, scheduleTaskId, gpuBusyMachines, { profileName });
|
|
271
301
|
log.info(`${dispatchableTasks.length} task(s) dispatchable after preflight`);
|
|
272
302
|
// Select task
|
|
273
303
|
const selectedTask = selectTask(dispatchableTasks);
|
|
@@ -306,6 +336,6 @@ async function selectAndClaimTask({ scheduleTaskId, dryRun = false }) {
|
|
|
306
336
|
template: selectedTask.template || null,
|
|
307
337
|
};
|
|
308
338
|
}
|
|
309
|
-
export { selectAndClaimTask, hasRunningExecutionForSchedule, computeNextInterval, updateScheduleInterval, isValidDispatchPrompt,
|
|
339
|
+
export { selectAndClaimTask, hasRunningExecutionForSchedule, computeNextInterval, updateScheduleInterval, isValidDispatchPrompt, isTemplateRateLimited,
|
|
310
340
|
// For testing
|
|
311
341
|
selectTask, filterLockedProjects, filterDispatchableTasks, findActiveDispatchMatch, checkRealGpuOccupancy, };
|
|
@@ -11,6 +11,12 @@ export declare function resolveAgentSlotConfig(ref: TemplateAgentRef): AgentSlot
|
|
|
11
11
|
export declare function resolveAgentSlotConfigByName(agentName: string): AgentSlotConfig | null;
|
|
12
12
|
/** Resolve all agent refs in a template to AgentSlotConfigs */
|
|
13
13
|
export declare function resolveTemplateAgents(template: ThreadTemplate): AgentSlotConfig[];
|
|
14
|
+
/** Resolve the unique profile names a template's agents will actually run with.
|
|
15
|
+
* Mirrors thread-runner profile resolution (runner.ts): hardcoded agent profiles win;
|
|
16
|
+
* `__active__` slots resolve to `activeProfile` (the dispatch/scheduler profile that
|
|
17
|
+
* would be injected via metadata.profileOverride). Null/empty entries are dropped.
|
|
18
|
+
* Unknown template or no resolvable agents → [] (fail-open; callers decide fallback). */
|
|
19
|
+
export declare function resolveTemplateProfiles(templateName: string, activeProfile: string | null): string[];
|
|
14
20
|
/** Render an `(agent, stage)` pair as the canonical endpoint string used for iterationCounts keys
|
|
15
21
|
* and transition-rule matching. Stages that are null render as bare agent names. */
|
|
16
22
|
export declare function formatEndpoint(agent: string, stage: string | null): string;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// Prompt assembly and agent slot config resolution.
|
|
2
2
|
// input: template-loader, artifact-io, thread-store, thread-types
|
|
3
|
-
// output: buildStepPrompt / resolveSystemVars / resolveAgentSlotConfig / resolveTemplateAgents / formatEndpoint / pickStepTemplate
|
|
3
|
+
// output: buildStepPrompt / resolveSystemVars / resolveAgentSlotConfig / resolveTemplateAgents / resolveTemplateProfiles / formatEndpoint / pickStepTemplate
|
|
4
4
|
import { threadStore } from '../../store/thread-repo.js';
|
|
5
|
-
import { getAgent, resolveFileRef } from './template-loader.js';
|
|
5
|
+
import { getAgent, getTemplate, resolveFileRef } from './template-loader.js';
|
|
6
6
|
import { getModifiedFilesFromSession, getSessionFileChanges, renderModifiedFilesWithDiff } from './artifact-io.js';
|
|
7
7
|
import { getDefaultAgent } from '../agents/index.js';
|
|
8
8
|
import { loadUserContext } from '../memory/user-context.js';
|
|
@@ -89,6 +89,23 @@ export function resolveTemplateAgents(template) {
|
|
|
89
89
|
}
|
|
90
90
|
return configs;
|
|
91
91
|
}
|
|
92
|
+
/** Resolve the unique profile names a template's agents will actually run with.
|
|
93
|
+
* Mirrors thread-runner profile resolution (runner.ts): hardcoded agent profiles win;
|
|
94
|
+
* `__active__` slots resolve to `activeProfile` (the dispatch/scheduler profile that
|
|
95
|
+
* would be injected via metadata.profileOverride). Null/empty entries are dropped.
|
|
96
|
+
* Unknown template or no resolvable agents → [] (fail-open; callers decide fallback). */
|
|
97
|
+
export function resolveTemplateProfiles(templateName, activeProfile) {
|
|
98
|
+
const template = getTemplate(templateName);
|
|
99
|
+
if (!template)
|
|
100
|
+
return [];
|
|
101
|
+
const profiles = new Set();
|
|
102
|
+
for (const config of resolveTemplateAgents(template)) {
|
|
103
|
+
const profile = config.profile === '__active__' ? activeProfile : config.profile;
|
|
104
|
+
if (profile)
|
|
105
|
+
profiles.add(profile);
|
|
106
|
+
}
|
|
107
|
+
return [...profiles];
|
|
108
|
+
}
|
|
92
109
|
/** Render an `(agent, stage)` pair as the canonical endpoint string used for iterationCounts keys
|
|
93
110
|
* and transition-rule matching. Stages that are null render as bare agent names. */
|
|
94
111
|
export function formatEndpoint(agent, stage) {
|