@sentropic/artifacts 0.2.17 → 0.2.20
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 +39 -0
- package/README.md +14 -0
- package/dist/adapters/github-forge.d.ts +4 -0
- package/dist/adapters/github-forge.js +88 -0
- package/dist/adapters/github-git-port.d.ts +5 -0
- package/dist/adapters/github-git-port.js +102 -0
- package/dist/adapters/github-http.d.ts +5 -0
- package/dist/adapters/github-http.js +57 -0
- package/dist/adapters/github-receive-pack.d.ts +4 -0
- package/dist/adapters/github-receive-pack.js +49 -0
- package/dist/adapters/postgres-git-bindings.d.ts +7 -0
- package/dist/adapters/postgres-git-bindings.js +131 -0
- package/dist/adapters/postgres-live.d.ts +4 -0
- package/dist/adapters/postgres-live.js +97 -0
- package/dist/adapters/postgres.d.ts +1 -0
- package/dist/adapters/postgres.js +1 -0
- package/dist/git-tool-definitions.d.ts +606 -0
- package/dist/git-tool-definitions.js +14 -0
- package/dist/http.d.ts +9 -0
- package/dist/http.js +31 -2
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -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 +3 -3
- package/dist/mcp-core.js +18 -2
- package/dist/profile/contracts.d.ts +1 -1
- package/dist/profile/contracts.js +4 -0
- package/dist/profile/index.js +8 -1
- package/dist/profile/schemas.js +19 -0
- package/dist/profile/validation.js +5 -1
- package/dist/server/build-contract.d.ts +64 -0
- package/dist/server/build-contract.js +58 -0
- package/dist/server/build-dependencies.d.ts +3 -0
- package/dist/server/build-dependencies.js +122 -0
- package/dist/server/consent-grant.d.ts +91 -0
- package/dist/server/consent-grant.js +89 -0
- package/dist/server/consent-screen.d.ts +21 -0
- package/dist/server/consent-screen.js +52 -0
- package/dist/server/failures.d.ts +3 -2
- package/dist/server/failures.js +30 -0
- package/dist/server/git-bindings.d.ts +10 -0
- package/dist/server/git-bindings.js +138 -0
- package/dist/server/git-contracts.d.ts +115 -0
- package/dist/server/git-contracts.js +1 -0
- package/dist/server/git-port-policy.d.ts +9 -0
- package/dist/server/git-port-policy.js +76 -0
- package/dist/server/git-port-read.d.ts +3 -0
- package/dist/server/git-port-read.js +95 -0
- package/dist/server/git-port-session.d.ts +38 -0
- package/dist/server/git-port-session.js +59 -0
- package/dist/server/git-port-tree.d.ts +8 -0
- package/dist/server/git-port-tree.js +92 -0
- package/dist/server/git-port-write.d.ts +6 -0
- package/dist/server/git-port-write.js +102 -0
- package/dist/server/git-port.d.ts +147 -0
- package/dist/server/git-port.js +8 -0
- package/dist/server/git-projection.d.ts +16 -0
- package/dist/server/git-projection.js +20 -0
- package/dist/server/git-registry.d.ts +37 -0
- package/dist/server/git-registry.js +39 -0
- 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-body.d.ts +3 -0
- package/dist/server/live-body.js +28 -0
- package/dist/server/live-commit-outcome.d.ts +6 -0
- package/dist/server/live-commit-outcome.js +10 -0
- package/dist/server/live-commit.d.ts +11 -0
- package/dist/server/live-commit.js +133 -0
- package/dist/server/live-contracts.d.ts +62 -0
- package/dist/server/live-contracts.js +8 -0
- package/dist/server/live-crypto.d.ts +14 -0
- package/dist/server/live-crypto.js +50 -0
- package/dist/server/live-drafts.d.ts +61 -0
- package/dist/server/live-drafts.js +119 -0
- package/dist/server/live-errors.d.ts +23 -0
- package/dist/server/live-errors.js +9 -0
- package/dist/server/live-mutations.d.ts +18 -0
- package/dist/server/live-mutations.js +83 -0
- package/dist/server/live-read.d.ts +15 -0
- package/dist/server/live-read.js +95 -0
- package/dist/server/live-service.d.ts +3 -0
- package/dist/server/live-service.js +181 -0
- package/dist/server/live-store.d.ts +111 -0
- package/dist/server/live-store.js +80 -0
- package/dist/server/live-tree.d.ts +22 -0
- package/dist/server/live-tree.js +148 -0
- package/dist/server/live-worker.d.ts +10 -0
- package/dist/server/live-worker.js +55 -0
- package/dist/server/templates.js +26 -1
- package/migrations/0010_git_bindings.sql +82 -0
- package/migrations/0011_live_drafts.sql +42 -0
- package/migrations/0012_git_attach_intents.sql +19 -0
- package/package.json +17 -1
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A-LIVE §8.2 live edge wire format (W9 / M4-E), pure and dependency-free so the host (immo), the controller
|
|
3
|
+
* (Sentropic API) and `artifact-content` sign and verify with the same code. Three HMAC-SHA256 message kinds, each
|
|
4
|
+
* with its own MAC-bound prefix so none can be replayed as another:
|
|
5
|
+
* - `v1` host assertion (immo → artifact-content), on every live request and websocket upgrade;
|
|
6
|
+
* - `c1` host control (immo → artifact-content): session or invitation revocation;
|
|
7
|
+
* - `f1` controller fence (Sentropic API → artifact-content): generation and route-epoch floor.
|
|
8
|
+
*/
|
|
9
|
+
export declare const ASSERTION_HEADER = "x-live-host-assertion";
|
|
10
|
+
export declare const CONTROL_HEADER = "x-live-host-control";
|
|
11
|
+
export declare const FENCE_HEADER = "x-live-controller-fence";
|
|
12
|
+
export declare const MIN_KEY_BYTES = 32;
|
|
13
|
+
export declare const MAX_ASSERTION_SECONDS = 3600;
|
|
14
|
+
export declare const MAX_CONTROL_SECONDS = 300;
|
|
15
|
+
export declare const MAX_SKEW_SECONDS = 30;
|
|
16
|
+
/** The live source revision is an opaque string (A-LIVE live revisions), compared, never parsed. */
|
|
17
|
+
export declare const MAX_SOURCE_REVISION_LENGTH = 256;
|
|
18
|
+
export interface LiveAssertionClaims {
|
|
19
|
+
v: 1;
|
|
20
|
+
kid: string;
|
|
21
|
+
host: string;
|
|
22
|
+
artifactId: string;
|
|
23
|
+
storageScopeId: string;
|
|
24
|
+
sessionId: string;
|
|
25
|
+
generation: number;
|
|
26
|
+
routeEpoch: number;
|
|
27
|
+
podUid: string;
|
|
28
|
+
podName: string;
|
|
29
|
+
sourceRevision: string;
|
|
30
|
+
principalId: string;
|
|
31
|
+
role: 'binding_owner' | 'invitee';
|
|
32
|
+
invitationId: string;
|
|
33
|
+
invitationEpoch: number;
|
|
34
|
+
invitationExp: number;
|
|
35
|
+
iat: number;
|
|
36
|
+
exp: number;
|
|
37
|
+
}
|
|
38
|
+
/** Host revocation; `epoch` is the invitation's new floor: every assertion below it is refused. */
|
|
39
|
+
export interface LiveControlClaims {
|
|
40
|
+
v: 1;
|
|
41
|
+
kid: string;
|
|
42
|
+
host: string;
|
|
43
|
+
artifactId: string;
|
|
44
|
+
op: 'revoke_session' | 'revoke_invitation';
|
|
45
|
+
sessionId: string;
|
|
46
|
+
invitationId: string;
|
|
47
|
+
epoch: number;
|
|
48
|
+
iat: number;
|
|
49
|
+
exp: number;
|
|
50
|
+
}
|
|
51
|
+
/** Controller fence: routes below this generation, or below this route epoch within it, are refused. */
|
|
52
|
+
export interface LiveFenceClaims {
|
|
53
|
+
v: 1;
|
|
54
|
+
kid: string;
|
|
55
|
+
artifactId: string;
|
|
56
|
+
generation: number;
|
|
57
|
+
routeEpoch: number;
|
|
58
|
+
iat: number;
|
|
59
|
+
exp: number;
|
|
60
|
+
}
|
|
61
|
+
export interface VerifyOptions {
|
|
62
|
+
key(kid: string): Uint8Array | undefined;
|
|
63
|
+
now(): number;
|
|
64
|
+
}
|
|
65
|
+
export declare function signLiveAssertion(claims: LiveAssertionClaims, key: Uint8Array): string;
|
|
66
|
+
export declare const signLiveControl: (claims: LiveControlClaims, key: Uint8Array) => string;
|
|
67
|
+
export declare const signLiveFence: (claims: LiveFenceClaims, key: Uint8Array) => string;
|
|
68
|
+
export declare function verifyLiveAssertion(token: string, options: VerifyOptions): LiveAssertionClaims | undefined;
|
|
69
|
+
export declare function verifyLiveControl(token: string, options: VerifyOptions): LiveControlClaims | undefined;
|
|
70
|
+
export declare function verifyLiveFence(token: string, options: VerifyOptions): LiveFenceClaims | undefined;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* A-LIVE §8.2 live edge wire format (W9 / M4-E), pure and dependency-free so the host (immo), the controller
|
|
4
|
+
* (Sentropic API) and `artifact-content` sign and verify with the same code. Three HMAC-SHA256 message kinds, each
|
|
5
|
+
* with its own MAC-bound prefix so none can be replayed as another:
|
|
6
|
+
* - `v1` host assertion (immo → artifact-content), on every live request and websocket upgrade;
|
|
7
|
+
* - `c1` host control (immo → artifact-content): session or invitation revocation;
|
|
8
|
+
* - `f1` controller fence (Sentropic API → artifact-content): generation and route-epoch floor.
|
|
9
|
+
*/
|
|
10
|
+
export const ASSERTION_HEADER = 'x-live-host-assertion';
|
|
11
|
+
export const CONTROL_HEADER = 'x-live-host-control';
|
|
12
|
+
export const FENCE_HEADER = 'x-live-controller-fence';
|
|
13
|
+
export const MIN_KEY_BYTES = 32;
|
|
14
|
+
export const MAX_ASSERTION_SECONDS = 3600;
|
|
15
|
+
export const MAX_CONTROL_SECONDS = 300;
|
|
16
|
+
export const MAX_SKEW_SECONDS = 30;
|
|
17
|
+
/** The live source revision is an opaque string (A-LIVE live revisions), compared, never parsed. */
|
|
18
|
+
export const MAX_SOURCE_REVISION_LENGTH = 256;
|
|
19
|
+
const revision = (value) => typeof value === 'string' && value.length >= 1 && value.length <= MAX_SOURCE_REVISION_LENGTH;
|
|
20
|
+
const ASSERTION_FIELDS = {
|
|
21
|
+
v: 'number', kid: 'string', host: 'string', artifactId: 'string', storageScopeId: 'string', sessionId: 'string',
|
|
22
|
+
generation: 'number', routeEpoch: 'number', podUid: 'string', podName: 'string', sourceRevision: 'string',
|
|
23
|
+
principalId: 'string', role: 'string', invitationId: 'string', invitationEpoch: 'number', invitationExp: 'number', iat: 'number', exp: 'number',
|
|
24
|
+
};
|
|
25
|
+
const CONTROL_FIELDS = {
|
|
26
|
+
v: 'number', kid: 'string', host: 'string', artifactId: 'string', op: 'string', sessionId: 'string',
|
|
27
|
+
invitationId: 'string', epoch: 'number', iat: 'number', exp: 'number',
|
|
28
|
+
};
|
|
29
|
+
const FENCE_FIELDS = {
|
|
30
|
+
v: 'number', kid: 'string', artifactId: 'string', generation: 'number', routeEpoch: 'number', iat: 'number', exp: 'number',
|
|
31
|
+
};
|
|
32
|
+
const mac = (key, prefix, body) => createHmac('sha256', key).update(`${prefix}.${body}`).digest();
|
|
33
|
+
function sign(prefix, claims, key) {
|
|
34
|
+
if (key.length < MIN_KEY_BYTES)
|
|
35
|
+
throw new Error('Live key must contain at least 32 bytes');
|
|
36
|
+
const body = Buffer.from(JSON.stringify(claims)).toString('base64url');
|
|
37
|
+
return `${prefix}.${body}.${mac(key, prefix, body).toString('base64url')}`;
|
|
38
|
+
}
|
|
39
|
+
function verify(prefix, fields, maxSeconds, token, options) {
|
|
40
|
+
const parts = token.split('.');
|
|
41
|
+
if (parts.length !== 3 || parts[0] !== prefix || token.length > 2048)
|
|
42
|
+
return;
|
|
43
|
+
let claims;
|
|
44
|
+
try {
|
|
45
|
+
claims = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
46
|
+
if (!claims || typeof claims !== 'object' || claims.v !== 1
|
|
47
|
+
|| Object.keys(claims).sort().join() !== Object.keys(fields).sort().join()
|
|
48
|
+
|| Object.entries(fields).some(([name, type]) => {
|
|
49
|
+
const value = claims[name];
|
|
50
|
+
return typeof value !== type || (type === 'number' && (!Number.isSafeInteger(value) || value < 0));
|
|
51
|
+
}))
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const key = options.key(claims.kid);
|
|
58
|
+
if (!key || key.length < MIN_KEY_BYTES)
|
|
59
|
+
return;
|
|
60
|
+
const given = Buffer.from(parts[2], 'base64url');
|
|
61
|
+
const expected = mac(key, prefix, parts[1]);
|
|
62
|
+
if (given.length !== expected.length || !timingSafeEqual(given, expected))
|
|
63
|
+
return;
|
|
64
|
+
const now = options.now() / 1000;
|
|
65
|
+
if (claims.exp <= now || claims.iat > now + MAX_SKEW_SECONDS || claims.exp - claims.iat > maxSeconds)
|
|
66
|
+
return;
|
|
67
|
+
return claims;
|
|
68
|
+
}
|
|
69
|
+
const ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
70
|
+
/** Owner claims carry no invitation; an invitee claim must name a live invitation that outlasts the assertion. */
|
|
71
|
+
function validRole(c, now) {
|
|
72
|
+
if (c.role === 'binding_owner')
|
|
73
|
+
return c.invitationId === '' && c.invitationEpoch === 0 && c.invitationExp === 0;
|
|
74
|
+
return c.role === 'invitee' && ID.test(c.invitationId) && c.invitationEpoch >= 1
|
|
75
|
+
&& c.invitationExp > now && c.exp <= c.invitationExp;
|
|
76
|
+
}
|
|
77
|
+
function validControl(c) {
|
|
78
|
+
if (c.op === 'revoke_session')
|
|
79
|
+
return ID.test(c.sessionId) && c.invitationId === '' && c.epoch === 0;
|
|
80
|
+
return c.op === 'revoke_invitation' && ID.test(c.invitationId) && c.epoch >= 1 && c.sessionId === '';
|
|
81
|
+
}
|
|
82
|
+
export function signLiveAssertion(claims, key) {
|
|
83
|
+
if (!revision(claims.sourceRevision))
|
|
84
|
+
throw new TypeError('Live source revision must be a string of 1 to 256 characters');
|
|
85
|
+
return sign('v1', claims, key);
|
|
86
|
+
}
|
|
87
|
+
export const signLiveControl = (claims, key) => sign('c1', claims, key);
|
|
88
|
+
export const signLiveFence = (claims, key) => sign('f1', claims, key);
|
|
89
|
+
export function verifyLiveAssertion(token, options) {
|
|
90
|
+
const claims = verify('v1', ASSERTION_FIELDS, MAX_ASSERTION_SECONDS, token, options);
|
|
91
|
+
return claims && revision(claims.sourceRevision) && validRole(claims, options.now() / 1000) ? claims : undefined;
|
|
92
|
+
}
|
|
93
|
+
export function verifyLiveControl(token, options) {
|
|
94
|
+
const claims = verify('c1', CONTROL_FIELDS, MAX_CONTROL_SECONDS, token, options);
|
|
95
|
+
return claims && validControl(claims) ? claims : undefined;
|
|
96
|
+
}
|
|
97
|
+
export function verifyLiveFence(token, options) {
|
|
98
|
+
const claims = verify('f1', FENCE_FIELDS, MAX_CONTROL_SECONDS, token, options);
|
|
99
|
+
return claims && claims.generation >= 1 ? claims : undefined;
|
|
100
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { HandoffClaims } from './handoff.js';
|
|
2
|
+
/** Host state read INSIDE the host publication transaction, on the locked binding and job rows (A-LIVE §8.3). */
|
|
3
|
+
export interface AttemptFence {
|
|
4
|
+
runId: string;
|
|
5
|
+
attempt: number;
|
|
6
|
+
}
|
|
7
|
+
export interface HostRecheckView {
|
|
8
|
+
/** Authenticated host scope; never taken from the handoff. */
|
|
9
|
+
scopeId: string;
|
|
10
|
+
/** Operator pause or kill switch for sandbox publication. */
|
|
11
|
+
killSwitch: boolean;
|
|
12
|
+
/** Exact builder image digest strings (A-LIVE §8.1). */
|
|
13
|
+
imageAllowlist: readonly string[];
|
|
14
|
+
currentReleaseId: string | null;
|
|
15
|
+
/** The required head is reachable on the bound branch, observed in this transaction. */
|
|
16
|
+
headReachable: boolean;
|
|
17
|
+
binding: {
|
|
18
|
+
artifactId: string;
|
|
19
|
+
state: string;
|
|
20
|
+
generation: number;
|
|
21
|
+
executor: string;
|
|
22
|
+
autoPublish: boolean;
|
|
23
|
+
pendingJobId: string | null;
|
|
24
|
+
pendingCommitSha: string | null;
|
|
25
|
+
};
|
|
26
|
+
/** The persisted G0 v3 §2.6 job; `fence` is the attempt last admitted by `resolvePendingJob`. */
|
|
27
|
+
job: {
|
|
28
|
+
jobId: string;
|
|
29
|
+
state: string;
|
|
30
|
+
bindingGeneration: number;
|
|
31
|
+
commitSha: string;
|
|
32
|
+
expectedCurrentReleaseId: string | null;
|
|
33
|
+
fence: AttemptFence | null;
|
|
34
|
+
} | undefined;
|
|
35
|
+
/** Current owner/code rights and host write scope; the automatic policy and the §5.3.1 progress predicate or the
|
|
36
|
+
* separately recorded initial exception. */
|
|
37
|
+
policy: {
|
|
38
|
+
ownerAuthorized: boolean;
|
|
39
|
+
automaticAuthorized: boolean;
|
|
40
|
+
automaticEligible: boolean;
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export declare const RECHECK_REFUSALS: readonly ["scope_mismatch", "publication_paused", "generation_mismatch", "job_not_pending", "attempt_fenced", "policy_refused", "head_unreachable", "release_conflict", "image_not_allowed"];
|
|
44
|
+
export type RecheckRefusal = typeof RECHECK_REFUSALS[number];
|
|
45
|
+
/** The host job the builder may build (A-LIVE §8.4 server-resolved commit), from `resolvePendingJob`. */
|
|
46
|
+
export interface HostJob {
|
|
47
|
+
jobId: string;
|
|
48
|
+
generation: number;
|
|
49
|
+
headSha: string;
|
|
50
|
+
expectedReleaseId: string | null;
|
|
51
|
+
}
|
|
52
|
+
/** Every §8.3 final recheck, in order; null admits. acceptHandoff applies it; the host only supplies the view. */
|
|
53
|
+
export declare function publicationRecheck(view: HostRecheckView, claims: HandoffClaims): RecheckRefusal | null;
|
|
54
|
+
/** Host side of the builder's job resolution: only the binding's pending job at its generation, never a caller SHA.
|
|
55
|
+
* The attempt fence is monotonic; the host persists the returned fence on the job in the same transaction. */
|
|
56
|
+
export declare function resolvePendingJob(view: HostRecheckView, jobId: string, fence: AttemptFence): {
|
|
57
|
+
job: HostJob;
|
|
58
|
+
fence: AttemptFence;
|
|
59
|
+
} | null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const RECHECK_REFUSALS = ['scope_mismatch', 'publication_paused', 'generation_mismatch', 'job_not_pending',
|
|
2
|
+
'attempt_fenced', 'policy_refused', 'head_unreachable', 'release_conflict', 'image_not_allowed'];
|
|
3
|
+
function pending(view, jobId, generation) {
|
|
4
|
+
const { binding, job } = view;
|
|
5
|
+
return job !== undefined && ['build_pending', 'building'].includes(job.state) && binding.state === 'build_pending'
|
|
6
|
+
&& binding.executor === 'sandbox' && binding.pendingJobId === jobId && job.jobId === jobId
|
|
7
|
+
&& binding.generation === generation && job.bindingGeneration === generation
|
|
8
|
+
&& binding.pendingCommitSha === job.commitSha ? job : undefined;
|
|
9
|
+
}
|
|
10
|
+
/** Every §8.3 final recheck, in order; null admits. acceptHandoff applies it; the host only supplies the view. */
|
|
11
|
+
export function publicationRecheck(view, claims) {
|
|
12
|
+
if (claims.scopeId !== view.scopeId || claims.artifactId !== view.binding.artifactId)
|
|
13
|
+
return 'scope_mismatch';
|
|
14
|
+
if (view.killSwitch || view.binding.state === 'paused')
|
|
15
|
+
return 'publication_paused';
|
|
16
|
+
if (claims.generation !== view.binding.generation)
|
|
17
|
+
return 'generation_mismatch';
|
|
18
|
+
const job = pending(view, claims.jobId, claims.generation);
|
|
19
|
+
if (!job || job.commitSha !== claims.commitSha)
|
|
20
|
+
return 'job_not_pending';
|
|
21
|
+
if (job.fence?.runId !== claims.runId || job.fence.attempt !== claims.attempt)
|
|
22
|
+
return 'attempt_fenced';
|
|
23
|
+
if (claims.kind === 'explicit' ? view.policy.ownerAuthorized !== true
|
|
24
|
+
: !(view.binding.autoPublish === true && view.policy.automaticAuthorized === true && view.policy.automaticEligible === true)) {
|
|
25
|
+
return 'policy_refused';
|
|
26
|
+
}
|
|
27
|
+
if (view.headReachable !== true)
|
|
28
|
+
return 'head_unreachable';
|
|
29
|
+
if (claims.expectedReleaseId !== job.expectedCurrentReleaseId || view.currentReleaseId !== job.expectedCurrentReleaseId)
|
|
30
|
+
return 'release_conflict';
|
|
31
|
+
if (!view.imageAllowlist.includes(claims.tuple.builderImageDigest))
|
|
32
|
+
return 'image_not_allowed';
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
/** Host side of the builder's job resolution: only the binding's pending job at its generation, never a caller SHA.
|
|
36
|
+
* The attempt fence is monotonic; the host persists the returned fence on the job in the same transaction. */
|
|
37
|
+
export function resolvePendingJob(view, jobId, fence) {
|
|
38
|
+
const job = pending(view, jobId, view.binding.generation);
|
|
39
|
+
if (!job || typeof fence?.runId !== 'string' || !fence.runId || !Number.isSafeInteger(fence.attempt) || fence.attempt < 1
|
|
40
|
+
|| (job.fence && (fence.attempt < job.fence.attempt || (fence.attempt === job.fence.attempt && fence.runId !== job.fence.runId)))) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return { job: { jobId, generation: job.bindingGeneration, headSha: job.commitSha, expectedReleaseId: job.expectedCurrentReleaseId },
|
|
44
|
+
fence: { runId: fence.runId, attempt: fence.attempt } };
|
|
45
|
+
}
|
package/dist/mcp-core.d.ts
CHANGED
|
@@ -10,8 +10,8 @@ export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
|
10
10
|
export type { ArtifactKeyDerivationBinding } from './server/command-identity.js';
|
|
11
11
|
export declare const ARTIFACTS_PROVIDER_ID = "sentropic.artifacts";
|
|
12
12
|
export declare const ARTIFACTS_APP_ID = "sentropic-artifacts";
|
|
13
|
-
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.
|
|
14
|
-
export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2"];
|
|
13
|
+
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.20";
|
|
14
|
+
export declare const ARTIFACTS_TOOL_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2", "artifacts_list_app_sources", "artifacts_fetch_app_source", "artifacts_git_attach", "artifacts_git_commit", "artifacts_git_publish", "artifacts_git_live", "artifacts_live_write", "artifacts_live_read", "artifacts_live_reset", "artifacts_live_status", "artifacts_live_control"];
|
|
15
15
|
export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
|
|
16
16
|
export interface ArtifactsToolDefinition {
|
|
17
17
|
readonly description: string;
|
|
@@ -24,7 +24,7 @@ export interface ArtifactsToolDefinition {
|
|
|
24
24
|
/** Static wire definitions for every artifacts tool; identical across deployments and profiles. */
|
|
25
25
|
export declare const ARTIFACTS_TOOL_DEFINITIONS: Readonly<Record<ArtifactsToolName, ArtifactsToolDefinition>>;
|
|
26
26
|
export declare const ARTIFACTS_TOOL_SPECS: {
|
|
27
|
-
name: "artifacts_get_template" | "artifacts_get_api_guide" | "artifacts_ensure" | "artifacts_publish" | "artifacts_create_upload" | "artifacts_commit_upload" | "artifacts_list" | "artifacts_get" | "artifacts_get_source" | "artifacts_fork" | "artifacts_set_access" | "artifacts_promote" | "artifacts_renew" | "artifacts_delete" | "artifacts_restore" | "artifacts_list_versions" | "artifacts_revert" | "artifacts_lookup_people" | "artifacts_list_access" | "artifacts_publish_bundle" | "artifacts_revoke_reader_consent" | "artifacts_create_upload_page" | "artifacts_list_assets" | "artifacts_publish_bundle_v2";
|
|
27
|
+
name: "artifacts_get_template" | "artifacts_get_api_guide" | "artifacts_ensure" | "artifacts_publish" | "artifacts_create_upload" | "artifacts_commit_upload" | "artifacts_list" | "artifacts_get" | "artifacts_get_source" | "artifacts_fork" | "artifacts_set_access" | "artifacts_promote" | "artifacts_renew" | "artifacts_delete" | "artifacts_restore" | "artifacts_list_versions" | "artifacts_revert" | "artifacts_lookup_people" | "artifacts_list_access" | "artifacts_publish_bundle" | "artifacts_revoke_reader_consent" | "artifacts_create_upload_page" | "artifacts_list_assets" | "artifacts_publish_bundle_v2" | "artifacts_list_app_sources" | "artifacts_fetch_app_source" | "artifacts_git_attach" | "artifacts_git_commit" | "artifacts_git_publish" | "artifacts_git_live" | "artifacts_live_write" | "artifacts_live_read" | "artifacts_live_reset" | "artifacts_live_status" | "artifacts_live_control";
|
|
28
28
|
description: string;
|
|
29
29
|
mutability: import("@sentropic/mcp-platform").Mutability;
|
|
30
30
|
}[];
|
package/dist/mcp-core.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { assertArtifactsTransportProfile } from './http.js';
|
|
2
|
+
import { GIT_TOOL_DEFINITIONS } from './git-tool-definitions.js';
|
|
2
3
|
import { ARTIFACT_CAPABILITY_NAMES, ArtifactProfileInputError } from './profile/index.js';
|
|
3
4
|
import { ArtifactOperationError, classifyArtifactFailure } from './server/failures.js';
|
|
4
5
|
import { projectArtifactHttpOutcome, projectArtifactMcpOutcome } from './server/outcome-projection.js';
|
|
@@ -6,7 +7,7 @@ export * from './profile/index.js';
|
|
|
6
7
|
export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
7
8
|
export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
|
|
8
9
|
export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
|
|
9
|
-
export const ARTIFACTS_PROVIDER_VERSION = '0.2.
|
|
10
|
+
export const ARTIFACTS_PROVIDER_VERSION = '0.2.20';
|
|
10
11
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
11
12
|
// ---------------------------------------------------------------------------
|
|
12
13
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
|
@@ -46,9 +47,12 @@ const edit = obj({ path, oldStr: str, newStr: { type: 'string' } }, ['path', 'ol
|
|
|
46
47
|
const idOnly = obj({ artifactId: id }, ['artifactId']);
|
|
47
48
|
const ARTIFACTS_OUTPUT_SCHEMA = { type: 'object', additionalProperties: true };
|
|
48
49
|
const READ_ONLY_TOOLS = ['artifacts_list', 'artifacts_get',
|
|
50
|
+
'artifacts_list_app_sources', 'artifacts_fetch_app_source', 'artifacts_live_read', 'artifacts_live_status',
|
|
49
51
|
'artifacts_get_template', 'artifacts_get_api_guide', 'artifacts_get_source', 'artifacts_list_versions',
|
|
50
52
|
'artifacts_lookup_people', 'artifacts_list_access', 'artifacts_list_assets'];
|
|
51
53
|
const IDEMPOTENT_WRITERS = ['artifacts_ensure', 'artifacts_publish',
|
|
54
|
+
'artifacts_git_attach', 'artifacts_git_commit', 'artifacts_git_publish', 'artifacts_git_live',
|
|
55
|
+
'artifacts_live_write', 'artifacts_live_reset', 'artifacts_live_control',
|
|
52
56
|
'artifacts_commit_upload', 'artifacts_publish_bundle', 'artifacts_publish_bundle_v2',
|
|
53
57
|
'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
|
|
54
58
|
'artifacts_revoke_reader_consent'];
|
|
@@ -59,7 +63,7 @@ function staticTool(name, inputSchema, description) {
|
|
|
59
63
|
outputSchema: ARTIFACTS_OUTPUT_SCHEMA,
|
|
60
64
|
mutability: READ_ONLY_TOOLS.includes(name) ? 'read-only'
|
|
61
65
|
: name === 'artifacts_publish' || name === 'artifacts_publish_bundle' ||
|
|
62
|
-
name === 'artifacts_publish_bundle_v2' ? 'append' : 'state-transition',
|
|
66
|
+
name === 'artifacts_publish_bundle_v2' || name === 'artifacts_git_publish' ? 'append' : 'state-transition',
|
|
63
67
|
idempotency: IDEMPOTENT_WRITERS.includes(name) ? { required: true, scope: 'principal' } : { required: false },
|
|
64
68
|
gates: { requiresElicitation: false, requiresHumanConfirmation: name === 'artifacts_delete',
|
|
65
69
|
requiresPrincipalGate: false },
|
|
@@ -67,6 +71,7 @@ function staticTool(name, inputSchema, description) {
|
|
|
67
71
|
}
|
|
68
72
|
/** Static wire definitions for every artifacts tool; identical across deployments and profiles. */
|
|
69
73
|
export const ARTIFACTS_TOOL_DEFINITIONS = {
|
|
74
|
+
...GIT_TOOL_DEFINITIONS,
|
|
70
75
|
artifacts_get_template: staticTool('artifacts_get_template', obj({ templateId: str }, ['templateId'])),
|
|
71
76
|
artifacts_get_api_guide: staticTool('artifacts_get_api_guide', obj({ version: str })),
|
|
72
77
|
artifacts_ensure: staticTool('artifacts_ensure', obj({ bindingName: str, parameters: obj({}),
|
|
@@ -208,6 +213,17 @@ export function createArtifactsToolExecutor(deps) {
|
|
|
208
213
|
const args = profile.validate(input.tool, input.args, input.idempotencyKey, { deferPrecondition: true });
|
|
209
214
|
let request;
|
|
210
215
|
switch (input.tool) {
|
|
216
|
+
case 'artifacts_live_write':
|
|
217
|
+
case 'artifacts_live_read':
|
|
218
|
+
case 'artifacts_live_reset':
|
|
219
|
+
case 'artifacts_live_status':
|
|
220
|
+
case 'artifacts_live_control':
|
|
221
|
+
case 'artifacts_git_commit':
|
|
222
|
+
case 'artifacts_fetch_app_source':
|
|
223
|
+
case 'artifacts_git_attach':
|
|
224
|
+
case 'artifacts_git_publish':
|
|
225
|
+
request = { method: 'POST', path: '/' + input.tool.slice(10), body: args };
|
|
226
|
+
break;
|
|
211
227
|
case 'artifacts_ensure':
|
|
212
228
|
request = { method: 'POST', path: '/ensure', body: args };
|
|
213
229
|
break;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { JsonValue } from '../contracts.js';
|
|
2
2
|
import type { EffectiveArtifactCommand } from '../server/command-identity.js';
|
|
3
3
|
export declare const PROFILE_CONTRACT_VERSION: "artifacts-profile/v1";
|
|
4
|
-
export declare const ARTIFACT_CAPABILITY_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2"];
|
|
4
|
+
export declare const ARTIFACT_CAPABILITY_NAMES: readonly ["artifacts_get_template", "artifacts_get_api_guide", "artifacts_ensure", "artifacts_publish", "artifacts_create_upload", "artifacts_commit_upload", "artifacts_list", "artifacts_get", "artifacts_get_source", "artifacts_fork", "artifacts_set_access", "artifacts_promote", "artifacts_renew", "artifacts_delete", "artifacts_restore", "artifacts_list_versions", "artifacts_revert", "artifacts_lookup_people", "artifacts_list_access", "artifacts_publish_bundle", "artifacts_revoke_reader_consent", "artifacts_create_upload_page", "artifacts_list_assets", "artifacts_publish_bundle_v2", "artifacts_list_app_sources", "artifacts_fetch_app_source", "artifacts_git_attach", "artifacts_git_commit", "artifacts_git_publish", "artifacts_git_live", "artifacts_live_write", "artifacts_live_read", "artifacts_live_reset", "artifacts_live_status", "artifacts_live_control"];
|
|
5
5
|
export type ArtifactCapabilityName = (typeof ARTIFACT_CAPABILITY_NAMES)[number];
|
|
6
6
|
export type ArtifactSchema = Readonly<Record<string, unknown>>;
|
|
7
7
|
export interface OperationProfile {
|
|
@@ -12,6 +12,10 @@ export const ARTIFACT_CAPABILITY_NAMES = [
|
|
|
12
12
|
'artifacts_create_upload_page',
|
|
13
13
|
'artifacts_list_assets',
|
|
14
14
|
'artifacts_publish_bundle_v2',
|
|
15
|
+
'artifacts_list_app_sources', 'artifacts_fetch_app_source',
|
|
16
|
+
'artifacts_git_attach', 'artifacts_git_commit', 'artifacts_git_publish', 'artifacts_git_live',
|
|
17
|
+
'artifacts_live_write', 'artifacts_live_read', 'artifacts_live_reset',
|
|
18
|
+
'artifacts_live_status', 'artifacts_live_control',
|
|
15
19
|
];
|
|
16
20
|
/** Projection fields are data-only; invocation correlation is added by L6. */
|
|
17
21
|
export const PRECONDITION_REQUIRED_MESSAGE = 'expectedCurrentReleaseId is required by the active artifact profile. Re-read this artifact with artifacts_get or artifacts_list, then send expectedCurrentReleaseId using the currentReleaseId returned by that read. Send null only if the read confirms that there is no current release. Before editing an existing release, read it with artifacts_get_source and use that releaseId. The server will not infer this value.';
|
package/dist/profile/index.js
CHANGED
|
@@ -125,7 +125,9 @@ export function compileArtifactsProfile(input) {
|
|
|
125
125
|
throw new Error('profile/schema default mismatch');
|
|
126
126
|
}
|
|
127
127
|
if (['artifacts_ensure', 'artifacts_publish', 'artifacts_commit_upload', 'artifacts_publish_bundle',
|
|
128
|
-
'artifacts_publish_bundle_v2', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'
|
|
128
|
+
'artifacts_publish_bundle_v2', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
|
|
129
|
+
'artifacts_git_attach', 'artifacts_git_commit', 'artifacts_git_publish', 'artifacts_git_live',
|
|
130
|
+
'artifacts_live_write', 'artifacts_live_reset', 'artifacts_live_control'].includes(name)) {
|
|
129
131
|
idempotency[name] = { required: true, scope: 'principal' };
|
|
130
132
|
}
|
|
131
133
|
}
|
|
@@ -146,6 +148,11 @@ export function compileArtifactsProfile(input) {
|
|
|
146
148
|
},
|
|
147
149
|
capabilityForRoute(method, path) {
|
|
148
150
|
let name;
|
|
151
|
+
const gitRoutes = ['list_app_sources', 'fetch_app_source', 'git_attach', 'git_commit', 'git_publish',
|
|
152
|
+
'live_write', 'live_read', 'live_reset', 'live_status', 'live_control'];
|
|
153
|
+
if (method === 'POST' && gitRoutes.some(route => path === '/' + route)) {
|
|
154
|
+
name = `artifacts_${path.slice(1)}`;
|
|
155
|
+
}
|
|
149
156
|
if (method === 'POST' && path === '/ensure')
|
|
150
157
|
name = 'artifacts_ensure';
|
|
151
158
|
if (method === 'POST' && path === '/publish')
|
package/dist/profile/schemas.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SERVER_MAX_FILE_BYTES, SERVER_MAX_FILES_PER_RELEASE, SERVER_MAX_TOTAL_BYTES } from '../server/publication-limits.js';
|
|
2
|
+
import { GIT_TOOL_DEFINITIONS } from '../git-tool-definitions.js';
|
|
2
3
|
const str = { type: 'string', minLength: 1 };
|
|
3
4
|
const integer = (minimum, maximum) => ({ type: 'integer', minimum,
|
|
4
5
|
...(maximum === undefined ? {} : { maximum }) });
|
|
@@ -16,6 +17,13 @@ const metadata = {
|
|
|
16
17
|
/** Required configuration includes semantic limits absent from JSON Schema. */
|
|
17
18
|
export function assertCompleteOperation(config) {
|
|
18
19
|
const required = {
|
|
20
|
+
git_attach: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
21
|
+
git_commit: { limits: ['idempotencyKeyMaxUnits', 'gitMessageMaxUnits'], defaults: [] },
|
|
22
|
+
git_publish: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
23
|
+
git_live: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
24
|
+
live_write: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
25
|
+
live_reset: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
26
|
+
live_control: { limits: ['idempotencyKeyMaxUnits'], defaults: [] },
|
|
19
27
|
ensure: { limits: ['bindingNameMinUnits', 'bindingNameMaxUnits', 'idempotencyKeyMaxUnits'],
|
|
20
28
|
defaults: ['parameters'] },
|
|
21
29
|
// publish additionally accepts the optional release-budget keys
|
|
@@ -55,6 +63,17 @@ export function capabilitySchema(name, profile) {
|
|
|
55
63
|
const part1 = profile.profileRevisionId === undefined || profile.resultEnvelopeVersion === 2;
|
|
56
64
|
const config = operationProfile(profile, operation);
|
|
57
65
|
const limits = config.limits;
|
|
66
|
+
if (Object.hasOwn(GIT_TOOL_DEFINITIONS, name)) {
|
|
67
|
+
const definition = GIT_TOOL_DEFINITIONS[name];
|
|
68
|
+
const schema = structuredClone(definition.inputSchema);
|
|
69
|
+
if (schema.properties.idempotencyKey)
|
|
70
|
+
schema.properties.idempotencyKey.maxLength = limits.idempotencyKeyMaxUnits;
|
|
71
|
+
if (schema.properties.message)
|
|
72
|
+
schema.properties.message.maxLength = limits.gitMessageMaxUnits;
|
|
73
|
+
if (schema.properties.cursor)
|
|
74
|
+
schema.properties.cursor.maxLength = 4096;
|
|
75
|
+
return schema;
|
|
76
|
+
}
|
|
58
77
|
const key = { type: 'string', minLength: 1, maxLength: limits.idempotencyKeyMaxUnits,
|
|
59
78
|
description: 'Nonblank by JavaScript trim(); length is UTF-16 units; original bytes retained.' };
|
|
60
79
|
const idOnly = obj({ artifactId: id }, ['artifactId']);
|
|
@@ -103,7 +103,8 @@ export function normalizeArguments(profile, name, input, schema, envelopeKey, op
|
|
|
103
103
|
const { defaults, limits } = operationProfile(profile, operation);
|
|
104
104
|
const normalized = { ...copyJson(defaults), ...args };
|
|
105
105
|
if (['ensure', 'publish', 'commit_upload', 'publish_bundle', 'publish_bundle_v2',
|
|
106
|
-
'set_access', 'delete', 'revert'
|
|
106
|
+
'set_access', 'delete', 'revert', 'git_attach', 'git_commit', 'git_publish', 'git_live',
|
|
107
|
+
'live_write', 'live_reset', 'live_control'].includes(operation)) {
|
|
107
108
|
const key = args.idempotencyKey;
|
|
108
109
|
requireInput(typeof key === 'string' && key.trim().length > 0 && key.length <= limits.idempotencyKeyMaxUnits);
|
|
109
110
|
requireInput(envelopeKey === undefined || envelopeKey === key);
|
|
@@ -112,6 +113,9 @@ export function normalizeArguments(profile, name, input, schema, envelopeKey, op
|
|
|
112
113
|
requireInput(envelopeKey === undefined);
|
|
113
114
|
if (Object.hasOwn(args, 'artifactId'))
|
|
114
115
|
requireInput(isArtifactId(args.artifactId));
|
|
116
|
+
if (operation === 'git_commit')
|
|
117
|
+
requireInput(typeof args.message === 'string' &&
|
|
118
|
+
args.message.trim().length > 0 && args.message.length <= limits.gitMessageMaxUnits);
|
|
115
119
|
if (operation === 'get_source' && args.paths !== undefined) {
|
|
116
120
|
const paths = args.paths;
|
|
117
121
|
requireInput(new Set(paths).size === paths.length && paths.every((path) => Buffer.byteLength(path, 'utf8') <= profile.rules.pathMaxBytes));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Frozen G0 v3 §4.1 fields. Install permissions belong to the host. */
|
|
2
|
+
export interface ArtifactBuildDescriptor {
|
|
3
|
+
readonly version: 1;
|
|
4
|
+
readonly buildScript: string;
|
|
5
|
+
readonly outputDir: string;
|
|
6
|
+
readonly lockfilePath: string;
|
|
7
|
+
readonly entry?: string;
|
|
8
|
+
readonly publicEnvNames?: readonly string[];
|
|
9
|
+
}
|
|
10
|
+
export interface PostinstallAllowlistEntry {
|
|
11
|
+
readonly package: string;
|
|
12
|
+
readonly version: string;
|
|
13
|
+
readonly integrity: string;
|
|
14
|
+
}
|
|
15
|
+
/** Host supplies files from one exact SHA, rooted at the repository, never the live draft. */
|
|
16
|
+
export interface ArtifactBuildSnapshot {
|
|
17
|
+
readonly subPath: string;
|
|
18
|
+
readonly files: Readonly<Record<string, string>>;
|
|
19
|
+
readonly postinstallAllowlist?: readonly PostinstallAllowlistEntry[];
|
|
20
|
+
readonly allowedRegistries?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
export interface ArtifactBuildTuple {
|
|
23
|
+
readonly commitSha: string;
|
|
24
|
+
readonly treeSha: string;
|
|
25
|
+
readonly lockfileDigest: string;
|
|
26
|
+
readonly descriptorDigest: string;
|
|
27
|
+
readonly builderImageDigest: string;
|
|
28
|
+
readonly nodeVersion: string;
|
|
29
|
+
readonly npmVersion: string;
|
|
30
|
+
readonly publicEnvHashes: Readonly<Record<string, string>>;
|
|
31
|
+
}
|
|
32
|
+
export interface ArtifactBuildCandidate {
|
|
33
|
+
readonly candidateDigest: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ArtifactBuildReceipt extends ArtifactBuildCandidate {
|
|
36
|
+
readonly jobId: string;
|
|
37
|
+
readonly tuple: ArtifactBuildTuple;
|
|
38
|
+
readonly releaseId: string;
|
|
39
|
+
readonly manifestDigest: string;
|
|
40
|
+
readonly executor: 'caller' | 'ci' | 'sandbox';
|
|
41
|
+
readonly producer: {
|
|
42
|
+
readonly runId: string;
|
|
43
|
+
readonly attempt: number;
|
|
44
|
+
};
|
|
45
|
+
readonly verification: 'declared' | 'sha-verified' | 'builder-attested';
|
|
46
|
+
}
|
|
47
|
+
export declare function buildRecord(value: unknown): value is Record<string, unknown>;
|
|
48
|
+
export declare function buildJson(text: string | undefined): Record<string, unknown>;
|
|
49
|
+
export declare function buildPath(value: unknown): value is string;
|
|
50
|
+
/** Validation only: no filesystem, network, install, shell or script execution. */
|
|
51
|
+
export declare function validateArtifactBuild(snapshot: ArtifactBuildSnapshot): {
|
|
52
|
+
readonly descriptor: ArtifactBuildDescriptor;
|
|
53
|
+
readonly installDirectory: string;
|
|
54
|
+
readonly scriptDirectory: string;
|
|
55
|
+
readonly install: {
|
|
56
|
+
readonly command: "npm";
|
|
57
|
+
readonly args: readonly ["ci", "--ignore-scripts"];
|
|
58
|
+
};
|
|
59
|
+
readonly build: {
|
|
60
|
+
readonly command: "npm";
|
|
61
|
+
readonly args: readonly ["run", string];
|
|
62
|
+
};
|
|
63
|
+
readonly postinstall: readonly PostinstallAllowlistEntry[];
|
|
64
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ArtifactOperationError } from './failures.js';
|
|
2
|
+
import { validateBuildDependencies } from './build-dependencies.js';
|
|
3
|
+
export function buildRecord(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
export function buildJson(text) {
|
|
7
|
+
try {
|
|
8
|
+
const value = JSON.parse(text ?? '');
|
|
9
|
+
if (buildRecord(value))
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
catch { /* Refuse malformed input without exposing source bytes. */ }
|
|
13
|
+
throw new ArtifactOperationError('build_descriptor_invalid');
|
|
14
|
+
}
|
|
15
|
+
export function buildPath(value) {
|
|
16
|
+
return typeof value === 'string' && value.length > 0
|
|
17
|
+
&& !/[\\\u0000-\u001f\u007f:%?#]/.test(value)
|
|
18
|
+
&& value.split('/').every(segment => segment !== '' && segment !== '.' && segment !== '..');
|
|
19
|
+
}
|
|
20
|
+
const join = (root, path) => root ? `${root}/${path}` : path;
|
|
21
|
+
/** Validation only: no filesystem, network, install, shell or script execution. */
|
|
22
|
+
export function validateArtifactBuild(snapshot) {
|
|
23
|
+
const invalid = () => { throw new ArtifactOperationError('build_descriptor_invalid'); };
|
|
24
|
+
if (snapshot.subPath !== '' && !buildPath(snapshot.subPath))
|
|
25
|
+
invalid();
|
|
26
|
+
const value = buildJson(snapshot.files[join(snapshot.subPath, 'sentropic.artifact.json')]);
|
|
27
|
+
const fields = ['version', 'buildScript', 'outputDir', 'lockfilePath', 'entry', 'publicEnvNames'];
|
|
28
|
+
if (Object.keys(value).some(key => !fields.includes(key)) || value.version !== 1
|
|
29
|
+
|| typeof value.buildScript !== 'string' || !/^[A-Za-z0-9:_-]+$/.test(value.buildScript)
|
|
30
|
+
|| value.buildScript.trim() !== value.buildScript
|
|
31
|
+
|| !buildPath(value.outputDir) || !buildPath(value.lockfilePath)
|
|
32
|
+
|| (value.entry !== undefined && !buildPath(value.entry))
|
|
33
|
+
|| (value.publicEnvNames !== undefined && (!Array.isArray(value.publicEnvNames)
|
|
34
|
+
|| value.publicEnvNames.some(name => typeof name !== 'string' || !/^[A-Za-z_][A-Za-z0-9_]*$/.test(name)
|
|
35
|
+
|| name.trim() !== name))))
|
|
36
|
+
invalid();
|
|
37
|
+
const descriptor = value;
|
|
38
|
+
const manifest = buildJson(snapshot.files[join(snapshot.subPath, 'package.json')]);
|
|
39
|
+
const script = buildRecord(manifest.scripts) && Object.hasOwn(manifest.scripts, descriptor.buildScript)
|
|
40
|
+
? manifest.scripts[descriptor.buildScript] : undefined;
|
|
41
|
+
if (typeof script !== 'string' || !script.trim())
|
|
42
|
+
throw new ArtifactOperationError('build_script_missing');
|
|
43
|
+
if (!Object.hasOwn(snapshot.files, descriptor.lockfilePath))
|
|
44
|
+
throw new ArtifactOperationError('lock_missing');
|
|
45
|
+
const lock = buildJson(snapshot.files[descriptor.lockfilePath]);
|
|
46
|
+
const installDirectory = descriptor.lockfilePath.includes('/')
|
|
47
|
+
? descriptor.lockfilePath.slice(0, descriptor.lockfilePath.lastIndexOf('/')) : '';
|
|
48
|
+
if (installDirectory && snapshot.subPath !== installDirectory
|
|
49
|
+
&& !snapshot.subPath.startsWith(`${installDirectory}/`))
|
|
50
|
+
invalid();
|
|
51
|
+
const postinstall = validateBuildDependencies(snapshot, lock, installDirectory);
|
|
52
|
+
return {
|
|
53
|
+
descriptor, installDirectory, scriptDirectory: snapshot.subPath,
|
|
54
|
+
install: { command: 'npm', args: ['ci', '--ignore-scripts'] },
|
|
55
|
+
build: { command: 'npm', args: ['run', descriptor.buildScript] },
|
|
56
|
+
postinstall,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { ArtifactBuildSnapshot, PostinstallAllowlistEntry } from './build-contract.js';
|
|
2
|
+
/** Validate the lock-indexed install closure, including host-owned lifecycle permissions. */
|
|
3
|
+
export declare function validateBuildDependencies(snapshot: ArtifactBuildSnapshot, lock: Record<string, unknown>, installDirectory: string): readonly PostinstallAllowlistEntry[];
|