@cortex-agent/server 2026.9.14 → 2026.9.21

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 (259) hide show
  1. package/README.md +3 -2
  2. package/defaults/config/hooks/08-agents-md-injector-post-tool.json +10 -0
  3. package/defaults/config/hooks/{10-cortex-md-injector-session-start.json → 10-agents-md-injector-session-start.json} +3 -3
  4. package/defaults/config/hooks/{CORTEX.md → AGENTS.md} +2 -2
  5. package/defaults/hooks/{CORTEX.md → AGENTS.md} +1 -1
  6. package/defaults/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  7. package/defaults/hooks/cortex-hook-api.mjs +2 -2
  8. package/defaults/hooks/new-session-hook.mjs +2 -2
  9. package/defaults/hooks/rules-loader.mjs +2 -2
  10. package/defaults/hooks/status-md-guard.mjs +8 -8
  11. package/defaults/hooks/task-status-check.mjs +18 -76
  12. package/defaults/hooks/tasks-yaml-guard.mjs +2 -2
  13. package/defaults/plugins/cortex-commission/.claude-plugin/plugin.json +2 -2
  14. package/defaults/plugins/cortex-commission/plugin.json +2 -2
  15. package/defaults/plugins/cortex-commission/skills/commission/SKILL.md +3 -3
  16. package/defaults/plugins/cortex-feishu/skills/feishu-doc/SKILL.md +1 -1
  17. package/defaults/plugins/cortex-system/skills/client-manage/SKILL.md +2 -2
  18. package/defaults/plugins/cortex-system/skills/project-init/SKILL.md +4 -4
  19. package/defaults/plugins/cortex-system/skills/task/SKILL.md +1 -1
  20. package/defaults/rules/{cortex-md.md → agents-md.md} +4 -4
  21. package/defaults/rules/decision-records.md +1 -1
  22. package/defaults/rules/meta-conventions.md +4 -4
  23. package/defaults/rules/mission-md.md +1 -1
  24. package/dist/agent-adapter/claude/adapter.d.ts +0 -6
  25. package/dist/agent-adapter/claude/adapter.js +0 -8
  26. package/dist/agent-adapter/claude/defaults.d.ts +10 -7
  27. package/dist/agent-adapter/claude/defaults.js +18 -16
  28. package/dist/agent-adapter/claude/hooks-builder.js +2 -2
  29. package/dist/agent-adapter/claude/spawn-args.d.ts +0 -3
  30. package/dist/agent-adapter/claude/spawn-args.js +20 -16
  31. package/dist/agent-adapter/claude/turn-machine.d.ts +11 -0
  32. package/dist/agent-adapter/claude/turn-machine.js +46 -5
  33. package/dist/agent-adapter/normalize/prompt-builder.d.ts +16 -1
  34. package/dist/agent-adapter/normalize/prompt-builder.js +24 -6
  35. package/dist/agent-adapter/pi/mcp-bridge-logic.d.ts +11 -2
  36. package/dist/agent-adapter/pi/mcp-bridge-logic.js +32 -1
  37. package/dist/agent-adapter/pi/mcp-bridge.js +16 -15
  38. package/dist/agent-adapter/pi/session-options.d.ts +0 -6
  39. package/dist/agent-adapter/pi/session-options.js +1 -8
  40. package/dist/agent-adapter/types.d.ts +1 -1
  41. package/dist/core/mcp-tool-gate.d.ts +3 -17
  42. package/dist/core/mcp-tool-gate.js +4 -19
  43. package/dist/core/media-types.d.ts +10 -0
  44. package/dist/core/media-types.js +34 -0
  45. package/dist/core/platform-settings-spec.js +1 -1
  46. package/dist/core/settings-spec.d.ts +22 -1
  47. package/dist/core/settings-spec.js +33 -2
  48. package/dist/core/types/agent-types.d.ts +3 -1
  49. package/dist/core/utils.d.ts +1 -1
  50. package/dist/core/utils.js +1 -1
  51. package/dist/domain/agents/config.d.ts +1 -1
  52. package/dist/domain/agents/config.js +1 -1
  53. package/dist/domain/agents/profile-switch.d.ts +1 -1
  54. package/dist/domain/agents/profile-switch.js +3 -5
  55. package/dist/domain/agents/subagent/runner.js +0 -1
  56. package/dist/domain/commissions/commission-draft.d.ts +58 -0
  57. package/dist/domain/commissions/commission-draft.js +87 -4
  58. package/dist/domain/commissions/commission-finalize.d.ts +8 -3
  59. package/dist/domain/commissions/commission-finalize.js +14 -0
  60. package/dist/domain/executions/registry.d.ts +1 -2
  61. package/dist/domain/executions/registry.js +0 -3
  62. package/dist/domain/mcp/bundled-server.js +4 -3
  63. package/dist/domain/mcp/feishu/file.js +37 -18
  64. package/dist/domain/mcp/feishu/types.d.ts +3 -0
  65. package/dist/domain/mcp/feishu-server.js +1 -1
  66. package/dist/domain/mcp/tools/{cortex-md.d.ts → agents-md.d.ts} +6 -6
  67. package/dist/domain/mcp/tools/{cortex-md.js → agents-md.js} +6 -6
  68. package/dist/domain/mcp/tools/commission-tools.d.ts +12 -1
  69. package/dist/domain/mcp/tools/commission-tools.js +68 -14
  70. package/dist/domain/mcp/tools/remote-file.d.ts +20 -0
  71. package/dist/domain/mcp/tools/remote-file.js +44 -0
  72. package/dist/domain/mcp/tools/slack.d.ts +2 -0
  73. package/dist/domain/mcp/tools/slack.js +22 -7
  74. package/dist/domain/mcp/tools/task-ops.js +5 -13
  75. package/dist/domain/mcp/tools/ui-file.js +23 -10
  76. package/dist/domain/mcp/tools/waitpoint.d.ts +3 -0
  77. package/dist/domain/mcp/tools/waitpoint.js +122 -0
  78. package/dist/domain/memory/agents-md-injector.d.ts +24 -0
  79. package/dist/domain/memory/{cortex-md-injector.js → agents-md-injector.js} +10 -7
  80. package/dist/domain/projects/project-store.d.ts +1 -1
  81. package/dist/domain/projects/project-store.js +3 -3
  82. package/dist/domain/remote/client-hot-reload.js +3 -1
  83. package/dist/domain/remote/client-manager.js +105 -126
  84. package/dist/domain/remote/client-ssh-tunnel.d.ts +16 -5
  85. package/dist/domain/remote/client-ssh-tunnel.js +12 -5
  86. package/dist/domain/remote/cortex-client-config.d.ts +1 -1
  87. package/dist/domain/remote/cortex-client-config.js +1 -1
  88. package/dist/domain/remote/device-file.d.ts +51 -0
  89. package/dist/domain/remote/device-file.js +193 -0
  90. package/dist/domain/remote/device-port.js +3 -0
  91. package/dist/domain/remote/reverse-stream.d.ts +18 -7
  92. package/dist/domain/remote/reverse-stream.js +19 -6
  93. package/dist/domain/runs/builders.js +0 -1
  94. package/dist/domain/runs/compact.js +0 -1
  95. package/dist/domain/runs/engine-spec.d.ts +11 -4
  96. package/dist/domain/runs/engine-spec.js +7 -4
  97. package/dist/domain/runs/prompt.js +16 -10
  98. package/dist/domain/runs/request.d.ts +0 -1
  99. package/dist/domain/sessions/session-hooks.d.ts +5 -12
  100. package/dist/domain/sessions/session-hooks.js +6 -13
  101. package/dist/domain/sessions/session-lifecycle.d.ts +4 -4
  102. package/dist/domain/sessions/session-lifecycle.js +5 -6
  103. package/dist/domain/sessions/session-retention.d.ts +1 -3
  104. package/dist/domain/sessions/session-retention.js +9 -26
  105. package/dist/domain/sessions/session-use.d.ts +32 -0
  106. package/dist/domain/sessions/session-use.js +63 -0
  107. package/dist/domain/sessions/session.js +6 -5
  108. package/dist/domain/system/server-update-check.js +29 -1
  109. package/dist/domain/system/update-ui-state.d.ts +32 -0
  110. package/dist/domain/system/update-ui-state.js +63 -0
  111. package/dist/domain/tasks/claim-recovery.js +2 -2
  112. package/dist/domain/tasks/dispatch-utils.d.ts +10 -1
  113. package/dist/domain/tasks/dispatch-utils.js +46 -1
  114. package/dist/domain/tasks/dispatcher.js +4 -5
  115. package/dist/domain/tasks/mutator.d.ts +2 -2
  116. package/dist/domain/tasks/mutator.js +2 -2
  117. package/dist/domain/tasks/system/task-cli.js +2 -2
  118. package/dist/domain/tasks/system/task-state.js +1 -1
  119. package/dist/domain/threads/runner.js +3 -2
  120. package/dist/domain/ui-service/app-router.d.ts +54 -3
  121. package/dist/domain/ui-service/app-router.js +12 -14
  122. package/dist/domain/ui-service/input-schemas.d.ts +49 -5
  123. package/dist/domain/ui-service/input-schemas.js +35 -9
  124. package/dist/domain/ui-service/mutate/platform-settings.js +1 -1
  125. package/dist/domain/ui-service/mutate/sessions.d.ts +17 -1
  126. package/dist/domain/ui-service/mutate/sessions.js +83 -3
  127. package/dist/domain/ui-service/mutate/system.d.ts +3 -1
  128. package/dist/domain/ui-service/mutate/system.js +13 -0
  129. package/dist/domain/ui-service/mutate/waitpoints.d.ts +2 -0
  130. package/dist/domain/ui-service/mutate/waitpoints.js +20 -0
  131. package/dist/domain/ui-service/platform-settings.js +1 -1
  132. package/dist/domain/ui-service/plugins-shared.js +1 -1
  133. package/dist/domain/ui-service/query/config.js +1 -1
  134. package/dist/domain/ui-service/query/executions.js +0 -2
  135. package/dist/domain/ui-service/query/machine-detail.js +3 -8
  136. package/dist/domain/ui-service/query/memory.js +1 -1
  137. package/dist/domain/ui-service/query/sessions.js +7 -0
  138. package/dist/domain/ui-service/query/system.d.ts +2 -1
  139. package/dist/domain/ui-service/query/system.js +4 -0
  140. package/dist/domain/ui-service/query/threads.js +1 -54
  141. package/dist/domain/ui-service/query/waitpoints.d.ts +30 -0
  142. package/dist/domain/ui-service/query/waitpoints.js +117 -0
  143. package/dist/domain/ui-service/query-input-schemas.d.ts +3 -0
  144. package/dist/domain/ui-service/query-input-schemas.js +3 -0
  145. package/dist/domain/ui-service/trpc.js +1 -1
  146. package/dist/domain/ui-service/types.d.ts +175 -50
  147. package/dist/domain/ui-service/types.js +1 -1
  148. package/dist/domain/ui-service/ui-service.js +13 -33
  149. package/dist/domain/waitpoints/notices.d.ts +21 -0
  150. package/dist/domain/waitpoints/notices.js +115 -0
  151. package/dist/domain/waitpoints/service.d.ts +91 -0
  152. package/dist/domain/waitpoints/service.js +243 -0
  153. package/dist/entry/app.js +39 -29
  154. package/dist/entry/auth-login-cli.js +1 -1
  155. package/dist/entry/auth-login-terminal.js +1 -1
  156. package/dist/entry/init-auth.js +1 -1
  157. package/dist/entry/init.js +6 -6
  158. package/dist/entry/signal-cli.d.ts +30 -0
  159. package/dist/entry/signal-cli.js +207 -0
  160. package/dist/entry/start-ui-http.d.ts +1 -1
  161. package/dist/entry/start-ui-http.js +5 -3
  162. package/dist/events/event-types.d.ts +5 -7
  163. package/dist/hooks/{cortex-md-injector.mjs → agents-md-injector.mjs} +117 -26
  164. package/dist/hooks/cortex-hook-api.mjs +2 -2
  165. package/dist/hooks/new-session-hook.mjs +2 -2
  166. package/dist/hooks/rules-loader.mjs +2 -2
  167. package/dist/hooks/status-md-guard.mjs +8 -8
  168. package/dist/hooks/task-status-check.mjs +18 -76
  169. package/dist/hooks/tasks-yaml-guard.mjs +2 -2
  170. package/dist/orchestration/agent-file-send.d.ts +9 -0
  171. package/dist/orchestration/agent-file-send.js +21 -2
  172. package/dist/orchestration/agent-runner.d.ts +4 -3
  173. package/dist/orchestration/agent-runner.js +25 -23
  174. package/dist/orchestration/attachments-store.d.ts +31 -0
  175. package/dist/orchestration/attachments-store.js +184 -0
  176. package/dist/orchestration/conversation-request.d.ts +30 -8
  177. package/dist/orchestration/conversation-request.js +62 -26
  178. package/dist/orchestration/edit-retry.js +2 -1
  179. package/dist/orchestration/interactions/ask-user-resume.js +2 -1
  180. package/dist/orchestration/interactions/plan-approvals.js +1 -1
  181. package/dist/orchestration/interactions/ui-update-prompt.d.ts +8 -0
  182. package/dist/orchestration/interactions/ui-update-prompt.js +47 -0
  183. package/dist/orchestration/outputs-store.d.ts +11 -0
  184. package/dist/orchestration/outputs-store.js +32 -6
  185. package/dist/orchestration/resume-dispatcher.js +2 -2
  186. package/dist/orchestration/routing/file-handler.d.ts +23 -2
  187. package/dist/orchestration/routing/file-handler.js +22 -5
  188. package/dist/orchestration/routing/webhook.js +240 -39
  189. package/dist/orchestration/session-compact.d.ts +3 -0
  190. package/dist/orchestration/session-compact.js +3 -2
  191. package/dist/orchestration/session-events.d.ts +6 -0
  192. package/dist/orchestration/session-events.js +5 -0
  193. package/dist/orchestration/session-gateway.d.ts +1 -1
  194. package/dist/orchestration/session-gateway.js +1 -0
  195. package/dist/orchestration/thread-executor.d.ts +2 -0
  196. package/dist/orchestration/thread-executor.js +11 -1
  197. package/dist/orchestration/thread-input.d.ts +3 -2
  198. package/dist/orchestration/thread-input.js +8 -9
  199. package/dist/orchestration/turn/turn-prep.d.ts +15 -1
  200. package/dist/orchestration/turn/turn-prep.js +21 -9
  201. package/dist/orchestration/waitpoint-ingress.d.ts +41 -0
  202. package/dist/orchestration/waitpoint-ingress.js +172 -0
  203. package/dist/orchestration/waitpoint-notifier.d.ts +21 -0
  204. package/dist/orchestration/waitpoint-notifier.js +119 -0
  205. package/dist/orchestration/waitpoint-remote-drain.d.ts +20 -0
  206. package/dist/orchestration/waitpoint-remote-drain.js +147 -0
  207. package/dist/orchestration/waitpoint-sweep.d.ts +42 -0
  208. package/dist/orchestration/waitpoint-sweep.js +87 -0
  209. package/dist/platform/adapters/feishu-image.d.ts +19 -0
  210. package/dist/platform/adapters/feishu-image.js +71 -0
  211. package/dist/platform/adapters/feishu.d.ts +2 -0
  212. package/dist/platform/adapters/feishu.js +26 -16
  213. package/dist/platform/ui-http/app-update.d.ts +11 -0
  214. package/dist/platform/ui-http/app-update.js +3 -0
  215. package/dist/platform/ui-http/listening-ports.d.ts +1 -1
  216. package/dist/platform/ui-http/listening-ports.js +1 -1
  217. package/dist/platform/ui-http/ui-session.js +1 -1
  218. package/dist/store/conversation-ledger-repo.d.ts +10 -19
  219. package/dist/store/conversation-ledger-repo.js +143 -152
  220. package/dist/store/execution-repo.d.ts +1 -19
  221. package/dist/store/execution-repo.js +1 -18
  222. package/dist/store/project-notes-repo.js +11 -2
  223. package/dist/store/prompt-migration-replacements.js +1 -1
  224. package/dist/store/session-registry-import.d.ts +34 -0
  225. package/dist/store/session-registry-import.js +182 -0
  226. package/dist/store/session-registry-journal.d.ts +107 -0
  227. package/dist/store/session-registry-journal.js +308 -19
  228. package/dist/store/session-registry-repo.d.ts +113 -28
  229. package/dist/store/session-registry-repo.js +288 -105
  230. package/dist/store/version-migrations.d.ts +29 -3
  231. package/dist/store/version-migrations.js +288 -24
  232. package/dist/store/waitpoint-repo.d.ts +108 -0
  233. package/dist/store/waitpoint-repo.js +94 -0
  234. package/package.json +2 -2
  235. package/web/dist/assets/index-CwwQNMpP.css +1 -0
  236. package/web/dist/assets/index-DLSfgq3o.js +444 -0
  237. package/web/dist/assets/{index-aHbOZSP6.js → index-DZTuqUO4.js} +1 -1
  238. package/web/dist/index.html +2 -2
  239. package/defaults/config/hooks/08-cortex-md-injector-post-tool.json +0 -10
  240. package/dist/domain/executions/log-tailer.d.ts +0 -71
  241. package/dist/domain/executions/log-tailer.js +0 -194
  242. package/dist/domain/memory/cortex-md-injector.d.ts +0 -24
  243. package/dist/domain/memory/cortex-md-scanner.d.ts +0 -10
  244. package/dist/domain/memory/cortex-md-scanner.js +0 -66
  245. package/dist/domain/remote/cortex-client.d.ts +0 -1
  246. package/dist/domain/remote/cortex-client.js +0 -662
  247. package/dist/domain/tasks/system/cortex-run.d.ts +0 -25
  248. package/dist/domain/tasks/system/cortex-run.js +0 -360
  249. package/dist/store/session-repo.d.ts +0 -65
  250. package/dist/store/session-repo.js +0 -184
  251. package/web/dist/assets/index-BuXbCsuz.js +0 -444
  252. package/web/dist/assets/index-CCPxQ94C.css +0 -1
  253. /package/defaults/{CORTEX.md → AGENTS.md} +0 -0
  254. /package/defaults/config/{CORTEX.md → AGENTS.md} +0 -0
  255. /package/defaults/context/{CORTEX.md → AGENTS.md} +0 -0
  256. /package/defaults/context/ideas/{CORTEX.md → AGENTS.md} +0 -0
  257. /package/defaults/context/projects/{CORTEX.md → AGENTS.md} +0 -0
  258. /package/defaults/context/scans/{CORTEX.md → AGENTS.md} +0 -0
  259. /package/defaults/context/user/{CORTEX.md → AGENTS.md} +0 -0
@@ -0,0 +1,71 @@
1
+ // input: a local file a Feishu send is about to carry
2
+ // output: an image_key when Feishu can show it inline in the chat, null when it has to go as a file
3
+ // pos: platform/adapters — shared by the Feishu adapter's `uploadFile` and the `feishu_send_file`
4
+ // MCP tool, the two independent implementations of "send this file to Feishu". Both used to
5
+ // call `im/v1/files` unconditionally, so a screenshot the agent produced arrived as a
6
+ // download card: the user had to tap it to see their own picture, and it never previewed in
7
+ // a notification or on mobile. `im/v1/images` was never called at all.
8
+ import { createReadStream, promises as fs } from 'fs';
9
+ import { sniffImageMime } from '../../core/media-types.js';
10
+ import { createLogger } from '../../core/log.js';
11
+ const log = createLogger('feishu-image');
12
+ /** Feishu rejects an image upload above 10 MB (im/v1/images). Anything larger goes as a file. */
13
+ export const FEISHU_IMAGE_MAX_BYTES = 10 * 1024 * 1024;
14
+ /** Bytes read to identify the file's real type. */
15
+ const SNIFF_BYTES = 16;
16
+ /** The formats Feishu renders inline in a chat. Deliberately a subset of what it accepts: a format
17
+ * we cannot identify from its first bytes is safer as a file than as a rejected upload. */
18
+ const INLINE_IMAGE_MIMES = new Set(['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp']);
19
+ /**
20
+ * The mime Feishu would show inline for this file, or null when it must be sent as a file.
21
+ *
22
+ * Decided from the bytes, not the extension: the agent writes `chart.png` with whatever its plotting
23
+ * library produced, and a mislabelled file that is uploaded as an image is rejected by the API.
24
+ */
25
+ export async function inlineImageMime(filePath, size) {
26
+ if (!(size > 0) || size > FEISHU_IMAGE_MAX_BYTES)
27
+ return null;
28
+ let handle;
29
+ try {
30
+ handle = await fs.open(filePath, 'r');
31
+ const buf = Buffer.alloc(SNIFF_BYTES);
32
+ const { bytesRead } = await handle.read(buf, 0, SNIFF_BYTES, 0);
33
+ const mime = sniffImageMime(buf.subarray(0, bytesRead));
34
+ return mime && INLINE_IMAGE_MIMES.has(mime) ? mime : null;
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ finally {
40
+ await handle?.close().catch(() => undefined);
41
+ }
42
+ }
43
+ /**
44
+ * Upload `filePath` as a chat image and return its `image_key`, or null when the caller should send
45
+ * it as a file instead.
46
+ *
47
+ * Null is the ordinary outcome for a non-image, an oversized image — and for an upload the app is
48
+ * not allowed to make: `im/v1/images` needs the `im:resource` scope, which an app registered before
49
+ * Cortex ever sent an image will not have. A missing scope must degrade to the previous behaviour,
50
+ * never lose the send.
51
+ */
52
+ export async function uploadFeishuImage(client, filePath, size) {
53
+ if (!(await inlineImageMime(filePath, size)))
54
+ return null;
55
+ try {
56
+ const res = await client.im.v1.image.create({
57
+ data: { image_type: 'message', image: createReadStream(filePath) },
58
+ });
59
+ if (res && typeof res.code === 'number' && res.code !== 0) {
60
+ throw new Error(`Feishu API error ${res.code}: ${res.msg ?? 'unknown'}`);
61
+ }
62
+ const key = res?.data?.image_key ?? res?.image_key;
63
+ if (key)
64
+ return key;
65
+ log.warn(`image upload returned no image_key for ${filePath}; sending it as a file`);
66
+ }
67
+ catch (e) {
68
+ log.warn(`image upload failed for ${filePath} (${e.message}); sending it as a file`);
69
+ }
70
+ return null;
71
+ }
@@ -50,6 +50,8 @@ export declare class FeishuAdapter implements PlatformAdapter {
50
50
  markQueued(ref: MessageRef): Promise<void>;
51
51
  unmarkQueued(ref: MessageRef): Promise<void>;
52
52
  uploadFile(destination: Destination, filePath: string, opts?: FileUploadOpts): Promise<void>;
53
+ /** Upload as a chat file and return its file_key. */
54
+ private uploadFeishuFile;
53
55
  downloadFile(fileRef: PlatformFileRef, destDir: string): Promise<DownloadedFile>;
54
56
  getPermalink(_ref: MessageRef): Promise<string | null>;
55
57
  openOutputStream(destination: Destination, opts?: OpenOutputStreamOpts): OutputStream;
@@ -7,6 +7,7 @@ import { updateSettings } from '../../core/settings.js';
7
7
  import { FeishuOutputStream } from './feishu-output-stream.js';
8
8
  import { configureFeishuHttp } from './feishu-http.js';
9
9
  import { ProjectConduitsStore } from './project-conduits.js';
10
+ import { uploadFeishuImage } from './feishu-image.js';
10
11
  import { reactionFailureReason, shouldWarnReactionFailure } from '../utils/reaction-diagnostics.js';
11
12
  const log = createLogger('feishu');
12
13
  /**
@@ -316,26 +317,21 @@ export class FeishuAdapter {
316
317
  if (!destResolved.channel) {
317
318
  return;
318
319
  }
319
- const { resolved: fileResolved } = this.resolveFilePath(filePath);
320
+ const { resolved: fileResolved, size } = this.resolveFilePath(filePath);
320
321
  const fileName = opts?.filename || path.basename(fileResolved);
321
- // Upload file to get file_key
322
- const uploadRes = await this.client.im.v1.file.create({
323
- data: {
324
- file_type: this.inferFeishuFileType(fileName),
325
- file_name: fileName,
326
- file: fs.readFileSync(fileResolved),
327
- },
328
- });
329
- const fileKey = uploadRes?.data?.file_key;
330
- if (!fileKey)
331
- throw new Error('Feishu file upload failed: no file_key returned');
332
- // Send file message
333
- const msgContent = JSON.stringify({ file_key: fileKey });
322
+ // A picture the user can see beats a download card. Feishu shows an `image` message inline (and
323
+ // in the notification preview); anything it cannot — a non-image, an image over 10 MB, an app
324
+ // without the `im:resource` scope — falls back to the file card this always used to send.
325
+ const imageKey = await uploadFeishuImage(this.client, fileResolved, size);
326
+ const msgType = imageKey ? 'image' : 'file';
327
+ const msgContent = imageKey
328
+ ? JSON.stringify({ image_key: imageKey })
329
+ : JSON.stringify({ file_key: await this.uploadFeishuFile(fileResolved, fileName) });
334
330
  const threadId = opts?.threadId;
335
331
  if (threadId) {
336
332
  await this.client.im.v1.message.reply({
337
333
  path: { message_id: threadId },
338
- data: { msg_type: 'file', content: msgContent },
334
+ data: { msg_type: msgType, content: msgContent },
339
335
  });
340
336
  }
341
337
  else {
@@ -343,12 +339,26 @@ export class FeishuAdapter {
343
339
  params: { receive_id_type: 'chat_id' },
344
340
  data: {
345
341
  receive_id: destResolved.channel,
346
- msg_type: 'file',
342
+ msg_type: msgType,
347
343
  content: msgContent,
348
344
  },
349
345
  });
350
346
  }
351
347
  }
348
+ /** Upload as a chat file and return its file_key. */
349
+ async uploadFeishuFile(fileResolved, fileName) {
350
+ const uploadRes = await this.client.im.v1.file.create({
351
+ data: {
352
+ file_type: this.inferFeishuFileType(fileName),
353
+ file_name: fileName,
354
+ file: fs.readFileSync(fileResolved),
355
+ },
356
+ });
357
+ const fileKey = uploadRes?.data?.file_key;
358
+ if (!fileKey)
359
+ throw new Error('Feishu file upload failed: no file_key returned');
360
+ return fileKey;
361
+ }
352
362
  async downloadFile(fileRef, destDir) {
353
363
  const raw = fileRef.raw || {};
354
364
  const messageId = raw.message_id;
@@ -45,6 +45,17 @@ export declare function parseAppAssetName(name: string): {
45
45
  */
46
46
  export declare function buildAppUpdateManifest(releases: GhRelease[], serverVersion: string): AppUpdateManifest | null;
47
47
  export interface AppUpdateRouteOptions {
48
+ /**
49
+ * When true the route serves `{}` unconditionally, which the shell reads as "no update".
50
+ *
51
+ * A server running out of a source checkout (`CORTEX_REPO`) is a development install whose
52
+ * version bears no relation to any published release, and the shell caps itself at OUR version —
53
+ * so advertising releases from here would either offer nothing or offer the wrong thing, and with
54
+ * silent updating on it would do so without asking. Same rule the npm self-update path applies
55
+ * (domain/system/server-update-check.ts), decided by the caller because the platform layer may
56
+ * not import from domain.
57
+ */
58
+ devMode?: boolean;
48
59
  serverVersion?: string;
49
60
  fetchReleases?: () => Promise<GhRelease[]>;
50
61
  ttlMs?: number;
@@ -112,12 +112,15 @@ async function defaultFetchReleases() {
112
112
  */
113
113
  export function createAppUpdateRoutes(opts = {}) {
114
114
  const serverVersion = opts.serverVersion ?? CORTEX_VERSION;
115
+ const devMode = opts.devMode ?? false;
115
116
  const fetchReleases = opts.fetchReleases ?? defaultFetchReleases;
116
117
  const ttlMs = opts.ttlMs ?? DEFAULT_TTL_MS;
117
118
  const now = opts.now ?? Date.now;
118
119
  let lastGood = null;
119
120
  let fetchedAt = null;
120
121
  const manifest = async () => {
122
+ if (devMode)
123
+ return null;
121
124
  if (fetchedAt !== null && now() - fetchedAt < ttlMs)
122
125
  return lastGood;
123
126
  fetchedAt = now();
@@ -24,7 +24,7 @@ export declare const MIN_FORWARDABLE_PORT = 1024;
24
24
  *
25
25
  * `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
26
26
  * rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
27
- * fail. Verified on my-pc.
27
+ * fail. Verified on a Windows device.
28
28
  */
29
29
  export declare const WINDOWS_LISTENER_COMMAND = "netstat -ano; echo '#--tasklist--#'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH";
30
30
  /**
@@ -27,7 +27,7 @@ const TASKLIST_MARKER = '#--tasklist--#';
27
27
  *
28
28
  * `MSYS_NO_PATHCONV=1` is required because commands reach a Windows device through git-bash, which
29
29
  * rewrites the `/FO` switch into a filesystem path (`C:/Program Files/Git/FO`) and makes tasklist
30
- * fail. Verified on my-pc.
30
+ * fail. Verified on a Windows device.
31
31
  */
32
32
  export const WINDOWS_LISTENER_COMMAND = `netstat -ano; echo '${TASKLIST_MARKER}'; MSYS_NO_PATHCONV=1 tasklist /FO CSV /NH`;
33
33
  /** Foreign address of a listening socket, in both families. Locale-independent — unlike the state
@@ -5,7 +5,7 @@
5
5
  // HttpOnly cookie; every later request is admitted by that id instead of the token, so the
6
6
  // secret itself never enters the page's JavaScript. Ids are 32 random bytes with an
7
7
  // ABSOLUTE expiry (verify never renews — that keeps verify write-free), persisted to
8
- // DATA_DIR/ui-sessions.json at 0600 so a daemon restart does not log every browser out.
8
+ // STORE_DIR/ui-sessions.json at 0600 so a daemon restart does not log every browser out.
9
9
  // A session id is bearer-equivalent but strictly weaker than the token: the auth gate never
10
10
  // accepts it on the /forward WebSocket upgrade (see ui-http-server.ts).
11
11
  import * as crypto from 'crypto';
@@ -1,16 +1,8 @@
1
- export type TurnStatus = 'processing' | 'completed' | 'superseded';
2
- export interface LedgerTurn {
3
- turnIndex: number;
4
- userMessageTs: string;
5
- userMessageText: string;
6
- statusMessageTs: string | null;
7
- responseMessageTimestamps: string[];
8
- executionId: string | null;
9
- backupPath: string | null;
10
- status: TurnStatus;
11
- createdAt: string;
12
- updatedAt: string;
13
- }
1
+ import { type SessionRegistryRepo } from './session-registry-repo.js';
2
+ import type { TurnRecord, TurnStatus } from './session-registry-journal.js';
3
+ export type { TurnStatus };
4
+ /** The ledger's turn IS the registry's turn record — one definition, no drift. */
5
+ export type LedgerTurn = TurnRecord;
14
6
  export interface ChannelConversation {
15
7
  sessionId: string | null;
16
8
  sessionName: string | null;
@@ -23,8 +15,8 @@ export interface ChannelConversation {
23
15
  }
24
16
  export type LedgerData = Record<string, ChannelConversation>;
25
17
  export declare class ConversationLedgerRepo {
26
- private repo;
27
- constructor(filePath?: string);
18
+ private readonly registry;
19
+ constructor(registry?: SessionRegistryRepo);
28
20
  getConversation(channel: string): Promise<ChannelConversation | null>;
29
21
  findTurn(channel: string, userMessageTs: string): Promise<{
30
22
  conversation: ChannelConversation;
@@ -58,7 +50,6 @@ export declare class ConversationLedgerRepo {
58
50
  channel: string;
59
51
  }>>;
60
52
  clearBySessionIds(sessionIds: Iterable<string>): Promise<number>;
61
- deleteExceptSessionIds(sessionIds: Iterable<string>): Promise<number>;
62
53
  switchSession(channel: string, opts: {
63
54
  sessionId: string;
64
55
  sessionName: string | null;
@@ -66,7 +57,7 @@ export declare class ConversationLedgerRepo {
66
57
  profileName?: string | null;
67
58
  }): Promise<void>;
68
59
  /**
69
- * Atomic init-if-missing + beginTurn. Captures the turn index under mutex
60
+ * Atomic init-if-missing + beginTurn. Captures the turn index under one lock
70
61
  * so callers can safely pass it to sessionBackup.createBackup.
71
62
  * Returns { turn, turnIndex } for the caller.
72
63
  */
@@ -84,9 +75,9 @@ export declare class ConversationLedgerRepo {
84
75
  }>;
85
76
  /** Set the backup path on the turn identified by userMessageTs. */
86
77
  setBackupPath(channel: string, userMessageTs: string, backupPath: string | null): Promise<void>;
87
- /** Drop the in-memory cache so the next read() fetches from disk. For testing. */
78
+ /** Drop the registry's in-memory cache so the next read fetches from disk. For testing. */
88
79
  invalidate(): void;
89
- /** Wait for any in-flight mutate() to complete. For graceful SIGTERM drain. */
80
+ /** Wait for any in-flight registry mutation to complete. For graceful SIGTERM drain. */
90
81
  flush(): Promise<void>;
91
82
  }
92
83
  export declare const conversationLedger: ConversationLedgerRepo;