@cortex-agent/server 2026.6.15 → 2026.6.18-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 (39) hide show
  1. package/defaults/config/thread-templates.json +2 -2
  2. package/defaults/hooks/task-status-check.mjs +9 -7
  3. package/defaults/plugins/cortex-stage-gate/skills/task/SKILL.md +103 -16
  4. package/defaults/plugins/cortex-system/skills/orient/SKILL.md +6 -6
  5. package/defaults/plugins/cortex-system/skills/thread/SKILL.md +29 -35
  6. package/defaults/prompts/directives/manager.md +21 -11
  7. package/dist/agent-adapter/claude/spawn-args.d.ts +5 -0
  8. package/dist/agent-adapter/claude/spawn-args.js +6 -0
  9. package/dist/agent-adapter/types.d.ts +4 -0
  10. package/dist/core/task-parser.d.ts +6 -0
  11. package/dist/core/task-parser.js +10 -0
  12. package/dist/core/types/thread-types.d.ts +29 -0
  13. package/dist/domain/agents/facade.d.ts +4 -0
  14. package/dist/domain/agents/facade.js +3 -1
  15. package/dist/domain/mcp/core-server.js +15 -9
  16. package/dist/domain/mcp/tools/task-monitor.d.ts +2 -0
  17. package/dist/domain/mcp/tools/task-monitor.js +99 -0
  18. package/dist/domain/mcp/tools/thread-ops.js +50 -85
  19. package/dist/domain/scheduling/jobs/task-dispatch.js +12 -6
  20. package/dist/domain/tasks/dispatch-utils.d.ts +5 -0
  21. package/dist/domain/tasks/dispatch-utils.js +9 -1
  22. package/dist/domain/tasks/dispatcher.js +4 -4
  23. package/dist/domain/tasks/system/task-cli.d.ts +1 -0
  24. package/dist/domain/tasks/system/task-cli.js +82 -6
  25. package/dist/domain/tasks/system/task-mutations.d.ts +6 -1
  26. package/dist/domain/tasks/system/task-mutations.js +10 -1
  27. package/dist/domain/threads/hook-runner.js +1 -0
  28. package/dist/domain/threads/prompt-builder.js +15 -9
  29. package/dist/domain/threads/runner.d.ts +5 -0
  30. package/dist/domain/threads/runner.js +44 -11
  31. package/dist/domain/threads/state-machine.d.ts +9 -12
  32. package/dist/domain/threads/state-machine.js +27 -50
  33. package/dist/hooks/task-status-check.mjs +9 -7
  34. package/dist/orchestration/routing/webhook.js +38 -1
  35. package/dist/orchestration/thread-callback.d.ts +11 -1
  36. package/dist/orchestration/thread-callback.js +66 -30
  37. package/dist/platform/adapters/feishu.d.ts +27 -0
  38. package/dist/platform/adapters/feishu.js +136 -4
  39. package/package.json +1 -1
