@kruntime/kdrive
v0.1.15
Published
Reusable Drive adapters and factories for KRuntime Komputers.
Readme
@kruntime/kdrive
Reusable Drive factories for KRuntime.
K core defines the Drive contract and mount semantics. @kruntime/kdrive
contains adapters that turn application resources into file-shaped resources:
import { Komputer, ro, rw } from '@kruntime/komputer'
import { textFileDrive, directoryDrive } from '@kruntime/kdrive'
await computer.mount('/home/claw/SOUL.md', ro(textFileDrive({
name: `soul:${userId}`,
read: () => db.profile.soul(userId),
})))
await computer.mount('/home/claw/memory', rw(directoryDrive({
name: `memory:${userId}`,
readdir: path => appMemory.list(userId, path),
readText: path => appMemory.read(userId, path),
writeText: (path, text) => appMemory.write(userId, path, text),
})))The mental model stays Unix:
Drive resource implementation
mount where the resource appears in the Komputer
ro/rw Agent-facing mount authorization
stat('/') whether the mounted thing looks like file, dir, or symlinkDrive factory options are intentionally application-owned. A database-backed
Drive can accept tenantId, readonly, pool, cache, table, or any other
configuration it needs. K only cares that the returned object satisfies the
Drive interface.
Cross-platform Factories
textFileDrive(...)exposes one text file.jsonFileDrive(...)exposes one JSON file.directoryDrive(...)wraps directory-shaped callbacks.
These factories do not import Node APIs and can run in browsers, workers, H5, mini programs, Electron renderers, and server runtimes.
Node Adapter
@kruntime/kdrive/node contains Node-only adapters:
import { localDirDrive, sqliteDirectoryDrive, sqliteTextFileDrive } from '@kruntime/kdrive/node'
await computer.mount('/workspace', localDirDrive('/srv/workspace', {
exposeRealPath: true,
}))
await computer.mount('/home/claw/SOUL.md', rw(sqliteTextFileDrive({
database: './tenant.db',
key: `/tenants/${userId}/SOUL.md`,
})))
await computer.mount('/home/claw/memory', rw(sqliteDirectoryDrive({
database: './tenant.db',
root: `/tenants/${userId}/memory`,
})))exposeRealPath is opt-in because it allows remote shell adapters to receive
real machine paths. K still enforces mount ro/rw; ro real paths require a
remote with hard sandbox enforcement before they can be used by real shell
commands.
SQLite adapters use a filetree table. They are intentionally ordinary Drives:
the same mount('/path', ro|rw(drive)) rule applies, and a reboot simply
creates fresh Drive objects against the same database.
