@aiti-ai/aiti-git-ops 0.1.11 → 0.1.13
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/aiti-git-ops.test.mjs +56 -1
- package/dev-pack.mjs +16 -3
- package/git-engine.ts +14 -10
- package/index.ts +2 -2
- package/package.json +2 -2
package/aiti-git-ops.test.mjs
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { test } from "node:test";
|
|
12
12
|
import assert from "node:assert/strict";
|
|
13
|
-
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync, rmSync } from "node:fs";
|
|
14
14
|
import { tmpdir } from "node:os";
|
|
15
15
|
import { join } from "node:path";
|
|
16
16
|
import { execFileSync } from "node:child_process";
|
|
@@ -310,6 +310,24 @@ test("log 分页:--graph 无 --skip 语义下翻页完整(55 空提交)",
|
|
|
310
310
|
assert.equal(tail.body.lines.length, 0); // 越界空页不炸
|
|
311
311
|
});
|
|
312
312
|
|
|
313
|
+
test("log: decorate always on + ref filter (graph view branch filter, borrow plan 2.1)", async () => {
|
|
314
|
+
git(["checkout", "-b", "graphview-x"]);
|
|
315
|
+
git(["commit", "--allow-empty", "-m", "gvx-1"]);
|
|
316
|
+
git(["commit", "--allow-empty", "-m", "gvx-2"]);
|
|
317
|
+
const r = await call(["git", "log"], { cwd: repo, ref: "graphview-x" });
|
|
318
|
+
assert.equal(r.status, 200);
|
|
319
|
+
const tip = r.body.lines.find((l) => l.includes("gvx-2"));
|
|
320
|
+
assert.ok(/\(HEAD -> graphview-x\)/.test(tip)); // --decorate=short badge inline
|
|
321
|
+
assert.ok(r.body.lines.some((l) => l.includes("gvx-1")));
|
|
322
|
+
const back = await call(["git", "log"], { cwd: repo, ref: "main", cursor: 0 });
|
|
323
|
+
assert.equal(back.status, 200);
|
|
324
|
+
assert.ok(!back.body.lines.some((l) => l.includes("gvx-2"))); // main view excludes branch-only commits
|
|
325
|
+
assert.ok(back.body.lines.some((l) => l.includes("c55"))); // shared history still visible
|
|
326
|
+
const bad = await call(["git", "log"], { cwd: repo, ref: "-U executing" });
|
|
327
|
+
assert.equal(bad.status, 400); // same assertSafeRef gate as checkout
|
|
328
|
+
git(["checkout", "main"]);
|
|
329
|
+
});
|
|
330
|
+
|
|
313
331
|
test("审计 jsonl 已写入(state 分层路径)", async () => {
|
|
314
332
|
const auditPath = join(tmp, "ext", "config", "state", "aiti-git-ops", "git-ops.jsonl");
|
|
315
333
|
assert.equal(existsSync(auditPath), true);
|
|
@@ -469,3 +487,40 @@ test("cherry-pick:冲突 409 + 中间态文件清单 + abort 复原", async ()
|
|
|
469
487
|
const st = await call(["git", "refs"], { cwd: repo });
|
|
470
488
|
assert.equal(st.body.dirtyCount, 0); // 工作区干净(走出中间态)
|
|
471
489
|
});
|
|
490
|
+
|
|
491
|
+
// ── folder "Add to .gitignore": trailing newline handling ───────────────────
|
|
492
|
+
|
|
493
|
+
test("ignore-add: prepend missing trailing newline, with idempotency / all-skipped / new-file cases", async () => {
|
|
494
|
+
const dir = mkdtempSync(join(tmpdir(), "git-ops-ignore-"));
|
|
495
|
+
const r = join(dir, "repo");
|
|
496
|
+
mkdirSync(r, { recursive: true });
|
|
497
|
+
execFileSync("git", ["init"], { cwd: r });
|
|
498
|
+
const gi = join(r, ".gitignore");
|
|
499
|
+
|
|
500
|
+
// No trailing newline: the new entry must not be glued to the last line
|
|
501
|
+
writeFileSync(gi, "keep.txt");
|
|
502
|
+
const first = await call(["git", "ignore-add"], { cwd: r, paths: ["new-dir"] });
|
|
503
|
+
assert.equal(first.status, 200);
|
|
504
|
+
assert.deepEqual(first.body.added, ["new-dir"]);
|
|
505
|
+
assert.equal(readFileSync(gi, "utf8"), "keep.txt\nnew-dir\n");
|
|
506
|
+
|
|
507
|
+
// Repeated add: no duplicate write, content unchanged
|
|
508
|
+
const again = await call(["git", "ignore-add"], { cwd: r, paths: ["new-dir"] });
|
|
509
|
+
assert.deepEqual(again.body.added, []);
|
|
510
|
+
assert.deepEqual(again.body.skipped, ["new-dir"]);
|
|
511
|
+
assert.equal(readFileSync(gi, "utf8"), "keep.txt\nnew-dir\n");
|
|
512
|
+
|
|
513
|
+
// All entries skipped but newline still missing: fix the newline anyway
|
|
514
|
+
writeFileSync(gi, "new-dir");
|
|
515
|
+
const fixNl = await call(["git", "ignore-add"], { cwd: r, paths: ["new-dir"] });
|
|
516
|
+
assert.equal(fixNl.status, 200);
|
|
517
|
+
assert.deepEqual(fixNl.body.skipped, ["new-dir"]);
|
|
518
|
+
assert.equal(readFileSync(gi, "utf8"), "new-dir\n");
|
|
519
|
+
|
|
520
|
+
// No .gitignore: the new file must not start with an empty line
|
|
521
|
+
rmSync(gi);
|
|
522
|
+
const fresh = await call(["git", "ignore-add"], { cwd: r, paths: ["fresh.txt"] });
|
|
523
|
+
assert.equal(fresh.status, 200);
|
|
524
|
+
assert.deepEqual(fresh.body.added, ["fresh.txt"]);
|
|
525
|
+
assert.equal(readFileSync(gi, "utf8"), "fresh.txt\n");
|
|
526
|
+
});
|
package/dev-pack.mjs
CHANGED
|
@@ -77,7 +77,7 @@ export function agentsMdTemplate(extId) {
|
|
|
77
77
|
|
|
78
78
|
/** 默认 tools/build.mjs(esbuild 单包零配置;扩展自带 tools/build.mjs 则不走到这里)。 */
|
|
79
79
|
function buildMjsTemplate(extId, extRoot, clientOut, entryRel) {
|
|
80
|
-
|
|
80
|
+
// No hardcoded checkout path: candidates are resolved at run time (see repoCandidates below).
|
|
81
81
|
return `/**
|
|
82
82
|
* ${extId} · 现场构建入口(dev-pack 默认模板,esbuild 单包零配置)
|
|
83
83
|
* 用法:node tools/build.mjs
|
|
@@ -96,12 +96,25 @@ const entryRel = ${JSON.stringify(entryRel || "")};
|
|
|
96
96
|
|
|
97
97
|
// esbuild 解析:部署目录 node_modules → 源码仓 node_modules(本机开发场景)→ PATH 上的 esbuild → npm exec 现拉。
|
|
98
98
|
// 注意:node_modules/esbuild/bin/esbuild 是原生二进制(ELF/Mach-O),必须直接执行(不能当 JS 跑)。
|
|
99
|
+
// Checkout roots are discovered by walking up from the extension dir (a root has node_modules/),
|
|
100
|
+
// plus AITI_REPO_ROOT when set — no machine-specific absolute paths baked into generated files.
|
|
101
|
+
function repoCandidates() {
|
|
102
|
+
const out = [];
|
|
103
|
+
if (process.env.AITI_REPO_ROOT) out.push(process.env.AITI_REPO_ROOT.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
|
|
104
|
+
let d = extRoot;
|
|
105
|
+
for (let i = 0; i < 8; i++) {
|
|
106
|
+
out.push(d.split(pathSep).join("/") + "/node_modules/esbuild/bin/esbuild");
|
|
107
|
+
const up = dirname(d);
|
|
108
|
+
if (up === d) break;
|
|
109
|
+
d = up;
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
99
113
|
function findEsbuild() {
|
|
100
114
|
const home = (process.env.HOME || process.env.USERPROFILE || "").split(pathSep).join("/");
|
|
101
115
|
const candidates = [
|
|
102
116
|
extRoot + "/node_modules/esbuild/bin/esbuild",
|
|
103
|
-
|
|
104
|
-
"D:/workspace/pi-work/node_modules/esbuild/bin/esbuild", // 155 win(源码在 D 盘)
|
|
117
|
+
...repoCandidates(),
|
|
105
118
|
];
|
|
106
119
|
for (const c of candidates) {
|
|
107
120
|
if (!existsSync(c)) continue;
|
package/git-engine.ts
CHANGED
|
@@ -295,18 +295,22 @@ export async function stashFiles(cwd: string, index: number): Promise<{ tracked:
|
|
|
295
295
|
/**
|
|
296
296
|
* 图谱分页。注意:`git log --graph` 与 `--skip` 不兼容(静默返回空,实测 git 2.48),
|
|
297
297
|
* 改为 --max-count=(skip+count+1) 后本地切片;是否还有下一页用 rev-list --count 判断。
|
|
298
|
+
* ref (optional, graph-view branch filter): defaults to HEAD; --decorate=short always on so the client can draw ref badges.
|
|
298
299
|
*/
|
|
299
|
-
export async function gitLog(cwd: string, cursor: number, count = 50): Promise<{ lines: string[]; nextCursor: number | null }> {
|
|
300
|
+
export async function gitLog(cwd: string, cursor: number, count = 50, ref?: string): Promise<{ lines: string[]; nextCursor: number | null }> {
|
|
300
301
|
const repo = await repoRoot(cwd);
|
|
302
|
+
const wanted = typeof ref === "string" ? ref.trim() : "";
|
|
303
|
+
const rev = wanted && wanted !== "HEAD" ? wanted : "HEAD";
|
|
304
|
+
if (rev !== "HEAD") assertSafeRef(rev, "ref");
|
|
301
305
|
const skip = Number.isInteger(cursor) && cursor > 0 ? cursor : 0;
|
|
302
|
-
const out = await run(repo, ["log", "--graph", "--oneline", "--date-order", `--max-count=${skip + count + 1}
|
|
306
|
+
const out = await run(repo, ["log", "--graph", "--oneline", "--date-order", "--decorate=short", `--max-count=${skip + count + 1}`, rev], 60_000);
|
|
303
307
|
const all = out.split("\n");
|
|
304
308
|
if (all[all.length - 1] === "") all.pop();
|
|
305
309
|
const lines = all.slice(skip, skip + count);
|
|
306
310
|
let nextCursor: number | null = null;
|
|
307
311
|
if (lines.length === count) {
|
|
308
312
|
try {
|
|
309
|
-
const total = Number((await run(repo, ["rev-list", "--count",
|
|
313
|
+
const total = Number((await run(repo, ["rev-list", "--count", rev], 30_000)).trim());
|
|
310
314
|
if (skip + count < total) nextCursor = skip + count;
|
|
311
315
|
} catch { /* 空仓库 */ }
|
|
312
316
|
}
|
|
@@ -720,8 +724,9 @@ export async function gitIgnoreAdd(cwd: string, paths: string[]): Promise<{ ok:
|
|
|
720
724
|
const lines = new Set(existing.split(/\r?\n/).map((l) => l.trim()).filter(Boolean));
|
|
721
725
|
const added: string[] = [];
|
|
722
726
|
const skipped: string[] = [];
|
|
723
|
-
|
|
724
|
-
|
|
727
|
+
// A file without a trailing newline would glue the first new entry onto its last line.
|
|
728
|
+
// Prepend the missing newline to the appended payload so the existing content stays untouched.
|
|
729
|
+
const needsNewline = existing.length > 0 && !existing.endsWith("\n");
|
|
725
730
|
for (const rel of rels) {
|
|
726
731
|
const entry = rel.replace(/\\/g, "/");
|
|
727
732
|
if (lines.has(entry)) {
|
|
@@ -729,13 +734,12 @@ export async function gitIgnoreAdd(cwd: string, paths: string[]): Promise<{ ok:
|
|
|
729
734
|
continue;
|
|
730
735
|
}
|
|
731
736
|
lines.add(entry);
|
|
732
|
-
content += entry + "\n";
|
|
733
737
|
added.push(entry);
|
|
734
738
|
}
|
|
735
|
-
if (added.length > 0) {
|
|
736
|
-
await appendFile(giPath, added.map((e) => e + "\n").join(""), "utf8");
|
|
737
|
-
await audit({ repo, cmd: "ignore-add", paths: added });
|
|
738
|
-
changed(repo, "stage", `ignore +${added.length}`);
|
|
739
|
+
if (added.length > 0 || needsNewline) {
|
|
740
|
+
await appendFile(giPath, (needsNewline ? "\n" : "") + added.map((e) => e + "\n").join(""), "utf8");
|
|
741
|
+
if (added.length > 0) await audit({ repo, cmd: "ignore-add", paths: added });
|
|
742
|
+
changed(repo, "stage", added.length > 0 ? `ignore +${added.length}` : "ignore: trailing newline");
|
|
739
743
|
}
|
|
740
744
|
return { ok: true as const, added, skipped };
|
|
741
745
|
});
|
package/index.ts
CHANGED
|
@@ -52,7 +52,7 @@ export default {
|
|
|
52
52
|
try {
|
|
53
53
|
ctx.services?.provide?.("aiti-git-ops.api", {
|
|
54
54
|
refs: (cwd: string) => engine.gitRefs(cwd),
|
|
55
|
-
log: (cwd: string, cursor: number) => engine.gitLog(cwd, cursor),
|
|
55
|
+
log: (cwd: string, cursor: number, ref?: string) => engine.gitLog(cwd, cursor, 50, ref),
|
|
56
56
|
checkout: (cwd: string, ref: string, mode?: string) => engine.gitCheckout(cwd, ref, mode),
|
|
57
57
|
branchCreate: (cwd: string, name: string, from?: string, checkout?: boolean) => engine.gitBranchCreate(cwd, name, from, checkout),
|
|
58
58
|
branchDelete: (cwd: string, name: string) => engine.gitBranchDelete(cwd, name),
|
|
@@ -103,7 +103,7 @@ export default {
|
|
|
103
103
|
try {
|
|
104
104
|
switch (p[1]) {
|
|
105
105
|
case "refs": return json({ ok: true, ...(await engine.gitRefs(cwd)) });
|
|
106
|
-
case "log": return json({ ok: true, ...(await engine.gitLog(cwd, body?.cursor ?? 0)) });
|
|
106
|
+
case "log": return json({ ok: true, ...(await engine.gitLog(cwd, body?.cursor ?? 0, 50, body?.ref)) });
|
|
107
107
|
case "checkout": return json(await engine.gitCheckout(cwd, body?.ref, body?.mode));
|
|
108
108
|
case "branch-create": return json(await engine.gitBranchCreate(cwd, body?.name, body?.from, body?.checkout !== false));
|
|
109
109
|
case "branch-delete": return json(await engine.gitBranchDelete(cwd, body?.name));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiti-ai/aiti-git-ops",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "Whitelisted git write engine — checkout precheck / stash / plan breakpoints / audit / changed topic, consumed by folder and session-manager",
|
|
5
5
|
"soul": "一处写仓,处处安全。",
|
|
6
6
|
"aitiExtProtocol": "1.0",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@aiti-ai/ext-shared": "^0.1.12"
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT",
|
|
11
|
-
"contentHash": "
|
|
11
|
+
"contentHash": "af29f11dd3e18ac5",
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/aiti-ai/aiti-ai.git",
|