Implementation:0xranx OpenContext Store getDocByStableId
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Management, API |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for resolving document metadata by stable ID (UUID), enabling stable reference links that survive renames and moves.
Description
The getDocByStableId function performs the reverse lookup of `getDocMeta`: given a UUID stable_id, it queries the SQLite database for the document record and returns its current relative path, absolute path, description, and updated_at.
This function is the resolution mechanism behind `oc://doc/<stable_id>` links. When an agent or user encounters a stable link, they call this function (via `oc doc resolve <stable_id>` CLI or `oc_resolve` MCP tool) to find the document's current location.
The stable_id is immutable: it is assigned at document creation and never changes, even if the document is moved or renamed. This makes stable links the preferred citation format.
Usage
- Context Discovery: Resolve stable links encountered in documents or agent outputs to find current paths.
- Citation: The `oc doc resolve` CLI command and `oc_resolve` MCP tool use this function.
- Link validation: Check whether a stable link still points to an existing document.
Code Reference
Source Location
- Repository: OpenContext
- File (JS adapter): src/core/store-native.js
- File (Rust core): crates/opencontext-core/src/lib.rs
- File (CLI): bin/oc.js
- File (MCP): src/mcp/server.js
Signature
/**
* Get document by stable ID
* @param {string} stableId - UUID stable identifier
* @returns {Doc}
*/
function getDocByStableId(stableId) {
return handleResult(native.get().getDocByStableId(stableId));
}
Import
const { getDocByStableId } = require('./core/store-native');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| stableId | string | Yes | UUID stable identifier |
Outputs
| Name | Type | Description |
|---|---|---|
| returns.stable_id | string | UUID stable identifier |
| returns.rel_path | string | Current relative path from contexts root |
| returns.abs_path | string | Current absolute filesystem path |
| returns.description | string | Document description |
| returns.updated_at | null | Last updated timestamp (ms since epoch) |
Usage Examples
Resolve Stable Link (CLI)
oc doc resolve abc-123-def-456
# Output: { "rel_path": "projects/architecture/design.md", "abs_path": "...", ... }
Resolve Stable Link (JavaScript)
const { getDocByStableId } = require('./core/store-native');
const doc = getDocByStableId('abc-123-def-456');
if (doc) {
console.log(`Current path: ${doc.rel_path}`);
console.log(`Description: ${doc.description}`);
// Read the document content
const content = require('fs').readFileSync(doc.abs_path, 'utf8');
} else {
console.log('Document not found (may have been deleted)');
}
MCP Tool Usage
{
"tool": "oc_resolve",
"arguments": {
"stableId": "abc-123-def-456"
}
}
Related Pages
Implements Principle
- Principle:0xranx_OpenContext_Context_Discovery
- Principle:0xranx_OpenContext_Document_Lifecycle_Management