@tensorix/metahub 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -10
- package/README.zh-CN.md +23 -10
- package/dist/cli/edge-worker-script.d.ts +4 -0
- package/dist/cli/edge-worker-script.d.ts.map +1 -0
- package/dist/cli.js +16882 -8691
- package/dist/cli.js.map +109 -59
- package/dist/core/access-policy.d.ts +82 -0
- package/dist/core/access-policy.d.ts.map +1 -0
- package/dist/core/blobs-core.d.ts +19 -0
- package/dist/core/blobs-core.d.ts.map +1 -1
- package/dist/core/blobs.d.ts.map +1 -1
- package/dist/core/compact.d.ts.map +1 -1
- package/dist/core/config.d.ts +13 -0
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/crdt.d.ts +29 -2
- package/dist/core/crdt.d.ts.map +1 -1
- package/dist/core/data-map.d.ts +105 -0
- package/dist/core/data-map.d.ts.map +1 -0
- package/dist/core/db.d.ts +1 -1
- package/dist/core/db.d.ts.map +1 -1
- package/dist/core/documents.d.ts.map +1 -1
- package/dist/core/errors.d.ts +2 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/grants-core.d.ts +132 -0
- package/dist/core/grants-core.d.ts.map +1 -0
- package/dist/core/guest-intent.d.ts +33 -0
- package/dist/core/guest-intent.d.ts.map +1 -0
- package/dist/core/hash.d.ts +4 -0
- package/dist/core/hash.d.ts.map +1 -0
- package/dist/core/history.d.ts.map +1 -1
- package/dist/core/hlc.d.ts +5 -0
- package/dist/core/hlc.d.ts.map +1 -1
- package/dist/core/ids.d.ts +1 -1
- package/dist/core/ids.d.ts.map +1 -1
- package/dist/core/inject-runtime.d.ts +8 -0
- package/dist/core/inject-runtime.d.ts.map +1 -0
- package/dist/core/intent-retention.d.ts +23 -0
- package/dist/core/intent-retention.d.ts.map +1 -0
- package/dist/core/md/inline.d.ts +6 -2
- package/dist/core/md/inline.d.ts.map +1 -1
- package/dist/core/node.d.ts +13 -0
- package/dist/core/node.d.ts.map +1 -1
- package/dist/core/records.d.ts +31 -0
- package/dist/core/records.d.ts.map +1 -1
- package/dist/core/schema-init.d.ts +19 -2
- package/dist/core/schema-init.d.ts.map +1 -1
- package/dist/core/schema.d.ts +1 -1
- package/dist/core/schema.d.ts.map +1 -1
- package/dist/core/shares.d.ts +15 -0
- package/dist/core/shares.d.ts.map +1 -1
- package/dist/core/site-channel-lifecycle.d.ts +10 -0
- package/dist/core/site-channel-lifecycle.d.ts.map +1 -0
- package/dist/core/site-channel-store.d.ts +120 -0
- package/dist/core/site-channel-store.d.ts.map +1 -0
- package/dist/core/site-channels.d.ts +65 -0
- package/dist/core/site-channels.d.ts.map +1 -0
- package/dist/core/sites-core.d.ts +100 -7
- package/dist/core/sites-core.d.ts.map +1 -1
- package/dist/core/sites.d.ts +65 -2
- package/dist/core/sites.d.ts.map +1 -1
- package/dist/core/sync/anti-abuse.d.ts +26 -0
- package/dist/core/sync/anti-abuse.d.ts.map +1 -0
- package/dist/core/sync/auth.d.ts +30 -2
- package/dist/core/sync/auth.d.ts.map +1 -1
- package/dist/core/sync/blob-routes.d.ts.map +1 -1
- package/dist/core/sync/cf-api.d.ts +54 -0
- package/dist/core/sync/cf-api.d.ts.map +1 -0
- package/dist/core/sync/cf-oauth.d.ts +91 -0
- package/dist/core/sync/cf-oauth.d.ts.map +1 -0
- package/dist/core/sync/client.d.ts +12 -0
- package/dist/core/sync/client.d.ts.map +1 -1
- package/dist/core/sync/data-map-db.d.ts +8 -0
- package/dist/core/sync/data-map-db.d.ts.map +1 -0
- package/dist/core/sync/devices.d.ts +65 -0
- package/dist/core/sync/devices.d.ts.map +1 -0
- package/dist/core/sync/drop-host.d.ts +40 -0
- package/dist/core/sync/drop-host.d.ts.map +1 -0
- package/dist/core/sync/drop-keys.d.ts +64 -0
- package/dist/core/sync/drop-keys.d.ts.map +1 -0
- package/dist/core/sync/drop-protocol.d.ts +94 -0
- package/dist/core/sync/drop-protocol.d.ts.map +1 -0
- package/dist/core/sync/drop-pull.d.ts +67 -0
- package/dist/core/sync/drop-pull.d.ts.map +1 -0
- package/dist/core/sync/drop-wire.d.ts +39 -0
- package/dist/core/sync/drop-wire.d.ts.map +1 -0
- package/dist/core/sync/e2ee.d.ts +3 -0
- package/dist/core/sync/e2ee.d.ts.map +1 -1
- package/dist/core/sync/edge-config.d.ts +77 -0
- package/dist/core/sync/edge-config.d.ts.map +1 -0
- package/dist/core/sync/edge-connect.d.ts +13 -0
- package/dist/core/sync/edge-connect.d.ts.map +1 -0
- package/dist/core/sync/edge-service.d.ts +100 -0
- package/dist/core/sync/edge-service.d.ts.map +1 -0
- package/dist/core/sync/grants-routes.d.ts +46 -0
- package/dist/core/sync/grants-routes.d.ts.map +1 -0
- package/dist/core/sync/guest-session.d.ts +29 -0
- package/dist/core/sync/guest-session.d.ts.map +1 -0
- package/dist/core/sync/html-escape.d.ts +2 -0
- package/dist/core/sync/html-escape.d.ts.map +1 -0
- package/dist/core/sync/http-status.d.ts +14 -0
- package/dist/core/sync/http-status.d.ts.map +1 -0
- package/dist/core/sync/http-util.d.ts +6 -0
- package/dist/core/sync/http-util.d.ts.map +1 -0
- package/dist/core/sync/pairing.d.ts +9 -9
- package/dist/core/sync/pairing.d.ts.map +1 -1
- package/dist/core/sync/partition.d.ts +77 -0
- package/dist/core/sync/partition.d.ts.map +1 -0
- package/dist/core/sync/peers-routes.d.ts.map +1 -1
- package/dist/core/sync/peers.d.ts +77 -0
- package/dist/core/sync/peers.d.ts.map +1 -1
- package/dist/core/sync/protocol.d.ts +2 -0
- package/dist/core/sync/protocol.d.ts.map +1 -1
- package/dist/core/sync/rate-limit.d.ts +20 -0
- package/dist/core/sync/rate-limit.d.ts.map +1 -0
- package/dist/core/sync/recovery.d.ts +9 -0
- package/dist/core/sync/recovery.d.ts.map +1 -0
- package/dist/core/sync/room-client.d.ts +50 -0
- package/dist/core/sync/room-client.d.ts.map +1 -0
- package/dist/core/sync/room-peer.d.ts +62 -0
- package/dist/core/sync/room-peer.d.ts.map +1 -0
- package/dist/core/sync/room-protocol.d.ts +130 -0
- package/dist/core/sync/room-protocol.d.ts.map +1 -0
- package/dist/core/sync/room-serve.d.ts +38 -0
- package/dist/core/sync/room-serve.d.ts.map +1 -0
- package/dist/core/sync/room-url.d.ts +4 -0
- package/dist/core/sync/room-url.d.ts.map +1 -0
- package/dist/core/sync/routes.d.ts +4 -1
- package/dist/core/sync/routes.d.ts.map +1 -1
- package/dist/core/sync/seal.d.ts +22 -0
- package/dist/core/sync/seal.d.ts.map +1 -0
- package/dist/core/sync/server.d.ts +7 -0
- package/dist/core/sync/server.d.ts.map +1 -1
- package/dist/core/sync/share-actions.d.ts +55 -6
- package/dist/core/sync/share-actions.d.ts.map +1 -1
- package/dist/core/sync/share-export.d.ts +14 -0
- package/dist/core/sync/share-export.d.ts.map +1 -1
- package/dist/core/sync/share-render.d.ts +9 -1
- package/dist/core/sync/share-render.d.ts.map +1 -1
- package/dist/core/sync/share-serve.d.ts +5 -1
- package/dist/core/sync/share-serve.d.ts.map +1 -1
- package/dist/core/sync/site-channel-reconcile.d.ts +26 -0
- package/dist/core/sync/site-channel-reconcile.d.ts.map +1 -0
- package/dist/core/sync/site-publish-recovery.d.ts +32 -0
- package/dist/core/sync/site-publish-recovery.d.ts.map +1 -0
- package/dist/core/sync/site-reachability.d.ts +13 -0
- package/dist/core/sync/site-reachability.d.ts.map +1 -0
- package/dist/core/sync/sites-routes.d.ts.map +1 -1
- package/dist/core/sync/sites-serve.d.ts +24 -1
- package/dist/core/sync/sites-serve.d.ts.map +1 -1
- package/dist/core/sync/storage-s3-bun.d.ts +1 -24
- package/dist/core/sync/storage-s3-bun.d.ts.map +1 -1
- package/dist/core/sync/storage-s3-sign.d.ts +43 -0
- package/dist/core/sync/storage-s3-sign.d.ts.map +1 -0
- package/dist/core/sync/storage.d.ts +59 -0
- package/dist/core/sync/storage.d.ts.map +1 -1
- package/dist/db-worker.js +206 -76
- package/dist/edge-worker.js +3960 -0
- package/dist/index.js +13175 -6670
- package/dist/index.js.map +87 -41
- package/dist/metahub-sdk.js +10 -1
- package/dist/mh-runtime.js +1 -1
- package/dist/room/do-driver.d.ts +30 -0
- package/dist/room/do-driver.d.ts.map +1 -0
- package/dist/sw.js +10 -1
- package/dist/webui/server/edge-routes.d.ts +3 -0
- package/dist/webui/server/edge-routes.d.ts.map +1 -0
- package/dist/webui/server/json-handler.d.ts +4 -0
- package/dist/webui/server/json-handler.d.ts.map +1 -0
- package/dist/webui/server/routes.d.ts.map +1 -1
- package/dist/webui/server/share-routes.d.ts.map +1 -1
- package/dist/webui/server/site-hosting-routes.d.ts +7 -0
- package/dist/webui/server/site-hosting-routes.d.ts.map +1 -0
- package/dist/webui.js +192 -137
- package/dist/workers/edge-worker.d.ts +66 -0
- package/dist/workers/edge-worker.d.ts.map +1 -0
- package/dist/workers/room.d.ts +34 -0
- package/dist/workers/room.d.ts.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -78,15 +78,19 @@ mh --server --port 7777
|
|
|
78
78
|
mh sync http://a-host:7777
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
Pair two devices once and they sync both ways on a timer — no need to run `mh sync` each time. The same `sync` command also moves a single document or table to/from a local file (document ↔ Markdown, table ↔ CSV). See the [system-design docs](./docs/system-design/) for how it works.
|
|
81
|
+
Pair two devices once (`mh config device code` / `mh config device add`) and they sync both ways on a timer — no need to run `mh sync` each time. `mh status` answers "where does my data live and how fresh is each copy" from local state alone, so it works offline. The same `sync` command also moves a single document or table to/from a local file (document ↔ Markdown, table ↔ CSV). See the [system-design docs](./docs/system-design/) for how it works.
|
|
82
82
|
|
|
83
83
|
## WebUI, API, and agent-hosted sites
|
|
84
84
|
|
|
85
|
-
`mh --server` serves a browser **WebUI** at `/` (browse and inline-edit tables,
|
|
85
|
+
`mh --server` serves a browser **WebUI** at `/` (browse and inline-edit tables, a **CodeMirror 6** WYSIWYG Markdown editor — slash menu, doc tables, media embeds, `[[…]]` internal links, one-click code-block formatting, source/blocks toggle, find, TOC — full-text search, manage agent sites). The same server also exposes:
|
|
86
86
|
|
|
87
87
|
- `/api/*` — REST endpoints over your tables and documents (read **and** write; hosted site pages call them same-origin).
|
|
88
88
|
- `/docs` — auto-generated OpenAPI documentation.
|
|
89
|
-
- `/sites/<name>/` — `mh site
|
|
89
|
+
- `/sites/<name>/` — `mh site upload` hosts the HTML/CSS/JS an agent generates; pages call `/api/*` same-origin, or import the optional typed client at `/metahub-sdk.js` (a local mini-Supabase). Note the trust model: hosted pages are same-origin, so any published site effectively holds full hub access — publish only sites you or your agent authored.
|
|
90
|
+
- `/sites/<name>/api/*` — the **guest** data surface of a *public* site: anonymous visitors get exactly the table×operation access you granted with `mh site grant` (`read`/`create`/`update` — never delete), optionally behind a password or Turnstile.
|
|
91
|
+
- `/share/<slug>` — `mh share` publishes a doc/database/site as a public link (view = read-only SSR, edit = accepts guest writes; optional password + expiry), over a server, an S3 bucket, or an always-on room on your own Cloudflare edge.
|
|
92
|
+
|
|
93
|
+
**Publishing when your device is offline** is optional and runs entirely in *your* Cloudflare account: `mh edge deploy` (sign in with Cloudflare, or paste an API token) puts up one Worker with two namespaces — a **write inbox** that accepts sealed, encrypted visitor submissions your device ingests on its next sync round, and **rooms** (Durable Objects) that keep a shared site live and realtime while every device of yours is asleep. metahub itself operates no backend: the edge only ever holds ciphertext envelopes, or the partition you explicitly shared.
|
|
90
94
|
|
|
91
95
|
Requests are guarded by a single token (persisted in `~/.metahub`). The server binds `127.0.0.1` by default; only `--host 0.0.0.0` exposes it, and credentials travel as plaintext Bearer — put it behind a trusted network or TLS (a reverse proxy like Caddy / Tailscale Serve, or `--tls-cert`/`--tls-key` to terminate TLS directly). Details in the [system-design docs](./docs/system-design/).
|
|
92
96
|
|
|
@@ -105,7 +109,7 @@ The WebUI is an installable PWA. Open **Settings → 离线副本** and this bro
|
|
|
105
109
|
|
|
106
110
|
| Command | Description |
|
|
107
111
|
| --- | --- |
|
|
108
|
-
| `mh init` | Create `~/.metahub` |
|
|
112
|
+
| `mh init` | Create `~/.metahub` (`--claude` / `--codex` install this guide as a Claude Code `/mh` / Codex `$mh` skill instead) |
|
|
109
113
|
| `mh db create\|list\|get\|delete` | Manage databases (tables) |
|
|
110
114
|
| `mh use [<db>] [--clear]` | Set/show the "current db" (record/prop default to it) |
|
|
111
115
|
| `mh get <ref>` | Universal lookup: resolve by id/prefix/name, auto-detect type |
|
|
@@ -113,7 +117,7 @@ The WebUI is an installable PWA. Open **Settings → 离线副本** and this bro
|
|
|
113
117
|
| `mh record create\|list\|get\|update\|delete` | Manage records (rows) |
|
|
114
118
|
| `mh doc create\|list\|get\|update\|delete` | Manage Markdown documents |
|
|
115
119
|
| `mh doc read <id>` | Read body + version token (AI reads before editing) |
|
|
116
|
-
| `mh doc edit <id> --old --new` | Anchored find-and-replace (`--replace-all` / `--if-match`) |
|
|
120
|
+
| `mh doc edit <id> --old --new` | Anchored find-and-replace (`--replace-all` / `--if-match`); `--edits '<json array>'` applies N pairs atomically in one pass |
|
|
117
121
|
| `mh doc append\|prepend <id> --body` | Append a block at the document head/tail |
|
|
118
122
|
| `mh doc history <id>` / `mh doc revert <id> --to <version>` | List a document's revisions / restore a past version (a new forward revision; `doc get --at <version>` previews; revert resurrects a deleted doc) |
|
|
119
123
|
| `mh record history <id> [--field <name>]` / `mh record revert <id> --to <version>` | Record edit history (per-revision field diffs, or one cell's value trail) / restore past cells (resurrects a deleted record) |
|
|
@@ -124,14 +128,23 @@ The WebUI is an installable PWA. Open **Settings → 离线副本** and this bro
|
|
|
124
128
|
| `mh doctor` | Read-only health check: list integrity issues (orphan refs/cells, duplicate paths, doc cycles, name clashes) + oplog/disk stats |
|
|
125
129
|
| `mh repair [--dry-run]` | Deterministic, idempotent repair of auto-fixable issues (changes replicate via oplog); `--dry-run` previews (same as doctor) |
|
|
126
130
|
| `mh compact [--keep <days>] [--dry-run]` | Prune oplog history older than the retention window (default 90d) + GC blobs + VACUUM. Local-only; current data untouched, older history collapses to a baseline |
|
|
127
|
-
| `mh site create\|put\|
|
|
131
|
+
| `mh site create\|scaffold\|put\|upload\|list\|files\|rm\|delete` | Host static sites (HTML/CSS/JS) an agent generates, served by `--server` at `/sites/<name>/`. `scaffold` writes a starter page; `upload <dir>` mirrors a directory (`--create` on first upload, `--prune` to delete what's gone) |
|
|
132
|
+
| `mh site access <site> [public\|private]` | Show or change who can reach a site. Public = token-free; private answers exactly like a nonexistent site. `--show-links` prints capability URLs (they *are* the secret) |
|
|
133
|
+
| `mh site grant <site> <db>:<ops>` / `mh site grants <site>` | Anonymous data access for a public site's `api/` (`read,create,update` — no delete), optionally gated by `--password` / `--turnstile`; `--revoke <db>` / `--clear` to take it back |
|
|
134
|
+
| `mh share create\|list\|servers\|link\|renew\|revoke` | Publish a doc/database/site as a public link (`/share/<slug>`): server SSR, S3 export, or `--room` on your own edge; view/edit permission, optional password + expiry, optional `--grant <db>:<ops>` data surface |
|
|
135
|
+
| `mh edge deploy\|status\|pull\|rotate\|connect` | Your own Cloudflare Worker + D1 (+ Durable Objects): deploy it (sign in with Cloudflare or an API token), check health, pull the write inbox by hand, rotate recipient keys, or attach a second device to an existing edge |
|
|
136
|
+
| `mh blob add <file>` / `mh blob get <hash>` | Store a local file as a content-addressed `/blob/<hash>` URL (embed in a doc) / resolve its bytes (local cache → peers → bucket) |
|
|
137
|
+
| `mh cache [status\|clear\|gc\|full-device\|redundancy\|pin\|unpin]` | Inspect/manage the local blob cache; designate "full blob devices" (durable anchors) so images are safely clearable |
|
|
128
138
|
| `mh token [show\|refresh]` | Show/rotate the persisted server auth token (stored in `~/.metahub`, rotates at 30-day expiry by default) |
|
|
129
139
|
| `mh completion <bash\|zsh\|fish>` | Print a completion script: `eval "$(mh completion zsh)"` |
|
|
130
|
-
| `mh sync
|
|
140
|
+
| `mh sync` | Sync now: one round against every configured device and bucket |
|
|
141
|
+
| `mh sync <url>` | Sync one round with a specific server (CRDT push/pull); uses a stored credential when `/sync` is protected, otherwise prompts for a token in an interactive terminal and remembers it (`--token` for non-interactive) |
|
|
131
142
|
| `mh sync <src> <dst>` | Move a single document/table to/from a file: document ↔ Markdown, table ↔ CSV; direction inferred from which side is an in-repo entity |
|
|
132
|
-
| `mh
|
|
133
|
-
| `mh config
|
|
134
|
-
| `mh config
|
|
143
|
+
| `mh status` | Where your data lives and how fresh each copy is: every device/bucket, its freshness, the one issue that matters most, and what to do about it. Purely local — it answers offline |
|
|
144
|
+
| `mh config` | Interactive wizard over everything below (`server` / `device` / `backup` / `edge`). Daily *tools* stay top-level; anything that changes long-lived state lives under `config` |
|
|
145
|
+
| `mh config server --port … --host … --sync-interval …` | Server settings persisted in `~/.metahub` (CLI flags still win at startup) |
|
|
146
|
+
| `mh config device code\|add\|list\|revoke` | Pair devices with a one-time code, inspect the roster (how each joined, last activity, whether it can be cut off — `--refresh` adds bucket presence), or cut one off |
|
|
147
|
+
| `mh config backup connect\|list\|rotate\|recovery\|anchors` | Attach a cloud bucket (S3/R2) for offline store-and-forward — direct keys, an `--enroll` code/QR, or `--provision-r2` to create the bucket first. `rotate` re-keys after losing a device; `recovery` prints a hand-copyable recovery card; `anchors` sets blob redundancy |
|
|
135
148
|
| `mh --server [--port] [--host] [--debug] [--token] [--sync-interval] [--no-auto-sync] [--tls-cert --tls-key]` | Start the server: `/sync` (master token or pairing credential) + WebUI/PWA at `/` + `/api/*` REST + `/docs` (OpenAPI) + static sites `/sites/<name>/` + token exchange `/auth/token` + pairing `/api/pair`; a built-in timer auto-syncs paired peers; `--tls-*` serves https directly (PEM paths) |
|
|
136
149
|
|
|
137
150
|
</details>
|
package/README.zh-CN.md
CHANGED
|
@@ -71,15 +71,19 @@ mh --server --port 7777
|
|
|
71
71
|
mh sync http://a-host:7777
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
|
|
74
|
+
配对一次(`mh config device code` / `mh config device add`)后即可后台**周期性自动双向同步**,不必每次手敲 `mh sync`。`mh status` 只凭本地状态就能回答「我的数据存在哪几处、每处有多新」,因此离线也答得出。同一条 `sync` 命令也能在「单个文档 / 数据表」与本地文件之间导入导出(文档 ↔ markdown、数据表 ↔ CSV)。原理详见[系统设计文档](./docs/system-design/)。
|
|
75
75
|
|
|
76
76
|
## WebUI、API 与 Agent 站点
|
|
77
77
|
|
|
78
|
-
`mh --server` 在根路径 `/` 内置浏览器 **WebUI**(浏览 /
|
|
78
|
+
`mh --server` 在根路径 `/` 内置浏览器 **WebUI**(浏览 / 行内编辑数据表、**CodeMirror 6** 所见即所得 Markdown 编辑器——斜杠菜单、文档表格、媒体嵌入、`[[…]]` 文档内链、代码块一键格式化、源码/块模式切换、查找、TOC、全文搜索、管理 agent 站点)。同一服务端还暴露:
|
|
79
79
|
|
|
80
80
|
- `/api/*` —— REST 接口,读写本库的数据表与文档。
|
|
81
81
|
- `/docs` —— 自动生成的 OpenAPI 文档。
|
|
82
|
-
- `/sites/<name>/` —— `mh site
|
|
82
|
+
- `/sites/<name>/` —— `mh site upload` 托管 agent 生成的 HTML/CSS/JS;页面同源调用 `/api/*` 即可读本库数据(一个本地 mini-Supabase)。
|
|
83
|
+
- `/sites/<name>/api/*` —— **公开**站点的访客数据面:匿名访客只拿到你用 `mh site grant` 明确开出的「表 × 操作」权限(`read`/`create`/`update`,**没有 delete**),可再加密码或 Turnstile。
|
|
84
|
+
- `/share/<slug>` —— `mh share` 把文档/数据库/站点发布成公开链接(view = 只读 SSR,edit = 接受 guest 写入;可加密码 + 过期),经 server、S3 桶,或你自己 Cloudflare 边缘上的常在线房间。
|
|
85
|
+
|
|
86
|
+
**设备离线时也想让别人访问**是可选能力,且完全跑在**你自己的** Cloudflare 账号里:`mh edge deploy`(用 Cloudflare 登录,或粘贴 API token)部署一个 Worker、两个命名空间——**写信箱**收下访客的密文投稿,你的设备下次同步时再解密入库;**房间**(Durable Object)让分享出去的站点在你所有设备都休眠时依然实时可用。metahub 自己不运营任何后端:边缘上要么只有密文信封,要么只有你明确分享出去的那一小块分区。
|
|
83
87
|
|
|
84
88
|
每个请求由单 token 守护(持久化在 `~/.metahub`)。服务端默认只绑 `127.0.0.1`;`--host 0.0.0.0` 才对外,此时凭据以明文 Bearer 传输,请置于可信网络或前置 TLS。细节见[系统设计文档](./docs/system-design/)。
|
|
85
89
|
|
|
@@ -90,7 +94,7 @@ mh sync http://a-host:7777
|
|
|
90
94
|
|
|
91
95
|
| 命令 | 说明 |
|
|
92
96
|
| --- | --- |
|
|
93
|
-
| `mh init` | 创建 `~/.metahub` |
|
|
97
|
+
| `mh init` | 创建 `~/.metahub`(`--claude` / `--codex` 改为把本指南装成 Claude Code `/mh` / Codex `$mh` skill) |
|
|
94
98
|
| `mh db create\|list\|get\|delete` | 管理数据库(表) |
|
|
95
99
|
| `mh use [<db>] [--clear]` | 设置/显示「当前库」(record/prop 默认作用于它) |
|
|
96
100
|
| `mh get <ref>` | 通用查找:按 id/前缀/名字解析,自动判别类型 |
|
|
@@ -98,7 +102,7 @@ mh sync http://a-host:7777
|
|
|
98
102
|
| `mh record create\|list\|get\|update\|delete` | 管理记录(行) |
|
|
99
103
|
| `mh doc create\|list\|get\|update\|delete` | 管理 markdown 文档 |
|
|
100
104
|
| `mh doc read <id>` | 读正文 + version token(AI 改前先读) |
|
|
101
|
-
| `mh doc edit <id> --old --new` | 锚定查找替换(`--replace-all` / `--if-match
|
|
105
|
+
| `mh doc edit <id> --old --new` | 锚定查找替换(`--replace-all` / `--if-match`);`--edits '<json 数组>'` 一次原子应用 N 对 |
|
|
102
106
|
| `mh doc append\|prepend <id> --body` | 在文档首/尾追加块 |
|
|
103
107
|
| `mh doc history <id>` / `mh doc revert <id> --to <version>` | 列出文档修订历史 / 恢复到某版本(回滚是一次新的正向修订;`doc get --at <version>` 预览;revert 可复活已删文档) |
|
|
104
108
|
| `mh record history <id> [--field <名>]` / `mh record revert <id> --to <version>` | 记录修改历史(逐修订字段 diff,或单字段值变迁)/ 恢复历史值(可复活已删记录) |
|
|
@@ -109,14 +113,23 @@ mh sync http://a-host:7777
|
|
|
109
113
|
| `mh doctor` | 只读体检:列出逻辑完整性问题(孤儿引用/单元格、重复路径、文档环、重名等)+ oplog/磁盘统计 |
|
|
110
114
|
| `mh repair [--dry-run]` | 确定性、幂等修复可自动修的问题(改动随 oplog 复制);`--dry-run` 仅预览(等价 doctor) |
|
|
111
115
|
| `mh compact [--keep <天数>] [--dry-run]` | 清理保留窗口(默认 90 天)之外的 oplog 历史 + 回收无引用 blob + VACUUM。纯本地操作;当前数据不变,窗口外历史坍缩为基线(无法再回滚到更早版本) |
|
|
112
|
-
| `mh site create\|put\|
|
|
116
|
+
| `mh site create\|scaffold\|put\|upload\|list\|files\|rm\|delete` | 托管 agent 生成的静态站点(HTML/CSS/JS),由 `--server` 在 `/sites/<name>/` serve 出去。`scaffold` 写一份起步页;`upload <目录>` 镜像整个目录(首次加 `--create`,`--prune` 连带删除本地已不存在的文件) |
|
|
117
|
+
| `mh site access <site> [public\|private]` | 查看 / 修改「谁可以访问这个站点」。public = 免 token;private 的响应与「不存在」完全一致。`--show-links` 才打印能力 URL(链接本身即密钥) |
|
|
118
|
+
| `mh site grant <site> <db>:<ops>` / `mh site grants <site>` | 给公开站点的 `api/` 开匿名数据授权(`read,create,update`,无 delete),可用 `--password` / `--turnstile` 加门;`--revoke <db>` / `--clear` 收回 |
|
|
119
|
+
| `mh share create\|list\|servers\|link\|renew\|revoke` | 把文档/数据库/站点发布成公开链接(`/share/<slug>`):server SSR、S3 导出,或 `--room` 上你自己的边缘;view/edit 权限、可选密码 + 过期、可选 `--grant <db>:<ops>` 数据面 |
|
|
120
|
+
| `mh edge deploy\|status\|pull\|rotate\|connect` | 你自己的 Cloudflare Worker + D1(+ Durable Object):部署(用 Cloudflare 登录或 API token)、查健康、手动拉一轮写信箱、轮换收件密钥、把第二台设备接到既有 edge |
|
|
121
|
+
| `mh blob add <file>` / `mh blob get <hash>` | 把本地文件存成内容寻址 `/blob/<hash>` URL(嵌入文档)/ 取回字节(本地 cache → peer → 桶) |
|
|
122
|
+
| `mh cache [status\|clear\|gc\|full-device\|redundancy\|pin\|unpin]` | 查看/管理本地 blob 缓存;指定「全量设备」(durable 锚)使图片可安全清理 |
|
|
113
123
|
| `mh token [show\|refresh]` | 查看 / 轮换持久化的服务器鉴权 token(存于 `~/.metahub`,默认 30 天到期轮换) |
|
|
114
124
|
| `mh completion <bash\|zsh\|fish>` | 打印补全脚本:`eval "$(mh completion zsh)"` |
|
|
115
|
-
| `mh sync
|
|
125
|
+
| `mh sync` | 立即同步:对每一台已配置的设备与每一个桶各跑一轮 |
|
|
126
|
+
| `mh sync <url>` | 与指定服务端同步一轮(CRDT 推/拉);`/sync` 受保护时按已存凭据直连,否则在交互终端提示输入 token 并记住(`--token` 非交互) |
|
|
116
127
|
| `mh sync <src> <dst>` | 单个文档/数据表与文件互导:文档↔markdown、数据表↔CSV;方向按参数判别(哪侧是库内实体) |
|
|
117
|
-
| `mh
|
|
118
|
-
| `mh config
|
|
119
|
-
| `mh config
|
|
128
|
+
| `mh status` | 数据在哪几处、每处有多新、当前最要紧的问题是什么、该怎么办。纯本地派生,离线可答 |
|
|
129
|
+
| `mh config` | 交互向导,覆盖下面全部(`server` / `device` / `backup` / `edge`)。日常**工具**留在顶层,凡改**长期状态**的都收在 `config` 下 |
|
|
130
|
+
| `mh config server --port … --host … --sync-interval …` | 持久化服务器设置到 `~/.metahub`(启动时 CLI flag 仍优先) |
|
|
131
|
+
| `mh config device code\|add\|list\|revoke` | 用一次性码配对设备、查看设备名册(怎么加入的、最后活跃、能否吊销;`--refresh` 追加桶在场性)、断开某台设备 |
|
|
132
|
+
| `mh config backup connect\|list\|rotate\|recovery\|anchors` | 挂云端桶(S3/R2)做离线 store-and-forward——直填凭据、`--enroll` 码/二维码,或 `--provision-r2` 先替你建桶。`rotate` 丢设备后换钥换短语;`recovery` 打印可手抄的恢复码卡;`anchors` 设 blob 冗余判定 |
|
|
120
133
|
| `mh --server [--port] [--host] [--debug] [--token] [--sync-interval] [--no-auto-sync]` | 启动服务端:`/sync`(主 token 或配对凭据)+ 根路径 WebUI + `/api/*` REST + `/docs`(OpenAPI)+ 静态站点 `/sites/<name>/` + token 交换 `/auth/token` + 配对 `/api/pair`;内置定时器自动同步已配对 peer |
|
|
121
134
|
|
|
122
135
|
</details>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edge-worker-script.d.ts","sourceRoot":"","sources":["../../src/cli/edge-worker-script.ts"],"names":[],"mappings":"AAeA,uDAAuD;AACvD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAExD;AAED,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC,CAmB3D"}
|