@agimon-ai/po-git 0.0.0-alpha.44 → 0.0.0-alpha.46
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/dist/extensions/native.mjs +6 -3
- package/dist/extensions/native.mjs.map +1 -1
- package/dist/extensions/server.cjs +57 -53
- package/dist/extensions/server.cjs.map +1 -1
- package/dist/extensions/server.mjs +56 -52
- package/dist/extensions/server.mjs.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{worktreeOperations-CU0iV2h-.cjs → worktreeOperations-C1ygq-Na.cjs} +73 -65
- package/dist/worktreeOperations-C1ygq-Na.cjs.map +1 -0
- package/dist/{worktreeOperations-BqLLypS5.mjs → worktreeOperations-CP2lYxrI.mjs} +72 -64
- package/dist/worktreeOperations-CP2lYxrI.mjs.map +1 -0
- package/package.json +8 -8
- package/dist/worktreeOperations-BqLLypS5.mjs.map +0 -1
- package/dist/worktreeOperations-CU0iV2h-.cjs.map +0 -1
|
@@ -2,9 +2,9 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_worktreeOperations = require("../worktreeOperations-
|
|
6
|
-
let
|
|
7
|
-
|
|
5
|
+
const require_worktreeOperations = require("../worktreeOperations-C1ygq-Na.cjs");
|
|
6
|
+
let node_fs_promises = require("node:fs/promises");
|
|
7
|
+
node_fs_promises = require_worktreeOperations.__toESM(node_fs_promises, 1);
|
|
8
8
|
let node_path = require("node:path");
|
|
9
9
|
node_path = require_worktreeOperations.__toESM(node_path, 1);
|
|
10
10
|
let node_os = require("node:os");
|
|
@@ -653,11 +653,11 @@ const NAME_STATUS = {
|
|
|
653
653
|
T: "modified"
|
|
654
654
|
};
|
|
655
655
|
/** Line count of a small regular file, or undefined when it is binary, large, or not a regular file. */
|
|
656
|
-
function untrackedLines(root, relPath) {
|
|
656
|
+
async function untrackedLines(root, relPath) {
|
|
657
657
|
const absolute = node_path.default.join(root, relPath);
|
|
658
658
|
let stat;
|
|
659
659
|
try {
|
|
660
|
-
stat =
|
|
660
|
+
stat = await node_fs_promises.default.lstat(absolute);
|
|
661
661
|
} catch {
|
|
662
662
|
return;
|
|
663
663
|
}
|
|
@@ -666,7 +666,7 @@ function untrackedLines(root, relPath) {
|
|
|
666
666
|
binary: false
|
|
667
667
|
};
|
|
668
668
|
if (!stat.isFile() || stat.size > MAX_FILE_BYTES) return void 0;
|
|
669
|
-
const content =
|
|
669
|
+
const content = await node_fs_promises.default.readFile(absolute);
|
|
670
670
|
if (content.subarray(0, BINARY_PROBE_BYTES).includes(0)) return {
|
|
671
671
|
lines: 0,
|
|
672
672
|
binary: true
|
|
@@ -789,8 +789,8 @@ function createBranchDiff() {
|
|
|
789
789
|
"--exclude-standard",
|
|
790
790
|
"-z"
|
|
791
791
|
]));
|
|
792
|
-
untracked.
|
|
793
|
-
const counted = index < MAX_UNTRACKED_COUNTED ? untrackedLines(root, relPath) : void 0;
|
|
792
|
+
for (const [index, relPath] of untracked.entries()) {
|
|
793
|
+
const counted = index < MAX_UNTRACKED_COUNTED ? await untrackedLines(root, relPath) : void 0;
|
|
794
794
|
entries.push({
|
|
795
795
|
path: relPath,
|
|
796
796
|
status: "untracked",
|
|
@@ -798,18 +798,20 @@ function createBranchDiff() {
|
|
|
798
798
|
removed: 0,
|
|
799
799
|
...counted?.binary ? { binary: true } : {}
|
|
800
800
|
});
|
|
801
|
-
}
|
|
801
|
+
}
|
|
802
802
|
entries.sort((left, right) => left.path.localeCompare(right.path));
|
|
803
803
|
const conflicts = [...unmerged];
|
|
804
|
-
const
|
|
804
|
+
const rebaseMerge = await readLine$1(root, [
|
|
805
805
|
"rev-parse",
|
|
806
806
|
"--git-path",
|
|
807
807
|
"rebase-merge"
|
|
808
|
-
])
|
|
808
|
+
]);
|
|
809
|
+
const rebaseApply = await readLine$1(root, [
|
|
809
810
|
"rev-parse",
|
|
810
811
|
"--git-path",
|
|
811
812
|
"rebase-apply"
|
|
812
|
-
])
|
|
813
|
+
]);
|
|
814
|
+
const rebasing = (await Promise.all([rebaseMerge, rebaseApply].map(async (gitPath) => gitPath === void 0 ? false : node_fs_promises.default.access(node_path.default.resolve(root, gitPath)).then(() => true, () => false)))).some(Boolean);
|
|
813
815
|
const upstreamRef = branch === void 0 ? void 0 : await upstreamOf(root, branch);
|
|
814
816
|
let upstream;
|
|
815
817
|
if (upstreamRef !== void 0) {
|
|
@@ -854,7 +856,7 @@ function createBranchDiff() {
|
|
|
854
856
|
if (entry === void 0) throw new Error("That path is not in this review.");
|
|
855
857
|
if (entry.status === "untracked") {
|
|
856
858
|
const absolute = node_path.default.join(review.root, entry.path);
|
|
857
|
-
const stat =
|
|
859
|
+
const stat = await node_fs_promises.default.lstat(absolute);
|
|
858
860
|
if (stat.isSymbolicLink()) return {
|
|
859
861
|
path: entry.path,
|
|
860
862
|
hunks: [{
|
|
@@ -862,7 +864,7 @@ function createBranchDiff() {
|
|
|
862
864
|
rows: [{
|
|
863
865
|
marker: "+",
|
|
864
866
|
line: 1,
|
|
865
|
-
content:
|
|
867
|
+
content: await node_fs_promises.default.readlink(absolute)
|
|
866
868
|
}]
|
|
867
869
|
}]
|
|
868
870
|
};
|
|
@@ -871,7 +873,7 @@ function createBranchDiff() {
|
|
|
871
873
|
hunks: [],
|
|
872
874
|
tooLarge: true
|
|
873
875
|
};
|
|
874
|
-
const content =
|
|
876
|
+
const content = await node_fs_promises.default.readFile(absolute);
|
|
875
877
|
if (content.subarray(0, BINARY_PROBE_BYTES).includes(0)) return {
|
|
876
878
|
path: entry.path,
|
|
877
879
|
hunks: [],
|
|
@@ -988,9 +990,9 @@ function isRecord(value) {
|
|
|
988
990
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
989
991
|
}
|
|
990
992
|
/** The workspace key: the canonical root, so a symlinked path and its target share one entry. */
|
|
991
|
-
function workspaceKey(workspaceRoot) {
|
|
993
|
+
async function workspaceKey(workspaceRoot) {
|
|
992
994
|
try {
|
|
993
|
-
return
|
|
995
|
+
return await node_fs_promises.default.realpath(workspaceRoot);
|
|
994
996
|
} catch {
|
|
995
997
|
return node_path.default.resolve(workspaceRoot);
|
|
996
998
|
}
|
|
@@ -1039,7 +1041,7 @@ function publicView(config) {
|
|
|
1039
1041
|
* the saved one, and only for the same host: a token never follows a host it
|
|
1040
1042
|
* was not entered for.
|
|
1041
1043
|
*/
|
|
1042
|
-
function parseGitAuthSave(request, current, homeDir) {
|
|
1044
|
+
async function parseGitAuthSave(request, current, homeDir) {
|
|
1043
1045
|
if (!isRecord(request)) throw require_worktreeOperations.invalidRequest("The git auth request is not an object.", "Send method none, ssh or https.");
|
|
1044
1046
|
if (request.method === "none") return { method: "none" };
|
|
1045
1047
|
if (request.method === "ssh") {
|
|
@@ -1049,7 +1051,7 @@ function parseGitAuthSave(request, current, homeDir) {
|
|
|
1049
1051
|
if (!keyPath.startsWith("/") && !keyPath.startsWith("~/")) throw require_worktreeOperations.invalidRequest("The key path is not absolute.", "Give the key as an absolute path or one under ~/.");
|
|
1050
1052
|
let isFile = false;
|
|
1051
1053
|
try {
|
|
1052
|
-
isFile =
|
|
1054
|
+
isFile = (await node_fs_promises.default.stat(expandHome(keyPath, homeDir))).isFile();
|
|
1053
1055
|
} catch {
|
|
1054
1056
|
isFile = false;
|
|
1055
1057
|
}
|
|
@@ -1084,16 +1086,16 @@ function parseGitAuthSave(request, current, homeDir) {
|
|
|
1084
1086
|
throw require_worktreeOperations.invalidRequest("The git auth method is unknown.", "Send method none, ssh or https.");
|
|
1085
1087
|
}
|
|
1086
1088
|
/** Tightens a file or folder something left readable by group or others. */
|
|
1087
|
-
function tighten(target, mode) {
|
|
1089
|
+
async function tighten(target, mode) {
|
|
1088
1090
|
try {
|
|
1089
|
-
if ((
|
|
1091
|
+
if (((await node_fs_promises.default.stat(target)).mode & LOOSE_BITS) !== 0) await node_fs_promises.default.chmod(target, mode);
|
|
1090
1092
|
} catch {}
|
|
1091
1093
|
}
|
|
1092
1094
|
function createGitAuthStore(homeDir = node_os.default.homedir()) {
|
|
1093
1095
|
const file = require_worktreeOperations.credentialsFile(homeDir);
|
|
1094
|
-
const readFile = () => {
|
|
1095
|
-
tighten(file, OWNER_ONLY_FILE);
|
|
1096
|
-
const raw = require_worktreeOperations.readJson(file);
|
|
1096
|
+
const readFile = async () => {
|
|
1097
|
+
await tighten(file, OWNER_ONLY_FILE);
|
|
1098
|
+
const raw = await require_worktreeOperations.readJson(file);
|
|
1097
1099
|
const workspaces = {};
|
|
1098
1100
|
if (isRecord(raw) && raw.version === 1 && isRecord(raw.workspaces)) for (const [key, value] of Object.entries(raw.workspaces)) {
|
|
1099
1101
|
const config = parseConfig(value);
|
|
@@ -1104,28 +1106,28 @@ function createGitAuthStore(homeDir = node_os.default.homedir()) {
|
|
|
1104
1106
|
workspaces
|
|
1105
1107
|
};
|
|
1106
1108
|
};
|
|
1107
|
-
const read = (workspaceRoot) => readFile().workspaces[workspaceKey(workspaceRoot)] ?? { method: "none" };
|
|
1109
|
+
const read = async (workspaceRoot) => (await readFile()).workspaces[await workspaceKey(workspaceRoot)] ?? { method: "none" };
|
|
1108
1110
|
return {
|
|
1109
1111
|
read,
|
|
1110
|
-
view: (workspaceRoot) => publicView(read(workspaceRoot)),
|
|
1111
|
-
save(workspaceRoot, request) {
|
|
1112
|
-
const key = workspaceKey(workspaceRoot);
|
|
1113
|
-
const current = readFile();
|
|
1114
|
-
const next = parseGitAuthSave(request, current.workspaces[key] ?? { method: "none" }, homeDir);
|
|
1112
|
+
view: async (workspaceRoot) => publicView(await read(workspaceRoot)),
|
|
1113
|
+
async save(workspaceRoot, request) {
|
|
1114
|
+
const key = await workspaceKey(workspaceRoot);
|
|
1115
|
+
const current = await readFile();
|
|
1116
|
+
const next = await parseGitAuthSave(request, current.workspaces[key] ?? { method: "none" }, homeDir);
|
|
1115
1117
|
const root = require_worktreeOperations.poGitRoot(homeDir);
|
|
1116
|
-
|
|
1118
|
+
await node_fs_promises.default.mkdir(root, {
|
|
1117
1119
|
recursive: true,
|
|
1118
1120
|
mode: OWNER_ONLY_DIRECTORY
|
|
1119
1121
|
});
|
|
1120
|
-
|
|
1122
|
+
await node_fs_promises.default.chmod(root, OWNER_ONLY_DIRECTORY);
|
|
1121
1123
|
const workspaces = { ...current.workspaces };
|
|
1122
1124
|
if (next.method === "none") delete workspaces[key];
|
|
1123
1125
|
else workspaces[key] = next;
|
|
1124
|
-
require_worktreeOperations.writeJsonAtomic(file, {
|
|
1126
|
+
await require_worktreeOperations.writeJsonAtomic(file, {
|
|
1125
1127
|
version: 1,
|
|
1126
1128
|
workspaces
|
|
1127
1129
|
});
|
|
1128
|
-
|
|
1130
|
+
await node_fs_promises.default.chmod(file, OWNER_ONLY_FILE);
|
|
1129
1131
|
return publicView(next);
|
|
1130
1132
|
}
|
|
1131
1133
|
};
|
|
@@ -1371,9 +1373,9 @@ var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)({
|
|
|
1371
1373
|
if (request.method !== "GET" && request.method !== "PUT") return Response.json({ error: "Use GET or PUT." }, { status: 405 });
|
|
1372
1374
|
const root = rootOf(url);
|
|
1373
1375
|
if (root instanceof Response) return root;
|
|
1374
|
-
if (request.method === "GET") return Response.json(gitAuth.view(root));
|
|
1376
|
+
if (request.method === "GET") return Response.json(await gitAuth.view(root));
|
|
1375
1377
|
try {
|
|
1376
|
-
return Response.json(gitAuth.save(root, await request.json().catch(() => void 0)));
|
|
1378
|
+
return Response.json(await gitAuth.save(root, await request.json().catch(() => void 0)));
|
|
1377
1379
|
} catch (error) {
|
|
1378
1380
|
if (error instanceof require_worktreeOperations.PoGitExpectedError && error.code === "invalid_request") {
|
|
1379
1381
|
const text = error.message.replace(/^\[[a-z_]+\] /u, "").replace("\nRecovery: ", " ");
|
|
@@ -1397,7 +1399,7 @@ var route_server_default = (0, _agimon_ai_po_core_extensionFile.defineRoute)({
|
|
|
1397
1399
|
if (request.method !== "GET") return Response.json({ error: "Use GET." }, { status: 405 });
|
|
1398
1400
|
let recordedBaseRef;
|
|
1399
1401
|
try {
|
|
1400
|
-
recordedBaseRef = require_worktreeOperations.createWorktreeRegistry(require_worktreeOperations.registryFile(cwd, homeDir)).list().find((record) => record.sessionId === context.sessionId)?.baseRef;
|
|
1402
|
+
recordedBaseRef = (await require_worktreeOperations.createWorktreeRegistry(await require_worktreeOperations.registryFile(cwd, homeDir)).list()).find((record) => record.sessionId === context.sessionId)?.baseRef;
|
|
1401
1403
|
} catch {
|
|
1402
1404
|
recordedBaseRef = void 0;
|
|
1403
1405
|
}
|
|
@@ -1597,7 +1599,7 @@ async function rebasing(root) {
|
|
|
1597
1599
|
"--git-path",
|
|
1598
1600
|
name
|
|
1599
1601
|
]);
|
|
1600
|
-
if (gitPath !== void 0 &&
|
|
1602
|
+
if (gitPath !== void 0 && await node_fs_promises.default.access(node_path.default.resolve(root, gitPath)).then(() => true, () => false)) return true;
|
|
1601
1603
|
}
|
|
1602
1604
|
return false;
|
|
1603
1605
|
}
|
|
@@ -1830,9 +1832,9 @@ function createGitChangesChannel(options = {}) {
|
|
|
1830
1832
|
const rerun = /* @__PURE__ */ new Set();
|
|
1831
1833
|
const busy = /* @__PURE__ */ new Set();
|
|
1832
1834
|
/** The base the session's own worktree was created from, when it has one. */
|
|
1833
|
-
const recordedBaseRef = (scope) => {
|
|
1835
|
+
const recordedBaseRef = async (scope) => {
|
|
1834
1836
|
try {
|
|
1835
|
-
return require_worktreeOperations.createWorktreeRegistry(require_worktreeOperations.registryFile(scope.cwd, homeDir)).list().find((record) => record.sessionId === scope.sessionId)?.baseRef;
|
|
1837
|
+
return (await require_worktreeOperations.createWorktreeRegistry(await require_worktreeOperations.registryFile(scope.cwd, homeDir)).list()).find((record) => record.sessionId === scope.sessionId)?.baseRef;
|
|
1836
1838
|
} catch {
|
|
1837
1839
|
return;
|
|
1838
1840
|
}
|
|
@@ -1865,8 +1867,7 @@ function createGitChangesChannel(options = {}) {
|
|
|
1865
1867
|
return;
|
|
1866
1868
|
}
|
|
1867
1869
|
inFlight.add(sessionId);
|
|
1868
|
-
|
|
1869
|
-
diff.review(scope.cwd, base === void 0 ? {} : { recordedBaseRef: base }).then((review) => {
|
|
1870
|
+
recordedBaseRef(scope).then((base) => diff.review(scope.cwd, base === void 0 ? {} : { recordedBaseRef: base })).then((review) => {
|
|
1870
1871
|
if (scopes.has(sessionId)) update(sessionId, { changes: review?.changes });
|
|
1871
1872
|
}).catch((error) => {
|
|
1872
1873
|
host.onNotice(`git diff refresh failed for ${sessionId} (${error instanceof Error ? error.name : "unknown"})`);
|
|
@@ -1875,12 +1876,12 @@ function createGitChangesChannel(options = {}) {
|
|
|
1875
1876
|
if (rerun.delete(sessionId)) refresh(sessionId);
|
|
1876
1877
|
});
|
|
1877
1878
|
};
|
|
1878
|
-
const run = (scope, command) => {
|
|
1879
|
+
const run = async (scope, command) => {
|
|
1879
1880
|
const workspaceRoot = scope.sessionContext?.workspaceRoot ?? scope.cwd;
|
|
1880
|
-
const base = recordedBaseRef(scope);
|
|
1881
|
+
const base = await recordedBaseRef(scope);
|
|
1881
1882
|
const context = {
|
|
1882
1883
|
cwd: scope.cwd,
|
|
1883
|
-
auth: auth.read(workspaceRoot),
|
|
1884
|
+
auth: await auth.read(workspaceRoot),
|
|
1884
1885
|
...base === void 0 ? {} : { recordedBaseRef: base }
|
|
1885
1886
|
};
|
|
1886
1887
|
if (command.action === "pull") return sync.pull(context);
|
|
@@ -1978,9 +1979,9 @@ function payloadOf(state) {
|
|
|
1978
1979
|
};
|
|
1979
1980
|
}
|
|
1980
1981
|
/** Worktrees visible to this session, using the hub's live session table for ownership. */
|
|
1981
|
-
function viewsFor(scope, deps) {
|
|
1982
|
+
async function viewsFor(scope, deps) {
|
|
1982
1983
|
try {
|
|
1983
|
-
return require_worktreeOperations.createWorktreeRegistry(require_worktreeOperations.registryFile(scope.cwd, deps.homeDir)).list().flatMap((record) => {
|
|
1984
|
+
return (await require_worktreeOperations.createWorktreeRegistry(await require_worktreeOperations.registryFile(scope.cwd, deps.homeDir)).list()).flatMap((record) => {
|
|
1984
1985
|
if (record.parentSessionId === void 0 && record.sessionId !== scope.sessionId) return [];
|
|
1985
1986
|
const owned = record.parentSessionId === void 0 || record.parentSessionId === scope.sessionId;
|
|
1986
1987
|
const unowned = !owned && !deps.sessionService.isLive(record.parentSessionId);
|
|
@@ -2098,10 +2099,13 @@ function createWorktreesChannel(options = {}) {
|
|
|
2098
2099
|
return generation;
|
|
2099
2100
|
};
|
|
2100
2101
|
/** Republishes a session, skipping a frame that would say nothing new. */
|
|
2101
|
-
const publish = (scope, force) => {
|
|
2102
|
+
const publish = async (scope, force) => {
|
|
2103
|
+
const generation = generations.get(scope.sessionId);
|
|
2104
|
+
const worktreeViews = await viewsFor(scope, views);
|
|
2105
|
+
if (generation === void 0 || generations.get(scope.sessionId) !== generation) return;
|
|
2102
2106
|
const previous = latest.get(scope.sessionId);
|
|
2103
2107
|
const next = {
|
|
2104
|
-
worktrees:
|
|
2108
|
+
worktrees: worktreeViews,
|
|
2105
2109
|
pending: previous?.pending,
|
|
2106
2110
|
error: previous?.error,
|
|
2107
2111
|
errorTarget: previous?.errorTarget
|
|
@@ -2113,7 +2117,7 @@ function createWorktreesChannel(options = {}) {
|
|
|
2113
2117
|
const mark = (scope, pending, error, errorTarget) => {
|
|
2114
2118
|
const previous = latest.get(scope.sessionId);
|
|
2115
2119
|
latest.set(scope.sessionId, {
|
|
2116
|
-
worktrees: previous?.worktrees ??
|
|
2120
|
+
worktrees: previous?.worktrees ?? [],
|
|
2117
2121
|
pending,
|
|
2118
2122
|
error,
|
|
2119
2123
|
errorTarget
|
|
@@ -2153,15 +2157,15 @@ function createWorktreesChannel(options = {}) {
|
|
|
2153
2157
|
sessionAdded(scope) {
|
|
2154
2158
|
newGeneration(scope.sessionId);
|
|
2155
2159
|
publish(scope, false);
|
|
2156
|
-
const unsubscribe = host.directEvents.subscribe(require_worktreeOperations.GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, (payload) => {
|
|
2160
|
+
const unsubscribe = host.directEvents.subscribe(require_worktreeOperations.GIT_WORKTREE_LIFECYCLE_EVENT, scope.sessionId, async (payload) => {
|
|
2157
2161
|
if (!require_worktreeOperations.isWorktreeLifecycleEvent(payload)) return;
|
|
2158
2162
|
let sameRepository = false;
|
|
2159
2163
|
try {
|
|
2160
|
-
sameRepository = require_worktreeOperations.registryFile(scope.cwd, options.homeDir) === require_worktreeOperations.registryFile(payload.repositoryRoot, options.homeDir);
|
|
2164
|
+
sameRepository = await require_worktreeOperations.registryFile(scope.cwd, options.homeDir) === await require_worktreeOperations.registryFile(payload.repositoryRoot, options.homeDir);
|
|
2161
2165
|
} catch {
|
|
2162
2166
|
sameRepository = false;
|
|
2163
2167
|
}
|
|
2164
|
-
if (sameRepository) publish(scope, false);
|
|
2168
|
+
if (sameRepository) await publish(scope, false);
|
|
2165
2169
|
});
|
|
2166
2170
|
subscriptions.set(scope.sessionId, unsubscribe);
|
|
2167
2171
|
},
|