Implementation:0xranx OpenContext Store moveDoc
| Knowledge Sources | |
|---|---|
| Domains | Knowledge_Management, API |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for moving and renaming documents in the OpenContext knowledge base while preserving stable identifiers, provided by the native store adapter.
Description
The moveDoc, renameDoc, and renameFolder functions reorganize the knowledge base while keeping the database in sync with the filesystem. They are exposed as separate functions but share the same underlying Rust core operations.
Key behavior:
- moveDoc: Moves a document to a different folder. Updates the database `rel_path` and `abs_path`, and moves the file on disk. The `stable_id` remains unchanged.
- renameDoc: Changes the document's file name. Updates both database and filesystem.
- renameFolder: Renames a folder, cascading the path update to all contained documents.
All operations preserve the `stable_id` — existing `oc://doc/<stable_id>` links continue to resolve to the new location.
Usage
- Document reorganization: Move documents between folders as projects evolve.
- Rename for clarity: Rename documents and folders to reflect current understanding.
- Safe reorganization: All operations go through the store API to keep database and filesystem in sync.
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 (UI): src/ui/src/services/move.js
Signature
/**
* Move a document
* @param {{ docPath: string, destFolderPath: string }} options
* @returns {{ old_path: string, new_path: string }}
*/
function moveDoc(options) {
return handleResult(native.get().moveDoc({
docPath: options.docPath,
destFolderPath: options.destFolderPath,
}));
}
/**
* Rename a document
* @param {{ docPath: string, newName: string }} options
* @returns {{ old_path: string, new_path: string }}
*/
function renameDoc(options) {
return handleResult(native.get().renameDoc({
docPath: options.docPath,
newName: options.newName,
}));
}
/**
* Rename a folder
* @param {{ path: string, newName: string }} options
* @returns {{ old_path: string, new_path: string }}
*/
function renameFolder(options) {
return handleResult(native.get().renameFolder({
path: options.path,
newName: options.newName,
}));
}
Import
const { moveDoc, renameDoc, renameFolder } = require('./core/store-native');
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| moveDoc.docPath | string | Yes | Source document path |
| moveDoc.destFolderPath | string | Yes | Destination folder path |
| renameDoc.docPath | string | Yes | Source document path |
| renameDoc.newName | string | Yes | New document name |
| renameFolder.path | string | Yes | Source folder path |
| renameFolder.newName | string | Yes | New folder name |
Outputs
| Name | Type | Description |
|---|---|---|
| returns.old_path | string | Previous relative path |
| returns.new_path | string | New relative path |
Usage Examples
Move a Document (CLI)
oc doc mv projects/old/design.md projects/new/
Rename a Document (CLI)
oc doc rename projects/architecture/old-name.md new-name.md
Move and Rename (JavaScript)
const { moveDoc, renameDoc } = require('./core/store-native');
// Move document to new folder
const moveResult = moveDoc({
docPath: 'projects/old/design.md',
destFolderPath: 'projects/new'
});
console.log(`Moved: ${moveResult.old_path} -> ${moveResult.new_path}`);
// Rename document
const renameResult = renameDoc({
docPath: 'projects/new/design.md',
newName: 'architecture.md'
});
console.log(`Renamed: ${renameResult.old_path} -> ${renameResult.new_path}`);
// stable_id is preserved throughout