@sentropic/artifacts 0.2.12 → 0.2.13

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/README.md +45 -10
  3. package/dist/adapters/postgres-management.js +3 -2
  4. package/dist/adapters/postgres-reader-consent.d.ts +11 -0
  5. package/dist/adapters/postgres-reader-consent.js +109 -0
  6. package/dist/adapters/postgres.js +4 -3
  7. package/dist/adapters/s3-uploads.d.ts +33 -0
  8. package/dist/adapters/s3-uploads.js +105 -0
  9. package/dist/content/headers.js +12 -0
  10. package/dist/http.d.ts +16 -2
  11. package/dist/http.js +325 -12
  12. package/dist/mcp-core.d.ts +3 -3
  13. package/dist/mcp-core.js +51 -4
  14. package/dist/profile/contracts.d.ts +1 -1
  15. package/dist/profile/contracts.js +3 -0
  16. package/dist/profile/index.js +33 -2
  17. package/dist/profile/radar.js +7 -0
  18. package/dist/profile/schemas.js +59 -0
  19. package/dist/profile/validation.d.ts +11 -0
  20. package/dist/profile/validation.js +71 -6
  21. package/dist/server/access.d.ts +2 -0
  22. package/dist/server/command-identity.d.ts +1 -1
  23. package/dist/server/command-identity.js +5 -3
  24. package/dist/server/consent.d.ts +65 -0
  25. package/dist/server/consent.js +42 -0
  26. package/dist/server/gc.d.ts +17 -0
  27. package/dist/server/gc.js +22 -0
  28. package/dist/server/management.d.ts +3 -1
  29. package/dist/server/management.js +48 -7
  30. package/dist/server/mime.d.ts +26 -2
  31. package/dist/server/mime.js +124 -2
  32. package/dist/server/ports.d.ts +29 -0
  33. package/dist/server/ports.js +11 -0
  34. package/dist/server/publication-limits.d.ts +12 -0
  35. package/dist/server/publication-limits.js +19 -1
  36. package/dist/server/publication.d.ts +9 -0
  37. package/dist/server/publication.js +4 -2
  38. package/dist/server/reader-store.d.ts +58 -0
  39. package/dist/server/reader-store.js +109 -0
  40. package/dist/server/templates.js +50 -2
  41. package/dist/server/uploads.d.ts +154 -18
  42. package/dist/server/uploads.js +227 -80
  43. package/migrations/0007_uploads.sql +43 -0
  44. package/migrations/0008_reader_consent.sql +48 -0
  45. package/package.json +22 -1
  46. package/sql/reader-consent.sql +47 -0
package/dist/http.js CHANGED
@@ -5,8 +5,13 @@ import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './pro
5
5
  import { createArtifactCommand } from './server/command-identity.js';
6
6
  import { createGuardedEnsureService } from './server/service.js';
7
7
  import { assertArtifactReplayMigration } from './server/idempotency.js';
8
- import { combineSharingPolicy, resolveSharingPolicy } from './server/ports.js';
9
- import { createGuardedPublicationService } from './server/publication.js';
8
+ import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy } from './server/ports.js';
9
+ import { createGuardedPublicationService, resolveBlobConcurrency, runBlobPool, verifyStagedBlobs } from './server/publication.js';
10
+ import { SERVER_MAX_FILE_BYTES, SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL } from './server/publication-limits.js';
11
+ import { releaseBudget } from './profile/validation.js';
12
+ import { createUploadService, stagingKey } from './server/uploads.js';
13
+ import { accessModeOf, evaluateGrant } from './server/access.js';
14
+ import { assertConsentScopeId } from './server/consent.js';
10
15
  import { applyEdits } from './server/edits.js';
11
16
  import { CommitQuarantineError } from './server/commit/types.js';
12
17
  import { ArtifactOperationError, classifyArtifactFailure } from './server/failures.js';
@@ -16,7 +21,7 @@ import { artifactSummary } from './server/summary.js';
16
21
  import { artifactVersions } from './server/versions.js';
17
22
  import { manageArtifact } from './server/management.js';
18
23
  import { createPostgresManagementUnit } from './adapters/postgres-management.js';
19
- import { TEXT_MIME_RE } from './server/mime.js';
24
+ import { TEXT_MIME_RE, validateFileBytes } from './server/mime.js';
20
25
  import { API_GUIDE_REF } from './server/templates.js';
21
26
  export { projectArtifactHttpOutcome } from './server/outcome-projection.js';
22
27
  /** Stable content-route error codes; private driver messages never leave the host. */
@@ -36,7 +41,10 @@ function object(value) {
36
41
  export function assertArtifactsTransportProfile(value) {
37
42
  assertCompiledArtifactsProfile(value);
38
43
  const supported = ['artifacts_ensure', 'artifacts_publish', 'artifacts_list', 'artifacts_get',
39
- 'artifacts_list_versions', 'artifacts_get_source', 'artifacts_revert', 'artifacts_set_access', 'artifacts_delete'];
44
+ 'artifacts_list_versions', 'artifacts_get_source', 'artifacts_revert', 'artifacts_set_access', 'artifacts_delete',
45
+ 'artifacts_lookup_people', 'artifacts_list_access',
46
+ 'artifacts_create_upload', 'artifacts_commit_upload', 'artifacts_publish_bundle',
47
+ 'artifacts_revoke_reader_consent'];
40
48
  if (value.selectedCapabilities.some((name) => !supported.includes(name))) {
41
49
  throw new Error('unsupported artifacts transport capability');
42
50
  }
@@ -58,6 +66,14 @@ export function createHttpArtifactApp(deps) {
58
66
  if (profile.selectedCapabilities.includes('artifacts_delete') && !deps.management?.confirmation) {
59
67
  throw new Error('artifact delete confirmation port required');
60
68
  }
69
+ // Files parity LOT 1: upload ports are required as soon as one upload capability is selected.
70
+ const uploadCapabilities = ['artifacts_create_upload', 'artifacts_commit_upload', 'artifacts_publish_bundle'];
71
+ const needsUploads = uploadCapabilities.some((name) => profile.selectedCapabilities.includes(name));
72
+ if (needsUploads && !deps.uploads)
73
+ throw new Error('artifact upload ports required');
74
+ const budget = releaseBudget(profile);
75
+ const uploadService = deps.uploads === undefined ? undefined : createUploadService({ sessions: deps.uploads.sessions, staging: deps.uploads.staging, signer: deps.uploads.signer }, { maxUploadBytes: Math.min(budget.fileBytesMax, SERVER_MAX_FILE_BYTES),
76
+ maxSessionsPerPrincipal: SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL });
61
77
  const ensure = createGuardedEnsureService({ profile, coordinator: deps.coordinator,
62
78
  derivation: deps.derivation, host: {
63
79
  lockBinding: (client, binding) => deps.ensureHost.lockBinding(client, binding),
@@ -130,6 +146,54 @@ export function createHttpArtifactApp(deps) {
130
146
  meta.icon = normalized.icon;
131
147
  return Object.keys(meta).length > 0 ? meta : undefined;
132
148
  }
149
+ /**
150
+ * G2 projection (converged-r2 §2.3): no internal principal id (`sub`) ever
151
+ * reaches a model payload. When a directory port is wired, every summary
152
+ * `ownerId` and grant `principalId` keeps its field name but carries the
153
+ * opaque `userRef` (re-injectable into `set_access`). Without a port the
154
+ * legacy trusted form is kept (G1 behaviour).
155
+ */
156
+ async function projectUserRef(internalId, storageScopeId) {
157
+ if (!deps.directory)
158
+ return internalId;
159
+ return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? internalId;
160
+ }
161
+ async function projectSummary(summary, storageScopeId) {
162
+ if (!deps.directory)
163
+ return summary;
164
+ return { ...summary, ownerId: await projectUserRef(summary.ownerId, storageScopeId) };
165
+ }
166
+ async function projectGrants(grants, storageScopeId) {
167
+ if (!deps.directory)
168
+ return grants;
169
+ return Promise.all(grants.map(async (grant) => ({ ...grant,
170
+ principalId: await projectUserRef(grant.principalId, storageScopeId) })));
171
+ }
172
+ /**
173
+ * G2 visibility for `artifacts_list_access` (§2.3 order (2), same admin
174
+ * exception as `set_access`): the owner, a grant holder, a content reader
175
+ * or an APPROVED platform admin of the SAME storageScopeId pass; any other
176
+ * actor gets `not_found` so the artifact's existence never leaks. The
177
+ * exception never makes the admin a content reader.
178
+ */
179
+ async function visibleForAccessList(artifactId, invocation) {
180
+ const acl = await deps.acls.getArtifactAcl(artifactId);
181
+ if (!acl || acl.storageScopeId !== invocation.storageScopeId)
182
+ throw new ArtifactOperationError('not_found');
183
+ if (acl.ownerId === invocation.actorId)
184
+ return acl;
185
+ if (acl.grants.some((grant) => grant.principalId === invocation.actorId))
186
+ return acl;
187
+ const state = await deps.lifecycle.stateOf(artifactId);
188
+ const policy = await sharingPolicyContext(invocation.storageScopeId);
189
+ if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, policy)) {
190
+ return acl;
191
+ }
192
+ if (await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
193
+ deps.isApprovedAccount?.(invocation.actorId) === true)
194
+ return acl;
195
+ throw new ArtifactOperationError('not_found');
196
+ }
133
197
  function blobKey(storageScopeId, digest) {
134
198
  // Manifest digests are `sha256:<hex>`; physical keys are `.../blobs/sha256/<hex>`.
135
199
  return `artifacts/${storageScopeId}/blobs/${digest.replace(':', '/')}`;
@@ -269,7 +333,8 @@ export function createHttpArtifactApp(deps) {
269
333
  }
270
334
  }
271
335
  const normalized = profile.validate(capability, args, request.idempotencyKey, { deferPrecondition: true });
272
- const command = ['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'].includes(capability)
336
+ const command = ['artifacts_ensure', 'artifacts_publish', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
337
+ 'artifacts_commit_upload', 'artifacts_publish_bundle'].includes(capability)
273
338
  ? createArtifactCommand(profile, capability, args, invocation, deps.derivation, request.idempotencyKey, { deferPrecondition: true }) : undefined;
274
339
  if (command && ['ensure', 'publish'].includes(command.operation)) {
275
340
  phase = 'migration';
@@ -289,10 +354,10 @@ export function createHttpArtifactApp(deps) {
289
354
  return outcome;
290
355
  const artifactId = outcome.result.artifactId;
291
356
  const acl = await visible(artifactId, invocation);
292
- const summary = artifactSummary({ artifactId, acl, actorId: invocation.actorId,
357
+ const summary = await projectSummary(artifactSummary({ artifactId, acl, actorId: invocation.actorId,
293
358
  state: await deps.lifecycle.stateOf(artifactId), current: await deps.publication.getCurrent(artifactId),
294
359
  urls: deps.publicationUrls, approved: deps.isApprovedAccount,
295
- policy: await sharingPolicyContext(invocation.storageScopeId) });
360
+ policy: await sharingPolicyContext(invocation.storageScopeId) }), invocation.storageScopeId);
296
361
  return { ...outcome, result: { status: 201, body: profile.resultEnvelopeVersion === 2
297
362
  ? { ...summary, ...outcome.result } : { ...outcome.result, ...acl.metadata } } };
298
363
  }
@@ -328,10 +393,37 @@ export function createHttpArtifactApp(deps) {
328
393
  sharingPolicy: deps.sharingPolicy,
329
394
  profileAllowPublicSharing: profile.rules.allowPublicSharing,
330
395
  actorIsAdmin: deps.actorIsAdmin,
396
+ directory: deps.directory,
331
397
  validateNewCommand: () => { profile.validate(capability, args, request.idempotencyKey); },
332
398
  }, invocation, command, normalized.confirmationRef);
333
399
  return outcome.ok ? { ...outcome, result: { status: 200, body: outcome.result } } : outcome;
334
400
  }
401
+ if (capability === 'artifacts_revoke_reader_consent') {
402
+ // Self-revocation only: the reader is the invocation principal
403
+ // (mcp-core.ts:225); no principalId argument exists, so the model
404
+ // can never target another person. Error order: syntax (validated
405
+ // above) → visibility (not_found, no existence oracle) → store
406
+ // gate (capability_unavailable when no port is wired).
407
+ const artifactId = normalized.artifactId;
408
+ await visible(artifactId, invocation);
409
+ const store = deps.readerConsent;
410
+ if (!store)
411
+ throw new ArtifactProfileInputError(true);
412
+ const scope = normalized.scope;
413
+ if (scope !== undefined)
414
+ assertConsentScopeId(scope);
415
+ const at = new Date().toISOString();
416
+ // The route serves the MCP revocation tool; the api binding records
417
+ // first-party screen/api surfaces through the service layer instead.
418
+ const audit = { actor: invocation.actorId, surface: 'mcp' };
419
+ const result = await store.revokeAllConsents({ storageScopeId: invocation.storageScopeId,
420
+ readerAccountId: invocation.actorId, artifactId, ...(scope === undefined ? {} : { scopeId: scope }) }, 'self', at, audit);
421
+ return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed',
422
+ replayed: false, result: { status: 200, body: scope === undefined
423
+ ? { artifactId, scopeId: null, changed: result.changed, revoked: result.revoked }
424
+ : { artifactId, scopeId: scope, changed: result.changed,
425
+ revokedAt: result.changed ? at : null } } };
426
+ }
335
427
  if (capability === 'artifacts_publish' || capability === 'artifacts_revert') {
336
428
  const artifactId = normalized.artifactId;
337
429
  const acl = await visible(artifactId, invocation);
@@ -383,23 +475,205 @@ export function createHttpArtifactApp(deps) {
383
475
  source = { kind: 'base-commit', commit: releaseId };
384
476
  releaseProfile = (targetManifest.profile ?? {});
385
477
  }
478
+ if (capability === 'artifacts_publish') {
479
+ // B.2 MIME ceiling: magic-byte / strict-UTF-8 / SVG validation on every
480
+ // newly published file (revert re-releases already-verified blobs).
481
+ for (const file of files)
482
+ validateFileBytes(file.mimeType, file.bytes);
483
+ }
386
484
  const outcome = await publication.publishFinalized({
387
485
  ...input, source, profile: releaseProfile, files,
388
486
  });
389
487
  const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
390
488
  return await conflictSource(committed, normalized, invocation);
391
489
  }
490
+ if (capability === 'artifacts_create_upload') {
491
+ const artifactId = normalized.artifactId;
492
+ const acl = await visible(artifactId, invocation);
493
+ if (acl.ownerId !== invocation.actorId)
494
+ throw new ArtifactOperationError('access_denied');
495
+ let created;
496
+ try {
497
+ created = await uploadService.create({
498
+ artifactId, storageScopeId: invocation.storageScopeId, ownerId: acl.ownerId,
499
+ mimeType: normalized.mimeType,
500
+ ...(normalized.maxSize === undefined ? {} : { maxSize: normalized.maxSize }),
501
+ });
502
+ }
503
+ catch (cause) {
504
+ if (cause instanceof Error && /quota exceeded/.test(cause.message)) {
505
+ throw new ArtifactOperationError('limit_exceeded', { cause,
506
+ publicDetails: { upload: { reason: 'open_session_quota' } } });
507
+ }
508
+ if (cause instanceof Error && /invalid/.test(cause.message))
509
+ throw new ArtifactProfileInputError();
510
+ throw cause;
511
+ }
512
+ return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
513
+ result: { status: 201, body: { uploadId: created.uploadId, uploadUrl: created.uploadUrl,
514
+ method: created.method, expiresAt: created.expiresAt, maxSize: created.maxSize,
515
+ requiredHeaders: created.requiredHeaders, checksumHeader: created.checksumHeader } } };
516
+ }
517
+ if (capability === 'artifacts_commit_upload') {
518
+ const artifactId = normalized.artifactId;
519
+ const acl = await visible(artifactId, invocation);
520
+ if (acl.ownerId !== invocation.actorId)
521
+ throw new ArtifactOperationError('access_denied');
522
+ const uploadId = normalized.uploadId;
523
+ const digest = normalized.digest;
524
+ const size = normalized.size;
525
+ const mimeType = normalized.mimeType;
526
+ const path = normalized.path;
527
+ const commitInput = { uploadId, artifactId, storageScopeId: invocation.storageScopeId,
528
+ ownerId: acl.ownerId, path, mimeType, digest, size };
529
+ const work = async () => {
530
+ let session;
531
+ try {
532
+ session = await uploadService.sessionForCommit(commitInput);
533
+ }
534
+ catch (cause) {
535
+ // One response for unknown, foreign-bound, closed or expired sessions (no oracle).
536
+ throw new ArtifactOperationError('verification_failed', { cause,
537
+ publicDetails: { upload: { reason: 'session unknown, bound elsewhere, closed or expired' } } });
538
+ }
539
+ const key = stagingKey(invocation.storageScopeId, uploadId);
540
+ const bytes = await deps.uploads.staging.get(key);
541
+ if (bytes === undefined) {
542
+ throw new ArtifactOperationError('verification_failed', { publicDetails: { upload: { reason: 'staged object missing' } } });
543
+ }
544
+ // Re-verify declared size + digest + MIME against the staged bytes (review finding 3).
545
+ try {
546
+ uploadService.verifyStaged(session, bytes, { digest, size, mimeType });
547
+ }
548
+ catch (cause) {
549
+ throw new ArtifactOperationError('verification_failed', { cause,
550
+ publicDetails: { upload: { reason: 'size/digest/MIME mismatch' } } });
551
+ }
552
+ // Promote to the digest-addressed CAS blob via the #907 bounded pool + read-back.
553
+ const casKey = blobKey(invocation.storageScopeId, digest);
554
+ const concurrency = resolveBlobConcurrency(deps.publication.blobConcurrency);
555
+ await runBlobPool([{ key: casKey, bytes }], { concurrency }, async (item) => { await deps.publication.blobs.putBlob(item.key, item.bytes); });
556
+ await verifyStagedBlobs(deps.publication.blobs, [{ key: casKey, bytes }], { concurrency });
557
+ const pinReason = `upload:${uploadId}`;
558
+ await deps.publication.refs.pin(digest, pinReason);
559
+ let staged;
560
+ try {
561
+ staged = await uploadService.completeCommit(session, { path, mimeType, digest, size });
562
+ }
563
+ catch (cause) {
564
+ await deps.publication.refs.unpin(digest, pinReason).catch(() => undefined);
565
+ throw cause;
566
+ }
567
+ await deps.uploads.staging.delete(key);
568
+ return { artifactId, uploadId, path, mimeType, digest, size, state: 'staged', stagedAt: staged.createdAt };
569
+ };
570
+ let body;
571
+ if (deps.uploads.idempotency !== undefined && command !== undefined) {
572
+ // Same key + same digest replays; same key + different payload is command_conflict.
573
+ const storeKey = JSON.stringify(['commit_upload', acl.ownerId, normalized.idempotencyKey]);
574
+ try {
575
+ const { result } = await deps.uploads.idempotency.execute(storeKey, command.identity.commandHash, work);
576
+ body = result;
577
+ }
578
+ catch (cause) {
579
+ if (cause instanceof Error && /idempotency conflict/.test(cause.message)) {
580
+ throw new ArtifactOperationError('command_conflict', { cause });
581
+ }
582
+ throw cause;
583
+ }
584
+ }
585
+ else {
586
+ body = await work();
587
+ }
588
+ return { ok: true, invocationId: invocation.invocationId, commitState: 'committed', replayed: false,
589
+ result: { status: 201, body } };
590
+ }
591
+ if (capability === 'artifacts_publish_bundle') {
592
+ const artifactId = normalized.artifactId;
593
+ const acl = await visible(artifactId, invocation);
594
+ if (acl.ownerId !== invocation.actorId)
595
+ throw new ArtifactOperationError('access_denied');
596
+ const publication = createGuardedPublicationService({ ...deps.publication, coordinator: deps.coordinator,
597
+ limits: { maxFiles: budget.filesMax, maxFileBytes: budget.fileBytesMax, maxTotalBytes: budget.totalBytesMax } });
598
+ const meta = metadataOf(normalized);
599
+ const input = { ownerId: acl.ownerId, storageScopeId: invocation.storageScopeId, artifactId,
600
+ identity: command.identity, actorId: invocation.actorId, invocationId: invocation.invocationId,
601
+ attemptId: invocation.invocationId, policyRevision: await deps.ensureHost.readPolicyRevision(),
602
+ authorizeCommit: invocation.authorizeCommit, metadata: meta, operation: 'publish',
603
+ expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
604
+ const replay = await publication.replayFinalized(input);
605
+ if (replay !== undefined)
606
+ return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
607
+ profile.validate(capability, args, request.idempotencyKey);
608
+ // Resolve the files/assets union BEFORE any commit step: one missing or
609
+ // digest-mismatched asset fails the whole publish and commits nothing.
610
+ const files = [];
611
+ const origins = {};
612
+ for (const file of (normalized.files ?? [])) {
613
+ const bytes = Uint8Array.from(file.bytes);
614
+ validateFileBytes(file.mimeType, bytes);
615
+ files.push({ path: file.path, mimeType: file.mimeType, bytes });
616
+ origins[file.path] = 'inline';
617
+ }
618
+ for (const asset of (normalized.assets ?? [])) {
619
+ const path = asset.path;
620
+ if (Object.hasOwn(asset, 'uploadId')) {
621
+ const staged = await deps.uploads.sessions.getStagedFile(asset.uploadId);
622
+ if (staged === undefined || staged.artifactId !== artifactId) {
623
+ throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'unknown upload' } } });
624
+ }
625
+ const bytes = await deps.publication.blobs.getBlob(blobKey(invocation.storageScopeId, staged.digest));
626
+ if (bytes === undefined || bytes.length !== staged.size ||
627
+ `sha256:${createHash('sha256').update(bytes).digest('hex')}` !== staged.digest) {
628
+ throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'staged blob missing or digest mismatch' } } });
629
+ }
630
+ validateFileBytes(staged.mimeType, bytes);
631
+ files.push({ path, mimeType: staged.mimeType, bytes });
632
+ origins[path] = `upload:${staged.uploadId}`;
633
+ }
634
+ else {
635
+ const digest = asset.digest;
636
+ const size = asset.size;
637
+ const mimeType = asset.mimeType;
638
+ const bytes = await deps.publication.blobs.getBlob(blobKey(invocation.storageScopeId, digest));
639
+ if (bytes === undefined) {
640
+ throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'blob missing' } } });
641
+ }
642
+ if (bytes.length !== size || `sha256:${createHash('sha256').update(bytes).digest('hex')}` !== digest) {
643
+ throw new ArtifactOperationError('verification_failed', { publicDetails: { asset: { path, reason: 'size/digest mismatch' } } });
644
+ }
645
+ validateFileBytes(mimeType, bytes);
646
+ files.push({ path, mimeType, bytes });
647
+ origins[path] = 'cas';
648
+ }
649
+ }
650
+ const outcome = await publication.publishFinalized({
651
+ ...input, source: { kind: 'inline-original' },
652
+ profile: normalized.profile, files,
653
+ });
654
+ const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
655
+ if (committed.ok) {
656
+ const parsedBundleManifest = parseManifest(committed.result.body.manifest);
657
+ const entries = parsedBundleManifest.files ?? [];
658
+ committed.result.body.files = entries.map((entry) => ({
659
+ path: entry.path, mimeType: entry.mimeType, size: entry.size, digest: entry.digest,
660
+ origin: origins[entry.path] ?? 'inline',
661
+ }));
662
+ }
663
+ return committed;
664
+ }
392
665
  if (capability === 'artifacts_get') {
393
666
  const artifactId = normalized.artifactId;
394
667
  const acl = await visible(artifactId, invocation);
395
668
  const state = await deps.lifecycle.stateOf(artifactId);
396
669
  const current = await deps.publication.getCurrent(artifactId);
397
670
  return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
398
- result: { status: 200, body: { ...artifactSummary({ artifactId, acl, state, current,
671
+ result: { status: 200, body: { ...await projectSummary(artifactSummary({ artifactId, acl, state, current,
399
672
  actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount,
400
- policy: await sharingPolicyContext(invocation.storageScopeId) }),
673
+ policy: await sharingPolicyContext(invocation.storageScopeId) }), invocation.storageScopeId),
401
674
  ...(acl.metadata !== undefined ? { metadata: acl.metadata } : {}),
402
- ...(acl.ownerId === invocation.actorId ? { grants: acl.grants } : {}) } } };
675
+ ...(acl.ownerId === invocation.actorId
676
+ ? { grants: await projectGrants(acl.grants, invocation.storageScopeId) } : {}) } } };
403
677
  }
404
678
  if (capability === 'artifacts_list_versions') {
405
679
  const artifactId = normalized.artifactId;
@@ -426,6 +700,45 @@ export function createHttpArtifactApp(deps) {
426
700
  return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
427
701
  result: { status: 200, body: { artifactId, total: releases.length, releases } } };
428
702
  }
703
+ if (capability === 'artifacts_lookup_people') {
704
+ // G2 approved-caller guard: the tool has no artifactId, so no visible()
705
+ // carries this check — a pending/disabled account gets access_denied
706
+ // before any directory enumeration.
707
+ if (deps.isApprovedAccount?.(invocation.actorId) !== true)
708
+ throw new ArtifactOperationError('access_denied');
709
+ if (!deps.directory)
710
+ throw new ArtifactProfileInputError(true);
711
+ const matches = await deps.directory.searchPeople(invocation.storageScopeId, normalized.query, normalized.limit);
712
+ return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
713
+ result: { status: 200, body: { matches: matches.map((person) => ({ userRef: person.userRef,
714
+ displayName: person.displayName, emailHint: maskEmailHint(person.email) })) } } };
715
+ }
716
+ if (capability === 'artifacts_list_access') {
717
+ const artifactId = normalized.artifactId;
718
+ const acl = await visibleForAccessList(artifactId, invocation);
719
+ if (!deps.directory)
720
+ throw new ArtifactProfileInputError(true);
721
+ const admin = await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
722
+ deps.isApprovedAccount?.(invocation.actorId) === true;
723
+ const canManage = acl.ownerId === invocation.actorId || admin;
724
+ // Owner and admin see the full list; a simple reader sees the mode and its own entry only.
725
+ const visibleGrants = canManage ? acl.grants
726
+ : acl.grants.filter((grant) => grant.principalId === invocation.actorId);
727
+ const grants = await Promise.all(visibleGrants.map(async (grant) => {
728
+ const person = await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId);
729
+ const userRef = person?.userRef ?? grant.principalId;
730
+ const { effective, blockedBy } = evaluateGrant(acl, grant.principalId, deps.isApprovedAccount ?? (() => false));
731
+ return { userRef, displayName: person?.displayName ?? userRef,
732
+ ...(person === undefined ? {} : { emailHint: maskEmailHint(person.email) }),
733
+ grant: grant.grant, createdAt: grant.createdAt ?? null, effective,
734
+ ...(blockedBy === undefined ? {} : { blockedBy }) };
735
+ }));
736
+ const owner = await deps.directory.describePrincipal(invocation.storageScopeId, acl.ownerId);
737
+ return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
738
+ result: { status: 200, body: { artifactId, accessMode: accessModeOf(acl),
739
+ owner: { userRef: owner?.userRef ?? acl.ownerId, displayName: owner?.displayName ?? acl.ownerId },
740
+ canManage, grants } } };
741
+ }
429
742
  const visibleArtifacts = [];
430
743
  const listPolicy = await sharingPolicyContext(invocation.storageScopeId);
431
744
  for (const artifactId of await deps.acls.listArtifactIds()) {
@@ -434,9 +747,9 @@ export function createHttpArtifactApp(deps) {
434
747
  continue;
435
748
  const state = await deps.lifecycle.stateOf(artifactId);
436
749
  if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, listPolicy)) {
437
- visibleArtifacts.push(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
750
+ visibleArtifacts.push(await projectSummary(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
438
751
  current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls,
439
- approved: deps.isApprovedAccount, policy: listPolicy }));
752
+ approved: deps.isApprovedAccount, policy: listPolicy }), invocation.storageScopeId));
440
753
  }
441
754
  }
442
755
  const offset = normalized.offset;
@@ -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.12";
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"];
13
+ export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.13";
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"];
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_ensure" | "artifacts_publish" | "artifacts_set_access" | "artifacts_delete" | "artifacts_revert" | "artifacts_get_template" | "artifacts_get_api_guide" | "artifacts_create_upload" | "artifacts_commit_upload" | "artifacts_list" | "artifacts_get" | "artifacts_get_source" | "artifacts_fork" | "artifacts_promote" | "artifacts_renew" | "artifacts_restore" | "artifacts_list_versions";
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";
28
28
  description: string;
29
29
  mutability: import("@sentropic/mcp-platform").Mutability;
30
30
  }[];
package/dist/mcp-core.js CHANGED
@@ -6,7 +6,7 @@ export * from './profile/index.js';
6
6
  export { createRadarKeyDerivation } from './server/command-identity.js';
7
7
  export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
8
8
  export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
9
- export const ARTIFACTS_PROVIDER_VERSION = '0.2.12';
9
+ export const ARTIFACTS_PROVIDER_VERSION = '0.2.13';
10
10
  export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
11
11
  // ---------------------------------------------------------------------------
12
12
  // Byte-stable tool definitions (MCP tool-definition stability rule).
@@ -46,16 +46,18 @@ const edit = obj({ path, oldStr: str, newStr: { type: 'string' } }, ['path', 'ol
46
46
  const idOnly = obj({ artifactId: id }, ['artifactId']);
47
47
  const ARTIFACTS_OUTPUT_SCHEMA = { type: 'object', additionalProperties: true };
48
48
  const READ_ONLY_TOOLS = ['artifacts_list', 'artifacts_get',
49
- 'artifacts_get_template', 'artifacts_get_api_guide', 'artifacts_get_source', 'artifacts_list_versions'];
49
+ 'artifacts_get_template', 'artifacts_get_api_guide', 'artifacts_get_source', 'artifacts_list_versions',
50
+ 'artifacts_lookup_people', 'artifacts_list_access'];
50
51
  const IDEMPOTENT_WRITERS = ['artifacts_ensure', 'artifacts_publish',
51
- 'artifacts_commit_upload', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'];
52
+ 'artifacts_commit_upload', 'artifacts_publish_bundle', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert',
53
+ 'artifacts_revoke_reader_consent'];
52
54
  function staticTool(name, inputSchema, description) {
53
55
  return {
54
56
  description: description ?? `Artifacts ${name.slice('artifacts_'.length).replaceAll('_', ' ')}.`,
55
57
  inputSchema,
56
58
  outputSchema: ARTIFACTS_OUTPUT_SCHEMA,
57
59
  mutability: READ_ONLY_TOOLS.includes(name) ? 'read-only'
58
- : name === 'artifacts_publish' ? 'append' : 'state-transition',
60
+ : name === 'artifacts_publish' || name === 'artifacts_publish_bundle' ? 'append' : 'state-transition',
59
61
  idempotency: IDEMPOTENT_WRITERS.includes(name) ? { required: true, scope: 'principal' } : { required: false },
60
62
  gates: { requiresElicitation: false, requiresHumanConfirmation: name === 'artifacts_delete',
61
63
  requiresPrincipalGate: false },
@@ -82,6 +84,9 @@ export const ARTIFACTS_TOOL_DEFINITIONS = {
82
84
  artifacts_list: staticTool('artifacts_list', obj({ limit: integer(1), offset: integer(0) })),
83
85
  artifacts_get: staticTool('artifacts_get', idOnly),
84
86
  artifacts_get_source: staticTool('artifacts_get_source', obj({ artifactId: id, releaseId: id,
87
+ // Frozen ceiling (review finding 5): maxItems 32 is part of this frozen
88
+ // definition and must NOT change. Server-side caps only move BELOW the
89
+ // frozen schema; larger listings belong to the new listing tools.
85
90
  paths: { type: 'array', minItems: 1, maxItems: 32, items: str } }, ['artifactId']), 'Artifacts get source: verified files of the current or a selected release as `text` (encoding "utf8") '
86
91
  + 'or `base64` (encoding "base64"), never an integer array, plus a guideRef instead of the guide body.'),
87
92
  artifacts_fork: staticTool('artifacts_fork', idOnly),
@@ -100,6 +105,30 @@ export const ARTIFACTS_TOOL_DEFINITIONS = {
100
105
  limit: integer(1, 100), cursor: { ...str, maxLength: 4096 } }, ['artifactId'])),
101
106
  artifacts_revert: staticTool('artifacts_revert', obj({ artifactId: id, releaseId: id, targetReleaseId: id,
102
107
  expectedCurrentReleaseId, idempotencyKey }, ['artifactId', 'idempotencyKey'])),
108
+ artifacts_lookup_people: staticTool('artifacts_lookup_people', obj({ query: str, limit: integer(1) }, ['query']), 'Artifacts lookup people: search the host directory by name or email and return opaque userRefs with '
109
+ + 'masked email hints (approved callers only; homonyms are returned, never silently resolved). '
110
+ + 'Use the returned userRef as principalId of artifacts_set_access.'),
111
+ artifacts_list_access: staticTool('artifacts_list_access', idOnly, 'Artifacts list access: sharing mode, owner and grant list of one artifact, projected to userRefs. '
112
+ + 'The owner and platform admins see every entry; a simple reader sees the mode and its own entry only.'),
113
+ // Files parity LOT 1 — appended last; frozen at birth like every definition above.
114
+ artifacts_publish_bundle: staticTool('artifacts_publish_bundle', { ...obj({
115
+ artifactId: id, idempotencyKey,
116
+ files: { type: 'array', items: file, minItems: 1,
117
+ description: 'Inline files (bytes travel through the model, inline budget); at least one of files/assets is required.' },
118
+ assets: { type: 'array', minItems: 1,
119
+ items: { oneOf: [
120
+ obj({ path, uploadId: id }, ['path', 'uploadId']),
121
+ obj({ path, digest: { type: 'string', pattern: '^sha256:[0-9a-f]{64}$' }, size: integer(1), mimeType: str }, ['path', 'digest', 'size', 'mimeType']),
122
+ ] },
123
+ description: 'Assets whose bytes already left the model: an uploadId staged via artifacts_create_upload/artifacts_commit_upload, or a sha256 digest of an already-pinned blob in the same scope. The release budget applies to the union of files and assets; duplicate paths are refused.' },
124
+ expectedCurrentReleaseId, profile: primitiveRecord, ...metadata
125
+ }, ['artifactId', 'idempotencyKey', 'expectedCurrentReleaseId']),
126
+ anyOf: [{ required: ['files'] }, { required: ['assets'] }] }, 'Artifacts publish bundle: one atomic release combining inline files with assets whose bytes already left the model '
127
+ + '(an uploadId staged via artifacts_create_upload + signed PUT + artifacts_commit_upload, or a sha256:<hex> digest '
128
+ + 'of an already-pinned blob). expectedCurrentReleaseId is always required (CAS); null requires an unpublished artifact.'),
129
+ artifacts_revoke_reader_consent: staticTool('artifacts_revoke_reader_consent', obj({ artifactId: id,
130
+ scope: { type: 'string', minLength: 1, maxLength: 128 }, idempotencyKey }, ['artifactId', 'idempotencyKey']), 'Artifacts revoke reader consent: withdraw persistent consent of the caller for one scope of one artifact, '
131
+ + 'or for every scope when scope is omitted. Self-revocation only; the next call asks again.'),
103
132
  };
104
133
  export const ARTIFACTS_TOOL_SPECS = ARTIFACTS_TOOL_NAMES.map((name) => ({ name,
105
134
  description: ARTIFACTS_TOOL_DEFINITIONS[name].description,
@@ -155,6 +184,15 @@ export function createArtifactsToolExecutor(deps) {
155
184
  case 'artifacts_publish':
156
185
  request = { method: 'POST', path: '/publish', body: args };
157
186
  break;
187
+ case 'artifacts_publish_bundle':
188
+ request = { method: 'POST', path: '/publish_bundle', body: args };
189
+ break;
190
+ case 'artifacts_create_upload':
191
+ request = { method: 'POST', path: '/uploads/create', body: args };
192
+ break;
193
+ case 'artifacts_commit_upload':
194
+ request = { method: 'POST', path: '/uploads/commit', body: args };
195
+ break;
158
196
  case 'artifacts_list':
159
197
  request = { method: 'POST', path: '/list', body: args };
160
198
  break;
@@ -167,6 +205,12 @@ export function createArtifactsToolExecutor(deps) {
167
205
  case 'artifacts_set_access':
168
206
  request = { method: 'POST', path: '/set_access', body: args };
169
207
  break;
208
+ case 'artifacts_lookup_people':
209
+ request = { method: 'POST', path: '/lookup_people', body: args };
210
+ break;
211
+ case 'artifacts_list_access':
212
+ request = { method: 'POST', path: '/list_access', body: args };
213
+ break;
170
214
  case 'artifacts_delete':
171
215
  request = { method: 'POST', path: '/delete', body: args };
172
216
  break;
@@ -176,6 +220,9 @@ export function createArtifactsToolExecutor(deps) {
176
220
  case 'artifacts_revert':
177
221
  request = { method: 'POST', path: '/revert', body: args };
178
222
  break;
223
+ case 'artifacts_revoke_reader_consent':
224
+ request = { method: 'POST', path: '/revoke_reader_consent', body: args };
225
+ break;
179
226
  default: throw new ArtifactProfileInputError(true);
180
227
  }
181
228
  return await deps.app.execute({ ...request, actorId: input.invocation.actorId,
@@ -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"];
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"];
5
5
  export type ArtifactCapabilityName = (typeof ARTIFACT_CAPABILITY_NAMES)[number];
6
6
  export type ArtifactSchema = Readonly<Record<string, unknown>>;
7
7
  export interface OperationProfile {
@@ -5,6 +5,9 @@ export const ARTIFACT_CAPABILITY_NAMES = [
5
5
  'artifacts_list', 'artifacts_get', 'artifacts_get_source', 'artifacts_fork',
6
6
  'artifacts_set_access', 'artifacts_promote', 'artifacts_renew',
7
7
  'artifacts_delete', 'artifacts_restore', 'artifacts_list_versions', 'artifacts_revert',
8
+ 'artifacts_lookup_people', 'artifacts_list_access',
9
+ 'artifacts_publish_bundle',
10
+ 'artifacts_revoke_reader_consent',
8
11
  ];
9
12
  /** Projection fields are data-only; invocation correlation is added by L6. */
10
13
  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.';