@boxxy/model 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +27 -2
  2. package/dist/actor-ref-schema.d.ts +2 -0
  3. package/dist/brand-schemas.d.ts +26 -0
  4. package/dist/build-applied-change.d.ts +13 -0
  5. package/dist/build-close-out-schema.d.ts +3 -0
  6. package/dist/build-item-views.d.ts +2 -0
  7. package/dist/define-admission.d.ts +3 -0
  8. package/dist/define-gate.d.ts +3 -0
  9. package/dist/define-signal.d.ts +3 -0
  10. package/dist/derive-item-state.d.ts +2 -0
  11. package/dist/fact-schemas.d.ts +5 -0
  12. package/dist/find-slot-take.d.ts +5 -0
  13. package/dist/format-key-path.d.ts +1 -0
  14. package/dist/friction-schema.d.ts +3 -0
  15. package/dist/index.d.ts +24 -1
  16. package/dist/live-levers.d.ts +2 -0
  17. package/dist/outbox-fact-schema.d.ts +3 -0
  18. package/dist/row-schemas.d.ts +5 -0
  19. package/dist/signal-key.d.ts +3 -0
  20. package/dist/test-utils/build-mock-attempt-row.d.ts +2 -0
  21. package/dist/test-utils/build-mock-evidence-row.d.ts +2 -0
  22. package/dist/test-utils/build-mock-fact-id.d.ts +2 -0
  23. package/dist/test-utils/build-mock-frame-item.d.ts +2 -0
  24. package/dist/test-utils/build-mock-item-row.d.ts +2 -0
  25. package/dist/test-utils/build-mock-item-rows.d.ts +2 -0
  26. package/dist/test-utils/build-mock-item-view.d.ts +2 -0
  27. package/dist/test-utils/build-mock-lease-row.d.ts +2 -0
  28. package/dist/test-utils/build-mock-lever-row.d.ts +2 -0
  29. package/dist/test-utils/build-mock-link-row.d.ts +2 -0
  30. package/dist/test-utils/build-mock-pull-request-row.d.ts +2 -0
  31. package/dist/test-utils/build-mock-snapshot.d.ts +2 -0
  32. package/dist/test-utils/seed-faker.d.ts +1 -0
  33. package/dist/to-json-value.d.ts +2 -0
  34. package/dist/types/core.d.ts +233 -0
  35. package/dist/types/dispatch.d.ts +82 -0
  36. package/dist/types/facts.d.ts +154 -0
  37. package/dist/types/planning.d.ts +94 -0
  38. package/dist/types/ports.d.ts +218 -0
  39. package/dist/types/registries.d.ts +150 -0
  40. package/package.json +9 -2
  41. package/src/actor-ref-schema.ts +9 -0
  42. package/src/brand-schemas.ts +46 -0
  43. package/src/build-applied-change.ts +71 -0
  44. package/src/build-close-out-schema.ts +28 -0
  45. package/src/build-item-views.ts +128 -0
  46. package/src/define-admission.ts +6 -0
  47. package/src/define-gate.ts +6 -0
  48. package/src/define-signal.ts +6 -0
  49. package/src/derive-item-state.ts +76 -0
  50. package/src/fact-schemas.ts +132 -0
  51. package/src/find-slot-take.ts +12 -0
  52. package/src/format-key-path.ts +19 -0
  53. package/src/friction-schema.ts +10 -0
  54. package/src/index.ts +196 -1
  55. package/src/live-levers.ts +22 -0
  56. package/src/outbox-fact-schema.ts +25 -0
  57. package/src/row-schemas.ts +89 -0
  58. package/src/signal-key.ts +7 -0
  59. package/src/test-utils/build-mock-attempt-row.ts +37 -0
  60. package/src/test-utils/build-mock-evidence-row.ts +17 -0
  61. package/src/test-utils/build-mock-fact-id.ts +7 -0
  62. package/src/test-utils/build-mock-frame-item.ts +9 -0
  63. package/src/test-utils/build-mock-item-row.ts +22 -0
  64. package/src/test-utils/build-mock-item-rows.ts +14 -0
  65. package/src/test-utils/build-mock-item-view.ts +8 -0
  66. package/src/test-utils/build-mock-lease-row.ts +15 -0
  67. package/src/test-utils/build-mock-lever-row.ts +17 -0
  68. package/src/test-utils/build-mock-link-row.ts +15 -0
  69. package/src/test-utils/build-mock-pull-request-row.ts +16 -0
  70. package/src/test-utils/build-mock-snapshot.ts +5 -0
  71. package/src/test-utils/seed-faker.ts +3 -0
  72. package/src/to-json-value.ts +25 -0
  73. package/src/types/core.ts +299 -0
  74. package/src/types/dispatch.ts +95 -0
  75. package/src/types/facts.ts +166 -0
  76. package/src/types/planning.ts +136 -0
  77. package/src/types/ports.ts +262 -0
  78. package/src/types/registries.ts +185 -0
  79. package/dist/package-name.d.ts +0 -1
  80. package/src/package-name.ts +0 -1
