modscode EN

modscode / 図鑑 / forge

forge

Forge's board and machine views inside Claude Code.

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

何をするか

  • 欄・プロンプトの上の帯・トーストを描く
  • /forge を足す
  • session.end・session.start・turn.complete・turn.startにフックする
  • ターンをまたいで自分の状態を持つ
  • プロセスを起こす

良いところ

  • ネットワークに出ない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like forge by knacklabs (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/knacklabs-forge/
// 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: "Forge" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box } = $.ui.resolve(e)
    return (
      <Box flexDirection="column" gap={1} />
    )
  })

  // the band above the prompt; what else goes there is drawn under it
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const { Box } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">

        {await next(e)}
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const message = '…'
    const drop = '…'
    await $.ui.toast(`Couldn't check the next step: ${message}`)
    await $.ui.toast(`Couldn't run the next step: ${drop}`)
    return next(e)
  })
}

Mod 自身のコード

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

src/forge/mod/hooks/pane.ts 43〜70 行 · ペイン
  on('ui.render', { component: 'Pane' }, async ($, e, next) => {
    if (e.requestId !== 'forge' || (e.surface !== 'terminal' && e.surface !== 'desktop')) return next(e)
    const t = $.ui.resolve(e)
    const now = await $.clock.now()
    const children: RenderNode[] = []
    if (tabs.size) children.push(t.Box({ flexDirection: 'row', gap: 1, children: ['Board', ...tabs.keys()].map(name => t.Button({ key: `tab-${name}`, label: name, onPress: () => { selected = name; $.ui.invalidate('ui.render') } })) }))
    const tab = tabs.get(selected)
    if (tab) children.push(tab(e))
    else if (data.error === TOO_OLD) children.push(t.Text({ children: TOO_OLD }))
    else {
      if (!data.board) children.push(t.Text({ dimColor: true, children: 'Loading Forge…' }))
      if (data.board && !data.board.items.length) children.push(t.Text({ children: 'Nothing in progress.' }))
      for (const item of rows(data.board?.items ?? [])) {
        const [state, detail] = itemLines(item, now)
        if (e.surface === 'desktop') {
          const desktop = $.ui.resolve(e)
          children.push(desktop.Markdown({ text: `| Item and status |\n| --- |\n| ${tableCell(state)} |\n| ${tableCell(detail)} |` }))
          children.push(desktop.Svg({ source: timeline(item, now), alt: stages(item).map(s => stageText(s, now)).join(' → '), isInteractive: true }))
        } else {
          children.push(t.Text({ bold: true, wrap: 'wrap', children: state }))
          children.push(t.Text({ wrap: 'wrap', children: detail }))
        }
        for (const render of actions.get(item.kind ?? '') ?? []) children.push(render(item, e))
      }
    }
    if (data.error && data.error !== TOO_OLD) children.push(t.Text({ dimColor: true, children: `Couldn't refresh: ${data.error}` }))
    return t.Box({ flexDirection: 'column', gap: 1, children })
  })
