modscode EN

modscode / 図鑑 / sidebot

sidebot

嗶嗶(Sidebot):像素機器人旁路小助手,在側邊小窗回答問題,看得到主 session 的內容但不干擾它

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

何をするか

  • 欄・トーストを描く
  • /buddy を足す
  • session.startにフックする

良いところ

  • ネットワークに出ない
  • プロセスを起こさない
  • 小さい(203 行)
  • TypeScript で書かれている

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like sidebot by monowu (pane, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/monowu-sidebot/
// 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: "嗶嗶" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Input } = $.ui.resolve(e)
    const bubble = '…'
    const caption = '…'
    const text = '…'
    const text2 = '…'
    const text3 = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="column" alignItems="center">
          <Box>
            <Box>
              <Box marginLeft={1}>
                <Text dimColor>
                  {bubble}
                </Text>
              </Box>
            </Box>
          </Box>
          <Text dimColor>
            {caption}
          </Text>
        </Box>
        <Box flexDirection="column">
          <Box flexDirection="column">
            <Text color="suggestion" wrap="wrap">
              你:
              {text}
            </Text>
            <Button plain label="[複製]" />
          </Box>
          <Box flexDirection="column">
            <Text color="suggestion" wrap="wrap">
              你:
              {text2}
            </Text>
            <Button plain label="[複製]" />
          </Box>
          <Box flexDirection="column">
            <Text color="suggestion" wrap="wrap">
              你:
              {text3}
            </Text>
            <Button plain label="[複製]" />
          </Box>
        </Box>
        <Input placeholder="問點什麼…(Enter 送出)" autoFocus />
        <Box>
          <Box marginRight={2}>
            <Button label="[收起]" />
          </Box>
          <Button label="[清空對話]" />
        </Box>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    await $.ui.toast(`已複製回覆`)
    return next(e)
  })
}

Mod 自身のコード

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

