@cortex-agent/server 2026.6.11 → 2026.6.18
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/defaults/config/thread-templates.json +2 -2
- package/defaults/hooks/task-status-check.mjs +9 -7
- package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +103 -16
- package/defaults/plugins/cortex-system/skills/orient/SKILL.md +6 -6
- package/defaults/plugins/cortex-system/skills/thread/SKILL.md +29 -35
- package/defaults/prompts/directives/manager.md +21 -11
- package/dist/agent-adapter/claude/spawn-args.d.ts +5 -0
- package/dist/agent-adapter/claude/spawn-args.js +6 -0
- package/dist/agent-adapter/types.d.ts +4 -0
- 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/task-parser.d.ts +6 -0
- package/dist/core/task-parser.js +10 -0
- package/dist/core/types/thread-types.d.ts +29 -0
- 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/agents/facade.d.ts +4 -0
- package/dist/domain/agents/facade.js +3 -1
- package/dist/domain/mcp/core-server.js +15 -9
- package/dist/domain/mcp/tools/task-monitor.d.ts +2 -0
- package/dist/domain/mcp/tools/task-monitor.js +99 -0
- package/dist/domain/mcp/tools/thread-ops.js +50 -85
- package/dist/domain/scheduling/jobs/task-dispatch.js +18 -16
- 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/dispatch-utils.d.ts +5 -0
- package/dist/domain/tasks/dispatch-utils.js +9 -1
- package/dist/domain/tasks/dispatcher.d.ts +11 -2
- package/dist/domain/tasks/dispatcher.js +41 -11
- package/dist/domain/tasks/system/task-cli.d.ts +1 -0
- package/dist/domain/tasks/system/task-cli.js +82 -6
- package/dist/domain/tasks/system/task-mutations.d.ts +6 -1
- package/dist/domain/tasks/system/task-mutations.js +10 -1
- package/dist/domain/threads/hook-runner.js +1 -0
- package/dist/domain/threads/prompt-builder.d.ts +6 -0
- package/dist/domain/threads/prompt-builder.js +34 -11
- package/dist/domain/threads/runner.d.ts +5 -0
- package/dist/domain/threads/runner.js +44 -11
- package/dist/domain/threads/state-machine.d.ts +9 -12
- package/dist/domain/threads/state-machine.js +27 -50
- 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/hooks/task-status-check.mjs +9 -7
- 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/routing/webhook.js +38 -1
- package/dist/orchestration/status-helpers.js +6 -5
- package/dist/orchestration/thread-callback.d.ts +11 -1
- package/dist/orchestration/thread-callback.js +66 -30
- package/dist/platform/adapters/feishu.d.ts +11 -0
- package/dist/platform/adapters/feishu.js +74 -3
- 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
package/dist/entry/init.js
CHANGED
|
@@ -23,6 +23,7 @@ import { generateProfiles, writeProfilesJson, listChoices } from '../core/profil
|
|
|
23
23
|
import { mergeThreadTemplates } from '../domain/threads/index.js';
|
|
24
24
|
import { createLogger } from '../core/log.js';
|
|
25
25
|
import { INSTALL_ROOT, DEFAULTS_DIR } from '../core/utils.js';
|
|
26
|
+
import { t, setLocale, normalizeLocale, detectSystemLocale } from '../core/i18n.js';
|
|
26
27
|
import { cmdFeishu } from './feishu-login.js';
|
|
27
28
|
// ─── Path computation (DATA_DIR resolved locally to support --home override) ──
|
|
28
29
|
const log = createLogger('init');
|
|
@@ -98,21 +99,12 @@ export function generateDotEnvContent(answers) {
|
|
|
98
99
|
lines.push(`SLACK_BOT_TOKEN=${answers.slackConfig.botToken}`);
|
|
99
100
|
lines.push(`SLACK_SIGNING_SECRET=${answers.slackConfig.signingSecret}`);
|
|
100
101
|
lines.push(`SLACK_APP_TOKEN=${answers.slackConfig.appToken}`);
|
|
101
|
-
if (answers.slackConfig.adminChannel) {
|
|
102
|
-
lines.push(`CORTEX_ADMIN_CHANNEL=${answers.slackConfig.adminChannel}`);
|
|
103
|
-
}
|
|
104
102
|
lines.push('');
|
|
105
103
|
}
|
|
106
104
|
if (answers.feishuConfig) {
|
|
107
105
|
lines.push('# Feishu configuration');
|
|
108
106
|
lines.push(`FEISHU_APP_ID=${answers.feishuConfig.appId}`);
|
|
109
107
|
lines.push(`FEISHU_APP_SECRET=${answers.feishuConfig.appSecret}`);
|
|
110
|
-
if (answers.feishuConfig.encryptKey) {
|
|
111
|
-
lines.push(`FEISHU_ENCRYPT_KEY=${answers.feishuConfig.encryptKey}`);
|
|
112
|
-
}
|
|
113
|
-
if (answers.feishuConfig.verificationToken) {
|
|
114
|
-
lines.push(`FEISHU_VERIFICATION_TOKEN=${answers.feishuConfig.verificationToken}`);
|
|
115
|
-
}
|
|
116
108
|
if (answers.feishuConfig.domain) {
|
|
117
109
|
lines.push(`FEISHU_DOMAIN=${answers.feishuConfig.domain}`);
|
|
118
110
|
}
|
|
@@ -137,8 +129,10 @@ export function generateDefaultModeJson(primaryBackend = 'claude') {
|
|
|
137
129
|
}
|
|
138
130
|
/** Format resolved paths and initialization status for `cortex config` output. */
|
|
139
131
|
export function formatConfigOutput(paths, status) {
|
|
132
|
+
const found = t('init.config.found');
|
|
133
|
+
const missing = t('init.config.missing');
|
|
140
134
|
const lines = [
|
|
141
|
-
'
|
|
135
|
+
t('init.config.title'),
|
|
142
136
|
` INSTALL_ROOT: ${paths.INSTALL_ROOT}`,
|
|
143
137
|
` DATA_DIR: ${paths.DATA_DIR}`,
|
|
144
138
|
` CONFIG_DIR: ${paths.CONFIG_DIR}`,
|
|
@@ -147,11 +141,11 @@ export function formatConfigOutput(paths, status) {
|
|
|
147
141
|
` PROJECTS_DIR: ${paths.PROJECTS_DIR}`,
|
|
148
142
|
` WORKSPACE_DIR: ${paths.WORKSPACE_DIR}`,
|
|
149
143
|
'',
|
|
150
|
-
'
|
|
151
|
-
` DATA_DIR: ${status.dataDirExists ? 'initialized' : '
|
|
152
|
-
` .env: ${status.dotEnvExists ?
|
|
153
|
-
` mcp-config.json: ${status.mcpConfigExists ?
|
|
154
|
-
` mode.json: ${status.modeJsonExists ?
|
|
144
|
+
t('init.config.statusTitle'),
|
|
145
|
+
` DATA_DIR: ${status.dataDirExists ? t('init.config.initialized') : t('init.config.notInitialized')}`,
|
|
146
|
+
` .env: ${status.dotEnvExists ? found : missing}`,
|
|
147
|
+
` mcp-config.json: ${status.mcpConfigExists ? found : missing}`,
|
|
148
|
+
` mode.json: ${status.modeJsonExists ? found : missing}`,
|
|
155
149
|
];
|
|
156
150
|
return lines.join('\n');
|
|
157
151
|
}
|
|
@@ -160,14 +154,14 @@ const BACKEND_INFO = {
|
|
|
160
154
|
claude: {
|
|
161
155
|
bin: 'claude',
|
|
162
156
|
npmPackage: '@anthropic-ai/claude-code',
|
|
163
|
-
|
|
164
|
-
|
|
157
|
+
labelKey: 'init.backend.label.claude',
|
|
158
|
+
loginHintKey: 'init.backend.loginHint.claude',
|
|
165
159
|
},
|
|
166
160
|
pi: {
|
|
167
161
|
bin: 'pi',
|
|
168
162
|
npmPackage: '@mariozechner/pi-coding-agent',
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
labelKey: 'init.backend.label.pi',
|
|
164
|
+
loginHintKey: 'init.backend.loginHint.pi',
|
|
171
165
|
},
|
|
172
166
|
};
|
|
173
167
|
// ─── Slack App Manifest ──────────────────────────────────────────
|
|
@@ -266,7 +260,7 @@ function copyToClipboard(text) {
|
|
|
266
260
|
async function promptCopyManifestToClipboard(manifest) {
|
|
267
261
|
if (!process.stdin.isTTY)
|
|
268
262
|
return; // Non-interactive mode, skip
|
|
269
|
-
process.stdout.write('
|
|
263
|
+
process.stdout.write(t('init.clipboard.prompt'));
|
|
270
264
|
return new Promise((resolve) => {
|
|
271
265
|
const wasRaw = process.stdin.isRaw ?? false;
|
|
272
266
|
try {
|
|
@@ -294,11 +288,11 @@ async function promptCopyManifestToClipboard(manifest) {
|
|
|
294
288
|
if (ch.toLowerCase() === 'c') {
|
|
295
289
|
const ok = copyToClipboard(manifest);
|
|
296
290
|
if (ok) {
|
|
297
|
-
clack.log.success('
|
|
291
|
+
clack.log.success(t('init.clipboard.copied'));
|
|
298
292
|
}
|
|
299
293
|
else {
|
|
300
|
-
clack.log.warn('
|
|
301
|
-
clack.log.info('
|
|
294
|
+
clack.log.warn(t('init.clipboard.failed'));
|
|
295
|
+
clack.log.info(t('init.clipboard.manual'));
|
|
302
296
|
}
|
|
303
297
|
}
|
|
304
298
|
resolve();
|
|
@@ -328,8 +322,6 @@ function parseExistingEnvSlackConfig(envPath) {
|
|
|
328
322
|
result.appToken = value;
|
|
329
323
|
else if (key === 'SLACK_BOT_TOKEN')
|
|
330
324
|
result.botToken = value;
|
|
331
|
-
else if (key === 'CORTEX_ADMIN_CHANNEL')
|
|
332
|
-
result.adminChannel = value;
|
|
333
325
|
}
|
|
334
326
|
if (!result.signingSecret && !result.appToken && !result.botToken)
|
|
335
327
|
return null;
|
|
@@ -374,23 +366,24 @@ function detectGpuCount() {
|
|
|
374
366
|
async function checkAndInstallBackends(backends) {
|
|
375
367
|
for (const backend of backends) {
|
|
376
368
|
const info = BACKEND_INFO[backend];
|
|
369
|
+
const label = t(info.labelKey);
|
|
377
370
|
const installed = isBackendInstalled(backend);
|
|
378
371
|
if (installed) {
|
|
379
|
-
clack.log.success(
|
|
372
|
+
clack.log.success(t('init.backend.alreadyInstalled', { label }));
|
|
380
373
|
}
|
|
381
374
|
else {
|
|
382
375
|
const s = clack.spinner();
|
|
383
|
-
s.start(
|
|
376
|
+
s.start(t('init.backend.installing', { label }));
|
|
384
377
|
try {
|
|
385
378
|
execSync(getInstallCommand(backend), { stdio: 'pipe', timeout: 120_000 });
|
|
386
|
-
s.stop(
|
|
379
|
+
s.stop(t('init.backend.installed', { label }));
|
|
387
380
|
}
|
|
388
381
|
catch (err) {
|
|
389
|
-
s.stop(
|
|
390
|
-
clack.log.error(
|
|
382
|
+
s.stop(t('init.backend.installFailed', { label }));
|
|
383
|
+
clack.log.error(t('init.backend.installFailedHint', { command: getInstallCommand(backend) }));
|
|
391
384
|
}
|
|
392
385
|
}
|
|
393
|
-
clack.log.info(info.
|
|
386
|
+
clack.log.info(t(info.loginHintKey));
|
|
394
387
|
}
|
|
395
388
|
}
|
|
396
389
|
// ─── Gateway usage config ────────────────────────────────────────
|
|
@@ -408,7 +401,7 @@ export function generateGatewayUsageYaml(config) {
|
|
|
408
401
|
}
|
|
409
402
|
return yaml.stringify(doc);
|
|
410
403
|
}
|
|
411
|
-
/** Write gateway usage config to ~/.aistatus/config.yaml, or <configDir>/config.yaml if configDir is given. */
|
|
404
|
+
/** Write gateway usage config to ~/.aistatus/config.yaml, or <configDir>/config.yaml if configDir is given (for testing). */
|
|
412
405
|
function writeGatewayUsageConfig(config, configDir) {
|
|
413
406
|
const configPath = configDir
|
|
414
407
|
? path.join(configDir, 'config.yaml')
|
|
@@ -518,8 +511,8 @@ function installService(dataDir) {
|
|
|
518
511
|
const plistContent = generateLaunchdPlist(user, cortexBin, dataDir);
|
|
519
512
|
const plistPath = path.join(os.homedir(), 'Library', 'LaunchAgents', plistName);
|
|
520
513
|
writeFileSync(plistPath, plistContent);
|
|
521
|
-
clack.log.success(
|
|
522
|
-
clack.log.info('
|
|
514
|
+
clack.log.success(t('init.service.launchdWritten', { path: plistPath }));
|
|
515
|
+
clack.log.info(t('init.service.launchdStartHint', { path: plistPath }));
|
|
523
516
|
}
|
|
524
517
|
else if (platform === 'linux') {
|
|
525
518
|
const unitContent = generateSystemdUnit(user, cortexBin, dataDir);
|
|
@@ -531,8 +524,8 @@ function installService(dataDir) {
|
|
|
531
524
|
mkdirSync(userUnitDir, { recursive: true });
|
|
532
525
|
const userUnitPath = path.join(userUnitDir, unitName);
|
|
533
526
|
writeFileSync(userUnitPath, unitContent);
|
|
534
|
-
clack.log.success(
|
|
535
|
-
clack.log.info('
|
|
527
|
+
clack.log.success(t('init.service.systemdUserWritten', { path: userUnitPath }));
|
|
528
|
+
clack.log.info(t('init.service.systemdUserEnableHint'));
|
|
536
529
|
return;
|
|
537
530
|
}
|
|
538
531
|
catch {
|
|
@@ -544,69 +537,45 @@ function installService(dataDir) {
|
|
|
544
537
|
const tmpPath = path.join(os.tmpdir(), unitName);
|
|
545
538
|
writeFileSync(tmpPath, unitContent);
|
|
546
539
|
execSync(`sudo cp ${tmpPath} ${systemPath} && sudo systemctl daemon-reload`, { stdio: 'pipe' });
|
|
547
|
-
clack.log.success(
|
|
548
|
-
clack.log.info('
|
|
540
|
+
clack.log.success(t('init.service.systemdInstalled', { path: systemPath }));
|
|
541
|
+
clack.log.info(t('init.service.systemdEnableHint'));
|
|
549
542
|
}
|
|
550
543
|
catch (err) {
|
|
551
|
-
clack.log.warn(
|
|
544
|
+
clack.log.warn(t('init.service.systemInstallFailed', { message: err.message }));
|
|
552
545
|
}
|
|
553
546
|
}
|
|
554
547
|
else {
|
|
555
548
|
// No sudo — write to config dir and show instructions
|
|
556
549
|
const localPath = path.join(dataDir, 'config', unitName);
|
|
557
550
|
writeFileSync(localPath, unitContent);
|
|
558
|
-
clack.log.warn('
|
|
559
|
-
clack.log.info(
|
|
551
|
+
clack.log.warn(t('init.service.noSudo'));
|
|
552
|
+
clack.log.info(t('init.service.manualInstallHint', { localPath, systemPath }));
|
|
560
553
|
}
|
|
561
554
|
}
|
|
562
555
|
else {
|
|
563
|
-
clack.log.warn(
|
|
556
|
+
clack.log.warn(t('init.service.unsupported', { platform }));
|
|
564
557
|
}
|
|
565
558
|
}
|
|
566
559
|
// ─── Interactive prompts (TTY) ───────────────────────────────────
|
|
567
560
|
function handleCancel(value) {
|
|
568
561
|
if (clack.isCancel(value)) {
|
|
569
|
-
clack.cancel('
|
|
562
|
+
clack.cancel(t('init.cancel'));
|
|
570
563
|
process.exit(0);
|
|
571
564
|
}
|
|
572
565
|
}
|
|
573
566
|
async function collectSlackConfig(prefill) {
|
|
574
|
-
clack.note(SLACK_APP_MANIFEST, '
|
|
575
|
-
clack.note(
|
|
576
|
-
'To set up Slack, you need a Slack App:',
|
|
577
|
-
'',
|
|
578
|
-
'1. Go to https://api.slack.com/apps',
|
|
579
|
-
'2. Click "Create New App" → "From a manifest"',
|
|
580
|
-
'3. Select your workspace, then paste the manifest (shown above)',
|
|
581
|
-
'4. Go to "Basic Information" → copy the Signing Secret',
|
|
582
|
-
'5. Under Basic Information, generate an App-Level Token',
|
|
583
|
-
' (scope: connections:write, name it "cortex-socket")',
|
|
584
|
-
'6. Go to "OAuth & Permissions" → Install to Workspace',
|
|
585
|
-
' Copy the *Bot User OAuth Token* after installing',
|
|
586
|
-
'7. Go to "App Home" → Show Tabs → enable *Messages Tab*',
|
|
587
|
-
' and check "Allow users to send messages from the messages tab"',
|
|
588
|
-
' (required for DM support)',
|
|
589
|
-
'',
|
|
590
|
-
'The manifest includes socket_mode_enabled, so Socket Mode',
|
|
591
|
-
'is automatically enabled when you import it.',
|
|
592
|
-
'',
|
|
593
|
-
'Required Bot Token Scopes (included in manifest):',
|
|
594
|
-
' chat:write, im:history, im:write, reactions:read, reactions:write,',
|
|
595
|
-
' users:read, commands, app_mentions:read,',
|
|
596
|
-
' channels:history, channels:read, groups:history,',
|
|
597
|
-
' files:read, files:write, emoji:read, pins:read, pins:write',
|
|
598
|
-
].join('\n'), 'Slack App Setup Guide');
|
|
567
|
+
clack.note(SLACK_APP_MANIFEST, t('init.slack.manifestTitle'));
|
|
568
|
+
clack.note(t('init.slack.guide'), t('init.slack.guideTitle'));
|
|
599
569
|
await promptCopyManifestToClipboard(SLACK_APP_MANIFEST);
|
|
600
570
|
const hasPrefill = prefill && (prefill.signingSecret || prefill.appToken || prefill.botToken);
|
|
601
571
|
let signingSecret;
|
|
602
572
|
let appToken;
|
|
603
573
|
let botToken;
|
|
604
|
-
let adminChannelRaw;
|
|
605
574
|
if (hasPrefill) {
|
|
606
|
-
clack.log.info('
|
|
575
|
+
clack.log.info(t('init.slack.prefillFound'));
|
|
607
576
|
const skip = await clack.text({
|
|
608
|
-
message: '
|
|
609
|
-
placeholder: '
|
|
577
|
+
message: t('init.slack.skipPrompt'),
|
|
578
|
+
placeholder: t('init.slack.skipPlaceholder'),
|
|
610
579
|
defaultValue: '',
|
|
611
580
|
});
|
|
612
581
|
handleCancel(skip);
|
|
@@ -615,95 +584,65 @@ async function collectSlackConfig(prefill) {
|
|
|
615
584
|
signingSecret = prefill.signingSecret;
|
|
616
585
|
appToken = prefill.appToken;
|
|
617
586
|
botToken = prefill.botToken;
|
|
618
|
-
adminChannelRaw = prefill.adminChannel ?? '';
|
|
619
587
|
}
|
|
620
588
|
}
|
|
621
589
|
if (!signingSecret) {
|
|
622
590
|
signingSecret = await clack.password({
|
|
623
|
-
message: '
|
|
591
|
+
message: t('init.slack.signingSecretPrompt'),
|
|
624
592
|
validate(value) {
|
|
625
593
|
if (!value)
|
|
626
|
-
return '
|
|
594
|
+
return t('init.slack.signingSecretRequired');
|
|
627
595
|
},
|
|
628
596
|
});
|
|
629
597
|
handleCancel(signingSecret);
|
|
630
598
|
appToken = await clack.password({
|
|
631
|
-
message: '
|
|
599
|
+
message: t('init.slack.appTokenPrompt'),
|
|
632
600
|
validate(value) {
|
|
633
601
|
if (!value)
|
|
634
|
-
return '
|
|
602
|
+
return t('init.slack.appTokenRequired');
|
|
635
603
|
if (!value.startsWith('xapp-'))
|
|
636
|
-
return '
|
|
604
|
+
return t('init.slack.appTokenPrefix');
|
|
637
605
|
},
|
|
638
606
|
});
|
|
639
607
|
handleCancel(appToken);
|
|
640
608
|
botToken = await clack.password({
|
|
641
|
-
message: '
|
|
609
|
+
message: t('init.slack.botTokenPrompt'),
|
|
642
610
|
validate(value) {
|
|
643
611
|
if (!value)
|
|
644
|
-
return '
|
|
612
|
+
return t('init.slack.botTokenRequired');
|
|
645
613
|
if (!value.startsWith('xoxb-'))
|
|
646
|
-
return '
|
|
614
|
+
return t('init.slack.botTokenPrefix');
|
|
647
615
|
},
|
|
648
616
|
});
|
|
649
617
|
handleCancel(botToken);
|
|
650
|
-
adminChannelRaw = await clack.text({
|
|
651
|
-
message: 'Step 4/4: CORTEX_ADMIN_CHANNEL (optional — Slack channel ID for admin notifications):',
|
|
652
|
-
placeholder: 'e.g. C0123456789 or D0123456789 (leave blank to configure later)',
|
|
653
|
-
initialValue: prefill?.adminChannel,
|
|
654
|
-
});
|
|
655
|
-
handleCancel(adminChannelRaw);
|
|
656
618
|
}
|
|
657
619
|
return {
|
|
658
620
|
signingSecret: signingSecret,
|
|
659
621
|
appToken: appToken,
|
|
660
622
|
botToken: botToken,
|
|
661
|
-
adminChannel: adminChannelRaw.trim() || undefined,
|
|
662
623
|
};
|
|
663
624
|
}
|
|
664
625
|
async function collectFeishuConfig() {
|
|
665
|
-
clack.note(
|
|
666
|
-
'To set up Feishu (飞书), create a Feishu app:',
|
|
667
|
-
'',
|
|
668
|
-
'1. Go to https://open.feishu.cn/app',
|
|
669
|
-
'2. Click "Create Agentic App" (创建agentic应用)',
|
|
670
|
-
'3. Enter agent name (e.g. CortexAgent), select an avatar, and click Create',
|
|
671
|
-
'4. After creation, the page will display App ID and App Secret — copy them directly',
|
|
672
|
-
'5. Enable bot events and subscribe to: im.message.receive_v1',
|
|
673
|
-
'',
|
|
674
|
-
'Identity for MCP document operations (docx/wiki/bitable/sheets/drive):',
|
|
675
|
-
' - bot: documents are created/owned by the app (default)',
|
|
676
|
-
' - user: documents are created/owned by YOUR Feishu account (Recommended)',
|
|
677
|
-
].join('\n'), 'Feishu App Setup Guide');
|
|
626
|
+
clack.note(t('init.feishu.guide'), t('init.feishu.guideTitle'));
|
|
678
627
|
const appId = await clack.text({
|
|
679
|
-
message: '
|
|
628
|
+
message: t('init.feishu.appIdPrompt'),
|
|
680
629
|
validate(value) {
|
|
681
630
|
if (!value)
|
|
682
|
-
return '
|
|
631
|
+
return t('init.feishu.appIdRequired');
|
|
683
632
|
},
|
|
684
633
|
});
|
|
685
634
|
handleCancel(appId);
|
|
686
635
|
const appSecret = await clack.password({
|
|
687
|
-
message: '
|
|
636
|
+
message: t('init.feishu.appSecretPrompt'),
|
|
688
637
|
validate(value) {
|
|
689
638
|
if (!value)
|
|
690
|
-
return '
|
|
639
|
+
return t('init.feishu.appSecretRequired');
|
|
691
640
|
},
|
|
692
641
|
});
|
|
693
642
|
handleCancel(appSecret);
|
|
694
|
-
const encryptKeyRaw = await clack.text({
|
|
695
|
-
message: 'FEISHU_ENCRYPT_KEY (optional):',
|
|
696
|
-
placeholder: 'leave blank to skip',
|
|
697
|
-
});
|
|
698
|
-
handleCancel(encryptKeyRaw);
|
|
699
|
-
const verificationTokenRaw = await clack.text({
|
|
700
|
-
message: 'FEISHU_VERIFICATION_TOKEN (optional):',
|
|
701
|
-
placeholder: 'leave blank to skip',
|
|
702
|
-
});
|
|
703
|
-
handleCancel(verificationTokenRaw);
|
|
704
643
|
const domainRaw = await clack.text({
|
|
705
|
-
message: '
|
|
706
|
-
placeholder: 'feishu
|
|
644
|
+
message: t('init.feishu.domainPrompt'),
|
|
645
|
+
placeholder: t('init.feishu.domainPlaceholder'),
|
|
707
646
|
});
|
|
708
647
|
handleCancel(domainRaw);
|
|
709
648
|
const domainVal = domainRaw.trim().toLowerCase();
|
|
@@ -711,10 +650,10 @@ async function collectFeishuConfig() {
|
|
|
711
650
|
? domainVal
|
|
712
651
|
: undefined;
|
|
713
652
|
const authMode = await clack.select({
|
|
714
|
-
message: '
|
|
653
|
+
message: t('init.feishu.authModePrompt'),
|
|
715
654
|
options: [
|
|
716
|
-
{ value: 'bot', label: '
|
|
717
|
-
{ value: 'user', label: '
|
|
655
|
+
{ value: 'bot', label: t('init.feishu.authModeBotLabel'), hint: t('init.feishu.authModeBotHint') },
|
|
656
|
+
{ value: 'user', label: t('init.feishu.authModeUserLabel'), hint: t('init.feishu.authModeUserHint') },
|
|
718
657
|
],
|
|
719
658
|
initialValue: 'user',
|
|
720
659
|
});
|
|
@@ -722,8 +661,6 @@ async function collectFeishuConfig() {
|
|
|
722
661
|
return {
|
|
723
662
|
appId: appId,
|
|
724
663
|
appSecret: appSecret,
|
|
725
|
-
encryptKey: encryptKeyRaw.trim() || undefined,
|
|
726
|
-
verificationToken: verificationTokenRaw.trim() || undefined,
|
|
727
664
|
domain,
|
|
728
665
|
authMode: authMode,
|
|
729
666
|
};
|
|
@@ -757,14 +694,31 @@ export async function runFeishuUserLogin(config, configDir, deps = {}) {
|
|
|
757
694
|
return result;
|
|
758
695
|
}
|
|
759
696
|
async function collectAnswersInteractive(paths) {
|
|
760
|
-
|
|
697
|
+
// Step 0: Language selection — shown first and bilingually (the prompt itself is always
|
|
698
|
+
// bilingual since no choice has been made yet). The option pre-selected as the default is
|
|
699
|
+
// inferred from the system locale (Chinese system → 中文 highlighted, otherwise English), so a
|
|
700
|
+
// Chinese user can just press Enter. The choice is applied immediately via setLocale() so every
|
|
701
|
+
// subsequent prompt renders in that language, and persisted to config/preferences.json.
|
|
702
|
+
const detected = detectSystemLocale();
|
|
703
|
+
const langSel = await clack.select({
|
|
704
|
+
message: 'Select language / 选择语言',
|
|
705
|
+
options: [
|
|
706
|
+
{ value: 'en', label: 'English' },
|
|
707
|
+
{ value: 'zh', label: '中文 (Simplified Chinese)' },
|
|
708
|
+
],
|
|
709
|
+
initialValue: detected,
|
|
710
|
+
});
|
|
711
|
+
handleCancel(langSel);
|
|
712
|
+
const lang = langSel;
|
|
713
|
+
setLocale(lang);
|
|
714
|
+
clack.intro(t('init.intro'));
|
|
761
715
|
// Step 1: Backend selection
|
|
762
|
-
clack.note('
|
|
716
|
+
clack.note(t('init.backend.noteBody'), t('init.backend.noteTitle'));
|
|
763
717
|
const backends = await clack.multiselect({
|
|
764
|
-
message: '
|
|
718
|
+
message: t('init.backend.prompt'),
|
|
765
719
|
options: [
|
|
766
|
-
{ value: 'claude', label: '
|
|
767
|
-
{ value: 'pi', label: '
|
|
720
|
+
{ value: 'claude', label: t('init.backend.claudeLabel'), hint: t('init.backend.claudeHint') },
|
|
721
|
+
{ value: 'pi', label: t('init.backend.piLabel'), hint: t('init.backend.piHint') },
|
|
768
722
|
],
|
|
769
723
|
required: true,
|
|
770
724
|
});
|
|
@@ -772,10 +726,10 @@ async function collectAnswersInteractive(paths) {
|
|
|
772
726
|
// Step 2: Platform selection (multi-select — Slack and Feishu can run simultaneously).
|
|
773
727
|
// Leave empty to skip and configure platforms later by editing .env manually.
|
|
774
728
|
const platformsSel = await clack.multiselect({
|
|
775
|
-
message: '
|
|
729
|
+
message: t('init.platform.prompt'),
|
|
776
730
|
options: [
|
|
777
|
-
{ value: 'slack', label: '
|
|
778
|
-
{ value: 'feishu', label: '
|
|
731
|
+
{ value: 'slack', label: t('init.platform.slackLabel'), hint: t('init.platform.slackHint') },
|
|
732
|
+
{ value: 'feishu', label: t('init.platform.feishuLabel') },
|
|
779
733
|
],
|
|
780
734
|
required: false,
|
|
781
735
|
});
|
|
@@ -796,74 +750,64 @@ async function collectAnswersInteractive(paths) {
|
|
|
796
750
|
// hint to run `cortex feishu login` later). Best-effort: a failed/abandoned login won't abort
|
|
797
751
|
// init — credentials are already captured in feishuConfig and the operator can retry.
|
|
798
752
|
if (feishuConfig.authMode === 'user') {
|
|
799
|
-
clack.log.info(
|
|
753
|
+
clack.log.info(t('init.feishu.loginStarting'));
|
|
800
754
|
const res = await runFeishuUserLogin(feishuConfig, paths.CONFIG_DIR);
|
|
801
755
|
if (res.exitCode === 0) {
|
|
802
|
-
clack.log.success('
|
|
756
|
+
clack.log.success(t('init.feishu.loginComplete'));
|
|
803
757
|
}
|
|
804
758
|
else {
|
|
805
|
-
clack.log.warn('
|
|
759
|
+
clack.log.warn(t('init.feishu.loginIncomplete'));
|
|
806
760
|
}
|
|
807
761
|
}
|
|
808
762
|
}
|
|
809
763
|
// Step 3: Machine identity
|
|
810
764
|
const hostname = os.hostname();
|
|
811
765
|
const machineName = await clack.text({
|
|
812
|
-
message: '
|
|
766
|
+
message: t('init.machine.prompt'),
|
|
813
767
|
placeholder: hostname,
|
|
814
768
|
defaultValue: hostname,
|
|
815
769
|
validate(value) {
|
|
816
770
|
if (!value)
|
|
817
|
-
return '
|
|
771
|
+
return t('init.machine.required');
|
|
818
772
|
},
|
|
819
773
|
});
|
|
820
774
|
handleCancel(machineName);
|
|
821
775
|
// GPU detection
|
|
822
776
|
const gpuCount = detectGpuCount();
|
|
823
777
|
if (gpuCount > 0) {
|
|
824
|
-
clack.log.success(
|
|
778
|
+
clack.log.success(t('init.machine.gpuDetected', { count: gpuCount }));
|
|
825
779
|
}
|
|
826
780
|
else {
|
|
827
|
-
clack.log.info(
|
|
781
|
+
clack.log.info(t('init.machine.gpuNone'));
|
|
828
782
|
}
|
|
829
783
|
// Step 4: Gateway usage
|
|
830
|
-
clack.note(
|
|
831
|
-
'Cortex includes an open-source local gateway that proxies all',
|
|
832
|
-
'LLM calls, providing multi-key rotation, automatic failover,',
|
|
833
|
-
'and per-request cost tracking.',
|
|
834
|
-
'',
|
|
835
|
-
'You can optionally share anonymous token usage with aistatus.cc,',
|
|
836
|
-
'an AI model status monitoring site. Your token usage will appear',
|
|
837
|
-
'on the public leaderboard (name + org + token counts). Email is',
|
|
838
|
-
'used only as an identity key and is never displayed.',
|
|
839
|
-
'',
|
|
840
|
-
'Learn more: https://aistatus.cc',
|
|
841
|
-
].join('\n'), 'Gateway & aistatus');
|
|
784
|
+
clack.note(t('init.gateway.note'), t('init.gateway.noteTitle'));
|
|
842
785
|
const enableGateway = await clack.confirm({
|
|
843
|
-
message: '
|
|
786
|
+
message: t('init.gateway.enablePrompt'),
|
|
844
787
|
initialValue: true,
|
|
845
788
|
});
|
|
846
789
|
handleCancel(enableGateway);
|
|
847
790
|
let gatewayUsage = { enabled: false };
|
|
848
791
|
if (enableGateway) {
|
|
849
|
-
const name = await clack.text({ message: '
|
|
792
|
+
const name = await clack.text({ message: t('init.gateway.namePrompt'), placeholder: t('init.gateway.namePlaceholder') });
|
|
850
793
|
handleCancel(name);
|
|
851
|
-
const org = await clack.text({ message: '
|
|
794
|
+
const org = await clack.text({ message: t('init.gateway.orgPrompt'), placeholder: t('init.gateway.orgPlaceholder') });
|
|
852
795
|
handleCancel(org);
|
|
853
796
|
const email = await clack.text({
|
|
854
|
-
message: '
|
|
855
|
-
placeholder: '
|
|
797
|
+
message: t('init.gateway.emailPrompt'),
|
|
798
|
+
placeholder: t('init.gateway.emailPlaceholder'),
|
|
856
799
|
});
|
|
857
800
|
handleCancel(email);
|
|
858
801
|
gatewayUsage = { enabled: true, name: name, org: org, email: email };
|
|
859
802
|
}
|
|
860
803
|
// Step 5: Service registration
|
|
861
804
|
const wantService = await clack.confirm({
|
|
862
|
-
message: '
|
|
805
|
+
message: t('init.serviceRegister.prompt'),
|
|
863
806
|
initialValue: true,
|
|
864
807
|
});
|
|
865
808
|
handleCancel(wantService);
|
|
866
809
|
return {
|
|
810
|
+
lang,
|
|
867
811
|
backends: backends,
|
|
868
812
|
machineName: machineName,
|
|
869
813
|
gpuCount,
|
|
@@ -903,40 +847,38 @@ async function collectAnswersNonInteractive() {
|
|
|
903
847
|
const gatewayEnabled = gatewayEnabledRaw?.toLowerCase() === 'y';
|
|
904
848
|
log.info('Cortex Initialization (non-interactive)');
|
|
905
849
|
// Parse platform token blocks from remaining lines (starting at index 7). Blocks are
|
|
906
|
-
// concatenated in fixed order — slack (
|
|
850
|
+
// concatenated in fixed order — slack (3 lines), then feishu (3 lines) — regardless of the
|
|
907
851
|
// order given in the platform list. The profile-choice lines (optional "mode:model"; empty
|
|
908
852
|
// → auto-infer) follow whatever token lines were consumed. Single-platform layouts are
|
|
909
|
-
// back-compatible: slack-only → choices at
|
|
853
|
+
// back-compatible: slack-only → choices at 10; feishu-only → choices at 10.
|
|
910
854
|
let slackConfig;
|
|
911
855
|
let feishuConfig;
|
|
912
856
|
let cursor = 7;
|
|
913
|
-
if (platforms.includes('slack') && lines.length >= cursor +
|
|
857
|
+
if (platforms.includes('slack') && lines.length >= cursor + 3) {
|
|
914
858
|
slackConfig = {
|
|
915
859
|
signingSecret: lines[cursor] || '',
|
|
916
860
|
appToken: lines[cursor + 1] || '',
|
|
917
861
|
botToken: lines[cursor + 2] || '',
|
|
918
|
-
adminChannel: lines[cursor + 3]?.trim() || undefined,
|
|
919
862
|
};
|
|
920
|
-
cursor +=
|
|
863
|
+
cursor += 3;
|
|
921
864
|
}
|
|
922
|
-
if (platforms.includes('feishu') && lines.length >= cursor +
|
|
923
|
-
const domainVal = (lines[cursor +
|
|
865
|
+
if (platforms.includes('feishu') && lines.length >= cursor + 3) {
|
|
866
|
+
const domainVal = (lines[cursor + 2] || '').trim().toLowerCase();
|
|
924
867
|
feishuConfig = {
|
|
925
868
|
appId: lines[cursor] || '',
|
|
926
869
|
appSecret: lines[cursor + 1] || '',
|
|
927
|
-
encryptKey: lines[cursor + 2]?.trim() || undefined,
|
|
928
|
-
verificationToken: lines[cursor + 3]?.trim() || undefined,
|
|
929
870
|
domain: (domainVal === 'feishu' || domainVal === 'lark')
|
|
930
871
|
? domainVal
|
|
931
872
|
: undefined,
|
|
932
873
|
};
|
|
933
|
-
cursor +=
|
|
874
|
+
cursor += 3;
|
|
934
875
|
}
|
|
935
876
|
const profileChoiceStart = cursor;
|
|
936
877
|
const planChoice = parseChoiceLine(lines[profileChoiceStart]);
|
|
937
878
|
const executeChoice = parseChoiceLine(lines[profileChoiceStart + 1]);
|
|
938
879
|
const extraProfiles = parseExtraProfilesLine(lines[profileChoiceStart + 2]);
|
|
939
880
|
return {
|
|
881
|
+
lang: process.env.CORTEX_LANG ? normalizeLocale(process.env.CORTEX_LANG) : detectSystemLocale(),
|
|
940
882
|
backends: backends.length > 0 ? backends : ['claude'],
|
|
941
883
|
machineName: os.hostname(),
|
|
942
884
|
gpuCount: detectGpuCount(),
|
|
@@ -1038,7 +980,7 @@ export function getGitInstallHint() {
|
|
|
1038
980
|
export function ensureGitInstalled() {
|
|
1039
981
|
if (isGitInstalled())
|
|
1040
982
|
return true;
|
|
1041
|
-
clack.log.warn('
|
|
983
|
+
clack.log.warn(t('init.git.required'));
|
|
1042
984
|
// Build the auto-install command for the current platform
|
|
1043
985
|
let installCmd = null;
|
|
1044
986
|
if (process.platform === 'linux') {
|
|
@@ -1061,22 +1003,22 @@ export function ensureGitInstalled() {
|
|
|
1061
1003
|
}
|
|
1062
1004
|
if (installCmd) {
|
|
1063
1005
|
const s = clack.spinner();
|
|
1064
|
-
s.start('
|
|
1006
|
+
s.start(t('init.git.autoInstalling'));
|
|
1065
1007
|
try {
|
|
1066
1008
|
execSync(installCmd, { stdio: 'pipe', timeout: 120_000 });
|
|
1067
|
-
s.stop('
|
|
1009
|
+
s.stop(t('init.git.installed'));
|
|
1068
1010
|
// Verify the install actually put git on PATH
|
|
1069
1011
|
if (isGitInstalled())
|
|
1070
1012
|
return true;
|
|
1071
|
-
clack.log.warn('
|
|
1013
|
+
clack.log.warn(t('init.git.notOnPath'));
|
|
1072
1014
|
}
|
|
1073
1015
|
catch (err) {
|
|
1074
|
-
s.stop('
|
|
1016
|
+
s.stop(t('init.git.autoInstallFailed'));
|
|
1075
1017
|
clack.log.warn(err.message);
|
|
1076
1018
|
}
|
|
1077
1019
|
}
|
|
1078
1020
|
const hint = getGitInstallHint();
|
|
1079
|
-
clack.log.info(
|
|
1021
|
+
clack.log.info(t('init.git.manualHint', { hint }));
|
|
1080
1022
|
return false;
|
|
1081
1023
|
}
|
|
1082
1024
|
// ─── Git repo initialization ────────────────────────────────────
|
|
@@ -1087,7 +1029,7 @@ function ensureGitRepo(dataDir) {
|
|
|
1087
1029
|
execSync('git init', { cwd: dataDir, stdio: 'pipe' });
|
|
1088
1030
|
}
|
|
1089
1031
|
catch (err) {
|
|
1090
|
-
clack.log.warn(
|
|
1032
|
+
clack.log.warn(t('init.git.initFailed', { message: err.message }));
|
|
1091
1033
|
}
|
|
1092
1034
|
}
|
|
1093
1035
|
// ─── Safe copy helpers ──────────────────────────────────────────
|
|
@@ -1169,7 +1111,7 @@ function deployHooks(paths, force) {
|
|
|
1169
1111
|
safeCopy(src, dst, force, `hooks/${file}`);
|
|
1170
1112
|
}
|
|
1171
1113
|
}
|
|
1172
|
-
function generateConfigs(paths, answers, force) {
|
|
1114
|
+
export function generateConfigs(paths, answers, force) {
|
|
1173
1115
|
// MCP configs — always regenerate (machine-specific, in .gitignore)
|
|
1174
1116
|
writeFileSync(path.join(paths.CONFIG_DIR, 'mcp-config.json'), JSON.stringify(buildFullConfig(INSTALL_ROOT), null, 2));
|
|
1175
1117
|
writeFileSync(path.join(paths.CONFIG_DIR, 'mcp-config-core.json'), JSON.stringify(buildCoreConfig(INSTALL_ROOT), null, 2));
|
|
@@ -1180,6 +1122,12 @@ function generateConfigs(paths, answers, force) {
|
|
|
1180
1122
|
const primaryBackend = answers.backends[0] || 'claude';
|
|
1181
1123
|
writeFileSync(modeJsonPath, generateDefaultModeJson(primaryBackend));
|
|
1182
1124
|
}
|
|
1125
|
+
// preferences.json — operator UI language (read at startup by domain/system/preferences.ts).
|
|
1126
|
+
// Skip if exists (user may have changed it via !lang) unless --force.
|
|
1127
|
+
const prefsJsonPath = path.join(paths.CONFIG_DIR, 'preferences.json');
|
|
1128
|
+
if (!existsSync(prefsJsonPath) || force) {
|
|
1129
|
+
writeFileSync(prefsJsonPath, JSON.stringify({ lang: answers.lang }, null, 2) + '\n');
|
|
1130
|
+
}
|
|
1183
1131
|
// machines.json — runtime machine registry, server won't start without it
|
|
1184
1132
|
const machinesJsonPath = path.join(paths.CONFIG_DIR, 'machines.json');
|
|
1185
1133
|
if (!existsSync(machinesJsonPath) || force) {
|
|
@@ -1193,8 +1141,9 @@ function generateConfigs(paths, answers, force) {
|
|
|
1193
1141
|
}
|
|
1194
1142
|
/**
|
|
1195
1143
|
* Seed schedules.json from defaults/data/schedules.json into STORE_DIR.
|
|
1196
|
-
*
|
|
1197
|
-
*
|
|
1144
|
+
* The __ADMIN_CHANNEL__ placeholder resolves to an empty channel: the admin channel is
|
|
1145
|
+
* auto-detected at runtime (first DM to the bot) rather than collected during init.
|
|
1146
|
+
* Stamps createdAt with the current timestamp. Never overwrites existing file.
|
|
1198
1147
|
*/
|
|
1199
1148
|
function seedSchedules(paths, answers, force) {
|
|
1200
1149
|
const dstPath = path.join(paths.STORE_DIR, 'schedules.json');
|
|
@@ -1203,7 +1152,7 @@ function seedSchedules(paths, answers, force) {
|
|
|
1203
1152
|
const srcPath = path.join(DEFAULTS_DIR, 'data', 'schedules.json');
|
|
1204
1153
|
if (!existsSync(srcPath))
|
|
1205
1154
|
return;
|
|
1206
|
-
const adminChannel =
|
|
1155
|
+
const adminChannel = '';
|
|
1207
1156
|
const now = Date.now();
|
|
1208
1157
|
let content = readFileSync(srcPath, 'utf-8');
|
|
1209
1158
|
content = content.replace(/__ADMIN_CHANNEL__/g, adminChannel);
|
|
@@ -1248,7 +1197,7 @@ async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
|
1248
1197
|
// If existing profiles.json has plan/execute, ask before overwriting
|
|
1249
1198
|
if (detectExistingPlanOrExecute(configDir)) {
|
|
1250
1199
|
const confirm = await clack.confirm({
|
|
1251
|
-
message: '
|
|
1200
|
+
message: t('init.gatewaySetup.overwritePrompt'),
|
|
1252
1201
|
initialValue: false,
|
|
1253
1202
|
});
|
|
1254
1203
|
handleCancel(confirm);
|
|
@@ -1271,13 +1220,13 @@ async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
|
1271
1220
|
// Default = first lexicographic entry (no tier inference).
|
|
1272
1221
|
const firstChoiceValue = formatValue(choices[0]);
|
|
1273
1222
|
const planSel = await clack.select({
|
|
1274
|
-
message: '
|
|
1223
|
+
message: t('init.gatewaySetup.planPrompt'),
|
|
1275
1224
|
options,
|
|
1276
1225
|
initialValue: firstChoiceValue,
|
|
1277
1226
|
});
|
|
1278
1227
|
handleCancel(planSel);
|
|
1279
1228
|
const execSel = await clack.select({
|
|
1280
|
-
message: '
|
|
1229
|
+
message: t('init.gatewaySetup.executePrompt'),
|
|
1281
1230
|
options,
|
|
1282
1231
|
initialValue: firstChoiceValue,
|
|
1283
1232
|
});
|
|
@@ -1292,7 +1241,7 @@ async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
|
1292
1241
|
let planFallback;
|
|
1293
1242
|
if (planFallbackOptions.length > 0) {
|
|
1294
1243
|
const sel = await clack.multiselect({
|
|
1295
|
-
message: '
|
|
1244
|
+
message: t('init.gatewaySetup.planFallbackPrompt'),
|
|
1296
1245
|
options: planFallbackOptions,
|
|
1297
1246
|
required: false,
|
|
1298
1247
|
initialValues: [],
|
|
@@ -1305,7 +1254,7 @@ async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
|
1305
1254
|
let executeFallback;
|
|
1306
1255
|
if (execFallbackOptions.length > 0) {
|
|
1307
1256
|
const sel = await clack.multiselect({
|
|
1308
|
-
message: '
|
|
1257
|
+
message: t('init.gatewaySetup.executeFallbackPrompt'),
|
|
1309
1258
|
options: execFallbackOptions,
|
|
1310
1259
|
required: false,
|
|
1311
1260
|
initialValues: [],
|
|
@@ -1319,7 +1268,7 @@ async function pickPlanExecuteInteractive(endpoints, configDir) {
|
|
|
1319
1268
|
let extraProfiles;
|
|
1320
1269
|
if (options.length > 0) {
|
|
1321
1270
|
const sel = await clack.multiselect({
|
|
1322
|
-
message: '
|
|
1271
|
+
message: t('init.gatewaySetup.extraProfilesPrompt'),
|
|
1323
1272
|
options,
|
|
1324
1273
|
required: false,
|
|
1325
1274
|
initialValues: [],
|
|
@@ -1342,23 +1291,23 @@ async function runGatewaySetup(backends, paths, gatewayConfigDir, answers) {
|
|
|
1342
1291
|
// Discover endpoints from Claude/PI local configs — filtered by user-selected backends
|
|
1343
1292
|
const endpoints = discoverEndpoints(backends);
|
|
1344
1293
|
if (endpoints.length === 0) {
|
|
1345
|
-
clack.log.warn('
|
|
1346
|
-
clack.log.info('
|
|
1294
|
+
clack.log.warn(t('init.gatewaySetup.noBackends'));
|
|
1295
|
+
clack.log.info(t('init.gatewaySetup.rerunHint'));
|
|
1347
1296
|
return;
|
|
1348
1297
|
}
|
|
1349
1298
|
// Show discovered summary
|
|
1350
1299
|
const summary = endpoints.map(ep => ` ${ep.mode}/${ep.endpoint}: ${ep.models.slice(0, 3).join(', ')}${ep.models.length > 3 ? ', ...' : ''} (${ep.keys.length > 0 ? 'with key' : 'passthrough'})`).join('\n');
|
|
1351
|
-
clack.log.success(
|
|
1300
|
+
clack.log.success(t('init.gatewaySetup.discovered', { count: endpoints.length, summary }));
|
|
1352
1301
|
// Generate gateway.yaml — scoped to gatewayConfigDir when provided (test/alt env),
|
|
1353
1302
|
// otherwise defaults to ~/.aistatus/gateway.yaml (production). Merge-aware: preserves
|
|
1354
1303
|
// hand-maintained modes/keys and never drops previously-configured modes if discovery
|
|
1355
1304
|
// under-reports (e.g. a transient `pi --list-models` failure).
|
|
1356
1305
|
const { path: gatewayPath, result: mergeResult } = writeMergedGatewayYaml(endpoints, gatewayConfigDir);
|
|
1357
|
-
clack.log.success(
|
|
1306
|
+
clack.log.success(t('init.gatewaySetup.gatewayWritten', { path: gatewayPath }));
|
|
1358
1307
|
if (mergeResult.droppedFromDiscovery.length > 0) {
|
|
1359
1308
|
const list = mergeResult.droppedFromDiscovery.map(p => `${p.mode}/${p.endpoint}`).join(', ');
|
|
1360
|
-
clack.log.warn(
|
|
1361
|
-
clack.log.info('
|
|
1309
|
+
clack.log.warn(t('init.gatewaySetup.preservedModes', { count: mergeResult.droppedFromDiscovery.length, list }));
|
|
1310
|
+
clack.log.info(t('init.gatewaySetup.preservedModesHint'));
|
|
1362
1311
|
}
|
|
1363
1312
|
// Resolve plan/execute choices + fallback chains + extra profiles + overwrite intent.
|
|
1364
1313
|
let planChoice = answers?.planChoice;
|
|
@@ -1393,18 +1342,18 @@ async function runGatewaySetup(backends, paths, gatewayConfigDir, answers) {
|
|
|
1393
1342
|
extraProfiles,
|
|
1394
1343
|
overwrite,
|
|
1395
1344
|
});
|
|
1396
|
-
clack.log.success(
|
|
1345
|
+
clack.log.success(t('init.gatewaySetup.profilesWritten', { path: profilesPath }));
|
|
1397
1346
|
// Show profile summary (reflects what was actually generated, not what was merged)
|
|
1398
1347
|
const profiles = generateProfiles(endpoints, { planChoice, executeChoice, planFallback, executeFallback, extraProfiles });
|
|
1399
1348
|
const profileNames = Object.keys(profiles.profiles).join(', ');
|
|
1400
|
-
clack.log.info(
|
|
1349
|
+
clack.log.info(t('init.gatewaySetup.generatedProfiles', { names: profileNames, default: profiles.defaultProfile }));
|
|
1401
1350
|
// Validate profile ↔ gateway mode coupling. A profile referencing a non-existent gateway mode is
|
|
1402
1351
|
// exactly what produces a silent `400 Unknown mode: <x>` at runtime. Non-fatal — warn only.
|
|
1403
1352
|
const issues = validateProfilesAgainstGateway(mergeResult.endpoints, paths.CONFIG_DIR);
|
|
1404
1353
|
if (issues.length > 0) {
|
|
1405
1354
|
const lines = issues.map(i => ` - ${i.profile}: ${i.reason}`).join('\n');
|
|
1406
|
-
clack.log.warn(
|
|
1407
|
-
clack.log.info('
|
|
1355
|
+
clack.log.warn(t('init.gatewaySetup.profileIssues', { count: issues.length, lines }));
|
|
1356
|
+
clack.log.info(t('init.gatewaySetup.profileIssuesHint'));
|
|
1408
1357
|
}
|
|
1409
1358
|
}
|
|
1410
1359
|
export async function runInit(options = {}) {
|
|
@@ -1427,7 +1376,7 @@ export async function runInit(options = {}) {
|
|
|
1427
1376
|
generateConfigs(paths, answers, force);
|
|
1428
1377
|
seedSchedules(paths, answers, force);
|
|
1429
1378
|
// 5. Gateway usage
|
|
1430
|
-
writeGatewayUsageConfig(answers.gatewayUsage,
|
|
1379
|
+
writeGatewayUsageConfig(answers.gatewayUsage, options.gatewayConfigDir);
|
|
1431
1380
|
// 6. Service registration
|
|
1432
1381
|
if (answers.installService) {
|
|
1433
1382
|
installService(paths.DATA_DIR);
|
|
@@ -1436,19 +1385,13 @@ export async function runInit(options = {}) {
|
|
|
1436
1385
|
if (processStdin.isTTY) {
|
|
1437
1386
|
const loginHints = answers.backends.map(b => {
|
|
1438
1387
|
const info = BACKEND_INFO[b];
|
|
1439
|
-
return ` • ${info.
|
|
1388
|
+
return ` • ${t(info.labelKey)}: ${t(info.loginHintKey).replace(/^Run /, '').replace(/\.$/, '')}`;
|
|
1440
1389
|
}).join('\n');
|
|
1441
|
-
clack.note(
|
|
1442
|
-
'Cortex can auto-detect your Claude Code and PI configurations',
|
|
1443
|
-
'to generate gateway.yaml and profiles.json automatically.',
|
|
1444
|
-
'',
|
|
1445
|
-
'Make sure you have logged into:',
|
|
1446
|
-
loginHints,
|
|
1447
|
-
].join('\n'), 'Gateway & Profile Setup');
|
|
1390
|
+
clack.note(t('init.gatewayProfile.note', { loginHints }), t('init.gatewayProfile.noteTitle'));
|
|
1448
1391
|
let gatewayDone = false;
|
|
1449
1392
|
while (!gatewayDone) {
|
|
1450
1393
|
const ready = await clack.confirm({
|
|
1451
|
-
message: '
|
|
1394
|
+
message: t('init.gatewayProfile.readyPrompt'),
|
|
1452
1395
|
initialValue: true,
|
|
1453
1396
|
});
|
|
1454
1397
|
handleCancel(ready);
|
|
@@ -1458,17 +1401,17 @@ export async function runInit(options = {}) {
|
|
|
1458
1401
|
}
|
|
1459
1402
|
else {
|
|
1460
1403
|
// User hasn't logged in yet — let them choose to go log in or skip entirely
|
|
1461
|
-
clack.log.info(
|
|
1404
|
+
clack.log.info(t('init.gatewayProfile.loginNow', { loginHints }));
|
|
1462
1405
|
const action = await clack.select({
|
|
1463
|
-
message: '
|
|
1406
|
+
message: t('init.gatewayProfile.actionPrompt'),
|
|
1464
1407
|
options: [
|
|
1465
|
-
{ value: 'retry', label: '
|
|
1466
|
-
{ value: 'skip', label: '
|
|
1408
|
+
{ value: 'retry', label: t('init.gatewayProfile.retryLabel') },
|
|
1409
|
+
{ value: 'skip', label: t('init.gatewayProfile.skipLabel') },
|
|
1467
1410
|
],
|
|
1468
1411
|
});
|
|
1469
1412
|
handleCancel(action);
|
|
1470
1413
|
if (action === 'skip') {
|
|
1471
|
-
clack.log.info('
|
|
1414
|
+
clack.log.info(t('init.gatewayProfile.skipped'));
|
|
1472
1415
|
gatewayDone = true;
|
|
1473
1416
|
}
|
|
1474
1417
|
// action === 'retry' → loop continues, re-prompt the confirm
|
|
@@ -1502,5 +1445,5 @@ export async function runInit(options = {}) {
|
|
|
1502
1445
|
log.warn(`Failed to update activeProfile in mode.json: ${e.message}`);
|
|
1503
1446
|
}
|
|
1504
1447
|
// 9. Done
|
|
1505
|
-
clack.outro(
|
|
1448
|
+
clack.outro(t('init.outro', { dataDir: paths.DATA_DIR }));
|
|
1506
1449
|
}
|