@arshdelight/practi 0.17.4 → 0.19.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 (76) hide show
  1. package/README.md +76 -136
  2. package/dist/client.js +6 -6
  3. package/dist/client.js.map +1 -1
  4. package/dist/cmd/blob.js +21 -24
  5. package/dist/cmd/blob.js.map +1 -1
  6. package/dist/cmd/branch.js +42 -51
  7. package/dist/cmd/branch.js.map +1 -1
  8. package/dist/cmd/clone.js +52 -38
  9. package/dist/cmd/clone.js.map +1 -1
  10. package/dist/cmd/commit.js +97 -0
  11. package/dist/cmd/commit.js.map +1 -0
  12. package/dist/cmd/config.js +1 -17
  13. package/dist/cmd/config.js.map +1 -1
  14. package/dist/cmd/edit.js +18 -4
  15. package/dist/cmd/edit.js.map +1 -1
  16. package/dist/cmd/embed.js +30 -25
  17. package/dist/cmd/embed.js.map +1 -1
  18. package/dist/cmd/export.js +43 -0
  19. package/dist/cmd/export.js.map +1 -0
  20. package/dist/cmd/fix.js +9 -153
  21. package/dist/cmd/fix.js.map +1 -1
  22. package/dist/cmd/gc.js +6 -5
  23. package/dist/cmd/gc.js.map +1 -1
  24. package/dist/cmd/history.js +160 -0
  25. package/dist/cmd/history.js.map +1 -0
  26. package/dist/cmd/init.js +10 -5
  27. package/dist/cmd/init.js.map +1 -1
  28. package/dist/cmd/lint.js +23 -20
  29. package/dist/cmd/lint.js.map +1 -1
  30. package/dist/cmd/log.js +33 -42
  31. package/dist/cmd/log.js.map +1 -1
  32. package/dist/cmd/merge.js +32 -91
  33. package/dist/cmd/merge.js.map +1 -1
  34. package/dist/cmd/new.js +56 -54
  35. package/dist/cmd/new.js.map +1 -1
  36. package/dist/cmd/note.js +27 -42
  37. package/dist/cmd/note.js.map +1 -1
  38. package/dist/cmd/practice.js +56 -0
  39. package/dist/cmd/practice.js.map +1 -0
  40. package/dist/cmd/publish.js +124 -0
  41. package/dist/cmd/publish.js.map +1 -0
  42. package/dist/cmd/pull.js +78 -46
  43. package/dist/cmd/pull.js.map +1 -1
  44. package/dist/cmd/push.js +204 -67
  45. package/dist/cmd/push.js.map +1 -1
  46. package/dist/cmd/search.js +30 -44
  47. package/dist/cmd/search.js.map +1 -1
  48. package/dist/cmd/show.js +5 -4
  49. package/dist/cmd/show.js.map +1 -1
  50. package/dist/cmd/similar.js +7 -20
  51. package/dist/cmd/similar.js.map +1 -1
  52. package/dist/cmd/skill.js +16 -16
  53. package/dist/cmd/skill.js.map +1 -1
  54. package/dist/cmd/switch.js +20 -26
  55. package/dist/cmd/switch.js.map +1 -1
  56. package/dist/index.js +292 -396
  57. package/dist/index.js.map +1 -1
  58. package/dist/practice.js +221 -0
  59. package/dist/practice.js.map +1 -0
  60. package/dist/quality.js +2 -2
  61. package/dist/quality.js.map +1 -1
  62. package/dist/state.js +13 -73
  63. package/dist/state.js.map +1 -1
  64. package/dist/sync.js +6 -48
  65. package/dist/sync.js.map +1 -1
  66. package/dist/web.js +159 -442
  67. package/dist/web.js.map +1 -1
  68. package/dist/workspace.js +10 -52
  69. package/dist/workspace.js.map +1 -1
  70. package/package.json +1 -1
  71. package/skills/use-practi/SKILL.md +121 -125
  72. package/web-default/chain.html +39 -0
  73. package/web-default/chain.js +54 -0
  74. package/web-default/lang.js +4 -0
  75. package/web-default/app.js +0 -106
  76. package/web-default/index.html +0 -28
package/dist/index.js CHANGED
@@ -3,12 +3,10 @@ import { parseArgs } from 'node:util';
3
3
  import { PracticeError } from '@arshdelight/pop-sdk';
4
4
  import { runInit } from './cmd/init.js';
5
5
  import { runConfig } from './cmd/config.js';
6
- import { runRepair } from './cmd/repair.js';
7
- import { runMigrate } from './cmd/migrate.js';
8
- import { runLs } from './cmd/ls.js';
9
6
  import { runLint } from './cmd/lint.js';
10
7
  import { runNew } from './cmd/new.js';
11
- import { runEdit } from './cmd/edit.js';
8
+ import { runCommit } from './cmd/commit.js';
9
+ import { runExport } from './cmd/export.js';
12
10
  import { runGc } from './cmd/gc.js';
13
11
  import { runShow } from './cmd/show.js';
14
12
  import { runWeb } from './web.js';
@@ -17,19 +15,16 @@ import { runSearch } from './cmd/search.js';
17
15
  import { runSimilar } from './cmd/similar.js';
18
16
  import { runEmbed } from './cmd/embed.js';
19
17
  import { runNote } from './cmd/note.js';
20
- import { runRemove } from './cmd/remove.js';
21
- import { runClaim, runUnclaim } from './cmd/claim.js';
18
+ import { runSkill } from './cmd/skill.js';
22
19
  import { runFix } from './cmd/fix.js';
23
20
  import { runUpdate } from './cmd/update.js';
24
21
  import { runSpec } from './cmd/spec.js';
25
- import { runSkill } from './cmd/skill.js';
26
22
  import { runLogin, runLogout, runMe } from './cmd/login.js';
27
23
  import { runRemote } from './cmd/remote.js';
28
24
  import { runPush } from './cmd/push.js';
29
25
  import { runPull } from './cmd/pull.js';
30
26
  import { runClone } from './cmd/clone.js';
31
- import { runFetch } from './cmd/fetch.js';
32
- import { runInstance } from './cmd/instance.js';
27
+ import { runHistory } from './cmd/history.js';
33
28
  import { runBranch } from './cmd/branch.js';
