Learn mode presents concepts at useful depths

What it does

Learn mode explains the technology and principles used in real work. The learn skill controls when the agent presents an explanation. The operator enables the mode and can stop it at any time.

The build derives a concept deck from public lore, system pages, and skills. Cards preserve page titles, summaries, terms, references, and links. Explicit prerequisite metadata supplies prerequisite ids.

A page that is not a concept, such as an announcement, sets learn: false in its frontmatter. The build leaves it out of the deck and logs its id.

A card can also teach with three optional fields:

FieldSourceContent
plainPage frontmatterOne line in plain words, shown before the claim.
snippet.brain/data/learn-cards/<id>.tsThe smallest idiomatic TypeScript for the idea.
diagramPage frontmatterPlain text, at most 30 columns and 12 rows of one-column characters.

A capability is one named action with shared value definitions and a server-side implementation. Four capabilities serve the deck and learning events. Two local capabilities serve display preferences:

CapabilityJob
learnDeckList the public cards.
learnCardRead one card at a requested depth.
learnNextSelect explanations for concepts in play.
learnRecordRecord an explicit learning event.
learnPreferencesRead local display preferences. Local only.
learnSetPreferencesChange local display preferences. Local only.

learnNext and learnRecord treat omitted progress as empty version 1 progress.

XState owns the learning lifecycle as a state machine: named states and the events that permit movement between them. Effect describes the work with typed failures36 and required services. A service is a named interface for one job.

Selection follows deck order when context is absent. A public context term selects its owner and resolves unintroduced prerequisites first. A shown walkthrough introduces a prerequisite. Dismissed prerequisites count as satisfied; dismissed cards stay silent.

The command-line interface (CLI) and MCP tools use a local progress adapter, an implementation that connects learning operations to local files. MCP27 means Model Context Protocol. Its stdio connection uses the process’s standard input and output to carry tool calls.

The learning cartridge36 provides the adapter through @rat-stack/learn/local. A cartridge is a package for one job, with its implementation and required infrastructure. The CLI supplies filesystem access and the default directory.

Public HTTP and MCP calls operate on supplied progress. The public server stores no progress. The default local directory is ~/.rat-learn/.

Local fileRole
log.jsonlAuthoritative append-only learning events.
cards.jsonlRebuildable concept progress.
tasks.jsonlRebuildable concept ids and presentation depths.
README.mdStore shape and recovery instructions.
preferences.jsonDisplay width, visual style, and snippet length. A missing file means narrow inline text with full snippets.

Feedback sign-in

Feedback is separate from learning progress. A person signs in through Better Auth16 and approves an agent’s code on their phone. The agent receives a credential that permits learnFeedback only. The database stores feedback against the approving person.

CapabilityJob
learnFeedbackStartReturn a short code, verification URL, lifetime, and polling interval.
learnFeedbackPollReport pending, approval, denial, expiry, or polling too fast.
learnFeedbackValidate the credential and card, then store the agreed feedback.

The phone page is /learn/approve. It shows the code and requires sign-in before approval. The stock /auth/device/token endpoint is disabled because it issues a full sign-in session.

Feedback credentials are separate signed values. They cannot authenticate a normal Better Auth session.

The device machine reflects the provider’s stored approval facts. Its declared Effect actors inspect the grant and issue the credential. The credential machine checks signature, audience, expiry, and the current grant before it returns an author.

Learn owns the FeedbackAuthor port19. Mischief provides its auth adapter inside each request. Learn imports no auth provider.

AUTH_ENABLED defaults to false. Off removes sign-in routes, the phone page, feedback HTTP operations, and feedback MCP tools. The D1 database and signing-secret foundation stay declared to keep state and resource ownership. On adds Better Auth table migrations and the Worker bindings23 that use them.

Feedback writes are not replay-idempotent. Each successful call stores a new row. An uncertain write needs a storage check before another attempt.

The standard

Effect Schema describes accepted values and their runtime checks. The event schema defines the available observations:

packages/core/src/learn-model.ts · cec3fcc3 · Explicit learning events
export const LearnEventSchema = Schema.Union([
  Schema.Struct({
    at: LearnTimestampSchema,
    depth: LearnDepthSchema,
    id: ConceptIdSchema,
    kind: Schema.Literal("shown"),
    version: Schema.Literal(1),
  }),
  Schema.Struct({
    at: LearnTimestampSchema,
    id: ConceptIdSchema,
    kind: Schema.Literals(["used", "got-it", "skipped", "dismissed"]),
    version: Schema.Literal(1),
  }),
]);

How to check

Build the CLI and start its local stdio MCP:

pnpm turbo run build --filter=@rat-stack/cli
node apps/cli/dist/cli.js mcp --devtools

Through an MCP client:

  1. Call learnDeck and choose lore.effect-basics.
  2. Call learnNext with that id and timestamp 100. Omit progress.
  3. Confirm the returned depth is walkthrough in a fresh store.
  4. Call learnRecord with a version 1 shown event at 100 and depth walkthrough.
  5. Call learnNext at 101. Omit progress again.
  6. Confirm the returned depth is line. The local log supplies the progress.
  7. Inspect rat_list_calls for three successful learning calls.

