@boxxy/model 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (234) hide show
  1. package/README.md +8 -6
  2. package/dist/closeouts/build-close-out-schema.d.ts +31 -0
  3. package/dist/closeouts/close-out-answer-schema.d.ts +3 -0
  4. package/dist/closeouts/close-out-schema.d.ts +3 -0
  5. package/dist/closeouts/design-close-out-schema.d.ts +30 -0
  6. package/dist/closeouts/friction-schema.d.ts +14 -0
  7. package/dist/closeouts/open-item-schema.d.ts +3 -0
  8. package/dist/closeouts/review-close-out-schema.d.ts +40 -0
  9. package/dist/closeouts/triage-close-out-schema.d.ts +40 -0
  10. package/dist/closeouts/types.d.ts +221 -0
  11. package/dist/dispatch/build-applied-change.d.ts +6 -0
  12. package/dist/dispatch/collect-seat-sync.d.ts +14 -0
  13. package/dist/dispatch/pick-seat-take.d.ts +10 -0
  14. package/dist/dispatch/types.d.ts +11 -0
  15. package/dist/{outbox-fact-schema.d.ts → facts/outbox-fact-schema.d.ts} +1 -1
  16. package/dist/facts/parse-new-fact.d.ts +2 -0
  17. package/dist/facts/types.d.ts +191 -0
  18. package/dist/facts/work-fact-schemas.d.ts +293 -0
  19. package/dist/index.d.ts +64 -23
  20. package/dist/items/build-item-views.d.ts +4 -0
  21. package/dist/items/collect-retries.d.ts +3 -0
  22. package/dist/items/collect-settled.d.ts +3 -0
  23. package/dist/items/derive-item-state.d.ts +17 -0
  24. package/dist/{live-levers.d.ts → items/live-levers.d.ts} +1 -1
  25. package/dist/items/types.d.ts +12 -0
  26. package/dist/pipeline/advance.d.ts +10 -0
  27. package/dist/pipeline/constants.d.ts +2 -0
  28. package/dist/pipeline/count-trailing.d.ts +1 -0
  29. package/dist/pipeline/find-position.d.ts +9 -0
  30. package/dist/pipeline/find-step.d.ts +3 -0
  31. package/dist/pipeline/merge-by-time.d.ts +9 -0
  32. package/dist/pipeline/position-schema.d.ts +3 -0
  33. package/dist/pipeline/types.d.ts +28 -0
  34. package/dist/planning/define-admission.d.ts +3 -0
  35. package/dist/planning/define-gate.d.ts +3 -0
  36. package/dist/planning/define-signal.d.ts +3 -0
  37. package/dist/planning/is-filter-match.d.ts +3 -0
  38. package/dist/planning/limit-fill-schema.d.ts +3 -0
  39. package/dist/{signal-key.d.ts → planning/signal-key.d.ts} +1 -1
  40. package/dist/planning/types.d.ts +155 -0
  41. package/dist/ports/types.d.ts +289 -0
  42. package/dist/reports/constants.d.ts +3 -0
  43. package/dist/reports/cost-to-land-schema.d.ts +29 -0
  44. package/dist/reports/outbox-status.d.ts +16 -0
  45. package/dist/reports/stage-time-schema.d.ts +25 -0
  46. package/dist/reports/types.d.ts +5 -0
  47. package/dist/rows/actor-ref-schema.d.ts +2 -0
  48. package/dist/rows/attempt-row-schema.d.ts +3 -0
  49. package/dist/rows/attempt-session-row-schema.d.ts +3 -0
  50. package/dist/{brand-schemas.d.ts → rows/brand-schemas.d.ts} +5 -2
  51. package/dist/rows/caller-identity-schema.d.ts +3 -0
  52. package/dist/rows/criterion-schema.d.ts +3 -0
  53. package/dist/rows/decision-row-schema.d.ts +34 -0
  54. package/dist/rows/evidence-row-schema.d.ts +3 -0
  55. package/dist/rows/item-row-schema.d.ts +28 -0
  56. package/dist/rows/item-view-schema.d.ts +3 -0
  57. package/dist/rows/lease-row-schema.d.ts +3 -0
  58. package/dist/rows/lever-row-schema.d.ts +12 -0
  59. package/dist/rows/limit-schema.d.ts +3 -0
  60. package/dist/rows/limit-seat-row-schema.d.ts +3 -0
  61. package/dist/rows/note-row-schema.d.ts +3 -0
  62. package/dist/rows/notice-row-schema.d.ts +3 -0
  63. package/dist/rows/pull-request-row-schema.d.ts +3 -0
  64. package/dist/rows/relation-row-schema.d.ts +3 -0
  65. package/dist/{row-schemas.d.ts → rows/row-schemas.d.ts} +2 -2
  66. package/dist/rows/runner-row-schema.d.ts +3 -0
  67. package/dist/rows/spawn-request-schema.d.ts +3 -0
  68. package/dist/rules/define-phase.d.ts +3 -0
  69. package/dist/rules/load-rejection-schema.d.ts +3 -0
  70. package/dist/rules/types.d.ts +244 -0
  71. package/dist/test-utils/build-mock-cost-to-land.d.ts +2 -0
  72. package/dist/test-utils/build-mock-evidence-row.d.ts +1 -1
  73. package/dist/test-utils/build-mock-fact-id.d.ts +1 -1
  74. package/dist/test-utils/build-mock-frame-item.d.ts +1 -1
  75. package/dist/test-utils/build-mock-frame.d.ts +2 -0
  76. package/dist/test-utils/build-mock-item-rules.d.ts +2 -0
  77. package/dist/test-utils/build-mock-lease-row.d.ts +1 -1
  78. package/dist/test-utils/build-mock-outbox-fact.d.ts +2 -0
  79. package/dist/test-utils/build-mock-phase-kind.d.ts +7 -0
  80. package/dist/test-utils/build-mock-pipeline.d.ts +7 -0
  81. package/dist/test-utils/build-mock-relation-row.d.ts +2 -0
  82. package/dist/test-utils/build-mock-settled.d.ts +9 -0
  83. package/dist/test-utils/build-mock-snapshot.d.ts +1 -1
  84. package/dist/test-utils/build-mock-v1-attempt-row.d.ts +2 -0
  85. package/dist/test-utils/build-mock-v1-item-row.d.ts +2 -0
  86. package/dist/test-utils/build-mock-v1-item-view.d.ts +2 -0
  87. package/dist/test-utils/build-mock-v1-lever-row.d.ts +2 -0
  88. package/dist/test-utils/build-mock-v1-pull-request-row.d.ts +2 -0
  89. package/dist/test-utils/build-mock-work-fact.d.ts +12 -0
  90. package/dist/test-utils/create-fake-notifier.d.ts +9 -0
  91. package/dist/test-utils/create-fake-pepys-reader.d.ts +13 -0
  92. package/dist/test-utils/fact-sink-contract.d.ts +14 -0
  93. package/dist/test-utils/pepys-reader-contract.d.ts +17 -0
  94. package/dist/{types/core.d.ts → types.d.ts} +93 -43
  95. package/package.json +13 -3
  96. package/src/{build-close-out-schema.ts → closeouts/build-close-out-schema.ts} +5 -10
  97. package/src/closeouts/close-out-answer-schema.ts +42 -0
  98. package/src/closeouts/close-out-schema.ts +13 -0
  99. package/src/closeouts/design-close-out-schema.ts +20 -0
  100. package/src/closeouts/friction-schema.ts +11 -0
  101. package/src/closeouts/open-item-schema.ts +8 -0
  102. package/src/closeouts/review-close-out-schema.ts +38 -0
  103. package/src/closeouts/triage-close-out-schema.ts +29 -0
  104. package/src/closeouts/types.ts +230 -0
  105. package/src/dispatch/build-applied-change.ts +57 -0
  106. package/src/dispatch/collect-seat-sync.ts +86 -0
  107. package/src/dispatch/pick-seat-take.ts +39 -0
  108. package/src/dispatch/types.ts +14 -0
  109. package/src/facts/outbox-fact-schema.ts +22 -0
  110. package/src/facts/parse-new-fact.ts +16 -0
  111. package/src/facts/types.ts +235 -0
  112. package/src/facts/work-fact-schemas.ts +201 -0
  113. package/src/index.ts +147 -55
  114. package/src/items/build-item-views.ts +146 -0
  115. package/src/items/collect-retries.ts +12 -0
  116. package/src/items/collect-settled.ts +20 -0
  117. package/src/items/derive-item-state.ts +95 -0
  118. package/src/{live-levers.ts → items/live-levers.ts} +1 -1
  119. package/src/items/types.ts +26 -0
  120. package/src/pipeline/advance.ts +78 -0
  121. package/src/pipeline/constants.ts +12 -0
  122. package/src/pipeline/count-trailing.ts +16 -0
  123. package/src/pipeline/find-position.ts +74 -0
  124. package/src/pipeline/find-step.ts +6 -0
  125. package/src/pipeline/merge-by-time.ts +33 -0
  126. package/src/pipeline/position-schema.ts +27 -0
  127. package/src/pipeline/types.ts +47 -0
  128. package/src/{define-admission.ts → planning/define-admission.ts} +2 -2
  129. package/src/{define-gate.ts → planning/define-gate.ts} +2 -2
  130. package/src/{define-signal.ts → planning/define-signal.ts} +2 -2
  131. package/src/planning/is-filter-match.ts +10 -0
  132. package/src/planning/limit-fill-schema.ts +12 -0
  133. package/src/{signal-key.ts → planning/signal-key.ts} +1 -1
  134. package/src/planning/types.ts +216 -0
  135. package/src/ports/types.ts +412 -0
  136. package/src/reports/constants.ts +6 -0
  137. package/src/reports/cost-to-land-schema.ts +47 -0
  138. package/src/reports/outbox-status.ts +22 -0
  139. package/src/reports/stage-time-schema.ts +21 -0
  140. package/src/reports/types.ts +7 -0
  141. package/src/rows/actor-ref-schema.ts +17 -0
  142. package/src/rows/attempt-row-schema.ts +69 -0
  143. package/src/rows/attempt-session-row-schema.ts +12 -0
  144. package/src/{brand-schemas.ts → rows/brand-schemas.ts} +5 -2
  145. package/src/rows/caller-identity-schema.ts +7 -0
  146. package/src/rows/criterion-schema.ts +9 -0
  147. package/src/rows/decision-row-schema.ts +34 -0
  148. package/src/rows/evidence-row-schema.ts +13 -0
  149. package/src/rows/item-row-schema.ts +32 -0
  150. package/src/rows/item-view-schema.ts +31 -0
  151. package/src/rows/lease-row-schema.ts +12 -0
  152. package/src/rows/lever-row-schema.ts +17 -0
  153. package/src/rows/limit-schema.ts +12 -0
  154. package/src/rows/limit-seat-row-schema.ts +12 -0
  155. package/src/rows/note-row-schema.ts +12 -0
  156. package/src/rows/notice-row-schema.ts +17 -0
  157. package/src/rows/pull-request-row-schema.ts +15 -0
  158. package/src/rows/relation-row-schema.ts +13 -0
  159. package/src/rows/row-schemas.ts +30 -0
  160. package/src/rows/runner-row-schema.ts +9 -0
  161. package/src/rows/spawn-request-schema.ts +15 -0
  162. package/src/rules/define-phase.ts +12 -0
  163. package/src/rules/load-rejection-schema.ts +51 -0
  164. package/src/rules/types.ts +291 -0
  165. package/src/test-utils/build-mock-cost-to-land.ts +31 -0
  166. package/src/test-utils/build-mock-evidence-row.ts +2 -2
  167. package/src/test-utils/build-mock-fact-id.ts +3 -3
  168. package/src/test-utils/build-mock-frame-item.ts +10 -5
  169. package/src/test-utils/build-mock-frame.ts +13 -0
  170. package/src/test-utils/build-mock-item-rules.ts +17 -0
  171. package/src/test-utils/build-mock-lease-row.ts +2 -2
  172. package/src/test-utils/build-mock-outbox-fact.ts +22 -0
  173. package/src/test-utils/build-mock-phase-kind.ts +29 -0
  174. package/src/test-utils/build-mock-pipeline.ts +52 -0
  175. package/src/test-utils/{build-mock-link-row.ts → build-mock-relation-row.ts} +4 -4
  176. package/src/test-utils/build-mock-settled.ts +18 -0
  177. package/src/test-utils/build-mock-snapshot.ts +10 -2
  178. package/src/test-utils/{build-mock-attempt-row.ts → build-mock-v1-attempt-row.ts} +28 -9
  179. package/src/test-utils/{build-mock-item-row.ts → build-mock-v1-item-row.ts} +7 -3
  180. package/src/test-utils/build-mock-v1-item-view.ts +29 -0
  181. package/src/test-utils/{build-mock-lever-row.ts → build-mock-v1-lever-row.ts} +5 -3
  182. package/src/test-utils/build-mock-v1-pull-request-row.ts +26 -0
  183. package/src/test-utils/build-mock-work-fact.ts +179 -0
  184. package/src/test-utils/create-fake-notifier.ts +54 -0
  185. package/src/test-utils/create-fake-pepys-reader.ts +73 -0
  186. package/src/test-utils/fact-sink-contract.ts +103 -0
  187. package/src/test-utils/pepys-reader-contract.ts +117 -0
  188. package/src/{types/core.ts → types.ts} +183 -59
  189. package/dist/actor-ref-schema.d.ts +0 -2
  190. package/dist/build-applied-change.d.ts +0 -13
  191. package/dist/build-close-out-schema.d.ts +0 -3
  192. package/dist/build-item-views.d.ts +0 -2
  193. package/dist/define-admission.d.ts +0 -3
  194. package/dist/define-gate.d.ts +0 -3
  195. package/dist/define-signal.d.ts +0 -3
  196. package/dist/derive-item-state.d.ts +0 -2
  197. package/dist/fact-schemas.d.ts +0 -5
  198. package/dist/find-slot-take.d.ts +0 -5
  199. package/dist/friction-schema.d.ts +0 -3
  200. package/dist/test-utils/build-mock-attempt-row.d.ts +0 -2
  201. package/dist/test-utils/build-mock-item-row.d.ts +0 -2
  202. package/dist/test-utils/build-mock-item-rows.d.ts +0 -2
  203. package/dist/test-utils/build-mock-item-view.d.ts +0 -2
  204. package/dist/test-utils/build-mock-lever-row.d.ts +0 -2
  205. package/dist/test-utils/build-mock-link-row.d.ts +0 -2
  206. package/dist/test-utils/build-mock-pull-request-row.d.ts +0 -2
  207. package/dist/types/dispatch.d.ts +0 -82
  208. package/dist/types/facts.d.ts +0 -154
  209. package/dist/types/planning.d.ts +0 -94
  210. package/dist/types/ports.d.ts +0 -218
  211. package/dist/types/registries.d.ts +0 -150
  212. package/src/actor-ref-schema.ts +0 -9
  213. package/src/build-applied-change.ts +0 -71
  214. package/src/build-item-views.ts +0 -128
  215. package/src/derive-item-state.ts +0 -76
  216. package/src/fact-schemas.ts +0 -132
  217. package/src/find-slot-take.ts +0 -12
  218. package/src/friction-schema.ts +0 -10
  219. package/src/outbox-fact-schema.ts +0 -25
  220. package/src/row-schemas.ts +0 -89
  221. package/src/test-utils/build-mock-item-rows.ts +0 -14
  222. package/src/test-utils/build-mock-item-view.ts +0 -8
  223. package/src/test-utils/build-mock-pull-request-row.ts +0 -16
  224. package/src/types/dispatch.ts +0 -95
  225. package/src/types/facts.ts +0 -166
  226. package/src/types/planning.ts +0 -136
  227. package/src/types/ports.ts +0 -262
  228. package/src/types/registries.ts +0 -185
  229. /package/dist/test-utils/{seed-faker.d.ts → pin-faker-seed.d.ts} +0 -0
  230. /package/dist/{format-key-path.d.ts → utils/format-key-path.d.ts} +0 -0
  231. /package/dist/{to-json-value.d.ts → utils/to-json-value.d.ts} +0 -0
  232. /package/src/test-utils/{seed-faker.ts → pin-faker-seed.ts} +0 -0
  233. /package/src/{format-key-path.ts → utils/format-key-path.ts} +0 -0
  234. /package/src/{to-json-value.ts → utils/to-json-value.ts} +0 -0
