@sentropic/artifacts 0.2.14 → 0.2.15

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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.15
4
+
5
+ - R1: every model-visible userRef projection emits the opaque `unknown` value
6
+ when the directory entry is missing instead of falling back to the raw
7
+ internal id (`sub`): `projectUserRef`, `list_access` grants and owner,
8
+ the `set_access` receipt, and the `list_versions` v1 author (plus the v2
9
+ `authorPrincipalId`). No MCP tool definition changes.
10
+ - R5: `assertShareable` enforces the approved-principal gate on `grant` only;
11
+ `revoke` stays allowed for dormant (suspended or deleted) principals as the
12
+ expected cleanup step. Revoking an absent grant is a no-op success.
13
+
3
14
  ## 0.2.14
4
15
 
5
16
  - Add a durable local SQLite adapter set behind the new `./sqlite` subpath export:
package/dist/http.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /** Selected HTTP control surface over the authorized atomic services. */
2
2
  import { createHash } from 'node:crypto';
3
- import { parseManifest } from './codecs.js';
3
+ import { canonicalManifest, manifestDigest, parseManifest } from './codecs.js';
4
4
  import { assertCompiledArtifactsProfile, ArtifactProfileInputError } from './profile/index.js';
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, maskEmailHint, resolveSharingPolicy } from './server/ports.js';
8
+ import { combineSharingPolicy, maskEmailHint, resolveSharingPolicy, UNKNOWN_USER_REF } from './server/ports.js';
9
9
  import { createGuardedPublicationService } from './server/publication.js';
10
10
  import { SERVER_MAX_FILE_BYTES, SERVER_MAX_SOURCE_FILES, SERVER_MAX_SOURCE_INLINE_BYTES, SERVER_MAX_SOURCE_TOTAL_BYTES, SERVER_MAX_UPLOAD_SESSIONS_PER_PRINCIPAL } from './server/publication-limits.js';
11
11
  import { releaseBudget } from './profile/validation.js';
@@ -325,7 +325,7 @@ export function createHttpArtifactApp(deps) {
325
325
  async function projectUserRef(internalId, storageScopeId) {
326
326
  if (!deps.directory)
327
327
  return internalId;
328
- return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? internalId;
328
+ return (await deps.directory.describePrincipal(storageScopeId, internalId))?.userRef ?? UNKNOWN_USER_REF;
329
329
  }
330
330
  async function projectSummary(summary, storageScopeId) {
331
331
  if (!deps.directory)
@@ -431,15 +431,47 @@ export function createHttpArtifactApp(deps) {
431
431
  ? { base64: Buffer.from(file.bytes).toString('base64'), encoding: 'base64' }
432
432
  : { text: file.text, encoding: 'utf8' }) }));
433
433
  await visible(artifactId, invocation, 'source');
434
+ const projectedManifest = await projectManifestForOutput(release.manifest, invocation.storageScopeId);
434
435
  const failure = { ...outcome.failure, conflict: { ...conflict, currentSource: {
435
- artifactId, releaseId: release.releaseId, digest: conflict.currentDigest, manifest: release.manifest,
436
+ artifactId, releaseId: release.releaseId, digest: parseManifest(projectedManifest).digest ?? conflict.currentDigest,
437
+ manifest: projectedManifest,
436
438
  files, sourceRef: null, guideRef: API_GUIDE_REF, ...deps.publicationUrls?.(artifactId, release.releaseId),
437
439
  } } };
438
440
  Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
439
441
  return { ok: false, failure: Object.freeze(failure) };
440
442
  }
443
+ /**
444
+ * R1 output-boundary projection for the release manifest embedded in
445
+ * publish/revert/bundle receipts. Storage keeps the raw internal `ownerId`
446
+ * (the manifest bytes are content-addressed); only this model-visible copy
447
+ * carries the opaque `userRef` (or `UNKNOWN_USER_REF` when the directory
448
+ * has no entry). Without a directory port the stored bytes pass through
449
+ * unchanged (G1 legacy behaviour).
450
+ */
451
+ async function projectManifestForOutput(rawManifest, storageScopeId) {
452
+ if (!deps.directory)
453
+ return rawManifest;
454
+ let parsed;
455
+ try {
456
+ parsed = JSON.parse(rawManifest);
457
+ }
458
+ catch {
459
+ return rawManifest;
460
+ }
461
+ const rawOwner = parsed.ownerId;
462
+ if (typeof rawOwner !== 'string')
463
+ return rawManifest;
464
+ const projected = (await deps.directory.describePrincipal(storageScopeId, rawOwner))?.userRef
465
+ ?? UNKNOWN_USER_REF;
466
+ if (projected === rawOwner)
467
+ return rawManifest;
468
+ const { digest: _drop, ...body } = parsed;
469
+ void _drop;
470
+ const nextDigest = manifestDigest({ ...body, ownerId: projected });
471
+ return canonicalManifest({ ...body, ownerId: projected, digest: nextDigest });
472
+ }
441
473
  /** Shared guarded-commit response for publish and revert (same commit path, same receipt shape). */
