@usine/orchestrator 0.1.0 → 0.2.0

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 (121) hide show
  1. package/README.md +44 -21
  2. package/dist/board/items.d.ts +18 -0
  3. package/dist/board/items.d.ts.map +1 -0
  4. package/dist/board/items.js +46 -0
  5. package/dist/board/items.js.map +1 -0
  6. package/dist/board/projection.d.ts +6 -5
  7. package/dist/board/projection.d.ts.map +1 -1
  8. package/dist/board/projection.js +25 -65
  9. package/dist/board/projection.js.map +1 -1
  10. package/dist/board/tasks.d.ts +8 -0
  11. package/dist/board/tasks.d.ts.map +1 -0
  12. package/dist/board/tasks.js +86 -0
  13. package/dist/board/tasks.js.map +1 -0
  14. package/dist/credentials.d.ts +6 -6
  15. package/dist/credentials.d.ts.map +1 -1
  16. package/dist/credentials.js +6 -6
  17. package/dist/credentials.js.map +1 -1
  18. package/dist/exe-dev.d.ts +5 -4
  19. package/dist/exe-dev.d.ts.map +1 -1
  20. package/dist/exe-dev.js +5 -4
  21. package/dist/exe-dev.js.map +1 -1
  22. package/dist/idle-triggers.d.ts +1 -1
  23. package/dist/idle-triggers.d.ts.map +1 -1
  24. package/dist/idle-triggers.js +3 -1
  25. package/dist/idle-triggers.js.map +1 -1
  26. package/dist/label-reconciler.d.ts +30 -0
  27. package/dist/label-reconciler.d.ts.map +1 -0
  28. package/dist/label-reconciler.js +119 -0
  29. package/dist/label-reconciler.js.map +1 -0
  30. package/dist/local.d.ts +17 -12
  31. package/dist/local.d.ts.map +1 -1
  32. package/dist/local.js +20 -13
  33. package/dist/local.js.map +1 -1
  34. package/dist/operator/attempt.d.ts +66 -0
  35. package/dist/operator/attempt.d.ts.map +1 -0
  36. package/dist/operator/attempt.js +58 -0
  37. package/dist/operator/attempt.js.map +1 -0
  38. package/dist/operator/board.d.ts +119 -0
  39. package/dist/operator/board.d.ts.map +1 -0
  40. package/dist/operator/board.js +101 -0
  41. package/dist/operator/board.js.map +1 -0
  42. package/dist/operator/http.d.ts +114 -0
  43. package/dist/operator/http.d.ts.map +1 -0
  44. package/dist/operator/http.js +139 -0
  45. package/dist/operator/http.js.map +1 -0
  46. package/dist/operator/need.d.ts +66 -0
  47. package/dist/operator/need.d.ts.map +1 -0
  48. package/dist/operator/need.js +70 -0
  49. package/dist/operator/need.js.map +1 -0
  50. package/dist/operator/operator.d.ts +64 -0
  51. package/dist/operator/operator.d.ts.map +1 -0
  52. package/dist/operator/{service.js → operator.js} +147 -32
  53. package/dist/operator/operator.js.map +1 -0
  54. package/dist/operator/overview.d.ts +51 -0
  55. package/dist/operator/overview.d.ts.map +1 -0
  56. package/dist/operator/overview.js +48 -0
  57. package/dist/operator/overview.js.map +1 -0
  58. package/dist/operator/projection.d.ts +9 -9
  59. package/dist/operator/projection.d.ts.map +1 -1
  60. package/dist/operator/projection.js +18 -10
  61. package/dist/operator/projection.js.map +1 -1
  62. package/dist/operator/run.d.ts +38 -0
  63. package/dist/operator/run.d.ts.map +1 -0
  64. package/dist/operator/run.js +41 -0
  65. package/dist/operator/run.js.map +1 -0
  66. package/dist/operator/transcript.d.ts +57 -0
  67. package/dist/operator/transcript.d.ts.map +1 -0
  68. package/dist/operator/transcript.js +59 -0
  69. package/dist/operator/transcript.js.map +1 -0
  70. package/dist/orchestrator.d.ts +3 -2
  71. package/dist/orchestrator.d.ts.map +1 -1
  72. package/dist/orchestrator.js +1 -1
  73. package/dist/orchestrator.js.map +1 -1
  74. package/dist/polling/cycle.d.ts +51 -0
  75. package/dist/polling/cycle.d.ts.map +1 -0
  76. package/dist/polling/cycle.js +44 -0
  77. package/dist/polling/cycle.js.map +1 -0
  78. package/dist/polling/hints.d.ts +20 -0
  79. package/dist/polling/hints.d.ts.map +1 -0
  80. package/dist/polling/hints.js +54 -0
  81. package/dist/polling/hints.js.map +1 -0
  82. package/dist/polling/loop-evaluation.d.ts +21 -0
  83. package/dist/polling/loop-evaluation.d.ts.map +1 -0
  84. package/dist/polling/loop-evaluation.js +131 -0
  85. package/dist/polling/loop-evaluation.js.map +1 -0
  86. package/dist/polling/polling.d.ts +36 -0
  87. package/dist/polling/polling.d.ts.map +1 -0
  88. package/dist/polling/polling.js +296 -0
  89. package/dist/polling/polling.js.map +1 -0
  90. package/dist/polling/repository-sync.d.ts +45 -0
  91. package/dist/polling/repository-sync.d.ts.map +1 -0
  92. package/dist/polling/repository-sync.js +169 -0
  93. package/dist/polling/repository-sync.js.map +1 -0
  94. package/dist/polling-triggers.d.ts +3 -39
  95. package/dist/polling-triggers.d.ts.map +1 -1
  96. package/dist/polling-triggers.js +3 -393
  97. package/dist/polling-triggers.js.map +1 -1
  98. package/dist/schedule-triggers.d.ts +17 -15
  99. package/dist/schedule-triggers.d.ts.map +1 -1
  100. package/dist/schedule-triggers.js +53 -43
  101. package/dist/schedule-triggers.js.map +1 -1
  102. package/dist/scheduler.d.ts +5 -5
  103. package/dist/scheduler.d.ts.map +1 -1
  104. package/dist/scheduler.js +28 -43
  105. package/dist/scheduler.js.map +1 -1
  106. package/dist/trigger-submission.d.ts +33 -24
  107. package/dist/trigger-submission.d.ts.map +1 -1
  108. package/dist/trigger-submission.js +32 -29
  109. package/dist/trigger-submission.js.map +1 -1
  110. package/package.json +50 -14
  111. package/dist/index.d.ts +0 -11
  112. package/dist/index.d.ts.map +0 -1
  113. package/dist/index.js +0 -11
  114. package/dist/index.js.map +0 -1
  115. package/dist/operator/model.d.ts +0 -280
  116. package/dist/operator/model.d.ts.map +0 -1
  117. package/dist/operator/model.js +0 -242
  118. package/dist/operator/model.js.map +0 -1
  119. package/dist/operator/service.d.ts +0 -36
  120. package/dist/operator/service.d.ts.map +0 -1
  121. package/dist/operator/service.js.map +0 -1
