modscode EN

modscode / 図鑑 / agent-swarm

agent-swarm

Mission control for your subagents: every spawned agent becomes a live, animated card above the prompt, with its phase, effort, tools, cost and a timeline you can follow

確かめやすいコードターミナル+デスクトップバンドステータスライントーストBoxButtonText

何をするか

  • プロンプトの上の帯・トーストを描く
  • /swarm を足す
  • ツールの呼び出しを見張る
  • agent.spawn・config.set・prompt.submit・session.start ほか 3 個にフックする
  • ターンをまたいで自分の状態を持つ

良いところ

  • ネットワークに出ない
  • プロセスを起こさない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある

作り始めるためのコード

2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。

雛形(register.tsx)

register.tsx
import type { Register } from 'claude-code'

// Drawn like agent-swarm by Jeff Arese (band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/jeffarese-agent-swarm/
// Written by modscode from that reading, not copied from the mod: use it as you like.
// Each value below stands for one the mod works out at run time; put in your own.
export const register: Register = on => {
  // the band above the prompt; what else goes there is drawn under it
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const { Box, Text, Button } = $.ui.resolve(e)
    const done = '…'
    const failed = '…'
    const tools = '…'
    const usd = '…'
    const hint = '…'
    const compactLabel = '…'
    const clearLabel = '…'
    const lead = '…'
    const effort = '…'
    const who = '…'
    const at = '…'
    const length = '…'
    const head = '…'
    const facts = '…'
    const fold = '…'
    const clock = '…'
    const head2 = '…'
    const head3 = '…'
    const head4 = '…'
    const tail = '…'
    return (
      <Box flexDirection="column" borderStyle="round" borderDimColor paddingX={1}>
        <Box flexDirection="column" marginBottom={1}>
          <Box justifyContent="space-between" gap={2}>
            <Box flexShrink={1}>
              <Text wrap="truncate-end">
                <Text bold color="claude">
                  ◆
                </Text>
                <Text color="suggestion">
                  {"  0 live"}
                </Text>
                <Text dimColor>
                  {" · "}
                </Text>
                <Text color="success">
                  {`${done} done`}
                </Text>
                <Text dimColor>
                  {" · "}
                </Text>
                <Text color="error">
                  {`${failed} failed`}
                </Text>
                <Text dimColor>
                  {` · ⚒ ${tools}`}
                </Text>
                <Text dimColor>
                  {" · "}
                </Text>
                <Text color="warning">
                  {usd}
                </Text>
                <Text dimColor>
                  {hint}
                </Text>
              </Text>
            </Box>
            <Box gap={2} flexShrink={0}>
              <Button label={`${compactLabel}`} hotkey="v" plain dimColor />
              <Button label={`${clearLabel}`} hotkey="c" plain dimColor />
              <Button label="close" hotkey="x" plain dimColor />
            </Box>
          </Box>
          <Box gap={2} flexShrink={0}>
            <Button label={`${compactLabel}`} hotkey="v" plain dimColor />
            <Button label={`${clearLabel}`} hotkey="c" plain dimColor />
            <Button label="close" hotkey="x" plain dimColor />
          </Box>
        </Box>
        <Box gap={1}>
          0
          0
          0
        </Box>
        <Box gap={1}>
          0
          0
          0
        </Box>
        <Box gap={1}>
          0
          0
          0
        </Box>
        <Box flexDirection="column" marginTop={1} borderStyle="round" paddingX={1}>
          <Box justifyContent="space-between" gap={2} flexDirection="column">
            <Box flexShrink={1}>
              <Text bold wrap="truncate-end">
                {lead}
                <Text>
                  {effort}
                </Text>
                <Text bold={false} dimColor>
                  {`  ${who}`}
                </Text>
              </Text>
            </Box>
            <Box gap={2} flexShrink={0}>
              <Button label={`‹`} hotkey="p" plain dimColor />
              <Text dimColor>
                {`${at}1/${length}`}
              </Text>
              <Button label="›" hotkey="n" plain dimColor />
              <Button label="hide" hotkey="h" plain dimColor />
            </Box>
          </Box>
          <Text bold wrap="truncate-end">
            …
          </Text>
          <Text dimColor italic wrap="wrap">
            {head}
          </Text>
          <Text dimColor wrap="truncate-end">
            {facts}
          </Text>
          <Box marginTop={1} flexDirection="column">
            <Text dimColor>
              {`  ⋯ ${fold} earlier`}
            </Text>
            <Text dimColor>
              ◌ waiting for its first move…
            </Text>
            <Box flexDirection="column">
              <Box>
                <Box width={7} flexShrink={0}>
                  <Text dimColor>
                    {`+${clock}`}
                  </Text>
                </Box>
                <Box width={2} flexShrink={0} />
                <Box flexGrow={1} flexShrink={1} />
                <Box flexShrink={0} marginLeft={1} />
              </Box>
              <Box>
                <Text wrap="wrap">
                  {head2}
                </Text>
              </Box>
            </Box>
            <Box flexDirection="column">
              <Box>
                <Box width={7} flexShrink={0}>
                  <Text dimColor>
                    {`+${clock}`}
                  </Text>
                </Box>
                <Box width={2} flexShrink={0} />
                <Box flexGrow={1} flexShrink={1} />
                <Box flexShrink={0} marginLeft={1} />
              </Box>
              <Box>
                <Text wrap="wrap">
                  {head3}
                </Text>
              </Box>
            </Box>
            <Box flexDirection="column">
              <Box>
                <Box width={7} flexShrink={0}>
                  <Text dimColor>
                    {`+${clock}`}
                  </Text>
                </Box>
                <Box width={2} flexShrink={0} />
                <Box flexGrow={1} flexShrink={1} />
                <Box flexShrink={0} marginLeft={1} />
              </Box>
              <Box>
                <Text wrap="wrap">
                  {head4}
                </Text>
              </Box>
            </Box>
            <Box>
              <Box width={7} flexShrink={0}>
                <Text dimColor>
                  {`+${clock}`}
                </Text>
              </Box>
              <Box width={2} flexShrink={0}>
                <Text>
                  ✎
                </Text>
              </Box>
              <Box flexGrow={1} flexShrink={1}>
                <Text wrap="wrap">
                  {tail}
                  <Text>
                    ▍
                  </Text>
                </Text>
              </Box>
            </Box>
          </Box>
        </Box>
        {await next(e)}
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    await $.ui.toast(`Agents view folded · /swarm to reopen`)
    return next(e)
  })
}

