@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.
Files changed (70) hide show
  1. package/dist/core/gateway-generator.js +24 -3
  2. package/dist/core/i18n.d.ts +19 -0
  3. package/dist/core/i18n.js +46 -0
  4. package/dist/core/locales/en.d.ts +438 -0
  5. package/dist/core/locales/en.js +24 -0
  6. package/dist/core/locales/slices/commands.d.ts +214 -0
  7. package/dist/core/locales/slices/commands.js +462 -0
  8. package/dist/core/locales/slices/init.d.ts +121 -0
  9. package/dist/core/locales/slices/init.js +380 -0
  10. package/dist/core/locales/slices/interactions.d.ts +47 -0
  11. package/dist/core/locales/slices/interactions.js +102 -0
  12. package/dist/core/locales/slices/lang.d.ts +8 -0
  13. package/dist/core/locales/slices/lang.js +18 -0
  14. package/dist/core/locales/slices/scheduling.d.ts +36 -0
  15. package/dist/core/locales/slices/scheduling.js +74 -0
  16. package/dist/core/locales/slices/startup.d.ts +6 -0
  17. package/dist/core/locales/slices/startup.js +14 -0
  18. package/dist/core/locales/slices/status.d.ts +20 -0
  19. package/dist/core/locales/slices/status.js +48 -0
  20. package/dist/core/locales/zh.d.ts +5 -0
  21. package/dist/core/locales/zh.js +23 -0
  22. package/dist/core/singleton-lock.d.ts +23 -0
  23. package/dist/core/singleton-lock.js +53 -0
  24. package/dist/core/status-format.js +2 -1
  25. package/dist/core/utils.d.ts +9 -1
  26. package/dist/core/utils.js +9 -1
  27. package/dist/domain/agents/config.d.ts +2 -1
  28. package/dist/domain/agents/config.js +25 -6
  29. package/dist/domain/scheduling/jobs/task-dispatch.js +6 -10
  30. package/dist/domain/scheduling/schedule-command.js +38 -37
  31. package/dist/domain/system/github-release.d.ts +18 -0
  32. package/dist/domain/system/github-release.js +106 -0
  33. package/dist/domain/system/preferences.d.ts +12 -0
  34. package/dist/domain/system/preferences.js +36 -0
  35. package/dist/domain/tasks/dispatcher.d.ts +11 -2
  36. package/dist/domain/tasks/dispatcher.js +37 -7
  37. package/dist/domain/threads/prompt-builder.d.ts +6 -0
  38. package/dist/domain/threads/prompt-builder.js +19 -2
  39. package/dist/entry/app.js +36 -3
  40. package/dist/entry/daemon.js +12 -30
  41. package/dist/entry/init.d.ts +4 -3
  42. package/dist/entry/init.js +151 -208
  43. package/dist/entry/startup-notify.js +6 -3
  44. package/dist/orchestration/interactions/interaction-handlers.js +12 -11
  45. package/dist/orchestration/interactions/update-prompt-slack.js +11 -10
  46. package/dist/orchestration/interactions/update-prompt.js +66 -11
  47. package/dist/orchestration/lifecycle.js +13 -12
  48. package/dist/orchestration/routing/commands/cancel.js +10 -9
  49. package/dist/orchestration/routing/commands/channel.js +27 -26
  50. package/dist/orchestration/routing/commands/cost.js +10 -2
  51. package/dist/orchestration/routing/commands/device.js +11 -9
  52. package/dist/orchestration/routing/commands/dispatch.js +10 -10
  53. package/dist/orchestration/routing/commands/index.js +6 -2
  54. package/dist/orchestration/routing/commands/lang.d.ts +3 -0
  55. package/dist/orchestration/routing/commands/lang.js +31 -0
  56. package/dist/orchestration/routing/commands/mode.js +28 -27
  57. package/dist/orchestration/routing/commands/nvtop.js +13 -12
  58. package/dist/orchestration/routing/commands/orient.js +2 -1
  59. package/dist/orchestration/routing/commands/schedule.js +23 -22
  60. package/dist/orchestration/routing/commands/sendfile.js +8 -7
  61. package/dist/orchestration/routing/commands/session.js +11 -10
  62. package/dist/orchestration/routing/commands/status.js +78 -71
  63. package/dist/orchestration/routing/commands/tail.js +6 -5
  64. package/dist/orchestration/routing/commands/task.js +23 -22
  65. package/dist/orchestration/routing/commands/thread-handlers.js +40 -39
  66. package/dist/orchestration/status-helpers.js +6 -5
  67. package/dist/platform/interactive-builder.js +19 -18
  68. package/dist/store/version-migrations.d.ts +7 -0
  69. package/dist/store/version-migrations.js +88 -0
  70. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { projectStore } from '../../../domain/projects/index.js';
2
2
  import { projectDirRepo } from '../../../store/project-dir-repo.js';
3
3
  import { Icons } from '../../../core/icons.js';
4
+ import { t } from '../../../core/i18n.js';
4
5
  import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
