cladogram 0.6.0-beta.5 → 0.6.0-beta.6

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.
@@ -156,10 +156,17 @@ export function createCladoPiTools({
156
156
  events = null,
157
157
  emit = () => {},
158
158
  waitForUserAnswer = null,
159
+ sessionOps = null,
160
+ automationOps = null,
161
+ onCardChanges = null,
159
162
  }) {
160
163
  const runMcp = async (tool, input = {}) => {
161
164
  if (!workspaceService) throw new Error('Clado workspaceService 未就绪。');
162
- return workspaceService(tool, { workspace, ...input });
165
+ const res = await workspaceService(tool, { workspace, ...input });
166
+ if (res && typeof onCardChanges === 'function' && (Array.isArray(res.cardChanges) || ['create', 'update', 'delete', 'insert', 'rename', 'move', 'connect', 'disconnect'].includes(input.action))) {
167
+ try { onCardChanges(tool, res); } catch {}
168
+ }
169
+ return res;
163
170
  };
164
171
 
165
172
  const inspectGraphCheck = async file => {
@@ -629,5 +636,157 @@ export function createCladoPiTools({
629
636
  }
630
637
  },
631
638
  }),
639
+
640
+ ...(sessionOps ? [
641
+ defineTool({
642
+ name: 'clado_session_list',
643
+ label: '列出主会话',
644
+ description: '列出当前工作空间内所有主会话(角色、状态、最近活跃时间、消息数与摘要),支持传 sinceMinutes(如 20)只看最近 N 分钟内活跃的会话。',
645
+ promptSnippet: '列出工作区主会话(支持 sinceMinutes 过滤最近活跃会话)',
646
+ parameters: {
647
+ type: 'object',
648
+ properties: {
649
+ sinceMinutes: { type: 'number', description: '可选:仅返回最近 N 分钟内活跃过的会话(例如 20)' },
650
+ includeArchived: { type: 'boolean', description: '是否包含已归档会话,默认 false' },
651
+ },
652
+ },
653
+ async execute(_id, params = {}) {
654
+ try {
655
+ const list = await sessionOps.list({
656
+ sinceMinutes: Number(params.sinceMinutes) || 0,
657
+ includeArchived: Boolean(params.includeArchived),
658
+ });
659
+ return textResult({
660
+ currentSessionId: sessionOps.currentSessionId || '',
661
+ count: list.length,
662
+ sessions: list.map(s => ({
663
+ id: s.id,
664
+ title: s.title,
665
+ roleId: s.roleId,
666
+ phase: s.phase,
667
+ status: s.status,
668
+ updatedAt: s.updatedAt,
669
+ messageCount: s.messageCount ?? 0,
670
+ summaryBadge: s.summaryBadge || '',
671
+ lastMessagePreview: s.lastMessagePreview || '',
672
+ })),
673
+ });
674
+ } catch (err) {
675
+ return errorResult('clado_session_list', err);
676
+ }
677
+ },
678
+ }),
679
+
680
+ defineTool({
681
+ name: 'clado_session_read',
682
+ label: '读取会话记录',
683
+ description: '读取工作区中指定主会话的最近 N 轮对话摘要与工具调用记录,用于跨角色同步上下文或「记忆记录专员」扫描沉淀记忆。',
684
+ promptSnippet: '读取指定主会话的最近对话与工具记录',
685
+ parameters: {
686
+ type: 'object',
687
+ properties: {
688
+ sessionId: { type: 'string', description: '目标主会话 ID(可先通过 clado_session_list 获取)' },
689
+ limit: { type: 'number', description: '返回最近多少条消息,默认 12,最大 60' },
690
+ },
691
+ required: ['sessionId'],
692
+ },
693
+ async execute(_id, params = {}) {
694
+ try {
695
+ const transcript = await sessionOps.read({
696
+ sessionId: params.sessionId,
697
+ limit: Number(params.limit) || 12,
698
+ });
699
+ if (!transcript) return errorResult('clado_session_read', new Error(`找不到会话:${params.sessionId}`));
700
+ return textResult(transcript);
701
+ } catch (err) {
702
+ return errorResult('clado_session_read', err);
703
+ }
704
+ },
705
+ }),
706
+
707
+ defineTool({
708
+ name: 'clado_session_open',
709
+ label: '拉起主会话',
710
+ description: '按指定角色 ID 拉起一个新的平等主会话,或复用该角色最近活跃的主会话,供后续通过 clado_session_send 协作交流。',
711
+ promptSnippet: '按角色拉起或复用另一个主会话',
712
+ parameters: {
713
+ type: 'object',
714
+ properties: {
715
+ roleId: { type: 'string', description: '目标角色 ID(如 architect / developer / tester / archivist 或自定义角色 ID)' },
716
+ title: { type: 'string', description: '可选:自定义会话标题' },
717
+ reuseLatest: { type: 'boolean', description: '是否优先复用该角色最近会话(默认 true;设 false 强制新建)' },
718
+ },
719
+ required: ['roleId'],
720
+ },
721
+ async execute(_id, params = {}) {
722
+ try {
723
+ const res = await sessionOps.open({
724
+ roleId: params.roleId,
725
+ title: params.title || '',
726
+ reuseLatest: params.reuseLatest !== false,
727
+ });
728
+ return textResult(res);
729
+ } catch (err) {
730
+ return errorResult('clado_session_open', err);
731
+ }
732
+ },
733
+ }),
734
+
735
+ defineTool({
736
+ name: 'clado_session_send',
737
+ label: '跨会话发消息',
738
+ description: '向工作区中的另一个主会话注入协作消息。若对方空闲则自动唤醒运行;若对方正在运行则以中途插话(steer)方式平滑送达。支持 wait:true 等待对方本轮答复摘要,内置无进展防打转熔断。',
739
+ promptSnippet: '向另一个主会话发送协作消息(唤醒或插话)',
740
+ parameters: {
741
+ type: 'object',
742
+ properties: {
743
+ targetSessionId: { type: 'string', description: '目标主会话 ID(与 targetRoleId 二选一)' },
744
+ targetRoleId: { type: 'string', description: '目标角色 ID(若未传 targetSessionId,则自动定位/拉起该角色主会话)' },
745
+ message: { type: 'string', description: '要发送给对方的清晰协作消息、任务或问题' },
746
+ wait: { type: 'boolean', description: '是否同步等待对方本轮执行完成并返回答复摘要(默认 false,异步唤醒不阻塞)' },
747
+ },
748
+ required: ['message'],
749
+ },
750
+ async execute(_id, params = {}) {
751
+ try {
752
+ const res = await sessionOps.send({
753
+ targetSessionId: params.targetSessionId || '',
754
+ targetRoleId: params.targetRoleId || '',
755
+ message: params.message,
756
+ wait: Boolean(params.wait),
757
+ });
758
+ return textResult(res);
759
+ } catch (err) {
760
+ return errorResult('clado_session_send', err);
761
+ }
762
+ },
763
+ }),
764
+ ] : []),
765
+
766
+ ...(automationOps ? [
767
+ defineTool({
768
+ name: 'clado_automations',
769
+ label: '定时与事件订阅',
770
+ description: '管理当前工作区的定时唤醒任务(如「记忆记录专员」每 10 分钟扫描近 20 分钟活跃会话,支持 onlyIfActive 零消耗跳过)与系统事件订阅触发规则(会话/卡片/Tag/代码/记忆变更)。',
771
+ promptSnippet: '查看或管理工作区定时唤醒与事件订阅规则',
772
+ parameters: {
773
+ type: 'object',
774
+ properties: {
775
+ action: { type: 'string', enum: ['list', 'save', 'delete', 'pause', 'resume', 'run_now', 'events_catalog'], description: '操作类型' },
776
+ ruleId: { type: 'string', description: 'delete / run_now 时的规则 ID' },
777
+ rule: { type: 'object', description: 'save 时的规则配置对象' },
778
+ },
779
+ required: ['action'],
780
+ },
781
+ async execute(_id, params = {}) {
782
+ try {
783
+ const res = await automationOps.handle(params);
784
+ return textResult(res);
785
+ } catch (err) {
786
+ return errorResult('clado_automations', err);
787
+ }
788
+ },
789
+ }),
790
+ ] : []),
632
791
  ];
633
792
  }