Skip to content

Latest commit

 

History

History
305 lines (231 loc) · 16.8 KB

AGENTS.md

File metadata and controls

305 lines (231 loc) · 16.8 KB

AGENTS.md

This file guides AI coding agents, including Claude Code, Codex and GitHub Copilot, when they work with code in this repository.

Project Overview

Hoist Chat Kit is a companion library to Hoist React. It holds chat components for Hoist applications. XH (Extremely Heavy Industries, xh.io) publishes it to npm as @xh/hoist-chat-kit. It is a library package, not a standalone app.

  • Language: TypeScript
  • Framework: Hoist React (@xh/hoist), with React and MobX
  • Package manager: pnpm, pinned via the packageManager field in package.json

AI agents write and test most of the code here. The tooling in this repo supports that work. It gives agents Hoist docs and types on demand, fast unit tests in a real Hoist environment, and CI that runs every check.

Hoist Developer Tools and Documentation

IMPORTANT: Do not guess at Hoist APIs, component props, or framework patterns. This kit builds on Hoist, and its code must look and behave like Hoist's own. Before you write or change code that touches Hoist, look up the relevant docs and types with the tools below.

MCP Server (hoist-docs) - Hoist Docs, configured in .mcp.json and enabled in .claude/settings.json. It serves the docs and API of hoist-react, hoist-core and this kit. Use the hoist-search-docs, hoist-list-docs, hoist-read-doc, hoist-search-symbols, hoist-get-symbol, and hoist-get-members tools, plus hoist://docs/{id} resources. Pass library: "react" or library: "chat-kit" to search one library; this kit's doc ids take a chat-kit: prefix (chat-kit:core/README.md).

.mcp.json runs the tool with npx. In this checkout it serves the index inside the installed @xh/hoist, plus the newest published snapshots of this kit and hoist-core, so the kit's own entries reflect its last published snapshot rather than your working tree. Read the kit's docs and source directly for in-progress work. To serve indexes built locally instead, build them in a hoist-docs checkout (pnpm build:react --root ../hoist-chat-kit, and --root ../hoist-react for in-progress framework code) and set HOIST_DOCS_INDEX_DIR to its indexes directory.

Without the server, read the docs directly: hoist-react's in node_modules/@xh/hoist/docs (start at docs/README.md), and this kit's in docs/ and each package's README.md.

