@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.
- package/README.md +76 -136
- package/dist/client.js +6 -6
- package/dist/client.js.map +1 -1
- package/dist/cmd/blob.js +21 -24
- package/dist/cmd/blob.js.map +1 -1
- package/dist/cmd/branch.js +42 -51
- package/dist/cmd/branch.js.map +1 -1
- package/dist/cmd/clone.js +52 -38
- package/dist/cmd/clone.js.map +1 -1
- package/dist/cmd/commit.js +97 -0
- package/dist/cmd/commit.js.map +1 -0
- package/dist/cmd/config.js +1 -17
- package/dist/cmd/config.js.map +1 -1
- package/dist/cmd/edit.js +18 -4
- package/dist/cmd/edit.js.map +1 -1
- package/dist/cmd/embed.js +30 -25
- package/dist/cmd/embed.js.map +1 -1
- package/dist/cmd/export.js +43 -0
- package/dist/cmd/export.js.map +1 -0
- package/dist/cmd/fix.js +9 -153
- package/dist/cmd/fix.js.map +1 -1
- package/dist/cmd/gc.js +6 -5
- package/dist/cmd/gc.js.map +1 -1
- package/dist/cmd/history.js +160 -0
- package/dist/cmd/history.js.map +1 -0
- package/dist/cmd/init.js +10 -5
- package/dist/cmd/init.js.map +1 -1
- package/dist/cmd/lint.js +23 -20
- package/dist/cmd/lint.js.map +1 -1
- package/dist/cmd/log.js +33 -42
- package/dist/cmd/log.js.map +1 -1
- package/dist/cmd/merge.js +32 -91
- package/dist/cmd/merge.js.map +1 -1
- package/dist/cmd/new.js +56 -54
- package/dist/cmd/new.js.map +1 -1
- package/dist/cmd/note.js +27 -42
- package/dist/cmd/note.js.map +1 -1
- package/dist/cmd/practice.js +56 -0
- package/dist/cmd/practice.js.map +1 -0
- package/dist/cmd/publish.js +124 -0
- package/dist/cmd/publish.js.map +1 -0
- package/dist/cmd/pull.js +78 -46
- package/dist/cmd/pull.js.map +1 -1
- package/dist/cmd/push.js +204 -67
- package/dist/cmd/push.js.map +1 -1
- package/dist/cmd/search.js +30 -44
- package/dist/cmd/search.js.map +1 -1
- package/dist/cmd/show.js +5 -4
- package/dist/cmd/show.js.map +1 -1
- package/dist/cmd/similar.js +7 -20
- package/dist/cmd/similar.js.map +1 -1
- package/dist/cmd/skill.js +16 -16
- package/dist/cmd/skill.js.map +1 -1
- package/dist/cmd/switch.js +20 -26
- package/dist/cmd/switch.js.map +1 -1
- package/dist/index.js +292 -396
- package/dist/index.js.map +1 -1
- package/dist/practice.js +221 -0
- package/dist/practice.js.map +1 -0
- package/dist/quality.js +2 -2
- package/dist/quality.js.map +1 -1
- package/dist/state.js +13 -73
- package/dist/state.js.map +1 -1
- package/dist/sync.js +6 -48
- package/dist/sync.js.map +1 -1
- package/dist/web.js +159 -442
- package/dist/web.js.map +1 -1
- package/dist/workspace.js +10 -52
- package/dist/workspace.js.map +1 -1
- package/package.json +1 -1
- package/skills/use-practi/SKILL.md +121 -125
- package/web-default/chain.html +39 -0
- package/web-default/chain.js +54 -0
- package/web-default/lang.js +4 -0
- package/web-default/app.js +0 -106
- package/web-default/index.html +0 -28
package/dist/cmd/log.js
CHANGED
|
@@ -1,59 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { authedFetch } from '../client.js';
|
|
1
|
+
import { resolveRepo } from '../practice.js';
|
|
3
2
|
import { shortHash } from '../render.js';
|
|
4
|
-
import { unpushedCommits } from '../commits.js';
|
|
5
3
|
/**
|
|
6
|
-
* practi log [--branch <b>] [--limit N] [--json]
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
4
|
+
* practi log [--branch <b>] [--limit N] [--json]:实例提交历史(本地链,tip 在前)。
|
|
5
|
+
* git log 同构——seq 是链内登记序号,短哈希是全球坐标;未推送到 hub 的提交标注
|
|
6
|
+
* (local, unpushed)。历史编辑(history squash/reword/drop/reset)后的链以此为准,
|
|
7
|
+
* push 时与 hub 对账。
|
|
10
8
|
*/
|
|
11
|
-
export
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
if (!state.remote) {
|
|
15
|
-
console.error('error: no remote configured — run `practi remote set <url>` first');
|
|
9
|
+
export function runLog(opts) {
|
|
10
|
+
const repo = resolveRepo({ dir: opts.dir, verb: 'log' });
|
|
11
|
+
if (repo === null)
|
|
16
12
|
return 1;
|
|
13
|
+
const chain = repo.chain;
|
|
14
|
+
const branch = opts.branch ?? chain.current;
|
|
15
|
+
const head = chain.branches[branch] ?? null;
|
|
16
|
+
// 该支的提交:从支头沿 parent 回溯(多支时只显示所在链段)
|
|
17
|
+
const byRoot = new Map(chain.commits.map((c) => [c.root, c]));
|
|
18
|
+
const rows = [];
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
let cur = head;
|
|
21
|
+
while (cur !== null && !seen.has(cur)) {
|
|
22
|
+
const c = byRoot.get(cur);
|
|
23
|
+
if (!c)
|
|
24
|
+
break;
|
|
25
|
+
seen.add(cur);
|
|
26
|
+
rows.push(c);
|
|
27
|
+
cur = c.parent;
|
|
17
28
|
}
|
|
18
|
-
if (!state.instance) {
|
|
19
|
-
console.error('error: no instance bound — use `practi instance bind <owner>/<name>` first');
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
const { owner, name, branch } = state.instance;
|
|
23
|
-
const showBranch = opts.branch ?? branch;
|
|
24
|
-
const res = await authedFetch(dataDir, state.remote.url, `/api/v1/instances/${encodeURIComponent(owner)}/${encodeURIComponent(name)}?branch=${encodeURIComponent(showBranch)}`);
|
|
25
|
-
const body = (await res.json());
|
|
26
|
-
if (!res.ok) {
|
|
27
|
-
const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
|
|
28
|
-
console.error(`error: ${detail}`);
|
|
29
|
-
return 1;
|
|
30
|
-
}
|
|
31
|
-
const rows = body.revisions ?? [];
|
|
32
29
|
if (opts.json === true) {
|
|
33
|
-
console.log(JSON.stringify({
|
|
30
|
+
console.log(JSON.stringify({
|
|
31
|
+
practice: chain.owner ? `${chain.owner}/${chain.name}` : chain.name,
|
|
32
|
+
branch,
|
|
33
|
+
revisions: rows.map((c) => ({ seq: c.seq, root_hash: c.root, parent_hash: c.parent, message: c.message, pushed: c.pushedAt !== undefined })),
|
|
34
|
+
}, null, 2));
|
|
34
35
|
return 0;
|
|
35
36
|
}
|
|
36
|
-
const unpushed = unpushedCommits(dataDir);
|
|
37
|
-
if (unpushed.length > 0) {
|
|
38
|
-
console.log(`local, unpushed (${unpushed.length}):`);
|
|
39
|
-
for (const c of unpushed) {
|
|
40
|
-
console.log(` · ${shortHash(c.hash)} ${c.createdAt.slice(0, 10)} ${c.message}${c.from ? ` (from ${shortHash(c.from)})` : ''}`);
|
|
41
|
-
}
|
|
42
|
-
console.log('');
|
|
43
|
-
}
|
|
44
37
|
if (rows.length === 0) {
|
|
45
|
-
console.log(`no revisions on ${
|
|
38
|
+
console.log(`no revisions on ${chain.name}@${branch}`);
|
|
46
39
|
return 0;
|
|
47
40
|
}
|
|
48
41
|
const limit = opts.limit !== undefined && opts.limit > 0 ? opts.limit : rows.length;
|
|
49
|
-
for (const
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
const note = r.message ? ` ${r.message}` : '';
|
|
53
|
-
console.log(`v${String(r.seq).padEnd(4)} ${shortHash(r.root_hash)} ${date} ${r.status.padEnd(15)} ${title}${r.missing ? ' (document deleted)' : ''}${note}`);
|
|
42
|
+
for (const c of rows.slice(0, limit)) {
|
|
43
|
+
const unpushed = c.pushedAt === undefined ? ' (local, unpushed)' : '';
|
|
44
|
+
console.log(`v${String(c.seq).padEnd(4)} ${shortHash(c.root)} ${c.message}${unpushed}`);
|
|
54
45
|
}
|
|
55
46
|
if (rows.length > limit)
|
|
56
|
-
console.log(`... ${rows.length
|
|
47
|
+
console.log(`... ${rows.length} more (use --limit)`);
|
|
57
48
|
return 0;
|
|
58
49
|
}
|
|
59
50
|
//# sourceMappingURL=log.js.map
|
package/dist/cmd/log.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/cmd/log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C;QACvE,OAAO,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,GAAG,QAAQ,EAAE,CAAC,CAAC;IAC3F,CAAC;IACD,IAAI,IAAI,CAAC,MAAM,GAAG,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,MAAM,qBAAqB,CAAC,CAAC;IAC9E,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/cmd/merge.js
CHANGED
|
@@ -1,65 +1,29 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { defaultDataDir, loadState } from '../state.js';
|
|
3
|
-
import { openWorkspace } from '../workspace.js';
|
|
4
|
-
import { authedFetch } from '../client.js';
|
|
1
|
+
import { dirtyGuardMessage, isDirty, resolveRepo, saveChain, writeWorkingFile } from '../practice.js';
|
|
5
2
|
import { shortHash } from '../render.js';
|
|
6
|
-
import { stripAttachmentUrls } from './push.js';
|
|
7
3
|
/**
|
|
8
|
-
* practi merge <branch
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* 合并提交在 hub 上、本地还没有——提示 `practi pull <hash>` 同步。
|
|
4
|
+
* practi merge <branch>:把指定支合并进当前支(本地链操作,合并方向=参数支 → 当前支)。
|
|
5
|
+
* 两种结局,按本地提交链 parent 可达性决定:
|
|
6
|
+
* - fast-forward:参数支头沿 parent 链可达当前支头 → 纯移指针,零新提交;
|
|
7
|
+
* - 分叉(squash):不可达 → 指针移动(同 root 恰一行——同树提交是同一个提交,
|
|
8
|
+
* 无法带第二 parent,spec §9.1)。合并永远可完成;push 时与 hub 对账。
|
|
9
|
+
* 工作文件有未提交改动时拒合并;合并后工作文件回写成新头。
|
|
15
10
|
*/
|
|
16
|
-
export
|
|
17
|
-
const dataDir = opts.dataDir ?? defaultDataDir();
|
|
18
|
-
const state = loadState(dataDir);
|
|
19
|
-
if (!state.remote) {
|
|
20
|
-
console.error('error: no remote configured — run `practi remote set <url>` first');
|
|
21
|
-
return 1;
|
|
22
|
-
}
|
|
23
|
-
if (!state.instance) {
|
|
24
|
-
console.error('error: no instance bound — use `practi instance bind <owner>/<name>` first');
|
|
25
|
-
return 1;
|
|
26
|
-
}
|
|
11
|
+
export function runMerge(opts) {
|
|
27
12
|
const fromBranch = opts.positional[0];
|
|
28
13
|
if (!fromBranch) {
|
|
29
14
|
console.error('usage: practi merge <branch>');
|
|
30
15
|
return 1;
|
|
31
16
|
}
|
|
32
|
-
const {
|
|
33
|
-
|
|
34
|
-
if (fromBranch === intoBranch) {
|
|
35
|
-
console.error(`error: cannot merge ${fromBranch} into itself`);
|
|
17
|
+
const repo = resolveRepo({ dir: opts.dir, verb: 'merge' });
|
|
18
|
+
if (repo === null)
|
|
36
19
|
return 1;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const res = await authedFetch(dataDir, state.remote.url, `${base}?branch=${encodeURIComponent(branch)}`);
|
|
41
|
-
const body = (await res.json());
|
|
42
|
-
if (!res.ok) {
|
|
43
|
-
const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
|
|
44
|
-
throw new Error(detail);
|
|
45
|
-
}
|
|
46
|
-
return body;
|
|
47
|
-
};
|
|
48
|
-
let intoTip;
|
|
49
|
-
let fromTip;
|
|
50
|
-
let parents;
|
|
51
|
-
try {
|
|
52
|
-
const into = await fetchBranch(intoBranch);
|
|
53
|
-
const from = await fetchBranch(fromBranch);
|
|
54
|
-
intoTip = into.branch_head_hash ?? null;
|
|
55
|
-
fromTip = from.branch_head_hash ?? null;
|
|
56
|
-
// 提交链现算可达性:两条支的登记提交合起来看(seq 是实例级登记,parent 才是血统边)
|
|
57
|
-
parents = new Map([...(into.revisions ?? []), ...(from.revisions ?? [])].map((r) => [r.root_hash, r.parent_hash ?? null]));
|
|
58
|
-
}
|
|
59
|
-
catch (e) {
|
|
60
|
-
console.error(`error: ${e.message}`);
|
|
20
|
+
const chain = repo.chain;
|
|
21
|
+
if (fromBranch === chain.current) {
|
|
22
|
+
console.error(`error: cannot merge ${fromBranch} into itself`);
|
|
61
23
|
return 1;
|
|
62
24
|
}
|
|
25
|
+
const fromTip = chain.branches[fromBranch] ?? null;
|
|
26
|
+
const intoTip = chain.branches[chain.current] ?? null;
|
|
63
27
|
if (!fromTip) {
|
|
64
28
|
console.error(`error: branch ${fromBranch} has no revisions to merge`);
|
|
65
29
|
return 1;
|
|
@@ -68,61 +32,38 @@ export async function runMerge(opts) {
|
|
|
68
32
|
console.log('already up to date');
|
|
69
33
|
return 0;
|
|
70
34
|
}
|
|
71
|
-
|
|
35
|
+
if (isDirty(repo)) {
|
|
36
|
+
console.error(`error: ${dirtyGuardMessage(repo)}`);
|
|
37
|
+
return 1;
|
|
38
|
+
}
|
|
39
|
+
// 快进判定:from 头沿 parent 链能走到 into 头(into 为空=天然快进)
|
|
72
40
|
const reaches = (from, target) => {
|
|
73
41
|
if (target === null)
|
|
74
42
|
return true;
|
|
43
|
+
const byRoot = new Map(chain.commits.map((c) => [c.root, c]));
|
|
75
44
|
const seen = new Set();
|
|
76
45
|
let cur = from;
|
|
77
46
|
while (cur !== null && !seen.has(cur)) {
|
|
78
47
|
if (cur === target)
|
|
79
48
|
return true;
|
|
80
49
|
seen.add(cur);
|
|
81
|
-
cur =
|
|
50
|
+
cur = byRoot.get(cur)?.parent ?? null;
|
|
82
51
|
}
|
|
83
52
|
return false;
|
|
84
53
|
};
|
|
85
54
|
if (reaches(fromTip, intoTip)) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
91
|
-
const body = await res.json();
|
|
92
|
-
if (!res.ok) {
|
|
93
|
-
const detail = typeof body.message === 'string' ? body.message : `HTTP ${res.status}`;
|
|
94
|
-
console.error(`error: fast-forward failed — ${detail}`);
|
|
95
|
-
return 1;
|
|
96
|
-
}
|
|
97
|
-
console.log(`fast-forward: ${intoBranch} → ${shortHash(fromTip)} (merged ${fromBranch})`);
|
|
55
|
+
chain.branches[chain.current] = fromTip;
|
|
56
|
+
saveChain(repo);
|
|
57
|
+
writeWorkingFile(repo, fromTip);
|
|
58
|
+
console.log(`fast-forward: ${chain.current} → ${shortHash(fromTip)} (merged ${fromBranch}) (working file updated)`);
|
|
98
59
|
return 0;
|
|
99
60
|
}
|
|
100
|
-
//
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const tipNode = ws.nodes.get(fromTip);
|
|
107
|
-
if (!tipNode) {
|
|
108
|
-
console.error(`error: branch tip ${shortHash(fromTip)} is not in the local workspace — \`practi fetch ${owner}/${name} ${shortHash(fromTip)}\` first`);
|
|
109
|
-
return 1;
|
|
110
|
-
}
|
|
111
|
-
const doc = stripAttachmentUrls(exportSubtree(tipNode, ws.nodes));
|
|
112
|
-
const stored = await authedFetch(dataDir, state.remote.url, `${base}/branches/${encodeURIComponent(intoBranch)}/revisions`, {
|
|
113
|
-
method: 'POST',
|
|
114
|
-
headers: { 'content-type': 'application/json' },
|
|
115
|
-
body: JSON.stringify({ document: doc, message: `merge branch '${fromBranch}'` }),
|
|
116
|
-
});
|
|
117
|
-
const storedBody = await stored.json();
|
|
118
|
-
if (!stored.ok || typeof storedBody.root_hash !== 'string') {
|
|
119
|
-
const detail = typeof storedBody.message === 'string' ? storedBody.message : `HTTP ${stored.status}`;
|
|
120
|
-
console.error(`error: storing the merge commit failed — ${detail}`);
|
|
121
|
-
return 1;
|
|
122
|
-
}
|
|
123
|
-
const mergeRoot = storedBody.root_hash;
|
|
124
|
-
console.log(`merged (squash): ${fromBranch} → ${intoBranch} as ${shortHash(mergeRoot)}`);
|
|
125
|
-
console.log(`note: the merge commit lives on the hub — \`practi fetch ${owner}/${name} ${shortHash(mergeRoot)}\` to sync it locally`);
|
|
61
|
+
// 分叉:同 root 恰一行(§9.1)——同树提交无法带第二个 parent,指针移动即合并
|
|
62
|
+
chain.branches[chain.current] = fromTip;
|
|
63
|
+
saveChain(repo);
|
|
64
|
+
writeWorkingFile(repo, fromTip);
|
|
65
|
+
console.log(`merged: ${fromBranch} → ${chain.current} ${shortHash(fromTip)} (pointer move — same-tree commits are identical)`);
|
|
66
|
+
console.log('note: the chain diverged from the hub if pushed — `practi push --force` to sync');
|
|
126
67
|
return 0;
|
|
127
68
|
}
|
|
128
69
|
//# sourceMappingURL=merge.js.map
|
package/dist/cmd/merge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/cmd/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"merge.js","sourceRoot":"","sources":["../../src/cmd/merge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAa,MAAM,gBAAgB,CAAC;AACjH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAe;IACtC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAC9C,OAAO,CAAC,CAAC;IACX,CAAC;IACD,MAAM,IAAI,GAAgB,WAAW,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACxE,IAAI,IAAI,KAAK,IAAI;QAAE,OAAO,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACzB,IAAI,UAAU,KAAK,KAAK,CAAC,OAAO,EAAE,C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ChC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACd,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,IAAI,IAAI,CAAC;QACxC,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;IAEF,IAAI,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,EAAE,CAAC;QAC9B,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;QACxC,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAChC,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,CAAC,OAAO,MAAM,SAAS,CAAC,OAAO,CAAC,YAAY,UAAU,2BAA2B,CAAC,CAAC;QACrH,OAAO,CAAC,CAAC;IACX,CAAC;IAED,iDAAiD;IACjD,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;IACxC,SAAS,CAAC,IAAI,CAAC,CAAC;IAChB,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IAChC,OAAO,CAAC,GAAG,CAAC,YAAY,UAAU,MAAM,KAAK,CAAC,OAAO,KAAK,SAAS,CAAC,OAAO,CAAC,oDAAoD,CAAC,CAAC;IAClI,OAAO,CAAC,GAAG,CAAC,oFAAoF,CAAC,CAAC;IAClG,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/cmd/new.js
CHANGED
|
@@ -1,69 +1,71 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { openWorkspace, subtreeFiles } from '../workspace.js';
|
|
2
|
+
import { loadWorkspace, validateWorkspace } from '@arshdelight/pop-sdk';
|
|
3
|
+
import { createRepo, saveChain } from '../practice.js';
|
|
5
4
|
import { printQualityHints } from '../quality.js';
|
|
6
|
-
import {
|
|
5
|
+
import { shortHash } from '../render.js';
|
|
6
|
+
import { subtreeFiles } from '../workspace.js';
|
|
7
7
|
import { describeRefresh, refreshVectors } from '../embed/optional.js';
|
|
8
|
-
|
|
9
|
-
return fs.readFileSync(0, 'utf8');
|
|
10
|
-
}
|
|
8
|
+
import { nodeIndexFields } from '../retrieval.js';
|
|
11
9
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* practi new <name> [--base <file.json>] [-m <msg>]:
|
|
11
|
+
* 在 cwd 诞生实例文件夹 <name>/——工作文件 <name>.json(pop 本体,任何编辑器直接改)
|
|
12
|
+
* + .practi/(历史仓库:链+节点池)。--base 给一篇现成 pop 文档则写入第一版;
|
|
13
|
+
* 实例首次 push 才在 hub 诞生。目录已存在=拒绝。
|
|
15
14
|
*/
|
|
16
15
|
export async function runNew(opts) {
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
else if (opts.file)
|
|
21
|
-
text = fs.readFileSync(opts.file, 'utf8');
|
|
22
|
-
else if (opts.positional[0])
|
|
23
|
-
text = fs.readFileSync(opts.positional[0], 'utf8');
|
|
24
|
-
else if (!process.stdin.isTTY)
|
|
25
|
-
text = readStdin();
|
|
26
|
-
if (text === undefined || text.trim() === '') {
|
|
27
|
-
console.error('usage: practi new <file.json> | practi new --json \'<json text>\' | practi new < file.json');
|
|
16
|
+
const name = opts.positional[0];
|
|
17
|
+
if (!name || !/^[a-z0-9][a-z0-9-]{0,62}$/i.test(name)) {
|
|
18
|
+
console.error('usage: practi new <name> [--base <file.json>] [-m <msg>] (name: letters/digits/dash)');
|
|
28
19
|
return 1;
|
|
29
20
|
}
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
|
|
21
|
+
let baseDoc;
|
|
22
|
+
if (opts.base !== undefined) {
|
|
23
|
+
let text;
|
|
24
|
+
try {
|
|
25
|
+
text = fs.readFileSync(opts.base, 'utf8');
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
console.error(`error: cannot read ${opts.base}`);
|
|
29
|
+
return 1;
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
baseDoc = JSON.parse(text);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
console.error(`error [E_JSON]: ${e.message}`);
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
33
38
|
}
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
const repo = createRepo(process.cwd(), name, baseDoc, opts.message);
|
|
40
|
+
if (repo === null)
|
|
36
41
|
return 1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
console.error(
|
|
42
|
+
console.log(`created: ${name}/ (working file ${name}.json + history in .practi/)`);
|
|
43
|
+
if (baseDoc !== undefined) {
|
|
44
|
+
const root = repo.chain.commits[0].root;
|
|
45
|
+
// 与 new/edit 时代同口径的子树门禁:本次内容的 E_* 拦下(链已停在空仓库,
|
|
46
|
+
// 节点留给 gc——内容寻址幂等,不回滚文件)
|
|
47
|
+
const loaded = loadWorkspace(repo.poolDir);
|
|
48
|
+
const mine = subtreeFiles(loaded, root);
|
|
49
|
+
const issues = validateWorkspace(loaded).filter((i) => mine.has(i.file));
|
|
50
|
+
if (issues.length > 0) {
|
|
51
|
+
for (const i of issues)
|
|
52
|
+
console.error(` ${i.code}: ${i.message}${i.hint ? ` (${i.hint})` : ''}`);
|
|
53
|
+
// 回滚诞生:链清空、工作文件撤掉——干净拒绝,不留「已上链却报未提交」的矛盾态
|
|
54
|
+
repo.chain.commits = [];
|
|
55
|
+
repo.chain.branches = { main: null };
|
|
56
|
+
saveChain(repo);
|
|
57
|
+
if (fs.existsSync(repo.filePath))
|
|
58
|
+
fs.unlinkSync(repo.filePath);
|
|
59
|
+
console.error('error: not committed — the folder is born empty; fix the document and `practi commit -m "..."` inside it');
|
|
60
|
+
return 1;
|
|
55
61
|
}
|
|
56
|
-
console.
|
|
57
|
-
|
|
62
|
+
console.log(`first revision: v1 ${shortHash(root)} ${repo.chain.commits[0].message}`);
|
|
63
|
+
printQualityHints(loaded, root);
|
|
64
|
+
const note = describeRefresh(await refreshVectors(repo.poolDir, [...loaded.nodes.keys()].sort(), (h) => indexTextOf(h, loaded)));
|
|
65
|
+
if (note !== null)
|
|
66
|
+
console.error(note);
|
|
58
67
|
}
|
|
59
|
-
console.log(
|
|
60
|
-
// W_* 提示:登记已完成,提示只影响写作,不影响结果(E_ 在上面已经拦掉了)
|
|
61
|
-
printQualityHints(loaded, root);
|
|
62
|
-
// 向量索引保鲜:只在**已经启用**(pull 过模型且 build 过)时顺手补几个新节点;
|
|
63
|
-
// 没启用就一次网络/原生调用都不发生(见 embed/optional.ts)
|
|
64
|
-
const note = describeRefresh(await refreshVectors(dataDir, [...loaded.nodes.keys()].sort(), (h) => indexTextOf(h, loaded)));
|
|
65
|
-
if (note !== null)
|
|
66
|
-
console.error(note);
|
|
68
|
+
console.log(`next: cd ${name} — edit ${name}.json, \`practi commit -m "..."\`, then \`practi push\``);
|
|
67
69
|
return 0;
|
|
68
70
|
}
|
|
69
71
|
/** 与 search 同一口径的索引文本(全字段拼接) */
|
package/dist/cmd/new.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/cmd/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"new.js","sourceRoot":"","sources":["../../src/cmd/new.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAA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-
import {
|
|
3
|
-
import { openWorkspace } from '../workspace.js';
|
|
2
|
+
import { openPool, chainHead, resolveRepo } from '../practice.js';
|
|
4
3
|
import { shortHash } from '../render.js';
|
|
5
4
|
import { loadNotes, insertNote, updateNote, removeNote, subtreeHashes } from '../notes.js';
|
|
6
|
-
|
|
7
|
-
const USAGE = `usage: practi note add|list|edit|delete|promote
|
|
5
|
+
const USAGE = `usage: practi note add|list|edit|delete
|
|
8
6
|
practi note add <node> -m "<text>" [--json]
|
|
9
7
|
pin a learning/reproduction note to a node hash (prefix OK; local only,
|
|
10
8
|
never uploaded)
|
|
@@ -12,48 +10,36 @@ const USAGE = `usage: practi note add|list|edit|delete|promote
|
|
|
12
10
|
no arg = all notes (grouped by owning document); hash = only notes within
|
|
13
11
|
that node's subtree
|
|
14
12
|
practi note edit <note-id> -m "<new text>" [--json]
|
|
15
|
-
practi note delete <note-id
|
|
16
|
-
practi note promote <note-id> [--out <file>]
|
|
17
|
-
turn a note back into a draft document (the owning direct root's --doc,
|
|
18
|
-
the note spliced in at its node); drafts only, never an automatic edit —
|
|
19
|
-
merging it in is your call`;
|
|
13
|
+
practi note delete <note-id>`;
|
|
20
14
|
export function runNote(opts) {
|
|
21
|
-
const
|
|
15
|
+
const repo = resolveRepo({ dir: opts.dir, verb: 'note' });
|
|
16
|
+
if (repo === null)
|
|
17
|
+
return 1;
|
|
22
18
|
const sub = opts.positional[0];
|
|
23
19
|
switch (sub) {
|
|
24
20
|
case 'add':
|
|
25
|
-
return noteAdd(opts,
|
|
21
|
+
return noteAdd(opts, repo);
|
|
26
22
|
case 'list':
|
|
27
|
-
return noteList(opts,
|
|
23
|
+
return noteList(opts, repo);
|
|
28
24
|
case 'edit':
|
|
29
|
-
return noteEdit(opts,
|
|
25
|
+
return noteEdit(opts, repo.poolDir);
|
|
30
26
|
case 'delete':
|
|
31
|
-
return noteDelete(opts,
|
|
32
|
-
case 'promote':
|
|
33
|
-
return notePromote(opts, dataDir);
|
|
27
|
+
return noteDelete(opts, repo.poolDir);
|
|
34
28
|
default:
|
|
35
29
|
console.error(USAGE);
|
|
36
30
|
return 1;
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
|
-
function
|
|
40
|
-
const id = opts.positional[1];
|
|
41
|
-
if (!id) {
|
|
42
|
-
console.error('usage: practi note promote <note-id> [--out <file>]');
|
|
43
|
-
return 1;
|
|
44
|
-
}
|
|
45
|
-
return runNotePromote({ dataDir, id, out: opts.out });
|
|
46
|
-
}
|
|
47
|
-
function noteAdd(opts, dataDir) {
|
|
33
|
+
function noteAdd(opts, repo) {
|
|
48
34
|
const target = opts.positional[1];
|
|
49
35
|
if (!target || !opts.message || !opts.message.trim()) {
|
|
50
36
|
console.error('usage: practi note add <node> -m "<text>"');
|
|
51
37
|
return 1;
|
|
52
38
|
}
|
|
53
|
-
//
|
|
54
|
-
const ws =
|
|
39
|
+
// 存在性校验兼前缀解析:笔记必须钉在池里已有的节点上(挡手滑哈希)
|
|
40
|
+
const ws = openPool(repo);
|
|
55
41
|
const hash = resolveNodeRef(ws, target);
|
|
56
|
-
const note = insertNote(
|
|
42
|
+
const note = insertNote(repo.poolDir, hash, opts.message);
|
|
57
43
|
if (opts.json) {
|
|
58
44
|
console.log(JSON.stringify(note, null, 2));
|
|
59
45
|
return 0;
|
|
@@ -61,12 +47,12 @@ function noteAdd(opts, dataDir) {
|
|
|
61
47
|
console.log(`noted on ${shortHash(hash)} — id ${note.id}`);
|
|
62
48
|
return 0;
|
|
63
49
|
}
|
|
64
|
-
function noteList(opts,
|
|
50
|
+
function noteList(opts, repo) {
|
|
65
51
|
const target = opts.positional[1];
|
|
66
|
-
const file = loadNotes(
|
|
52
|
+
const file = loadNotes(repo.poolDir);
|
|
67
53
|
let notes = file.notes;
|
|
68
54
|
if (target) {
|
|
69
|
-
const ws =
|
|
55
|
+
const ws = openPool(repo);
|
|
70
56
|
const hash = resolveNodeRef(ws, target);
|
|
71
57
|
const set = subtreeHashes(ws, hash);
|
|
72
58
|
notes = notes.filter(n => set.has(n.hash));
|
|
@@ -81,19 +67,18 @@ function noteList(opts, dataDir) {
|
|
|
81
67
|
return 0;
|
|
82
68
|
}
|
|
83
69
|
if (target) {
|
|
84
|
-
const ws2 =
|
|
70
|
+
const ws2 = openPool(repo);
|
|
85
71
|
printNotes(notes, h => ws2.nodes.get(h)?.name ?? shortHash(h));
|
|
86
72
|
return 0;
|
|
87
73
|
}
|
|
88
74
|
// 无参:按所属文档分组(组内时间正序=学习轨迹,组按最新笔记倒序=最近在学的在前);
|
|
89
|
-
//
|
|
90
|
-
const ws =
|
|
91
|
-
const
|
|
75
|
+
// 实例的「所属文档」就是当前支头,钉在已换根历史节点上的笔记归入悬空组殿后
|
|
76
|
+
const ws = openPool(repo);
|
|
77
|
+
const head = chainHead(repo.chain);
|
|
78
|
+
const roots = head !== null && ws.nodes.has(head) ? [head] : [];
|
|
92
79
|
const claimed = new Set();
|
|
93
80
|
const groups = [];
|
|
94
|
-
for (const root of
|
|
95
|
-
if (!ws.nodes.has(root))
|
|
96
|
-
continue;
|
|
81
|
+
for (const root of roots) {
|
|
97
82
|
const set = subtreeHashes(ws, root);
|
|
98
83
|
const items = notes.filter(n => set.has(n.hash));
|
|
99
84
|
if (!items.length)
|
|
@@ -146,13 +131,13 @@ function reportMutation(id, m) {
|
|
|
146
131
|
}
|
|
147
132
|
return 0;
|
|
148
133
|
}
|
|
149
|
-
function noteEdit(opts,
|
|
134
|
+
function noteEdit(opts, poolDir) {
|
|
150
135
|
const id = opts.positional[1];
|
|
151
136
|
if (!id || !opts.message || !opts.message.trim()) {
|
|
152
137
|
console.error('usage: practi note edit <note-id> -m "<new text>"');
|
|
153
138
|
return 1;
|
|
154
139
|
}
|
|
155
|
-
const m = updateNote(
|
|
140
|
+
const m = updateNote(poolDir, id, opts.message);
|
|
156
141
|
if (!m.ok)
|
|
157
142
|
return reportMutation(id, m);
|
|
158
143
|
if (opts.json) {
|
|
@@ -162,13 +147,13 @@ function noteEdit(opts, dataDir) {
|
|
|
162
147
|
console.log(`note ${m.note.id} edited`);
|
|
163
148
|
return 0;
|
|
164
149
|
}
|
|
165
|
-
function noteDelete(opts,
|
|
150
|
+
function noteDelete(opts, poolDir) {
|
|
166
151
|
const id = opts.positional[1];
|
|
167
152
|
if (!id) {
|
|
168
153
|
console.error('usage: practi note delete <note-id>');
|
|
169
154
|
return 1;
|
|
170
155
|
}
|
|
171
|
-
const m = removeNote(
|
|
156
|
+
const m = removeNote(poolDir, id);
|
|
172
157
|
if (!m.ok)
|
|
173
158
|
return reportMutation(id, m);
|
|
174
159
|
console.log(`note ${m.note.id} deleted`);
|