@mastra/factory 0.12.1-alpha.0 → 0.13.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.
Files changed (89) hide show
  1. package/README.md +10 -0
  2. package/dist/factory.d.ts.map +1 -1
  3. package/dist/factory.js +90 -9
  4. package/dist/factory.js.map +1 -1
  5. package/dist/integrations/github/provenance.d.ts +2 -0
  6. package/dist/integrations/github/provenance.d.ts.map +1 -1
  7. package/dist/integrations/github/provenance.js +3 -2
  8. package/dist/integrations/github/provenance.js.map +1 -1
  9. package/dist/integrations/github/routes.d.ts.map +1 -1
  10. package/dist/integrations/github/routes.js +12 -39
  11. package/dist/integrations/github/routes.js.map +1 -1
  12. package/dist/integrations/github/rules.d.ts.map +1 -1
  13. package/dist/integrations/github/rules.js +33 -4
  14. package/dist/integrations/github/rules.js.map +1 -1
  15. package/dist/integrations/github/webhook.d.ts.map +1 -1
  16. package/dist/integrations/github/webhook.js +34 -2
  17. package/dist/integrations/github/webhook.js.map +1 -1
  18. package/dist/routes/attention-providers.d.ts +17 -0
  19. package/dist/routes/attention-providers.d.ts.map +1 -1
  20. package/dist/routes/attention-providers.js +128 -2
  21. package/dist/routes/attention-providers.js.map +1 -1
  22. package/dist/routes/attention.d.ts.map +1 -1
  23. package/dist/routes/attention.js +11 -4
  24. package/dist/routes/attention.js.map +1 -1
  25. package/dist/routes/projects.d.ts +9 -1
  26. package/dist/routes/projects.d.ts.map +1 -1
  27. package/dist/routes/projects.js +26 -5
  28. package/dist/routes/projects.js.map +1 -1
  29. package/dist/routes/supervisor.d.ts +23 -0
  30. package/dist/routes/supervisor.d.ts.map +1 -0
  31. package/dist/routes/supervisor.js +34 -0
  32. package/dist/routes/supervisor.js.map +1 -0
  33. package/dist/routes/surface.js +1 -1
  34. package/dist/routes/work-items.d.ts.map +1 -1
  35. package/dist/routes/work-items.js +5 -0
  36. package/dist/routes/work-items.js.map +1 -1
  37. package/dist/rules/defaults.d.ts.map +1 -1
  38. package/dist/rules/defaults.js +20 -8
  39. package/dist/rules/defaults.js.map +1 -1
  40. package/dist/rules/dispatcher.d.ts +1 -0
  41. package/dist/rules/dispatcher.d.ts.map +1 -1
  42. package/dist/rules/dispatcher.js +81 -23
  43. package/dist/rules/dispatcher.js.map +1 -1
  44. package/dist/rules/terminal-cleanup.d.ts +3 -1
  45. package/dist/rules/terminal-cleanup.d.ts.map +1 -1
  46. package/dist/rules/terminal-cleanup.js +5 -0
  47. package/dist/rules/terminal-cleanup.js.map +1 -1
  48. package/dist/rules/transition-service.d.ts +1 -0
  49. package/dist/rules/transition-service.d.ts.map +1 -1
  50. package/dist/rules/transition-service.js +2 -1
  51. package/dist/rules/transition-service.js.map +1 -1
  52. package/dist/rules/types.d.ts +7 -0
  53. package/dist/rules/types.d.ts.map +1 -1
  54. package/dist/rules/types.js.map +1 -1
  55. package/dist/sandbox/session-retirement.js +1 -1
  56. package/dist/storage/domains/work-items/base.d.ts +36 -1
  57. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  58. package/dist/storage/domains/work-items/base.js +144 -2
  59. package/dist/storage/domains/work-items/base.js.map +1 -1
  60. package/dist/supervisor/health-worker.d.ts +17 -0
  61. package/dist/supervisor/health-worker.d.ts.map +1 -0
  62. package/dist/supervisor/health-worker.js +72 -0
  63. package/dist/supervisor/health-worker.js.map +1 -0
  64. package/dist/supervisor/health.d.ts +81 -0
  65. package/dist/supervisor/health.d.ts.map +1 -0
  66. package/dist/supervisor/health.js +245 -0
  67. package/dist/supervisor/health.js.map +1 -0
  68. package/dist/supervisor/instructions.d.ts +6 -0
  69. package/dist/supervisor/instructions.d.ts.map +1 -0
  70. package/dist/supervisor/instructions.js +64 -0
  71. package/dist/supervisor/instructions.js.map +1 -0
  72. package/dist/supervisor/read-tools.d.ts +41 -0
  73. package/dist/supervisor/read-tools.d.ts.map +1 -0
  74. package/dist/supervisor/read-tools.js +338 -0
  75. package/dist/supervisor/read-tools.js.map +1 -0
  76. package/dist/supervisor/session.d.ts +38 -0
  77. package/dist/supervisor/session.d.ts.map +1 -0
  78. package/dist/supervisor/session.js +63 -0
  79. package/dist/supervisor/session.js.map +1 -0
  80. package/dist/supervisor/write-tools.d.ts +26 -0
  81. package/dist/supervisor/write-tools.d.ts.map +1 -0
  82. package/dist/supervisor/write-tools.js +227 -0
  83. package/dist/supervisor/write-tools.js.map +1 -0
  84. package/dist/workspace.d.ts +3 -0
  85. package/dist/workspace.d.ts.map +1 -1
  86. package/dist/workspace.js +14 -4
  87. package/dist/workspace.js.map +1 -1
  88. package/factory-skills/factory-triage/SKILL.md +1 -1
  89. package/package.json +4 -4
@@ -80,6 +80,13 @@ function factoryActivityAttentionIdentity(workItemId, occurrence) {
80
80
  occurrence
81
81
  };
82
82
  }
83
+ function factorySupervisorFindingAttentionIdentity(findingKey, occurrence) {
84
+ return {
85
+ kind: "supervisor-finding",
86
+ sourceId: findingKey,
87
+ occurrence
88
+ };
89
+ }
83
90
  function factoryAttentionKey(factoryProjectId, identity) {
84
91
  return `factory:${factoryProjectId}:attention:${identity.kind}:${identity.sourceId}:${identity.occurrence}`;
85
92
  }
@@ -490,6 +497,41 @@ const FACTORY_GOVERNANCE_SCHEMAS = [
490
497
  }
491
498
  ]
492
499
  },
500
+ {
501
+ name: "factory_supervisor_findings",
502
+ columns: {
503
+ id: { type: "uuid-pk" },
504
+ org_id: { type: "text" },
505
+ factory_project_id: { type: "text" },
506
+ finding_key: { type: "text" },
507
+ occurrence: { type: "integer" },
508
+ finding: { type: "json" },
509
+ opened_at: { type: "timestamp" },
510
+ updated_at: { type: "timestamp" },
511
+ resolved_at: {
512
+ type: "timestamp",
513
+ nullable: true
514
+ }
515
+ },
516
+ uniqueIndexes: [{
517
+ name: "factory_supervisor_findings_project_key_unique",
518
+ columns: [
519
+ "org_id",
520
+ "factory_project_id",
521
+ "finding_key"
522
+ ]
523
+ }],
524
+ indexes: [{
525
+ name: "factory_supervisor_findings_project_open_idx",
526
+ columns: [
527
+ "org_id",
528
+ "factory_project_id",
529
+ "resolved_at",
530
+ "updated_at",
531
+ "id"
532
+ ]
533
+ }]
534
+ },
493
535
  {
494
536
  name: "factory_attention_receipts",
495
537
  columns: {
@@ -683,9 +725,22 @@ function toDeferredDecision(row) {
683
725
  };
684
726
  }
685
727
  function attentionReceiptKind(value) {
686
- if (value === "automation-failed" || value === "mention" || value === "activity") return value;
728
+ if (value === "automation-failed" || value === "mention" || value === "activity" || value === "supervisor-finding") return value;
687
729
  throw new Error(`Unsupported attention receipt kind '${String(value)}'.`);
688
730
  }
731
+ function toSupervisorFinding(row) {
732
+ return {
733
+ id: row.id,
734
+ orgId: String(row.org_id),
735
+ factoryProjectId: String(row.factory_project_id),
736
+ findingKey: String(row.finding_key),
737
+ occurrence: Number(row.occurrence),
738
+ finding: row.finding,
739
+ openedAt: row.opened_at,
740
+ updatedAt: row.updated_at,
741
+ resolvedAt: row.resolved_at ?? null
742
+ };
743
+ }
689
744
  function attentionReceiptState(value) {
690
745
  if (value === "read" || value === "archived") return value;
691
746
  throw new Error(`Unsupported attention receipt state '${String(value)}'.`);
@@ -768,6 +823,86 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
768
823
  if (!count) throw new Error("[WorkItemsStorage] storage backend does not support collection counts.");
769
824
  return count.call(this.#db, collection, where);
770
825
  }
826
+ async syncSupervisorFindings(input) {
827
+ if (await this.#withProjectRelationTransaction(input.orgId, input.factoryProjectId, async (ops) => {
828
+ let changed = false;
829
+ const existingOpen = await ops.findMany("factory_supervisor_findings", {
830
+ org_id: input.orgId,
831
+ factory_project_id: input.factoryProjectId,
832
+ resolved_at: null
833
+ });
834
+ const currentKeys = new Set(input.findings.map((finding) => finding.id));
835
+ for (const row of existingOpen) if (!currentKeys.has(String(row.finding_key))) {
836
+ await ops.updateAtomic("factory_supervisor_findings", {
837
+ id: row.id,
838
+ resolved_at: null
839
+ }, () => ({
840
+ resolved_at: input.now,
841
+ updated_at: input.now
842
+ }));
843
+ changed = true;
844
+ }
845
+ const openByKey = new Map(existingOpen.map((row) => [String(row.finding_key), row]));
846
+ for (const finding of input.findings) {
847
+ const row = openByKey.get(finding.id) ?? await ops.findOne("factory_supervisor_findings", {
848
+ org_id: input.orgId,
849
+ factory_project_id: input.factoryProjectId,
850
+ finding_key: finding.id
851
+ });
852
+ if (!row) {
853
+ await ops.insertOne("factory_supervisor_findings", {
854
+ org_id: input.orgId,
855
+ factory_project_id: input.factoryProjectId,
856
+ finding_key: finding.id,
857
+ occurrence: 0,
858
+ finding,
859
+ opened_at: input.now,
860
+ updated_at: input.now,
861
+ resolved_at: null
862
+ });
863
+ changed = true;
864
+ continue;
865
+ }
866
+ const reopening = row.resolved_at !== null;
867
+ const findingChanged = stableJson(row.finding) !== stableJson(finding);
868
+ if (!reopening && !findingChanged) continue;
869
+ await ops.updateAtomic("factory_supervisor_findings", { id: row.id }, (current) => ({
870
+ finding,
871
+ occurrence: Number(current.occurrence) + (current.resolved_at !== null ? 1 : 0),
872
+ opened_at: current.resolved_at !== null ? input.now : current.opened_at,
873
+ updated_at: input.now,
874
+ resolved_at: null
875
+ }));
876
+ changed = true;
877
+ }
878
+ return changed;
879
+ })) this.#attentionChanged?.({
880
+ orgId: input.orgId,
881
+ factoryProjectId: input.factoryProjectId
882
+ });
883
+ }
884
+ async listSupervisorFindingPage(input) {
885
+ const rows = await this.#db.findMany("factory_supervisor_findings", {
886
+ org_id: input.orgId,
887
+ factory_project_id: input.factoryProjectId,
888
+ resolved_at: null
889
+ }, {
890
+ orderBy: [["updated_at", "desc"], ["id", "desc"]],
891
+ limit: input.limit + 1,
892
+ ...input.before ? { cursor: { values: [input.before.occurredAt, input.before.id] } } : {}
893
+ });
894
+ return {
895
+ rows: rows.slice(0, input.limit).map(toSupervisorFinding),
896
+ hasMore: rows.length > input.limit
897
+ };
898
+ }
899
+ async countOpenSupervisorFindings(input) {
900
+ return this.#countRows("factory_supervisor_findings", {
901
+ org_id: input.orgId,
902
+ factory_project_id: input.factoryProjectId,
903
+ resolved_at: null
904
+ });
905
+ }
771
906
  async #withProjectRelationTransaction(orgId, factoryProjectId, fn) {