@@ -1,166 +0,0 @@
1
- import type { JsonValue } from '@boxxy/content-hash';
2
- import type {
3
- ActorRef,
4
- AgentSessionId,
5
- AtcSessionId,
6
- CommitSha,
7
- Criterion,
8
- CriterionId,
9
- DecisionRow,
10
- EvidenceKind,
11
- FactId,
12
- Instant,
13
- ItemId,
14
- ItemRow,
15
- LeverRow,
16
- LinkTypeName,
17
- PhaseName,
18
- PoolName,
19
- RecipeHash,
20
- RepoName,
21
- RulesVersion,
22
- RunnerId,
23
- } from './core.ts';
24
-
25
- export interface BuildCloseOut {
26
- readonly result:
27
- | { readonly kind: 'built' }
28
- | { readonly kind: 'blocked'; readonly reason: string }
29
- | { readonly kind: 'abandoned'; readonly reason: string };
30
- readonly criteria: readonly { readonly criterion: CriterionId; readonly evidence: FactId }[];
31
- readonly openItems: readonly OpenItem[];
32
- readonly friction: readonly Friction[];
33
- readonly frictionDropped: number;
34
- }
35
-
36
- export interface OpenItem {
37
- readonly kind: 'core.issue';
38
- readonly title: string;
39
- readonly body: string;
40
- }
41
-
42
- export type FrictionTargetKind = 'skill' | 'rule' | 'lint' | 'agents-md' | 'tool';
43
-
44
- export interface Friction {
45
- readonly target: { readonly kind: FrictionTargetKind; readonly name: string };
46
- readonly change: string;
47
- }
48
-
49
- export type EntityRef =
50
- | `boxxy:item:${string}`
51
- | `boxxy:link:${string}:${string}:${string}`
52
- | `boxxy:attempt:${string}`
53
- | `boxxy:decision:${string}`
54
- | `boxxy:runner:${string}`;
55
-
56
- export interface FactEnvelope<
57
- M extends object = SliceOneFacts,
58
- T extends keyof M & string = keyof M & string,
59
- > {
60
- readonly id: FactId;
61
- readonly type: T;
62
-
63
- // oxlint-disable-next-line id-length -- pepys's fact envelope names this field
64
- readonly v: 1;
65
- readonly api: 'boxxy/1';
66
- readonly entity: EntityRef;
67
- readonly actor: ActorRef;
68
- readonly at: Instant;
69
- readonly payload: M[T] & { readonly storeVersion: number };
70
- }
71
-
72
- export interface NewFact<T extends keyof M & string, M extends object = SliceOneFacts> {
73
- readonly id: FactId;
74
- readonly type: T;
75
- readonly entity: EntityRef;
76
- readonly actor: ActorRef;
77
- readonly payload: M[T];
78
- }
79
-
80
- export interface OutboxFact {
81
- readonly seq: number;
82
- readonly factId: FactId;
83
- readonly type: string;
84
- readonly entity: EntityRef;
85
- readonly actor: ActorRef;
86
- readonly at: Instant;
87
- readonly payload: JsonValue;
88
- readonly sentAt: Instant | null;
89
- }
90
-
91
- export type FactType = keyof SliceOneFacts;
92
-
93
- export interface LinkPayload {
94
- readonly source: ItemId;
95
- readonly target: ItemId;
96
- readonly type: LinkTypeName;
97
- }
98
-
99
- export interface SliceOneFacts {
100
- 'boxxy.item.filed': ItemRow;
101
- 'boxxy.item.edited': {
102
- readonly title?: string;
103
- readonly outcome?: string;
104
- readonly acceptance?: readonly Criterion[];
105
- };
106
- 'boxxy.item.closed': { readonly reason: string };
107
- 'boxxy.link.added': LinkPayload;
108
- 'boxxy.link.removed': LinkPayload;
109
- 'boxxy.lever.recorded': LeverRow;
110
- 'boxxy.attempt.claimed': {
111
- readonly item: ItemId;
112
- readonly phase: PhaseName;
113
- readonly number: number;
114
- readonly pool: PoolName;
115
- readonly slot: number;
116
- readonly gen: number;
117
- readonly recipeHash: RecipeHash;
118
- readonly rulesVersion: RulesVersion;
119
- };
120
- 'boxxy.decision.recorded': DecisionRow;
121
- 'boxxy.attempt.started': { readonly atcSession: AtcSessionId };
122
- 'boxxy.attempt.reconciling': { readonly reason: string };
123
- 'boxxy.attempt.reconciled': { readonly atcSession: AtcSessionId };
124
- 'boxxy.attempt.session_bound': {
125
- readonly atcSession: AtcSessionId;
126
- readonly agentSession: AgentSessionId;
127
- readonly seenAt: Instant;
128
- };
129
- 'boxxy.attempt.closed_out': { readonly closeOut: BuildCloseOut };
130
- 'boxxy.attempt.settled': {
131
- readonly state: 'succeeded' | 'failed';
132
- readonly failure: string | null;
133
- readonly endedAt: Instant;
134
- readonly criteria: readonly {
135
- readonly criterion: CriterionId;
136
- readonly evidence: readonly FactId[];
137
- }[];
138
- readonly matched: readonly ItemId[];
139
- readonly frictionDropped: number;
140
- };
141
- 'boxxy.evidence.recorded': {
142
- readonly kind: EvidenceKind;
143
- readonly ref: string;
144
- readonly observed: string | null;
145
- };
146
- 'boxxy.evidence.pr_linked': {
147
- readonly repo: RepoName;
148
- readonly number: number;
149
- readonly url: string;
150
- };
151
- 'boxxy.evidence.commit_linked': {
152
- readonly repo: RepoName;
153
- readonly sha: CommitSha;
154
- readonly pr: number;
155
- };
156
- 'boxxy.pr.merged': {
157
- readonly repo: RepoName;
158
- readonly number: number;
159
- readonly mergedAt: Instant;
160
- readonly mergeCommit: CommitSha;
161
- };
162
- 'boxxy.pr.closed': { readonly repo: RepoName; readonly number: number };
163
- 'boxxy.proposal.recorded': Friction;
164
- 'boxxy.runner.paused': { readonly runner: RunnerId };
165
- 'boxxy.runner.resumed': { readonly runner: RunnerId };
166
- }
@@ -1,136 +0,0 @@
1
- import type {
2
- FaultRecord,
3
- Instant,
4
- ItemId,
5
- ItemView,
6
- LeverRow,
7
- LinkRow,
8
- LinkTypeName,
9
- PhaseName,
10
- PoolName,
11
- } from './core.ts';
12
- import type { Schema } from './registries.ts';
13
-
14
- export type SignalName = string;
15
-
16
- export type GateName = string;
17
-
18
- export type WaiverName = string;
19
-
20
- export type AdmissionName = string;
21
-
22
- export type ViewName = string;
23
-
24
- export type SignalKey = `${SignalName}#${string}`;
25
-
26
- export interface Snapshot {
27
- storeVersion: number;
28
-
29
- // every item not yet done and not archived, with its state derived at the read's `now`
30
- items: ItemView[];
31
- links: LinkRow[];
32
- levers: LeverRow[];
33
- freeSlots: Record<PoolName, number>;
34
- }
35
-
36
- export interface FrameItem extends ItemView {
37
- readonly phase: PhaseName;
38
- }
39
-
40
- export interface Frame {
41
- // the open items in state `ready`, the only items decide picks
42
- candidates: FrameItem[];
43
- fields: Map<ItemId, Readonly<Record<string, readonly string[]>>>;
44
- values: Map<SignalKey, Map<ItemId, number>>;
45
- holds: Map<ItemId, Hold[]>;
46
- lifted: Map<ItemId, Lift[]>;
47
- faults: Fault[];
48
- }
49
-
50
- export type FrameValues = ReadonlyMap<SignalKey, ReadonlyMap<ItemId, number>>;
51
-
52
- export interface Hold {
53
- readonly gate: GateName;
54
- readonly reason: string;
55
- readonly until?: Instant;
56
- }
57
-
58
- export interface Lift {
59
- readonly waiver: WaiverName;
60
- readonly gate: GateName;
61
- readonly reason: string;
62
- }
63
-
64
- export type Fault = FaultRecord;
65
-
66
- export interface Decision {
67
- // in pool order, then by each pool's `order`
68
- picks: Pick[];
69
- }
70
-
71
- export interface Pick {
72
- item: ItemId;
73
- phase: PhaseName;
74
- pool: PoolName;
75
- }
76
-
77
- export interface Pool {
78
- readonly name: PoolName;
79
- readonly slots: number;
80
- readonly takes: Readonly<Record<string, readonly string[]>>;
81
-
82
- // `lead`, then the pool's own `order`: lower first, no value last, then item id
83
- readonly order: readonly SignalKey[];
84
- }
85
-
86
- export interface PlanContext {
87
- now: Instant;
88
- levers: LeverRow[];
89
- links: LinkRow[];
90
- values: FrameValues;
91
- }
92
-
93
- export interface Signal<P> {
94
- name: SignalName;
95
- params: Schema<P>;
96
-
97
- // null is no opinion
98
- value: (item: FrameItem, ctx: PlanContext, params: P) => number | null;
99
- combine?: (left: number, right: number) => number;
100
- }
101
-
102
- export interface Gate<P> {
103
- name: GateName;
104
- liftable: boolean;
105
- params: Schema<P>;
106
- hold: (item: FrameItem, ctx: PlanContext, params: P) => Hold | null;
107
- }
108
-
109
- export interface Waiver {
110
- name: WaiverName;
111
- lifts: GateName;
112
- lift: (item: FrameItem, hold: Hold, ctx: PlanContext) => Lift | null;
113
- }
114
-
115
- export interface Admission<P> {
116
- name: AdmissionName;
117
- params: Schema<P>;
118
- admit: (item: FrameItem, ctx: PlanContext, params: P) => AdmissionGrant | null;
119
- }
120
-
121
- export interface AdmissionGrant {
122
- readonly admission: AdmissionName;
123
- readonly pools: readonly PoolName[] | 'any';
124
- readonly reason: string;
125
- }
126
-
127
- export interface View<I = unknown, O = unknown> {
128
- name: ViewName;
129
- render: (frame: Frame, input: I) => O;
130
- }
131
-
132
- export interface PropagationLine {
133
- readonly value: SignalName;
134
- readonly over: LinkTypeName;
135
- readonly toward: 'source' | 'target';
136
- }
@@ -1,262 +0,0 @@
1
- import type { JsonValue } from '@boxxy/content-hash';
2
- import type {
3
- AgentSessionId,
4
- AtcSessionId,
5
- AttemptId,
6
- AttemptRow,
7
- AttemptSessionRow,
8
- CommitSha,
9
- DecisionRow,
10
- Effort,
11
- EvidenceRow,
12
- FactId,
13
- Instant,
14
- ItemId,
15
- ItemRow,
16
- ItemState,
17
- ItemView,
18
- ItemWithLevers,
19
- LeaseRow,
20
- LeverRow,
21
- LinkRow,
22
- MaxAttemptsByKind,
23
- PhaseName,
24
- PoolName,
25
- PoolSlotRow,
26
- PullRequestRef,
27
- PullRequestRow,
28
- RepoName,
29
- RunnerId,
30
- RunnerRow,
31
- } from './core.ts';
32
- import type { FactType, NewFact, OutboxFact } from './facts.ts';
33
- import type { Snapshot } from './planning.ts';
34
-
35
- export interface ClaimStore {
36
- exclusive: <T>(work: (tx: StoreTx) => Promise<T>) => Promise<T>;
37
- read: <T>(work: (tx: StoreReader) => Promise<T>) => Promise<T>;
38
- }
39
-
40
- export interface StoreReader {
41
- readSnapshot: (now: Instant, maxAttemptsByKind: MaxAttemptsByKind) => Promise<Snapshot>;
42
- readItem: (
43
- id: ItemId,
44
- now: Instant,
45
- maxAttemptsByKind: MaxAttemptsByKind,
46
- ) => Promise<ItemView | null>;
47
- readItemDetail: (
48
- id: ItemId,
49
- now: Instant,
50
- maxAttemptsByKind: MaxAttemptsByKind,
51
- ) => Promise<ItemDetailRows | null>;
52
- listItems: (
53
- filter: ItemFilter,
54
- now: Instant,
55
- maxAttemptsByKind: MaxAttemptsByKind,
56
- ) => Promise<ItemWithLevers[]>;
57
- listOpenIssues: (
58
- repo: RepoName,
59
- now: Instant,
60
- maxAttemptsByKind: MaxAttemptsByKind,
61
- ) => Promise<ItemView[]>;
62
-
63
- // 0 when the item phase has no lease
64
- readLastLeaseGen: (item: ItemId, phase: PhaseName) => Promise<number>;
65
- readAttempt: (id: AttemptId) => Promise<AttemptRow | null>;
66
- listEvidence: (attempt: AttemptId) => Promise<EvidenceRow[]>;
67
- listLiveAttempts: () => Promise<AttemptRow[]>;
68
- listSucceededAttemptsWithoutPr: () => Promise<AttemptRow[]>;
69
- findAttemptBySession: (session: AtcSessionId) => Promise<AttemptRow | null>;
70
- findAttemptByAgentSession: (session: AgentSessionId) => Promise<AttemptId | null>;
71
-
72
- // the rows in state `open`
73
- listWatchedPullRequests: () => Promise<PullRequestRow[]>;
74
-
75
- // retired rows included
76
- listPoolSlots: () => Promise<PoolSlotRow[]>;
77
-
78
- // oldest first
79
- readUnsentFacts: (limit: number) => Promise<OutboxFact[]>;
80
- readOutboxLag: () => Promise<{
81
- readonly unsent: number;
82
- readonly oldestUnsentAt: Instant | null;
83
- }>;
84
-
85
- // null before the runner's first heartbeat, which reads as not paused
86
- readRunner: (id: RunnerId) => Promise<RunnerRow | null>;
87
- }
88
-
89
- export interface ItemDetailRows {
90
- readonly item: ItemWithLevers;
91
- readonly attempts: readonly AttemptRow[];
92
- readonly links: readonly LinkRow[];
93
- readonly evidence: readonly EvidenceRow[];
94
- readonly pullRequests: readonly PullRequestRow[];
95
- }
96
-
97
- export interface StoreTx extends StoreReader {
98
- applyChange: (change: StoreChange) => Promise<ApplyResult>;
99
- markFactsSent: (ids: FactId[], at: Instant) => Promise<void>;
100
- writeHeartbeat: (runner: RunnerId, at: Instant) => Promise<void>;
101
- syncPoolSlots: (
102
- pools: readonly { readonly name: PoolName; readonly slots: number }[],
103
- ) => Promise<void>;
104
- markPullRequestChecked: (ref: PullRequestRef, at: Instant) => Promise<void>;
105
- }
106
-
107
- export interface StoreChange {
108
- at: Instant;
109
- under?: {
110
- item: ItemId;
111
- phase: PhaseName;
112
- gen: number;
113
- slot?: { pool: PoolName; slot: number; gen: number };
114
- };
115
- writes: RowWrite[];
116
- facts: AnyNewFact[];
117
- }
118
-
119
- export type ApplyResult =
120
- | { kind: 'applied'; slot: { pool: PoolName; slot: number; gen: number } | null }
121
- | { kind: 'stale-generation' }
122
- | { kind: 'lease-held' }
123
- | { kind: 'no-free-slot' }
124
- | { kind: 'guard-mismatch'; table: TableName; key: JsonValue };
125
-
126
- export interface ItemFilter {
127
- readonly state?: ItemState;
128
- readonly repo?: RepoName;
129
- }
130
-
131
- export interface Tables {
132
- items: ItemRow;
133
- links: LinkRow;
134
- levers: LeverRow;
135
- attempts: AttemptRow;
136
- attempt_sessions: AttemptSessionRow;
137
- leases: LeaseRow;
138
- pool_slots: PoolSlotRow;
139
- decisions: DecisionRow;
140
- evidence: EvidenceRow;
141
- pull_requests: PullRequestRow;
142
- runners: RunnerRow;
143
- }
144
-
145
- export type TableName = keyof Tables;
146
-
147
- export type RowWrite =
148
- | {
149
- [T in TableName]: { readonly op: 'insert'; readonly table: T; readonly row: Tables[T] };
150
- }[TableName]
151
- | {
152
- [T in TableName]: {
153
- readonly op: 'update';
154
- readonly table: T;
155
- readonly key: Partial<Tables[T]>;
156
- readonly expect: Partial<Tables[T]>;
157
- readonly set: Partial<Tables[T]>;
158
- };
159
- }[TableName]
160
- | { readonly op: 'take-slot'; readonly pool: PoolName; readonly holder: AttemptId }
161
- | {
162
- readonly op: 'release-slot';
163
- readonly pool: PoolName;
164
- readonly slot: number;
165
- readonly holder: AttemptId;
166
- };
167
-
168
- export type AnyNewFact = { [T in FactType]: NewFact<T> }[FactType];
169
-
170
- export interface WorkerKind {
171
- start: (request: SpawnRequest) => Promise<StartOutcome>;
172
- reconcile: (attempt: AttemptRow) => Promise<SessionReading>;
173
- }
174
-
175
- export type StartOutcome =
176
- | { kind: 'started'; atcSession: AtcSessionId; agentSession: AgentSessionId | null }
177
- | { kind: 'refused'; reason: string }
178
- | { kind: 'unknown'; reason: string };
179
-
180
- export type SessionReading =
181
- | { kind: 'running'; atcSession: AtcSessionId; agentSession: AgentSessionId | null }
182
- | { kind: 'ended'; atcSession: AtcSessionId; agentSession: AgentSessionId | null }
183
- | { kind: 'absent' };
184
-
185
- export interface SpawnRequest {
186
- // the repo's configured local path
187
- readonly cwd: string;
188
- readonly prompt: string;
189
- readonly agent: string;
190
- readonly model: string;
191
- readonly effort: Effort;
192
- readonly pluginDirs: readonly string[];
193
- readonly name: `boxxy/${string}`;
194
- readonly idempotencyKey: AttemptId;
195
- }
196
-
197
- export interface SessionFault {
198
- readonly kind: 'fault';
199
- readonly fault: 'agent-session-owned';
200
- readonly agentSession: AgentSessionId;
201
- readonly attempt: AttemptId;
202
- readonly holder: AttemptId;
203
- }
204
-
205
- export interface FactSink {
206
- append: (
207
- facts: OutboxFact[],
208
- ) => Promise<
209
- 'accepted' | { kind: 'unknown'; reason: string } | { kind: 'rejected'; error: string }
210
- >;
211
- }
212
-
213
- export interface CostToLandRow {
214
- readonly item: ItemId;
215
- readonly title: string;
216
- readonly repo: RepoName;
217
- readonly landedAt: Instant;
218
- readonly model: string;
219
- readonly attempts: number;
220
- readonly requests: number;
221
- readonly inputTokens: number;
222
- readonly outputTokens: number;
223
- readonly cacheReadTokens: number;
224
- readonly cacheCreationTokens: number;
225
-
226
- // input, cache read and cache creation tokens together
227
- readonly totalInputTokens: number;
228
-
229
- // modelled at list price, not billed
230
- readonly costUsd: number;
231
- }
232
-
233
- export interface CostToLandInput {
234
- readonly repo?: string;
235
-
236
- // ISO 8601, as the pepys query takes it
237
- readonly landedFrom?: string;
238
- readonly landedTo?: string;
239
- }
240
-
241
- export interface CostReader {
242
- costToLand: (input: CostToLandInput) => Promise<CostToLandRow[]>;
243
- }
244
-
245
- export interface Forge {
246
- readPullRequest: (ref: PullRequestRef) => Promise<PullRequestReading | 'not-found'>;
247
- listOpenPullRequests: (repo: RepoName) => Promise<PullRequestRef[]>;
248
- }
249
-
250
- export interface PullRequestReading {
251
- url: string;
252
- state: 'open' | 'closed' | 'merged';
253
- mergedAt: Instant | null;
254
- mergeCommit: CommitSha | null;
255
- commits: { sha: CommitSha; message: string }[];
256
- }
257
-
258
- export interface Clock {
259
- now: () => Instant;
260
- }
261
-
262
- export type NewId = () => string;