@cat-factory/contracts 0.100.0 → 0.101.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -65,5 +65,6 @@ export * from './sandbox.js';
65
65
  export * from './workspace-settings.js';
66
66
  export * from './kaizen.js';
67
67
  export * from './initiative.js';
68
+ export * from './initiative-preset.js';
68
69
  export * from './routes/index.js';
69
70
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,qBAAqB,CAAA;AACnC,cAAc,mBAAmB,CAAA;AACjC,cAAc,cAAc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A;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
package/dist/index.js CHANGED
@@ -65,5 +65,6 @@ export * from './sandbox.js';
65
65
  export * from './workspace-settings.js';
66
66
  export * from './kaizen.js';
67
67
  export * from './initiative.js';
68
+ export * from './initiative-preset.js';
68
69
  export * from './routes/index.js';
69
70
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,cAAc,CAAA;AAC5B,cAAc,sBAAsB,CAAA;AACpC,cAAc,eAAe,CAAA;AAC7B,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,aAAa,CAAA;AAC3B,cAAc,sBAAsB,CAAA;AACpC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,wBAAwB,CAAA;AACtC,cA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B,CAAA;AAClC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,oBAAoB,CAAA;AAClC,cAAc,YAAY,CAAA;AAC1B,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,oBAAoB,CAAA;AAClC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,6BAA6B,CAAA;AAC3C,cAAc,kBAAkB,CAAA;AAChC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,cAAc,CAAA;AAC5B,cAAc,yBAAyB,CAAA;AACvC,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,258 @@
1
+ import * as v from 'valibot';
2
+ import { type InitiativePresetInputs } from './initiative.js';
3
+ /**
4
+ * How a preset field is rendered/collected. The first six mirror {@link ProviderConfigField}'s
5
+ * types exactly; `checkbox-group` (a multi-select, value `string[]`) and `path` (a repo-relative
6
+ * directory, {@link isSafeRepoDirPath}-validated) are the two additions the preset form needs.
7
+ */
8
+ export declare const initiativePresetFieldTypeSchema: v.PicklistSchema<["text", "password", "select", "number", "checkbox", "textarea", "checkbox-group", "path"], undefined>;
9
+ export type InitiativePresetFieldType = v.InferOutput<typeof initiativePresetFieldTypeSchema>;
10
+ /**
11
+ * Single-condition visibility for a field: it renders only when the referenced field's value
12
+ * matches. `equals` compares a scalar value; `includes` tests membership in a `checkbox-group`
13
+ * value (the per-doc-type subfolder case — "show `diagramsDir` only when `docTypes` includes
14
+ * `diagrams`"). Deliberately ONE condition — resist growing this into a recursive schema
15
+ * renderer (that is the descriptor-forms initiative's separate line item).
16
+ */
17
+ export declare const initiativePresetShowWhenSchema: v.ObjectSchema<{
18
+ /** The `key` of the field whose value gates this one's visibility. */
19
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
20
+ /**
21
+ * Show when the referenced scalar value equals this. A union so `equals` can gate a
22
+ * `checkbox` (boolean) or `number` field, not only a `select`/`text` string — the
23
+ * comparison is strict, so the type must match the referenced field's value.
24
+ */
25
+ readonly equals: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
26
+ /** Show when the referenced `checkbox-group` value includes this. */
27
+ readonly includes: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
28
+ }, undefined>;
29
+ export type InitiativePresetShowWhen = v.InferOutput<typeof initiativePresetShowWhenSchema>;
30
+ /** One value a preset needs, rendered as a single form field. */
31
+ export declare const initiativePresetFieldSchema: v.ObjectSchema<{
32
+ /** Stable key the value is stored/sent under (e.g. `docTypes`, `docsRoot`). */
33
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
34
+ /** Human label for the form field (backend-supplied English). */
35
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 120, undefined>]>;
36
+ /** Optional helper text shown under the field. */
37
+ readonly help: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
38
+ /** Optional input placeholder. */
39
+ readonly placeholder: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
40
+ /** Whether the value is required (absent ⇒ optional). A hidden (`showWhen`) field is never required. */
41
+ readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
42
+ /** Field type; absent is treated as `text`. */
43
+ readonly type: v.OptionalSchema<v.PicklistSchema<["text", "password", "select", "number", "checkbox", "textarea", "checkbox-group", "path"], undefined>, undefined>;
44
+ /** Choices for a `select` / `checkbox-group` field. */
45
+ readonly options: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
46
+ readonly value: v.StringSchema<undefined>;
47
+ readonly label: v.StringSchema<undefined>;
48
+ }, undefined>, undefined>, undefined>;
49
+ /** The scalar default (`text`/`select`/`path`/`number`/`checkbox`); the form falls back to it when blank. */
50
+ readonly default: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
51
+ /** The multi-select default for a `checkbox-group` field. */
52
+ readonly defaultValues: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
53
+ /** Single-condition visibility; absent ⇒ always shown. */
54
+ readonly showWhen: v.OptionalSchema<v.ObjectSchema<{
55
+ /** The `key` of the field whose value gates this one's visibility. */
56
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
57
+ /**
58
+ * Show when the referenced scalar value equals this. A union so `equals` can gate a
59
+ * `checkbox` (boolean) or `number` field, not only a `select`/`text` string — the
60
+ * comparison is strict, so the type must match the referenced field's value.
61
+ */
62
+ readonly equals: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
63
+ /** Show when the referenced `checkbox-group` value includes this. */
64
+ readonly includes: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
65
+ }, undefined>, undefined>;
66
+ }, undefined>;
67
+ export type InitiativePresetField = v.InferOutput<typeof initiativePresetFieldSchema>;
68
+ /** Display metadata for a preset in the create-initiative picker. */
69
+ export declare const initiativePresetPresentationSchema: v.ObjectSchema<{
70
+ /** Human label, e.g. `Documentation refresh`. */
71
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
72
+ /** Icon id (e.g. an `i-lucide-*` name). */
73
+ readonly icon: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 120, undefined>]>;
74
+ /** Accent colour (CSS hex/keyword). */
75
+ readonly color: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
76
+ /** One-line description shown in the picker. */
77
+ readonly description: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, undefined>]>;
78
+ }, undefined>;
79
+ export type InitiativePresetPresentation = v.InferOutput<typeof initiativePresetPresentationSchema>;
80
+ /**
81
+ * The serialisable, SPA-facing description of a preset: everything the create-initiative
82
+ * modal needs to render the picker + form and start planning, attached to the workspace
83
+ * snapshot (the `customAgentKinds` precedent). The code hooks (`detect`/`seedPlan`/
84
+ * `promptAdditions`) live on the kernel registration, NOT here.
85
+ */
86
+ export declare const initiativePresetDescriptorSchema: v.ObjectSchema<{
87
+ /** Stable preset id (e.g. `preset_generic`, `preset_docs_refresh`). */
88
+ readonly id: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
89
+ readonly presentation: v.ObjectSchema<{
90
+ /** Human label, e.g. `Documentation refresh`. */
91
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
92
+ /** Icon id (e.g. an `i-lucide-*` name). */
93
+ readonly icon: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 120, undefined>]>;
94
+ /** Accent colour (CSS hex/keyword). */
95
+ readonly color: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 40, undefined>]>;
96
+ /** One-line description shown in the picker. */
97
+ readonly description: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MaxLengthAction<string, 500, undefined>]>;
98
+ }, undefined>;
99
+ /** The form fields the user fills at create time (empty for the generic preset). */
100
+ readonly fields: v.ArraySchema<v.ObjectSchema<{
101
+ /** Stable key the value is stored/sent under (e.g. `docTypes`, `docsRoot`). */
102
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
103
+ /** Human label for the form field (backend-supplied English). */
104
+ readonly label: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 120, undefined>]>;
105
+ /** Optional helper text shown under the field. */
106
+ readonly help: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
107
+ /** Optional input placeholder. */
108
+ readonly placeholder: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
109
+ /** Whether the value is required (absent ⇒ optional). A hidden (`showWhen`) field is never required. */
110
+ readonly required: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
111
+ /** Field type; absent is treated as `text`. */
112
+ readonly type: v.OptionalSchema<v.PicklistSchema<["text", "password", "select", "number", "checkbox", "textarea", "checkbox-group", "path"], undefined>, undefined>;
113
+ /** Choices for a `select` / `checkbox-group` field. */
114
+ readonly options: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
115
+ readonly value: v.StringSchema<undefined>;
116
+ readonly label: v.StringSchema<undefined>;
117
+ }, undefined>, undefined>, undefined>;
118
+ /** The scalar default (`text`/`select`/`path`/`number`/`checkbox`); the form falls back to it when blank. */
119
+ readonly default: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
120
+ /** The multi-select default for a `checkbox-group` field. */
121
+ readonly defaultValues: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, undefined>;
122
+ /** Single-condition visibility; absent ⇒ always shown. */
123
+ readonly showWhen: v.OptionalSchema<v.ObjectSchema<{
124
+ /** The `key` of the field whose value gates this one's visibility. */
125
+ readonly key: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
126
+ /**
127
+ * Show when the referenced scalar value equals this. A union so `equals` can gate a
128
+ * `checkbox` (boolean) or `number` field, not only a `select`/`text` string — the
129
+ * comparison is strict, so the type must match the referenced field's value.
130
+ */
131
+ readonly equals: v.OptionalSchema<v.UnionSchema<[v.StringSchema<undefined>, v.BooleanSchema<undefined>, v.NumberSchema<undefined>], undefined>, undefined>;
132
+ /** Show when the referenced `checkbox-group` value includes this. */
133
+ readonly includes: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
134
+ }, undefined>, undefined>;
135
+ }, undefined>, undefined>;
136
+ /** The planning pipeline the SPA starts (e.g. `pl_initiative`, `pl_initiative_docs`). */
137
+ readonly planningPipelineId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.MinLengthAction<string, 1, undefined>]>;
138
+ /** `full` runs the interviewer; `skip` treats the form AS the interview (seeded qa). */
139
+ readonly interview: v.PicklistSchema<["full", "skip"], undefined>;
140
+ /** Default for the human-review opt-in (mapped to the gate-override seam at start). */
141
+ readonly humanReviewDefault: v.BooleanSchema<undefined>;
142
+ /** Best-practice prompt fragments applied by default (configurable via a form field). */
143
+ readonly defaultFragmentIds: v.OptionalSchema<v.ArraySchema<v.StringSchema<undefined>, undefined>, readonly []>;
144
+ /** Partial execution-policy overrides folded in at plan ingest. */
145
+ readonly policyDefaults: v.OptionalSchema<Omit<v.ObjectSchema<{
146
+ readonly maxConcurrent: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 20, undefined>]>;
147
+ readonly rules: v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
148
+ readonly pipelineId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
149
+ readonly minComplexity: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
150
+ readonly minRisk: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
151
+ readonly minImpact: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
152
+ }, undefined>, undefined>, readonly []>;
153
+ readonly defaultPipelineId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
154
+ readonly onMissingEstimate: v.OptionalSchema<v.PicklistSchema<["default", "strongest"], undefined>, "default">;
155
+ }, undefined>, "entries" | "~run" | "~standard" | "~types"> & {
156
+ readonly entries: {
157
+ readonly maxConcurrent: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 1, undefined>, v.MaxValueAction<number, 20, undefined>]>, undefined>;
158
+ readonly rules: v.OptionalSchema<v.OptionalSchema<v.ArraySchema<v.ObjectSchema<{
159
+ readonly pipelineId: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>;
160
+ readonly minComplexity: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
161
+ readonly minRisk: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
162
+ readonly minImpact: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.MinValueAction<number, 0, undefined>, v.MaxValueAction<number, 1, undefined>]>, undefined>;
163
+ }, undefined>, undefined>, readonly []>, undefined>;
164
+ readonly defaultPipelineId: v.OptionalSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.TrimAction, v.MinLengthAction<string, 1, undefined>, v.MaxLengthAction<string, 80, undefined>]>, undefined>;
165
+ readonly onMissingEstimate: v.OptionalSchema<v.OptionalSchema<v.PicklistSchema<["default", "strongest"], undefined>, "default">, undefined>;
166
+ };
167
+ readonly "~standard": v.StandardProps<{
168
+ maxConcurrent?: number | undefined;
169
+ rules?: {
170
+ pipelineId: string;
171
+ minComplexity?: number | undefined;
172
+ minRisk?: number | undefined;
173
+ minImpact?: number | undefined;
174
+ }[] | undefined;
175
+ defaultPipelineId?: string | undefined;
176
+ onMissingEstimate?: "default" | "strongest" | undefined;
177
+ }, {
178
+ maxConcurrent?: number | undefined;
179
+ rules?: {
180
+ pipelineId: string;
181
+ minComplexity?: number | undefined;
182
+ minRisk?: number | undefined;
183
+ minImpact?: number | undefined;
184
+ }[] | undefined;
185
+ defaultPipelineId?: string | undefined;
186
+ onMissingEstimate?: "default" | "strongest" | undefined;
187
+ }>;
188
+ readonly "~run": (dataset: v.UnknownDataset, config: v.Config<v.BaseIssue<unknown>>) => v.OutputDataset<{
189
+ maxConcurrent?: number | undefined;
190
+ rules?: {
191
+ pipelineId: string;
192
+ minComplexity?: number | undefined;
193
+ minRisk?: number | undefined;
194
+ minImpact?: number | undefined;
195
+ }[] | undefined;
196
+ defaultPipelineId?: string | undefined;
197
+ onMissingEstimate?: "default" | "strongest" | undefined;
198
+ }, v.ArrayIssue | v.IntegerIssue<number> | v.MaxLengthIssue<string, 80> | v.MaxValueIssue<number, 1> | v.MaxValueIssue<number, 20> | v.MinLengthIssue<string, 1> | v.MinValueIssue<number, 0> | v.MinValueIssue<number, 1> | v.NumberIssue | v.ObjectIssue | v.PicklistIssue | v.StringIssue>;
199
+ readonly "~types"?: {
200
+ readonly input: {
201
+ maxConcurrent?: number | undefined;
202
+ rules?: {
203
+ pipelineId: string;
204
+ minComplexity?: number | undefined;
205
+ minRisk?: number | undefined;
206
+ minImpact?: number | undefined;
207
+ }[] | undefined;
208
+ defaultPipelineId?: string | undefined;
209
+ onMissingEstimate?: "default" | "strongest" | undefined;
210
+ };
211
+ readonly output: {
212
+ maxConcurrent?: number | undefined;
213
+ rules?: {
214
+ pipelineId: string;
215
+ minComplexity?: number | undefined;
216
+ minRisk?: number | undefined;
217
+ minImpact?: number | undefined;
218
+ }[] | undefined;
219
+ defaultPipelineId?: string | undefined;
220
+ onMissingEstimate?: "default" | "strongest" | undefined;
221
+ };
222
+ readonly issue: v.ArrayIssue | v.IntegerIssue<number> | v.MaxLengthIssue<string, 80> | v.MaxValueIssue<number, 1> | v.MaxValueIssue<number, 20> | v.MinLengthIssue<string, 1> | v.MinValueIssue<number, 0> | v.MinValueIssue<number, 1> | v.NumberIssue | v.ObjectIssue | v.PicklistIssue | v.StringIssue;
223
+ } | undefined;
224
+ }, undefined>;
225
+ /**
226
+ * Whether this preset supports a repo-detection PREFILL probe (a `detect` hook is wired on
227
+ * the registration). Computed server-side when the snapshot is built (the `supportsTest`
228
+ * convention) so the SPA knows to call `POST …/initiative-presets/:id/probe`. Never blocks
229
+ * create — an unwired probe / GitHub simply falls back to the descriptor defaults.
230
+ */
231
+ readonly probe: v.OptionalSchema<v.BooleanSchema<undefined>, undefined>;
232
+ }, undefined>;
233
+ export type InitiativePresetDescriptor = v.InferOutput<typeof initiativePresetDescriptorSchema>;
234
+ /** Strictly parse a preset descriptor. Throws on shape violations. */
235
+ export declare function parseInitiativePresetDescriptor(value: unknown): InitiativePresetDescriptor;
236
+ /**
237
+ * Whether `path` is a SAFE repo-relative DIRECTORY (the `path`-field analogue of
238
+ * {@link isSafeDocPath}, minus the `.md` requirement). A preset `path` value is used verbatim
239
+ * as an in-repo placement dir the writers commit under, so it must not escape the repo: no `..`
240
+ * traversal, no absolute path (`/…` or a Windows drive), no backslash / NUL. An empty string is
241
+ * NOT a valid path (callers treat "unset" separately). A trailing slash is tolerated.
242
+ */
243
+ export declare function isSafeRepoDirPath(path: string): boolean;
244
+ /** Whether a field is visible given the current input values (its `showWhen` condition). */
245
+ export declare function isPresetFieldVisible(field: InitiativePresetField, inputs: InitiativePresetInputs): boolean;
246
+ /**
247
+ * Validate a filled preset form against its descriptor, returning a list of human-readable
248
+ * problems (EMPTY ⇒ valid). Pure + total (never throws), so the create controller can map a
249
+ * non-empty result to a single ValidationError. Enforces: no unknown keys, correct value type
250
+ * per field, required VISIBLE fields present (a required `checkbox` must be CHECKED — an
251
+ * unchecked `false` counts as unset), `select`/`checkbox-group` values drawn from the declared
252
+ * options, and `path` values that stay inside the repo ({@link isSafeRepoDirPath}). Hidden
253
+ * fields (failing `showWhen`) are not required and their stale values are ignored.
254
+ */
255
+ export declare function validateInitiativePresetInputs(descriptor: InitiativePresetDescriptor, inputs: InitiativePresetInputs): string[];
256
+ /** Strictly parse a bounded preset-inputs record. Throws on shape violations. */
257
+ export declare function parseInitiativePresetInputs(value: unknown): InitiativePresetInputs;
258
+ //# sourceMappingURL=initiative-preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initiative-preset.d.ts","sourceRoot":"","sources":["../src/initiative-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EAGL,KAAK,sBAAsB,EAE5B,MAAM,iBAAiB,CAAA;AAuBxB;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,yHAS1C,CAAA;AACF,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,+BAA+B,CAAC,CAAA;AAE7F;;;;;;GAMG;AACH,eAAO,MAAM,8BAA8B;IACzC,sEAAsE;;IAEtE;;;;OAIG;;IAEH,qEAAqE;;aAErE,CAAA;AACF,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,WAAW,CAAC,OAAO,8BAA8B,CAAC,CAAA;AAE3F,iEAAiE;AACjE,eAAO,MAAM,2BAA2B;IACtC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E,OAAO,GAAG,0BAA0B,CAE1F;AAMD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAMvD;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,qBAAqB,EAC5B,MAAM,EAAE,sBAAsB,GAC7B,OAAO,CAQT;AAoBD;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAC5C,UAAU,EAAE,0BAA0B,EACtC,MAAM,EAAE,sBAAsB,GAC7B,MAAM,EAAE,CA8CV;AAED,iFAAiF;AACjF,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,sBAAsB,CAElF"}
@@ -0,0 +1,228 @@
1
+ import * as v from 'valibot';
2
+ import { initiativeExecutionPolicySchema, initiativePresetInputsSchema, } from './initiative.js';
3
+ // ---------------------------------------------------------------------------
4
+ // Initiative-preset wire contracts.
5
+ //
6
+ // An initiative PRESET is more than a pipeline: it bundles (a) its own FORM the user
7
+ // fills at create time — rendered generically by the SPA from this backend-supplied
8
+ // descriptor, zero frontend changes per preset — (b) a planning-pipeline binding
9
+ // (skip the interviewer when the form IS the interview), (c) execution-policy /
10
+ // fragment / human-review defaults, and (d) code hooks (a repo-detection prefill
11
+ // probe, a plan post-processor) that live on the KERNEL registration, not here (this
12
+ // file is the serialisable, SPA-facing subset). See
13
+ // `docs/initiatives/initiative-presets-and-docs-refresh.md` and the kernel
14
+ // `initiative-preset-registry.ts`.
15
+ //
16
+ // The field descriptor extends the `ProviderConfigField` family with the two shapes a
17
+ // preset form needs that a flat provider form did not: `checkbox-group` (a multi-select
18
+ // whose value is `string[]`) and `path` (a repo-relative directory), plus single-condition
19
+ // `showWhen` visibility (a per-doc-type subfolder shown only when that type is checked).
20
+ // Descriptor labels are backend-supplied English (the `describeConfig` convention); only
21
+ // the surrounding chrome is i18n.
22
+ // ---------------------------------------------------------------------------
23
+ /**
24
+ * How a preset field is rendered/collected. The first six mirror {@link ProviderConfigField}'s
25
+ * types exactly; `checkbox-group` (a multi-select, value `string[]`) and `path` (a repo-relative
26
+ * directory, {@link isSafeRepoDirPath}-validated) are the two additions the preset form needs.
27
+ */
28
+ export const initiativePresetFieldTypeSchema = v.picklist([
29
+ 'text',
30
+ 'password',
31
+ 'select',
32
+ 'number',
33
+ 'checkbox',
34
+ 'textarea',
35
+ 'checkbox-group',
36
+ 'path',
37
+ ]);
38
+ /**
39
+ * Single-condition visibility for a field: it renders only when the referenced field's value
40
+ * matches. `equals` compares a scalar value; `includes` tests membership in a `checkbox-group`
41
+ * value (the per-doc-type subfolder case — "show `diagramsDir` only when `docTypes` includes
42
+ * `diagrams`"). Deliberately ONE condition — resist growing this into a recursive schema
43
+ * renderer (that is the descriptor-forms initiative's separate line item).
44
+ */
45
+ export const initiativePresetShowWhenSchema = v.object({
46
+ /** The `key` of the field whose value gates this one's visibility. */
47
+ key: v.pipe(v.string(), v.minLength(1)),
48
+ /**
49
+ * Show when the referenced scalar value equals this. A union so `equals` can gate a
50
+ * `checkbox` (boolean) or `number` field, not only a `select`/`text` string — the
51
+ * comparison is strict, so the type must match the referenced field's value.
52
+ */
53
+ equals: v.optional(v.union([v.string(), v.boolean(), v.number()])),
54
+ /** Show when the referenced `checkbox-group` value includes this. */
55
+ includes: v.optional(v.string()),
56
+ });
57
+ /** One value a preset needs, rendered as a single form field. */
58
+ export const initiativePresetFieldSchema = v.object({
59
+ /** Stable key the value is stored/sent under (e.g. `docTypes`, `docsRoot`). */
60
+ key: v.pipe(v.string(), v.minLength(1), v.maxLength(80)),
61
+ /** Human label for the form field (backend-supplied English). */
62
+ label: v.pipe(v.string(), v.minLength(1), v.maxLength(120)),
63
+ /** Optional helper text shown under the field. */
64
+ help: v.optional(v.string()),
65
+ /** Optional input placeholder. */
66
+ placeholder: v.optional(v.string()),
67
+ /** Whether the value is required (absent ⇒ optional). A hidden (`showWhen`) field is never required. */
68
+ required: v.optional(v.boolean()),
69
+ /** Field type; absent is treated as `text`. */
70
+ type: v.optional(initiativePresetFieldTypeSchema),
71
+ /** Choices for a `select` / `checkbox-group` field. */
72
+ options: v.optional(v.array(v.object({ value: v.string(), label: v.string() }))),
73
+ /** The scalar default (`text`/`select`/`path`/`number`/`checkbox`); the form falls back to it when blank. */
74
+ default: v.optional(v.string()),
75
+ /** The multi-select default for a `checkbox-group` field. */
76
+ defaultValues: v.optional(v.array(v.string())),
77
+ /** Single-condition visibility; absent ⇒ always shown. */
78
+ showWhen: v.optional(initiativePresetShowWhenSchema),
79
+ });
80
+ /** Display metadata for a preset in the create-initiative picker. */
81
+ export const initiativePresetPresentationSchema = v.object({
82
+ /** Human label, e.g. `Documentation refresh`. */
83
+ label: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80)),
84
+ /** Icon id (e.g. an `i-lucide-*` name). */
85
+ icon: v.pipe(v.string(), v.minLength(1), v.maxLength(120)),
86
+ /** Accent colour (CSS hex/keyword). */
87
+ color: v.pipe(v.string(), v.minLength(1), v.maxLength(40)),
88
+ /** One-line description shown in the picker. */
89
+ description: v.pipe(v.string(), v.maxLength(500)),
90
+ });
91
+ /**
92
+ * The serialisable, SPA-facing description of a preset: everything the create-initiative
93
+ * modal needs to render the picker + form and start planning, attached to the workspace
94
+ * snapshot (the `customAgentKinds` precedent). The code hooks (`detect`/`seedPlan`/
95
+ * `promptAdditions`) live on the kernel registration, NOT here.
96
+ */
97
+ export const initiativePresetDescriptorSchema = v.object({
98
+ /** Stable preset id (e.g. `preset_generic`, `preset_docs_refresh`). */
99
+ id: v.pipe(v.string(), v.trim(), v.minLength(1), v.maxLength(80)),
100
+ presentation: initiativePresetPresentationSchema,
101
+ /** The form fields the user fills at create time (empty for the generic preset). */
102
+ fields: v.array(initiativePresetFieldSchema),
103
+ /** The planning pipeline the SPA starts (e.g. `pl_initiative`, `pl_initiative_docs`). */
104
+ planningPipelineId: v.pipe(v.string(), v.minLength(1)),
105
+ /** `full` runs the interviewer; `skip` treats the form AS the interview (seeded qa). */
106
+ interview: v.picklist(['full', 'skip']),
107
+ /** Default for the human-review opt-in (mapped to the gate-override seam at start). */
108
+ humanReviewDefault: v.boolean(),
109
+ /** Best-practice prompt fragments applied by default (configurable via a form field). */
110
+ defaultFragmentIds: v.optional(v.array(v.string()), []),
111
+ /** Partial execution-policy overrides folded in at plan ingest. */
112
+ policyDefaults: v.optional(v.partial(initiativeExecutionPolicySchema)),
113
+ /**
114
+ * Whether this preset supports a repo-detection PREFILL probe (a `detect` hook is wired on
115
+ * the registration). Computed server-side when the snapshot is built (the `supportsTest`
116
+ * convention) so the SPA knows to call `POST …/initiative-presets/:id/probe`. Never blocks
117
+ * create — an unwired probe / GitHub simply falls back to the descriptor defaults.
118
+ */
119
+ probe: v.optional(v.boolean()),
120
+ });
121
+ /** Strictly parse a preset descriptor. Throws on shape violations. */
122
+ export function parseInitiativePresetDescriptor(value) {
123
+ return v.parse(initiativePresetDescriptorSchema, value);
124
+ }
125
+ // ---------------------------------------------------------------------------
126
+ // Path safety + input validation (pure — shared by the create-flow validation).
127
+ // ---------------------------------------------------------------------------
128
+ /**
129
+ * Whether `path` is a SAFE repo-relative DIRECTORY (the `path`-field analogue of
130
+ * {@link isSafeDocPath}, minus the `.md` requirement). A preset `path` value is used verbatim
131
+ * as an in-repo placement dir the writers commit under, so it must not escape the repo: no `..`
132
+ * traversal, no absolute path (`/…` or a Windows drive), no backslash / NUL. An empty string is
133
+ * NOT a valid path (callers treat "unset" separately). A trailing slash is tolerated.
134
+ */
135
+ export function isSafeRepoDirPath(path) {
136
+ const p = path.trim();
137
+ if (!p || p.length > 300)
138
+ return false;
139
+ if (p.startsWith('/') || /^[a-zA-Z]:/.test(p))
140
+ return false;
141
+ if (p.includes('\\') || p.includes('\0'))
142
+ return false;
143
+ return !p.split('/').some((segment) => segment === '..');
144
+ }
145
+ /** Whether a field is visible given the current input values (its `showWhen` condition). */
146
+ export function isPresetFieldVisible(field, inputs) {
147
+ const cond = field.showWhen;
148
+ if (!cond)
149
+ return true;
150
+ const value = inputs[cond.key];
151
+ if (cond.equals !== undefined)
152
+ return value === cond.equals;
153
+ if (cond.includes !== undefined)
154
+ return Array.isArray(value) && value.includes(cond.includes);
155
+ // A `showWhen` with neither predicate is a malformed condition — treat as always visible.
156
+ return true;
157
+ }
158
+ /** Whether a filled value matches the field's declared type (structural, pre-semantic check). */
159
+ function valueMatchesFieldType(field, value) {
160
+ switch (field.type) {
161
+ case 'checkbox-group':
162
+ return Array.isArray(value);
163
+ case 'checkbox':
164
+ return typeof value === 'boolean';
165
+ case 'number':
166
+ return typeof value === 'number';
167
+ default:
168
+ // text / password / select / textarea / path (and the untyped default) are strings.
169
+ return typeof value === 'string';
170
+ }
171
+ }
172
+ /**
173
+ * Validate a filled preset form against its descriptor, returning a list of human-readable
174
+ * problems (EMPTY ⇒ valid). Pure + total (never throws), so the create controller can map a
175
+ * non-empty result to a single ValidationError. Enforces: no unknown keys, correct value type
176
+ * per field, required VISIBLE fields present (a required `checkbox` must be CHECKED — an
177
+ * unchecked `false` counts as unset), `select`/`checkbox-group` values drawn from the declared
178
+ * options, and `path` values that stay inside the repo ({@link isSafeRepoDirPath}). Hidden
179
+ * fields (failing `showWhen`) are not required and their stale values are ignored.
180
+ */
181
+ export function validateInitiativePresetInputs(descriptor, inputs) {
182
+ const problems = [];
183
+ const byKey = new Map(descriptor.fields.map((f) => [f.key, f]));
184
+ for (const key of Object.keys(inputs)) {
185
+ if (!byKey.has(key))
186
+ problems.push(`Unknown field "${key}".`);
187
+ }
188
+ for (const field of descriptor.fields) {
189
+ const visible = isPresetFieldVisible(field, inputs);
190
+ const value = inputs[field.key];
191
+ // A checkbox is "present" only when checked: a required checkbox means "must be checked",
192
+ // so an unchecked (`false`) box counts as unset and fails the required check below.
193
+ const present = value !== undefined &&
194
+ !(typeof value === 'string' && value.trim() === '') &&
195
+ !(Array.isArray(value) && value.length === 0) &&
196
+ value !== false;
197
+ if (!visible)
198
+ continue;
199
+ if (!present) {
200
+ if (field.required)
201
+ problems.push(`Field "${field.key}" is required.`);
202
+ continue;
203
+ }
204
+ if (!valueMatchesFieldType(field, value)) {
205
+ problems.push(`Field "${field.key}" has the wrong type for a ${field.type ?? 'text'} field.`);
206
+ continue;
207
+ }
208
+ const optionValues = new Set((field.options ?? []).map((o) => o.value));
209
+ if (field.type === 'select' && optionValues.size > 0 && !optionValues.has(value)) {
210
+ problems.push(`Field "${field.key}" has a value outside its options.`);
211
+ }
212
+ if (field.type === 'checkbox-group' && optionValues.size > 0) {
213
+ for (const entry of value) {
214
+ if (!optionValues.has(entry))
215
+ problems.push(`Field "${field.key}" has an option "${entry}" outside its choices.`);
216
+ }
217
+ }
218
+ if (field.type === 'path' && !isSafeRepoDirPath(value)) {
219
+ problems.push(`Field "${field.key}" must be a relative path inside the repo (no "..", absolute, or backslash segments).`);
220
+ }
221
+ }
222
+ return problems;
223
+ }
224
+ /** Strictly parse a bounded preset-inputs record. Throws on shape violations. */
225
+ export function parseInitiativePresetInputs(value) {
226
+ return v.parse(initiativePresetInputsSchema, value);
227
+ }
228
+ //# sourceMappingURL=initiative-preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initiative-preset.js","sourceRoot":"","sources":["../src/initiative-preset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,SAAS,CAAA;AAC5B,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,GAG7B,MAAM,iBAAiB,CAAA;AAExB,8EAA8E;AAC9E,oCAAoC;AACpC,EAAE;AACF,qFAAqF;AACrF,oFAAoF;AACpF,iFAAiF;AACjF,gFAAgF;AAChF,iFAAiF;AACjF,qFAAqF;AACrF,oDAAoD;AACpD,2EAA2E;AAC3E,mCAAmC;AACnC,EAAE;AACF,sFAAsF;AACtF,wFAAwF;AACxF,2FAA2F;AAC3F,yFAAyF;AACzF,yFAAyF;AACzF,kCAAkC;AAClC,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAAC,CAAC,QAAQ,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