modscode EN

modscode / 図鑑 / lemo-meter

lemo-meter

用量横条:输入框上方显示上下文、5 小时额度、花费和 git 分支;状态栏显示消息编号(已有自己的状态栏时默认关闭);点「检查」才联网查新版本 / Usage meter: context, 5-hour quota, cost and git branch above the prompt; a status line with the message number (off by default if you have your own); checks for upd…

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

何をするか

  • プロンプトの上の帯を描く
  • lemo.caps・lemo.off・lemo.toggle・session.start ほか 1 個にフックする
  • ターンをまたいで自分の状態を持つ
  • ネットワークに出る

良いところ

  • プロセスを起こさない
  • TypeScript で書かれている
  • デスクトップ専用の分岐がある
  • エラーを扱う

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like lemo-meter by lemomo (pane, band, status), as modscode read it from the mod's code:
// https://modscode.com/gallery/lemomo-ai-lemo-meter/
// 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, Svg } = $.ui.resolve(e)
    const bandSvg = '…'
    const alt = '…'
    return (
      <Box flexDirection="column" gap={1}>
        <Box flexDirection="column" width="100%">
          <Svg source={`${bandSvg}`} alt={`${alt}`} height={106} />
        </Box>
        {await next(e)}
      </Box>
    )
  })
}

Mod 自身のコード

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

plugins/lemo-meter/hooks/register.tsx 482〜496 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    // 问卷占着横条时让给它;安全页上关了横条就原样交给里层
    if (e.props.hasSurvey || !(await read($, bandOn))) return next(e)
    const below = await next(e)
    const band = await drawBand($, e)
    if (below.type === 'engine') return band
    // 引擎原样不许放进带 width 的 Box(会拒绝整棵树),所以外面这层不给 width
    const { Box } = $.ui.resolve(e)
    return (
      <Box flexDirection="column" gap={1}>
        {band}
        {below}
      </Box>
    )
  })
plugins/lemo-meter/hooks/register.tsx 273〜398 行 · バンド
async function drawBand($: EngineInterface, e: RenderInput<'AbovePrompt'>): Promise<RenderElement> {
  const lk = await look($)
  const S = STR[lk.lang]
  const u = await read($, usage)
  const n = await seqOf($)
  const br = await read($, branch)
  const now = await $.clock.now()
  const list = liveBadges((await $.state.get(BadgesRef)).value, now)
  const shown = (await $.state.get(NoticeRef)).value ?? null
  // 读了 frame 就每秒重画一次。有倒计时的胶囊时要读,剩余时间跟着走;
  // 终端有像素小画时也读,小画一直冒泡。
  // 桌面没有倒计时就不读,免得 SVG 跟着一直重画、闪(平时让 SVG 自己的气泡动画跑)
  const ticking = list.some(b => typeof b.endsAt === 'number' && b.endsAt > now)
  const animate = e.surface === 'terminal' && lk.st.sprite !== null && lk.st.sprite.frames.length > 1
  const tick = ticking || animate ? ((await $.state.get(FrameRef)).value ?? 0) : 0
  const pills: Pill[] = list.map(b => ({ text: badgeLabel(b, now, lk.lang), tone: b.tone }))
  const brandName = word(lk, 'lemo-core.title', 'lemo-mod')

  if (e.surface === 'desktop') {
    const { Box, Svg } = $.ui.resolve(e)
    const data = {
      ctx: u.ctx,
      quota: u.quota,
      usd: u.usd,
      label: fill(word(lk, 'lemo-meter.trial', S.trial), { no: exp(n) }),
      pills: br === null ? pills : [...pills, { text: `⎇ ${br}`, tone: 'grey' as const }],
      notice: shown === null ? null : { text: shown.text, tone: shown.tone },
      brand: brandName,
      brandSub: word(lk, 'lemo-meter.brandSub', S.brandSub),
      words: { ctx: S.band.ctx, quota: S.band.quota, cost: S.band.cost, pending: word(lk, 'lemo-meter.pending', S.band.pending) },
    }
    const alt = `${brandName}: ${S.band.ctx} ${pct(u.ctx)}, ${S.band.quota} ${pct(u.quota)}`
    const guess = Math.round(e.props.bodyColumns * CELL_PX)
    // 不给 width,外面包一层竖排 Box,竖排容器会把它横向拉满(桌面上单独放只有 280 像素)。
    // 不加 isInteractive:那样 SVG 装在一个沙盒框里,每重画一次整个框重新加载、闪一下;画成图片,内容没变就不闪
    return (
      <Box flexDirection="column" width="100%">
        <Svg source={bandSvg(data, { width: '100%', guess }, lk.c, lk.st.motif, lk.st.sprite)} alt={alt} height={BAND_H} />
      </Box>
    )
  }

  // 终端(以及别的界面):两行刻度尺 + 一行底行;提示出现时顶替底行
  const { Box, Text } = $.ui.resolve(e)
  const ink = bareInk(lk, e.surface)
  const ctxLabel = word(lk, 'lemo-meter.tbandCtx', S.tband.ctx)
  const quotaLabel = word(lk, 'lemo-meter.tbandQuota', S.tband.quota)
  const cols = Math.max(width(ctxLabel), width(quotaLabel))
  const scale = (key: string, label: string, v: number | null) => {
    const r = ruler(v)
    return (
      <Box key={key} flexDirection="row">
        <Text color={lk.c.pencil}>{padTo(label, cols) + ' '}</Text>
        <Text color={lk.c.grid}>{r.before}</Text>
        <Text color={lk.c.ink}>●</Text>
        <Text color={lk.c.grid}>{r.after}</Text>
        <Text {...ink}>{' ' + (v === null ? word(lk, 'lemo-meter.pending', S.band.pending) : pct(v))}</Text>
      </Box>
    )
  }
  const sample = word(lk, 'lemo-meter.tbandSample', S.tband.sample)
  // 底行放不下时截掉,不折行:折出来的行会把刻度尺往上挤,分支名也会断成「⎇」和「main」两行
  let foot: RenderChildren
  if (shown !== null) {
    foot = <Text {...termTone(lk, shown.tone)} bold wrap="truncate">{` ● ${shown.text} `}</Text>
  } else {
    foot = (
      <Text color={lk.c.pencil} wrap="truncate">
        {`${sample} ${exp(n)}${u.usd === null ? '' : ` · ${money(u.usd)}`}`}
        {pills.map((p, i) => (
          <Text key={`badge-${i}`} color={lk.c.pencil}>
            {' · '}
            <Text {...termTone(lk, p.tone)}>{p.tone === 'accent' ? ` ${p.text} ` : p.text}</Text>
          </Text>
        ))}
        {br === null ? '' : ` · ⎇ ${br}`}
      </Text>
    )
  }
  // 地方不够时一级一级往下减:先不画小画,刻度尺也放不下(面板停在旁边、对话区很窄,或者面板在输入框上方、
  // 只给一两行)时改成一行文字。不然刻度尺会被挤成竖排,引擎再把多出来的行收成「↓ 3 more」。
  // 引擎在横条第一行的右端画收起按钮「[-]」(3 格):第一行右边留出 FOLD 格,数值不被它盖住
  const room = e.props.bodyColumns
  const rows = e.props.maxRows
  const pending = word(lk, 'lemo-meter.pending', S.band.pending)
  const rowW = cols + 1 + width(ruler(0).before) + 1 + width(ruler(0).after) + 1 + Math.max(width(pending), 4)
  if (room < rowW + FOLD || rows < 3) {
    const val = (v: number | null) => (v === null ? pending : pct(v))
    const brief = (
      <Box key="meter-brief" paddingRight={FOLD}>
        <Text {...ink} wrap="truncate">{`${ctxLabel} ${val(u.ctx)} · ${quotaLabel} ${val(u.quota)}`}</Text>
      </Box>
    )
    // 只给一行时:有提示就只写提示,没有就只写用量
    if (rows < 2) return shown !== null ? <Box paddingRight={FOLD}>{foot}</Box> : brief
    return (
      <Box flexDirection="column">
        {brief}
        {foot}
      </Box>
    )
  }
  const meter = (
    <Box flexDirection="column">
      {scale('meter-ctx', ctxLabel, u.ctx)}
      {scale('meter-quota', quotaLabel, u.quota)}
      {foot}
    </Box>
  )
  const sprite = lk.st.sprite
  if (e.surface === 'terminal' && sprite !== null && sprite.frames.length > 0) {
    // 风格的像素小画:每秒换一帧。放不下(宽度或行数不够)就不画
    const frame = sprite.frames[tick % sprite.frames.length] ?? sprite.frames[0] ?? []
    const cells = spriteCells(sprite.palette, frame)
    if (room >= cells.columns + 2 + rowW + FOLD && rows >= cells.rows) {
      const { Raster } = $.ui.resolve(e)
      return (
        <Box flexDirection="row" gap={2} alignItems="center">
          <Raster key="meter-sprite" {...cells} />
          {meter}
        </Box>
      )
    }
  }
  return meter
}
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 lemomo

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.

このコードはコード参考書の実例にもあります: プロンプト上の帯(バンド)・$.store で状態を残す

コードが呼ぶもの

通信ファイル読み取り保存

コードから読めること

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

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

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

入れる

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

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

/plugin marketplace add lemomo-ai/lemo-mod
/plugin install lemo-meter@lemo-mod

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン