@mastra/factory 0.12.0 → 0.12.1-alpha.1

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.
Files changed (35) hide show
  1. package/dist/factory.d.ts.map +1 -1
  2. package/dist/factory.js +26 -1
  3. package/dist/factory.js.map +1 -1
  4. package/dist/integrations/github/provenance.d.ts +2 -0
  5. package/dist/integrations/github/provenance.d.ts.map +1 -1
  6. package/dist/integrations/github/provenance.js +3 -2
  7. package/dist/integrations/github/provenance.js.map +1 -1
  8. package/dist/integrations/github/routes.d.ts.map +1 -1
  9. package/dist/integrations/github/routes.js +12 -39
  10. package/dist/integrations/github/routes.js.map +1 -1
  11. package/dist/integrations/github/rules.d.ts.map +1 -1
  12. package/dist/integrations/github/rules.js +7 -2
  13. package/dist/integrations/github/rules.js.map +1 -1
  14. package/dist/integrations/github/webhook.d.ts.map +1 -1
  15. package/dist/integrations/github/webhook.js +34 -2
  16. package/dist/integrations/github/webhook.js.map +1 -1
  17. package/dist/routes/projects.d.ts +9 -1
  18. package/dist/routes/projects.d.ts.map +1 -1
  19. package/dist/routes/projects.js +26 -5
  20. package/dist/routes/projects.js.map +1 -1
  21. package/dist/routes/surface.js +1 -1
  22. package/dist/rules/defaults.d.ts.map +1 -1
  23. package/dist/rules/defaults.js +17 -7
  24. package/dist/rules/defaults.js.map +1 -1
  25. package/dist/rules/dispatcher.d.ts +1 -0
  26. package/dist/rules/dispatcher.d.ts.map +1 -1
  27. package/dist/rules/dispatcher.js +32 -2
  28. package/dist/rules/dispatcher.js.map +1 -1
  29. package/dist/rules/types.d.ts +2 -0
  30. package/dist/rules/types.d.ts.map +1 -1
  31. package/dist/rules/types.js.map +1 -1
  32. package/dist/sandbox/session-retirement.js +1 -1
  33. package/dist/workspace.js +1 -1
  34. package/factory-skills/factory-triage/SKILL.md +1 -1
  35. package/package.json +7 -7
@@ -1,5 +1,6 @@
1
1
  import { clearGithubPat, getGithubPatStatus, setGithubPat } from "./pat.js";
2
2
  import { listPullRequestSubscriptionsForThread, subscribeToPullRequest } from "./subscriptions.js";
3
+ import { MaterializeError, SetupCommandError, commitAll, isValidGitRef, pushBranch } from "./sandbox.js";
3
4
  import { requireExec } from "../../sandbox/materialization.js";
4
5
  import { sanitizeSegment } from "../../sandbox/workdir.js";
5
6
  import { peekSessionSandbox } from "../../sandbox/session-sandbox.js";
@@ -7,7 +8,6 @@ import { normalizeSessionTitle } from "../../session/session-title.js";
7
8
  import { listRepositoryCommits } from "./commits.js";
8
9
  import { getGithubFeatureDiagnostics, isGithubFeatureEnabled } from "./config.js";
9
10
  import { reclaimDeletedSessionSandbox } from "./sandbox-release.js";
10
- import { MaterializeError, SetupCommandError, commitAll, isValidGitRef as isValidGitRef$1, pushBranch } from "./sandbox.js";
11
11
  import { handleGithubWebhook } from "./webhook.js";
12
12
  import { registerApiRoute } from "@mastra/core/server";
13
13
  import { randomUUID } from "crypto";
@@ -60,15 +60,6 @@ function pullRequestNumberFromUrl(value, expectedRepo) {
60
60
  return;
61
61
  }
62
62
  }
63
- /**
64
- * Validate a git branch/ref name against a strict whitelist. The value is later
65
- * interpolated into a shell `git clone --branch` command, so it must never
66
- * contain shell metacharacters. We accept only git-ref-safe characters and
67
- * reject anything else rather than relying on shell quoting alone.
68
- */
69
- function isValidGitRef(value) {
70
- return typeof value === "string" && value.length > 0 && value.length <= 255 && /^[A-Za-z0-9_./-]+$/.test(value);
71
- }
72
63
  function isJsonObject(value) {
73
64
  return typeof value === "object" && value !== null && !Array.isArray(value);
74
65
  }
@@ -404,29 +395,11 @@ function buildGithubRoutes(options) {
404
395
  repo
405
396
  });
406
397
  }
