openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
119 lines (118 loc) • 4.46 kB
JavaScript
import { t as quoteCliArg } from "./quote-cli-arg-J7A9UE6m.mjs";
import { a as executeGitCommand } from "./git-exec-DHBL622T.mjs";
import { n as gitEnvironment } from "./git-BBx5S0aA.mjs";
import { t as note } from "./note-CnLgHvug.mjs";
import { t as listProjectRegistry } from "./project-registry-CaveJtQj.mjs";
//#region src/commands/doctor-project-clone-shape.ts
const CHECK_ID = "core/doctor/project-clone-shape";
function describeCloneConfigKey(e) {
if (!e.startsWith("remote.")) return {
name: e,
urlKey: false
};
const t = e.lastIndexOf(".");
const n = e.slice(7, t);
if (!/(:\/\/|::|@)/.test(n)) return {
name: e,
urlKey: false
};
const r = /^(?:[^:/?#@]+::)+/.exec(n)?.[0] ?? "";
let i = n.slice(r.length);
const a = i.lastIndexOf("@");
if (a >= 0) {
const e = i.indexOf("://");
const t = e >= 0 && e < a ? e + 3 : i.startsWith("//") ? 2 : 0;
i = `${i.slice(0, t)}***@${i.slice(a + 1)}`;
}
i = i.split(/[?#]/, 1)[0] ?? "";
return {
name: `remote.${r}${i}${e.slice(t)}`,
urlKey: true
};
}
async function readCloneGit(e, t, n = false) {
const r = await executeGitCommand(e, t, {
env: gitEnvironment({
...process.env,
GIT_NO_LAZY_FETCH: "1"
}),
timeoutMs: 5e3,
maxOutputBytes: 65536
});
if (r.termination !== "exit" || r.stdoutTruncatedBytes || r.code !== 0 && !(n && r.code === 1)) throw new Error("clone inspection unavailable");
return r.stdout;
}
async function collectProjectCloneShapeHealthFindings(e) {
const t = [];
const warn = (e) => t.push({
checkId: CHECK_ID,
severity: "warning",
category: "fix-now",
docsUrl: "https://docs.openclaw.ai/cli/doctor/checks",
...e
});
let n;
try {
n = (await listProjectRegistry(e)).filter((e) => e.source === "cloned");
} catch {
warn({
message: "Skipped project clone inspection: the project registry is unreadable.",
fixHint: "Restore access to the project registry and rerun openclaw doctor."
});
return t;
}
for (const e of n) try {
const t = await readCloneGit(e.repoRoot, [
"config",
"--null",
"--name-only",
"--get-regexp",
"^remote\\..*\\.(promisor|partialclonefilter)$"
], true);
const n = (await readCloneGit(e.repoRoot, ["rev-parse", "--is-shallow-repository"])).trim();
const r = await readCloneGit(e.repoRoot, [
"config",
"--get",
"extensions.partialclone"
], true);
const i = [...new Set(t.split("\0").filter(Boolean))].toSorted().map(describeCloneConfigKey);
if (r) i.push(describeCloneConfigKey("extensions.partialclone"));
if (n !== "true" && i.length === 0) continue;
const unset = (e) => e.urlKey ? [
`# Before continuing, locate ${e.name} locally; the raw output may contain credentials:`,
"# git config --get-regexp '^remote\\..*\\.(promisor|partialclonefilter)$'",
"# Then run: git config --unset-all <the key shown by that command>"
] : [`git config --unset-all ${quoteCliArg(e.name)}`];
warn({
path: e.repoRoot,
category: "recommended",
message: `Project clone ${e.displayName} (${e.id}): shallow=${n}; partial-clone keys: ${i.map((e) => e.name).join(", ") || "none"}. Full clones are recommended for managed worktrees.`,
fixHint: [
"Manual repair only (POSIX shell); stop on any failed step:",
`cd ${quoteCliArg(e.repoRoot)}`,
...i.filter((e) => e.name.endsWith(".partialclonefilter")).flatMap(unset),
`git fetch --no-auto-maintenance --refetch${n === "true" ? " --unshallow" : ""} origin`,
"git rev-list --objects --missing=print --all | grep '^?' | cut -c2- | git fetch --no-auto-maintenance origin --no-tags --no-write-fetch-head --recurse-submodules=no --stdin",
...i.filter((e) => e.name.endsWith(".promisor") || e.name === "extensions.partialclone").flatMap(unset),
"git repack -a -d",
"Rerun openclaw doctor. If history or objects remain missing, recover them from the original repository."
].join("\n")
});
} catch {
warn({
path: e.repoRoot,
message: `Skipped project clone ${e.displayName} (${e.id}): repository is missing, unreadable, or Git inspection did not complete.`,
fixHint: "Check the clone path, permissions, and Git installation, then rerun openclaw doctor."
});
}
return t;
}
async function noteProjectCloneShape(e) {
for (const t of await collectProjectCloneShapeHealthFindings(e)) note([
t.message,
t.path,
t.fixHint
].filter(Boolean).join("\n"), "Project clones");
}
//#endregion
export { collectProjectCloneShapeHealthFindings, noteProjectCloneShape };