← 返回
未分类 中文

agt0

Local-first agent storage — SQLite database, virtual filesystem, and memory in one .db file. Use when persisting agent state, querying CSV/JSONL/logs with SQ...
本地优先的代理存储 — SQLite 数据库、虚拟文件系统与内存集成在单个 .db 文件中。用于持久化代理状态、查询CSV/JSONL/日志等使用 SQL 的场景。
liuhao6741
未分类 clawhub v1.0.1 1 版本 100000 Key: 无需
★ 0
Stars
📥 349
下载
💾 0
安装
1
版本
#latest

概述

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

npm install -g @seekcontext/agt0
agt0 init <dbname>
agt0 use <dbname>          # set as default (omit db name in later commands)

After agt0 use, you can omit from all commands below.


Essential Patterns

Store and retrieve data (SQL)

# Inline SQL
agt0 sql -q "CREATE TABLE tasks (id INTEGER PRIMARY KEY, title TEXT, status TEXT)"
agt0 sql -q "INSERT INTO tasks (title, status) VALUES ('Build API', 'doing')"
agt0 sql -q "SELECT * FROM tasks WHERE status = 'doing'"

# Execute SQL file
agt0 sql -f schema.sql

Store and retrieve files (CLI)

agt0 fs put ./data.csv myapp:/data/data.csv        # upload file
agt0 fs put -r ./src myapp:/src                     # upload directory
agt0 fs cat myapp:/data/data.csv                    # read file
agt0 fs ls myapp:/data/                             # list directory
agt0 fs get myapp:/data/data.csv ./local.csv        # download file
agt0 fs rm myapp:/data/old.csv                      # delete file
agt0 fs mkdir myapp:/data/exports                   # create directory

Store and retrieve files (SQL)

SELECT fs_write('/memory/context.md', 'User prefers dark mode');
SELECT fs_read('/memory/context.md');
SELECT fs_append('/logs/session.log', 'Step completed' || char(10));
SELECT fs_exists('/config.json');                  -- 1 or 0
SELECT fs_size('/config.json');                    -- bytes

Query files as tables (zero-import)

-- CSV → queryable rows (each row is JSON in _data column)
SELECT json_extract(_data, '$.name') AS name,
       json_extract(_data, '$.email') AS email
FROM fs_csv('/data/users.csv')
WHERE json_extract(_data, '$.role') = 'admin';

-- JSONL structured logs
SELECT json_extract(line, '$.level') AS level, COUNT(*)
FROM fs_jsonl('/logs/app.jsonl')
GROUP BY level;

-- Grep across text files
SELECT _path, _line_number, line
FROM fs_text('/src/**/*.ts')
WHERE line LIKE '%TODO%';

-- Directory listing
SELECT path, type, size, mtime FROM fs_list('/data/');

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.

CREATE VIRTUAL TABLE v_users USING csv_expand('/data/users.csv');
SELECT name, email FROM v_users WHERE role = 'admin';

CREATE VIRTUAL TABLE v_logs USING jsonl_expand('/logs/app.jsonl');
SELECT level, msg FROM v_logs WHERE level = 'error';

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

INSERT INTO users (name, email)
SELECT DISTINCT
  json_extract(_data, '$.name'),
  json_extract(_data, '$.email')
FROM fs_csv('/data/users.csv')
WHERE json_extract(_data, '$.email') IS NOT NULL;

Complete SQL Function Reference

Scalar Functions

FunctionReturnsDescription
---------
fs_read(path)TEXTRead file content as text
fs_write(path, content)INTEGERWrite/overwrite file, returns bytes
fs_append(path, data)INTEGERAppend to file, returns total bytes
fs_exists(path)INTEGER1 if path exists, 0 otherwise
fs_size(path)INTEGERFile size in bytes
fs_mtime(path)TEXTLast modified time (ISO 8601)
fs_remove(path [, recursive])INTEGERDelete file/dir, returns deleted count
fs_mkdir(path [, recursive])INTEGERCreate directory (1=recursive)
fs_truncate(path, size)INTEGERTruncate to byte size
fs_read_at(path, offset, length)TEXTRead byte range as UTF-8
fs_write_at(path, offset, data)INTEGERWrite at byte offset (pads with NUL)

Table-Valued Functions

FunctionColumnsDescription
---------
fs_list(dir)path, type, size, mode, mtimeList directory entries
fs_text(path [, opts])_line_number, line, _pathRead text by line
fs_csv(path [, opts])_line_number, _data, _pathRead CSV (row → JSON)
fs_tsv(path [, opts])_line_number, _data, _pathRead TSV (row → JSON)
fs_jsonl(path [, opts])_line_number, line, _pathRead JSONL by line

Virtual table modules (dynamic columns; single path, no globs):

ModuleExample
------
csv_expandCREATE VIRTUAL TABLE t USING csv_expand('/data/x.csv' [, opts])
tsv_expandCREATE VIRTUAL TABLE t USING tsv_expand('/data/x.tsv' [, opts])
jsonl_expandCREATE 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

agt0 list                                # list all databases
agt0 inspect <db>                        # overview (tables, files, size)
agt0 inspect <db> tables                 # table list with row counts
agt0 inspect <db> schema                 # show CREATE statements
agt0 dump <db> -o backup.sql             # full SQL export
agt0 dump <db> --ddl-only                # schema only
agt0 seed <db> schema.sql                # run SQL file
agt0 delete <db> --yes                   # delete database
agt0 branch create <db> --name staging   # branch (copy) database
agt0 branch list <db>                    # list branches
agt0 branch delete <db> --name staging   # delete branch

Interactive Shells

SQL REPL

agt0 sql <db>

Type SQL ending with ; to execute. Dot commands: .help, .tables, .schema, .fshelp, .quit.

Filesystem Shell

agt0 fs sh <db>

Commands: ls, cd, cat, echo > , mkdir, rm, pwd, exit, help.


Storage Layout

~/.agt0/
├── config.json              # default database setting
└── databases/
    ├── myapp.db             # single file = tables + files + memory
    └── myapp-staging.db     # branch

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.
  • fs_read_at / 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.

版本历史

共 1 个版本

  • v1.0.1 当前
    2026-05-07 05:14 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

ai-intelligence

Mindkeeper

liuhao6741
AI大脑的时间机器——对代理上下文文件进行版本控制。当用户询问 SOUL.md、AGENTS.md、MEMORY.md 等文件的变更时使用。
★ 0 📥 778

Clawprobe

liuhao6741
实时监控OpenClaw智能体的健康状态、Token用量、API费用及上下文窗口。用于检查自身状态、查看上下文使用情况等场景。
★ 0 📥 537

WeChat Share

liuhao6741
在workspace之间导出和导入选定的OpenClaw工作区文件,可选择一次性阅读后销毁(burn‑after‑read)。适用于用户想要分享SOUL.md、AGENTS.md、TO...
★ 0 📥 417