@under18dev/veritas-core 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +12 -2
- package/dist/artifacts/store.d.ts +115 -0
- package/dist/artifacts/store.d.ts.map +1 -0
- package/dist/artifacts/store.js +323 -0
- package/dist/artifacts/store.js.map +1 -0
- package/dist/config/load.d.ts +20 -0
- package/dist/config/load.d.ts.map +1 -0
- package/dist/config/load.js +54 -0
- package/dist/config/load.js.map +1 -0
- package/dist/config/schema.d.ts +123 -0
- package/dist/config/schema.d.ts.map +1 -0
- package/dist/config/schema.js +171 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/exit-codes.d.ts +21 -0
- package/dist/exit-codes.d.ts.map +1 -0
- package/dist/exit-codes.js +36 -0
- package/dist/exit-codes.js.map +1 -0
- package/dist/hash.d.ts +5 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +26 -0
- package/dist/hash.js.map +1 -0
- package/dist/ids.d.ts +11 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +22 -0
- package/dist/ids.js.map +1 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/paths.d.ts +13 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +61 -0
- package/dist/paths.js.map +1 -0
- package/dist/pipeline.d.ts +34 -0
- package/dist/pipeline.d.ts.map +1 -0
- package/dist/pipeline.js +72 -0
- package/dist/pipeline.js.map +1 -0
- package/dist/policy.d.ts +30 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +105 -0
- package/dist/policy.js.map +1 -0
- package/dist/process.d.ts +53 -0
- package/dist/process.d.ts.map +1 -0
- package/dist/process.js +249 -0
- package/dist/process.js.map +1 -0
- package/dist/project/detect.d.ts +23 -0
- package/dist/project/detect.d.ts.map +1 -0
- package/dist/project/detect.js +91 -0
- package/dist/project/detect.js.map +1 -0
- package/dist/project/doctor.d.ts +29 -0
- package/dist/project/doctor.d.ts.map +1 -0
- package/dist/project/doctor.js +134 -0
- package/dist/project/doctor.js.map +1 -0
- package/dist/project/init.d.ts +18 -0
- package/dist/project/init.d.ts.map +1 -0
- package/dist/project/init.js +46 -0
- package/dist/project/init.js.map +1 -0
- package/dist/project/llm.d.ts +20 -0
- package/dist/project/llm.d.ts.map +1 -0
- package/dist/project/llm.js +86 -0
- package/dist/project/llm.js.map +1 -0
- package/dist/redact.d.ts +7 -0
- package/dist/redact.d.ts.map +1 -0
- package/dist/redact.js +77 -0
- package/dist/redact.js.map +1 -0
- package/dist/run-context.d.ts +38 -0
- package/dist/run-context.d.ts.map +1 -0
- package/dist/run-context.js +95 -0
- package/dist/run-context.js.map +1 -0
- package/dist/sandbox-runner.d.ts +2 -0
- package/dist/sandbox-runner.d.ts.map +1 -0
- package/dist/sandbox-runner.js +62 -0
- package/dist/sandbox-runner.js.map +1 -0
- package/dist/sandbox.d.ts +80 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +138 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/schema/common.d.ts +30 -0
- package/dist/schema/common.d.ts.map +1 -0
- package/dist/schema/common.js +23 -0
- package/dist/schema/common.js.map +1 -0
- package/dist/schema/evidence.d.ts +82 -0
- package/dist/schema/evidence.d.ts.map +1 -0
- package/dist/schema/evidence.js +41 -0
- package/dist/schema/evidence.js.map +1 -0
- package/dist/schema/finding.d.ts +57 -0
- package/dist/schema/finding.d.ts.map +1 -0
- package/dist/schema/finding.js +31 -0
- package/dist/schema/finding.js.map +1 -0
- package/dist/schema/formal.d.ts +52 -0
- package/dist/schema/formal.d.ts.map +1 -0
- package/dist/schema/formal.js +32 -0
- package/dist/schema/formal.js.map +1 -0
- package/dist/schema/improvement.d.ts +81 -0
- package/dist/schema/improvement.d.ts.map +1 -0
- package/dist/schema/improvement.js +52 -0
- package/dist/schema/improvement.js.map +1 -0
- package/dist/schema/ir.d.ts +194 -0
- package/dist/schema/ir.d.ts.map +1 -0
- package/dist/schema/ir.js +85 -0
- package/dist/schema/ir.js.map +1 -0
- package/dist/schema/mutation.d.ts +41 -0
- package/dist/schema/mutation.d.ts.map +1 -0
- package/dist/schema/mutation.js +21 -0
- package/dist/schema/mutation.js.map +1 -0
- package/dist/schema/property.d.ts +191 -0
- package/dist/schema/property.d.ts.map +1 -0
- package/dist/schema/property.js +66 -0
- package/dist/schema/property.js.map +1 -0
- package/dist/schema/run.d.ts +233 -0
- package/dist/schema/run.d.ts.map +1 -0
- package/dist/schema/run.js +92 -0
- package/dist/schema/run.js.map +1 -0
- package/dist/schema/status.d.ts +113 -0
- package/dist/schema/status.d.ts.map +1 -0
- package/dist/schema/status.js +82 -0
- package/dist/schema/status.js.map +1 -0
- package/dist/schema/tests.d.ts +157 -0
- package/dist/schema/tests.d.ts.map +1 -0
- package/dist/schema/tests.js +76 -0
- package/dist/schema/tests.js.map +1 -0
- package/dist/schemas-registry.d.ts +6 -0
- package/dist/schemas-registry.d.ts.map +1 -0
- package/dist/schemas-registry.js +44 -0
- package/dist/schemas-registry.js.map +1 -0
- package/dist/symbols.d.ts +10 -0
- package/dist/symbols.d.ts.map +1 -0
- package/dist/symbols.js +14 -0
- package/dist/symbols.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +4 -0
- package/dist/version.js.map +1 -0
- package/package.json +24 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @under18dev/veritas-core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Domain model, schemas, artifact store and orchestration core for Veritas
|
|
4
|
+
|
|
5
|
+
Part of [Veritas](https://github.com/under18dev/veritas), specification-aware test verification for TypeScript/JavaScript projects. Most users install the main package, which provides the `veritas` and `veritas-mcp` commands and the Node API:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -D @under18dev/veritas
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This package is an internal building block of that package; its API may change between minor versions. Source: [`packages/core`](https://github.com/under18dev/veritas/tree/main/packages/core).
|
|
12
|
+
|
|
13
|
+
Licensed under Apache-2.0.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ArtifactMeta } from '../schema/common.js';
|
|
3
|
+
export declare const RUNS_DIR: string;
|
|
4
|
+
/** Run-relative name of the index that gives raw (non-envelope) artifacts their metadata and content hash. */
|
|
5
|
+
export declare const ARTIFACT_INDEX_FILE = "artifact-index.json";
|
|
6
|
+
/**
|
|
7
|
+
* Raw artifacts (solver input/output, Lean sources, rendered reports, files written by external tools) cannot hold
|
|
8
|
+
* an envelope themselves. Each is listed here with its SHA-256, and the index's envelope carries the run metadata.
|
|
9
|
+
*/
|
|
10
|
+
export declare const ArtifactIndex: z.ZodArray<z.ZodObject<{
|
|
11
|
+
path: z.ZodString;
|
|
12
|
+
kind: z.ZodEnum<{
|
|
13
|
+
text: "text";
|
|
14
|
+
external: "external";
|
|
15
|
+
}>;
|
|
16
|
+
sha256: z.ZodString;
|
|
17
|
+
bytes: z.ZodNumber;
|
|
18
|
+
createdAt: z.ZodISODateTime;
|
|
19
|
+
}, z.core.$strip>>;
|
|
20
|
+
export type ArtifactIndex = z.infer<typeof ArtifactIndex>;
|
|
21
|
+
export declare const CACHE_DIR: string;
|
|
22
|
+
export interface Envelope<T> {
|
|
23
|
+
meta: ArtifactMeta;
|
|
24
|
+
data: T;
|
|
25
|
+
}
|
|
26
|
+
export declare function gitCommit(root: string): string | null;
|
|
27
|
+
/** Persists the artifacts of one run under `.veritas/runs/<run-id>/`, each wrapped with traceability metadata. */
|
|
28
|
+
export declare class RunStore {
|
|
29
|
+
readonly root: string;
|
|
30
|
+
readonly runId: string;
|
|
31
|
+
readonly dir: string;
|
|
32
|
+
private readonly baseMeta;
|
|
33
|
+
private readonly rawArtifacts;
|
|
34
|
+
constructor(root: string, runId: string, context: {
|
|
35
|
+
configHash: string;
|
|
36
|
+
sourceHash: string;
|
|
37
|
+
gitCommit?: string | null;
|
|
38
|
+
});
|
|
39
|
+
meta(): ArtifactMeta;
|
|
40
|
+
/** Validate against `schema`, redact secrets, wrap in an envelope and write. Returns the run-relative path. */
|
|
41
|
+
write<S extends z.ZodType>(name: string, schema: S, data: z.input<S>): string;
|
|
42
|
+
/** Raw text artifacts such as solver input/output or logs. Secrets are always redacted. */
|
|
43
|
+
writeText(name: string, content: string): string;
|
|
44
|
+
/**
|
|
45
|
+
* Record files that an external tool wrote under `dir` (run-relative) in the artifact index, so they carry the
|
|
46
|
+
* run metadata and a content hash like every other artifact. Returns the run-relative paths recorded.
|
|
47
|
+
*/
|
|
48
|
+
recordExternal(dir: string): string[];
|
|
49
|
+
private index;
|
|
50
|
+
private writeIndex;
|
|
51
|
+
read<S extends z.ZodType>(name: string, schema: S): Envelope<z.output<S>>;
|
|
52
|
+
pathFor(name: string): string;
|
|
53
|
+
}
|
|
54
|
+
/** Upgrades an envelope written with an older schema version by exactly one version step. */
|
|
55
|
+
export interface Migration {
|
|
56
|
+
from: string;
|
|
57
|
+
to: string;
|
|
58
|
+
migrate(envelope: {
|
|
59
|
+
meta: Record<string, unknown>;
|
|
60
|
+
data: unknown;
|
|
61
|
+
}): {
|
|
62
|
+
meta: Record<string, unknown>;
|
|
63
|
+
data: unknown;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** Registered migrations, oldest first. Empty while only one schema version exists. */
|
|
67
|
+
export declare const MIGRATIONS: Migration[];
|
|
68
|
+
export declare function readEnvelope<S extends z.ZodType>(file: string, schema: S, migrations?: Migration[]): Envelope<z.output<S>>;
|
|
69
|
+
/** Run IDs under `.veritas/runs`, newest first. */
|
|
70
|
+
export declare function listRuns(root: string): string[];
|
|
71
|
+
/**
|
|
72
|
+
* Content-addressed cache. The key must include every input that can change the result
|
|
73
|
+
* (sources, dependency versions, config, model, scope); callers pass them all in `keyParts`.
|
|
74
|
+
*/
|
|
75
|
+
export declare class ContentCache {
|
|
76
|
+
private readonly secret;
|
|
77
|
+
private readonly dir;
|
|
78
|
+
/**
|
|
79
|
+
* `secret` authenticates entries (HMAC-SHA256 over namespace, key and value). It is kept outside the project
|
|
80
|
+
* (see `openCache`), so an entry placed in `.veritas/cache` by anything else is a miss, not a result.
|
|
81
|
+
*/
|
|
82
|
+
constructor(root: string, secret: Buffer);
|
|
83
|
+
private mac;
|
|
84
|
+
key(keyParts: Record<string, unknown>): string;
|
|
85
|
+
/** The entry for `key`, or undefined when there is none or it does not match `schema` (a miss, never an error). */
|
|
86
|
+
get<S extends z.ZodType>(namespace: string, key: string, schema: S): z.output<S> | undefined;
|
|
87
|
+
private lookup;
|
|
88
|
+
set(namespace: string, key: string, value: unknown): void;
|
|
89
|
+
private file;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The project's cache, or null with the reason when it must not be used: disabled by `cache.enabled`, or
|
|
93
|
+
* `.veritas/cache` is tracked by git. Committed entries could come from anyone with write access to the
|
|
94
|
+
* repository (a pull request, for example) and forge results, so a tracked cache is ignored entirely.
|
|
95
|
+
*/
|
|
96
|
+
export declare function openCache(root: string, config: {
|
|
97
|
+
cache: {
|
|
98
|
+
enabled: boolean;
|
|
99
|
+
};
|
|
100
|
+
}, env?: NodeJS.ProcessEnv): {
|
|
101
|
+
cache: ContentCache | null;
|
|
102
|
+
message: string | null;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Where the cache key lives: `VERITAS_CACHE_KEY_FILE`, else the user's cache directory (`$XDG_CACHE_HOME` or
|
|
106
|
+
* `~/.cache` on POSIX, `%LOCALAPPDATA%` on Windows) under `veritas/cache-key`. Never inside a project.
|
|
107
|
+
*/
|
|
108
|
+
export declare function cacheKeyFile(env?: NodeJS.ProcessEnv): string;
|
|
109
|
+
/** Output of a git command run with the allowlisted environment, or null when git fails. */
|
|
110
|
+
export declare function gitOutput(root: string, args: string[]): string | null;
|
|
111
|
+
export declare function hashFiles(files: {
|
|
112
|
+
path: string;
|
|
113
|
+
content: string | Uint8Array;
|
|
114
|
+
}[]): string;
|
|
115
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/artifacts/store.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { chmodSync, mkdirSync, readdirSync, readFileSync, renameSync, statSync, writeFileSync, } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { VeritasError } from '../exit-codes.js';
|
|
8
|
+
import { canonicalJson, hashValue, sha256 } from '../hash.js';
|
|
9
|
+
import { resolveInsideRoot } from '../paths.js';
|
|
10
|
+
import { DEFAULT_ENV_ALLOWLIST } from '../process.js';
|
|
11
|
+
import { redact, redactDeep } from '../redact.js';
|
|
12
|
+
import { logEvent } from '../run-context.js';
|
|
13
|
+
import { ArtifactMeta, SCHEMA_VERSION } from '../schema/common.js';
|
|
14
|
+
import { TOOL_VERSION } from '../version.js';
|
|
15
|
+
export const RUNS_DIR = path.join('.veritas', 'runs');
|
|
16
|
+
/** Run-relative name of the index that gives raw (non-envelope) artifacts their metadata and content hash. */
|
|
17
|
+
export const ARTIFACT_INDEX_FILE = 'artifact-index.json';
|
|
18
|
+
/**
|
|
19
|
+
* Raw artifacts (solver input/output, Lean sources, rendered reports, files written by external tools) cannot hold
|
|
20
|
+
* an envelope themselves. Each is listed here with its SHA-256, and the index's envelope carries the run metadata.
|
|
21
|
+
*/
|
|
22
|
+
export const ArtifactIndex = z.array(z.object({
|
|
23
|
+
path: z.string().min(1),
|
|
24
|
+
kind: z.enum(['text', 'external']),
|
|
25
|
+
sha256: z.string().regex(/^[0-9a-f]{64}$/),
|
|
26
|
+
bytes: z.number().int().nonnegative(),
|
|
27
|
+
createdAt: z.iso.datetime({ offset: true }),
|
|
28
|
+
}));
|
|
29
|
+
export const CACHE_DIR = path.join('.veritas', 'cache');
|
|
30
|
+
export function gitCommit(root) {
|
|
31
|
+
// Like every child process, git gets only the allowlisted environment, never tokens or other secrets.
|
|
32
|
+
return gitOutput(root, ['rev-parse', 'HEAD'])?.trim() || null;
|
|
33
|
+
}
|
|
34
|
+
/** Write atomically (temp file + rename) so readers never see a half-written artifact. */
|
|
35
|
+
function writeAtomic(file, content) {
|
|
36
|
+
mkdirSync(path.dirname(file), { recursive: true });
|
|
37
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
38
|
+
writeFileSync(tmp, content);
|
|
39
|
+
renameSync(tmp, file);
|
|
40
|
+
}
|
|
41
|
+
/** Persists the artifacts of one run under `.veritas/runs/<run-id>/`, each wrapped with traceability metadata. */
|
|
42
|
+
export class RunStore {
|
|
43
|
+
root;
|
|
44
|
+
runId;
|
|
45
|
+
dir;
|
|
46
|
+
baseMeta;
|
|
47
|
+
rawArtifacts = new Map();
|
|
48
|
+
constructor(root, runId, context) {
|
|
49
|
+
this.root = root;
|
|
50
|
+
this.runId = runId;
|
|
51
|
+
this.dir = resolveInsideRoot(root, path.join(RUNS_DIR, runId));
|
|
52
|
+
this.baseMeta = {
|
|
53
|
+
schemaVersion: SCHEMA_VERSION,
|
|
54
|
+
runId,
|
|
55
|
+
toolVersion: TOOL_VERSION,
|
|
56
|
+
gitCommit: context.gitCommit === undefined ? gitCommit(root) : context.gitCommit,
|
|
57
|
+
configHash: context.configHash,
|
|
58
|
+
sourceHash: context.sourceHash,
|
|
59
|
+
};
|
|
60
|
+
mkdirSync(this.dir, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
meta() {
|
|
63
|
+
return { ...this.baseMeta, createdAt: new Date().toISOString() };
|
|
64
|
+
}
|
|
65
|
+
/** Validate against `schema`, redact secrets, wrap in an envelope and write. Returns the run-relative path. */
|
|
66
|
+
write(name, schema, data) {
|
|
67
|
+
const parsed = schema.safeParse(data);
|
|
68
|
+
if (!parsed.success) {
|
|
69
|
+
throw new VeritasError('tool', 'ARTIFACT_INVALID', `artifact ${name} does not match its schema`, undefined, parsed.error.issues);
|
|
70
|
+
}
|
|
71
|
+
const file = this.pathFor(name);
|
|
72
|
+
const envelope = { meta: this.meta(), data: redactDeep(parsed.data) };
|
|
73
|
+
writeAtomic(file, `${JSON.stringify(envelope, null, 2)}\n`);
|
|
74
|
+
return path.relative(this.dir, file).split(path.sep).join('/');
|
|
75
|
+
}
|
|
76
|
+
/** Raw text artifacts such as solver input/output or logs. Secrets are always redacted. */
|
|
77
|
+
writeText(name, content) {
|
|
78
|
+
const file = this.pathFor(name);
|
|
79
|
+
const redacted = redact(content);
|
|
80
|
+
writeAtomic(file, redacted);
|
|
81
|
+
const relative = path.relative(this.dir, file).split(path.sep).join('/');
|
|
82
|
+
this.index(relative, 'text', Buffer.from(redacted));
|
|
83
|
+
return relative;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Record files that an external tool wrote under `dir` (run-relative) in the artifact index, so they carry the
|
|
87
|
+
* run metadata and a content hash like every other artifact. Returns the run-relative paths recorded.
|
|
88
|
+
*/
|
|
89
|
+
recordExternal(dir) {
|
|
90
|
+
const base = this.pathFor(dir);
|
|
91
|
+
const recorded = [];
|
|
92
|
+
const walk = (current) => {
|
|
93
|
+
let entries;
|
|
94
|
+
try {
|
|
95
|
+
entries = readdirSync(current, { withFileTypes: true });
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
for (const entry of entries) {
|
|
101
|
+
const abs = path.join(current, entry.name);
|
|
102
|
+
if (entry.isDirectory())
|
|
103
|
+
walk(abs);
|
|
104
|
+
else if (entry.isFile()) {
|
|
105
|
+
const relative = path.relative(this.dir, abs).split(path.sep).join('/');
|
|
106
|
+
this.rawArtifacts.set(relative, {
|
|
107
|
+
path: relative,
|
|
108
|
+
kind: 'external',
|
|
109
|
+
sha256: sha256(readFileSync(abs)),
|
|
110
|
+
bytes: statSync(abs).size,
|
|
111
|
+
createdAt: new Date().toISOString(),
|
|
112
|
+
});
|
|
113
|
+
recorded.push(relative);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
walk(base);
|
|
118
|
+
if (recorded.length)
|
|
119
|
+
this.writeIndex();
|
|
120
|
+
return recorded.sort();
|
|
121
|
+
}
|
|
122
|
+
index(relative, kind, content) {
|
|
123
|
+
this.rawArtifacts.set(relative, {
|
|
124
|
+
path: relative,
|
|
125
|
+
kind,
|
|
126
|
+
sha256: sha256(content),
|
|
127
|
+
bytes: content.length,
|
|
128
|
+
createdAt: new Date().toISOString(),
|
|
129
|
+
});
|
|
130
|
+
this.writeIndex();
|
|
131
|
+
}
|
|
132
|
+
writeIndex() {
|
|
133
|
+
const entries = [...this.rawArtifacts.values()].sort((a, b) => a.path.localeCompare(b.path));
|
|
134
|
+
this.write(ARTIFACT_INDEX_FILE, ArtifactIndex, entries);
|
|
135
|
+
}
|
|
136
|
+
read(name, schema) {
|
|
137
|
+
return readEnvelope(this.pathFor(name), schema);
|
|
138
|
+
}
|
|
139
|
+
pathFor(name) {
|
|
140
|
+
return resolveInsideRoot(this.dir, name);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Registered migrations, oldest first. Empty while only one schema version exists. */
|
|
144
|
+
export const MIGRATIONS = [];
|
|
145
|
+
export function readEnvelope(file, schema, migrations = MIGRATIONS) {
|
|
146
|
+
let raw;
|
|
147
|
+
try {
|
|
148
|
+
raw = JSON.parse(readFileSync(file, 'utf8'));
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
throw new VeritasError('tool', 'ARTIFACT_UNREADABLE', `cannot read artifact ${file}: ${error.message}`);
|
|
152
|
+
}
|
|
153
|
+
let envelope = { meta: raw.meta ?? {}, data: raw.data };
|
|
154
|
+
const seen = new Set();
|
|
155
|
+
while (envelope.meta.schemaVersion !== SCHEMA_VERSION) {
|
|
156
|
+
const version = String(envelope.meta.schemaVersion ?? 'none');
|
|
157
|
+
const step = migrations.find((m) => m.from === version);
|
|
158
|
+
if (!step || seen.has(version)) {
|
|
159
|
+
throw new VeritasError('user', 'ARTIFACT_SCHEMA_VERSION', `artifact ${file} has schema version ${version}, expected ${SCHEMA_VERSION}, and no migration is available`, 'rerun the stage that produced it');
|
|
160
|
+
}
|
|
161
|
+
seen.add(version);
|
|
162
|
+
envelope = step.migrate(envelope);
|
|
163
|
+
envelope.meta = { ...envelope.meta, schemaVersion: step.to };
|
|
164
|
+
}
|
|
165
|
+
const meta = ArtifactMeta.safeParse(envelope.meta);
|
|
166
|
+
if (!meta.success) {
|
|
167
|
+
throw new VeritasError('tool', 'ARTIFACT_META_INVALID', `artifact ${file} has incomplete metadata`, undefined, meta.error.issues);
|
|
168
|
+
}
|
|
169
|
+
const parsed = schema.safeParse(envelope.data);
|
|
170
|
+
if (!parsed.success) {
|
|
171
|
+
throw new VeritasError('tool', 'ARTIFACT_INVALID', `artifact ${file} does not match its schema`, undefined, parsed.error.issues);
|
|
172
|
+
}
|
|
173
|
+
return { meta: meta.data, data: parsed.data };
|
|
174
|
+
}
|
|
175
|
+
/** Run IDs under `.veritas/runs`, newest first. */
|
|
176
|
+
export function listRuns(root) {
|
|
177
|
+
try {
|
|
178
|
+
return readdirSync(path.join(root, RUNS_DIR), { withFileTypes: true })
|
|
179
|
+
.filter((d) => d.isDirectory() && d.name.startsWith('run-'))
|
|
180
|
+
.map((d) => d.name)
|
|
181
|
+
.sort()
|
|
182
|
+
.reverse();
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
return [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Content-addressed cache. The key must include every input that can change the result
|
|
190
|
+
* (sources, dependency versions, config, model, scope); callers pass them all in `keyParts`.
|
|
191
|
+
*/
|
|
192
|
+
export class ContentCache {
|
|
193
|
+
secret;
|
|
194
|
+
dir;
|
|
195
|
+
/**
|
|
196
|
+
* `secret` authenticates entries (HMAC-SHA256 over namespace, key and value). It is kept outside the project
|
|
197
|
+
* (see `openCache`), so an entry placed in `.veritas/cache` by anything else is a miss, not a result.
|
|
198
|
+
*/
|
|
199
|
+
constructor(root, secret) {
|
|
200
|
+
this.secret = secret;
|
|
201
|
+
this.dir = resolveInsideRoot(root, CACHE_DIR);
|
|
202
|
+
}
|
|
203
|
+
mac(namespace, key, value) {
|
|
204
|
+
return createHmac('sha256', this.secret)
|
|
205
|
+
.update(`${namespace}\0${key}\0${canonicalJson(value)}`)
|
|
206
|
+
.digest('hex');
|
|
207
|
+
}
|
|
208
|
+
key(keyParts) {
|
|
209
|
+
return hashValue({ toolVersion: TOOL_VERSION, schemaVersion: SCHEMA_VERSION, ...keyParts });
|
|
210
|
+
}
|
|
211
|
+
/** The entry for `key`, or undefined when there is none or it does not match `schema` (a miss, never an error). */
|
|
212
|
+
get(namespace, key, schema) {
|
|
213
|
+
const value = this.lookup(namespace, key, schema);
|
|
214
|
+
logEvent('debug', `cache ${value === undefined ? 'miss' : 'hit'} ${namespace}/${key.slice(0, 12)}`, {
|
|
215
|
+
event: 'cache',
|
|
216
|
+
namespace,
|
|
217
|
+
key,
|
|
218
|
+
hit: value !== undefined,
|
|
219
|
+
});
|
|
220
|
+
return value;
|
|
221
|
+
}
|
|
222
|
+
lookup(namespace, key, schema) {
|
|
223
|
+
try {
|
|
224
|
+
const entry = JSON.parse(readFileSync(this.file(namespace, key), 'utf8'));
|
|
225
|
+
if (typeof entry.mac !== 'string' || !/^[0-9a-f]{64}$/.test(entry.mac))
|
|
226
|
+
return undefined;
|
|
227
|
+
const expected = Buffer.from(this.mac(namespace, key, entry.value), 'hex');
|
|
228
|
+
if (!timingSafeEqual(Buffer.from(entry.mac, 'hex'), expected))
|
|
229
|
+
return undefined;
|
|
230
|
+
const parsed = schema.safeParse(entry.value);
|
|
231
|
+
return parsed.success ? parsed.data : undefined;
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return undefined;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
set(namespace, key, value) {
|
|
238
|
+
const stored = JSON.parse(JSON.stringify(redactDeep(value)));
|
|
239
|
+
writeAtomic(this.file(namespace, key), JSON.stringify({ mac: this.mac(namespace, key, stored), value: stored }));
|
|
240
|
+
}
|
|
241
|
+
file(namespace, key) {
|
|
242
|
+
if (!/^[a-z0-9-]+$/.test(namespace) || !/^[0-9a-f]{64}$/.test(key)) {
|
|
243
|
+
throw new VeritasError('tool', 'CACHE_KEY_INVALID', `invalid cache namespace or key: ${namespace}/${key}`);
|
|
244
|
+
}
|
|
245
|
+
return path.join(this.dir, namespace, key.slice(0, 2), `${key}.json`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The project's cache, or null with the reason when it must not be used: disabled by `cache.enabled`, or
|
|
250
|
+
* `.veritas/cache` is tracked by git. Committed entries could come from anyone with write access to the
|
|
251
|
+
* repository (a pull request, for example) and forge results, so a tracked cache is ignored entirely.
|
|
252
|
+
*/
|
|
253
|
+
export function openCache(root, config, env = process.env) {
|
|
254
|
+
if (!config.cache.enabled)
|
|
255
|
+
return { cache: null, message: 'cache: disabled by configuration' };
|
|
256
|
+
if (gitOutput(root, ['ls-files', '--', CACHE_DIR.split(path.sep).join('/')])?.trim()) {
|
|
257
|
+
return {
|
|
258
|
+
cache: null,
|
|
259
|
+
message: 'cache: ignored because .veritas/cache is tracked by git (committed entries are not trusted)',
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
const secret = cacheSecret(env);
|
|
263
|
+
if (!secret)
|
|
264
|
+
return { cache: null, message: 'cache: disabled because no cache key could be created' };
|
|
265
|
+
return { cache: new ContentCache(root, secret), message: null };
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Where the cache key lives: `VERITAS_CACHE_KEY_FILE`, else the user's cache directory (`$XDG_CACHE_HOME` or
|
|
269
|
+
* `~/.cache` on POSIX, `%LOCALAPPDATA%` on Windows) under `veritas/cache-key`. Never inside a project.
|
|
270
|
+
*/
|
|
271
|
+
export function cacheKeyFile(env = process.env) {
|
|
272
|
+
if (env.VERITAS_CACHE_KEY_FILE)
|
|
273
|
+
return path.resolve(env.VERITAS_CACHE_KEY_FILE);
|
|
274
|
+
const base = process.platform === 'win32'
|
|
275
|
+
? env.LOCALAPPDATA || path.join(homedir(), 'AppData', 'Local')
|
|
276
|
+
: env.XDG_CACHE_HOME || path.join(env.HOME || homedir(), '.cache');
|
|
277
|
+
return path.join(base, 'veritas', 'cache-key');
|
|
278
|
+
}
|
|
279
|
+
/** The 32-byte cache key, created (mode 0600) on first use; null when it can be neither read nor created. */
|
|
280
|
+
function cacheSecret(env) {
|
|
281
|
+
const file = cacheKeyFile(env);
|
|
282
|
+
try {
|
|
283
|
+
mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
284
|
+
// Exclusive create: when two processes race, both end up using the key that was written first.
|
|
285
|
+
writeFileSync(file, randomBytes(32), { mode: 0o600, flag: 'wx' });
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
if (error.code !== 'EEXIST')
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
try {
|
|
292
|
+
// A key others can read could sign forged entries: tighten it to 0600, or do without a cache.
|
|
293
|
+
if (process.platform !== 'win32' && (statSync(file).mode & 0o077) !== 0)
|
|
294
|
+
chmodSync(file, 0o600);
|
|
295
|
+
if (process.platform !== 'win32' && (statSync(file).mode & 0o077) !== 0)
|
|
296
|
+
return null;
|
|
297
|
+
const secret = readFileSync(file);
|
|
298
|
+
return secret.length === 32 ? secret : null;
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/** Output of a git command run with the allowlisted environment, or null when git fails. */
|
|
305
|
+
export function gitOutput(root, args) {
|
|
306
|
+
try {
|
|
307
|
+
const env = Object.fromEntries(DEFAULT_ENV_ALLOWLIST.flatMap((name) => process.env[name] === undefined ? [] : [[name, process.env[name]]]));
|
|
308
|
+
return execFileSync('git', args, {
|
|
309
|
+
cwd: root,
|
|
310
|
+
env,
|
|
311
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
312
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
313
|
+
}).toString();
|
|
314
|
+
}
|
|
315
|
+
catch {
|
|
316
|
+
return null;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
export function hashFiles(files) {
|
|
320
|
+
const sorted = [...files].sort((a, b) => a.path.localeCompare(b.path));
|
|
321
|
+
return hashValue(sorted.map((f) => [f.path, sha256(f.content)]));
|
|
322
|
+
}
|
|
323
|
+
//# sourceMappingURL=store.js.map
|