modscode EN

modscode / 図鑑 / away-receipt

away-receipt

離開一段時間回來時,對話旁列出離開期間發生了什麼:多久、跑了幾輪、花多少,動過的 repo、跑過的測試、做完的背景工作

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

何をするか

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

良いところ

  • ネットワークに出ない
  • 小さい(353 行)
  • TypeScript で書かれている
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like away-receipt by Mango (pane, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/mangow314-away-receipt/
// 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 } = $.ui.resolve(e)
    return (
      <Box flexDirection="column">
        <Text color="#7d8794">
          還沒有收據,打 /receipt
        </Text>
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const duration = '…'
    await $.ui.toast(`away-receipt:離開 ${duration},終端機太窄沒畫出來,打 /receipt 看收據`)
    await $.ui.toast(`away-receipt:提示框現在收不到字(可能有對話框開著),沒有填進去`)
    return next(e)
  })
}

Mod 自身のコード

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

away-receipt/hooks/register.tsx 153〜237 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
    const { Box, Button, Text } = $.ui.resolve(e)
    const r = await read($, receiptAtom)
    if (r === null) return <Box flexDirection="column"><Text color={LABEL}>還沒有收據,打 /receipt</Text></Box>
    const lines: RenderElement[] = []
    // 每行一個帶 key 的 Box:太長截斷
    const line = (key: string, ...parts: RenderElement[]) => lines.push(<Box key={key}><Text wrap="truncate-end">{parts}</Text></Box>)
    const gap = (key: string) => lines.push(<Box key={key}><Text>{' '}</Text></Box>)
    const more = (key: string, n: number, unit: string) => {
      if (n > MAX_ITEMS) line(key, <Text color={LABEL}>{`    還有 ${n - MAX_ITEMS} ${unit}`}</Text>)
    }

    line('head',
      <Text color={LABEL}>離開 </Text>, <Text color={VALUE} bold>{duration(r.awayMs)}</Text>,
      <Text color={LABEL}> · 跑了 </Text>, <Text color={VALUE} bold>{String(r.turns)}</Text>, <Text color={LABEL}> 輪 · </Text>,
      <Text color={VALUE} bold>{`$${r.usd.toFixed(2)}`}</Text>)

    r.repos.forEach((repo, i) => {
      gap(`repo-${i}-gap`)
      const isClean = repo.commits.length === 0 && repo.files.length === 0
      line(`repo-${i}`, <Text color={SKY} bold>{`${GIT} ${repo.name}`}</Text>, <Text color={VALUE}>{` (${repo.branch})`}</Text>,
        isClean ? <Text color={LABEL}>{' ✓ 沒有新 commit、沒有未 commit 檔'}</Text> : <Text>{''}</Text>)
      if (repo.commits.length > 0) line(`repo-${i}-commits`, <Text color={LABEL}>{`  新 commit ${repo.commits.length} 個`}</Text>)
      repo.commits.slice(0, MAX_ITEMS).forEach((c, j) => {
        const [hash = '', ...subject] = c.split(' ')
        line(`repo-${i}-c${j}`, <Text color={ORANGE}>{`    ${hash}`}</Text>, <Text color={VALUE}>{` ${subject.join(' ')}`}</Text>)
      })
      more(`repo-${i}-cmore`, repo.commits.length, '個')
      if (repo.files.length > 0) line(`repo-${i}-files`, <Text color={LABEL}>{`  未 commit ${repo.files.length} 檔`}</Text>)
      repo.files.slice(0, MAX_ITEMS).forEach((f, j) => line(`repo-${i}-f${j}`, <Text color={VALUE}>{`    ${f}`}</Text>))
      more(`repo-${i}-fmore`, repo.files.length, '檔')
      repo.worktrees.forEach((w, j) => line(`repo-${i}-w${j}`, <Text color={LABEL}>{`  ⎇ ${w}`}</Text>))
    })

    if (r.tests.length > 0) {
      gap('tests-gap')
      const failed = r.tests.filter(t => t.code !== 0)
      const hint = failed.length === 0 ? '' : `  按 ${failed.length === 1 ? '1' : `1–${Math.min(MAX_KEYS, failed.length)}`} 把失敗的指令填進提示框`
      line('tests', <Text color={VALUE} bold>驗證</Text>, <Text color={LABEL}>{hint}</Text>)
      // 失敗的測試是按鈕:按下把「修這個」填進提示框、關掉收據,像 quickfix 跳到該處(前 9 條有數字鍵)
      let k = 0
      r.tests.forEach((t, j) => {
        const runs = t.runs > 1 ? ` ×${t.runs}` : ''
        if (t.code === 0) {
          line(`test-${j}`, <Text color={LABEL}>{`  ✔ exit 0${runs}  `}</Text>, <Text color={VALUE}>{t.cmd}</Text>)
          return
        }
        k += 1
        const press = () => askFix($, t)
        lines.push(
          <Box key={`test-${j}`} flexDirection="row">
            <Text>{'  '}</Text>
            {k <= MAX_KEYS
              ? <Button key={`fix-${k}`} plain hotkey={String(k)} label="✗" onPress={press} />
              : <Button key={`fix-${k}`} plain label="✗" onPress={press} />}
            <Text color={RED} wrap="truncate-end">{` exit ${t.code ?? '?'}${runs}  ${t.cmd}`}</Text>
          </Box>,
        )
      })
    }

    if (r.tasks.length > 0) {
      gap('tasks-gap')
      line('tasks', <Text color={VALUE} bold>背景工作</Text>)
      r.tasks.forEach((t, j) => {
        const isOk = t.status === 'completed'
        line(`task-${j}`, <Text color={isOk ? LABEL : RED}>{`  ${isOk ? '✔' : '✗'} `}</Text>,
          <Text color={isOk ? VALUE : RED}>{isOk ? t.summary : `${t.summary}(${t.status})`}</Text>)
      })
    }

    if (r.repos.length === 0 && r.tests.length === 0 && r.tasks.length === 0) {
      gap('none-gap')
      line('none', <Text color={LABEL}>這段時間沒有動到 repo、沒跑測試、沒有背景工作</Text>)
    }

    return (
      <Box flexDirection="column">
        {lines}
        <Box marginTop={1}>
          <Button key="close" plain hotkey="q" label="關閉" onPress={() => $.ui.close({ id: PANE })} />
        </Box>
      </Box>
    )
  })
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 Mango

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.

コードが呼ぶもの

プログラム起動環境変数ツール呼び出し保存

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

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

コードから読めること

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。away-receipt/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 のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。git(通信する)
読んで送るファイルや環境変数を読み、かつ通信するか。読んだうえで通信する
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

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

入れる

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

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

/plugin marketplace add mangow314/mango-mods
/plugin install away-receipt@mango-mods

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン