@sentropic/artifacts 0.2.22 → 0.2.24
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 +41 -0
- package/dist/adapters/github-forge.js +32 -2
- package/dist/live-host/draft-stager.d.ts +64 -0
- package/dist/live-host/draft-stager.js +74 -0
- package/dist/live-host/index.d.ts +2 -0
- package/dist/live-host/index.js +2 -0
- package/dist/live-host/worker-client.d.ts +58 -0
- package/dist/live-host/worker-client.js +143 -0
- package/dist/mcp-core.d.ts +1 -1
- package/dist/mcp-core.js +1 -1
- package/dist/server/git-tools-attach.js +3 -1
- package/dist/server/live-service.js +105 -59
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,46 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.24
|
|
4
|
+
|
|
5
|
+
- `artifacts_live_status` and `artifacts_live_control` start no longer walk the repository tree: they
|
|
6
|
+
resolve the head (`git/ref/heads/{branch}`) and read the base tree SHA from one commit lookup, then
|
|
7
|
+
return `liveRevision`, `currentHeadSha`, `bindingGeneration` and the draft state. Only reads that list
|
|
8
|
+
base entries (`live_read`, `live_write`, `live_status` with `includeDiff`/`cursor`) take the snapshot.
|
|
9
|
+
- The tree walk, the base commit lookup and the fast-forward checks no longer run inside the per-artifact
|
|
10
|
+
advisory-locked draft transaction: the draft fence is read in a short transaction, those forge calls run
|
|
11
|
+
outside the lock, and the locked transaction re-checks the fence (bounded retry, then
|
|
12
|
+
`git_live_conflict`/`transition_busy`). Status, start and reset therefore make no forge call under the lock
|
|
13
|
+
(immo preprod 08/11: 502 on live_status, `idle in transaction`, lock timeouts). Still under the lock:
|
|
14
|
+
the base file reads of a `live_read` page and of `live_write` edits, and the host `authorize` callback.
|
|
15
|
+
- Status, start and reset no longer validate the whole tree (walk limits, entry names); those checks stay
|
|
16
|
+
with the reads that list base entries. A host GitPort without `snapshot` now gets `capability_unselected`
|
|
17
|
+
before the transaction.
|
|
18
|
+
- `@sentropic/artifacts/live-host` ships the host live worker: `createLiveWorkerClient` is the HTTP
|
|
19
|
+
`LiveWorkerPort` over the builder host live API (`v1/live/reconcile`, `v1/live/stop`). Before every
|
|
20
|
+
reconcile it stages the current durable draft: `v1/live/draft/page` for each non-empty page (at most
|
|
21
|
+
1 MiB of file bytes, 32 pages; overlay at most 255 paths, 1 MiB per file, 8 MiB), then
|
|
22
|
+
`v1/live/draft/seal` (a clean draft is `pages: 0`, `deletes: []`, `treeSha` = the live tree). The
|
|
23
|
+
reconcile body carries `ownerId` from the live record runtime. A refused page or seal stops before the
|
|
24
|
+
reconcile (`provider_unavailable`); an overlay over the limits fails before any call (`limit_exceeded`).
|
|
25
|
+
- Host ports of the worker: `fences` (owner and fences of the runtime), `bindings`, `sessionState` and
|
|
26
|
+
`drafts` (the current draft overlay). `liveStoreFences(store)` and `liveStoreDrafts(store, keys)` supply
|
|
27
|
+
them from the package `LiveStore`. `planLiveDraft`, `stageLiveDraft` and `LIVE_DRAFT_LIMITS` are exported.
|
|
28
|
+
|
|
29
|
+
## 0.2.23
|
|
30
|
+
|
|
31
|
+
- `createGitHubForge` resolves a branch through `GET /repos/{owner}/{repo}/git/ref/heads/{branch}`
|
|
32
|
+
(each ref segment encoded on its own, so `artifact/p/<id>/<app>` keeps its slashes) and reads the
|
|
33
|
+
exact `refs/heads/<branch>` commit `object.sha`; a full 40-hex commit SHA goes straight to
|
|
34
|
+
`/commits/<sha>`. Another registered ref (a tag, an abbreviated SHA) that is not a branch still
|
|
35
|
+
resolves through `/commits/{ref}` (per-segment encoding); an `artifact/` branch never does.
|
|
36
|
+
- An absent ref is `missing` on every lookup: GitHub answers 422 « No commit found » (not 404) for an
|
|
37
|
+
unknown ref, and that 422 no longer maps to `conflict`/`git_ref_not_allowed`. `resolveRef` on the
|
|
38
|
+
bound branch reports `git_branch_missing` and `artifacts_git_attach` now treats it as an absent
|
|
39
|
+
branch, so a new personal branch is created from `baseRef` instead of failing the attach.
|
|
40
|
+
`createBranch` on an existing branch stays `conflict`.
|
|
41
|
+
- `ARTIFACTS_PROVIDER_VERSION` follows the package (0.2.23): the APP-P1 manifest digest changes through
|
|
42
|
+
its version field only (four-tool selection and tool definitions unchanged).
|
|
43
|
+
|
|
3
44
|
## 0.2.22
|
|
4
45
|
|
|
5
46
|
- Generic live invitations through MCP (A-LIVE v2 §8.2, §9): four tools appended last and frozen at
|
|
@@ -8,9 +8,38 @@ const sha = (value) => {
|
|
|
8
8
|
throw new GitForgeError('unavailable');
|
|
9
9
|
return value;
|
|
10
10
|
};
|
|
11
|
+
/** GitHub answers 422 « No commit found » (not 404) for an unknown ref: both mean absent, never a ref refusal. */
|
|
12
|
+
async function absentAsMissing(request) {
|
|
13
|
+
try {
|
|
14
|
+
return await request;
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (error instanceof GitForgeError && (error.code === 'missing' || error.code === 'conflict'))
|
|
18
|
+
throw new GitForgeError('missing');
|
|
19
|
+
throw error;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
11
22
|
/** Fixed public GitHub origins. The SG0-net host owns network admission and egress receipts. */
|
|
12
23
|
export function createGitHubForge(fetcher = globalThis.fetch) {
|
|
13
24
|
const api = githubApi(fetcher);
|
|
25
|
+
/** Each ref segment is encoded on its own so « artifact/p/x » keeps its path slashes. */
|
|
26
|
+
const segments = (ref) => ref.split('/').map(encodeURIComponent).join('/');
|
|
27
|
+
/** Exact branch lookup first; artifact branches never resolve as anything else. */
|
|
28
|
+
async function refHead(context, ref) {
|
|
29
|
+
try {
|
|
30
|
+
const result = await absentAsMissing(api(context, `/git/ref/heads/${segments(ref)}`));
|
|
31
|
+
if (result?.ref !== `refs/heads/${ref}` || result?.object?.type !== 'commit')
|
|
32
|
+
throw new GitForgeError('unavailable');
|
|
33
|
+
return sha(result.object.sha);
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (ref.startsWith('artifact/') || !(error instanceof GitForgeError && error.code === 'missing'))
|
|
37
|
+
throw error;
|
|
38
|
+
}
|
|
39
|
+
// Registered sources may also be read at a tag or an abbreviated commit SHA (docs/git-port.md).
|
|
40
|
+
const result = await absentAsMissing(api(context, `/commits/${segments(ref)}`));
|
|
41
|
+
return sha(result?.sha);
|
|
42
|
+
}
|
|
14
43
|
return {
|
|
15
44
|
async repositoryId(context) {
|
|
16
45
|
const result = await api(context, '');
|
|
@@ -20,8 +49,9 @@ export function createGitHubForge(fetcher = globalThis.fetch) {
|
|
|
20
49
|
return String(result.id);
|
|
21
50
|
},
|
|
22
51
|
async resolve(context, ref) {
|
|
23
|
-
const
|
|
24
|
-
|
|
52
|
+
const commitSha = /^[0-9a-f]{40}$/.test(ref) ? ref : await refHead(context, ref);
|
|
53
|
+
const result = await absentAsMissing(api(context, `/commits/${commitSha}`));
|
|
54
|
+
if (result?.sha !== commitSha || !Array.isArray(result?.parents) || typeof result?.commit?.message !== 'string' ||
|
|
25
55
|
[result.commit.author, result.commit.committer].some(person => typeof person?.name !== 'string' || typeof person?.email !== 'string')) {
|
|
26
56
|
throw new GitForgeError('unavailable');
|
|
27
57
|
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { LiveKeyPort } from '../server/live-crypto.js';
|
|
2
|
+
import type { LiveIdentity, LiveOverlayEntry, LiveStore } from '../server/live-store.js';
|
|
3
|
+
/** Builder draft paths of the host live API (s-archi contract 07/11): pages in order, then the seal, both answering 204. */
|
|
4
|
+
export declare const LIVE_DRAFT_PATHS: Readonly<{
|
|
5
|
+
page: "v1/live/draft/page";
|
|
6
|
+
seal: "v1/live/draft/seal";
|
|
7
|
+
}>;
|
|
8
|
+
/** A-LIVE §3.2 overlay (255 paths, 1 MiB per file, 8 MiB), pushed as at most 32 non-empty pages of at most 1 MiB of file bytes. */
|
|
9
|
+
export declare const LIVE_DRAFT_LIMITS: Readonly<{
|
|
10
|
+
paths: 255;
|
|
11
|
+
fileBytes: number;
|
|
12
|
+
totalBytes: number;
|
|
13
|
+
pageBytes: number;
|
|
14
|
+
pages: 32;
|
|
15
|
+
}>;
|
|
16
|
+
/** The current durable draft of a live identity: an overlay on `baseHeadSha` whose resulting tree is `liveTreeSha`. */
|
|
17
|
+
export interface LiveDraftSnapshot {
|
|
18
|
+
readonly revision: string;
|
|
19
|
+
readonly baseHeadSha: string;
|
|
20
|
+
readonly liveTreeSha: string;
|
|
21
|
+
/** `text: null` is a deletion; `mode` is the git tree mode (`100644` or `100755`). */
|
|
22
|
+
readonly overlay: readonly LiveOverlayEntry[];
|
|
23
|
+
}
|
|
24
|
+
/** Host port: the current durable draft of the package store; undefined when the identity has no draft record. */
|
|
25
|
+
export interface LiveDraftSource {
|
|
26
|
+
current(identity: LiveIdentity): Promise<LiveDraftSnapshot | undefined>;
|
|
27
|
+
}
|
|
28
|
+
export interface LiveDraftPageFile {
|
|
29
|
+
readonly path: string;
|
|
30
|
+
readonly mode: number;
|
|
31
|
+
readonly data: string;
|
|
32
|
+
}
|
|
33
|
+
/** Closed PAGE body: artifactId, bindingGeneration, revision, page, files. */
|
|
34
|
+
export interface LiveDraftPageBody {
|
|
35
|
+
readonly artifactId: string;
|
|
36
|
+
readonly bindingGeneration: number;
|
|
37
|
+
readonly revision: string;
|
|
38
|
+
readonly page: number;
|
|
39
|
+
readonly files: readonly LiveDraftPageFile[];
|
|
40
|
+
}
|
|
41
|
+
/** Closed SEAL body: an empty overlay is `pages: 0, deletes: []` with `treeSha` = the live tree. */
|
|
42
|
+
export interface LiveDraftSealBody {
|
|
43
|
+
readonly artifactId: string;
|
|
44
|
+
readonly bindingGeneration: number;
|
|
45
|
+
readonly revision: string;
|
|
46
|
+
readonly pages: number;
|
|
47
|
+
readonly baseHeadSha: string;
|
|
48
|
+
readonly treeSha: string;
|
|
49
|
+
readonly deletes: readonly string[];
|
|
50
|
+
}
|
|
51
|
+
export interface LiveDraftPlan {
|
|
52
|
+
readonly pages: readonly LiveDraftPageBody[];
|
|
53
|
+
readonly seal: LiveDraftSealBody;
|
|
54
|
+
}
|
|
55
|
+
/** Splits a draft into wire pages and deletes within LIVE_DRAFT_LIMITS. A duplicate path or a non-regular mode fails closed. */
|
|
56
|
+
export declare function planLiveDraft(draft: LiveDraftSnapshot, identity: LiveIdentity): LiveDraftPlan;
|
|
57
|
+
/** Posts one body to a builder path and returns its HTTP status; a transport failure throws. */
|
|
58
|
+
export type LiveDraftSend = (path: string, body: unknown) => Promise<{
|
|
59
|
+
status: number;
|
|
60
|
+
}>;
|
|
61
|
+
/** Stages the current draft: every page in order, then the seal. Anything but 204 is provider_unavailable. */
|
|
62
|
+
export declare function stageLiveDraft(source: LiveDraftSource, identity: LiveIdentity, send: LiveDraftSend): Promise<void>;
|
|
63
|
+
/** The LiveDraftSource of a host on the package LiveStore: the decrypted overlay of the current record. */
|
|
64
|
+
export declare function liveStoreDrafts(store: LiveStore, keys: LiveKeyPort, now?: () => number): LiveDraftSource;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ArtifactOperationError } from '../server/failures.js';
|
|
2
|
+
import { createLiveDraftVault } from '../server/live-drafts.js';
|
|
3
|
+
/** Builder draft paths of the host live API (s-archi contract 07/11): pages in order, then the seal, both answering 204. */
|
|
4
|
+
export const LIVE_DRAFT_PATHS = Object.freeze({ page: 'v1/live/draft/page', seal: 'v1/live/draft/seal' });
|
|
5
|
+
/** A-LIVE §3.2 overlay (255 paths, 1 MiB per file, 8 MiB), pushed as at most 32 non-empty pages of at most 1 MiB of file bytes. */
|
|
6
|
+
export const LIVE_DRAFT_LIMITS = Object.freeze({ paths: 255, fileBytes: 1024 * 1024, totalBytes: 8 * 1024 * 1024,
|
|
7
|
+
pageBytes: 1024 * 1024, pages: 32 });
|
|
8
|
+
/** Regular git file modes only; a symlink or submodule entry cannot be staged. */
|
|
9
|
+
const modeOf = (mode) => (mode === '100644' ? 0o644 : mode === '100755' ? 0o755 : unavailable());
|
|
10
|
+
const limit = () => { throw new ArtifactOperationError('limit_exceeded'); };
|
|
11
|
+
const unavailable = () => { throw new ArtifactOperationError('provider_unavailable'); };
|
|
12
|
+
/** Splits a draft into wire pages and deletes within LIVE_DRAFT_LIMITS. A duplicate path or a non-regular mode fails closed. */
|
|
13
|
+
export function planLiveDraft(draft, identity) {
|
|
14
|
+
const head = { artifactId: identity.artifactId, bindingGeneration: identity.bindingGeneration, revision: draft.revision };
|
|
15
|
+
const pages = [];
|
|
16
|
+
const deletes = [];
|
|
17
|
+
const seen = new Set();
|
|
18
|
+
let files = [];
|
|
19
|
+
let pageBytes = 0;
|
|
20
|
+
let total = 0;
|
|
21
|
+
const flush = () => {
|
|
22
|
+
if (files.length)
|
|
23
|
+
pages.push({ ...head, page: pages.length, files });
|
|
24
|
+
files = [];
|
|
25
|
+
pageBytes = 0;
|
|
26
|
+
};
|
|
27
|
+
for (const entry of draft.overlay) {
|
|
28
|
+
if (seen.has(entry.path))
|
|
29
|
+
unavailable();
|
|
30
|
+
seen.add(entry.path);
|
|
31
|
+
if (seen.size > LIVE_DRAFT_LIMITS.paths)
|
|
32
|
+
limit();
|
|
33
|
+
if (entry.text === null) {
|
|
34
|
+
deletes.push(entry.path);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const mode = modeOf(entry.mode);
|
|
38
|
+
const bytes = Buffer.from(entry.text, 'utf8');
|
|
39
|
+
if (bytes.byteLength > LIVE_DRAFT_LIMITS.fileBytes)
|
|
40
|
+
limit();
|
|
41
|
+
total += bytes.byteLength;
|
|
42
|
+
if (total > LIVE_DRAFT_LIMITS.totalBytes)
|
|
43
|
+
limit();
|
|
44
|
+
if (files.length && pageBytes + bytes.byteLength > LIVE_DRAFT_LIMITS.pageBytes)
|
|
45
|
+
flush();
|
|
46
|
+
files.push({ path: entry.path, mode, data: bytes.toString('base64') });
|
|
47
|
+
pageBytes += bytes.byteLength;
|
|
48
|
+
}
|
|
49
|
+
flush();
|
|
50
|
+
if (pages.length > LIVE_DRAFT_LIMITS.pages)
|
|
51
|
+
limit();
|
|
52
|
+
return { pages, seal: { ...head, pages: pages.length, baseHeadSha: draft.baseHeadSha, treeSha: draft.liveTreeSha, deletes } };
|
|
53
|
+
}
|
|
54
|
+
/** Stages the current draft: every page in order, then the seal. Anything but 204 is provider_unavailable. */
|
|
55
|
+
export async function stageLiveDraft(source, identity, send) {
|
|
56
|
+
const draft = await source.current(identity) ?? unavailable();
|
|
57
|
+
const plan = planLiveDraft(draft, identity);
|
|
58
|
+
for (const page of plan.pages)
|
|
59
|
+
if ((await send(LIVE_DRAFT_PATHS.page, page)).status !== 204)
|
|
60
|
+
unavailable();
|
|
61
|
+
if ((await send(LIVE_DRAFT_PATHS.seal, plan.seal)).status !== 204)
|
|
62
|
+
unavailable();
|
|
63
|
+
}
|
|
64
|
+
/** The LiveDraftSource of a host on the package LiveStore: the decrypted overlay of the current record. */
|
|
65
|
+
export function liveStoreDrafts(store, keys, now) {
|
|
66
|
+
const vault = createLiveDraftVault({ store, keys, ...(now ? { now } : {}) });
|
|
67
|
+
return {
|
|
68
|
+
async current(identity) {
|
|
69
|
+
const draft = await vault.read(identity);
|
|
70
|
+
return draft ? { revision: draft.revision, baseHeadSha: draft.baseHeadSha, liveTreeSha: draft.liveTreeSha, overlay: draft.overlay }
|
|
71
|
+
: undefined;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
@@ -8,3 +8,5 @@ export { publicationRecheck, RECHECK_REFUSALS, resolvePendingJob, type AttemptFe
|
|
|
8
8
|
export { acceptHandoff, type AcceptOptions, type HostLedger } from './accept.js';
|
|
9
9
|
export { encodeHandoffRequest, HOST_BUILD_PATHS, JOB_REQUEST_LIFETIME_MS, parseHandoffRequest, refusalFrom, refusalOf, sealJobRequest, verifyJobRequest, type HostBuildRefusal, type HostCandidateFile, type HostHandoffRequest, type HostHandoffResponse, type HostJobClaims, type HostJobRequest, type HostJobResponse, } from './api.js';
|
|
10
10
|
export { ASSERTION_HEADER, CONTROL_HEADER, FENCE_HEADER, MAX_ASSERTION_SECONDS, MAX_CONTROL_SECONDS, MAX_SKEW_SECONDS, MAX_SOURCE_REVISION_LENGTH, MIN_KEY_BYTES, signLiveAssertion, signLiveControl, signLiveFence, verifyLiveAssertion, verifyLiveControl, verifyLiveFence, type LiveAssertionClaims, type LiveControlClaims, type LiveFenceClaims, type VerifyOptions, } from './live-format.js';
|
|
11
|
+
export { LIVE_DRAFT_LIMITS, LIVE_DRAFT_PATHS, liveStoreDrafts, planLiveDraft, stageLiveDraft, type LiveDraftPageBody, type LiveDraftPageFile, type LiveDraftPlan, type LiveDraftSealBody, type LiveDraftSend, type LiveDraftSnapshot, type LiveDraftSource, } from './draft-stager.js';
|
|
12
|
+
export { createLiveWorkerClient, LIVE_WORKER_PATHS, liveStoreFences, type LiveBridgeAck, type LiveWorkerClientOptions, type LiveWorkerFences, } from './worker-client.js';
|
package/dist/live-host/index.js
CHANGED
|
@@ -8,3 +8,5 @@ export { publicationRecheck, RECHECK_REFUSALS, resolvePendingJob, } from './rech
|
|
|
8
8
|
export { acceptHandoff } from './accept.js';
|
|
9
9
|
export { encodeHandoffRequest, HOST_BUILD_PATHS, JOB_REQUEST_LIFETIME_MS, parseHandoffRequest, refusalFrom, refusalOf, sealJobRequest, verifyJobRequest, } from './api.js';
|
|
10
10
|
export { ASSERTION_HEADER, CONTROL_HEADER, FENCE_HEADER, MAX_ASSERTION_SECONDS, MAX_CONTROL_SECONDS, MAX_SKEW_SECONDS, MAX_SOURCE_REVISION_LENGTH, MIN_KEY_BYTES, signLiveAssertion, signLiveControl, signLiveFence, verifyLiveAssertion, verifyLiveControl, verifyLiveFence, } from './live-format.js';
|
|
11
|
+
export { LIVE_DRAFT_LIMITS, LIVE_DRAFT_PATHS, liveStoreDrafts, planLiveDraft, stageLiveDraft, } from './draft-stager.js';
|
|
12
|
+
export { createLiveWorkerClient, LIVE_WORKER_PATHS, liveStoreFences, } from './worker-client.js';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import type { GitBindingStore } from '../server/git-contracts.js';
|
|
3
|
+
import type { LiveInvitationState, LiveWorkerPort } from '../server/live-contracts.js';
|
|
4
|
+
import type { LiveIdentity, LiveStore } from '../server/live-store.js';
|
|
5
|
+
import { type LiveDraftSource } from './draft-stager.js';
|
|
6
|
+
/** Builder control paths of the host live API (s-archi contract 07/11), relative to the builder base URL. */
|
|
7
|
+
export declare const LIVE_WORKER_PATHS: Readonly<{
|
|
8
|
+
reconcile: "v1/live/reconcile";
|
|
9
|
+
stop: "v1/live/stop";
|
|
10
|
+
}>;
|
|
11
|
+
/** Host port: the live runtime of the package store record (owner, session and fences); undefined without a runtime. */
|
|
12
|
+
export interface LiveWorkerFences {
|
|
13
|
+
current(identity: LiveIdentity): Promise<{
|
|
14
|
+
ownerId: string;
|
|
15
|
+
liveSessionId: string;
|
|
16
|
+
leaseEpoch: number;
|
|
17
|
+
routeEpoch: number;
|
|
18
|
+
} | undefined>;
|
|
19
|
+
}
|
|
20
|
+
/** Builder answer of a reconcile; the package checks it against its own fences before marking the session LIVE. */
|
|
21
|
+
export interface LiveBridgeAck {
|
|
22
|
+
liveSessionId: string;
|
|
23
|
+
leaseEpoch: number;
|
|
24
|
+
routeEpoch: number;
|
|
25
|
+
revision: string;
|
|
26
|
+
ready: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface LiveWorkerClientOptions {
|
|
29
|
+
/** Builder base URL (https, no query or fragment); absent keeps every call closed with builder_unavailable. */
|
|
30
|
+
readonly baseUrl?: string | undefined;
|
|
31
|
+
/** S2S credential of the host (scope artifacts:builder); the builder takes the storage scope from it, never from a body. */
|
|
32
|
+
readonly identity?: {
|
|
33
|
+
authorization(): Promise<string>;
|
|
34
|
+
} | undefined;
|
|
35
|
+
readonly fetch?: typeof fetch;
|
|
36
|
+
/** Page, seal and stop calls (default 10 s). */
|
|
37
|
+
readonly timeoutMs?: number;
|
|
38
|
+
/** Reconcile call (default 30 s): the builder answers within its live wait (25 s in the product builder). */
|
|
39
|
+
readonly reconcileTimeoutMs?: number;
|
|
40
|
+
/** Host port: owner and fences of the current live runtime (see liveStoreFences). */
|
|
41
|
+
readonly fences: LiveWorkerFences;
|
|
42
|
+
/** Host port: the git binding of the artifact; only an attached binding of the exact generation is sent. */
|
|
43
|
+
readonly bindings: Pick<GitBindingStore, 'get'>;
|
|
44
|
+
/** Host port: the session invitation state of the live session (LiveSessionService.liveInvitationState). */
|
|
45
|
+
readonly sessionState: (identity: LiveIdentity, liveSessionId: string) => Promise<LiveInvitationState>;
|
|
46
|
+
/** Host port: the current durable draft, staged (pages, then seal) before every reconcile (see liveStoreDrafts). */
|
|
47
|
+
readonly drafts: LiveDraftSource;
|
|
48
|
+
}
|
|
49
|
+
/** The LiveWorkerFences of a host on the package LiveStore: ownerId and fences come from the record runtime. */
|
|
50
|
+
export declare function liveStoreFences(store: LiveStore): LiveWorkerFences;
|
|
51
|
+
/**
|
|
52
|
+
* HTTP LiveWorkerPort of the Sentropic builder, composed as the package LiveService `worker`. A reconcile reads the
|
|
53
|
+
* attached binding of the exact generation (else git_not_attached before any call), the runtime owner and fences,
|
|
54
|
+
* stages the current draft (pages, then seal), then posts the closed RECONCILE body; a stop posts the closed STOP body.
|
|
55
|
+
* Unconfigured: builder_unavailable. Transport error, non-200 reconcile, non-204 stop or page/seal, malformed ACK:
|
|
56
|
+
* provider_unavailable (the package keeps the durable intent for the fenced reconciliation).
|
|
57
|
+
*/
|
|
58
|
+
export declare function createLiveWorkerClient(options: LiveWorkerClientOptions): LiveWorkerPort;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { ArtifactOperationError } from '../server/failures.js';
|
|
2
|
+
import { stageLiveDraft } from './draft-stager.js';
|
|
3
|
+
/** Builder control paths of the host live API (s-archi contract 07/11), relative to the builder base URL. */
|
|
4
|
+
export const LIVE_WORKER_PATHS = Object.freeze({ reconcile: 'v1/live/reconcile', stop: 'v1/live/stop' });
|
|
5
|
+
const MAX_ANSWER_BYTES = 64 * 1024;
|
|
6
|
+
const ID = /^[A-Za-z0-9_-]{1,128}$/;
|
|
7
|
+
const REVISION = /^[\x21-\x7e]{1,256}$/;
|
|
8
|
+
/** The LiveWorkerFences of a host on the package LiveStore: ownerId and fences come from the record runtime. */
|
|
9
|
+
export function liveStoreFences(store) {
|
|
10
|
+
return {
|
|
11
|
+
async current(identity) {
|
|
12
|
+
const runtime = await store.transaction(identity, async (tx) => tx.record?.runtime ?? undefined);
|
|
13
|
+
return runtime ? { ownerId: runtime.ownerId, liveSessionId: runtime.liveSessionId, leaseEpoch: runtime.leaseEpoch,
|
|
14
|
+
routeEpoch: runtime.routeEpoch } : undefined;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function builderBase(raw) {
|
|
19
|
+
const base = new URL(raw);
|
|
20
|
+
if (base.protocol !== 'https:' || base.search || base.hash)
|
|
21
|
+
throw new ArtifactOperationError('builder_unavailable');
|
|
22
|
+
return new URL(base.pathname.endsWith('/') ? base.href : `${base.href}/`);
|
|
23
|
+
}
|
|
24
|
+
/** Reads the answer to completion and parses at most MAX_ANSWER_BYTES of JSON; anything else is undefined. */
|
|
25
|
+
async function boundedJson(response) {
|
|
26
|
+
if (!response.body)
|
|
27
|
+
return undefined;
|
|
28
|
+
const reader = response.body.getReader();
|
|
29
|
+
const chunks = [];
|
|
30
|
+
let size = 0;
|
|
31
|
+
try {
|
|
32
|
+
for (;;) {
|
|
33
|
+
const { done, value } = await reader.read();
|
|
34
|
+
if (done)
|
|
35
|
+
break;
|
|
36
|
+
size += value.byteLength;
|
|
37
|
+
if (size > MAX_ANSWER_BYTES) {
|
|
38
|
+
await reader.cancel().catch(() => undefined);
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
chunks.push(value);
|
|
42
|
+
}
|
|
43
|
+
const text = Buffer.concat(chunks).toString('utf8');
|
|
44
|
+
return text ? JSON.parse(text) : undefined;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const count = (value) => Number.isSafeInteger(value) && value >= 0;
|
|
51
|
+
function parseAck(raw) {
|
|
52
|
+
const r = raw;
|
|
53
|
+
if (!r || typeof r !== 'object' || typeof r.liveSessionId !== 'string' || !ID.test(r.liveSessionId) || !count(r.leaseEpoch)
|
|
54
|
+
|| !count(r.routeEpoch) || typeof r.revision !== 'string' || !REVISION.test(r.revision) || typeof r.ready !== 'boolean') {
|
|
55
|
+
throw new ArtifactOperationError('provider_unavailable');
|
|
56
|
+
}
|
|
57
|
+
return { liveSessionId: r.liveSessionId, leaseEpoch: r.leaseEpoch, routeEpoch: r.routeEpoch, revision: r.revision, ready: r.ready };
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* HTTP LiveWorkerPort of the Sentropic builder, composed as the package LiveService `worker`. A reconcile reads the
|
|
61
|
+
* attached binding of the exact generation (else git_not_attached before any call), the runtime owner and fences,
|
|
62
|
+
* stages the current draft (pages, then seal), then posts the closed RECONCILE body; a stop posts the closed STOP body.
|
|
63
|
+
* Unconfigured: builder_unavailable. Transport error, non-200 reconcile, non-204 stop or page/seal, malformed ACK:
|
|
64
|
+
* provider_unavailable (the package keeps the durable intent for the fenced reconciliation).
|
|
65
|
+
*/
|
|
66
|
+
export function createLiveWorkerClient(options) {
|
|
67
|
+
const base = options.baseUrl !== undefined && options.identity !== undefined ? builderBase(options.baseUrl) : undefined;
|
|
68
|
+
const bounded = (map, key, value) => {
|
|
69
|
+
if (!map.has(key) && map.size >= 4096)
|
|
70
|
+
map.delete(map.keys().next().value);
|
|
71
|
+
map.set(key, value);
|
|
72
|
+
};
|
|
73
|
+
/** Session epoch floor per binding generation: never lower than an epoch already sent (409 stale_invitation). */
|
|
74
|
+
const floors = new Map();
|
|
75
|
+
const floor = (identity, epoch) => {
|
|
76
|
+
const key = JSON.stringify([identity.storageScopeId, identity.artifactId, identity.bindingGeneration]);
|
|
77
|
+
const next = Math.max(floors.get(key) ?? 0, epoch);
|
|
78
|
+
bounded(floors, key, next);
|
|
79
|
+
return next;
|
|
80
|
+
};
|
|
81
|
+
/** One stage+reconcile or stop at a time per artifact in this client: a late seal never overwrites a newer revision. */
|
|
82
|
+
const lanes = new Map();
|
|
83
|
+
function serial(identity, run) {
|
|
84
|
+
const key = JSON.stringify([identity.storageScopeId, identity.artifactId]);
|
|
85
|
+
const next = (lanes.get(key) ?? Promise.resolve()).then(run);
|
|
86
|
+
const tail = next.then(() => undefined, () => undefined);
|
|
87
|
+
lanes.set(key, tail);
|
|
88
|
+
void tail.then(() => { if (lanes.get(key) === tail)
|
|
89
|
+
lanes.delete(key); });
|
|
90
|
+
return next;
|
|
91
|
+
}
|
|
92
|
+
async function call(path, body, timeoutMs = options.timeoutMs ?? 10_000) {
|
|
93
|
+
if (!base)
|
|
94
|
+
throw new ArtifactOperationError('builder_unavailable');
|
|
95
|
+
try {
|
|
96
|
+
const response = await (options.fetch ?? fetch)(new URL(path, base), { method: 'POST', redirect: 'error',
|
|
97
|
+
headers: { 'content-type': 'application/json', authorization: await options.identity.authorization() },
|
|
98
|
+
body: JSON.stringify(body), signal: AbortSignal.timeout(timeoutMs) });
|
|
99
|
+
return { status: response.status, payload: await boundedJson(response) };
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
if (error instanceof ArtifactOperationError)
|
|
103
|
+
throw error;
|
|
104
|
+
throw new ArtifactOperationError('provider_unavailable');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function reconcile(identity) {
|
|
108
|
+
const record = await options.bindings.get(identity.storageScopeId, identity.artifactId);
|
|
109
|
+
if (!record || record.state === 'detached' || record.generation !== identity.bindingGeneration) {
|
|
110
|
+
throw new ArtifactOperationError('git_not_attached');
|
|
111
|
+
}
|
|
112
|
+
const fences = await options.fences.current(identity);
|
|
113
|
+
if (!fences)
|
|
114
|
+
throw new ArtifactOperationError('provider_unavailable');
|
|
115
|
+
await stageLiveDraft(options.drafts, identity, (path, body) => call(path, body));
|
|
116
|
+
const session = await options.sessionState(identity, fences.liveSessionId);
|
|
117
|
+
const answer = await call(LIVE_WORKER_PATHS.reconcile, { artifactId: identity.artifactId,
|
|
118
|
+
bindingGeneration: identity.bindingGeneration, ownerId: fences.ownerId, liveSessionId: fences.liveSessionId,
|
|
119
|
+
leaseEpoch: fences.leaseEpoch, routeEpoch: fences.routeEpoch,
|
|
120
|
+
binding: { repoId: record.repoId, branch: record.branch, subPath: record.subPath },
|
|
121
|
+
invitation: { epoch: floor(identity, session.epoch), expiresAt: session.expiresAt } }, options.reconcileTimeoutMs ?? 30_000);
|
|
122
|
+
if (answer.status !== 200)
|
|
123
|
+
throw new ArtifactOperationError('provider_unavailable');
|
|
124
|
+
return parseAck(answer.payload);
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
async reconcile(identity) {
|
|
128
|
+
if (!base)
|
|
129
|
+
throw new ArtifactOperationError('builder_unavailable');
|
|
130
|
+
return serial(identity, () => reconcile(identity));
|
|
131
|
+
},
|
|
132
|
+
async stop(input) {
|
|
133
|
+
if (!base)
|
|
134
|
+
throw new ArtifactOperationError('builder_unavailable');
|
|
135
|
+
await serial(input, async () => {
|
|
136
|
+
const answer = await call(LIVE_WORKER_PATHS.stop, { artifactId: input.artifactId, bindingGeneration: input.bindingGeneration,
|
|
137
|
+
liveSessionId: input.liveSessionId, leaseEpoch: input.leaseEpoch });
|
|
138
|
+
if (answer.status !== 204)
|
|
139
|
+
throw new ArtifactOperationError('provider_unavailable');
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
};
|
|
143
|
+
}
|
package/dist/mcp-core.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ 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.
|
|
13
|
+
export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.24";
|
|
14
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", "artifacts_live_invite", "artifacts_live_accept_invitation", "artifacts_live_revoke_invitation", "artifacts_live_invitations"];
|
|
15
15
|
export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
|
|
16
16
|
export interface ArtifactsToolDefinition {
|
package/dist/mcp-core.js
CHANGED
|
@@ -7,7 +7,7 @@ export * from './profile/index.js';
|
|
|
7
7
|
export { createRadarKeyDerivation } from './server/command-identity.js';
|
|
8
8
|
export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
|
|
9
9
|
export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
|
|
10
|
-
export const ARTIFACTS_PROVIDER_VERSION = '0.2.
|
|
10
|
+
export const ARTIFACTS_PROVIDER_VERSION = '0.2.24';
|
|
11
11
|
export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
13
13
|
// Byte-stable tool definitions (MCP tool-definition stability rule).
|
|
@@ -5,7 +5,9 @@ import { validateGitBindingTarget } from './git-registry.js';
|
|
|
5
5
|
import { requireCodeRight, requireOwner } from './git-tools-publish.js';
|
|
6
6
|
const FIELDS = ['repoId', 'branch', 'baseRef', 'subPath', 'autoPublish', 'executor', 'pause'];
|
|
7
7
|
const id8 = (value) => createHash('sha256').update(value).digest('hex').slice(0, 8);
|
|
8
|
-
|
|
8
|
+
/** The git port reports an absent bound branch as git_branch_missing and any other absent ref as not_found. */
|
|
9
|
+
const notFound = (error) => error instanceof ArtifactOperationError &&
|
|
10
|
+
(error.kind === 'not_found' || error.kind === 'git_branch_missing');
|
|
9
11
|
/** G0 v3 §1.2 Tool 3 / A-LIVE S03: attach, configure, pause, resume or detach one binding. */
|
|
10
12
|
export async function attachGit(deps, args, inv) {
|
|
11
13
|
await requireOwner(deps, inv, args.artifactId, true);
|
|
@@ -116,69 +116,82 @@ export function createLiveService(deps) {
|
|
|
116
116
|
throw new ArtifactOperationError('invalid_request');
|
|
117
117
|
if (args.expectedHeadSha && args.expectedHeadSha !== head)
|
|
118
118
|
throw new ArtifactOperationError('git_head_moved', { publicDetails: { expectedHeadSha: args.expectedHeadSha, actualHeadSha: head } });
|
|
119
|
+
if (!deps.git.snapshot && !stop)
|
|
120
|
+
throw new ArtifactOperationError('capability_unselected');
|
|
121
|
+
// Only reads that list base entries walk the tree; status, start and reset need the base tree SHA only.
|
|
122
|
+
const fullTree = operation === 'live_write' || operation === 'live_read' ||
|
|
123
|
+
(operation === 'live_status' && Boolean(args.includeDiff || args.cursor));
|
|
119
124
|
let action = null;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
let result;
|
|
126
|
+
for (let attempt = 0; !result; attempt++) {
|
|
127
|
+
if (attempt === LIVE_PREFETCH_ATTEMPTS)
|
|
128
|
+
liveBusy('transition_busy');
|
|
129
|
+
// Base tree and ancestry forge calls run here, before the per-artifact advisory lock.
|
|
130
|
+
const prefetch = stop ? undefined : await prefetchLiveBase(deps, authority.target, identity, operation, head, fullTree);
|
|
131
|
+
const outcome = await deps.store.transaction(identity, async (tx) => {
|
|
132
|
+
const current = await deps.authorize(invocation, args.artifactId);
|
|
133
|
+
if (!stop && current.binding.generation !== identity.bindingGeneration || current.ownerId !== invocation.actorId &&
|
|
134
|
+
!(operation === 'live_read' && current.invited && current.canReadCode) ||
|
|
135
|
+
(!stop && !current.canReadCode))
|
|
136
|
+
throw new ArtifactOperationError('access_denied');
|
|
137
|
+
if (writer && !stop && (!current.canWrite || !current.humanLinked || current.binding.state !== 'attached'))
|
|
138
|
+
throw new ArtifactOperationError('access_denied');
|
|
139
|
+
if ((operation === 'live_write' || operation === 'live_control' && !stop) && !current.qualified)
|
|
140
|
+
throw new ArtifactOperationError('builder_unavailable');
|
|
141
|
+
authority = current;
|
|
142
|
+
if (command) {
|
|
143
|
+
const prior = await tx.receipt(command.actorId, command.key);
|
|
144
|
+
if (prior) {
|
|
145
|
+
if (prior.hash !== command.hash)
|
|
146
|
+
throw new ArtifactOperationError('command_conflict');
|
|
147
|
+
return { ...prior.result, replayed: true };
|
|
148
|
+
}
|
|
137
149
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
record.lastProgressEventId = 'head:' + head;
|
|
150
|
+
if (prefetch && !prefetch.covers(tx.record))
|
|
151
|
+
return LIVE_PREFETCH_STALE;
|
|
152
|
+
const base = stop ? { treeSha: tx.record?.baseTreeSha ?? '', entries: [] } : prefetch.base();
|
|
153
|
+
if (!tx.record)
|
|
154
|
+
tx.record = cleanLiveRecord(identity, head, base.treeSha, now());
|
|
155
|
+
const record = tx.record;
|
|
156
|
+
if (!stop && operation !== 'live_reset' && record.expiresAt && Date.parse(record.expiresAt) <= now())
|
|
157
|
+
throw new ArtifactOperationError('git_live_draft_expired');
|
|
158
|
+
if (!stop && record.latestVerifiedHeadSha !== head) {
|
|
159
|
+
const fastForward = prefetch.ancestor(record.latestVerifiedHeadSha);
|
|
160
|
+
if (!fastForward && writer)
|
|
161
|
+
throw new ArtifactOperationError('git_diverged');
|
|
162
|
+
if (fastForward) {
|
|
163
|
+
record.latestVerifiedHeadSha = head;
|
|
164
|
+
record.progressSeq++;
|
|
165
|
+
record.lastProgressEventId = 'head:' + head;
|
|
166
|
+
}
|
|
156
167
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
168
|
+
if (!stop && record.baseHeadSha !== head && !record.changedPaths) {
|
|
169
|
+
if (!prefetch.ancestor(record.baseHeadSha))
|
|
170
|
+
throw new ArtifactOperationError('git_diverged');
|
|
171
|
+
Object.assign(record, { revision: randomUUID(), baseHeadSha: head, baseTreeSha: base.treeSha, liveTreeSha: base.treeSha,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
if (operation === 'live_reset' && record.baseHeadSha !== head &&
|
|
175
|
+
!prefetch.ancestor(record.baseHeadSha))
|
|
160
176
|
throw new ArtifactOperationError('git_diverged');
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
await tx.complete(command, { ...mutation.result, revision: tx.record.revision });
|
|
180
|
-
return mutation.result;
|
|
181
|
-
});
|
|
177
|
+
const overlay = stop ? [] : operation === 'live_reset' && expired ? [] : await readLiveOverlay(tx, deps.keys);
|
|
178
|
+
if (operation === 'live_read' || operation === 'live_status')
|
|
179
|
+
return { ...liveResponse(record, head),
|
|
180
|
+
dirty: record.changedPaths > 0, changedPaths: record.changedPaths, draftBytes: record.draftBytes,
|
|
181
|
+
jobId: binding.pendingJobId, publicationIntent: record.progressSeq > record.publicationBaselineSeq && binding.autoPublish ? 'deferred' : null,
|
|
182
|
+
retentionWarning: record.expiresAt && Date.parse(record.expiresAt) - now() < 86400000 ? 'expires_within_24_hours' : null,
|
|
183
|
+
...(operation === 'live_read' || args.includeDiff || args.cursor ? await readLivePage({ git: deps.git, authority, record,
|
|
184
|
+
overlay, base, args, invocation, kind: operation === 'live_read' ? 'read' : 'diff', now: now() }) : { nextCursor: null }) };
|
|
185
|
+
if (stop && !authority.canReadCode)
|
|
186
|
+
args.expectedLiveRevision = record.revision;
|
|
187
|
+
const mutation = await mutateLive({ deps, tx, authority, operation, args, base, overlay, currentHeadSha: head, now: now() });
|
|
188
|
+
action = mutation.action;
|
|
189
|
+
await tx.complete(command, { ...mutation.result, revision: tx.record.revision });
|
|
190
|
+
return mutation.result;
|
|
191
|
+
});
|
|
192
|
+
if (outcome !== LIVE_PREFETCH_STALE)
|
|
193
|
+
result = outcome;
|
|
194
|
+
}
|
|
182
195
|
if (!result.replayed && action) {
|
|
183
196
|
const settling = settleLiveWorker({ deps, identity, action, result, now: now() });
|
|
184
197
|
if (action === 'stop')
|
|
@@ -189,3 +202,36 @@ export function createLiveService(deps) {
|
|
|
189
202
|
return narrowStop ? { liveSessionId: result.liveSessionId, state: result.state } : result;
|
|
190
203
|
} };
|
|
191
204
|
}
|
|
205
|
+
const LIVE_PREFETCH_ATTEMPTS = 3;
|
|
206
|
+
// A string (not a symbol): store adapters clone transaction results.
|
|
207
|
+
const LIVE_PREFETCH_STALE = 'live-prefetch-stale';
|
|
208
|
+
const settle = (pending) => pending.then(value => ({ ok: true, value }), error => ({ ok: false, error }));
|
|
209
|
+
const take = (settled) => { if (!settled.ok)
|
|
210
|
+
throw settled.error; return settled.value; };
|
|
211
|
+
/** Reads the draft fence in a short transaction, then performs every forge call outside the advisory lock.
|
|
212
|
+
* Failures are replayed at their original use site inside the locked transaction, so error precedence is unchanged. */
|
|
213
|
+
async function prefetchLiveBase(deps, target, identity, operation, head, fullTree) {
|
|
214
|
+
const fence = (record) => record ? JSON.stringify([record.changedPaths > 0, record.baseHeadSha,
|
|
215
|
+
record.latestVerifiedHeadSha]) : null;
|
|
216
|
+
const peek = await deps.store.transaction(identity, async (tx) => tx.record ? structuredClone(tx.record) : undefined);
|
|
217
|
+
const baseSha = operation === 'live_reset' || !peek?.changedPaths ? head : peek.baseHeadSha;
|
|
218
|
+
const ancestors = [...new Set([peek?.latestVerifiedHeadSha,
|
|
219
|
+
peek && (!peek.changedPaths || operation === 'live_reset') ? peek.baseHeadSha : undefined])]
|
|
220
|
+
.filter((sha) => Boolean(sha) && sha !== head);
|
|
221
|
+
const [base, ...ancestry] = await Promise.all([
|
|
222
|
+
settle(fullTree ? deps.git.snapshot(target, baseSha) :
|
|
223
|
+
deps.git.inspectCommit(target, baseSha).then(commit => ({ treeSha: commit.treeSha, entries: [] }))),
|
|
224
|
+
...ancestors.map(sha => settle(deps.git.isAncestor(target, sha, head))),
|
|
225
|
+
]);
|
|
226
|
+
const known = new Map(ancestors.map((sha, index) => [sha, ancestry[index]]));
|
|
227
|
+
return {
|
|
228
|
+
covers: (record) => fence(record) === fence(peek),
|
|
229
|
+
base: () => take(base),
|
|
230
|
+
ancestor(sha) {
|
|
231
|
+
const settled = known.get(sha);
|
|
232
|
+
if (!settled)
|
|
233
|
+
liveBusy('stale_fence');
|
|
234
|
+
return take(settled);
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sentropic/artifacts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.24",
|
|
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",
|