wtt-connect 0.1.3 → 0.1.5

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/runner.js +55 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wtt-connect",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "private": false,
5
5
  "description": "WTT-native connector daemon for Codex, Claude Code, Cursor, Gemini, ACP, and other coding agent surfaces.",
6
6
  "type": "module",
package/src/runner.js CHANGED
@@ -156,12 +156,14 @@ export class Runner {
156
156
  const transcripts = await this.transcribeAttachments(staged.files);
157
157
  const adapter = this.registry.select({ ...m, content });
158
158
  await this.wtt.typing(topicId, 'start', { statusText: `${adapterDisplayName(adapter.name)} 正在执行`, statusKind: 'running', adapter: adapter.name, ttlMs: 30000 });
159
- const agentSoul = renderAgentSoulContext(m.metadata);
160
- const discussionRouting = renderDiscussionRoutingInstruction(m);
159
+ const agentSoul = renderAgentSoulContext(m.metadata, this.config.agentId);
160
+ const discussionRouting = renderDiscussionRoutingInstruction(m, this.config);
161
161
  const prompt = [
162
162
  'You are replying to a WTT Web conversation. Do not mention implementation internals unless asked.',
163
163
  `WTT topic_id: ${topicId}`,
164
164
  `WTT topic_type: ${messageTopicType(m) || 'unknown'}`,
165
+ `current_agent_id: ${this.config.agentId || 'unknown'}`,
166
+ this.config.setupDisplayName ? `current_agent_display_name: ${this.config.setupDisplayName}` : null,
165
167
  `sender_id: ${m.sender_id || 'human'}`,
166
168
  m.sender_display_name || m.senderDisplayName ? `sender_display_name: ${m.sender_display_name || m.senderDisplayName}` : null,
167
169
  '',
@@ -311,20 +313,26 @@ function messageTopicType(m) {
311
313
  return String(m.topic_type || metadataValue(m.metadata, 'topic_type') || metadataValue(m.metadata, 'topicType') || '').toLowerCase();
312
314
  }
313
315
 
314
- function renderDiscussionRoutingInstruction(m) {
316
+ function renderDiscussionRoutingInstruction(m, config) {
315
317
  const topicType = messageTopicType(m);
316
318
  if (topicType !== 'discussion' && topicType !== 'collaborative') return '';
317
319
 
318
320
  const senderId = String(m.sender_id || '').trim();
319
321
  const senderName = String(m.sender_display_name || m.senderDisplayName || '').trim();
320
- const directTarget = senderName || senderId;
321
- const directMention = directTarget ? `@${directTarget.replace(/^@+/, '')}` : '@<agent-name>';
322
+ const currentAgentId = String(config.agentId || '').trim();
323
+ const currentAgentName = String(config.setupDisplayName || '').trim();
324
+ const senderIsSelf = Boolean(senderId && currentAgentId && senderId === currentAgentId);
325
+ const directTarget = senderIsSelf ? '' : (senderName || senderId);
326
+ const directMention = directTarget ? `@${directTarget.replace(/^@+/, '')}` : '@<other-agent-name>';
322
327
 
323
328
  return [
324
329
  'Internal WTT group-discussion routing rule. Follow it silently and do not explain it:',
325
330
  '- In discussion/collaborative topics, another agent will only run if your visible reply explicitly @mentions that agent.',
326
- `- If you want the sender agent to continue, challenge, verify, or answer, include ${directMention} in the visible reply.`,
327
- '- If you want a different agent to continue, @mention that agent by its exact visible name or agent id from the conversation.',
331
+ `- Your current agent identity is ${currentAgentName ? `${currentAgentName} (${currentAgentId || 'unknown id'})` : (currentAgentId || 'unknown')}. Never @mention yourself, your own display name, or your own agent id.`,
332
+ senderIsSelf
333
+ ? '- The triggering sender appears to be yourself. Do not @mention the sender; answer normally or @mention a different agent only if that specific other agent should act next.'
334
+ : `- If you want the sender agent to continue, challenge, verify, or answer, include ${directMention} in the visible reply.`,
335
+ '- If you want a different agent to continue, @mention only that other agent by its exact visible name or agent id from the conversation.',
328
336
  '- If your reply is a final answer, summary, or no further agent action is needed, do not @mention anyone.',
329
337
  '- Do not use @all or vague mentions; mention only the specific next agent that should act.',
330
338
  ].join('\n');
@@ -463,23 +471,32 @@ function parseMetadata(metadata) {
463
471
  return obj && typeof obj === 'object' ? obj : null;
464
472
  }
465
473
 
466
- function renderAgentSoulContext(metadata) {
474
+ function renderAgentSoulContext(metadata, currentAgentId = '') {
467
475
  const meta = parseMetadata(metadata);
468
476
  if (!meta) return '';
469
477
 
470
478
  const lines = [];
471
479
  const soul = meta.agent_soul;
472
480
  const role = meta.agent_role_template;
481
+ const hasRoleMap = hasAgentRoleTemplateMap(meta);
482
+ const roleByAgent = getRoleTemplateForAgent(meta, currentAgentId);
473
483
  const persona = meta.worker_persona;
474
484
  const workerContext = meta.worker_context;
475
485
 
476
- if (soul && typeof soul === 'object') {
486
+ if (roleByAgent) {
487
+ if (roleByAgent.label) lines.push(`Adopt this agent role silently: ${roleByAgent.label}.`);
488
+ if (Array.isArray(roleByAgent.skills) && roleByAgent.skills.length) lines.push(`Relevant capabilities: ${roleByAgent.skills.join(', ')}.`);
489
+ const systemPrompt = roleByAgent.system_prompt || roleByAgent.systemPrompt || roleByAgent.instructions;
490
+ if (systemPrompt) lines.push(String(systemPrompt));
491
+ } else if (!hasRoleMap && soul && typeof soul === 'object') {
477
492
  if (soul.role) lines.push(`Adopt this agent role silently: ${soul.role}.`);
478
493
  if (Array.isArray(soul.skills) && soul.skills.length) lines.push(`Relevant capabilities: ${soul.skills.join(', ')}.`);
479
494
  if (soul.instructions) lines.push(String(soul.instructions));
480
- } else if (role && typeof role === 'object') {
495
+ } else if (!hasRoleMap && role && typeof role === 'object') {
481
496
  if (role.label) lines.push(`Adopt this agent role silently: ${role.label}.`);
482
497
  if (Array.isArray(role.skills) && role.skills.length) lines.push(`Relevant capabilities: ${role.skills.join(', ')}.`);
498
+ const systemPrompt = role.system_prompt || role.systemPrompt || role.instructions;
499
+ if (systemPrompt) lines.push(String(systemPrompt));
483
500
  }
484
501
 
485
502
  if (persona && typeof persona === 'object' && persona.persona_md) {
@@ -499,6 +516,31 @@ function renderAgentSoulContext(metadata) {
499
516
  ].join('\n');
500
517
  }
501
518
 
519
+ function hasAgentRoleTemplateMap(meta) {
520
+ const byAgent = meta.agent_role_templates_by_agent || meta.agentRoleTemplatesByAgent;
521
+ return Boolean(byAgent && typeof byAgent === 'object');
522
+ }
523
+
524
+ function getRoleTemplateForAgent(meta, currentAgentId) {
525
+ const byAgent = meta.agent_role_templates_by_agent || meta.agentRoleTemplatesByAgent;
526
+ if (!byAgent || typeof byAgent !== 'object' || !currentAgentId) return null;
527
+
528
+ const exact = byAgent[currentAgentId];
529
+ if (exact && typeof exact === 'object') return exact;
530
+
531
+ const normalizedCurrent = normalizeAgentRoleMapKey(currentAgentId);
532
+ for (const [agentId, role] of Object.entries(byAgent)) {
533
+ if (normalizeAgentRoleMapKey(agentId) === normalizedCurrent && role && typeof role === 'object') {
534
+ return role;
535
+ }
536
+ }
537
+ return null;
538
+ }
539
+
540
+ function normalizeAgentRoleMapKey(value) {
541
+ return String(value || '').trim().toLowerCase();
542
+ }
543
+
502
544
  function stripHiddenContextLeak(text) {
503
545
  return String(text || '')
504
546
  .replace(/\[Agent Role Template\][\s\S]*?\[\/Agent Role Template\]\s*/gi, '')
@@ -577,11 +619,14 @@ function taskFromEvent(taskId, event) {
577
619
  function buildTaskPrompt(task, config, staged = { promptBlock: '' }, transcripts = []) {
578
620
  const title = task.title || task.name || `Task ${task.id}`;
579
621
  const description = task.description || task.content || task.task_request || '';
622
+ const agentSoul = renderAgentSoulContext(task.metadata || task.msg_metadata, config.agentId);
580
623
  return [
581
624
  'You are executing a WTT task through wtt-connect.',
582
625
  `Task ID: ${task.id}`,
583
626
  `Title: ${title}`,
584
627
  '',
628
+ agentSoul,
629
+ agentSoul ? '' : null,
585
630
  'Description:',
586
631
  description,
587
632
  staged.promptBlock,