@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
package/dist/entry/app.js
CHANGED
|
@@ -6,7 +6,8 @@ import * as dotenv from 'dotenv';
|
|
|
6
6
|
import { mkdirSync } from 'fs';
|
|
7
7
|
import * as path from 'path';
|
|
8
8
|
import { createAdapterFromEnv, extractTuiAdapter } from '../platform/index.js';
|
|
9
|
-
import { WORKSPACE_DIR, CONFIG_DIR } from '../core/utils.js';
|
|
9
|
+
import { WORKSPACE_DIR, CONFIG_DIR, DATA_DIR, STORE_DIR } from '../core/utils.js';
|
|
10
|
+
import { tryAcquireSingletonLock, releaseSingletonLock } from '../core/singleton-lock.js';
|
|
10
11
|
import { closeAllSessions, closeSession as closeClaudePooledSession, shutdownCodex } from '../domain/agents/index.js';
|
|
11
12
|
import { closeAllAdapters } from '../agent-adapter/index.js';
|
|
12
13
|
import { recoverTuiOrphans } from '../agent-adapter/claude/adapter.js';
|
|
@@ -30,8 +31,10 @@ import { conversationLedger } from '../store/conversation-ledger-repo.js';
|
|
|
30
31
|
import { executionRepo } from '../store/execution-repo.js';
|
|
31
32
|
import { loadConfig as loadThreadConfig, startConfigWatcher as startThreadConfigWatcher, setAdminNotifier as setConfigNotifier } from '../domain/threads/index.js';
|
|
32
33
|
import { startMemoryWatcher } from '../domain/memory/watcher.js';
|
|
33
|
-
import { getActiveBackend } from '../domain/agents/index.js';
|
|
34
|
+
import { getActiveBackend, configureEnvForMode, loadMode } from '../domain/agents/index.js';
|
|
34
35
|
import { createEditHandler } from '../orchestration/routing/edit-handler.js';
|
|
36
|
+
import { setLocale, normalizeLocale } from '../core/i18n.js';
|
|
37
|
+
import { loadLang } from '../domain/system/preferences.js';
|
|
35
38
|
// Extracted modules
|
|
36
39
|
import { cleanupLogs, ensureMcpConfig } from './startup-helpers.js';
|
|
37
40
|
import { createLogger } from '../core/log.js';
|
|
@@ -50,7 +53,7 @@ import { createUpdatePrompt } from '../orchestration/interactions/update-prompt.
|
|
|
50
53
|
import { registerMessageHandler } from '../orchestration/routing/message-router.js';
|
|
51
54
|
import { initRateLimitThrottle } from '../domain/costs/rate-limit-throttle.js';
|
|
52
55
|
import { scheduleRepo } from '../store/schedule-repo.js';
|
|
53
|
-
import { runMigrations } from '../store/version-migrations.js';
|
|
56
|
+
import { runMigrations, migrateAistatusConfigLocation } from '../store/version-migrations.js';
|
|
54
57
|
import { syncManagedHooks } from '../store/hook-sync.js';
|
|
55
58
|
import { costRepo } from '../store/cost-repo.js';
|
|
56
59
|
import { profileRepo, startProfileWatcher, setAdminNotifier as setProfileNotifier } from '../store/profile-repo.js';
|
|
@@ -68,7 +71,35 @@ import { createTuiSessionService } from '../domain/tui-session/index.js';
|
|
|
68
71
|
import { enqueue, conduitQueues } from '../orchestration/conduit-queue.js';
|
|
69
72
|
import { getCostSummary } from '../domain/costs/cost-tracker.js';
|
|
70
73
|
dotenv.config({ path: path.join(CONFIG_DIR, '.env') });
|
|
74
|
+
// Apply the persisted mode to env now that .env is loaded. This used to be an import-time
|
|
75
|
+
// side effect inside domain/agents/config.ts; it is explicit here so that CLI processes
|
|
76
|
+
// (cortex init / setup-gateway) importing that module don't get their env mutated.
|
|
77
|
+
configureEnvForMode(loadMode());
|
|
78
|
+
// Resolve the UI language for all system-generated user-facing text. Precedence:
|
|
79
|
+
// CORTEX_LANG env (escape hatch, now that .env is loaded) > config/preferences.json > 'en'.
|
|
80
|
+
// The !lang command switches this live at runtime via setLocale().
|
|
81
|
+
setLocale(process.env.CORTEX_LANG ? normalizeLocale(process.env.CORTEX_LANG) : loadLang());
|
|
71
82
|
const log = createLogger('app');
|
|
83
|
+
// --- Singleton lock ---
|
|
84
|
+
// app.js owns ports 3001 (webhook) / 3002 (client-manager); a second instance would
|
|
85
|
+
// crash-loop on EADDRINUSE. The daemon's own daemon.pid lock only guards the supervisor
|
|
86
|
+
// layer and does nothing for `cortex start` (which forks app.js directly, bypassing the
|
|
87
|
+
// daemon). Acquire our own app.pid lock here, as early as possible, to fail fast before
|
|
88
|
+
// any heavy initialization or port binding. Stale locks (previous owner SIGKILL'd / crashed)
|
|
89
|
+
// are reclaimed automatically. Released on process exit (covers SIGTERM→exit(0) and Ctrl+C).
|
|
90
|
+
const APP_PID_FILE = path.join(STORE_DIR, 'app.pid');
|
|
91
|
+
const appLock = tryAcquireSingletonLock(APP_PID_FILE);
|
|
92
|
+
if (appLock.acquired) {
|
|
93
|
+
if (appLock.stale)
|
|
94
|
+
log.info(`Reclaimed stale app.pid lock for PID ${process.pid}`);
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
log.error(`Another Cortex app.js is already running (PID ${appLock.holderPid}, lockfile ${APP_PID_FILE}).\n` +
|
|
98
|
+
` Refusing to start a second instance — it already holds ports 3001/3002; this process would crash on EADDRINUSE.\n` +
|
|
99
|
+
` Inspect with \`cortex daemon status\`, or stop the running instance before retrying.`);
|
|
100
|
+
process.exit(1);
|
|
101
|
+
}
|
|
102
|
+
process.on('exit', () => releaseSingletonLock(APP_PID_FILE));
|
|
72
103
|
// --- Crash safety net ---
|
|
73
104
|
// A single failed outbound post while handling an inbound message must never take
|
|
74
105
|
// down the whole server. Detached per-conduit queue work (conduit-queue.ts) and
|
|
@@ -214,6 +245,8 @@ process.on('SIGTERM', async () => {
|
|
|
214
245
|
cleanupLogs();
|
|
215
246
|
ensureMcpConfig();
|
|
216
247
|
await runMigrations();
|
|
248
|
+
// Migrate old aistatus config from wrong location (CORTEX_HOME/config) to correct location (~/.aistatus)
|
|
249
|
+
await migrateAistatusConfigLocation(DATA_DIR);
|
|
217
250
|
// Refresh version-stamped hooks in DATA_DIR/hooks from the shipped defaults. init's deployHooks
|
|
218
251
|
// only copies-if-missing, so without this an existing install never picks up hook code fixes.
|
|
219
252
|
await syncManagedHooks();
|
package/dist/entry/daemon.js
CHANGED
|
@@ -36,10 +36,11 @@
|
|
|
36
36
|
*/
|
|
37
37
|
import * as dotenv from 'dotenv';
|
|
38
38
|
import { fork, spawn } from 'child_process';
|
|
39
|
-
import { watch, existsSync, unlinkSync, statSync,
|
|
39
|
+
import { watch, existsSync, unlinkSync, statSync, writeFileSync, readdirSync } from 'fs';
|
|
40
40
|
import * as path from 'path';
|
|
41
41
|
import { createLogger } from '../core/log.js';
|
|
42
42
|
import { isMainModule, moduleDir, DATA_DIR, CONFIG_DIR, STORE_DIR } from '../core/utils.js';
|
|
43
|
+
import { tryAcquireSingletonLock, releaseSingletonLock as releaseLock } from '../core/singleton-lock.js';
|
|
43
44
|
// Load .env BEFORE reading any CORTEX_* env vars below. Mirrors app.ts §61 — the
|
|
44
45
|
// daemon needs CORTEX_REPO (and potentially other vars) from .env, not just from
|
|
45
46
|
// the OS shell env. Must be sync and before the `CORTEX_REPO` constant below.
|
|
@@ -479,39 +480,20 @@ function setupShutdown() {
|
|
|
479
480
|
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
|
480
481
|
}
|
|
481
482
|
function acquireSingletonLock() {
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
const otherPid = Number(raw);
|
|
485
|
-
if (Number.isFinite(otherPid) && otherPid > 0) {
|
|
486
|
-
let alive = false;
|
|
487
|
-
try {
|
|
488
|
-
process.kill(otherPid, 0);
|
|
489
|
-
alive = true;
|
|
490
|
-
}
|
|
491
|
-
catch {
|
|
492
|
-
alive = false;
|
|
493
|
-
}
|
|
494
|
-
if (alive) {
|
|
495
|
-
log.error(`Another Cortex daemon is already running (PID ${otherPid}, lockfile ${PID_FILE}).\n` +
|
|
496
|
-
` Refusing to start a second instance — its app.ts already holds ports 3001/3002 and your child would crash-loop on EADDRINUSE.\n` +
|
|
497
|
-
` To restart the running daemon: \`touch agent-server/.restart\` (hot reload), or send SIGTERM to PID ${otherPid} and rerun.`);
|
|
498
|
-
process.exit(1);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
483
|
+
const result = tryAcquireSingletonLock(PID_FILE);
|
|
484
|
+
if (result.acquired) {
|
|
501
485
|
// Stale lock — previous daemon died without cleanup
|
|
502
|
-
|
|
486
|
+
if (result.stale)
|
|
487
|
+
log.info(`Removed stale PID file and reclaimed lock for PID ${process.pid}`);
|
|
488
|
+
return;
|
|
503
489
|
}
|
|
504
|
-
|
|
490
|
+
log.error(`Another Cortex daemon is already running (PID ${result.holderPid}, lockfile ${PID_FILE}).\n` +
|
|
491
|
+
` Refusing to start a second instance — its app.ts already holds ports 3001/3002 and your child would crash-loop on EADDRINUSE.\n` +
|
|
492
|
+
` To restart the running daemon: \`touch agent-server/.restart\` (hot reload), or send SIGTERM to PID ${result.holderPid} and rerun.`);
|
|
493
|
+
process.exit(1);
|
|
505
494
|
}
|
|
506
495
|
function releaseSingletonLock() {
|
|
507
|
-
|
|
508
|
-
if (!existsSync(PID_FILE))
|
|
509
|
-
return;
|
|
510
|
-
const raw = readFileSync(PID_FILE, 'utf8').trim();
|
|
511
|
-
if (Number(raw) === process.pid)
|
|
512
|
-
unlinkSync(PID_FILE);
|
|
513
|
-
}
|
|
514
|
-
catch { }
|
|
496
|
+
releaseLock(PID_FILE);
|
|
515
497
|
try {
|
|
516
498
|
if (existsSync(CHILD_PID_FILE))
|
|
517
499
|
unlinkSync(CHILD_PID_FILE);
|
package/dist/entry/init.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ModelChoice } from '../core/profile-generator.js';
|
|
2
|
+
import { type Locale } from '../core/i18n.js';
|
|
2
3
|
import { cmdFeishu, type CliResult } from './feishu-login.js';
|
|
3
4
|
export interface InitPaths {
|
|
4
5
|
DATA_DIR: string;
|
|
@@ -19,13 +20,10 @@ export interface SlackInitConfig {
|
|
|
19
20
|
botToken: string;
|
|
20
21
|
signingSecret: string;
|
|
21
22
|
appToken: string;
|
|
22
|
-
adminChannel?: string;
|
|
23
23
|
}
|
|
24
24
|
export interface FeishuInitConfig {
|
|
25
25
|
appId: string;
|
|
26
26
|
appSecret: string;
|
|
27
|
-
encryptKey?: string;
|
|
28
|
-
verificationToken?: string;
|
|
29
27
|
domain?: 'feishu' | 'lark';
|
|
30
28
|
/** Identity for MCP document operations: 'bot' (default) or the operator's 'user' account. */
|
|
31
29
|
authMode?: 'bot' | 'user';
|
|
@@ -37,6 +35,8 @@ export interface GatewayUsageConfig {
|
|
|
37
35
|
email?: string;
|
|
38
36
|
}
|
|
39
37
|
export interface InitAnswers {
|
|
38
|
+
/** UI language for system-generated messages. Persisted to config/preferences.json. */
|
|
39
|
+
lang: Locale;
|
|
40
40
|
backends: InitBackend[];
|
|
41
41
|
machineName: string;
|
|
42
42
|
gpuCount: number;
|
|
@@ -107,6 +107,7 @@ export declare function getGitInstallHint(): string;
|
|
|
107
107
|
*/
|
|
108
108
|
export declare function ensureGitInstalled(): boolean;
|
|
109
109
|
export declare function safeCopy(src: string, dst: string, force: boolean, _label: string): boolean;
|
|
110
|
+
export declare function generateConfigs(paths: InitPaths, answers: InitAnswers, force: boolean): void;
|
|
110
111
|
export interface InitOptions {
|
|
111
112
|
homeDir?: string;
|
|
112
113
|
force?: boolean;
|