5
6
  /**
6
7
  * Render a (possibly platform-prefixed) conduit for display.
@@ -18,7 +19,7 @@ export async function handleProjectsCmd(channel, adapter) {
18
19
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
19
20
  const projects = projectStore.list().map(p => p.id);
20
21
  if (projects.length === 0) {
21
- await adapter.postMessage(dest, { text: 'No projects found.' });
22
+ await adapter.postMessage(dest, { text: t('cmd.channel.noProjects') });
22
23
  return;
23
24
  }
24
25
  const registrations = await adapter.getProjectConduits();
@@ -27,7 +28,7 @@ export async function handleProjectsCmd(channel, adapter) {
27
28
  const status = ch ? ` → ${displayConduit(ch)}` : '';
28
29
  return `• \`${p}\`${status}`;
29
30
  });
30
- await adapter.postMessage(dest, { text: `*Projects*\n${lines.join('\n')}` });
31
+ await adapter.postMessage(dest, { text: t('cmd.channel.projectsHeader', { list: lines.join('\n') }) });
31
32
  }
32
33
  const MAX_PROJECT_BUTTONS = 10;
33
34
  export function createRegisterHandler(router) {
@@ -41,7 +42,7 @@ export function createRegisterHandler(router) {
41
42
  await adapter.bindProjectConduit(project, ctx.channelId);
42
43
  if (ctx.messageRef) {
43
44
  await adapter.updateMessage(ctx.messageRef, {
44
- text: `${Icons.ok} Registered for \`${project}\` task notifications.`,
45
+ text: `${Icons.ok} ${t('cmd.channel.registeredNotification', { project })}`,
45
46
  }).catch(() => { });
46
47
  }
47
48
  }
@@ -61,11 +62,11 @@ export function createRegisterHandler(router) {
61
62
  const project = args[0];
62
63
  const projects = projectStore.list().map(p => p.id);
63
64
  if (!projects.includes(project)) {
64
- await adapter.postMessage(dest, { text: `${Icons.error} Unknown project: \`${project}\`\nAvailable: ${projects.map(p => `\`${p}\``).join(', ')}` });
65
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.unknownProject', { project, available: projects.map(p => `\`${p}\``).join(', ') })}` });
65
66
  return;
66
67
  }
67
68
  await adapter.bindProjectConduit(project, channel);
68
- await adapter.postMessage(dest, { text: `${Icons.ok} This channel is now registered for project \`${project}\` task notifications.` });
69
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.channelRegistered', { project })}` });
69
70
  return;
70
71
  }
71
72
  const registrations = await adapter.getProjectConduits();
@@ -74,13 +75,13 @@ export function createRegisterHandler(router) {
74
75
  const unbound = projects.filter(p => !bound.includes(p));
75
76
  const lines = [];
76
77
  if (bound.length > 0) {
77
- lines.push(`Registered: ${bound.map(p => `\`${p}\``).join(', ')}`);
78
+ lines.push(t('cmd.channel.registeredList', { list: bound.map(p => `\`${p}\``).join(', ') }));
78
79
  }
79
80
  else {
80
- lines.push('This channel is not registered to any project.');
81
+ lines.push(t('cmd.channel.notRegisteredAny'));
81
82
  }
82
83
  if (unbound.length > 0) {
83
- lines.push(`Available: ${unbound.map(p => `\`${p}\``).join(', ')}`);
84
+ lines.push(t('cmd.channel.availableList', { list: unbound.map(p => `\`${p}\``).join(', ') }));
84
85
  }
85
86
  const text = lines.join('\n');
86
87
  if (!router || unbound.length === 0) {
@@ -109,33 +110,33 @@ export async function handleUnregisterCmd(channel, adapter, trimmedMessage) {
109
110
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
110
111
  const args = trimmedMessage.split(/\s+/).slice(1);
111
112
  if (args.length === 0) {
112
- await adapter.postMessage(dest, { text: 'Usage: `!unregister <project>`' });
113
+ await adapter.postMessage(dest, { text: t('cmd.channel.unregisterUsage') });
113
114
  return;
114
115
  }
115
116
  const project = args[0];
116
117
  const registrations = await adapter.getProjectConduits();
117
118
  const current = registrations[project] ?? null;
118
119
  if (!current || current !== channel) {
119
- await adapter.postMessage(dest, { text: `${Icons.error} This channel is not registered for project \`${project}\`.` });
120
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.notRegistered', { project })}` });
120
121
  return;
121
122
  }
122
123
  await adapter.unbindProjectConduit(project);
123
- await adapter.postMessage(dest, { text: `${Icons.ok} Unregistered this channel from project \`${project}\`.` });
124
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.unregistered', { project })}` });
124
125
  }
125
126
  function buildProjectDirModal(channel) {
126
127
  const machines = Object.keys(getMachineRegistry());
127
128
  return {
128
129
  callbackId: 'cmd_project_dir_add',
129
- title: 'Add Project Directory',
130
- submitLabel: 'Save',
130
+ title: t('cmd.channel.modalTitle'),
131
+ submitLabel: t('cmd.channel.modalSubmit'),
131
132
  privateMetadata: JSON.stringify({ channel }),
132
133
  fields: [
133
- { type: 'text_input', blockId: 'pd_project', label: 'Project name', actionId: 'text', placeholder: 'e.g. example-project-dataset' },
134
+ { type: 'text_input', blockId: 'pd_project', label: t('cmd.channel.modalProjectLabel'), actionId: 'text', placeholder: t('cmd.channel.modalProjectPlaceholder') },
134
135
  {
135
- type: 'select', blockId: 'pd_machine', label: 'Machine', actionId: 'selection',
136
+ type: 'select', blockId: 'pd_machine', label: t('cmd.channel.modalMachineLabel'), actionId: 'selection',
136
137
  options: machines.map(m => ({ label: m, value: m })),
137
138
  },
138
- { type: 'text_input', blockId: 'pd_path', label: 'Directory path', actionId: 'text', placeholder: 'e.g. /home/user/project' },
139
+ { type: 'text_input', blockId: 'pd_path', label: t('cmd.channel.modalPathLabel'), actionId: 'text', placeholder: t('cmd.channel.modalPathPlaceholder') },
139
140
  ],
140
141
  };
141
142
  }
@@ -167,7 +168,7 @@ export function createProjectDirHandler(router) {
167
168
  return;
168
169
  await projectDirRepo.setProjectDir(project, machine, dirPath);
169
170
  await adapter.postMessage(modalDest, {
170
- text: `${Icons.ok} \`${project}\` on \`${machine}\` → \`${dirPath}\``,
171
+ text: `${Icons.ok} ${t('cmd.channel.dirSet', { project, machine, dir: dirPath })}`,
171
172
  });
172
173
  },
173
174
  }],
@@ -178,42 +179,42 @@ export function createProjectDirHandler(router) {
178
179
  const args = trimmedMessage.split(/\s+/).slice(1);
179
180
  if (args.length > 0) {
180
181
  if (args.length < 2) {
181
- await adapter.postMessage(dest, { text: `${Icons.error} Usage: \`!project-dir <project> <machine> <path>\` or \`!project-dir <project> <machine> --remove\`` });
182
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.projectDirUsage')}` });
182
183
  return;
183
184
  }
184
185
  const [project, machine] = args;
185
186
  const validMachines = Object.keys(getMachineRegistry());
186
187
  if (!validMachines.includes(machine)) {
187
- await adapter.postMessage(dest, { text: `${Icons.error} Unknown machine: \`${machine}\`\nValid: ${validMachines.map(m => `\`${m}\``).join(', ')}` });
188
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.channel.unknownMachine', { machine, valid: validMachines.map(m => `\`${m}\``).join(', ') })}` });
188
189
  return;
189
190
  }
190
191
  if (args.length === 2 || args[2] === '--remove') {
191
192
  if (args[2] === '--remove') {
192
193
  await projectDirRepo.removeProjectDir(project, machine);
193
- await adapter.postMessage(dest, { text: `${Icons.ok} Removed \`${project}\` directory on \`${machine}\`.` });
194
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.dirRemoved', { project, machine })}` });
194
195
  }
195
196
  else {
196
197
  const dir = await projectDirRepo.getProjectDir(project, machine);
197
198
  if (dir) {
198
- await adapter.postMessage(dest, { text: `\`${project}\` on \`${machine}\` → \`${dir}\`` });
199
+ await adapter.postMessage(dest, { text: t('cmd.channel.dirShow', { project, machine, dir }) });
199
200
  }
200
201
  else {
201
- await adapter.postMessage(dest, { text: `No directory registered for \`${project}\` on \`${machine}\`.` });
202
+ await adapter.postMessage(dest, { text: t('cmd.channel.dirNone', { project, machine }) });
202
203
  }
203
204
  }
204
205
  return;
205
206
  }
206
207
  const dirPath = args.slice(2).join(' ');
207
208
  await projectDirRepo.setProjectDir(project, machine, dirPath);
208
- await adapter.postMessage(dest, { text: `${Icons.ok} \`${project}\` on \`${machine}\` → \`${dirPath}\`` });
209
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.channel.dirSet', { project, machine, dir: dirPath })}` });
209
210
  return;
210
211
  }
211
212
  const allDirs = await projectDirRepo.getAllProjectDirs();
212
213
  const entries = Object.entries(allDirs);
213
214
  const lines = entries.length > 0
214
215
  ? entries.flatMap(([project, machines]) => Object.entries(machines).map(([machine, dir]) => `• \`${project}\` on \`${machine}\` → \`${dir}\``))
215
- : ['No project directories registered.'];
216
- const text = `*Project Directories*\n${lines.join('\n')}`;
216
+ : [t('cmd.channel.noProjectDirs')];
217
+ const text = t('cmd.channel.projectDirsHeader', { list: lines.join('\n') });
217
218
  if (!router) {
218
219
  await adapter.postMessage(dest, { text });
219
220
  return;
@@ -223,7 +224,7 @@ export function createProjectDirHandler(router) {
223
224
  richBlocks: [{ type: 'section', text }],
224
225
  actions: [{
225
226
  type: 'button',
226
- text: 'Add',
227
+ text: t('cmd.channel.addButton'),
227
228
  actionId: 'cmd:project-dir:open-add',
228
229
  value: 'add',
229
230
  style: 'primary',
@@ -1,5 +1,6 @@
1
1
  import { formatCostReport, checkBudget, setBudget } from '../../../domain/costs/cost-tracker.js';
2
2
  import { Icons } from '../../../core/icons.js';
3
+ import { t } from '../../../core/i18n.js';
3
4
  export async function handleCostCmd(channel, adapter, trimmedMessage) {
4
5
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
5
6
  const project = trimmedMessage.split(/\s+/).slice(1).join(' ').trim() || null;
@@ -11,7 +12,14 @@ export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
11
12
  if (args.length === 0) {
12
13
  const b = await checkBudget();
13
14
  await adapter.postMessage(dest, {
14
- text: `*Budget*\n• Daily: $${b.dailyBudget} (spent: $${b.dailySpent.toFixed(2)}, remaining: $${b.dailyRemaining.toFixed(2)})\n• Monthly: $${b.monthlyBudget} (spent: $${b.monthlySpent.toFixed(2)}, remaining: $${b.monthlyRemaining.toFixed(2)})`,
15
+ text: t('cmd.cost.budgetHeader', {
16
+ dailyBudget: b.dailyBudget,
17
+ dailySpent: b.dailySpent.toFixed(2),
18
+ dailyRemaining: b.dailyRemaining.toFixed(2),
19
+ monthlyBudget: b.monthlyBudget,
20
+ monthlySpent: b.monthlySpent.toFixed(2),
21
+ monthlyRemaining: b.monthlyRemaining.toFixed(2),
22
+ }),
15
23
  });
16
24
  return;
17
25
  }
@@ -21,5 +29,5 @@ export async function handleBudgetCmd(channel, adapter, trimmedMessage) {
21
29
  daily_usd: daily ? parseFloat(daily) : undefined,
22
30
  monthly_usd: monthly ? parseFloat(monthly) : undefined,
23
31
  });
24
- await adapter.postMessage(dest, { text: `${Icons.ok} Budget updated: $${result.daily_usd}/day, $${result.monthly_usd}/month` });
32
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.cost.budgetUpdated', { daily: result.daily_usd, monthly: result.monthly_usd })}` });
25
33
  }
@@ -1,6 +1,7 @@
1
1
  import { getOnlineDevices } from '../../../domain/remote/client-manager.js';
2
2
  import { getMachineRegistry } from '../../../domain/tasks/dispatch-utils.js';
3
3
  import { Icons } from '../../../core/icons.js';
4
+ import { t } from '../../../core/i18n.js';
4
5
  function formatTimeAgo(ms) {
5
6
  const seconds = Math.floor(ms / 1000);
6
7
  if (seconds < 60)
@@ -20,29 +21,30 @@ function buildDevicesText() {
20
21
  for (const d of onlineDevices)
21
22
  knownNames.add(d.device);
22
23
  const now = Date.now();
23
- const lines = ['*Devices*'];
24
+ const lines = [t('cmd.device.header')];
24
25
  for (const name of [...knownNames].sort()) {
25
26
  const online = onlineDevices.find(d => d.device === name);
26
27
  if (online) {
27
28
  const connAgo = formatTimeAgo(now - online.connectedAt.getTime());
28
29
  const hbAgo = formatTimeAgo(now - online.lastHeartbeat.getTime());
29
- lines.push(`${Icons.ok} \`${name}\` ${online.platform} connected ${connAgo} heartbeat ${hbAgo}`);
30
+ lines.push(`${Icons.ok} ${t('cmd.device.online', { name, platform: online.platform, connAgo, hbAgo })}`);
30
31
  }
31
32
  else {
32
- lines.push(`${Icons.error} \`${name}\` offline`);
33
+ lines.push(`${Icons.error} ${t('cmd.device.offline', { name })}`);
33
34
  }
34
35
  }
35
36
  if (knownNames.size === 0) {
36
- lines.push('No devices registered or online.');
37
+ lines.push(t('cmd.device.none'));
37
38
  }
38
39
  return lines.join('\n');
39
40
  }
40
- const REFRESH_BUTTON = {
41
+ // Built per call so the label is resolved in the active locale (not frozen at import time).
42
+ const refreshButton = () => ({
41
43
  type: 'button',
42
- text: 'Refresh',
44
+ text: t('cmd.device.refreshButton'),
43
45
  actionId: 'cmd:devices:refresh',
44
46
  value: 'refresh',
45
- };
47
+ });
46
48
  export function createDevicesHandler(router) {
47
49
  if (router) {
48
50
  router.registerCommand('devices', {
@@ -57,7 +59,7 @@ export function createDevicesHandler(router) {
57
59
  text,
58
60
  richBlocks: [
59
61
  { type: 'section', text },
60
- { type: 'actions', elements: [REFRESH_BUTTON] },
62
+ { type: 'actions', elements: [refreshButton()] },
61
63
  ],
62
64
  }).catch(() => { });
63
65
  },
@@ -74,7 +76,7 @@ export function createDevicesHandler(router) {
74
76
  return {
75
77
  text,
76
78
  richBlocks: [{ type: 'section', text }],
77
- actions: [REFRESH_BUTTON],
79
+ actions: [refreshButton()],
78
80
  };
79
81
  };
80
82
  }
@@ -4,34 +4,34 @@
4
4
  import { threadStore } from '../../../store/thread-repo.js';
5
5
  import { resolveProfile } from '../../../domain/agents/profile-manager.js';
6
6
  import { Icons } from '../../../core/icons.js';
7
- const USAGE = 'Usage: `!dispatch <threadId> [--profile <name>]`';
7
+ import { t } from '../../../core/i18n.js';
8
8
  export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
9
9
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
10
10
  const args = trimmedMessage.split(/\s+/).slice(1);
11
11
  if (args.length === 0) {
12
- await adapter.postMessage(dest, { text: USAGE });
12
+ await adapter.postMessage(dest, { text: t('cmd.dispatch.usage') });
13
13
  return;
14
14
  }
15
15
  const threadId = args[0];
16
16
  const thread = threadStore.get(threadId);
17
17
  if (!thread) {
18
- await adapter.postMessage(dest, { text: `${Icons.error} Thread not found: \`${threadId}\`` });
18
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.dispatch.threadNotFound', { threadId })}` });
19
19
  return;
20
20
  }
21
21
  if (thread.metadata?.trigger !== 'task-dispatch') {
22
- await adapter.postMessage(dest, { text: `${Icons.error} Thread \`${threadId}\` is not a dispatch thread.` });
22
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.dispatch.notDispatchThread', { threadId })}` });
23
23
  return;
24
24
  }
25
25
  if (thread.status === 'completed' || thread.status === 'failed' || thread.status === 'cancelled' || thread.status === 'aborted') {
26
26
  await adapter.postMessage(dest, {
27
- text: `${Icons.warning} Dispatch \`${threadId.substring(0, 12)}\` is \`${thread.status}\`. Profile override will only apply if the thread is continued via \`!thread add\`.${thread.status === 'completed' ? '' : ''}`,
27
+ text: `${Icons.warning} ${t('cmd.dispatch.terminalWarning', { threadId: threadId.substring(0, 12), status: thread.status })}`,
28
28
  });
29
29
  // Allow the change to go through even for completed threads — it takes effect if continued.
30
30
  }
31
31
  const profileIdx = args.indexOf('--profile');
32
32
  if (profileIdx === -1 || profileIdx + 1 >= args.length) {
33
33
  const current = thread.metadata?.profileOverride || '(not set)';
34
- await adapter.postMessage(dest, { text: `Dispatch \`${threadId.substring(0, 12)}\`: current \`profileOverride\` = \`${current}\`\n${USAGE}` });
34
+ await adapter.postMessage(dest, { text: `${t('cmd.dispatch.currentOverride', { threadId: threadId.substring(0, 12), current })}\n${t('cmd.dispatch.usage')}` });
35
35
  return;
36
36
  }
37
37
  const profileName = args[profileIdx + 1];
@@ -39,13 +39,13 @@ export async function handleDispatchCmd(channel, adapter, trimmedMessage) {
39
39
  resolveProfile(profileName);
40
40
  }
41
41
  catch {
42
- await adapter.postMessage(dest, { text: `${Icons.error} Unknown profile: \`${profileName}\`. Use \`!profile\` to see available profiles.` });
42
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.dispatch.unknownProfile', { profile: profileName })}` });
43
43
  return;
44
44
  }
45
- await threadStore.mutate(threadId, (t) => {
46
- t.metadata = { ...t.metadata, profileOverride: profileName };
45
+ await threadStore.mutate(threadId, (th) => {
46
+ th.metadata = { ...th.metadata, profileOverride: profileName };
47
47
  });
48
48
  await adapter.postMessage(dest, {
49
- text: `${Icons.ok} Dispatch \`${threadId.substring(0, 12)}\`: \`profileOverride\` set to \`${profileName}\`. Next step will use this profile.`,
49
+ text: `${Icons.ok} ${t('cmd.dispatch.overrideSet', { threadId: threadId.substring(0, 12), profile: profileName })}`,
50
50
  });
51
51
  }
@@ -1,5 +1,6 @@
1
1
  import { createLogger } from '../../../core/log.js';
2
2
  import { Icons } from '../../../core/icons.js';
3
+ import { t } from '../../../core/i18n.js';
3
4
  import { handleOrientCmd } from './orient.js';
4
5
  import { handleThreadCmd } from './thread.js';
5
6
  import { createScheduleHandler } from './schedule.js';
@@ -15,6 +16,7 @@ import { createDevicesHandler } from './device.js';
15
16
  import { handleTailCmd } from './tail.js';
16
17
  import { handleSendFileCmd } from './sendfile.js';
17
18
  import { handleDispatchCmd } from './dispatch.js';
19
+ import { handleLangCmd } from './lang.js';
18
20
  const log = createLogger('command-handler');
19
21
  /**
20
22
  * Execute a command handler and handle its return.
@@ -52,7 +54,7 @@ const catchHandlerError = (promise, cmd, channel, adapter, threadAnchorId) => {
52
54
  if (err?.data)
53
55
  log.error(`Slack error data:`, JSON.stringify(err.data));
54
56
  const cmdDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
55
- adapter.postMessage(cmdDest, { text: `${Icons.error} Command error: ${err?.message || 'unknown error'}` }).catch(() => { });
57
+ adapter.postMessage(cmdDest, { text: `${Icons.error} ${t('cmd.error', { error: err?.message || t('cmd.errorUnknown') })}` }).catch(() => { });
56
58
  });
57
59
  };
58
60
  export function registerCommands(deps) {
@@ -84,6 +86,7 @@ export function registerCommands(deps) {
84
86
  '!thread': (ch, ad, msg) => handleThreadCmd(ch, ad, msg),
85
87
  '!agent': (ch, ad, msg) => handleAgentCmdInteractive(ch, ad, msg),
86
88
  '!orient': (ch, ad, _msg) => handleOrientCmd(ch, ad),
89
+ '!lang': (ch, ad, msg) => handleLangCmd(ch, ad, msg),
87
90
  };
88
91
  const PREFIX_COMMANDS = [
89
92
  { prefix: '!cancel', handler: handleCancelCmd },
@@ -105,6 +108,7 @@ export function registerCommands(deps) {
105
108
  { prefix: '!agent', handler: handleAgentCmdInteractive },
106
109
  { prefix: '!sendFile', handler: handleSendFileCmd },
107
110
  { prefix: '!dispatch', handler: handleDispatchCmd },
111
+ { prefix: '!lang', handler: handleLangCmd },
108
112
  ];
109
113
  const dispatchFn = function dispatchCommand(trimmedMessage, channel, adapter, threadAnchorId) {
110
114
  if (!trimmedMessage)
@@ -123,7 +127,7 @@ export function registerCommands(deps) {
123
127
  if (trimmedMessage.startsWith('!')) {
124
128
  const cmd = trimmedMessage.split(/\s+/)[0];
125
129
  const cmdDest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
126
- adapter.postMessage(cmdDest, { text: `${Icons.error} Unknown command: \`${cmd}\`. Run \`!help\` for available commands.` });
130
+ adapter.postMessage(cmdDest, { text: `${Icons.error} ${t('cmd.unknown', { cmd })}` });
127
131
  return true;
128
132
  }
129
133
  return false;
@@ -0,0 +1,3 @@
1
+ import type { PlatformAdapter } from '../../../platform/index.js';
2
+ import type { CommandResult } from './command-context.js';
3
+ export declare function handleLangCmd(_channel: string, _adapter: PlatformAdapter, trimmedMessage: string): Promise<CommandResult>;
@@ -0,0 +1,31 @@
1
+ // input: core/i18n (t/setLocale/getLocale), domain/system/preferences (setLang)
2
+ // output: handleLangCmd — !lang [en|zh] show/switch handler
3
+ // pos: !lang command. Persists to config/preferences.json AND switches the live locale
4
+ // (no restart). Registered in commands/index.ts.
5
+ // >>> If I am updated, update my header comment and the parent folder's CORTEX.md <<<
6
+ import { Icons } from '../../../core/icons.js';
7
+ import { t, setLocale, getLocale } from '../../../core/i18n.js';
8
+ import { setLang } from '../../../domain/system/preferences.js';
9
+ /** Human labels for the confirmation text (shown regardless of active locale). */
10
+ const LANG_LABELS = { en: 'English', zh: '中文' };
11
+ export async function handleLangCmd(_channel, _adapter, trimmedMessage) {
12
+ const arg = (trimmedMessage.split(/\s+/)[1] || '').trim().toLowerCase();
13
+ // No argument → show current language, the available set, and usage.
14
+ if (!arg) {
15
+ const cur = getLocale();
16
+ return {
17
+ text: [
18
+ t('lang.current', { lang: LANG_LABELS[cur] }),
19
+ t('lang.available'),
20
+ t('lang.usage'),
21
+ ].join('\n'),
22
+ };
23
+ }
24
+ if (arg !== 'en' && arg !== 'zh') {
25
+ return { text: `${Icons.error} ${t('lang.unknown', { lang: arg })}` };
26
+ }
27
+ const loc = arg;
28
+ setLang(loc); // persist to preferences.json
29
+ setLocale(loc); // live switch — subsequent t() calls render in the new locale
30
+ return { text: `${Icons.ok} ${t('lang.switched', { lang: LANG_LABELS[loc] })}` };
31
+ }
@@ -1,4 +1,5 @@
1
1
  import { Icons } from '../../../core/icons.js';