src/forge/mod/hooks/pane.ts 71〜167 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    working = e.props.isWorking
    if (e.props.hasSurvey || e.props.maxRows < 1) return next(e)
    const t = $.ui.resolve(e), now = await $.clock.now()
    const command = data.error === TOO_OLD || working ? null : data.next?.next.command
    const narrow = e.props.bodyColumns < 80 || e.props.maxRows === 1
    let lines = summary(data, now, working)
    let compact: { title: string, counts: string, timing: string, tail: string } | undefined
    if (narrow && !data.lanes) lines = lines.slice(0, 1)
    else if (narrow && data.error !== TOO_OLD) {
      const n = laneCounts(data), first = activeRows(data)[0]
      const stage = first && stages(first).find(s => s.status === 'running')
      const counts = data.lanes ? `${n.agentsRunning + (n.test ? 1 : 0)} running, ${n.agentsWaiting}+${n.testsWaiting} waiting · ` : ''
      const step = record(first?.worker).step
      lines = [`${counts}${command ? `1: ${command}` : data.next?.next.line ?? 'Loading Forge…'}${typeof step === 'string' ? ` · ${step}` : ''}`]
      compact = { title: first?.title ?? '', counts, timing: first ? `: ${stage ? stageText(stage, now) : first.stage ?? 'unknown'} (${total(first, now)}) · ` : '', tail: `${data.next?.next.line ?? 'Loading Forge…'}${typeof step === 'string' ? ` · ${step}` : ''}` }
    }
    if ((e.viewport?.columns ?? e.props.bodyColumns) < 144 && data.error !== TOO_OLD) {
      lines[0] += ' · /forge for the board'
      if (compact) compact.tail += ' · /forge for the board'
    }
    const children: RenderNode[] = []
    const firstChildren: RenderNode[] = []
    const first = lines[0] ?? ''
    const lanes = laneCounts(data)
    const counts = !narrow && data.lanes && data.error !== TOO_OLD ? `Agents ${lanes.agentsRunning}/${lanes.size} (${lanes.agentsWaiting} waiting) · Tests: ${lanes.test ? 1 : 0} running (${lanes.testsWaiting} waiting) · ` : ''
    const testTitle = `${lanes.testTitle ?? lanes.test?.item ?? 'idle'} · `
    const titleWidth = Math.min(testTitle.length, Math.max(0, e.props.bodyColumns - counts.length - MIN_TITLE_COLUMNS))
    const nextWidth = Math.max(0, e.props.bodyColumns - counts.length - titleWidth)
    let tailColumns = compact?.tail.length ?? 0
    if (command) {
      const [prefix, suffix = ''] = first.split(`1: ${command}`)
      tailColumns = command.length + 3 + suffix.length
      firstChildren.push(
        t.Text({ children: prefix ?? '', wrap: 'truncate-end' }),
        t.Button({ key: 'next-step', hotkey: '1', plain: true, label: counts && command.length + 3 > nextWidth ? `${Array.from(command).slice(0, Math.max(0, nextWidth - 4)).join('')}…` : command, onPress: async () => {
          if (working) return
          let updated: Next
          try {
            const result = await $.process.run(['forge', 'next', '--json'], { cwd: cwd || data.board?.repo_root, timeoutMs: 20000 })
            if (result.exitCode !== 0) throw new Error((result.stderr || result.stdout || 'Forge did not answer').split(/\r?\n/)[0])
            const value: unknown = JSON.parse(result.stdout)
            const root = record(value), following = record(root.next)
            if (typeof root.version !== 'string' || typeof root.repo_root !== 'string' || typeof following.line !== 'string' || !(following.command === null || typeof following.command === 'string')) throw new Error('Malformed forge next output')
            updated = value as Next
          } catch (error) {
            $.ui.toast(`Couldn't check the next step: ${error instanceof Error ? error.message : String(error)}`)
            return
          }
          data.next = updated
          $.ui.invalidate('ui.render')
          if (updated.next.command !== command || working) return
          try {
            // The published declarations lag the documented asUser option.
            const submission = { text: command, asUser: true }
            const result = await $.prompt.submit(submission)
            if (result.drop !== undefined) $.ui.toast(`Couldn't run the next step: ${result.drop || 'Prompt unavailable'}`)
          } catch (error) {
            $.ui.toast(`Couldn't run the next step: ${error instanceof Error ? error.message : String(error)}`)
          }
        } }),
        t.Text({ children: suffix, wrap: 'truncate-end' }),
      )
    } else firstChildren.push(t.Text({ wrap: 'truncate-end', children: first }))
    if (compact) {
      const fixed = compact.counts.length + compact.timing.length
      const tailWidth = Math.min(tailColumns, Math.max(0, e.props.bodyColumns - fixed - MIN_TITLE_COLUMNS))
      children.push(t.Box({ flexDirection: 'row', width: e.props.bodyColumns, children: [
        t.Box({ width: compact.counts.length, flexShrink: 0, children: t.Text({ children: compact.counts }) }),
        t.Box({ width: Math.max(0, e.props.bodyColumns - fixed - tailWidth), minWidth: 0, children: t.Text({ wrap: 'truncate-end', children: compact.title }) }),
        t.Box({ width: compact.timing.length, flexShrink: 0, children: t.Text({ children: compact.timing }) }),
        t.Box({ width: tailWidth, flexShrink: 0, overflow: 'hidden', flexDirection: 'row', children: command ? firstChildren.slice(1) : t.Text({ wrap: 'truncate-end', children: compact.tail }) }),
      ] }))
    } else if (counts) {
      const step = record(activeRows(data).find(i => typeof record(i.worker).step === 'string')?.worker).step
      const tail = `${data.next?.next.line ?? 'Loading Forge…'}${step ? ` · ${step}` : ''}${(e.viewport?.columns ?? e.props.bodyColumns) < 144 ? ' · /forge for the board' : ''}`
      children.push(t.Box({ flexDirection: 'row', width: e.props.bodyColumns, children: [
        t.Box({ width: counts.length, flexShrink: 0, children: t.Text({ children: counts }) }),
        t.Box({ width: titleWidth, minWidth: 0, children: t.Text({ wrap: 'truncate-end', children: testTitle }) }),
        t.Box({ width: nextWidth, flexShrink: 0, overflow: 'hidden', flexDirection: 'row', children: command ? firstChildren.slice(1) : t.Text({ wrap: 'truncate-end', children: tail }) }),
      ] }))
    } else children.push(command ? t.Box({ flexDirection: 'row', children: firstChildren }) : firstChildren[0]!)
    const active = activeRows(data)
    for (const [n, line] of lines.slice(1, Math.min(3, e.props.maxRows)).entries()) {
      const item = active.length > 2 && n === 1 ? undefined : active[n]
      const timing = item ? itemTime(item, now).slice(item.title.length + 2) : undefined
      let status = timing ?? line
      // Reserve the timing cells; the native surface truncates only the title.
      if (timing && status.length >= e.props.bodyColumns) status = status.replaceAll(' ', '')
      const text = t.Text({ wrap: 'truncate-end', children: status.split('✗').flatMap((part, n) => n ? [t.Text({ color: 'red', children: '✗' }), part] : [part]) })
      children.push(item && timing ? t.Box({ flexDirection: 'row', width: e.props.bodyColumns, children: [
        t.Box({ width: Math.max(0, e.props.bodyColumns - status.length), minWidth: 0, children: t.Text({ wrap: 'truncate-end', children: `${item.title}: ` }) }),
        t.Box({ width: status.length, flexShrink: 0, children: text }),
      ] }) : text)
    }
    return t.Box({ flexDirection: 'column', children })
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2024 Symphony Forge Contributors

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。src/forge/mod/hooks/register.ts
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。7 ファイルを解析
コードが 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 のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。forge
読んで送るファイルや環境変数を読み、かつ通信するか。通信しない
ソースの鍵ソースに 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 のデザイン「knacklabs-forge」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン