@boxxy/pepys 0.0.0-stage → 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 (52) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +43 -2
  3. package/dist/boxxy-source.d.ts +636 -0
  4. package/dist/boxxy-work-plugin.d.ts +1 -0
  5. package/dist/build-boxxy-plugin.d.ts +181 -0
  6. package/dist/consumers/apply-scope.d.ts +5 -0
  7. package/dist/create-pepys-fact-sink.d.ts +9 -0
  8. package/dist/create-pepys-reader.d.ts +9 -0
  9. package/dist/generated/boxxy-work-boundary.d.ts +566 -0
  10. package/dist/index.d.ts +5 -0
  11. package/dist/queries/build-cost-to-land-query.d.ts +156 -0
  12. package/dist/queries/build-cost-to-land.d.ts +12 -0
  13. package/dist/queries/build-stage-time-query.d.ts +29 -0
  14. package/dist/queries/build-stage-time.d.ts +10 -0
  15. package/dist/queries/constants.d.ts +6 -0
  16. package/dist/queries/find-item-entity-id.d.ts +2 -0
  17. package/dist/queries/types.d.ts +109 -0
  18. package/dist/sink/is-outgoing-fact.d.ts +3 -0
  19. package/dist/sink/pick-sink-answer.d.ts +7 -0
  20. package/dist/sink/to-wire-fact.d.ts +5 -0
  21. package/dist/types.d.ts +6 -0
  22. package/dist/wire-fact-schemas.d.ts +319 -0
  23. package/dist/work/boxxy-work-consumer.d.ts +125 -0
  24. package/dist/work/constants.d.ts +3 -0
  25. package/dist/work/fold-work-facts.d.ts +2 -0
  26. package/dist/work/types.d.ts +147 -0
  27. package/package.json +59 -4
  28. package/src/boxxy-source.ts +25 -0
  29. package/src/boxxy-work-plugin.ts +11 -0
  30. package/src/build-boxxy-plugin.ts +18 -0
  31. package/src/consumers/apply-scope.ts +125 -0
  32. package/src/create-pepys-fact-sink.ts +64 -0
  33. package/src/create-pepys-reader.ts +79 -0
  34. package/src/generated/boxxy-work-boundary.ts +2923 -0
  35. package/src/generated/boxxy-work.sql +71 -0
  36. package/src/index.ts +17 -0
  37. package/src/queries/build-cost-to-land-query.ts +127 -0
  38. package/src/queries/build-cost-to-land.ts +226 -0
  39. package/src/queries/build-stage-time-query.ts +59 -0
  40. package/src/queries/build-stage-time.ts +188 -0
  41. package/src/queries/constants.ts +10 -0
  42. package/src/queries/find-item-entity-id.ts +16 -0
  43. package/src/queries/types.ts +168 -0
  44. package/src/sink/is-outgoing-fact.ts +19 -0
  45. package/src/sink/pick-sink-answer.ts +29 -0
  46. package/src/sink/to-wire-fact.ts +31 -0
  47. package/src/types.ts +14 -0
  48. package/src/wire-fact-schemas.ts +41 -0
  49. package/src/work/boxxy-work-consumer.ts +95 -0
  50. package/src/work/constants.ts +25 -0
  51. package/src/work/fold-work-facts.ts +490 -0
  52. package/src/work/types.ts +177 -0
