@mastra/factory 0.31.0-alpha.1 → 0.31.0-alpha.3

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 (29) hide show
  1. package/dist/integrations/github/review-status-comment.d.ts +4 -0
  2. package/dist/integrations/github/review-status-comment.d.ts.map +1 -1
  3. package/dist/integrations/github/review-status-comment.js +24 -8
  4. package/dist/integrations/github/review-status-comment.js.map +1 -1
  5. package/dist/integrations/github/review-status-reporter.d.ts.map +1 -1
  6. package/dist/integrations/github/review-status-reporter.js +8 -1
  7. package/dist/integrations/github/review-status-reporter.js.map +1 -1
  8. package/dist/integrations/github/review-status.d.ts.map +1 -1
  9. package/dist/integrations/github/review-status.js +2 -1
  10. package/dist/integrations/github/review-status.js.map +1 -1
  11. package/dist/integrations/github/session-subscriptions.d.ts +6 -0
  12. package/dist/integrations/github/session-subscriptions.d.ts.map +1 -1
  13. package/dist/integrations/github/session-subscriptions.js +22 -3
  14. package/dist/integrations/github/session-subscriptions.js.map +1 -1
  15. package/dist/rules/dispatch-errors.d.ts +5 -1
  16. package/dist/rules/dispatch-errors.d.ts.map +1 -1
  17. package/dist/rules/dispatch-errors.js +3 -1
  18. package/dist/rules/dispatch-errors.js.map +1 -1
  19. package/dist/rules/dispatcher.d.ts +5 -0
  20. package/dist/rules/dispatcher.d.ts.map +1 -1
  21. package/dist/rules/dispatcher.js +12 -3
  22. package/dist/rules/dispatcher.js.map +1 -1
  23. package/dist/session/work-item-state-processor.d.ts.map +1 -1
  24. package/dist/session/work-item-state-processor.js +7 -1
  25. package/dist/session/work-item-state-processor.js.map +1 -1
  26. package/factory-skills/factory-build/SKILL.md +1 -1
  27. package/factory-skills/factory-self-review/SKILL.md +1 -1
  28. package/factory-skills/factory-triage/SKILL.md +5 -3
  29. package/package.json +7 -7
