nanocoai/nanoclaw / .claude/skills/slack-agent-flow
slack-agent-flow
FlaggedLet an existing Slack agent create new agents that arrive as their own Slack bots — provisioned app, operator DM, and a shared three-way room, hot-started without a host restart.
src/modules/slack-agent-flow/provision.prefetch.test.ts
View on GitHub/**
* Avatar prefetch (multi-agent creates): prefetchAvatar starts the broker job
* in the background; the flow's later requestAvatar with the same
* (displayName, description) consumes that in-flight job instead of starting
* a second generation. A key miss or an already-consumed entry falls back to
* a fresh request.
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { clearAvatarPrefetches, prefetchAvatar, requestAvatar } from './provision.js';
const fetchMock = vi.fn();
function avatarBrokerResponses(id: string): void {
fetchMock.mockImplementation((url: string) => {
if (url.endsWith('/v1/avatars')) {
return Promise.resolve(new Response(JSON.stringify({ avatar_id: id }), { status: 200 }));
}
return Promise.resolve(new Response(JSON.stringify({ status: 'ready' }), { status: 200 }));
});
}
function postCount(): number {
return fetchMock.mock.calls.filter((c) => (c as [string])[0].endsWith('/v1/avatars')).length;
}
beforeEach(() => {
fetchMock.mockReset();
vi.stubGlobal('fetch', fetchMock);
clearAvatarPrefetches();
});
afterEach(() => {
vi.unstubAllGlobals();
clearAvatarPrefetches();
});
describe('avatar prefetch', () => {
it('requestAvatar consumes a pending prefetch — exactly one generation job', async () => {
avatarBrokerResponses('av-1');
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
const id = await requestAvatar('https://broker', 'tok', 'Maya', 'content writer');
expect(id).toBe('av-1');
expect(postCount()).toBe(1);
});
it('a prefetch is consumed once — the next same-key request goes fresh', async () => {
avatarBrokerResponses('av-1');
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
await requestAvatar('https://broker', 'tok', 'Maya', 'content writer');
await requestAvatar('https://broker', 'tok', 'Maya', 'content writer');
expect(postCount()).toBe(2);
});
it('different (name, description) keys never share a job', async () => {
avatarBrokerResponses('av-x');
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
await requestAvatar('https://broker', 'tok', 'Maya', 'designer');
expect(postCount()).toBe(2);
});
it('duplicate prefetches for one key start one job', async () => {
avatarBrokerResponses('av-1');
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
expect(postCount()).toBe(1);
});
it('a failed prefetch resolves undefined without throwing into the flow', async () => {
fetchMock.mockRejectedValue(new Error('offline'));
prefetchAvatar('https://broker', 'tok', 'Maya', 'content writer');
const id = await requestAvatar('https://broker', 'tok', 'Maya', 'content writer');
expect(id).toBeUndefined();
});
});
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 471k | Updated | Claude CodeCodex | Verified | Install |
| 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: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| 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 available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |