@mastra/factory 0.29.0-alpha.6 → 0.29.0-alpha.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -20
- package/dist/boards/board-events.d.ts +23 -0
- package/dist/boards/board-events.d.ts.map +1 -1
- package/dist/boards/board-events.js +37 -3
- package/dist/boards/board-events.js.map +1 -1
- package/dist/boards/board-writes.d.ts +6 -4
- package/dist/boards/board-writes.d.ts.map +1 -1
- package/dist/boards/board-writes.js +9 -6
- package/dist/boards/board-writes.js.map +1 -1
- package/dist/boards/intake-routing.d.ts +30 -16
- package/dist/boards/intake-routing.d.ts.map +1 -1
- package/dist/boards/intake-routing.js +41 -28
- package/dist/boards/intake-routing.js.map +1 -1
- package/dist/boards/project-boards.d.ts +15 -0
- package/dist/boards/project-boards.d.ts.map +1 -1
- package/dist/boards/project-boards.js +43 -7
- package/dist/boards/project-boards.js.map +1 -1
- package/dist/factory.d.ts +4 -14
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +22 -15
- package/dist/factory.js.map +1 -1
- package/dist/integrations/github/integration.d.ts.map +1 -1
- package/dist/integrations/github/integration.js +101 -0
- package/dist/integrations/github/integration.js.map +1 -1
- package/dist/integrations/github/rules.d.ts.map +1 -1
- package/dist/integrations/github/rules.js +7 -3
- package/dist/integrations/github/rules.js.map +1 -1
- package/dist/integrations/github/sandbox.d.ts +7 -1
- package/dist/integrations/github/sandbox.d.ts.map +1 -1
- package/dist/integrations/github/sandbox.js +15 -1
- package/dist/integrations/github/sandbox.js.map +1 -1
- package/dist/integrations/github/session-subscriptions.js +1 -1
- package/dist/integrations/github/session-subscriptions.js.map +1 -1
- package/dist/integrations/gitlab/rules.d.ts.map +1 -1
- package/dist/integrations/gitlab/rules.js +2 -1
- package/dist/integrations/gitlab/rules.js.map +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js +1 -1
- package/dist/integrations/gitlab/session-subscriptions.js.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.d.ts +1 -0
- package/dist/integrations/slack/channel-reply-processor.d.ts.map +1 -1
- package/dist/integrations/slack/channel-reply-processor.js +4 -1
- package/dist/integrations/slack/channel-reply-processor.js.map +1 -1
- package/dist/integrations/slack/run-error-card.js +6 -1
- package/dist/integrations/slack/run-error-card.js.map +1 -1
- package/dist/links.d.ts +4 -2
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +5 -3
- package/dist/links.js.map +1 -1
- package/dist/routes/boards.d.ts +1 -1
- package/dist/routes/boards.d.ts.map +1 -1
- package/dist/routes/boards.js.map +1 -1
- package/dist/routes/contracts.d.ts +32 -5
- package/dist/routes/contracts.d.ts.map +1 -1
- package/dist/routes/contracts.js +36 -9
- package/dist/routes/contracts.js.map +1 -1
- package/dist/routes/intake-check.d.ts.map +1 -1
- package/dist/routes/intake-check.js +3 -1
- package/dist/routes/intake-check.js.map +1 -1
- package/dist/routes/intake-routes.d.ts +0 -3
- package/dist/routes/intake-routes.d.ts.map +1 -1
- package/dist/routes/intake-routes.js +1 -1
- package/dist/routes/intake-routes.js.map +1 -1
- package/dist/routes/skills.d.ts +1 -1
- package/dist/routes/skills.d.ts.map +1 -1
- package/dist/routes/skills.js +92 -28
- package/dist/routes/skills.js.map +1 -1
- package/dist/routes/surface.d.ts +0 -3
- package/dist/routes/surface.d.ts.map +1 -1
- package/dist/routes/surface.js +0 -1
- package/dist/routes/surface.js.map +1 -1
- package/dist/rules/dispatch-errors.d.ts +6 -0
- package/dist/rules/dispatch-errors.d.ts.map +1 -1
- package/dist/rules/dispatch-errors.js +10 -1
- package/dist/rules/dispatch-errors.js.map +1 -1
- package/dist/rules/dispatcher.d.ts.map +1 -1
- package/dist/rules/dispatcher.js +74 -32
- package/dist/rules/dispatcher.js.map +1 -1
- package/dist/rules/event-rules.d.ts +3 -2
- package/dist/rules/event-rules.d.ts.map +1 -1
- package/dist/rules/event-rules.js +5 -3
- package/dist/rules/event-rules.js.map +1 -1
- package/dist/rules/public-failure-reason.d.ts +11 -0
- package/dist/rules/public-failure-reason.d.ts.map +1 -0
- package/dist/rules/public-failure-reason.js +136 -0
- package/dist/rules/public-failure-reason.js.map +1 -0
- package/dist/rules/transition-service.d.ts +13 -0
- package/dist/rules/transition-service.d.ts.map +1 -1
- package/dist/rules/transition-service.js +5 -1
- package/dist/rules/transition-service.js.map +1 -1
- package/dist/rules/types.d.ts +12 -0
- package/dist/rules/types.d.ts.map +1 -1
- package/dist/rules/types.js.map +1 -1
- package/dist/rules/validation.d.ts.map +1 -1
- package/dist/rules/validation.js +11 -2
- package/dist/rules/validation.js.map +1 -1
- package/dist/run-error.d.ts +1 -1
- package/dist/run-error.d.ts.map +1 -1
- package/dist/run-error.js +21 -12
- package/dist/run-error.js.map +1 -1
- package/dist/session/environment-state-processor.d.ts.map +1 -1
- package/dist/session/environment-state-processor.js +6 -2
- package/dist/session/environment-state-processor.js.map +1 -1
- package/dist/session/session-row-view.js +1 -1
- package/dist/session/session-row-view.js.map +1 -1
- package/dist/session/source-control-tools.d.ts.map +1 -1
- package/dist/session/source-control-tools.js +5 -3
- package/dist/session/source-control-tools.js.map +1 -1
- package/dist/skills/app-skills.d.ts +3 -2
- package/dist/skills/app-skills.d.ts.map +1 -1
- package/dist/skills/app-skills.js +5 -3
- package/dist/skills/app-skills.js.map +1 -1
- package/dist/skills/catalog.d.ts +23 -4
- package/dist/skills/catalog.d.ts.map +1 -1
- package/dist/skills/catalog.js +61 -28
- package/dist/skills/catalog.js.map +1 -1
- package/dist/storage/domains/audit/actions.d.ts +1 -1
- package/dist/storage/domains/audit/actions.d.ts.map +1 -1
- package/dist/storage/domains/audit/actions.js +6 -1
- package/dist/storage/domains/audit/actions.js.map +1 -1
- package/dist/storage/domains/boards/base.d.ts +12 -0
- package/dist/storage/domains/boards/base.d.ts.map +1 -1
- package/dist/storage/domains/boards/base.js +3 -0
- package/dist/storage/domains/boards/base.js.map +1 -1
- package/dist/storage/domains/boards/schemas.d.ts.map +1 -1
- package/dist/storage/domains/boards/schemas.js +4 -0
- package/dist/storage/domains/boards/schemas.js.map +1 -1
- package/dist/storage/domains/skill-overrides/base.d.ts +28 -4
- package/dist/storage/domains/skill-overrides/base.d.ts.map +1 -1
- package/dist/storage/domains/skill-overrides/base.js +54 -1
- package/dist/storage/domains/skill-overrides/base.js.map +1 -1
- package/dist/storage/domains/work-items/base.d.ts +2 -0
- package/dist/storage/domains/work-items/base.d.ts.map +1 -1
- package/dist/storage/domains/work-items/base.js +13 -5
- package/dist/storage/domains/work-items/base.js.map +1 -1
- package/dist/tools/audit-events-tool.d.ts +1 -1
- package/dist/tools/read-tools.d.ts.map +1 -1
- package/dist/tools/read-tools.js +0 -1
- package/dist/tools/read-tools.js.map +1 -1
- package/dist/tools/work-item-tools.d.ts.map +1 -1
- package/dist/tools/work-item-tools.js +0 -3
- package/dist/tools/work-item-tools.js.map +1 -1
- package/dist/work-items/create-work-item.d.ts.map +1 -1
- package/dist/work-items/create-work-item.js +2 -1
- package/dist/work-items/create-work-item.js.map +1 -1
- package/dist/workspace.d.ts +5 -1
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +69 -9
- package/dist/workspace.js.map +1 -1
- package/package.json +8 -8
package/dist/rules/dispatcher.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { isUpdateEvent } from "../boards/board-events.js";
|
|
2
|
+
import { cardRuleFacts } from "../boards/card-facts.js";
|
|
2
3
|
import "../boards/index.js";
|
|
3
|
-
import { INTAKE_ROUTE_METADATA_KEY, arrivalRuleFacts, landingPhase, placedByIntakeRoute, planEventMove, projectIntakeEvaluator, resolveIntake } from "../boards/intake-routing.js";
|
|
4
4
|
import "../boards/define-board.js";
|
|
5
5
|
import { UNTRUSTED_PULL_REQUESTS_KEY, isOpenPullRequestSource, isPullRequestCard, pullRequestSources, pullRequestTrustKey, trustedPullRequestSource } from "../work-items/change-requests.js";
|
|
6
|
-
import { boardFlow, boardForWorkItem, cardBoardFlow, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
|
|
6
|
+
import { boardFlow, boardForWorkItem, cardBoardFlow, hasPullRequest, isTerminalWorkItem, resolvePhaseSemantics, reviewsPullRequest, workItemPhaseSemantics } from "../boards/semantics.js";
|
|
7
|
+
import { INTAKE_ROUTE_METADATA_KEY, arrivalRuleFacts, placedByIntakeRoute, planEventMove, projectIntakeEvaluator, resolveIntake, resumeLandingPhase, untrustedPullRequestEvent } from "../boards/intake-routing.js";
|
|
7
8
|
import { autoApprovedExitTool, startsInAutoPhase } from "../boards/phase-automation.js";
|
|
8
9
|
import { toBoardSource } from "../boards/project-boards.js";
|
|
9
10
|
import { moveCardToBoard } from "../boards/relocate.js";
|
|
@@ -15,15 +16,16 @@ import { FACTORY_RULE_MATERIALIZATION_KEY, FactoryRunBindingSupersededError, Wor
|
|
|
15
16
|
import { withWorkItemDescription } from "../work-items/description-context.js";
|
|
16
17
|
import { workItemProviderAdapter } from "../work-items/providers/index.js";
|
|
17
18
|
import { decisionOvertaken } from "./decision-applicability.js";
|
|
18
|
-
import { FactoryDispatchError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
19
|
+
import { FactoryDispatchError, FactoryRuleRejectedError, factoryDispatchFailureCode, factoryDispatchFailureMetadata } from "./dispatch-errors.js";
|
|
19
20
|
import { isStatusEventDecision } from "./event-rules.js";
|
|
20
21
|
import { PHASE_GOAL_METADATA_KEY, endPhaseGoal, phaseGoalOf, startPhaseGoal } from "./phase-goal.js";
|
|
22
|
+
import { causeOf, isProviderCallError, publicFailureReason } from "./public-failure-reason.js";
|
|
21
23
|
import { isRunBearingDecision } from "./run-bearing.js";
|
|
22
24
|
import { authorTrusted, externalSourceForWorkItem, workItemSource } from "./types.js";
|
|
23
25
|
import { eventRouteIngress, foldUpdate, updateGroup } from "./update-fold.js";
|
|
24
26
|
import { assertFactoryDecisionTarget, validateFactoryRuleDecision } from "./validation.js";
|
|
25
27
|
import { RequestContext } from "@mastra/core/request-context";
|
|
26
|
-
import {
|
|
28
|
+
import { classifyProviderError } from "@mastra/core/error";
|
|
27
29
|
// src/rules/dispatcher.ts
|
|
28
30
|
const LEASE_MS = 3e4;
|
|
29
31
|
/** How long the run waits on a status-comment write; well inside one lease so a slow provider never costs the claim. */
|
|
@@ -78,14 +80,6 @@ function httpStatus(error) {
|
|
|
78
80
|
if ("statusCode" in error && typeof error.statusCode === "number") return error.statusCode;
|
|
79
81
|
return "status" in error && typeof error.status === "number" ? error.status : void 0;
|
|
80
82
|
}
|
|
81
|
-
function causeOf(error) {
|
|
82
|
-
return error && typeof error === "object" && "cause" in error ? error.cause : void 0;
|
|
83
|
-
}
|
|
84
|
-
function isProviderCallError(error) {
|
|
85
|
-
if (!error || typeof error !== "object") return false;
|
|
86
|
-
if ("name" in error && typeof error.name === "string" && PROVIDER_CALL_ERROR_NAME.test(error.name)) return true;
|
|
87
|
-
return "statusCode" in error || "responseBody" in error;
|
|
88
|
-
}
|
|
89
83
|
function runErrorCode(error, message) {
|
|
90
84
|
const lower = message.toLowerCase();
|
|
91
85
|
if (lower.includes(CREDENTIAL_RESOLUTION_FAILURE)) return lower.includes(NO_AUTHENTICATED_USER) ? "run_user_unauthenticated" : "run_credentials_unavailable";
|
|
@@ -95,8 +89,8 @@ function runErrorCode(error, message) {
|
|
|
95
89
|
}
|
|
96
90
|
function runErrorFailure(label, error) {
|
|
97
91
|
const cause = (error instanceof Error ? error.message : String(error ?? "")).trim();
|
|
98
|
-
if (!cause) return new RunEndedInError("run_failed", `${label} ended in error
|
|
99
|
-
return new RunEndedInError(runErrorCode(error, cause), `${label} ended in error: ${cause}
|
|
92
|
+
if (!cause) return new RunEndedInError("run_failed", `${label} ended in error.`, { cause: error });
|
|
93
|
+
return new RunEndedInError(runErrorCode(error, cause), `${label} ended in error: ${cause}`, { cause: error });
|
|
100
94
|
}
|
|
101
95
|
/** A run in the review seat: a pull request review, unless it is the card's board's self-review. */
|
|
102
96
|
function reviewSeatSkill(decision) {
|
|
@@ -671,6 +665,12 @@ var FactoryDecisionDispatcher = class {
|
|
|
671
665
|
olderThan: new Date(now.getTime() - this.#staleBindingTtlMs),
|
|
672
666
|
now,
|
|
673
667
|
keep: async (binding) => {
|
|
668
|
+
try {
|
|
669
|
+
if (await this.#worksOpenCard(binding)) return true;
|
|
670
|
+
} catch (error) {
|
|
671
|
+
console.warn(`Factory stale-binding sweep kept binding card=${binding.workItemId} session=${binding.sessionId}: could not read its card`, sanitizeDispatchError(error));
|
|
672
|
+
return true;
|
|
673
|
+
}
|
|
674
674
|
try {
|
|
675
675
|
const session = await this.#controller.getSession(binding.sessionId);
|
|
676
676
|
if (session?.thread.getId() !== binding.threadId) return false;
|
|
@@ -678,13 +678,24 @@ var FactoryDecisionDispatcher = class {
|
|
|
678
678
|
} catch {
|
|
679
679
|
return false;
|
|
680
680
|
}
|
|
681
|
-
}
|
|
681
|
+
},
|
|
682
|
+
onRevoked: (binding) => console.info(`Factory stale-binding sweep revoked binding card=${binding.workItemId} session=${binding.sessionId} role=${binding.role}`)
|
|
682
683
|
});
|
|
683
684
|
if (revoked > 0) console.info(`Factory stale-binding sweep revoked ${revoked} binding(s)`);
|
|
684
685
|
} catch (error) {
|
|
685
686
|
console.error("Factory stale-binding sweep failed", sanitizeDispatchError(error));
|
|
686
687
|
}
|
|
687
688
|
}
|
|
689
|
+
/** Whether the binding's card sits in a working phase that the binding's role runs. */
|
|
690
|
+
async #worksOpenCard(binding) {
|
|
691
|
+
const item = await this.#storage.get({
|
|
692
|
+
orgId: binding.orgId,
|
|
693
|
+
id: binding.workItemId
|
|
694
|
+
});
|
|
695
|
+
if (!item || item.stages.length !== 1) return false;
|
|
696
|
+
const phase = (await this.#boards.load(binding)).get(boardForWorkItem(item))?.phases[item.stages[0]];
|
|
697
|
+
return phase?.kind === "working" && phase.runner.context === binding.role;
|
|
698
|
+
}
|
|
688
699
|
#track(pool, dispatch) {
|
|
689
700
|
pool.add(dispatch);
|
|
690
701
|
dispatch.catch(() => {}).then(() => {
|
|
@@ -740,7 +751,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
740
751
|
if (terminal || this.#reviewQueued.has(record)) await this.#reviewStatus(failed ?? record, record.decision, {
|
|
741
752
|
phase: terminal ? "failed" : "retrying",
|
|
742
753
|
endedAt: /* @__PURE__ */ new Date(),
|
|
743
|
-
reason:
|
|
754
|
+
reason: publicFailureReason(failureCode, error)
|
|
744
755
|
});
|
|
745
756
|
}
|
|
746
757
|
}
|
|
@@ -870,6 +881,24 @@ var FactoryDecisionDispatcher = class {
|
|
|
870
881
|
const phase = selfReview === void 0 ? void 0 : board?.phases[selfReview];
|
|
871
882
|
return phase?.kind !== "working" || phase.runner.skill !== run.skillName;
|
|
872
883
|
}
|
|
884
|
+
/**
|
|
885
|
+
* When a re-entered review's head was already reviewed while this decision waited for the
|
|
886
|
+
* pass in flight: that pass read the pushed commit, so its verdict is the one this decision
|
|
887
|
+
* was queued to produce. A verdict from before the decision does not count, so a person
|
|
888
|
+
* asking for another pass on the same commit still gets one.
|
|
889
|
+
*/
|
|
890
|
+
async #headReviewedSince(record, decision) {
|
|
891
|
+
if (!record.workItemId || decision.resume !== true) return void 0;
|
|
892
|
+
if (!await this.#isReviewRun(record, decision)) return void 0;
|
|
893
|
+
const { pullRequestHeadSha: head, reviewedHeadSha: reviewed, reviewedAt } = (await this.#storage.get({
|
|
894
|
+
orgId: record.orgId,
|
|
895
|
+
id: record.workItemId
|
|
896
|
+
}))?.metadata ?? {};
|
|
897
|
+
if (typeof head !== "string" || typeof reviewed !== "string" || typeof reviewedAt !== "string") return void 0;
|
|
898
|
+
if (head.toLowerCase() !== reviewed.toLowerCase()) return void 0;
|
|
899
|
+
const at = new Date(reviewedAt);
|
|
900
|
+
return at.getTime() >= record.createdAt.getTime() ? at : void 0;
|
|
901
|
+
}
|
|
873
902
|
async #reviewQueuedOnce(record, decision) {
|
|
874
903
|
if (this.#reviewQueued.has(record)) return;
|
|
875
904
|
this.#reviewQueued.add(record);
|
|
@@ -972,6 +1001,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
972
1001
|
}
|
|
973
1002
|
async #needsApproval(record, decision) {
|
|
974
1003
|
if (record.approvedAt !== null) return false;
|
|
1004
|
+
if ((decision.type === "invokeSkill" || decision.type === "sendMessage") && decision.untrustedPullRequestEvent === true) return true;
|
|
975
1005
|
const boards = await this.#boards.load(record);
|
|
976
1006
|
if (!requestsConsent(boards, record, decision)) return false;
|
|
977
1007
|
const item = record.workItemId ? await this.#storage.get({
|
|
@@ -1057,6 +1087,15 @@ var FactoryDecisionDispatcher = class {
|
|
|
1057
1087
|
return this.#replayLanded(record, decision, session, runStillActive);
|
|
1058
1088
|
}
|
|
1059
1089
|
if (await kickoffStale()) throw new FactoryDecisionSuperseded();
|
|
1090
|
+
const coveredAt = await this.#headReviewedSince(record, decision);
|
|
1091
|
+
if (coveredAt) {
|
|
1092
|
+
await this.#reviewStatus(record, decision, {
|
|
1093
|
+
phase: "completed",
|
|
1094
|
+
startedAt: record.createdAt,
|
|
1095
|
+
endedAt: coveredAt
|
|
1096
|
+
});
|
|
1097
|
+
return;
|
|
1098
|
+
}
|
|
1060
1099
|
const current = record.workItemId ? await this.#storage.get({
|
|
1061
1100
|
orgId: record.orgId,
|
|
1062
1101
|
id: record.workItemId
|
|
@@ -1228,7 +1267,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1228
1267
|
ifActive: { behavior: "deliver" },
|
|
1229
1268
|
ifIdle: { behavior: decision.idleBehavior ?? "wake" },
|
|
1230
1269
|
requestContext
|
|
1231
|
-
}),
|
|
1270
|
+
}), decision.idleBehavior !== "persist");
|
|
1232
1271
|
return;
|
|
1233
1272
|
}
|
|
1234
1273
|
case "signalActivity":
|
|
@@ -1459,7 +1498,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1459
1498
|
id: result.item.id,
|
|
1460
1499
|
purgeRuleState: false
|
|
1461
1500
|
});
|
|
1462
|
-
throw new
|
|
1501
|
+
throw new FactoryRuleRejectedError(initial.code, initial.reason);
|
|
1463
1502
|
}
|
|
1464
1503
|
expectedRevision = initial.revision;
|
|
1465
1504
|
}
|
|
@@ -1481,9 +1520,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
1481
1520
|
identity: `decision:${record.idempotencyKey}:${result.item.id}:destination`
|
|
1482
1521
|
},
|
|
1483
1522
|
cause: materializedByDecision ? "linked_item_materialized" : "linked_item_reconciled",
|
|
1484
|
-
causalChain
|
|
1523
|
+
causalChain,
|
|
1524
|
+
...materializedByDecision ? { routeFiling: true } : {}
|
|
1485
1525
|
});
|
|
1486
|
-
if (moved.status === "rejected") throw new
|
|
1526
|
+
if (moved.status === "rejected") throw new FactoryRuleRejectedError(moved.code, moved.reason);
|
|
1487
1527
|
}
|
|
1488
1528
|
/**
|
|
1489
1529
|
* Files a pull or merge request on the existing card `workItemId`, as one more source, when
|
|
@@ -1618,6 +1658,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1618
1658
|
event: {
|
|
1619
1659
|
type: "pull_request.opened",
|
|
1620
1660
|
pullRequestTrusted: link.trusted,
|
|
1661
|
+
actorTrusted: link.trusted,
|
|
1621
1662
|
closedIssue: {
|
|
1622
1663
|
phase: link.phase,
|
|
1623
1664
|
hasPullRequest: link.hasPullRequest
|
|
@@ -1725,12 +1766,6 @@ var FactoryDecisionDispatcher = class {
|
|
|
1725
1766
|
};
|
|
1726
1767
|
}
|
|
1727
1768
|
/**
|
|
1728
|
-
* A card an intake route placed stays on the route's board when its source is filed again
|
|
1729
|
-
* (a reconcile replaying "opened"): the decision lands
|
|
1730
|
-
* on the card's board at its first phase, so it only backfills facts and moves nothing.
|
|
1731
|
-
* An explicit placement (`skipRules`) still wins.
|
|
1732
|
-
*/
|
|
1733
|
-
/**
|
|
1734
1769
|
* A retry of the decision that filed `existing` finishes the filing where it started: on the
|
|
1735
1770
|
* card's board, at the phase its route names now, or the board's first phase when the route was
|
|
1736
1771
|
* deleted, disabled or re-pointed since. Routes are not re-run, so an edit cannot send the card
|
|
@@ -1748,13 +1783,18 @@ var FactoryDecisionDispatcher = class {
|
|
|
1748
1783
|
return {
|
|
1749
1784
|
...decision,
|
|
1750
1785
|
board: board.id,
|
|
1751
|
-
stage:
|
|
1786
|
+
stage: resumeLandingPhase(board, route?.target.phaseKey, cardRuleFacts(existing), hasPullRequest(existing)),
|
|
1752
1787
|
metadata: {
|
|
1753
1788
|
...decision.metadata,
|
|
1754
1789
|
[INTAKE_ROUTE_METADATA_KEY]: routeId
|
|
1755
1790
|
}
|
|
1756
1791
|
};
|
|
1757
1792
|
}
|
|
1793
|
+
/**
|
|
1794
|
+
* A card an intake route placed stays on the route's board when its source is filed again
|
|
1795
|
+
* (a reconcile replaying "opened"): the decision lands on the card's board at its first phase,
|
|
1796
|
+
* so it only backfills facts and moves nothing. An explicit placement (`skipRules`) still wins.
|
|
1797
|
+
*/
|
|
1758
1798
|
#keepRoutedCard(existing, decision, boards) {
|
|
1759
1799
|
if (decision.skipRules === true || !placedByIntakeRoute(existing)) return decision;
|
|
1760
1800
|
const board = boards.get(boardForWorkItem(existing));
|
|
@@ -1789,9 +1829,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
1789
1829
|
},
|
|
1790
1830
|
cause: "rule_decision",
|
|
1791
1831
|
causalChain: nextChain,
|
|
1792
|
-
...decision.reenter ? { reenter: true } : {}
|
|
1832
|
+
...decision.reenter ? { reenter: true } : {},
|
|
1833
|
+
...decision.event && untrustedPullRequestEvent(decision.event) ? { untrustedPullRequestEvent: true } : {}
|
|
1793
1834
|
});
|
|
1794
|
-
if (result.status === "rejected") throw new
|
|
1835
|
+
if (result.status === "rejected") throw new FactoryRuleRejectedError(result.code, result.reason);
|
|
1795
1836
|
const transitionMessage = decision.message;
|
|
1796
1837
|
if (!transitionMessage) return;
|
|
1797
1838
|
const moved = await this.#storage.get({
|
|
@@ -1816,7 +1857,7 @@ var FactoryDecisionDispatcher = class {
|
|
|
1816
1857
|
idempotencyKey: messageKey,
|
|
1817
1858
|
message: transitionMessage.text,
|
|
1818
1859
|
priority: "high",
|
|
1819
|
-
idleBehavior: "wake",
|
|
1860
|
+
idleBehavior: decision.event && untrustedPullRequestEvent(decision.event) ? "persist" : "wake",
|
|
1820
1861
|
...transitionMessage.role !== void 0 ? { role: transitionMessage.role } : {}
|
|
1821
1862
|
}],
|
|
1822
1863
|
causalChain: nextChain,
|
|
@@ -1901,9 +1942,10 @@ var FactoryDecisionDispatcher = class {
|
|
|
1901
1942
|
},
|
|
1902
1943
|
cause: "event_route",
|
|
1903
1944
|
causalChain,
|
|
1904
|
-
eventRoute: { routeId: route.routeId }
|
|
1945
|
+
eventRoute: { routeId: route.routeId },
|
|
1946
|
+
...untrustedPullRequestEvent(event) ? { untrustedPullRequestEvent: true } : {}
|
|
1905
1947
|
});
|
|
1906
|
-
if (result.status === "rejected" && result.code === "stale") throw new
|
|
1948
|
+
if (result.status === "rejected" && result.code === "stale") throw new FactoryRuleRejectedError(result.code, result.reason);
|
|
1907
1949
|
if (result.status === "accepted" && crossesBoards) await this.#storage.supersedeDecisionsForWorkItem({
|
|
1908
1950
|
orgId: record.orgId,
|
|
1909
1951
|
factoryProjectId: record.factoryProjectId,
|