@@ -0,0 +1,185 @@
1
+ import type { JsonValue } from '@boxxy/content-hash';
2
+ import type { z } from 'zod';
3
+ import type {
4
+ ConceptPin,
5
+ ItemKindName,
6
+ LeverKind,
7
+ LoadedRecipe,
8
+ MaxAttemptsByKind,
9
+ PhaseName,
10
+ PipelineName,
11
+ RecipeName,
12
+ RulesVersion,
13
+ } from './core.ts';
14
+ import type {
15
+ Admission,
16
+ FrameItem,
17
+ Gate,
18
+ Pool,
19
+ PropagationLine,
20
+ Signal,
21
+ SignalKey,
22
+ SignalName,
23
+ View,
24
+ Waiver,
25
+ } from './planning.ts';
26
+
27
+ export type Schema<T> = z.ZodType<T>;
28
+
29
+ export interface ParamKinds<P> {
30
+ signal: Signal<P>;
31
+ gate: Gate<P>;
32
+ admission: Admission<P>;
33
+ }
34
+
35
+ export type ParamKindName = keyof ParamKinds<unknown>;
36
+
37
+ export interface Registered<K extends ParamKindName> {
38
+ readonly kind: K;
39
+ readonly name: string;
40
+ open: <R>(use: <P>(plugin: ParamKinds<P>[K]) => R) => R;
41
+ }
42
+
43
+ export interface Resolved<K extends ParamKindName> {
44
+ readonly kind: K;
45
+ readonly name: string;
46
+
47
+ // `signalKey(name, params)` for a signal, and the name for a gate
48
+ readonly key: string;
49
+ open: <R>(use: <P>(plugin: ParamKinds<P>[K], params: P) => R) => R;
50
+ }
51
+
52
+ export type ConceptName = string;
53
+
54
+ export interface Concept {
55
+ name: ConceptName;
56
+ version: number;
57
+ signals?: Registered<'signal'>[];
58
+ gates?: Registered<'gate'>[];
59
+ waivers?: Waiver[];
60
+ levers?: LeverKind[];
61
+ filterFields?: FilterField[];
62
+ }
63
+
64
+ export interface FilterField {
65
+ name: string;
66
+
67
+ // null never matches a filter on this field
68
+ value: (item: FrameItem) => string | readonly string[] | null;
69
+ }
70
+
71
+ export interface PlainKinds {
72
+ waiver: Waiver;
73
+ 'filter-field': FilterField;
74
+ lever: { readonly kind: LeverKind };
75
+ view: View;
76
+ }
77
+
78
+ export type PluginKindName = ParamKindName | keyof PlainKinds;
79
+
80
+ export type Registry = { readonly [K in ParamKindName]: ReadonlyMap<string, Registered<K>> } & {
81
+ readonly [K in keyof PlainKinds]: ReadonlyMap<string, PlainKinds[K]>;
82
+ } & { readonly pins: readonly ConceptPin[] };
83
+
84
+ export interface KindRules {
85
+ readonly pipeline: Pipeline;
86
+ readonly recipes: Readonly<Record<PhaseName, RecipeName>>;
87
+ }
88
+
89
+ export interface Pipeline {
90
+ readonly name: PipelineName;
91
+ readonly steps: readonly PipelineStep[];
92
+ }
93
+
94
+ export interface PipelineStep {
95
+ readonly phase: PhaseName;
96
+
97
+ // failed attempts before the item waits on "attempts used up"
98
+ readonly maxAttempts: number;
99
+ }
100
+
101
+ export type ConceptEntry = `${string}@${number}`;
102
+
103
+ export type PluginRef = string | Readonly<Record<string, JsonValue>>;
104
+
105
+ export type SignalRef = SignalName | Readonly<Record<string, JsonValue>>;
106
+
107
+ export interface RulesFile {
108
+ readonly version: 1;
109
+ readonly concepts: readonly ConceptEntry[];
110
+ readonly kinds: Readonly<
111
+ Record<
112
+ string,
113
+ {
114
+ readonly pipeline: readonly string[] | PipelineName;
115
+ readonly maxAttempts: Readonly<Record<string, number>>;
116
+ readonly recipes: Readonly<Record<string, string>>;
117
+ }
118
+ >
119
+ >;
120
+ readonly pools: readonly {
121
+ readonly name: string;
122
+ readonly slots: number;
123
+ readonly takes: Readonly<Record<string, JsonValue>>;
124
+ readonly order: readonly SignalRef[];
125
+ }[];
126
+ readonly lead: readonly SignalRef[];
127
+ readonly propagation: readonly {
128
+ readonly value: string;
129
+ readonly over: string;
130
+ readonly toward: 'source' | 'target';
131
+ }[];
132
+ readonly recipes: Readonly<
133
+ Record<
134
+ string,
135
+ {
136
+ readonly agent: string;
137
+ readonly model: string;
138
+ readonly effort: string;
139
+ readonly prompt: string;
140
+ readonly source: string;
141
+ }
142
+ >
143
+ >;
144
+ }
145
+
146
+ export interface LoadedRules {
147
+ readonly version: RulesVersion;
148
+ readonly commit: string;
149
+ readonly registry: Registry;
150
+ readonly signals: ReadonlyMap<SignalKey, Resolved<'signal'>>;
151
+ readonly gates: readonly Resolved<'gate'>[];
152
+ readonly kinds: ReadonlyMap<ItemKindName, KindRules>;
153
+ readonly maxAttemptsByKind: MaxAttemptsByKind;
154
+
155
+ // in declared order, each pool's `order` starting with `lead`
156
+ readonly pools: readonly Pool[];
157
+ readonly propagation: readonly PropagationLine[];
158
+ readonly recipes: ReadonlyMap<RecipeName, LoadedRecipe>;
159
+ }
160
+
161
+ export interface LoadRejection {
162
+ readonly file: string;
163
+ readonly path: string;
164
+ readonly reason: LoadRejectionReason;
165
+ }
166
+
167
+ export type LoadRejectionReason =
168
+ | { readonly kind: 'invalid'; readonly message: string }
169
+ | { readonly kind: 'unknown-concept'; readonly ref: string }
170
+ | { readonly kind: 'unknown-signal'; readonly signal: string }
171
+ | {
172
+ readonly kind: 'bad-plugin-params';
173
+ readonly pluginKind: ParamKindName;
174
+ readonly name: string;
175
+ readonly message: string;
176
+ }
177
+ | { readonly kind: 'unknown-link-type'; readonly link: string }
178
+ | { readonly kind: 'signal-without-combine'; readonly signal: string }
179
+ | { readonly kind: 'missing-recipe'; readonly itemKind: string; readonly phase: string }
180
+ | { readonly kind: 'missing-prompt'; readonly path: string }
181
+ | { readonly kind: 'uncommitted-changes' };
182
+
183
+ export type LoadResult =
184
+ | { readonly kind: 'loaded'; readonly rules: LoadedRules; readonly warnings: readonly string[] }
185
+ | { readonly kind: 'rejected'; readonly rejections: readonly LoadRejection[] };
@@ -1 +0,0 @@
1
- export declare const packageName = "@boxxy/model";
@@ -1 +0,0 @@
1
- export const packageName = '@boxxy/model';