@cortex-agent/server 2026.5.19-3 → 2026.5.22-2

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 (134) hide show
  1. package/README.md +5 -1
  2. package/defaults/config/thread-templates.json +65 -39
  3. package/defaults/plugins/cortex-system/skills/schedule/SKILL.md +4 -4
  4. package/defaults/prompts/directives/coder-reviewer.md +9 -4
  5. package/defaults/prompts/directives/coder.md +10 -2
  6. package/dist/core/gateway-generator.js +26 -4
  7. package/dist/core/log.js +61 -12
  8. package/dist/core/profile-generator.js +4 -3
  9. package/dist/core/status-format.js +1 -1
  10. package/dist/core/task-parser.d.ts +1 -1
  11. package/dist/core/task-parser.js +13 -6
  12. package/dist/core/types/thread-types.d.ts +4 -2
  13. package/dist/domain/costs/codex-usage-monitor.d.ts +1 -2
  14. package/dist/domain/costs/codex-usage-monitor.js +2 -2
  15. package/dist/domain/costs/cost-tracker.d.ts +2 -0
  16. package/dist/domain/costs/cost-tracker.js +4 -20
  17. package/dist/domain/costs/rate-limit-throttle.js +1 -4
  18. package/dist/domain/mcp/tools/context.d.ts +4 -2
  19. package/dist/domain/mcp/tools/context.js +7 -5
  20. package/dist/domain/mcp/tools/schedule.d.ts +1 -1
  21. package/dist/domain/mcp/tools/schedule.js +24 -20
  22. package/dist/domain/memory/index-regen.js +8 -5
  23. package/dist/domain/monitor/disk-monitor.js +1 -6
  24. package/dist/domain/projects/index.d.ts +2 -0
  25. package/dist/domain/projects/index.js +3 -0
  26. package/dist/domain/projects/project-store.d.ts +54 -0
  27. package/dist/domain/projects/project-store.js +194 -0
  28. package/dist/domain/projects/project-types.d.ts +11 -0
  29. package/dist/domain/projects/project-types.js +5 -0
  30. package/dist/domain/remote/client-hot-reload.d.ts +1 -0
  31. package/dist/domain/remote/client-hot-reload.js +284 -53
  32. package/dist/domain/scheduling/jobs/_shared.d.ts +1 -1
  33. package/dist/domain/scheduling/jobs/_shared.js +6 -5
  34. package/dist/domain/scheduling/jobs/memory-index-regen.js +2 -2
  35. package/dist/domain/scheduling/jobs/scheduled-task.d.ts +2 -2
  36. package/dist/domain/scheduling/jobs/scheduled-task.js +38 -36
  37. package/dist/domain/scheduling/jobs/sync-public.d.ts +1 -0
  38. package/dist/domain/scheduling/jobs/sync-public.js +34 -0
  39. package/dist/domain/scheduling/jobs/target-dispatch.d.ts +3 -7
  40. package/dist/domain/scheduling/jobs/target-dispatch.js +7 -9
  41. package/dist/domain/scheduling/jobs/task-archive.js +2 -2
  42. package/dist/domain/scheduling/jobs/task-dispatch.js +18 -16
  43. package/dist/domain/scheduling/runner.d.ts +1 -0
  44. package/dist/domain/scheduling/runner.js +2 -0
  45. package/dist/domain/scheduling/schedule-cli.d.ts +1 -0
  46. package/dist/domain/scheduling/schedule-cli.js +14 -14
  47. package/dist/domain/scheduling/schedule-command.js +45 -36
  48. package/dist/domain/scheduling/scheduler.d.ts +1 -1
  49. package/dist/domain/scheduling/scheduler.js +12 -11
  50. package/dist/domain/sessions/session-hooks.d.ts +10 -11
  51. package/dist/domain/sessions/session-hooks.js +26 -27
  52. package/dist/domain/sessions/session-registry.d.ts +10 -5
  53. package/dist/domain/sessions/session-registry.js +24 -9
  54. package/dist/domain/tasks/pending-tracker.js +8 -9
  55. package/dist/domain/tasks/system/task-cli.d.ts +2 -0
  56. package/dist/domain/tasks/system/task-cli.js +189 -29
  57. package/dist/domain/tasks/system/task-lifecycle-edit.js +3 -3
  58. package/dist/domain/threads/hook-runner.js +12 -7
  59. package/dist/domain/threads/runner.d.ts +3 -3
  60. package/dist/domain/threads/runner.js +30 -28
  61. package/dist/domain/threads/state-machine.d.ts +3 -0
  62. package/dist/domain/threads/state-machine.js +4 -0
  63. package/dist/entry/app.js +30 -9
  64. package/dist/entry/cli.js +19 -4
  65. package/dist/entry/daemon.js +28 -2
  66. package/dist/entry/startup-notify.js +8 -6
  67. package/dist/orchestration/agent-runner.js +19 -13
  68. package/dist/orchestration/durable-helpers.js +3 -2
  69. package/dist/orchestration/interactions/ask-user-question.d.ts +2 -3
  70. package/dist/orchestration/interactions/ask-user-question.js +5 -4
  71. package/dist/orchestration/interactions/interaction-handlers.js +8 -5
  72. package/dist/orchestration/interactions/plan-handler.js +3 -3
  73. package/dist/orchestration/lifecycle.js +43 -38
  74. package/dist/orchestration/routing/commands/cancel.js +9 -8
  75. package/dist/orchestration/routing/commands/channel.js +32 -26
  76. package/dist/orchestration/routing/commands/cost.js +5 -3
  77. package/dist/orchestration/routing/commands/device.js +2 -1
  78. package/dist/orchestration/routing/commands/dispatch.js +8 -7
  79. package/dist/orchestration/routing/commands/index.js +7 -4
  80. package/dist/orchestration/routing/commands/mode.js +24 -18
  81. package/dist/orchestration/routing/commands/nvtop.js +14 -12
  82. package/dist/orchestration/routing/commands/orient.js +2 -1
  83. package/dist/orchestration/routing/commands/schedule.js +2 -1
  84. package/dist/orchestration/routing/commands/sendfile.js +12 -9
  85. package/dist/orchestration/routing/commands/session.js +12 -10
  86. package/dist/orchestration/routing/commands/status.js +2 -2
  87. package/dist/orchestration/routing/commands/tail.js +10 -6
  88. package/dist/orchestration/routing/commands/task.js +5 -4
  89. package/dist/orchestration/routing/commands/thread-handlers.js +19 -12
  90. package/dist/orchestration/routing/hook-bridge-subscribers.js +15 -13
  91. package/dist/orchestration/status-helpers.d.ts +4 -5
  92. package/dist/orchestration/status-helpers.js +7 -8
  93. package/dist/orchestration/thread-executor.js +21 -12
  94. package/dist/platform/adapter.d.ts +13 -9
  95. package/dist/platform/adapter.js +1 -1
  96. package/dist/platform/adapters/feishu-output-stream.d.ts +27 -0
  97. package/dist/platform/adapters/feishu-output-stream.js +114 -0
  98. package/dist/platform/adapters/feishu.d.ts +16 -7
  99. package/dist/platform/adapters/feishu.js +64 -18
  100. package/dist/platform/adapters/index.d.ts +4 -1
  101. package/dist/platform/adapters/index.js +1 -1
  102. package/dist/platform/adapters/slack-output-stream.d.ts +55 -0
  103. package/dist/platform/{virtual-message.js → adapters/slack-output-stream.js} +98 -165
  104. package/dist/platform/adapters/slack-project-conduits.d.ts +9 -0
  105. package/dist/platform/adapters/slack-project-conduits.js +40 -0
  106. package/dist/platform/adapters/slack.d.ts +18 -8
  107. package/dist/platform/adapters/slack.js +82 -24
  108. package/dist/platform/index.d.ts +3 -2
  109. package/dist/platform/index.js +1 -1
  110. package/dist/platform/output-stream-chunk.d.ts +6 -0
  111. package/dist/platform/output-stream-chunk.js +45 -0
  112. package/dist/platform/output-stream-helpers.d.ts +6 -0
  113. package/dist/platform/output-stream-helpers.js +11 -0
  114. package/dist/platform/output-stream.d.ts +28 -0
  115. package/dist/platform/output-stream.js +4 -0
  116. package/dist/platform/testing.d.ts +41 -8
  117. package/dist/platform/testing.js +93 -11
  118. package/dist/platform/tool-trace.d.ts +9 -8
  119. package/dist/platform/tool-trace.js +19 -17
  120. package/dist/platform/types.d.ts +21 -1
  121. package/dist/platform/types.js +17 -1
  122. package/dist/store/channel-repo.d.ts +6 -0
  123. package/dist/store/channel-repo.js +9 -0
  124. package/dist/store/json-repository.js +12 -1
  125. package/dist/store/outbound-queue.d.ts +5 -4
  126. package/dist/store/outbound-queue.js +9 -6
  127. package/dist/store/schedule-repo.d.ts +9 -5
  128. package/dist/store/schedule-repo.js +59 -14
  129. package/dist/store/session-registry-repo.d.ts +36 -7
  130. package/dist/store/session-registry-repo.js +186 -25
  131. package/dist/store/thread-repo.d.ts +1 -0
  132. package/dist/store/thread-repo.js +8 -0
  133. package/package.json +1 -1
  134. package/dist/platform/virtual-message.d.ts +0 -68
