@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.
Files changed (194) hide show
  1. package/README.md +10 -6
  2. package/defaults/context/projects/AGENTS.md +1 -1
  3. package/defaults/gitignore +3 -3
  4. package/defaults/hooks/new-session-hook.mjs +1 -1
  5. package/defaults/hooks/status-md-guard.mjs +6 -6
  6. package/defaults/plugins/cortex-system/plugin.json +1 -1
  7. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +16 -9
  8. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +2 -2
  9. package/defaults/rules/agents-md.md +1 -1
  10. package/defaults/rules/issues-md.md +1 -1
  11. package/defaults/rules/meta-conventions.md +3 -3
  12. package/defaults/rules/mission-md.md +1 -1
  13. package/defaults/rules/status-md.md +1 -1
  14. package/dist/agent-adapter/claude/bg-task-tracker.d.ts +3 -1
  15. package/dist/agent-adapter/claude/bg-task-tracker.js +6 -2
  16. package/dist/agent-adapter/claude/mcp-config.js +11 -0
  17. package/dist/agent-adapter/claude/turn-machine.d.ts +2 -1
  18. package/dist/agent-adapter/claude/turn-machine.js +8 -5
  19. package/dist/agent-adapter/continuation-phase.d.ts +6 -3
  20. package/dist/agent-adapter/continuation-phase.js +8 -3
  21. package/dist/agent-adapter/run-events.d.ts +4 -0
  22. package/dist/agent-adapter/types.d.ts +9 -2
  23. package/dist/build-info.json +1 -0
  24. package/dist/client-bundle/client.mjs +10 -5
  25. package/dist/client-bundle/manifest.json +2 -2
  26. package/dist/core/claude-credentials.d.ts +6 -0
  27. package/dist/core/claude-credentials.js +11 -0
  28. package/dist/core/gateway-generator.d.ts +17 -0
  29. package/dist/core/gateway-generator.js +42 -4
  30. package/dist/core/hook-bus.d.ts +1 -1
  31. package/dist/core/hook-bus.js +1 -8
  32. package/dist/core/locales/en.d.ts +1 -0
  33. package/dist/core/locales/slices/init.d.ts +1 -0
  34. package/dist/core/locales/slices/init.js +2 -0
  35. package/dist/core/log.d.ts +3 -0
  36. package/dist/core/log.js +18 -1
  37. package/dist/core/settings-spec.d.ts +5 -0
  38. package/dist/core/settings-spec.js +4 -0
  39. package/dist/core/types/agent-types.d.ts +3 -1
  40. package/dist/core/types/environment-types.d.ts +1 -6
  41. package/dist/domain/agents/environments/registry.js +3 -2
  42. package/dist/domain/agents/environments/schema.d.ts +3 -2
  43. package/dist/domain/agents/environments/schema.js +4 -3
  44. package/dist/domain/auth/auth-watch.js +48 -18
  45. package/dist/domain/mcp/tools/context.d.ts +0 -1
  46. package/dist/domain/mcp/tools/context.js +0 -1
  47. package/dist/domain/monitor/event-loop-monitor.d.ts +2 -0
  48. package/dist/domain/monitor/event-loop-monitor.js +5 -1
  49. package/dist/domain/plugins/authoring.d.ts +8 -1
  50. package/dist/domain/plugins/authoring.js +24 -9
  51. package/dist/domain/plugins/runtime-gc.d.ts +7 -0
  52. package/dist/domain/plugins/runtime-gc.js +52 -19
  53. package/dist/domain/plugins/runtime.js +2 -1
  54. package/dist/domain/remote/client-bootstrap.js +1 -1
  55. package/dist/domain/remote/client-manager.js +6 -1
  56. package/dist/domain/runs/retryable-errors.js +3 -1
  57. package/dist/domain/runs/service.d.ts +0 -9
  58. package/dist/domain/runs/service.js +29 -15
  59. package/dist/domain/scheduling/builtin-job-controller.d.ts +3 -1
  60. package/dist/domain/scheduling/builtin-job-controller.js +5 -2
  61. package/dist/domain/scheduling/builtin-jobs.js +7 -0
  62. package/dist/domain/scheduling/scheduler.js +14 -5
  63. package/dist/domain/system/server-update-check.js +2 -1
  64. package/dist/domain/telemetry/bus-collector.d.ts +3 -0
  65. package/dist/domain/telemetry/bus-collector.js +22 -0
  66. package/dist/domain/telemetry/child-exit.d.ts +11 -0
  67. package/dist/domain/telemetry/child-exit.js +36 -0
  68. package/dist/domain/telemetry/client-kind.d.ts +4 -0
  69. package/dist/domain/telemetry/client-kind.js +7 -0
  70. package/dist/domain/telemetry/crash-limits.d.ts +15 -0
  71. package/dist/domain/telemetry/crash-limits.js +50 -0
  72. package/dist/domain/telemetry/crash.d.ts +25 -0
  73. package/dist/domain/telemetry/crash.js +70 -0
  74. package/dist/domain/telemetry/daily-upload.d.ts +5 -0
  75. package/dist/domain/telemetry/daily-upload.js +20 -0
  76. package/dist/domain/telemetry/daily.d.ts +5 -0
  77. package/dist/domain/telemetry/daily.js +104 -0
  78. package/dist/domain/telemetry/endpoint.d.ts +7 -0
  79. package/dist/domain/telemetry/endpoint.js +40 -0
  80. package/dist/domain/telemetry/envelope.d.ts +6 -0
  81. package/dist/domain/telemetry/envelope.js +35 -0
  82. package/dist/domain/telemetry/error-digest.d.ts +7 -0
  83. package/dist/domain/telemetry/error-digest.js +43 -0
  84. package/dist/domain/telemetry/funnel.d.ts +6 -0
  85. package/dist/domain/telemetry/funnel.js +22 -0
  86. package/dist/domain/telemetry/gate.d.ts +19 -0
  87. package/dist/domain/telemetry/gate.js +67 -0
  88. package/dist/domain/telemetry/heartbeat.d.ts +17 -0
  89. package/dist/domain/telemetry/heartbeat.js +49 -0
  90. package/dist/domain/telemetry/info.d.ts +9 -0
  91. package/dist/domain/telemetry/info.js +12 -0
  92. package/dist/domain/telemetry/init-answer.d.ts +12 -0
  93. package/dist/domain/telemetry/init-answer.js +42 -0
  94. package/dist/domain/telemetry/install-id.d.ts +5 -0
  95. package/dist/domain/telemetry/install-id.js +42 -0
  96. package/dist/domain/telemetry/normalize.d.ts +33 -0
  97. package/dist/domain/telemetry/normalize.js +88 -0
  98. package/dist/domain/telemetry/outbox.d.ts +18 -0
  99. package/dist/domain/telemetry/outbox.js +93 -0
  100. package/dist/domain/telemetry/panic-group.d.ts +4 -0
  101. package/dist/domain/telemetry/panic-group.js +51 -0
  102. package/dist/domain/telemetry/paths.d.ts +7 -0
  103. package/dist/domain/telemetry/paths.js +11 -0
  104. package/dist/domain/telemetry/redact.d.ts +18 -0
  105. package/dist/domain/telemetry/redact.js +109 -0
  106. package/dist/domain/telemetry/rollup-types.d.ts +81 -0
  107. package/dist/domain/telemetry/rollup-types.js +31 -0
  108. package/dist/domain/telemetry/rollup.d.ts +16 -0
  109. package/dist/domain/telemetry/rollup.js +102 -0
  110. package/dist/domain/telemetry/schema.d.ts +931 -0
  111. package/dist/domain/telemetry/schema.js +275 -0
  112. package/dist/domain/telemetry/service.d.ts +34 -0
  113. package/dist/domain/telemetry/service.js +146 -0
  114. package/dist/domain/telemetry/state.d.ts +17 -0
  115. package/dist/domain/telemetry/state.js +29 -0
  116. package/dist/domain/telemetry/turns.d.ts +17 -0
  117. package/dist/domain/telemetry/turns.js +176 -0
  118. package/dist/domain/telemetry/upgrade.d.ts +14 -0
  119. package/dist/domain/telemetry/upgrade.js +87 -0
  120. package/dist/domain/telemetry/uploader.d.ts +21 -0
  121. package/dist/domain/telemetry/uploader.js +82 -0
  122. package/dist/domain/telemetry/usage.d.ts +25 -0
  123. package/dist/domain/telemetry/usage.js +153 -0
  124. package/dist/domain/telemetry/web-report.d.ts +8 -0
  125. package/dist/domain/telemetry/web-report.js +15 -0
  126. package/dist/domain/ui-service/app-router.d.ts +69 -25
  127. package/dist/domain/ui-service/app-router.js +9 -2
  128. package/dist/domain/ui-service/input-schemas.d.ts +68 -4
  129. package/dist/domain/ui-service/input-schemas.js +9 -1
  130. package/dist/domain/ui-service/mutate/approvals.d.ts +3 -2
  131. package/dist/domain/ui-service/mutate/approvals.js +3 -2
  132. package/dist/domain/ui-service/mutate/plugin-packages.js +1 -1
  133. package/dist/domain/ui-service/mutate/telemetry.d.ts +5 -0
  134. package/dist/domain/ui-service/mutate/telemetry.js +6 -0
  135. package/dist/domain/ui-service/query/approvals.js +4 -3
  136. package/dist/domain/ui-service/query/machine-probe.d.ts +1 -1
  137. package/dist/domain/ui-service/query/machine-probe.js +3 -2
  138. package/dist/domain/ui-service/query/models.d.ts +3 -0
  139. package/dist/domain/ui-service/query/models.js +47 -30
  140. package/dist/domain/ui-service/query/plugin-source.js +4 -3
  141. package/dist/domain/ui-service/query/sessions.js +1 -0
  142. package/dist/domain/ui-service/query/telemetry.d.ts +3 -0
  143. package/dist/domain/ui-service/query/telemetry.js +4 -0
  144. package/dist/domain/ui-service/trpc.d.ts +8 -3
  145. package/dist/domain/ui-service/trpc.js +1 -1
  146. package/dist/domain/ui-service/types.d.ts +20 -2
  147. package/dist/domain/ui-service/ui-service.d.ts +33 -4
  148. package/dist/domain/ui-service/ui-service.js +19 -18
  149. package/dist/entry/app.js +20 -2
  150. package/dist/entry/cli-help.js +27 -14
  151. package/dist/entry/daemon.d.ts +1 -1
  152. package/dist/entry/daemon.js +86 -72
  153. package/dist/entry/init.d.ts +3 -0
  154. package/dist/entry/init.js +50 -28
  155. package/dist/entry/shutdown.js +3 -0
  156. package/dist/entry/signal-cli.js +8 -11
  157. package/dist/entry/start-ui-http.js +40 -18
  158. package/dist/entry/telemetry-wiring.d.ts +12 -0
  159. package/dist/entry/telemetry-wiring.js +56 -0
  160. package/dist/entry/ui-cli.d.ts +0 -11
  161. package/dist/entry/ui-cli.js +42 -33
  162. package/dist/events/event-types.d.ts +1 -4
  163. package/dist/orchestration/routing/message-router.js +2 -0
  164. package/dist/orchestration/routing/webhook.js +2 -0
  165. package/dist/orchestration/transcript-sink.d.ts +6 -0
  166. package/dist/orchestration/transcript-sink.js +17 -0
  167. package/dist/orchestration/waitpoint-ingress.js +3 -0
  168. package/dist/platform/ui-http/ui-auth-routes.d.ts +2 -0
  169. package/dist/platform/ui-http/ui-auth-routes.js +9 -2
  170. package/dist/platform/ui-http/ui-device-routes.d.ts +13 -0
  171. package/dist/platform/ui-http/ui-device-routes.js +81 -0
  172. package/dist/platform/ui-http/ui-devices.d.ts +24 -0
  173. package/dist/platform/ui-http/ui-devices.js +107 -0
  174. package/dist/platform/ui-http/ui-http-server.d.ts +10 -3
  175. package/dist/platform/ui-http/ui-http-server.js +11 -7
  176. package/dist/platform/ui-http/ui-pairing.d.ts +25 -0
  177. package/dist/platform/ui-http/ui-pairing.js +98 -0
  178. package/dist/store/gitignore-migration.d.ts +2 -0
  179. package/dist/store/gitignore-migration.js +16 -0
  180. package/dist/store/hook-registry.d.ts +1 -1
  181. package/dist/store/hook-registry.js +11 -6
  182. package/dist/store/session-registry-journal.js +3 -0
  183. package/dist/store/version-migrations.d.ts +5 -0
  184. package/dist/store/version-migrations.js +117 -80
  185. package/dist/tui/components/Dashboard.js +4 -3
  186. package/dist/tui/hooks/useDashboardData.js +1 -1
  187. package/package.json +3 -3
  188. package/web/dist/assets/{board-math-css-CB4GJ6qO.js → board-math-css-spk7yR6n.js} +1 -1
  189. package/web/dist/assets/index-BQ69u-92.css +1 -0
  190. package/web/dist/assets/{index-cIGFv27z.js → index-CKNLatCd.js} +1 -1
  191. package/web/dist/assets/index-CkzWfC98.js +525 -0
  192. package/web/dist/index.html +2 -2
  193. package/web/dist/assets/index-CaSZPg_H.css +0 -1
  194. 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,2 @@
