@sentropic/artifacts 0.2.18 → 0.2.21
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/CHANGELOG.md +35 -0
- package/README.md +14 -0
- package/dist/adapters/postgres-git-bindings.js +25 -4
- package/dist/http.d.ts +3 -0
- package/dist/http.js +12 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/live-host/accept.d.ts +30 -0
- package/dist/live-host/accept.js +43 -0
- package/dist/live-host/api.d.ts +67 -0
- package/dist/live-host/api.js +60 -0
- package/dist/live-host/candidate.d.ts +21 -0
- package/dist/live-host/candidate.js +41 -0
- package/dist/live-host/errors.d.ts +9 -0
- package/dist/live-host/errors.js +14 -0
- package/dist/live-host/handoff.d.ts +63 -0
- package/dist/live-host/handoff.js +66 -0
- package/dist/live-host/index.d.ts +10 -0
- package/dist/live-host/index.js +10 -0
- package/dist/live-host/keys.d.ts +14 -0
- package/dist/live-host/keys.js +8 -0
- package/dist/live-host/live-format.d.ts +70 -0
- package/dist/live-host/live-format.js +100 -0
- package/dist/live-host/recheck.d.ts +59 -0
- package/dist/live-host/recheck.js +45 -0
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +4 -1
- package/dist/server/build-contract.d.ts +15 -1
- package/dist/server/build-contract.js +14 -5
- package/dist/server/build-dependencies.d.ts +12 -1
- package/dist/server/build-dependencies.js +41 -13
- package/dist/server/build-integrity.d.ts +48 -0
- package/dist/server/build-integrity.js +70 -0
- package/dist/server/build-output.d.ts +22 -0
- package/dist/server/build-output.js +40 -0
- package/dist/server/build-receipt.d.ts +51 -0
- package/dist/server/build-receipt.js +76 -0
- package/dist/server/failures.d.ts +2 -2
- package/dist/server/failures.js +1 -1
- package/dist/server/git-bindings.d.ts +3 -1
- package/dist/server/git-bindings.js +26 -1
- package/dist/server/git-contracts.d.ts +18 -1
- package/dist/server/git-tools-attach.d.ts +8 -0
- package/dist/server/git-tools-attach.js +139 -0
- package/dist/server/git-tools-contracts.d.ts +59 -0
- package/dist/server/git-tools-contracts.js +1 -0
- package/dist/server/git-tools-fetch.d.ts +21 -0
- package/dist/server/git-tools-fetch.js +65 -0
- package/dist/server/git-tools-publish.d.ts +13 -0
- package/dist/server/git-tools-publish.js +66 -0
- package/dist/server/git-tools.d.ts +4 -0
- package/dist/server/git-tools.js +18 -0
- package/dist/server/live-mutations.d.ts +1 -1
- package/dist/server/live-mutations.js +3 -2
- package/dist/server/live-read.d.ts +1 -1
- package/dist/server/live-read.js +2 -1
- package/dist/server/live-store.d.ts +2 -1
- package/dist/server/live-store.js +2 -0
- package/dist/server/templates.js +26 -1
- package/migrations/0012_git_attach_intents.sql +19 -0
- package/package.json +5 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ArtifactOperationError } from './failures.js';
|
|
3
|
+
export const sha256Hex = (text) => createHash('sha256').update(text, 'utf8').digest('hex');
|
|
4
|
+
/** SHA-256 of the exact lockfile text read at the pinned commit. */
|
|
5
|
+
export const lockfileSha256 = (lockText) => sha256Hex(lockText);
|
|
6
|
+
const SRI_BYTES = { sha256: 32, sha384: 48, sha512: 64 };
|
|
7
|
+
/** npm SRI carrying at least one SHA-256-or-stronger digest; SHA-1-only or malformed values never qualify. */
|
|
8
|
+
export function approvedIntegrity(value) {
|
|
9
|
+
if (typeof value !== 'string' || value.length > 1024)
|
|
10
|
+
return false;
|
|
11
|
+
let strong = false;
|
|
12
|
+
for (const token of value.split(' ')) {
|
|
13
|
+
const match = /^(sha1|sha256|sha384|sha512)-([A-Za-z0-9+/]+={0,2})$/.exec(token);
|
|
14
|
+
if (!match)
|
|
15
|
+
return false;
|
|
16
|
+
const bytes = SRI_BYTES[match[1]];
|
|
17
|
+
if (bytes === undefined)
|
|
18
|
+
continue;
|
|
19
|
+
if (match[2].length !== Math.ceil(bytes / 3) * 4 || Buffer.from(match[2], 'base64').length !== bytes)
|
|
20
|
+
return false;
|
|
21
|
+
strong = true;
|
|
22
|
+
}
|
|
23
|
+
return strong;
|
|
24
|
+
}
|
|
25
|
+
/** Canonical map digest: entries ordered by path, fixed field order. */
|
|
26
|
+
export function hostIntegrityMapDigest(map) {
|
|
27
|
+
const rows = map.entries.map(entry => [entry.path, entry.name, entry.version, entry.registryUrl, entry.integrity]);
|
|
28
|
+
rows.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
29
|
+
return sha256Hex(JSON.stringify(['sentropic.integrity-map/v1', map.lockfileDigest, rows]));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Cover every remote lock entry by literal lockfile SRI or the sealed host map, before any fetch.
|
|
33
|
+
* No trust on first use, no reuse across versions or paths, no SHA-1-only pin, no contradicting value.
|
|
34
|
+
*/
|
|
35
|
+
export function dependencyIntegrity(remote, lockfileDigest, map, approvedRegistryUrl) {
|
|
36
|
+
const mismatch = () => { throw new ArtifactOperationError('dependency_integrity_mismatch'); };
|
|
37
|
+
const mapped = new Map();
|
|
38
|
+
if (map !== undefined) {
|
|
39
|
+
if (map?.lockfileDigest !== lockfileDigest || !Array.isArray(map.entries))
|
|
40
|
+
mismatch();
|
|
41
|
+
const locked = new Map(remote.map(entry => [entry.path, entry]));
|
|
42
|
+
for (const entry of map.entries) {
|
|
43
|
+
const lock = locked.get(entry?.path);
|
|
44
|
+
if (lock === undefined || mapped.has(entry.path) || entry.name !== lock.name || entry.version !== lock.version
|
|
45
|
+
|| !approvedRegistryUrl(entry.registryUrl) || !approvedIntegrity(entry.integrity)
|
|
46
|
+
|| (lock.resolved !== undefined && lock.resolved !== entry.registryUrl)
|
|
47
|
+
|| (approvedIntegrity(lock.integrity) && lock.integrity !== entry.integrity))
|
|
48
|
+
mismatch();
|
|
49
|
+
mapped.set(entry.path, entry);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const entries = remote.map((lock) => {
|
|
53
|
+
const host = mapped.get(lock.path);
|
|
54
|
+
const literal = approvedIntegrity(lock.integrity) ? lock.integrity : undefined;
|
|
55
|
+
if (literal === undefined && host === undefined)
|
|
56
|
+
throw new ArtifactOperationError('dependency_integrity_missing');
|
|
57
|
+
const registryUrl = lock.resolved ?? host?.registryUrl;
|
|
58
|
+
// A literal pin without a locked URL names no approved registry location.
|
|
59
|
+
if (registryUrl === undefined)
|
|
60
|
+
throw new ArtifactOperationError('dep_outside_lock');
|
|
61
|
+
const base = { path: lock.path, name: lock.name, version: lock.version, registryUrl };
|
|
62
|
+
return literal !== undefined ? { ...base, integrity: literal, source: 'lockfile' }
|
|
63
|
+
: { ...base, integrity: host.integrity, source: 'host_map' };
|
|
64
|
+
});
|
|
65
|
+
const lockfileSri = entries.filter(entry => entry.source === 'lockfile').length;
|
|
66
|
+
return {
|
|
67
|
+
mapDigest: map === undefined ? null : hostIntegrityMapDigest(map),
|
|
68
|
+
lockfileSri, hostMap: entries.length - lockfileSri, entries,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type PublicationLimits } from './publication-limits.js';
|
|
2
|
+
/** One entry of the stable output snapshot, relative to the descriptor outputDir; directories are implicit. */
|
|
3
|
+
export interface BuildOutputEntry {
|
|
4
|
+
readonly path: string;
|
|
5
|
+
readonly kind: 'file' | 'symlink' | 'other';
|
|
6
|
+
readonly bytes: number;
|
|
7
|
+
}
|
|
8
|
+
export interface AdmittedOutputFile {
|
|
9
|
+
readonly path: string;
|
|
10
|
+
readonly bytes: number;
|
|
11
|
+
readonly mimeType: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A-LIVE §8.3 / G0 §4.1 pre-flight on the supervisor's inventory, after build processes ended and before
|
|
15
|
+
* hashing or upload: regular files only, canonical unique paths, a mapped MIME type, the descriptor entry
|
|
16
|
+
* present, and the stricter of profile and server ceilings (255 files, 16 MiB per file, 64 MiB in total).
|
|
17
|
+
* Structural faults are verification_failed; ceiling overflow is dist_over_limits; nothing is uploaded.
|
|
18
|
+
*/
|
|
19
|
+
export declare function validateBuildOutput(entries: readonly BuildOutputEntry[], options?: {
|
|
20
|
+
entry?: string;
|
|
21
|
+
limits?: Partial<PublicationLimits>;
|
|
22
|
+
}): readonly AdmittedOutputFile[];
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ArtifactOperationError } from './failures.js';
|
|
2
|
+
import { isWithinMimeCeiling, mimeTypeForPath } from './mime.js';
|
|
3
|
+
import { publicationLimits } from './publication-limits.js';
|
|
4
|
+
const outputPath = (value) => typeof value === 'string' && Buffer.byteLength(value) <= 1024
|
|
5
|
+
&& !/[\\%?#:\u0000-\u001f\u007f]/.test(value) && value.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
6
|
+
/**
|
|
7
|
+
* A-LIVE §8.3 / G0 §4.1 pre-flight on the supervisor's inventory, after build processes ended and before
|
|
8
|
+
* hashing or upload: regular files only, canonical unique paths, a mapped MIME type, the descriptor entry
|
|
9
|
+
* present, and the stricter of profile and server ceilings (255 files, 16 MiB per file, 64 MiB in total).
|
|
10
|
+
* Structural faults are verification_failed; ceiling overflow is dist_over_limits; nothing is uploaded.
|
|
11
|
+
*/
|
|
12
|
+
export function validateBuildOutput(entries, options = {}) {
|
|
13
|
+
const limits = publicationLimits(options.limits);
|
|
14
|
+
const invalid = () => { throw new ArtifactOperationError('verification_failed'); };
|
|
15
|
+
const over = () => { throw new ArtifactOperationError('dist_over_limits'); };
|
|
16
|
+
if (!Array.isArray(entries) || entries.length === 0)
|
|
17
|
+
invalid();
|
|
18
|
+
if (entries.length > limits.maxFiles)
|
|
19
|
+
over();
|
|
20
|
+
const seen = new Set();
|
|
21
|
+
let total = 0;
|
|
22
|
+
const files = entries.map((entry) => {
|
|
23
|
+
if (entry?.kind !== 'file' || !outputPath(entry.path) || seen.has(entry.path)
|
|
24
|
+
|| !Number.isSafeInteger(entry.bytes) || entry.bytes < 0)
|
|
25
|
+
invalid();
|
|
26
|
+
seen.add(entry.path);
|
|
27
|
+
const mimeType = mimeTypeForPath(entry.path);
|
|
28
|
+
if (mimeType === undefined || !isWithinMimeCeiling(mimeType))
|
|
29
|
+
return invalid();
|
|
30
|
+
if (entry.bytes > limits.maxFileBytes)
|
|
31
|
+
over();
|
|
32
|
+
total += entry.bytes;
|
|
33
|
+
if (total > limits.maxTotalBytes)
|
|
34
|
+
over();
|
|
35
|
+
return { path: entry.path, bytes: entry.bytes, mimeType };
|
|
36
|
+
});
|
|
37
|
+
if (options.entry !== undefined && !seen.has(options.entry))
|
|
38
|
+
invalid();
|
|
39
|
+
return files.sort((a, b) => (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
40
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** One candidate output file as hashed by the trusted supervisor from the stable output snapshot. */
|
|
2
|
+
export interface CandidateFileDigest {
|
|
3
|
+
readonly path: string;
|
|
4
|
+
readonly bytes: number;
|
|
5
|
+
readonly sha256: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A-LIVE §8.4 builder-attested evidence, sealed outside repository code. Every field is mandatory;
|
|
9
|
+
* unknown fields are additive and ignored. releaseId/manifestDigest stay null until publication.
|
|
10
|
+
*/
|
|
11
|
+
export interface BuilderAttestedEvidence {
|
|
12
|
+
readonly storageScopeId: string;
|
|
13
|
+
readonly artifactId: string;
|
|
14
|
+
readonly bindingGeneration: number;
|
|
15
|
+
readonly jobId: string;
|
|
16
|
+
readonly runId: string;
|
|
17
|
+
readonly attempt: number;
|
|
18
|
+
readonly commitSha: string;
|
|
19
|
+
readonly treeSha: string;
|
|
20
|
+
readonly descriptorDigest: string;
|
|
21
|
+
readonly lockfileDigest: string;
|
|
22
|
+
/** Digest of the integrity-map/cache receipt that admitted the dependency closure. */
|
|
23
|
+
readonly integrityReceiptDigest: string;
|
|
24
|
+
readonly builderImageDigest: string;
|
|
25
|
+
readonly platform: string;
|
|
26
|
+
readonly nodeVersion: string;
|
|
27
|
+
readonly npmVersion: string;
|
|
28
|
+
readonly publicEnvHashes: Readonly<Record<string, string>>;
|
|
29
|
+
readonly stagingPolicy: string;
|
|
30
|
+
readonly stagingDigest: string;
|
|
31
|
+
readonly candidateDigest: string;
|
|
32
|
+
readonly candidateFiles: readonly CandidateFileDigest[];
|
|
33
|
+
readonly releaseId: string | null;
|
|
34
|
+
readonly manifestDigest: string | null;
|
|
35
|
+
}
|
|
36
|
+
/** Server-resolved job, sealed handoff and admitted inputs the evidence must join exactly. */
|
|
37
|
+
export type BuilderReceiptExpectation = Pick<BuilderAttestedEvidence, typeof JOINS[number][0]>;
|
|
38
|
+
/** Closed `git_build_job_mismatch` reasons; no foreign job, scope or digest value is disclosed. */
|
|
39
|
+
export type BuilderReceiptMismatch = 'scope' | 'job' | 'source' | 'inputs' | 'candidate';
|
|
40
|
+
declare const JOINS: readonly [readonly ["storageScopeId", "scope"], readonly ["artifactId", "scope"], readonly ["bindingGeneration", "scope"], readonly ["jobId", "job"], readonly ["runId", "job"], readonly ["attempt", "job"], readonly ["commitSha", "source"], readonly ["treeSha", "source"], readonly ["descriptorDigest", "inputs"], readonly ["lockfileDigest", "inputs"], readonly ["integrityReceiptDigest", "inputs"], readonly ["builderImageDigest", "inputs"], readonly ["platform", "inputs"], readonly ["publicEnvHashes", "inputs"], readonly ["stagingPolicy", "inputs"], readonly ["stagingDigest", "inputs"], readonly ["candidateDigest", "candidate"]];
|
|
41
|
+
/** Canonical candidate manifest digest over every file (path, size, SHA-256); file order is irrelevant. */
|
|
42
|
+
export declare function candidateInventoryDigest(files: readonly CandidateFileDigest[]): string;
|
|
43
|
+
/**
|
|
44
|
+
* Pure verdict (BR-82 pattern, G0 §4.3): mandatory schema, candidate digest recomputed from the complete
|
|
45
|
+
* file inventory, then the exact join against server evidence. Authentication, single use and expiry of
|
|
46
|
+
* the supervisor handoff belong to the SG4b handoff, not to this function.
|
|
47
|
+
*/
|
|
48
|
+
export declare function verifyBuilderReceipt(evidence: unknown, expected: BuilderReceiptExpectation): BuilderAttestedEvidence;
|
|
49
|
+
/** Anti-repack: the re-read uploaded bytes must hash to the sealed candidate digest. */
|
|
50
|
+
export declare function verifyServedCandidate(evidence: BuilderAttestedEvidence, served: readonly CandidateFileDigest[]): void;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { sha256Hex } from './build-integrity.js';
|
|
2
|
+
import { ArtifactOperationError } from './failures.js';
|
|
3
|
+
import { isGitSha } from './git-port-policy.js';
|
|
4
|
+
import { SERVER_MAX_FILES_PER_RELEASE, SERVER_MAX_FILE_BYTES } from './publication-limits.js';
|
|
5
|
+
const JOINS = [
|
|
6
|
+
['storageScopeId', 'scope'], ['artifactId', 'scope'], ['bindingGeneration', 'scope'],
|
|
7
|
+
['jobId', 'job'], ['runId', 'job'], ['attempt', 'job'], ['commitSha', 'source'], ['treeSha', 'source'],
|
|
8
|
+
['descriptorDigest', 'inputs'], ['lockfileDigest', 'inputs'], ['integrityReceiptDigest', 'inputs'],
|
|
9
|
+
['builderImageDigest', 'inputs'], ['platform', 'inputs'], ['publicEnvHashes', 'inputs'],
|
|
10
|
+
['stagingPolicy', 'inputs'], ['stagingDigest', 'inputs'], ['candidateDigest', 'candidate'],
|
|
11
|
+
];
|
|
12
|
+
const HEX = /^[a-f0-9]{64}$/;
|
|
13
|
+
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
14
|
+
const VERSION = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
15
|
+
const id = (value) => typeof value === 'string' && value.length > 0 && value.length <= 256
|
|
16
|
+
&& value.trim() === value && !/[\u0000-\u001f\u007f]/.test(value);
|
|
17
|
+
const count = (value, min) => Number.isSafeInteger(value) && value >= min;
|
|
18
|
+
const record = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
19
|
+
const path = (value) => typeof value === 'string' && Buffer.byteLength(value) <= 1024
|
|
20
|
+
&& !/[\\%?#:\u0000-\u001f\u007f]/.test(value) && value.split('/').every(part => part !== '' && part !== '.' && part !== '..');
|
|
21
|
+
const canonicalEnv = (hashes) => JSON.stringify(Object.entries(hashes).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)));
|
|
22
|
+
/** Canonical candidate manifest digest over every file (path, size, SHA-256); file order is irrelevant. */
|
|
23
|
+
export function candidateInventoryDigest(files) {
|
|
24
|
+
const rows = files.map(file => [file.path, file.bytes, file.sha256]);
|
|
25
|
+
rows.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0));
|
|
26
|
+
return sha256Hex(JSON.stringify(['sentropic.build-candidate/v1', rows]));
|
|
27
|
+
}
|
|
28
|
+
function schema(value) {
|
|
29
|
+
if (!record(value))
|
|
30
|
+
return false;
|
|
31
|
+
const files = value.candidateFiles;
|
|
32
|
+
const env = value.publicEnvHashes;
|
|
33
|
+
return id(value.storageScopeId) && typeof value.artifactId === 'string' && UUID.test(value.artifactId)
|
|
34
|
+
&& count(value.bindingGeneration, 1) && id(value.jobId) && id(value.runId) && count(value.attempt, 1)
|
|
35
|
+
&& typeof value.commitSha === 'string' && isGitSha(value.commitSha)
|
|
36
|
+
&& typeof value.treeSha === 'string' && isGitSha(value.treeSha)
|
|
37
|
+
&& [value.descriptorDigest, value.lockfileDigest, value.integrityReceiptDigest, value.stagingDigest,
|
|
38
|
+
value.candidateDigest].every(digest => typeof digest === 'string' && HEX.test(digest))
|
|
39
|
+
&& typeof value.builderImageDigest === 'string' && /^sha256:[a-f0-9]{64}$/.test(value.builderImageDigest)
|
|
40
|
+
&& typeof value.platform === 'string' && /^[a-z0-9]+\/[a-z0-9_]+(?:\/[a-z0-9]+)?$/.test(value.platform)
|
|
41
|
+
&& typeof value.nodeVersion === 'string' && VERSION.test(value.nodeVersion)
|
|
42
|
+
&& typeof value.npmVersion === 'string' && VERSION.test(value.npmVersion)
|
|
43
|
+
&& record(env) && Object.entries(env).every(([name, hash]) => /^[A-Za-z_][A-Za-z0-9_]*$/.test(name)
|
|
44
|
+
&& typeof hash === 'string' && HEX.test(hash))
|
|
45
|
+
&& id(value.stagingPolicy)
|
|
46
|
+
&& (value.releaseId === null || (typeof value.releaseId === 'string' && UUID.test(value.releaseId)))
|
|
47
|
+
&& (value.manifestDigest === null || (typeof value.manifestDigest === 'string' && HEX.test(value.manifestDigest)))
|
|
48
|
+
&& Array.isArray(files) && files.length > 0 && files.length <= SERVER_MAX_FILES_PER_RELEASE
|
|
49
|
+
&& new Set(files.map(file => file?.path)).size === files.length
|
|
50
|
+
&& files.every(file => record(file) && path(file.path) && count(file.bytes, 0)
|
|
51
|
+
&& file.bytes <= SERVER_MAX_FILE_BYTES && typeof file.sha256 === 'string' && HEX.test(file.sha256));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Pure verdict (BR-82 pattern, G0 §4.3): mandatory schema, candidate digest recomputed from the complete
|
|
55
|
+
* file inventory, then the exact join against server evidence. Authentication, single use and expiry of
|
|
56
|
+
* the supervisor handoff belong to the SG4b handoff, not to this function.
|
|
57
|
+
*/
|
|
58
|
+
export function verifyBuilderReceipt(evidence, expected) {
|
|
59
|
+
if (!schema(evidence) || candidateInventoryDigest(evidence.candidateFiles) !== evidence.candidateDigest) {
|
|
60
|
+
throw new ArtifactOperationError('verification_failed');
|
|
61
|
+
}
|
|
62
|
+
for (const [key, reason] of JOINS) {
|
|
63
|
+
const same = key === 'publicEnvHashes'
|
|
64
|
+
? record(expected.publicEnvHashes) && canonicalEnv(evidence.publicEnvHashes) === canonicalEnv(expected.publicEnvHashes)
|
|
65
|
+
: evidence[key] === expected[key];
|
|
66
|
+
if (!same)
|
|
67
|
+
throw new ArtifactOperationError('git_build_job_mismatch', { publicDetails: { reason } });
|
|
68
|
+
}
|
|
69
|
+
return Object.freeze({ ...evidence });
|
|
70
|
+
}
|
|
71
|
+
/** Anti-repack: the re-read uploaded bytes must hash to the sealed candidate digest. */
|
|
72
|
+
export function verifyServedCandidate(evidence, served) {
|
|
73
|
+
if (!Array.isArray(served) || candidateInventoryDigest(served) !== evidence.candidateDigest) {
|
|
74
|
+
throw new ArtifactOperationError('verification_failed');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -5,7 +5,7 @@ export type ArtifactCommitState = 'not_committed' | 'committed' | 'unknown';
|
|
|
5
5
|
export type ArtifactInternalKey = string & {
|
|
6
6
|
readonly __brand: 'internal-key';
|
|
7
7
|
};
|
|
8
|
-
export type ArtifactErrorKind = LiveErrorCode | 'provider_unavailable' | 'command_conflict' | 'pointer_conflict' | 'unauthorized_at_commit' | 'capability_unselected' | 'admission_unavailable' | 'invalid_request' | 'anonymous' | 'access_denied' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'git_binding_conflict' | 'git_repo_not_registered' | 'git_ref_not_allowed' | 'git_head_moved' | 'git_path_refused' | 'git_branch_missing' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted';
|
|
8
|
+
export type ArtifactErrorKind = LiveErrorCode | 'provider_unavailable' | 'command_conflict' | 'pointer_conflict' | 'unauthorized_at_commit' | 'capability_unselected' | 'admission_unavailable' | 'invalid_request' | 'anonymous' | 'access_denied' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'git_binding_conflict' | 'git_repo_not_registered' | 'git_ref_not_allowed' | 'git_head_moved' | 'git_path_refused' | 'git_branch_missing' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted' | 'dist_over_limits';
|
|
9
9
|
/** Optimistic-concurrency payload: the caller re-reads and merges against this. */
|
|
10
10
|
export interface ArtifactConflictDetails {
|
|
11
11
|
readonly artifactId?: string;
|
|
@@ -49,7 +49,7 @@ export interface ArtifactOperationalFailure extends ArtifactFailureFields {
|
|
|
49
49
|
}
|
|
50
50
|
export interface ArtifactOrdinaryFailure extends Omit<ArtifactFailureFields, 'variant' | 'retriable'> {
|
|
51
51
|
readonly kind: 'ordinary';
|
|
52
|
-
readonly category: 'invalid_request' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | LiveErrorCode | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted' | 'git_path_refused' | 'git_branch_missing' | 'git_ref_not_allowed' | 'git_repo_not_registered';
|
|
52
|
+
readonly category: 'invalid_request' | 'not_found' | 'gone' | 'release_unavailable' | 'limit_exceeded' | LiveErrorCode | 'unprocessable' | 'verification_failed' | 'edit_mismatch' | 'precondition_required' | 'build_descriptor_invalid' | 'build_script_missing' | 'lock_missing' | 'dep_outside_lock' | 'install_script_not_allowlisted' | 'dist_over_limits' | 'git_path_refused' | 'git_branch_missing' | 'git_ref_not_allowed' | 'git_repo_not_registered';
|
|
53
53
|
readonly retriable: false;
|
|
54
54
|
}
|
|
55
55
|
/** Entry authority outcomes are separate from ordinary and operational failures. */
|
package/dist/server/failures.js
CHANGED
|
@@ -32,7 +32,7 @@ const DOMAIN_STATUS = {
|
|
|
32
32
|
not_found: 404, gone: 410, release_unavailable: 410, limit_exceeded: 413, unprocessable: 422, verification_failed: 422, edit_mismatch: 422,
|
|
33
33
|
precondition_required: 428,
|
|
34
34
|
build_descriptor_invalid: 422, build_script_missing: 422, lock_missing: 422,
|
|
35
|
-
dep_outside_lock: 422, install_script_not_allowlisted: 422,
|
|
35
|
+
dep_outside_lock: 422, install_script_not_allowlisted: 422, dist_over_limits: 422,
|
|
36
36
|
git_path_refused: 422, git_branch_missing: 422, git_ref_not_allowed: 422, git_repo_not_registered: 422,
|
|
37
37
|
};
|
|
38
38
|
function field(value, name) {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { GitBinding, GitBindingEvent, GitBindingStore, GitBindingWrite } from './git-contracts.js';
|
|
1
|
+
import type { GitAttachIntent, GitBinding, GitBindingEvent, GitBindingStore, GitBindingWrite } from './git-contracts.js';
|
|
2
2
|
export type * from './git-contracts.js';
|
|
3
3
|
export declare function gitBindingReceiptKey(input: GitBindingWrite): string;
|
|
4
4
|
/** Shared invariants run inside the adapter transaction, after receipt replay and before mutation. */
|
|
5
5
|
export declare function validateGitBindingWrite(before: GitBinding | undefined, input: GitBindingWrite): void;
|
|
6
6
|
export declare function gitBindingEvent(input: GitBindingWrite): GitBindingEvent;
|
|
7
|
+
/** Shared attach-intent admission for every adapter, before the put-if-absent. */
|
|
8
|
+
export declare function validateGitAttachIntent(intent: GitAttachIntent): void;
|
|
7
9
|
/** Atomic single-process fake tenant. Outputs never expose mutable internal records. */
|
|
8
10
|
export declare function createMemoryGitBindingStore(): GitBindingStore;
|
|
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
2
2
|
import { ArtifactOperationError } from './failures.js';
|
|
3
3
|
import { createKeyMutex } from './ports.js';
|
|
4
4
|
import { isAllowedGitBranch } from './git-registry.js';
|
|
5
|
+
import { isGitSha } from './git-port-policy.js';
|
|
5
6
|
export function gitBindingReceiptKey(input) {
|
|
6
7
|
return 'git-binding:' + createHash('sha256').update(JSON.stringify([
|
|
7
8
|
input.binding.storageScopeId, input.actorId, input.idempotencyKey,
|
|
@@ -34,6 +35,9 @@ export function validateGitBindingWrite(before, input) {
|
|
|
34
35
|
const action = input.event.action;
|
|
35
36
|
const active = before !== undefined && before.state !== 'detached';
|
|
36
37
|
const configuring = action === 'attach' && active;
|
|
38
|
+
if (input.event.branchCreated !== undefined && (input.event.branchCreated !== true || action !== 'attach' || active)) {
|
|
39
|
+
throw new ArtifactOperationError('invalid_request');
|
|
40
|
+
}
|
|
37
41
|
const transition = action === 'attach' ? (configuring ? next.state === before.state : next.state === 'attached')
|
|
38
42
|
: action === 'pause' ? active && next.state === 'paused'
|
|
39
43
|
: action === 'resume' ? before?.state === 'paused' && next.state === 'attached' &&
|
|
@@ -71,13 +75,23 @@ export function gitBindingEvent(input) {
|
|
|
71
75
|
return { id: randomUUID(), artifactId: input.binding.artifactId, storageScopeId: input.binding.storageScopeId,
|
|
72
76
|
actorId: input.actorId, action: input.event.action, beforeSha: input.event.beforeSha,
|
|
73
77
|
afterSha: input.event.afterSha, deliveryId: input.event.deliveryId,
|
|
74
|
-
invocationId: input.event.invocationId,
|
|
78
|
+
invocationId: input.event.invocationId, ...(input.event.branchCreated ? { branchCreated: true } : {}),
|
|
79
|
+
createdAt: input.binding.updatedAt };
|
|
75
80
|
}
|
|
81
|
+
/** Shared attach-intent admission for every adapter, before the put-if-absent. */
|
|
82
|
+
export function validateGitAttachIntent(intent) {
|
|
83
|
+
if (!isAllowedGitBranch(intent.branch) || !intent.idempotencyKey.trim() || !intent.commandHash || !intent.actorId ||
|
|
84
|
+
!intent.storageScopeId || !intent.artifactId || !intent.repoId || !isGitSha(intent.baseCommitSha)) {
|
|
85
|
+
throw new ArtifactOperationError('invalid_request');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const intentKey = (scope, actorId, key) => JSON.stringify([scope, actorId, key]);
|
|
76
89
|
/** Atomic single-process fake tenant. Outputs never expose mutable internal records. */
|
|
77
90
|
export function createMemoryGitBindingStore() {
|
|
78
91
|
const rows = new Map();
|
|
79
92
|
const audit = [];
|
|
80
93
|
const receipts = new Map();
|
|
94
|
+
const intents = new Map();
|
|
81
95
|
const mutex = createKeyMutex();
|
|
82
96
|
return {
|
|
83
97
|
async get(scope, id) {
|
|
@@ -87,6 +101,17 @@ export function createMemoryGitBindingStore() {
|
|
|
87
101
|
async events(scope, id) {
|
|
88
102
|
return structuredClone(audit.filter(event => event.storageScopeId === scope && event.artifactId === id));
|
|
89
103
|
},
|
|
104
|
+
async reserveAttachIntent(intent) {
|
|
105
|
+
validateGitAttachIntent(intent);
|
|
106
|
+
const key = intentKey(intent.storageScopeId, intent.actorId, intent.idempotencyKey);
|
|
107
|
+
if (!intents.has(key))
|
|
108
|
+
intents.set(key, structuredClone(intent));
|
|
109
|
+
return structuredClone(intents.get(key));
|
|
110
|
+
},
|
|
111
|
+
async attachIntent(scope, actorId, idempotencyKey) {
|
|
112
|
+
const intent = intents.get(intentKey(scope, actorId, idempotencyKey));
|
|
113
|
+
return intent && structuredClone(intent);
|
|
114
|
+
},
|
|
90
115
|
async write(input) {
|
|
91
116
|
const snapshot = structuredClone(input);
|
|
92
117
|
return mutex.runSerialized('git-bindings', async () => {
|
|
@@ -46,6 +46,8 @@ export interface GitBindingEvent {
|
|
|
46
46
|
afterSha?: string;
|
|
47
47
|
deliveryId?: string;
|
|
48
48
|
invocationId?: string;
|
|
49
|
+
/** A-LIVE §5.3.1: only on the attach event that verified creation of the branch; initialUnpublishedBranchEligible input. */
|
|
50
|
+
branchCreated?: true;
|
|
49
51
|
createdAt: string;
|
|
50
52
|
}
|
|
51
53
|
export interface GitReleaseIndex {
|
|
@@ -72,7 +74,19 @@ export interface GitBindingWrite {
|
|
|
72
74
|
actorId: string;
|
|
73
75
|
idempotencyKey: string;
|
|
74
76
|
commandHash: string;
|
|
75
|
-
event: Pick<GitBindingEvent, 'action' | 'beforeSha' | 'afterSha' | 'deliveryId' | 'invocationId'>;
|
|
77
|
+
event: Pick<GitBindingEvent, 'action' | 'beforeSha' | 'afterSha' | 'deliveryId' | 'invocationId' | 'branchCreated'>;
|
|
78
|
+
}
|
|
79
|
+
/** Written before createBranch, keyed like the replay receipt, so a same-key retry knows the branch is its own. */
|
|
80
|
+
export interface GitAttachIntent {
|
|
81
|
+
storageScopeId: string;
|
|
82
|
+
artifactId: string;
|
|
83
|
+
actorId: string;
|
|
84
|
+
idempotencyKey: string;
|
|
85
|
+
commandHash: string;
|
|
86
|
+
repoId: string;
|
|
87
|
+
branch: string;
|
|
88
|
+
baseCommitSha: string;
|
|
89
|
+
createdAt: string;
|
|
76
90
|
}
|
|
77
91
|
export interface GitBindingStore {
|
|
78
92
|
get(storageScopeId: string, artifactId: string): Promise<GitBinding | undefined>;
|
|
@@ -82,6 +96,9 @@ export interface GitBindingStore {
|
|
|
82
96
|
replayed: boolean;
|
|
83
97
|
}>;
|
|
84
98
|
events(storageScopeId: string, artifactId: string): Promise<GitBindingEvent[]>;
|
|
99
|
+
/** Durable put-if-absent by (scope, actor, key); returns the stored intent, which wins over the input. */
|
|
100
|
+
reserveAttachIntent(intent: GitAttachIntent): Promise<GitAttachIntent>;
|
|
101
|
+
attachIntent(storageScopeId: string, actorId: string, idempotencyKey: string): Promise<GitAttachIntent | undefined>;
|
|
85
102
|
}
|
|
86
103
|
/** SG4 writes the index using its release-transaction client; SG1 provides the record/read port. */
|
|
87
104
|
export interface GitReleaseIndexStore {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { GitBinding } from './git-contracts.js';
|
|
2
|
+
import type { GitToolInvocation, GitToolsDeps } from './git-tools-contracts.js';
|
|
3
|
+
/** G0 v3 §1.2 Tool 3 / A-LIVE S03: attach, configure, pause, resume or detach one binding. */
|
|
4
|
+
export declare function attachGit(deps: GitToolsDeps, args: Record<string, any>, inv: GitToolInvocation): Promise<{
|
|
5
|
+
artifactId: any;
|
|
6
|
+
git: GitBinding;
|
|
7
|
+
replayed: boolean;
|
|
8
|
+
}>;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { orderedDigest } from '../profile/json.js';
|
|
3
|
+
import { ArtifactOperationError } from './failures.js';
|
|
4
|
+
import { validateGitBindingTarget } from './git-registry.js';
|
|
5
|
+
import { requireCodeRight, requireOwner } from './git-tools-publish.js';
|
|
6
|
+
const FIELDS = ['repoId', 'branch', 'baseRef', 'subPath', 'autoPublish', 'executor', 'pause'];
|
|
7
|
+
const id8 = (value) => createHash('sha256').update(value).digest('hex').slice(0, 8);
|
|
8
|
+
const notFound = (error) => error instanceof ArtifactOperationError && error.kind === 'not_found';
|
|
9
|
+
/** G0 v3 §1.2 Tool 3 / A-LIVE S03: attach, configure, pause, resume or detach one binding. */
|
|
10
|
+
export async function attachGit(deps, args, inv) {
|
|
11
|
+
await requireOwner(deps, inv, args.artifactId, true);
|
|
12
|
+
const scope = inv.storageScopeId;
|
|
13
|
+
const before = await deps.bindings.get(scope, args.artifactId);
|
|
14
|
+
const active = before !== undefined && before.state !== 'detached';
|
|
15
|
+
const given = FIELDS.filter(field => args[field] !== undefined);
|
|
16
|
+
const now = (deps.now?.() ?? new Date()).toISOString();
|
|
17
|
+
const hash = orderedDigest({ operation: 'git_attach', args });
|
|
18
|
+
const write = async (binding, action, afterSha, branchCreated = false) => {
|
|
19
|
+
const out = await deps.bindings.write({ binding, expectedVersion: before?.version ?? null, actorId: inv.actorId,
|
|
20
|
+
idempotencyKey: args.idempotencyKey, commandHash: hash,
|
|
21
|
+
event: { action, beforeSha: before?.headCommitSha ?? undefined, afterSha, invocationId: inv.invocationId,
|
|
22
|
+
...(branchCreated ? { branchCreated: true } : {}) } });
|
|
23
|
+
return { artifactId: args.artifactId, git: out.binding, replayed: out.replayed };
|
|
24
|
+
};
|
|
25
|
+
const base = before && { ...before, version: before.version + 1, updatedAt: now };
|
|
26
|
+
if (args.detach !== undefined) {
|
|
27
|
+
if (args.detach !== true || given.length)
|
|
28
|
+
throw new ArtifactOperationError('invalid_request');
|
|
29
|
+
if (!active)
|
|
30
|
+
throw new ArtifactOperationError('git_not_attached');
|
|
31
|
+
await requireCodeRight(deps, inv, before.repoId);
|
|
32
|
+
return write({ ...base, state: 'detached', generation: before.generation + 1,
|
|
33
|
+
pendingJobId: null, pendingCommitSha: null }, 'detach');
|
|
34
|
+
}
|
|
35
|
+
if (args.pause !== undefined) {
|
|
36
|
+
if (given.length !== 1)
|
|
37
|
+
throw new ArtifactOperationError('invalid_request');
|
|
38
|
+
if (!active)
|
|
39
|
+
throw new ArtifactOperationError('git_not_attached');
|
|
40
|
+
await requireCodeRight(deps, inv, before.repoId);
|
|
41
|
+
if (args.pause)
|
|
42
|
+
return write({ ...base, state: 'paused', generation: before.generation + 1,
|
|
43
|
+
pendingJobId: null, pendingCommitSha: null }, 'pause');
|
|
44
|
+
const target = await attachTarget(deps, before, inv);
|
|
45
|
+
await deps.git.resolveRef(target, before.branch).catch(error => {
|
|
46
|
+
throw notFound(error) ? new ArtifactOperationError('git_branch_missing') : error;
|
|
47
|
+
});
|
|
48
|
+
return write({ ...base, state: 'attached' }, 'resume');
|
|
49
|
+
}
|
|
50
|
+
const repoId = active ? before.repoId : args.repoId;
|
|
51
|
+
if (repoId === undefined)
|
|
52
|
+
throw new ArtifactOperationError('invalid_request');
|
|
53
|
+
await requireCodeRight(deps, inv, repoId);
|
|
54
|
+
const executor = args.executor ?? (active ? before.executor : 'caller');
|
|
55
|
+
await admitExecutor(deps, executor);
|
|
56
|
+
if (active) {
|
|
57
|
+
if ((args.repoId ?? before.repoId) !== before.repoId || (args.branch ?? before.branch) !== before.branch ||
|
|
58
|
+
(args.subPath ?? before.subPath) !== before.subPath || executor !== before.executor) {
|
|
59
|
+
throw new ArtifactOperationError('git_binding_conflict', { publicDetails: { artifactId: args.artifactId } });
|
|
60
|
+
}
|
|
61
|
+
const autoPublish = args.autoPublish ?? before.autoPublish;
|
|
62
|
+
if (autoPublish && !before.autoPublish)
|
|
63
|
+
await assertAutoPublish(deps, before.repoId, before.branch, before.channel, inv);
|
|
64
|
+
return write({ ...base, autoPublish }, 'attach', before.headCommitSha ?? undefined);
|
|
65
|
+
}
|
|
66
|
+
const principal = id8(`${scope}\0${inv.actorId}`);
|
|
67
|
+
const branch = args.branch ?? `artifact/p/${principal}/app-${id8(args.artifactId)}`;
|
|
68
|
+
const subPath = args.subPath ?? '';
|
|
69
|
+
const repo = await validateGitBindingTarget(deps.registry, scope, repoId, branch, subPath);
|
|
70
|
+
const personal = branch.startsWith('artifact/p/');
|
|
71
|
+
if (personal && !branch.startsWith(`artifact/p/${principal}/`))
|
|
72
|
+
throw new ArtifactOperationError('git_ref_not_allowed');
|
|
73
|
+
const channel = personal ? 'personal' : 'shared';
|
|
74
|
+
if (args.autoPublish === true)
|
|
75
|
+
await assertAutoPublish(deps, repoId, branch, channel, inv);
|
|
76
|
+
const target = { storageScopeId: scope, repoId, branch, subPath,
|
|
77
|
+
principalId: inv.actorId, outputDir: deps.outputDir ?? 'dist' };
|
|
78
|
+
const { head, created } = await attachHead(deps, target, args, inv, hash, now);
|
|
79
|
+
if (args.autoPublish === true && !created) {
|
|
80
|
+
throw new ArtifactOperationError('git_auto_publish_refused', { publicDetails: { reason: 'initial_pre_existing_branch' } });
|
|
81
|
+
}
|
|
82
|
+
const defaulted = created && channel === 'personal' && repo.publicationPolicy.delegatedPublication === 'personal-only';
|
|
83
|
+
const binding = { artifactId: args.artifactId, storageScopeId: scope, repoId, branch,
|
|
84
|
+
channel, personalPrincipalId: personal ? inv.actorId : null, subPath, baseCommitSha: head, headCommitSha: head,
|
|
85
|
+
releaseCommitSha: before?.releaseCommitSha ?? null, autoPublish: args.autoPublish ?? defaulted, executor,
|
|
86
|
+
pendingJobId: null, pendingCommitSha: null, state: 'attached', generation: before ? before.generation + 1 : 1,
|
|
87
|
+
version: before ? before.version + 1 : 1, attachedBy: inv.actorId, attachedAt: now, updatedAt: now };
|
|
88
|
+
return write(binding, 'attach', head, created);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A-LIVE v2 §5.3.1: « created by this command » is the durable intent written before createBranch, never a forge
|
|
92
|
+
* guess. A same-key retry after a lost binding write keeps the outcome; a moved head or a foreign branch does not.
|
|
93
|
+
*/
|
|
94
|
+
async function attachHead(deps, target, args, inv, hash, now) {
|
|
95
|
+
const current = await deps.git.resolveRef(target, target.branch).catch(error => {
|
|
96
|
+
if (notFound(error))
|
|
97
|
+
return undefined;
|
|
98
|
+
throw error;
|
|
99
|
+
});
|
|
100
|
+
const prior = await deps.bindings.attachIntent(inv.storageScopeId, inv.actorId, args.idempotencyKey);
|
|
101
|
+
if (prior && prior.commandHash !== hash)
|
|
102
|
+
throw new ArtifactOperationError('command_conflict');
|
|
103
|
+
if (current !== undefined)
|
|
104
|
+
return { head: current, created: prior?.baseCommitSha === current };
|
|
105
|
+
if (args.baseRef === undefined)
|
|
106
|
+
throw new ArtifactOperationError('git_branch_missing');
|
|
107
|
+
const intent = prior ?? await deps.bindings.reserveAttachIntent({ storageScopeId: inv.storageScopeId,
|
|
108
|
+
artifactId: args.artifactId, actorId: inv.actorId, idempotencyKey: args.idempotencyKey, commandHash: hash,
|
|
109
|
+
repoId: target.repoId, branch: target.branch, baseCommitSha: await deps.git.resolveRef(target, args.baseRef),
|
|
110
|
+
createdAt: now });
|
|
111
|
+
if (intent.commandHash !== hash)
|
|
112
|
+
throw new ArtifactOperationError('command_conflict');
|
|
113
|
+
await deps.git.createBranch(target, intent.baseCommitSha);
|
|
114
|
+
return { head: intent.baseCommitSha, created: true };
|
|
115
|
+
}
|
|
116
|
+
/** G0 v3 §1.2 / A-LIVE S03: the host build port admits every executor, the omitted caller default included. */
|
|
117
|
+
async function admitExecutor(deps, executor) {
|
|
118
|
+
const open = executor !== 'ci' && (deps.build
|
|
119
|
+
? await deps.build.admits(executor).then(value => value === true, () => false) : executor === 'caller');
|
|
120
|
+
if (!open)
|
|
121
|
+
throw new ArtifactOperationError('builder_unavailable', { publicDetails: { executor,
|
|
122
|
+
reason: executor === 'ci' ? 'executor_retired' : 'executor_unavailable' } });
|
|
123
|
+
}
|
|
124
|
+
async function attachTarget(deps, binding, inv) {
|
|
125
|
+
await validateGitBindingTarget(deps.registry, binding.storageScopeId, binding.repoId, binding.branch, binding.subPath);
|
|
126
|
+
return { storageScopeId: binding.storageScopeId, repoId: binding.repoId, branch: binding.branch,
|
|
127
|
+
subPath: binding.subPath, principalId: inv.actorId, outputDir: deps.outputDir ?? 'dist' };
|
|
128
|
+
}
|
|
129
|
+
/** OD2 (G0 v3 §1.2): delegated publication is host policy, never a caller claim. */
|
|
130
|
+
async function assertAutoPublish(deps, repoId, branch, channel, inv) {
|
|
131
|
+
const repo = await deps.registry.get(inv.storageScopeId, repoId);
|
|
132
|
+
const policy = repo?.publicationPolicy;
|
|
133
|
+
const designated = policy?.sharedPublishers.some(entry => entry.branch === branch &&
|
|
134
|
+
entry.principalIds.includes(inv.actorId));
|
|
135
|
+
const ok = policy?.delegatedPublication === 'personal-only' ? channel === 'personal'
|
|
136
|
+
: policy?.delegatedPublication === 'designated-shared' ? channel === 'personal' || designated === true : false;
|
|
137
|
+
if (!ok)
|
|
138
|
+
throw new ArtifactOperationError('git_auto_publish_refused', { publicDetails: { reason: 'delegation_policy' } });
|
|
139
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { GitBindingStore, GitCodeRightsPort } from './git-contracts.js';
|
|
2
|
+
import type { GitRepositoryRegistry } from './git-registry.js';
|
|
3
|
+
import type { GitPort } from './git-port.js';
|
|
4
|
+
export interface GitToolInvocation {
|
|
5
|
+
actorId: string;
|
|
6
|
+
storageScopeId: string;
|
|
7
|
+
invocationId: string;
|
|
8
|
+
}
|
|
9
|
+
/** Server-resolved artifact authority; never a tool argument. G0 v3 §1.4: owner + host write scope. */
|
|
10
|
+
export interface GitToolAuthority {
|
|
11
|
+
ownerId: string;
|
|
12
|
+
canWrite: boolean;
|
|
13
|
+
}
|
|
14
|
+
export type GitBuildJobState = 'build_pending' | 'building' | 'published' | 'build_failed' | 'cancelled';
|
|
15
|
+
/** G0 v3 §2.6: the persisted job identity; the release CAS and the SHA are never caller-editable later. */
|
|
16
|
+
export interface GitBuildJobRequest {
|
|
17
|
+
storageScopeId: string;
|
|
18
|
+
artifactId: string;
|
|
19
|
+
repoId: string;
|
|
20
|
+
branch: string;
|
|
21
|
+
subPath: string;
|
|
22
|
+
commitSha: string;
|
|
23
|
+
bindingGeneration: number;
|
|
24
|
+
expectedCurrentReleaseId: string | null;
|
|
25
|
+
executor: 'caller' | 'ci' | 'sandbox';
|
|
26
|
+
requestedBy: string;
|
|
27
|
+
idempotencyKey: string;
|
|
28
|
+
}
|
|
29
|
+
/** Build executor port: persists the job before returning its id; the same principal key returns the same job. */
|
|
30
|
+
export interface GitBuildPort {
|
|
31
|
+
/** Executor gate (G0 v3 §3.3, A-LIVE S03): false closes the executor with builder_unavailable. */
|
|
32
|
+
admits(executor: 'caller' | 'ci' | 'sandbox'): Promise<boolean>;
|
|
33
|
+
request(job: GitBuildJobRequest): Promise<{
|
|
34
|
+
jobId: string;
|
|
35
|
+
state: GitBuildJobState;
|
|
36
|
+
}>;
|
|
37
|
+
}
|
|
38
|
+
export interface GitToolsDeps {
|
|
39
|
+
bindings: GitBindingStore;
|
|
40
|
+
registry: GitRepositoryRegistry;
|
|
41
|
+
codeRights: GitCodeRightsPort;
|
|
42
|
+
git: GitPort;
|
|
43
|
+
authorize(invocation: GitToolInvocation, artifactId: string): Promise<GitToolAuthority>;
|
|
44
|
+
/** Absent ⇒ git_publish fails closed with provider_unavailable (503 capability_unavailable). */
|
|
45
|
+
build?: GitBuildPort;
|
|
46
|
+
/** Descriptor output subtree resolved by the host; excluded from writes. */
|
|
47
|
+
outputDir?: string;
|
|
48
|
+
/** Journal of every source read: repoId + resolved SHA (G0 v3 §1.4). */
|
|
49
|
+
journal?: (entry: {
|
|
50
|
+
actorId: string;
|
|
51
|
+
repoId: string;
|
|
52
|
+
commitSha: string;
|
|
53
|
+
invocationId: string;
|
|
54
|
+
}) => void | Promise<void>;
|
|
55
|
+
now?: () => Date;
|
|
56
|
+
}
|
|
57
|
+
export interface GitToolService {
|
|
58
|
+
execute(operation: string, args: Record<string, unknown>, invocation: GitToolInvocation): Promise<Record<string, any>>;
|
|
59
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|