442
- function commitOutcome(outcome, artifactId, meta, setCommitState) {
474
+ async function commitOutcome(outcome, artifactId, meta, setCommitState, storageScopeId) {
443
475
  if (!outcome.ok) {
444
476
  const failure = { ...outcome.failure, kind: 'operational' };
445
477
  Object.defineProperty(failure, 'cause', { value: outcome.failure.cause, enumerable: false });
@@ -450,11 +482,12 @@ export function createHttpArtifactApp(deps) {
450
482
  if (typeof receipt.releaseId !== 'string' || typeof receipt.manifest !== 'string') {
451
483
  throw new Error('invalid publication receipt');
452
484
  }
485
+ const manifest = await projectManifestForOutput(receipt.manifest, storageScopeId);
453
486
  return { ...outcome, result: { status: 201, body: {
454
- artifactId, releaseId: receipt.releaseId, manifest: receipt.manifest,
487
+ artifactId, releaseId: receipt.releaseId, manifest,
455
488
  previousReleaseId: receipt.previousReleaseId ?? null, updatedAt: receipt.updatedAt ?? null,
456
489
  ...(typeof receipt.revertedFromReleaseId === 'string' ? { revertedFromReleaseId: receipt.revertedFromReleaseId } : {}),
457
- digest: parseManifest(receipt.manifest).digest,
490
+ digest: parseManifest(manifest).digest,
458
491
  ...deps.publicationUrls?.(artifactId, receipt.releaseId), ...(receipt.metadata ?? meta ?? {}),
459
492
  } } };
460
493
  }
@@ -550,7 +583,11 @@ export function createHttpArtifactApp(deps) {
550
583
  maxInlineBytes: sourceOp?.limits['sourceInlineFileBytesMax'] ?? SERVER_MAX_SOURCE_INLINE_BYTES,
551
584
  maxTotalBytes: sourceOp?.limits['sourceTotalBytesMax'] ?? SERVER_MAX_SOURCE_TOTAL_BYTES,
552
585
  }, normalized);
553
- return { ok: true, result: { status: 200, body: result }, invocationId: invocation.invocationId,
586
+ const projectedSourceManifest = await projectManifestForOutput(result.manifest, invocation.storageScopeId);
587
+ const projectedSource = projectedSourceManifest === result.manifest ? result
588
+ : { ...result, manifest: projectedSourceManifest,
589
+ digest: parseManifest(projectedSourceManifest).digest ?? result.digest };
590
+ return { ok: true, result: { status: 200, body: projectedSource }, invocationId: invocation.invocationId,
554
591
  commitState: 'not_committed', replayed: false };
555
592
  }
556
593
  if (capability === 'artifacts_list_assets') {
@@ -685,7 +722,7 @@ export function createHttpArtifactApp(deps) {
685
722
  expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
686
723
  const replay = await publication.replayFinalized(input);
687
724
  if (replay !== undefined)
688
- return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
725
+ return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
689
726
  profile.validate(capability, args, request.idempotencyKey);
690
727
  let files;
691
728
  let source;
@@ -727,7 +764,7 @@ export function createHttpArtifactApp(deps) {
727
764
  const outcome = await publication.publishFinalized({
728
765
  ...input, source, profile: releaseProfile, files,
729
766
  });
730
- const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
767
+ const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
731
768
  return await conflictSource(committed, normalized, invocation);
732
769
  }
733
770
  if (capability === 'artifacts_create_upload') {
@@ -864,7 +901,7 @@ export function createHttpArtifactApp(deps) {
864
901
  expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
865
902
  const replay = await publication.replayFinalized(input);
866
903
  if (replay !== undefined)
867
- return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
904
+ return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
868
905
  profile.validate(capability, args, request.idempotencyKey);
869
906
  // Resolve the files/assets union BEFORE any commit step: one missing,
870
907
  // expired or digest-mismatched asset fails the whole publish and commits nothing.
@@ -876,7 +913,7 @@ export function createHttpArtifactApp(deps) {
876
913
  ...input, source: { kind: 'inline-original' },
877
914
  profile: normalized.profile, files,
878
915
  });
879
- const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
916
+ const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
880
917
  if (committed.ok) {
881
918
  const parsedBundleManifest = parseManifest(committed.result.body.manifest);
882
919
  const entries = parsedBundleManifest.files ?? [];
@@ -914,7 +951,7 @@ export function createHttpArtifactApp(deps) {
914
951
  expectedCurrentReleaseId: normalized.expectedCurrentReleaseId };
915
952
  const replay = await publication.replayFinalized(input);
916
953
  if (replay !== undefined)
917
- return commitOutcome(replay, artifactId, meta, state => { commitState = state; });
954
+ return commitOutcome(replay, artifactId, meta, state => { commitState = state; }, invocation.storageScopeId);
918
955
  profile.validate(capability, args, request.idempotencyKey);
919
956
  const resolved = await resolveBundleAssets(invocation, artifactId, {
920
957
  files: (normalized.files ?? []),
@@ -926,7 +963,7 @@ export function createHttpArtifactApp(deps) {
926
963
  ...input, source: { kind: 'inline-original' },
927
964
  profile: normalized.profile, files: resolved.files,
928
965
  });
929
- const committed = commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; });
966
+ const committed = await commitOutcome(outcome, artifactId, meta, (state) => { commitState = state; }, invocation.storageScopeId);
930
967
  if (committed.ok) {
931
968
  const parsedBundleManifest = parseManifest(committed.result.body.manifest);
932
969
  const entries = parsedBundleManifest.files ?? [];
@@ -974,14 +1011,25 @@ export function createHttpArtifactApp(deps) {
974
1011
  limit: normalized.limit, cursor: normalized.cursor,
975
1012
  state: id => deps.lifecycle.getReleaseState(id), urls: deps.publicationUrls });
976
1013
  await visible(artifactId, invocation);
1014
+ if (deps.directory) {
1015
+ for (const version of body.versions) {
1016
+ if (typeof version.authorPrincipalId === 'string') {
1017
+ version.authorPrincipalId = (await deps.directory.describePrincipal(invocation.storageScopeId, version.authorPrincipalId))?.userRef ?? UNKNOWN_USER_REF;
1018
+ }
1019
+ }
1020
+ }
977
1021
  return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
978
1022
  result: { status: 200, body } };
979
1023
  }
980
1024
  const releases = [];
981
1025
  for (const release of await deps.publication.listReleases(artifactId)) {
982
1026
  const manifest = parseManifest(release.manifest);
1027
+ const rawAuthor = typeof manifest.ownerId === 'string' ? manifest.ownerId : null;
1028
+ const author = rawAuthor === null || !deps.directory ? rawAuthor
1029
+ : (await deps.directory.describePrincipal(invocation.storageScopeId, rawAuthor))?.userRef
1030
+ ?? UNKNOWN_USER_REF;
983
1031
  releases.push({ releaseId: release.releaseId, createdAt: release.createdAt,
984
- author: typeof manifest.ownerId === 'string' ? manifest.ownerId : null,
1032
+ author,
985
1033
  state: await deps.lifecycle.getReleaseState(release.releaseId),
986
1034
  isCurrent: current?.releaseId === release.releaseId,
987
1035
  digest: release.manifestDigest });
@@ -1015,7 +1063,7 @@ export function createHttpArtifactApp(deps) {
1015
1063
  : acl.grants.filter((grant) => grant.principalId === invocation.actorId);
1016
1064
  const grants = await Promise.all(visibleGrants.map(async (grant) => {
1017
1065
  const person = await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId);
1018
- const userRef = person?.userRef ?? grant.principalId;
1066
+ const userRef = person?.userRef ?? UNKNOWN_USER_REF;
1019
1067
  const { effective, blockedBy } = evaluateGrant(acl, grant.principalId, deps.isApprovedAccount ?? (() => false));
1020
1068
  return { userRef, displayName: person?.displayName ?? userRef,
1021
1069
  ...(person === undefined ? {} : { emailHint: maskEmailHint(person.email) }),
@@ -1025,7 +1073,8 @@ export function createHttpArtifactApp(deps) {
1025
1073
  const owner = await deps.directory.describePrincipal(invocation.storageScopeId, acl.ownerId);
1026
1074
  return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
1027
1075
  result: { status: 200, body: { artifactId, accessMode: accessModeOf(acl),
1028
- owner: { userRef: owner?.userRef ?? acl.ownerId, displayName: owner?.displayName ?? acl.ownerId },
1076
+ owner: { userRef: owner?.userRef ?? UNKNOWN_USER_REF,
1077
+ displayName: owner?.displayName ?? UNKNOWN_USER_REF },
1029
1078
  canManage, grants } } };
1030
1079
  }
1031
1080
  const visibleArtifacts = [];
@@ -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.14";
13
+ export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.15";
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"];
15
15
  export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
16
16
  export interface ArtifactsToolDefinition {
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.14';
9
+ export const ARTIFACTS_PROVIDER_VERSION = '0.2.15';
10
10
  export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
11
11
  // ---------------------------------------------------------------------------
12
12
  // Byte-stable tool definitions (MCP tool-definition stability rule).
@@ -1,5 +1,5 @@
1
1
  import { audienceOf, canManageAccess, PUBLIC_PRINCIPAL } from './access.js';
2
- import { combineSharingPolicy, resolveSharingPolicy } from './ports.js';
2
+ import { combineSharingPolicy, resolveSharingPolicy, UNKNOWN_USER_REF } from './ports.js';
3
3
  import { ArtifactOperationError } from './failures.js';
4
4
  export function confirmationFailure(code, details) {
5
5
  return new ArtifactOperationError('unauthorized_at_commit', { publicDetails: details,
@@ -67,10 +67,14 @@ export async function manageArtifact(deps, invocation, command, proof) {
67
67
  return await deps.directory.resolvePrincipal(invocation.storageScopeId, principalId) ?? principalId;
68
68
  };
69
69
  // Unknown, inactive, unapproved and out-of-scope targets merge into the
70
- // single `person_not_shareable` so no account status can be probed.
70
+ // single `person_not_shareable` so no account status can be probed. R5: the
71
+ // approval gate applies to `grant` only; `revoke` is the expected cleanup
72
+ // step for dormant (suspended or deleted) principals and must stay allowed.
71
73
  const assertShareable = async (internal, action) => {
74
+ if (action !== 'grant')
75
+ return;
72
76
  if (deps.directory === undefined) {
73
- if (action === 'grant' && !await deps.isApprovedPrincipal(internal))
77
+ if (!await deps.isApprovedPrincipal(internal))
74
78
  throw refused('access_denied');
75
79
  return;
76
80
  }
@@ -78,14 +82,15 @@ export async function manageArtifact(deps, invocation, command, proof) {
78
82
  throw shareableRefused();
79
83
  };
80
84
  // The receipt is model-visible: project internal principals to userRefs
81
- // (audit events keep the internal form).
85
+ // (audit events keep the internal form). R1: a missing directory entry
86
+ // projects to the opaque unknown value, never the raw internal id.
82
87
  const projectGrants = async (grants) => {
83
88
  if (deps.directory === undefined)
84
89
  return grants;
85
90
  return Promise.all(grants.map(async (grant) => ({
86
91
  ...grant,
87
92
  principalId: (await deps.directory.describePrincipal(invocation.storageScopeId, grant.principalId))?.userRef
88
- ?? grant.principalId,
93
+ ?? UNKNOWN_USER_REF,
89
94
  })));
90
95
  };
91
96
  const request = {
@@ -49,6 +49,13 @@ export interface PrincipalDirectoryPort {
49
49
  /** Inverse projection: internal principal id → directory person (userRef/displayName/email). */
50
50
  describePrincipal(scope: string, principalId: string): Promise<DirectoryPerson | undefined>;
51
51
  }
52
+ /**
53
+ * R1 typed unknown principal (review 1002): every model-visible projection of
54
+ * an internal principal whose directory entry is missing emits this opaque
55
+ * value instead of the raw internal id (`sub`). It never resolves back to a
56
+ * principal, so re-injecting it fails closed with `person_not_shareable`.
57
+ */
58
+ export declare const UNKNOWN_USER_REF = "unknown";
52
59
  /**
53
60
  * Mask an email for model payloads: first local-part character kept, rest of
54
61
  * the local part masked, domain visible — lifts homonyms without disclosing
@@ -21,6 +21,13 @@ export function createCryptoUuid() {
21
21
  },
22
22
  };
23
23
  }
24
+ /**
25
+ * R1 typed unknown principal (review 1002): every model-visible projection of
26
+ * an internal principal whose directory entry is missing emits this opaque
27
+ * value instead of the raw internal id (`sub`). It never resolves back to a
28
+ * principal, so re-injecting it fails closed with `person_not_shareable`.
29
+ */
30
+ export const UNKNOWN_USER_REF = 'unknown';
24
31
  /**
25
32
  * Mask an email for model payloads: first local-part character kept, rest of
26
33
  * the local part masked, domain visible — lifts homonyms without disclosing
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sentropic/artifacts",
3
- "version": "0.2.14",
3
+ "version": "0.2.15",
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",