@arshdelight/practi 0.14.0 → 0.17.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.
Files changed (45) hide show
  1. package/README.md +86 -10
  2. package/dist/client.js +43 -36
  3. package/dist/client.js.map +1 -1
  4. package/dist/cmd/branch.js +71 -0
  5. package/dist/cmd/branch.js.map +1 -0
  6. package/dist/cmd/clone.js +50 -56
  7. package/dist/cmd/clone.js.map +1 -1
  8. package/dist/cmd/config.js +2 -0
  9. package/dist/cmd/config.js.map +1 -1
  10. package/dist/cmd/edit.js +5 -14
  11. package/dist/cmd/edit.js.map +1 -1
  12. package/dist/cmd/fetch.js +37 -0
  13. package/dist/cmd/fetch.js.map +1 -0
  14. package/dist/cmd/fix.js +232 -0
  15. package/dist/cmd/fix.js.map +1 -0
  16. package/dist/cmd/instance.js +97 -0
  17. package/dist/cmd/instance.js.map +1 -0
  18. package/dist/cmd/log.js +59 -0
  19. package/dist/cmd/log.js.map +1 -0
  20. package/dist/cmd/merge.js +128 -0
  21. package/dist/cmd/merge.js.map +1 -0
  22. package/dist/cmd/pull.js +45 -92
  23. package/dist/cmd/pull.js.map +1 -1
  24. package/dist/cmd/push.js +66 -65
  25. package/dist/cmd/push.js.map +1 -1
  26. package/dist/cmd/show.js +0 -5
  27. package/dist/cmd/show.js.map +1 -1
  28. package/dist/cmd/switch.js +36 -0
  29. package/dist/cmd/switch.js.map +1 -0
  30. package/dist/commits.js +89 -0
  31. package/dist/commits.js.map +1 -0
  32. package/dist/index.js +210 -10
  33. package/dist/index.js.map +1 -1
  34. package/dist/net.js +29 -9
  35. package/dist/net.js.map +1 -1
  36. package/dist/oauth.js +33 -20
  37. package/dist/oauth.js.map +1 -1
  38. package/dist/state.js +15 -0
  39. package/dist/state.js.map +1 -1
  40. package/dist/sync.js +78 -0
  41. package/dist/sync.js.map +1 -0
  42. package/package.json +2 -2
  43. package/skills/use-practi/SKILL.md +45 -6
  44. package/web-default/detail.js +2 -32
  45. package/web-default/lang.js +0 -4
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # practi
2
2
 
