Domaine frontend team plugin for Claude Code: the Shopify theme skills (ship, preview theme, steps to test, TA, breaking changes, translations, PR), the…

fe is the Domaine frontend team plugin for Claude Code. It holds the Shopify theme work. Its skills take a ticket from a Technical Approach (TA) to a pull request and a preview theme. To install it, see Quick install (Claude Code) or § Install below.
fe also holds these parts:
fe:theme-explorer scout and the fe:stt-drafter / fe:pr-body-drafter drafters;fe builds on base and requires it. base supplies the Jira, Figma and doc readers, the Jira writer, the review agents, the task workspace, the commit and review skills, the guards and the shared MCP servers (plugins/base/README.md). base requires slim, so fe runs with slim too.
Current release: fe v0.11.4.
scripts/install.sh --plugin fe exits 2."dependencies": ["base"] in its manifest), and slim through base. The engine does not install a dependency by itself, so install all three./plugin marketplace add domaine-oleksandr-kever/claude-plugins
/plugin install slim@domaine
/plugin install band@domaine
/plugin install base@domaine
/plugin install fe@domaine
/reload-plugins
Then run /base-doctor and /fe-doctor to check the install (§ Doctor). To enable the same set through settings, add this to ~/.claude/settings.json:
{
"enabledPlugins": {
"slim@domaine": true,
"band@domaine": true,
"base@domaine": true,
"fe@domaine": true
}
}
The team plugins fe, qa, be and pm co-install. Each needs only base, and none needs another.
Call the skills by their qualified names (/fe:<skill>). They hand off to base's skills and agents by base's qualified names (/base:commit, /base:pre-commit-review, base:jira-reader, …). A hand-off is an offer at the end of the run, never an automatic start. Only /fe:ship runs the series by itself.
| Skill | Does | Uses / hands off to |
|---|---|---|
/fe:ship | a ready ticket end to end: one interview, one plan and QA-checklist approval, then the series runs itself (implement, QA, review and commit, PR, Steps to Test) | base:jira-reader, base:figma-reader, base:doc-reader, fe:theme-explorer; offers /base:worktree before it starts; a missing TA → /fe:write-technical-approach |
/fe:write-technical-approach | drafts a Technical Approach from the ticket's Description and Acceptance Criteria, then writes the field after approval | base:jira-reader, base:doc-reader, base:jira-writer → /fe:develop-feature-or-fix |
/fe:develop-feature-or-fix | implements an approved Technical Approach with in-browser validation on the work stream's preview theme | base:jira-reader, base:figma-reader, base:doc-reader, fe:theme-explorer, base:bug-hunter, scripts/create-preview-theme.sh → /fe:qa-feature-or-fix |
/fe:qa-feature-or-fix | structured QA of a finished change against its ticket: checklist, browser checks, pass / fail report | base:jira-reader, base:figma-reader, base:jira-writer, scripts/create-preview-theme.sh → /base:pre-commit-review (with the profile word) once every blocking check passes |
/fe:write-steps-to-test | Steps to Test in Domaine's format, written to the field after approval; the series' last step | base:jira-reader, base:doc-reader, fe:stt-drafter, scripts/drafter-check.cjs, base:jira-writer → /fe:create-pull-request when the branch has no PR |
/fe:create-pull-request | a pull request with the Domaine description: a plain-English Summary, the theme-preview table, To check steps and screenshot placeholders | base:jira-reader, base:change-reviewer, base:bug-hunter, /fe:preview-theme's script, fe:pr-body-drafter, scripts/drafter-check.cjs → /fe:write-steps-to-test while the field is empty |
/fe:preview-theme | creates or refreshes an unpublished preview theme from the branch; in a new worktree, un-pins the copied store config first | scripts/create-preview-theme.sh, scripts/worktree-theme.sh |
/fe:preflight-checks | checks the project, the tools and the dev server before work starts | → /fe:write-technical-approach or /fe:develop-feature-or-fix |
/fe:fix-accessibility-issue | fixes an accessibility issue in theme components | → /base:commit |
/fe:get-breaking-changes | lists the breaking changes merged since the last major version in breaking-changes.md | → /fe:fix-breaking-changes |
/fe:fix-breaking-changes | applies the documented breaking changes to templates and settings data | its bundled script template; reads /fe:get-breaking-changes's report |
/fe:update-translations | translates storefront and schema strings into the theme's other languages | the project's own update-translations.js (fe ships none) |
fe's progress-series section (§ Conventions) lists the progress rows that these skills tick in a ticket's progress.md.
A worktree: fe sets up a worktree in two steps. /fe:ship offers the same two steps before it starts.
/base:worktree makes the checkout, copies .env and shopify.theme.toml (fe's worktree copy list: line) and records a dev port./fe:preview-theme in the worktree runs scripts/worktree-theme.sh. The script un-pins the copied config once, because a worktree never inherits the main checkout's session theme. Then it prints the dev-server line with that port.On the main checkout the script answers error=not_a_linked_worktree, and the skill continues without it.
| Agent | Does |
|---|---|
fe:theme-explorer | read-only scout of the theme: which files, sections and snippets a change touches; the profile comes in its brief |
fe:stt-drafter | drafts Steps to Test into the workspace steps-to-test.md (sonnet); returns ESCALATE / LOOKUP, an answer, or the path + an unconfirmed list, never the text |
fe:pr-body-drafter | drafts the PR title and body into the workspace pr-body.md, and after the PR exists the Jira PR-link comment into jira-comment.md (PR: <url> — <title>, a short brief only on request, never a preview link) (haiku); returns ESCALATE, an answer, or the path, title, Summary and an unconfirmed list |
The skills and the agents cite fe's own files by their path under fe's root (<fe root>/…, from the session's fe plugin root: line). They cite base's files by their path under base's root (<base root>/…). tests/team-refs-lint.sh checks that every cited path exists.
| Reference | Read by | Holds |
|---|---|---|
references/session-theme.md | /fe:ship, /fe:preview-theme, /fe:create-pull-request, /fe:develop-feature-or-fix, /fe:qa-feature-or-fix | one preview theme per work stream: the gate, the pin into shopify.theme.toml, the worktree un-pin |
references/preview-theme-errors.md | /fe:preview-theme, /fe:create-pull-request, /fe:develop-feature-or-fix, /fe:qa-feature-or-fix, /fe:ship, fe:pr-body-drafter | how to read a create-preview-theme.sh run (its workspace lines and warnings), one entry per error= key, Shopify rejections and page deep-links |
references/theme-gotchas.md | /fe:develop-feature-or-fix, /fe:preview-theme | Shopify theme traps that fail silently: dropped settings, presets, Liquid limits, cascade layers, browser checks; preview-theme recipes (templates-only push, stale hashed CSS, Playwright setContent) |
references/technical-approach-format.md | /fe:write-technical-approach | the short TA format |
references/research-pressure-test.md | /fe:write-technical-approach, /fe:develop-feature-or-fix, /fe:ship | cross-checking a draft plan against fresh external sources |
references/metafield-metaobject-setup.md | /fe:develop-feature-or-fix, /fe:qa-feature-or-fix, /fe:write-technical-approach, /fe:ship | inspecting, creating, mocking and binding store metafields and metaobjects |
references/store-auth-troubleshooting.md | through metafield-metaobject-setup.md | when shopify store auth fails, and the re-auth blurb |
references/theme-customizer-state.md | /fe:develop-feature-or-fix, /fe:qa-feature-or-fix, /fe:write-technical-approach | reading and driving the theme editor's state through theme JSON |
references/customizer-sandbox.md | through theme-customizer-state.md | a disposable theme for a walk that would thrash the shared dev theme |
references/preflight-checklist.md | /fe:preflight-checks, /fe:develop-feature-or-fix, /fe:qa-feature-or-fix | the environment checklist |
references/pipeline-mode.md, references/pipeline-phases.md | /fe:ship | the run contract and the phase briefs |
references/eslint-no-restricted-syntax.md | /fe:develop-feature-or-fix, /fe:fix-accessibility-issue, /fe:ship | Foundation only: state through data-* attributes, not classList / style.* |
references/section-css-variables-pattern.md | /fe:develop-feature-or-fix, /fe:ship | Foundation only: a section that drives its blocks' sizes through CSS variables |
references/drafter-loop.md | /fe:write-steps-to-test, /fe:create-pull-request | the drafter loop: spawn, receipt check, ESCALATE / LOOKUP relay, SendMessage continuation, ask / revise, caps, the never-read rule, the re-spawn fallback |
| Script | Run by | Does | ||||
|---|---|---|---|---|---|---|
scripts/create-preview-theme.sh | /fe:preview-theme, /fe:create-pull-request, /fe:develop-feature-or-fix, /fe:qa-feature-or-fix, /fe:ship | builds and pushes an unpublished preview theme (create), re-pushes one (refresh), pins the session theme (pin). `create --duplicate-of <theme-id\ | name> --store <store> copies a theme on that store server-side, waits until theme list shows the copy ready, then pushes the branch code into it; --brand <b> (create, refresh) exports BRAND=<b>` to the build and does nothing else | |||
scripts/session-theme.sh | sourced by create-preview-theme.sh, run by worktree-theme.sh | the pin and un-pin grammar of shopify.theme.toml (# fe:session-theme, # fe:superseded) | ||||
scripts/worktree-theme.sh | /fe:preview-theme in a worktree, /fe:ship | the Shopify half of a new worktree: the one-time un-pin and the dev-server line | ||||
scripts/theme-json.sh | the skills, through the store-access section | reads and writes a theme's JSON files (templates/*.json, config/settings_data.json) with a read-back check; locate <id> finds which store holds a theme (the stores in <base root>/scripts/qa-stores.cjs plus every store the toml's [environments.*] blocks name, or --stores a,b, or --store <one>) | ||||
scripts/shopify-admin-gql.sh | the skills, through the store-access section | one Admin GraphQL call against the project's store | ||||
scripts/project-profile.sh | fe's hooks module, worktree-theme.sh, the doctor, the skills' fallback | prints foundation, theme or none | ||||
scripts/doctor.cjs | /fe-doctor, or by hand | the static install checks (§ Doctor) | ||||
scripts/drafter-check.cjs | fe:stt-drafter, fe:pr-body-drafter, /fe:write-steps-to-test, /fe:create-pull-request | checks a drafter's file (`file stt\ | pr\ | jira: structure, the PR core skeleton, the Theme preview table by default — --no-preview honored only when the workspace notes.md records preview-decision: no preview, Summary sentence lengths, the Jira comment's PR line and brief size with no preview link, theme id or editor URL, no AI attribution) and its reply (receipt stt\ | pr\ | jira: one kind, no empty field) in code, printing counts and fail` lines only — never the draft |
scripts/_shopify-common.sh | sourced by the store scripts | the shared Shopify CLI and config helpers |
/fe:fix-breaking-changes copies its own skills/fix-breaking-changes/scripts/fix-breaking-changes.template.js into the project and removes the copy after the run. theme-json.sh locate reads the QA store registry's store list (<base root>/scripts/qa-stores.cjs list --json, never a password) from base's install beside fe.
fe's sections reach the model through one channel on every login: a Claude Code command hook, node hooks/conventions.cjs start, on SessionStart with the matcher startup|clear|compact (hooks/hooks.json, beside the hooks module). A resume or a fork keeps the copy the transcript already holds. The context arrives with the first user message, after CLAUDE.md, in the order below. The text lives in one file, hooks/conventions-text.json; the hook fills in the roots. The envelope stays well under the host's ~10,000-character inline limit (a larger one is spilled to a file).
The hook writes a marker, <log dir>/<session-id>/conventions.fe.json: via, event, source, the sections it sent, chars, the login (work, personal or unknown, read from the login file; doctor evidence only) and the profile it decided. /base-doctor's conventions row reads it. Where the log folder is missing or not writable, the marker goes to the spare folder <TMPDIR or /tmp>/domaine-log/<session-id>/.
| Name | Holds | When | ||
|---|---|---|---|---|
root | fe plugin root: <path>, the directory fe's scripts and references start from; the same line defines <fe root> and <base root> (the base plugin root: path) for every fe skill, agent and reference, and says to spell both out in commands since ${CLAUDE_PLUGIN_ROOT} is empty in the Bash tool's shell | always | ||
profile | `fe project profile: <foundation\ | theme\ | none>` | always |
comment-discipline-foundation | LiquidDoc on every snippet param; src/entry/core/* is protected; the Liquid core is hand-synced from the foundation repo, so prefer a copy | profile foundation | ||
store-access | the two store runners, scripts/shopify-admin-gql.sh and scripts/theme-json.sh, with their paths under fe's root; never Read .env or shopify.theme.toml | the project root holds shopify.theme.toml, or .env with a profile other than none | ||
worktree | worktree copy list: shopify.theme.toml (the line /base:worktree reads), then /fe:preview-theme in the new worktree | the project root holds shopify.theme.toml | ||
preview-default-on / preview-default-off | fe preview default: preview theme — /fe:develop-feature-or-fix and /fe:qa-feature-or-fix validate on the work stream's preview theme — or fe preview default: local dev server (FE_PREVIEW_DEFAULT=0); the skills key on this line and never read the switch | the project root holds shopify.theme.toml (no preview theme without it) | ||
preview-links | ## fe convention — preview link in every report: a reply that reports a check, validation, repro or refresh on a preview theme opens with Preview: <store>/<page path>?preview_theme_id=<id> (one per page checked), Editor: <editor_url> and Password: when the storefront has one, the values from create-preview-theme.sh's preview_url= / editor_url= or the session-theme: line — the id alone never counts; reaches ad-hoc fixes as well as the skills | the project root holds shopify.theme.toml, either preview default | ||
progress-series | the rows of a ticket's progress.md in order — write-technical-approach, develop-feature-or-fix, qa-feature-or-fix, pre-commit-review, commit, create-pull-request, write-steps-to-test — and the skill that ticks each; a batch lists its tickets, then the same tail | a profile other than none, or shopify.theme.toml at the root |
The profile is decided by the start hook, once per session start; a /clear decides again. fe takes the first answer in this order:
FE_PROFILE, when it holds one of the three words.scripts/project-profile.sh on the project root. The script also reads FE_PROFILE from .claude/domaine.env or ~/.config/domaine/env.snippets/@*.liquid, sections/core-*.liquid, blocks/core-*.liquid or src/entry/core/ ⇒ foundation; layout/theme.liquid ⇒ theme; else none.A probe that fails or times out (5 s) gives none and says why in the marker. The hooks module decides the same way once per session id for its own readers (the event log, /fe-doctor) and logs one profile line.
Subagents get fe's share as added context at their start, through a second command hook, node hooks/conventions.cjs subagent on SubagentStart: the main session's context does not reach a subagent. The profile comes from this session's marker; without one the hook decides it. The share depends on the agent type:
base:jira-reader, base:jira-writer, base:figma-reader, base:doc-reader), Claude Code's claude-code-guide and statusline-setup, and a fork (it inherits the transcript) get nothing from fe.fe:theme-explorer, base:change-reviewer, base:bug-hunter, Explore, Plan) get the root, the profile and the Foundation section.fe:stt-drafter, fe:pr-body-drafter) get the root, the profile and store access — they confirm fixture handles on the store — but not the Foundation section: they write prose, not theme code.base required: at a session start fe looks for base's skills in the command list. If they are missing, fe shows one toast and writes one install line: fe: needs the base plugin — claude plugin install base@domaine.
/fe-doctor checks fe's side of the install. It prints one PASS / FAIL / SKIP / WARN row per check, the counts, and the last 10 fe.events lines. /base-doctor checks base's side (slim, the MCP servers).
| Row | Checks |
|---|---|
node | Node 18 or newer |
manifest | the manifest's version, the name fe, base in its dependencies |
scripts | every scripts/*.sh but the sourced _*.sh keeps its exec bit and answers --help (project-profile.sh is probed by the profile row) |
base | base installed (user scope or this project) and enabled — else claude plugin install base@domaine; FAIL when that install lacks <base root>/scripts/review-scope.sh (the PR review gate runs it), skills/shopify/SKILL.md or references/shopify-recipes.md (fe store work points at them) — update base |
shopify-cli | shopify version answers; absent or failing only warns (the store scripts need it, the rest of fe does not) |
profile | the word and how it was decided: FE_PROFILE, project-profile.sh, or a fallback to none (warns); in a session, the one the start hook delivered (its marker), else the hooks module's own decision |
store-config | shopify.theme.toml and .env present at the project root — presence only, never a value; one missing warns; neither in a none project skips |
preview | where develop and qa validate: preview theme, or local dev server (FE_PREVIEW_DEFAULT=0) — decided by the same hooks/conventions.cjs function as the start line |
event-log | this session's fe.jsonl: its line count and newest ts; no file yet passes (a /clear's new session has none before its first line) |
base-live, slim-live | what this session loaded: base's skills, slim's mcp__slim__view tool |
The first nine rows come from scripts/doctor.cjs. You can also run it by hand: node <fe plugin root>/scripts/doctor.cjs [--project <dir>] [--log-dir <dir>]. It exits 1 when a row fails. By hand, its event-log row reads the newest session folder unless --log-dir names one. Each run writes one doctor line to fe.events.
fe writes its lines to $HOME/.claude/domaine/log/<session-id>/fe.jsonl. The file follows the same contract as every Domaine plugin (plugins/base/README.md):
{"ts":"…","plugin":"fe","version":"<fe's version>","session":"<id>","kind":"profile","agent":"main","text":"theme (project-profile.sh)"}.start (fe <version>, first in every session's file, once), install (base is not loaded), profile (the word and how it was decided), doctor (a /fe-doctor run's counts). The same lines fill fe.events (oldest first, at most 200).fe: event log not written: <reason>.FE_EVENT_LOG=0 stops the file and the fe.events lines alike.band's Log pane (/band-log) shows fe's lines beside the lines of the other plugins, with fe in its plugin column.
Every switch fe reads has a row here. Set it in ~/.claude/settings.json → env. The store scripts also read their switches from ~/.config/domaine/env. They read the tuning switches (FE_PROFILE, FE_GQL_PROBE_CACHE, FE_CPT_THROTTLE_WAITS, FE_CPT_OVERLAY_VERIFY_WAIT, FE_THEME_JSON_VERIFY_WAIT, SHOPIFY_ADMIN_GQL_QUIET) from the nearest .claude/domaine.env too. The process environment wins.
| Variable | Default | Effect |
|---|---|---|
FE_PROFILE | detected | foundation, theme or none (spaces around it trimmed) forces the project profile instead of detecting it, in the hooks/conventions.cjs command hook and the hooks module alike; any other value is ignored and the profile is detected |
FE_EVENT_LOG | on | 0 keeps fe.events empty and writes no fe.jsonl |
FE_PREVIEW_DEFAULT | on | 0 turns off the preview-theme default of /fe:develop-feature-or-fix and /fe:qa-feature-or-fix: they validate on the local dev server, which must then be running. Decided once by the hooks/conventions.cjs start hook (its fe preview default: line, toml checkouts only) and shown by the doctor's preview row; read from the process environment, else ~/.config/domaine/env — never from the project .claude/domaine.env |
DOMAINE_LOG_DIR | ~/.claude/domaine/log | Where every Domaine plugin (slim, band, base, fe, qa, be, pm) writes its event log on disk: <dir>/<session-id>/<plugin>.jsonl, one JSON line per event. An absolute directory; the <session-id>/ folder is still made under it. Without it and without HOME (a cloud session) no file is written. The hooks/conventions.cjs command hook writes its marker conventions.fe.json there too. |
CLAUDE_CONFIG_DIR | ~/.claude | read, never set, by scripts/doctor.cjs: the Claude Code config directory whose plugins/installed_plugins.json (else the claude.ai-synced copy under plugins/synced/) and settings.json the base row reads; by the hooks/conventions.cjs command hook: the login file it labels in its marker (<dir>/.claude.json, or ~/.claude.json for the default directory) |
TMPDIR | /tmp | read, never set, by the hooks/conventions.cjs command hook: <dir>/domaine-log/<session-id>/ is the spare folder of the marker where the log folder is missing or not writable |
CLAUDE_PLUGIN_ROOT | set by Claude Code | read, never set, by the hooks/conventions.cjs command hook: fe's root, filled into the root line and the store-access paths (the script's own parent directory when unset) |
FE_GQL_PROBE_CACHE | 21600 | seconds shopify-admin-gql.sh reuses its shopify version probe and its "store execute is unavailable for this store" fact; 0 re-probes on every call (right after a shopify store auth) |
| FE_CPT_THROTTLE_WAITS | 20 60 | pauses, in seconds, between create-preview-theme.sh's push r
hooks/mods/register.ts 12 lines1// fe hooks module (Claude Code only): the frontend team's conventions, project profile, store access and doctor
2// beside base. fe writes only fe.* atoms. Each feature file declares its own atoms and keeps its `$` code to
3// itself: the validator follows `$` only within one file.
4import type { Register } from 'claude-code'
5import { registerDoctor } from './doctor.ts'
6import { registerSession } from './session.ts'
7
8export const register: Register = (on) => {
9 registerSession(on)
10 registerDoctor(on)
11}
12hooks/mods/doctor.ts 203 lines1// /fe-doctor: runs scripts/doctor.cjs for what a node process sees and adds what only a session answers —
2// base loaded, slim's view tool registered, the profile this session delivered — then the tail of fe.events.
3import { atom, read, update } from 'claude-code'
4import type { EngineInterface, On } from 'claude-code'
5import type { FeEvent, FeProfileInfo } from '../../types'
6import { logDir, logLine, pushEvent } from './events.ts'
7import type { Disk } from './events.ts'
8import { BASE_MISSING, isProfile, profileText } from './session.ts'
9
10export const COMMAND = {
11 name: 'fe-doctor',
12 description: 'Check the fe install: node, manifest, scripts, base, slim, Shopify CLI, profile, store config, event log',
13 immediate: true,
14} as const
15export const SLIM_VIEW = 'mcp__slim__view'
16const TAIL = 10
17
18type Status = 'PASS' | 'FAIL' | 'SKIP' | 'WARN'
19export type Row = { status: Status; name: string; detail: string }
20
21const armed = atom({ plugin: 'fe', key: 'armed' } as const, null)
22const events = atom({ plugin: 'fe', key: 'events' } as const, [] as FeEvent[])
23const profile = atom({ plugin: 'fe', key: 'profile' } as const, null)
24
25type $ = EngineInterface
26
27/** events.ts's file writer reaches `$` through this: the validator follows `$` only within one file. */
28function diskOf($: $): Disk {
29 return {
30 session: () => $.session.id(),
31 home: () => $.env.get('HOME'),
32 override: () => $.env.get('DOMAINE_LOG_DIR'),
33 manifest: () => $.fs.read(`${$.plugin.root}/.claude-plugin/plugin.json`),
34 read: path => $.fs.read(path),
35 write: (path, text) => $.fs.write(path, text),
36 toast: text => $.ui.toast(text),
37 }
38}
39
40/** The command on every session start (a reload or a re-enable drops it) and at the first prompt of a new session id. */
41async function arm($: $, start: boolean): Promise<void> {
42 try {
43 const sid = String(await $.session.id())
44 const fresh = (await read($, armed)) !== sid
45 if (!start && !fresh) return
46 await $.command.register(COMMAND).catch(() => undefined)
47 if (fresh) await update($, armed, () => sid)
48 } catch {}
49}
50
51const STATUSES = new Set(['PASS', 'FAIL', 'SKIP', 'WARN'])
52
53/** doctor.cjs --json rows, or null when its stdout is not that shape. */
54export function parseStatic(stdout: string): Row[] | null {
55 try {
56 const rows = (JSON.parse(stdout) as { rows?: unknown }).rows
57 if (!Array.isArray(rows)) return null
58 return rows.filter(
59 (r): r is Row => !!r && STATUSES.has(r.status) && typeof r.name === 'string' && typeof r.detail === 'string',
60 )
61 } catch {
62 return null
63 }
64}
65
66async function staticRows($: $): Promise<Row[]> {
67 const root = $.plugin.root
68 let r
69 try {
70 const argv = ['node', `${root}/scripts/doctor.cjs`, '--json', '--root', root, '--project', await $.session.root()]
71 const dir = logDir(await $.env.get('HOME'), await $.env.get('DOMAINE_LOG_DIR'), await $.session.id())
72 if (dir) argv.push('--log-dir', dir)
73 r = await $.process.run(argv, { timeoutMs: 60_000 })
74 } catch (err) {
75 const why = err instanceof Error ? err.message : String(err)
76 return [{ status: 'SKIP', name: 'static', detail: `scripts/doctor.cjs did not run (${why}): the static checks need node` }]
77 }
78 const rows = parseStatic(r.stdout)
79 if (rows?.length) return rows
80 const why = (r.stderr.trim().split('\n')[0] ?? '') || 'no rows on stdout'
81 return [{ status: 'FAIL', name: 'static', detail: `scripts/doctor.cjs exited ${r.exitCode}: ${why}` }]
82}
83
84async function liveRows($: $): Promise<Row[]> {
85 const rows: Row[] = []
86 try {
87 rows.push((await $.command.list()).some(c => c.plugin === 'base')
88 ? { status: 'PASS', name: 'base-live', detail: "base's skills are loaded" }
89 : { status: 'FAIL', name: 'base-live', detail: `fe ${BASE_MISSING}` })
90 } catch {
91 rows.push({ status: 'SKIP', name: 'base-live', detail: 'the command list did not answer' })
92 }
93 try {
94 rows.push((await $.tool.list()).some(t => t.name === SLIM_VIEW)
95 ? { status: 'PASS', name: 'slim-live', detail: `${SLIM_VIEW} registered` }
96 : { status: 'FAIL', name: 'slim-live', detail: 'slim is not loaded — claude plugin install slim@domaine; base refuses its readers until it is' })
97 } catch {
98 rows.push({ status: 'SKIP', name: 'slim-live', detail: 'the tool list did not answer' })
99 }
100 return rows
101}
102
103/**
104 * The session's own profile replaces doctor.cjs's probe (the session decided it once, the prompt follows that
105 * one); a static `base` FAIL for a base that is loaded anyway (a `--plugin-dir` load has no install record)
106 * reads as a warning.
107 */
108export function reconcile(rows: Row[], session: { word: string; text: string; fallback: boolean } | null): Row[] {
109 const live = rows.find(r => r.name === 'base-live')?.status === 'PASS'
110 return rows.map(r => {
111 if (live && r.name === 'base' && r.status === 'FAIL' && r.detail.startsWith('not installed')) {
112 return { status: 'WARN', name: 'base', detail: 'not in installed_plugins.json, yet loaded this session (a --plugin-dir load?)' }
113 }
114 if (session && r.name === 'profile') {
115 return { status: session.fallback ? 'WARN' : 'PASS', name: 'profile', detail: `${session.text} — this session's` }
116 }
117 return r
118 })
119}
120
121export function age(ms: number): string {
122 const s = Math.max(0, Math.round(ms / 1000))
123 if (s < 60) return `${s}s`
124 if (s < 3600) return `${Math.floor(s / 60)}m`
125 if (s < 48 * 3600) return `${Math.floor(s / 3600)}h`
126 return `${Math.floor(s / 86400)}d`
127}
128
129export function summary(rows: Row[]): string {
130 const n = { PASS: 0, FAIL: 0, SKIP: 0, WARN: 0 }
131 for (const r of rows) n[r.status]++
132 return `${n.PASS} passed, ${n.FAIL} failed, ${n.SKIP} skipped${n.WARN ? `, ${n.WARN} warned` : ''}`
133}
134
135export function render(root: string, rows: Row[], tail: string[]): string {
136 const width = rows.reduce((w, r) => Math.max(w, r.name.length), 0)
137 return [
138 `fe doctor — plugin root: ${root}`,
139 ...rows.map(r => `${r.status} ${r.name.padEnd(width)} ${r.detail}`),
140 `doctor: ${summary(rows)}`,
141 '',
142 ...tail,
143 ].join('\n')
144}
145
146async function eventTail($: $): Promise<string[]> {
147 if ((await $.env.get('FE_EVENT_LOG')) === '0') return ['fe events: off (FE_EVENT_LOG=0)']
148 const list = await read($, events)
149 if (!list.length) return ['fe events: none yet']
150 const now = await $.clock.now()
151 const shown = list.slice(-TAIL)
152 return [
153 `fe events (last ${shown.length} of ${list.length}, newest last):`,
154 ...shown.map(ev => ` ${age(now - ev.atMs).padStart(4)} ${ev.kind.padEnd(9)} ${ev.text}`),
155 ]
156}
157
158async function logDoctor($: $, text: string): Promise<void> {
159 try {
160 if ((await $.env.get('FE_EVENT_LOG')) === '0') return
161 const ev: FeEvent = { atMs: await $.clock.now(), kind: 'doctor', text }
162 await update($, events, l => pushEvent(l, ev))
163 await logLine(diskOf($), ev)
164 } catch {}
165}
166
167/** The profile the SessionStart command hook delivered (its marker), else the one the mod decided for this session id. */
168async function sessionProfile($: $): Promise<{ word: string; text: string; fallback: boolean } | null> {
169 try {
170 const sid = String(await $.session.id())
171 const dir = logDir(await $.env.get('HOME'), await $.env.get('DOMAINE_LOG_DIR'), sid)
172 const m = dir ? await $.fs.read(`${dir}/conventions.fe.json`).then(t => (JSON.parse(t) as { profile?: FeProfileInfo }).profile, () => null) : null
173 const p = m && isProfile(m.word) ? { ...m, session: sid } : await read($, profile)
174 if (!p || p.session !== sid) return null
175 return { word: p.word, text: profileText(p), fallback: p.via === 'fallback' }
176 } catch {
177 return null
178 }
179}
180
181export function registerDoctor(on: On): void {
182 // A matcher apart from session.ts's start hook: one unmatched hook per event per plugin.
183 on('session.start', { cwd: /$/ }, async ($, e, next) => {
184 const r = await next(e)
185 await arm($, true)
186 return r
187 })
188
189 on('prompt.submit', async ($, e, next) => {
190 const r = await next(e)
191 await arm($, false)
192 return r
193 })
194
195 on('command.run', { command: COMMAND.name }, async $ => {
196 const [fixed, live, mine] = await Promise.all([staticRows($), liveRows($), sessionProfile($)])
197 const rows = reconcile([...fixed, ...live], mine)
198 const tail = await eventTail($)
199 await logDoctor($, summary(rows))
200 return { text: render($.plugin.root, rows, tail) }
201 })
202}
203hooks/mods/session.ts 122 lines1// fe's session: the start line, the base check and the project profile (decided once per session id) for the
2// module's readers. The conventions reach the model through command hooks only (hooks/conventions.cjs).
3import { atom, read, update } from 'claude-code'
4import type { EngineInterface, On } from 'claude-code'
5import type { FeEvent, FeEventKind, FeProfile, FeProfileInfo } from '../../types'
6import { logLine, pushEvent } from './events.ts'
7import type { Disk } from './events.ts'
8
9export const BASE_MISSING = 'needs the base plugin — claude plugin install base@domaine'
10export const PROFILE_TIMEOUT_MS = 5_000
11
12const events = atom({ plugin: 'fe', key: 'events' } as const, [] as FeEvent[])
13const started = atom({ plugin: 'fe', key: 'started' } as const, null)
14const profile = atom({ plugin: 'fe', key: 'profile' } as const, null)
15
16type $ = EngineInterface
17
18/** events.ts's file writer reaches `$` through this: the validator follows `$` only within one file. */
19function diskOf($: $): Disk {
20 return {
21 session: () => $.session.id(),
22 home: () => $.env.get('HOME'),
23 override: () => $.env.get('DOMAINE_LOG_DIR'),
24 manifest: () => $.fs.read(`${$.plugin.root}/.claude-plugin/plugin.json`),
25 read: path => $.fs.read(path),
26 write: (path, text) => $.fs.write(path, text),
27 toast: text => $.ui.toast(text),
28 }
29}
30
31async function logEvent($: $, kind: FeEventKind, text: string): Promise<void> {
32 try {
33 if ((await $.env.get('FE_EVENT_LOG')) === '0') return
34 const ev: FeEvent = { atMs: await $.clock.now(), kind, text }
35 await update($, events, l => pushEvent(l, ev))
36 await logLine(diskOf($), ev)
37 } catch {}
38}
39
40async function version($: $): Promise<string> {
41 try {
42 const v = (JSON.parse(await $.fs.read(`${$.plugin.root}/.claude-plugin/plugin.json`)) as { version?: unknown }).version
43 return typeof v === 'string' && v ? v : 'unknown'
44 } catch {
45 return 'unknown'
46 }
47}
48
49/** base's skills carry `plugin: 'base'` in the command list from its manifest on; a list that fails says nothing. */
50async function baseLoaded($: $): Promise<boolean> {
51 try {
52 return (await $.command.list()).some(c => c.plugin === 'base')
53 } catch {
54 return true
55 }
56}
57
58export const isProfile = (w: string | undefined): w is FeProfile => w === 'foundation' || w === 'theme' || w === 'none'
59
60const oneLine = (s: string) => s.replace(/\s+/g, ' ').trim().slice(0, 120)
61
62/** `theme (project-profile.sh)`, `foundation (FE_PROFILE)`, `none (fallback: <why>)`: the profile line's text. */
63export function profileText(p: FeProfileInfo): string {
64 return p.via === 'fallback' ? `none (fallback: ${p.why ?? 'unknown'})` : `${p.word} (${p.via})`
65}
66
67async function decide($: $, session: string): Promise<FeProfileInfo> {
68 let root = ''
69 let toml = false
70 let env = false
71 try {
72 root = await $.session.root()
73 toml = await $.fs.exists(`${root}/shopify.theme.toml`)
74 env = await $.fs.exists(`${root}/.env`)
75 } catch {}
76 const info = (word: FeProfile, via: FeProfileInfo['via'], why: string | null): FeProfileInfo =>
77 ({ session, word, via, why, toml, store: toml || (env && word !== 'none') })
78 const forced = (await $.env.get('FE_PROFILE').catch(() => undefined))?.trim()
79 if (isProfile(forced)) return info(forced, 'FE_PROFILE', null)
80 let why: string
81 try {
82 const argv = ['bash', `${$.plugin.root}/scripts/project-profile.sh`]
83 if (root) argv.push(root)
84 const r = await $.process.run(argv, { timeoutMs: PROFILE_TIMEOUT_MS })
85 const word = r.stdout.trim()
86 if (r.exitCode === 0 && isProfile(word)) return info(word, 'project-profile.sh', null)
87 why = `project-profile.sh exited ${r.exitCode}: ${oneLine(r.stderr.split('\n')[0] || word) || 'no answer'}`
88 } catch (err) {
89 why = `project-profile.sh did not run: ${oneLine(err instanceof Error ? err.message : String(err))}`
90 }
91 return info('none', 'fallback', why)
92}
93
94/** Decides this session's profile unless the atom already holds this id; stores and logs it once. */
95async function storeProfile($: $): Promise<void> {
96 const session = String(await $.session.id())
97 if ((await read($, profile))?.session === session) return
98 const p = await decide($, session)
99 await update($, profile, () => p)
100 await logEvent($, 'profile', profileText(p))
101}
102
103export function registerSession(on: On): void {
104 // The engine allows one unmatched hook per event per plugin; this matcher takes every session.
105 on('session.start', { cwd: /^/ }, async ($, e, next) => {
106 try {
107 const sid = String(await $.session.id())
108 if ((await read($, started)) !== sid) {
109 await update($, started, () => sid)
110 await logEvent($, 'start', `fe ${await version($)}`)
111 if (!(await baseLoaded($))) {
112 await logEvent($, 'install', BASE_MISSING)
113 $.ui.toast(`fe: ${BASE_MISSING}`)
114 }
115 }
116 // Unawaited: the probe never holds the start.
117 void storeProfile($).catch(() => undefined)
118 } catch {}
119 return next(e)
120 })
121}
122hooks/mods/events.ts 157 lines1// fe's event list and its file on disk, `<log dir>/<session-id>/fe.jsonl`, under the contract base, band and
2// slim write theirs by. No `$` here: each writer file keeps its own wrapper, which pushes the line to fe.events
3// and then hands it to `logLine` with a `Disk` it built, as the validator follows `$` only within one file.
4// fe never sweeps old session directories: base owns that.
5import type { FeEvent } from '../../types'
6
7export const EVENT_CAP = 200
8export const FILE_LINES = 2000
9export const FILE_BYTES = 256 * 1024
10
11/** Appends `ev`, oldest first, at most EVENT_CAP: past the cap the oldest line goes. */
12export function pushEvent(list: readonly FeEvent[], ev: FeEvent): FeEvent[] {
13 return list.length < EVENT_CAP ? [...list, ev] : [...list.slice(1), ev]
14}
15
16const trimSlash = (p: string) => p.replace(/\/+$/, '')
17
18/** A name the engine could not have made a session id of never becomes a path segment. */
19export function isSessionName(name: string): boolean {
20 return /^[\w.-]+$/.test(name) && !/^\.+$/.test(name)
21}
22
23/** `<DOMAINE_LOG_DIR>/<session>` when the override is absolute, else `$HOME/.claude/domaine/log/<session>`; null with neither. */
24export function logDir(home: string | undefined, override: string | undefined, session: string): string | null {
25 if (!isSessionName(session)) return null
26 const o = override?.trim() ?? ''
27 if (o.startsWith('/')) return `${trimSlash(o)}/${session}`
28 const h = home?.trim() ?? ''
29 return h.startsWith('/') ? `${trimSlash(h)}/.claude/domaine/log/${session}` : null
30}
31
32/** One fe.jsonl line; `plugin` is fe's own name, never taken from another plugin's state. */
33export function fileLine(ev: FeEvent, version: string, session: string): string {
34 return JSON.stringify({ ts: new Date(ev.atMs).toISOString(), plugin: 'fe', version, session, kind: ev.kind, agent: 'main', text: ev.text })
35}
36
37export function utf8Bytes(s: string): number {
38 let n = 0
39 for (const ch of s) {
40 const cp = ch.codePointAt(0) ?? 0
41 n += cp < 0x80 ? 1 : cp < 0x800 ? 2 : cp < 0x10000 ? 3 : 4
42 }
43 return n
44}
45
46/** Drops the oldest lines past FILE_LINES lines or FILE_BYTES bytes; the newest line always stays. */
47function trimFront(out: string[]): string[] {
48 let bytes = 0
49 for (const l of out) bytes += utf8Bytes(l) + 1
50 let cut = 0
51 while (out.length - cut > 1 && (out.length - cut > FILE_LINES || bytes > FILE_BYTES)) bytes -= utf8Bytes(out[cut++]!) + 1
52 return cut ? out.slice(cut) : out
53}
54
55/** Appends `line` within the cap. */
56export function capLines(lines: readonly string[], line: string): string[] {
57 return trimFront([...lines, line])
58}
59
60/** The lines of a fe.jsonl that belong to `session`, oldest first, within the cap: what a reload goes on from. */
61export function seedLines(text: string, session: string): string[] {
62 return trimFront(text.split('\n').filter(l => {
63 try {
64 return (JSON.parse(l) as { session?: unknown }).session === session
65 } catch {
66 return false
67 }
68 }))
69}
70
71const hasStart = (lines: readonly string[]) => lines.some(l => l.includes('"kind":"start"'))
72
73/**
74 * The file's lines after `ev`: the start line first in every session (a /clear's new id gets one before its
75 * first event, as no session.start announces it), and one start line per session.
76 */
77export function nextLines(lines: readonly string[], ev: FeEvent, version: string, session: string): string[] | null {
78 if (ev.kind === 'start') return hasStart(lines) ? null : capLines(lines, fileLine(ev, version, session))
79 const head = lines.length ? lines : [fileLine({ atMs: ev.atMs, kind: 'start', text: `fe ${version}` }, version, session)]
80 return capLines(head, fileLine(ev, version, session))
81}
82
83/** What the writer needs from `$`, built by each writer file's `diskOf`. */
84export type Disk = {
85 session: () => Promise<string>
86 home: () => Promise<string | undefined>
87 override: () => Promise<string | undefined>
88 manifest: () => Promise<string>
89 read: (path: string) => Promise<string>
90 write: (path: string, text: string) => Promise<void>
91 toast: (text: string) => void
92}
93
94type Sink = { path: string; lines: string[] }
95
96// Module-local, so a hot reload starts from the file: the lines already on disk for this session.
97let sink: Promise<Sink | null> | null = null
98let sinkSession = ''
99let version: Promise<string> | null = null
100let writes: Promise<void> = Promise.resolve()
101let toasted = ''
102
103async function readVersion(disk: Disk): Promise<string> {
104 try {
105 const v = (JSON.parse(await disk.manifest()) as { version?: unknown }).version
106 return typeof v === 'string' && v ? v : 'unknown'
107 } catch {
108 return 'unknown'
109 }
110}
111
112async function openSink(disk: Disk, session: string): Promise<Sink | null> {
113 const dir = logDir(await disk.home(), await disk.override(), session)
114 if (dir === null) return null
115 const path = `${dir}/fe.jsonl`
116 let lines: string[] = []
117 try {
118 lines = seedLines(await disk.read(path), session)
119 } catch {}
120 return { path, lines }
121}
122
123/**
124 * Rewrites this session's fe.jsonl with `ev` appended (`$.fs.write` has no append), after the line went to
125 * fe.events. Never throws; one toast per session when a write fails.
126 */
127export async function logLine(disk: Disk, ev: FeEvent): Promise<void> {
128 let session = ''
129 try {
130 session = await disk.session()
131 if (!sink || sinkSession !== session) {
132 sinkSession = session
133 sink = openSink(disk, session).catch(() => null)
134 }
135 version ??= readVersion(disk)
136 const v = await version
137 const s = await sink
138 if (!s) return
139 // Read, append and write inside one queue: two events in flight never build on the same snapshot.
140 const w = writes.then(async () => {
141 const lines = nextLines(s.lines, ev, v, session)
142 if (!lines) return
143 s.lines = lines
144 await disk.write(s.path, `${lines.join('\n')}\n`)
145 })
146 writes = w.catch(() => {})
147 await w
148 } catch (err) {
149 if (toasted === session) return
150 toasted = session
151 const reason = String((err as { message?: unknown } | null)?.message ?? err).replace(/\s+/g, ' ').slice(0, 120)
152 try {
153 disk.toast(`fe: event log not written: ${reason}`)
154 } catch {}
155 }
156}
157types/index.d.ts 46 lines1// fe's $.state contract. Values are JSON, so an absent value is null, never undefined. base's and slim's keys
2// come from the dependency contracts the engine lays beside the module (base, and slim through base); they
3// are never redeclared here.
4
5/**
6 * At most 9 characters each (band's kind cell). `start` fe's version at session start, `install` base is not
7 * loaded, `profile` the project profile fe decided and how, `doctor` the counts of a /fe-doctor run.
8 */
9export type FeEventKind = 'start' | 'install' | 'profile' | 'doctor'
10
11/** atMs = $.clock.now() when written; text is one line. */
12export type FeEvent = { atMs: number; kind: FeEventKind; text: string }
13
14/** The project profile fe's conventions follow; `none` outside a Shopify theme. */
15export type FeProfile = 'foundation' | 'theme' | 'none'
16
17/**
18 * The profile of one session's project. `via`: `FE_PROFILE` forced it, `project-profile.sh` answered it
19 * (detection or a domaine env file), `fallback` the script failed and fe took `none` (`why` says how).
20 * `toml`: the project root holds `shopify.theme.toml`. `store`: the store-access section applies — a toml, or a
21 * root `.env` in a project whose profile is not `none`.
22 */
23export type FeProfileInfo = {
24 session: string
25 word: FeProfile
26 via: 'FE_PROFILE' | 'project-profile.sh' | 'fallback'
27 why: string | null
28 toml: boolean
29 store: boolean
30}
31
32declare module 'claude-code' {
33 interface PluginState {
34 fe: {
35 /** Oldest first, at most 200; any plugin reads, fe writes. Stays [] under FE_EVENT_LOG=0. */
36 events: FeEvent[]
37 /** Decided once per session id; null before the first decision. */
38 profile: FeProfileInfo | null
39 /** The session id whose start line was written and whose base check ran: a module reload does neither again. */
40 started: string | null
41 /** The session id whose /fe-doctor command is registered. */
42 armed: string | null
43 }
44 }
45}
46