@@ -1 +1 @@
1
- {"version":3,"file":"dispatch-errors.js","names":[],"sources":["../../src/rules/dispatch-errors.ts"],"sourcesContent":["import type {\n FactoryDispatchFailureCode,\n StoredFactoryDispatchFailureCode,\n} from '../storage/domains/work-items/base.js';\nimport type { FactoryRuleRejectionCode } from './types.js';\n\ninterface FactoryDispatchFailureMetadata {\n /** A person may retry the failed decision. */\n canRetry: boolean;\n /** `false` when only a person's retry can succeed: the dispatcher does not try again on its own. */\n autoRetry?: false;\n label: string;\n}\n\nconst FAILURE_METADATA = {\n session_unavailable: { canRetry: true, label: 'Factory session unavailable' },\n source_control_missing: { canRetry: true, label: 'Source-control connection unavailable' },\n source_repository_missing: { canRetry: true, label: 'Source repository unavailable' },\n source_repository_ambiguous: { canRetry: true, label: 'Work item repository unresolved' },\n unsupported_provider_item: { canRetry: false, label: 'Unsupported provider work item' },\n notification_delivery_failed: { canRetry: true, label: 'Factory message delivery failed' },\n run_terminal_event_missing: { canRetry: false, label: 'Agent run terminal event was not observed' },\n run_incomplete: { canRetry: true, label: 'Agent run ended before completing the working phase' },\n skill_delivery_ambiguous: { canRetry: false, label: 'Factory skill delivery could not be confirmed' },\n run_overdue: { canRetry: false, label: 'Agent run is overdue' },\n repository_git_missing: { canRetry: false, label: 'Git is unavailable in the workspace' },\n repository_sandbox_unresponsive: { canRetry: true, label: 'Workspace sandbox stopped responding' },\n repository_egress_blocked: { canRetry: false, label: 'Repository network access is blocked' },\n repository_clone_failed: { canRetry: true, label: 'Repository clone failed' },\n repository_pull_failed: { canRetry: true, label: 'Repository update failed' },\n repository_push_failed: { canRetry: true, label: 'Repository push failed' },\n repository_commit_failed: { canRetry: true, label: 'Repository commit failed' },\n repository_cli_missing: { canRetry: false, label: 'GitHub CLI is unavailable in the workspace' },\n repository_pr_failed: { canRetry: true, label: 'Pull request creation failed' },\n run_configuration_invalid: { canRetry: false, label: 'Run configuration rejected by provider' },\n run_credentials_unavailable: { canRetry: true, label: 'Model credentials unavailable for the run' },\n // The run's request carries no user, so every retry fails the same way; a person has to start it.\n run_user_unauthenticated: { canRetry: false, label: 'Run started without an authenticated user' },\n // Automatic work runs as the Factory, on the organization's keys only. Trying again cannot add one,\n // so the dispatcher stops at once; a person retries after adding the key.\n factory_org_key_missing: {\n canRetry: true,\n autoRetry: false,\n label: 'Add an organization model key to run this automatically',\n },\n run_failed: { canRetry: true, label: 'Agent run ended in error' },\n unknown: { canRetry: true, label: 'Factory automation failed' },\n // Retired: no path writes these any more, stored rows still read through here.\n plan_awaiting_approval: { canRetry: false, label: 'Plan waiting for review' },\n run_awaiting_input: { canRetry: false, label: 'Agent is waiting for an answer' },\n} satisfies Record<StoredFactoryDispatchFailureCode, FactoryDispatchFailureMetadata>;\n\nexport class FactoryDispatchError extends Error {\n constructor(\n readonly code: FactoryDispatchFailureCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = 'FactoryDispatchError';\n }\n}\n\n/** A transition the board's rules rejected while a decision was being applied. */\nexport class FactoryRuleRejectedError extends Error {\n constructor(\n readonly code: FactoryRuleRejectionCode,\n reason: string,\n ) {\n super(`${code}: ${reason}`);\n this.name = 'FactoryRuleRejectedError';\n }\n}\n\nexport function factoryDispatchFailureCode(error: unknown): FactoryDispatchFailureCode {\n return error instanceof FactoryDispatchError ? error.code : 'unknown';\n}\n\nexport function factoryDispatchFailureMetadata(\n code: StoredFactoryDispatchFailureCode | null,\n): FactoryDispatchFailureMetadata {\n return code === null ? FAILURE_METADATA.unknown : FAILURE_METADATA[code];\n}\n"],"mappings":";AAcA,MAAM,mBAAmB;CACvB,qBAAqB;EAAE,UAAU;EAAM,OAAO;CAA8B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;CAAwC;CACzF,2BAA2B;EAAE,UAAU;EAAM,OAAO;CAAgC;CACpF,6BAA6B;EAAE,UAAU;EAAM,OAAO;CAAkC;CACxF,2BAA2B;EAAE,UAAU;EAAO,OAAO;CAAiC;CACtF,8BAA8B;EAAE,UAAU;EAAM,OAAO;CAAkC;CACzF,4BAA4B;EAAE,UAAU;EAAO,OAAO;CAA4C;CAClG,gBAAgB;EAAE,UAAU;EAAM,OA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,MAAM,OAAO;AAC9D;AAEA,SAAgB,+BACd,MACgC;CAChC,OAAO,SAAS,OAAO,iBAAiB,UAAU,iBAAiB;AACrE"}
1
+ {"version":3,"file":"dispatch-errors.js","names":[],"sources":["../../src/rules/dispatch-errors.ts"],"sourcesContent":["import type {\n FactoryDispatchFailureCode,\n StoredFactoryDispatchFailureCode,\n} from '../storage/domains/work-items/base.js';\nimport type { FactoryRuleRejectionCode } from './types.js';\n\ninterface FactoryDispatchFailureMetadata {\n /** A person may retry the failed decision. */\n canRetry: boolean;\n /** `false` when only a person's retry can succeed: the dispatcher does not try again on its own. */\n autoRetry?: false;\n label: string;\n}\n\nconst FAILURE_METADATA = {\n session_unavailable: { canRetry: true, label: 'Factory session unavailable' },\n source_control_missing: { canRetry: true, label: 'Source-control connection unavailable' },\n source_repository_missing: { canRetry: true, label: 'Source repository unavailable' },\n source_repository_ambiguous: { canRetry: true, label: 'Work item repository unresolved' },\n unsupported_provider_item: { canRetry: false, label: 'Unsupported provider work item' },\n notification_delivery_failed: { canRetry: true, label: 'Factory message delivery failed' },\n run_terminal_event_missing: { canRetry: false, label: 'Agent run terminal event was not observed' },\n run_incomplete: { canRetry: true, label: 'Agent run ended before completing the working phase' },\n skill_delivery_ambiguous: { canRetry: false, label: 'Factory skill delivery could not be confirmed' },\n run_overdue: { canRetry: false, label: 'Agent run is overdue' },\n repository_git_missing: { canRetry: false, label: 'Git is unavailable in the workspace' },\n repository_sandbox_unresponsive: { canRetry: true, label: 'Workspace sandbox stopped responding' },\n repository_egress_blocked: { canRetry: false, label: 'Repository network access is blocked' },\n repository_clone_failed: { canRetry: true, label: 'Repository clone failed' },\n repository_pull_failed: { canRetry: true, label: 'Repository update failed' },\n repository_push_failed: { canRetry: true, label: 'Repository push failed' },\n repository_commit_failed: { canRetry: true, label: 'Repository commit failed' },\n repository_cli_missing: { canRetry: false, label: 'GitHub CLI is unavailable in the workspace' },\n repository_pr_failed: { canRetry: true, label: 'Pull request creation failed' },\n run_configuration_invalid: { canRetry: false, label: 'Run configuration rejected by provider' },\n run_credentials_unavailable: { canRetry: true, label: 'Model credentials unavailable for the run' },\n // The run's request carries no user, so every retry fails the same way; a person has to start it.\n run_user_unauthenticated: { canRetry: false, label: 'Run started without an authenticated user' },\n // Automatic work runs as the Factory, on the organization's keys only. Trying again cannot add one,\n // so the dispatcher stops at once; a person retries after adding the key.\n factory_org_key_missing: {\n canRetry: true,\n autoRetry: false,\n label: 'Add an organization model key to run this automatically',\n },\n run_failed: { canRetry: true, label: 'Agent run ended in error' },\n unknown: { canRetry: true, label: 'Factory automation failed' },\n // Retired: no path writes these any more, stored rows still read through here.\n plan_awaiting_approval: { canRetry: false, label: 'Plan waiting for review' },\n run_awaiting_input: { canRetry: false, label: 'Agent is waiting for an answer' },\n} satisfies Record<StoredFactoryDispatchFailureCode, FactoryDispatchFailureMetadata>;\n\nexport class FactoryDispatchError extends Error {\n constructor(\n readonly code: FactoryDispatchFailureCode,\n message: string,\n options?: ErrorOptions,\n ) {\n super(message, options);\n this.name = 'FactoryDispatchError';\n }\n}\n\n/** A transition the board's rules rejected while a decision was being applied. */\nexport class FactoryRuleRejectedError extends Error {\n constructor(\n readonly code: FactoryRuleRejectionCode,\n reason: string,\n /** Every retry would replay this same refusal, so only a person can move the work on. */\n readonly settled = false,\n ) {\n super(`${code}: ${reason}`);\n this.name = 'FactoryRuleRejectedError';\n }\n}\n\nexport function factoryDispatchFailureCode(error: unknown): FactoryDispatchFailureCode {\n return error instanceof FactoryDispatchError ? error.code : 'unknown';\n}\n\nexport function factoryDispatchFailureMetadata(\n code: StoredFactoryDispatchFailureCode | null,\n): FactoryDispatchFailureMetadata {\n return code === null ? FAILURE_METADATA.unknown : FAILURE_METADATA[code];\n}\n"],"mappings":";AAcA,MAAM,mBAAmB;CACvB,qBAAqB;EAAE,UAAU;EAAM,OAAO;CAA8B;CAC5E,wBAAwB;EAAE,UAAU;EAAM,OAAO;CAAwC;CACzF,2BAA2B;EAAE,UAAU;EAAM,O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A;EAKT,KAAK,OAAO;CACd;AACF;;AAGA,IAAa,2BAAb,cAA8C,MAAM;CAEvC;CAGA;CAJX,YACE,MACA,QAEA,UAAmB,OACnB;EACA,MAAM,GAAG,KAAK,IAAI,QAAQ;EALjB,KAAA,OAAA;EAGA,KAAA,UAAA;EAGT,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,2BAA2B,OAA4C;CACrF,OAAO,iBAAiB,uBAAuB,MAAM,OAAO;AAC9D;AAEA,SAAgB,+BACd,MACgC;CAChC,OAAO,SAAS,OAAO,iBAAiB,UAAU,iBAAiB;AACrE"}
@@ -42,6 +42,11 @@ export interface FactoryReviewStatusEvent {
42
42
  phase: FactoryReviewStatusPhase;
43
43
  /** When the agent was handed the review; set on the 'reviewing' step. */
44
44
  startedAt?: Date;
45
+ /** The session running the review, on every step after it was delivered, so the status can link to it. */
46
+ session?: {
47
+ sessionId: string;
48
+ threadId: string;
49
+ };
45
50
  /** When the run ended; set on final steps. */
46
51
  endedAt?: Date;
47
52
  /** Why the run failed or will retry, already sanitized. */
@@ -1 +1 @@
1
- {"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../src/rules/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAyC,MAAM,+BAA+B,CAAC;AA0B5G,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAaxD,OAAO,KAAK,EAAE,kBAAkB,EAAqB,MAAM,6BAA6B,CAAC;AAGzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAetE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAQzE,OAAO,KAAK,EACV,yBAAyB,EACzB,6BAA6B,EAG7B,uBAAuB,EACvB,IAAI,EACJ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GACX,EAAE;QACD,KAAK,EAAE,MAAM,CAAC;QACd,gBAAgB,EAAE,MAAM,CAAC;QACzB,UAAU,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,OAAO,CAAC,CAWnB;CA8VF;AAED,eAAO,MAAM,0BAA0B;aACrC,OAAO;aACP,MAAM;aACN,SAAS;aACT,WAAW;aACX,cAAc;aACd,YAAY;aACZ,mCAAmC;aACnC,sBAAsB;aACtB,cAAc;aACd,WAAW;aACX,qBAAqB;CACb,CAAC"}
@@ -385,6 +385,8 @@ var FactoryDecisionDispatcher = class {
385
385
  #reviewWatched = /* @__PURE__ */ new WeakSet();
386
386
  /** Re-claims that found an earlier attempt's kickoff landed and its run already over. */
387
387
  #reviewReplayed = /* @__PURE__ */ new WeakSet();
388
+ /** The session a review run was delivered to, so every later status step can link it. */
389
+ #reviewSessions = /* @__PURE__ */ new WeakMap();
388
390
  /** Last pending status-comment write per run, so writes stay ordered. */
389
391
  /**
390
392
  * Per review run: the write chain, the newest step issued, and how many
@@ -743,7 +745,7 @@ var FactoryDecisionDispatcher = class {
743
745
  return;
744
746
  }
745
747
  const failureCode = factoryDispatchFailureCode(error);
746
- const terminal = isTerminalFailure(record.attempts, failureCode);
748
+ const terminal = isTerminalFailure(record.attempts, failureCode) || error instanceof FactoryRuleRejectedError && error.settled;
747
749
  const failed = await this.#storage.failDeferredDecision({
748
750
  ...leaseIdentity(record, this.#ownerId),
749
751
  now: /* @__PURE__ */ new Date(),
@@ -757,7 +759,8 @@ var FactoryDecisionDispatcher = class {
757
759
  if (terminal || this.#reviewQueued.has(record)) await this.#reviewStatus(failed ?? record, record.decision, {
758
760
  phase: terminal ? "failed" : "retrying",
759
761
  endedAt: /* @__PURE__ */ new Date(),
760
- reason: publicFailureReason(failureCode, error)
762
+ reason: publicFailureReason(failureCode, error),
763
+ session: this.#reviewSessions.get(record)
761
764
  });
762
765
  }
763
766
  }