@@ -76,6 +76,33 @@ export declare class FeishuAdapter implements PlatformAdapter {
76
76
  * im.v1.messageResource.get (which requires both message_id and a type param).
77
77
  */
78
78
  private extractInboundFiles;
79
+ /**
80
+ * Parse a Feishu `post` (富文本/rich-text) message content payload. Feishu wraps
81
+ * a single message that mixes text and images as a post, whose `content` is a 2D
82
+ * array of paragraphs, each a run of element nodes:
83
+ * { title?, content: [ [ {tag:'text',text}, {tag:'a',text,href}, {tag:'at',user_name},
84
+ * {tag:'img',image_key} ], ... ] }
85
+ * Returns the concatenated text (paragraphs joined by '\n', non-empty title
86
+ * prefixed) and the list of inline image_keys, so callers recover BOTH the text
87
+ * and the images from one mixed message.
88
+ */
89
+ private parsePostContent;
90
+ /**
91
+ * Resolve a Feishu message's human-readable text from its type + parsed content.
92
+ * `post` (rich text) buries text in a 2D run array; plain text lives in
93
+ * parsed.text; a few legacy payloads ship a bare non-JSON string as content.
94
+ * Shared by both inbound messages and quoted-parent enrichment.
95
+ */
96
+ private extractMessageText;
97
+ /**
98
+ * Fetch the directly-quoted parent message (one level) and project it to the same
99
+ * { text, files } shape an inbound message produces, so a reply can be enriched
100
+ * with what it quotes — notably files, since a Feishu file message carries no text
101
+ * and thus cannot @ the bot. Returns null on any failure (best-effort).
102
+ * NOTE: im.v1.message.get returns content under data.items[].body.content (a JSON
103
+ * string), NOT the top-level `content` field the receive_v1 event uses.
104
+ */
105
+ private fetchQuotedParent;
79
106
  private handleCardAction;
80
107
  private buildMessagePayload;
81
108
  private buildCardJson;
@@ -464,9 +464,11 @@ export class FeishuAdapter {
464
464
  catch {
465
465
  parsed = {};
466
466
  }
467
- const text = typeof parsed.text === 'string'
468
- ? parsed.text
469
- : (typeof message.content === 'string' && !message.content.startsWith('{') ? message.content : '');
467
+ // `post` (富文本/rich-text) is what Feishu sends when a message mixes text and
468
+ // images — the text is NOT a top-level `parsed.text` but buried in a 2D array
469
+ // of paragraph element-runs, so the simple text/raw-string path below would
470
+ // yield '' and drop the user's message. Parse post specially.
471
+ let text = this.extractMessageText(messageType, parsed, message.content || '');
470
472
  const ref = {
471
473
  conduit: this._wrap(chatId),
472
474
  messageId,
@@ -474,7 +476,24 @@ export class FeishuAdapter {
474
476
  };
475
477
  // Extract file references from the parsed content. The id (file_key/image_key)
476
478
  // plus message_id + resourceType are needed by downloadFile (messageResource.get).
477
- const files = this.extractInboundFiles(messageType, parsed, messageId, chatId);
479
+ let files = this.extractInboundFiles(messageType, parsed, messageId, chatId);
480
+ // Quote/reply enrichment. When a message replies to another (parent_id set),
481
+ // Feishu delivers ONLY the reply — the quoted message's text/files are not
482
+ // inlined. A user sharing a file cannot @ the bot on the file message itself
483
+ // (file messages carry no text), so they reply-and-@ instead; without this the
484
+ // file would be lost. Fetch the direct parent (one level) unconditionally —
485
+ // including bot-authored parents — and merge its text + files into this message.
486
+ // Best-effort: a fetch failure must never drop the user's own message.
487
+ if (parentId) {
488
+ const quoted = await this.fetchQuotedParent(parentId, chatId);
489
+ if (quoted) {
490
+ if (quoted.text)
491
+ text = text ? `${text}\n\n[引用消息]\n${quoted.text}` : quoted.text;
492
+ if (quoted.files && quoted.files.length) {
493
+ files = files ? [...files, ...quoted.files] : quoted.files;
494
+ }
495
+ }
496
+ }
478
497
  // TODO: Parse Feishu forwarded/merged messages (merge_forward msg type) into
479
498
  // IncomingAttachment[]. Feishu's format differs from Slack's msg.attachments.
480
499
  const kind = files ? 'file_share' : 'user';
@@ -527,10 +546,123 @@ export class FeishuAdapter {
527
546
  if (!parsed.image_key)
528
547
  return undefined;
529
548
  return mk(parsed.image_key, `${parsed.image_key}.png`, 'image/png', 'image');
549
+ case 'post': {
550
+ // A rich-text post may embed any number of inline images (tag:'img'). Each
551
+ // image_key is a resource of THIS message, downloadable via the same
552
+ // messageResource.get(type:'image') path as a standalone image message.
553
+ const { imageKeys } = this.parsePostContent(parsed);
554
+ if (imageKeys.length === 0)
555
+ return undefined;
556
+ return imageKeys.map(k => ({
557
+ id: k,
558
+ name: `${k}.png`,
559
+ mimetype: 'image/png',
560
+ url: '',
561
+ conduit: this._wrap(chatId),
562
+ raw: { message_id: messageId, resourceType: 'image' },
563
+ }));
564
+ }
530
565
  default:
531
566
  return undefined;
532
567
  }
533
568
  }
569
+ /**
570
+ * Parse a Feishu `post` (富文本/rich-text) message content payload. Feishu wraps
571
+ * a single message that mixes text and images as a post, whose `content` is a 2D
572
+ * array of paragraphs, each a run of element nodes:
573
+ * { title?, content: [ [ {tag:'text',text}, {tag:'a',text,href}, {tag:'at',user_name},
574
+ * {tag:'img',image_key} ], ... ] }
575
+ * Returns the concatenated text (paragraphs joined by '\n', non-empty title
576
+ * prefixed) and the list of inline image_keys, so callers recover BOTH the text
577
+ * and the images from one mixed message.
578
+ */
579
+ parsePostContent(parsed) {
580
+ const imageKeys = [];
581
+ const content = parsed?.content;
582
+ if (!Array.isArray(content))
583
+ return { text: '', imageKeys };
584
+ const lines = [];
585
+ for (const paragraph of content) {
586
+ if (!Array.isArray(paragraph))
587
+ continue;
588
+ let line = '';
589
+ for (const node of paragraph) {
590
+ if (!node || typeof node !== 'object')
591
+ continue;
592
+ switch (node.tag) {
593
+ case 'text':
594
+ case 'a':
595
+ if (typeof node.text === 'string')
596
+ line += node.text;
597
+ break;
598
+ case 'at':
599
+ if (typeof node.user_name === 'string')
600
+ line += `@${node.user_name}`;
601
+ break;
602
+ case 'img':
603
+ if (typeof node.image_key === 'string')
604
+ imageKeys.push(node.image_key);
605
+ break;
606
+ default:
607
+ break;
608
+ }
609
+ }
610
+ lines.push(line);
611
+ }
612
+ let text = lines.join('\n').trim();
613
+ if (typeof parsed.title === 'string' && parsed.title.trim()) {
614
+ text = text ? `${parsed.title}\n${text}` : parsed.title.trim();
615
+ }
616
+ return { text, imageKeys };
617
+ }
618
+ /**
619
+ * Resolve a Feishu message's human-readable text from its type + parsed content.
620
+ * `post` (rich text) buries text in a 2D run array; plain text lives in
621
+ * parsed.text; a few legacy payloads ship a bare non-JSON string as content.
622
+ * Shared by both inbound messages and quoted-parent enrichment.
623
+ */
624
+ extractMessageText(messageType, parsed, rawContent) {
625
+ if (messageType === 'post')
626
+ return this.parsePostContent(parsed).text;
627
+ if (typeof parsed?.text === 'string')
628
+ return parsed.text;
629
+ if (typeof rawContent === 'string' && rawContent && !rawContent.startsWith('{'))
630
+ return rawContent;
631
+ return '';
632
+ }
633
+ /**
634
+ * Fetch the directly-quoted parent message (one level) and project it to the same
635
+ * { text, files } shape an inbound message produces, so a reply can be enriched
636
+ * with what it quotes — notably files, since a Feishu file message carries no text
637
+ * and thus cannot @ the bot. Returns null on any failure (best-effort).
638
+ * NOTE: im.v1.message.get returns content under data.items[].body.content (a JSON
639
+ * string), NOT the top-level `content` field the receive_v1 event uses.
640
+ */
641
+ async fetchQuotedParent(parentId, chatId) {
642
+ try {
643
+ const resp = await this.client.im.v1.message.get({ path: { message_id: parentId } });
644
+ const item = resp?.data?.items?.[0];
645
+ if (!item)
646
+ return null;
647
+ const messageType = item.msg_type || '';
648
+ const rawContent = item.body?.content || '';
649
+ let parsed = {};
650
+ try {
651
+ parsed = JSON.parse(rawContent || '{}');
652
+ }
653
+ catch {
654
+ parsed = {};
655
+ }
656
+ const text = this.extractMessageText(messageType, parsed, rawContent);
657
+ // Files of the parent must download against the PARENT's message_id.
658
+ const files = this.extractInboundFiles(messageType, parsed, item.message_id || parentId, chatId);
659
+ return { text, files };
660
+ }
661
+ catch (e) {
662
+ log.warn(`Failed to fetch quoted parent ${parentId}: ${e.message}`);
663
+ return null;
664
+ }
665
+ }
534
666
  async handleCardAction(data) {
535
667
  const event = data.event || data;
536
668
  const action = event.action || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortex-agent/server",
3
- "version": "2026.6.15",
3
+ "version": "2026.6.18-2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Autonomous agent system for long-running projects — mission-driven, multi-agent pipelines, self-evolving skills.",