Resources for MATS fellows

Resources for MATS (ML Alignment Theory Scholars) fellows using Claude Code.
Literature review (/mats:lit-review) — Staged literature review pipeline. Searches arXiv, Semantic Scholar, and Google Scholar; collects LessWrong and Alignment Forum posts. Downloads papers, converts to markdown, generates summaries with relevance scoring, and produces a final report. Resumable if interrupted. Works for any research topic, not just AI safety.
hooks/register.tsx 62 lines1// mats as a mod: scripts/check.sh's install row in the band above the prompt, checked at startup
2// and /clear. Left to the hive plugin when that is enabled, since hive draws the same row.
3import { atom, read, update } from 'claude-code'
4import type { EngineInterface, Register } from 'claude-code'
5
6import { noticeRows } from './notice-band'
7import type { Notice, NoticeAction } from './notice-band'
8
9const PLUGIN = 'mats'
10const notices = atom({ plugin: 'mats', key: 'notices' } as const, [] as Notice[])
11const dismissed = atom({ plugin: 'mats', key: 'dismissed' } as const, [] as string[])
12
13/** Runs the plugin's session-start check and keeps its rows; none when it fails. */
14async function check($: EngineInterface, projectDir: string): Promise<void> {
15 try {
16 // The hive plugin draws the same install row, so mats leaves it to hive. No API lists
17 // plugins; the hive plugin's commands are its mark.
18 if ((await $.command.list()).some(command => command.name.startsWith('hive:'))) return
19 const { exitCode, stdout } = await $.process.run(['bash', `${$.plugin.root}/scripts/check.sh`], {
20 env: { CLAUDE_PLUGIN_ROOT: $.plugin.root, CLAUDE_PROJECT_DIR: projectDir },
21 })
22 const found = exitCode === 0 && stdout.trim() ? (JSON.parse(stdout) as { notices: Notice[] }).notices : []
23 await update($, notices, () => found)
24 } catch {
25 // A check that fails shows nothing rather than a wrong row.
26 }
27}
28
29export const register: Register = on => {
30 // The SessionStart hook's lifecycle: startup and /clear, awaited.
31 on('classic.SessionStart', async ($, e, next) => {
32 if (e.source === 'startup' || e.source === 'clear') await check($, e.cwd)
33 return next(e)
34 })
35
36 on('ui.render', { component: 'AbovePrompt' }, async ($, e, next) => {
37 const [below, found, hidden] = await Promise.all([next(e), read($, notices), read($, dismissed)])
38 if (e.props.hasSurvey) return below
39
40 const rows = (found as Notice[]).filter(notice => !hidden.includes(notice.id))
41 if (rows.length === 0) return below
42
43 const onAction = async (_notice: Notice, action: NoticeAction) => {
44 // The install script asks questions, so it runs in a terminal of the person's own.
45 if (action.kind !== 'copy' || !action.command) return
46 const copied = await $.ui.copy({ text: action.command, surface: e.surface })
47 $.ui.toast(copied.isCopied ? 'Copied: paste it into a terminal' : `Run in a terminal: ${action.command}`)
48 }
49 const onDismiss = (notice: Notice) => update($, dismissed, list => [...list, notice.id])
50
51 const ui = $.ui.resolve(e)
52 const drawn = noticeRows(ui, PLUGIN, rows, { onAction, onDismiss })
53
54 return (
55 <ui.Box flexDirection="column">
56 {drawn}
57 {below}
58 </ui.Box>
59 )
60 })
61}
62hooks/notice-band.tsx 92 lines1// One plugin's rows in the band above the prompt, drawn without `$`: each
2// plugin's own `ui.render` hook reads its state and stacks this over what the
3// plugins beneath drew, so third-party plugins on the band keep working.
4//
5// A plugin cannot import another's files, so each plugin that shows notices
6// carries this file; plugins/notice-band.test.ts keeps the copies identical.
7// The `notices` its check prints are this file's `Notice` as JSON.
8import type { EngineInterface, RenderElement } from 'claude-code'
9
10export type Severity = 'urgent' | 'problem' | 'action' | 'info'
11
12export type NoticeAction = {
13 id: string
14 label: string
15 // command: a slash command; copy: `command` goes on the clipboard, for a
16 // terminal command that is interactive; plugin: the plugin's own handler decides.
17 kind: 'command' | 'copy' | 'plugin'
18 command?: string
19}
20
21export type Notice = {
22 id: string
23 severity: Severity
24 // The whole message: rows wrap rather than hide what the person needs to act.
25 text: string
26 actions?: NoticeAction[]
27 // Set on "updated" notices: a dismissal holds until the plugin's next
28 // version. Without it, a dismissal holds for this session only.
29 version?: string
30 // What a pressed button is doing ("restarting…"): drawn after the text in
31 // place of the buttons, so the row never looks inert. Set by the plugin.
32 busy?: string
33}
34
35export type NoticeHandlers = {
36 onAction: (notice: Notice, action: NoticeAction) => unknown
37 onDismiss: (notice: Notice) => unknown
38}
39
40const MARK: Record<Severity, { rank: number; glyph: string; color: string }> = {
41 urgent: { rank: 0, glyph: '✖', color: 'error' },
42 problem: { rank: 1, glyph: '!', color: 'warning' },
43 action: { rank: 2, glyph: '›', color: 'suggestion' },
44 info: { rank: 3, glyph: '↑', color: 'ide' },
45}
46
47/** Draws `notices` as band rows, most severe first, each keyed and labeled by `plugin`. */
48export function noticeRows(
49 ui: ReturnType<EngineInterface['ui']['resolve']>,
50 plugin: string,
51 notices: Notice[],
52 { onAction, onDismiss }: NoticeHandlers,
53): RenderElement[] {
54 const { Box, Button, Text } = ui
55
56 return [...notices]
57 .sort((a, b) => MARK[a.severity].rank - MARK[b.severity].rank)
58 .map(notice => {
59 const mark = MARK[notice.severity]
60 const key = `${plugin}:${notice.id}`
61
62 const buttons = (notice.busy ? [] : (notice.actions ?? [])).map((action, index) => (
63 <Button
64 key={`${key}:${action.id}`}
65 label={action.label}
66 variant={index === 0 ? 'primary' : 'secondary'}
67 onPress={() => onAction(notice, action)}
68 />
69 ))
70 // An info row is a state, not a request: the band's own collapse hides it.
71 if (notice.severity !== 'info' && !notice.busy) {
72 buttons.push(<Button key={`${key}:dismiss`} label="Dismiss" dimColor onPress={() => onDismiss(notice)} />)
73 }
74
75 // The buttons wrap under the text where the row does not fit.
76 return (
77 <Box key={key} flexDirection="row" flexWrap="wrap" justifyContent="space-between" columnGap={2}>
78 <Text>
79 <Text color={mark.color} weight="semibold">
80 {mark.glyph}{' '}
81 </Text>
82 <Text weight="semibold">{plugin}</Text> {notice.busy ? `${notice.text} · ${notice.busy}` : notice.text}
83 </Text>
84 {/* Grows to fill its line, so the buttons stay right-aligned when they wrap. */}
85 <Box flexDirection="row" flexGrow={1} justifyContent="flex-end" columnGap={1}>
86 {buttons}
87 </Box>
88 </Box>
89 )
90 })
91}
92types/index.d.ts 7 lines1declare module 'claude-code' {
2 interface PluginState {
3 // `notices`: the check's rows, hooks/notice-band.tsx's Notice as parsed JSON.
4 mats: { notices: unknown[]; dismissed: string[] }
5 }
6}
7