@@ -0,0 +1,131 @@
1
+ import { ConfigParser } from "@usine/config/parser";
2
+ import { environmentFor, repositoryContext } from "@usine/config/payload-slices";
3
+ import { AttemptTask } from "@usine/core/attempt";
4
+ import { DedupKey } from "@usine/core/event";
5
+ import { CommitSha, RepositoryRevision, canonicalRepositoryName } from "@usine/core/repository";
6
+ import { RunEngine } from "@usine/engine/engine";
7
+ import { ExpressionEngine } from "@usine/expression/expression-engine";
8
+ import { InvalidGitHubResponseError } from "@usine/github/github-app";
9
+ import { DateTime, Effect, Result, Schema } from "effect";
10
+ import { configFileErrorLogFields, DEFAULT_BRANCH_REVISION, submissionLogFields, triggerSubmission, } from "../trigger-submission.js";
11
+ import { RepositoryPollFailure } from "./cycle.js";
12
+ const eventKey = (loop, repository, { projection: item, cycleGeneration }) => DedupKey.make(JSON.stringify([
13
+ loop.name,
14
+ canonicalRepositoryName(repository.name),
15
+ item.number,
16
+ item.contentHash,
17
+ // Preserve pre-budget identities while making every reset a fresh Event
18
+ // with the current rendered task, Agent and authored limit.
19
+ ...(cycleGeneration === 0 ? [] : [cycleGeneration]),
20
+ ]));
21
+ /**
22
+ * Evaluates an already projected Item against its repository's active Loops,
23
+ * renders matching prompts, and submits or revokes Runs. Prompt-render failures
24
+ * are reported per Loop; expression and Run failures stop the repository before
25
+ * its cursor commits. Schedule Ticks have separate evaluation semantics.
26
+ */
27
+ export const evaluateItem = Effect.fn("PollingTriggers.evaluateItem")(function* (repository, resolved, observed) {
28
+ const { projection: item, cycleGeneration } = observed;
29
+ yield* Effect.annotateCurrentSpan({
30
+ repository: repository.name,
31
+ item: item.number,
32
+ });
33
+ const config = yield* ConfigParser;
34
+ const expressions = yield* ExpressionEngine;
35
+ const runs = yield* RunEngine;
36
+ const loops = resolved.filter(({ loop }) => loop.trigger.on === item.source);
37
+ const payload = item.payload;
38
+ const context = { repo: repositoryContext(repository), item: payload };
39
+ if (loops.length === 0) {
40
+ yield* Effect.logDebug("Item projected without any matching repository Loop", {
41
+ repository: repository.name,
42
+ item: item.number,
43
+ stream: item.source,
44
+ });
45
+ return { submissions: [], revokedRuns: 0, failures: [] };
46
+ }
47
+ const submissions = [];
48
+ // Projections store generic JSON; decode the GitHub PR revision at this boundary.
49
+ const revision = item.source === "pr"
50
+ ? RepositoryRevision.make(yield* Schema.decodeUnknownEffect(CommitSha)(payload.headRefOid).pipe(Effect.mapError(() => new InvalidGitHubResponseError({
51
+ operation: "fetch-pull-request-snapshot",
52
+ message: "The pull request payload has no valid head commit",
53
+ detail: `PR ${item.number} requires a full headRefOid`,
54
+ }))))
55
+ : DEFAULT_BRANCH_REVISION;
56
+ const failures = [];
57
+ let revokedRuns = 0;
58
+ for (const { agent, loop, parentModel } of loops) {
59
+ yield* Effect.annotateCurrentSpan({ loop: loop.name, agent: agent.name });
60
+ const matches = yield* expressions.evaluateBoolean(loop.trigger.if, environmentFor(loop.trigger.on), context);
61
+ if (!matches) {
62
+ yield* Effect.logDebug("Item did not match its loop expression", {
63
+ repository: repository.name,
64
+ loop: loop.name,
65
+ agent: agent.name,
66
+ item: item.number,
67
+ });
68
+ const revoked = yield* runs.revoke(loop.name, item.itemKey);
69
+ revokedRuns += revoked.length;
70
+ if (revoked.length > 0) {
71
+ yield* Effect.logInfo("Item stopped matching; revoked its unstarted runs", {
72
+ repository: repository.name,
73
+ loop: loop.name,
74
+ agent: agent.name,
75
+ item: item.number,
76
+ runIds: revoked.join(", "),
77
+ });
78
+ }
79
+ continue;
80
+ }
81
+ const dedupKey = eventKey(loop, repository, observed);
82
+ const receivedAt = yield* DateTime.now;
83
+ // A render failure comes from the loop's authoring, not transport, so
84
+ // re-polling would fail the same way. It is scoped to this loop so the
85
+ // sibling loops and the cursor still advance.
86
+ const rendered = yield* Effect.result(config.renderPrompt(loop, context));
87
+ if (Result.isFailure(rendered)) {
88
+ yield* Effect.logError("Loop prompt rendering failed; sibling loops were unaffected", {
89
+ loop: loop.name,
90
+ repository: repository.name,
91
+ agent: agent.name,
92
+ item: item.number,
93
+ errorTag: rendered.failure._tag,
94
+ message: rendered.failure.message,
95
+ ...configFileErrorLogFields(rendered.failure),
96
+ });
97
+ failures.push(new RepositoryPollFailure({
98
+ repository: repository.name,
99
+ errorTag: rendered.failure._tag,
100
+ message: rendered.failure.message,
101
+ }));
102
+ continue;
103
+ }
104
+ const submitted = yield* runs.submit(triggerSubmission({
105
+ dedupKey,
106
+ cycleGeneration,
107
+ itemKey: item.itemKey,
108
+ loop,
109
+ payload,
110
+ receivedAt,
111
+ repository,
112
+ revision,
113
+ task: AttemptTask.make(rendered.success),
114
+ agent,
115
+ parentModel,
116
+ }));
117
+ yield* Effect.logInfo("Submitted matching item state", {
118
+ repository: repository.name,
119
+ loop: loop.name,
120
+ agent: agent.name,
121
+ item: item.number,
122
+ contentHash: item.contentHash,
123
+ revision,
124
+ result: submitted._tag,
125
+ ...submissionLogFields(submitted),
126
+ });
127
+ submissions.push(submitted);
128
+ }
129
+ return { submissions, revokedRuns, failures };
130
+ });
131
+ //# sourceMappingURL=loop-evaluation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loop-evaluation.js","sourceRoot":"","sources":["../../src/polling/loop-evaluation.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjF,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,EAAE,SAAS,EAAyB,MAAM,sBAAsB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0BAA0B,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EAEvB,mBAAmB,EACnB,iBAAiB,GAClB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,qBAAqB,EAAE,MAAM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AM;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW;YAC7B,QAAQ;YACR,MAAM,EAAE,SAAS,CAAC,IAAI;YACtB,GAAG,mBAAmB,CAAC,SAAS,CAAC;SAClC,CAAC,CAAC;QACH,WAAW,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAsB,CAAC;AACpE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type { LoadedInstance } from "@usine/config/instance";
2
+ import { ConfigParser } from "@usine/config/parser";
3
+ import { type RepositoryName } from "@usine/core/repository";
4
+ import { CursorStore } from "@usine/engine/cursor";
5
+ import { CycleBudgets } from "@usine/engine/cycle-budget";
6
+ import { RunEngine, type EnginePersistenceError } from "@usine/engine/engine";
7
+ import { ItemProjectionWriter } from "@usine/engine/item-projection";
8
+ import { LoopControl } from "@usine/engine/loop-control";
9
+ import { RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter } from "@usine/engine/repository-label-projection";
10
+ import { ExpressionEngine } from "@usine/expression/expression-engine";
11
+ import { type ChangedItem, GitHubPolling } from "@usine/github/polling";
12
+ import { Context, DateTime, Effect, Layer, Option } from "effect";
13
+ import { LabelReconciler } from "../label-reconciler.ts";
14
+ import { PollCycle } from "./cycle.ts";
15
+ declare const PollingTriggers_base: Context.ServiceClass<PollingTriggers, "@usine/orchestrator/PollingTriggers", {
16
+ /**
17
+ * Polls every managed repository, including those without active Loops.
18
+ * Label preflight precedes change detection; each changed Item is projected
19
+ * before its Run decisions. A repository commits its cursor only after all
20
+ * Items finish. Repository failures are reported while siblings continue;
21
+ * failure to read Loop runtime state fails the whole cycle.
22
+ */
23
+ readonly poll: (instance: LoadedInstance) => Effect.Effect<PollCycle, EnginePersistenceError>;
24
+ /** Nudges an authoritative Item fetch after a self-write, retaining any request backoff from the writer. Pending duplicates coalesce; polling repairs loss. */
25
+ readonly hint: (repository: RepositoryName, item: ChangedItem, backoffUntil?: Option.Option<DateTime.Utc>) => Effect.Effect<void>;
26
+ /** Repeats cycles at the configured interval and processes self-write Hints, respecting GitHub request backoff. */
27
+ readonly run: (instance: LoadedInstance) => Effect.Effect<never>;
28
+ /** The last completed cycle, including its isolated failures; absent until the first cycle completes. */
29
+ readonly latest: Effect.Effect<Option.Option<PollCycle>>;
30
+ }>;
31
+ /** Keeps managed repositories' Boards current and evaluates their active Loops against changed Items. */
32
+ export declare class PollingTriggers extends PollingTriggers_base {
33
+ static readonly layer: Layer.Layer<PollingTriggers, never, ConfigParser | CursorStore | CycleBudgets | ExpressionEngine | GitHubPolling | ItemProjectionWriter | LabelReconciler | LoopControl | RepositoryLabelProjectionReader | RepositoryLabelProjectionWriter | RunEngine>;
34
+ }
35
+ export {};
36
+ //# sourceMappingURL=polling.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.d.ts","sourceRoot":"","sources":["../../src/polling/polling.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAa,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EACL,SAAS,EACT,KAAK,sBAAsB,EAE5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,EAChC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,KAAK,WAAW,EAAyB,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC/F,OAAO,EAEL,OAAO,EACP,QAAQ,EAER,MAAM,EACN,KAAK,EACL,MAAM,EAKP,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,eAAe,EAA8B,MAAM,wBAAwB,CAAC;AAErF,OAAO,EAGL,SAAS,EAIV,MAAM,YAAY,CAAC;;IAmEhB;;;;;;OAMG;mBACY,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,sBAAsB,CAAC;IAC7F,+JAA+J;mBAChJ,CACb,UAAU,EAAE,cAAc,EAC1B,IAAI,EAAE,WAAW,EACjB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,KACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IACxB,mHAAmH;kBACrG,CAAC,QAAQ,EAAE,cAAc,KAAK,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;IAChE,yGAAyG;qBACxF,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;;AArB5D,yGAAyG;AACzG,qBAAa,eAAgB,SAAQ,oBAsBK;IACxC,MAAM,CAAC,QAAQ,CAAC,KAAK,2PAyVkB;CACxC"}
@@ -0,0 +1,296 @@
1
+ import { ConfigParser } from "@usine/config/parser";
2
+ import { matchesSelector } from "@usine/config/selector";
3
+ import { canonicalRepositoryName } from "@usine/core/repository";
4
+ import { CursorKey, CursorStore } from "@usine/engine/cursor";
5
+ import { CycleBudgets } from "@usine/engine/cycle-budget";
6
+ import { RunEngine, } from "@usine/engine/engine";
7
+ import { ItemProjectionWriter } from "@usine/engine/item-projection";
8
+ import { LoopControl } from "@usine/engine/loop-control";
9
+ import { RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter, } from "@usine/engine/repository-label-projection";
10
+ import { ExpressionEngine } from "@usine/expression/expression-engine";
11
+ import { EntityTag, PollCursor, GitHubPolling } from "@usine/github/polling";
12
+ import { Clock, Context, DateTime, Duration, Effect, Layer, Option, Ref, Result, Schema, Semaphore, } from "effect";
13
+ import { LabelReconciler } from "../label-reconciler.js";
14
+ import { resolveTriggerLoops } from "../trigger-submission.js";
15
+ import { latestPollAt, PollCycle, RepositoryPollFailure, repositoryFailureLogFields, } from "./cycle.js";
16
+ import { evaluateItem } from "./loop-evaluation.js";
17
+ import { observeItem, synchronizeLabels } from "./repository-sync.js";
18
+ import { ItemHints } from "./hints.js";
19
+ /** GitHub tolerates a handful of parallel REST and GraphQL calls per token. */
20
+ const REPOSITORY_CONCURRENCY = 4;
21
+ const ITEM_CONCURRENCY = 4;
22
+ const WatchKey = Schema.NonEmptyString.pipe(Schema.brand("GitHubPollWatchKey"));
23
+ class StoredPollCursor extends Schema.Class("@usine/orchestrator/StoredPollCursor")({
24
+ boardVersion: Schema.Literal(4),
25
+ cursor: PollCursor,
26
+ labelEntityTag: Schema.OptionFromNullOr(EntityTag),
27
+ watches: Schema.Array(WatchKey).check(Schema.isUnique()),
28
+ }) {
29
+ }
30
+ const cursorKey = (repository) => CursorKey.make(`github-poll:${canonicalRepositoryName(repository.name)}`);
31
+ const watchKey = ({ loop }) => WatchKey.make(JSON.stringify([loop.name, loop.trigger.on, loop.trigger.if]));
32
+ const watchedRepositories = (instance, resolved) => instance.config.repos.map((repository) => {
33
+ const loops = resolved.filter(({ loop }) => loop.trigger.on !== "schedule" && matchesSelector(loop.selector, repository));
34
+ return {
35
+ repository,
36
+ declaredLabels: instance.config.labels,
37
+ loops,
38
+ watches: loops.map(watchKey).sort(),
39
+ };
40
+ });
41
+ const sameWatches = (left, right) => left.length === right.length && left.every((value, index) => value === right[index]);
42
+ /** Keeps managed repositories' Boards current and evaluates their active Loops against changed Items. */
43
+ export class PollingTriggers extends Context.Service()("@usine/orchestrator/PollingTriggers") {
44
+ static layer = Layer.effect(PollingTriggers, Effect.gen(function* () {
45
+ const cursors = yield* CursorStore;
46
+ const budgets = yield* CycleBudgets;
47
+ const github = yield* GitHubPolling;
48
+ const loops = yield* LoopControl;
49
+ const latest = yield* Ref.make(Option.none());
50
+ const hints = yield* ItemHints;
51
+ const ownership = yield* Semaphore.make(1);
52
+ const emptyCursor = (watches) => new StoredPollCursor({
53
+ boardVersion: 4,
54
+ cursor: PollCursor.empty,
55
+ labelEntityTag: Option.none(),
56
+ watches,
57
+ });
58
+ const readCursor = Effect.fn("PollingTriggers.readCursor")(function* (watched) {
59
+ yield* Effect.annotateCurrentSpan({ repository: watched.repository.name });
60
+ const stored = yield* cursors.read(cursorKey(watched.repository), StoredPollCursor);
61
+ if (Option.isNone(stored))
62
+ return emptyCursor(watched.watches);
63
+ if (!sameWatches(stored.value.watches, watched.watches)) {
64
+ yield* Effect.logInfo("Watched loops changed; re-polling the repository from scratch", {
65
+ repository: watched.repository.name,
66
+ previousWatches: stored.value.watches.length,
67
+ currentWatches: watched.watches.length,
68
+ });
69
+ return emptyCursor(watched.watches);
70
+ }
71
+ return stored.value;
72
+ });
73
+ const writeCursor = Effect.fn("PollingTriggers.writeCursor")(function* (watched, cursor) {
74
+ yield* Effect.annotateCurrentSpan({ repository: watched.repository.name });
75
+ yield* cursors.write(cursorKey(watched.repository), StoredPollCursor, cursor);
76
+ });
77
+ const pollRepository = Effect.fn("PollingTriggers.pollRepository")(function* (watched) {
78
+ yield* Effect.annotateCurrentSpan({ repository: watched.repository.name });
79
+ const resets = (yield* budgets.pendingResets()).filter(({ repository }) => canonicalRepositoryName(repository) ===
80
+ canonicalRepositoryName(watched.repository.name));
81
+ const stored = resets.length > 0 ? emptyCursor(watched.watches) : yield* readCursor(watched);
82
+ if (resets.length > 0)
83
+ yield* Effect.logInfo("Cycle budget reset requests fresh repository polling", {
84
+ repository: watched.repository.name,
85
+ items: resets.map(({ itemKey }) => itemKey),
86
+ });
87
+ const preflight = yield* synchronizeLabels(watched.repository.name, watched.declaredLabels, stored.labelEntityTag);
88
+ yield* hints.defer(preflight.nextPollAt);
89
+ return yield* Effect.gen(function* () {
90
+ // Label creation finishes before change detection and Item evaluation
91
+ // begin, including on the first cycle after `usine up`.
92
+ const detected = yield* github.changes(watched.repository.name, stored.cursor);
93
+ yield* hints.defer(detected.backoffUntil);
94
+ const nextCursor = new StoredPollCursor({
95
+ boardVersion: 4,
96
+ cursor: detected.cursor,
97
+ labelEntityTag: preflight.labelEntityTag,
98
+ watches: watched.watches,
99
+ });
100
+ const nextPollAt = latestPollAt([detected.nextPollAt, preflight.nextPollAt]);
101
+ if (detected._tag === "RepositoryNotModified") {
102
+ if (preflight.entityTagChanged) {
103
+ yield* writeCursor(watched, nextCursor);
104
+ }
105
+ yield* Effect.logDebug("Repository unchanged (304)", {
106
+ repository: watched.repository.name,
107
+ });
108
+ return {
109
+ changedItems: 0,
110
+ submissions: [],
111
+ revokedRuns: 0,
112
+ failures: preflight.failures,
113
+ preflightFindings: preflight.preflightFindings,
114
+ nextPollAt,
115
+ };
116
+ }
117
+ yield* Effect.logInfo("Repository changed", {
118
+ repository: watched.repository.name,
119
+ changedItems: detected.items.length,
120
+ backlog: detected.backlog,
121
+ });
122
+ const itemCycles = yield* Effect.forEach(detected.items, (item) => observeItem(watched.repository.name, item).pipe(Effect.flatMap((projection) => evaluateItem(watched.repository, watched.loops, projection))), { concurrency: ITEM_CONCURRENCY });
123
+ // Advancing the cursor is the commit point: every changed item was
124
+ // fetched, evaluated, and submitted or revoked. After a failure the
125
+ // old cursor stays so the next cycle re-polls.
126
+ yield* writeCursor(watched, nextCursor);
127
+ yield* Effect.forEach(resets, budgets.acknowledgeReset, { discard: true });
128
+ return {
129
+ changedItems: detected.items.length,
130
+ submissions: itemCycles.flatMap(({ submissions }) => submissions),
131
+ revokedRuns: itemCycles.reduce((sum, cycle) => sum + cycle.revokedRuns, 0),
132
+ failures: [...preflight.failures, ...itemCycles.flatMap(({ failures }) => failures)],
133
+ preflightFindings: preflight.preflightFindings,
134
+ nextPollAt,
135
+ };
136
+ }).pipe(Effect.mapError((error) => ({
137
+ _tag: "InterruptedRepositoryCycle",
138
+ error,
139
+ failures: preflight.failures,
140
+ preflightFindings: preflight.preflightFindings,
141
+ nextPollAt: preflight.nextPollAt,
142
+ })));
143
+ });
144
+ // Bind only dependencies, preserving the caller's clock, logging and
145
+ // tracing context on each cycle instead of capturing them at layer build.
146
+ const repositoryServices = (yield* Effect.context()).pipe(Context.pick(ConfigParser, CycleBudgets, ExpressionEngine, GitHubPolling, ItemProjectionWriter, LabelReconciler, RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter, RunEngine));
147
+ const poll = Effect.fn("PollingTriggers.poll")(function* (instance) {
148
+ yield* hints.awaitBackoff;
149
+ const paused = new Set((yield* loops.states).filter((state) => state.paused).map((state) => state.loop));
150
+ for (const loop of instance.loops) {
151
+ if (loop.trigger.on !== "schedule" && paused.has(loop.name)) {
152
+ yield* Effect.logDebug("Paused Loop skipped during repository polling", {
153
+ loop: loop.name,
154
+ });
155
+ }
156
+ }
157
+ const resolved = (yield* resolveTriggerLoops(instance)).filter(({ loop }) => !paused.has(loop.name));
158
+ const watched = watchedRepositories(instance, resolved);
159
+ const settled = yield* Effect.forEach(watched, (repository) => Effect.result(pollRepository(repository)).pipe(Effect.map((result) => ({ repository, result }))), { concurrency: REPOSITORY_CONCURRENCY });
160
+ const cycles = [];
161
+ const failures = [];
162
+ const backoffs = [];
163
+ const preflightFindings = [];
164
+ for (const { repository, result } of settled) {
165
+ if (Result.isSuccess(result)) {
166
+ cycles.push(result.success);
167
+ preflightFindings.push(...result.success.preflightFindings);
168
+ continue;
169
+ }
170
+ const interrupted = result.failure._tag === "InterruptedRepositoryCycle";
171
+ const error = interrupted ? result.failure.error : result.failure;
172
+ if (interrupted) {
173
+ failures.push(...result.failure.failures);
174
+ preflightFindings.push(...result.failure.preflightFindings);
175
+ backoffs.push(result.failure.nextPollAt);
176
+ yield* hints.defer(result.failure.nextPollAt);
177
+ }
178
+ if (error._tag === "GitHubRateLimitError") {
179
+ // A rate-limit pause is scheduling input, not a repository failure.
180
+ yield* Effect.logWarning("GitHub rate limit reached; delaying the next cycle", {
181
+ repository: repository.repository.name,
182
+ operation: error.operation,
183
+ retryAt: DateTime.formatIso(error.retryAt),
184
+ });
185
+ backoffs.push(Option.some(error.retryAt));
186
+ yield* hints.defer(Option.some(error.retryAt));
187
+ continue;
188
+ }
189
+ yield* Effect.logError("Repository poll cycle failed; siblings were unaffected", {
190
+ repository: repository.repository.name,
191
+ ...repositoryFailureLogFields(error),
192
+ });
193
+ failures.push(new RepositoryPollFailure({
194
+ repository: repository.repository.name,
195
+ errorTag: error._tag,
196
+ message: error.message,
197
+ }));
198
+ }
199
+ const cycle = new PollCycle({
200
+ repositories: watched.length,
201
+ changedItems: cycles.reduce((sum, cycle) => sum + cycle.changedItems, 0),
202
+ submissions: cycles.flatMap(({ submissions }) => submissions),
203
+ revokedRuns: cycles.reduce((sum, cycle) => sum + cycle.revokedRuns, 0),
204
+ failures: [...cycles.flatMap(({ failures: isolated }) => isolated), ...failures],
205
+ preflightFindings,
206
+ nextPollAt: latestPollAt([...cycles.map(({ nextPollAt }) => nextPollAt), ...backoffs]),
207
+ });
208
+ yield* Ref.set(latest, Option.some(cycle));
209
+ return cycle;
210
+ }, Effect.provideContext(repositoryServices), ownership.withPermits(1));
211
+ const refreshHint = Effect.fn("PollingTriggers.refreshHint")(function* (instance, hint) {
212
+ yield* Effect.annotateCurrentSpan({
213
+ repository: hint.repository,
214
+ item: hint.item.number,
215
+ });
216
+ yield* hints.awaitBackoff;
217
+ const paused = new Set((yield* loops.states).filter((state) => state.paused).map((state) => state.loop));
218
+ const resolved = (yield* resolveTriggerLoops(instance)).filter(({ loop }) => !paused.has(loop.name));
219
+ const watched = watchedRepositories(instance, resolved).find(({ repository }) => canonicalRepositoryName(repository.name) === canonicalRepositoryName(hint.repository));
220
+ if (watched === undefined) {
221
+ yield* Effect.logInfo("Self-write Hint ignored for an unmanaged repository", {
222
+ repository: hint.repository,
223
+ item: hint.item.number,
224
+ });
225
+ return;
226
+ }
227
+ // Share the normal snapshot, projection and dedup path. Hints never
228
+ // advance a REST cursor or replace the latest complete cycle's findings.
229
+ const observed = yield* observeItem(watched.repository.name, hint.item);
230
+ const result = yield* evaluateItem(watched.repository, watched.loops, observed);
231
+ yield* Effect.logInfo("Self-write Hint refreshed the Item", {
232
+ repository: hint.repository,
233
+ item: hint.item.number,
234
+ submissions: result.submissions.length,
235
+ revokedRuns: result.revokedRuns,
236
+ failures: result.failures.length,
237
+ });
238
+ }, Effect.provideContext(repositoryServices), (effect, _instance, hint) => effect.pipe(Effect.catch((error) => Effect.gen(function* () {
239
+ if (error._tag === "GitHubRateLimitError")
240
+ yield* hints.defer(Option.some(error.retryAt));
241
+ yield* Effect.logWarning("Self-write Hint refresh failed; the normal poll will retry", {
242
+ repository: hint.repository,
243
+ item: hint.item.number,
244
+ ...repositoryFailureLogFields(error),
245
+ });
246
+ })), ownership.withPermits(1)));
247
+ const waitForNextPoll = (instance, target) => Effect.gen(function* () {
248
+ while (true) {
249
+ const remaining = target - (yield* Clock.currentTimeMillis);
250
+ if (remaining <= 0)
251
+ return;
252
+ const hint = yield* Effect.raceFirst(hints.take.pipe(Effect.map(Option.some)), Effect.sleep(Duration.millis(remaining)).pipe(Effect.as(Option.none())));
253
+ if (Option.isNone(hint))
254
+ return;
255
+ yield* refreshHint(instance, hint.value);
256
+ }
257
+ });
258
+ // `run` never returns, so wrapping it in Effect.fn would open a span that
259
+ // never closes; `poll` opens the span for each cycle.
260
+ const run = (instance) => Effect.gen(function* () {
261
+ const startedAt = yield* Clock.currentTimeMillis;
262
+ const result = yield* Effect.result(poll(instance));
263
+ if (Result.isFailure(result)) {
264
+ const sleepMs = instance.config.settings.pollInterval * 1_000;
265
+ yield* Effect.logError("Poll cycle could not read Loop runtime state; retrying", {
266
+ errorTag: result.failure._tag,
267
+ message: result.failure.message,
268
+ operation: result.failure.operation,
269
+ sleepMs,
270
+ });
271
+ yield* Effect.sleep(Duration.millis(sleepMs));
272
+ return;
273
+ }
274
+ const cycle = result.success;
275
+ const intervalAt = startedAt + instance.config.settings.pollInterval * 1_000;
276
+ const target = Option.match(cycle.nextPollAt, {
277
+ onNone: () => intervalAt,
278
+ onSome: (value) => Math.max(intervalAt, DateTime.toEpochMillis(value)),
279
+ });
280
+ const now = yield* Clock.currentTimeMillis;
281
+ const sleepMs = Math.max(0, target - now);
282
+ yield* Effect.logInfo("Poll cycle complete", {
283
+ repositories: cycle.repositories,
284
+ changedItems: cycle.changedItems,
285
+ submissions: cycle.submissions.length,
286
+ revokedRuns: cycle.revokedRuns,
287
+ failures: cycle.failures.length,
288
+ preflightFindings: cycle.preflightFindings.length,
289
+ sleepMs,
290
+ });
291
+ yield* waitForNextPoll(instance, target);
292
+ }).pipe(Effect.forever);
293
+ return { latest: Ref.get(latest), poll, run, hint: hints.offer };
294
+ })).pipe(Layer.provide(ItemHints.layer));
295
+ }
296
+ //# sourceMappingURL=polling.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"polling.js","sourceRoot":"","sources":["../../src/polling/polling.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAuB,MAAM,wBAAwB,CAAC;AACtF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EACL,SAAS,GAGV,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EACL,+BAA+B,EAC/B,+BAA+B,GAChC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAoB,SAAS,EAAE,UAAU,EAAE,aAA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,EAAE;gBAC5C,MAAM,EAAE,GAAG,EAAE,CAAC,UAAU;gBACxB,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;aACvE,CAAC,CAAC;YACH,MAAM,GAAG,GAAG,KAAK,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC;YAC3C,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC;YAC1C,KAAK,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,qBAAqB,EAAE;gBAC3C,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,YAAY,EAAE,KAAK,CAAC,YAAY;gBAChC,WAAW,EAAE,KAAK,CAAC,WAAW,CAAC,MAAM;gBACrC,WAAW,EAAE,KAAK,CAAC,WAAW;gBAC9B,QAAQ,EAAE,KAAK,CAAC,QAAQ,CAAC,MAAM;gBAC/B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB,CAAC,MAAM;gBACjD,OAAO;aACR,CAAC,CAAC;YACH,KAAK,CAAC,CAAC,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,CAAC;IACnE,CAAC,CAAC,CACH,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;CACxC"}
@@ -0,0 +1,45 @@
1
+ import type { DeclaredLabel } from "@usine/config/label";
2
+ import { CycleGeneration } from "@usine/core/cycle-budget";
3
+ import { CycleBudgets } from "@usine/engine/cycle-budget";
4
+ import { ItemProjection, ItemProjectionWriter } from "@usine/engine/item-projection";
5
+ import { RepositoryLabelProjectionReader, RepositoryLabelProjectionWriter } from "@usine/engine/repository-label-projection";
6
+ import { GitHubPolling } from "@usine/github/polling";
7
+ import { DateTime, Effect, Option, Schema } from "effect";
8
+ import { LabelReconciler } from "../label-reconciler.ts";
9
+ import { type InterruptedRepositoryCycle, RepositoryPollFailure } from "./cycle.ts";
10
+ /**
11
+ * Identifies one GitHub issue or pull request across its changing snapshots.
12
+ * Encoding uses the canonical repository name and Item number; decoding lets
13
+ * Board consumers locate the Item associated with a Run. Schedule Runs identify
14
+ * the repository alone and do not decode as an Item.
15
+ */
16
+ export declare const GitHubItemKey: Schema.compose<Schema.fromJsonString<Schema.Tuple<readonly [Schema.Literal<"github">, Schema.brand<Schema.String, "RepositoryName">, Schema.brand<Schema.Int, "ItemNumber">]>>, Schema.toType<Schema.brand<Schema.NonEmptyString, "ItemKey">>>;
17
+ /**
18
+ * Refreshes and reconciles one repository's Board label catalog before change
19
+ * detection. Pass the catalog ETag from its stored poll cursor; the result gives
20
+ * the ETag to persist after Item processing, plus preflight findings and backoff.
21
+ * Failed catalog requests retain the stored projection and defer provisioning;
22
+ * persistence failures stop the repository for retry.
23
+ */
24
+ export declare const synchronizeLabels: (repository: string & import("effect/Brand").Brand<"RepositoryName">, declared: readonly DeclaredLabel[], entityTag: Option.Option<string & import("effect/Brand").Brand<"GitHubEntityTag">>) => Effect.Effect<{
25
+ labelEntityTag: Option.None<string & import("effect/Brand").Brand<"GitHubEntityTag">> | Option.Some<string & import("effect/Brand").Brand<"GitHubEntityTag">>;
26
+ entityTagChanged: boolean;
27
+ failures: never[] | RepositoryPollFailure[];
28
+ preflightFindings: readonly import("../label-reconciler.ts").LabelPreflightFinding[];
29
+ nextPollAt: Option.Option<DateTime.Utc>;
30
+ }, import("@usine/engine/engine").EnginePersistenceError | InterruptedRepositoryCycle, GitHubPolling | LabelReconciler | RepositoryLabelProjectionReader | RepositoryLabelProjectionWriter>;
31
+ /** A fetched snapshot paired with the allowance observed before its request began. */
32
+ export interface ObservedItem {
33
+ readonly projection: ItemProjection;
34
+ readonly cycleGeneration: CycleGeneration;
35
+ }
36
+ /**
37
+ * Fetches a detected Item and durably updates its Board projection regardless of
38
+ * whether any Loop applies. Evaluation uses the returned projection's snapshot,
39
+ * identity and content hash, so Board observation and Run decisions agree.
40
+ */
41
+ export declare const observeItem: (repository: string & import("effect/Brand").Brand<"RepositoryName">, changed: import("@usine/github/polling").ChangedIssue | import("@usine/github/polling").ChangedPullRequest) => Effect.Effect<{
42
+ projection: ItemProjection;
43
+ cycleGeneration: number & import("effect/Brand").Brand<"CycleGeneration">;
44
+ }, import("@usine/github/github-app").AppPermissionError | import("@usine/engine/engine").EnginePersistenceError | import("@usine/github/github-app").GitHubApiError | import("@usine/github/github-app").GitHubRateLimitError | import("@usine/github/github-app").InstallationDiscoveryError | import("@usine/github/github-app").InvalidGitHubResponseError, CycleBudgets | GitHubPolling | ItemProjectionWriter>;
45
+ //# sourceMappingURL=repository-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"repository-sync.d.ts","sourceRoot":"","sources":["../../src/polling/repository-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG1D,OAAO,EAEL,cAAc,EAEd,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,+BAA+B,EAC/B,+BAA+B,EAChC,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAGL,aAAa,EAGd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAU,MAAM,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAA4B,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACnF,OAAO,EACL,KAAK,0BAA0B,EAE/B,qBAAqB,EAEtB,MAAM,YAAY,CAAC;AAEpB;;;;;GAKG;AACH,eAAO,MAAM,aAAa,gPAIzB,CAAC;AA8GF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB;;;;;;2LAwC5B,CAAC;AAEH,sFAAsF;AACtF,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC;IACpC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;CAC3C;AAED;;;;GAIG;AACH,eAAO,MAAM,WAAW;;;oZA+BtB,CAAC"}