Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/learning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ node <replica-checkout>/packages/learning/bin/replica-learning.mjs doctor
| `recall --task <text>` | Prints the accepted learnings for the next run. `--task-file -` reads the task from standard input instead, which keeps a person's prompt out of the process list. `--session-id` and `--session-label` name the agent session asking. Each recall stores a guidance record and the exact text of each learning it gave, so a later report can name them. `--preview --by github:<login>` shows a person the same text without recording a use. Only a person can preview, so an agent never reads learnings without an audit entry. A host such as Hub adds learnings other repositories shared to a preview with `--shared-file`, a JSON list of their accepted records read from their own stores. Recall refuses a damaged, unaccepted, or same-repository record. It leaves out a shared learning whose ID matches one of the repository's own, and keeps one copy of an ID that two sources share. A recall that stores deliveries refuses shared learnings, because a stored copy would outlive the source's deletion |
| `report-usage <report.json>` | Records which recalled learnings an agent says it used for a commit. The report names its own `reportId`, so sending it again stores nothing new. Each used learning names the `deliveryId` recall gave it, and may add a before and an after screenshot as a PNG file beside the report. Only each screenshot's digest is recorded; in a local store the bytes are kept under `evidence/` in the learning data directory. A hosted store keeps no bytes and accepts screenshots only with `--grant <id>`, an active grant for `evaluation` that lists the `agent_screenshots` source. A report is the agent's claim, never a verified result |
| `usage --commit <sha>` | Lists the usage reports for one full commit SHA. Each used learning names its ID, the version the agent received, its title and text, and the digest, capture details, and consent grant of any before and after screenshot. Title and text are empty once the learning's evidence no longer allows review. A host uses it to show what was applied in the Build made from that commit |
| `score <used-learning-id> --operation-id <uuid>` | Asks Copilot how efficiently one used learning helped, from 1 to 4, and whether the agent followed it, then keeps the score. See [Score applied learnings](#score-applied-learnings) |
| `delete <memory-id> --reason <text>` | Removes a learning for good: every version, the records of its deliveries and use, and their screenshots. A learning that is part of a replacement, or that a stored proposal would replace, cannot be deleted; retire it instead |
| `expire-guidance [--days <n>]` | Removes guidance records older than `--days`, 365 by default, that no usage report names |
| `delete-repository --confirm <owner/name>` | Removes every record this repository's store holds, including its audit trail. Naming the repository again guards against deleting the wrong store. Copies outside the store, such as exports, are not touched |
Expand Down Expand Up @@ -272,6 +273,21 @@ A labeler failure remains the primary error even if the usage attached to it is

To use another labeler, set `labeling.labeler` to `{ "module": "./path.mjs" }` exporting `createLabeler(options)`. A labeler returns labels for the comments it was asked about; the types are `MemoryLabeler` in [`index.d.mts`](index.d.mts).

## Score applied learnings

`replica-learning score <used-learning-id> --operation-id <uuid>` asks Copilot to judge one learning an agent said it used. For example, after an agent reports that "Keep form labels visible" shaped commit `a1b2c3`, the score says whether the agent followed it and how efficiently it led to good work:

1. Not efficient at all.
2. Slightly efficient.
3. Mostly efficient.
4. Highly efficient.

A score of 1 or 2 also names the main issue. A learning is scored only while the review evidence behind the version the agent received is allowed for evaluation; otherwise the command fails with `unavailable` and spends nothing. Copilot sees the learning text the agent received, the usage report, and the screenshots whose consent still allows evaluation. `--diff-file <file>` adds the Build's diff, cut at 200,000 characters. A hosted store keeps no screenshot bytes, so the host writes them to a directory as `<sha256 hex>.png` and names it with `--screenshots <dir>`.

Every score uses the strongest route Copilot offers, so scores stay comparable. It asks for Copilot Fusion at its max tier first. When Fusion is unavailable or does not take effect, it asks Copilot Auto which model it would choose and uses that model at its highest reasoning effort. Each score records the route it used. Inputs are treated as untrusted data, and the session has no tools, as in labeling.

The host names each attempt with `--operation-id`, so a retry keeps the first score. The output includes the usage in AI credits; with `--json`, a failed attempt still prints the usage it spent, so a host can keep to its budget. Deleting a learning deletes its scores.

## Bring your own consolidator

A consolidator has a `manifest` and `consolidate(request, view)`. It reads a frozen view of the evidence the purpose may use and returns proposals and diagnostics. The view shows a memory's content, evidence, and counterevidence only while its evidence permits the purpose. The store gives a consolidator no write access and saves everything it returns as proposed, up to the run's cap on new or changed proposals. A proposal it already holds unchanged does not count against the cap, so a consolidator should return every proposal it would make. A consolidator is code you choose to run; the frozen view is not a sandbox. Select one with `consolidation.consolidator` in the config, using `"recurrence"` (the default), `"none"`, or `{ "module": "./path.mjs" }` exporting `createConsolidator(options, builtins)`. `builtins` holds `createRecurrenceConsolidator` and `createNoopConsolidator`, so a module can build on them without importing this package.
Expand Down
44 changes: 42 additions & 2 deletions packages/learning/conformance/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,7 @@ export function memoryProviderConformance({ name, createProvider }) {
assert.equal((await store.getMemory(designer(), first.id)).status.superseded, true)
})

