Implementation:0xranx OpenContext Store getDocMeta
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Management, API |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for retrieving document metadata including stable IDs from the OpenContext knowledge base, enabling stable link generation.
Description
The getDocMeta function retrieves metadata for a document by its path. It queries the SQLite database for the document record, returning the stable_id (UUID), relative path, absolute path, description, and updated_at timestamp.
This function is the companion to getDocByStableId: together they enable bidirectional resolution between paths and stable IDs. The `oc doc link` CLI command uses `getDocMeta` to retrieve the stable_id and format it as a `oc://doc/<stable_id>` markdown link.
Usage
- Stable link generation: Retrieve stable_id to generate `oc://doc/<stable_id>` links.
- Citation: Resolve document metadata for citation blocks in agent output.
- Manifest display: Used internally by manifest generation to include descriptions and stable links.
- MCP integration: The `oc_get_link` MCP tool uses this to generate stable links for agents.
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 metadata
* @param {{ docPath: string }} options
* @returns {Doc}
*/
function getDocMeta(options) {
return handleResult(native.get().getDocMeta(options.docPath));
}
Import
const { getDocMeta } = require('./core/store-native');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| options.docPath | string | Yes | Document path relative to contexts/ |
Outputs
| Name | Type | Description |
|---|---|---|
| returns.stable_id | string | UUID stable identifier |
| returns.rel_path | string | Relative path from contexts root |
| returns.abs_path | string | Absolute filesystem path |
| returns.description | string | Document description |
| returns.updated_at | null | Last updated timestamp (ms since epoch) |
Usage Examples
Generate Stable Link (CLI)
oc doc link projects/architecture/design.md
# Output: [design](oc://doc/abc-123-def-456)
Get Metadata (JavaScript)
const { getDocMeta } = require('./core/store-native');
const meta = getDocMeta({ docPath: 'projects/architecture/design.md' });
console.log(`Stable ID: ${meta.stable_id}`);
console.log(`Stable link: [design](oc://doc/${meta.stable_id})`);
Resolve by Stable ID
const { getDocByStableId } = require('./core/store-native');
// Reverse lookup: stable_id -> current path
const doc = getDocByStableId('abc-123-def-456');
console.log(`Current path: ${doc.rel_path}`);
Related Pages
Implements Principle
- Principle:0xranx_OpenContext_Document_Lifecycle_Management
- Principle:0xranx_OpenContext_Context_Discovery