Skip to content

[TUI] Task 6: Extract additional data from parse_mode response #477

@JeremyDev87

Description

@JeremyDev87

Parent Issue

#471 - TUI Data Integration Audit

Problem (C2)

The parse_mode response contains rich data but currently only 3 fields are extracted.

Currently Extracted (extractFromParseMode)

Field Extracted Event
mode MODE_CHANGED
included_skills[] SKILL_RECOMMENDED
delegates_to AGENT_ACTIVATED (primary)

Not Extracted (present in parse_mode response)

Field Use Possible Event
originalPrompt Current task description OBJECTIVE_SET (handled in Task 2)
recommended_act_agent.agentName Next-phase agent recommendation AGENT_RELATIONSHIP
parallelAgentsRecommendation.specialists Expected parallel agents PARALLEL_STARTED

Implementation Approach

6A. recommended_act_agent → AGENT_RELATIONSHIP

When parse_mode response includes recommended_act_agent, extract a "recommends" relationship from the primary agent to the recommended agent.

// Add to extractFromParseMode
const recAgent = json.recommended_act_agent;
if (recAgent && typeof recAgent === 'object') {
  const rec = recAgent as Record<string, unknown>;
  if (typeof rec.agentName === 'string' && delegateName) {
    events.push({
      event: TUI_EVENTS.AGENT_RELATIONSHIP,
      payload: {
        from: `primary:${delegateName}`,
        to: `recommended:${rec.agentName}`,
        label: 'recommends',
        type: 'recommendation',
      },
    });
  }
}

6B. parallelAgentsRecommendation.specialists → PARALLEL_STARTED

const parRec = json.parallelAgentsRecommendation;
if (parRec && typeof parRec === 'object') {
  const par = parRec as Record<string, unknown>;
  if (Array.isArray(par.specialists) && par.specialists.length > 0) {
    const specialists = par.specialists.filter(
      (s): s is string => typeof s === 'string',
    );
    if (specialists.length > 0) {
      events.push({
        event: TUI_EVENTS.PARALLEL_STARTED,
        payload: {
          specialists,
          mode: (json.mode as Mode) ?? 'PLAN',
        },
      });
    }
  }
}

TDD Steps

Step 1: Write failing tests

File: apps/mcp-server/src/tui/events/response-event-extractor.spec.ts

describe('extractFromParseMode - additional data', () => {
  it('should extract AGENT_RELATIONSHIP from recommended_act_agent', () => {
    const events = extractEventsFromResponse('parse_mode', {
      mode: 'PLAN',
      delegates_to: 'technical-planner',
      recommended_act_agent: { agentName: 'frontend-developer', confidence: 0.9 },
    });
    const rel = events.find(e => e.event === TUI_EVENTS.AGENT_RELATIONSHIP);
    expect(rel).toBeDefined();
    expect(rel!.payload).toEqual({
      from: 'primary:technical-planner',
      to: 'recommended:frontend-developer',
      label: 'recommends',
      type: 'recommendation',
    });
  });

  it('should extract PARALLEL_STARTED from parallelAgentsRecommendation', () => {
    const events = extractEventsFromResponse('parse_mode', {
      mode: 'EVAL',
      delegates_to: 'evaluator',
      parallelAgentsRecommendation: {
        specialists: ['security-specialist', 'performance-specialist'],
      },
    });
    const ps = events.find(e => e.event === TUI_EVENTS.PARALLEL_STARTED);
    expect(ps).toBeDefined();
    expect(ps!.payload).toEqual({
      specialists: ['security-specialist', 'performance-specialist'],
      mode: 'EVAL',
    });
  });

  it('should not extract AGENT_RELATIONSHIP without delegates_to', () => {
    const events = extractEventsFromResponse('parse_mode', {
      mode: 'PLAN',
      recommended_act_agent: { agentName: 'frontend-developer', confidence: 0.9 },
    });
    const rel = events.find(e => e.event === TUI_EVENTS.AGENT_RELATIONSHIP);
    expect(rel).toBeUndefined();
  });
});

Step 2: Verify failure, Step 3: Implement, Step 4: Full test suite

yarn workspace codingbuddy test -- --run response-event-extractor.spec.ts
# After implementation
yarn workspace codingbuddy test

Notes

Related Files

  • apps/mcp-server/src/tui/events/response-event-extractor.ts
  • apps/mcp-server/src/tui/events/response-event-extractor.spec.ts
  • apps/mcp-server/src/tui/events/types.ts (if EdgeType needs extension)
  • apps/mcp-server/src/tui/dashboard-types.ts (check EdgeType union)

Metadata

Metadata

Assignees

Labels

featphase-2Phase 2: Widget Development (Day 4-10)

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions