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
14 changes: 13 additions & 1 deletion packages/learning/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ node <replica-checkout>/packages/learning/bin/replica-learning.mjs doctor
| `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) |
| `outcomes <memory-id>` | Lists how agents' uses of one learning were scored, oldest first. Each outcome names the version the agent received, the commit it reported, the efficiency from 1 to 4, whether the agent followed the learning, the evaluator's reasoning, and any before and after screenshot. Scores of a version whose evidence no longer permits review are left out |
| `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 |
| `propose-update <memory-id>` | Suggests new wording for an accepted learning when scored uses keep showing the same issue. See [Suggest learning updates](#suggest-learning-updates) |
| `updates <memory-id>` | Lists a learning's suggested updates, oldest first, each `open`, `applied`, `dismissed`, or `stale` |
| `apply-update <proposal-id> --operation-id <uuid>`, `dismiss-update <proposal-id>` | Records a person's decision on a suggested update. `apply-update` makes the suggested wording, or the person's edit of it from `--title-file` and `--content-file`, the learning's next version |
| `delete <memory-id> --reason <text>` | Removes a learning for good: every version, the records of its deliveries and use, their screenshots, and its suggested updates. 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 |
| `mcp` | Serves the learning tools to a coding agent over standard input and output, as [Connect an agent](#connect-an-agent) describes |
Expand Down Expand Up @@ -183,6 +186,7 @@ The JSON Schemas in [`contracts/v1`](contracts/v1) are the normative contract. E
| `guidance`, `delivered-learning` | One recall by an agent, and each learning version it received with its exact text |
| `usage-report`, `used-learning` | An agent's report of which delivered learnings it used for a commit |
| `screenshot` | One screenshot in a usage report, named by the SHA-256 of its PNG bytes |
| `update-proposal`, `update-decision` | Suggested new wording for a learning, with the scores behind it, and a person's decision to apply or dismiss it |
| `audit-entry` | One operation, with IDs and digests but no content |

Each digest is `sha256:` plus the SHA-256 of the record's RFC 8785 canonical JSON. [`contracts/v1/vectors/canonical-json.json`](contracts/v1/vectors/canonical-json.json) holds shared vectors for other languages. Times are UTC with six fractional digits, so text order is time order. [`contracts/v1/examples`](contracts/v1/examples) holds a valid example of every record, and [`contracts/v1/invalid`](contracts/v1/invalid) holds records that must fail, each with its reason.
Expand Down Expand Up @@ -289,6 +293,14 @@ Every score uses the strongest route Copilot offers, so scores stay comparable.

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.

## Suggest learning updates

`replica-learning propose-update <memory-id>` suggests new wording for an accepted learning when scored uses keep showing the same problem. For example, if agents followed "Keep form labels visible" in two Builds but still put labels beside the fields, it might suggest "Show a visible label above every form field" and say why.

Only scores of the current version count, and only scores whose evidence included the Build's diff or a reviewer's confirmation. Each Build counts once, by its commit. Copilot is asked only when, in at least two Builds, the agent followed the learning and still scored 1 or 2 with an issue. It sees the newest 500 issues, groups them, names each group, and drafts the full new wording. A group becomes a suggestion only when it spans at least two Builds, more Builds than went well with a score of 3 or 4, and its wording differs from the current text. A run that finds too little evidence, or no new low or high scores since the last suggestion, spends nothing. A run where Copilot suggests nothing is not recorded, so a host runs it again only after new scores arrive.

A person decides with `apply-update` or `dismiss-update`. Applying records the wording, or the person's edit of it, as the learning's next version, the same way `edit` does. The host names each apply with `--operation-id`, so a retry finishes an apply that stopped partway. A suggestion goes `stale` when the learning changes, when it is no longer accepted, when a score it relied on is gone or no longer shown, when the learning is superseded or in conflict, or when a newer suggestion names the same issue. A dismissed issue is suggested again only with at least two Builds first scored after the dismissal, one confirmed by a reviewer. Drafting needs the evaluation purpose, since it sends the learning to Copilot. The route, usage reporting, and untrusted-input handling match [scoring](#score-applied-learnings).

## 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
108 changes: 108 additions & 0 deletions packages/learning/conformance/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,114 @@ export function memoryProviderConformance({ name, createProvider }) {
assert.equal((await store.verify(designer())).ok, true)
})

it("updates: a suggestion is kept once, replaced, dismissed, or applied as a new version", async (t) => {
const { store, provider, proposal } = await proposed()
if (!supportsIndexedDecisions(provider)) {
t.skip("Provider does not support indexed learning decisions.")
return
}
await store.acceptMemory(designer(), proposal.id, { expectedDigest: proposal.reviewDigest })
const recalled = await store.recall(agent())
for (const [reportId, commit] of [
["change-1", "a"],
["change-2", "b"],
["change-3", "c"],
])
await store.reportUsage(agent(), {
reportId,
guidanceIds: [recalled.guidanceId],
commitSha: commit.repeat(40),
used: [{ deliveryId: recalled.memories[0].deliveryId }],
})
const scores = []
for (const used of await provider.readRecords("usedLearnings", { scope: SCOPE }))
scores.push(
await store.recordScore(agent(), {
usedLearningId: used.id,
operationId: "33333333-3333-4333-8333-333333333333",
efficiency: 2,
followed: "followed",
reasoning: "The agent added labels but put them beside the fields.",
issue: "The rule does not say where the label goes.",
inputs: ["build_diff"],
route: { kind: "fusion", fusionTier: "max" },
}),
)
const { record } = await store.getMemory(designer(), proposal.id)
const update = {
memoryId: proposal.id,
versionDigest: record.digest,
issueKey: "label-placement",
issue: "The rule does not say where the label goes.",
content: "Show a visible label above every form field.",
reasoning: "Naming the position removes the guess.",
support: scores.slice(0, 2).map((item) => item.id),
route: { kind: "fusion", fusionTier: "max" },
}
const operationId = "55555555-5555-4555-8555-555555555555"

const first = await store.proposeUpdate(agent(), update)
const again = await store.proposeUpdate(agent(), { ...update, content: "Other wording." })
const other = await store.proposeUpdate(agent(), { ...update, issueKey: "label-contrast" })
const dismissed = await store.dismissUpdate(designer(), other.id, { reason: "Not it." })
const redismissed = await store.dismissUpdate(designer(), other.id, { reason: "Not it." })
// A newer suggestion for the same issue replaces the first one.
const newer = await store.proposeUpdate(agent(), {
...update,
support: scores.map((item) => item.id),
})
// The edit lands but saving the decision fails, so a retry must finish the apply.
const append = provider.appendBatch
provider.appendBatch = async (batch, options) => {
if (batch.updateDecisions) throw new Error("The decision could not be saved.")
return append.call(provider, batch, options)
}
const decision = { reason: "Matches reviews.", content: "Put a label above each field." }
await assert.rejects(
store.applyUpdate(designer(), newer.id, { ...decision, operationId }),
/could not be saved/,
)
provider.appendBatch = append
await assert.rejects(
store.applyUpdate(designer(), newer.id, {
...decision,
operationId: "66666666-6666-4666-8666-666666666666",
}),
{ code: "invalid_transition" },
)
const applied = await store.applyUpdate(designer(), newer.id, { ...decision, operationId })

assert.deepEqual([first.stored, again.stored], [true, false])
assert.equal(again.proposal.content, update.content)
assert.deepEqual([dismissed.stored, redismissed.stored], [true, false])
assert.equal(applied.memory.version, record.version + 1)
assert.equal(applied.memory.content, decision.content)
assert.equal((await store.getMemory(designer(), proposal.id)).record.version, record.version + 1)
assert.deepEqual(
(await store.updatesFor(designer(), { memoryId: proposal.id })).map((item) => [
item.id,
item.state,
item.decision?.appliedVersion,
]),
[
[first.id, "stale", undefined],
[other.id, "dismissed", undefined],
[newer.id, "applied", record.version + 1],
],
)
await assert.rejects(
store.applyUpdate(designer(), other.id, {
reason: "Changed my mind.",
operationId: "77777777-7777-4777-8777-777777777777",
}),
{ code: "invalid_transition" },
)
await assert.rejects(store.proposeUpdate(agent(), { ...update, issueKey: "late" }), {
code: "stale_review",
})
assert.equal((await store.verify(designer())).ok, true)
})

it("deletion: a deleted learning takes its usage records, and old guidance expires", async (t) => {
let now = NOW
const { store, provider, proposal } = await proposed(undefined, undefined)
Expand Down
6 changes: 5 additions & 1 deletion packages/learning/contracts/v1/audit-entry.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"memory.delete",
"usage.report",
"usage.score",
"update.propose",
"update.decide",
"guidance.expire",
"export.create"
]
Expand Down Expand Up @@ -70,7 +72,9 @@
"usage_report",
"used_learning",
"screenshot",
"score"
"score",
"update_proposal",
"update_decision"
]
},
"id": { "$ref": "common.schema.json#/$defs/id" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"schemaVersion": "replica.update-decision/v1",
"id": "update_decision_4f8b2c6e0a1d3e5f7b9c1a3e",
"scope": {
"host": "github.com",
"repository": "acme/checkout-prototypes"
},
"proposalId": "update_7a3e91c04b2d58f6e1a0c3b9",
"memoryId": "memory_3c1f0a9b8e7d6c5b4a392817",
"decision": "applied",
"appliedVersion": 3,
"reason": "The suggested wording matches what reviewers asked for.",
"decidedBy": {
"kind": "human",
"id": "github:mona"
},
"decidedAt": "2026-10-14T09:30:00.000000Z",
"digest": "sha256:fddda0edca3fe83e5765b821ea1c0dd105627885bbf8f7216d648ce08f7e71c6"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"schemaVersion": "replica.update-proposal/v1",
"id": "update_7a3e91c04b2d58f6e1a0c3b9",
"scope": {
"host": "github.com",
"repository": "acme/checkout-prototypes"
},
"memoryId": "memory_3c1f0a9b8e7d6c5b4a392817",
"version": 2,
"versionDigest": "sha256:2f7c1b9e0d4a8c6e3b5f7a9d1c3e5b7f9a1c3e5d7b9f1a3c5e7d9b1f3a5c7e9d",
"issueKey": "label-placement",
"issue": "The learning does not say where labels go, so side labels broke narrow layouts.",
"content": "Show a visible label above every form field, never beside it, so forms fit narrow screens.",
"reasoning": "Two Builds placed labels beside fields and had to rework narrow layouts; naming the position removes the guess.",
"support": [
"score_5d0e2a7c41b98f3e6a2d1c09",
"score_9b1c4e7a2d5f8036c1e4a7b0"
],
"counter": [
"score_0e3a6c9f2b5d8e1a4c7f0b3d"
],
"route": {
"kind": "fusion",
"fusionTier": "max"
},
"proposedBy": {
"kind": "agent",
"id": "agent:copilot"
},
"proposedAt": "2026-10-13T06:00:00.000000Z",
"digest": "sha256:921cbd69f8b73d20ba87763ad8e1b8eed37e0713f1303f076aa3bacd88c7cf31"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"kind": "updateDecision",
"reason": "An applied update names the version its wording became, so the history can link them.",
"expect": "must have required property 'appliedVersion'",
"record": {
"schemaVersion": "replica.update-decision/v1",
"id": "update_decision_4f8b2c6e0a1d3e5f7b9c1a3e",
"scope": {
"host": "github.com",
"repository": "acme/checkout-prototypes"
},
"proposalId": "update_7a3e91c04b2d58f6e1a0c3b9",
"memoryId": "memory_3c1f0a9b8e7d6c5b4a392817",
"decision": "applied",
"reason": "The suggested wording matches what reviewers asked for.",
"decidedBy": {
"kind": "human",
"id": "github:mona"
},
"decidedAt": "2026-10-14T09:30:00.000000Z",
"digest": "sha256:395093346b0e017af2b716634a027bd8ea01a50a253ffa42e728b6f0774e8742"
}
}
65 changes: 65 additions & 0 deletions packages/learning/contracts/v1/update-decision.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://github.com/github/replica/learning/v1/update-decision.schema.json",
"title": "Replica update decision v1",
"description": "A person's decision on one update proposal: applied as a new version of the learning, or dismissed.",
"type": "object",
"additionalProperties": false,
"required": [
"schemaVersion",
"id",
"scope",
"proposalId",
"memoryId",
"decision",
"reason",
"decidedBy",
"decidedAt",
"digest"
],
"if": {
"properties": { "decision": { "const": "applied" } }
},
"then": {
"required": ["appliedVersion"]
},
"properties": {
"schemaVersion": {
"const": "replica.update-decision/v1"
},
"id": {
"$ref": "common.schema.json#/$defs/id"
},
"scope": {
"$ref": "common.schema.json#/$defs/scope"
},
"proposalId": {
"$ref": "common.schema.json#/$defs/id"
},
"memoryId": {
"$ref": "common.schema.json#/$defs/id"
},
"decision": {
"enum": ["applied", "dismissed"]
},
"appliedVersion": {
"description": "The learning version the applied wording became.",
"type": "integer",
"minimum": 2
},
"reason": {
"type": "string",
"minLength": 1,
"maxLength": 2000
},
"decidedBy": {
"$ref": "common.schema.json#/$defs/humanActor"
},
"decidedAt": {
"$ref": "common.schema.json#/$defs/timestamp"
},
"digest": {
"$ref": "common.schema.json#/$defs/digest"
}
}
}
Loading
Loading