3
- The `practi` command (formerly `pop` / `@arshdelight/pop-cli`): a local registry for POP (Protocol of Practice) documents — a personal, content-addressed collection of practice documents, built on [@arshdelight/pop-sdk](https://www.npmjs.com/package/@arshdelight/pop-sdk). Fully offline: everything lives in your data directory, nothing leaves the machine.
3
+ The `practi` command (formerly `pop` / `@arshdelight/pop-cli`): a local registry for POP (Protocol of Practice) documents — a personal, content-addressed collection of practice documents, built on [@arshdelight/pop-sdk](https://www.npmjs.com/package/@arshdelight/pop-sdk). Your data lives in your data directory and never leaves the machine; the only network calls are the ones you ask for — self-update (`practi update`), fetching the offline vector model (`practi embed pull`), staging a URL attachment (`practi blob add <url>`), and optionally syncing with [practihub](https://practihub.com) (see **Hub**, below).
4
4
 
5
5
  ## Install
6
6
 
@@ -20,8 +20,12 @@ practi repair backfill missing claim timestamps from node fi
20
20
  (idempotent; stamped claims are never touched)
21
21
  practi ls [-a] [--json] list direct POPs (-a also lists indirect nodes)
22
22
  practi new <file.json> create a POP from a JSON document (or --json '<text>', or stdin)
23
- practi edit <hash> <file.json> replace a direct POP with new content (new hash; auto-revision
24
- + GC of nodes unreachable from any direct root)
23
+ practi edit <hash> <file.json> replace a direct POP with new content (new hash; the swap is
24
+ recorded in the local commit log commits.json; GC of nodes
25
+ unreachable from any direct root)
26
+ practi fix <file> | <hash> | --all migrate POP 1.x documents to 2.0: strip the removed history
27
+ fields (revisions/refines), re-validate, report the new hash
28
+ (--dry-run previews)
25
29
  practi gc [--apply] free orphan blobs — bytes no stored node references
26
30
  (dry-run by default; --apply removes)
27
31
  practi migrate [path] [--keep] move the workspace to a new data directory (cut: old dir removed
@@ -33,32 +37,68 @@ practi skill import <dir> | export <ref> [--dir]
33
37
  replay a skill-export directory back into a POP / project one out
34
38
  practi show <hash> [--json] [--doc] inspect one node (hash prefix OK)
35
39
  practi web [--port 4317] [--no-open] browse direct POPs in a local web UI
36
- practi search [query...] search the local workspace (name/description/content substring
37
- + hash prefixes; empty = browse direct roots; --limit N; --json)
40
+ practi search [query...] search every stored node — direct, indirect and orphans alike:
41
+ field-weighted BM25, title-first ranking, multi-word AND that may
42
+ match across fields, `field:` scoping (name: desc: content: flow:
43
+ loop: op: hash:), and a labeled relax tier for a partial majority
44
+ of terms. --limit N; --json; --notes also indexes local notes
45
+ (off by default); --semantic fuses vector recall with the lexical
46
+ ranking (needs embed pull + build). Empty = browse direct roots
47
+ practi similar <hash> [--limit N] [--json]
48
+ content neighbours: the target subtree becomes the query, every
49
+ stored node is scored against it, and each hit lists the shared
50
+ terms that carried it. Literal (character-bigram + latin-word
51
+ relevance), not semantics — a paraphrase will not surface
52
+ practi lint [--json] [--limit N] audit recording quality across every direct pop: the same W_*
53
+ hints `practi new` prints once, on demand. Read-only and never
54
+ blocking (exit code is always 0) — a to-do list, not a gate
55
+ practi embed status report model readiness and index coverage (--json)
56
+ practi embed pull fetch the offline vector model into <data-dir>/models/
57
+ practi embed build [--notes] build/refresh the vector index, incrementally — only hashes not
58
+ already cached; --notes embeds local notes too
59
+ practi embed prune drop vector buckets left by an older model fingerprint
60
+ (the whole layer is optional: no model means lexical-only, and
61
+ `search --semantic` says what is missing rather than recalling less)
38
62
  practi remove <hash> take a direct pop out of the local directory (registry op;
39
63
  GCs nodes unreachable from the rest — shared indirect nodes survive)
40
64
  practi claim <hash> register an existing stored node as a direct pop (indirect → direct)
41
65
  practi unclaim <hash> take a referenced direct pop back to indirect (fails when unreferenced —
42
66
  that would orphan it; delete with "remove" instead)
43
- practi blob add <file-or-url> stage an attachment; emits the attachment entry
44
- (hashes the bytes, stores local blobs in the workspace)
67
+ practi blob add <file-or-url> [--name <name>]
68
+ stage an attachment; emits the attachment entry (hashes the bytes,
69
+ stores local blobs in the workspace). A URL source is fetched
70
+ through the system proxy and its bytes are stored too — the
71
+ pointer itself stays hash-only
45
72
  practi note add <node> -m "<text>" pin a local learning note to any node hash (sidecar
46
73
  notes.json; hash prefix OK)
47
74
  practi note list [hash] [--json] list notes — all (grouped by document) or a subtree
48
75
  practi note edit|delete <note-id> edit (-m "<text>") or remove a note (id prefix OK)
76
+ practi note promote <note-id> [--out <file>]
77
+ turn a note back into a **draft** document of its owning direct
78
+ root, with the note spliced in at the node it was pinned to — it
79
+ drafts and stops, never edits for you (an edit is a new hash:
80
+ that call is yours)
49
81
  ```
50
82
 
51
83
  The data directory is a POP workspace (nodes content-addressed under `nodes/*.md`); `practi.json` records the registered **direct** roots, each with a claim timestamp (time lives on the claim event, never inside content-addressed nodes — the git refs/reflog split; indirect = every other node the direct POPs reference).
52
84
 
53
85
  ### Edit
54
86
 
55
- Editing is replacing: content addressing means an edit produces a **new root hash**. `practi edit <hash> <file.json>` (or `--json` / stdin) validates and stores the new tree, swaps the old root out of the direct registration, and auto-appends a revision record on the root (`from` = old root hash — a history pointer that may dangle by design, never validated). Nodes no longer reachable from any direct root are garbage-collected: content still referenced by another direct POP survives, exclusive descendants go (`--keep` preserves them; `--message` sets the revision note; `--no-revision` skips it).
87
+ Editing is replacing: content addressing means an edit produces a **new root hash**. `practi edit <hash> <file.json>` (or `--json` / stdin) validates and stores the new tree and swaps the old root out of the direct registration. The document carries no history (POP 2.0): the swap is recorded in the local commit log `commits.json` (`from` = old root hash; `--message` sets the commit note that `practi push` sends to the hub). Nodes no longer reachable from any direct root are garbage-collected: content still referenced by another direct POP survives, exclusive descendants go (`--keep` preserves them).
56
88
 
57
89
  ### Search
58
90
 
59
- - `practi search <query...>` searches the local workspace: case-insensitive substring match over name/description/content of every stored node (including indirect); pure-hex queries (≥4 chars) also match hash prefixes.
91
+ - `practi search <query...>` searches **every stored node** — direct, indirect, nodes referenced only through `inputs.from`, and orphans alike. The index text covers name / description / content / declared inputs+outputs / loop prose / op, ranked by field-weighted BM25 with title-first ordering; hits report which field matched. Pure-hex queries (≥4 chars) also match hash prefixes. Derived at search time only: never written back into a node, never part of a hash.
92
+ - **Words are ANDed** — every word must match somewhere, and words may match in *different* fields. Quote a phrase to search it whole. `field:value` scopes one word: `name: desc: content: flow: loop: op: hash:`.
93
+ - **Partial match is labeled** — when strict matching finds nothing, results relax to a strict majority of terms and say so. Treat a relaxed row as a lead, not an answer.
60
94
  - Empty query = browse: lists direct roots with their node counts.
61
- - `--json` emits `{query, results, total}`; `--limit N` caps the output (default 20, max 50).
95
+ - `--json` emits `{query, mode, results, total}`; `--limit N` caps the output (default 20, max 50). `--notes` additionally indexes your local notes (off by default, so existing hit sets are unchanged); `--semantic` fuses vector recall with the lexical ranking via RRF — it needs `embed pull` + `embed build`, and otherwise reports what is missing and is ignored.
96
+
97
+ ### Recording quality (`W_*` hints)
98
+
99
+ `practi new` prints `W_*` hints **once, at creation**. `practi lint` runs the same checks — the same code, no second standard — across every direct pop, aggregates them by code, and ranks the worst nodes first, so the debt you skipped at creation time stays visible instead of quietly accumulating. It is read-only and always exits 0: a to-do list, not a gate.
100
+
101
+ `W_*` are never errors: a document that draws them is stored and registered exactly like one that does not (`E_*` remain the only codes that refuse a document). The vocabulary is the shared part, the thresholds are this implementation's own calibration (pop-spec §6) — and `practi lint --json` emits the full set with `code`/`hash`/`name`/`message` for scripting.
62
102
 
63
103
  ### Web
64
104
 
@@ -81,6 +121,42 @@ Editing is replacing: content addressing means an edit produces a **new root has
81
121
  - `practi note` keeps **local learning notes** in `notes.json` next to `practi.json` — a sidecar, like `claims`. Each note is pinned to a node hash: content addressing gives the pin exact semantics (the note is about *that version* of the node, and can never drift with edits). Notes never enter the POP protocol body.
82
122
  - Two write doors, one file: the CLI (`practi note add <node-hash> -m "step 3 needs admin rights on Windows"` — the gate agents go through) and `practi web`'s **notes sidebar** on the detail page (toggle in the header; lists the current node's notes with inline add/edit/delete; empty file just means an empty panel). The wizard view also renders a node's notes inline on its card, and amber dots in the outline mark nodes that carry notes.
83
123
 
124
+ ### Hub (practihub, optional)
125
+
126
+ The workspace can back onto a practice **instance** on practihub — a single-owner, GitHub-like home for one POP's revision chain, with branches. The binding lives in `practi.json` (`remote` + `instance: {owner, name, branch}`), like git's origin + HEAD. Everything below needs `practi login` (OAuth 2.1 + PKCE, browser consent; credentials in `practi.auth.json`, auto-refreshed with rotation).
127
+
128
+ ```
129
+ practi remote set <url> | remove point at a hub (default: https://practihub.com)
130
+ practi login [--no-open] [--reauth] OAuth sign-in / re-credentials; logout revokes + drops
131
+ practi me show the signed-in account
132
+ practi clone <owner>/<name>[@branch] fetch a practice instance, bind the workspace to it and
133
+ check out its head (git clone: the instance IS the repository)
134
+ practi instance create <name> [--public] [--desc <text>] create + bind (branch main)
135
+ practi instance bind <owner>/<name> | show bind an existing instance / summary
136
+ practi push [hash] [--branch <b>] one call: store the document AND bind it as the branch head —
137
+ the commit is appended with parent = current head (linear lineage
138
+ by construction); --message / the local commit log supplies the
139
+ commit note. Requires a bound instance
140
+ practi log [--branch <b>] [--limit N] [--json] commit history of the current branch (tip first;
141
+ unpushed local entries listed on top)
142
+ practi branch [name] [--from <hash>] | -d <name> list (* = default) / create / delete a branch
143
+ practi switch <branch> switch the bound branch (local pointer; pull brings content)
144
+ practi merge <branch> merge into the current branch: fast-forward (pointer move)
145
+ when the tip's parent chain reaches the head, otherwise a squash
146
+ merge commit is appended (tree = the branch tip, parent = the
147
+ head, note = "merge branch 'X'") — the merge always completes;
148
+ `practi pull` syncs it back
149
+ practi pull sync the bound instance's remote revisions into the workspace
150
+ (git pull inside the repository): missing chain revisions are
151
+ fetched hash-verified, the head fast-forwards when your local
152
+ direct is an ancestor, checks out otherwise
153
+ practi fetch <hash> pull a single POP from the hub into your local registry (direct;
154
+ full sha256 hash). Public content fetchable by anyone, private
155
+ only by instance owners — no instance involved
156
+ ```
157
+
158
+ Content addressing is untouched: the hub re-derives the root hash server-side with the same SDK, and visibility follows the instance — a PUBLIC instance's chain is readable by anyone (that's what `clone`/`fetch` read), PRIVATE only by its owner. Making an instance public is a hub-web workflow. POP lives on the hub only as practice instances — `push`/`pull` require a bound instance (start with `clone` or `instance create`/`bind`); the document store is object storage addressed by hash, not an inbox.
159
+
84
160
  ## License
85
161
 
86
162
  MIT © 2026 arsh tech
package/dist/client.js CHANGED
@@ -1,11 +1,30 @@
1
1
  import { loadCredentials, saveCredentials, isAccessTokenFresh, } from './credentials.js';
2
2
  import { refreshAccessToken } from './oauth.js';
3
+ import { fetchUrl } from './net.js';
4
+ import { createFromDoc, parseDocument } from '@arshdelight/pop-sdk';
5
+ import { openWorkspace } from './workspace.js';
3
6
  /** refresh 被服务端拒绝(token 端点有应答但 HTTP 报错)——凭据已死,需重新 login */
4
7
  export class RefreshRejectedError extends Error {
5
8
  }
6
9
  /** token 端点不可达(网络/超时)——凭据生死未知,报"连不上"而非"已过期" */
7
10
  export class HubUnreachableError extends Error {
8
11
  }
12
+ function toReply(r) {
13
+ const text = r.bytes.toString('utf8');
14
+ return {
15
+ ok: r.ok,
16
+ status: r.status,
17
+ json: async () => {
18
+ try {
19
+ return JSON.parse(text);
20
+ }
21
+ catch {
22
+ return {};
23
+ }
24
+ },
25
+ text: async () => text,
26
+ };
27
+ }
9
28
  /**
10
29
  * 登录态之上的远程请求层:保证请求带有效 Bearer access token。
11
30
  * - access token 已过期 → 用 refresh token 换新对(rotation,回写 practi.auth.json)
@@ -52,9 +71,10 @@ export async function validAccessToken(dataDir, remote) {
52
71
  export async function authedFetch(dataDir, remote, path, init) {
53
72
  const creds = await validAccessToken(dataDir, remote);
54
73
  const url = /^https?:\/\//i.test(path) ? path : `${remote}${path}`;
55
- const call = (token) => fetch(url, {
56
- ...init,
74
+ const call = (token) => fetchUrl(url, {
75
+ method: init?.method,
57
76
  headers: { ...(init?.headers ?? {}), authorization: `Bearer ${token}` },
77
+ body: init?.body,
58
78
  });
59
79
  let res = await call(creds.access_token);
60
80
  if (res.status === 401) {
@@ -80,48 +100,35 @@ export async function authedFetch(dataDir, remote, path, init) {
80
100
  }
81
101
  }
82
102
  }
83
- return res;
84
- }
85
- /** hub 上「我的」认领列表(DIRECT 根),按 total 分页拉全——push/pull 做认领表 diff 的基准。 */
86
- export async function fetchMine(dataDir, remote) {
87
- const out = [];
88
- const limit = 100;
89
- for (let page = 1;; page++) {
90
- const res = await authedFetch(dataDir, remote, `/api/v1/pop/mine?page=${page}&limit=${limit}`);
91
- if (!res.ok) {
92
- const body = (await res.json().catch(() => ({})));
93
- throw new Error(`listing own documents failed — ${body.error ?? `HTTP ${res.status}`}`);
94
- }
95
- const body = (await res.json());
96
- const results = body.results ?? [];
97
- out.push(...results);
98
- // total 缺省时旧写法恒真=永远只取第一页;按页满即续页收口
99
- if (results.length === 0 || (body.total !== undefined && out.length >= body.total))
100
- break;
101
- }
102
- return out;
103
+ return toReply(res);
103
104
  }
104
105
  /** hub 端点一律要 `sha256:` 全形 root_hash;CLI 面子统一接受裸 64-hex 自动补前缀。
105
- * 前缀短哈希这里不猜——直传端点的命令(clone/comment)没法可靠解析任意公开文档的
106
- * 前缀,宁要全哈希也不要猜错。返回 null = 不是全哈希。 */
106
+ * 前缀短哈希这里不猜——直传端点的命令没法可靠解析任意公开文档的前缀,
107
+ * 宁要全哈希也不要猜错。返回 null = 不是全哈希。 */
107
108
  export function normalizeHashRef(ref) {
108
109
  const hex = ref.replace(/^sha256:/i, '').toLowerCase();
109
110
  return /^[0-9a-f]{64}$/.test(hex) ? `sha256:${hex}` : null;
110
111
  }
111
- /** POST /api/v1/pop:把文档(创作 JSON 或展开树均可)交给 hub——服务端委托官方 SDK * 解析、规范化、算 root_hash 并认领(默认 PRIVATE)。new --remote / edit --remote 共用。 */
112
- export async function storeDocumentRemote(dataDir, remote, doc) {
113
- const res = await authedFetch(dataDir, remote, '/api/v1/pop', {
114
- method: 'POST',
115
- headers: { 'content-type': 'application/json' },
116
- body: JSON.stringify(doc),
117
- });
112
+ /** GET /api/v1/pop/:ref + 入库前验算(内容寻址的客户端责任,hub 读路径不代验):
113
+ * 纯导入(不落库)算出的根哈希必须等于请求地址——不符即拒绝,防止
114
+ * 「另一身份的文档被悄悄注册进本地库」。clone/pull/fetch 共用。
115
+ * 可见性随 hub:公开内容任何人可拉,私有内容仅实例利益方(登录账号是 owner 即可)。 */
116
+ export async function fetchRemoteDoc(dataDir, remote, ref) {
117
+ const res = await authedFetch(dataDir, remote, `/api/v1/pop/${encodeURIComponent(ref)}`);
118
118
  const body = (await res.json().catch(() => ({})));
119
119
  if (!res.ok) {
120
- const code = body.code ? `[${body.code}] ` : '';
121
- throw new Error(`${code}${body.message ?? `HTTP ${res.status}`}`);
120
+ const detail = typeof body.message === 'string' ? body.message : typeof body.error === 'string' ? body.error : `HTTP ${res.status}`;
121
+ throw new Error(`${ref} — ${detail}`);
122
+ }
123
+ if (body.document === undefined || body.document === null) {
124
+ throw new Error(`${ref} — response missing document`);
125
+ }
126
+ const parsed = parseDocument(body.document);
127
+ if (parsed.rootHash !== ref) {
128
+ throw new Error(`${ref} — hash mismatch: content hashes to ${parsed.rootHash}`);
122
129
  }
123
- if (!body.root_hash)
124
- throw new Error('hub stored the document but the response carries no root_hash');
125
- return { rootHash: body.root_hash, status: body.status ?? 'PRIVATE', idempotent: body.idempotent === true };
130
+ const ws = openWorkspace(dataDir);
131
+ createFromDoc(ws, body.document);
132
+ return { rootHash: parsed.rootHash, status: body.status ?? 'PRIVATE' };
126
133
  }
127
134
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,eAAe,EACf,kBAAkB,GAEnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEhD,2DAA2D;AAC3D,MAAM,OAAO,oBAAqB,SAAQ,KAAK;CAAG;AAClD,+CAA+C;AAC/C,MAAM,OAAO,mBAAoB,SAAQ,KAAK;CAAG;AAEjD;;;;;GAKG;AAEH,MAAM,UAAU,kBAAkB,CAAC,OAAe;IAChD,MAAM,KAAK,GAAG,eAAe,CAAC,OAAO,CAAC,CAA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AAK,SAAS,IAAI,IAAI,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,8BAA8B,CAAC,CAAC;IACxD,CAAC;IACD,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,MAAM,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,GAAG,GAAG,uCAAuC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC;IAClF,CAAC;IACD,MAAM,EAAE,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IAClC,aAAa,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;AACzE,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { defaultDataDir, loadState } from '../state.js';
2
+ import { authedFetch } from '../client.js';
3
+ import { shortHash } from '../render.js';
4
+ /**
5
+ * practi branch — 实例分支管理(git branch 同构):
6
+ * branch 列全部分支(* = 默认支)
7
+ * branch <name> 从当前支头(或 --from <hash>,须是实例已登记版本)建新支
8
+ * branch -d <name> 删分支(纯指针;默认支不可删)
9
+ * 需已 `practi instance bind`。
10
+ */
11
+ export async function runBranch(opts) {
12
+ const dataDir = opts.dataDir ?? defaultDataDir();
13
+ const state = loadState(dataDir);
14
+ if (!state.remote) {
15
+ console.error('error: no remote configured — run `practi remote set <url>` first');
16
+ return 1;
17
+ }
18
+ if (!state.instance) {
19
+ console.error('error: no instance bound — use `practi instance bind <owner>/<name>` first');
20
+ return 1;
21
+ }
22
+ const base = `/api/v1/instances/${encodeURIComponent(state.instance.owner)}/${encodeURIComponent(state.instance.name)}`;
23
+ // 删支:branch -d <name>
24
+ if (opts.deleteBranch) {
25
+ const res = await authedFetch(dataDir, state.remote.url, `${base}/branches/${encodeURIComponent(opts.deleteBranch)}`, {
26
+ method: 'DELETE',
27
+ });
28
+ const body = await res.json();
29
+ if (!res.ok) {
30
+ const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
31
+ console.error(`error: ${detail}`);
32
+ return 1;
33
+ }
34
+ if (state.instance.branch === opts.deleteBranch) {
35
+ console.log(`note: deleted the current branch — \`practi switch main\` to go back`);
36
+ }
37
+ console.log(`deleted branch: ${opts.deleteBranch} (revisions and documents untouched)`);
38
+ return 0;
39
+ }
40
+ // 建支:branch <name> [--from <hash>]
41
+ const name = opts.positional[0];
42
+ if (name) {
43
+ const res = await authedFetch(dataDir, state.remote.url, `${base}/branches`, {
44
+ method: 'POST',
45
+ headers: { 'content-type': 'application/json' },
46
+ body: JSON.stringify({ name, ...(opts.from !== undefined && opts.from !== '' ? { from_hash: opts.from } : {}) }),
47
+ });
48
+ const body = await res.json();
49
+ if (!res.ok) {
50
+ const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
51
+ console.error(`error: ${detail}`);
52
+ return 1;
53
+ }
54
+ console.log(`created branch: ${name} (from ${(body.head_hash ? shortHash(String(body.head_hash)) : 'empty root')})`);
55
+ console.log(`next: \`practi switch ${name}\` then \`practi push <hash>\``);
56
+ return 0;
57
+ }
58
+ // 列表:branch
59
+ const res = await authedFetch(dataDir, state.remote.url, base);
60
+ const body = (await res.json());
61
+ if (!res.ok) {
62
+ const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
63
+ console.error(`error: ${detail}`);
64
+ return 1;
65
+ }
66
+ for (const b of body.branches ?? []) {
67
+ console.log(`${b.is_default ? '*' : ' '} ${b.name}${b.head_hash ? ` ${shortHash(b.head_hash)}` : ' (empty)'}`);
68
+ }
69
+ return 0;
70
+ }
71
+ //# sourceMappingURL=branch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/cmd/branch.ts"],"names":[],"mappings":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AACX,CAAC"}
package/dist/cmd/clone.js CHANGED
@@ -1,13 +1,21 @@
1
- import { createFromDoc, parseDocument } from '@arshdelight/pop-sdk';
2
- import { claimDirect, defaultDataDir, loadState, saveState } from '../state.js';
1
+ import { defaultDataDir, loadState, saveState } from '../state.js';
3
2
  import { openWorkspace } from '../workspace.js';
4
- import { authedFetch, normalizeHashRef } from '../client.js';
3
+ import { checkoutTip, fetchInstanceChain, persistIfMoved, syncInstanceObjects, } from '../sync.js';
4
+ import { shortHash } from '../render.js';
5
+ /** `practi clone <owner>/<name>[@branch]` 的 ref 形态(分支段可选,缺省=实例默认支) */
6
+ export function parseCloneRef(ref) {
7
+ const m = /^([a-z0-9][a-z0-9-]{0,38}[a-z0-9]?)\/([a-z0-9][a-z0-9-]{0,38}[a-z0-9]?)(?:@([a-z0-9][a-z0-9-]{0,38}[a-z0-9]?))?$/.exec(ref);
8
+ if (!m)
9
+ return null;
10
+ const [, owner, name, branch] = m;
11
+ return { owner, name, branch };
12
+ }
5
13
  /**
6
- * practi clone <hash>:从 hub 取一个文档并认领它(git clone / fork 语义)。
7
- * - 只用于公共(PUBLISHED)或你本就可读的内容;POP 认领制「能拿到即可认领」。
8
- * - 本地:落 workspace + 注册为 direct;远端:POST /api/v1/pop(内容寻址幂等)→
9
- * 你也获得 hub 认领——本地/hub 双向一致,之后 `practi pull` 能拉回。
10
- * - 已在你的认领里 → 幂等返回。
14
+ * practi clone <owner>/<name>[@branch]:把一个实践实例拉进工作区并绑定(git clone 同构)。
15
+ * - 拉当前支全部版本的对象(历史=对象,不进 direct——git 同构:只有 HEAD 是 ref)
16
+ * - 绑定写 practi.json 的 instance 字段(此后的 push/pull/log 都在「这个仓库」里)
17
+ * - 检出支 tip 为 direct(工作区已有的其它 direct 原样保留,提示带 hash 操作)
18
+ * 认领制退役(2026-10-19):clone 的对象就是实践实例——没有脱离实例的「我的认领表」。
11
19
  */
12
20
  export async function runClone(opts) {
13
21
  const dataDir = opts.dataDir ?? defaultDataDir();
@@ -17,65 +25,51 @@ export async function runClone(opts) {
17
25
  return 1;
18
26
  }
19
27
  const ref = opts.positional[0];
20
- if (!ref) {
21
- console.error('usage: practi clone <hash>');
22
- return 1;
23
- }
24
- // 统一哈希口径:裸 64-hex 自动补 sha256:;前缀不猜(任意公开文档无处可靠解析)
25
- const full = normalizeHashRef(ref);
26
- if (!full) {
27
- console.error(`error: "${ref}" is not a full hash — clone needs the full root hash (with or without the sha256: prefix); get it from \`practi search <q>\``);
28
- return 1;
29
- }
30
- const remote = state.remote.url;
31
- // 取文档体(公开可读;私有且非本人会被 hub 拒)
32
- const res = await authedFetch(dataDir, remote, `/api/v1/pop/${encodeURIComponent(full)}`);
33
- const body = (await res.json().catch(() => ({})));
34
- if (!res.ok) {
35
- const detail = typeof body.message === 'string' ? body.message : typeof body.error === 'string' ? body.error : `HTTP ${res.status}`;
36
- console.error(`clone failed: ${full} — ${detail}`);
28
+ const parsed = ref ? parseCloneRef(ref) : null;
29
+ if (!parsed) {
30
+ console.error('usage: practi clone <owner>/<name>[@branch]');
37
31
  return 1;
38
32
  }
39
- if (body.document === undefined || body.document === null) {
40
- console.error(`clone failed: ${full} — response missing document`);
41
- return 1;
42
- }
43
- // 入库前验算(内容寻址的客户端责任):本地算出的根哈希必须等于请求地址(也是服务器
44
- // 声称的 root_hash)——注册与推送一律用本地算的值,不采信服务器声称的哈希
45
- let computedRoot;
33
+ const { owner, name, branch } = parsed;
34
+ let view;
46
35
  try {
47
- computedRoot = parseDocument(body.document).rootHash;
36
+ view = await fetchInstanceChain(dataDir, state.remote.url, owner, name, branch);
48
37
  }
49
38
  catch (e) {
50
- console.error(`clone failed: ${full} — invalid document: ${e.message}`);
39
+ console.error(`clone failed: ${e.message}`);
51
40
  return 1;
52
41
  }
53
- if (computedRoot !== full || (body.root_hash !== undefined && body.root_hash !== computedRoot)) {
54
- console.error(`clone failed: ${full} — hash mismatch: content hashes to ${computedRoot}`);
42
+ const ws = openWorkspace(dataDir);
43
+ const sync = await syncInstanceObjects(dataDir, state.remote.url, view, (h) => ws.nodes.has(h));
44
+ if (sync.failed.length > 0) {
45
+ console.error(`clone incomplete: ${sync.failed.length} revision(s) failed to fetch`);
55
46
  return 1;
56
47
  }
57
- // 落本地 workspace + 注册 direct
58
- const ws = openWorkspace(dataDir);
59
- createFromDoc(ws, body.document);
60
- const rootHash = computedRoot;
61
- const alreadyMine = body.ownership?.mine === true;
62
- const localState = loadState(dataDir);
63
- if (claimDirect(localState, rootHash)) {
64
- saveState(dataDir, localState);
48
+ state.instance = { owner, name, branch: view.branch };
49
+ const outcome = checkoutTip(state, view);
50
+ saveState(dataDir, state);
51
+ persistIfMoved(dataDir, state, outcome);
52
+ console.log(`cloned: ${owner}/${name} (${view.visibility}, branch ${view.branch}, ${view.revisions.length} revision(s))`);
53
+ if (sync.missing > 0) {
54
+ console.log(`note: ${sync.missing} revision(s) missing on the hub (history traces of hard-deleted documents)`);
65
55
  }
66
- // 同步到 hub 认领(双向一致;幂等)
67
- const pushRes = await authedFetch(dataDir, remote, '/api/v1/pop', {
68
- method: 'POST',
69
- headers: { 'content-type': 'application/json' },
70
- body: JSON.stringify(body.document),
71
- });
72
- const pushBody = (await pushRes.json().catch(() => ({})));
73
- if (!pushRes.ok) {
74
- const detail = typeof pushBody.message === 'string' ? pushBody.message : typeof pushBody.error === 'string' ? pushBody.error : `HTTP ${pushRes.status}`;
75
- console.error(`clone failed: ${rootHash} — could not claim on remote: ${detail}`);
76
- return 1;
56
+ switch (outcome.kind) {
57
+ case 'up-to-date':
58
+ console.log(`head: ${shortHash(outcome.head)} (already a direct pop)`);
59
+ break;
60
+ case 'fast-forward':
61
+ console.log(`head: ${shortHash(outcome.to)} (fast-forwarded from ${shortHash(outcome.from)})`);
62
+ break;
63
+ case 'checked-out':
64
+ console.log(`head: ${outcome.head}`);
65
+ if (state.direct.length > 1) {
66
+ console.log(`note: ${state.direct.length - 1} other direct pop(s) remain — push/edit take an explicit hash when several are registered`);
67
+ }
68
+ break;
69
+ case 'untouched':
70
+ console.log(`head: ${view.head ?? '(none)'} (not checked out — ${outcome.reason})`);
71
+ break;
77
72
  }
78
- console.log(`cloned: ${rootHash} (${body.status ?? 'PUBLISHED'}) [direct]${alreadyMine ? ' (already yours on the remote)' : ' (claimed on remote)'}`);
79
73
  return 0;
80
74
  }
81
75
  //# sourceMappingURL=clone.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"clone.js","sourceRoot":"","sources":["../../src/cmd/clone.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAO7D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAe;IAC5C,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,IAAI,cAAc,EAAE,CAAC;IACjD,MAAM,KAAK,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,mEAAmE,CAAC,CAAC;QACnF,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,CAAC,KAAK,CAAC,4BAA4B,CAAC,CAAC;QAC5C,OAAO,CAAC,CAAC;IACX,CAAC;IACD,iDAAiD;IACjD,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,KAAK,CAAC,WAAW,GAAG,+HAA+H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2FAA2F,CAAC,CAAC;YAC3I,CAAC;YACD,MAAM;QACR,KAAK,WAAW;YACd,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,CAAC,IAAI,IAAI,QAAQ,wBAAwB,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;YACxF,MAAM;IACV,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -31,6 +31,8 @@ export function runConfig(opts) {
31
31
  const indirect = ws ? ws.nodes.size - direct : 0;
32
32
  console.log(`practi: ${CLI_VERSION} pop-spec: ${POP_SPEC_VERSION}`);
33
33
  console.log(`data dir: ${dataDir} (via ${via})`);
34
+ console.log(`remote: ${state.remote?.url ?? '(default https://practihub.com)'}`);
35
+ console.log(`instance: ${state.instance ? `${state.instance.owner}/${state.instance.name}@${state.instance.branch}` : '(none bound)'}`);
34
36
  console.log(`direct: ${direct}`);
35
37
  console.log(`indirect: ${indirect}`);
36
38
  if (ws && ws.parseIssues.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/cmd/config.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAM9D;0EAC0E;AAC1E,SAAS,eAAe,CAAC,QAAiB;IACxC,IAAI,QAAQ;QAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,GAAG,EAAE,YAAY,EAAE,CAAC;IACxE,MAAM,CAAC,GAAG,iBAAiB,EAAE,CAAC;IAC9B,MAAM,GAAG,GACP,CAAC,CAAC,GAAG,KAAK,KAAK;QACb,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,WAAW;YACvB,CA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pC,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,CAAC,WAAW,CAAC,MAAM,iDAAiD,CAAC,CAAC;IACrG,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
package/dist/cmd/edit.js CHANGED
@@ -6,6 +6,7 @@ import { shortHash } from '../render.js';
6
6
  import { printQualityHints } from '../quality.js';
7
7
  import { nodeIndexFields } from '../retrieval.js';
8
8
  import { describeRefresh, refreshVectors } from '../embed/optional.js';
9
+ import { appendCommit } from '../commits.js';
9
10
  function readStdin() {
10
11
  return fs.readFileSync(0, 'utf8');
11
12
  }
@@ -43,7 +44,8 @@ export function collectUnreachable(ws, directRoots) {
43
44
  }
44
45
  /**
45
46
  * practi edit <hash>:非交互编辑一个 direct 根——新文档(file/--json/stdin)→ 新哈希换注册。
46
- * 编辑即修订:根节点自动追加 revisions(from = 旧根哈希;spec §2.2 历史指针,允许悬空、永不校验)。
47
+ * POP 2.0:文档是纯快照,不写历史;本次编辑的血统记进本地提交日志 commits.json
48
+ * (from = 旧根哈希,--message 是提交说明,push 时上送 hub)。
47
49
  * 默认 GC 不可达节点(旧根及其独有后代;仍被其它 direct 根引用的内容保留);--keep 跳过。
48
50
  * 纯本地操作。
49
51
  */
@@ -60,7 +62,7 @@ export async function runEdit(opts) {
60
62
  text = readStdin();
61
63
  if (!ref || text === undefined || text.trim() === '') {
62
64
  console.error("usage: practi edit <hash> <file.json> | practi edit <hash> --json '<text>' | practi edit <hash> < file.json");
63
- console.error(' [--message <text>] [--no-revision] [--keep]');
65
+ console.error(' [--message <text>] [--keep]');
64
66
  return 1;
65
67
  }
66
68
  const dataDir = opts.dataDir ?? defaultDataDir();
@@ -84,18 +86,6 @@ export async function runEdit(opts) {
84
86
  console.error('error [E_SCHEMA]: the document must be a JSON object (one tree, root included)');
85
87
  return 1;
86
88
  }
87
- if (opts.noRevision !== true) {
88
- const revisions = Array.isArray(doc.revisions) ? doc.revisions : [];
89
- const already = revisions.some((r) => isRecord(r) && r.from === oldRoot);
90
- if (!already) {
91
- revisions.push({
92
- when: new Date().toISOString().slice(0, 10),
93
- what: opts.message ?? 'edited via practi edit',
94
- from: oldRoot,
95
- });
96
- doc.revisions = revisions;
97
- }
98
- }
99
89
  const { root: newRoot, count } = createFromDoc(ws, doc);
100
90
  // 门禁只统计本次子树:其它文档的历史问题不连坐本次 swap-in(与 new 同口径)
101
91
  const loaded = loadWorkspace(dataDir);
@@ -115,6 +105,7 @@ export async function runEdit(opts) {
115
105
  state.direct = state.direct.filter((h) => h !== oldRoot);
116
106
  claimDirect(state, newRoot);
117
107
  saveState(dataDir, state);
108
+ appendCommit(dataDir, newRoot, oldRoot, opts.message ?? 'edited via practi edit');
118
109
  console.log(`edited: ${oldRoot} -> ${newRoot} (${count} nodes)`);
119
110
  printQualityHints(loaded, newRoot);
120
111
  // 向量保鲜放在 GC 之前?不 —— GC 会删掉不可达节点,索引要按**最终**工作区来算,