@@ -0,0 +1,156 @@
1
+ import { z } from 'zod';
2
+ import type { ForeignReads, GithubPullRequestConsumer, TelemetryModelRequestConsumer, TelemetryTurnCostConsumer } from './types.ts';
3
+ export declare function buildCostToLandQuery(foreign: ForeignReads): import("@pepys/kit").QueryDefinition<"boxxy_cost_to_land", z.ZodObject<{
4
+ item: z.ZodString;
5
+ }, z.core.$strip>, z.ZodObject<{
6
+ item: z.ZodString;
7
+ landedAt: z.ZodNullable<z.ZodString>;
8
+ attempts: z.ZodNumber;
9
+ lines: z.ZodArray<z.ZodObject<{
10
+ phase: z.ZodString;
11
+ rework: z.ZodBoolean;
12
+ product: z.ZodString;
13
+ model: z.ZodNullable<z.ZodString>;
14
+ requests: z.ZodNumber;
15
+ inputTokens: z.ZodNumber;
16
+ cacheReadTokens: z.ZodNumber;
17
+ cacheCreationTokens: z.ZodNumber;
18
+ outputTokens: z.ZodNumber;
19
+ costUSD: z.ZodNullable<z.ZodNumber>;
20
+ costBasis: z.ZodEnum<{
21
+ none: "none";
22
+ reported: "reported";
23
+ turn: "turn";
24
+ }>;
25
+ }, z.core.$strip>>;
26
+ totals: z.ZodObject<{
27
+ requests: z.ZodNumber;
28
+ costUSD: z.ZodNumber;
29
+ reworkCostUSD: z.ZodNumber;
30
+ requestsWithoutCost: z.ZodNumber;
31
+ }, z.core.$strip>;
32
+ }, z.core.$strip>, readonly [import("@pepys/kit").ConsumerDeclaration<"boxxy_work", {
33
+ readonly boxxy_item: import("@pepys/kit").TableDeclaration<{
34
+ readonly id: {
35
+ readonly kind: "entityID";
36
+ };
37
+ readonly kind: {
38
+ readonly kind: "text";
39
+ };
40
+ readonly repo: {
41
+ readonly kind: "text";
42
+ };
43
+ readonly title: {
44
+ readonly kind: "text";
45
+ };
46
+ readonly design_mode: {
47
+ readonly kind: "text";
48
+ readonly nullable: true;
49
+ };
50
+ readonly filed_at: {
51
+ readonly kind: "timestamp";
52
+ };
53
+ readonly closed_at: {
54
+ readonly kind: "timestamp";
55
+ readonly nullable: true;
56
+ };
57
+ readonly close_reason: {
58
+ readonly kind: "text";
59
+ readonly nullable: true;
60
+ };
61
+ readonly updated_at: {
62
+ readonly kind: "timestamp";
63
+ };
64
+ }>;
65
+ readonly boxxy_attempt: import("@pepys/kit").TableDeclaration<{
66
+ readonly id: {
67
+ readonly kind: "entityID";
68
+ };
69
+ readonly item_id: {
70
+ readonly kind: "entityID";
71
+ };
72
+ readonly phase: {
73
+ readonly kind: "text";
74
+ };
75
+ readonly number: {
76
+ readonly kind: "integer";
77
+ };
78
+ readonly round: {
79
+ readonly kind: "integer";
80
+ };
81
+ readonly mode: {
82
+ readonly kind: "text";
83
+ };
84
+ readonly pool: {
85
+ readonly kind: "text";
86
+ };
87
+ readonly recipe_hash: {
88
+ readonly kind: "text";
89
+ };
90
+ readonly rules_version: {
91
+ readonly kind: "text";
92
+ };
93
+ readonly atc_session: {
94
+ readonly kind: "text";
95
+ readonly nullable: true;
96
+ };
97
+ readonly state: {
98
+ readonly kind: "text";
99
+ };
100
+ readonly outcome: {
101
+ readonly kind: "text";
102
+ readonly nullable: true;
103
+ };
104
+ readonly failure: {
105
+ readonly kind: "text";
106
+ readonly nullable: true;
107
+ };
108
+ readonly claimed_at: {
109
+ readonly kind: "timestamp";
110
+ };
111
+ readonly started_at: {
112
+ readonly kind: "timestamp";
113
+ readonly nullable: true;
114
+ };
115
+ readonly closed_out_at: {
116
+ readonly kind: "timestamp";
117
+ readonly nullable: true;
118
+ };
119
+ readonly ended_at: {
120
+ readonly kind: "timestamp";
121
+ readonly nullable: true;
122
+ };
123
+ readonly sleeps: {
124
+ readonly kind: "json";
125
+ };
126
+ readonly updated_at: {
127
+ readonly kind: "timestamp";
128
+ };
129
+ }>;
130
+ readonly boxxy_attempt_session: import("@pepys/kit").TableDeclaration<{
131
+ readonly attempt_id: {
132
+ readonly kind: "entityID";
133
+ };
134
+ readonly session_id: {
135
+ readonly kind: "entityID";
136
+ };
137
+ readonly key: {
138
+ readonly kind: "text";
139
+ };
140
+ readonly product: {
141
+ readonly kind: "text";
142
+ readonly nullable: true;
143
+ };
144
+ readonly caller_issuer: {
145
+ readonly kind: "text";
146
+ readonly nullable: true;
147
+ };
148
+ readonly caller_subject: {
149
+ readonly kind: "text";
150
+ readonly nullable: true;
151
+ };
152
+ readonly bound_at: {
153
+ readonly kind: "timestamp";
154
+ };
155
+ }>;
156
+ }, import("@pepys/kit").LinkTypeDeclaration<"attempt_of", "boxxy:attempt", "boxxy:item"> | import("@pepys/kit").LinkTypeDeclaration<"produced", "boxxy:attempt", "github:pull_request"> | import("@pepys/kit").LinkTypeDeclaration<"ran_in", "boxxy:attempt", "telemetry:session">>, TelemetryModelRequestConsumer, TelemetryTurnCostConsumer, GithubPullRequestConsumer]>;
@@ -0,0 +1,12 @@
1
+ import type { CostToLand } from '@boxxy/model';
2
+ import type { AttemptReadRow, BindingReadRow, PullRequestReadRow, RequestReadRow, TurnReadRow } from './types.ts';
3
+ interface CostParts {
4
+ readonly item: string;
5
+ readonly attempts: readonly AttemptReadRow[];
6
+ readonly bindings: readonly BindingReadRow[];
7
+ readonly requests: readonly RequestReadRow[];
8
+ readonly turns: readonly TurnReadRow[];
9
+ readonly pullRequests: readonly PullRequestReadRow[];
10
+ }
11
+ export declare function buildCostToLand(parts: CostParts): CostToLand;
12
+ export {};
@@ -0,0 +1,29 @@
1
+ import { z } from 'zod';
2
+ import type { DeliveryReads, StageTimeReads } from './types.ts';
3
+ export declare function buildStageTimeQuery(delivery: DeliveryReads): import("@pepys/kit").QueryDefinition<"boxxy_stage_time", z.ZodObject<{
4
+ item: z.ZodString;
5
+ environment: z.ZodString;
6
+ }, z.core.$strip>, z.ZodObject<{
7
+ item: z.ZodString;
8
+ environment: z.ZodString;
9
+ steps: z.ZodArray<z.ZodObject<{
10
+ step: z.ZodEnum<{
11
+ build: "build";
12
+ deploy: "deploy";
13
+ design: "design";
14
+ merge: "merge";
15
+ release: "release";
16
+ review: "review";
17
+ triage: "triage";
18
+ }>;
19
+ minutes: z.ZodNullable<z.ZodNumber>;
20
+ endedAt: z.ZodNullable<z.ZodString>;
21
+ }, z.core.$strip>>;
22
+ rework: z.ZodObject<{
23
+ count: z.ZodNumber;
24
+ minutes: z.ZodNumber;
25
+ }, z.core.$strip>;
26
+ reviewWaitMinutes: z.ZodNullable<z.ZodNumber>;
27
+ sleepMinutes: z.ZodNumber;
28
+ pullRequests: z.ZodArray<z.ZodString>;
29
+ }, z.core.$strip>, StageTimeReads>;
@@ -0,0 +1,10 @@
1
+ import type { StageTime } from '@boxxy/model';
2
+ import type { AttemptReadRow, DeliveryReadRow } from './types.ts';
3
+ interface StageParts {
4
+ readonly item: string;
5
+ readonly environment: string;
6
+ readonly attempts: readonly AttemptReadRow[];
7
+ readonly deliveries: readonly DeliveryReadRow[];
8
+ }
9
+ export declare function buildStageTime(parts: StageParts): StageTime;
10
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const noCapacityFailure = "no-capacity";
2
+ export declare const outcomeNames: {
3
+ readonly built: 'built';
4
+ readonly passed: 'passed';
5
+ readonly changesRequested: 'changes-requested';
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { EntityID } from '@pepys/kit';
2
+ export declare function findItemEntityID(text: string): EntityID | undefined;
@@ -0,0 +1,109 @@
1
+ import type { ColumnKind, ConsumerDeclaration, EntityID, QueryCall, TableDeclaration } from '@pepys/kit';
2
+ import type { boxxyWorkConsumer } from '../work/boxxy-work-consumer.ts';
3
+ export interface AttemptReadRow {
4
+ id: string;
5
+ phase: string;
6
+ number: number;
7
+ round: number;
8
+ state: string;
9
+ outcome: string | null;
10
+ failure: string | null;
11
+ claimed_at: string;
12
+ ended_at: string | null;
13
+ sleeps: unknown;
14
+ }
15
+ export interface BindingReadRow {
16
+ attempt_id: string;
17
+ session_id: string;
18
+ bound_at: string;
19
+ caller_issuer: string | null;
20
+ caller_subject: string | null;
21
+ }
22
+ interface TelemetryReadRow {
23
+ session_id: string;
24
+ origin_issuer: string | null;
25
+ origin_subject: string | null;
26
+ product: string;
27
+ at: string;
28
+ }
29
+ export interface RequestReadRow extends TelemetryReadRow {
30
+ model: string;
31
+ cost_basis: string;
32
+ cost_usd: number | null;
33
+ input_tokens: number;
34
+ cache_read_tokens: number;
35
+ cache_creation_tokens: number;
36
+ output_tokens: number;
37
+ }
38
+ export interface TurnReadRow extends TelemetryReadRow {
39
+ model: string | null;
40
+ cost_usd: number;
41
+ }
42
+ export interface PullRequestReadRow {
43
+ id: string;
44
+ merged_at: string | null;
45
+ }
46
+ export interface DeliveryReadRow {
47
+ pullRequest: string;
48
+ mergedAt: string | null;
49
+ release: {
50
+ at: string;
51
+ } | null;
52
+ deploy: {
53
+ at: string;
54
+ } | null;
55
+ }
56
+ interface Column<Kind extends ColumnKind> {
57
+ readonly kind: Kind;
58
+ }
59
+ interface NullableColumn<Kind extends ColumnKind> {
60
+ readonly kind: Kind;
61
+ readonly nullable: true;
62
+ }
63
+ type TelemetryColumns = Readonly<{
64
+ session_id: Column<'entityID'>;
65
+ origin_issuer: NullableColumn<'text'>;
66
+ origin_subject: NullableColumn<'text'>;
67
+ product: Column<'text'>;
68
+ at: Column<'timestamp'>;
69
+ }>;
70
+ export type TelemetryModelRequestConsumer = ConsumerDeclaration<'telemetry_model_request', {
71
+ readonly telemetry_model_request: TableDeclaration<TelemetryColumns & {
72
+ readonly model: Column<'text'>;
73
+ readonly cost_basis: Column<'text'>;
74
+ readonly cost_usd: NullableColumn<'real'>;
75
+ readonly input_tokens: Column<'integer'>;
76
+ readonly cache_read_tokens: Column<'integer'>;
77
+ readonly cache_creation_tokens: Column<'integer'>;
78
+ readonly output_tokens: Column<'integer'>;
79
+ }>;
80
+ }>;
81
+ export type TelemetryTurnCostConsumer = ConsumerDeclaration<'telemetry_turn_cost', {
82
+ readonly telemetry_turn_cost: TableDeclaration<TelemetryColumns & {
83
+ readonly model: NullableColumn<'text'>;
84
+ readonly cost_usd: Column<'real'>;
85
+ }>;
86
+ }>;
87
+ export type GithubPullRequestConsumer = ConsumerDeclaration<'github_pull_request', {
88
+ readonly github_pull_request: TableDeclaration<{
89
+ readonly id: Column<'entityID'>;
90
+ readonly merged_at: NullableColumn<'timestamp'>;
91
+ }>;
92
+ }>;
93
+ export type OpaqueConsumer = ConsumerDeclaration<string, Readonly<Record<`opaque:${string}`, TableDeclaration>>>;
94
+ export type StageTimeReads = readonly [typeof boxxyWorkConsumer, ...OpaqueConsumer[]];
95
+ export interface DeliveryInput {
96
+ readonly item: EntityID;
97
+ readonly environment: string;
98
+ }
99
+ export interface DeliveryReads {
100
+ readonly consumers: readonly OpaqueConsumer[];
101
+ readonly readDeliveries: (db: QueryCall<unknown, StageTimeReads>['db'], input: DeliveryInput) => Promise<readonly DeliveryReadRow[]>;
102
+ }
103
+ export interface ForeignReads {
104
+ readonly telemetryModelRequest: TelemetryModelRequestConsumer;
105
+ readonly telemetryTurnCost: TelemetryTurnCostConsumer;
106
+ readonly githubPullRequest: GithubPullRequestConsumer;
107
+ readonly delivery: DeliveryReads;
108
+ }
109
+ export {};
@@ -0,0 +1,3 @@
1
+ import type { FactBatchBody, OutgoingFact } from '@pepys/kit';
2
+ import type { boxxySource } from '../boxxy-source.ts';
3
+ export declare function isOutgoingFact(fact: FactBatchBody['facts'][number]): fact is OutgoingFact<typeof boxxySource>;
@@ -0,0 +1,7 @@
1
+ import type { SinkAnswer } from '@boxxy/model';
2
+ import type { Result, SendFailure } from '@pepys/kit';
3
+ type SendResult = Result<{
4
+ stored: number;
5
+ }, SendFailure>;
6
+ export declare function pickSinkAnswer(sent: SendResult | 'timeout', timeoutMs: number): SinkAnswer;
7
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { OutboxFact } from '@boxxy/model';
2
+ import type { FactBatchBody } from '@pepys/kit';
3
+ type WireFact = FactBatchBody['facts'][number];
4
+ export declare function toWireFact(fact: OutboxFact): WireFact;
5
+ export {};
@@ -0,0 +1,6 @@
1
+ import type { PluginClient } from '@pepys/kit';
2
+ import type { buildBoxxyPlugin } from './build-boxxy-plugin.ts';
3
+ export type BoxxyQueryClient = PluginClient<ReturnType<typeof buildBoxxyPlugin>>;
4
+ export type UncheckedQueryClient = {
5
+ readonly [Query in keyof BoxxyQueryClient]: (input: Parameters<BoxxyQueryClient[Query]>[0]) => Promise<unknown>;
6
+ };