hooks/register.tsx 47〜202 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const { Box, Text, Input, Button } = $.ui.resolve(e)
    const busy = await read($, isBusy)
    const msgs = await read($, chat)
    const n = await read($, round)
    const until = await read($, typingUntil)
    const now = await $.clock.now()

    // 三種狀態:敲鍵盤(娃娃正在回答)、思考(使用者正在打字,娃娃在旁邊等)、閒晃
    const mode = busy ? 'type' : now < until ? 'think' : 'idle'
    const odd = frame % 2 === 1
    const blink = frame % 11 === 0

    // 閒晃:原地左右看(中、左、中、右,每 1.6 秒換一次)
    const pos = SPAN / 2
    const gaze: Gaze = mode === 'idle' ? (['center', 'left', 'center', 'right'] as const)[Math.floor(frame / 4) % 4] : 'center'

    // 眼睛字元:思考時往上看、打字時往下看
    const glyph = mode === 'think' ? '▀' : mode === 'type' ? '▄' : blink ? '▁' : '▪'
    const bubble = mode === 'think' ? ['·', '··', '···'][frame % 3] : ''

    const send = async (text: string) => {
      const q = text.trim()
      if (!q || (await read($, isBusy))) return
      // 換一個 key 讓輸入框重建,送出後即清空
      await update($, round, (v: number) => v + 1)
      await update($, typingUntil, () => 0)
      const before = await read($, chat)
      await update($, chat, (l: Msg[]) => [...l, { role: 'user', text: q } as Msg].slice(-100))
      await update($, isBusy, () => true)
      const history = before
        .slice(-20)
        .map(m => `${m.role === 'user' ? '使用者' : '小機器人'}:${m.text}`)
        .join('\n')
      // 旁路:複製主 session 目前的對話當背景(唯讀、不寫回主 session),
      // 再附上小窗自己的對話。小窗的問答不會出現在主 session。
      const prompt =
        `【旁路小窗】${PERSONA}\n` +
        '以下是你和使用者在小窗裡的對話紀錄,請只回答最後一個問題。\n' +
        `${history ? history + '\n' : ''}使用者:${q}\n小機器人:`
      let r = await $.model.fork({ prompt })
      let note = ''
      if (!r.isAnswered && r.reason === 'nothing-to-fork') {
        // 主 session 還沒有任何回覆(或剛 /clear):改用沒有背景的一般回答
        note = '(主 session 還沒有內容,這次沒有背景)\n'
        r = await $.model.complete({
          model: 'haiku',
          system: PERSONA,
          prompt,
          maxTokens: 700,
          timeoutMs: 60000,
        })
      }
      const reply = r.isAnswered ? note + r.text.trim() : `(出錯了:${r.reason})`
      await update($, chat, (l: Msg[]) => [...l, { role: 'buddy', text: reply } as Msg].slice(-100))
      await update($, isBusy, () => false)
    }

    const S = '#b8c4d6'
    const Ss = '#8493aa'

    // 機器人(寬 10、高 3)
    const antenna = mode === 'think' ? (odd ? '#ef4444' : '#fecaca') : odd ? '#ef4444' : '#fca5a5'
    const screen = [0, 1, 2, 3, 4, 5].map(i => {
      const isEye = EYE_AT[gaze].includes(i)
      const g = mode === 'idle' && !isEye ? ' ' : isEye ? (glyph === '▪' ? '■' : glyph) : ' '
      return (
        <Text key={`s${i}`} color={odd && mode !== 'idle' ? '#5eead4' : '#22d3ee'} backgroundColor={DARK}>
          {g}
        </Text>
      )
    })
    const robotFeet =
      ' ▀▙▄▄▄▄▟▀ '
    const robot = (
      <Box flexDirection="column">
        <Text color={S}>
          {'  ▟██'}
          <Text color={antenna}>●</Text>
          {'█▙  '}
        </Text>
        <Text color={S}>
          {'▐█'}
          {screen}
          {'█▌'}
        </Text>
        {mode === 'type' ? (
          <Text>
            {odd ? <Text color={S}>▐▌</Text> : null}
            <Text color={KEY}>▄▄▄▄▄▄▄▄</Text>
            {odd ? null : <Text color={S}>▐▌</Text>}
          </Text>
        ) : (
          <Text color={Ss}>{robotFeet}</Text>
        )}
      </Box>
    )

    const sprite = robot
    // 用主題色鍵,會跟著深淺色主題自動調整
    const tint = 'suggestion'
    const caption = mode === 'type' ? '敲鍵盤回答中…' : mode === 'think' ? '嗯…我想想~' : '問我任何事~(我看得到主 session,但不會動它)'

    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="column" alignItems="center">
          <Box width={SPAN + 16}>
            <Box marginLeft={pos}>
              {sprite}
              <Box marginLeft={1}>
                <Text dimColor>{bubble}</Text>
              </Box>
            </Box>
          </Box>
          <Text dimColor>{caption}</Text>
        </Box>
        <Box flexDirection="column">
          {msgs.slice(-30).map((m: Msg, i: number) => (
            <Box key={`m${i}`} flexDirection="column">
              <Text color={m.role === 'user' ? undefined : tint} wrap="wrap">
                {m.role === 'user' ? '你:' : '娃:'}
                {m.text}
              </Text>
              {m.role === 'buddy' ? (
                <Button
                  key={`copy${i}`}
                  plain
                  label="[複製]"
                  onPress={async press => {
                    const r = await $.ui.copy({ text: m.text, surface: press.surface })
                    $.ui.toast(r.isCopied ? '已複製回覆' : '複製失敗')
                  }}
                />
              ) : null}
            </Box>
          ))}
        </Box>
        <Input
          key={`ask${n}`}
          placeholder="問點什麼…(Enter 送出)"
          onInput={async (v: string) => {
            const t = await $.clock.now()
            await update($, typingUntil, () => (v ? t + TYPING_MS : 0))
          }}
          onSubmit={(v: string) => send(v)}
          autoFocus
        />
        <Box>
          <Box marginRight={2}>
            <Button key="close" label="[收起]" onPress={() => $.ui.close({ id: PANE })} />
          </Box>
          <Button key="clear" label="[清空對話]" onPress={() => update($, chat, () => [])} />
        </Box>
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 monowu

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。1 ファイルを解析
コードが 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 のデザイン「monowu-sidebot」をコードごと読んで、同じようなペインを作って

Claude から探す: MCP コネクタ

似たデザイン