407
- const repos = new Array(matches.length);
408
- const upsertConcurrency = 10;
409
- for (let start = 0; start < matches.length; start += upsertConcurrency) await Promise.all(matches.slice(start, start + upsertConcurrency).map(async ({ inst, repo }, offset) => {
410
- const repository = await github.sourceControlStorage.repositories.upsert({
411
- orgId,
412
- input: {
413
- installationId: inst.id,
414
- externalId: repo.id.toString(),
415
- slug: repo.fullName,
416
- defaultBranch: isValidGitRef(repo.defaultBranch) ? repo.defaultBranch : "main",
417
- providerMetadata: {
418
- private: repo.private,
419
- owner: repo.owner
420
- }
421
- }
422
- });
423
- repos[start + offset] = {
424
- ...repo,
425
- installationStorageId: inst.id,
426
- repositoryStorageId: repository.id,
427
- sandboxProvider: sandbox ? "custom" : "none",
428
- sandboxWorkdir: `~/${sanitizeSegment(repo.fullName.split("/", 2)[1] || "repo")}`
429
- };
398
+ const repos = matches.map(({ inst, repo }) => ({
399
+ ...repo,
400
+ installationStorageId: inst.id,
401
+ sandboxProvider: sandbox ? "custom" : "none",
402
+ sandboxWorkdir: `~/${sanitizeSegment(repo.fullName.split("/", 2)[1] || "repo")}`
430
403
  }));
431
404
  return c.json({ repos });
432
405
  }
@@ -944,7 +917,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
944
917
  const requestedBaseBranch = body.baseBranch;
945
918
  if (requestedBaseBranch !== void 0 && typeof requestedBaseBranch !== "string") return c.json({ error: "Invalid baseBranch" }, 400);
946
919
  const baseBranch = requestedBaseBranch ?? project.defaultBranch;
947
- if (!isValidGitRef$1(baseBranch)) return c.json({ error: "Invalid baseBranch" }, 400);
920
+ if (!isValidGitRef(baseBranch)) return c.json({ error: "Invalid baseBranch" }, 400);
948
921
  const requestedSessionId = body.sessionId;
949
922
  if (requestedSessionId !== void 0 && (typeof requestedSessionId !== "string" || !UUID_PATTERN.test(requestedSessionId))) return c.json({ error: "Invalid sessionId" }, 400);
950
923
  const sessionId = requestedSessionId ?? randomUUID();
@@ -954,7 +927,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
954
927
  const requestedBranch = body.branch;
955
928
  let branch;
956
929
  if (requestedBranch === void 0) branch = `${USER_SESSION_BRANCH_PREFIX}${sessionId}`;
957
- else if (typeof requestedBranch === "string" && isValidGitRef$1(requestedBranch)) branch = requestedBranch;
930
+ else if (typeof requestedBranch === "string" && isValidGitRef(requestedBranch)) branch = requestedBranch;
958
931
  else return c.json({ error: "Invalid branch" }, 400);
959
932
  if (requestedSessionId !== void 0) {
960
933
  const existing = await github.sourceControlStorage.sessions.getBySessionId(sessionId);
@@ -1133,7 +1106,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1133
1106
  if ("response" in loaded) return loaded.response;
1134
1107
  const { orgId, project } = loaded;
1135
1108
  const branch = c.req.query("branch") ?? project.defaultBranch;
1136
- if (!isValidGitRef$1(branch)) return c.json({ error: "Invalid branch" }, 400);
1109
+ if (!isValidGitRef(branch)) return c.json({ error: "Invalid branch" }, 400);
1137
1110
  const limit = Math.min(Math.max(Math.floor(Number(c.req.query("limit") ?? DEFAULT_COMMIT_PAGE)) || DEFAULT_COMMIT_PAGE, 1), MAX_COMMIT_PAGE);
1138
1111
  try {
1139
1112
  const commits = await listRepositoryCommits(github, {
@@ -1169,7 +1142,7 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1169
1142
  } catch {
1170
1143
  return c.json({ error: "Invalid JSON body" }, 400);
1171
1144
  }
1172
- if (!isValidGitRef$1(body.branch)) return c.json({ error: "Invalid branch" }, 400);
1145
+ if (!isValidGitRef(body.branch)) return c.json({ error: "Invalid branch" }, 400);
1173
1146
  const branch = body.branch;
1174
1147
  const sessionWorkspace = await resolveSessionWorkspace(github, project.id, userId, body.sessionId);
1175
1148
  if (!sessionWorkspace) return c.json({ error: "Invalid sessionId" }, 400);
@@ -1226,9 +1199,9 @@ function buildProjectGitRoutes({ github, auth, sandbox, users, controller, memor
1226
1199
  } catch {
1227
1200
  return c.json({ error: "Invalid JSON body" }, 400);
1228
1201
  }
1229
- if (!isValidGitRef$1(body.branch)) return c.json({ error: "Invalid branch" }, 400);
1202
+ if (!isValidGitRef(body.branch)) return c.json({ error: "Invalid branch" }, 400);
1230
1203
  const base = body.base === void 0 ? project.defaultBranch : body.base;
1231
- if (!isValidGitRef$1(base)) return c.json({ error: "Invalid base" }, 400);
1204
+ if (!isValidGitRef(base)) return c.json({ error: "Invalid base" }, 400);
1232
1205
  if (typeof body.title !== "string" || body.title.trim().length === 0 || body.title.length > 256) return c.json({ error: "Invalid title" }, 400);
1233
1206
  if (body.body !== void 0 && (typeof body.body !== "string" || body.body.length > 65536)) return c.json({ error: "Invalid body" }, 400);
1234
1207
  const head = body.branch;