@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,148 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { ArtifactOperationError } from './failures.js';
|
|
3
|
+
import { assertGitTarget, gitPath } from './git-port-policy.js';
|
|
4
|
+
import { liveTextValid, overlayBytes } from './live-crypto.js';
|
|
5
|
+
export function validateLiveMutation(repo, target, input, maxPaths = 255, maxBytes = 2 * 1024 * 1024) {
|
|
6
|
+
assertGitTarget(repo, target, true);
|
|
7
|
+
const seen = new Set();
|
|
8
|
+
let bytes = 0;
|
|
9
|
+
for (const kind of ['edits', 'files', 'deletes']) {
|
|
10
|
+
const array = input[kind];
|
|
11
|
+
if (array === undefined)
|
|
12
|
+
continue;
|
|
13
|
+
if (!Array.isArray(array) || !array.length)
|
|
14
|
+
throw new ArtifactOperationError('invalid_request');
|
|
15
|
+
if (kind === 'edits' && array.length > 100)
|
|
16
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
17
|
+
for (const value of array) {
|
|
18
|
+
const path = typeof value === 'string' ? value : value?.path;
|
|
19
|
+
if (typeof path !== 'string' || seen.has(path))
|
|
20
|
+
throw new ArtifactOperationError('invalid_request');
|
|
21
|
+
gitPath(repo, target, path, true);
|
|
22
|
+
seen.add(path);
|
|
23
|
+
if (path.split('/').some(part => /^package.*\.json$/i.test(part)) ||
|
|
24
|
+
['.github/**', 'deploy/**', 'api/**', '.track/**', 'packages/immo-mcp/**'].some(glob => path === glob.slice(0, -3) || path.startsWith(glob.slice(0, -2))))
|
|
25
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
const keys = kind === 'edits' ? ['path', 'oldStr', 'newStr'] : ['path', 'text'];
|
|
28
|
+
if (Object.keys(value).some(key => !keys.includes(key)))
|
|
29
|
+
throw new ArtifactOperationError('invalid_request');
|
|
30
|
+
for (const key of keys.filter(key => key !== 'path')) {
|
|
31
|
+
const text = value[key];
|
|
32
|
+
if (typeof text !== 'string' || !liveTextValid(text) || (key === 'oldStr' && !text))
|
|
33
|
+
throw new ArtifactOperationError('invalid_request');
|
|
34
|
+
if (/-----BEGIN (?:[A-Z ]+ )?PRIVATE KEY-----/.test(text))
|
|
35
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
36
|
+
bytes += Buffer.byteLength(text);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!seen.size)
|
|
42
|
+
throw new ArtifactOperationError('invalid_request');
|
|
43
|
+
if (seen.size > maxPaths || bytes > maxBytes)
|
|
44
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
45
|
+
}
|
|
46
|
+
/** Compute actual Git object IDs without creating forge objects, preserving all excluded base entries. */
|
|
47
|
+
export function liveTreeSha(base, overlay, target) {
|
|
48
|
+
const algorithm = base.treeSha.length === 64 ? 'sha256' : 'sha1';
|
|
49
|
+
const objectId = (kind, bytes) => createHash(algorithm)
|
|
50
|
+
.update(Buffer.from(`${kind} ${bytes.length}\0`)).update(bytes).digest('hex');
|
|
51
|
+
const files = new Map(base.entries.map(entry => [entry.path, { mode: entry.mode, sha: entry.sha, type: entry.type }]));
|
|
52
|
+
for (const entry of overlay) {
|
|
53
|
+
const path = target.subPath ? target.subPath + '/' + entry.path : entry.path;
|
|
54
|
+
if (entry.text === null)
|
|
55
|
+
files.delete(path);
|
|
56
|
+
else
|
|
57
|
+
files.set(path, { mode: entry.mode, sha: objectId('blob', Buffer.from(entry.text)), type: 'blob' });
|
|
58
|
+
}
|
|
59
|
+
const node = () => ({ files: new Map(), directories: new Map() });
|
|
60
|
+
const root = node();
|
|
61
|
+
for (const [path, file] of files) {
|
|
62
|
+
const parts = path.split('/');
|
|
63
|
+
let current = root;
|
|
64
|
+
for (const part of file.type === 'tree' ? parts : parts.slice(0, -1)) {
|
|
65
|
+
if (!current.directories.has(part))
|
|
66
|
+
current.directories.set(part, node());
|
|
67
|
+
current = current.directories.get(part);
|
|
68
|
+
}
|
|
69
|
+
if (file.type !== 'tree')
|
|
70
|
+
current.files.set(parts.at(-1), file);
|
|
71
|
+
}
|
|
72
|
+
function hash(current) {
|
|
73
|
+
const entries = [...current.files].map(([name, entry]) => ({ name, ...entry, directory: false }));
|
|
74
|
+
for (const [name, child] of current.directories)
|
|
75
|
+
entries.push({ name, mode: '40000', sha: hash(child), directory: true });
|
|
76
|
+
entries.sort((a, b) => Buffer.compare(Buffer.from(a.name + (a.directory ? '/' : '')), Buffer.from(b.name + (b.directory ? '/' : ''))));
|
|
77
|
+
return objectId('tree', Buffer.concat(entries.map(entry => Buffer.concat([
|
|
78
|
+
Buffer.from(`${entry.mode.replace(/^0/, '')} ${entry.name}\0`), Buffer.from(entry.sha, 'hex')
|
|
79
|
+
]))));
|
|
80
|
+
}
|
|
81
|
+
return hash(root);
|
|
82
|
+
}
|
|
83
|
+
export async function applyLiveMutation(git, target, base, baseHeadSha, before, input) {
|
|
84
|
+
const overlay = new Map(before.map(entry => [entry.path, entry]));
|
|
85
|
+
const baseEntry = (path) => base.entries.find(entry => entry.path === (target.subPath ? target.subPath + '/' : '') + path);
|
|
86
|
+
const cache = new Map();
|
|
87
|
+
async function textAtBase(path) {
|
|
88
|
+
if (!baseEntry(path))
|
|
89
|
+
return undefined;
|
|
90
|
+
if (!cache.has(path)) {
|
|
91
|
+
const file = (await git.read(target, { commitSha: baseHeadSha, paths: [path] })).files[0];
|
|
92
|
+
if (!file || !('text' in file))
|
|
93
|
+
throw new ArtifactOperationError('edit_mismatch');
|
|
94
|
+
cache.set(path, file.text);
|
|
95
|
+
}
|
|
96
|
+
return cache.get(path);
|
|
97
|
+
}
|
|
98
|
+
async function put(path, text) {
|
|
99
|
+
const full = (target.subPath ? target.subPath + '/' : '') + path;
|
|
100
|
+
const entry = baseEntry(path);
|
|
101
|
+
if (base.entries.some(e => e.path.startsWith(full + '/') || (full.startsWith(e.path + '/') && e.type !== 'tree')) ||
|
|
102
|
+
(entry && (entry.type !== 'blob' || !['100644', '100755'].includes(entry.mode))))
|
|
103
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
104
|
+
if (text === null && !entry) {
|
|
105
|
+
if (overlay.get(path)?.text === undefined || overlay.get(path)?.text === null)
|
|
106
|
+
throw new ArtifactOperationError('invalid_request');
|
|
107
|
+
overlay.delete(path);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (text !== null && Buffer.byteLength(text) > 1024 * 1024)
|
|
111
|
+
throw new ArtifactOperationError('limit_exceeded');
|
|
112
|
+
if (text !== null && entry && text === await textAtBase(path))
|
|
113
|
+
overlay.delete(path);
|
|
114
|
+
else
|
|
115
|
+
overlay.set(path, { path, text, mode: entry?.mode ?? '100644' });
|
|
116
|
+
}
|
|
117
|
+
for (const edit of input.edits ?? []) {
|
|
118
|
+
const text = overlay.has(edit.path) ? overlay.get(edit.path).text : await textAtBase(edit.path);
|
|
119
|
+
const first = text?.indexOf(edit.oldStr) ?? -1;
|
|
120
|
+
if (text === null || text === undefined || first < 0 || text.indexOf(edit.oldStr, first + 1) >= 0)
|
|
121
|
+
throw new ArtifactOperationError('edit_mismatch');
|
|
122
|
+
await put(edit.path, text.slice(0, first) + edit.newStr + text.slice(first + edit.oldStr.length));
|
|
123
|
+
}
|
|
124
|
+
for (const file of input.files ?? [])
|
|
125
|
+
await put(file.path, file.text);
|
|
126
|
+
for (const path of input.deletes ?? [])
|
|
127
|
+
await put(path, null);
|
|
128
|
+
const result = [...overlay.values()].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0);
|
|
129
|
+
const paths = new Set(base.entries.filter(entry => entry.type !== 'tree').map(entry => entry.path));
|
|
130
|
+
for (const entry of result) {
|
|
131
|
+
const full = (target.subPath ? target.subPath + '/' : '') + entry.path;
|
|
132
|
+
if (entry.text === null)
|
|
133
|
+
paths.delete(full);
|
|
134
|
+
else
|
|
135
|
+
paths.add(full);
|
|
136
|
+
}
|
|
137
|
+
for (const path of paths) {
|
|
138
|
+
const parents = path.split('/');
|
|
139
|
+
parents.pop();
|
|
140
|
+
while (parents.length) {
|
|
141
|
+
if (paths.has(parents.join('/')))
|
|
142
|
+
throw new ArtifactOperationError('git_path_refused');
|
|
143
|
+
parents.pop();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
overlayBytes(result);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { LiveIdentity } from './live-store.js';
|
|
2
|
+
import type { LiveServiceDeps } from './live-contracts.js';
|
|
3
|
+
/** Side effects follow durable intents. Failure leaves the accepted source recoverable and pending. */
|
|
4
|
+
export declare function settleLiveWorker(input: {
|
|
5
|
+
deps: LiveServiceDeps;
|
|
6
|
+
identity: LiveIdentity;
|
|
7
|
+
action: 'project' | 'stop';
|
|
8
|
+
result: Record<string, any>;
|
|
9
|
+
now: number;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { expireLiveDraft, persistLiveOverlay, readLiveOverlay } from './live-drafts.js';
|
|
2
|
+
/** Side effects follow durable intents. Failure leaves the accepted source recoverable and pending. */
|
|
3
|
+
export async function settleLiveWorker(input) {
|
|
4
|
+
const { deps, identity, action, result, now } = input;
|
|
5
|
+
if (!deps.worker)
|
|
6
|
+
return;
|
|
7
|
+
try {
|
|
8
|
+
if (action === 'stop') {
|
|
9
|
+
const runtime = await deps.store.transaction(identity, async (tx) => tx.record?.runtime);
|
|
10
|
+
if (!runtime || runtime.liveSessionId !== result.liveSessionId)
|
|
11
|
+
return;
|
|
12
|
+
await deps.worker.stop({ ...identity, liveSessionId: runtime.liveSessionId, leaseEpoch: runtime.leaseEpoch });
|
|
13
|
+
await deps.store.transaction(identity, async (tx) => {
|
|
14
|
+
if (tx.record?.runtime?.liveSessionId === runtime.liveSessionId && tx.record.runtime.leaseEpoch === runtime.leaseEpoch &&
|
|
15
|
+
['QUIESCING', 'SAVING', 'DECOMMISSIONING'].includes(tx.record.runtime.phase)) {
|
|
16
|
+
tx.record.runtime.phase = 'DORMANT';
|
|
17
|
+
tx.record.runtime.appliedRevision = null;
|
|
18
|
+
result.state = 'DORMANT';
|
|
19
|
+
result.runtimeState = 'DORMANT';
|
|
20
|
+
result.appliedRevision = null;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
const ack = await deps.worker.reconcile(identity);
|
|
26
|
+
if (!ack?.ready)
|
|
27
|
+
return;
|
|
28
|
+
await deps.store.transaction(identity, async (tx) => {
|
|
29
|
+
const record = tx.record;
|
|
30
|
+
const runtime = record?.runtime;
|
|
31
|
+
if (!record || !runtime || ack.liveSessionId !== runtime.liveSessionId || ack.leaseEpoch !== runtime.leaseEpoch ||
|
|
32
|
+
ack.routeEpoch !== runtime.routeEpoch || ack.revision !== record.revision || !['REVIVING', 'LIVE'].includes(runtime.phase))
|
|
33
|
+
return;
|
|
34
|
+
const at = (deps.now ?? Date.now)();
|
|
35
|
+
if (expireLiveDraft(tx, at))
|
|
36
|
+
return;
|
|
37
|
+
if (runtime.renewOnReady && record.changedPaths) {
|
|
38
|
+
const overlay = await readLiveOverlay(tx, deps.keys);
|
|
39
|
+
const renewed = await persistLiveOverlay(tx, deps.keys, { identity, expectedRevision: record.revision,
|
|
40
|
+
baseHeadSha: record.baseHeadSha, baseTreeSha: record.baseTreeSha, liveTreeSha: record.liveTreeSha, overlay }, at, true, true);
|
|
41
|
+
// Source revision remains fenced to the worker ACK; reauthentication is handled by the vault.
|
|
42
|
+
result.draftExpiresAt = renewed.expiresAt;
|
|
43
|
+
}
|
|
44
|
+
runtime.renewOnReady = false;
|
|
45
|
+
runtime.appliedRevision = ack.revision;
|
|
46
|
+
runtime.phase = 'LIVE';
|
|
47
|
+
result.appliedRevision = ack.revision;
|
|
48
|
+
result.workerPending = false;
|
|
49
|
+
result.runtimeState = 'LIVE';
|
|
50
|
+
result.state = 'LIVE';
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch { /* The durable intent remains available to the controller's fenced reconciliation. */ }
|
|
55
|
+
}
|
package/dist/server/templates.js
CHANGED
|
@@ -91,7 +91,8 @@ const GUIDE_V1 = [
|
|
|
91
91
|
' release, for editing. Text mime types come back as `text` with',
|
|
92
92
|
' `encoding: "utf8"`; every other file as `base64` with `encoding: "base64"` —',
|
|
93
93
|
' never an integer array. The result carries a `guideRef` (tool + version),',
|
|
94
|
-
' never the guide body. Per call: at most 32 files
|
|
94
|
+
' never the guide body. Per call: at most 32 files; the byte caps are the',
|
|
95
|
+
' active profile\'s (generic maxima: 1 MiB per file, 2 MiB total).',
|
|
95
96
|
'- `artifacts_revert`: make an earlier release current again as a NEW',
|
|
96
97
|
' release that copies its content — the artifact URL stays stable and',
|
|
97
98
|
' history only grows. Purged releases are refused with `release_unavailable`.',
|
|
@@ -135,6 +136,30 @@ const GUIDE_V1 = [
|
|
|
135
136
|
'available for small text edits; the upload channel exists precisely so',
|
|
136
137
|
'bulk bytes skip the model.',
|
|
137
138
|
'',
|
|
139
|
+
'## Git-backed applications',
|
|
140
|
+
'',
|
|
141
|
+
'When the host registers a repository, build an application from its source',
|
|
142
|
+
'instead of publishing files (contracts G0 v3 §1.4/§2.6, A-LIVE v2). Only',
|
|
143
|
+
'the tools your host selected are available:',
|
|
144
|
+
'',
|
|
145
|
+
'1. `artifacts_fetch_app_source {repoId, ref}` (or `{artifactId}` once',
|
|
146
|
+
' attached): read the repository source at a server-resolved commit,',
|
|
147
|
+
' with the parsed build descriptor; page with `nextCursor`. Oversized',
|
|
148
|
+
' files come back as omitted entries.',
|
|
149
|
+
'2. `artifacts_git_attach {artifactId, repoId, baseRef, idempotencyKey}`:',
|
|
150
|
+
' bind the artifact to a dedicated `artifact/` branch (created from',
|
|
151
|
+
' `baseRef` when missing). Also pauses, resumes or detaches the binding.',
|
|
152
|
+
'3. `artifacts_git_commit`, then `artifacts_git_publish {artifactId,',
|
|
153
|
+
' commitSha, expectedCurrentReleaseId, idempotencyKey}`: the server builds',
|
|
154
|
+
' that commit from the descriptor recipe and publishes only the build',
|
|
155
|
+
' output after validation. The built output is never committed.',
|
|
156
|
+
'',
|
|
157
|
+
'Git-backed releases carry the repository build output, so they are not',
|
|
158
|
+
'bound by the inline `files` caps. Inline `files` publication keeps the',
|
|
159
|
+
'profile budget (generic maxima: 255 files, 16 MiB per file, 64 MiB per',
|
|
160
|
+
'release). Source-code rights are per repository and independent of page',
|
|
161
|
+
'sharing.',
|
|
162
|
+
'',
|
|
138
163
|
'Tool definitions are stable: names, descriptions and schemas never change',
|
|
139
164
|
'between versions or profiles, so host permissions (for example claude.ai',
|
|
140
165
|
'"Always allow") survive upgrades. The active profile revision and result',
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
-- SG1, G0 FROZEN v3 §2. Additive; live sessions have a separate later migration.
|
|
2
|
+
CREATE UNIQUE INDEX artifacts_id_scope_git ON artifacts.artifacts(id, storage_scope_id);
|
|
3
|
+
CREATE TABLE artifacts.git_bindings (
|
|
4
|
+
artifact_id UUID PRIMARY KEY,
|
|
5
|
+
storage_scope_id TEXT NOT NULL,
|
|
6
|
+
repo_id TEXT NOT NULL,
|
|
7
|
+
branch TEXT NOT NULL CHECK (branch LIKE 'artifact/%'),
|
|
8
|
+
channel TEXT NOT NULL CHECK (channel IN ('personal', 'shared')),
|
|
9
|
+
personal_principal_id TEXT,
|
|
10
|
+
sub_path TEXT NOT NULL,
|
|
11
|
+
base_commit_sha TEXT NOT NULL,
|
|
12
|
+
head_commit_sha TEXT,
|
|
13
|
+
release_commit_sha TEXT,
|
|
14
|
+
auto_publish BOOLEAN NOT NULL DEFAULT false,
|
|
15
|
+
executor TEXT NOT NULL CHECK (executor IN ('caller', 'ci', 'sandbox')),
|
|
16
|
+
pending_job_id TEXT,
|
|
17
|
+
pending_commit_sha TEXT,
|
|
18
|
+
state TEXT NOT NULL CHECK (state IN ('attached', 'syncing', 'build_pending', 'build_failed',
|
|
19
|
+
'diverged', 'paused', 'detached', 'error')),
|
|
20
|
+
state_detail TEXT,
|
|
21
|
+
generation INTEGER NOT NULL CHECK (generation > 0),
|
|
22
|
+
version INTEGER NOT NULL CHECK (version > 0),
|
|
23
|
+
attached_by TEXT NOT NULL,
|
|
24
|
+
attached_at TIMESTAMPTZ NOT NULL,
|
|
25
|
+
updated_at TIMESTAMPTZ NOT NULL,
|
|
26
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id),
|
|
27
|
+
CHECK ((channel = 'personal') = (personal_principal_id IS NOT NULL)),
|
|
28
|
+
CHECK ((pending_job_id IS NULL) = (pending_commit_sha IS NULL))
|
|
29
|
+
);
|
|
30
|
+
CREATE UNIQUE INDEX git_bindings_active_artifact ON artifacts.git_bindings(artifact_id) WHERE state <> 'detached';
|
|
31
|
+
CREATE UNIQUE INDEX git_bindings_active_branch ON artifacts.git_bindings(repo_id, branch) WHERE state <> 'detached';
|
|
32
|
+
CREATE INDEX git_bindings_scope ON artifacts.git_bindings(storage_scope_id, artifact_id);
|
|
33
|
+
|
|
34
|
+
CREATE TABLE artifacts.git_binding_events (
|
|
35
|
+
id BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
|
|
36
|
+
artifact_id UUID NOT NULL,
|
|
37
|
+
storage_scope_id TEXT NOT NULL,
|
|
38
|
+
actor_id TEXT NOT NULL,
|
|
39
|
+
action TEXT NOT NULL CHECK (action IN ('attach', 'pause', 'resume', 'detach', 'commit', 'inbound',
|
|
40
|
+
'publish', 'conflict', 'resolve', 'error')),
|
|
41
|
+
before_sha TEXT,
|
|
42
|
+
after_sha TEXT,
|
|
43
|
+
delivery_id TEXT,
|
|
44
|
+
invocation_id TEXT,
|
|
45
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
46
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id)
|
|
47
|
+
);
|
|
48
|
+
CREATE INDEX git_binding_events_scope ON artifacts.git_binding_events(storage_scope_id, artifact_id, created_at);
|
|
49
|
+
|
|
50
|
+
ALTER TABLE artifacts.releases ADD COLUMN git_commit TEXT NULL;
|
|
51
|
+
CREATE UNIQUE INDEX releases_id_artifact_git ON artifacts.releases(id, artifact_id);
|
|
52
|
+
CREATE TABLE artifacts.git_release_index (
|
|
53
|
+
release_id UUID PRIMARY KEY,
|
|
54
|
+
artifact_id UUID NOT NULL,
|
|
55
|
+
storage_scope_id TEXT NOT NULL,
|
|
56
|
+
repo_id TEXT NOT NULL,
|
|
57
|
+
branch TEXT NOT NULL,
|
|
58
|
+
commit_sha TEXT NOT NULL,
|
|
59
|
+
tree_sha TEXT,
|
|
60
|
+
manifest_digest TEXT NOT NULL,
|
|
61
|
+
candidate_digest TEXT NOT NULL,
|
|
62
|
+
executor TEXT NOT NULL CHECK (executor IN ('caller', 'ci', 'sandbox')),
|
|
63
|
+
verification TEXT NOT NULL CHECK (verification IN ('declared', 'sha-verified', 'builder-attested')),
|
|
64
|
+
receipt_id TEXT NOT NULL,
|
|
65
|
+
job_id TEXT NOT NULL,
|
|
66
|
+
build_run_id TEXT,
|
|
67
|
+
attempt INTEGER CHECK (attempt > 0),
|
|
68
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
69
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id),
|
|
70
|
+
FOREIGN KEY (release_id, artifact_id) REFERENCES artifacts.releases(id, artifact_id)
|
|
71
|
+
);
|
|
72
|
+
CREATE INDEX git_release_index_commit ON artifacts.git_release_index(storage_scope_id, artifact_id, commit_sha);
|
|
73
|
+
|
|
74
|
+
CREATE FUNCTION artifacts.reject_git_record_mutation() RETURNS trigger AS $$
|
|
75
|
+
BEGIN
|
|
76
|
+
RAISE EXCEPTION 'append-only: git audit and release index are immutable';
|
|
77
|
+
END;
|
|
78
|
+
$$ LANGUAGE plpgsql;
|
|
79
|
+
CREATE TRIGGER git_binding_events_append_only BEFORE UPDATE OR DELETE OR TRUNCATE ON artifacts.git_binding_events
|
|
80
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_git_record_mutation();
|
|
81
|
+
CREATE TRIGGER git_release_index_append_only BEFORE UPDATE OR DELETE OR TRUNCATE ON artifacts.git_release_index
|
|
82
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_git_record_mutation();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
-- Private draft namespace: no publication blob key, manifest or reader grant references it.
|
|
2
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_drafts (
|
|
3
|
+
storage_scope_id text NOT NULL,
|
|
4
|
+
artifact_id uuid NOT NULL,
|
|
5
|
+
binding_generation bigint NOT NULL CHECK (binding_generation > 0),
|
|
6
|
+
record jsonb NOT NULL,
|
|
7
|
+
PRIMARY KEY (storage_scope_id, artifact_id, binding_generation)
|
|
8
|
+
);
|
|
9
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_draft_objects (
|
|
10
|
+
storage_scope_id text NOT NULL,
|
|
11
|
+
artifact_id uuid NOT NULL,
|
|
12
|
+
binding_generation bigint NOT NULL,
|
|
13
|
+
object_ref uuid NOT NULL,
|
|
14
|
+
envelope jsonb NOT NULL,
|
|
15
|
+
PRIMARY KEY (storage_scope_id, artifact_id, binding_generation, object_ref)
|
|
16
|
+
);
|
|
17
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_commands (
|
|
18
|
+
storage_scope_id text NOT NULL,
|
|
19
|
+
actor_id text NOT NULL,
|
|
20
|
+
command_key text NOT NULL,
|
|
21
|
+
command_hash text NOT NULL,
|
|
22
|
+
result jsonb NOT NULL,
|
|
23
|
+
PRIMARY KEY (storage_scope_id, actor_id, command_key)
|
|
24
|
+
);
|
|
25
|
+
CREATE TABLE IF NOT EXISTS artifacts.live_commit_quota (
|
|
26
|
+
storage_scope_id text NOT NULL,
|
|
27
|
+
actor_id text NOT NULL,
|
|
28
|
+
artifact_id uuid NOT NULL,
|
|
29
|
+
invocation_id text NOT NULL,
|
|
30
|
+
created_at timestamptz NOT NULL,
|
|
31
|
+
PRIMARY KEY (storage_scope_id, actor_id, invocation_id)
|
|
32
|
+
);
|
|
33
|
+
CREATE INDEX IF NOT EXISTS live_commit_quota_window ON artifacts.live_commit_quota(storage_scope_id, created_at);
|
|
34
|
+
|
|
35
|
+
CREATE OR REPLACE FUNCTION artifacts.reject_live_object_update() RETURNS trigger LANGUAGE plpgsql AS $$
|
|
36
|
+
BEGIN
|
|
37
|
+
RAISE EXCEPTION 'live draft objects are immutable';
|
|
38
|
+
END;
|
|
39
|
+
$$;
|
|
40
|
+
DROP TRIGGER IF EXISTS live_object_immutable ON artifacts.live_draft_objects;
|
|
41
|
+
CREATE TRIGGER live_object_immutable BEFORE UPDATE ON artifacts.live_draft_objects
|
|
42
|
+
FOR EACH STATEMENT EXECUTE FUNCTION artifacts.reject_live_object_update();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
-- SG3 git_attach, A-LIVE v2 §5.3.1. Additive only: one nullable audit column and one intent table.
|
|
2
|
+
-- branch_created is true only on the attach event that verified creation of its branch.
|
|
3
|
+
ALTER TABLE artifacts.git_binding_events ADD COLUMN branch_created BOOLEAN NULL;
|
|
4
|
+
ALTER TABLE artifacts.git_binding_events ADD CONSTRAINT git_binding_events_branch_created
|
|
5
|
+
CHECK (branch_created IS NULL OR (branch_created AND action = 'attach'));
|
|
6
|
+
-- Written before the forge createBranch, keyed like the replay receipt (scope, actor, key).
|
|
7
|
+
CREATE TABLE artifacts.git_attach_intents (
|
|
8
|
+
storage_scope_id TEXT NOT NULL,
|
|
9
|
+
actor_id TEXT NOT NULL,
|
|
10
|
+
idempotency_key TEXT NOT NULL,
|
|
11
|
+
command_hash TEXT NOT NULL,
|
|
12
|
+
artifact_id UUID NOT NULL,
|
|
13
|
+
repo_id TEXT NOT NULL,
|
|
14
|
+
branch TEXT NOT NULL CHECK (branch LIKE 'artifact/%'),
|
|
15
|
+
base_commit_sha TEXT NOT NULL,
|
|
16
|
+
created_at TIMESTAMPTZ NOT NULL,
|
|
17
|
+
PRIMARY KEY (storage_scope_id, actor_id, idempotency_key),
|
|
18
|
+
FOREIGN KEY (artifact_id, storage_scope_id) REFERENCES artifacts.artifacts(id, storage_scope_id)
|
|
19
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.20",
|
|
4
4
|
"description": "Generic configurable artifacts MCP and artifact service: StorageScope/Artifact/Binding/Release model, canonical manifests, object authorization, idempotent intents (spec-v8 §9).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -67,6 +67,10 @@
|
|
|
67
67
|
},
|
|
68
68
|
"./sql/*": "./sql/*",
|
|
69
69
|
"./migrations/*": "./migrations/*",
|
|
70
|
+
"./server/build-contract": {
|
|
71
|
+
"types": "./dist/server/build-contract.d.ts",
|
|
72
|
+
"import": "./dist/server/build-contract.js"
|
|
73
|
+
},
|
|
70
74
|
"./server/ports": {
|
|
71
75
|
"types": "./dist/server/ports.d.ts",
|
|
72
76
|
"import": "./dist/server/ports.js"
|
|
@@ -75,6 +79,14 @@
|
|
|
75
79
|
"types": "./dist/server/consent.d.ts",
|
|
76
80
|
"import": "./dist/server/consent.js"
|
|
77
81
|
},
|
|
82
|
+
"./server/consent-grant": {
|
|
83
|
+
"types": "./dist/server/consent-grant.d.ts",
|
|
84
|
+
"import": "./dist/server/consent-grant.js"
|
|
85
|
+
},
|
|
86
|
+
"./server/mime": {
|
|
87
|
+
"types": "./dist/server/mime.d.ts",
|
|
88
|
+
"import": "./dist/server/mime.js"
|
|
89
|
+
},
|
|
78
90
|
"./server/reader-store": {
|
|
79
91
|
"types": "./dist/server/reader-store.d.ts",
|
|
80
92
|
"import": "./dist/server/reader-store.js"
|
|
@@ -210,6 +222,10 @@
|
|
|
210
222
|
"./client": {
|
|
211
223
|
"types": "./dist/client.d.ts",
|
|
212
224
|
"import": "./dist/client.js"
|
|
225
|
+
},
|
|
226
|
+
"./live-host": {
|
|
227
|
+
"types": "./dist/live-host/index.d.ts",
|
|
228
|
+
"import": "./dist/live-host/index.js"
|
|
213
229
|
}
|
|
214
230
|
},
|
|
215
231
|
"files": [
|