Mod 自身のコード

Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。

hooks/register.tsx 1719〜1832 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const t0 = performance.now()
    try {
      const [isOpen] = await Promise.all([read($, openAtom), restore($)])
      if (e.props.hasSurvey) {
        mounted.delete(e.requestId)
        fullSite = undefined

        return next(e)
      }
      if (isOpen) return await drawFull($, e)
      if (fullSite === e.requestId) fullSite = undefined
      await read($, bandRevAtom)
      const list = ordered(snapshot.filter(a => isLive(a.phase) || (a.endedAt ?? 0) >= batchStart))
      if (list.length === 0) {
        mounted.delete(e.requestId)

        return next(e)
      }
      const { Box, Text, Button } = $.ui.resolve(e)
      const Raster = e.surface === 'terminal' ? $.ui.resolve(e).Raster : undefined
      const Client = e.surface === 'terminal' ? $.ui.resolve(e).Client : undefined
      /** A transparent region over the whole agent, last so it is on top: a click anywhere picks it. */
      const hitArea = (a: SwarmAgent, columns: number, rows: number, inset = 1) =>
        Client === undefined ? null : (
          <Box position="absolute" top={-inset} left={-inset}>
            <Client key={`hit-${coreKey(a.id)}`} module="./hit-area.tsx" props={{ id: a.id }} width={columns} height={rows} />
          </Box>
        )
      const width = Math.max(SQUARE, e.props.bodyColumns)
      const perRow = Math.max(1, Math.floor((width + GAP) / (SQUARE + GAP)))
      const fitRows = Math.max(1, Math.floor((e.props.maxRows - 1) / SQUARE_ROWS))
      const shown = list.slice(0, perRow * fitRows)
      const hidden = list.length - shown.length
      const inner = SQUARE - 2
      const live = list.filter(a => isLive(a.phase)).length
      const cost = totalCost(list)

      bandSite = e.requestId
      const prevCores = mounted.get(e.requestId)
      const cores = new Map<string, Core>()
      mounted.set(e.requestId, cores)

      const square = (a: SwarmAgent) => {
        const color = phaseColor(a.phase)
        const isOn = isLive(a.phase)
        let core
        if (Raster !== undefined) {
          core = <Raster key={coreKey(a.id)} columns={inner} rows={1} cells={coreCells(prevCores, cores, a, inner, 1)} />
        } else {
          core = <Text color={color}>{isOn ? '· • ● • ·' : a.phase}</Text>
        }

        return (
          <Box
            key={`sq-${a.id}`}
            flexDirection="column"
            width={SQUARE}
            borderStyle="round"
            borderColor={isOn ? color : hex(ramp(a.phase)[2])}
            borderDimColor={!isOn}
            hover={{ borderColor: hex(ramp(a.phase)[4]), borderDimColor: false }}
          >
            <Button
              key={`band-pick-${a.id}`}
              label={head(`${PHASE_GLYPH[a.phase]} ${a.name ?? a.type}`, inner)}
              plain
              dimColor={!isOn}
              onPress={() => void select($, a.id, { toggle: false, open: true })}
            />
            {core}
            <Box justifyContent="space-between">
              <Box>
                {effortCells(a.effortLevel).map(c =>
                  c.isOn ? (
                    <Text color={c.color} dimColor={!isOn}>
                      {c.ch}
                    </Text>
                  ) : (
                    <Text dimColor>{c.ch}</Text>
                  ),
                )}
              </Box>
              <Text dimColor>
                {a.phase === 'tool' && a.tool ? a.tool.slice(0, 8) : (costLabel(a) ?? `⚒${a.tools}`)}
              </Text>
            </Box>
            {hitArea(a, SQUARE, SQUARE_ROWS)}
          </Box>
        )
      }

      const rows: SwarmAgent[][] = []
      for (let i = 0; i < shown.length; i += perRow) rows.push(shown.slice(i, i + perRow))

      return (
        <Box flexDirection="column">
          <Text wrap="truncate-end">
            <Text bold color={BRAND}>◆ </Text>
            <Text color="suggestion">{live > 0 ? `${live} working` : 'all finished'}</Text>
            {cost !== undefined && <Text color={COST_COLOR}>{` · ${usd(cost)}`}</Text>}
            <Text dimColor>{`${hidden > 0 ? ` · +${hidden} more` : ''} · click one for details · /swarm unfolds`}</Text>
          </Text>
          {rows.map((row, i) => (
            <Box key={`band-row-${i}`} gap={GAP}>
              {row.map(square)}
            </Box>
          ))}
        </Box>
      )
    } finally {
      record('render.band', performance.now() - t0)
    }
  })
