@mastra/factory 0.27.0-alpha.1 → 0.27.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 (129) hide show
  1. package/README.md +91 -9
  2. package/dist/boards/card-facts.d.ts +1 -1
  3. package/dist/boards/card-facts.d.ts.map +1 -1
  4. package/dist/boards/card-facts.js +3 -1
  5. package/dist/boards/card-facts.js.map +1 -1
  6. package/dist/boards/index.d.ts +2 -2
  7. package/dist/boards/index.d.ts.map +1 -1
  8. package/dist/boards/index.js +2 -2
  9. package/dist/boards/index.js.map +1 -1
  10. package/dist/boards/intake-routing.d.ts +37 -0
  11. package/dist/boards/intake-routing.d.ts.map +1 -0
  12. package/dist/boards/intake-routing.js +70 -0
  13. package/dist/boards/intake-routing.js.map +1 -0
  14. package/dist/boards/pull-request-review.d.ts +21 -0
  15. package/dist/boards/pull-request-review.d.ts.map +1 -0
  16. package/dist/boards/pull-request-review.js +80 -0
  17. package/dist/boards/pull-request-review.js.map +1 -0
  18. package/dist/boards/review.d.ts +0 -2
  19. package/dist/boards/review.d.ts.map +1 -1
  20. package/dist/boards/review.js +2 -76
  21. package/dist/boards/review.js.map +1 -1
  22. package/dist/boards/semantics.d.ts +20 -0
  23. package/dist/boards/semantics.d.ts.map +1 -1
  24. package/dist/boards/semantics.js +21 -1
  25. package/dist/boards/semantics.js.map +1 -1
  26. package/dist/boards/work-transition-policy.d.ts.map +1 -1
  27. package/dist/boards/work-transition-policy.js +22 -0
  28. package/dist/boards/work-transition-policy.js.map +1 -1
  29. package/dist/boards/work.d.ts +2 -2
  30. package/dist/boards/work.d.ts.map +1 -1
  31. package/dist/boards/work.js +12 -0
  32. package/dist/boards/work.js.map +1 -1
  33. package/dist/factory.d.ts +4 -2
  34. package/dist/factory.d.ts.map +1 -1
  35. package/dist/factory.js +18 -27
  36. package/dist/factory.js.map +1 -1
  37. package/dist/integrations/github/default-rules.d.ts +14 -14
  38. package/dist/integrations/github/default-rules.d.ts.map +1 -1
  39. package/dist/integrations/github/default-rules.js +36 -21
  40. package/dist/integrations/github/default-rules.js.map +1 -1
  41. package/dist/integrations/github/rules.d.ts.map +1 -1
  42. package/dist/integrations/github/rules.js +2 -0
  43. package/dist/integrations/github/rules.js.map +1 -1
  44. package/dist/integrations/gitlab/default-rules.d.ts +7 -7
  45. package/dist/integrations/gitlab/default-rules.d.ts.map +1 -1
  46. package/dist/integrations/gitlab/default-rules.js +28 -14
  47. package/dist/integrations/gitlab/default-rules.js.map +1 -1
  48. package/dist/integrations/gitlab/rules.js.map +1 -1
  49. package/dist/packages/_internals/workspace/dist/index.js.map +1 -1
  50. package/dist/routes/boards.js +1 -1
  51. package/dist/routes/config.d.ts +4 -4
  52. package/dist/routes/config.d.ts.map +1 -1
  53. package/dist/routes/config.js +6 -5
  54. package/dist/routes/config.js.map +1 -1
  55. package/dist/routes/contracts.d.ts +195 -0
  56. package/dist/routes/contracts.d.ts.map +1 -1
  57. package/dist/routes/contracts.js +105 -1
  58. package/dist/routes/contracts.js.map +1 -1
  59. package/dist/routes/intake-routes.d.ts +28 -0
  60. package/dist/routes/intake-routes.d.ts.map +1 -0
  61. package/dist/routes/intake-routes.js +199 -0
  62. package/dist/routes/intake-routes.js.map +1 -0
  63. package/dist/routes/intake.d.ts.map +1 -1
  64. package/dist/routes/intake.js +9 -0
  65. package/dist/routes/intake.js.map +1 -1
  66. package/dist/routes/surface.d.ts.map +1 -1
  67. package/dist/routes/surface.js +14 -3
  68. package/dist/routes/surface.js.map +1 -1
  69. package/dist/routes/work-items.d.ts +3 -0
  70. package/dist/routes/work-items.d.ts.map +1 -1
  71. package/dist/routes/work-items.js +1 -0
  72. package/dist/routes/work-items.js.map +1 -1
  73. package/dist/rules/dispatcher.d.ts +4 -1
  74. package/dist/rules/dispatcher.d.ts.map +1 -1
  75. package/dist/rules/dispatcher.js +96 -17
  76. package/dist/rules/dispatcher.js.map +1 -1
  77. package/dist/rules/processor.d.ts.map +1 -1
  78. package/dist/rules/processor.js +5 -2
  79. package/dist/rules/processor.js.map +1 -1
  80. package/dist/rules/rule-group.d.ts +1 -1
  81. package/dist/rules/rule-group.d.ts.map +1 -1
  82. package/dist/rules/rule-group.js +1 -0
  83. package/dist/rules/rule-group.js.map +1 -1
  84. package/dist/rules/tools.d.ts.map +1 -1
  85. package/dist/rules/tools.js +11 -5
  86. package/dist/rules/tools.js.map +1 -1
  87. package/dist/rules/transition-service.d.ts.map +1 -1
  88. package/dist/rules/transition-service.js +2 -7
  89. package/dist/rules/transition-service.js.map +1 -1
  90. package/dist/rules/types.d.ts +3 -1
  91. package/dist/rules/types.d.ts.map +1 -1
  92. package/dist/rules/types.js +7 -3
  93. package/dist/rules/types.js.map +1 -1
  94. package/dist/session/self-review-gate.d.ts +13 -0
  95. package/dist/session/self-review-gate.d.ts.map +1 -0
  96. package/dist/session/self-review-gate.js +37 -0
  97. package/dist/session/self-review-gate.js.map +1 -0
  98. package/dist/storage/domains/audit/actions.d.ts +1 -0
  99. package/dist/storage/domains/audit/actions.d.ts.map +1 -1
  100. package/dist/storage/domains/audit/actions.js +7 -1
  101. package/dist/storage/domains/audit/actions.js.map +1 -1
  102. package/dist/storage/domains/boards/base.d.ts +72 -1
  103. package/dist/storage/domains/boards/base.d.ts.map +1 -1
  104. package/dist/storage/domains/boards/base.js +292 -8
  105. package/dist/storage/domains/boards/base.js.map +1 -1
  106. package/dist/storage/domains/boards/schemas.d.ts +8 -0
  107. package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
  108. package/dist/storage/domains/boards/schemas.js +64 -1
  109. package/dist/storage/domains/boards/schemas.js.map +1 -1
  110. package/dist/storage/domains/work-items/base.d.ts.map +1 -1
  111. package/dist/storage/domains/work-items/base.js +2 -1
  112. package/dist/storage/domains/work-items/base.js.map +1 -1
  113. package/dist/tools/permissions.d.ts.map +1 -1
  114. package/dist/tools/permissions.js +2 -1
  115. package/dist/tools/permissions.js.map +1 -1
  116. package/dist/tools/sandbox-tools.d.ts +5 -0
  117. package/dist/tools/sandbox-tools.d.ts.map +1 -1
  118. package/dist/tools/sandbox-tools.js +68 -30
  119. package/dist/tools/sandbox-tools.js.map +1 -1
  120. package/dist/tools/work-item-tools.d.ts +3 -0
  121. package/dist/tools/work-item-tools.d.ts.map +1 -1
  122. package/dist/tools/work-item-tools.js +2 -1
  123. package/dist/tools/work-item-tools.js.map +1 -1
  124. package/dist/work-items/create-work-item.d.ts +5 -2
  125. package/dist/work-items/create-work-item.d.ts.map +1 -1
  126. package/dist/work-items/create-work-item.js +54 -3
  127. package/dist/work-items/create-work-item.js.map +1 -1
  128. package/factory-skills/configure-factory-rules/SKILL.md +1 -1
  129. package/package.json +9 -9
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/tools/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEvF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAqB3D,CAAC;AAEF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE;QAAE,KAAK,IAAI,MAAM,CAAA;KAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,IAAI,eAAe,CAAC;QAC5B,UAAU,CAAC,IAAI,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,gBAAgB,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACjF,CAAC;CACH;AAED,MAAM,WAAW,kCAAkC;IACjD,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,6BAA6B,EACtC,EAAE,QAAQ,EAAE,EAAE,kCAAkC,EAChD,SAAS,GAAE,SAAS,MAAM,EAAmC,GAC5D,OAAO,CAAC,IAAI,CAAC,CASf"}
1
+ {"version":3,"file":"permissions.d.ts","sourceRoot":"","sources":["../../src/tools/permissions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEvF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAsB3D,CAAC;AAEF,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,QAAQ,EAAE;QAAE,KAAK,IAAI,MAAM,CAAA;KAAE,CAAC;IACvC,QAAQ,CAAC,WAAW,EAAE;QACpB,QAAQ,IAAI,eAAe,CAAC;QAC5B,UAAU,CAAC,IAAI,EAAE;YAAE,QAAQ,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,gBAAgB,CAAA;SAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACjF,CAAC;CACH;AAED,MAAM,WAAW,kCAAkC;IACjD,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;CAC9D;AAED;;;;;GAKG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,6BAA6B,EACtC,EAAE,QAAQ,EAAE,EAAE,kCAAkC,EAChD,SAAS,GAAE,SAAS,MAAM,EAAmC,GAC5D,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -24,7 +24,8 @@ const FACTORY_TOOLS_WITHOUT_APPROVAL = [
24
24
  "factory_start_session",
25
25
  "factory_answer_approval",
26
26
  "factory_switch_session_model",
27
- "factory_recreate_sandbox"
27
+ "factory_recreate_sandbox",
28
+ "factory_sandbox_port_url"
28
29
  ];
29
30
  /**
30
31
  * Allow the no-approval Factory tools on a newly created Factory session.
@@ -1 +1 @@
1
- {"version":3,"file":"permissions.js","names":[],"sources":["../../src/tools/permissions.ts"],"sourcesContent":["import type { PermissionPolicy, PermissionRules } from '@mastra/core/agent-controller';\n\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\n\n/**\n * Factory tools that run without asking. Factory tools fall into the SDK's\n * `mcp` category, whose default policy is `ask`, so each of these needs an\n * explicit per-session `allow`.\n */\nexport const FACTORY_TOOLS_WITHOUT_APPROVAL: readonly string[] = [\n 'factory_list_work_items',\n 'factory_inspect_work_item',\n 'factory_list_attention',\n 'factory_create_work_item',\n 'factory_update_work_item',\n 'factory_transition_work_item',\n 'factory_retry_decision',\n 'factory_dismiss_decision',\n 'factory_resolve_proposal',\n 'factory_subscribe_work_item',\n 'factory_unsubscribe_work_item',\n 'factory_signal_session',\n 'factory_message_origin',\n 'factory_list_side_sessions',\n 'factory_subscribe_session',\n 'factory_unsubscribe_session',\n 'factory_start_session',\n 'factory_answer_approval',\n 'factory_switch_session_model',\n 'factory_recreate_sandbox',\n];\n\nexport interface FactoryToolPermissionsSession {\n readonly identity: { getId(): string };\n readonly permissions: {\n getRules(): PermissionRules;\n setForTool(args: { toolName: string; policy: PermissionPolicy }): Promise<void>;\n };\n}\n\nexport interface FactoryToolPermissionsDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getBySessionId'>;\n}\n\n/**\n * Allow the no-approval Factory tools on a newly created Factory session.\n * This only sets policy; which tools a turn actually gets is decided by the\n * tool scope. A person's own choices win: a per-tool policy is never\n * overwritten, and an explicit `mcp` category policy leaves everything alone.\n */\nexport async function applyFactoryToolPermissions(\n session: FactoryToolPermissionsSession,\n { sessions }: FactoryToolPermissionsDependencies,\n toolNames: readonly string[] = FACTORY_TOOLS_WITHOUT_APPROVAL,\n): Promise<void> {\n const row = await sessions.getBySessionId(session.identity.getId());\n if (!row?.factoryProjectId) return;\n const rules = session.permissions.getRules();\n if (rules.categories.mcp !== undefined) return;\n for (const toolName of toolNames) {\n if (session.permissions.getRules().tools[toolName] !== undefined) continue;\n await session.permissions.setForTool({ toolName, policy: 'allow' });\n }\n}\n"],"mappings":";;;;;;AASA,MAAa,iCAAoD;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;AAoBA,eAAsB,4BACpB,SACA,EAAE,YACF,YAA+B,gCAChB;CAEf,IAAI,EAAC,MADa,SAAS,eAAe,QAAQ,SAAS,MAAM,CAAC,EAAA,EACxD,kBAAkB;CAE5B,IADc,QAAQ,YAAY,SAC1B,CAAC,CAAC,WAAW,QAAQ,KAAA,GAAW;CACxC,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI,QAAQ,YAAY,SAAS,CAAC,CAAC,MAAM,cAAc,KAAA,GAAW;EAClE,MAAM,QAAQ,YAAY,WAAW;GAAE;GAAU,QAAQ;EAAQ,CAAC;CACpE;AACF"}
1
+ {"version":3,"file":"permissions.js","names":[],"sources":["../../src/tools/permissions.ts"],"sourcesContent":["import type { PermissionPolicy, PermissionRules } from '@mastra/core/agent-controller';\n\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\n\n/**\n * Factory tools that run without asking. Factory tools fall into the SDK's\n * `mcp` category, whose default policy is `ask`, so each of these needs an\n * explicit per-session `allow`.\n */\nexport const FACTORY_TOOLS_WITHOUT_APPROVAL: readonly string[] = [\n 'factory_list_work_items',\n 'factory_inspect_work_item',\n 'factory_list_attention',\n 'factory_create_work_item',\n 'factory_update_work_item',\n 'factory_transition_work_item',\n 'factory_retry_decision',\n 'factory_dismiss_decision',\n 'factory_resolve_proposal',\n 'factory_subscribe_work_item',\n 'factory_unsubscribe_work_item',\n 'factory_signal_session',\n 'factory_message_origin',\n 'factory_list_side_sessions',\n 'factory_subscribe_session',\n 'factory_unsubscribe_session',\n 'factory_start_session',\n 'factory_answer_approval',\n 'factory_switch_session_model',\n 'factory_recreate_sandbox',\n 'factory_sandbox_port_url',\n];\n\nexport interface FactoryToolPermissionsSession {\n readonly identity: { getId(): string };\n readonly permissions: {\n getRules(): PermissionRules;\n setForTool(args: { toolName: string; policy: PermissionPolicy }): Promise<void>;\n };\n}\n\nexport interface FactoryToolPermissionsDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getBySessionId'>;\n}\n\n/**\n * Allow the no-approval Factory tools on a newly created Factory session.\n * This only sets policy; which tools a turn actually gets is decided by the\n * tool scope. A person's own choices win: a per-tool policy is never\n * overwritten, and an explicit `mcp` category policy leaves everything alone.\n */\nexport async function applyFactoryToolPermissions(\n session: FactoryToolPermissionsSession,\n { sessions }: FactoryToolPermissionsDependencies,\n toolNames: readonly string[] = FACTORY_TOOLS_WITHOUT_APPROVAL,\n): Promise<void> {\n const row = await sessions.getBySessionId(session.identity.getId());\n if (!row?.factoryProjectId) return;\n const rules = session.permissions.getRules();\n if (rules.categories.mcp !== undefined) return;\n for (const toolName of toolNames) {\n if (session.permissions.getRules().tools[toolName] !== undefined) continue;\n await session.permissions.setForTool({ toolName, policy: 'allow' });\n }\n}\n"],"mappings":";;;;;;AASA,MAAa,iCAAoD;CAC/D;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;;AAoBA,eAAsB,4BACpB,SACA,EAAE,YACF,YAA+B,gCAChB;CAEf,IAAI,EAAC,MADa,SAAS,eAAe,QAAQ,SAAS,MAAM,CAAC,EAAA,EACxD,kBAAkB;CAE5B,IADc,QAAQ,YAAY,SAC1B,CAAC,CAAC,WAAW,QAAQ,KAAA,GAAW;CACxC,KAAK,MAAM,YAAY,WAAW;EAChC,IAAI,QAAQ,YAAY,SAAS,CAAC,CAAC,MAAM,cAAc,KAAA,GAAW;EAClE,MAAM,QAAQ,YAAY,WAAW;GAAE;GAAU,QAAQ;EAAQ,CAAC;CACpE;AACF"}
@@ -1,3 +1,4 @@
1
+ import type { MastraBrowser } from '@mastra/core/browser';
1
2
  import type { IntegrationTools } from '../integrations/base.js';
2
3
  import type { RecreateSessionSandboxInput } from '../sandbox/session-retirement.js';
3
4
  import type { SourceControlSessionLookup } from '../session/factory-session.js';
@@ -6,6 +7,10 @@ export interface FactorySandboxToolDependencies {
6
7
  sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;
7
8
  /** `SessionRetirementCoordinator.resetSessionSandbox`. */
8
9
  resetSandbox: (input: RecreateSessionSandboxInput) => Promise<'reset' | 'not-found' | 'not-here'>;
10
+ /** The session's running sandbox, if this process has one. */
11
+ findSandbox: (input: RecreateSessionSandboxInput) => Promise<object | undefined>;
12
+ /** The browser session agents drive, when Factory has one. */
13
+ browser?: MastraBrowser;
9
14
  }
10
15
  /** Tools a session uses on its own sandbox. Every session with a sandbox gets them. */
11
16
  export declare function createFactorySandboxTools(scope: FactoryToolScope, deps: FactorySandboxToolDependencies): IntegrationTools;
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-tools.d.ts","sourceRoot":"","sources":["../../src/tools/sandbox-tools.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,6BAA6B,CAAC,CAAC;IAC1E,0DAA0D;IAC1D,YAAY,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,OAAO,CAAC,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC,CAAC;CACnG;AAED,uFAAuF;AACvF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,8BAA8B,GACnC,gBAAgB,CA+BlB"}
1
+ {"version":3,"file":"sandbox-tools.d.ts","sourceRoot":"","sources":["../../src/tools/sandbox-tools.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAMzE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,kCAAkC,CAAC;AACpF,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,6BAA6B,CAAC,CAAC;IAC1E,0DAA0D;IAC1D,YAAY,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,OAAO,CAAC,OAAO,GAAG,WAAW,GAAG,UAAU,CAAC,CAAC;IAClG,8DAA8D;IAC9D,WAAW,EAAE,CAAC,KAAK,EAAE,2BAA2B,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACjF,8DAA8D;IAC9D,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAWD,uFAAuF;AACvF,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,8BAA8B,GACnC,gBAAgB,CA4ElB"}
@@ -1,38 +1,76 @@
1
+ import { supportsNetworking } from "@mastra/core/workspace";
1
2
  import { z } from "zod";
2
3
  import { createTool } from "@mastra/core/tools";
3
4
  // src/tools/sandbox-tools.ts
5
+ function hasPortAuthCookie(sandbox) {
6
+ return typeof sandbox.getPortAuthCookie === "function";
7
+ }
4
8
  /** Tools a session uses on its own sandbox. Every session with a sandbox gets them. */
5
9
  function createFactorySandboxTools(scope, deps) {
6
- return { factory_recreate_sandbox: createTool({
7
- id: "factory_recreate_sandbox",
8
- description: [
9
- "Destroy this session's sandbox and replace it with a fresh one. Use it only to recover when the sandbox stops working: commands that time out even for `echo ok`, or errors like \"onStart hook failed\".",
10
- "This deletes the VM. Everything in it that is not committed and pushed is lost for good: uncommitted and unpushed changes, untracked files, installed dependencies, build output and running processes.",
11
- "Push what you can first. If the sandbox can't run commands, call it anyway without waiting for anyone, and mention what was lost in your reply.",
12
- "Your next command starts the new sandbox, which clones the repositories and runs setup again, so it takes a while. Check the branch and working tree before going on."
13
- ].join(" "),
14
- inputSchema: z.object({ reason: z.string().trim().min(1).max(500).describe("What went wrong with the sandbox.") }).strict(),
15
- execute: async ({ reason }) => {
16
- const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);
17
- if (!sourceControl) throw new Error("This session has no sandbox to recreate.");
18
- console.warn("[Mastra Factory] Session agent is recreating its sandbox", {
19
- orgId: scope.orgId,
20
- sessionId: scope.sessionId,
21
- reason
22
- });
23
- const outcome = await deps.resetSandbox({
24
- sourceControl,
25
- orgId: scope.orgId,
26
- sessionId: scope.sessionId
27
- });
28
- if (outcome === "not-found") throw new Error("This session has no sandbox to recreate.");
29
- if (outcome === "not-here") throw new Error("This session has no sandbox running yet. Run a command to start one.");
30
- return {
31
- recreated: true,
32
- next: "Your next command starts a fresh sandbox."
33
- };
34
- }
35
- }) };
10
+ return {
11
+ factory_recreate_sandbox: createTool({
12
+ id: "factory_recreate_sandbox",
13
+ description: [
14
+ "Destroy this session's sandbox and replace it with a fresh one. Use it only to recover when the sandbox stops working: commands that time out even for `echo ok`, or errors like \"onStart hook failed\".",
15
+ "This deletes the VM. Everything in it that is not committed and pushed is lost for good: uncommitted and unpushed changes, untracked files, installed dependencies, build output and running processes.",
16
+ "Push what you can first. If the sandbox can't run commands, call it anyway without waiting for anyone, and mention what was lost in your reply.",
17
+ "Your next command starts the new sandbox, which clones the repositories and runs setup again, so it takes a while. Check the branch and working tree before going on."
18
+ ].join(" "),
19
+ inputSchema: z.object({ reason: z.string().trim().min(1).max(500).describe("What went wrong with the sandbox.") }).strict(),
20
+ execute: async ({ reason }) => {
21
+ const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);
22
+ if (!sourceControl) throw new Error("This session has no sandbox to recreate.");
23
+ console.warn("[Mastra Factory] Session agent is recreating its sandbox", {
24
+ orgId: scope.orgId,
25
+ sessionId: scope.sessionId,
26
+ reason
27
+ });
28
+ const outcome = await deps.resetSandbox({
29
+ sourceControl,
30
+ orgId: scope.orgId,
31
+ sessionId: scope.sessionId
32
+ });
33
+ if (outcome === "not-found") throw new Error("This session has no sandbox to recreate.");
34
+ if (outcome === "not-here") throw new Error("This session has no sandbox running yet. Run a command to start one.");
35
+ return {
36
+ recreated: true,
37
+ next: "Your next command starts a fresh sandbox."
38
+ };
39
+ }
40
+ }),
41
+ factory_sandbox_port_url: createTool({
42
+ id: "factory_sandbox_port_url",
43
+ description: [
44
+ "Get the link that opens a port in your sandbox in a browser, so you or the person you are working with can see a server you started there (a dev server, a preview, an API).",
45
+ "Start the server first, in the background and without a timeout, or it may stop.",
46
+ "Dev servers that check the Host header (like Vite) see a different host than the link, so allow all hosts up front, such as Vite's `server.allowedHosts: true`.",
47
+ "The link does not expire, so you can share it. Depending on the sandbox, it may only open for people signed in to your organization.",
48
+ "It also lets your own browser tool open that port for the next hour. If your browser later lands on a sign-in page, call this again."
49
+ ].join(" "),
50
+ inputSchema: z.object({ port: z.number().int().min(1).max(65535).describe("The port the server listens on inside the sandbox.") }).strict(),
51
+ execute: async ({ port }, context) => {
52
+ const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);
53
+ const sandbox = sourceControl && await deps.findSandbox({
54
+ sourceControl,
55
+ orgId: scope.orgId,
56
+ sessionId: scope.sessionId
57
+ });
58
+ if (!sandbox) throw new Error("This session has no sandbox running yet. Run a command to start one.");
59
+ if (!supportsNetworking(sandbox)) throw new Error("This session's sandbox can't expose ports.");
60
+ const url = await sandbox.networking.getPortUrl(port);
61
+ if (!url) throw new Error(`Port ${port} can't be opened from this sandbox.`);
62
+ const threadId = context?.agent?.threadId;
63
+ if (threadId && deps.browser && hasPortAuthCookie(sandbox)) await sandbox.getPortAuthCookie(port).then((cookie) => cookie && deps.browser.setCookies([cookie], threadId)).catch((error) => {
64
+ console.warn("[Mastra Factory] Couldn't sign the session's browser in to a sandbox port", {
65
+ sessionId: scope.sessionId,
66
+ port,
67
+ error: error instanceof Error ? error.message : String(error)
68
+ });
69
+ });
70
+ return { url };
71
+ }
72
+ })
73
+ };
36
74
  }
