@cortex-agent/server 2026.10.21 → 2026.10.25
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/README.md +10 -6
- package/defaults/context/projects/AGENTS.md +1 -1
- package/defaults/gitignore +3 -3
- package/defaults/hooks/new-session-hook.mjs +1 -1
- package/defaults/hooks/status-md-guard.mjs +6 -6
- package/defaults/plugins/cortex-system/plugin.json +1 -1
- package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
- package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
- package/defaults/rules/agents-md.md +1 -1
- package/defaults/rules/issues-md.md +1 -1
- package/defaults/rules/meta-conventions.md +3 -3
- package/defaults/rules/mission-md.md +1 -1
- package/defaults/rules/status-md.md +1 -1
- package/dist/agent-adapter/claude/bg-task-tracker.d.ts +3 -1
- package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
- package/dist/agent-adapter/claude/mcp-config.js +11 -0
- package/dist/agent-adapter/claude/turn-machine.d.ts +2 -1
- package/dist/agent-adapter/claude/turn-machine.js +8 -5
- package/dist/agent-adapter/continuation-phase.d.ts +6 -3
- package/dist/agent-adapter/continuation-phase.js +8 -3
- package/dist/agent-adapter/run-events.d.ts +4 -0
- package/dist/agent-adapter/types.d.ts +9 -2
- package/dist/build-info.json +1 -0
- package/dist/client-bundle/client.mjs +10 -5
- package/dist/client-bundle/manifest.json +2 -2
- package/dist/core/claude-credentials.d.ts +6 -0
- package/dist/core/claude-credentials.js +11 -0
- package/dist/core/gateway-generator.d.ts +17 -0
- package/dist/core/gateway-generator.js +42 -4
- package/dist/core/hook-bus.d.ts +1 -1
- package/dist/core/hook-bus.js +1 -8
- package/dist/core/locales/en.d.ts +1 -0
- package/dist/core/locales/slices/init.d.ts +1 -0
- package/dist/core/locales/slices/init.js +2 -0
- package/dist/core/log.d.ts +3 -0
- package/dist/core/log.js +18 -1
- package/dist/core/settings-spec.d.ts +5 -0
- package/dist/core/settings-spec.js +4 -0
- package/dist/core/types/agent-types.d.ts +3 -1
- package/dist/core/types/environment-types.d.ts +1 -6
- package/dist/domain/agents/environments/registry.js +3 -2
- package/dist/domain/agents/environments/schema.d.ts +3 -2
- package/dist/domain/agents/environments/schema.js +4 -3
- package/dist/domain/auth/auth-watch.js +48 -18
- package/dist/domain/mcp/tools/context.d.ts +0 -1
- package/dist/domain/mcp/tools/context.js +0 -1
- package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
- package/dist/domain/monitor/event-loop-monitor.js +5 -1
- package/dist/domain/plugins/authoring.d.ts +8 -1
- package/dist/domain/plugins/authoring.js +24 -9
- package/dist/domain/plugins/runtime-gc.d.ts +7 -0
- package/dist/domain/plugins/runtime-gc.js +52 -19
- package/dist/domain/plugins/runtime.js +2 -1
- package/dist/domain/remote/client-bootstrap.js +1 -1
- package/dist/domain/remote/client-manager.js +6 -1
- package/dist/domain/runs/retryable-errors.js +3 -1
- package/dist/domain/runs/service.d.ts +0 -9
- package/dist/domain/runs/service.js +29 -15
- package/dist/domain/scheduling/builtin-job-controller.d.ts +3 -1
- package/dist/domain/scheduling/builtin-job-controller.js +5 -2
- package/dist/domain/scheduling/builtin-jobs.js +7 -0
- package/dist/domain/scheduling/scheduler.js +14 -5
- package/dist/domain/system/server-update-check.js +2 -1
- package/dist/domain/telemetry/bus-collector.d.ts +3 -0
- package/dist/domain/telemetry/bus-collector.js +22 -0
- package/dist/domain/telemetry/child-exit.d.ts +11 -0
- package/dist/domain/telemetry/child-exit.js +36 -0
- package/dist/domain/telemetry/client-kind.d.ts +4 -0
- package/dist/domain/telemetry/client-kind.js +7 -0
- package/dist/domain/telemetry/crash-limits.d.ts +15 -0
- package/dist/domain/telemetry/crash-limits.js +50 -0
- package/dist/domain/telemetry/crash.d.ts +25 -0
- package/dist/domain/telemetry/crash.js +70 -0
- package/dist/domain/telemetry/daily-upload.d.ts +5 -0
- package/dist/domain/telemetry/daily-upload.js +20 -0
- package/dist/domain/telemetry/daily.d.ts +5 -0
- package/dist/domain/telemetry/daily.js +104 -0
- package/dist/domain/telemetry/endpoint.d.ts +7 -0
- package/dist/domain/telemetry/endpoint.js +40 -0
- package/dist/domain/telemetry/envelope.d.ts +6 -0
- package/dist/domain/telemetry/envelope.js +35 -0
- package/dist/domain/telemetry/error-digest.d.ts +7 -0
- package/dist/domain/telemetry/error-digest.js +43 -0
- package/dist/domain/telemetry/funnel.d.ts +6 -0
- package/dist/domain/telemetry/funnel.js +22 -0
- package/dist/domain/telemetry/gate.d.ts +19 -0
- package/dist/domain/telemetry/gate.js +67 -0
- package/dist/domain/telemetry/heartbeat.d.ts +17 -0
- package/dist/domain/telemetry/heartbeat.js +49 -0
- package/dist/domain/telemetry/info.d.ts +9 -0
- package/dist/domain/telemetry/info.js +12 -0
- package/dist/domain/telemetry/init-answer.d.ts +12 -0
- package/dist/domain/telemetry/init-answer.js +42 -0
- package/dist/domain/telemetry/install-id.d.ts +5 -0
- package/dist/domain/telemetry/install-id.js +42 -0
- package/dist/domain/telemetry/normalize.d.ts +33 -0
- package/dist/domain/telemetry/normalize.js +88 -0
- package/dist/domain/telemetry/outbox.d.ts +18 -0
- package/dist/domain/telemetry/outbox.js +93 -0
- package/dist/domain/telemetry/panic-group.d.ts +4 -0
- package/dist/domain/telemetry/panic-group.js +51 -0
- package/dist/domain/telemetry/paths.d.ts +7 -0
- package/dist/domain/telemetry/paths.js +11 -0
- package/dist/domain/telemetry/redact.d.ts +18 -0
- package/dist/domain/telemetry/redact.js +109 -0
- package/dist/domain/telemetry/rollup-types.d.ts +81 -0
- package/dist/domain/telemetry/rollup-types.js +31 -0
- package/dist/domain/telemetry/rollup.d.ts +16 -0
- package/dist/domain/telemetry/rollup.js +102 -0
- package/dist/domain/telemetry/schema.d.ts +931 -0
- package/dist/domain/telemetry/schema.js +275 -0
- package/dist/domain/telemetry/service.d.ts +34 -0
- package/dist/domain/telemetry/service.js +146 -0
- package/dist/domain/telemetry/state.d.ts +17 -0
- package/dist/domain/telemetry/state.js +29 -0
- package/dist/domain/telemetry/turns.d.ts +17 -0
- package/dist/domain/telemetry/turns.js +176 -0
- package/dist/domain/telemetry/upgrade.d.ts +14 -0
- package/dist/domain/telemetry/upgrade.js +87 -0
- package/dist/domain/telemetry/uploader.d.ts +21 -0
- package/dist/domain/telemetry/uploader.js +82 -0
- package/dist/domain/telemetry/usage.d.ts +25 -0
- package/dist/domain/telemetry/usage.js +153 -0
- package/dist/domain/telemetry/web-report.d.ts +8 -0
- package/dist/domain/telemetry/web-report.js +15 -0
- package/dist/domain/ui-service/app-router.d.ts +69 -25
- package/dist/domain/ui-service/app-router.js +9 -2
- package/dist/domain/ui-service/input-schemas.d.ts +68 -4
- package/dist/domain/ui-service/input-schemas.js +9 -1
- package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
- package/dist/domain/ui-service/mutate/approvals.js +3 -2
- package/dist/domain/ui-service/mutate/plugin-packages.js +1 -1
- package/dist/domain/ui-service/mutate/telemetry.d.ts +5 -0
- package/dist/domain/ui-service/mutate/telemetry.js +6 -0
- package/dist/domain/ui-service/query/approvals.js +4 -3
- package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
- package/dist/domain/ui-service/query/machine-probe.js +3 -2
- package/dist/domain/ui-service/query/models.d.ts +3 -0
- package/dist/domain/ui-service/query/models.js +47 -30
- package/dist/domain/ui-service/query/plugin-source.js +4 -3
- package/dist/domain/ui-service/query/sessions.js +1 -0
- package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
- package/dist/domain/ui-service/query/telemetry.js +4 -0
- package/dist/domain/ui-service/trpc.d.ts +8 -3
- package/dist/domain/ui-service/trpc.js +1 -1
- package/dist/domain/ui-service/types.d.ts +20 -2
- package/dist/domain/ui-service/ui-service.d.ts +33 -4
- package/dist/domain/ui-service/ui-service.js +19 -18
- package/dist/entry/app.js +20 -2
- package/dist/entry/cli-help.js +27 -14
- package/dist/entry/daemon.d.ts +1 -1
- package/dist/entry/daemon.js +86 -72
- package/dist/entry/init.d.ts +3 -0
- package/dist/entry/init.js +50 -28
- package/dist/entry/shutdown.js +3 -0
- package/dist/entry/signal-cli.js +8 -11
- package/dist/entry/start-ui-http.js +40 -18
- package/dist/entry/telemetry-wiring.d.ts +12 -0
- package/dist/entry/telemetry-wiring.js +56 -0
- package/dist/entry/ui-cli.d.ts +0 -11
- package/dist/entry/ui-cli.js +42 -33
- package/dist/events/event-types.d.ts +1 -4
- package/dist/orchestration/routing/message-router.js +2 -0
- package/dist/orchestration/routing/webhook.js +2 -0
- package/dist/orchestration/transcript-sink.d.ts +6 -0
- package/dist/orchestration/transcript-sink.js +17 -0
- package/dist/orchestration/waitpoint-ingress.js +3 -0
- package/dist/platform/ui-http/ui-auth-routes.d.ts +2 -0
- package/dist/platform/ui-http/ui-auth-routes.js +9 -2
- package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
- package/dist/platform/ui-http/ui-device-routes.js +81 -0
- package/dist/platform/ui-http/ui-devices.d.ts +24 -0
- package/dist/platform/ui-http/ui-devices.js +107 -0
- package/dist/platform/ui-http/ui-http-server.d.ts +10 -3
- package/dist/platform/ui-http/ui-http-server.js +11 -7
- package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
- package/dist/platform/ui-http/ui-pairing.js +98 -0
- package/dist/store/gitignore-migration.d.ts +2 -0
- package/dist/store/gitignore-migration.js +16 -0
- package/dist/store/hook-registry.d.ts +1 -1
- package/dist/store/hook-registry.js +11 -6
- package/dist/store/session-registry-journal.js +3 -0
- package/dist/store/version-migrations.d.ts +5 -0
- package/dist/store/version-migrations.js +117 -80
- package/dist/tui/components/Dashboard.js +4 -3
- package/dist/tui/hooks/useDashboardData.js +1 -1
- package/package.json +3 -3
- package/web/dist/assets/{board-math-css-CB4GJ6qO.js → board-math-css-spk7yR6n.js} +1 -1
- package/web/dist/assets/index-BQ69u-92.css +1 -0
- package/web/dist/assets/{index-cIGFv27z.js → index-CKNLatCd.js} +1 -1
- package/web/dist/assets/index-CkzWfC98.js +525 -0
- package/web/dist/index.html +2 -2
- package/web/dist/assets/index-CaSZPg_H.css +0 -1
- package/web/dist/assets/index-CzOR7Edh.js +0 -522
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// One-time pairing codes: the short credential a new app or browser types instead of the 64-char
|
|
2
|
+
// client token. A signed-in UI (or `cortex ui pair` on the server) mints a code; redeeming it once
|
|
3
|
+
// hands the newcomer its own device token (apps) or a session cookie (browsers).
|
|
4
|
+
//
|
|
5
|
+
// Codes live in a file rather than in memory because the CLI that mints one runs in a different
|
|
6
|
+
// process from the server that redeems it. Every operation re-reads the file for the same reason.
|
|
7
|
+
import * as crypto from 'crypto';
|
|
8
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'fs';
|
|
9
|
+
import * as path from 'path';
|
|
10
|
+
import { createLogger } from '../../core/log.js';
|
|
11
|
+
const log = createLogger('ui-http');
|
|
12
|
+
/** Outstanding codes, under the store dir — shared by the server and `cortex ui pair`. */
|
|
13
|
+
export const PAIRING_FILE_NAME = 'ui-pairing.json';
|
|
14
|
+
/** How long a code stays redeemable. */
|
|
15
|
+
export const PAIRING_CODE_TTL_MS = 10 * 60 * 1000;
|
|
16
|
+
/**
|
|
17
|
+
* Wrong guesses tolerated before every outstanding code is voided. With 40 bits per code this caps
|
|
18
|
+
* an online guesser's odds at roughly 20 in 10^12 per minted code.
|
|
19
|
+
*/
|
|
20
|
+
export const PAIRING_MAX_FAILURES = 20;
|
|
21
|
+
/** Crockford base32: no I, L, O or U, so a code read aloud or off a phone screen survives. */
|
|
22
|
+
const ALPHABET = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
23
|
+
const CODE_LENGTH = 8;
|
|
24
|
+
/** Look-alikes a person may type for a digit. */
|
|
25
|
+
const LOOKALIKES = { O: '0', I: '1', L: '1' };
|
|
26
|
+
/** Canonical form of a typed code, or null when the input cannot be a pairing code at all. */
|
|
27
|
+
export function normalizePairingCode(input) {
|
|
28
|
+
const raw = input.toUpperCase().replace(/[\s-]/g, '');
|
|
29
|
+
if (raw.length !== CODE_LENGTH)
|
|
30
|
+
return null;
|
|
31
|
+
const mapped = [...raw].map((ch) => LOOKALIKES[ch] ?? ch).join('');
|
|
32
|
+
return [...mapped].every((ch) => ALPHABET.includes(ch)) ? mapped : null;
|
|
33
|
+
}
|
|
34
|
+
function formatCode(raw) {
|
|
35
|
+
return `${raw.slice(0, 4)}-${raw.slice(4)}`;
|
|
36
|
+
}
|
|
37
|
+
function randomCode() {
|
|
38
|
+
const bytes = crypto.randomBytes(CODE_LENGTH);
|
|
39
|
+
return [...bytes].map((b) => ALPHABET[b % ALPHABET.length]).join('');
|
|
40
|
+
}
|
|
41
|
+
function readState(file, now) {
|
|
42
|
+
let parsed = null;
|
|
43
|
+
try {
|
|
44
|
+
parsed = JSON.parse(readFileSync(file, 'utf8'));
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// absent or corrupt → no codes
|
|
48
|
+
}
|
|
49
|
+
const codes = {};
|
|
50
|
+
for (const [code, exp] of Object.entries(parsed?.codes ?? {})) {
|
|
51
|
+
if (typeof exp === 'number' && exp > now)
|
|
52
|
+
codes[code] = exp;
|
|
53
|
+
}
|
|
54
|
+
return { codes, failures: typeof parsed?.failures === 'number' ? parsed.failures : 0 };
|
|
55
|
+
}
|
|
56
|
+
function writeState(file, state) {
|
|
57
|
+
try {
|
|
58
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
59
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
60
|
+
writeFileSync(tmp, JSON.stringify(state), { mode: 0o600 });
|
|
61
|
+
renameSync(tmp, file);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
log.warn(`could not persist pairing codes: ${e.message}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
export function createPairingStore(opts) {
|
|
68
|
+
const now = opts.now ?? (() => Date.now());
|
|
69
|
+
const { file } = opts;
|
|
70
|
+
return {
|
|
71
|
+
create() {
|
|
72
|
+
const t = now();
|
|
73
|
+
const state = readState(file, t);
|
|
74
|
+
const raw = randomCode();
|
|
75
|
+
state.codes[raw] = t + PAIRING_CODE_TTL_MS;
|
|
76
|
+
state.failures = 0;
|
|
77
|
+
writeState(file, state);
|
|
78
|
+
return { code: formatCode(raw), expiresAt: state.codes[raw] };
|
|
79
|
+
},
|
|
80
|
+
redeem(input) {
|
|
81
|
+
const state = readState(file, now());
|
|
82
|
+
const raw = normalizePairingCode(input);
|
|
83
|
+
if (raw && raw in state.codes) {
|
|
84
|
+
delete state.codes[raw];
|
|
85
|
+
writeState(file, state);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
state.failures += 1;
|
|
89
|
+
if (state.failures >= PAIRING_MAX_FAILURES) {
|
|
90
|
+
log.warn('too many wrong pairing codes — voiding every outstanding code');
|
|
91
|
+
state.codes = {};
|
|
92
|
+
state.failures = 0;
|
|
93
|
+
}
|
|
94
|
+
writeState(file, state);
|
|
95
|
+
return false;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// $CORTEX_HOME/.gitignore lives at the home root, so a pattern with a slash is anchored there:
|
|
2
|
+
// the shipped `projects/*/…/index.md` rules never matched the memory indexes under context/.
|
|
3
|
+
const MEMORY_INDEX_IGNORES = [
|
|
4
|
+
'context/projects/*/experiments/index.md',
|
|
5
|
+
'context/projects/*/knowledge/index.md',
|
|
6
|
+
'context/projects/*/patterns/index.md',
|
|
7
|
+
];
|
|
8
|
+
/** Append whichever memory-index rules are absent; every existing line is kept as is. */
|
|
9
|
+
export function appendMemoryIndexIgnores(text) {
|
|
10
|
+
const present = new Set(text.split(/\r?\n/).map(line => line.trim()));
|
|
11
|
+
const missing = MEMORY_INDEX_IGNORES.filter(rule => !present.has(rule));
|
|
12
|
+
if (missing.length === 0)
|
|
13
|
+
return text;
|
|
14
|
+
const separator = text.length === 0 || text.endsWith('\n') ? '' : '\n';
|
|
15
|
+
return `${text}${separator}${missing.join('\n')}\n`;
|
|
16
|
+
}
|
|
@@ -13,7 +13,7 @@ export type HookRun = ({
|
|
|
13
13
|
timeout?: number;
|
|
14
14
|
};
|
|
15
15
|
export type HookFilterValue = string | number | boolean | null;
|
|
16
|
-
export type HookResultMode = '
|
|
16
|
+
export type HookResultMode = 'stdout-as-prompt' | 'none';
|
|
17
17
|
export interface HookEntry {
|
|
18
18
|
id: string;
|
|
19
19
|
event: HookEvent;
|
|
@@ -20,14 +20,15 @@ const AGENT_EVENTS = new Set([
|
|
|
20
20
|
'agent:turn-end',
|
|
21
21
|
]);
|
|
22
22
|
const CALVER_RE = /^\d{4}\.\d{1,2}\.\d{1,2}(?:-\d+)?$/;
|
|
23
|
-
const RESULT_MODES = new Set(['
|
|
23
|
+
const RESULT_MODES = new Set(['stdout-as-prompt', 'none']);
|
|
24
|
+
const RETIRED_RESULT_MODE = 'hook-result';
|
|
24
25
|
export const RESULT_CAPABILITY_BY_EVENT = new Map([
|
|
25
|
-
['cortex:thread.start', 'hook-result'],
|
|
26
|
-
['cortex:thread.transition', 'hook-result'],
|
|
27
|
-
['cortex:thread.end', 'hook-result'],
|
|
28
26
|
['cortex:session.new', 'stdout-as-prompt'],
|
|
29
27
|
['cortex:session.messageEnd', 'stdout-as-prompt'],
|
|
30
28
|
]);
|
|
29
|
+
/** A configuration that was once valid but no longer does anything: skipped with a warning. */
|
|
30
|
+
class RetiredHookConfigError extends Error {
|
|
31
|
+
}
|
|
31
32
|
function asObject(value, field) {
|
|
32
33
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
33
34
|
throw new Error(`${field} must be an object`);
|
|
@@ -137,8 +138,11 @@ function validateBlocking(value) {
|
|
|
137
138
|
function validateResult(value, event) {
|
|
138
139
|
if (value === undefined)
|
|
139
140
|
return;
|
|
141
|
+
if (value === RETIRED_RESULT_MODE) {
|
|
142
|
+
throw new RetiredHookConfigError(`result mode "${RETIRED_RESULT_MODE}" is retired; remove the hook or its result field`);
|
|
143
|
+
}
|
|
140
144
|
if (typeof value !== 'string' || !RESULT_MODES.has(value)) {
|
|
141
|
-
throw new Error('result must be
|
|
145
|
+
throw new Error('result must be stdout-as-prompt or none');
|
|
142
146
|
}
|
|
143
147
|
if (value !== 'none' && RESULT_CAPABILITY_BY_EVENT.get(event) !== value) {
|
|
144
148
|
throw new Error(`result mode "${value}" is not permitted for event "${event}"`);
|
|
@@ -166,7 +170,8 @@ export function validateHookEntry(value) {
|
|
|
166
170
|
}
|
|
167
171
|
function reportInvalid(source, error) {
|
|
168
172
|
const message = error instanceof Error ? error.message : String(error);
|
|
169
|
-
console.
|
|
173
|
+
const report = error instanceof RetiredHookConfigError ? console.warn : console.error;
|
|
174
|
+
report(`[hook-registry] skipped ${source}: ${message}`);
|
|
170
175
|
}
|
|
171
176
|
function registryFiles(directory) {
|
|
172
177
|
if (!directory)
|
|
@@ -799,6 +799,9 @@ async function writeReplacementFile(tmp, events) {
|
|
|
799
799
|
}
|
|
800
800
|
}
|
|
801
801
|
async function syncParentDir(filePath) {
|
|
802
|
+
// Windows rejects fsync on a directory handle with EPERM; NTFS journals the rename itself.
|
|
803
|
+
if (process.platform === 'win32')
|
|
804
|
+
return;
|
|
802
805
|
const handle = await fsp.open(path.dirname(filePath), 'r');
|
|
803
806
|
try {
|
|
804
807
|
await handle.sync();
|
|
@@ -82,6 +82,11 @@ export interface MigrationOptions {
|
|
|
82
82
|
* real `stepMigrations`. Lets tests drive the step-runner contract (bump / skip / throw / order)
|
|
83
83
|
* with probe steps instead of the real S1 import. */
|
|
84
84
|
stepMigrations?: StepMigration[];
|
|
85
|
+
/** Observer of each migration that throws (telemetry); never affects the run. */
|
|
86
|
+
onMigrationFailure?: (failure: {
|
|
87
|
+
migration: string;
|
|
88
|
+
error: unknown;
|
|
89
|
+
}) => void;
|
|
85
90
|
}
|
|
86
91
|
export declare function runMigrations(opts?: MigrationOptions): Promise<void>;
|
|
87
92
|
/** Move the retired singular session hook config into declarative registry files. */
|
|
@@ -6,6 +6,7 @@ import { AISTATUS_DIR, DATA_DIR, DEFAULTS_DIR, PROJECTS_DIR } from '../core/path
|
|
|
6
6
|
import { compareCalVer } from '../core/calver.js';
|
|
7
7
|
import { atomicWrite } from '../core/atomic-write.js';
|
|
8
8
|
import { RETIRED_MCP_TOOLS } from '../core/mcp-tool-gate.js';
|
|
9
|
+
import { migrateRetiredPiUpstreams } from '../core/gateway-generator.js';
|
|
9
10
|
import { createLogger } from '../core/log.js';
|
|
10
11
|
import { validateHookEntry } from './hook-registry.js';
|
|
11
12
|
import { migrateProviderStateFromSchedules } from './provider-state-repo.js';
|
|
@@ -15,6 +16,7 @@ import { migrateClaudeConfigHome } from './claude-transcript-migration.js';
|
|
|
15
16
|
import { retireCommissions } from './board-migration.js';
|
|
16
17
|
import { migrateToBuiltinOverlay } from './builtin-overlay-migration.js';
|
|
17
18
|
import { retireProfiles } from './retire-profiles-migration.js';
|
|
19
|
+
import { appendMemoryIndexIgnores } from './gitignore-migration.js';
|
|
18
20
|
import { CODER_COMMIT_POLICY_REPLACEMENTS, CODER_REVIEWER_COMMIT_POLICY_REPLACEMENTS, STATUS_REGISTER_REPLACEMENTS, } from './prompt-migration-replacements.js';
|
|
19
21
|
const log = createLogger('version-migrations');
|
|
20
22
|
// ── Marker-block helpers (text migrations) ─────────────────────
|
|
@@ -374,6 +376,11 @@ const migrations = [
|
|
|
374
376
|
return { ...state, providerUsage: kept };
|
|
375
377
|
},
|
|
376
378
|
},
|
|
379
|
+
// M12: anchor the shipped memory-index ignore rules under context/ in existing installs.
|
|
380
|
+
{
|
|
381
|
+
filePath: '.gitignore', version: '2026.10.22', format: 'text',
|
|
382
|
+
migrate: (data) => typeof data === 'string' ? appendMemoryIndexIgnores(data) : data,
|
|
383
|
+
},
|
|
377
384
|
];
|
|
378
385
|
// ── Step migration registry ────────────────────────────────────
|
|
379
386
|
// Add step migrations here. Executed in list order AFTER the file-migration loop.
|
|
@@ -517,6 +524,13 @@ const stepMigrations = [
|
|
|
517
524
|
return false;
|
|
518
525
|
},
|
|
519
526
|
},
|
|
527
|
+
// S11: PI 1.3.0 moved Kimi Coding and OpenCode to new base URLs. Gateway routes Cortex wrote for
|
|
528
|
+
// the old ones follow; hand-pointed relays are left alone.
|
|
529
|
+
{
|
|
530
|
+
key: 'sentinel:pi-retired-upstreams',
|
|
531
|
+
version: '2026.10.22',
|
|
532
|
+
run: async () => { migrateRetiredPiUpstreams(path.join(AISTATUS_DIR, 'gateway.yaml')); },
|
|
533
|
+
},
|
|
520
534
|
];
|
|
521
535
|
// ── Execution environments (S5) ────────────────────────────────
|
|
522
536
|
const KEPT_ENVIRONMENTS = ['main', 'creative'];
|
|
@@ -934,110 +948,133 @@ export async function loadVersionsFrom(filePath) {
|
|
|
934
948
|
export async function saveVersionsTo(filePath, versions) {
|
|
935
949
|
await atomicWrite(filePath, JSON.stringify(versions, null, 2) + '\n');
|
|
936
950
|
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
log.warn(`Could not migrate legacy provider state: ${error.message}`);
|
|
944
|
-
});
|
|
945
|
-
await migrateSessionHooksToRegistry(dataDir);
|
|
946
|
-
await removeRetiredDefaultHooks(dataDir).catch((error) => {
|
|
947
|
-
log.warn(`Could not remove retired default hooks: ${error.message}`);
|
|
948
|
-
});
|
|
949
|
-
const versionsFile = path.join(storeDir, 'versions.json');
|
|
950
|
-
const versions = await loadVersionsFrom(versionsFile);
|
|
951
|
-
// Group migrations by filePath
|
|
951
|
+
function pendingFor(list, trackedVersion) {
|
|
952
|
+
return list
|
|
953
|
+
.filter(m => compareCalVer(trackedVersion, m.version) < 0 && compareCalVer(CORTEX_VERSION, m.version) >= 0)
|
|
954
|
+
.sort((a, b) => compareCalVer(a.version, b.version));
|
|
955
|
+
}
|
|
956
|
+
function groupByFile(list) {
|
|
952
957
|
const byFilePath = new Map();
|
|
953
|
-
for (const m of
|
|
954
|
-
const
|
|
955
|
-
|
|
956
|
-
byFilePath.set(m.filePath,
|
|
958
|
+
for (const m of list) {
|
|
959
|
+
const group = byFilePath.get(m.filePath) ?? [];
|
|
960
|
+
group.push(m);
|
|
961
|
+
byFilePath.set(m.filePath, group);
|
|
957
962
|
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
const
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
let data;
|
|
972
|
-
try {
|
|
973
|
-
const raw = await fs.readFile(absPath, 'utf8');
|
|
974
|
-
data = format === 'text' ? raw : JSON.parse(raw);
|
|
963
|
+
return byFilePath;
|
|
964
|
+
}
|
|
965
|
+
/** The file's current contents, or `undefined` when it is absent or corrupt (skip its migrations). */
|
|
966
|
+
async function readMigrationTarget(absPath, filePath, format) {
|
|
967
|
+
try {
|
|
968
|
+
const raw = await fs.readFile(absPath, 'utf8');
|
|
969
|
+
return format === 'text' ? raw : JSON.parse(raw);
|
|
970
|
+
}
|
|
971
|
+
catch (err) {
|
|
972
|
+
const e = err;
|
|
973
|
+
if (e.code === 'ENOENT') {
|
|
974
|
+
log.info(`Skipping migrations for ${filePath}: file does not exist yet`);
|
|
975
|
+
return undefined;
|
|
975
976
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
log.info(`Skipping migrations for ${filePath}: file does not exist yet`);
|
|
980
|
-
continue;
|
|
981
|
-
}
|
|
982
|
-
if (err instanceof SyntaxError) {
|
|
983
|
-
log.warn(`Skipping migrations for ${filePath}: corrupt JSON (${e.message})`);
|
|
984
|
-
continue;
|
|
985
|
-
}
|
|
986
|
-
throw err;
|
|
977
|
+
if (err instanceof SyntaxError) {
|
|
978
|
+
log.warn(`Skipping migrations for ${filePath}: corrupt JSON (${e.message})`);
|
|
979
|
+
return undefined;
|
|
987
980
|
}
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
anyFailed = true;
|
|
1000
|
-
break;
|
|
1001
|
-
}
|
|
1002
|
-
if (serialize(data) !== before) {
|
|
1003
|
-
log.info(`Migration ${m.version} applied to ${filePath}`);
|
|
1004
|
-
changed = true;
|
|
1005
|
-
}
|
|
981
|
+
throw err;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
/** Apply pending migrations in order; stops at the first failure. */
|
|
985
|
+
function applyPending(pending, start, filePath, serialize, report) {
|
|
986
|
+
let data = start;
|
|
987
|
+
let changed = false;
|
|
988
|
+
for (const m of pending) {
|
|
989
|
+
const before = serialize(data);
|
|
990
|
+
try {
|
|
991
|
+
data = m.migrate(data);
|
|
1006
992
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
993
|
+
catch (err) {
|
|
994
|
+
log.error(`Migration ${m.version} for ${filePath} failed: ${err.message}; skipping remaining migrations for this file`);
|
|
995
|
+
report({ migration: `${m.version}:${filePath}`, error: err });
|
|
996
|
+
return { data, changed: false, failed: true };
|
|
1010
997
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
// retry next boot. Idempotent migrations guarantee this is safe.
|
|
1015
|
-
if (!anyFailed) {
|
|
1016
|
-
versions[filePath] = pending[pending.length - 1].version;
|
|
998
|
+
if (serialize(data) !== before) {
|
|
999
|
+
log.info(`Migration ${m.version} applied to ${filePath}`);
|
|
1000
|
+
changed = true;
|
|
1017
1001
|
}
|
|
1018
1002
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
//
|
|
1023
|
-
|
|
1003
|
+
return { data, changed, failed: false };
|
|
1004
|
+
}
|
|
1005
|
+
async function migrateFile(dataDir, filePath, pending, versions, report) {
|
|
1006
|
+
// A file is either JSON or text — take the format from the pending migrations.
|
|
1007
|
+
const format = pending.find(m => m.format === 'text') ? 'text' : 'json';
|
|
1008
|
+
const serialize = (d) => (format === 'text' ? String(d) : JSON.stringify(d));
|
|
1009
|
+
const absPath = path.join(dataDir, filePath);
|
|
1010
|
+
const data = await readMigrationTarget(absPath, filePath, format);
|
|
1011
|
+
if (data === undefined)
|
|
1012
|
+
return;
|
|
1013
|
+
const result = applyPending(pending, data, filePath, serialize, report);
|
|
1014
|
+
if (result.changed) {
|
|
1015
|
+
const out = format === 'text' ? String(result.data) : JSON.stringify(result.data, null, 2) + '\n';
|
|
1016
|
+
await atomicWrite(absPath, out);
|
|
1017
|
+
}
|
|
1018
|
+
// Only bump the tracked version if ALL pending migrations succeeded.
|
|
1019
|
+
// If any failed: we did not write the file (changed=false), so the data on
|
|
1020
|
+
// disk is unchanged. Leave version at the old value → all pending migrations
|
|
1021
|
+
// retry next boot. Idempotent migrations guarantee this is safe.
|
|
1022
|
+
if (!result.failed)
|
|
1023
|
+
versions[filePath] = pending[pending.length - 1].version;
|
|
1024
|
+
}
|
|
1025
|
+
// Step migrations run AFTER the file loop (so a step sees the file rewrites above) with the same
|
|
1026
|
+
// pending rule and the same versions.json, keyed by `key`. A throwing step logs and is skipped
|
|
1027
|
+
// WITHOUT bumping — it retries next boot. S10 is required before runtime state writes. Only a step that
|
|
1028
|
+
// completes (rather than returning false to defer) bumps its key.
|
|
1029
|
+
async function runStepMigrations(steps, ctx, versions, report) {
|
|
1030
|
+
for (const step of steps) {
|
|
1024
1031
|
const tracked = versions[step.key] || '0.0.0';
|
|
1025
1032
|
const pending = compareCalVer(tracked, step.version) < 0 && compareCalVer(CORTEX_VERSION, step.version) >= 0;
|
|
1026
1033
|
if (!pending)
|
|
1027
1034
|
continue;
|
|
1028
1035
|
try {
|
|
1029
|
-
if (await step.run(
|
|
1036
|
+
if (await step.run(ctx) === false)
|
|
1030
1037
|
continue;
|
|
1031
1038
|
versions[step.key] = step.version;
|
|
1032
1039
|
log.info(`Step migration ${step.version} applied for ${step.key}`);
|
|
1033
1040
|
}
|
|
1034
1041
|
catch (err) {
|
|
1035
1042
|
log.error(`Step migration ${step.version} for ${step.key} failed: ${err.message}; not bumping`);
|
|
1043
|
+
report({ migration: `${step.version}:${step.key}`, error: err });
|
|
1036
1044
|
// Runtime state writes must not discard the legacy inputs needed to retry this conversion.
|
|
1037
1045
|
if (step.key === 'sentinel:retire-profiles')
|
|
1038
1046
|
throw err;
|
|
1039
1047
|
}
|
|
1040
1048
|
}
|
|
1049
|
+
}
|
|
1050
|
+
async function runLegacyRelocations(dataDir) {
|
|
1051
|
+
await migrateProviderStateFromSchedules(dataDir).catch((error) => {
|
|
1052
|
+
log.warn(`Could not migrate legacy provider state: ${error.message}`);
|
|
1053
|
+
});
|
|
1054
|
+
await migrateSessionHooksToRegistry(dataDir);
|
|
1055
|
+
await removeRetiredDefaultHooks(dataDir).catch((error) => {
|
|
1056
|
+
log.warn(`Could not remove retired default hooks: ${error.message}`);
|
|
1057
|
+
});
|
|
1058
|
+
}
|
|
1059
|
+
export async function runMigrations(opts = {}) {
|
|
1060
|
+
const dataDir = opts.dataDir ?? DATA_DIR;
|
|
1061
|
+
const defaultsDir = opts.defaultsDir ?? DEFAULTS_DIR;
|
|
1062
|
+
const storeDir = opts.storeDir ?? path.join(dataDir, 'data');
|
|
1063
|
+
const report = (failure) => {
|
|
1064
|
+
try {
|
|
1065
|
+
opts.onMigrationFailure?.(failure);
|
|
1066
|
+
}
|
|
1067
|
+
catch { /* an observer never stops migrations */ }
|
|
1068
|
+
};
|
|
1069
|
+
await runLegacyRelocations(dataDir);
|
|
1070
|
+
const versionsFile = path.join(storeDir, 'versions.json');
|
|
1071
|
+
const versions = await loadVersionsFrom(versionsFile);
|
|
1072
|
+
for (const [filePath, fileMigrations] of groupByFile(migrations)) {
|
|
1073
|
+
const pending = pendingFor(fileMigrations, versions[filePath] || '0.0.0');
|
|
1074
|
+
if (pending.length > 0)
|
|
1075
|
+
await migrateFile(dataDir, filePath, pending, versions, report);
|
|
1076
|
+
}
|
|
1077
|
+
await runStepMigrations(opts.stepMigrations ?? stepMigrations, { dataDir, storeDir, defaultsDir }, versions, report);
|
|
1041
1078
|
await saveVersionsTo(versionsFile, versions);
|
|
1042
1079
|
}
|
|
1043
1080
|
const SESSION_HOOK_DESTINATIONS = {
|
|
@@ -40,9 +40,10 @@ function TabContent({ tab, active, sendFrame, mutate, projectId, dashState, onRe
|
|
|
40
40
|
initialQuerySent.current = true;
|
|
41
41
|
// Send query for initial data
|
|
42
42
|
sendFrameRef.current({ type: 'ui.query', id: queryId, scope: tab === 'cost' ? 'cost.summary' : `${tab}.list`, params: projectId ? { projectId } : {} });
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (scope.events.length > 0) {
|
|
44
|
+
sendFrameRef.current({ type: 'ui.subscribe', id: queryId, filter: { events: scope.events, projectId } });
|
|
45
|
+
onRegisterSubscriptionRef.current(queryId, tab);
|
|
46
|
+
}
|
|
46
47
|
}
|
|
47
48
|
// Cleanup on unmount
|
|
48
49
|
return () => {
|
|
@@ -9,7 +9,7 @@ export const EMPTY_DASH_STATE = {
|
|
|
9
9
|
},
|
|
10
10
|
};
|
|
11
11
|
export const TAB_SCOPES = {
|
|
12
|
-
schedules: { queryId: 'dash-schedules', events: [
|
|
12
|
+
schedules: { queryId: 'dash-schedules', events: [] },
|
|
13
13
|
executions: { queryId: 'dash-executions', events: ['agent.started', 'agent.completed', 'agent.failed', 'agent.superseded'] },
|
|
14
14
|
cost: { queryId: 'dash-cost', events: ['agent.completed'] },
|
|
15
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortex-agent/server",
|
|
3
|
-
"version": "2026.10.
|
|
3
|
+
"version": "2026.10.25",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Agent workbench for auto research, self-improvement loops, and long-running work — multi-agent teams, persistent project memory, cross-machine GPU training.",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@clack/prompts": "^1.3.0",
|
|
46
|
-
"@earendil-works/pi-ai": "1.
|
|
47
|
-
"@earendil-works/pi-coding-agent": "1.
|
|
46
|
+
"@earendil-works/pi-ai": "1.4.0",
|
|
47
|
+
"@earendil-works/pi-coding-agent": "1.4.0",
|
|
48
48
|
"@modelcontextprotocol/sdk": "^1.27.1",
|
|
49
49
|
"@sinclair/typebox": "^0.34.49",
|
|
50
50
|
"@slack/bolt": "^4.6.0",
|