it("usage: recall records what an agent got, and a report is stored once", async () => {
it("usage: recall records what an agent got, and a report and score are stored once", async () => {
const { store, provider, proposal } = await proposed()
await store.acceptMemory(designer(), proposal.id, { expectedDigest: proposal.reviewDigest })

Expand All @@ -1584,6 +1584,37 @@ export function memoryProviderConformance({ name, createProvider }) {
})
const [used] = await provider.readRecords("usedLearnings", { scope: SCOPE })
assert.equal(used.memoryId, proposal.id)
const score = {
usedLearningId: used.id,
operationId: "33333333-3333-4333-8333-333333333333",
efficiency: 2,
followed: "followed",
reasoning: "The label stayed visible, but the agent rebuilt the field twice.",
issue: "The rule did not say where the label goes.",
route: { kind: "fusion", fusionTier: "max" },
}
const scored = await store.recordScore(agent(), score)
const rescored = await store.recordScore(agent(), { ...score, efficiency: 4 })
assert.deepEqual([scored.stored, rescored.stored], [true, false])
assert.equal(rescored.score.efficiency, 2)
const raced = await Promise.all(
[3, 4].map((efficiency) =>
store.recordScore(agent(), {
...score,
operationId: "44444444-4444-4444-8444-444444444444",
efficiency,
}),
),
)
assert.deepEqual(raced.map((result) => result.stored).sort(), [false, true])
assert.equal(raced[0].score.digest, raced[1].score.digest)
// Review comments were shared for review and instruction only, not evaluation.
await assert.rejects(store.evaluationInputs(agent(), { usedLearningId: used.id }), {
code: "unavailable",
})
await store.addGrant(designer(), { ...grantInput(), purposes: ["evaluation"] })
const inputs = await store.evaluationInputs(agent(), { usedLearningId: used.id })
assert.equal(inputs.learning.text, delivery.text)
assert.equal((await store.verify(designer())).ok, true)
})

Expand All @@ -1603,12 +1634,21 @@ export function memoryProviderConformance({ name, createProvider }) {
commitSha: "a".repeat(40),
used: [{ deliveryId: recalled.memories[0].deliveryId }],
})
const [used] = await provider.readRecords("usedLearnings", { scope: SCOPE })
await clocked.recordScore(agent(), {
usedLearningId: used.id,
operationId: "33333333-3333-4333-8333-333333333333",
efficiency: 4,
followed: "followed",
reasoning: "The agent kept the label visible on the first try.",
route: { kind: "auto", model: "gpt-test", reasoningEffort: "high" },
})

await clocked.deleteMemory(designer(), proposal.id, { reason: "The rule was wrong." })
now += 366 * 24 * 60 * 60 * 1000
const expired = await clocked.expireGuidance(designer())

for (const stream of ["deliveries", "usedLearnings", "usageReports", "guidance"])
for (const stream of ["deliveries", "usedLearnings", "usageReports", "scores", "guidance"])
assert.deepEqual(await provider.readRecords(stream, { scope: SCOPE }), [], stream)
assert.equal(expired.records.guidance, 1)
assert.equal(
Expand Down
4 changes: 3 additions & 1 deletion packages/learning/contracts/v1/audit-entry.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"memory.recall",
"memory.delete",
"usage.report",
"usage.score",
"guidance.expire",
"export.create"
]
Expand Down Expand Up @@ -68,7 +69,8 @@
"delivery",
"usage_report",
"used_learning",
"screenshot"
"screenshot",
"score"
]
},
"id": { "$ref": "common.schema.json#/$defs/id" },
Expand Down
30 changes: 30 additions & 0 deletions packages/learning/contracts/v1/examples/score.example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"schemaVersion": "replica.score/v1",
"id": "score_5d0e2a7c41b98f3e6a2d1c09",
"scope": {
"host": "github.com",
"repository": "acme/checkout-prototypes"
},
"usedLearningId": "used_86cb6647d216cf8e3de96d55",
"usageReportId": "usage_c980d22472110f3f8aa8184f",
"memoryId": "memory_3c1f0a9b8e7d6c5b4a392817",
"operationId": "5b1f8f0e-6a8c-4c2e-9d3a-0f6e2b7c9a41",
"rubricVersion": "replica.efficiency-rubric/v1",
"efficiency": 2,
"followed": "followed",
"reasoning": "Every field gained a visible label, but the labels sit beside the fields and the form needed rework to fit narrow screens.",
"issue": "The learning does not say where labels go, so side labels broke narrow layouts.",
"inputs": [
"build_diff"
],
"route": {
"kind": "fusion",
"fusionTier": "max"
},
"scoredBy": {
"kind": "agent",
"id": "agent:copilot"
},
"scoredAt": "2026-10-12T10:20:00.000000Z",
"digest": "sha256:aa391a0bb6c512697a6534a9e1f8a9e57024e7359ddbfacecc130f35f73c3526"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"kind": "score",
"reason": "A score of 1 or 2 says what went wrong, so later proposals can group the same issue.",
"expect": "must have required property 'issue'",
"record": {
"schemaVersion": "replica.score/v1",
"id": "score_5d0e2a7c41b98f3e6a2d1c09",
"scope": {
"host": "github.com",
"repository": "acme/checkout-prototypes"
},
"usedLearningId": "used_86cb6647d216cf8e3de96d55",
"usageReportId": "usage_c980d22472110f3f8aa8184f",
"memoryId": "memory_3c1f0a9b8e7d6c5b4a392817",
"operationId": "5b1f8f0e-6a8c-4c2e-9d3a-0f6e2b7c9a41",
"rubricVersion": "replica.efficiency-rubric/v1",
"efficiency": 2,
"followed": "followed",
"reasoning": "Every field gained a visible label, but the labels sit beside the fields and the form needed rework to fit narrow screens.",
"inputs": [
"build_diff"
],
"route": {
"kind": "fusion",
"fusionTier": "max"
},
"scoredBy": {
"kind": "agent",
"id": "agent:copilot"
},
"scoredAt": "2026-10-12T10:20:00.000000Z",
"digest": "sha256:9292035a7e52df4de970a81f5ea80ea3044909180fdc960677a40c721190da97"
}
}
110 changes: 110 additions & 0 deletions packages/learning/contracts/v1/score.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/github/replica/learning/v1/score.schema.json",
"title": "Replica score v1",
"description": "A model's judgment of how much one used learning helped the Build it was used for. It is evidence for a person, never a decision.",
"type": "object",
"additionalProperties": false,
"required": [
"schemaVersion",
"id",
"scope",
"usedLearningId",
"usageReportId",
"memoryId",
"operationId",
"rubricVersion",
"efficiency",
"followed",
"reasoning",
"inputs",
"route",
"scoredBy",
"scoredAt",
"digest"
],
"if": {
"properties": { "efficiency": { "enum": [1, 2] } }
},
"then": {
"required": ["issue"]
},
"properties": {
"schemaVersion": {
"const": "replica.score/v1"
},
"id": {
"$ref": "common.schema.json#/$defs/id"
},
"scope": {
"$ref": "common.schema.json#/$defs/scope"
},
"usedLearningId": {
"$ref": "common.schema.json#/$defs/id"
},
"usageReportId": {
"$ref": "common.schema.json#/$defs/id"
},
"memoryId": {
"$ref": "common.schema.json#/$defs/id"
},
"operationId": {
"description": "The host's ID for this scoring attempt, so a retry stores one score.",
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
},
"rubricVersion": {
"const": "replica.efficiency-rubric/v1"
},
"efficiency": {
"description": "1 not efficient at all, 2 slightly, 3 mostly, 4 highly efficient.",
"type": "integer",
"minimum": 1,
"maximum": 4
},
"followed": {
"description": "Whether the Build followed the learning, judged apart from the score.",
"enum": ["followed", "not_followed", "unclear"]
},
"reasoning": {
"type": "string",
"minLength": 1,
"maxLength": 4000
},
"issue": {
"description": "What went wrong, as one reusable sentence, when the score is 1 or 2.",
"type": "string",
"minLength": 1,
"maxLength": 500
},
"inputs": {
"description": "What the model saw besides the learning and the usage report.",
"type": "array",
"maxItems": 2,
"items": {
"enum": ["screenshots", "build_diff"]
}
},
"route": {
"description": "How the model was chosen: Copilot Fusion at a tier, or Auto at a reasoning effort.",
"type": "object",
"additionalProperties": false,
"required": ["kind"],
"properties": {
"kind": { "enum": ["fusion", "auto"] },
"fusionTier": { "type": "string", "minLength": 1, "maxLength": 50 },
"model": { "type": "string", "minLength": 1, "maxLength": 200 },
"reasoningEffort": { "type": "string", "minLength": 1, "maxLength": 50 }
}
},
"scoredBy": {
"$ref": "common.schema.json#/$defs/actor"
},
"scoredAt": {
"$ref": "common.schema.json#/$defs/timestamp"
},
"digest": {
"$ref": "common.schema.json#/$defs/digest"
}
}
}
Loading
Loading