agt0 — Agent Storage Skill
One file. All your agent needs.
Local-first database + filesystem + memory in a single SQLite file.
You are using agt0 to persist data. Follow this reference precisely.
Setup
CODEBLOCK0
After agt0 use, you can omit <db> from all commands below.
Essential Patterns
Store and retrieve data (SQL)
CODEBLOCK1
Store and retrieve files (CLI)
CODEBLOCK2
Store and retrieve files (SQL)
CODEBLOCK3
Query files as tables (zero-import)
CODEBLOCK4
CSV / JSONL with real columns (virtual tables; single file only)
Use CREATE VIRTUAL TABLE ... USING csv_expand(...) / tsv_expand / jsonl_expand when you want native column names instead of json_extract(_data, ...). No globs — one path per CREATE. For **/*.csv patterns, keep using fs_csv / fs_jsonl.
CODEBLOCK5
Schema is fixed at CREATE time; DROP and recreate if the file layout changes. JSONL columns = sorted union of object keys from the first AGT0_FS_EXPAND_JSONL_SCAN_LINES non-empty lines (default 256). Optional 2nd arg: same JSON as TVFs (strict, delimiter, header, etc.).
agt0 sql (CLI only): for a literal single-file path (no globs), fs_csv / fs_tsv / fs_jsonl are auto-rewritten so SELECT * returns real columns. Set AGT0_SQL_FS_EXPAND=0 to disable. In Node, call expandFsTableSql(sql, db) from the package if you need the same rewrite.
Import file data into tables
CODEBLOCK6
Complete SQL Function Reference
Scalar Functions
| Function | Returns | Description |
|---|
| INLINECODE24 | TEXT | Read file content as text |
| INLINECODE25 |
INTEGER | Write/overwrite file, returns bytes |
|
fs_append(path, data) | INTEGER | Append to file, returns total bytes |
|
fs_exists(path) | INTEGER | 1 if path exists, 0 otherwise |
|
fs_size(path) | INTEGER | File size in bytes |
|
fs_mtime(path) | TEXT | Last modified time (ISO 8601) |
|
fs_remove(path [, recursive]) | INTEGER | Delete file/dir, returns deleted count |
|
fs_mkdir(path [, recursive]) | INTEGER | Create directory (1=recursive) |
|
fs_truncate(path, size) | INTEGER | Truncate to byte size |
|
fs_read_at(path, offset, length) | TEXT | Read byte range as UTF-8 |
|
fs_write_at(path, offset, data) | INTEGER | Write at byte offset (pads with NUL) |
Table-Valued Functions
| Function | Columns | Description |
|---|
| INLINECODE35 | path, type, size, mode, mtime | List directory entries |
| INLINECODE36 |
linenumber, line, _path | Read text by line |
|
fs_csv(path [, opts]) |
linenumber,
data, path | Read CSV (row → JSON) |
|
fs_tsv(path [, opts]) |
linenumber,
data, path | Read TSV (row → JSON) |
|
fs_jsonl(path [, opts]) |
linenumber, line, _path | Read JSONL by line |
Virtual table modules (dynamic columns; single path, no globs):
| Module | Example |
|---|
| INLINECODE40 | INLINECODE41 |
| INLINECODE42 |
CREATE VIRTUAL TABLE t USING tsv_expand('/data/x.tsv' [, opts]) |
|
jsonl_expand |
CREATE VIRTUAL TABLE t USING jsonl_expand('/logs/x.jsonl' [, opts]) |
Path globs: * = one segment, ** = any depth, ? = one char. Example: /logs/**/*.log.
Options (JSON string, 2nd arg): exclude (comma-separated globs), strict (bool — fail on bad rows), delimiter (string), header (bool). (exclude is ignored by *_expand modules.)
Limits (env vars): AGT0_FS_MAX_FILES, AGT0_FS_MAX_FILE_BYTES, AGT0_FS_MAX_TOTAL_BYTES, AGT0_FS_MAX_ROWS (optional cap per TVF / expand scan), AGT0_FS_PARSE_CHUNK_BYTES, AGT0_FS_PREVIEW_BYTES (multi-file CSV/TSV column discovery), AGT0_FS_EXPAND_JSONL_SCAN_LINES (JSONL key discovery for jsonl_expand), AGT0_SQL_FS_EXPAND (CLI rewrite of literal-path fs_* TVFs; default on).
Database Management
CODEBLOCK7
Interactive Shells
SQL REPL
CODEBLOCK8
Type SQL ending with ; to execute. Dot commands: .help, .tables, .schema, .fshelp, .quit.
Filesystem Shell
CODEBLOCK9
Commands: ls, cd, cat, echo <text> > <path>, mkdir, rm, pwd, exit, help.
Storage Layout
CODEBLOCK10
Override with AGT0_HOME env var.
Critical Rules
- - All data is local. No network calls, no API keys.
- Each database is a single
.db file. Copy it to back up or share. - The
_fs table is internal. Never drop it. - CSV rows from
fs_csv are JSON in _data (json_extract(_data, '$.column_name')), or use csv_expand / tsv_expand for real columns after CREATE VIRTUAL TABLE. - INLINECODE90 /
fs_write_at operate on byte offsets. - The SQL REPL (
.fshelp) and the filesystem shell (help) are different interfaces with different commands. - Glob
* matches one path segment (no /). Use ** to match across directories.
agt0 — 智能体存储技能
一个文件。智能体所需的一切。
本地优先的数据库 + 文件系统 + 内存,全部集成于单个SQLite文件中。
你正在使用 agt0 来持久化数据。请严格遵循本参考文档。
设置
bash
npm install -g @seekcontext/agt0
agt0 init <数据库名>
agt0 use <数据库名> # 设为默认(后续命令可省略数据库名)
执行 agt0 use 后,以下所有命令中均可省略 <数据库> 参数。
核心模式
存储和检索数据(SQL)
bash
内联SQL
agt0 sql -q CREATE TABLE tasks (id INTEGER PRIMARY KEY, title TEXT, status TEXT)
agt0 sql -q INSERT INTO tasks (title, status) VALUES (构建API, 进行中)
agt0 sql -q SELECT * FROM tasks WHERE status = 进行中
执行SQL文件
agt0 sql -f schema.sql
存储和检索文件(命令行)
bash
agt0 fs put ./data.csv myapp:/data/data.csv # 上传文件
agt0 fs put -r ./src myapp:/src # 上传目录
agt0 fs cat myapp:/data/data.csv # 读取文件
agt0 fs ls myapp:/data/ # 列出目录
agt0 fs get myapp:/data/data.csv ./local.csv # 下载文件
agt0 fs rm myapp:/data/old.csv # 删除文件
agt0 fs mkdir myapp:/data/exports # 创建目录
存储和检索文件(SQL)
sql
SELECT fs_write(/memory/context.md, 用户偏好深色模式);
SELECT fs_read(/memory/context.md);
SELECT fs_append(/logs/session.log, 步骤完成 || char(10));
SELECT fs_exists(/config.json); -- 返回1或0
SELECT fs_size(/config.json); -- 返回字节数
将文件作为表查询(零导入)
sql
-- CSV → 可查询的行(每行以JSON格式存储在_data列中)
SELECT jsonextract(data, $.name) AS 姓名,
jsonextract(data, $.email) AS 邮箱
FROM fs_csv(/data/users.csv)
WHERE jsonextract(data, $.role) = admin;
-- JSONL结构化日志
SELECT json_extract(line, $.level) AS 级别, COUNT(*)
FROM fs_jsonl(/logs/app.jsonl)
GROUP BY 级别;
-- 跨文本文件搜索
SELECT path, line_number, line
FROM fs_text(/src//*.ts)
WHERE line LIKE %TODO%;
-- 目录列表
SELECT path, type, size, mtime FROM fs_list(/data/);
带真实列的CSV/JSONL(虚拟表;仅限单个文件)
当需要原生列名而非 jsonextract(data, ...) 时,使用 CREATE VIRTUAL TABLE ... USING csvexpand(...) / tsvexpand / jsonlexpand。不支持通配符 — 每个CREATE对应一个路径。对于/*.csv模式,请继续使用fscsv/fs_jsonl。
sql
CREATE VIRTUAL TABLE vusers USING csvexpand(/data/users.csv);
SELECT name, email FROM v_users WHERE role = admin;
CREATE VIRTUAL TABLE vlogs USING jsonlexpand(/logs/app.jsonl);
SELECT level, msg FROM v_logs WHERE level = error;
模式在CREATE时固定;文件结构变化时需DROP并重新创建。JSONL列 = 前AGT0FSEXPANDJSONLSCAN_LINES个非空行(默认256)中对象键的排序并集。可选的第二个参数:与TVF相同的JSON(strict、delimiter、header等)。
agt0 sql(仅命令行): 对于字面单文件路径(无通配符),fscsv/fstsv/fsjsonl会被自动重写,使SELECT *返回真实列。设置AGT0SQLFSEXPAND=0可禁用。在Node中,如需相同重写,可调用包中的expandFsTableSql(sql, db)。
将文件数据导入表
sql
INSERT INTO users (name, email)
SELECT DISTINCT
jsonextract(data, $.name),
jsonextract(data, $.email)
FROM fs_csv(/data/users.csv)
WHERE jsonextract(data, $.email) IS NOT NULL;
完整SQL函数参考
标量函数
| 函数 | 返回类型 | 描述 |
|---|
| fsread(path) | TEXT | 以文本形式读取文件内容 |
| fswrite(path, content) |
INTEGER | 写入/覆盖文件,返回字节数 |
| fs_append(path, data) | INTEGER | 追加到文件,返回总字节数 |
| fs_exists(path) | INTEGER | 路径存在返回1,否则返回0 |
| fs_size(path) | INTEGER | 文件大小(字节) |
| fs_mtime(path) | TEXT | 最后修改时间(ISO 8601格式) |
| fs_remove(path [, recursive]) | INTEGER | 删除文件/目录,返回删除数量 |
| fs_mkdir(path [, recursive]) | INTEGER | 创建目录(1=递归创建) |
| fs_truncate(path, size) | INTEGER | 截断到指定字节大小 |
| fs
readat(path, offset, length) | TEXT | 以UTF-8格式读取字节范围 |
| fs
writeat(path, offset, data) | INTEGER | 在字节偏移处写入(用NUL填充) |
表值函数
| 函数 | 列 | 描述 |
|---|
| fslist(dir) | path, type, size, mode, mtime | 列出目录条目 |
| fstext(path [, opts]) |
linenumber, line, _path | 按行读取文本 |
| fs
csv(path [, opts]) | line
number, data, _path | 读取CSV(行→JSON) |
| fs
tsv(path [, opts]) | line
number, data, _path | 读取TSV(行→JSON) |
| fs
jsonl(path [, opts]) | line
number, line, path | 按行读取JSONL |
虚拟表模块(动态列;单一路径,无通配符):
| 模块 | 示例 |
|---|
| csvexpand | CREATE VIRTUAL TABLE t USING csvexpand(/data/x.csv [, opts]) |
| tsvexpand |
CREATE VIRTUAL TABLE t USING tsvexpand(/data/x.tsv [, opts]) |
| jsonl
expand | CREATE VIRTUAL TABLE t USING jsonlexpand(/logs/x.jsonl [, opts]) |
路径通配符: = 一个段, = 任意深度,? = 一个字符。示例:/logs//.log。
选项(JSON字符串,第二个参数):exclude(逗号分隔的通配符)、strict(布尔值—失败时处理错误行)、delimiter(字符串)、header(布尔值)。(*_expand模块忽略exclude。)
限制(环境变量):AGT0FSMAXFILES、AGT0FSMAXFILEBYTES、AGT0FSMAXTOTALBYTES、AGT0FSMAXROWS(每个TVF/扩展扫描的可选上限)、AGT0FSPARSECHUNKBYTES、AGT0FSPREVIEWBYTES(多文件CSV/TSV列发现)、AGT0FSEXPANDJSONLSCANLINES(jsonlexpand的JSONL键发现)、AGT0SQLFSEXPAND(命令行对字面路径fs_* TVF的重写;默认开启)。
数据库管理
bash
agt0 list # 列出所有数据库
agt0 inspect <数据库> # 概览(表、文件、大小)
agt0 inspect <数据库> tables # 表列表及行数
agt0 inspect <数据库> schema # 显示CREATE语句
agt0 dump <数据库> -o backup.sql # 完整SQL导出
agt0 dump <数据库> --ddl-only # 仅导出模式
agt0 seed <数据库> schema.sql # 运行SQL文件
agt0 delete <数据库> --yes # 删除数据库
agt