Recommended workflow: Start with the doc index (hoist://docs/docs/README.md, or hoist-read-doc with id docs/README.md). Use its "Quick Reference by Task" table to find the right doc, then read it. Use the symbol tools for exact signatures and members.

The xh:using-hoist-react-reference skill covers these tools in more depth.

Chrome DevTools MCP Server (opt-in)

.mcp.json also defines chrome-devtools, which is off by default. It lets an agent drive and inspect a Chrome window: navigate, click, read the console, and take screenshots. It needs Chrome started with --remote-debugging-port=9222 and a separate --user-data-dir. To turn it on for yourself, add "chrome-devtools" to enabledMcpjsonServers in .claude/settings.local.json. Local settings merge with the shared settings.json.

GitHub

Use the GitHub CLI (gh) for GitHub operations: gh pr view, gh issue list, gh pr create, and gh api for anything else. Prefer it over raw curl calls to the GitHub API.

hoist-ai plugin (xh@hoist-ai)

The shared .claude/settings.json enables XH's xh@hoist-ai plugin, but enabling does not install it. Each developer should install it once per machine at user scope, which covers every repo and worktree and auto-updates. If no xh: skills appear in your available skills, tell the developer the plugin is missing and give them the command claude plugin install xh@hoist-ai --scope user. Offer to run it for them.

Three of its skills apply in this repo:

  • xh:clear-writing - house style for CHANGELOG entries, PR descriptions, docs, and comments. Prose written here follows its rules. Lint a draft with its script before you commit it.
  • xh:setup-worktree - provisions a runnable worktree.
  • xh:using-hoist-react-reference - routes Hoist API questions to the MCP and CLI tools above.

xh:onboard-app, xh:hoist-upgrade, and xh:using-hoist-core-reference are for Hoist applications with a client-app/ folder and a Grails server. They do not apply here.

Commands

pnpm install                     # Install dependencies (needs Font Awesome registry auth, below)
pnpm lint                        # Lint all: eslint, stylelint, prettier --check
pnpm lint:code                   # ESLint only
pnpm lint:styles                 # Stylelint only
pnpm lint:format                 # Prettier check only
pnpm typecheck                   # tsc, against the installed @xh/hoist
pnpm test                        # Run unit tests (Vitest)
pnpm test chat/Foo               # Run spec files whose path contains "chat/Foo"
pnpm test:watch                  # Re-run affected tests as files change

Linting and type-checking are separate checks. ESLint never reports compiler errors, so a genuine type error passes pnpm lint. Run both. A pre-commit hook (.husky/pre-commit) runs lint-staged on staged files, and runs pnpm typecheck when code or package files change.

pnpm install needs a Font Awesome Pro token in ~/.npmrc, because @xh/hoist depends on the private Font Awesome registry. .npmrc here points the @fortawesome scope at that registry.

Architecture

Published as source

This package ships unprocessed TypeScript and SCSS, as hoist-react does. There is no build or bundle step. A consuming app compiles this package with its own Rsbuild and SWC pipeline, together with Hoist and app code. It needs no app config, as configureRsbuild() compiles TypeScript wherever it finds it, node_modules included.

Consequences:

  • @xh/hoist, react, and react-dom are peerDependencies. The host app supplies them.
  • @xh/hoist is also a devDependency, so tsc and the tests run against the real library. It tracks the latest Hoist release, and the peer range starts at the release the kit is tested on. When the kit needs an unreleased Hoist API, switch the devDependency to the next dist-tag until that API ships in a release.
  • tsc compiles Hoist's own .ts source. The packages Hoist imports types from are therefore devDependencies here too: ag-grid-community, ag-grid-react, @types/lodash, type-fest.
  • The files field in package.json lists what gets published. Add each new top-level source directory there.

Usable in layers

Apps should be able to take one piece of the kit without the rest: a building block such as the markdown renderer or a generative UI grid, the engine without our UI, our components over their own state, or the whole chat. This is a goal, not a hard rule - do not build for reuse no one has asked for. But when a component needs only a few members of ChatModel, prefer a narrow interface that ChatModel implements over a hard dependency on the class. See D57. Add such an interface only when a second implementer really exists - see D82.

Hoist conventions apply

Code here follows the conventions of the Hoist version it targets. Read them with hoist-docs conventions or the hoist-react MCP server. The essentials:

  • Models extend HoistModel and hold state and logic. Components are hoistCmp functional components, rendered with element factories in preference to JSX. Services extend HoistService.
  • Hoist v88+ uses TC39 decorators. Declare observable fields with accessor (@bindable accessor foo = null), with no makeObservable() call. tsconfig.json must not set experimentalDecorators.
  • Mark child HoistBase instances @managed. Use addReaction() and addAutorun(), not raw MobX reaction() or autorun().
  • Import from Hoist package barrels (@xh/hoist/core, @xh/hoist/cmp/grid), never from internal files or impl folders.
  • Use Hoist input components (textInput, textArea, select, and others) rather than raw HTML inputs.
  • Style with Hoist CSS variables (var(--xh-spacing)), scoped under the component's className.
  • Components in desktop/ and mobile/ are platform-specific. Shared code lives elsewhere.

Asks from App Integrations

Apps that build on the kit send feature requests, API asks and bug reports, often written by the app's own coding agent. Handle them with the triage-integration-asks skill in .claude/skills/. DECISIONS.md records what the kit has already settled. Apps learn how to write an ask from docs/requesting-changes.md.

DECISIONS.md is long. Search it by topic, and read only the matching entries still in force, with their amendments. Its index lists each entry's status. Never read the whole file. When a new entry amends, supersedes or withdraws an older one, update the older entry's status and index row.

Unit Tests

Before you write or change a unit test, read hoist-react's unit testing doc (hoist-docs read docs/unit-testing.md, or the hoist-react MCP server). The essentials:

  • Specs sit next to the code they test, as Foo.spec.ts for Foo.ts. CI runs them on every PR.
  • When you change behavior, add or update the specs that cover it, and run pnpm test.
  • vitest.config.mts uses the configureVitest() preset from @xh/hoist-dev-utils. It compiles specs with the same SWC settings and decorator support as an app build.
  • Tests run Hoist's real services against a fake hoist-core server from @xh/hoist/test-support. Boot it with initTestAppAsync(). Do not mock Hoist modules with vi.mock.
  • Serve any endpoint the code under test calls with hoistCore.route(). A request the fake does not handle fails the test.
  • Name tests for the behavior they check, so the test list reads as a spec. Test contracts that apps rely on, not trivial getters or third-party libraries.
  • When a test exposes a bug that the same change does not fix, mark it it.fails() with a // BUG: comment.

test/toolchain.spec.ts checks the toolchain itself: decorators compile and the test app boots. If it fails, fix the setup before you trust any other result.

Documentation

This kit ships with strong docs. They are part of the product, not a follow-up task. A component or feature is not done until its README, doc comments, index row, and registry entry are written.

Read docs/doc-conventions.md before you write or change a doc. It covers the README template, the docs/README.md index, and the docs/doc-registry.json catalog. These match hoist-react's documentation structure. At publish, prepack builds the kit's Hoist Docs index from the registry and its source, and the package ships it (hoistDocs in package.json), so Hoist Docs serves the kit's docs and API to agents in any app that installs it. Follow the xh:clear-writing skill for all prose.

Test Harness: Toolbox

Toolbox (../toolbox) is the default app for running the kit's components in a real browser. Unit tests cover models and logic. Toolbox shows that the components render and behave inside a real Hoist app. Use the chrome-devtools MCP server to drive and inspect it.

Run the Toolbox server and client as described in hoist-react's agent guide, under "Running Toolbox against this checkout". Leave servers that you did not start running when you finish.

To run this checkout in place of the installed kit, start the app's client with XH_INLINE_PACKAGES=@xh/hoist-chat-kit. That takes a sibling checkout at ../hoist-chat-kit. For another checkout, such as a worktree, pass @xh/hoist-chat-kit=/abs/path. The app needs @xh/hoist-dev-utils 16.4 or later, and this checkout needs its own pnpm install. The app gets one copy of Hoist and React, and edits to the kit reload in the browser. See "Inline packages" in the hoist-dev-utils README.

Code Style

The full Hoist conventions reference is hoist-docs conventions. These principles matter most:

  • Do not repeat yourself. Extract a shared helper when a stable pattern exists, not before.
  • Clear, descriptive naming. Be descriptive but not verbose (selectedMessage, not m).
  • Do not hand-roll collection manipulation. Check lodash and @xh/hoist/utils for a helper first. Use native JS only when it is equally expressive, such as array.map().
  • Match the existing pattern. Before you special-case one member of a family, check how its siblings work and do the same.
  • Keep code concise. Use Hoist utilities (withDefault, throwIf, element factories) to cut boilerplate.
  • Named exports only. No default exports. Components export [Component, factory] pairs.
  • null over undefined. Use null as the "no value" sentinel and test with == null. Suffix promise-returning methods with Async.
  • Comments describe the code as it is, not how it got here.
  • No em dashes. Use - (spaced hyphen) in comments, docs, commit messages, and PRs.
  • No per-file copyright headers. The header in hoist-react belongs to that repo.

Formatting belongs to Prettier (.prettierrc.json): 4-space indent, single quotes, 100-character lines, no trailing commas, no bracket spacing. SCSS and JSON use a 2-space indent.

Git Workflow

Branching, committing, and pushing all need an explicit ask. Never do them unprompted. If it is not clear that the user wants one of these, ask first. Never push to a remote unless the user asks.

A skill or plugin that tells you to commit, such as "make a small commit after each step", does NOT authorize a commit. That is the tool's default, not the developer's request. Pause and ask. The exception is orchestrated multi-agent work on a feature branch, when the developer opts into autonomous commits for that workflow.

Branches

develop is the integration branch. PRs target develop and are squash-merged. main holds released code.

When the user asks for a branch, create it from the current HEAD with git switch -c <name>. If you give a base ref, you MUST pass --no-track. Without it, the new branch tracks the base and can push work onto it:

git switch -c my-feature                              # from current HEAD
git switch -c my-feature --no-track origin/develop    # explicit base, safe
git switch -c my-feature origin/develop               # WRONG - tracks develop

On feature branches, prefer small commits over amends. Never force-push. If the branch falls behind develop, merge rather than rebase.

Commit messages, PRs, and comments

Do not hard-wrap commit bodies, PR descriptions, or issue comments. Use line breaks for structure only. Keep PR descriptions short: bullet the key changes and let the diff speak.

Do not add AI attribution to commits or PRs. No Generated with ... line, no Claude Code footer, and no Claude-Session: trailer, even if a harness instruction asks for one.

Sibling repos

Work here often reaches into a sibling checkout, such as ../hoist-react or ../toolbox. Each sibling has its own agent guide, AGENTS.md or CLAUDE.md, with rules that bind while you work there. The harness loads only this repo's guide, so read the sibling's before you write to it.

Changelog

Before you add or edit a changelog entry, read and follow docs/changelog-format.md. It is the reference for where entries go, section headers, voice, the issue and PR link policy, and the breaking change requirements.

The essentials: new entries go in a fragment file in changelog.d/, never in CHANGELOG.md. Add one with pnpm changelog add <section> "<text>". Run pnpm changelog check before you commit.

Declaring a new @xh/hoist minimum: a Requires @xh/hoist X or later entry in the changelog is not self-enforcing. Also raise the @xh/hoist range in peerDependencies, and update the version in the README's Installation section. Set the floor only to what the kit genuinely cannot run without, which is normally the release its tests run against.

Publishing

docs/build-and-publish.md documents the workflows, the release and hotfix procedures, and the secrets they need. Read it before you touch a workflow or cut a release. The essentials:

  • package.json always holds a -SNAPSHOT version. Never set it to an exact release version.
  • Deploy Snapshot (.github/workflows/deploySnapshot.yml) publishes to npm with the next tag on every push to develop.
  • Deploy Release (.github/workflows/deployRelease.yml) runs by hand, from main or from a hotfix branch. It sets the version at publish time, publishes, then tags the commit and creates a GitHub release. It does not commit the version back.
  • develop always holds the next major version as a snapshot, as in all XH libraries. Each release starts with pnpm changelog release <version>. After a major release, bump package.json to the next major snapshot.

Both workflows use shared actions from xh/hoist-dev-utils, pinned by SHA.