+ agentConnections?: AgentConnectionRouteDependencies
agentVisualCritic?: AgentVisualCriticRouteDependencies
authentication?: AuthenticationRouteDependencies
copilotConnection?: CopilotConnectionRouteDependencies
diff --git a/hub/vite.config.ts b/hub/vite.config.ts
index ed83c66cb..48d51024b 100644
--- a/hub/vite.config.ts
+++ b/hub/vite.config.ts
@@ -8,6 +8,14 @@ import {
controlsValidatorPath,
} from "./controls-validator-plugin.ts"
+// Agents reach the MCP and OAuth endpoints at the root, so these go to Express too.
+const hubProxy = {
+ "/api": { target: "http://127.0.0.1:3001", ws: true },
+ "^/(?:mcp|register|authorize|token|revoke|\\.well-known/oauth-[a-z-]+)(?:/|$)": {
+ target: "http://127.0.0.1:3001",
+ },
+}
+
export default defineConfig({
plugins: [reactRouter(), controlsValidatorPlugin()],
ssr: {
@@ -20,12 +28,12 @@ export default defineConfig({
server: {
port: 5173,
strictPort: true,
- proxy: { "/api": { target: "http://127.0.0.1:3001", ws: true } },
+ proxy: hubProxy,
},
preview: {
port: 5173,
strictPort: true,
- proxy: { "/api": { target: "http://127.0.0.1:3001", ws: true } },
+ proxy: hubProxy,
},
resolve: { alias: { ...viteAliases, [controlsValidatorModule]: controlsValidatorPath } },
optimizeDeps: { include: [controlsValidatorModule] },
diff --git a/packages/learning/README.md b/packages/learning/README.md
index 88dd05506..c9e7d977b 100644
--- a/packages/learning/README.md
+++ b/packages/learning/README.md
@@ -136,7 +136,7 @@ The agent gets these tools:
The server tells the agent when to call each tool. Errors that aren't learning refusals reach the agent as a generic message, and their cause is written to the server's standard error. Copilot CLI passes a server's instructions to the model only when the server is allowlisted or you start it with `--allow-all-mcp-server-instructions`, so the tool descriptions repeat what matters. The agent acts as `--actor`, `agent:mcp` by default. It can never accept, reject, edit, or delete a learning.
-Hosts such as Hub can serve the same tools by importing `createLearningMcpServer` from `@github/replica-learning/mcp` and passing their own backend. The tools and their wording then stay the same everywhere.
+Hosts such as Hub can serve the same tools by importing `createLearningMcpServer` from `@github/replica-learning/mcp` and passing their own backend. The tools and their wording then stay the same everywhere. The module also exports `LearningError`; throw it from the backend to give the agent a code and message.
## Rules
@@ -160,7 +160,7 @@ Hosts such as Hub can serve the same tools by importing `createLearningMcpServer
- Damaged records stop the operations that read them. If a grant, withdrawal, episode, event, or collection that an operation reads fails its schema, digest, or scope check, that operation refuses to run until `verify` finds the damage and someone repairs it. Learning decisions read only the records tied to their evidence, so damage elsewhere in the store does not block them. `verify` still checks every record. A damaged learning is never used, and reading it shows only its ID, state, kind, theme, and digests, each strictly checked. These checks catch altered records; they cannot catch a provider that omits or replays whole records.
- Comment text is data. It never changes settings or decisions, terminal output quotes it, and recall never includes raw comments. Input JSON that repeats a member name is refused.
- Recall writes each learning as plain lines of data, with the learning's text quoted as a JSON string. Every field, including who accepted the learning, has its line breaks turned into spaces and its control characters and invisible formatting characters removed: zero-width characters, tag characters, and marks that reorder text. The store refuses a person or agent ID that contains such characters, and the v1 schemas refuse a record with such an actor ID, so an ID reads the same everywhere it is shown. The character budget includes the full heading, framing, quotes, and newlines. A budget too small for the required framing is refused with the minimum it needs; recall never cuts off the framing or returns oversized text.
-- Reading a learning is a use. `show` and `memories` read for review; when a learning's evidence no longer permits review, they withhold its content, evidence, and rationale. `show --history` checks each version on its own, so an older version whose evidence or counterevidence no longer permits review shows only its state and digests.
+- Reading a learning is a use. `show` and `memories` read for review; when a learning's evidence no longer permits review, they withhold its content, evidence, and rationale. Add `--purpose instruction` to see exactly what an agent may read. `show --history` checks each version on its own, so an older version whose evidence or counterevidence no longer permits review shows only its state and digests.
## Contracts
diff --git a/packages/learning/mcp.d.mts b/packages/learning/mcp.d.mts
index 09d93107f..574ea1f4a 100644
--- a/packages/learning/mcp.d.mts
+++ b/packages/learning/mcp.d.mts
@@ -1,6 +1,8 @@
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import type { MemoryReading } from "./index.mjs"
+export { LearningError } from "./index.mjs"
+
/**
* What a host supplies to serve the learning tools. Each method receives the tool's
* checked input and returns the JSON the agent sees. Throw a LearningError to give the
diff --git a/packages/learning/src/cli.mjs b/packages/learning/src/cli.mjs
index ebd4ecbb5..6ba474508 100644
--- a/packages/learning/src/cli.mjs
+++ b/packages/learning/src/cli.mjs
@@ -40,8 +40,11 @@ Inspect
observations [--purpose ] [--event ]...
Evidence a purpose may use now; select up to
100 event IDs and only their containing episodes
- memories [--state ]... Learnings with their state and whether they are recalled
- show [--history] One learning, its evidence, and its digests
+ memories [--state ]... [--purpose ]
+ Learnings with their state and whether they are
+ recalled; --purpose instruction shows what agents see
+ show [--history] [--purpose ]
+ One learning, its evidence, and its digests
operation-status --operation-id
Whether one host decision operation is in intact history
verify Re-check every record's schema, digest, and history
@@ -1029,6 +1032,7 @@ async function memories(session) {
const { store } = await open(session)
const items = await store.queryMemory(context(session, actor(session)), {
states: session.values.state,
+ purpose: single(session.values.purpose, "--purpose") ?? "review",
})
session.out(
items,
@@ -1051,6 +1055,7 @@ async function show(session) {
const { store } = await open(session)
const item = await store.getMemory(context(session, actor(session)), id, {
history: Boolean(session.values.history),
+ purpose: single(session.values.purpose, "--purpose") ?? "review",
})
const { record, status } = item
const head = [
diff --git a/packages/learning/src/mcp.mjs b/packages/learning/src/mcp.mjs
index 033417e61..0e570ea97 100644
--- a/packages/learning/src/mcp.mjs
+++ b/packages/learning/src/mcp.mjs
@@ -2,6 +2,9 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"
import { z } from "zod"
import { LearningError } from "./errors.mjs"
+// Agents see a code and message only for this exact class, so hosts need it too.
+export { LearningError }
+
const INSTRUCTIONS = `This server holds the learnings a team accepted from past reviews of its prototypes.
Before you start a task, call get_guidance with a short description of the task and follow the learnings it returns. Keep its guidanceId and each learning's deliveryId.
diff --git a/packages/learning/test/cli.test.mjs b/packages/learning/test/cli.test.mjs
index 3d0df2247..68885d2c7 100644
--- a/packages/learning/test/cli.test.mjs
+++ b/packages/learning/test/cli.test.mjs
@@ -1163,6 +1163,27 @@ describe("replica-learning CLI: guard rails", () => {
assert.match(refused.stderr, /invalid_input.*budget must be at least/)
})
+ it("shows people a learning that agents can no longer read", async () => {
+ const repo = checkout("purpose-reading")
+ const { grant, proposal } = await learnFromReviews(repo)
+ await ok(repo, [
+ "grants",
+ "withdraw",
+ grant.id,
+ "--purpose",
+ "instruction",
+ "--by",
+ "github:ana-designer",
+ ])
+
+ const forPeople = (await ok(repo, ["memories", "--json"])).json()
+ assert.equal(forPeople[0].withheld, false)
+ const forAgents = (await ok(repo, ["memories", "--purpose", "instruction", "--json"])).json()
+ assert.equal(forAgents[0].withheld, true)
+ const shown = await ok(repo, ["show", proposal.id, "--purpose", "instruction"])
+ assert.match(shown.stdout, /Content, evidence, and rationale are withheld/)
+ })
+
it("rejects usage errors with exit code 2", async () => {
const repo = checkout("usage")
assert.equal((await cli(repo, [])).code, 2)