2
+ import { t } from '../../../core/i18n.js';
2
3
  import { switchMode, getActiveBackend, setActiveBackend, getClaudeModel, setClaudeModel, getActiveProfile, setActiveProfile, clearChannelProfile, getDefaultAgent, setDefaultAgent } from '../../../domain/agents/index.js';
3
4
  import { getDefaultProfileName, listProfiles, resolveProfile } from '../../../domain/agents/profile-manager.js';
4
5
  import { getDisplaySkillGroups } from '../../../domain/memory/skill-scanner.js';
@@ -11,11 +12,11 @@ function formatProfileList(channel) {
11
12
  return listProfiles().map(profile => {
12
13
  const markers = [];
13
14
  if (profile.name === defaultName)
14
- markers.push('default');
15
+ markers.push(t('cmd.profile.markerDefault'));
15
16
  if (profile.name === (globalActive || defaultName))
16
- markers.push('global');
17
+ markers.push(t('cmd.profile.markerGlobal'));
17
18
  if (channel && channelActive !== globalActive && profile.name === channelActive)
18
- markers.push('channel');
19
+ markers.push(t('cmd.profile.markerChannel'));
19
20
  const suffix = markers.length ? ` (${markers.join(', ')})` : '';
20
21
  const backend = profile.backend || 'claude';
21
22
  const mode = profile.mode || '-';
@@ -25,7 +26,7 @@ function formatProfileList(channel) {
25
26
  export async function handleModeCmd(channel, adapter) {
26
27
  const { newMode } = switchMode();
27
28
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
28
- await adapter.postMessage(dest, { text: `${Icons.refresh} Switched to *${newMode === 'api' ? 'API' : 'Plan'}* mode` });
29
+ await adapter.postMessage(dest, { text: `${Icons.refresh} ${t('cmd.mode.switched', { mode: newMode === 'api' ? t('cmd.mode.apiLabel') : t('cmd.mode.planLabel') })}` });
29
30
  }
30
31
  export async function handleBackendCmd(channel, adapter, trimmedMessage) {
31
32
  const arg = trimmedMessage.split(/\s+/)[1];
@@ -33,23 +34,23 @@ export async function handleBackendCmd(channel, adapter, trimmedMessage) {
33
34
  setActiveBackend(newBackend);
34
35
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
35
36
  await adapter.postMessage(dest, {
36
- text: `${Icons.refresh} Backend: *${newBackend === 'claude' ? 'Claude Code' : 'Codex'}*`,
37
+ text: `${Icons.refresh} ${t('cmd.backend.switched', { backend: newBackend === 'claude' ? t('cmd.backend.claudeLabel') : t('cmd.backend.codexLabel') })}`,
37
38
  });
38
39
  }
39
40
  export async function handleModelCmd(channel, adapter, trimmedMessage) {
40
41
  const args = trimmedMessage.split(/\s+/).slice(1);
41
42
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
42
43
  if (args.length === 0) {
43
- await adapter.postMessage(dest, { text: `Current Claude model: *${getClaudeModel()}*` });
44
+ await adapter.postMessage(dest, { text: t('cmd.model.current', { model: getClaudeModel() }) });
44
45
  return;
45
46
  }
46
47
  const model = args.join(' ').trim();
47
48
  if (!model) {
48
- await adapter.postMessage(dest, { text: `${Icons.error} Usage: \`!model <model-name>\`` });
49
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.model.usage')}` });
49
50
  return;
50
51
  }
51
52
  setClaudeModel(model);
52
- await adapter.postMessage(dest, { text: `${Icons.ok} Claude model set to *${getClaudeModel()}*` });
53
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.model.set', { model: getClaudeModel() })}` });
53
54
  }
54
55
  const MAX_PROFILE_BUTTONS = 10;
55
56
  function buildProfileText(channel) {
@@ -57,8 +58,8 @@ function buildProfileText(channel) {
57
58
  const globalProfile = getActiveProfile() || getDefaultProfileName();
58
59
  const isOverridden = channel && effective !== globalProfile;
59
60
  const header = isOverridden
60
- ? `Channel profile: *${effective}* (global: ${globalProfile})`
61
- : `Active profile: *${effective}*`;
61
+ ? t('cmd.profile.channelHeader', { effective, global: globalProfile })
62
+ : t('cmd.profile.activeHeader', { effective });
62
63
  return `${header}\n${formatProfileList(channel)}`;
63
64
  }
64
65
  function buildProfileButtons(channel) {
@@ -80,7 +81,7 @@ export function createProfileHandler(router) {
80
81
  const { name, channel } = JSON.parse(ctx.value);
81
82
  resolveProfile(name);
82
83
  setActiveProfile(name, channel);
83
- const text = `${Icons.ok} Channel profile set to *${name}*\n${formatProfileList(channel)}`;
84
+ const text = `${Icons.ok} ${t('cmd.profile.channelSet', { name })}\n${formatProfileList(channel)}`;
84
85
  if (ctx.messageRef) {
85
86
  await adapter.updateMessage(ctx.messageRef, {
86
87
  text,
@@ -114,20 +115,20 @@ export function createProfileHandler(router) {
114
115
  if (args[0] === 'reset') {
115
116
  clearChannelProfile(channel);
116
117
  const fallback = getActiveProfile() || getDefaultProfileName();
117
- await adapter.postMessage(dest, { text: `${Icons.ok} Channel profile cleared, using global: *${fallback}*` });
118
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.profile.cleared', { name: fallback })}` });
118
119
  await handleNewCmd(channel, adapter, { skipHook: true });
119
120
  return;
120
121
  }
121
122
  if (args[0] === 'global') {
122
123
  if (args.length < 2) {
123
- await adapter.postMessage(dest, { text: `${Icons.error} Usage: \`!profile global <name>\`` });
124
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.profile.globalUsage')}` });
124
125
  return;
125
126
  }
126
127
  const profileName = args[1];
127
128
  try {
128
129
  resolveProfile(profileName);
129
130
  setActiveProfile(profileName);
130
- await adapter.postMessage(dest, { text: `${Icons.ok} Global profile set to *${profileName}*\n${formatProfileList(channel)}` });
131
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.profile.globalSet', { name: profileName })}\n${formatProfileList(channel)}` });
131
132
  await handleNewCmd(channel, adapter, { skipHook: true });
132
133
  }
133
134
  catch (error) {
@@ -139,7 +140,7 @@ export function createProfileHandler(router) {
139
140
  try {
140
141
  resolveProfile(profileName);
141
142
  setActiveProfile(profileName, channel);
142
- await adapter.postMessage(dest, { text: `${Icons.ok} Channel profile set to *${profileName}*\n${formatProfileList(channel)}` });
143
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.profile.channelSet', { name: profileName })}\n${formatProfileList(channel)}` });
143
144
  await handleNewCmd(channel, adapter, { skipHook: true });
144
145
  }
145
146
  catch (error) {
@@ -168,12 +169,12 @@ export async function handleSkillsCmd(channel, adapter) {
168
169
  const groups = getDisplaySkillGroups();
169
170
  const dest = { type: 'interactive-reply', conduit: channel, sessionId: '' };
170
171
  if (groups.length === 0) {
171
- await adapter.postMessage(dest, { text: 'No skills found.' });
172
+ await adapter.postMessage(dest, { text: t('cmd.skills.none') });
172
173
  return;
173
174
  }
174
- const lines = ['*Available skills*'];
175
+ const lines = [t('cmd.skills.header')];
175
176
  for (const { plugin, skills } of groups) {
176
- lines.push(plugin ? `_${plugin}_` : '_.claude/skills_');
177
+ lines.push(plugin ? `_${plugin}_` : `_${t('cmd.skills.localGroup')}_`);
177
178
  for (const skill of skills) {
178
179
  lines.push(`• \`${skill}\``);
179
180
  }
@@ -188,9 +189,9 @@ function buildAgentText() {
188
189
  const agentDef = getAgent(current);
189
190
  const profile = agentDef?.profile || '?';
190
191
  const claudeAgentStr = agentDef?.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
191
- return `Default agent: *${current}* (${profile}${claudeAgentStr})`;
192
+ return t('cmd.agent.current', { name: current, detail: `${profile}${claudeAgentStr}` });
192
193
  }
193
- return 'No default agent set.\nAvailable: ' + agents.map(a => `\`${a.name}\``).join(', ');
194
+ return t('cmd.agent.none', { agents: agents.map(a => `\`${a.name}\``).join(', ') });
194
195
  }
195
196
  function buildAgentButtons() {
196
197
  const agents = listAgents();
@@ -202,7 +203,7 @@ function buildAgentButtons() {
202
203
  }));
203
204
  buttons.push({
204
205
  type: 'button',
205
- text: 'Disable',
206
+ text: t('cmd.agent.disableButton'),
206
207
  actionId: 'cmd:agent:disable',
207
208
  value: 'off',
208
209
  style: 'danger',
@@ -221,7 +222,7 @@ export function createAgentHandler(router) {
221
222
  return;
222
223
  setDefaultAgent(name);
223
224
  const claudeAgentStr = agentDef.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
224
- const text = `${Icons.ok} Default agent set to *${name}* (${agentDef.profile}${claudeAgentStr})`;
225
+ const text = `${Icons.ok} ${t('cmd.agent.defaultSet', { name, detail: `${agentDef.profile}${claudeAgentStr}` })}`;
225
226
  if (ctx.messageRef) {
226
227
  await adapter.updateMessage(ctx.messageRef, {
227
228
  text,
@@ -239,9 +240,9 @@ export function createAgentHandler(router) {
239
240
  setDefaultAgent(null);
240
241
  if (ctx.messageRef) {
241
242
  await adapter.updateMessage(ctx.messageRef, {
242
- text: `${Icons.ok} Default agent disabled.`,
243
+ text: `${Icons.ok} ${t('cmd.agent.disabled')}`,
243
244
  richBlocks: [
244
- { type: 'section', text: `${Icons.ok} Default agent disabled.` },
245
+ { type: 'section', text: `${Icons.ok} ${t('cmd.agent.disabled')}` },
245
246
  { type: 'actions', elements: buildAgentButtons() },
246
247
  ],
247
248
  }).catch(() => { });
@@ -264,18 +265,18 @@ export function createAgentHandler(router) {
264
265
  const name = args.split(/\s+/)[0];
265
266
  if (name === 'off' || name === 'none' || name === 'disable') {
266
267
  setDefaultAgent(null);
267
- await adapter.postMessage(dest, { text: `${Icons.ok} Default agent disabled.` });
268
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.agent.disabled')}` });
268
269
  return;
269
270
  }
270
271
  const agentDef = getAgent(name);
271
272
  if (!agentDef) {
272
273
  const available = listAgents().map(a => `\`${a.name}\``).join(', ');
273
- await adapter.postMessage(dest, { text: `${Icons.error} Unknown agent: \`${name}\`\nAvailable: ${available}` });
274
+ await adapter.postMessage(dest, { text: `${Icons.error} ${t('cmd.agent.unknown', { name, available })}` });
274
275
  return;
275
276
  }
276
277
  setDefaultAgent(name);
277
278
  const claudeAgentStr = agentDef.claudeAgent ? ` · agent:${agentDef.claudeAgent}` : '';
278
- await adapter.postMessage(dest, { text: `${Icons.ok} Default agent set to *${name}* (${agentDef.profile}${claudeAgentStr})` });
279
+ await adapter.postMessage(dest, { text: `${Icons.ok} ${t('cmd.agent.defaultSet', { name, detail: `${agentDef.profile}${claudeAgentStr}` })}` });
279
280
  return;
280
281
  }
281
282
  const text = buildAgentText();