Skip to content

phuryn/product-engineering / app-stack/skills/embedded-agents-agent-sdk

embedded-agents-agent-sdk

Verified

Only when the Agent SDK is asked for, an agent needs Claude Code's own tools, or the app already runs it: embed Claude agents in a Next.js app with the Agent SDK.

templates/agents.live.test.ts

View on GitHub
import { describe, test, expect, vi } from 'vitest';
import { query, type SDKMessage } from '@anthropic-ai/claude-agent-sdk';

vi.mock('server-only', () => ({}));
import { askAgent, agentOptions, listAgents } from '@/lib/agent';

// Every agent, against the real SDK and model. Costs money and needs ANTHROPIC_API_KEY
// (or the developer's own local login) plus each agent's MCP secrets. Runs outside the
// gate as `npm run agents:live`, before any release that adds or changes an agent.

async function initMessage(agent: string) {
  const ac = new AbortController();
  try {
    for await (const msg of query({ prompt: 'x', options: { ...agentOptions({ agent }), abortController: ac } })) {
      if (msg.type === 'system' && msg.subtype === 'init') { ac.abort(); return msg as Extract<SDKMessage, { subtype: 'init' }>; }
    }
  } catch (err) {
    if (!ac.signal.aborted) throw err;
  }
  throw new Error(`${agent}: no init message`);
}

describe.each(listAgents())('%s', (agent) => {
  test('sees exactly the MCP servers its .mcp.json declares, all connected, and only its allowed tools', async () => {
    const options = agentOptions({ agent });
    const init = await initMessage(agent);
    expect(init.mcp_servers.map((s) => s.name).sort()).toEqual(Object.keys(options.mcpServers ?? {}).sort());
    for (const s of init.mcp_servers) expect(s.status).toBe('connected');
    const builtIns = init.tools.filter((t) => !t.startsWith('mcp__'));
    for (const t of builtIns) expect(options.tools).toContain(t);
  });

  test('answers', async () => {
    let done = false;
    for await (const ev of askAgent({ agent, prompt: 'Introduce yourself in one sentence.' })) {
      if (ev.type === 'done') done = true;
    }
    expect(done).toBe(true);
  });
});
reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.Stars: 322kUpdated Claude CodeCodexVerifiedInstall
dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependenciesStars: 322kUpdated Claude CodeCodexVerifiedInstall
executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is availableStars: 322kUpdated Claude CodeCodexVerifiedInstall