@@ -931,6 +934,8 @@ var FactoryDecisionDispatcher = class {
931
934
  attempt: record.attempts,
932
935
  ...step
933
936
  };
937
+ const session = step.session ?? this.#reviewSessions.get(record);
938
+ if (session) event.session = session;
934
939
  const run = this.#reviewStatusRuns.get(record.id) ?? {
935
940
  tail: Promise.resolve(),
936
941
  issued: 0,
@@ -1082,6 +1087,10 @@ var FactoryDecisionDispatcher = class {
1082
1087
  userId: startedBy,
1083
1088
  orgId: record.orgId
1084
1089
  });
1090
+ this.#reviewSessions.set(record, {
1091
+ sessionId: binding.sessionId,
1092
+ threadId: binding.threadId
1093
+ });
1085
1094
  const deliveryId = record.deliveryGeneration === 0 ? record.id : `${record.id}:retry:${record.deliveryGeneration}`;
1086
1095
  const kickoffLanded = async () => (await session.thread.listActiveMessages()).some((message) => message.id === deliveryId);
1087
1096
  const kickoffStale = async () => await this.#roleSuperseded(record, decision.role) || (await this.#findBinding(record, decision.role))?.id !== binding.id || await this.#decisionOvertaken(record, decision.role);
@@ -1846,7 +1855,7 @@ var FactoryDecisionDispatcher = class {
1846
1855
  ...decision.reenter ? { reenter: true } : {},
1847
1856
  ...decision.event && untrustedPullRequestEvent(decision.event) ? { untrustedPullRequestEvent: true } : {}
1848
1857
  });
1849
- if (result.status === "rejected") throw new FactoryRuleRejectedError(result.code, result.reason);
1858
+ if (result.status === "rejected") throw new FactoryRuleRejectedError(result.code, result.reason, result.code !== "stale");
1850
1859
  const transitionMessage = decision.message;
1851
1860
  if (!transitionMessage) return;
1852
1861
  const moved = await this.#storage.get({