34
29
  import { runSwitch } from './cmd/switch.js';
35
30
  import { runMerge } from './cmd/merge.js';
@@ -40,124 +35,69 @@ function printVersion() {
40
35
  console.log(`pop-spec ${POP_SPEC_VERSION} (via @arshdelight/pop-sdk)`);
41
36
  return 0;
42
37
  }
43
- const USAGE = `practi — local registry for POP (Protocol of Practice), with a practihub bridge
38
+ const USAGE = `practi — practice folders for POP (Protocol of Practice), with a practihub bridge
39
+
40
+ a practice is a self-contained folder:
41
+ <name>.json the pop — a plain document, edit it with any editor
42
+ .practi/ the history (like .git): chain.json (commits + branches)
43
+ and the content-addressed pool of every revision
44
44
 
45
- usage:
46
- practi blob add <file-or-url> [--name <name>]
47
- (hashes the bytes, stores local blobs in the workspace)
48
- practi branch [name] [--from <hash>] | -d <name>
49
- instance branches (needs 'practi instance bind'):
50
- no arg lists branches (* = default), a name creates one
51
- from the current branch head (or --from, a registered
52
- revision), -d deletes the pointer (default branch is kept)
53
- practi claim <hash> register an existing stored node as a direct pop (indirect → direct)
54
- practi clone <owner>/<name>[@branch]
55
- fetch a practice instance from the hub into this workspace,
56
- bind to it (git clone: the instance IS the repository), pull
57
- every revision of its branch, and check out the head as a
58
- direct pop. The hub has no claim table — clone is how
59
- someone else's practice travels
60
- practi config show data dir and registry summary
61
- practi edit <hash> <file.json> replace a direct POP (new hash; the swap is recorded in the
62
- | practi edit <hash> --json '<text>' | practi edit <hash> < file.json
63
- local commit log (commits.json) and pushed as the commit message)
64
- [--message <text>] [--keep]
65
- practi embed status|pull|build|prune optional offline vector model (bge-small-zh-v1.5,
66
- ~24MB int8 ONNX). pull fetches it, build embeds every
67
- stored node (incrementally), status reports coverage.
68
- Nothing here is required: without a model practi is
69
- lexical-only, and search --semantic says so
70
- practi gc [--apply] free orphan blobs — attachment bytes on disk that no
71
- stored node references (dry-run by default; --apply removes)
72
- practi fetch <owner>/<name> <hash>
73
- pull one revision of that instance into your local registry
74
- (direct; full sha256 hash — no prefix guessing). Content
75
- access is repo-scoped: public instances are fetchable by
76
- anyone, private ones only by their owners
77
- practi fix <file.json> | <hash> | --all
78
- migrate POP 1.x documents to 2.0: strip the removed history
79
- fields (revisions/refines), re-validate, report the new hash.
80
- <hash> re-stores a workspace node and re-binds direct/claims;
81
- --all sweeps every direct pop; --dry-run previews
82
- practi instance create <name> [--public] [--desc <text>] | bind <owner>/<name> | show
83
- bind this workspace to a practice instance on the hub
84
- (git's origin); push/merge/log default to the binding
45
+ usage (run inside a practice folder unless noted):
46
+ practi new <name> [--base <file.json>] [-m <msg>] birth a practice folder in cwd;
47
+ --base seeds the first revision from a pop document
48
+ (hub-side copy is born by the first push)
49
+ practi commit [-m <msg>] [--amend] snapshot the working file as a new revision
50
+ (local only; nothing to commit when it matches the
51
+ head; --amend replaces the head instead)
52
+ practi export <hash> [-o <file>] write any revision back out as a document
53
+ (the current one is the working file already)
54
+ practi push [--force] sync the practice to the hub (first push creates it;
55
+ divergence errors, --force overwrites and the hub
56
+ drops unreachable objects)
57
+ practi pull reconcile with the hub: fetch missing revisions,
58
+ fast-forward the branch, update the working file
59
+ practi clone <owner>/<name>[@branch] [--dir <path>]
60
+ clone a hub practice into a local practice folder
61
+ practi branch [name] [-d <name>] [--from <hash>]
62
+ list / create / delete branches (* marks the current one)
63
+ practi switch <branch> switch branches (working file follows the head; refuses
64
+ when it has uncommitted changes)
65
+ practi merge <branch> fast-forward, else a pointer move (same-tree commits
66
+ are identical)
85
67
  practi log [--branch <b>] [--limit N] [--json]
86
- revision history of the bound instance branch (tip first)
87
- practi ls [-a] [--json] list direct pops (-a also lists indirect nodes)
88
- practi lint [--json] [--limit N] audit recording quality across every direct pop: the
89
- same W_* hints new prints once, on demand for the
90
- whole workspace. Read-only, never blocking (always exits 0)
91
- practi login [--no-open] [--reauth] OAuth sign-in to the hub (browser consent; --no-open
92
- prints the URL for headless use, --reauth re-credentials)
93
- practi logout revoke and drop stored credentials
94
- practi me show the signed-in account, role and scopes
95
- practi merge <branch> merge a branch into the current one: fast-forward when the
96
- tip's parent chain reaches the current head, otherwise a
97
- squash merge commit is appended — always succeeds
98
- practi migrate [path] [--keep] move the workspace to a new data directory
99
- (cut: the old directory is removed after per-file
100
- verification; --keep retains it as <dir>.bak-<timestamp>;
101
- no arg = ~/.practi; a path is recorded in
102
- ~/.practi-home and becomes the default)
103
- practi note add|list|edit|delete|promote local learning notes pinned to node hashes
104
- (sidecar notes.json, never uploaded). promote turns a
105
- note into a draft document of its owning direct root —
106
- a draft only, never an automatic edit
107
- practi new <file.json> create a POP from a JSON document (local)
108
- | practi new --json '<text>'
109
- | practi new < file.json
110
- practi pull sync the bound instance's remote revisions into the
111
- workspace (git pull inside the repository): missing chain
112
- revisions are fetched (hash-verified), the branch head is
113
- fast-forwarded when your local direct is an ancestor,
114
- checked out when the workspace has none on the chain
115
- practi push [hash] [--branch <b>] one call: store the document and bind it as the branch
116
- [--message <text>] head (the commit is appended with parent = current head;
117
- --message or the local commit log supplies the commit
118
- message). Requires a bound instance — POP lives on the
119
- hub only as practice instances
120
- practi remote set <url> | remove point practi at a hub (no implicit default; hub commands
121
- need a remote)
122
- practi remove <hash> take a direct pop out of the local directory (registry op;
123
- GCs nodes unreachable from the rest — shared indirect nodes survive)
124
- practi repair backfill missing claim timestamps from node file times
125
- (idempotent; stamped claims are never touched)
126
- practi search [query...] search the local workspace: every stored node is
127
- [--limit N] [--json] indexed (name / description / content / declared
128
- [--notes] [--semantic] inputs+outputs / loop prose), ranked title-first, each hit
129
- showing why it was recalled. Multiple words are AND (each
130
- must match, possibly in a different field); field:value
131
- scopes one word. Pure-hex queries also match hash prefixes.
132
- --notes also indexes local notes; --semantic fuses vector
133
- recall (needs practi embed pull + embed build first, else
134
- it says so and is ignored). Empty query = browse roots
135
- practi show <hash> [--json] [--doc] inspect one node (hash prefix OK)
136
- practi similar <hash> content neighbours of a node: same topic, other wording
137
- [--limit N] [--json] (literal character-bigram similarity — no semantics;
138
- the subtree is what gets compared)
139
- practi skill install install the bundled use-practi skill (default: ~/.agents/skills)
140
- practi skill update refresh the installed use-practi skill (--dir to override)
141
- practi skill uninstall remove the installed use-practi skill
142
- practi skill import <dir> replay a practi skill export directory back into a POP (sidecar required;
143
- foreign skills enter POP by authoring, not import)
144
- practi skill export <ref> [--dir] project a POP as an installable skill directory (SKILL.md + sidecar)
145
- practi spec print pop-spec.md (bundled with the SDK; no network)
146
- practi switch <branch> switch the bound instance's current branch (local pointer;
147
- bring the content into the workspace with 'practi pull')
148
- practi unclaim <hash> take a referenced direct pop back to indirect (fails when
149
- unreferenced — that would orphan it; delete with "remove")
150
- practi update self-update via npm (checks the registry's latest)
151
- practi version | --version show CLI + pop-spec versions
152
- practi web [--port 4317] [--no-open] browse direct pops in a local web UI
68
+ the commit history (tip first)
69
+ practi history reword <seq> -m <msg> | squash <seq> | drop <seq> | reset <seq>
70
+ rewrite the local commit chain (git-style);
71
+ push reconciles with the hub — divergence needs --force
72
+ practi export is the read-back door; the working file is the write door
73
+
74
+ inside a practice folder also:
75
+ practi show <hash> [--json] [--doc] inspect one revision node (hash prefix OK)
76
+ practi search [query...] [--json] search this practice's revisions
77
+ practi note add|list|edit|delete local learning notes pinned to node hashes
78
+ (.practi/notes.json, never uploaded)
79
+ practi lint quality hints on the current branch head
80
+ practi blob add <file-or-url> store an attachment's bytes in the pool
81
+ practi gc [--apply] free orphan blobs (dry-run by default)
82
+ practi web [--port 4317] browse this practice in a local web UI
83
+
84
+ anywhere:
85
+ practi init [path] create the config home (credentials + remote)
86
+ practi login [--no-open] OAuth sign-in to the hub (browser consent)
87
+ practi logout | me | remote set <url> | remove
88
+ practi config show config home and remote
89
+ practi fix <file.json> [--dry-run] migrate a POP 1.x document file to 2.0
90
+ practi spec print pop-spec.md (bundled with the SDK)
91
+ practi skill install | update | uninstall | import <dir> | export <ref>
92
+ practi update self-update via npm
93
+ practi version | --version show CLI + pop-spec versions
153
94
 
154
95
  options:
155
- --data-dir <path> target data directory (same default as init)
96
+ --dir <path> target a practice folder from outside it
156
97
 
157
- the data directory is a POP workspace: nodes are content-addressed (nodes/*.md),
158
- practi.json records the registered direct roots plus the remote/instance binding;
159
- notes live in notes.json, the local commit log in commits.json. Hub commands need
160
- 'practi login' + 'practi remote set'.
98
+ the config home (default ~/.practi) keeps practi.json (remote) and
99
+ practi.auth.json (OAuth credentials) — practices themselves are plain
100
+ folders, wherever you keep your documents.
161
101
  `;
162
102
  const COMMON = {
163
103
  'data-dir': { type: 'string' },
@@ -166,6 +106,25 @@ const COMMON = {
166
106
  function str(v) {
167
107
  return v;
168
108
  }
109
+ /** 退役命令统一存根:说清去哪了 */
110
+ function retired(cmd) {
111
+ const pointers = {
112
+ edit: 'the working file IS the edit — open <name>.json with any editor, then `practi commit -m "..."`',
113
+ ls: 'practices are folders — use your file manager; `practi log` shows a practice\'s revisions',
114
+ list: 'practices are folders — browse them in your file manager',
115
+ remove: 'a practice folder is self-contained — deleting the folder removes the practice (the hub copy stays)',
116
+ claim: 'the pops registry retired — content lives in practice folders now',
117
+ unclaim: 'the pops registry retired — content lives in practice folders now',
118
+ publish: 'two steps now: `practi commit -m "..."` then `practi push`',
119
+ fetch: 'clone brings the full chain; fetch retired',
120
+ repair: 'the claims ledger retired — nothing to repair',
121
+ migrate: 'the config home is tiny — move the folder and point $PRACTI_HOME at it',
122
+ instance: 'retired by the practice-folder model (2026-10-20)',
123
+ practice: 'commands are flat now: `practi new <name>` / `practi log` / ... (the practice prefix retired)',
124
+ };
125
+ console.error(`\`practi ${cmd}\` was retired — ${pointers[cmd] ?? 'see practi --help'}`);
126
+ return 1;
127
+ }
169
128
  async function main(argv) {
170
129
  const cmd = argv[0] ?? 'help';
171
130
  const rest = argv.slice(1);
@@ -176,19 +135,19 @@ async function main(argv) {
176
135
  case 'gc': {
177
136
  const { values } = parseArgs({
178
137
  args: rest,
179
- options: { ...COMMON, apply: { type: 'boolean' } },
138
+ options: { ...COMMON, apply: { type: 'boolean' }, dir: { type: 'string' } },
180
139
  allowPositionals: true,
181
140
  });
182
141
  if (values.help) {
183
142
  console.log('usage: practi gc [--apply] (free orphan blobs; dry-run by default)');
184
143
  return 0;
185
144
  }
186
- return runGc({ dataDir: str(values['data-dir']), apply: values.apply === true });
145
+ return runGc({ dir: str(values.dir), apply: values.apply === true });
187
146
  }
188
147
  case 'init': {
189
148
  const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
190
149
  if (values.help) {
191
- console.log('usage: practi init [path]');
150
+ console.log('usage: practi init [path] (create the config home: credentials + remote)');
192
151
  return 0;
193
152
  }
194
153
  return runInit({ dataDir: str(values['data-dir']), positional: positionals });
@@ -201,127 +160,62 @@ async function main(argv) {
201
160
  }
202
161
  return runConfig({ dataDir: str(values['data-dir']) });
203
162
  }
204
- case 'repair': {
205
- const { values } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
206
- if (values.help) {
207
- console.log('usage: practi repair (backfill missing claim timestamps; idempotent)');
208
- return 0;
209
- }
210
- return runRepair({ dataDir: str(values['data-dir']) });
211
- }
212
- case 'migrate': {
213
- const { values, positionals } = parseArgs({
214
- args: rest,
215
- options: { ...COMMON, keep: { type: 'boolean' } },
216
- allowPositionals: true,
217
- });
218
- if (values.help) {
219
- console.log('usage: practi migrate [path] [--keep] (cut: the old directory is removed after per-file verification; --keep retains it as <dir>.bak-<timestamp>; no arg = ~/.practi, a path is recorded in ~/.practi-home as the default)');
220
- return 0;
221
- }
222
- return runMigrate({ dataDir: str(values['data-dir']), positional: positionals, keep: values.keep === true });
223
- }
224
163
  case 'lint': {
225
164
  const { values } = parseArgs({
226
165
  args: rest,
227
- options: { ...COMMON, json: { type: 'boolean' }, limit: { type: 'string' } },
166
+ options: { ...COMMON, json: { type: 'boolean' }, dir: { type: 'string' } },
228
167
  allowPositionals: true,
229
168
  });
230
169
  if (values.help) {
231
- console.log('usage: practi lint [--json] [--limit N]');
232
- console.log(' audit recording quality across every direct pop: the same W_* hints');
233
- console.log(' `practi new` prints once, but for the whole workspace, on demand.');
234
- console.log(' read-only and never blocking (exit code is always 0) — it is a to-do');
235
- console.log(' list, not a gate. --limit caps how many nodes are listed (default 20).');
170
+ console.log('usage: practi lint (quality hints on the current branch head; read-only, exit 0)');
236
171
  return 0;
237
172
  }
238
- const lintLimit = values.limit ? Number(values.limit) : 20;
239
- return runLint({
240
- dataDir: str(values['data-dir']),
241
- json: values.json === true,
242
- limit: Number.isInteger(lintLimit) && lintLimit > 0 ? Math.min(lintLimit, 200) : 20,
243
- });
173
+ return runLint({ dir: str(values.dir), json: values.json === true });
244
174
  }
245
- case 'ls': {
175
+ case 'new': {
246
176
  const { values, positionals } = parseArgs({
247
177
  args: rest,
248
- options: { ...COMMON, all: { type: 'boolean', short: 'a' }, json: { type: 'boolean' } },
178
+ options: { ...COMMON, base: { type: 'string' }, message: { type: 'string', short: 'm' }, dir: { type: 'string' } },
249
179
  allowPositionals: true,
250
180
  });
251
181
  if (values.help) {
252
- console.log('usage: practi ls [-a] [--json]');
182
+ console.log('usage: practi new <name> [--base <file.json>] [-m <msg>] (birth a practice folder in cwd)');
253
183
  return 0;
254
184
  }
255
- return runLs({ dataDir: str(values['data-dir']), all: values.all === true, json: values.json === true });
185
+ return await runNew({ positional: positionals, base: values.base, message: values.message });
256
186
  }
257
- case 'note': {
187
+ case 'commit': {
258
188
  const { values, positionals } = parseArgs({
259
189
  args: rest,
260
- options: {
261
- ...COMMON,
262
- message: { type: 'string', short: 'm' },
263
- json: { type: 'boolean' },
264
- out: { type: 'string' },
265
- },
190
+ options: { ...COMMON, message: { type: 'string', short: 'm' }, amend: { type: 'boolean' }, dir: { type: 'string' } },
266
191
  allowPositionals: true,
267
192
  });
268
193
  if (values.help) {
269
- console.log('usage: practi note add|list|edit|delete|promote (see `practi note` help)');
194
+ console.log('usage: practi commit [-m <msg>] [--amend] (snapshot the working file; local only)');
270
195
  return 0;
271
196
  }
272
- return runNote({
273
- dataDir: str(values['data-dir']),
274
- positional: positionals,
275
- message: values.message,
276
- json: values.json === true,
277
- out: values.out,
278
- });
279
- }
280
- case 'new': {
281
- const { values, positionals } = parseArgs({
282
- args: rest,
283
- options: {
284
- ...COMMON,
285
- json: { type: 'string' },
286
- file: { type: 'string' },
287
- },
288
- allowPositionals: true,
289
- });
290
- if (values.help) {
291
- console.log('usage: practi new <file.json> | practi new --json \'<text>\' | practi new < file.json');
292
- return 0;
197
+ if (positionals.length > 0) {
198
+ console.error('error: commit takes no arguments — the working file <name>.json is what gets committed');
199
+ return 1;
293
200
  }
294
- return await runNew({ dataDir: str(values['data-dir']), json: values.json, file: values.file, positional: positionals });
201
+ return await runCommit({ positional: positionals, message: values.message, amend: values.amend === true, dir: values.dir });
295
202
  }
296
- case 'edit': {
203
+ case 'export': {
297
204
  const { values, positionals } = parseArgs({
298
205
  args: rest,
299
- options: {
300
- ...COMMON,
301
- json: { type: 'string' },
302
- file: { type: 'string' },
303
- message: { type: 'string', short: 'm' },
304
- keep: { type: 'boolean' },
305
- },
206
+ options: { ...COMMON, out: { type: 'string', short: 'o' }, dir: { type: 'string' } },
306
207
  allowPositionals: true,
307
208
  });
308
209
  if (values.help) {
309
- console.log('usage: practi edit <hash> <file.json> | --json \'<text>\' | < file.json [--message] [--keep]');
210
+ console.log('usage: practi export <hash> [-o <file>] (write a revision back out as a document)');
310
211
  return 0;
311
212
  }
312
- return runEdit({
313
- dataDir: str(values['data-dir']),
314
- json: values.json,
315
- file: values.file,
316
- message: values.message,
317
- keep: values.keep === true,
318
- positional: positionals,
319
- });
213
+ return runExport({ positional: positionals, out: values.out, dir: values.dir });
320
214
  }
321
215
  case 'show': {
322
216
  const { values, positionals } = parseArgs({
323
217
  args: rest,
324
- options: { ...COMMON, json: { type: 'boolean' }, doc: { type: 'boolean' } },
218
+ options: { ...COMMON, json: { type: 'boolean' }, doc: { type: 'boolean' }, dir: { type: 'string' } },
325
219
  allowPositionals: true,
326
220
  });
327
221
  if (values.help) {
@@ -332,7 +226,7 @@ async function main(argv) {
332
226
  console.error('usage: practi show <hash> [--json] [--doc]');
333
227
  return 1;
334
228
  }
335
- return runShow({ dataDir: str(values['data-dir']), hash: positionals[0], json: values.json === true, doc: values.doc === true });
229
+ return runShow({ hash: positionals[0], json: values.json === true, doc: values.doc === true, dir: values.dir });
336
230
  }
337
231
  case 'web': {
338
232
  const { values } = parseArgs({
@@ -342,159 +236,30 @@ async function main(argv) {
342
236
  port: { type: 'string' },
343
237
  open: { type: 'boolean', default: true },
344
238
  'no-open': { type: 'boolean' },
239
+ dir: { type: 'string' },
345
240
  },
346
241
  allowPositionals: true,
347
242
  });
348
243
  if (values.help) {
349
- console.log('usage: practi web [--port 4317] [--no-open]');
244
+ console.log('usage: practi web [--port 4317] [--no-open] (browse this practice locally)');
350
245
  return 0;
351
246
  }
352
247
  const port = values.port ? Number(values.port) : 4317;
353
- return runWeb({ dataDir: str(values['data-dir']), port: Number.isInteger(port) && port > 0 ? port : 4317, open: values['no-open'] !== true });
354
- }
355
- case 'remove': {
356
- const { values, positionals } = parseArgs({
357
- args: rest,
358
- options: COMMON,
359
- allowPositionals: true,
360
- });
361
- if (values.help) {
362
- console.log('usage: practi remove <hash> (local directory; unreachable nodes are GCed)');
363
- return 0;
364
- }
365
- if (positionals.length === 0) {
366
- console.error('usage: practi remove <hash> (local directory; unreachable nodes are GCed)');
367
- return 1;
368
- }
369
- return runRemove({
370
- dataDir: str(values['data-dir']),
371
- positional: positionals,
372
- });
373
- }
374
- case 'claim': {
375
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
376
- if (values.help) {
377
- console.log('usage: practi claim <hash> (register an existing stored node as a direct pop)');
378
- return 0;
379
- }
380
- if (positionals.length === 0) {
381
- console.error('usage: practi claim <hash>');
382
- return 1;
383
- }
384
- return runClaim({ dataDir: str(values['data-dir']), positional: positionals });
385
- }
386
- case 'unclaim': {
387
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
388
- if (values.help) {
389
- console.log('usage: practi unclaim <hash> (take a referenced direct pop back to indirect)');
390
- return 0;
391
- }
392
- if (positionals.length === 0) {
393
- console.error('usage: practi unclaim <hash>');
394
- return 1;
395
- }
396
- return runUnclaim({ dataDir: str(values['data-dir']), positional: positionals });
397
- }
398
- case 'embed': {
399
- const { values, positionals } = parseArgs({
400
- args: rest,
401
- options: { ...COMMON, json: { type: 'boolean' }, notes: { type: 'boolean' } },
402
- allowPositionals: true,
403
- });
404
- if (values.help) {
405
- console.log('usage: practi embed status|pull|build|prune [--json] [--notes]');
406
- console.log(' optional offline vector model (bge-small-zh-v1.5, ~24MB int8 ONNX).');
407
- console.log(' pull downloads it into <data-dir>/models/, build embeds every stored node');
408
- console.log(' (incrementally — only new hashes are embedded), status reports coverage.');
409
- console.log(' nothing here is required: without a model practi is lexical-only.');
410
- return 0;
411
- }
412
- return await runEmbed({
413
- dataDir: str(values['data-dir']),
414
- positional: positionals,
415
- json: values.json === true,
416
- notes: values.notes === true,
417
- });
418
- }
419
- case 'search': {
420
- const { values, positionals } = parseArgs({
421
- args: rest,
422
- options: {
423
- ...COMMON,
424
- limit: { type: 'string' },
425
- json: { type: 'boolean' },
426
- notes: { type: 'boolean' },
427
- semantic: { type: 'boolean' },
428
- },
429
- allowPositionals: true,
430
- });
431
- if (values.help) {
432
- console.log('usage: practi search [query...] [--limit N] [--json] [--notes] [--semantic]');
433
- console.log(' words are ANDed — every word must match somewhere, and the words may');
434
- console.log(' match in different fields (name / description / content / declared');
435
- console.log(' inputs+outputs / loop). Quote a phrase to search it whole.');
436
- console.log(' field:value scopes one word — name: desc: content: flow: loop: op: hash:');
437
- console.log(' pure-hex queries also match node hash prefixes;');
438
- console.log(' if strict matching finds nothing, results fall back to partial match (labeled).');
439
- console.log(' --notes also indexes your local notes (off by default); hits show "note".');
440
- console.log(' --semantic fuses vector recall with the lexical ranking (needs');
441
- console.log(' `practi embed pull` + `practi embed build`; otherwise it says so and is ignored).');
442
- console.log(' empty query = browse direct roots');
443
- return 0;
444
- }
445
- const limit = values.limit ? Number(values.limit) : 20;
446
- return await runSearch({
447
- dataDir: str(values['data-dir']),
448
- positional: positionals,
449
- limit: Number.isInteger(limit) && limit > 0 ? Math.min(limit, 50) : 20,
450
- json: values.json === true,
451
- notes: values.notes === true,
452
- semantic: values.semantic === true,
453
- });
454
- }
455
- case 'similar': {
456
- const { values, positionals } = parseArgs({
457
- args: rest,
458
- options: {
459
- ...COMMON,
460
- limit: { type: 'string' },
461
- json: { type: 'boolean' },
462
- },
463
- allowPositionals: true,
464
- });
465
- if (values.help) {
466
- console.log('usage: practi similar <hash> [--limit N] [--json]');
467
- console.log(' content neighbours: the target subtree is treated as a query and every');
468
- console.log(' stored node is scored against it (character-bigram + latin-word relevance,');
469
- console.log(' literal — not semantics, so a paraphrase sharing no wording will not surface).');
470
- console.log(' score 1.0 = identical content; each hit lists the shared terms that carried it.');
471
- return 0;
472
- }
473
- if (positionals.length === 0) {
474
- console.error('usage: practi similar <hash> [--limit N] [--json]');
475
- return 1;
476
- }
477
- const simLimit = values.limit ? Number(values.limit) : 10;
478
- return runSimilar({
479
- dataDir: str(values['data-dir']),
480
- ref: positionals[0],
481
- limit: Number.isInteger(simLimit) && simLimit > 0 ? Math.min(simLimit, 50) : 10,
482
- json: values.json === true,
483
- });
248
+ return runWeb({ dir: str(values.dir), port: Number.isInteger(port) && port > 0 ? port : 4317, open: values['no-open'] !== true });
484
249
  }
485
250
  case 'blob': {
486
251
  const sub = rest[0];
487
252
  const { values, positionals } = parseArgs({
488
253
  args: rest.slice(1),
489
- options: { ...COMMON, name: { type: 'string' } },
254
+ options: { ...COMMON, name: { type: 'string' }, dir: { type: 'string' } },
490
255
  allowPositionals: true,
491
256
  });
492
257
  if (values.help) {
493
- console.log('usage: practi blob add <file-or-url> [--name <name>]');
258
+ console.log('usage: practi blob add <file-or-url> [--name <name>] (store attachment bytes in this practice)');
494
259
  return 0;
495
260
  }
496
261
  if (sub === 'add') {
497
- return runBlobAdd({ dataDir: str(values['data-dir']), name: values.name, positional: positionals });
262
+ return runBlobAdd({ name: values.name, dir: values.dir, positional: positionals });
498
263
  }
499
264
  console.error('usage: practi blob add <file-or-url> [--name <name>]');
500
265
  return 1;
@@ -510,17 +275,15 @@ async function main(argv) {
510
275
  const action = known.find((k) => k === sub);
511
276
  if (values.help) {
512
277
  console.log('usage: practi skill install|update|uninstall [--dir <skills-dir>] (default dir: ~/.agents/skills)');
513
- console.log(' practi skill import <skill-dir> [--data-dir <dir>] replay a `practi skill export` directory (sidecar required)');
514
- console.log(' practi skill export <ref> [--dir <out-dir>] [--data-dir <dir>] POP → skill directory');
278
+ console.log(' practi skill import <skill-dir> replay a `practi skill export` directory (sidecar required)');
279
+ console.log(' practi skill export <ref> [--dir <out-dir>] project a revision as an installable skill directory');
515
280
  return 0;
516
281
  }
517
282
  if (action === undefined) {
518
283
  console.error('usage: practi skill install|update|uninstall [--dir <skills-dir>] (default dir: ~/.agents/skills)');
519
- console.error(' practi skill import <skill-dir> [--data-dir <dir>] replay a `practi skill export` directory (sidecar required)');
520
- console.error(' practi skill export <ref> [--dir <out-dir>] [--data-dir <dir>] POP → skill directory');
521
284
  return 1;
522
285
  }
523
- return runSkill({ action, dir: values.dir, dataDir: str(values['data-dir']), positional: positionals[0] });
286
+ return runSkill({ action, dir: values.dir, positional: positionals[0] });
524
287
  }
525
288
  case 'spec': {
526
289
  const { values } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
@@ -528,7 +291,7 @@ async function main(argv) {
528
291
  console.log('usage: practi spec (print the bundled pop-spec.md)');
529
292
  return 0;
530
293
  }
531
- return runSpec({ dataDir: str(values['data-dir']) });
294
+ return runSpec({});
532
295
  }
533
296
  case 'update': {
534
297
  const { values } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
@@ -536,7 +299,7 @@ async function main(argv) {
536
299
  console.log('usage: practi update (self-update via npm; checks the registry\'s latest)');
537
300
  return 0;
538
301
  }
539
- return await runUpdate({ dataDir: str(values['data-dir']) });
302
+ return await runUpdate({});
540
303
  }
541
304
  case 'login': {
542
305
  const { values } = parseArgs({
@@ -575,109 +338,229 @@ async function main(argv) {
575
338
  return runRemote({ dataDir: str(values['data-dir']), positional: positionals });
576
339
  }
577
340
  case 'push': {
341
+ const { values } = parseArgs({
342
+ args: rest,
343
+ options: {
344
+ ...COMMON,
345
+ force: { type: 'boolean' },
346
+ dir: { type: 'string' },
347
+ },
348
+ allowPositionals: true,
349
+ });
350
+ if (values.help) {
351
+ console.log('usage: practi push [--force] [--dir <path>] (practice → hub; first push creates it; divergence errors, --force overwrites)');
352
+ return 0;
353
+ }
354
+ return await runPush({ dir: values.dir, force: values.force === true });
355
+ }
356
+ case 'pull': {
357
+ const { values } = parseArgs({
358
+ args: rest,
359
+ options: { ...COMMON, dir: { type: 'string' } },
360
+ allowPositionals: true,
361
+ });
362
+ if (values.help) {
363
+ console.log('usage: practi pull [--dir <path>] (reconcile with the hub: fetch missing revisions, fast-forward)');
364
+ return 0;
365
+ }
366
+ return await runPull({ dir: values.dir });
367
+ }
368
+ case 'clone': {
578
369
  const { values, positionals } = parseArgs({
579
370
  args: rest,
580
- options: { ...COMMON, branch: { type: 'string' }, message: { type: 'string', short: 'm' } },
371
+ options: { ...COMMON, dir: { type: 'string' } },
581
372
  allowPositionals: true,
582
373
  });
583
374
  if (values.help) {
584
- console.log('usage: practi push [hash] [--branch <b>] [--message <text>] (store + bind branch head; requires a bound instance — POP lives on the hub as practice instances)');
375
+ console.log('usage: practi clone <owner>/<name>[@branch] [--dir <path>] (clone a hub practice into a local folder)');
585
376
  return 0;
586
377
  }
587
- return await runPush({ dataDir: str(values['data-dir']), positional: positionals, branch: values.branch, message: values.message });
378
+ return await runClone({ positional: positionals, dir: values.dir });
588
379
  }
589
- case 'fix': {
380
+ case 'branch': {
590
381
  const { values, positionals } = parseArgs({
591
382
  args: rest,
592
- options: { ...COMMON, all: { type: 'boolean' }, 'dry-run': { type: 'boolean' } },
383
+ options: {
384
+ ...COMMON,
385
+ from: { type: 'string' },
386
+ delete: { type: 'string', short: 'd' },
387
+ dir: { type: 'string' },
388
+ },
593
389
  allowPositionals: true,
594
390
  });
595
391
  if (values.help) {
596
- console.log('usage: practi fix <file.json> | <hash> | --all [--dry-run] (strip POP 1.x history fields — revisions/refines — and re-validate under POP 2.0)');
392
+ console.log('usage: practi branch [name] [-d <name>] (list / create / delete branches; * marks the current branch)');
597
393
  return 0;
598
394
  }
599
- return runFix({ dataDir: str(values['data-dir']), positional: positionals, all: values.all === true, dryRun: values['dry-run'] === true });
395
+ return runBranch({ positional: positionals, from: values.from, deleteBranch: values.delete, dir: values.dir });
600
396
  }
601
- case 'pull': {
602
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
397
+ case 'switch': {
398
+ const { values, positionals } = parseArgs({
399
+ args: rest,
400
+ options: { ...COMMON, dir: { type: 'string' } },
401
+ allowPositionals: true,
402
+ });
603
403
  if (values.help) {
604
- console.log('usage: practi pull (sync the bound instance\'s remote revisions into the workspace; clone/fetch bring new content in)');
404
+ console.log('usage: practi switch <branch> (switch branches; the working file follows the head)');
605
405
  return 0;
606
406
  }
607
- return await runPull({ dataDir: str(values['data-dir']), positional: positionals });
407
+ return runSwitch({ positional: positionals, dir: values.dir });
608
408
  }
609
- case 'clone': {
610
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
409
+ case 'merge': {
410
+ const { values, positionals } = parseArgs({
411
+ args: rest,
412
+ options: { ...COMMON, dir: { type: 'string' } },
413
+ allowPositionals: true,
414
+ });
611
415
  if (values.help) {
612
- console.log('usage: practi clone <owner>/<name>[@branch] (fetch a practice instance, bind the workspace to it, check out its head)');
416
+ console.log('usage: practi merge <branch> (fast-forward, else pointer move)');
613
417
  return 0;
614
418
  }
615
- return await runClone({ dataDir: str(values['data-dir']), positional: positionals });
419
+ return runMerge({ positional: positionals, dir: values.dir });
616
420
  }
617
- case 'fetch': {
618
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
421
+ case 'log': {
422
+ const { values } = parseArgs({
423
+ args: rest,
424
+ options: {
425
+ ...COMMON,
426
+ branch: { type: 'string' },
427
+ limit: { type: 'string' },
428
+ json: { type: 'boolean' },
429
+ dir: { type: 'string' },
430
+ },
431
+ allowPositionals: true,
432
+ });
619
433
  if (values.help) {
620
- console.log('usage: practi fetch <owner>/<name> <hash> (pull one revision of that instance into your local registry, full sha256 hash)');
434
+ console.log('usage: practi log [--branch <b>] [--limit N] [--json] (the commit history, tip first)');
621
435
  return 0;
622
436
  }
623
- return await runFetch({ dataDir: str(values['data-dir']), positional: positionals });
437
+ const logLimit = values.limit ? Number(values.limit) : undefined;
438
+ return runLog({
439
+ branch: values.branch,
440
+ limit: logLimit !== undefined && Number.isInteger(logLimit) && logLimit > 0 ? logLimit : undefined,
441
+ json: values.json === true,
442
+ dir: values.dir,
443
+ });
624
444
  }
625
- case 'instance': {
445
+ case 'history': {
626
446
  const { values, positionals } = parseArgs({
627
447
  args: rest,
628
- options: { ...COMMON, public: { type: 'boolean' }, desc: { type: 'string' } },
448
+ options: {
449
+ ...COMMON,
450
+ dir: { type: 'string' },
451
+ message: { type: 'string', short: 'm' },
452
+ },
629
453
  allowPositionals: true,
630
454
  });
631
455
  if (values.help) {
632
- console.log('usage: practi instance create <name> [--public] [--desc <text>] | bind <owner>/<name> | show');
456
+ console.log('usage: practi history reword <seq> -m <msg> | squash <seq> | drop <seq> | reset <seq> (rewrite the local chain; push reconciles)');
633
457
  return 0;
634
458
  }
635
- return await runInstance({ dataDir: str(values['data-dir']), positional: positionals, publicVisibility: values.public === true, desc: values.desc });
459
+ return await runHistory({ positional: positionals, dir: values.dir, message: values.message });
636
460
  }
637
- case 'branch': {
461
+ case 'fix': {
638
462
  const { values, positionals } = parseArgs({
639
463
  args: rest,
640
- options: { ...COMMON, from: { type: 'string' }, delete: { type: 'string', short: 'd' } },
464
+ options: { ...COMMON, 'dry-run': { type: 'boolean' } },
641
465
  allowPositionals: true,
642
466
  });
643
467
  if (values.help) {
644
- console.log('usage: practi branch [name] [--from <hash>] | -d <name> (list / create / delete instance branches)');
468
+ console.log('usage: practi fix <file.json> [--dry-run] (strip POP 1.x history fields — revisions/refines — from a document file)');
645
469
  return 0;
646
470
  }
647
- return await runBranch({ dataDir: str(values['data-dir']), positional: positionals, from: values.from, deleteBranch: values.delete });
471
+ return runFix({ positional: positionals, dryRun: values['dry-run'] === true });
648
472
  }
649
- case 'switch': {
650
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
473
+ case 'search': {
474
+ const { values, positionals } = parseArgs({
475
+ args: rest,
476
+ options: {
477
+ ...COMMON,
478
+ limit: { type: 'string' },
479
+ json: { type: 'boolean' },
480
+ notes: { type: 'boolean' },
481
+ semantic: { type: 'boolean' },
482
+ dir: { type: 'string' },
483
+ },
484
+ allowPositionals: true,
485
+ });
651
486
  if (values.help) {
652
- console.log('usage: practi switch <branch> (switch the bound instance\'s current branch)');
487
+ console.log('usage: practi search [query...] [--limit N] [--json] [--notes] [--semantic] (search this practice\'s revisions)');
653
488
  return 0;
654
489
  }
655
- return await runSwitch({ dataDir: str(values['data-dir']), positional: positionals });
490
+ const limit = values.limit ? Number(values.limit) : 20;
491
+ return await runSearch({
492
+ positional: positionals,
493
+ limit: Number.isInteger(limit) && limit > 0 ? Math.min(limit, 50) : 20,
494
+ json: values.json === true,
495
+ notes: values.notes === true,
496
+ semantic: values.semantic === true,
497
+ dir: values.dir,
498
+ });
656
499
  }
657
- case 'merge': {
658
- const { values, positionals } = parseArgs({ args: rest, options: COMMON, allowPositionals: true });
500
+ case 'similar': {
501
+ const { values, positionals } = parseArgs({
502
+ args: rest,
503
+ options: {
504
+ ...COMMON,
505
+ limit: { type: 'string' },
506
+ json: { type: 'boolean' },
507
+ dir: { type: 'string' },
508
+ },
509
+ allowPositionals: true,
510
+ });
511
+ if (values.help) {
512
+ console.log('usage: practi similar <hash> [--limit N] [--json] (content neighbours within this practice)');
513
+ return 0;
514
+ }
515
+ if (positionals.length === 0) {
516
+ console.error('usage: practi similar <hash> [--limit N] [--json]');
517
+ return 1;
518
+ }
519
+ const simLimit = values.limit ? Number(values.limit) : 10;
520
+ return runSimilar({
521
+ ref: positionals[0],
522
+ limit: Number.isInteger(simLimit) && simLimit > 0 ? Math.min(simLimit, 50) : 10,
523
+ json: values.json === true,
524
+ dir: values.dir,
525
+ });
526
+ }
527
+ case 'note': {
528
+ const { values, positionals } = parseArgs({
529
+ args: rest,
530
+ options: {
531
+ ...COMMON,
532
+ message: { type: 'string', short: 'm' },
533
+ json: { type: 'boolean' },
534
+ dir: { type: 'string' },
535
+ },
536
+ allowPositionals: true,
537
+ });
659
538
  if (values.help) {
660
- console.log('usage: practi merge <branch> (fast-forward, else squash-merge into the current branch)');
539
+ console.log('usage: practi note add|list|edit|delete (local notes pinned to node hashes; see `practi note` help)');
661
540
  return 0;
662
541
  }
663
- return await runMerge({ dataDir: str(values['data-dir']), positional: positionals });
542
+ return runNote({
543
+ positional: positionals,
544
+ message: values.message,
545
+ json: values.json === true,
546
+ dir: values.dir,
547
+ });
664
548
  }
665
- case 'log': {
666
- const { values } = parseArgs({
549
+ case 'embed': {
550
+ const { values, positionals } = parseArgs({
667
551
  args: rest,
668
- options: { ...COMMON, branch: { type: 'string' }, limit: { type: 'string' }, json: { type: 'boolean' } },
552
+ options: { ...COMMON, json: { type: 'boolean' }, notes: { type: 'boolean' }, dir: { type: 'string' } },
669
553
  allowPositionals: true,
670
554
  });
671
555
  if (values.help) {
672
- console.log('usage: practi log [--branch <b>] [--limit N] [--json] (revision history, tip first)');
556
+ console.log('usage: practi embed status|pull|build|prune [--json] [--notes] (optional offline vector model, scoped to this practice)');
673
557
  return 0;
674
558
  }
675
- const logLimit = values.limit ? Number(values.limit) : undefined;
676
- return await runLog({
677
- dataDir: str(values['data-dir']),
678
- branch: values.branch,
679
- limit: logLimit !== undefined && Number.isInteger(logLimit) && logLimit > 0 ? logLimit : undefined,
559
+ return await runEmbed({
560
+ positional: positionals,
680
561
  json: values.json === true,
562
+ notes: values.notes === true,
563
+ dir: values.dir,
681
564
  });
682
565
  }
683
566
  case 'help':
@@ -685,6 +568,19 @@ async function main(argv) {
685
568
  case '-h':
686
569
  console.log(USAGE);
687
570
  return 0;
571
+ case 'edit':
572
+ case 'ls':
573
+ case 'list':
574
+ case 'remove':
575
+ case 'claim':
576
+ case 'unclaim':
577
+ case 'publish':
578
+ case 'fetch':
579
+ case 'repair':
580
+ case 'migrate':
581
+ case 'instance':
582
+ case 'practice':
583
+ return retired(cmd);
688
584
  default:
689
585
  console.error(`unknown command: ${cmd}`);
690
586
  console.error(USAGE);