Use a fresh test directory through RAT_LEARN_DIRECTORY. These timestamps are test fixtures. Use current Unix timestamps in milliseconds for real presentations.

Without MCP, use the same local adapter through the CLI:

node apps/cli/dist/cli.js learnNext \
  --context '{"at":100,"ids":["lore.effect-basics"]}'
node apps/cli/dist/cli.js learnRecord \
  --event '{"at":100,"depth":"walkthrough","id":"lore.effect-basics","kind":"shown","version":1}'
node apps/cli/dist/cli.js learnNext \
  --context '{"at":101,"ids":["lore.effect-basics"]}'
node apps/cli/dist/cli.js learnPreferences

Confirm learnPreferences prints narrow inline text in a fresh directory. Check one event in log.jsonl. Repeat the record command and confirm that the event count stays one. Confirm outbound deck requests contain only an empty JSON body.

With feedback sign-in enabled in a test composition:

  1. Call learnFeedbackStart and open its verification URL while signed out.
  2. Sign in on the phone, check the code, and approve feedback access.
  3. Poll with learnFeedbackPoll, respecting its interval.
  4. Call learnFeedback with a real public card id and the agreed text.
  5. Confirm the returned id and the stored person’s id.
  6. Check that the credential cannot authenticate a normal session or authorize another capability.
  7. Repeat with denial and expiry. Confirm neither grants feedback access.
  8. Disable the flag. Confirm the routes, OpenAPI operations, and MCP tools are absent.

The tests use memory auth for the HTTP seam. They do not establish deployed D1 health. The schema limits feedback to 2,000 characters, card ids to 200, and credentials to 4,096. These are initial input bounds, not measured traffic limits.

Run the implementation checks:

pnpm --filter @rat-stack/learn test
pnpm --filter @rat-stack/auth test
pnpm --filter @rat-stack/site generate
pnpm turbo run check test build --concurrency=1

Read /_content/learn.json after deployment. Confirm it includes this system page and the learn skill. Build success does not establish deployment health.

Sources

  1. Pinned device authorization plugin. GitHub better-auth/better-auth. Device codes, cookie-authenticated approval, provider lifetime, and polling interval. The application disables its full-session token exchange. Accessed 2026-10-08.
  2. Local progress adapter. GitHub joelhooks/rat-stack. Validated append-only events, writer locking, and rebuildable projections. Accessed 2026-10-07.
  3. Local CLI command projection. GitHub joelhooks/rat-stack. Plain CLI commands use the local learning capabilities. Accessed 2026-10-07.
  4. Learning cartridge. GitHub joelhooks/rat-stack. Source-derived cards, depth policy, lifecycle, and learning capabilities. Accessed 2026-10-07.
  5. Learning schemas. GitHub joelhooks/rat-stack. Versioned concept cards, events, and compact progress. Accessed 2026-10-07.
  6. Learning contracts. GitHub joelhooks/rat-stack. Deck reads, card reads, selection, and explicit event recording. Accessed 2026-10-07.

Last changed 2026-10-10 in 978dccc. Source on GitHub. Change log.

Linked from

  1. Agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.

    Learn rat-stack from your own agent — Turn on learn mode: your own agent explains rat-stack ideas during real work and keeps progress local.

  2. Agent rules for rat-stack (AGENTS.md). What you may change, which commands to run, and which changes need approval.
  3. Auth. Email and password sign-in through Better Auth, with the signed-in person provided to each RPC call.

    When enabled, learn feedback uses phone approval and a separate feedback-only credential.¶

  4. Change log. What changed in the files served here, newest first.

    Learn mode presents concepts at useful depths — edited: docs: point live docs, skills and Brain pages at apps/site

  5. Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
  6. learn. Present Effect, Alchemy, XState, and application-design concepts during real work when the operator enables learn mode. Use for adaptive explanations and local learning progress.

    Start only when the operator enables learn mode.¶

  7. Learn rat-stack from your own agent. Turn on learn mode: your own agent explains rat-stack ideas during real work and keeps progress local.

    Learn mode explains the ideas behind rat-stack-shaped apps while your own agent does real work.

  8. Learn the stack | rat-stack. Hands-on guides to Effect actions, XState lifecycles, and the seams between stack pieces.

    learn — Present Effect, Alchemy, XState, and application-design concepts during real work when the operator enables learn mode.

  9. Rat Stack systems | rat-stack. The systems rat-stack ships, the standard each keeps, and how to check it.

    Learn mode presents concepts at useful depths — An agent presents source-derived concepts during real work and keeps learning events in a private local log.

  10. Source change history (log.md). The generated change log as Markdown.

    Learn mode presents concepts at useful depths — edited: docs: point live docs, skills and Brain pages at apps/site