@ai-dev-orchestrator/artifacts 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 +21 -0
- package/README.md +53 -0
- package/dist/domain/agreement-artifacts/errors.d.ts +16 -0
- package/dist/domain/agreement-artifacts/errors.js +23 -0
- package/dist/domain/agreement-artifacts/index.d.ts +1 -0
- package/dist/domain/agreement-artifacts/index.js +1 -0
- package/dist/domain/artifact-system/artifact-content-schemas.d.ts +487 -0
- package/dist/domain/artifact-system/artifact-content-schemas.js +464 -0
- package/dist/domain/artifact-system/artifact-descriptors.d.ts +9 -0
- package/dist/domain/artifact-system/artifact-descriptors.js +165 -0
- package/dist/domain/artifact-system/constants.d.ts +7 -0
- package/dist/domain/artifact-system/constants.js +29 -0
- package/dist/domain/artifact-system/errors.d.ts +55 -0
- package/dist/domain/artifact-system/errors.js +75 -0
- package/dist/domain/artifact-system/index.d.ts +5 -0
- package/dist/domain/artifact-system/index.js +4 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -0
- package/dist/infrastructure/agreement-artifacts/agreement-gate.d.ts +27 -0
- package/dist/infrastructure/agreement-artifacts/agreement-gate.js +105 -0
- package/dist/infrastructure/agreement-artifacts/agreement-generator.d.ts +28 -0
- package/dist/infrastructure/agreement-artifacts/agreement-generator.js +89 -0
- package/dist/infrastructure/agreement-artifacts/agreement-validator.d.ts +7 -0
- package/dist/infrastructure/agreement-artifacts/agreement-validator.js +38 -0
- package/dist/infrastructure/agreement-artifacts/index.d.ts +3 -0
- package/dist/infrastructure/agreement-artifacts/index.js +3 -0
- package/dist/infrastructure/artifact-system/artifact-type-validator.d.ts +6 -0
- package/dist/infrastructure/artifact-system/artifact-type-validator.js +38 -0
- package/dist/infrastructure/artifact-system/checksum-engine.d.ts +4 -0
- package/dist/infrastructure/artifact-system/checksum-engine.js +9 -0
- package/dist/infrastructure/artifact-system/content-parser.d.ts +26 -0
- package/dist/infrastructure/artifact-system/content-parser.js +64 -0
- package/dist/infrastructure/artifact-system/default-ownership-registry.d.ts +14 -0
- package/dist/infrastructure/artifact-system/default-ownership-registry.js +65 -0
- package/dist/infrastructure/artifact-system/disk-reader.d.ts +7 -0
- package/dist/infrastructure/artifact-system/disk-reader.js +22 -0
- package/dist/infrastructure/artifact-system/disk-writer.d.ts +3 -0
- package/dist/infrastructure/artifact-system/disk-writer.js +21 -0
- package/dist/infrastructure/artifact-system/filesystem-artifact-store.d.ts +26 -0
- package/dist/infrastructure/artifact-system/filesystem-artifact-store.js +191 -0
- package/dist/infrastructure/artifact-system/index.d.ts +8 -0
- package/dist/infrastructure/artifact-system/index.js +7 -0
- package/dist/infrastructure/artifact-system/inventory-manager.d.ts +18 -0
- package/dist/infrastructure/artifact-system/inventory-manager.js +142 -0
- package/dist/infrastructure/artifact-system/version-manager.d.ts +12 -0
- package/dist/infrastructure/artifact-system/version-manager.js +42 -0
- package/dist/infrastructure/shared/hash.d.ts +2 -0
- package/dist/infrastructure/shared/hash.js +10 -0
- package/package.json +47 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { ARTIFACT_TYPES } from '@ai-dev-orchestrator/schemas';
|
|
2
|
+
import { ARTIFACT_DESCRIPTORS } from '../../domain/artifact-system/artifact-descriptors';
|
|
3
|
+
/**
|
|
4
|
+
* Builds an ownership override map from role contracts by collecting each role's
|
|
5
|
+
* declared `ownedArtifacts` into a map keyed by artifact type.
|
|
6
|
+
*/
|
|
7
|
+
export function buildOwnershipOverrides(roles) {
|
|
8
|
+
const map = new Map();
|
|
9
|
+
for (const role of roles) {
|
|
10
|
+
for (const artifactType of role.ownedArtifacts) {
|
|
11
|
+
const existing = map.get(artifactType);
|
|
12
|
+
if (existing) {
|
|
13
|
+
if (!existing.includes(role.id)) {
|
|
14
|
+
existing.push(role.id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
map.set(artifactType, [role.id]);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return map;
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_OWNERSHIP_MAP = Object.fromEntries(Object.entries(ARTIFACT_DESCRIPTORS).map(([k, v]) => [k, v.defaultOwners]));
|
|
25
|
+
export class DefaultOwnershipRegistry {
|
|
26
|
+
ownershipMap;
|
|
27
|
+
constructor(overrides) {
|
|
28
|
+
if (overrides) {
|
|
29
|
+
const merged = { ...DEFAULT_OWNERSHIP_MAP };
|
|
30
|
+
for (const [type, owners] of overrides) {
|
|
31
|
+
const existing = merged[type];
|
|
32
|
+
const ownerList = Array.isArray(owners) ? owners : [owners];
|
|
33
|
+
const newOwners = ownerList.filter((o) => !existing.includes(o));
|
|
34
|
+
if (newOwners.length > 0) {
|
|
35
|
+
merged[type] = [...existing, ...newOwners];
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
this.ownershipMap = merged;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
this.ownershipMap = DEFAULT_OWNERSHIP_MAP;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
getOwner(type) {
|
|
45
|
+
const owners = this.ownershipMap[type];
|
|
46
|
+
return owners[0] ?? null;
|
|
47
|
+
}
|
|
48
|
+
isAuthorized(role, type) {
|
|
49
|
+
if (role === 'system') {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
const owners = this.ownershipMap[type];
|
|
53
|
+
return owners.includes(role);
|
|
54
|
+
}
|
|
55
|
+
getOwnedTypes(role) {
|
|
56
|
+
const types = [];
|
|
57
|
+
for (const artifactType of ARTIFACT_TYPES) {
|
|
58
|
+
const owners = this.ownershipMap[artifactType];
|
|
59
|
+
if (owners.includes(role)) {
|
|
60
|
+
types.push(artifactType);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return types;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ArtifactMetadata, ArtifactRef } from '@ai-dev-orchestrator/schemas';
|
|
2
|
+
/** Read artifact content from disk. Throws ArtifactNotFoundError if the file does not exist. */
|
|
3
|
+
export declare function readContent(filePath: string, ref: ArtifactRef): string;
|
|
4
|
+
/** Read and parse artifact metadata from a YAML sidecar file. */
|
|
5
|
+
export declare function readMetadata(filePath: string, ref: ArtifactRef): ArtifactMetadata;
|
|
6
|
+
/** Check if a file exists on disk. */
|
|
7
|
+
export declare function fileExists(filePath: string): boolean;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { parse } from 'yaml';
|
|
3
|
+
import { ArtifactNotFoundError } from '../../domain/artifact-system/errors';
|
|
4
|
+
/** Read artifact content from disk. Throws ArtifactNotFoundError if the file does not exist. */
|
|
5
|
+
export function readContent(filePath, ref) {
|
|
6
|
+
if (!existsSync(filePath)) {
|
|
7
|
+
throw new ArtifactNotFoundError(ref);
|
|
8
|
+
}
|
|
9
|
+
return readFileSync(filePath, 'utf8');
|
|
10
|
+
}
|
|
11
|
+
/** Read and parse artifact metadata from a YAML sidecar file. */
|
|
12
|
+
export function readMetadata(filePath, ref) {
|
|
13
|
+
if (!existsSync(filePath)) {
|
|
14
|
+
throw new ArtifactNotFoundError(ref);
|
|
15
|
+
}
|
|
16
|
+
const content = readFileSync(filePath, 'utf8');
|
|
17
|
+
return parse(content);
|
|
18
|
+
}
|
|
19
|
+
/** Check if a file exists on disk. */
|
|
20
|
+
export function fileExists(filePath) {
|
|
21
|
+
return existsSync(filePath);
|
|
22
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { mkdirSync } from 'node:fs';
|
|
2
|
+
import { dirname } from 'node:path';
|
|
3
|
+
import { getErrorMessage } from '@ai-dev-orchestrator/utils';
|
|
4
|
+
import writeFileAtomic from 'write-file-atomic';
|
|
5
|
+
import { stringify } from 'yaml';
|
|
6
|
+
import { DiskWriteError } from '../../domain/artifact-system/errors';
|
|
7
|
+
export async function atomicWrite(filePath, content) {
|
|
8
|
+
const dir = dirname(filePath);
|
|
9
|
+
try {
|
|
10
|
+
mkdirSync(dir, { recursive: true });
|
|
11
|
+
await writeFileAtomic(filePath, content, { encoding: 'utf8' });
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
const message = getErrorMessage(error);
|
|
15
|
+
throw new DiskWriteError(filePath, message);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export async function writeMetadata(filePath, metadata) {
|
|
19
|
+
const content = stringify(metadata);
|
|
20
|
+
await atomicWrite(filePath, content);
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { ArtifactStore, ArtifactTypeValidator, OwnershipRegistry } from '@ai-dev-orchestrator/ports';
|
|
2
|
+
import type { Artifact, ArtifactInput, ArtifactInventory, ArtifactQuery, ArtifactRef, ArtifactType, IntegrityResult } from '@ai-dev-orchestrator/schemas';
|
|
3
|
+
/**
|
|
4
|
+
* Filesystem-backed artifact store using synchronous I/O.
|
|
5
|
+
*
|
|
6
|
+
* Sync operations are accepted here: artifacts are small text files written once
|
|
7
|
+
* and read infrequently, so async I/O adds complexity without measurable benefit.
|
|
8
|
+
* Async migration is deferred to S14 if profiling shows contention.
|
|
9
|
+
*/
|
|
10
|
+
export declare class FilesystemArtifactStore implements ArtifactStore {
|
|
11
|
+
private readonly artifactsDir;
|
|
12
|
+
private readonly versionManager;
|
|
13
|
+
private readonly inventoryManager;
|
|
14
|
+
private readonly ownershipRegistry;
|
|
15
|
+
private readonly typeValidator;
|
|
16
|
+
constructor(runDir: string, runId: string, ownershipRegistry: OwnershipRegistry, typeValidator: ArtifactTypeValidator);
|
|
17
|
+
store(input: ArtifactInput): Promise<ArtifactRef>;
|
|
18
|
+
get(ref: ArtifactRef): Promise<Artifact>;
|
|
19
|
+
getLatest(type: ArtifactType, name: string): Promise<Artifact | null>;
|
|
20
|
+
list(query: ArtifactQuery): Promise<ArtifactRef[]>;
|
|
21
|
+
history(type: ArtifactType, name: string): Promise<ArtifactRef[]>;
|
|
22
|
+
verify(ref: ArtifactRef): Promise<IntegrityResult>;
|
|
23
|
+
inventory(): Promise<ArtifactInventory>;
|
|
24
|
+
private artifactContentPath;
|
|
25
|
+
private artifactMetaPath;
|
|
26
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { ImmutabilityViolationError, OwnershipViolationError, TypeValidationError, } from '../../domain/artifact-system/errors';
|
|
3
|
+
import { computeChecksum, verifyChecksum } from './checksum-engine';
|
|
4
|
+
import { fileExists, readContent, readMetadata } from './disk-reader';
|
|
5
|
+
import { atomicWrite, writeMetadata } from './disk-writer';
|
|
6
|
+
import { InventoryManager } from './inventory-manager';
|
|
7
|
+
import { VersionManager } from './version-manager';
|
|
8
|
+
const FAIL_SAFE_ARTIFACT_TYPES = new Set([
|
|
9
|
+
'plan_review',
|
|
10
|
+
'static_review',
|
|
11
|
+
'security_review',
|
|
12
|
+
'performance_review',
|
|
13
|
+
'verification',
|
|
14
|
+
'judge_decision',
|
|
15
|
+
]);
|
|
16
|
+
/**
|
|
17
|
+
* Filesystem-backed artifact store using synchronous I/O.
|
|
18
|
+
*
|
|
19
|
+
* Sync operations are accepted here: artifacts are small text files written once
|
|
20
|
+
* and read infrequently, so async I/O adds complexity without measurable benefit.
|
|
21
|
+
* Async migration is deferred to S14 if profiling shows contention.
|
|
22
|
+
*/
|
|
23
|
+
export class FilesystemArtifactStore {
|
|
24
|
+
artifactsDir;
|
|
25
|
+
versionManager;
|
|
26
|
+
inventoryManager;
|
|
27
|
+
ownershipRegistry;
|
|
28
|
+
typeValidator;
|
|
29
|
+
constructor(runDir, runId, ownershipRegistry, typeValidator) {
|
|
30
|
+
this.artifactsDir = join(runDir, 'artifacts');
|
|
31
|
+
this.versionManager = new VersionManager(this.artifactsDir);
|
|
32
|
+
this.inventoryManager = new InventoryManager(runDir, runId);
|
|
33
|
+
this.ownershipRegistry = ownershipRegistry;
|
|
34
|
+
this.typeValidator = typeValidator;
|
|
35
|
+
}
|
|
36
|
+
async store(input) {
|
|
37
|
+
if (!this.ownershipRegistry.isAuthorized(input.producedBy, input.type)) {
|
|
38
|
+
const owner = this.ownershipRegistry.getOwner(input.type);
|
|
39
|
+
throw new OwnershipViolationError(input.producedBy, input.type, owner ?? 'unknown');
|
|
40
|
+
}
|
|
41
|
+
let validationFailed = false;
|
|
42
|
+
if (!input.preValidated) {
|
|
43
|
+
const validationResult = this.typeValidator.validate(input.type, input.content);
|
|
44
|
+
if (!validationResult.valid) {
|
|
45
|
+
if (FAIL_SAFE_ARTIFACT_TYPES.has(input.type)) {
|
|
46
|
+
validationFailed = true;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
throw new TypeValidationError(input.type, validationResult.errors ?? [{ path: '/', message: 'Validation failed' }]);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const version = this.versionManager.nextVersion(input.type, input.name);
|
|
54
|
+
const existingPath = this.artifactContentPath(input.type, input.name, version);
|
|
55
|
+
if (fileExists(existingPath)) {
|
|
56
|
+
throw new ImmutabilityViolationError({
|
|
57
|
+
type: input.type,
|
|
58
|
+
name: input.name,
|
|
59
|
+
version,
|
|
60
|
+
checksum: '',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const checksum = computeChecksum(input.content);
|
|
64
|
+
const createdAt = new Date().toISOString();
|
|
65
|
+
const sizeBytes = Buffer.byteLength(input.content, 'utf8');
|
|
66
|
+
const ref = { type: input.type, name: input.name, version, checksum };
|
|
67
|
+
await atomicWrite(existingPath, input.content);
|
|
68
|
+
const metadata = {
|
|
69
|
+
type: input.type,
|
|
70
|
+
name: input.name,
|
|
71
|
+
runId: input.runId,
|
|
72
|
+
version,
|
|
73
|
+
checksum,
|
|
74
|
+
producedBy: input.producedBy,
|
|
75
|
+
predecessorRef: input.predecessorRef ?? null,
|
|
76
|
+
createdAt,
|
|
77
|
+
sizeBytes,
|
|
78
|
+
metadata: validationFailed ? { ...input.metadata, validationFailed: true } : input.metadata,
|
|
79
|
+
};
|
|
80
|
+
const metaPath = this.artifactMetaPath(input.type, input.name, version);
|
|
81
|
+
await writeMetadata(metaPath, metadata);
|
|
82
|
+
const summary = {
|
|
83
|
+
ref,
|
|
84
|
+
type: input.type,
|
|
85
|
+
name: input.name,
|
|
86
|
+
version,
|
|
87
|
+
producedBy: input.producedBy,
|
|
88
|
+
createdAt,
|
|
89
|
+
sizeBytes,
|
|
90
|
+
};
|
|
91
|
+
await this.inventoryManager.addEntry(summary);
|
|
92
|
+
return ref;
|
|
93
|
+
}
|
|
94
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
95
|
+
async get(ref) {
|
|
96
|
+
const contentPath = this.artifactContentPath(ref.type, ref.name, ref.version);
|
|
97
|
+
const metaPath = this.artifactMetaPath(ref.type, ref.name, ref.version);
|
|
98
|
+
const content = readContent(contentPath, ref);
|
|
99
|
+
const meta = readMetadata(metaPath, ref);
|
|
100
|
+
return {
|
|
101
|
+
ref,
|
|
102
|
+
type: meta.type,
|
|
103
|
+
name: meta.name,
|
|
104
|
+
version: meta.version,
|
|
105
|
+
content,
|
|
106
|
+
checksum: meta.checksum,
|
|
107
|
+
producedBy: meta.producedBy,
|
|
108
|
+
predecessorRef: meta.predecessorRef ?? undefined,
|
|
109
|
+
createdAt: meta.createdAt,
|
|
110
|
+
sizeBytes: meta.sizeBytes,
|
|
111
|
+
metadata: meta.metadata,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
getLatest(type, name) {
|
|
115
|
+
const latest = this.versionManager.latestVersion(type, name);
|
|
116
|
+
if (latest === null) {
|
|
117
|
+
return Promise.resolve(null);
|
|
118
|
+
}
|
|
119
|
+
const contentPath = this.artifactContentPath(type, name, latest);
|
|
120
|
+
const metaPath = this.artifactMetaPath(type, name, latest);
|
|
121
|
+
const ref = { type, name, version: latest, checksum: '' };
|
|
122
|
+
const content = readContent(contentPath, ref);
|
|
123
|
+
const meta = readMetadata(metaPath, ref);
|
|
124
|
+
return Promise.resolve({
|
|
125
|
+
ref: { type, name, version: latest, checksum: meta.checksum },
|
|
126
|
+
type: meta.type,
|
|
127
|
+
name: meta.name,
|
|
128
|
+
version: meta.version,
|
|
129
|
+
content,
|
|
130
|
+
checksum: meta.checksum,
|
|
131
|
+
producedBy: meta.producedBy,
|
|
132
|
+
predecessorRef: meta.predecessorRef ?? undefined,
|
|
133
|
+
createdAt: meta.createdAt,
|
|
134
|
+
sizeBytes: meta.sizeBytes,
|
|
135
|
+
metadata: meta.metadata,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
list(query) {
|
|
139
|
+
let refs = this.inventoryManager.listRefs({
|
|
140
|
+
type: query.type,
|
|
141
|
+
name: query.name,
|
|
142
|
+
producedBy: query.producedBy,
|
|
143
|
+
});
|
|
144
|
+
const minVersion = query.minVersion;
|
|
145
|
+
if (minVersion !== undefined) {
|
|
146
|
+
refs = refs.filter((r) => r.version >= minVersion);
|
|
147
|
+
}
|
|
148
|
+
const maxVersion = query.maxVersion;
|
|
149
|
+
if (maxVersion !== undefined) {
|
|
150
|
+
refs = refs.filter((r) => r.version <= maxVersion);
|
|
151
|
+
}
|
|
152
|
+
return Promise.resolve(refs);
|
|
153
|
+
}
|
|
154
|
+
history(type, name) {
|
|
155
|
+
const versions = this.versionManager.listVersions(type, name);
|
|
156
|
+
const refs = [];
|
|
157
|
+
for (const version of versions) {
|
|
158
|
+
const metaPath = this.artifactMetaPath(type, name, version);
|
|
159
|
+
const dummyRef = { type, name, version, checksum: '' };
|
|
160
|
+
try {
|
|
161
|
+
const meta = readMetadata(metaPath, dummyRef);
|
|
162
|
+
refs.push({ type, name, version, checksum: meta.checksum });
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
refs.push(dummyRef);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Promise.resolve(refs);
|
|
169
|
+
}
|
|
170
|
+
verify(ref) {
|
|
171
|
+
const contentPath = this.artifactContentPath(ref.type, ref.name, ref.version);
|
|
172
|
+
const content = readContent(contentPath, ref);
|
|
173
|
+
const actualChecksum = computeChecksum(content);
|
|
174
|
+
const valid = verifyChecksum(content, ref.checksum);
|
|
175
|
+
return Promise.resolve({
|
|
176
|
+
valid,
|
|
177
|
+
expectedChecksum: ref.checksum,
|
|
178
|
+
actualChecksum,
|
|
179
|
+
ref,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
inventory() {
|
|
183
|
+
return Promise.resolve(this.inventoryManager.getInventory());
|
|
184
|
+
}
|
|
185
|
+
artifactContentPath(type, name, version) {
|
|
186
|
+
return join(this.artifactsDir, type, `${name}_v${String(version)}.md`);
|
|
187
|
+
}
|
|
188
|
+
artifactMetaPath(type, name, version) {
|
|
189
|
+
return join(this.artifactsDir, type, `${name}_v${String(version)}.meta.yaml`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { computeChecksum, verifyChecksum } from './checksum-engine';
|
|
2
|
+
export { DefaultArtifactTypeValidator } from './artifact-type-validator';
|
|
3
|
+
export { buildOwnershipOverrides, DefaultOwnershipRegistry } from './default-ownership-registry';
|
|
4
|
+
export { FilesystemArtifactStore } from './filesystem-artifact-store';
|
|
5
|
+
export { InventoryManager } from './inventory-manager';
|
|
6
|
+
export { safeJsonParse, parseTypedArtifactContent, parseFrontmatter, parseJson, parseYaml, parseArtifactContent, FRONTMATTER_REGEX, } from './content-parser';
|
|
7
|
+
export type { SafeParseResult } from './content-parser';
|
|
8
|
+
export { VersionManager } from './version-manager';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { computeChecksum, verifyChecksum } from './checksum-engine';
|
|
2
|
+
export { DefaultArtifactTypeValidator } from './artifact-type-validator';
|
|
3
|
+
export { buildOwnershipOverrides, DefaultOwnershipRegistry } from './default-ownership-registry';
|
|
4
|
+
export { FilesystemArtifactStore } from './filesystem-artifact-store';
|
|
5
|
+
export { InventoryManager } from './inventory-manager';
|
|
6
|
+
export { safeJsonParse, parseTypedArtifactContent, parseFrontmatter, parseJson, parseYaml, parseArtifactContent, FRONTMATTER_REGEX, } from './content-parser';
|
|
7
|
+
export { VersionManager } from './version-manager';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type ArtifactInventory, type ArtifactRef, type ArtifactSummary, type ArtifactType } from '@ai-dev-orchestrator/schemas';
|
|
2
|
+
export declare class InventoryManager {
|
|
3
|
+
private artifacts;
|
|
4
|
+
private readonly runId;
|
|
5
|
+
private readonly inventoryPath;
|
|
6
|
+
constructor(runDir: string, runId: string);
|
|
7
|
+
addEntry(summary: ArtifactSummary): Promise<void>;
|
|
8
|
+
removeEntry(ref: ArtifactRef): Promise<void>;
|
|
9
|
+
getInventory(): ArtifactInventory;
|
|
10
|
+
listRefs(query?: {
|
|
11
|
+
type?: ArtifactType;
|
|
12
|
+
name?: string;
|
|
13
|
+
producedBy?: string;
|
|
14
|
+
}): ArtifactRef[];
|
|
15
|
+
rebuild(artifactsDir: string): Promise<ArtifactInventory>;
|
|
16
|
+
private loadFromDisk;
|
|
17
|
+
private persist;
|
|
18
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { INVENTORY_FILENAME, } from '@ai-dev-orchestrator/schemas';
|
|
4
|
+
import { parse, stringify } from 'yaml';
|
|
5
|
+
import { InventoryCorruptionError } from '../../domain/artifact-system/errors';
|
|
6
|
+
import { fileExists, readContent } from './disk-reader';
|
|
7
|
+
import { atomicWrite } from './disk-writer';
|
|
8
|
+
export class InventoryManager {
|
|
9
|
+
artifacts = [];
|
|
10
|
+
runId;
|
|
11
|
+
inventoryPath;
|
|
12
|
+
constructor(runDir, runId) {
|
|
13
|
+
this.runId = runId;
|
|
14
|
+
this.inventoryPath = join(runDir, INVENTORY_FILENAME);
|
|
15
|
+
this.loadFromDisk();
|
|
16
|
+
}
|
|
17
|
+
async addEntry(summary) {
|
|
18
|
+
this.artifacts.push(summary);
|
|
19
|
+
await this.persist();
|
|
20
|
+
}
|
|
21
|
+
async removeEntry(ref) {
|
|
22
|
+
this.artifacts = this.artifacts.filter((a) => !(a.ref.type === ref.type && a.ref.name === ref.name && a.ref.version === ref.version));
|
|
23
|
+
await this.persist();
|
|
24
|
+
}
|
|
25
|
+
getInventory() {
|
|
26
|
+
const totalSizeBytes = this.artifacts.reduce((sum, a) => sum + a.sizeBytes, 0);
|
|
27
|
+
return {
|
|
28
|
+
runId: this.runId,
|
|
29
|
+
artifacts: [...this.artifacts],
|
|
30
|
+
totalCount: this.artifacts.length,
|
|
31
|
+
totalSizeBytes,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
listRefs(query) {
|
|
35
|
+
let filtered = this.artifacts;
|
|
36
|
+
if (query?.type) {
|
|
37
|
+
filtered = filtered.filter((a) => a.type === query.type);
|
|
38
|
+
}
|
|
39
|
+
if (query?.name) {
|
|
40
|
+
filtered = filtered.filter((a) => a.name === query.name);
|
|
41
|
+
}
|
|
42
|
+
if (query?.producedBy) {
|
|
43
|
+
filtered = filtered.filter((a) => a.producedBy === query.producedBy);
|
|
44
|
+
}
|
|
45
|
+
return filtered.map((a) => a.ref);
|
|
46
|
+
}
|
|
47
|
+
async rebuild(artifactsDir) {
|
|
48
|
+
this.artifacts = [];
|
|
49
|
+
if (!existsSync(artifactsDir)) {
|
|
50
|
+
await this.persist();
|
|
51
|
+
return this.getInventory();
|
|
52
|
+
}
|
|
53
|
+
const typeDirs = readdirSync(artifactsDir, { withFileTypes: true })
|
|
54
|
+
.filter((d) => d.isDirectory())
|
|
55
|
+
.map((d) => d.name);
|
|
56
|
+
for (const typeDir of typeDirs) {
|
|
57
|
+
const typePath = join(artifactsDir, typeDir);
|
|
58
|
+
const files = readdirSync(typePath).filter((f) => f.endsWith('.meta.yaml'));
|
|
59
|
+
for (const metaFile of files) {
|
|
60
|
+
const metaPath = join(typePath, metaFile);
|
|
61
|
+
try {
|
|
62
|
+
const metaRef = {
|
|
63
|
+
type: typeDir,
|
|
64
|
+
name: '',
|
|
65
|
+
version: 0,
|
|
66
|
+
checksum: '',
|
|
67
|
+
};
|
|
68
|
+
const raw = readContent(metaPath, metaRef);
|
|
69
|
+
const meta = parse(raw);
|
|
70
|
+
const summary = {
|
|
71
|
+
ref: {
|
|
72
|
+
type: meta.type,
|
|
73
|
+
name: meta.name,
|
|
74
|
+
version: meta.version,
|
|
75
|
+
checksum: meta.checksum,
|
|
76
|
+
},
|
|
77
|
+
type: meta.type,
|
|
78
|
+
name: meta.name,
|
|
79
|
+
version: meta.version,
|
|
80
|
+
producedBy: meta.producedBy,
|
|
81
|
+
createdAt: meta.createdAt,
|
|
82
|
+
sizeBytes: meta.sizeBytes,
|
|
83
|
+
};
|
|
84
|
+
this.artifacts.push(summary);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
throw new InventoryCorruptionError(`Failed to parse metadata file: ${metaPath}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
await this.persist();
|
|
92
|
+
return this.getInventory();
|
|
93
|
+
}
|
|
94
|
+
loadFromDisk() {
|
|
95
|
+
if (!fileExists(this.inventoryPath)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const inventoryRef = {
|
|
100
|
+
type: 'run_manifest',
|
|
101
|
+
name: 'inventory',
|
|
102
|
+
version: 0,
|
|
103
|
+
checksum: '',
|
|
104
|
+
};
|
|
105
|
+
const content = readContent(this.inventoryPath, inventoryRef);
|
|
106
|
+
const data = parse(content);
|
|
107
|
+
if (Array.isArray(data.artifacts)) {
|
|
108
|
+
this.artifacts = data.artifacts.map((raw) => {
|
|
109
|
+
const r = raw;
|
|
110
|
+
const ref = r.ref ?? {
|
|
111
|
+
type: raw.type,
|
|
112
|
+
name: raw.name,
|
|
113
|
+
version: raw.version,
|
|
114
|
+
checksum: typeof r.checksum === 'string' ? r.checksum : '',
|
|
115
|
+
};
|
|
116
|
+
return { ...raw, ref };
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
this.artifacts = [];
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
async persist() {
|
|
125
|
+
const data = {
|
|
126
|
+
runId: this.runId,
|
|
127
|
+
updatedAt: new Date().toISOString(),
|
|
128
|
+
totalCount: this.artifacts.length,
|
|
129
|
+
totalSizeBytes: this.artifacts.reduce((sum, a) => sum + a.sizeBytes, 0),
|
|
130
|
+
artifacts: this.artifacts.map((a) => ({
|
|
131
|
+
ref: a.ref,
|
|
132
|
+
type: a.type,
|
|
133
|
+
name: a.name,
|
|
134
|
+
version: a.version,
|
|
135
|
+
producedBy: a.producedBy,
|
|
136
|
+
createdAt: a.createdAt,
|
|
137
|
+
sizeBytes: a.sizeBytes,
|
|
138
|
+
})),
|
|
139
|
+
};
|
|
140
|
+
await atomicWrite(this.inventoryPath, stringify(data));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ArtifactType } from '@ai-dev-orchestrator/schemas';
|
|
2
|
+
/** Manages monotonically increasing version numbers for artifacts. */
|
|
3
|
+
export declare class VersionManager {
|
|
4
|
+
private readonly artifactsDir;
|
|
5
|
+
constructor(artifactsDir: string);
|
|
6
|
+
/** Get the next version number for an artifact name. Scans disk for existing versions. */
|
|
7
|
+
nextVersion(type: ArtifactType, name: string): number;
|
|
8
|
+
/** Get the highest version number for an artifact name. Returns null if none exist. */
|
|
9
|
+
latestVersion(type: ArtifactType, name: string): number | null;
|
|
10
|
+
/** List all version numbers for an artifact name, sorted ascending. */
|
|
11
|
+
listVersions(type: ArtifactType, name: string): number[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const VERSION_PATTERN = /_v(\d+)\.\w+$/;
|
|
4
|
+
/** Manages monotonically increasing version numbers for artifacts. */
|
|
5
|
+
export class VersionManager {
|
|
6
|
+
artifactsDir;
|
|
7
|
+
constructor(artifactsDir) {
|
|
8
|
+
this.artifactsDir = artifactsDir;
|
|
9
|
+
}
|
|
10
|
+
/** Get the next version number for an artifact name. Scans disk for existing versions. */
|
|
11
|
+
nextVersion(type, name) {
|
|
12
|
+
const latest = this.latestVersion(type, name);
|
|
13
|
+
return latest === null ? 1 : latest + 1;
|
|
14
|
+
}
|
|
15
|
+
/** Get the highest version number for an artifact name. Returns null if none exist. */
|
|
16
|
+
latestVersion(type, name) {
|
|
17
|
+
const versions = this.listVersions(type, name);
|
|
18
|
+
return versions.length === 0 ? null : (versions[versions.length - 1] ?? null);
|
|
19
|
+
}
|
|
20
|
+
/** List all version numbers for an artifact name, sorted ascending. */
|
|
21
|
+
listVersions(type, name) {
|
|
22
|
+
const typeDir = join(this.artifactsDir, type);
|
|
23
|
+
if (!existsSync(typeDir)) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const files = readdirSync(typeDir);
|
|
27
|
+
const versions = [];
|
|
28
|
+
for (const file of files) {
|
|
29
|
+
if (!file.startsWith(`${name}_v`)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (file.endsWith('.meta.yaml')) {
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
const match = VERSION_PATTERN.exec(file);
|
|
36
|
+
if (match?.[1]) {
|
|
37
|
+
versions.push(Number(match[1]));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return versions.sort((a, b) => a - b);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
const ALGORITHM = 'sha256';
|
|
3
|
+
const PREFIX = `${ALGORITHM}:`;
|
|
4
|
+
/** Compute a SHA-256 hex digest of the given data, returned as `sha256:<hex>`. */
|
|
5
|
+
export function hashContent(data) {
|
|
6
|
+
const hash = createHash(ALGORITHM)
|
|
7
|
+
.update(typeof data === 'string' ? Buffer.from(data, 'utf8') : data)
|
|
8
|
+
.digest('hex');
|
|
9
|
+
return `${PREFIX}${hash}`;
|
|
10
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ai-dev-orchestrator/artifacts",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/caponetto/ai-dev-orchestrator.git",
|
|
8
|
+
"directory": "packages/artifacts"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22"
|
|
13
|
+
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"write-file-atomic": "^8.0.0",
|
|
25
|
+
"yaml": "^2.9.0",
|
|
26
|
+
"zod": "^4.5.4",
|
|
27
|
+
"@ai-dev-orchestrator/ports": "0.1.1",
|
|
28
|
+
"@ai-dev-orchestrator/schemas": "0.1.1",
|
|
29
|
+
"@ai-dev-orchestrator/utils": "0.1.1"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^26.4.0",
|
|
33
|
+
"@types/write-file-atomic": "^4.0.3",
|
|
34
|
+
"fast-check": "^4.9.0",
|
|
35
|
+
"vitest": "^4.1.11",
|
|
36
|
+
"@ai-dev-orchestrator/build-config": "0.1.1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
|
|
40
|
+
"build:base": "rimraf dist tsconfig.build.tsbuildinfo && tsc -p tsconfig.build.json",
|
|
41
|
+
"build:dev": "pnpm run build:base",
|
|
42
|
+
"build:prod": "pnpm run clean && tsc -p tsconfig.build.json --sourceMap false --declarationMap false",
|
|
43
|
+
"lint": "eslint src/",
|
|
44
|
+
"test:unit": "vitest run",
|
|
45
|
+
"typecheck": "tsc -p tsconfig.build.json --noEmit"
|
|
46
|
+
}
|
|
47
|
+
}
|