1
+ /** Append whichever memory-index rules are absent; every existing line is kept as is. */
2
+ export declare function appendMemoryIndexIgnores(text: string): string;
@@ -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 = 'hook-result' | 'stdout-as-prompt' | 'none';
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(['hook-result', 'stdout-as-prompt', 'none']);
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 hook-result, stdout-as-prompt, or none');
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.error(`[hook-registry] skipped ${source}: ${message}`);
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
- // ── Runner ─────────────────────────────────────────────────────
938
- export async function runMigrations(opts = {}) {
939
- const dataDir = opts.dataDir ?? DATA_DIR;
940
- const defaultsDir = opts.defaultsDir ?? DEFAULTS_DIR;
941
- const storeDir = opts.storeDir ?? path.join(dataDir, 'data');
942
- await migrateProviderStateFromSchedules(dataDir).catch((error) => {
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 migrations) {
954
- const list = byFilePath.get(m.filePath) ?? [];
955
- list.push(m);
956
- byFilePath.set(m.filePath, list);
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
- for (const [filePath, fileMigrations] of byFilePath) {
959
- const trackedVersion = versions[filePath] || '0.0.0';
960
- // Pending: migrations whose version > trackedVersion and <= CORTEX_VERSION
961
- const pending = fileMigrations
962
- .filter(m => compareCalVer(trackedVersion, m.version) < 0 && compareCalVer(CORTEX_VERSION, m.version) >= 0)
963
- .sort((a, b) => compareCalVer(a.version, b.version));
964
- if (pending.length === 0)
965
- continue;
966
- // A file is either JSON or text — take the format from the pending migrations.
967
- const format = pending.find(m => m.format === 'text') ? 'text' : 'json';
968
- const serialize = (d) => (format === 'text' ? String(d) : JSON.stringify(d));
969
- // Read target file
970
- const absPath = path.join(dataDir, filePath);
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
- catch (err) {
977
- const e = err;
978
- if (e.code === 'ENOENT') {
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
- // Apply all pending migrations in version order
989
- let changed = false;
990
- let anyFailed = false;
991
- for (const m of pending) {
992
- const before = serialize(data);
993
- try {
994
- data = m.migrate(data);
995
- }
996
- catch (err) {
997
- log.error(`Migration ${m.version} for ${filePath} failed: ${err.message}; skipping remaining migrations for this file`);
998
- changed = false;
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
- if (changed) {
1008
- const out = format === 'text' ? String(data) : JSON.stringify(data, null, 2) + '\n';
1009
- await atomicWrite(absPath, out);
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
- // Only bump the tracked version if ALL pending migrations succeeded.
1012
- // If any failed: we did not write the file (changed=false), so the data on
1013
- // disk is unchanged. Leave version at the old value → all pending migrations
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
- // Step migrations run AFTER the file loop (so a step sees the file rewrites above) with the same
1020
- // pending rule and the same versions.json, keyed by `key`. A throwing step logs and is skipped
1021
- // WITHOUT bumping — it retries next boot. S10 is required before runtime state writes. Only a step that
1022
- // completes (rather than returning false to defer) bumps its key.
1023
- for (const step of opts.stepMigrations ?? stepMigrations) {
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({ dataDir, storeDir, defaultsDir }) === false)
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
- // Subscribe to events
44
- sendFrameRef.current({ type: 'ui.subscribe', id: queryId, filter: { events: scope.events, projectId } });
45
- onRegisterSubscriptionRef.current(queryId, tab);
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: ['scheduler.tick'] },
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.21",
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.2.0",
47
- "@earendil-works/pi-coding-agent": "1.2.0",
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",