session-inbox
Collects what is waiting on you in a session: questions, Claude's notes and PR reviews
何をするか
- プロンプトの上の帯・欄・トーストを描く
- /inbox を足す
- ツールの呼び出しを見張る(止めることがある)
- config.set・prompt.compose・prompt.context・prompt.submit ほか 5 個にフックする
- ターンをまたいで自分の状態を持つ
良いところ
- ネットワークに出ない
- TypeScript で書かれている
- エラーを扱う
- ファイルを書かない
作り始めるためのコード
2 種類あります。上のデザインから modscode が書いた雛形と、その Mod 自身のコードのうち描いている部分です。
雛形(register.tsx)
import type { Register } from 'claude-code'
// Drawn like session-inbox by petekp (pane, band, toast), as modscode read it from the mod's code:
// https://modscode.com/gallery/petekp-session-inbox/
// 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 } = $.ui.resolve(e)
const goal = '…'
const now = '…'
const hidden = '…'
const prAlert = '…'
const run = '…'
const run2 = '…'
const run3 = '…'
return (
<Box flexDirection="column">
<Text wrap="truncate-end">
<Text color="claude">
{"◆ "}
</Text>
<Text dimColor>
{goal}
{` · ${now}`}
</Text>
<Text color="warning">
{" · "}
{hidden}
{" older waiting on you in /inbox"}
</Text>
<Text color="autoAccept">
{" · "}
1 note
{" in /inbox"}
</Text>
<Text color="planMode">
{" · "}
{prAlert}
</Text>
</Text>
<Text wrap="truncate-end">
<Text color="success">
{" ● "}
</Text>
<Text dimColor>
{run}
</Text>
</Text>
<Text wrap="truncate-end">
<Text color="success">
{" ● "}
</Text>
<Text dimColor>
{run2}
</Text>
</Text>
<Text wrap="truncate-end">
<Text color="success">
{" ● "}
</Text>
<Text dimColor>
{run3}
</Text>
</Text>
{await next(e)}
</Box>
)
})
// the pane: open it with $.ui.open({ id: 'my-pane', title: "Session inbox" })
on('ui.render', { component: 'Pane', requestId: 'my-pane' }, async ($, e) => {
const { Box, Button, Text } = $.ui.resolve(e)
const hotkey = '…'
const label = '…'
const count = '…'
const count2 = '…'
const count3 = '…'
const length = '…'
const name = '…'
const url = '…'
const name2 = '…'
const url2 = '…'
const name3 = '…'
const url3 = '…'
const title = '…'
const d = '…'
const d2 = '…'
const d3 = '…'
const decisionText = '…'
const decisionText2 = '…'
const decisionText3 = '…'
const status = '…'
return (
<Box flexDirection="column" gap={1}>
<Box backgroundColor="userMessageBackground" paddingX={1} paddingY={1}>
<Box flexDirection="row" columnGap={3} flexGrow={1}>
<Box flexDirection="row">
<Button plain hotkey={`${hotkey}`} label={`${label}`} dimColor />
<Text>
{" "}
{count}
</Text>
</Box>
<Box flexDirection="row">
<Button plain hotkey={`${hotkey}`} label={`${label}`} dimColor />
<Text>
{" "}
{count2}
</Text>
</Box>
<Box flexDirection="row">
<Button plain hotkey={`${hotkey}`} label={`${label}`} dimColor />
<Text>
{" "}
{count3}
</Text>
</Box>
</Box>
</Box>
<Box flexDirection="column" paddingX={1} flexGrow={1}>
<Box flexDirection="column" gap={1}>
<Box flexDirection="column">
<Box paddingLeft={1}>
<Text dimColor wrap="wrap">
Nothing is waiting on you.
</Text>
</Box>
</Box>
<Box flexDirection="column" paddingLeft={1}>
<Text dimColor>
{"Running "}
{length}
</Text>
<Text wrap="wrap">
<Text color="success">
{"● "}
</Text>
<Text>
{name}
{" "}
</Text>
<Text dimColor>
{url}
</Text>
</Text>
<Text wrap="wrap">
<Text color="success">
{"● "}
</Text>
<Text>
{name2}
{" "}
</Text>
<Text dimColor>
{url2}
</Text>
</Text>
<Text wrap="wrap">
<Text color="success">
{"● "}
</Text>
<Text>
{name3}
{" "}
</Text>
<Text dimColor>
{url3}
</Text>
</Text>
</Box>
<Box flexDirection="column" paddingLeft={1}>
<Button plain label={`▸ ${title} ${length}`} dimColor />
<Box flexDirection="column" marginBottom={0}>
<Text wrap="wrap">
<Text color="success">
{"✓ "}
</Text>
<Text dimColor>
{d}
</Text>
</Text>
<Text wrap="wrap">
<Text color="success">
{"✓ "}
</Text>
<Text dimColor>
{d2}
</Text>
</Text>
<Text wrap="wrap">
<Text color="success">
{"✓ "}
</Text>
<Text dimColor>
{d3}
</Text>
</Text>
</Box>
<Button plain label={`▸ ${title} ${length}`} dimColor />
<Box flexDirection="column" marginBottom={0}>
<Text wrap="wrap" dimColor>
{decisionText}
</Text>
<Text wrap="wrap" dimColor>
{decisionText2}
</Text>
<Text wrap="wrap" dimColor>
{decisionText3}
</Text>
</Box>
</Box>
</Box>
</Box>
<Box backgroundColor="userMessageBackground" paddingX={1}>
<Box flexDirection="row" justifyContent="space-between" columnGap={2} flexGrow={1}>
<Box flexShrink={0}>
<Box flexDirection="row" flexWrap="wrap" columnGap={2}>
<Button plain />
<Button plain />
<Button plain />
</Box>
</Box>
<Box flexDirection="row" columnGap={2} flexShrink={1}>
<Text dimColor wrap="truncate-start">
{status}
</Text>
<Text color="error">
update failed, retries after the next reply
</Text>
</Box>
</Box>
</Box>
</Box>
)
})
on('session.start', async ($, e, next) => {
const name = '…'
const stderr = '…'
await $.ui.toast(`${name} is not there anymore`)
await $.ui.toast(`Could not open ${name}: ${stderr}`)
return next(e)
})
}
Mod 自身のコード
Mod のライセンス(MIT)に従って載せています。全文は下にあります。写すときは著作権表示を残してください。
mods/session-inbox/hooks/register.tsx 979〜1138 行 · バンド
on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
if (!isOn || e.props.hasSurvey) return next(e)
const { Box, Button, Text } = $.ui.resolve(e)
const [ledger, presence, prev, prs, now] = await Promise.all([
readLedger($),
read($, PRESENCE),
read($, PREVIOUS),
read($, PR_VIEWS),
$.clock.now(),
])
const isWorking = e.props.isWorking
if (prev && ledger.turn === 0) {
const c = prev.ledger.card
const waiting = prev.ledger.items.length
return (
<Box flexDirection="column">
<Text bold>
Last session in this folder <Text dimColor>· {ago(now - prev.savedAt)}</Text>
</Text>
{c && <Text wrap="truncate-end"> Goal {c.goal}</Text>}
{c?.now && <Text wrap="truncate-end" dimColor> Now {c.now}</Text>}
{waiting > 0 && (
<Text wrap="truncate-end" dimColor>
{' '}
{waiting} waiting on you: {prev.ledger.items.slice(0, 3).map(i => i.ask).join(' · ')}
</Text>
)}
<Box flexDirection="row" gap={1}>
{prev.isBroughtIn ? (
<Text dimColor> Added to your next message.</Text>
) : (
<Button
key="bring"
label="Continue from it"
variant="primary"
onPress={() => update($, PREVIOUS, p => (p ? { ...p, isBroughtIn: true } : p))}
/>
)}
<Button key="hide-prev" label="Hide" onPress={() => update($, PREVIOUS, () => null)} />
</Box>
</Box>
)
}
const card = ledger.card
if (!card && ledger.items.length === 0 && ledger.notes.length === 0) return next(e)
const batch = latestBatch(ledger)
const older = olderItems(ledger)
// Numbers only map back to items while no prompt has been sent since the
// reply that asked them; answerNote applies the same rule.
const numbered = ledger.batchTurn === ledger.turn ? batch : []
const goal = card?.goal || 'This session'
const waiting = ledger.items.length
const noteCount = ledger.notes.length
const prAlert = prAttention(Object.values(prs.views))
// What else in /inbox wants attention, appended to the band's first line.
const hints = [
noteCount > 0 ? <Text color={NOTES}> · {noteCount === 1 ? '1 note' : `${noteCount} notes`} in /inbox</Text> : null,
prAlert ? <Text color={PRS}> · {prAlert}</Text> : null,
]
if (isWorking) {
return (
<Text wrap="truncate-end">
<Text color={ACCENT}>◆ </Text>
<Text dimColor>{goal}</Text>
{waiting > 0 ? <Text color={WAITING}> · {waiting} waiting on you</Text> : null}
</Text>
)
}
const isReturn = presence.isAway && card !== null
const shown = (isReturn ? [...older.slice(-2), ...batch] : batch).slice(-6)
const hidden = waiting - shown.length
const olderRows = hidden > 0 ? [<Text dimColor> +{hidden} older in /inbox</Text>] : []
const fit = (rows: JSX.Element[]) => <Box flexDirection="column">{rows.slice(0, Math.max(1, e.props.maxRows))}</Box>
const itemRow = (item: Item) => {
const handle = marker(item, numbered)
const isInline = fitsInline(item)
return (
<Box flexDirection="row">
<Box width={4} flexShrink={0}>
<Text bold color={WAITING}>
{handle}
</Text>
</Box>
<Box flexShrink={1}>
<Text wrap="truncate-end">
{item.ask}
{!isInline && item.rec ? <Text dimColor> recommended: </Text> : null}
{!isInline && item.rec ? <Text color={RECOMMENDED}>{item.rec}</Text> : null}
</Text>
</Box>
{isInline ? (
<Box flexDirection="row" flexShrink={0} gap={1} marginLeft={2}>
{bandActions($, item).map(a => (
<Button {...a} />
))}
</Box>
) : null}
</Box>
)
}
const openRows = (card?.running ?? []).slice(0, 3).map(run => (
<Text wrap="truncate-end">
<Text color={DONE}> ● </Text>
<Text dimColor>{run}</Text>
</Text>
))
if (isReturn && card) {
const rows = [
<Text wrap="truncate-end">
<Text color={ACCENT}>◆ </Text>
<Text bold>{card.goal}</Text>
<Text dimColor> · last active {ago(now - presence.lastActiveAt)}</Text>
{hints}
</Text>,
...(card.done.length > 0
? [
<Text wrap="truncate-end">
<Text color={DONE}> ✓ </Text>
<Text dimColor>{card.done.slice(-3).join(' · ')}</Text>
</Text>,
]
: []),
<Text wrap="truncate-end">
<Text dimColor> → </Text>
{card.now}
</Text>,
...openRows,
...(ledger.decided.length > 0
? [
<Text wrap="truncate-end" dimColor>
{' Decided: '}
{ledger.decided
.slice(-2)
.map(decisionText)
.join(' · ')}
</Text>,
]
: []),
...(shown.length > 0
? [
<Text bold color={WAITING}>
Waiting on you
</Text>,
...shown.map(itemRow),
]
: []),
...olderRows,
]
return fit(rows)
}
mods/session-inbox/hooks/register.tsx 1180〜1339 行 · ペイン
on('ui.render', { component: 'Pane', requestId: PANE }, async ($, e) => {
const { Box, Button, Link, Markdown, Text } = $.ui.resolve(e)
const [ledger, presence, tab, prState, collapsed, selection, now, isDark] = await Promise.all([
readLedger($),
read($, PRESENCE),
read($, TAB),
read($, PR_VIEWS),
read($, COLLAPSED),
read($, SELECTION),
$.clock.now(),
read($, IS_DARK_THEME),
])
const card = ledger.card
const numbered = ledger.batchTurn === ledger.turn ? latestBatch(ledger) : []
const prViews = Object.values(prState.views)
const isFocused = e.props.isFocused
const color = TAB_COLORS[tab]
// One list row's content. Selected, a row shows its context line, its title
// in full, its body and its keys; otherwise one line: `line`, or the title.
type Row = {
id: string
handle: string
meta: JSX.Element
title: string
line?: JSX.Element
body?: JSX.Element | null
keys: () => KeyAction[]
}
const itemRow = (item: Item): Row => {
const handle = marker(item, numbered)
const rec = item.rec && item.kind !== 'do' ? item.rec : null
return {
id: item.id,
handle,
meta: (
<Text color={WAITING} bold>
{item.kind === 'do' ? 'Your task' : 'Question'}
</Text>
),
title: item.ask,
body: rec ? (
<Text wrap="wrap">
<Text dimColor>Recommended: </Text>
<Text bold>{rec}</Text>
</Text>
) : null,
keys: () => itemKeys($, item, handle),
}
}
const noteRow = (note: Note): Row => ({
id: note.id,
handle: '•',
meta: (
<Text wrap="truncate-end">
<Text color={NOTES} bold>
{noteKindLabel(note)}
</Text>
<Text dimColor>
{' · '}
{ago(now - note.at)}
{note.path ? ` · ${baseName(note.path)}` : ''}
</Text>
</Text>
),
title: note.title,
line: (
<Text wrap="truncate-end">
{note.title}
<Text dimColor> · {ago(now - note.at)}</Text>
</Text>
),
body: <Text wrap="wrap">{note.detail}</Text>,
keys: () => [
{ key: `address-${note.id}`, label: 'Address it', hotkey: 'a', onPress: () => void actOnNote($, note, 'address') },
{ key: `discuss-${note.id}`, label: 'Discuss', hotkey: 'd', onPress: () => void actOnNote($, note, 'discuss') },
{ key: `drop-${note.id}`, label: 'Dismiss', hotkey: 'x', onPress: () => void removeNote($, note.id) },
],
})
const checkRow = (pr: PrView, c: PrCheck): Row => ({
id: `${pr.ref} check ${c.name}`,
handle: '✗',
meta: (
<Text color="error" bold>
Failing check
</Text>
),
title: c.name,
line: (
<Text wrap="truncate-end">
<Text color="error">{c.name}</Text>
<Text dimColor> · failing check</Text>
</Text>
),
keys: () => [
{ key: `fix-${pr.ref}-${c.name}`, label: 'Fix', hotkey: 'f', onPress: () => void send($, prompts.fix(pr, c)) },
{ key: `log-${pr.ref}-${c.name}`, label: 'Open log', hotkey: 'o', onPress: () => void openUrl($, c.url ?? pr.url) },
],
})
const threadRow = (pr: PrView, t: PrThread): Row => {
const latest = t.reply ?? { author: t.author, body: t.body }
return {
id: `${pr.ref} thread ${t.id}`,
handle: '◦',
meta: (
<Text wrap="truncate-end">
<Text color={PRS} bold>
Review thread
</Text>
<Text dimColor>
{t.replies > 0 ? ` · ${t.replies + 1} comments` : ''}
{t.isOutdated ? ' · outdated' : ''}
</Text>
</Text>
),
title: threadWhere(t),
line: (
<Text wrap="truncate-end">
<Text dimColor>{threadWhere(t, baseName(t.path))} </Text>
{latest.body.replace(/\s+/g, ' ')}
</Text>
),
body: (
<Box flexDirection="column">
{t.reply ? <Markdown dimColor text={`@${t.author}: ${clipLabel(t.body, 200)}`} /> : null}
<Markdown text={`**@${latest.author}:** ${clipLabel(latest.body, 1200)}`} />
</Box>
),
keys: () => [
{ key: `address-${t.id}`, label: 'Address', hotkey: 'a', onPress: () => void send($, prompts.address(pr, [t])) },
{ key: `draft-${t.id}`, label: 'Draft reply', hotkey: 'r', onPress: () => void send($, prompts.draft(pr, t)) },
{ key: `discuss-${t.id}`, label: 'Discuss', hotkey: 'd', onPress: () => void send($, prompts.discuss(pr, t)) },
{ key: `open-${t.id}`, label: 'Open', hotkey: 'o', onPress: () => void openUrl($, t.reply?.url || t.url || pr.url) },
],
}
}
// Each tab's rows in order: the cursor, the counts and the drawing all read these.
const prGroups = prViews.map(pr => ({ pr, rows: [...failingChecks(pr).map(c => checkRow(pr, c)), ...waitingThreads(pr).map(t => threadRow(pr, t))] }))
const rows: Record<Tab, Row[]> = {
waiting: ledger.items.map(itemRow),
notes: [...ledger.notes].reverse().map(noteRow),
prs: prGroups.flatMap(g => g.rows),
}
const ids = rows[tab].map(r => r.id)
const indexOf = new Map(ids.map((id, n) => [id, n]))
const at = selectedIndex(ids, selection[tab])
// Wide enough for the longest handle, such as "you" on a task.
const handleWidth = 3 + Math.max(1, ...rows[tab].map(r => r.handle.length))
const keyRow = (keys: KeyAction[]) => (
<Box flexDirection="row" flexWrap="wrap" columnGap={2}>
{keys.map(k => (
<Button plain {...k} />
))}
</Box>
)
// The selected row gets a bar in the tab's color and a tinted background,ライセンスの全文(MIT)
MIT License Copyright (c) 2024 Pete Petrash 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 に読んだコミット 23e2b4fe4455 のソースから。最初のまとまりが載せる条件で、残りは自分で判断するための材料です。後のコミットは、次に読むまで見ていません。
| 載せる条件: 確かめやすいコード | |
|---|---|
| 入口を読んだ | hooks/hooks.json が名指すモジュールをすべて読んだ。mods/session-inbox/hooks/register.tsx |
| 解析できる | すべてのファイルが TypeScript か JavaScript として解析できる。3 ファイルを解析 |
| コードが 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/… などは無い)。mods/session-inbox/hooks/register.tsx:381 open(Windows にない); mods/session-inbox/hooks/register.tsx:614 open(Windows にない) |
| 通信 | fetch の送り先(https のホスト)がコードに書いてあるか。通信なし |
| プログラム | 起動するプログラムの名前がコードに書いてあり、シェル・インタプリタ・通信用の道具でないか。mods/session-inbox/hooks/register.tsx:379 実行時に決まるプログラム |
| 読んで送る | ファイルや環境変数を読み、かつ通信するか。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 .)、触るものを見て、読んだコミットを入れてください。
リポジトリの .claude-plugin/marketplace.json にこの Mod が載っていないため、入れる手順は出せません。コードとして読むか、作者の README に従ってください。
Claude に聞く
modscode のコネクタを入れると、Claude がこのデザイン・コードが触るもの・コードを読んで、それをもとに作れます。たとえば:
modscode のデザイン「petekp-session-inbox」をコードごと読んで、同じようなペインを作って似たデザイン
-
Claude に頼む…Fix loginRemoveCopy markdownacme/app · mainCopy linkCopy markdownbuild2h 10mbuild2h 10mbuild2h 10mHosted on uploads.sh, not committed to the repo.They will appear in a comment on the pull request once opened.
-
Claude に頼む…a1b2c3dFix loginok · merge ok (Bash) · Bashopen in browser copy URL stop watchingRequired checks (3)●build (optional)●build (optional)+ 3 optional checks · updated 2h 10m · refresh failed: Bash●build (optional)
-
✦ explain as pick how Claude answers×3 ● build3 ● build3 ● build▸ VideoClaude に頼む…
-
何をするか
- プロンプトの上の帯・欄を描く
- ツールの呼び出しを見張る(止めることがある)
- config.describe・session.start・turn.complete・ui.closeにフックする
- ターンをまたいで自分の状態を持つ
-
Claude に頼む…CIcross Bash · Classicmain · a1b2c3d · failed at 14:32Open the run on GitHubFix it fClose x
(no log available)
-
Claude に頼む…GitHub inboxGitHubloading…Refresh rbuildbuildbuildClose xStealth IssuesNo open issues in this view.#3 Fix login · Pinned notice · 2h 10m · Top row commentsWork on itopen#3 Fix login · Pinned notice · 2h 10m · Top row commentsWork on itopen#3 Fix login · Pinned notice · 2h 10m · Top row commentsWork on itopenPull requestsNo open pull requests.#3 Fix login · main · draft · build · HiddenChecksReviewopen#3 Fix login · main · draft · build · HiddenChecksReviewopen#3 Fix login · main · draft · build · HiddenChecksReviewopenChecks for #3Plain