A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fold the per-kind harness CRUD wrappers into create_memory/update_memory/delete_memory (#2154)
Sebastian Müllerd41a06154c71
diff --git a/packages/coding-agent/.changes/res-1336-harness-crud-trio.md b/packages/coding-agent/.changes/res-1336-harness-crud-trio.mdnew file mode 100644index 0000000000..6fd0e06547--- /dev/null+++ b/packages/coding-agent/.changes/res-1336-harness-crud-trio.md@@ -0,0 +1,2 @@+- Folded the twelve per-kind continual-harness CRUD methods into three: `rlm.harness.create_memory(title, content, kind=...)`, `rlm.harness.update_memory(id, title, content, kind=...)`, and `rlm.harness.delete_memory(id, kind=...)`. Prompt notes, skills, and subagent specs are subtypes of memory, so `kind` selects them; it defaults to `memory`, only skill entries accept `reference`/`arguments`, the nine removed names raise an error naming their replacement, and the positional-kind `create`/`update`/`delete` methods are removed as well.+- Renamed the harness entry grouping from `path` to `topic` in the kernel API, the refinement planner schema, and the harness digest; state files written before the rename still load, and saves keep writing the grouping under both names while older builds can still reach the shared global store.diff --git a/packages/coding-agent/docs/rlm-runtime.md b/packages/coding-agent/docs/rlm-runtime.mdindex a9c1e56e4f..61b0377eef 100644--- a/packages/coding-agent/docs/rlm-runtime.md+++ b/packages/coding-agent/docs/rlm-runtime.md@@ -188,6 +188,8 @@ On reload, the aggregate is reapplied to the parent message. Context-tree report`rlm.harness` is a persisted state ledger for prompt notes, memories, reusable skill descriptions, sub-agent specifications, and refinement events. It is not a second execution engine.+Entries are written with three calls: `rlm.harness.create_memory(title, content, kind=...)`, `rlm.harness.update_memory(id, title, content, kind=...)`, and `rlm.harness.delete_memory(id, kind=...)`. Prompt notes, skills, and subagent specs are subtypes of memory, so one method per operation covers every kind. `kind` is `prompt`, `memory`, `skill`, or `subagent` and defaults to `memory`; `topic=` groups entries; only skill entries accept `reference=` and `arguments=`.+Session-local state lives in the session artifact directory under `harness/harness_state.json`. Explicitly global entries live under `~/.prime/agent/harness/`. The Python store reloads after external modification so host-side `/refine` writes and kernel writes do not overwrite each other.`/refine` runs a dedicated review over the current trajectory and applies small create/update/delete edits. Rollback uses recorded before/after snapshots. The base system prompt remains immutable; refinements are supplemental state.diff --git a/packages/coding-agent/src/core/kernel/bootstrap.ts b/packages/coding-agent/src/core/kernel/bootstrap.tsindex dd56934df1..d33bfd5c9d 100644--- a/packages/coding-agent/src/core/kernel/bootstrap.ts+++ b/packages/coding-agent/src/core/kernel/bootstrap.ts@@ -80,22 +80,8 @@ const REQUIRED_MCP_DISCOVERY_METHODS = ["search_tools","describe_tool",];-const REQUIRED_HARNESS_METHODS = [- "create_memory",- "update_memory",- "delete_memory",- "create_skill",- "update_skill",- "delete_skill",- "create_subagent",- "update_subagent",- "delete_subagent",- "create_prompt_note",- "update_prompt_note",- "delete_prompt_note",- "record_refinement",-];-export const RUNTIME_READY_CHECK = `import inspect; import rlm; from rlm import McpIntegration; import rlm.mcp as mcp; from rlm.harness import HarnessEntry; _harness_methods = ${JSON.stringify(REQUIRED_HARNESS_METHODS)}; assert callable(mcp.list_tools); assert callable(mcp.call_tool); assert all(callable(getattr(mcp, _m, None)) for _m in ${JSON.stringify(REQUIRED_MCP_DISCOVERY_METHODS)}), "rlm.mcp is missing MCP discovery methods (list_plugins, search_plugins, list_connections, search_tools, describe_tool); the kernel venv needs a current prime-agent-runtime"; assert callable(rlm.spawn); assert hasattr(rlm, 'rlm'); assert callable(rlm.rlm.spawn); assert inspect.signature(rlm.spawn).parameters['name'].default is inspect.Parameter.empty; assert not hasattr(rlm, 'run'); assert not hasattr(rlm.rlm, 'run'); assert callable(rlm.host_request); assert callable(rlm.find_models); assert callable(rlm.rlm.find_models); assert callable(rlm.create_session); assert callable(rlm.rlm.create_session); assert callable(rlm.progress_note); assert callable(rlm.rlm.progress_note); assert hasattr(rlm, 'harness'); assert hasattr(rlm, 'get_harness_state'); assert hasattr(rlm.rlm, 'harness'); assert hasattr(rlm.rlm, 'get_harness_state'); assert all(callable(getattr(_harness, _method, None)) for _harness in (rlm.harness, rlm.rlm.harness) for _method in _harness_methods); assert 'reference' in HarnessEntry.__dataclass_fields__; assert 'scope' in HarnessEntry.__dataclass_fields__; assert 'reference' in inspect.signature(rlm.harness.create_skill).parameters; assert 'reference' in inspect.signature(rlm.harness.update_skill).parameters; assert 'global_' in inspect.signature(rlm.harness.create_memory).parameters; assert 'global_' in inspect.signature(rlm.get_harness_state).parameters; assert not hasattr(rlm, 'background'); assert not hasattr(rlm.rlm, 'background'); from rlm.bash import BashHandle, BashResult; assert callable(rlm.bash); assert all(callable(getattr(BashHandle, _m, None)) for _m in ('tail', 'output', 'poll', 'kill')); assert {'exit_code', 'output', 'duration'} <= set(BashResult.__dataclass_fields__); import rlm.repl as _repl; assert callable(_repl.main); assert callable(_repl.emit); assert callable(_repl.host_request); assert callable(_repl.is_active); assert _repl.PROTOCOL_VERSION == 3; assert callable(rlm.emit); assert not hasattr(rlm, 'HOST_COMM_TARGET'); assert not hasattr(mcp, 'install_shutdown_hook')`;+const REQUIRED_HARNESS_METHODS = ["create_memory", "update_memory", "delete_memory", "record_refinement"];+export const RUNTIME_READY_CHECK = `import inspect; import rlm; from rlm import McpIntegration; import rlm.mcp as mcp; from rlm.harness import HarnessEntry; _harness_methods = ${JSON.stringify(REQUIRED_HARNESS_METHODS)}; assert callable(mcp.list_tools); assert callable(mcp.call_tool); assert all(callable(getattr(mcp, _m, None)) for _m in ${JSON.stringify(REQUIRED_MCP_DISCOVERY_METHODS)}), "rlm.mcp is missing MCP discovery methods (list_plugins, search_plugins, list_connections, search_tools, describe_tool); the kernel venv needs a current prime-agent-runtime"; assert callable(rlm.spawn); assert hasattr(rlm, 'rlm'); assert callable(rlm.rlm.spawn); assert inspect.signature(rlm.spawn).parameters['name'].default is inspect.Parameter.empty; assert not hasattr(rlm, 'run'); assert not hasattr(rlm.rlm, 'run'); assert callable(rlm.host_request); assert callable(rlm.find_models); assert callable(rlm.rlm.find_models); assert callable(rlm.create_session); assert callable(rlm.rlm.create_session); assert callable(rlm.progress_note); assert callable(rlm.rlm.progress_note); assert hasattr(rlm, 'harness'); assert hasattr(rlm, 'get_harness_state'); assert hasattr(rlm.rlm, 'harness'); assert hasattr(rlm.rlm, 'get_harness_state'); assert all(callable(getattr(_harness, _method, None)) for _harness in (rlm.harness, rlm.rlm.harness) for _method in _harness_methods); assert 'reference' in HarnessEntry.__dataclass_fields__; assert 'scope' in HarnessEntry.__dataclass_fields__; assert 'topic' in HarnessEntry.__dataclass_fields__; assert {'kind', 'topic', 'reference', 'arguments', 'global_'} <= set(inspect.signature(rlm.harness.create_memory).parameters); assert {'kind', 'topic', 'reference', 'arguments', 'global_'} <= set(inspect.signature(rlm.harness.update_memory).parameters); assert {'kind', 'global_'} <= set(inspect.signature(rlm.harness.delete_memory).parameters); assert 'global_' in inspect.signature(rlm.get_harness_state).parameters; assert not hasattr(rlm, 'background'); assert not hasattr(rlm.rlm, 'background'); from rlm.bash import BashHandle, BashResult; assert callable(rlm.bash); assert all(callable(getattr(BashHandle, _m, None)) for _m in ('tail', 'output', 'poll', 'kill')); assert {'exit_code', 'output', 'duration'} <= set(BashResult.__dataclass_fields__); import rlm.repl as _repl; assert callable(_repl.main); assert callable(_repl.emit); assert callable(_repl.host_request); assert callable(_repl.is_active); assert _repl.PROTOCOL_VERSION == 3; assert callable(rlm.emit); assert not hasattr(rlm, 'HOST_COMM_TARGET'); assert not hasattr(mcp, 'install_shutdown_hook')`;const BOOTSTRAP_VERSION_FILE = ".bootstrap-version";const BOOTSTRAP_VERSION_TMP_FILE = `${BOOTSTRAP_VERSION_FILE}.tmp`;const BOOTSTRAP_LOCK_NAME = ".bootstrap.lock";@@ -963,7 +949,7 @@ async function ensureKernelPythonUncached(const missing: string[] = [];if (!(await hasPrimeAgentRuntime(python))) {missing.push(- "a current prime-agent-runtime with callable rlm.spawn, rlm.create_session, rlm.host_request, rlm.progress_note, and explicit harness CRUD methods",+ "a current prime-agent-runtime with callable rlm.spawn, rlm.create_session, rlm.host_request, rlm.progress_note, and rlm.harness.create_memory/update_memory/delete_memory",);}if (missing.length === 0) {diff --git a/packages/coding-agent/src/core/prompts/rlm.ts b/packages/coding-agent/src/core/prompts/rlm.tsindex 6a669324cf..d139d85fce 100644--- a/packages/coding-agent/src/core/prompts/rlm.ts+++ b/packages/coding-agent/src/core/prompts/rlm.ts@@ -44,7 +44,7 @@ const REPL_CONTROL_PROMPT = ["","Python state in the kernel persists across cells: named variables, helper functions, classes, imports, notes, parsed outputs, and helper data structures all remain available in every later turn. Tool calls are themselves Python `await` expressions, so their return values can be bound to variables and composed into program logic just like any other call.","",- "Continual harness state is available as `rlm.harness` and `rlm.get_harness_state()`. CRUD calls are local to this Prime Agent session by default: `rlm.harness.create_memory(...)`, `rlm.harness.update_memory(...)`, `rlm.harness.delete_memory(...)`, `rlm.harness.create_skill(...)`, `rlm.harness.update_skill(...)`, `rlm.harness.delete_skill(...)`, `rlm.harness.create_subagent(...)`, `rlm.harness.update_subagent(...)`, `rlm.harness.delete_subagent(...)`, `rlm.harness.create_prompt_note(...)`, `rlm.harness.update_prompt_note(...)`, `rlm.harness.delete_prompt_note(...)`, plus `rlm.harness.record_refinement(...)` and `rlm.harness.overview()`. Use `global_=True` only for stable cross-session lessons; Python reserves `global`, so literal `global=True` is invalid syntax.",+ "Continual harness state is available as `rlm.harness` and `rlm.get_harness_state()`. CRUD calls are local to this Prime Agent session by default: `rlm.harness.create_memory(title, content, kind=...)`, `rlm.harness.update_memory(id, title, content, kind=...)`, and `rlm.harness.delete_memory(id, kind=...)`, plus `rlm.harness.record_refinement(...)` and `rlm.harness.overview()`. Prompt notes, skills, and subagent specs are subtypes of memory: `kind` is one of `'prompt'`, `'memory'`, `'skill'`, `'subagent'` and defaults to `'memory'`; group entries with `topic=`. Only skill entries accept `reference=` and `arguments=`. Use `global_=True` only for stable cross-session lessons; Python reserves `global`, so literal `global=True` is invalid syntax.","","Terminology: continual harness names the persisted prompt, memory, skill, and subagent layer; RLM names the runtime, Python REPL kernel, and native call interface exposed to the model.","",diff --git a/packages/coding-agent/src/core/refinement/refinement.ts b/packages/coding-agent/src/core/refinement/refinement.tsindex 619666a919..cc93c05f74 100644--- a/packages/coding-agent/src/core/refinement/refinement.ts+++ b/packages/coding-agent/src/core/refinement/refinement.ts@@ -30,7 +30,7 @@ const DEFAULT_OVERVIEW_CONTENT_LIMIT = 180;* the shell flag was already false, i.e. identical renders), so equality* across the change is render-safe.*/-const HARNESS_DIGEST_FINGERPRINT_VERSION = 1;+const HARNESS_DIGEST_FINGERPRINT_VERSION = 2;export type RefinementKind = "prompt" | "memory" | "skill" | "subagent";export type RefinementAction = "create" | "update" | "delete";@@ -41,7 +41,7 @@ export interface HarnessEntry {kind: RefinementKind;title: string;content: string;- path: string;+ topic: string;scope?: HarnessScope;reference: Record<string, unknown>;arguments: Record<string, unknown>;@@ -73,7 +73,7 @@ export interface RefinementEdit {id?: string;title?: string;content?: string;- path?: string;+ topic?: string;reference?: Record<string, unknown>;arguments?: Record<string, unknown>;metadata?: Record<string, unknown>;@@ -148,7 +148,7 @@ Scope and persistence policy:- A caller may explicitly request global refinement. Global edits must be stable cross-session lessons, durable user preferences, reusable skills/subagents, or tool/environment facts that should affect future sessions.- Entry ids in the harness overview may carry a display-only \`local:\` or \`global:\` prefix. Always use the bare id (no prefix) in edits.- All edits in one refinement apply only to the requested scope's store. During a local refinement, global entries are read-only context: never propose update or delete edits for them; create a local entry instead when a session-specific override is genuinely needed.-- Project/workspace-specific lessons may be persisted globally only when the title, path, or content explicitly names the project/workspace and the lesson is likely to be reused in future sessions for that project. Prefer local edits when the lesson only belongs in the current conversation.+- Project/workspace-specific lessons may be persisted globally only when the title, topic, or content explicitly names the project/workspace and the lesson is likely to be reused in future sessions for that project. Prefer local edits when the lesson only belongs in the current conversation.- Use memory for declarative facts and preferences, skill for repeatable procedures exposed as Python calls, prompt for narrow behavioral policy addendums, and subagent for reusable delegation roles.- Create or update the smallest relevant component: repeated delegation roles should become subagent specs, repeated procedures should become skills, durable facts/preferences should become memories, and narrow behavioral policies should become prompt addendums.- When an edit is persisted, include metadata such as \`{"scope":"local"}\` or \`{"scope":"global"}\` when that helps future review understand the intended blast radius.@@ -169,7 +169,7 @@ JSON only with this exact shape:"id": "stable id for update/delete, optional for create","title": "required for create/update except delete","content": "required for create/update except delete",- "path": "optional grouping path",+ "topic": "optional grouping topic","reference": {"type": "python", "import": "package.module", "callable": "function_name", "call_pattern": "await function_name(...)"},"arguments": {"name": {"type": "string", "required": true, "description": "accepted input"}},"metadata": {},@@ -285,6 +285,12 @@ function objectRecord(value: unknown): Record<string, unknown> | undefined {return value as Record<string, unknown>;}+/** Grouping label of a stored entry, or undefined when it carries none. Older files spell it `path`. */+function harnessTopic(entry: { topic?: unknown; path?: unknown }): string | undefined {+ if (typeof entry.topic === "string") return entry.topic;+ return typeof entry.path === "string" ? entry.path : undefined;+}+function normalizeHarnessScope(value: unknown, fallback: HarnessScope): HarnessScope {return value === "global" || value === "local" ? value : fallback;}@@ -350,8 +356,10 @@ export function loadHarnessState(for (const [id, rawEntry] of Object.entries(records)) {const entry = objectRecord(rawEntry);if (!entry) continue;+ const { path: _path, ...rest } = entry as unknown as HarnessEntry & { path?: unknown };state.entries[kind][id] = {- ...(entry as unknown as HarnessEntry),+ ...rest,+ topic: harnessTopic(entry) ?? "general",scope: normalizeHarnessScope(entry.scope, scope),reference: objectRecord(entry.reference) ?? {},arguments: objectRecord(entry.arguments) ?? {},@@ -385,12 +393,28 @@ export function mergeHarnessStates(globalState: HarnessState, localState?: Harnereturn merged;}+/**+ * Pre-topic builds rewriting the shared global store drop unknown keys; mirror the grouping under+ * `path` so their rewrite round-trips it. Drop once no pre-topic build can reach a shared store.+ */+function serializeHarnessState(state: HarnessState): HarnessState {+ const serialized = emptyHarnessState();+ serialized.schema = state.schema;+ for (const kind of Object.keys(state.entries) as RefinementKind[]) {+ for (const [id, entry] of Object.entries(state.entries[kind])) {+ serialized.entries[kind][id] = { ...entry, path: entry.topic } as HarnessEntry;+ }+ }+ serialized.refinements = state.refinements;+ return serialized;+}+export function saveHarnessState(harnessStateDir: string, state: HarnessState): string {const statePath = getHarnessStatePath(harnessStateDir);mkdirSync(harnessStateDir, { recursive: true });const targetPath = realpathIfPresentSync(statePath);const mode = existsSync(targetPath) ? statSync(targetPath).mode & 0o777 : 0o600;- writeFileAtomicSync(targetPath, `${JSON.stringify(state, null, 2)}\n`, { mode });+ writeFileAtomicSync(targetPath, `${JSON.stringify(serializeHarnessState(state), null, 2)}\n`, { mode });return statePath;}@@ -586,7 +610,7 @@ export function harnessQueryTermIdf(entries: HarnessEntry[], terms: HarnessQuerydocuments += 1;const title = searchableField(entry.title);const content = searchableField(entry.content);- const identifier = `${searchableField(entry.path)} ${searchableField(entry.id)}`;+ const identifier = `${searchableField(entry.topic)} ${searchableField(entry.id)}`;for (const term of terms.keys()) {if (title.includes(term) || content.includes(term) || identifier.includes(term)) {matches.set(term, (matches.get(term) ?? 0) + 1);@@ -612,13 +636,13 @@ export function scoreHarnessEntryForQuery(if (terms.size === 0) return 0;const title = searchableField(entry.title);const content = searchableField(entry.content);- const identifier = `${searchableField(entry.path)} ${searchableField(entry.id)}`;+ const identifier = `${searchableField(entry.topic)} ${searchableField(entry.id)}`;let score = 0;for (const [term, weight] of terms) {// One match per field counts once per term: coverage over distinct- // fields matters more than repetition inside a single field. Path+ // fields matters more than repetition inside a single field. Topic// and id form a single identifier slot: the id is often embedded in- // the path, so matching both is one signal, not two.+ // the topic, so matching both is one signal, not two.let fields = 0;if (title.includes(term)) fields += 1;if (content.includes(term)) fields += 1;@@ -638,10 +662,10 @@ function compareRankedHarnessEntries(): number {const scoreDifference = scoreHarnessEntryForQuery(b, terms, idf) - scoreHarnessEntryForQuery(a, terms, idf);if (scoreDifference !== 0) return scoreDifference;- // Equal scores tie on stable identifier order (path, title, id), so+ // Equal scores tie on stable identifier order (topic, title, id), so// touching unrelated entries never reshuffles equal-score siblings and the// rendered digest keeps a stable prefix for provider prompt-cache reuse.- return [a.path, a.title, a.id].join("\0").localeCompare([b.path, b.title, b.id].join("\0"));+ return [a.topic, a.title, a.id].join("\0").localeCompare([b.topic, b.title, b.id].join("\0"));}export function formatHarnessStateForPrompt(@@ -694,7 +718,7 @@ export function formatHarnessStateForPrompt(const entries = ranked.sort((a, b) =>queryTerms !== undefined && queryTerms.size > 0? compareRankedHarnessEntries(a, b, queryTerms, idf)- : [a.path, a.title, a.id].join("\0").localeCompare([b.path, b.title, b.id].join("\0")),+ : [a.topic, a.title, a.id].join("\0").localeCompare([b.topic, b.title, b.id].join("\0")),);totalEntries += entries.length;// Render subagent specs as a task-shaped roster the model can match against — the@@ -725,7 +749,7 @@ export function formatHarnessStateForPrompt(? ` ref=${compactText(JSON.stringify(entry.reference), maxContentLength)}`: "";lines.push(- `- [${entry.scope ?? "global"}:${entry.id}] ${entry.title} (${entry.path}, v${entry.version})${referenceText}${argumentsText}: ${compactText(+ `- [${entry.scope ?? "global"}:${entry.id}] ${entry.title} (${entry.topic}, v${entry.version})${referenceText}${argumentsText}: ${compactText(entry.content,maxContentLength,)}`,@@ -795,7 +819,7 @@ export function harnessDigestFingerprint(kind: entry.kind,id: entry.id,title: entry.title,- path: entry.path,+ topic: entry.topic,version: entry.version,content: entry.content,// Only skills render the kernel call contract, so another kind can@@ -853,7 +877,7 @@ function overviewForPrompt(state: HarnessState): string {? ` ref=${JSON.stringify(entry.reference).slice(0, 240)}`: "";lines.push(- `- [${entry.scope ?? "global"}:${entry.id}] ${entry.title} (${entry.path}, v${entry.version})${referenceText}${argumentsText}: ${content}`,+ `- [${entry.scope ?? "global"}:${entry.id}] ${entry.title} (${entry.topic}, v${entry.version})${referenceText}${argumentsText}: ${content}`,);}if (entries.length > 40) {@@ -968,7 +992,7 @@ export function normalizeRefinementProposal(value: unknown): RefinementProposalid: typeof edit.id === "string" ? edit.id : undefined,title: typeof edit.title === "string" ? edit.title : undefined,content: typeof edit.content === "string" ? edit.content : undefined,- path: typeof edit.path === "string" ? edit.path : undefined,+ topic: harnessTopic(edit),reference: objectRecord(edit.reference),arguments: objectRecord(edit.arguments),metadata:@@ -1007,8 +1031,8 @@ function validateEdit(edit: RefinementEdit, computedId?: string): string | undefif (edit.id !== undefined && (typeof edit.id !== "string" || edit.id.length === 0)) {return `${edit.action} requires id to be a non-empty string when provided`;}- if (edit.path !== undefined && (typeof edit.path !== "string" || edit.path.length === 0)) {- return `${edit.action} requires path to be a non-empty string when provided`;+ if (edit.topic !== undefined && (typeof edit.topic !== "string" || edit.topic.length === 0)) {+ return `${edit.action} requires topic to be a non-empty string when provided`;}if (edit.action !== "delete" &&@@ -1112,7 +1136,7 @@ export function applyRefinementProposal(kind: edit.kind,title: edit.title ?? before?.title ?? id,content: edit.content ?? before?.content ?? "",- path: edit.path ?? before?.path ?? "general",+ topic: edit.topic ?? before?.topic ?? "general",scope: before?.scope ?? options.scope ?? "local",reference: edit.reference ?? before?.reference ?? {},arguments: edit.arguments ?? before?.arguments ?? {},@@ -1160,7 +1184,7 @@ function rollbackProposal(target: RefinementResult): RefinementProposal {id: edit.id,title: edit.before.title,content: edit.before.content,- path: edit.before.path,+ topic: harnessTopic(edit.before),reference: edit.before.reference,arguments: edit.before.arguments,metadata: edit.before.metadata,diff --git a/packages/coding-agent/src/modes/interactive/components/refinement-outcome-message.ts b/packages/coding-agent/src/modes/interactive/components/refinement-outcome-message.tsindex 856ff97bdf..a2dae0f48d 100644--- a/packages/coding-agent/src/modes/interactive/components/refinement-outcome-message.ts+++ b/packages/coding-agent/src/modes/interactive/components/refinement-outcome-message.ts@@ -12,7 +12,7 @@ type EditFieldKey = (typeof EDIT_FIELDS)[number]["key"];const EDIT_FIELDS = [{ key: "title", label: "Title" },{ key: "content", label: "Description" },- { key: "path", label: "Path" },+ { key: "topic", label: "Topic" },{ key: "reference", label: "Reference" },{ key: "arguments", label: "Arguments" },{ key: "metadata", label: "Metadata" },diff --git a/packages/coding-agent/test/acp-kernel-features.test.ts b/packages/coding-agent/test/acp-kernel-features.test.tsindex b7bd99a08d..ecf6d210bb 100644--- a/packages/coding-agent/test/acp-kernel-features.test.ts+++ b/packages/coding-agent/test/acp-kernel-features.test.ts@@ -96,11 +96,12 @@ describe("ACP mode over a real Python kernel", () => {const allKinds = await manager.execute(`import jsonmem = rlm.harness.create_memory(title="m", content="memory content", global_=True)-note = rlm.harness.create_prompt_note(title="n", content="prompt note content", global_=True)-spec = rlm.harness.create_subagent(title="s", content="subagent spec content", global_=True)-skill = rlm.harness.create_skill(+note = rlm.harness.create_memory(title="n", content="prompt note content", kind="prompt", global_=True)+spec = rlm.harness.create_memory(title="s", content="subagent spec content", kind="subagent", global_=True)+skill = rlm.harness.create_memory(title="k",content="skill content",+ kind="skill",reference={"type": "python", "import": "pkg.mod", "callable": "run", "call_pattern": "await run(...)"},arguments={"x": {"type": "string", "required": True, "description": "input"}},global_=True,@@ -127,7 +128,7 @@ entry = rlm.harness.create_memory()found = rlm.harness.get("memory", entry.id, global_=True)listed = [item.id for item in rlm.harness.list("memory", global_=True)]-deleted = rlm.harness.delete("memory", entry.id, global_=True)+deleted = rlm.harness.delete_memory(entry.id, kind="memory", global_=True)after = rlm.harness.get("memory", entry.id, global_=True)print(json.dumps({"created": entry.id,diff --git a/packages/coding-agent/test/refinement.test.ts b/packages/coding-agent/test/refinement.test.tsindex 74cd4b0ce4..0dc6bf0ad3 100644--- a/packages/coding-agent/test/refinement.test.ts+++ b/packages/coding-agent/test/refinement.test.ts@@ -1,4 +1,13 @@-import { appendFileSync, chmodSync, mkdtempSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";+import {+ appendFileSync,+ chmodSync,+ mkdtempSync,+ readdirSync,+ readFileSync,+ rmSync,+ statSync,+ writeFileSync,+} from "node:fs";import { tmpdir } from "node:os";import { join } from "node:path";import type { AgentMessage } from "@earendil-works/pi-agent-core";@@ -130,7 +139,7 @@ function seedEntry(state: HarnessState, kind: RefinementKind, id = `${kind}_entrid,title: `${kind} title`,content: `${kind} content`,- path: `${kind}/path`,+ topic: `${kind}/topic`,...(kind === "skill" ? skillContract : {}),metadata: { seeded: true },},@@ -217,7 +226,7 @@ describe("harness refinement", () => {id,title: `${kind} title`,content: `${kind} content`,- path: `${kind}/created`,+ topic: `${kind}/created`,...skillFields,metadata: { kind },},@@ -232,7 +241,7 @@ describe("harness refinement", () => {kind,title: `${kind} title`,content: `${kind} content`,- path: `${kind}/created`,+ topic: `${kind}/created`,metadata: { kind },source: "refine",version: 1,@@ -247,7 +256,7 @@ describe("harness refinement", () => {id,title: `${kind} title updated`,content: `${kind} content updated`,- path: `${kind}/updated`,+ topic: `${kind}/updated`,...skillFields,metadata: { updated: kind },},@@ -259,7 +268,7 @@ describe("harness refinement", () => {expect(state.entries[kind][id]).toMatchObject({title: `${kind} title updated`,content: `${kind} content updated`,- path: `${kind}/updated`,+ topic: `${kind}/updated`,metadata: { updated: kind },version: 2,});@@ -272,7 +281,7 @@ describe("harness refinement", () => {expect(state.refinements.at(-1)?.changes).toEqual([`delete ${kind}:${id}`]);});- it("creates ids from titles and uses default path and metadata when omitted", () => {+ it("creates ids from titles and uses default topic and metadata when omitted", () => {const state = loadHarnessState(makeTempDir());const result = applyRefinementProposal(@@ -286,7 +295,7 @@ describe("harness refinement", () => {expect(result.appliedEdits[0]).toMatchObject({applied: true,id: "native_check",- after: { id: "native_check", path: "general", reference: skillReference, metadata: {}, version: 1 },+ after: { id: "native_check", topic: "general", reference: skillReference, metadata: {}, version: 1 },});});@@ -431,9 +440,9 @@ describe("harness refinement", () => {error: "create requires reference to be an object when provided",},{- label: "a create with a numeric path",- edit: editWith("create", "memory", "bad_path", { path: 7 }),- error: "create requires path to be a non-empty string when provided",+ label: "a create with a numeric topic",+ edit: editWith("create", "memory", "bad_topic", { topic: 7 }),+ error: "create requires topic to be a non-empty string when provided",},{label: "a skill with list arguments",@@ -549,6 +558,23 @@ describe("harness refinement", () => {},);+ it("loads an entry that stores the grouping as path and resaves it as topic", () => {+ const dir = makeTempDir();+ writeFileSync(+ getHarnessStatePath(dir),+ '{"schema":1,"entries":{"memory":{"legacy":{"id":"legacy","kind":"memory","title":"Legacy","content":"c","path":"repo/testing"}}}}',+ "utf8",+ );++ const state = loadHarnessState(dir, "local");+ expect(state.entries.memory.legacy.topic).toBe("repo/testing");++ saveHarnessState(dir, state);+ const saved = JSON.parse(readFileSync(getHarnessStatePath(dir), "utf8")).entries.memory.legacy;+ expect(saved.topic).toBe("repo/testing");+ expect(saved.path).toBe("repo/testing");+ });+it("extracts well-formed refinement history from custom session entries", () => {const result: RefinementResult = {id: "refine_1",@@ -584,6 +610,7 @@ describe("harness refinement", () => {id: "native_validation",title: "Native validation",content: "Run validation through the target project environment.",+ path: "validation",};completeSimpleMock.mockResolvedValueOnce(assistantText(JSON.stringify({ summary: "s", rationale: "r", expectedOutcome: "o", edits: [edit] })),@@ -609,7 +636,7 @@ describe("harness refinement", () => {headers: { "x-test-header": "1" },});expect(result.appliedEdits[0]).toMatchObject({ kind: "memory", id: "native_validation", applied: true });- expect(state.entries.memory.native_validation.content).toBe(edit.content);+ expect(state.entries.memory.native_validation).toMatchObject({ content: edit.content, topic: "validation" });});it("caps the refinement output budget by the policy ceiling for wide models", async () => {@@ -683,7 +710,7 @@ describe("harness refinement", () => {id: "kept_memory",title: "Updated memory",content: "Updated memory content",- path: "updated/path",+ topic: "updated/topic",metadata: { updated: true },},{ action: "delete", kind: "skill", id: "deleted_skill" },@@ -691,7 +718,9 @@ describe("harness refinement", () => {{ id: "refine_target" },);- const rollback = await refineHarness([], state, [target], {} as never, "api-key", {+ // An older build recorded the edit snapshots with the legacy field name.+ const recorded = JSON.parse(JSON.stringify(target).replaceAll('"topic":', '"path":')) as RefinementResult;+ const rollback = await refineHarness([], state, [recorded], {} as never, "api-key", {rollbackId: "refine_target",});@@ -705,7 +734,7 @@ describe("harness refinement", () => {expect(state.entries.prompt.created_prompt).toBeUndefined();expect(state.entries.memory.kept_memory).toMatchObject({content: "memory content",- path: "memory/path",+ topic: "memory/topic",metadata: { seeded: true },version: 3,});@@ -773,7 +802,7 @@ describe("global refinement history", () => {kind: "memory" as const,title: "Legacy global memory",content: "created globally",- path: "general",+ topic: "general",scope: "global" as const,reference: {},arguments: {},@@ -920,7 +949,7 @@ describe("harness digest relevance ranking", () => {kind: "memory",title,content,- path: "memory",+ topic: "memory",scope: "global",reference: {},arguments: {},@@ -1040,7 +1069,7 @@ describe("harness digest relevance ranking", () => {maxEntriesPerKind: 1,queryTerms: new Map([["worktree", 1]]),});- // Equal scores render in stable identifier order ([path, title, id]);+ // Equal scores render in stable identifier order ([topic, title, id]);// updated_at recency must not hoist the newer entry into the window.expect(ranked).toContain("[global:aaa]");expect(ranked).not.toContain("[global:zzz]");diff --git a/packages/coding-agent/test/suite/agent-session-compaction.test.ts b/packages/coding-agent/test/suite/agent-session-compaction.test.tsindex c2f5073b15..760a640704 100644--- a/packages/coding-agent/test/suite/agent-session-compaction.test.ts+++ b/packages/coding-agent/test/suite/agent-session-compaction.test.ts@@ -367,7 +367,7 @@ describe("AgentSession compaction", () => {kind: "memory",title: "Compaction test memory",content: "Written before compaction.",- path: "general",+ topic: "general",scope: "local",reference: {},arguments: {},diff --git a/packages/coding-agent/test/suite/agent-session-prompt.test.ts b/packages/coding-agent/test/suite/agent-session-prompt.test.tsindex 156e023e9f..ab6dc26d65 100644--- a/packages/coding-agent/test/suite/agent-session-prompt.test.ts+++ b/packages/coding-agent/test/suite/agent-session-prompt.test.ts@@ -994,7 +994,7 @@ describe("Harness digest at cold boundaries", () => {kind: "memory",title,content,- path: "general",+ topic: "general",scope,reference: {},arguments: {},diff --git a/packages/coding-agent/test/suite/agent-session-serialized-refine.test.ts b/packages/coding-agent/test/suite/agent-session-serialized-refine.test.tsindex 0f29c4f6fb..68d7ec9c8f 100644--- a/packages/coding-agent/test/suite/agent-session-serialized-refine.test.ts+++ b/packages/coding-agent/test/suite/agent-session-serialized-refine.test.ts@@ -278,7 +278,7 @@ describe("Serialized refine", () => {kind: "memory",title: "Shared",content: "planning baseline",- path: "general",+ topic: "general",scope: "local",reference: {},arguments: {},diff --git a/prime-agent-runtime/src/rlm/harness.py b/prime-agent-runtime/src/rlm/harness.pyindex 03dabfaf2e..ae9fe6fbb6 100644--- a/prime-agent-runtime/src/rlm/harness.py+++ b/prime-agent-runtime/src/rlm/harness.py@@ -27,6 +27,11 @@ HarnessScope = Literal["local", "global"]_DEFAULT_FILE_NAME = "harness_state.json"_DEFAULT_HARNESS_DIR_NAME = "harness"_KINDS: tuple[HarnessKind, ...] = ("prompt", "memory", "skill", "subagent")+_REMOVED_WRAPPER_KINDS: dict[str, HarnessKind] = {+ "prompt_note": "prompt",+ "skill": "skill",+ "subagent": "subagent",+}_state_cache: dict[tuple[Path, HarnessScope], "HarnessState"] = {}@@ -121,6 +126,8 @@ def _agent_dir() -> Path:def _resolve_global_flag(global_: bool = False, extra: dict[str, Any] | None = None) -> bool:extra = dict(extra or {})+ if "path" in extra:+ raise TypeError("path was renamed to topic; pass topic=")if "global" in extra:value = extra.pop("global")if not isinstance(value, bool):@@ -174,7 +181,7 @@ class HarnessEntry:kind: HarnessKindtitle: strcontent: str- path: str = "general"+ topic: str = "general"scope: HarnessScope = "local"reference: dict[str, Any] = field(default_factory=dict)arguments: dict[str, Any] = field(default_factory=dict)@@ -221,6 +228,30 @@ def _validate_python_skill_reference(reference: dict[str, Any] | None, entry_namreturn normalized+def _serialize_entry(entry: HarnessEntry) -> dict[str, Any]:+ # Pre-topic builds rewriting the shared store drop "topic"; mirror the value under "path"+ # so their rewrite round-trips it. Drop once no pre-topic build can reach a shared store.+ record = asdict(entry)+ record["path"] = entry.topic+ return record+++def _default_topic(kind: HarnessKind) -> str:+ return "policy" if kind == "prompt" else "general"+++def _reject_skill_only_fields(+ kind: HarnessKind,+ reference: dict[str, Any] | None,+ arguments: dict[str, Any] | None,+) -> None:+ """Reject the skill-only call contract fields on the other kinds."""+ if kind != "skill":+ for name, value in (("reference", reference), ("arguments", arguments)):+ if value is not None:+ raise ValueError(f"{name} is only accepted for kind='skill', not kind={kind!r}")++def _type_name(value: Any) -> str:if isinstance(value, list):return "a list"@@ -263,7 +294,7 @@ def _validate_entry_shape(title: Any,content: Any,*,- path: Any,+ topic: Any,reference: Any,arguments: Any,metadata: Any,@@ -281,7 +312,7 @@ def _validate_entry_shape(_require_text(kind, entry_name, "id", entry_id)_require_text(kind, entry_name, "title", title)_require_text(kind, entry_name, "content", content)- _require_optional_text(kind, entry_name, "path", path)+ _require_optional_text(kind, entry_name, "topic", topic)_require_optional_record(kind, entry_name, "reference", reference)_require_optional_record(kind, entry_name, "arguments", arguments)_require_optional_record(kind, entry_name, "metadata", metadata)@@ -349,6 +380,19 @@ class HarnessState:self._loaded_mtime: int | None = Noneself.load()+ def _require_kind(self, kind: HarnessKind) -> None:+ if kind not in self.entries:+ raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")++ def _kind_of(self, id: str) -> HarnessKind | None:+ """The kind an id is stored under, if any."""+ return next((kind for kind in _KINDS if id in self.entries[kind]), None)++ def _missing_entry_message(self, kind: HarnessKind, id: str) -> str:+ if (actual := self._kind_of(id)) is not None:+ return f"entry {id!r} is kind={actual!r}; pass kind={actual!r}"+ return f"{kind} entry {id!r} does not exist"+def _ensure_local_writable(self) -> None:if self._local_write_error is not None:raise RuntimeError(self._local_write_error)@@ -406,8 +450,10 @@ class HarnessState:entry_data.get("content"), str):continue- if not isinstance(entry_data.get("path"), str):- entry_data["path"] = "general"+ if not isinstance(entry_data.get("topic"), str):+ # Older state files spell the grouping "path"; read both.+ stored_path = raw_entry.get("path")+ entry_data["topic"] = stored_path if isinstance(stored_path, str) else "general"if entry_data.get("scope") not in ("local", "global"):entry_data["scope"] = self.scopeif not isinstance(entry_data.get("source"), str):@@ -467,7 +513,7 @@ class HarnessState:data = {"schema": 1,"entries": {- kind: {entry_id: asdict(entry) for entry_id, entry in records.items()}+ kind: {entry_id: _serialize_entry(entry) for entry_id, entry in records.items()}for kind, records in self.entries.items()},"refinements": [asdict(event) for event in self.refinements],@@ -500,11 +546,10 @@ class HarnessState:content: str,*,id: str | None = None,- path: str = "general",+ topic: str = "general",reference: dict[str, Any] | None = None,arguments: dict[str, Any] | None = None,metadata: dict[str, Any] | None = None,- source: str = "agent",global_: bool = False,**kwargs: Any,) -> HarnessEntry:@@ -515,11 +560,10 @@ class HarnessState:title,content,id=id,- path=path,+ topic=topic,reference=reference,arguments=arguments,metadata=metadata,- source=source,)self._ensure_local_writable()self._sync_from_disk()@@ -528,11 +572,10 @@ class HarnessState:title,content,id=id,- path=path,+ topic=topic,reference=reference,arguments=arguments,metadata=metadata,- source=source,)def _upsert(@@ -542,18 +585,17 @@ class HarnessState:content: str,*,id: str | None = None,- path: str | None = None,+ topic: str | None = None,reference: dict[str, Any] | None = None,arguments: dict[str, Any] | None = None,metadata: dict[str, Any] | None = None,source: str = "agent",) -> HarnessEntry:- # Caller is responsible for syncing from disk first. create()/update() sync- # once and then call this directly so their existence check and the write are+ # Caller is responsible for syncing from disk first. create_memory()/update_memory()+ # sync once and then call this directly so their existence check and the write are# not separated by a second reload (which could turn create-or-fail into a# silent update).- if kind not in self.entries:- raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")+ self._require_kind(kind)# Guard before the id slug and the dict lookup: a non-string title or a# non-string id (falsy ids included, which the slug fallback would@@ -569,7 +611,7 @@ class HarnessState:entry_id,title,content,- path=path,+ topic=topic,reference=reference,arguments=arguments,metadata=metadata,@@ -579,12 +621,12 @@ class HarnessState:if existing:existing.title = titleexisting.content = content- # Preserve path/reference/arguments/metadata when the caller omits them+ # Preserve topic/reference/arguments/metadata when the caller omits them# (None) so updating only an entry's title or content does not reset its- # grouping path or wipe a skill's reference/argument contract. An explicit+ # grouping topic or wipe a skill's reference/argument contract. An explicit# value (including {}) still overwrites.- if path is not None:- existing.path = path+ if topic is not None:+ existing.topic = topicif reference is not None:existing.reference = dict(reference)if arguments is not None:@@ -601,7 +643,7 @@ class HarnessState:kind=kind,title=title,content=content,- path=path if path is not None else "general",+ topic=topic if topic is not None else "general",scope=self.scope,reference=dict(reference or {}),arguments=dict(arguments or {}),@@ -617,24 +659,9 @@ class HarnessState:if target := self._global_target(global_, kwargs):return target.get(kind, id)self._sync_from_disk()- if kind not in self.entries:- raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")+ self._require_kind(kind)return self.entries[kind].get(id)- def delete(self, kind: HarnessKind, id: str, *, global_: bool = False, **kwargs: Any) -> bool:- id, global_ = _strip_scope_prefix(id, global_)- if target := self._global_target(global_, kwargs):- return target.delete(kind, id)- self._ensure_local_writable()- self._sync_from_disk()- if kind not in self.entries:- raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")- if id not in self.entries[kind]:- return False- del self.entries[kind][id]- self.save()- return True-def list(self, kind: HarnessKind | None = None, *, global_: bool = False, **kwargs: Any) -> list[HarnessEntry]:if target := self._global_target(global_, kwargs):return target.list(kind)@@ -642,43 +669,48 @@ class HarnessState:kinds = [kind] if kind else list(_KINDS)records: list[HarnessEntry] = []for current_kind in kinds:- if current_kind not in self.entries:- raise ValueError(f"unknown harness kind {current_kind!r}; expected one of {_KINDS}")+ self._require_kind(current_kind)records.extend(self.entries[current_kind].values())- return sorted(records, key=lambda entry: (entry.kind, entry.path, entry.title, entry.id))+ return sorted(records, key=lambda entry: (entry.kind, entry.topic, entry.title, entry.id))- def create(+ def create_memory(self,- kind: HarnessKind,title: str,content: str,*,+ kind: HarnessKind = "memory",+ topic: str | None = None,id: str | None = None,- path: str = "general",+ metadata: dict[str, Any] | None = None,reference: dict[str, Any] | None = None,arguments: dict[str, Any] | None = None,- metadata: dict[str, Any] | None = None,- source: str = "agent",global_: bool = False,**kwargs: Any,) -> HarnessEntry:+ """Create a harness entry; fails when the id already exists.++ Prompt notes, skills, and subagent specs are subtypes of memory, so one+ method with ``kind`` covers them all. ``reference`` and ``arguments``+ describe a skill's Python call contract and are rejected for other kinds.+ ``topic`` groups entries and defaults to "policy" for prompt notes and+ "general" otherwise.+ """+ self._require_kind(kind)+ _reject_skill_only_fields(kind, reference, arguments)id, global_ = _strip_scope_prefix(id, global_)if target := self._global_target(global_, kwargs):- return target.create(- kind,+ return target.create_memory(title,content,+ kind=kind,+ topic=topic,id=id,- path=path,+ metadata=metadata,reference=reference,arguments=arguments,- metadata=metadata,- source=source,)self._ensure_local_writable()self._sync_from_disk()- if kind not in self.entries:- raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")_require_text(kind, _describe_entry(id, title), "title", title)if id is not None:_require_text(kind, _describe_entry(id, title), "id", id)@@ -690,207 +722,81 @@ class HarnessState:title,content,id=entry_id,- path=path,+ topic=topic if topic is not None else _default_topic(kind),reference=reference,arguments=arguments,metadata=metadata,- source=source,)- def update(+ def update_memory(self,- kind: HarnessKind,id: str,title: str,content: str,*,- path: str | None = None,+ kind: HarnessKind = "memory",+ topic: str | None = None,+ metadata: dict[str, Any] | None = None,reference: dict[str, Any] | None = None,arguments: dict[str, Any] | None = None,- metadata: dict[str, Any] | None = None,- source: str = "agent",global_: bool = False,**kwargs: Any,) -> HarnessEntry:+ """Update an existing harness entry; omitted fields keep their value."""+ self._require_kind(kind)+ _reject_skill_only_fields(kind, reference, arguments)id, global_ = _strip_scope_prefix(id, global_)if target := self._global_target(global_, kwargs):- return target.update(- kind,+ return target.update_memory(id,title,content,- path=path,+ kind=kind,+ topic=topic,+ metadata=metadata,reference=reference,arguments=arguments,- metadata=metadata,- source=source,)self._ensure_local_writable()self._sync_from_disk()- if kind not in self.entries:- raise ValueError(f"unknown harness kind {kind!r}; expected one of {_KINDS}")_require_text(kind, _describe_entry(id, title), "id", id)if id not in self.entries[kind]:- raise ValueError(f"{kind} entry {id!r} does not exist")+ raise ValueError(self._missing_entry_message(kind, id))return self._upsert(kind,title,content,id=id,- path=path,+ topic=topic,reference=reference,arguments=arguments,metadata=metadata,- source=source,)- def create_memory(- self,- title: str,- content: str,- *,- id: str | None = None,- path: str = "general",- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.create("memory", title, content, id=id, path=path, metadata=metadata, global_=global_, **kwargs)-- def update_memory(- self,- id: str,- title: str,- content: str,- *,- path: str | None = None,- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.update("memory", id, title, content, path=path, metadata=metadata, global_=global_, **kwargs)-- def delete_memory(self, id: str, *, global_: bool = False, **kwargs: Any) -> bool:- return self.delete("memory", id, global_=global_, **kwargs)-- def create_prompt_note(- self,- title: str,- content: str,- *,- id: str | None = None,- path: str = "policy",- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.create("prompt", title, content, id=id, path=path, metadata=metadata, global_=global_, **kwargs)-- def update_prompt_note(- self,- id: str,- title: str,- content: str,- *,- path: str | None = None,- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.update("prompt", id, title, content, path=path, metadata=metadata, global_=global_, **kwargs)-- def delete_prompt_note(self, id: str, *, global_: bool = False, **kwargs: Any) -> bool:- return self.delete("prompt", id, global_=global_, **kwargs)-- def create_skill(- self,- title: str,- content: str,- *,- id: str | None = None,- path: str = "general",- reference: dict[str, Any] | None = None,- arguments: dict[str, Any] | None = None,- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.create(- "skill",- title,- content,- id=id,- path=path,- reference=_validate_python_skill_reference(reference, _describe_entry(id, title)),- arguments=arguments,- metadata=metadata,- global_=global_,- **kwargs,- )-- def update_skill(- self,- id: str,- title: str,- content: str,- *,- path: str | None = None,- reference: dict[str, Any] | None = None,- arguments: dict[str, Any] | None = None,- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- # Only validate a reference when one is supplied; omitting it preserves the- # existing reference (see _upsert) rather than forcing every title/content-only- # update to re-send the full Python reference.- validated_reference = (- _validate_python_skill_reference(reference, _describe_entry(id, title)) if reference is not None else None- )- return self.update(- "skill",- id,- title,- content,- path=path,- reference=validated_reference,- arguments=arguments,- metadata=metadata,- global_=global_,- **kwargs,- )-- def delete_skill(self, id: str, *, global_: bool = False, **kwargs: Any) -> bool:- return self.delete("skill", id, global_=global_, **kwargs)-- def create_subagent(- self,- title: str,- content: str,- *,- id: str | None = None,- path: str = "general",- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.create("subagent", title, content, id=id, path=path, metadata=metadata, global_=global_, **kwargs)-- def update_subagent(- self,- id: str,- title: str,- content: str,- *,- path: str | None = None,- metadata: dict[str, Any] | None = None,- global_: bool = False,- **kwargs: Any,- ) -> HarnessEntry:- return self.update("subagent", id, title, content, path=path, metadata=metadata, global_=global_, **kwargs)+ def delete_memory(self, id: str, *, kind: HarnessKind = "memory", global_: bool = False, **kwargs: Any) -> bool:+ """Delete a harness entry; returns False when it does not exist."""+ self._require_kind(kind)+ id, global_ = _strip_scope_prefix(id, global_)+ if target := self._global_target(global_, kwargs):+ return target.delete_memory(id, kind=kind)+ self._ensure_local_writable()+ self._sync_from_disk()+ if id not in self.entries[kind]:+ if self._kind_of(id) is not None:+ raise ValueError(self._missing_entry_message(kind, id))+ return False+ del self.entries[kind][id]+ self.save()+ return True- def delete_subagent(self, id: str, *, global_: bool = False, **kwargs: Any) -> bool:- return self.delete("subagent", id, global_=global_, **kwargs)+ def __getattr__(self, name: str) -> Any:+ # Kernels and transcripts still carry the removed names, so name the+ # replacement instead of a bare AttributeError.+ action, _, suffix = name.partition("_")+ kind = _REMOVED_WRAPPER_KINDS.get(suffix)+ if kind and action in ("create", "update", "delete"):+ raise AttributeError(f"{name} was removed; use rlm.harness.{action}_memory(..., kind={kind!r})")+ raise AttributeError(name)def record_refinement(self,@@ -977,7 +883,7 @@ class HarnessState:reference_text = f"{reference_text[:117]}..."reference_summary = f" ref={reference_text}"lines.append(- f" - [{entry.scope}:{entry.id}] {entry.title} ({entry.path}, v{entry.version})"+ f" - [{entry.scope}:{entry.id}] {entry.title} ({entry.topic}, v{entry.version})"f"{reference_summary}{argument_summary}: {summary}")overflow = len(self.entries[kind]) - len(records)@@ -1002,7 +908,7 @@ class HarnessState:) -> list[HarnessEntry]:"""Return harness entries ranked by weighted term overlap with *query*.- Terms are scored against an entry's title, content, path, and id;+ Terms are scored against an entry's title, content, topic, and id;matches in more distinct fields count more. Each matched term isdiscounted by its document frequency across the ranked corpus(tf-idf style, ``weight * log(1 + N / df)``), so a rare,@@ -1028,9 +934,9 @@ class HarnessState:for entry in entries:title = entry.title.lower()content = entry.content.lower()- path_and_id = f"{entry.path} {entry.id}".lower()+ topic_and_id = f"{entry.topic} {entry.id}".lower()for term in terms:- if term in title or term in content or term in path_and_id:+ if term in title or term in content or term in topic_and_id:matches[term] += 1term_idf = {term: math.log(1 + len(entries) / count)@@ -1041,11 +947,11 @@ class HarnessState:def score(entry: HarnessEntry) -> float:title = entry.title.lower()content = entry.content.lower()- path_and_id = f"{entry.path} {entry.id}".lower()+ topic_and_id = f"{entry.topic} {entry.id}".lower()total = 0.0for term, idf in term_idf.items():fields = (1 if term in title else 0) + (1 if term in content else 0) + (- 1 if term in path_and_id else 0+ 1 if term in topic_and_id else 0)if fields:total += idf * (1 + (fields - 1) * 0.5)diff --git a/prime-agent-runtime/test/test_harness.py b/prime-agent-runtime/test/test_harness.pyindex 1b2ed97693..e5d2be8ed1 100644--- a/prime-agent-runtime/test/test_harness.py+++ b/prime-agent-runtime/test/test_harness.py@@ -2,6 +2,7 @@ from __future__ import annotationsimport jsonimport os+import reimport subprocessimport sysimport tempfile@@ -26,35 +27,38 @@ class HarnessStateTest(unittest.TestCase):state = HarnessState(Path(temp_dir) / "harness_state.json")created = {- "prompt": state.create_prompt_note(+ "prompt": state.create_memory("Prompt note","Prompt content",id="prompt_entry",- path="prompt/path",+ topic="prompt/topic",metadata={"kind": "prompt"},+ kind="prompt",),"memory": state.create_memory("Memory","Memory content",id="memory_entry",- path="memory/path",+ topic="memory/topic",metadata={"kind": "memory"},),- "skill": state.create_skill(+ "skill": state.create_memory("Skill","Skill content",id="skill_entry",- path="skill/path",+ topic="skill/topic",reference=PYTHON_REFERENCE,arguments={"target": {"type": "string", "required": True}},metadata={"kind": "skill"},+ kind="skill",),- "subagent": state.create_subagent(+ "subagent": state.create_memory("Subagent","Subagent content",id="subagent_entry",- path="subagent/path",+ topic="subagent/topic",metadata={"kind": "subagent"},+ kind="subagent",),}@@ -63,28 +67,66 @@ class HarnessStateTest(unittest.TestCase):self.assertIn("content", state.get(kind, entry.id).content.lower())self.assertIn(entry, state.list(kind))- state.update_prompt_note("prompt_entry", "Prompt note", "Prompt content updated")+ state.update_memory("prompt_entry", "Prompt note", "Prompt content updated", kind="prompt")state.update_memory("memory_entry", "Memory", "Memory content updated")- state.update_skill(+ state.update_memory("skill_entry","Skill","Skill content updated",reference=PYTHON_REFERENCE,arguments={"target": {"type": "string", "required": True}, "mode": {"type": "string"}},+ kind="skill",)- state.update_subagent("subagent_entry", "Subagent", "Subagent content updated")+ state.update_memory("subagent_entry", "Subagent", "Subagent content updated", kind="subagent")++ for mutate in (+ lambda: state.delete_memory("prompt_entry"),+ lambda: state.update_memory("prompt_entry", "Prompt note", "x"),+ ):+ with self.assertRaisesRegex(ValueError, "is kind='prompt'; pass kind='prompt'"):+ mutate()+ self.assertFalse(state.delete_memory("absent"))for kind in ("prompt", "memory", "skill", "subagent"):entry_id = f"{kind}_entry"self.assertEqual(state.get(kind, entry_id).version, 2)self.assertIn("updated", state.get(kind, entry_id).content)- delete_method = getattr(state, f"delete_{'prompt_note' if kind == 'prompt' else kind}")- self.assertTrue(delete_method(entry_id))+ self.assertTrue(state.delete_memory(entry_id, kind=kind))self.assertIsNone(state.get(kind, entry_id))- self.assertFalse(delete_method(entry_id))+ self.assertFalse(state.delete_memory(entry_id, kind=kind))self.assertEqual(state.list(), [])+ def test_create_defaults_and_skill_only_fields(self) -> None:+ with tempfile.TemporaryDirectory() as temp_dir:+ state = HarnessState(Path(temp_dir) / "harness_state.json")++ default_entry = state.create_memory("Default", "No kind given.")+ self.assertEqual(default_entry.kind, "memory")+ self.assertEqual(default_entry.topic, "general")+ self.assertEqual(state.create_memory("Note", "Policy note.", kind="prompt").topic, "policy")++ for kind in ("memory", "prompt", "subagent"):+ with self.assertRaisesRegex(ValueError, "only accepted for kind='skill'"):+ state.create_memory("Bad", "content", id=f"bad_{kind}", kind=kind, reference=PYTHON_REFERENCE)+ with self.assertRaisesRegex(ValueError, "only accepted for kind='skill'"):+ state.update_memory(default_entry.id, "Bad", "content", kind=kind, arguments={})++ with self.assertRaisesRegex(TypeError, "path was renamed to topic"):+ state.create_memory("Grouped", "content", **{"path": "repo/testing"})++ def test_removed_per_kind_wrappers_name_their_replacement(self) -> None:+ with tempfile.TemporaryDirectory() as temp_dir:+ state = HarnessState(Path(temp_dir) / "harness_state.json")++ for name, replacement in (+ ("update_skill", "update_memory(..., kind='skill')"),+ ("delete_prompt_note", "delete_memory(..., kind='prompt')"),+ ("create_subagent", "create_memory(..., kind='subagent')"),+ ):+ with self.assertRaisesRegex(AttributeError, re.escape(f"{name} was removed; use rlm.harness.{replacement}")):+ getattr(state, name)+def test_persists_entries_and_refinements(self) -> None:with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")@@ -92,21 +134,23 @@ class HarnessStateTest(unittest.TestCase):memory = state.create_memory("Prefer focused patches","Small harness updates are easier to validate than broad rewrites.",- path="engineering",+ topic="engineering",)- skill = state.create_skill(+ skill = state.create_memory("Check failures first","Inspect current failure evidence before editing code.",id="failure_first",reference=PYTHON_REFERENCE,arguments={"failure_log": {"type": "string", "description": "Current failure evidence."}},+ kind="skill",)- subagent = state.create_subagent(+ subagent = state.create_memory("Reviewer","Review the proposed patch for regressions and missing tests.",metadata={"max_turns": 3},+ kind="subagent",)- state.create_prompt_note("Refinement cadence", "Refine only after repeated evidence.")+ state.create_memory("Refinement cadence", "Refine only after repeated evidence.", kind="prompt")event = state.record_refinement("skill failed twice",["updated failure_first skill", "added reviewer subagent"],@@ -132,6 +176,7 @@ class HarnessStateTest(unittest.TestCase):self.assertIn("receiver_role='parent'", overview)self.assertIn("await rlm.list_subagents()", overview)self.assertIn("receiver_role='child'", overview)+ self.assertIn("(engineering, v1)", overview)self.assertIn("refinements: 1", reloaded.overview())def test_save_failure_preserves_previous_state_on_disk(self) -> None:@@ -253,7 +298,12 @@ class HarnessStateTest(unittest.TestCase):},"missing_content": {"title": "Missing content",- }+ },+ "grouped": {+ "title": "Grouped",+ "content": "c",+ "path": "repo/testing",+ },}},"refinements": [@@ -278,7 +328,7 @@ class HarnessStateTest(unittest.TestCase):self.assertEqual(state.get("memory", "known").content, "Loaded despite extra keys.")self.assertEqual(state.get("memory", "known").id, "known")self.assertEqual(state.get("memory", "known").kind, "memory")- self.assertEqual(state.get("memory", "known").path, "general")+ self.assertEqual(state.get("memory", "known").topic, "general")self.assertEqual(state.get("memory", "known").source, "agent")self.assertIsNone(state.get("memory", "mismatched"))self.assertEqual(state.get("memory", "known").version, 2)@@ -288,6 +338,12 @@ class HarnessStateTest(unittest.TestCase):self.assertEqual(state.refinements[0].changes, ["1", "loaded"])self.assertEqual(len(state.refinements), 1)self.assertIn("1, loaded", state.overview())+ self.assertEqual(state.get("memory", "grouped").topic, "repo/testing")++ state.update_memory("grouped", "Grouped", "resaved")+ saved = json.loads(state_path.read_text(encoding="utf-8"))["entries"]["memory"]["grouped"]+ self.assertEqual(saved["topic"], "repo/testing")+ self.assertEqual(saved["path"], "repo/testing")updated = state.update_memory("known", "Known memory", "Updated content.")self.assertEqual(updated.version, 3)@@ -296,7 +352,7 @@ class HarnessStateTest(unittest.TestCase):with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")- created = state.create_skill(+ created = state.create_memory("Edit file","Apply a targeted edit.",id="edit_file",@@ -311,8 +367,9 @@ class HarnessStateTest(unittest.TestCase):"find": {"type": "string", "required": True},"replace": {"type": "string", "required": True},},+ kind="skill",)- updated = state.update_skill(+ updated = state.update_memory("edit_file","Edit file","Apply a targeted edit after reading context.",@@ -328,6 +385,7 @@ class HarnessStateTest(unittest.TestCase):"replace": {"type": "string", "required": True},"validate": {"type": "boolean", "default": True},},+ kind="skill",)reloaded = HarnessState(state.file_path)@@ -344,22 +402,24 @@ class HarnessStateTest(unittest.TestCase):state = HarnessState(Path(temp_dir) / "harness_state.json")with self.assertRaisesRegex(ValueError, "Python reference"):- state.create_skill("No reference", "missing", arguments={})+ state.create_memory("No reference", "missing", arguments={}, kind="skill")with self.assertRaisesRegex(ValueError, "reference.type must be 'python'"):- state.create_skill(+ state.create_memory("Shell reference","bad",reference={"type": "shell", "command": "edit"},arguments={},+ kind="skill",)with self.assertRaisesRegex(ValueError, "Python import"):- state.create_skill("No import", "bad", reference={"type": "python", "callable": "run"}, arguments={})+ state.create_memory("No import", "bad", reference={"type": "python", "callable": "run"}, arguments={}, kind="skill")with self.assertRaisesRegex(ValueError, "callable or call_pattern"):- state.create_skill(+ state.create_memory("No callable","bad",reference={"type": "python", "import": "agent_skills.bad"},arguments={},+ kind="skill",)def test_rejects_invalid_entry_fields_before_persisting(self) -> None:@@ -376,7 +436,7 @@ class HarnessStateTest(unittest.TestCase):("numeric id", dict(title="T", content="c", id=7), "id must be a non-empty string, got int"),("unhashable list id", dict(title="T", content="c", id=["x"]), "id must be a non-empty string, got a list"),("falsy numeric id", dict(title="Zero", content="c", id=0), "id must be a non-empty string, got int"),- ("numeric path", dict(title="T", content="c", path=7), "path must be a non-empty string, got int"),+ ("numeric topic", dict(title="T", content="c", topic=7), "topic must be a non-empty string, got int"),("list metadata", dict(title="T", content="c", metadata=["m"]), "metadata must be a dict when provided, got a list"),]:with self.subTest(case=f"create {label}"):@@ -384,15 +444,15 @@ class HarnessStateTest(unittest.TestCase):state.create_memory(**kwargs)with self.subTest(case="subagent with list content"):with self.assertRaisesRegex(ValueError, "content must be a non-empty string, got a list"):- state.create_subagent("T", ["one string"])+ state.create_memory("T", ["one string"], kind="subagent")with self.subTest(case="skill create without a reference"):with self.assertRaisesRegex(ValueError, "skill entries require a Python reference"):- state.create("skill", "Skill", "content", id="orphan_skill")+ state.create_memory("Skill", "content", id="orphan_skill", kind="skill")with self.subTest(case="skill reference as a list"):with self.assertRaisesRegex(- ValueError, "skill entry 'Skill' rejected: skill entries require a Python reference"+ ValueError, "skill entry 'skill' rejected: reference must be a dict when provided, got a list"):- state.create_skill("Skill", "content", reference=["bad"])+ state.create_memory("Skill", "content", reference=["bad"], kind="skill")with self.subTest(case="update with list content"):with self.assertRaisesRegex(ValueError, "content must be a non-empty string, got a list"):state.update_memory("valid_entry", "Valid", ["one string"])@@ -432,54 +492,58 @@ class HarnessStateTest(unittest.TestCase):def test_update_skill_preserves_omitted_arguments(self) -> None:with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")- state.create_skill(+ state.create_memory("Edit file","Apply an edit.",id="edit_file",reference=PYTHON_REFERENCE,arguments={"path": {"type": "string", "required": True}},+ kind="skill",)# Updating only title/content (arguments omitted) must keep the contract.- state.update_skill("edit_file", "Edit file", "Apply an edit carefully.", reference=PYTHON_REFERENCE)+ state.update_memory("edit_file", "Edit file", "Apply an edit carefully.", reference=PYTHON_REFERENCE, kind="skill")self.assertEqual(state.get("skill", "edit_file").arguments, {"path": {"type": "string", "required": True}})# An explicit empty dict still clears it.- state.update_skill("edit_file", "Edit file", "Now argument-free.", reference=PYTHON_REFERENCE, arguments={})+ state.update_memory(+ "edit_file", "Edit file", "Now argument-free.", reference=PYTHON_REFERENCE, arguments={}, kind="skill"+ )self.assertEqual(state.get("skill", "edit_file").arguments, {})def test_update_skill_without_reference_preserves_contract(self) -> None:with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")- state.create_skill(+ state.create_memory("Edit file","Apply an edit.",id="edit_file",reference=PYTHON_REFERENCE,arguments={"path": {"type": "string", "required": True}},+ kind="skill",)# A title/content-only update must not require re-sending the reference,# and must preserve the existing reference and arguments.- updated = state.update_skill("edit_file", "Edit file", "Apply an edit carefully.")+ updated = state.update_memory("edit_file", "Edit file", "Apply an edit carefully.", kind="skill")self.assertEqual(updated.version, 2)self.assertEqual(updated.reference, PYTHON_REFERENCE)self.assertEqual(updated.arguments, {"path": {"type": "string", "required": True}})self.assertEqual(updated.content, "Apply an edit carefully.")- def test_update_preserves_omitted_path(self) -> None:+ def test_update_preserves_omitted_topic(self) -> None:with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")- state.create_memory("Grouped", "content", id="grouped", path="repo/testing")+ state.create_memory("Grouped", "content", id="grouped", topic="repo/testing")- # Updating without a path keeps the custom grouping path.+ # Updating without a topic keeps the custom grouping topic.state.update_memory("grouped", "Grouped", "new content")- self.assertEqual(state.get("memory", "grouped").path, "repo/testing")+ self.assertEqual(state.get("memory", "grouped").topic, "repo/testing")- # An explicit path still moves it.- state.update_memory("grouped", "Grouped", "newer", path="repo/other")- self.assertEqual(state.get("memory", "grouped").path, "repo/other")+ # An explicit topic still moves it.+ state.update_memory("grouped", "Grouped", "newer", topic="repo/other")+ self.assertEqual(state.get("memory", "grouped").topic, "repo/other")def test_in_memory_state_never_touches_disk(self) -> None:previous = os.environ.get("RLM_HARNESS_STATE_DIR")@@ -596,7 +660,7 @@ class HarnessStateTest(unittest.TestCase):future = state_path.stat().st_mtime + 5os.utime(state_path, (future, future))- # create() must observe the external entry and honor create-or-fail.+ # create_memory() must observe the external entry and honor create-or-fail.with self.assertRaisesRegex(ValueError, "already exists"):state.create_memory("Local", "Should not overwrite.", id="dup")self.assertEqual(state.get("memory", "dup").content, "Written elsewhere.")@@ -605,13 +669,13 @@ class HarnessStateTest(unittest.TestCase):with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")- first = state.create_skill("Triage", "old", id="triage", reference=PYTHON_REFERENCE, arguments={})+ first = state.create_memory("Triage", "old", id="triage", reference=PYTHON_REFERENCE, arguments={}, kind="skill")with self.assertRaisesRegex(ValueError, "already exists"):- state.create_skill("Triage", "duplicate", id="triage", reference=PYTHON_REFERENCE, arguments={})+ state.create_memory("Triage", "duplicate", id="triage", reference=PYTHON_REFERENCE, arguments={}, kind="skill")with self.assertRaisesRegex(ValueError, "does not exist"):- state.update_skill("missing", "Missing", "missing", reference=PYTHON_REFERENCE, arguments={})+ state.update_memory("missing", "Missing", "missing", reference=PYTHON_REFERENCE, arguments={}, kind="skill")- second = state.update_skill("triage", "Triage", "new", reference=PYTHON_REFERENCE, arguments={})+ second = state.update_memory("triage", "Triage", "new", reference=PYTHON_REFERENCE, arguments={}, kind="skill")self.assertEqual(first.id, second.id)self.assertEqual(second.content, "new")@@ -1076,7 +1140,7 @@ class HarnessStateTest(unittest.TestCase):with self.assertRaisesRegex(ValueError, "unknown harness kind"):state.get("tool", "tool")with self.assertRaisesRegex(ValueError, "unknown harness kind"):- state.delete("tool", "tool")+ state.delete_memory("tool", kind="tool")with self.assertRaisesRegex(ValueError, "unknown harness kind"):state.list("tool")@@ -1091,7 +1155,7 @@ class HarnessSearchTest(unittest.TestCase):state = HarnessState(Path(temp_dir) / "harness_state.json")state.create_memory("Tea notes", "All about oolong brewing.", id="tea")state.create_memory("Worktree policy", "Use git worktrees for parallel branches.", id="worktree")- state.create_prompt_note("RSI program", "Ship [RSI] PRs from worktrees.", id="rsi")+ state.create_memory("RSI program", "Ship [RSI] PRs from worktrees.", id="rsi", kind="prompt")results = state.search("worktree branches")@@ -1103,8 +1167,8 @@ class HarnessSearchTest(unittest.TestCase):with tempfile.TemporaryDirectory() as temp_dir:state = HarnessState(Path(temp_dir) / "harness_state.json")state.create_memory("Worktree memory", "worktree workflow", id="m1")- state.create_prompt_note("Worktree prompt", "worktree workflow", id="p1")- state.create_prompt_note("Worktree prompt 2", "worktree workflow", id="p2")+ state.create_memory("Worktree prompt", "worktree workflow", id="p1", kind="prompt")+ state.create_memory("Worktree prompt 2", "worktree workflow", id="p2", kind="prompt")prompts = state.search("worktree", kind="prompt")self.assertTrue(prompts)