772
907
  return withInProcessProjectLock(`work-items:${orgId}:${factoryProjectId}`, () => this.storage.withTransaction(fn, { isolationLevel: "serializable" }));
773
908
  }
@@ -1360,6 +1495,13 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
1360
1495
  factory_project_id: factoryProjectId,
1361
1496
  occurrence: identity.occurrence
1362
1497
  }) !== null;
1498
+ if (identity.kind === "supervisor-finding") return await ops.findOne("factory_supervisor_findings", {
1499
+ org_id: orgId,
1500
+ factory_project_id: factoryProjectId,
1501
+ finding_key: identity.sourceId,
1502
+ occurrence: identity.occurrence,
1503
+ resolved_at: null
1504
+ }) !== null;
1363
1505
  if (identity.occurrence !== 0) return false;
1364
1506
  if (!await ops.findOne("work_item_comment_mentions", {
1365
1507
  comment_id: identity.sourceId,
@@ -2247,6 +2389,6 @@ var WorkItemsStorage = class extends FactoryStorageDomain {
2247
2389
  }
2248
2390
  };
2249
2391
  //#endregion
2250
- export { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, FACTORY_RULE_MATERIALIZATION_KEY, WORK_ITEMS_SCHEMA, WorkItemRelationError, WorkItemsStorage, applyStageTransition, externalSourceKey, factoryActivityAttentionIdentity, factoryAttentionKey, factoryDecisionAttentionIdentity, factoryDecisionHash, factoryMentionAttentionIdentity, isAgentActor, stampSessions, validateParentRelation };
2392
+ export { FACTORY_PULL_REQUEST_RECONCILIATION_KEY, FACTORY_RULE_MATERIALIZATION_KEY, WORK_ITEMS_SCHEMA, WorkItemRelationError, WorkItemsStorage, applyStageTransition, externalSourceKey, factoryActivityAttentionIdentity, factoryAttentionKey, factoryDecisionAttentionIdentity, factoryDecisionHash, factoryMentionAttentionIdentity, factorySupervisorFindingAttentionIdentity, isAgentActor, stampSessions, validateParentRelation };
2251
2393
 
2252
2394
  //# sourceMappingURL=base.js.map