hooks/register.tsx 857〜1016 行 · バンド
async function drawFull($: EngineInterface, e: RenderInput<'AbovePrompt'>) {
  const t0 = performance.now()
  try {
    const { Box, Text, Button } = $.ui.resolve(e)
    const Raster = e.surface === 'terminal' ? $.ui.resolve(e).Raster : undefined
    const Client = e.surface === 'terminal' ? $.ui.resolve(e).Client : undefined
    /** A transparent region over the whole agent, last so it is on top: a click anywhere picks it. */
    const hitArea = (a: SwarmAgent, columns: number, rows: number, inset = 1) =>
      Client === undefined ? null : (
        <Box position="absolute" top={-inset} left={-inset}>
          <Client key={`hit-${coreKey(a.id)}`} module="./hit-area.tsx" props={{ id: a.id }} width={columns} height={rows} />
        </Box>
      )
    const [, isCompact, selectedId, now] = await Promise.all([
      read($, paneRevAtom),
      read($, compactAtom),
      read($, selectedAtom),
      $.clock.now(),
      restore($),
    ])
    const list = ordered(snapshot)
    const selected = list.find(a => a.id === selectedId)
    shownId = selected?.id ?? ''

    const bodyColumns = Math.max(8, e.props.bodyColumns - FRAME)
    const width = Math.max(MIN_CARD, bodyColumns)
    const perRow = Math.max(1, Math.min(Math.floor((width + GAP) / (MIN_CARD + GAP)), list.length || 1))
    const cardWidth = Math.floor((width - GAP * (perRow - 1)) / perRow)
    const inner = Math.max(8, cardWidth - 4)

    const live = list.filter(a => isLive(a.phase)).length
    const done = list.filter(a => a.phase === 'done').length
    const failed = list.filter(a => a.phase === 'failed' || a.phase === 'stopped').length
    const tools = list.reduce((n, a) => n + a.tools, 0)
    const cost = totalCost(list)
    const isNarrow = bodyColumns < 64
    const closesIn = closeAt === undefined ? undefined : Math.max(0, Math.ceil((closeAt - now) / 1000))

    const prevCores = mounted.get(e.requestId)
    const cores = new Map<string, Core>()
    const surfaceKey = `${e.surface}|${isLightTheme()}`
    fullSite = e.requestId
    mounted.set(e.requestId, cores)

    const heading = (a: SwarmAgent, width?: number) => {
      const isOn = isLive(a.phase)
      const { lead, effort } = headingParts(a)

      return (
        <Box width={width} flexShrink={1}>
          <Text bold={isOn} dimColor={!isOn} color={phaseColor(a.phase)} wrap="truncate-end">
            {lead}
            {effort !== '' && <Text color={effortColor(a.effortLevel)}>{effort}</Text>}
          </Text>
        </Box>
      )
    }

    const badgeOf = (a: SwarmAgent) => {
      const badge = BADGE[a.phase]

      return badge !== undefined ? (
        <Text bold color={BADGE_INK} backgroundColor={phaseColor(a.phase)}>
          {` ${badge} `}
        </Text>
      ) : (
        <Text dimColor>{a.phase.toUpperCase()}</Text>
      )
    }

    /** The agent's description as the control that opens it in the inspector; 1–9 press it. */
    const picker = (a: SwarmAgent, i: number, room: number) => {
      const hotkey = i < 9 ? String(i + 1) : undefined
      const isShown = a.id === selected?.id

      return (
        <Button
          key={`pick-${a.id}`}
          label={head(a.description || a.name || a.type, Math.max(4, room - (hotkey === undefined ? 0 : 3)))}
          hotkey={hotkey}
          plain
          dimColor={!isLive(a.phase) && !isShown}
          onPress={() => void select($, a.id)}
        />
      )
    }

    const borderOf = (a: SwarmAgent) => {
      const isOn = isLive(a.phase)
      const isShown = a.id === selected?.id

      return {
        borderStyle: isShown ? 'bold' : 'round',
        borderColor: isOn || isShown ? phaseColor(a.phase) : hex(ramp(a.phase)[2]),
        borderDimColor: !isOn && !isShown,
        hover: { borderColor: hex(ramp(a.phase)[4]), borderDimColor: false },
      }
    }

    // Compact: one line per agent, headings padded to one width so the animations line up.
    const BADGE_W = 7
    const headW = Math.min(
      Math.floor(width / 3),
      Math.max(0, ...list.map(a => headingParts(a)).map(p => p.lead.length + p.effort.length)),
    )
    const lineCore = Math.max(4, width - headW - BADGE_W - 2)

    const activityOf = (a: SwarmAgent, elapsed: number): string => {
      switch (a.phase) {
        case 'tool':
          return `▸ ${a.tool ?? 'tool'}${a.toolArg ? `  ${a.toolArg}` : ''}`
        case 'thinking':
          return `✻ thinking · step ${a.steps}`
        case 'writing':
          return `✎ writing · step ${a.steps}`
        case 'spawning':
          return `◌ starting${a.isBackground ? ' in background' : ''}…`
        default:
          return `${PHASE_GLYPH[a.phase]} ${a.phase} in ${clock(elapsed)} · ${a.steps} step${a.steps === 1 ? '' : 's'}`
      }
    }

    const line = (a: SwarmAgent, i: number) => {
      const isOn = isLive(a.phase)
      let core
      if (Raster !== undefined) {
        core = <Raster key={coreKey(a.id)} columns={lineCore} rows={1} cells={coreCells(prevCores, cores, a, lineCore, 1)} />
      } else {
        core = (
          <Text color={phaseColor(a.phase)} dimColor={!isOn} wrap="truncate-end">
            {isOn ? '· • ● • ·' : (a.description || '')}
          </Text>
        )
      }

      const elapsed = (a.endedAt ?? now) - a.startedAt
      const cost = costLabel(a)
      const stats = `${cost === undefined ? '' : `${cost} · `}⚒${a.tools} · ${clock(elapsed)}`
      const isShown = a.id === selected?.id

      return (
        <Box key={`line-${a.id}`} flexDirection="column">
          <Box gap={1}>
            {heading(a, headW)}
            <Box width={lineCore}>{core}</Box>
            <Box width={BADGE_W} justifyContent="flex-end">
              {badgeOf(a)}
            </Box>
          </Box>
          <Box paddingLeft={1}>
            <Text color={phaseColor(a.phase)}>{isShown ? '▸' : ' '}</Text>
            {picker(a, i, width - 2)}
          </Box>
          <Box justifyContent="space-between" gap={2} paddingLeft={2}>
            <Box flexShrink={1}>
              <Text color={phaseColor(a.phase)} dimColor wrap="truncate-end">
                {activityOf(a, elapsed)}
              </Text>
            </Box>
            <Box flexShrink={0}>
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Jeff Arese

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

コードが呼ぶもの

Claude を動かすツール呼び出し保存

コードから読み取ったデザイン

読み取ったコミットのソースから描いたもので、動かした結果ではありません。一覧は 3 回描き、条件はデスクトップアプリで描く最初の分岐を取り、動かしたときにだけ決まる値は仮の例(点線の下線)にするか省きます。色と書体はこのサイトのものです。

コードから読めること

2026-10-06 に読んだコミット eccf465133a5 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。5 ファイルを解析
コードが Mod の中で完結import は Mod 自身のファイルかエンジンのモジュールだけ。パッケージも require もない。コードはすべて Mod の中
読める圧縮した行・eval・new Function・計算した道の import()・符号化した塊がない。圧縮・eval・符号化した塊なし
呼び出しが見える通信とプログラム起動はその場で $.http.fetch・$.process.run と書き、他へ渡さない。外への呼び出しはすべてその場の $ で
入れる前に自分で判断する材料
描く場所コードから読んだ、描く先。ターミナル・デスクトップアプリ・両方・何も描かない(フックだけ: 見張りやプロンプトの書き換え)のどれか。出すだけで、外す理由にはしない。ターミナルとデスクトップアプリに同じように描く
入れる手順リポジトリ自身の .claude-plugin/marketplace.json にこの Mod が載っていて、ページに書いた手順でそのマーケットプレイスから入れられるか。リポジトリの .claude-plugin/marketplace.json に載っておらず、入れる手順は出せない
Windows のプログラム$.process で起動するプログラムが Windows にあるか(tail・date・open・osascript・/usr/… などは無い)。Windows にないプログラムを使わない
通信fetch の送り先(https のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。プログラムを起動しない
読んで送るファイルや環境変数を読み、かつ通信するか。通信しない
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

コードの文面を読んだだけで、安全の審査ではありません。動かしてはおらず、起動するプログラムの中で何が起きるかも見えません。入れる前の確認はあなたの役目です。 載せる条件

入れる

入れる前に、必ず自分で確かめてください。Mod はサンドボックスなしで、あなたの権限で動きます。modscode はこのコードの安全を保証しません。下のコードを読み(またはフォルダーで claude plugin validate .)、触るものを見て、読んだコミットを入れてください。

リポジトリの .claude-plugin/marketplace.json にこの Mod が載っていないため、入れる手順は出せません。コードとして読むか、作者の README に従ってください。

Claude に聞く

modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:

modscode のデザイン「jeffarese-agent-swarm」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン