Skip to main content
← Back to list
01Issue
FeatureClosedSwamp Club
AssigneesNone

Add context.readResource() to MethodContext for user extension models

Opened by swampadmin · 9/26/2025

Problem

User extension models that need to read back previously written data (e.g., reading discovery results during a pair operation) must use context.dataRepository.getContent() directly. This API uses positional arguments with an internal ModelType object:

context.dataRepository.getContent(context.modelType, context.modelId, dataName)

This is brittle and asymmetric — context.writeResource(specName, name, data) provides a clean high-level API for writes, but there is no equivalent for reads. Extension authors must:

  1. Know to use context.modelType (a ModelType object), not context.definition.id (a string) — the error when you get this wrong (type.toDirectoryPath is not a function) gives no hint about the actual problem.
  2. Manually decode the returned Uint8Array and parse JSON.
  3. Understand internal repository semantics that writeResource otherwise abstracts away.

Proposed Solution

Add a context.readResource(dataName) method to MethodContext that mirrors writeResource:

readResource(dataName: string): Promise<Record<string, unknown> | null>

This would:

  • Use context.modelType and context.modelId internally
  • Decode the Uint8Array and parse JSON automatically
  • Return null if the data doesn't exist

Summary

Changes would be needed in:

  • MethodContext interface in src/domain/models/model.ts to add the readResource method signature
  • method_execution_service.ts to provide the implementation when building the context
  • Symmetry with writeResource — same level of abstraction for both reads and writes

This keeps extension models working at the resource abstraction level without reaching into internal repository APIs.

Alternatives

  • Document the dataRepository.getContent() pattern more prominently (still brittle)
  • Use a named-object argument style for getContent instead of positional args (helps but still exposes internals)
02Bog Flow
OPENTRIAGEDIN PROGRESSCLOSED

Closed

No activity in this phase yet.

03Sludge Pulse

Sign in to post a ripple.