@mastra/platform-workspace 1.5.0 → 1.5.1-alpha.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/dist/index.js CHANGED
@@ -1991,6 +1991,14 @@ const BUILD_TOKEN_ENV = "MASTRA_REPOSITORY_ACCESS_TOKEN";
1991
1991
  const CLONE_URL_ALLOWED_CHARS = /^[a-z0-9:/._-]+$/i;
1992
1992
  const CLONE_URL_HOST_PATTERN = /^[a-z0-9.-]+$/i;
1993
1993
  const CLONE_URL_SEGMENT_PATTERN = /^[\w.-]+$/;
1994
+ /** Last default-branch head resolved per clone URL, shared across resolvers in this process. */
1995
+ const lastKnownHeads = /* @__PURE__ */ new Map();
1996
+ const MAX_LAST_KNOWN_HEADS = 1e3;
1997
+ function rememberHead(cloneUrl, sha) {
1998
+ lastKnownHeads.delete(cloneUrl);
1999
+ lastKnownHeads.set(cloneUrl, sha);
2000
+ if (lastKnownHeads.size > MAX_LAST_KNOWN_HEADS) lastKnownHeads.delete(lastKnownHeads.keys().next().value);
2001
+ }
1994
2002
  /**
1995
2003
  * Create a lazy repository template definition for PlatformSandbox, mirroring
1996
2004
  * `@mastra/e2b`'s `createRepoTemplate`: pass the sandbox context through and a
@@ -2001,8 +2009,10 @@ const CLONE_URL_SEGMENT_PATTERN = /^[\w.-]+$/;
2001
2009
  * what gets cloned and what the template is identified by can't drift — and
2002
2010
  * pins repositories to their current default-branch commit. Private repository
2003
2011
  * credentials are used for head resolution and sent to the provider as
2004
- * transient build envs; they never enter the serialized definition. If the
2005
- * repository or its head cannot be resolved, the resolver keeps `cpuCount` and
2012
+ * transient build envs; they never enter the serialized definition. A failed
2013
+ * head lookup reuses the last head resolved for the same clone URL in this
2014
+ * process. If the repository cannot be resolved, or no head has been resolved
2015
+ * yet, the resolver keeps `cpuCount` and
2006
2016
  * `memoryMB` in a resources-only template so the sandbox still boots at the
2007
2017
  * requested size, and the caller's runtime setup materializes the checkout.
2008
2018
  */
@@ -2033,16 +2043,30 @@ function createRepoTemplate(options) {
2033
2043
  }
2034
2044
  const token = access.authorization?.token;
2035
2045
  let headError;
2036
- const sha = await (token ? resolveHead(cloneUrl, token) : resolveHead(cloneUrl)).catch((error) => {
2046
+ const resolved = await (token ? resolveHead(cloneUrl, token) : resolveHead(cloneUrl)).catch((error) => {
2037
2047
  headError = error;
2038
2048
  });
2039
- if (!sha || !SHA_PATTERN.test(sha)) {
2040
- console.warn("[platform-workspace] repo template skipped: could not resolve default-branch head", {
2049
+ let sha;
2050
+ if (resolved && SHA_PATTERN.test(resolved)) {
2051
+ sha = resolved;
2052
+ rememberHead(cloneUrl, sha);
2053
+ } else {
2054
+ const lastKnown = lastKnownHeads.get(cloneUrl);
2055
+ if (!lastKnown) {
2056
+ console.warn("[platform-workspace] repo template skipped: could not resolve default-branch head", {
2057
+ cloneUrl,
2058
+ sha: resolved,
2059
+ error: redactSecrets(headError)
2060
+ });
2061
+ return resourcesOnly();
2062
+ }
2063
+ console.warn("[platform-workspace] repo template pinned to the last known default-branch head", {
2041
2064
  cloneUrl,
2042
- sha,
2065
+ sha: lastKnown,
2066
+ resolved,
2043
2067
  error: redactSecrets(headError)
2044
2068
  });
2045
- return resourcesOnly();
2069
+ sha = lastKnown;
2046
2070
  }
2047
2071
  const workingDirectory = options.workingDirectory === void 0 ? void 0 : trimTrailingSlashes(assertWorkingDirectory(options.workingDirectory));
2048
2072
  const repoDir = repoDirName(cloneUrl);