37
75
  export { createFactorySandboxTools };
38
76
 
@@ -1 +1 @@
1
- {"version":3,"file":"sandbox-tools.js","names":[],"sources":["../../src/tools/sandbox-tools.ts"],"sourcesContent":["import { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport type { IntegrationTools } from '../integrations/base.js';\nimport type { RecreateSessionSandboxInput } from '../sandbox/session-retirement.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactorySandboxToolDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n /** `SessionRetirementCoordinator.resetSessionSandbox`. */\n resetSandbox: (input: RecreateSessionSandboxInput) => Promise<'reset' | 'not-found' | 'not-here'>;\n}\n\n/** Tools a session uses on its own sandbox. Every session with a sandbox gets them. */\nexport function createFactorySandboxTools(\n scope: FactoryToolScope,\n deps: FactorySandboxToolDependencies,\n): IntegrationTools {\n const recreate = createTool({\n id: 'factory_recreate_sandbox',\n description: [\n 'Destroy this session\\'s sandbox and replace it with a fresh one. Use it only to recover when the sandbox stops working: commands that time out even for `echo ok`, or errors like \"onStart hook failed\".',\n 'This deletes the VM. Everything in it that is not committed and pushed is lost for good: uncommitted and unpushed changes, untracked files, installed dependencies, build output and running processes.',\n \"Push what you can first. If the sandbox can't run commands, call it anyway without waiting for anyone, and mention what was lost in your reply.\",\n 'Your next command starts the new sandbox, which clones the repositories and runs setup again, so it takes a while. Check the branch and working tree before going on.',\n ].join(' '),\n inputSchema: z\n .object({\n reason: z.string().trim().min(1).max(500).describe('What went wrong with the sandbox.'),\n })\n .strict(),\n execute: async ({ reason }) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no sandbox to recreate.');\n console.warn('[Mastra Factory] Session agent is recreating its sandbox', {\n orgId: scope.orgId,\n sessionId: scope.sessionId,\n reason,\n });\n const outcome = await deps.resetSandbox({ sourceControl, orgId: scope.orgId, sessionId: scope.sessionId });\n if (outcome === 'not-found') throw new Error('This session has no sandbox to recreate.');\n if (outcome === 'not-here') {\n throw new Error('This session has no sandbox running yet. Run a command to start one.');\n }\n return { recreated: true, next: 'Your next command starts a fresh sandbox.' };\n },\n });\n return { factory_recreate_sandbox: recreate };\n}\n"],"mappings":";;;;AAeA,SAAgB,0BACd,OACA,MACkB;CA8BlB,OAAO,EAAE,0BA7BQ,WAAW;EAC1B,IAAI;EACJ,aAAa;GACX;GACA;GACA;GACA;EACF,CAAC,CAAC,KAAK,GAAG;EACV,aAAa,EACV,OAAO,EACN,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,mCAAmC,EACxF,CAAC,CAAC,CACD,OAAO;EACV,SAAS,OAAO,EAAE,aAAa;GAC7B,MAAM,gBAAgB,MAAM,KAAK,SAAS,4BAA4B,MAAM,SAAS;GACrF,IAAI,CAAC,eAAe,MAAM,IAAI,MAAM,0CAA0C;GAC9E,QAAQ,KAAK,4DAA4D;IACvE,OAAO,MAAM;IACb,WAAW,MAAM;IACjB;GACF,CAAC;GACD,MAAM,UAAU,MAAM,KAAK,aAAa;IAAE;IAAe,OAAO,MAAM;IAAO,WAAW,MAAM;GAAU,CAAC;GACzG,IAAI,YAAY,aAAa,MAAM,IAAI,MAAM,0CAA0C;GACvF,IAAI,YAAY,YACd,MAAM,IAAI,MAAM,sEAAsE;GAExF,OAAO;IAAE,WAAW;IAAM,MAAM;GAA4C;EAC9E;CACF,CAC0C,EAAE;AAC9C"}
1
+ {"version":3,"file":"sandbox-tools.js","names":[],"sources":["../../src/tools/sandbox-tools.ts"],"sourcesContent":["import type { BrowserCookie, MastraBrowser } from '@mastra/core/browser';\nimport { createTool } from '@mastra/core/tools';\nimport { supportsNetworking } from '@mastra/core/workspace';\nimport type { WorkspaceSandbox } from '@mastra/core/workspace';\nimport { z } from 'zod';\n\nimport type { IntegrationTools } from '../integrations/base.js';\nimport type { RecreateSessionSandboxInput } from '../sandbox/session-retirement.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactorySandboxToolDependencies {\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n /** `SessionRetirementCoordinator.resetSessionSandbox`. */\n resetSandbox: (input: RecreateSessionSandboxInput) => Promise<'reset' | 'not-found' | 'not-here'>;\n /** The session's running sandbox, if this process has one. */\n findSandbox: (input: RecreateSessionSandboxInput) => Promise<object | undefined>;\n /** The browser session agents drive, when Factory has one. */\n browser?: MastraBrowser;\n}\n\n/** A sandbox that can sign a browser in to a private port, like `PlatformSandbox`. */\ninterface PortAuthCookieSandbox {\n getPortAuthCookie(port: number): Promise<BrowserCookie | null>;\n}\n\nfunction hasPortAuthCookie(sandbox: object): sandbox is PortAuthCookieSandbox {\n return typeof (sandbox as Partial<PortAuthCookieSandbox>).getPortAuthCookie === 'function';\n}\n\n/** Tools a session uses on its own sandbox. Every session with a sandbox gets them. */\nexport function createFactorySandboxTools(\n scope: FactoryToolScope,\n deps: FactorySandboxToolDependencies,\n): IntegrationTools {\n const recreate = createTool({\n id: 'factory_recreate_sandbox',\n description: [\n 'Destroy this session\\'s sandbox and replace it with a fresh one. Use it only to recover when the sandbox stops working: commands that time out even for `echo ok`, or errors like \"onStart hook failed\".',\n 'This deletes the VM. Everything in it that is not committed and pushed is lost for good: uncommitted and unpushed changes, untracked files, installed dependencies, build output and running processes.',\n \"Push what you can first. If the sandbox can't run commands, call it anyway without waiting for anyone, and mention what was lost in your reply.\",\n 'Your next command starts the new sandbox, which clones the repositories and runs setup again, so it takes a while. Check the branch and working tree before going on.',\n ].join(' '),\n inputSchema: z\n .object({\n reason: z.string().trim().min(1).max(500).describe('What went wrong with the sandbox.'),\n })\n .strict(),\n execute: async ({ reason }) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no sandbox to recreate.');\n console.warn('[Mastra Factory] Session agent is recreating its sandbox', {\n orgId: scope.orgId,\n sessionId: scope.sessionId,\n reason,\n });\n const outcome = await deps.resetSandbox({ sourceControl, orgId: scope.orgId, sessionId: scope.sessionId });\n if (outcome === 'not-found') throw new Error('This session has no sandbox to recreate.');\n if (outcome === 'not-here') {\n throw new Error('This session has no sandbox running yet. Run a command to start one.');\n }\n return { recreated: true, next: 'Your next command starts a fresh sandbox.' };\n },\n });\n\n const portUrl = createTool({\n id: 'factory_sandbox_port_url',\n description: [\n 'Get the link that opens a port in your sandbox in a browser, so you or the person you are working with can see a server you started there (a dev server, a preview, an API).',\n 'Start the server first, in the background and without a timeout, or it may stop.',\n \"Dev servers that check the Host header (like Vite) see a different host than the link, so allow all hosts up front, such as Vite's `server.allowedHosts: true`.\",\n 'The link does not expire, so you can share it. Depending on the sandbox, it may only open for people signed in to your organization.',\n 'It also lets your own browser tool open that port for the next hour. If your browser later lands on a sign-in page, call this again.',\n ].join(' '),\n inputSchema: z\n .object({\n port: z.number().int().min(1).max(65_535).describe('The port the server listens on inside the sandbox.'),\n })\n .strict(),\n execute: async ({ port }, context) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n const sandbox =\n sourceControl && (await deps.findSandbox({ sourceControl, orgId: scope.orgId, sessionId: scope.sessionId }));\n if (!sandbox) throw new Error('This session has no sandbox running yet. Run a command to start one.');\n if (!supportsNetworking(sandbox as WorkspaceSandbox)) {\n throw new Error(\"This session's sandbox can't expose ports.\");\n }\n const url = await (sandbox as WorkspaceSandbox).networking!.getPortUrl(port);\n if (!url) throw new Error(`Port ${port} can't be opened from this sandbox.`);\n // The browser tool can't sign in, so it gets the port auth cookie directly.\n // The cookie never goes back to the model.\n const threadId = context?.agent?.threadId;\n if (threadId && deps.browser && hasPortAuthCookie(sandbox)) {\n // The link works either way; without the cookie the browser just has to sign in.\n await sandbox\n .getPortAuthCookie(port)\n .then(cookie => cookie && deps.browser!.setCookies([cookie], threadId))\n .catch(error => {\n console.warn(\"[Mastra Factory] Couldn't sign the session's browser in to a sandbox port\", {\n sessionId: scope.sessionId,\n port,\n error: error instanceof Error ? error.message : String(error),\n });\n });\n }\n return { url };\n },\n });\n\n return { factory_recreate_sandbox: recreate, factory_sandbox_port_url: portUrl };\n}\n"],"mappings":";;;;AA0BA,SAAS,kBAAkB,SAAmD;CAC5E,OAAO,OAAQ,QAA2C,sBAAsB;AAClF;;AAGA,SAAgB,0BACd,OACA,MACkB;CA2ElB,OAAO;EAAE,0BA1EQ,WAAW;GAC1B,IAAI;GACJ,aAAa;IACX;IACA;IACA;IACA;GACF,CAAC,CAAC,KAAK,GAAG;GACV,aAAa,EACV,OAAO,EACN,QAAQ,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS,mCAAmC,EACxF,CAAC,CAAC,CACD,OAAO;GACV,SAAS,OAAO,EAAE,aAAa;IAC7B,MAAM,gBAAgB,MAAM,KAAK,SAAS,4BAA4B,MAAM,SAAS;IACrF,IAAI,CAAC,eAAe,MAAM,IAAI,MAAM,0CAA0C;IAC9E,QAAQ,KAAK,4DAA4D;KACvE,OAAO,MAAM;KACb,WAAW,MAAM;KACjB;IACF,CAAC;IACD,MAAM,UAAU,MAAM,KAAK,aAAa;KAAE;KAAe,OAAO,MAAM;KAAO,WAAW,MAAM;IAAU,CAAC;IACzG,IAAI,YAAY,aAAa,MAAM,IAAI,MAAM,0CAA0C;IACvF,IAAI,YAAY,YACd,MAAM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Registry } from '../boards/index.js';
7
+ import type { IntakeRoutesReader } from '../boards/intake-routing.js';
7
8
  import type { ProjectBoardSource } from '../boards/project-boards.js';
8
9
  import type { IntegrationTools } from '../integrations/base.js';
9
10
  import type { FactoryTransitionService } from '../rules/transition-service.js';
@@ -16,6 +17,8 @@ export interface FactoryWorkItemToolDependencies {
16
17
  workItems: WorkItemsStorage;
17
18
  /** A fixed registry, or the per-project boards. */
18
19
  boards: BoardRegistry | ProjectBoardSource;
20
+ /** The project's intake routes, which place a filed card. */
21
+ intakeRoutes?: IntakeRoutesReader;
19
22
  /** Governed stage moves; filing and moving items refuse while it is unavailable. */
20
23
  transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;
21
24
  /** Writes audit rows with an explicit actor; tool calls have no HTTP request to read one from. */
@@ -1 +1 @@
1
- {"version":3,"file":"work-item-tools.d.ts","sourceRoot":"","sources":["../../src/tools/work-item-tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGhE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC/E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAEhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAE5E,OAAO,KAAK,EAAoC,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAmBhH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,+BAA+B;IAC9C,SAAS,EAAE,gBAAgB,CAAC;IAC5B,mDAAmD;IACnD,MAAM,EAAE,aAAa,GA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G,kBAAkB,CAAC;IAC3C,6DAA6D;IAC7D,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAClC,oFAAoF;IACpF,iBAAiB,EAAE,IAAI,CAAC,wBAAwB,EAAE,YAAY,CAAC,GAAG,SAAS,CAAC;IAC5E,kGAAkG;IAClG,aAAa,EAAE,aAAa,CAAC;IAC7B,4FAA4F;IAC5F,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC,CAAC;IAC5C,qGAAqG;IACrG,QAAQ,EAAE,IAAI,CAAC,0BAA0B,EAAE,6BAA6B,CAAC,CAAC;CAC3E;AAiCD,8EAA8E;AAC9E,wBAAgB,0BAA0B,CACxC,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,+BAA+B,GACpC,gBAAgB,CAwTlB"}
@@ -97,7 +97,7 @@ function createFactoryWorkItemTools(scope, deps) {
97
97
  return {
98
98
  factory_create_work_item: createTool({
99
99
  id: "factory_create_work_item",
100
- description: "File a new work item on this Factory's Work board for the person you are working with. It lands in the board's first phase, exactly like pressing New card, and this session follows it. Check factory_list_work_items for an existing item first. Name the repository when the Factory links more than one; runs refuse to start on a card that doesn't say which.",
100
+ description: "File a new work item on this Factory's Work board (or wherever the project's intake routes send it) for the person you are working with. It enters its board's first phase, or the phase an intake route names, and this session follows it. Check factory_list_work_items for an existing item first. Name the repository when the Factory links more than one; runs refuse to start on a card that doesn't say which.",
101
101
  inputSchema: z.object({
102
102
  title: z.string().trim().min(1).max(512).describe("Short title, as it should read on the card."),
103
103
  brief: z.string().trim().min(1).max(8e3).describe("What needs doing and why; posted as the first comment on the card."),
@@ -109,6 +109,7 @@ function createFactoryWorkItemTools(scope, deps) {
109
109
  workItems: deps.workItems,
110
110
  boards: await toBoardSource(deps.boards).load(project),
111
111
  transitionService: deps.transitionService,
112
+ intakeRoutes: deps.intakeRoutes,
112
113
  audit,
113
114
  ...project,
114
115
  userId: scope.userId,
@@ -1 +1 @@
1
- {"version":3,"file":"work-item-tools.js","names":[],"sources":["../../src/tools/work-item-tools.ts"],"sourcesContent":["/**\n * Factory tools that change work items: file one, move it, settle its\n * decisions, and follow it. They act as the session's person (a human actor),\n * through the same code the board's routes use.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { boardForWorkItem } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport { toBoardSource } from '../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../boards/project-boards.js';\nimport type { IntegrationTools } from '../integrations/base.js';\nimport { factoryWorkItemUrl } from '../links.js';\nimport { transitionBodySchema } from '../routes/contracts.js';\nimport type { FactoryTransitionService } from '../rules/transition-service.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { CommentsDomain } from '../storage/domains/comments/domain.js';\nimport { WorkItemRelationError } from '../storage/domains/work-items/base.js';\nimport type { UpdateWorkItemInput, WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { createFactoryWorkItem } from '../work-items/create-work-item.js';\nimport type { FactoryAuditEmit } from '../work-items/create-work-item.js';\nimport {\n dismissFactoryDecision,\n resolveFactoryProposal,\n retryFactoryDecision,\n} from '../work-items/decision-actions.js';\nimport type { FactoryDecisionActionResult } from '../work-items/decision-actions.js';\nimport {\n MAX_TEXT,\n findWorkItem,\n workItemRefSchema,\n truncate,\n workItemNotFound,\n workItemNumber,\n workItemStage,\n} from './read-tools.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryWorkItemToolDependencies {\n workItems: WorkItemsStorage;\n /** A fixed registry, or the per-project boards. */\n boards: BoardRegistry | ProjectBoardSource;\n /** Governed stage moves; filing and moving items refuse while it is unavailable. */\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n /** Writes audit rows with an explicit actor; tool calls have no HTTP request to read one from. */\n auditRecorder: AuditRecorder;\n /** The feed's front door: validates, touches open boards and mirrors to linked channels. */\n feed: Pick<CommentsDomain, 'createComment'>;\n /** Finds the caller session's source-control provider, whose linked repositories a card can name. */\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n}\n\nconst repositorySchema = z\n .string()\n .trim()\n .min(3)\n .max(200)\n .regex(/^[^/\\s]+\\/[^/\\s]+$/, 'Use the owner/name form, e.g. \"mastra-ai/mastra\".')\n .describe('A repository linked to this Factory, as owner/name.');\n\nconst decisionId = z.string().trim().uuid().describe('Decision id, from factory_list_attention or inspect.');\n\nfunction briefItem(item: WorkItemRow) {\n return {\n id: item.id,\n number: workItemNumber(item),\n title: truncate(item.title, MAX_TEXT),\n stage: workItemStage(item),\n url:\n factoryWorkItemUrl({\n factoryProjectId: item.factoryProjectId,\n board: boardForWorkItem(item),\n workItemId: item.id,\n }) ?? null,\n };\n}\n\nfunction settled(result: FactoryDecisionActionResult) {\n if (!result.ok) throw new Error(result.message);\n const { decision } = result;\n return { decisionId: decision.id, status: decision.status, workItemId: decision.workItemId };\n}\n\n/** The work-item write and subscription tools for one user session's turn. */\nexport function createFactoryWorkItemTools(\n scope: FactoryToolScope,\n deps: FactoryWorkItemToolDependencies,\n): IntegrationTools {\n const project = { orgId: scope.orgId, factoryProjectId: scope.factoryProjectId };\n const audit: FactoryAuditEmit = async input => {\n await deps.auditRecorder.record({\n orgId: scope.orgId,\n // Turns nobody signed in started are recorded as this session's agent, as their moves are.\n actorId: scope.interactive ? scope.userId : `agent:session:${scope.sessionId}`,\n actorType: scope.interactive ? 'human' : 'agent',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ...input,\n });\n };\n const requireItem = async (ref: string) => {\n const item = await findWorkItem(deps.workItems, scope, ref);\n if (!item) throw workItemNotFound(ref);\n return item;\n };\n /**\n * Check `slug` is a repository linked to this Factory and that a card with\n * `metadata` would run in it (a card synced from an issue follows the\n * issue's repository, which a slug can't override).\n */\n const requireRepository = async (slug: string, metadata: Record<string, unknown> | null = null) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no source-control provider to look repositories up in.');\n const resolve = (repository?: string) =>\n resolveWorkItemRepository({\n sourceControl,\n ...project,\n item: { metadata: repository ? { ...metadata, repository } : metadata },\n });\n const resolution = await resolve(slug);\n if (resolution.status === 'resolved' && resolution.slug === slug) return;\n if (resolution.status === 'resolved') {\n throw new Error(`This card runs in ${resolution.slug}, which comes from its linked issue and can't be changed.`);\n }\n const linked = await resolve();\n const candidates =\n linked.status === 'ambiguous' ? linked.candidates : linked.status === 'resolved' ? [linked.slug] : [];\n throw new Error(\n candidates.length > 0\n ? `${slug} is not linked to this Factory. Linked repositories: ${candidates.join(', ')}.`\n : `${slug} is not linked to this Factory, and it has no linked repositories.`,\n );\n };\n const follow = (item: WorkItemRow, reason: 'created' | 'subscribed') =>\n deps.workItems.subscribeToWorkItem({\n ...project,\n workItemId: item.id,\n sessionId: scope.sessionId,\n threadId: scope.threadId,\n resourceId: scope.resourceId,\n userId: scope.userId,\n reason,\n });\n\n return {\n factory_create_work_item: createTool({\n id: 'factory_create_work_item',\n description:\n \"File a new work item on this Factory's Work board for the person you are working with. It lands in the board's first phase, exactly like pressing New card, and this session follows it. Check factory_list_work_items for an existing item first. Name the repository when the Factory links more than one; runs refuse to start on a card that doesn't say which.\",\n inputSchema: z\n .object({\n title: z.string().trim().min(1).max(512).describe('Short title, as it should read on the card.'),\n brief: z\n .string()\n .trim()\n .min(1)\n .max(8000)\n .describe('What needs doing and why; posted as the first comment on the card.'),\n repository: repositorySchema.optional(),\n })\n .strict(),\n execute: async ({ title, brief, repository }) => {\n if (repository) await requireRepository(repository);\n const created = await createFactoryWorkItem({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n transitionService: deps.transitionService,\n audit,\n ...project,\n userId: scope.userId,\n ...(scope.actorProfile ? { origin: { actorProfile: scope.actorProfile } } : {}),\n input: { title, ...(repository ? { metadata: { repository } } : {}) },\n });\n if (created.status === 'refused') throw new Error(created.message);\n if (created.status === 'rejected') throw new Error(`The board refused the new item: ${created.reason}`);\n const { item } = created;\n // The card exists from here on: report follow-up failures alongside it\n // rather than failing the call, so the agent doesn't file it twice.\n const warnings: string[] = [];\n try {\n const comment = await deps.feed.createComment({\n orgId: scope.orgId,\n workItemId: item.id,\n author: { kind: 'user', id: scope.userId },\n body: brief,\n });\n if (comment.status !== 'created') {\n warnings.push(\n `The brief was not posted (${comment.status === 'invalid' ? comment.message : comment.status}).`,\n );\n }\n } catch (error) {\n warnings.push(`The brief was not posted: ${error instanceof Error ? error.message : String(error)}`);\n }\n try {\n await follow(item, 'created');\n } catch (error) {\n warnings.push(\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n return warnings.length ? { ...briefItem(item), warnings } : briefItem(item);\n },\n }),\n\n factory_transition_work_item: createTool({\n id: 'factory_transition_work_item',\n description:\n \"Move a work item to another stage of its board, as the person you are working with. The board's rules decide whether the move is allowed and what it starts.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n stage: z.string().trim().min(1).max(64).describe('Destination stage, e.g. \"planning\" or \"done\".'),\n })\n .strict(),\n execute: async ({ workItem, stage }) => {\n if (!deps.transitionService) throw new Error('Factory stage transitions are not available right now.');\n const item = await requireItem(workItem);\n const parsed = transitionBodySchema.safeParse({\n board: boardForWorkItem(item),\n stage,\n expectedRevision: item.revision,\n requestId: randomUUID(),\n cause: 'factory_tools',\n });\n if (!parsed.success) throw new Error(`\"${stage}\" is not a valid stage name.`);\n const result = await deps.transitionService.transition({\n ...parsed.data,\n ...project,\n workItemId: item.id,\n ...(scope.interactive\n ? {\n actor: { type: 'human' as const, id: scope.userId },\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ingress: { ...parsed.data.ingress, identity: `human:${scope.userId}:${parsed.data.ingress.identity}` },\n }\n : {\n // Nobody signed in started this turn: move as this session's agent, so the\n // plan gate and the agent's done gates apply and the move arms no runs.\n actor: { type: 'agent' as const, bindingId: `session:${scope.sessionId}`, role: 'session' },\n ingress: {\n type: 'agent' as const,\n identity: `session:${scope.sessionId}:${parsed.data.ingress.identity}`,\n },\n }),\n });\n if (result.status === 'rejected') throw new Error(`The move was refused (${result.code}): ${result.reason}`);\n return { workItemId: item.id, stage: result.stage, revision: result.revision };\n },\n }),\n\n factory_update_work_item: createTool({\n id: 'factory_update_work_item',\n description:\n \"Edit a work item's fields as the person you are working with: its title, the repository its runs use, its parent item, or pre-approving its plans. Move stages with factory_transition_work_item and start roles with factory_start_session; post to the card's feed for anything else.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n title: z.string().trim().min(1).max(500).optional().describe('New card title.'),\n repository: repositorySchema.optional(),\n parentWorkItem: workItemRefSchema\n .nullable()\n .optional()\n .describe('Parent work item (id or #number), or null to detach it from its parent.'),\n plansPreapproved: z\n .literal(true)\n .optional()\n .describe(\n \"Pre-approve the item's plans, so its runs no longer stop for plan approval. Can't be undone here.\",\n ),\n })\n .strict()\n .refine(input => Object.keys(input).some(key => key !== 'workItem'), 'Pass at least one field to change.'),\n execute: async ({ workItem, title, repository, parentWorkItem, plansPreapproved }) => {\n // Pre-approval drops the plan-approval gate for good, so it is the person's call.\n if (plansPreapproved) requirePerson(scope, 'pre-approve plans');\n const item = await requireItem(workItem);\n if (repository) await requireRepository(repository, item.metadata);\n let parentWorkItemId: string | null | undefined;\n if (parentWorkItem === null) parentWorkItemId = null;\n else if (parentWorkItem !== undefined) parentWorkItemId = (await requireItem(parentWorkItem)).id;\n const patch: UpdateWorkItemInput = {\n ...(title !== undefined ? { title } : {}),\n ...(repository ? { metadata: { repository } } : {}),\n ...(parentWorkItemId !== undefined ? { parentWorkItemId } : {}),\n ...(plansPreapproved ? { plansPreapproved } : {}),\n };\n let updated: Awaited<ReturnType<WorkItemsStorage['update']>>;\n try {\n updated = await deps.workItems.update({ orgId: scope.orgId, id: item.id, userId: scope.userId, patch });\n } catch (error) {\n if (error instanceof WorkItemRelationError) throw new Error(`The parent was refused: ${error.message}`);\n throw error;\n }\n if (!updated) throw workItemNotFound(workItem);\n const fields = [\n ...(title !== undefined ? ['title'] : []),\n ...(repository ? ['metadata'] : []),\n ...(parentWorkItemId !== undefined ? ['parentWorkItemId'] : []),\n ...(plansPreapproved ? ['plansPreapproved'] : []),\n ];\n await audit({\n action: 'factory.work_item.updated',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'work_item', id: updated.item.id, name: updated.item.title }],\n metadata: { fields, cause: 'factory_tools' },\n });\n const metadata = updated.item.metadata ?? {};\n return {\n workItem: briefItem(updated.item),\n updated: fields.map(field => (field === 'metadata' ? 'repository' : field)),\n repository: typeof metadata.repository === 'string' ? metadata.repository : null,\n parentWorkItemId: updated.item.parentWorkItemId,\n plansPreapproved: updated.item.plansPreapprovedAt !== null,\n };\n },\n }),\n\n factory_retry_decision: createTool({\n id: 'factory_retry_decision',\n description:\n 'Retry one failed Factory run once its cause is fixed. Refused when the failure cannot be fixed by retrying or the item has moved on.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) =>\n settled(\n await retryFactoryDecision({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n ...project,\n decisionId,\n }),\n ),\n }),\n\n factory_dismiss_decision: createTool({\n id: 'factory_dismiss_decision',\n description: 'Dismiss one proposed Factory run that is no longer wanted.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) => {\n requirePerson(scope, 'dismiss a proposed run');\n return settled(\n await dismissFactoryDecision({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n }),\n );\n },\n }),\n\n factory_resolve_proposal: createTool({\n id: 'factory_resolve_proposal',\n description:\n \"Approve or dismiss one proposed Factory run. Approving starts the run and lets the item's later runs start without asking.\",\n inputSchema: z.object({ decisionId, action: z.enum(['approve', 'dismiss']) }).strict(),\n execute: async ({ decisionId, action }) => {\n requirePerson(scope, 'approve or dismiss a proposed run');\n return settled(\n await resolveFactoryProposal({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n action,\n }),\n );\n },\n }),\n\n factory_subscribe_work_item: createTool({\n id: 'factory_subscribe_work_item',\n description:\n 'Follow a work item from this session, so you hear about its progress and its sessions report to you. Items you file or start are followed already.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const subscription = await follow(item, 'subscribed');\n return { workItem: briefItem(item), subscribed: true, reason: subscription.reason };\n },\n }),\n\n factory_unsubscribe_work_item: createTool({\n id: 'factory_unsubscribe_work_item',\n description: 'Stop following a work item from this session.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const removed = await deps.workItems.unsubscribeFromWorkItem({\n orgId: scope.orgId,\n workItemId: item.id,\n sessionId: scope.sessionId,\n });\n return { workItem: briefItem(item), subscribed: false, wasSubscribed: removed };\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA0DA,MAAM,mBAAmB,EACtB,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,sBAAsB,qDAAmD,CAAC,CAChF,SAAS,qDAAqD;AAEjE,MAAM,aAAa,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,sDAAsD;AAE3G,SAAS,UAAU,MAAmB;CACpC,OAAO;EACL,IAAI,KAAK;EACT,QAAQ,eAAe,IAAI;EAC3B,OAAO,SAAS,KAAK,OAAA,GAAe;EACpC,OAAO,cAAc,IAAI;EACzB,KACE,mBAAmB;GACjB,kBAAkB,KAAK;GACvB,OAAO,iBAAiB,IAAI;GAC5B,YAAY,KAAK;EACnB,CAAC,KAAK;CACV;AACF;AAEA,SAAS,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Ae;IAC/B,MAAM,OAAO,MAAM,YAAY,QAAQ;IACvC,MAAM,eAAe,MAAM,OAAO,MAAM,YAAY;IACpD,OAAO;KAAE,UAAU,UAAU,IAAI;KAAG,YAAY;KAAM,QAAQ,aAAa;IAAO;GACpF;EACF,CAAC;EAED,+BAA+B,WAAW;GACxC,IAAI;GACJ,aAAa;GACb,aAAa,EAAE,OAAO,EAAE,UAAU,kBAAkB,CAAC,CAAC,CAAC,OAAO;GAC9D,SAAS,OAAO,EAAE,eAAe;IAC/B,MAAM,OAAO,MAAM,YAAY,QAAQ;IACvC,MAAM,UAAU,MAAM,KAAK,UAAU,wBAAwB;KAC3D,OAAO,MAAM;KACb,YAAY,KAAK;KACjB,WAAW,MAAM;IACnB,CAAC;IACD,OAAO;KAAE,UAAU,UAAU,IAAI;KAAG,YAAY;KAAO,eAAe;IAAQ;GAChF;EACF,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"work-item-tools.js","names":[],"sources":["../../src/tools/work-item-tools.ts"],"sourcesContent":["/**\n * Factory tools that change work items: file one, move it, settle its\n * decisions, and follow it. They act as the session's person (a human actor),\n * through the same code the board's routes use.\n */\n\nimport { randomUUID } from 'node:crypto';\nimport { createTool } from '@mastra/core/tools';\nimport { z } from 'zod';\n\nimport { boardForWorkItem } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { IntakeRoutesReader } from '../boards/intake-routing.js';\nimport { toBoardSource } from '../boards/project-boards.js';\nimport type { ProjectBoardSource } from '../boards/project-boards.js';\nimport type { IntegrationTools } from '../integrations/base.js';\nimport { factoryWorkItemUrl } from '../links.js';\nimport { transitionBodySchema } from '../routes/contracts.js';\nimport type { FactoryTransitionService } from '../rules/transition-service.js';\nimport type { SourceControlSessionLookup } from '../session/factory-session.js';\nimport { resolveWorkItemRepository } from '../session/work-item-repository.js';\nimport type { AuditRecorder } from '../storage/domains/audit/domain.js';\nimport type { CommentsDomain } from '../storage/domains/comments/domain.js';\nimport { WorkItemRelationError } from '../storage/domains/work-items/base.js';\nimport type { UpdateWorkItemInput, WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';\nimport { createFactoryWorkItem } from '../work-items/create-work-item.js';\nimport type { FactoryAuditEmit } from '../work-items/create-work-item.js';\nimport {\n dismissFactoryDecision,\n resolveFactoryProposal,\n retryFactoryDecision,\n} from '../work-items/decision-actions.js';\nimport type { FactoryDecisionActionResult } from '../work-items/decision-actions.js';\nimport {\n MAX_TEXT,\n findWorkItem,\n workItemRefSchema,\n truncate,\n workItemNotFound,\n workItemNumber,\n workItemStage,\n} from './read-tools.js';\nimport { requirePerson } from './scope.js';\nimport type { FactoryToolScope } from './scope.js';\n\nexport interface FactoryWorkItemToolDependencies {\n workItems: WorkItemsStorage;\n /** A fixed registry, or the per-project boards. */\n boards: BoardRegistry | ProjectBoardSource;\n /** The project's intake routes, which place a filed card. */\n intakeRoutes?: IntakeRoutesReader;\n /** Governed stage moves; filing and moving items refuse while it is unavailable. */\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n /** Writes audit rows with an explicit actor; tool calls have no HTTP request to read one from. */\n auditRecorder: AuditRecorder;\n /** The feed's front door: validates, touches open boards and mirrors to linked channels. */\n feed: Pick<CommentsDomain, 'createComment'>;\n /** Finds the caller session's source-control provider, whose linked repositories a card can name. */\n sessions: Pick<SourceControlSessionLookup, 'getSourceControlBySessionId'>;\n}\n\nconst repositorySchema = z\n .string()\n .trim()\n .min(3)\n .max(200)\n .regex(/^[^/\\s]+\\/[^/\\s]+$/, 'Use the owner/name form, e.g. \"mastra-ai/mastra\".')\n .describe('A repository linked to this Factory, as owner/name.');\n\nconst decisionId = z.string().trim().uuid().describe('Decision id, from factory_list_attention or inspect.');\n\nfunction briefItem(item: WorkItemRow) {\n return {\n id: item.id,\n number: workItemNumber(item),\n title: truncate(item.title, MAX_TEXT),\n stage: workItemStage(item),\n url:\n factoryWorkItemUrl({\n factoryProjectId: item.factoryProjectId,\n board: boardForWorkItem(item),\n workItemId: item.id,\n }) ?? null,\n };\n}\n\nfunction settled(result: FactoryDecisionActionResult) {\n if (!result.ok) throw new Error(result.message);\n const { decision } = result;\n return { decisionId: decision.id, status: decision.status, workItemId: decision.workItemId };\n}\n\n/** The work-item write and subscription tools for one user session's turn. */\nexport function createFactoryWorkItemTools(\n scope: FactoryToolScope,\n deps: FactoryWorkItemToolDependencies,\n): IntegrationTools {\n const project = { orgId: scope.orgId, factoryProjectId: scope.factoryProjectId };\n const audit: FactoryAuditEmit = async input => {\n await deps.auditRecorder.record({\n orgId: scope.orgId,\n // Turns nobody signed in started are recorded as this session's agent, as their moves are.\n actorId: scope.interactive ? scope.userId : `agent:session:${scope.sessionId}`,\n actorType: scope.interactive ? 'human' : 'agent',\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ...input,\n });\n };\n const requireItem = async (ref: string) => {\n const item = await findWorkItem(deps.workItems, scope, ref);\n if (!item) throw workItemNotFound(ref);\n return item;\n };\n /**\n * Check `slug` is a repository linked to this Factory and that a card with\n * `metadata` would run in it (a card synced from an issue follows the\n * issue's repository, which a slug can't override).\n */\n const requireRepository = async (slug: string, metadata: Record<string, unknown> | null = null) => {\n const sourceControl = await deps.sessions.getSourceControlBySessionId(scope.sessionId);\n if (!sourceControl) throw new Error('This session has no source-control provider to look repositories up in.');\n const resolve = (repository?: string) =>\n resolveWorkItemRepository({\n sourceControl,\n ...project,\n item: { metadata: repository ? { ...metadata, repository } : metadata },\n });\n const resolution = await resolve(slug);\n if (resolution.status === 'resolved' && resolution.slug === slug) return;\n if (resolution.status === 'resolved') {\n throw new Error(`This card runs in ${resolution.slug}, which comes from its linked issue and can't be changed.`);\n }\n const linked = await resolve();\n const candidates =\n linked.status === 'ambiguous' ? linked.candidates : linked.status === 'resolved' ? [linked.slug] : [];\n throw new Error(\n candidates.length > 0\n ? `${slug} is not linked to this Factory. Linked repositories: ${candidates.join(', ')}.`\n : `${slug} is not linked to this Factory, and it has no linked repositories.`,\n );\n };\n const follow = (item: WorkItemRow, reason: 'created' | 'subscribed') =>\n deps.workItems.subscribeToWorkItem({\n ...project,\n workItemId: item.id,\n sessionId: scope.sessionId,\n threadId: scope.threadId,\n resourceId: scope.resourceId,\n userId: scope.userId,\n reason,\n });\n\n return {\n factory_create_work_item: createTool({\n id: 'factory_create_work_item',\n description:\n \"File a new work item on this Factory's Work board (or wherever the project's intake routes send it) for the person you are working with. It enters its board's first phase, or the phase an intake route names, and this session follows it. Check factory_list_work_items for an existing item first. Name the repository when the Factory links more than one; runs refuse to start on a card that doesn't say which.\",\n inputSchema: z\n .object({\n title: z.string().trim().min(1).max(512).describe('Short title, as it should read on the card.'),\n brief: z\n .string()\n .trim()\n .min(1)\n .max(8000)\n .describe('What needs doing and why; posted as the first comment on the card.'),\n repository: repositorySchema.optional(),\n })\n .strict(),\n execute: async ({ title, brief, repository }) => {\n if (repository) await requireRepository(repository);\n const created = await createFactoryWorkItem({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n transitionService: deps.transitionService,\n intakeRoutes: deps.intakeRoutes,\n audit,\n ...project,\n userId: scope.userId,\n ...(scope.actorProfile ? { origin: { actorProfile: scope.actorProfile } } : {}),\n input: { title, ...(repository ? { metadata: { repository } } : {}) },\n });\n if (created.status === 'refused') throw new Error(created.message);\n if (created.status === 'rejected') throw new Error(`The board refused the new item: ${created.reason}`);\n const { item } = created;\n // The card exists from here on: report follow-up failures alongside it\n // rather than failing the call, so the agent doesn't file it twice.\n const warnings: string[] = [];\n try {\n const comment = await deps.feed.createComment({\n orgId: scope.orgId,\n workItemId: item.id,\n author: { kind: 'user', id: scope.userId },\n body: brief,\n });\n if (comment.status !== 'created') {\n warnings.push(\n `The brief was not posted (${comment.status === 'invalid' ? comment.message : comment.status}).`,\n );\n }\n } catch (error) {\n warnings.push(`The brief was not posted: ${error instanceof Error ? error.message : String(error)}`);\n }\n try {\n await follow(item, 'created');\n } catch (error) {\n warnings.push(\n `This session does not follow it yet: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n return warnings.length ? { ...briefItem(item), warnings } : briefItem(item);\n },\n }),\n\n factory_transition_work_item: createTool({\n id: 'factory_transition_work_item',\n description:\n \"Move a work item to another stage of its board, as the person you are working with. The board's rules decide whether the move is allowed and what it starts.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n stage: z.string().trim().min(1).max(64).describe('Destination stage, e.g. \"planning\" or \"done\".'),\n })\n .strict(),\n execute: async ({ workItem, stage }) => {\n if (!deps.transitionService) throw new Error('Factory stage transitions are not available right now.');\n const item = await requireItem(workItem);\n const parsed = transitionBodySchema.safeParse({\n board: boardForWorkItem(item),\n stage,\n expectedRevision: item.revision,\n requestId: randomUUID(),\n cause: 'factory_tools',\n });\n if (!parsed.success) throw new Error(`\"${stage}\" is not a valid stage name.`);\n const result = await deps.transitionService.transition({\n ...parsed.data,\n ...project,\n workItemId: item.id,\n ...(scope.interactive\n ? {\n actor: { type: 'human' as const, id: scope.userId },\n ...(scope.actorProfile ? { actorProfile: scope.actorProfile } : {}),\n ingress: { ...parsed.data.ingress, identity: `human:${scope.userId}:${parsed.data.ingress.identity}` },\n }\n : {\n // Nobody signed in started this turn: move as this session's agent, so the\n // plan gate and the agent's done gates apply and the move arms no runs.\n actor: { type: 'agent' as const, bindingId: `session:${scope.sessionId}`, role: 'session' },\n ingress: {\n type: 'agent' as const,\n identity: `session:${scope.sessionId}:${parsed.data.ingress.identity}`,\n },\n }),\n });\n if (result.status === 'rejected') throw new Error(`The move was refused (${result.code}): ${result.reason}`);\n return { workItemId: item.id, stage: result.stage, revision: result.revision };\n },\n }),\n\n factory_update_work_item: createTool({\n id: 'factory_update_work_item',\n description:\n \"Edit a work item's fields as the person you are working with: its title, the repository its runs use, its parent item, or pre-approving its plans. Move stages with factory_transition_work_item and start roles with factory_start_session; post to the card's feed for anything else.\",\n inputSchema: z\n .object({\n workItem: workItemRefSchema,\n title: z.string().trim().min(1).max(500).optional().describe('New card title.'),\n repository: repositorySchema.optional(),\n parentWorkItem: workItemRefSchema\n .nullable()\n .optional()\n .describe('Parent work item (id or #number), or null to detach it from its parent.'),\n plansPreapproved: z\n .literal(true)\n .optional()\n .describe(\n \"Pre-approve the item's plans, so its runs no longer stop for plan approval. Can't be undone here.\",\n ),\n })\n .strict()\n .refine(input => Object.keys(input).some(key => key !== 'workItem'), 'Pass at least one field to change.'),\n execute: async ({ workItem, title, repository, parentWorkItem, plansPreapproved }) => {\n // Pre-approval drops the plan-approval gate for good, so it is the person's call.\n if (plansPreapproved) requirePerson(scope, 'pre-approve plans');\n const item = await requireItem(workItem);\n if (repository) await requireRepository(repository, item.metadata);\n let parentWorkItemId: string | null | undefined;\n if (parentWorkItem === null) parentWorkItemId = null;\n else if (parentWorkItem !== undefined) parentWorkItemId = (await requireItem(parentWorkItem)).id;\n const patch: UpdateWorkItemInput = {\n ...(title !== undefined ? { title } : {}),\n ...(repository ? { metadata: { repository } } : {}),\n ...(parentWorkItemId !== undefined ? { parentWorkItemId } : {}),\n ...(plansPreapproved ? { plansPreapproved } : {}),\n };\n let updated: Awaited<ReturnType<WorkItemsStorage['update']>>;\n try {\n updated = await deps.workItems.update({ orgId: scope.orgId, id: item.id, userId: scope.userId, patch });\n } catch (error) {\n if (error instanceof WorkItemRelationError) throw new Error(`The parent was refused: ${error.message}`);\n throw error;\n }\n if (!updated) throw workItemNotFound(workItem);\n const fields = [\n ...(title !== undefined ? ['title'] : []),\n ...(repository ? ['metadata'] : []),\n ...(parentWorkItemId !== undefined ? ['parentWorkItemId'] : []),\n ...(plansPreapproved ? ['plansPreapproved'] : []),\n ];\n await audit({\n action: 'factory.work_item.updated',\n factoryProjectId: scope.factoryProjectId,\n targets: [{ type: 'work_item', id: updated.item.id, name: updated.item.title }],\n metadata: { fields, cause: 'factory_tools' },\n });\n const metadata = updated.item.metadata ?? {};\n return {\n workItem: briefItem(updated.item),\n updated: fields.map(field => (field === 'metadata' ? 'repository' : field)),\n repository: typeof metadata.repository === 'string' ? metadata.repository : null,\n parentWorkItemId: updated.item.parentWorkItemId,\n plansPreapproved: updated.item.plansPreapprovedAt !== null,\n };\n },\n }),\n\n factory_retry_decision: createTool({\n id: 'factory_retry_decision',\n description:\n 'Retry one failed Factory run once its cause is fixed. Refused when the failure cannot be fixed by retrying or the item has moved on.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) =>\n settled(\n await retryFactoryDecision({\n workItems: deps.workItems,\n boards: await toBoardSource(deps.boards).load(project),\n ...project,\n decisionId,\n }),\n ),\n }),\n\n factory_dismiss_decision: createTool({\n id: 'factory_dismiss_decision',\n description: 'Dismiss one proposed Factory run that is no longer wanted.',\n inputSchema: z.object({ decisionId }).strict(),\n execute: async ({ decisionId }) => {\n requirePerson(scope, 'dismiss a proposed run');\n return settled(\n await dismissFactoryDecision({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n }),\n );\n },\n }),\n\n factory_resolve_proposal: createTool({\n id: 'factory_resolve_proposal',\n description:\n \"Approve or dismiss one proposed Factory run. Approving starts the run and lets the item's later runs start without asking.\",\n inputSchema: z.object({ decisionId, action: z.enum(['approve', 'dismiss']) }).strict(),\n execute: async ({ decisionId, action }) => {\n requirePerson(scope, 'approve or dismiss a proposed run');\n return settled(\n await resolveFactoryProposal({\n workItems: deps.workItems,\n audit,\n ...project,\n userId: scope.userId,\n decisionId,\n action,\n }),\n );\n },\n }),\n\n factory_subscribe_work_item: createTool({\n id: 'factory_subscribe_work_item',\n description:\n 'Follow a work item from this session, so you hear about its progress and its sessions report to you. Items you file or start are followed already.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const subscription = await follow(item, 'subscribed');\n return { workItem: briefItem(item), subscribed: true, reason: subscription.reason };\n },\n }),\n\n factory_unsubscribe_work_item: createTool({\n id: 'factory_unsubscribe_work_item',\n description: 'Stop following a work item from this session.',\n inputSchema: z.object({ workItem: workItemRefSchema }).strict(),\n execute: async ({ workItem }) => {\n const item = await requireItem(workItem);\n const removed = await deps.workItems.unsubscribeFromWorkItem({\n orgId: scope.orgId,\n workItemId: item.id,\n sessionId: scope.sessionId,\n });\n return { workItem: briefItem(item), subscribed: false, wasSubscribed: removed };\n },\n }),\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA6DA,MAAM,mBAAmB,EACtB,OAAO,CAAC,CACR,KAAK,CAAC,CACN,IAAI,CAAC,CAAC,CACN,IAAI,GAAG,CAAC,CACR,MAAM,sBAAsB,qDAAmD,CAAC,CAChF,SAAS,qDAAqD;AAEjE,MAAM,aAAa,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,SAAS,sDAAsD;AAE3G,SAAS,UAAU,MAAmB;CACpC,OAAO;EACL,IAAI,KAAK;EACT,QAAQ,eAAe,IAAI;EAC3B,OAAO,SAAS,KAAK,OAAA,GAAe;EACpC,OAAO,cAAc,IAAI;EACzB,KACE,mBAAmB;GACjB,kBAAkB,KAAK;GACvB,OAAO,iBAAiB,IAAI;GAC5B,YAAY,KAAK;EACnB,CAAC,KAAK;CACV;AACF;AAEA,SAAS,QAAQ,QAAqC;CACpD,IAAI,CAAC,OAAO,IAAI,MAAM,IAAI,MAAM,OAAO,OAAO;CAC9C,MAAM,EAAE,aAAa;CACrB,OAAO;EAAE,YAAY,SAAS;EAAI,QAAQ,SAAS;EAAQ,YAAY,SAAS;CAAW;AAC7F;;AAGA,SAAgB,2BACd,OACA,MACkB;CAClB,MAAM,UAAU;EAAE,OAAO,MAAM;EAAO,kBAAkB,MAAM;CAAiB;CAC/E,MAAM,QAA0B,OAAM,UAAS;EAC7C,MAAM,KAAK,cAAc,OAAO;GAC9B,OAAO,MAAM;GAEb,SAAS,MAAM,cAAc,MAAM,SAAS,iBAAiB,MAAM;GACnE,WAAW,MAAM,cAAc,UAAU;GACzC,GAAI,MAAM,eAAe,EAAE,cAAc,MAAM,aAAa,IAAI,CAAC;GACjE,GAA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U,IAAI;KAAG,YAAY;KAAO,eAAe;IAAQ;GAChF;EACF,CAAC;CACH;AACF"}
@@ -3,6 +3,7 @@
3
3
  * so a card filed from a session goes through exactly what "New card" does.
4
4
  */
5
5
  import type { BoardRegistry } from '../boards/index.js';
6
+ import type { IntakeRoutesReader } from '../boards/intake-routing.js';
6
7
  import type { FactoryTransitionRequest, FactoryTransitionService } from '../rules/transition-service.js';
7
8
  import type { EmitAuditInput } from '../storage/domains/audit/domain.js';
8
9
  import type { CreateWorkItemInput, WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';
@@ -24,7 +25,7 @@ export type CreateFactoryWorkItemResult =
24
25
  code: 'invalid_board' | 'governed_transition_required' | 'factory_transitions_unavailable';
25
26
  message: string;
26
27
  }
27
- /** The first phase's entry rules refused the card; it was removed again. */
28
+ /** The first phase's entry rules (or the move to an intake route's phase) refused the card; it was removed again. */
28
29
  | {
29
30
  status: 'rejected';
30
31
  code: Extract<TransitionResult, {
@@ -42,6 +43,8 @@ export interface CreateFactoryWorkItemArgs {
42
43
  userId: string;
43
44
  factoryProjectId: string;
44
45
  input: CreateWorkItemInput;
46
+ /** The project's intake routes; they place a card filed without a board or stages. */
47
+ intakeRoutes?: IntakeRoutesReader;
45
48
  /** Where a browser request came from; a session's tool call carries none. */
46
49
  origin?: Pick<FactoryTransitionRequest, 'actorProfile' | 'context'>;
47
50
  }
@@ -50,6 +53,6 @@ export interface CreateFactoryWorkItemArgs {
50
53
  * person (rolling the card back if its entry rules refuse it), then audits
51
54
  * `factory.work_item.created`. Throws `WorkItemRelationError` for a bad parent.
52
55
  */
53
- export declare function createFactoryWorkItem({ workItems, boards, transitionService, audit, orgId, userId, factoryProjectId, input, origin, }: CreateFactoryWorkItemArgs): Promise<CreateFactoryWorkItemResult>;
56
+ export declare function createFactoryWorkItem({ workItems, boards, transitionService, audit, orgId, userId, factoryProjectId, input, intakeRoutes, origin, }: CreateFactoryWorkItemArgs): Promise<CreateFactoryWorkItemResult>;
54
57
  export {};
55
58
  //# sourceMappingURL=create-work-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-work-item.d.ts","sourceRoot":"","sources":["../../src/work-items/create-work-item.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,KAAK,EAAE,wBAAwB,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AACzG,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,KAAK,EAAE,mBAAmB,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AAEhH,4GAA4G;AAC5G,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAExE,KAAK,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC,wBAAwB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;AAEpF,MAAM,MAAM,2BAA2B;AACrC,oEAAoE;AAClE;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE;AAC1C,wGAAwG;GACtG;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACvC;IACE,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,eAAe,GAAG,8BAA8B,GAAG,iCAAiC,CAAC;IAC3F,OAAO,EAAE,MAAM,CAAC;CACjB;AACH,4EAA4E;GAC1E;IAAE,MAAM,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,OAAO,CAAC,gBAAgB,EAAE;QAAE,MAAM,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5G,MAAM,WAAW,yBAAyB;IACxC,SAAS,EAAE,gBAAgB,CAAC;IAC5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,CAwGlE"}
@@ -1,11 +1,26 @@
1
+ import { cardRuleFacts } from "../boards/card-facts.js";
2
+ import "../boards/index.js";
3
+ import { resolveIntakePlacement } from "../boards/intake-routing.js";
1
4
  // src/work-items/create-work-item.ts
2
5
  /**
6
+ * Filing a work item, shared by the board's create route and the Factory tools
7
+ * so a card filed from a session goes through exactly what "New card" does.
8
+ */
9
+ /**
3
10
  * Upserts the card into its board's first phase, enters that phase as the
4
11
  * person (rolling the card back if its entry rules refuse it), then audits
5
12
  * `factory.work_item.created`. Throws `WorkItemRelationError` for a bad parent.
6
13
  */
7
- async function createFactoryWorkItem({ workItems, boards, transitionService, audit, orgId, userId, factoryProjectId, input, origin }) {
8
- const boardId = input.board ?? (input.externalSource?.type === "pull-request" ? "review" : "work");
14
+ async function createFactoryWorkItem({ workItems, boards, transitionService, audit, orgId, userId, factoryProjectId, input, intakeRoutes, origin }) {
15
+ const placement = intakeRoutes && input.board === void 0 && input.stages === void 0 ? resolveIntakePlacement(await intakeRoutes.listIntakeRoutes({
16
+ orgId,
17
+ factoryProjectId
18
+ }), cardRuleFacts({
19
+ title: input.title,
20
+ metadata: input.metadata ?? null,
21
+ externalSource: input.externalSource ?? null
22
+ }), boards) : void 0;
23
+ const boardId = placement?.board ?? input.board ?? "work";
9
24
  const board = boards.get(boardId);
10
25
  if (!board) return {
11
26
  status: "refused",
@@ -34,7 +49,13 @@ async function createFactoryWorkItem({ workItems, boards, transitionService, aud
34
49
  status: "reused",
35
50
  item: result.item
36
51
  };
37
- const created = result.item;
52
+ const created = placement ? (await workItems.update({
53
+ orgId,
54
+ id: result.item.id,
55
+ userId,
56
+ patch: { metadata: { ["intakeRouteId"]: placement.routeId } },
57
+ expectedRevision: result.item.revision
58
+ }))?.item ?? result.item : result.item;
38
59
  if (!transitionService) {
39
60
  await workItems.delete({
40
61
  orgId,
@@ -76,6 +97,36 @@ async function createFactoryWorkItem({ workItems, boards, transitionService, aud
76
97
  reason: entered.reason
77
98
  };
78
99
  }
100
+ if (placement && placement.phase !== board.initialPhase) {
101
+ const moved = await transitionService.transition({
102
+ orgId,
103
+ factoryProjectId,
104
+ workItemId: created.id,
105
+ board: boardId,
106
+ stage: placement.phase,
107
+ expectedRevision: entered.revision,
108
+ actor: {
109
+ type: "system",
110
+ id: "factory-intake-route"
111
+ },
112
+ ingress: {
113
+ type: "rule",
114
+ identity: `work-item:${created.id}:intake-route`
115
+ },
116
+ cause: "work_item_created"
117
+ });
118
+ if (moved.status === "rejected") {
119
+ await workItems.delete({
120
+ orgId,
121
+ id: created.id
122
+ });
123
+ return {
124
+ status: "rejected",
125
+ code: moved.code,
126
+ reason: moved.reason
127
+ };
128
+ }
129
+ }
79
130
  const item = await workItems.getForProject(orgId, factoryProjectId, created.id) ?? created;
80
131
  await audit({
81
132
  action: "factory.work_item.created",
@@ -1 +1 @@
1
- {"version":3,"file":"create-work-item.js","names":[],"sources":["../../src/work-items/create-work-item.ts"],"sourcesContent":["/**\n * Filing a work item, shared by the board's create route and the Factory tools\n * so a card filed from a session goes through exactly what \"New card\" does.\n */\n\nimport type { BoardRegistry } from '../boards/index.js';\nimport type { FactoryTransitionRequest, FactoryTransitionService } from '../rules/transition-service.js';\nimport type { EmitAuditInput } from '../storage/domains/audit/domain.js';\nimport type { CreateWorkItemInput, WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';\n\n/** Records one audit event for the caller; routes bind it to the request, tools to the session's person. */\nexport type FactoryAuditEmit = (input: EmitAuditInput) => Promise<void>;\n\ntype TransitionResult = Awaited<ReturnType<FactoryTransitionService['transition']>>;\n\nexport type CreateFactoryWorkItemResult =\n /** A new card, entered into its board's first phase and audited. */\n | { status: 'created'; item: WorkItemRow }\n /** The source key matched an existing card, which was updated instead (the caller audits the patch). */\n | { status: 'reused'; item: WorkItemRow }\n | {\n status: 'refused';\n code: 'invalid_board' | 'governed_transition_required' | 'factory_transitions_unavailable';\n message: string;\n }\n /** The first phase's entry rules refused the card; it was removed again. */\n | { status: 'rejected'; code: Extract<TransitionResult, { status: 'rejected' }>['code']; reason: string };\n\nexport interface CreateFactoryWorkItemArgs {\n workItems: WorkItemsStorage;\n boards: BoardRegistry;\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n audit: FactoryAuditEmit;\n orgId: string;\n /** Who files the card; becomes its `created_by` and the human actor of its first phase entry. */\n userId: string;\n factoryProjectId: string;\n input: CreateWorkItemInput;\n /** Where a browser request came from; a session's tool call carries none. */\n origin?: Pick<FactoryTransitionRequest, 'actorProfile' | 'context'>;\n}\n\n/**\n * Upserts the card into its board's first phase, enters that phase as the\n * person (rolling the card back if its entry rules refuse it), then audits\n * `factory.work_item.created`. Throws `WorkItemRelationError` for a bad parent.\n */\nexport async function createFactoryWorkItem({\n workItems,\n boards,\n transitionService,\n audit,\n orgId,\n userId,\n factoryProjectId,\n input,\n origin,\n}: CreateFactoryWorkItemArgs): Promise<CreateFactoryWorkItemResult> {\n const boardId = input.board ?? (input.externalSource?.type === 'pull-request' ? 'review' : 'work');\n const board = boards.get(boardId);\n if (!board) return { status: 'refused', code: 'invalid_board', message: `Board '${boardId}' is not installed.` };\n const initialStages = input.stages ?? [board.initialPhase];\n if (initialStages.length !== 1 || initialStages[0] !== board.initialPhase) {\n return {\n status: 'refused',\n code: 'governed_transition_required',\n message: `New work items must enter through the '${board.initialPhase}' phase of board '${boardId}'.`,\n };\n }\n\n await workItems.ensureReady();\n const result = await workItems.upsert({\n orgId,\n userId,\n factoryProjectId,\n input: { ...input, board: boardId, stages: initialStages },\n reuseMode: 'non-stage',\n });\n if (!result.created) return { status: 'reused', item: result.item };\n\n const created = result.item;\n if (!transitionService) {\n await workItems.delete({ orgId, id: created.id });\n return {\n status: 'refused',\n code: 'factory_transitions_unavailable',\n message: 'Factory stage transitions are not available right now.',\n };\n }\n const entered = await transitionService.transition({\n orgId,\n factoryProjectId,\n workItemId: created.id,\n board: boardId,\n stage: board.initialPhase,\n expectedRevision: created.revision,\n actor: { type: 'human', id: userId },\n ...origin,\n ingress: { type: 'human', identity: `work-item:${created.id}:initial-entry` },\n cause: 'work_item_created',\n initialEntry: true,\n });\n if (entered.status === 'rejected') {\n await workItems.delete({ orgId, id: created.id });\n return { status: 'rejected', code: entered.code, reason: entered.reason };\n }\n const item = (await workItems.getForProject(orgId, factoryProjectId, created.id)) ?? created;\n await audit({\n action: 'factory.work_item.created',\n factoryProjectId,\n targets: [{ type: 'work_item', id: item.id, name: item.title }],\n metadata: { externalSource: item.externalSource, stages: item.stages },\n });\n return { status: 'created', item };\n}\n"],"mappings":";;;;;;AA+CA,eAAsB,sBAAsB,EAC1C,WACA,QACA,mBACA,OACA,OACA,QACA,kBACA,OACA,UACkE;CAClE,MAAM,UAAU,MAAM,UAAU,MAAM,gBAAgB,SAAS,iBAAiB,WAAW;CAC3F,MAAM,QAAQ,OAAO,IAAI,OAAO;CAChC,IAAI,CAAC,OAAO,OAAO;EAAE,QAAQ;EAAW,MAAM;EAAiB,SAAS,UAAU,QAAQ;CAAqB;CAC/G,MAAM,gBAAgB,MAAM,UAAU,CAAC,MAAM,YAAY;CACzD,IAAI,cAAc,WAAW,KAAK,cAAc,OAAO,MAAM,cAC3D,OAAO;EACL,QAAQ;EACR,MAAM;EACN,SAAS,0CAA0C,MAAM,aAAa,oBAAoB,QAAQ;CACpG;CAGF,MAAM,UAAU,YAAY;CAC5B,MAAM,SAAS,MAAM,UAAU,OAAO;EACpC;EACA;EACA;EACA,OAAO;GAAE,GAAG;GAAO,OAAO;GAAS,QAAQ;EAAc;EACzD,WAAW;CACb,CAAC;CACD,IAAI,CAAC,OAAO,SAAS,OAAO;EAAE,QAAQ;EAAU,MAAM,OAAO;CAAK;CAElE,MAAM,UAAU,OAAO;CACvB,IAAI,CAAC,mBAAmB;EACtB,MAAM,UAAU,OAAO;GAAE;GAAO,IAAI,QAAQ;EAAG,CAAC;EAChD,OAAO;GACL,QAAQ;GACR,MAAM;GACN,SAAS;EACX;CACF;CACA,MAAM,UAAU,MAAM,kBAAkB,WAAW;EACjD;EACA;EACA,YAAY,QAAQ;EACpB,OAAO;EACP,OAAO,MAAM;EACb,kBAAkB,QAAQ;EAC1B,OAAO;GAAE,MAAM;GAAS,IAAI;EAAO;EACnC,GAAG;EACH,SAAS;GAAE,MAAM;GAAS,UAAU,aAAa,QAAQ,GAAG;EAAgB;EAC5E,OAAO;EACP,cAAc;CAChB,CAAC;CACD,IAAI,QAAQ,WAAW,YAAY;EACjC,MAAM,UAAU,OAAO;GAAE;GAAO,IAAI,QAAQ;EAAG,CAAC;EAChD,OAAO;GAAE,QAAQ;GAAY,MAAM,QAAQ;GAAM,QAAQ,QAAQ;EAAO;CAC1E;CACA,MAAM,OAAQ,MAAM,UAAU,cAAc,OAAO,kBAAkB,QAAQ,EAAE,KAAM;CACrF,MAAM,MAAM;EACV,QAAQ;EACR;EACA,SAAS,CAAC;GAAE,MAAM;GAAa,IAAI,KAAK;GAAI,MAAM,KAAK;EAAM,CAAC;EAC9D,UAAU;GAAE,gBAAgB,KAAK;GAAgB,QAAQ,KAAK;EAAO;CACvE,CAAC;CACD,OAAO;EAAE,QAAQ;EAAW;CAAK;AACnC"}
1
+ {"version":3,"file":"create-work-item.js","names":[],"sources":["../../src/work-items/create-work-item.ts"],"sourcesContent":["/**\n * Filing a work item, shared by the board's create route and the Factory tools\n * so a card filed from a session goes through exactly what \"New card\" does.\n */\n\nimport { cardRuleFacts } from '../boards/index.js';\nimport type { BoardRegistry } from '../boards/index.js';\nimport { INTAKE_ROUTE_METADATA_KEY, resolveIntakePlacement } from '../boards/intake-routing.js';\nimport type { IntakeRoutesReader } from '../boards/intake-routing.js';\nimport type { FactoryTransitionRequest, FactoryTransitionService } from '../rules/transition-service.js';\nimport type { EmitAuditInput } from '../storage/domains/audit/domain.js';\nimport type { CreateWorkItemInput, WorkItemRow, WorkItemsStorage } from '../storage/domains/work-items/base.js';\n\n/** Records one audit event for the caller; routes bind it to the request, tools to the session's person. */\nexport type FactoryAuditEmit = (input: EmitAuditInput) => Promise<void>;\n\ntype TransitionResult = Awaited<ReturnType<FactoryTransitionService['transition']>>;\n\nexport type CreateFactoryWorkItemResult =\n /** A new card, entered into its board's first phase and audited. */\n | { status: 'created'; item: WorkItemRow }\n /** The source key matched an existing card, which was updated instead (the caller audits the patch). */\n | { status: 'reused'; item: WorkItemRow }\n | {\n status: 'refused';\n code: 'invalid_board' | 'governed_transition_required' | 'factory_transitions_unavailable';\n message: string;\n }\n /** The first phase's entry rules (or the move to an intake route's phase) refused the card; it was removed again. */\n | { status: 'rejected'; code: Extract<TransitionResult, { status: 'rejected' }>['code']; reason: string };\n\nexport interface CreateFactoryWorkItemArgs {\n workItems: WorkItemsStorage;\n boards: BoardRegistry;\n transitionService: Pick<FactoryTransitionService, 'transition'> | undefined;\n audit: FactoryAuditEmit;\n orgId: string;\n /** Who files the card; becomes its `created_by` and the human actor of its first phase entry. */\n userId: string;\n factoryProjectId: string;\n input: CreateWorkItemInput;\n /** The project's intake routes; they place a card filed without a board or stages. */\n intakeRoutes?: IntakeRoutesReader;\n /** Where a browser request came from; a session's tool call carries none. */\n origin?: Pick<FactoryTransitionRequest, 'actorProfile' | 'context'>;\n}\n\n/**\n * Upserts the card into its board's first phase, enters that phase as the\n * person (rolling the card back if its entry rules refuse it), then audits\n * `factory.work_item.created`. Throws `WorkItemRelationError` for a bad parent.\n */\nexport async function createFactoryWorkItem({\n workItems,\n boards,\n transitionService,\n audit,\n orgId,\n userId,\n factoryProjectId,\n input,\n intakeRoutes,\n origin,\n}: CreateFactoryWorkItemArgs): Promise<CreateFactoryWorkItemResult> {\n // A card filed without a board or stages goes where the project's intake routes say; one\n // that names either went where the person chose.\n const placement =\n intakeRoutes && input.board === undefined && input.stages === undefined\n ? resolveIntakePlacement(\n await intakeRoutes.listIntakeRoutes({ orgId, factoryProjectId }),\n cardRuleFacts({\n title: input.title,\n metadata: input.metadata ?? null,\n externalSource: input.externalSource ?? null,\n }),\n boards,\n )\n : undefined;\n const boardId = placement?.board ?? input.board ?? 'work';\n const board = boards.get(boardId);\n if (!board) return { status: 'refused', code: 'invalid_board', message: `Board '${boardId}' is not installed.` };\n const initialStages = input.stages ?? [board.initialPhase];\n if (initialStages.length !== 1 || initialStages[0] !== board.initialPhase) {\n return {\n status: 'refused',\n code: 'governed_transition_required',\n message: `New work items must enter through the '${board.initialPhase}' phase of board '${boardId}'.`,\n };\n }\n\n await workItems.ensureReady();\n const result = await workItems.upsert({\n orgId,\n userId,\n factoryProjectId,\n input: {\n ...input,\n board: boardId,\n stages: initialStages,\n },\n reuseMode: 'non-stage',\n });\n // A reused card keeps its own placement, so only a card this call created records the route.\n if (!result.created) return { status: 'reused', item: result.item };\n\n const created = placement\n ? ((\n await workItems.update({\n orgId,\n id: result.item.id,\n userId,\n patch: { metadata: { [INTAKE_ROUTE_METADATA_KEY]: placement.routeId } },\n expectedRevision: result.item.revision,\n })\n )?.item ?? result.item)\n : result.item;\n if (!transitionService) {\n await workItems.delete({ orgId, id: created.id });\n return {\n status: 'refused',\n code: 'factory_transitions_unavailable',\n message: 'Factory stage transitions are not available right now.',\n };\n }\n const entered = await transitionService.transition({\n orgId,\n factoryProjectId,\n workItemId: created.id,\n board: boardId,\n stage: board.initialPhase,\n expectedRevision: created.revision,\n actor: { type: 'human', id: userId },\n ...origin,\n ingress: { type: 'human', identity: `work-item:${created.id}:initial-entry` },\n cause: 'work_item_created',\n initialEntry: true,\n });\n if (entered.status === 'rejected') {\n await workItems.delete({ orgId, id: created.id });\n return { status: 'rejected', code: entered.code, reason: entered.reason };\n }\n if (placement && placement.phase !== board.initialPhase) {\n const moved = await transitionService.transition({\n orgId,\n factoryProjectId,\n workItemId: created.id,\n board: boardId,\n stage: placement.phase,\n expectedRevision: entered.revision,\n // The route moves the card, not the person: a run it starts still needs their consent.\n actor: { type: 'system', id: 'factory-intake-route' },\n ingress: { type: 'rule', identity: `work-item:${created.id}:intake-route` },\n cause: 'work_item_created',\n });\n if (moved.status === 'rejected') {\n await workItems.delete({ orgId, id: created.id });\n return { status: 'rejected', code: moved.code, reason: moved.reason };\n }\n }\n const item = (await workItems.getForProject(orgId, factoryProjectId, created.id)) ?? created;\n await audit({\n action: 'factory.work_item.created',\n factoryProjectId,\n targets: [{ type: 'work_item', id: item.id, name: item.title }],\n metadata: { externalSource: item.externalSource, stages: item.stages },\n });\n return { status: 'created', item };\n}\n"],"mappings":";;;;;;;;;;;;;AAoDA,eAAsB,sBAAsB,EAC1C,WACA,QACA,mBACA,OACA,OACA,QACA,kBACA,OACA,cACA,UACkE;CAGlE,MAAM,YACJ,gBAAgB,MAAM,UAAU,KAAA,KAAa,MAAM,WAAW,KAAA,IAC1D,uBACE,MAAM,aAAa,iBAAiB;EAAE;EAAO;CAAiB,CAAC,GAC/D,cAAc;EACZ,OAAO,MAAM;EACb,UAAU,MAAM,YAAY;EAC5B,gBAAgB,MAAM,kBAAkB;CAC1C,CAAC,GACD,MACF,IACA,KAAA;CACN,MAAM,UAAU,WAAW,SAAS,MAAM,SAAS;CACnD,MAAM,QAAQ,OAAO,IAAI,OAAO;CAChC,IAAI,CAAC,OAAO,OAAO;EAAE,QAAQ;EAAW,MAAM;EAAiB,SAAS,UAAU,QAAQ;CAAqB;CAC/G,MAAM,gBAAgB,MAAM,UAAU,CAAC,MAAM,YAAY;CACzD,IAAI,cAAc,WAAW,KAAK,cAAc,OAAO,MAAM,cAC3D,OAAO;EACL,QAAQ;EACR,MAAM;EACN,SAAS,0CAA0C,MAAM,aAAa,oBAAoB,QAAQ;CACpG;CAGF,MAAM,UAAU,YAAY;CAC5B,MAAM,SAAS,MAAM,UAAU,OAAO;EACpC;EACA;EACA;EACA,OAAO;GACL,GAAG;GACH,OAAO;GACP,QAAQ;EACV;EACA,WAAW;CACb,CAAC;CAED,IAAI,CAAC,OAAO,SAAS,OAAO;EAAE,QAAQ;EAAU,MAAM,OAAO;CAAK;CAElE,MAAM,UAAU,aAEV,MAAM,UAAU,OAAO;EACrB;EACA,IAAI,OAAO,KAAK;EAChB;EACA,OAAO,EAAE,UAAU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M,MAAM;EACV,QAAQ;EACR;EACA,SAAS,CAAC;GAAE,MAAM;GAAa,IAAI,KAAK;GAAI,MAAM,KAAK;EAAM,CAAC;EAC9D,UAAU;GAAE,gBAAgB,KAAK;GAAgB,QAAQ,KAAK;EAAO;CACvE,CAAC;CACD,OAAO;EAAE,QAAQ;EAAW;CAAK;AACnC"}
@@ -39,7 +39,7 @@ GitHub and Linear integrations exclusively own their event handlers; configure t
39
39
 
40
40
  Do not create an `actions` config or execute authoritative policy in React. Each handler returns one typed `FactoryRuleDecision` or `undefined`.
41
41
 
42
- Work and Review cards move independently. Never mirror their stages or mark Work Done only because a pull request merged.
42
+ A pull request's own card and the Work card that authored it move independently, whether the pull request card sits on Work or on the legacy Review board. Never mirror their stages or mark Work Done only because a pull request merged.
43
43
 
44
44
  ## Configure board transition policy
45
45
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/factory",
3
- "version": "0.27.0-alpha.1",
3
+ "version": "0.27.0-alpha.2",
4
4
  "description": "Mastra Software Factory module: the server core behind the Mastra Software Factory — storage domains, integrations, and surfaces for agent-powered software delivery",
5
5
  "type": "module",
6
6
  "publishConfig": {
@@ -60,10 +60,10 @@
60
60
  "zod": "^4.6.7",
61
61
  "@mastra/auth-studio": "1.3.11",
62
62
  "@mastra/auth-workos": "1.6.8",
63
- "@mastra/code-sdk": "1.18.0-alpha.1",
64
- "@mastra/core": "1.82.0-alpha.1",
65
- "@mastra/mcp": "2.8.0-alpha.0",
66
- "@mastra/platform-workspace": "1.11.1-alpha.0",
63
+ "@mastra/code-sdk": "1.18.0-alpha.2",
64
+ "@mastra/core": "1.82.0-alpha.2",
65
+ "@mastra/mcp": "2.8.0-alpha.1",
66
+ "@mastra/platform-workspace": "1.12.0-alpha.1",
67
67
  "@mastra/slack": "1.8.0"
68
68
  },
69
69
  "devDependencies": {
@@ -75,10 +75,10 @@
75
75
  "@internal/lint": "0.0.147",
76
76
  "@internal/types-builder": "0.0.122",
77
77
  "@internal/workspace": "0.0.19",
78
- "@mastra/deployer": "1.82.0-alpha.1",
79
- "@mastra/libsql": "1.29.0-alpha.0",
80
- "@mastra/pg": "1.35.0-alpha.1",
81
- "@mastra/server": "1.82.0-alpha.1"
78
+ "@mastra/deployer": "1.82.0-alpha.2",
79
+ "@mastra/libsql": "1.29.0-alpha.1",
80
+ "@mastra/pg": "1.35.0-alpha.2",
81
+ "@mastra/server": "1.82.0-alpha.2"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=22.19.0"