modscode EN

modscode / 図鑑 / clawd-factory

clawd-factory

ツール呼び出しのたびにClawdが1匹増え、持ち場で働く様子をペインに表示する作業状況モニター

確かめやすいコードターミナル+デスクトップペイントーストBoxSvgText

何をするか

  • 欄・トーストを描く
  • /clawd-factory を足す
  • ツールの呼び出しを見張る
  • session.start・turn.complete・turn.startにフックする
  • ターンをまたいで自分の状態を持つ

良いところ

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

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like clawd-factory by jnk0vc (pane, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/jnk0vc-clawd-factory/
// 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 pane: open it with $.ui.open({ id: 'my-pane', title: "Clawd Factory" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Svg } = $.ui.resolve(e)
    const status = '…'
    const fieldSvg = '…'
    const fieldAlt = '…'
    const footer = '…'
    return (
      <Box flexDirection="column">
        <Text wrap="truncate-end">
          {status}
        </Text>
        <Svg source={`${fieldSvg}`} alt={`${fieldAlt}`} isInteractive />
        <Text dimColor>
          {footer}
        </Text>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    await $.ui.toast(`Clawd Factoryを読み込みました`)
    return next(e)
  })
}

Mod 自身のコード

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

plugins/clawd-factory/hooks/register.tsx 188〜288 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const list = await read($, calls)
    const tally = await read($, totals)
    const t = await read($, turn)
    const rows = e.viewport?.rows ?? 30
    // SVG版は経過秒を出さない。毎秒の時計を読むと毎秒描き直され、SVGのアニメーションが頭から再生し直されるため
    const isSvg = e.surface === 'desktop' || e.surface === 'mobile'
    const now = isSvg ? undefined : await read($, clock)
    const since = (from: number): string => (now === undefined ? '' : ` ${fmt(now - from)}`)

    // 1行目: いま何をしているか
    const running = list.filter(c => c.endedAt === undefined && !c.isSub)
    const head = running[running.length - 1]
    const status = head
      ? `● ${head.tool}${since(head.startedAt)}${head.label ? `  ${head.label}` : ''}`
      : t.isActive
        ? `● 考え中${now === undefined ? '' : `  経過${fmt(now - (t.startedAt ?? now))}`}`
        : `○ 待機中${t.lastMs === undefined ? '' : `  前回のターン${fmt(t.lastMs)}`}`
    const statusColor = head ? CATS[head.cat].color : undefined

    const total = ORDER.reduce((n, c) => n + (tally[c]?.n ?? 0), 0)
    const failed = ORDER.reduce((n, c) => n + (tally[c]?.failed ?? 0), 0)
    const footer = `ターン${t.n} · 呼び出し${total}回${failed > 0 ? ` · 失敗${failed}` : ''}`

    const recent = list.slice(-MAX_CLAWDS)

    if (e.surface === 'desktop' || e.surface === 'mobile') {
      const { Box, Text, Svg } = $.ui.resolve(e)
      // 歩く・✓を出す演出は、直近のイベントの直後のClawdだけに付ける(時計ではなくイベント時刻で決め、描き直しで変わらないようにする)
      const lastEventAt = Math.max(0, ...recent.map(c => c.endedAt ?? c.startedAt))
      const field: SvgField = {
        width: Math.max(240, Math.min(1400, Math.round(e.props.bodyColumns * 10.5))),
        isActive: t.isActive,
        workers: recent.map(c => ({
          id: c.id,
          cat: c.cat,
          state: c.endedAt === undefined ? 'run' : c.hasFailed ? 'fail' : 'ok',
          isSub: c.isSub === true,
          say: c.say ?? '',
          seq: c.seq ?? 0,
          isFreshStart: c.endedAt === undefined && c.startedAt >= lastEventAt - 1200,
          isFreshEnd: c.endedAt !== undefined && c.endedAt >= lastEventAt - 2500,
        })),
      }
      if (field.workers.length === 0) {
        field.workers.push({
          id: 'clawd', cat: 'other', state: t.isActive ? 'run' : 'ok', isSub: false, say: '', seq: 0,
          isFreshStart: false, isFreshEnd: false,
        })
      }

      return (
        <Box flexDirection="column">
          <Text color={statusColor} dimColor={!head && !t.isActive} wrap="truncate-end">
            {status}
          </Text>
          <Svg source={fieldSvg(field)} alt={fieldAlt(field)} isInteractive />
          <Text dimColor>{footer}</Text>
        </Box>
      )
    }

    if (e.surface === 'terminal') {
      const { Box, Text, Client } = $.ui.resolve(e)
      // 幅を'100%'にすると親の幅が中身で決まり大きさがループするので数値で渡す
      const cols = Math.max(12, e.props.bodyColumns - 1)
      const fieldRows = Math.min(16, Math.max(7, rows - 4))
      const field: FieldProps = {
        cols,
        rows: fieldRows,
        isActive: t.isActive,
        workers: recent.map(c => ({
          id: c.id,
          cat: c.cat,
          state: c.endedAt === undefined ? 'run' : c.hasFailed ? 'fail' : 'ok',
          isSub: c.isSub === true,
          say: c.say ?? '',
          seq: c.seq ?? 0,
        })),
      }

      return (
        <Box flexDirection="column">
          <Text color={statusColor} dimColor={!head && !t.isActive} wrap="truncate-end">
            {status}
          </Text>
          <Client key="field" module="./field.tsx" props={field} width={cols} height={fieldRows} />
          <Text dimColor>{footer}</Text>
        </Box>
      )
    }

    // ClientもSvgもない画面(VS Code)では文字だけで出す
    const { Box, Text } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">
        <Text wrap="truncate-end">{status}</Text>
        <Text dimColor>{footer}</Text>
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 jnk0vc

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 に読んだコミット 159dc81b61bf のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。plugins/clawd-factory/hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。3 ファイルを解析
コードが 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 .)、触るものを見て、読んだコミットを入れてください。

リポジトリがそのままマーケットプレイスです。このマーケットプレイスを足し(ターミナルでは次のコマンド、デスクトップアプリではプラグインの設定)、そこから Mod を入れます。

/plugin marketplace add jnk0vc/clawd-factory
/plugin install clawd-factory@clawd-factory

入るのはマーケットプレイスの最新のコミットで、ここで読んだもの(159dc81b61bf)と違うことがあります。入れる前に見比べてください。

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン