modscode EN

modscode / 図鑑 / time-machine

time-machine

Every Claude turn becomes a snapshot: review what changed step by step, undo it, or travel back. Local, zero tokens.

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

何をするか

  • プロンプトの上の帯・欄・ステータス行・トーストを描く
  • Write・Edit・NotebookEdit・Bash の呼び出しを見張る
  • prompt.submit・session.start・turn.complete・turn.startにフックする
  • ターンをまたいで自分の状態を持つ
  • プロセスを起こす

良いところ

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

作り始めるためのコード

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

雛形(register.tsx)

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

// Drawn like time-machine by xzwache (pane, band, status, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/xzwache-time-machine/
// 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, Text, Button } = $.ui.resolve(e)
    const summary = '…'
    const alert = '…'
    return (
      <Box flexDirection="column">
        <Box flexDirection="row" gap={2}>
          <Text dimColor>
            {`⏱ ${summary}`}
          </Text>
          <Button plain hotkey="1" label="Undo turn" />
          <Button plain hotkey="2" label="Review" />
          <Button role="dismiss" label="×" />
        </Box>
        <Box flexDirection="row" gap={2}>
          <Text color="yellow">
            {`⚠ ${alert}`}
          </Text>
          <Button plain hotkey="3" label="Undo these" />
        </Box>
        {await next(e)}
      </Box>
    )
  })

  // the pane: open it with $.ui.open({ id: 'my-pane', title: "Heat" })
  on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
    const { Box, Text, Button, Svg, Markdown } = $.ui.resolve(e)
    const describe = '…'
    const turns = '…'
    const since = '…'
    const i = '…'
    const METRIC_LABELS = '…'
    const svgTreemap = '…'
    const alt = '…'
    const legend = '…'
    const value = '…'
    const length = '…'
    const path = '…'
    const notice = '…'
    const fileUrl = '…'
    return (
      <Box flexDirection="column">
        <Text bold>
          {`project  ·  ${describe}`}
        </Text>
        <Text dimColor>
          {`${turns} Claude turns since ${since} · size: lines changed`}
        </Text>
        <Box flexDirection="row" gap={1} marginTop={1}>
          <Button hotkey={`${i}`} variant="primary" label={`${METRIC_LABELS}`} />
          <Button hotkey={`${i}`} variant="primary" label={`${METRIC_LABELS}`} />
          <Button hotkey={`${i}`} variant="primary" label={`${METRIC_LABELS}`} />
          <Button hotkey="b" label="↑ Up" />
          <Button hotkey="o" label="Open in browser" />
        </Box>
        <Box marginTop={1}>
          <Svg source={`${svgTreemap}`} alt={`${alt}`} isInteractive />
        </Box>
        <Text dimColor>
          {legend}
        </Text>
        <Box flexDirection="column" marginTop={1}>
          <Box flexDirection="row" gap={1}>
            <Text>
              ██
            </Text>
            <Button plain label={`${value}`} />
          </Box>
          <Box flexDirection="row" gap={1}>
            <Text>
              ██
            </Text>
            <Button plain label={`${value}`} />
          </Box>
          <Box flexDirection="row" gap={1}>
            <Text>
              ██
            </Text>
            <Button plain label={`${value}`} />
          </Box>
          <Text dimColor>
            {"…and "}
            {length}
            {" more"}
          </Text>
        </Box>
        <Box flexDirection="column" marginTop={1}>
          <Box flexDirection="row" gap={1}>
            <Text bold>
              {path}
            </Text>
            <Button role="dismiss" label="×" />
          </Box>
          <Text dimColor>
            No closed Claude turn changed it in this window.
          </Text>
          <Button plain label={`${value}`} />
          <Button plain label={`${value}`} />
          <Button plain label={`${value}`} />
        </Box>
        <Text color="yellow">
          {notice}
        </Text>
        <Markdown text={`[Open the interactive map](${fileUrl})`} />
      </Box>
    )
  })

  on('session.start', async ($, e, next) => {
    const problem = '…'
    const took = '…'
    await $.ui.status(`⏱ time machine on`)
    await $.ui.toast(`⏱ ${problem}`)
    await $.ui.toast(`⏱ Snapshot took ${took}s. List big folders in .tmignore or .gitignore to speed it up.`)
    return next(e)
  })
}

Mod 自身のコード

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

hooks/register.tsx 150〜162 行 · バンド
  on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
    const shown = await read($, band)
    if (shown === null || e.props.hasSurvey || e.props.isWorking) return next(e)

    return bandView($.ui.resolve(e), shown, Math.max(20, e.props.bodyColumns), {
      undo: () => void update($, band, now => now && { ...now, confirm: 'turn' as const }),
      undoSensitive: () => void update($, band, now => now && { ...now, confirm: 'sensitive' as const }),
      confirm: () => void undoFromBand($, shown.id, shown.confirm === 'sensitive'),
      cancel: () => void update($, band, now => now && { ...now, confirm: null }),
      review: () => void openPane($, shown.id),
      close: () => void update($, band, () => null),
    })
  })
src/view.tsx 29〜69 行 · バンド
export function bandView(table: Table, shown: Band, columns: number, on: BandHandlers): RenderElement {
  const { Box, Text, Button } = table
  const close = <Button key="tm-close" role="dismiss" label="×" onPress={on.close} />

  if (shown.result !== null) {
    return (
      <Box flexDirection="row" gap={1}>
        <Text color="green">{clip(shown.result, columns - 6)}</Text>
        {close}
      </Box>
    )
  }

  if (shown.confirm === 'turn' || shown.confirm === 'sensitive') {
    const question = shown.confirm === 'turn' ? 'Undo this turn?' : `Undo only ${shown.alert ?? 'the flagged files'}?`
    return (
      <Box flexDirection="row" gap={2}>
        <Text bold>{clip(`⏱ ${question}`, Math.max(10, columns - 30))}</Text>
        <Button key="tm-yes" plain hotkey="1" label="Yes, undo" onPress={on.confirm} />
        <Button key="tm-no" plain hotkey="2" label="No" onPress={on.cancel} />
      </Box>
    )
  }

  return (
    <Box flexDirection="column">
      <Box flexDirection="row" gap={2}>
        <Text dimColor>{clip(`⏱ ${shown.summary}`, Math.max(10, columns - 34))}</Text>
        <Button key="tm-undo" plain hotkey="1" label="Undo turn" onPress={on.undo} />
        <Button key="tm-review" plain hotkey="2" label="Review" onPress={on.review} />
        {close}
      </Box>
      {shown.alert !== null && (
        <Box flexDirection="row" gap={2}>
          <Text color="yellow">{clip(`⚠ ${shown.alert}`, Math.max(10, columns - 20))}</Text>
          <Button key="tm-undo-sensitive" plain hotkey="3" label="Undo these" onPress={on.undoSensitive} />
        </Box>
      )}
    </Box>
  )
}
hooks/register.tsx 164〜180 行 · ペイン
  on('ui.render', { component: 'Pane', requestId: HEAT_PANE }, async ($, e) => {
    const view = await read($, heat)
    const table = $.ui.resolve(e)
    if (view === null) {
      const { Text } = table
      return <Text dimColor>Run /tm heat to draw the map.</Text>
    }

    return heatView(table, e.surface, view, Math.max(30, e.props.bodyColumns), e.viewport?.rows ?? 40, {
      metric: metric => void update($, heat, now => now && { ...now, metric }),
      enter: node => void heatAction($, () => (node.isDir ? moveHeat($, view, node.path) : pickFile($, view, node))),
      up: path => void heatAction($, () => moveHeat($, view, path)),
      openPage: () => void heatAction($, () => openHeatPage($, view)),
      openTurn: id => void openPane($, id),
      closeFile: () => void update($, heat, now => now && { ...now, file: null }),
    })
  })
src/view.tsx 190〜267 行 · ペイン
export function heatView(
  table: Table,
  surface: RenderSurface,
  view: HeatView,
  columns: number,
  rows: number,
  on: HeatHandlers,
): RenderElement {
  const { Box, Text, Button, Markdown } = table
  const { nodes, metric, parent } = view
  const max = maxValue(nodes, metric)
  const since = new Date(view.since).toISOString().slice(0, 10)
  const legend =
    metric === 'owner'
      ? 'blue: others · grey: both · orange: Claude'
      : `${METRIC_LABELS[metric]}: dark none → yellow most`

  return (
    <Box flexDirection="column">
      <Text bold>{clip(`${view.path === '' ? 'project' : `${view.path}/`}  ·  ${describe(view.total)}`, columns)}</Text>
      <Text dimColor>{clip(`${view.turns} Claude turns since ${since} · size: lines changed`, columns)}</Text>
      <Box flexDirection="row" gap={1} marginTop={1}>
        {METRICS.map((one, i) => (
          <Button
            key={`m-${one}`}
            hotkey={String(i + 1)}
            variant={one === metric ? 'primary' : undefined}
            label={METRIC_LABELS[one]}
            onPress={() => on.metric(one)}
          />
        ))}
        {parent !== null && <Button key="up" hotkey="b" label="↑ Up" onPress={() => on.up(parent)} />}
        <Button key="open" hotkey="o" label="Open in browser" onPress={on.openPage} />
      </Box>
      <Box marginTop={1}>
        {mapView(table, surface, nodes, metric, columns, Math.max(6, Math.min(MAP_ROWS, rows - LISTED - 10)))}
      </Box>
      <Text dimColor>{clip(legend, columns)}</Text>
      <Box flexDirection="column" marginTop={1}>
        {nodes.slice(0, LISTED).map((node, i) => {
          const name = `${node.isDir ? '▸' : ' '} ${node.name}${node.isDir ? '/' : ''}`
          const shown = metric === 'churn' ? '' : `${valueLabel(node, metric, METRIC_UNITS)} · `
          return (
            <Box key={`row-${i}`} flexDirection="row" gap={1}>
              <Text color={hex(heatColor(intensity(node, metric, max), metric))}>██</Text>
              <Button
                key={`n-${i}`}
                plain
                label={clip(`${name}  ${shown}${describe(node)}`, Math.max(10, columns - 4))}
                onPress={() => on.enter(node)}
              />
            </Box>
          )
        })}
        {nodes.length > LISTED && <Text dimColor>…and {nodes.length - LISTED} more</Text>}
      </Box>
      {view.file !== null && (
        <Box flexDirection="column" marginTop={1}>
          <Box flexDirection="row" gap={1}>
            <Text bold>{clip(view.file.path, columns - 4)}</Text>
            <Button key="file-close" role="dismiss" label="×" onPress={on.closeFile} />
          </Box>
          {view.file.turns.length === 0 && <Text dimColor>No closed Claude turn changed it in this window.</Text>}
          {view.file.turns.map((turn, i) => (
            <Button
              key={`t-${i}`}
              plain
              label={clip(`↳ ${clock(turn.time)} ${turn.title}`, columns)}
              onPress={() => on.openTurn(turn.id)}
            />
          ))}
        </Box>
      )}
      {view.notice !== '' && <Text color="yellow">{clip(view.notice, columns * 2)}</Text>}
      {view.page !== null && <Markdown text={`[Open the interactive map](${fileUrl(view.page)})`} />}
    </Box>
  )
}
src/view.tsx 269〜287 行 · ペイン
function mapView(
  table: Table,
  surface: RenderSurface,
  nodes: readonly HeatNode[],
  metric: HeatMetric,
  columns: number,
  rows: number,
): RenderElement {
  // The element table answers `in` for every name; the surface says what it draws.
  if (surface === 'terminal' && 'Raster' in table) {
    const width = Math.min(512, Math.max(10, columns))
    const { Raster } = table
    return <Raster key="heat-map" columns={width} rows={rows} cells={rasterCells(nodes, metric, width, rows)} />
  }
  if (!('Svg' in table)) throw new Error(`No treemap element on ${surface}`)
  const { Svg } = table
  const alt = `Treemap of ${nodes.length} entries by ${METRIC_LABELS[metric]}`
  return <Svg source={svgTreemap(nodes, metric, 720, 360)} alt={alt} isInteractive />
}
ライセンスの全文(MIT)
MIT License

Copyright (c) 2026 xzwache

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

載せる条件: 確かめやすいコード
入口を読んだhooks/hooks.json が名指すモジュールをすべて読んだ。hooks/register.tsx
解析できるすべてのファイルが TypeScript か JavaScript として解析できる。22 ファイルを解析
コードが 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/… などは無い)。hooks/register.tsx:298 uname(Windows にない)
通信fetch の送り先(https のホスト)がコードに書いてあるか。通信なし
プログラム起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。hooks/register.tsx:204 実行時に決まるプログラム; hooks/register.tsx:300 実行時に決まるプログラム
読んで送るファイルや環境変数を読み、かつ通信するか。reads environment variables and files and reaches the network
ソースの鍵ソースに API キーや秘密鍵らしきものがあるか。ソースに鍵なし
ライセンスオープンなライセンス(MIT・Apache-2.0・BSD・ISC・Unlicense・0BSD・CC0)で全文があれば、modscode にコードを載せる。違えばリンクだけ。MIT

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

入れる

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

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

/plugin marketplace add xzwache/claude-time-machine
/plugin install time-machine@claude-time-machine

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

Claude に聞く

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

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

Claude から探す: MCP コネクタ

似たデザイン