@@ -5,6 +5,9 @@
5
5
  import * as lark from '@larksuiteoapi/node-sdk';
6
6
  import * as fs from 'fs';
7
7
  import * as path from 'path';
8
+ import { createLogger } from '../../core/log.js';
9
+ import { FeishuOutputStream } from './feishu-output-stream.js';
10
+ const log = createLogger('feishu');
8
11
  export class FeishuAdapter {
9
12
  name = 'feishu';
10
13
  capabilities = {
@@ -84,7 +87,11 @@ export class FeishuAdapter {
84
87
  this.modalHandlers.set(callbackId, handler);
85
88
  }
86
89
  // --- Outbound messaging ---
87
- async postMessage(channel, content, opts) {
90
+ async postMessage(destination, content, opts) {
91
+ const resolved = await this.resolveDestination(destination);
92
+ if (!resolved.channel) {
93
+ return { channel: '', messageId: '' };
94
+ }
88
95
  const threadId = opts?.threadId;
89
96
  // If replying in a thread, use the reply API
90
97
  if (threadId) {
@@ -94,13 +101,13 @@ export class FeishuAdapter {
94
101
  const res = await this.client.im.v1.message.create({
95
102
  params: { receive_id_type: 'chat_id' },
96
103
  data: {
97
- receive_id: channel,
104
+ receive_id: resolved.channel,
98
105
  msg_type: msgType,
99
106
  content: msgContent,
100
107
  },
101
108
  });
102
109
  const messageId = res?.data?.message_id || '';
103
- return { channel, messageId };
110
+ return { channel: resolved.channel, messageId };
104
111
  }
105
112
  async updateMessage(ref, content) {
106
113
  // Feishu only supports updating interactive (card) messages via PATCH.
@@ -116,7 +123,11 @@ export class FeishuAdapter {
116
123
  });
117
124
  }
118
125
  // --- Interactive messages ---
119
- async postInteractive(channel, content, opts) {
126
+ async postInteractive(destination, content, opts) {
127
+ const resolved = await this.resolveDestination(destination);
128
+ if (!resolved.channel) {
129
+ return { channel: '', messageId: '' };
130
+ }
120
131
  const elements = content.richBlocks
121
132
  ? this.richBlocksToFeishuElements(content.richBlocks)
122
133
  : [];
@@ -142,20 +153,19 @@ export class FeishuAdapter {
142
153
  },
143
154
  });
144
155
  const messageId = res?.data?.message_id || '';
145
- return { channel, messageId, threadId };
156
+ return { channel: resolved.channel, messageId, threadId };
146
157
  }
147
158
  const res = await this.client.im.v1.message.create({
148
159
  params: { receive_id_type: 'chat_id' },
149
160
  data: {
150
- receive_id: channel,
161
+ receive_id: resolved.channel,
151
162
  msg_type: 'interactive',
152
163
  content: JSON.stringify(cardJson),
153
164
  },
154
165
  });
155
166
  const messageId = res?.data?.message_id || '';
156
- return { channel, messageId };
167
+ return { channel: resolved.channel, messageId };
157
168
  }
158
- // --- Modals (degraded to card forms) ---
159
169
  async openModal(triggerId, modal) {
160
170
  // Feishu has no native modal. Degrade to posting a card with an embedded
161
171
  // form container to the channel. triggerId format: "chatId:messageId"
@@ -185,15 +195,19 @@ export class FeishuAdapter {
185
195
  }
186
196
  }
187
197
  // --- Files ---
188
- async uploadFile(channel, filePath, opts) {
189
- const { resolved, size } = this.resolveFilePath(filePath);
190
- const fileName = opts?.filename || path.basename(resolved);
198
+ async uploadFile(destination, filePath, opts) {
199
+ const destResolved = await this.resolveDestination(destination);
200
+ if (!destResolved.channel) {
201
+ return;
202
+ }
203
+ const { resolved: fileResolved, size } = this.resolveFilePath(filePath);
204
+ const fileName = opts?.filename || path.basename(fileResolved);
191
205
  // Upload file to get file_key
192
206
  const uploadRes = await this.client.im.v1.file.create({
193
207
  data: {
194
208
  file_type: this.inferFeishuFileType(fileName),
195
209
  file_name: fileName,
196
- file: fs.readFileSync(resolved),
210
+ file: fs.readFileSync(fileResolved),
197
211
  },
198
212
  });
199
213
  const fileKey = uploadRes?.data?.file_key;
@@ -212,7 +226,7 @@ export class FeishuAdapter {
212
226
  await this.client.im.v1.message.create({
213
227
  params: { receive_id_type: 'chat_id' },
214
228
  data: {
215
- receive_id: channel,
229
+ receive_id: destResolved.channel,
216
230
  msg_type: 'file',
217
231
  content: msgContent,
218
232
  },
@@ -236,11 +250,43 @@ export class FeishuAdapter {
236
250
  async postEphemeral(_channel, _userId, _text) {
237
251
  // Feishu does not support ephemeral messages — no-op.
238
252
  }
239
- getAdminChannel() {
240
- return this.config.adminChannel || null;
253
+ // --- Output stream ---
254
+ openOutputStream(destination, opts) {
255
+ return new FeishuOutputStream(this, destination, opts);
241
256
  }
242
- getRawClient() {
243
- return this.client;
257
+ // --- Project conduit mapping (file-backed, separate file from Slack) ---
258
+ _feishuConduits = {};
259
+ async bindProjectConduit(projectId, conduitHint) {
260
+ this._feishuConduits[projectId] = conduitHint;
261
+ }
262
+ async unbindProjectConduit(projectId) {
263
+ delete this._feishuConduits[projectId];
264
+ }
265
+ async getProjectConduits() {
266
+ return { ...this._feishuConduits };
267
+ }
268
+ /**
269
+ * Resolve a Destination to a concrete Feishu chat_id + kind label.
270
+ * Returns channel=null for destinations that should be silently dropped
271
+ * (unconfigured admin channel).
272
+ */
273
+ async resolveDestination(dest) {
274
+ switch (dest.type) {
275
+ case 'interactive-reply':
276
+ return { channel: dest.conduit, kind: 'interactive-reply' };
277
+ case 'project-report':
278
+ // FIXME: resolve projectId → Feishu chat_id when a project→chat mapping
279
+ // layer is added for Feishu. For now, projectId is used directly.
280
+ return { channel: dest.projectId, kind: 'project-report' };
281
+ case 'system-notice':
282
+ if (!this.config.adminChannel) {
283
+ log.warn('No admin channel configured; dropping system-notice');
284
+ return { channel: null, kind: 'system-notice-noop' };
285
+ }
286
+ return { channel: this.config.adminChannel, kind: 'system-notice' };
287
+ default:
288
+ return { channel: null, kind: 'unknown' };
289
+ }
244
290
  }
245
291
  // =========================================================================
246
292
  // Internal: Inbound event handlers
@@ -289,7 +335,7 @@ export class FeishuAdapter {
289
335
  await this.messageHandler({
290
336
  message: incoming,
291
337
  async reply(content, replyOpts) {
292
- return adapter.postMessage(ref.channel, content, {
338
+ return adapter.postMessage({ type: 'interactive-reply', conduit: ref.channel, sessionId: '' }, content, {
293
339
  threadId: replyOpts?.threadId || ref.threadId,
294
340
  });
295
341
  },
@@ -8,8 +8,11 @@ export interface AdapterConfig {
8
8
  feishu?: FeishuAdapterConfig;
9
9
  }
10
10
  export declare function createAdapter(config: AdapterConfig): PlatformAdapter;
11
+ /** Options injected from the composition root for capabilities that cross layer boundaries. */
12
+ export interface AdapterOverrides {
13
+ }
11
14
  /** Create adapter from environment variables (auto-detect platform). */
12
- export declare function createAdapterFromEnv(): PlatformAdapter;
15
+ export declare function createAdapterFromEnv(overrides?: AdapterOverrides): PlatformAdapter;
13
16
  export { SlackAdapter } from './slack.js';
14
17
  export type { SlackAdapterConfig } from './slack.js';
15
18
  export { FeishuAdapter } from './feishu.js';
@@ -25,7 +25,7 @@ export function createAdapter(config) {
25
25
  }
26
26
  }
27
27
  /** Create adapter from environment variables (auto-detect platform). */
28
- export function createAdapterFromEnv() {
28
+ export function createAdapterFromEnv(overrides) {
29
29
  const platform = (process.env.CORTEX_PLATFORM || 'slack');
30
30
  if (platform === 'slack') {
31
31
  const botToken = process.env.SLACK_BOT_TOKEN;
@@ -0,0 +1,55 @@
1
+ import type { SlackAdapter } from './slack.js';
2
+ import type { OutputStream, MutableRegion, OpenOutputStreamOpts } from '../output-stream.js';
3
+ import type { MessageRef, RichBlock, ActionElement, Destination } from '../types.js';
4
+ /**
5
+ * Test-only: override retry delays to skip real wall-clock waits.
6
+ * Pass [] for no retries, [0,0,0,0] to keep 4-attempt retry semantics with no wait.
7
+ * Production code must never call this.
8
+ */
9
+ export declare function _testSetRetryDelays(delays: readonly number[]): void;
10
+ /** Test-only: restore production retry delays. */
11
+ export declare function _testResetRetryDelays(): void;
12
+ export declare class SlackOutputStream implements OutputStream {
13
+ private adapter;
14
+ private destination;
15
+ private threadId;
16
+ private onMessagePosted;
17
+ private maxChunk;
18
+ private durable;
19
+ /** Readable label for log messages, extracted from the Destination kind. */
20
+ private get _logChannel();
21
+ private parentRef;
22
+ private currentRef;
23
+ private currentContent;
24
+ private mutableTail;
25
+ private allRefs;
26
+ private queue;
27
+ private lastError;
28
+ /** Generation counter for MutableRegion staleness tracking.
29
+ * Incremented every time openMutable is called or a seal event occurs. */
30
+ private _regionGeneration;
31
+ constructor(adapter: SlackAdapter, destination: Destination, opts?: OpenOutputStreamOpts);
32
+ emitText(text: string): void;
33
+ openMutable(text: string): MutableRegion;
34
+ postInteractive(text: string, opts?: {
35
+ richBlocks?: RichBlock[];
36
+ actions?: ActionElement[];
37
+ }): Promise<MessageRef | null>;
38
+ flush(): Promise<void>;
39
+ getRefs(): MessageRef[];
40
+ getParentRef(): MessageRef | null;
41
+ /** Called by SlackMutableRegion.update(). No-op if the generation is stale. */
42
+ _regionUpdate(generation: number, text: string): void;
43
+ /** Return a no-op region for empty text. */
44
+ private _noopRegion;
45
+ private _processAppend;
46
+ private _processOpenMutable;
47
+ private _processEditMutableTail;
48
+ /** Combined display = currentContent [+ SEP + mutableTail]. */
49
+ private _renderWithTail;
50
+ /** Synchronously move mutableTail into currentContent. */
51
+ private _sealMutableTailNow;
52
+ private _postNew;
53
+ private _postOne;
54
+ private _updateCurrent;
55
+ }