@mastra/platform-workspace 1.5.0-alpha.1 → 1.5.0-alpha.2
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/index.cjs +78 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +78 -25
- package/dist/index.js.map +1 -1
- package/dist/repo-template.d.ts +25 -5
- package/dist/repo-template.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -1989,38 +1989,71 @@ const CLONE_URL_SEGMENT_PATTERN = /^[\w.-]+$/;
|
|
|
1989
1989
|
* pins repositories to their current default-branch commit. Private repository
|
|
1990
1990
|
* credentials are used for head resolution and sent to the provider as
|
|
1991
1991
|
* transient build envs; they never enter the serialized definition. If the
|
|
1992
|
-
* head cannot be resolved, the resolver
|
|
1993
|
-
*
|
|
1994
|
-
* the checkout
|
|
1992
|
+
* repository or its head cannot be resolved, the resolver keeps `cpuCount` and
|
|
1993
|
+
* `memoryMB` in a resources-only template so the sandbox still boots at the
|
|
1994
|
+
* requested size, and the caller's runtime setup materializes the checkout.
|
|
1995
1995
|
*/
|
|
1996
1996
|
function createRepoTemplate(options) {
|
|
1997
1997
|
const getRepositoryAccess = options.getRepositoryAccess;
|
|
1998
|
-
|
|
1998
|
+
const resourcesOnly = () => {
|
|
1999
|
+
if (options.cpuCount === void 0 && options.memoryMB === void 0) return void 0;
|
|
2000
|
+
return withResources(Template(), options);
|
|
2001
|
+
};
|
|
2002
|
+
if (!getRepositoryAccess) {
|
|
2003
|
+
const template = resourcesOnly();
|
|
2004
|
+
return template ? async () => template : void 0;
|
|
2005
|
+
}
|
|
1999
2006
|
const resolveHead = options.resolveHead ?? resolveDefaultBranchHead;
|
|
2000
2007
|
return async () => {
|
|
2001
|
-
|
|
2002
|
-
|
|
2008
|
+
let accessError;
|
|
2009
|
+
const access = await getRepositoryAccess().catch((error) => {
|
|
2010
|
+
accessError = error;
|
|
2011
|
+
});
|
|
2012
|
+
if (!access?.cloneUrl) {
|
|
2013
|
+
console.warn("[platform-workspace] repo template skipped: repository access unavailable", { error: redactSecrets(accessError) });
|
|
2014
|
+
return resourcesOnly();
|
|
2015
|
+
}
|
|
2003
2016
|
const cloneUrl = normalizeCloneUrl(access.cloneUrl);
|
|
2004
|
-
if (!isValidCloneUrl(cloneUrl))
|
|
2017
|
+
if (!isValidCloneUrl(cloneUrl)) {
|
|
2018
|
+
console.warn("[platform-workspace] repo template skipped: clone URL failed validation", { cloneUrl: redactSecrets(cloneUrl) });
|
|
2019
|
+
return resourcesOnly();
|
|
2020
|
+
}
|
|
2005
2021
|
const token = access.authorization?.token;
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2022
|
+
let headError;
|
|
2023
|
+
const sha = await (token ? resolveHead(cloneUrl, token) : resolveHead(cloneUrl)).catch((error) => {
|
|
2024
|
+
headError = error;
|
|
2025
|
+
});
|
|
2026
|
+
if (!sha || !SHA_PATTERN.test(sha)) {
|
|
2027
|
+
console.warn("[platform-workspace] repo template skipped: could not resolve default-branch head", {
|
|
2028
|
+
cloneUrl,
|
|
2029
|
+
sha,
|
|
2030
|
+
error: redactSecrets(headError)
|
|
2031
|
+
});
|
|
2032
|
+
return resourcesOnly();
|
|
2033
|
+
}
|
|
2034
|
+
const workingDirectory = options.workingDirectory === void 0 ? void 0 : trimTrailingSlashes(assertWorkingDirectory(options.workingDirectory));
|
|
2035
|
+
const repoDir = repoDirName(cloneUrl);
|
|
2009
2036
|
const auth = token ? `${gitAuthFlag()} ` : "";
|
|
2010
|
-
const
|
|
2011
|
-
|
|
2012
|
-
`git -C "${workdir}" ${auth}fetch origin ${sha}`,
|
|
2013
|
-
`git -C "${workdir}" checkout ${sha}`,
|
|
2014
|
-
...options.setupCommand ? [`cd "${workdir}" && ${options.setupCommand}`] : []
|
|
2015
|
-
];
|
|
2016
|
-
const family = `repo:${cloneUrl}:${workdir}`;
|
|
2037
|
+
const setupCommands = (options.setupCommand === void 0 ? [] : Array.isArray(options.setupCommand) ? options.setupCommand : [options.setupCommand]).filter((command) => command.trim() !== "");
|
|
2038
|
+
const family = `repo:${cloneUrl}:${workingDirectory ?? ""}/${repoDir}`;
|
|
2017
2039
|
let template = Template();
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2040
|
+
const buildEnv = {
|
|
2041
|
+
...options.buildEnv,
|
|
2042
|
+
...token ? { [BUILD_TOKEN_ENV]: token } : {}
|
|
2043
|
+
};
|
|
2044
|
+
if (Object.keys(buildEnv).length > 0) template = template.setEnvs(buildEnv, { ephemeral: true });
|
|
2045
|
+
template = withResources(template, options);
|
|
2046
|
+
if (workingDirectory) template = template.runCmd(`mkdir -p "${workingDirectory}"`).setWorkdir(workingDirectory);
|
|
2047
|
+
template = template.runCmd(`git ${auth}clone ${cloneUrl} "${repoDir}"`).runCmd(`git -C "${repoDir}" ${auth}fetch origin ${sha}`).runCmd(`git -C "${repoDir}" checkout ${sha}`);
|
|
2048
|
+
for (const command of setupCommands) template = template.runCmd(`cd "${repoDir}" && ${command}`);
|
|
2049
|
+
return template.withFamily(family);
|
|
2022
2050
|
};
|
|
2023
2051
|
}
|
|
2052
|
+
function withResources(template, options) {
|
|
2053
|
+
if (options.cpuCount !== void 0) template = template.cpuCount(options.cpuCount);
|
|
2054
|
+
if (options.memoryMB !== void 0) template = template.memoryMB(options.memoryMB);
|
|
2055
|
+
return template;
|
|
2056
|
+
}
|
|
2024
2057
|
function isValidCloneUrl(cloneUrl) {
|
|
2025
2058
|
if (cloneUrl.length > 2048 || !CLONE_URL_ALLOWED_CHARS.test(cloneUrl)) return false;
|
|
2026
2059
|
let url;
|
|
@@ -2046,8 +2079,26 @@ function normalizeCloneUrl(cloneUrl) {
|
|
|
2046
2079
|
return `${scheme.toLowerCase()}${host.toLowerCase()}`;
|
|
2047
2080
|
});
|
|
2048
2081
|
}
|
|
2049
|
-
function
|
|
2050
|
-
return
|
|
2082
|
+
function repoDirName(cloneUrl) {
|
|
2083
|
+
return (normalizeCloneUrl(cloneUrl).split("/").at(-1) ?? "").replace(/[^\w.-]/g, "-").replace(/^\.+/, "") || "repo";
|
|
2084
|
+
}
|
|
2085
|
+
function trimTrailingSlashes(path) {
|
|
2086
|
+
let end = path.length;
|
|
2087
|
+
while (end > 1 && path[end - 1] === "/") end--;
|
|
2088
|
+
return path.slice(0, end);
|
|
2089
|
+
}
|
|
2090
|
+
/** Validate a literal absolute path before embedding it in shell build steps. */
|
|
2091
|
+
function assertWorkingDirectory(dir) {
|
|
2092
|
+
if (!(/^\/[A-Za-z0-9._/-]*$/.test(dir) && !dir.split("/").includes(".."))) throw new Error(`Repo template workingDirectory must be an absolute path of plain path characters (got ${JSON.stringify(dir)}); ~ and $HOME are not expanded.`);
|
|
2093
|
+
return dir;
|
|
2094
|
+
}
|
|
2095
|
+
/**
|
|
2096
|
+
* Render a caught value for a warning without leaking credentials: URL
|
|
2097
|
+
* userinfo, HTTP authorization values, and GitHub token shapes are masked.
|
|
2098
|
+
*/
|
|
2099
|
+
function redactSecrets(value) {
|
|
2100
|
+
if (value === void 0 || value === null) return void 0;
|
|
2101
|
+
return (value instanceof Error ? value.message : typeof value === "string" ? value : String(value)).replace(/\/\/[^/@\s]+@/g, "//***@").replace(/\b(bearer|basic)\s+[^\s"']+/gi, "$1 ***").replace(/\b(gh[pousr]_|github_pat_)[A-Za-z0-9_]+/g, "$1***");
|
|
2051
2102
|
}
|
|
2052
2103
|
function gitAuthFlag() {
|
|
2053
2104
|
return `-c http.extraheader="AUTHORIZATION: basic $(printf 'x-access-token:%s' "$${BUILD_TOKEN_ENV}" | base64 -w0)"`;
|
|
@@ -2075,8 +2126,10 @@ async function resolveDefaultBranchHead(cloneUrl, token, execute = execFileAsync
|
|
|
2075
2126
|
});
|
|
2076
2127
|
const sha = stdout.trim().split(/\s+/, 1)[0];
|
|
2077
2128
|
return sha && SHA_PATTERN.test(sha) ? sha : void 0;
|
|
2078
|
-
} catch {
|
|
2079
|
-
|
|
2129
|
+
} catch (error) {
|
|
2130
|
+
const stderr = error.stderr;
|
|
2131
|
+
const detail = typeof stderr === "string" && stderr.trim() ? stderr.trim() : String(error);
|
|
2132
|
+
throw new Error(`git ls-remote failed: ${detail}`);
|
|
2080
2133
|
}
|
|
2081
2134
|
}
|
|
2082
2135
|
//#endregion
|