@cleocode/contracts 2026.4.69 → 2026.4.72
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/__tests__/acceptance-gate.test.d.ts +14 -0
- package/dist/__tests__/acceptance-gate.test.d.ts.map +1 -0
- package/dist/__tests__/acceptance-gate.test.js +642 -0
- package/dist/__tests__/acceptance-gate.test.js.map +1 -0
- package/dist/__tests__/attachment.test.d.ts +17 -0
- package/dist/__tests__/attachment.test.d.ts.map +1 -0
- package/dist/__tests__/attachment.test.js +505 -0
- package/dist/__tests__/attachment.test.js.map +1 -0
- package/dist/__tests__/evidence-record.test.d.ts +14 -0
- package/dist/__tests__/evidence-record.test.d.ts.map +1 -0
- package/dist/__tests__/evidence-record.test.js +362 -0
- package/dist/__tests__/evidence-record.test.js.map +1 -0
- package/dist/__tests__/invariants.test.d.ts +19 -0
- package/dist/__tests__/invariants.test.d.ts.map +1 -0
- package/dist/__tests__/invariants.test.js +351 -0
- package/dist/__tests__/invariants.test.js.map +1 -0
- package/dist/acceptance-gate-schema.d.ts +701 -0
- package/dist/acceptance-gate-schema.d.ts.map +1 -0
- package/dist/acceptance-gate-schema.js +303 -0
- package/dist/acceptance-gate-schema.js.map +1 -0
- package/dist/acceptance-gate.d.ts +350 -0
- package/dist/acceptance-gate.d.ts.map +1 -0
- package/dist/acceptance-gate.js +22 -0
- package/dist/acceptance-gate.js.map +1 -0
- package/dist/attachment-schema.d.ts +243 -0
- package/dist/attachment-schema.d.ts.map +1 -0
- package/dist/attachment-schema.js +200 -0
- package/dist/attachment-schema.js.map +1 -0
- package/dist/attachment.d.ts +224 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +21 -0
- package/dist/attachment.js.map +1 -0
- package/dist/evidence-record-schema.d.ts +202 -0
- package/dist/evidence-record-schema.d.ts.map +1 -0
- package/dist/evidence-record-schema.js +130 -0
- package/dist/evidence-record-schema.js.map +1 -0
- package/dist/evidence-record.d.ts +167 -0
- package/dist/evidence-record.d.ts.map +1 -0
- package/dist/evidence-record.js +21 -0
- package/dist/evidence-record.js.map +1 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/task-evidence.d.ts +251 -0
- package/dist/task-evidence.d.ts.map +1 -0
- package/dist/task-evidence.js +89 -0
- package/dist/task-evidence.js.map +1 -0
- package/dist/task.d.ts +23 -4
- package/dist/task.d.ts.map +1 -1
- package/package.json +8 -2
- package/schemas/acceptance-gate.schema.json +9 -0
- package/schemas/attachment.schema.json +9 -0
- package/schemas/gate-result-details.schema.json +9 -0
- package/schemas/gate-result.schema.json +9 -0
- package/schemas/manifest-v1.json +176 -0
- package/schemas/task-evidence.schema.json +9 -0
- package/schemas/task.schema.json +9 -0
- package/src/__tests__/acceptance-gate.test.ts +736 -0
- package/src/__tests__/attachment.test.ts +601 -0
- package/src/__tests__/evidence-record.test.ts +412 -0
- package/src/__tests__/invariants.test.ts +445 -0
- package/src/acceptance-gate-schema.ts +347 -0
- package/src/acceptance-gate.ts +370 -0
- package/src/attachment-schema.ts +223 -0
- package/src/attachment.ts +245 -0
- package/src/evidence-record-schema.ts +158 -0
- package/src/evidence-record.ts +182 -0
- package/src/index.ts +114 -1
- package/src/task-evidence.ts +239 -0
- package/src/task.ts +24 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Acceptance gate discriminated union and result types.
|
|
3
|
+
*
|
|
4
|
+
* A machine-verifiable acceptance gate. Gates coexist with free-text criteria
|
|
5
|
+
* in `Task.acceptance`; the runtime executes only gates and records results in
|
|
6
|
+
* `task.verification.gateResults` and in the `lifecycle_gate_results` DB table.
|
|
7
|
+
*
|
|
8
|
+
* Six gate kinds are supported:
|
|
9
|
+
* - `test` — run a command and assert exit code / test-count
|
|
10
|
+
* - `file` — assert properties of a file on disk
|
|
11
|
+
* - `command` — run any CLI command and assert exit code / stdout
|
|
12
|
+
* - `lint` — run a static-analysis tool and require a clean result
|
|
13
|
+
* - `http` — hit a URL and assert status + optional body
|
|
14
|
+
* - `manual` — explicit escape hatch requiring human/agent verdict
|
|
15
|
+
*
|
|
16
|
+
* @epic T760
|
|
17
|
+
* @task T763
|
|
18
|
+
* @task T779
|
|
19
|
+
* @see {@link https://github.com/kryptobaseddev/cleo} T760 RCASD hardening
|
|
20
|
+
*/
|
|
21
|
+
export {};
|
|
22
|
+
//# sourceMappingURL=acceptance-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acceptance-gate.js","sourceRoot":"","sources":["../src/acceptance-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG"}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod validation schemas for {@link Attachment} and related types.
|
|
3
|
+
*
|
|
4
|
+
* Kept in a separate file from the plain TypeScript types so that consumers
|
|
5
|
+
* that do not need runtime validation (e.g. type-only imports) pay zero cost.
|
|
6
|
+
*
|
|
7
|
+
* All schemas are named `*Schema` and their inferred types are compatible with
|
|
8
|
+
* the canonical TypeScript interfaces in `./attachment.ts`.
|
|
9
|
+
*
|
|
10
|
+
* Uses `z.discriminatedUnion('kind', [...])` for O(1) variant lookup on the
|
|
11
|
+
* `kind` discriminant.
|
|
12
|
+
*
|
|
13
|
+
* @epic T760
|
|
14
|
+
* @task T795
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
/**
|
|
18
|
+
* Zod schema for {@link LocalFileAttachment}.
|
|
19
|
+
*
|
|
20
|
+
* Validates that `path` is non-empty, `sha256` is a 64-character hex string,
|
|
21
|
+
* and `size` is a non-negative integer.
|
|
22
|
+
*/
|
|
23
|
+
export declare const localFileAttachmentSchema: z.ZodObject<{
|
|
24
|
+
description: z.ZodOptional<z.ZodString>;
|
|
25
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
26
|
+
kind: z.ZodLiteral<"local-file">;
|
|
27
|
+
path: z.ZodString;
|
|
28
|
+
sha256: z.ZodString;
|
|
29
|
+
mime: z.ZodString;
|
|
30
|
+
size: z.ZodNumber;
|
|
31
|
+
}, z.core.$strip>;
|
|
32
|
+
/**
|
|
33
|
+
* Zod schema for {@link UrlAttachment}.
|
|
34
|
+
*
|
|
35
|
+
* Validates that `url` is a well-formed absolute URL. The optional `cachedSha256`
|
|
36
|
+
* is validated as a 64-character hex string when present.
|
|
37
|
+
*/
|
|
38
|
+
export declare const urlAttachmentSchema: z.ZodObject<{
|
|
39
|
+
description: z.ZodOptional<z.ZodString>;
|
|
40
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
41
|
+
kind: z.ZodLiteral<"url">;
|
|
42
|
+
url: z.ZodString;
|
|
43
|
+
cachedSha256: z.ZodOptional<z.ZodString>;
|
|
44
|
+
cachedAt: z.ZodOptional<z.ZodString>;
|
|
45
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
46
|
+
}, z.core.$strip>;
|
|
47
|
+
/**
|
|
48
|
+
* Zod schema for {@link BlobAttachment}.
|
|
49
|
+
*
|
|
50
|
+
* Validates that `sha256` is 64 hex characters, `storageKey` is non-empty,
|
|
51
|
+
* and `size` is a non-negative integer.
|
|
52
|
+
*/
|
|
53
|
+
export declare const blobAttachmentSchema: z.ZodObject<{
|
|
54
|
+
description: z.ZodOptional<z.ZodString>;
|
|
55
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
56
|
+
kind: z.ZodLiteral<"blob">;
|
|
57
|
+
sha256: z.ZodString;
|
|
58
|
+
storageKey: z.ZodString;
|
|
59
|
+
mime: z.ZodString;
|
|
60
|
+
size: z.ZodNumber;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
/**
|
|
63
|
+
* Zod schema for {@link LlmsTxtAttachment}.
|
|
64
|
+
*
|
|
65
|
+
* Validates that `content` is non-empty, `sha256` is 64 hex characters, and
|
|
66
|
+
* `source` is one of the two allowed literal values.
|
|
67
|
+
*/
|
|
68
|
+
export declare const llmsTxtAttachmentSchema: z.ZodObject<{
|
|
69
|
+
description: z.ZodOptional<z.ZodString>;
|
|
70
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
71
|
+
kind: z.ZodLiteral<"llms-txt">;
|
|
72
|
+
source: z.ZodEnum<{
|
|
73
|
+
url: "url";
|
|
74
|
+
generated: "generated";
|
|
75
|
+
}>;
|
|
76
|
+
content: z.ZodString;
|
|
77
|
+
sha256: z.ZodString;
|
|
78
|
+
}, z.core.$strip>;
|
|
79
|
+
/**
|
|
80
|
+
* Zod schema for {@link LlmtxtDocAttachment}.
|
|
81
|
+
*
|
|
82
|
+
* Validates that `slug` is non-empty and `backend` is one of the two allowed
|
|
83
|
+
* literal values. `pinnedVersion` is an opaque string when present.
|
|
84
|
+
*/
|
|
85
|
+
export declare const llmtxtDocAttachmentSchema: z.ZodObject<{
|
|
86
|
+
description: z.ZodOptional<z.ZodString>;
|
|
87
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
88
|
+
kind: z.ZodLiteral<"llmtxt-doc">;
|
|
89
|
+
slug: z.ZodString;
|
|
90
|
+
backend: z.ZodEnum<{
|
|
91
|
+
local: "local";
|
|
92
|
+
remote: "remote";
|
|
93
|
+
}>;
|
|
94
|
+
pinnedVersion: z.ZodOptional<z.ZodString>;
|
|
95
|
+
}, z.core.$strip>;
|
|
96
|
+
/**
|
|
97
|
+
* Zod discriminated-union schema for {@link Attachment}.
|
|
98
|
+
*
|
|
99
|
+
* Uses `z.discriminatedUnion('kind', [...])` for O(1) variant lookup.
|
|
100
|
+
* Parse with `attachmentSchema.parse(input)` or
|
|
101
|
+
* `attachmentSchema.safeParse(input)`.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const att = attachmentSchema.parse({
|
|
106
|
+
* kind: 'local-file',
|
|
107
|
+
* path: 'docs/rfc-003.md',
|
|
108
|
+
* sha256: 'a'.repeat(64),
|
|
109
|
+
* mime: 'text/markdown',
|
|
110
|
+
* size: 8192,
|
|
111
|
+
* description: 'RFC draft v3',
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export declare const attachmentSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
116
|
+
description: z.ZodOptional<z.ZodString>;
|
|
117
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
118
|
+
kind: z.ZodLiteral<"local-file">;
|
|
119
|
+
path: z.ZodString;
|
|
120
|
+
sha256: z.ZodString;
|
|
121
|
+
mime: z.ZodString;
|
|
122
|
+
size: z.ZodNumber;
|
|
123
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
124
|
+
description: z.ZodOptional<z.ZodString>;
|
|
125
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
126
|
+
kind: z.ZodLiteral<"url">;
|
|
127
|
+
url: z.ZodString;
|
|
128
|
+
cachedSha256: z.ZodOptional<z.ZodString>;
|
|
129
|
+
cachedAt: z.ZodOptional<z.ZodString>;
|
|
130
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
131
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
132
|
+
description: z.ZodOptional<z.ZodString>;
|
|
133
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
134
|
+
kind: z.ZodLiteral<"blob">;
|
|
135
|
+
sha256: z.ZodString;
|
|
136
|
+
storageKey: z.ZodString;
|
|
137
|
+
mime: z.ZodString;
|
|
138
|
+
size: z.ZodNumber;
|
|
139
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
140
|
+
description: z.ZodOptional<z.ZodString>;
|
|
141
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
142
|
+
kind: z.ZodLiteral<"llms-txt">;
|
|
143
|
+
source: z.ZodEnum<{
|
|
144
|
+
url: "url";
|
|
145
|
+
generated: "generated";
|
|
146
|
+
}>;
|
|
147
|
+
content: z.ZodString;
|
|
148
|
+
sha256: z.ZodString;
|
|
149
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
150
|
+
description: z.ZodOptional<z.ZodString>;
|
|
151
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
152
|
+
kind: z.ZodLiteral<"llmtxt-doc">;
|
|
153
|
+
slug: z.ZodString;
|
|
154
|
+
backend: z.ZodEnum<{
|
|
155
|
+
local: "local";
|
|
156
|
+
remote: "remote";
|
|
157
|
+
}>;
|
|
158
|
+
pinnedVersion: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strip>], "kind">;
|
|
160
|
+
/** Inferred TypeScript type from {@link attachmentSchema}. */
|
|
161
|
+
export type AttachmentSchemaInput = z.input<typeof attachmentSchema>;
|
|
162
|
+
/**
|
|
163
|
+
* Zod schema for {@link AttachmentMetadata}.
|
|
164
|
+
*
|
|
165
|
+
* Validates the persisted registry row. The embedded `attachment` field is
|
|
166
|
+
* validated recursively through the discriminated union.
|
|
167
|
+
*/
|
|
168
|
+
export declare const attachmentMetadataSchema: z.ZodObject<{
|
|
169
|
+
id: z.ZodString;
|
|
170
|
+
sha256: z.ZodString;
|
|
171
|
+
attachment: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
172
|
+
description: z.ZodOptional<z.ZodString>;
|
|
173
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
174
|
+
kind: z.ZodLiteral<"local-file">;
|
|
175
|
+
path: z.ZodString;
|
|
176
|
+
sha256: z.ZodString;
|
|
177
|
+
mime: z.ZodString;
|
|
178
|
+
size: z.ZodNumber;
|
|
179
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
180
|
+
description: z.ZodOptional<z.ZodString>;
|
|
181
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
182
|
+
kind: z.ZodLiteral<"url">;
|
|
183
|
+
url: z.ZodString;
|
|
184
|
+
cachedSha256: z.ZodOptional<z.ZodString>;
|
|
185
|
+
cachedAt: z.ZodOptional<z.ZodString>;
|
|
186
|
+
mime: z.ZodOptional<z.ZodString>;
|
|
187
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
188
|
+
description: z.ZodOptional<z.ZodString>;
|
|
189
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
190
|
+
kind: z.ZodLiteral<"blob">;
|
|
191
|
+
sha256: z.ZodString;
|
|
192
|
+
storageKey: z.ZodString;
|
|
193
|
+
mime: z.ZodString;
|
|
194
|
+
size: z.ZodNumber;
|
|
195
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
196
|
+
description: z.ZodOptional<z.ZodString>;
|
|
197
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
198
|
+
kind: z.ZodLiteral<"llms-txt">;
|
|
199
|
+
source: z.ZodEnum<{
|
|
200
|
+
url: "url";
|
|
201
|
+
generated: "generated";
|
|
202
|
+
}>;
|
|
203
|
+
content: z.ZodString;
|
|
204
|
+
sha256: z.ZodString;
|
|
205
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
206
|
+
description: z.ZodOptional<z.ZodString>;
|
|
207
|
+
labels: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
208
|
+
kind: z.ZodLiteral<"llmtxt-doc">;
|
|
209
|
+
slug: z.ZodString;
|
|
210
|
+
backend: z.ZodEnum<{
|
|
211
|
+
local: "local";
|
|
212
|
+
remote: "remote";
|
|
213
|
+
}>;
|
|
214
|
+
pinnedVersion: z.ZodOptional<z.ZodString>;
|
|
215
|
+
}, z.core.$strip>], "kind">;
|
|
216
|
+
createdAt: z.ZodString;
|
|
217
|
+
refCount: z.ZodNumber;
|
|
218
|
+
}, z.core.$strip>;
|
|
219
|
+
/** Inferred TypeScript type from {@link attachmentMetadataSchema}. */
|
|
220
|
+
export type AttachmentMetadataSchemaInput = z.input<typeof attachmentMetadataSchema>;
|
|
221
|
+
/**
|
|
222
|
+
* Zod schema for {@link AttachmentRef}.
|
|
223
|
+
*
|
|
224
|
+
* Validates the junction row linking one attachment to one owner. `ownerType`
|
|
225
|
+
* is restricted to the six supported CLEO entity types.
|
|
226
|
+
*/
|
|
227
|
+
export declare const attachmentRefSchema: z.ZodObject<{
|
|
228
|
+
attachmentId: z.ZodString;
|
|
229
|
+
ownerType: z.ZodEnum<{
|
|
230
|
+
pattern: "pattern";
|
|
231
|
+
task: "task";
|
|
232
|
+
session: "session";
|
|
233
|
+
observation: "observation";
|
|
234
|
+
decision: "decision";
|
|
235
|
+
learning: "learning";
|
|
236
|
+
}>;
|
|
237
|
+
ownerId: z.ZodString;
|
|
238
|
+
attachedAt: z.ZodString;
|
|
239
|
+
attachedBy: z.ZodOptional<z.ZodString>;
|
|
240
|
+
}, z.core.$strip>;
|
|
241
|
+
/** Inferred TypeScript type from {@link attachmentRefSchema}. */
|
|
242
|
+
export type AttachmentRefSchemaInput = z.input<typeof attachmentRefSchema>;
|
|
243
|
+
//# sourceMappingURL=attachment-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment-schema.d.ts","sourceRoot":"","sources":["../src/attachment-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAmBxB;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;iBAUpC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;iBAU9B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;iBAU/B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB;;;;;;;;;;iBAQlC,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB;;;;;;;;;;iBAYpC,CAAC;AAIH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BAM3B,CAAC;AAEH,8DAA8D;AAC9D,MAAM,MAAM,qBAAqB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAIrE;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAsBnC,CAAC;AAEH,sEAAsE;AACtE,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAIrF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;iBAmB9B,CAAC;AAEH,iEAAiE;AACjE,MAAM,MAAM,wBAAwB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zod validation schemas for {@link Attachment} and related types.
|
|
3
|
+
*
|
|
4
|
+
* Kept in a separate file from the plain TypeScript types so that consumers
|
|
5
|
+
* that do not need runtime validation (e.g. type-only imports) pay zero cost.
|
|
6
|
+
*
|
|
7
|
+
* All schemas are named `*Schema` and their inferred types are compatible with
|
|
8
|
+
* the canonical TypeScript interfaces in `./attachment.ts`.
|
|
9
|
+
*
|
|
10
|
+
* Uses `z.discriminatedUnion('kind', [...])` for O(1) variant lookup on the
|
|
11
|
+
* `kind` discriminant.
|
|
12
|
+
*
|
|
13
|
+
* @epic T760
|
|
14
|
+
* @task T795
|
|
15
|
+
*/
|
|
16
|
+
import { z } from 'zod';
|
|
17
|
+
// ─── Shared field schemas ──────────────────────────────────────────────────────
|
|
18
|
+
/**
|
|
19
|
+
* Common optional fields shared by all attachment variants.
|
|
20
|
+
*
|
|
21
|
+
* Not exported as a standalone validator — always composed into full variant
|
|
22
|
+
* schemas via `.extend()`.
|
|
23
|
+
*/
|
|
24
|
+
const attachmentCommonSchema = z.object({
|
|
25
|
+
/** Free-text description of what this attachment contains. */
|
|
26
|
+
description: z.string().optional(),
|
|
27
|
+
/** Labels for filtering (e.g., `["rfc", "spec"]`). */
|
|
28
|
+
labels: z.array(z.string()).optional(),
|
|
29
|
+
});
|
|
30
|
+
// ─── Variant schemas ───────────────────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* Zod schema for {@link LocalFileAttachment}.
|
|
33
|
+
*
|
|
34
|
+
* Validates that `path` is non-empty, `sha256` is a 64-character hex string,
|
|
35
|
+
* and `size` is a non-negative integer.
|
|
36
|
+
*/
|
|
37
|
+
export const localFileAttachmentSchema = attachmentCommonSchema.extend({
|
|
38
|
+
kind: z.literal('local-file'),
|
|
39
|
+
/** Path to the file (absolute or project-root-relative, forward-slashes only). */
|
|
40
|
+
path: z.string().min(1),
|
|
41
|
+
/** SHA-256 hex digest (64 hex characters). */
|
|
42
|
+
sha256: z.string().length(64),
|
|
43
|
+
/** IANA MIME type. */
|
|
44
|
+
mime: z.string().min(1),
|
|
45
|
+
/** File size in bytes (non-negative integer). */
|
|
46
|
+
size: z.number().int().nonnegative(),
|
|
47
|
+
});
|
|
48
|
+
/**
|
|
49
|
+
* Zod schema for {@link UrlAttachment}.
|
|
50
|
+
*
|
|
51
|
+
* Validates that `url` is a well-formed absolute URL. The optional `cachedSha256`
|
|
52
|
+
* is validated as a 64-character hex string when present.
|
|
53
|
+
*/
|
|
54
|
+
export const urlAttachmentSchema = attachmentCommonSchema.extend({
|
|
55
|
+
kind: z.literal('url'),
|
|
56
|
+
/** The remote URL — must be a valid absolute URL. */
|
|
57
|
+
url: z.string().url(),
|
|
58
|
+
/** SHA-256 of the cached body (64 hex characters). */
|
|
59
|
+
cachedSha256: z.string().length(64).optional(),
|
|
60
|
+
/** ISO 8601 timestamp when the body was cached. */
|
|
61
|
+
cachedAt: z.string().datetime().optional(),
|
|
62
|
+
/** IANA MIME type detected from the Content-Type header. */
|
|
63
|
+
mime: z.string().optional(),
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Zod schema for {@link BlobAttachment}.
|
|
67
|
+
*
|
|
68
|
+
* Validates that `sha256` is 64 hex characters, `storageKey` is non-empty,
|
|
69
|
+
* and `size` is a non-negative integer.
|
|
70
|
+
*/
|
|
71
|
+
export const blobAttachmentSchema = attachmentCommonSchema.extend({
|
|
72
|
+
kind: z.literal('blob'),
|
|
73
|
+
/** SHA-256 hex digest of the uncompressed content (64 hex characters). */
|
|
74
|
+
sha256: z.string().length(64),
|
|
75
|
+
/** Storage key inside `.cleo/attachments/sha256/`. */
|
|
76
|
+
storageKey: z.string().min(1),
|
|
77
|
+
/** IANA MIME type. */
|
|
78
|
+
mime: z.string().min(1),
|
|
79
|
+
/** Size of the uncompressed content in bytes. */
|
|
80
|
+
size: z.number().int().nonnegative(),
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* Zod schema for {@link LlmsTxtAttachment}.
|
|
84
|
+
*
|
|
85
|
+
* Validates that `content` is non-empty, `sha256` is 64 hex characters, and
|
|
86
|
+
* `source` is one of the two allowed literal values.
|
|
87
|
+
*/
|
|
88
|
+
export const llmsTxtAttachmentSchema = attachmentCommonSchema.extend({
|
|
89
|
+
kind: z.literal('llms-txt'),
|
|
90
|
+
/** Where the llms.txt content originated. */
|
|
91
|
+
source: z.enum(['url', 'generated']),
|
|
92
|
+
/** Full markdown content of the llms.txt (stored inline). */
|
|
93
|
+
content: z.string().min(1),
|
|
94
|
+
/** SHA-256 hex digest of `content` (64 hex characters). */
|
|
95
|
+
sha256: z.string().length(64),
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Zod schema for {@link LlmtxtDocAttachment}.
|
|
99
|
+
*
|
|
100
|
+
* Validates that `slug` is non-empty and `backend` is one of the two allowed
|
|
101
|
+
* literal values. `pinnedVersion` is an opaque string when present.
|
|
102
|
+
*/
|
|
103
|
+
export const llmtxtDocAttachmentSchema = attachmentCommonSchema.extend({
|
|
104
|
+
kind: z.literal('llmtxt-doc'),
|
|
105
|
+
/** Document slug from the llmtxt backend. */
|
|
106
|
+
slug: z.string().min(1),
|
|
107
|
+
/** Which backend owns the document. */
|
|
108
|
+
backend: z.enum(['local', 'remote']),
|
|
109
|
+
/**
|
|
110
|
+
* Version string pinned at attach time.
|
|
111
|
+
*
|
|
112
|
+
* Opaque: integer version for local backends, API-assigned string for remote.
|
|
113
|
+
*/
|
|
114
|
+
pinnedVersion: z.string().optional(),
|
|
115
|
+
});
|
|
116
|
+
// ─── Discriminated union ──────────────────────────────────────────────────────
|
|
117
|
+
/**
|
|
118
|
+
* Zod discriminated-union schema for {@link Attachment}.
|
|
119
|
+
*
|
|
120
|
+
* Uses `z.discriminatedUnion('kind', [...])` for O(1) variant lookup.
|
|
121
|
+
* Parse with `attachmentSchema.parse(input)` or
|
|
122
|
+
* `attachmentSchema.safeParse(input)`.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```ts
|
|
126
|
+
* const att = attachmentSchema.parse({
|
|
127
|
+
* kind: 'local-file',
|
|
128
|
+
* path: 'docs/rfc-003.md',
|
|
129
|
+
* sha256: 'a'.repeat(64),
|
|
130
|
+
* mime: 'text/markdown',
|
|
131
|
+
* size: 8192,
|
|
132
|
+
* description: 'RFC draft v3',
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export const attachmentSchema = z.discriminatedUnion('kind', [
|
|
137
|
+
localFileAttachmentSchema,
|
|
138
|
+
urlAttachmentSchema,
|
|
139
|
+
blobAttachmentSchema,
|
|
140
|
+
llmsTxtAttachmentSchema,
|
|
141
|
+
llmtxtDocAttachmentSchema,
|
|
142
|
+
]);
|
|
143
|
+
// ─── AttachmentMetadata schema ────────────────────────────────────────────────
|
|
144
|
+
/**
|
|
145
|
+
* Zod schema for {@link AttachmentMetadata}.
|
|
146
|
+
*
|
|
147
|
+
* Validates the persisted registry row. The embedded `attachment` field is
|
|
148
|
+
* validated recursively through the discriminated union.
|
|
149
|
+
*/
|
|
150
|
+
export const attachmentMetadataSchema = z.object({
|
|
151
|
+
/**
|
|
152
|
+
* Unique attachment ID.
|
|
153
|
+
*
|
|
154
|
+
* Pattern: `att_<base62>` or UUID fallback. Must be non-empty.
|
|
155
|
+
*/
|
|
156
|
+
id: z.string().min(1),
|
|
157
|
+
/**
|
|
158
|
+
* Content hash — SHA-256 hex (64 chars) for byte-backed kinds, empty string
|
|
159
|
+
* for kinds that delegate content storage externally.
|
|
160
|
+
*/
|
|
161
|
+
sha256: z.string(),
|
|
162
|
+
/** The full attachment value (validated through the discriminated union). */
|
|
163
|
+
attachment: attachmentSchema,
|
|
164
|
+
/** ISO 8601 creation timestamp. */
|
|
165
|
+
createdAt: z.string().datetime(),
|
|
166
|
+
/**
|
|
167
|
+
* Reference count — how many `AttachmentRef` rows point at this attachment.
|
|
168
|
+
*
|
|
169
|
+
* Must be a non-negative integer.
|
|
170
|
+
*/
|
|
171
|
+
refCount: z.number().int().nonnegative(),
|
|
172
|
+
});
|
|
173
|
+
// ─── AttachmentRef schema ─────────────────────────────────────────────────────
|
|
174
|
+
/**
|
|
175
|
+
* Zod schema for {@link AttachmentRef}.
|
|
176
|
+
*
|
|
177
|
+
* Validates the junction row linking one attachment to one owner. `ownerType`
|
|
178
|
+
* is restricted to the six supported CLEO entity types.
|
|
179
|
+
*/
|
|
180
|
+
export const attachmentRefSchema = z.object({
|
|
181
|
+
/** ID of the attachment (→ `attachments.id`). Must be non-empty. */
|
|
182
|
+
attachmentId: z.string().min(1),
|
|
183
|
+
/**
|
|
184
|
+
* The domain entity type that owns this attachment.
|
|
185
|
+
*
|
|
186
|
+
* Restricted to the six supported CLEO entity types.
|
|
187
|
+
*/
|
|
188
|
+
ownerType: z.enum(['task', 'observation', 'session', 'decision', 'learning', 'pattern']),
|
|
189
|
+
/** ID of the owning entity. Must be non-empty. */
|
|
190
|
+
ownerId: z.string().min(1),
|
|
191
|
+
/** ISO 8601 timestamp when the ref was created. */
|
|
192
|
+
attachedAt: z.string().datetime(),
|
|
193
|
+
/**
|
|
194
|
+
* Agent identity (or `"human"`) that created the ref.
|
|
195
|
+
*
|
|
196
|
+
* Optional; populated from the active session credential when available.
|
|
197
|
+
*/
|
|
198
|
+
attachedBy: z.string().optional(),
|
|
199
|
+
});
|
|
200
|
+
//# sourceMappingURL=attachment-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attachment-schema.js","sourceRoot":"","sources":["../src/attachment-schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,kFAAkF;AAElF;;;;;GAKG;AACH,MAAM,sBAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,8DAA8D;IAC9D,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,sDAAsD;IACtD,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;CACvC,CAAC,CAAC;AAEH,kFAAkF;AAElF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC,MAAM,CAAC;IACrE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC7B,kFAAkF;IAClF,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,8CAA8C;IAC9C,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;IAC7B,sBAAsB;IACtB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACvB,iDAAiD;IACjD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,WAAW,EAAE;CACrC,CAAC,CAAC;AAEH;;;;;GA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