@sentropic/artifacts 0.2.8 → 0.2.10

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,53 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.10
4
+
5
+ - G1 sharing access model: artifacts carry an explicit `access_mode`
6
+ (`restricted` by default, `platform`, `public`) managed through
7
+ `artifacts_set_access` with sentinel transitions (`grant sentropic:platform`
8
+ degrades public→platform, `revoke sentropic:platform` on public is a no-op).
9
+ `restricted` mode allows at most one nominative `source` (collab) grant, and
10
+ widening the mode while a `source` grant is live is rejected. Migration
11
+ `0006_sharing.sql` is additive: `access_mode` column with CHECK, legacy
12
+ `is_public=true` backfilled to `platform` (zero artifacts become `public`),
13
+ an append-only `artifact_access_events` audit table (UPDATE/DELETE rejected by
14
+ trigger) and the Q1 schema guards (partial unique index, mode/grant triggers).
15
+ - Sharing policy is double-locked: profile rule `allowPublicSharing` (absent ⇒
16
+ false, covered by `profileDigest`) AND a runtime `SharingPolicyPort` resolved
17
+ fail-closed inside the commit transaction; public anonymous reads require the
18
+ policy to allow them. Approval freshness is enforced on read paths (suspension
19
+ cuts the next read, reactivation resumes automatically).
20
+ - D1: `set_access` visibility closes the existence oracle — a non-reader actor
21
+ gets `not_found` unless it is an approved platform admin of the same storage
22
+ scope; the management right itself (owner, or admin-reduce-only) is still
23
+ decided inside the transaction (403 otherwise).
24
+ - D2: `0006_sharing.sql` deterministically dedupes legacy multi-`source` grants
25
+ before the unique index (oldest `created_at`, tie-break `principal_id` stays
26
+ `source`; later duplicates demote to `read`; no row deleted), and
27
+ `putArtifactAcl` demotes a stale `source` grant to `read` when rewriting a
28
+ non-restricted ACL.
29
+ - MCP tool definitions stay byte-identical (new fields only, never edits).
30
+ - 0.2.10 stays inside the existing cluster-mesh `>=0.2.0 <0.3.0` peer range
31
+ (conductor allocation: #896=0.2.9, #901=0.2.10, #891=0.2.11; merge order
32
+ 896 > 901 > 891).
33
+
34
+ ## 0.2.9
35
+
36
+ - Make every `artifacts_*` MCP tool definition byte-stable across deployments,
37
+ package versions and profile switches: descriptions, input schemas, output
38
+ schemas, idempotency and gates are compile-time constants in
39
+ `ARTIFACTS_TOOL_DEFINITIONS` (`src/mcp-core.ts`). The active profile still
40
+ selects the exposed tool set and constrains every invocation server-side,
41
+ and stays visible in manifest audit metadata and typed result details — never
42
+ inside a tool definition. Hosts such as claude.ai key per-tool "Always allow"
43
+ permissions on definition bytes, so approvals now survive upgrades and profile
44
+ switches. The APP-P1 manifest pin still covers the definitions, so the pin
45
+ is stable too.
46
+ - Add tools/list snapshot tests (`packages/artifacts/tests/tools-list-snapshot.test.ts`,
47
+ `packages/mcp-platform/tests/tools-list-snapshot.test.ts`) that fail on any
48
+ tool-definition change unless the checked-in snapshot is deliberately
49
+ regenerated.
50
+
3
51
  ## 0.2.8
4
52
 
5
53
  - Content hosts use a single UUID label: `https://<id>.<base>/` resolves server-side,
package/README.md CHANGED
@@ -401,6 +401,14 @@ a registrable domain. Assets within the same artifact origin remain loadable.
401
401
  - `src/mcp-core.ts` — the platform-free `sentropic.artifacts` MCP provider: 15 exact
402
402
  `artifacts_*` tools with closed schemas, a host-bindable invocation
403
403
  scope, an executor over the same HTTP app and a platform adapter.
404
+ Tool definitions are byte-stable compile-time constants
405
+ (`ARTIFACTS_TOOL_DEFINITIONS`): no version, profile revision, digest or
406
+ limit ever appears in a description, schema, annotation or `_meta`, so host
407
+ per-tool permissions (claude.ai "Always allow") survive upgrades and profile
408
+ switches. The active profile selects the exposed tools and constrains
409
+ invocations server-side; it stays visible in manifest audit metadata and
410
+ typed result details. `tests/tools-list-snapshot.test.ts` pins the full
411
+ tools/list catalogue.
404
412
  - `src/mcp.ts` — the compatible `@sentropic/mcp-platform` kernel registry
405
413
  definition wrapper (the optional peer is required here and by the root barrel).
406
414
 
@@ -1,5 +1,10 @@
1
+ import { applyModeTransition, PLATFORM_PRINCIPAL, PUBLIC_PRINCIPAL } from '../server/access.js';
1
2
  /** Parent lock serializes ACL inserts, lifecycle changes and publication FKs. */
2
3
  export function createPostgresManagementUnit(client) {
4
+ const listGrants = async (id) => {
5
+ const { rows } = await client.query('SELECT principal_id, permission FROM artifacts.artifact_access WHERE artifact_id = $1 ORDER BY principal_id', [id]);
6
+ return rows.map((row) => ({ principalId: row.principal_id, grant: row.permission }));
7
+ };
3
8
  return {
4
9
  async lock(id) {
5
10
  await client.query('SELECT id FROM artifacts.artifacts WHERE id = $1 FOR UPDATE', [id]);
@@ -7,30 +12,48 @@ export function createPostgresManagementUnit(client) {
7
12
  await client.query('SELECT release_id FROM artifacts.artifact_current WHERE artifact_id = $1 FOR UPDATE', [id]);
8
13
  },
9
14
  async read(id) {
10
- const { rows } = await client.query(`SELECT a.owner_id, a.storage_scope_id, a.lifecycle_state, a.is_public, a.terminal_deleted_at, c.release_id
15
+ const { rows } = await client.query(`SELECT a.owner_id, a.storage_scope_id, a.lifecycle_state, a.is_public, a.access_mode, a.terminal_deleted_at, c.release_id
11
16
  FROM artifacts.artifacts a LEFT JOIN artifacts.artifact_current c ON c.artifact_id = a.id WHERE a.id = $1`, [id]);
12
17
  const row = rows[0];
13
18
  if (!row)
14
19
  return undefined;
20
+ // G1: access_mode is authoritative; is_public is its legacy projection.
21
+ const accessMode = (row.access_mode ?? (row.is_public ? 'platform' : 'restricted'));
15
22
  const acl = { ownerId: row.owner_id, storageScopeId: row.storage_scope_id,
16
- isPublic: row.is_public, withdrawn: row.lifecycle_state === 'withdrawn', grants: [] };
23
+ isPublic: accessMode !== 'restricted', accessMode, withdrawn: row.lifecycle_state === 'withdrawn', grants: [] };
17
24
  return { acl, state: row.lifecycle_state, terminal: row.terminal_deleted_at !== null,
18
25
  currentReleaseId: row.release_id };
19
26
  },
20
27
  async setAccess(id, principalId, action, updatedAt) {
28
+ const modeRow = await client.query('SELECT access_mode, is_public FROM artifacts.artifacts WHERE id = $1', [id]);
29
+ const current = (modeRow.rows[0] === undefined ? 'restricted'
30
+ : (modeRow.rows[0].access_mode ?? (modeRow.rows[0].is_public ? 'platform' : 'restricted')));
31
+ if (principalId === PLATFORM_PRINCIPAL || principalId === PUBLIC_PRINCIPAL) {
32
+ // Wide-audience sentinels move the mode through the normative transitions;
33
+ // is_public follows as projection (never forced to false).
34
+ const transition = applyModeTransition(current, action, principalId);
35
+ if (transition.changed) {
36
+ await client.query(`UPDATE artifacts.artifacts SET access_mode = $2, is_public = ($2 <> 'restricted'), updated_at = $3 WHERE id = $1`, [id, transition.mode, updatedAt]);
37
+ }
38
+ return { grants: await listGrants(id), updatedAt, accessMode: transition.mode, changed: transition.changed };
39
+ }
21
40
  const changed = action === 'grant' ? await client.query(`INSERT INTO artifacts.artifact_access (artifact_id, principal_id, permission) VALUES ($1, $2, 'read')
22
41
  ON CONFLICT (artifact_id, principal_id) DO NOTHING`, [id, principalId])
23
42
  : await client.query('DELETE FROM artifacts.artifact_access WHERE artifact_id = $1 AND principal_id = $2', [id, principalId]);
24
- await client.query(`UPDATE artifacts.artifacts SET is_public = false, updated_at = $2
25
- WHERE id = $1 AND ($3::boolean OR is_public)`, [id, updatedAt, changed.rowCount > 0]);
26
- const result = await client.query('SELECT principal_id, permission FROM artifacts.artifact_access WHERE artifact_id = $1 ORDER BY principal_id', [id]);
43
+ if (changed.rowCount > 0) {
44
+ await client.query('UPDATE artifacts.artifacts SET updated_at = $2 WHERE id = $1', [id, updatedAt]);
45
+ }
27
46
  const stamp = await client.query('SELECT updated_at FROM artifacts.artifacts WHERE id = $1', [id]);
28
- return { grants: result.rows.map((row) => ({ principalId: row.principal_id, grant: row.permission })),
29
- updatedAt: stamp.rows[0]?.updated_at?.toISOString() ?? null };
47
+ return { grants: await listGrants(id), updatedAt: stamp.rows[0]?.updated_at?.toISOString() ?? null,
48
+ accessMode: current, changed: changed.rowCount > 0 };
49
+ },
50
+ async recordEvent(event) {
51
+ await client.query(`INSERT INTO artifacts.artifact_access_events (artifact_id, actor_id, action, audience, principal_id, policy_revision)
52
+ VALUES ($1, $2, $3, $4, $5, $6)`, [event.artifactId, event.actorId, event.action, event.audience, event.principalId, event.policyRevision]);
30
53
  },
31
54
  async delete(id, deletedAt) {
32
55
  await client.query(`UPDATE artifacts.artifacts SET lifecycle_state = 'deleted', terminal_deleted_at = $2,
33
- updated_at = $2, is_public = false WHERE id = $1`, [id, deletedAt]);
56
+ updated_at = $2 WHERE id = $1`, [id, deletedAt]);
34
57
  },
35
58
  };
36
59
  }
@@ -196,7 +196,7 @@ export function createPostgresArtifactStore(pool) {
196
196
  return rows.map((row) => row.digest);
197
197
  },
198
198
  async getArtifactAcl(artifactId) {
199
- const { rows } = await pool.query(`SELECT owner_id, storage_scope_id, is_public, lifecycle_state, binding_name, created_at,
199
+ const { rows } = await pool.query(`SELECT owner_id, storage_scope_id, is_public, access_mode, lifecycle_state, binding_name, created_at,
200
200
  to_jsonb(a)->>'updated_at' AS updated_at, to_jsonb(a)->'metadata' AS metadata
201
201
  FROM artifacts.artifacts a WHERE id = $1`, [artifactId]);
202
202
  const row = rows[0];
@@ -204,12 +204,15 @@ export function createPostgresArtifactStore(pool) {
204
204
  return undefined;
205
205
  const grants = await pool.query(`SELECT principal_id, permission FROM artifacts.artifact_access
206
206
  WHERE artifact_id = $1 ORDER BY principal_id`, [artifactId]);
207
+ // G1: access_mode is authoritative; is_public is its legacy projection.
208
+ const accessMode = (row.access_mode ?? (row.is_public ? 'platform' : 'restricted'));
207
209
  return {
208
210
  bindingName: row.binding_name, createdAt: row.created_at.toISOString(), updatedAt: row.updated_at,
209
211
  ...(row.metadata ?? {}),
210
212
  ownerId: row.owner_id,
211
213
  storageScopeId: row.storage_scope_id,
212
- isPublic: row.is_public,
214
+ isPublic: accessMode !== 'restricted',
215
+ accessMode,
213
216
  withdrawn: row.lifecycle_state === 'withdrawn',
214
217
  grants: grants.rows.map((grant) => ({
215
218
  principalId: grant.principal_id,
@@ -219,17 +222,25 @@ export function createPostgresArtifactStore(pool) {
219
222
  };
220
223
  },
221
224
  async putArtifactAcl(artifactId, acl) {
222
- await pool.query(`UPDATE artifacts.artifacts SET is_public = $2, metadata = $4,
225
+ // G1: write access_mode; is_public stays as its projection (never forced false).
226
+ const accessMode = acl.accessMode ?? (acl.isPublic ? 'platform' : 'restricted');
227
+ await pool.query(`UPDATE artifacts.artifacts SET access_mode = $2, is_public = ($2 <> 'restricted'), metadata = $4,
223
228
  lifecycle_state = CASE WHEN $3 THEN 'withdrawn'
224
229
  WHEN lifecycle_state = 'withdrawn' THEN 'active'
225
230
  ELSE lifecycle_state END
226
- WHERE id = $1`, [artifactId, acl.isPublic, acl.withdrawn, JSON.stringify(acl.metadata ?? {})]);
231
+ WHERE id = $1`, [artifactId, accessMode, acl.withdrawn, JSON.stringify(acl.metadata ?? {})]);
227
232
  await pool.query(`DELETE FROM artifacts.artifact_access WHERE artifact_id = $1`, [
228
233
  artifactId,
229
234
  ]);
230
235
  for (const grant of acl.grants) {
236
+ // Q1 schema invariant: a source grant exists only in restricted mode. A
237
+ // legacy platform/public artifact (migrated by 0006 from is_public=true)
238
+ // may still carry one; rewriting its ACL (e.g. withdraw) must not trip
239
+ // the source guard on re-insert, so the stale source grant is demoted
240
+ // to read — the grant row is kept, never dropped.
241
+ const permission = grant.grant === 'source' && accessMode !== 'restricted' ? 'read' : grant.grant;
231
242
  await pool.query(`INSERT INTO artifacts.artifact_access (artifact_id, principal_id, permission)
232
- VALUES ($1, $2, $3)`, [artifactId, grant.principalId, grant.grant]);
243
+ VALUES ($1, $2, $3)`, [artifactId, grant.principalId, permission]);
233
244
  }
234
245
  },
235
246
  async listArtifactIds() {
@@ -1,5 +1,6 @@
1
1
  import type { AclStore } from '../server/access.js';
2
2
  import type { LifecycleService } from '../server/lifecycle.js';
3
+ import { type SharingPolicyPort } from '../server/ports.js';
3
4
  import type { PublicationBlobStore, PublicationService } from '../server/publication.js';
4
5
  import { type GrantSigner, type TicketService } from './grants.js';
5
6
  export interface ContentRequest {
@@ -25,7 +26,11 @@ export interface ContentHandlerDeps {
25
26
  grants: GrantSigner;
26
27
  tickets: TicketService;
27
28
  baseDomain: string;
28
- isApprovedAccount?: (principalId: string) => boolean;
29
+ isApprovedAccount?: (principalId: string) => boolean | Promise<boolean>;
30
+ /** G1 lock 2 (runtime): sharing policy per scope, fail-closed when absent. */
31
+ sharingPolicy?: SharingPolicyPort;
32
+ /** G1 lock 1 (deployment capability), absent ⇒ closed. */
33
+ allowPublicSharing?: boolean;
29
34
  assetCacheSeconds?: number;
30
35
  }
31
36
  /** Create the content handler over injected host ports (no server). */
@@ -14,6 +14,7 @@
14
14
  * Unknown/unreadable → same 404; bad grants → 401.
15
15
  */
16
16
  import { errorBody } from '../http.js';
17
+ import { combineSharingPolicy, resolveSharingPolicy } from '../server/ports.js';
17
18
  import { CONTENT_GRANT_TTL_SECONDS } from './grants.js';
18
19
  import { contentHeaders, grantCookie, parseGrantCookie } from './headers.js';
19
20
  import { isServiceWorkerPath, parseContentHost, resolveContentPath } from './routing.js';
@@ -29,13 +30,17 @@ function fail(status) {
29
30
  }
30
31
  /** Create the content handler over injected host ports (no server). */
31
32
  export function createContentHandler(deps) {
32
- const isApproved = deps.isApprovedAccount ?? (() => false);
33
33
  async function canReadNow(artifactId, subjectId) {
34
34
  const acl = await deps.acls.getArtifactAcl(artifactId);
35
35
  if (acl === undefined)
36
36
  return false;
37
37
  const state = await deps.lifecycle.stateOf(artifactId);
38
- return deps.lifecycle.canRead({ artifactId, state }, acl, subjectId, 'read', isApproved);
38
+ // G1 double lock, fail-closed: public mode serves anonymous reads only
39
+ // when the profile capability AND the live runtime policy both allow it.
40
+ const policy = acl.storageScopeId === undefined ? undefined : combineSharingPolicy(deps.allowPublicSharing, await resolveSharingPolicy(deps.sharingPolicy, acl.storageScopeId));
41
+ // G1 owner Q2: fresh account approval at every read; the host predicate may be async (live DB check).
42
+ const approved = (await deps.isApprovedAccount?.(subjectId)) ?? false;
43
+ return deps.lifecycle.canRead({ artifactId, state }, acl, subjectId, 'read', () => approved, policy);
39
44
  }
40
45
  async function serveFile(artifactId, manifest, filePath) {
41
46
  const acl = await deps.acls.getArtifactAcl(artifactId);
package/dist/http.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type CompiledArtifactsProfile } from './profile/index.js';
2
2
  import { type ArtifactKeyDerivationBinding } from './server/command-identity.js';
3
3
  import { type GuardedEnsureHost } from './server/service.js';
4
- import type { KvPort } from './server/ports.js';
4
+ import { type KvPort, type SharingPolicyPort } from './server/ports.js';
5
5
  import { type GuardedPublicationDeps, type PublicationService } from './server/publication.js';
6
6
  import type { AclStore } from './server/access.js';
7
7
  import type { LifecycleService } from './server/lifecycle.js';
@@ -51,6 +51,10 @@ export interface HttpAppDeps {
51
51
  acls: AclStore;
52
52
  lifecycle: Pick<LifecycleService, 'stateOf' | 'canRead' | 'getReleaseState'>;
53
53
  isApprovedAccount?: (principalId: string) => boolean;
54
+ /** G1 lock 2 (runtime, revocable): sharing policy per scope, resolved fail-closed. */
55
+ sharingPolicy?: SharingPolicyPort;
56
+ /** G1: server-resolved platform admin predicate (never a tool argument). */
57
+ actorIsAdmin?: (actorId: string, storageScopeId: string) => boolean | Promise<boolean>;
54
58
  /** One trusted URL policy shared by HTTP and MCP receipts: the artifact page and the exact version page. */
55
59
  publicationUrls?: (artifactId: string, releaseId: string) => {
56
60
  stableUrl: string;
package/dist/http.js CHANGED
@@ -5,6 +5,7 @@ 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';
8
9
  import { createGuardedPublicationService } from './server/publication.js';
9
10
  import { applyEdits } from './server/edits.js';
10
11
  import { CommitQuarantineError } from './server/commit/types.js';
@@ -70,6 +71,10 @@ export function createHttpArtifactApp(deps) {
70
71
  return receipt;
71
72
  },
72
73
  } });
74
+ /** G1 double lock: profile capability (lock 1) AND runtime port (lock 2), fail-closed. */
75
+ async function sharingPolicyContext(storageScopeId) {
76
+ return combineSharingPolicy(profile.rules.allowPublicSharing, await resolveSharingPolicy(deps.sharingPolicy, storageScopeId));
77
+ }
73
78
  async function visible(artifactId, invocation, action = 'read') {
74
79
  const acl = await deps.acls.getArtifactAcl(artifactId);
75
80
  if (!acl || acl.storageScopeId !== invocation.storageScopeId)
@@ -81,11 +86,39 @@ export function createHttpArtifactApp(deps) {
81
86
  return acl;
82
87
  throw new ArtifactOperationError('gone');
83
88
  }
84
- if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, action === true ? 'read' : action, deps.isApprovedAccount)) {
89
+ const policy = await sharingPolicyContext(invocation.storageScopeId);
90
+ if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, action === true ? 'read' : action, deps.isApprovedAccount, policy)) {
85
91
  throw new ArtifactOperationError('not_found');
86
92
  }
87
93
  return acl;
88
94
  }
95
+ /**
96
+ * G1 management visibility for `set_access` (converged-r2 §2.3 order (2)):
97
+ * readers pass as before; any other actor gets `not_found` unless it is an
98
+ * APPROVED platform admin of the SAME storageScopeId. The predicate is
99
+ * evaluated per call — never inferred from merely being wired — so a
100
+ * non-reader non-admin cannot distinguish an existing artifact (403) from a
101
+ * missing one (404): the existence oracle is closed. The management right
102
+ * itself (owner, or admin-reduce-only) is decided inside the transaction by
103
+ * `canManageAccess` (403 otherwise). The exception never makes the admin a
104
+ * content reader.
105
+ */
106
+ async function visibleForManagement(artifactId, invocation) {
107
+ const acl = await deps.acls.getArtifactAcl(artifactId);
108
+ if (!acl || acl.storageScopeId !== invocation.storageScopeId)
109
+ throw new ArtifactOperationError('not_found');
110
+ const state = await deps.lifecycle.stateOf(artifactId);
111
+ if (acl.ownerId === invocation.actorId && (state === 'deleted' || state === 'purged'))
112
+ return acl;
113
+ const policy = await sharingPolicyContext(invocation.storageScopeId);
114
+ if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, policy)) {
115
+ return acl;
116
+ }
117
+ if (await deps.actorIsAdmin?.(invocation.actorId, invocation.storageScopeId) === true &&
118
+ deps.isApprovedAccount?.(invocation.actorId) === true)
119
+ return acl;
120
+ throw new ArtifactOperationError('not_found');
121
+ }
89
122
  /** Display metadata fields present on validated args (ensure/publish). */
90
123
  function metadataOf(normalized) {
91
124
  const meta = {};
@@ -258,7 +291,8 @@ export function createHttpArtifactApp(deps) {
258
291
  const acl = await visible(artifactId, invocation);
259
292
  const summary = artifactSummary({ artifactId, acl, actorId: invocation.actorId,
260
293
  state: await deps.lifecycle.stateOf(artifactId), current: await deps.publication.getCurrent(artifactId),
261
- urls: deps.publicationUrls, approved: deps.isApprovedAccount });
294
+ urls: deps.publicationUrls, approved: deps.isApprovedAccount,
295
+ policy: await sharingPolicyContext(invocation.storageScopeId) });
262
296
  return { ...outcome, result: { status: 201, body: profile.resultEnvelopeVersion === 2
263
297
  ? { ...summary, ...outcome.result } : { ...outcome.result, ...acl.metadata } } };
264
298
  }
@@ -269,7 +303,7 @@ export function createHttpArtifactApp(deps) {
269
303
  authorize: async () => {
270
304
  const acl = await visible(artifactId, invocation);
271
305
  const state = await deps.lifecycle.stateOf(artifactId);
272
- if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'source', deps.isApprovedAccount)) {
306
+ if (!deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'source', deps.isApprovedAccount, await sharingPolicyContext(invocation.storageScopeId))) {
273
307
  throw new ArtifactOperationError('access_denied');
274
308
  }
275
309
  }, getCurrent: deps.publication.getCurrent, getRelease: deps.publication.getRelease,
@@ -280,13 +314,20 @@ export function createHttpArtifactApp(deps) {
280
314
  commitState: 'not_committed', replayed: false };
281
315
  }
282
316
  if (capability === 'artifacts_set_access' || capability === 'artifacts_delete') {
283
- const acl = await visible(normalized.artifactId, invocation, true);
284
- if (acl.ownerId !== invocation.actorId)
317
+ const artifactId = normalized.artifactId;
318
+ const acl = capability === 'artifacts_set_access'
319
+ ? await visibleForManagement(artifactId, invocation)
320
+ : await visible(artifactId, invocation, true);
321
+ if (capability === 'artifacts_delete' && acl.ownerId !== invocation.actorId) {
285
322
  throw new ArtifactOperationError('access_denied');
323
+ }
286
324
  const outcome = await manageArtifact({ coordinator: deps.coordinator,
287
325
  createUnit: deps.management?.createUnit ?? createPostgresManagementUnit,
288
326
  confirmation: deps.management?.confirmation, readPolicyRevision: () => deps.ensureHost.readPolicyRevision(),
289
327
  isApprovedPrincipal: deps.isApprovedAccount ?? (() => false),
328
+ sharingPolicy: deps.sharingPolicy,
329
+ profileAllowPublicSharing: profile.rules.allowPublicSharing,
330
+ actorIsAdmin: deps.actorIsAdmin,
290
331
  validateNewCommand: () => { profile.validate(capability, args, request.idempotencyKey); },
291
332
  }, invocation, command, normalized.confirmationRef);
292
333
  return outcome.ok ? { ...outcome, result: { status: 200, body: outcome.result } } : outcome;
@@ -355,7 +396,8 @@ export function createHttpArtifactApp(deps) {
355
396
  const current = await deps.publication.getCurrent(artifactId);
356
397
  return { ok: true, invocationId: invocation.invocationId, commitState: 'not_committed', replayed: false,
357
398
  result: { status: 200, body: { ...artifactSummary({ artifactId, acl, state, current,
358
- actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount }),
399
+ actorId: invocation.actorId, urls: deps.publicationUrls, approved: deps.isApprovedAccount,
400
+ policy: await sharingPolicyContext(invocation.storageScopeId) }),
359
401
  ...(acl.metadata !== undefined ? { metadata: acl.metadata } : {}),
360
402
  ...(acl.ownerId === invocation.actorId ? { grants: acl.grants } : {}) } } };
361
403
  }
@@ -385,14 +427,16 @@ export function createHttpArtifactApp(deps) {
385
427
  result: { status: 200, body: { artifactId, total: releases.length, releases } } };
386
428
  }
387
429
  const visibleArtifacts = [];
430
+ const listPolicy = await sharingPolicyContext(invocation.storageScopeId);
388
431
  for (const artifactId of await deps.acls.listArtifactIds()) {
389
432
  const acl = await deps.acls.getArtifactAcl(artifactId);
390
433
  if (!acl || acl.storageScopeId !== invocation.storageScopeId)
391
434
  continue;
392
435
  const state = await deps.lifecycle.stateOf(artifactId);
393
- if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount)) {
436
+ if (deps.lifecycle.canRead({ artifactId, state }, acl, invocation.actorId, 'read', deps.isApprovedAccount, listPolicy)) {
394
437
  visibleArtifacts.push(artifactSummary({ artifactId, acl, state, actorId: invocation.actorId,
395
- current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls, approved: deps.isApprovedAccount }));
438
+ current: await deps.publication.getCurrent(artifactId), urls: deps.publicationUrls,
439
+ approved: deps.isApprovedAccount, policy: listPolicy }));
396
440
  }
397
441
  }
398
442
  const offset = normalized.offset;
@@ -1,5 +1,5 @@
1
1
  /** Platform-free provider composition over the shared typed HTTP application. */
2
- import type { AppConnectorProviderAdapter, AppMcpProviderManifest, AppToolInvocation } from '@sentropic/mcp-platform';
2
+ import type { AppConnectorProviderAdapter, AppMcpProviderManifest, AppToolInvocation, CapabilityTool } from '@sentropic/mcp-platform';
3
3
  import type { ProviderParameterSchema } from '@sentropic/mcp-platform/registry';
4
4
  import type { ArtifactApp, HttpResponse } from './http.js';
5
5
  import { type CompiledArtifactsProfile } from './profile/index.js';
@@ -10,9 +10,19 @@ 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.8";
13
+ export declare const ARTIFACTS_PROVIDER_VERSION = "0.2.10";
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"];
15
15
  export type ArtifactsToolName = (typeof ARTIFACTS_TOOL_NAMES)[number];
16
+ export interface ArtifactsToolDefinition {
17
+ readonly description: string;
18
+ readonly inputSchema: Record<string, unknown>;
19
+ readonly outputSchema: Record<string, unknown>;
20
+ readonly mutability: CapabilityTool['mutability'];
21
+ readonly idempotency: CapabilityTool['idempotency'];
22
+ readonly gates: CapabilityTool['gates'];
23
+ }
24
+ /** Static wire definitions for every artifacts tool; identical across deployments and profiles. */
25
+ export declare const ARTIFACTS_TOOL_DEFINITIONS: Readonly<Record<ArtifactsToolName, ArtifactsToolDefinition>>;
16
26
  export declare const ARTIFACTS_TOOL_SPECS: {
17
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";
18
28
  description: string;
package/dist/mcp-core.js CHANGED
@@ -2,21 +2,108 @@ import { assertArtifactsTransportProfile } from './http.js';
2
2
  import { ARTIFACT_CAPABILITY_NAMES, ArtifactProfileInputError } from './profile/index.js';
3
3
  import { ArtifactOperationError, classifyArtifactFailure } from './server/failures.js';
4
4
  import { projectArtifactHttpOutcome, projectArtifactMcpOutcome } from './server/outcome-projection.js';
5
- import { ARTIFACT_RESULT_SCHEMA } from './server/result-schema.js';
6
5
  export * from './profile/index.js';
7
6
  export { createRadarKeyDerivation } from './server/command-identity.js';
8
7
  export const ARTIFACTS_PROVIDER_ID = 'sentropic.artifacts';
9
8
  export const ARTIFACTS_APP_ID = 'sentropic-artifacts';
10
- export const ARTIFACTS_PROVIDER_VERSION = '0.2.8';
9
+ export const ARTIFACTS_PROVIDER_VERSION = '0.2.10';
11
10
  export const ARTIFACTS_TOOL_NAMES = ARTIFACT_CAPABILITY_NAMES;
11
+ // ---------------------------------------------------------------------------
12
+ // Byte-stable tool definitions (MCP tool-definition stability rule).
13
+ //
14
+ // MCP hosts such as claude.ai reset per-tool "Always allow" permissions
15
+ // whenever a tool definition (description, inputSchema, outputSchema,
16
+ // annotations, _meta) changes between sessions. Every value below is a
17
+ // compile-time constant: no profile revision, provider version, digest,
18
+ // limit, default or date may appear in a definition. The active profile
19
+ // still constrains invocations server-side (profile.validate) and stays
20
+ // visible in manifest audit metadata and typed result details — never in a
21
+ // tool definition. The APP-P1 manifest pin keeps covering these
22
+ // definitions, so the pin is stable across profile switches as well.
23
+ // ---------------------------------------------------------------------------
24
+ const str = { type: 'string', minLength: 1 };
25
+ const integer = (minimum, maximum) => ({ type: 'integer', minimum,
26
+ ...(maximum === undefined ? {} : { maximum }) });
27
+ const obj = (properties, required = []) => ({ type: 'object', properties, required, additionalProperties: false });
28
+ const id = { type: 'string',
29
+ pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$' };
30
+ const idempotencyKey = { type: 'string', minLength: 1, description: 'Nonblank by JavaScript trim(); the active profile bounds its length in UTF-16 units; original bytes retained.' };
31
+ const expectedCurrentReleaseId = { ...id, type: ['string', 'null'], description: 'Compare the current release atomically; null requires an unpublished artifact.' };
32
+ const primitiveRecord = { type: 'object',
33
+ additionalProperties: { type: ['string', 'number', 'boolean', 'null'] } };
34
+ const metadata = {
35
+ title: { type: 'string', minLength: 1, maxLength: 160, description: 'Artifact display title.' },
36
+ description: { type: 'string', maxLength: 2000, description: 'Short artifact description.' },
37
+ icon: { type: ['string', 'null'], pattern: '^[a-z][a-z0-9-]{0,31}$',
38
+ description: 'One short lowercase word.' },
39
+ };
40
+ const path = { type: 'string', minLength: 1, description: 'Manifest path; the active profile bounds its byte length and forbids reserved or dot segments, enforced server-side with typed errors.' };
41
+ const file = { ...obj({ path, mimeType: str, text: { type: 'string' },
42
+ bytes: { type: 'array', items: integer(0, 255) } }, ['path', 'mimeType']),
43
+ oneOf: [{ required: ['text'], not: { required: ['bytes'] } },
44
+ { required: ['bytes'], not: { required: ['text'] } }] };
45
+ const edit = obj({ path, oldStr: str, newStr: { type: 'string' } }, ['path', 'oldStr', 'newStr']);
46
+ const idOnly = obj({ artifactId: id }, ['artifactId']);
47
+ const ARTIFACTS_OUTPUT_SCHEMA = { type: 'object', additionalProperties: true };
48
+ const READ_ONLY_TOOLS = ['artifacts_list', 'artifacts_get',
49
+ 'artifacts_get_template', 'artifacts_get_api_guide', 'artifacts_get_source', 'artifacts_list_versions'];
50
+ const IDEMPOTENT_WRITERS = ['artifacts_ensure', 'artifacts_publish',
51
+ 'artifacts_commit_upload', 'artifacts_set_access', 'artifacts_delete', 'artifacts_revert'];
52
+ function staticTool(name, inputSchema, description) {
53
+ return {
54
+ description: description ?? `Artifacts ${name.slice('artifacts_'.length).replaceAll('_', ' ')}.`,
55
+ inputSchema,
56
+ outputSchema: ARTIFACTS_OUTPUT_SCHEMA,
57
+ mutability: READ_ONLY_TOOLS.includes(name) ? 'read-only'
58
+ : name === 'artifacts_publish' ? 'append' : 'state-transition',
59
+ idempotency: IDEMPOTENT_WRITERS.includes(name) ? { required: true, scope: 'principal' } : { required: false },
60
+ gates: { requiresElicitation: false, requiresHumanConfirmation: name === 'artifacts_delete',
61
+ requiresPrincipalGate: false },
62
+ };
63
+ }
64
+ /** Static wire definitions for every artifacts tool; identical across deployments and profiles. */
65
+ export const ARTIFACTS_TOOL_DEFINITIONS = {
66
+ artifacts_get_template: staticTool('artifacts_get_template', obj({ templateId: str }, ['templateId'])),
67
+ artifacts_get_api_guide: staticTool('artifacts_get_api_guide', obj({ version: str })),
68
+ artifacts_ensure: staticTool('artifacts_ensure', obj({ bindingName: str, parameters: obj({}),
69
+ idempotencyKey, ...metadata }, ['bindingName', 'idempotencyKey'])),
70
+ artifacts_publish: staticTool('artifacts_publish', { ...obj({ artifactId: id, idempotencyKey,
71
+ files: { type: 'array', items: file, minItems: 1,
72
+ description: 'Full file set; required unless edits is supplied.' },
73
+ edits: { type: 'array', items: edit, minItems: 1, maxItems: 100,
74
+ description: 'Small old/new edits applied to the current release text files; required unless files is supplied.' },
75
+ expectedCurrentReleaseId, profile: primitiveRecord, ...metadata }, ['artifactId', 'idempotencyKey']),
76
+ oneOf: [{ required: ['files'], not: { required: ['edits'] } },
77
+ { required: ['edits'], not: { required: ['files'] } }] }),
78
+ artifacts_create_upload: staticTool('artifacts_create_upload', obj({ artifactId: id, mimeType: str,
79
+ maxSize: integer(1) }, ['artifactId', 'mimeType'])),
80
+ artifacts_commit_upload: staticTool('artifacts_commit_upload', obj({ artifactId: id, uploadId: str,
81
+ path, mimeType: str, digest: str, size: integer(0), profile: primitiveRecord, idempotencyKey }, ['artifactId', 'uploadId', 'path', 'mimeType', 'digest', 'size', 'idempotencyKey'])),
82
+ artifacts_list: staticTool('artifacts_list', obj({ limit: integer(1), offset: integer(0) })),
83
+ artifacts_get: staticTool('artifacts_get', idOnly),
84
+ artifacts_get_source: staticTool('artifacts_get_source', obj({ artifactId: id, releaseId: id,
85
+ 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
+ + 'or `base64` (encoding "base64"), never an integer array, plus a guideRef instead of the guide body.'),
87
+ artifacts_fork: staticTool('artifacts_fork', idOnly),
88
+ artifacts_set_access: staticTool('artifacts_set_access', { ...obj({ artifactId: id,
89
+ action: { type: 'string', enum: ['grant', 'revoke'] }, principalId: { ...str, maxLength: 256 },
90
+ grant: { type: 'string', enum: ['read'] }, idempotencyKey }, ['artifactId', 'action', 'principalId', 'idempotencyKey']), oneOf: [
91
+ { properties: { action: { enum: ['grant'] } }, required: ['grant'] },
92
+ { properties: { action: { enum: ['revoke'] } }, not: { required: ['grant'] } },
93
+ ] }),
94
+ artifacts_promote: staticTool('artifacts_promote', obj({ artifactId: id, releaseId: id, expectedCurrent: id }, ['artifactId', 'releaseId', 'expectedCurrent'])),
95
+ artifacts_renew: staticTool('artifacts_renew', idOnly),
96
+ artifacts_delete: staticTool('artifacts_delete', obj({ artifactId: id, expectedCurrentReleaseId,
97
+ idempotencyKey, confirmationRef: { ...str, maxLength: 4096 } }, ['artifactId', 'idempotencyKey'])),
98
+ artifacts_restore: staticTool('artifacts_restore', idOnly),
99
+ artifacts_list_versions: staticTool('artifacts_list_versions', obj({ artifactId: id,
100
+ limit: integer(1, 100), cursor: { ...str, maxLength: 4096 } }, ['artifactId'])),
101
+ artifacts_revert: staticTool('artifacts_revert', obj({ artifactId: id, releaseId: id, targetReleaseId: id,
102
+ expectedCurrentReleaseId, idempotencyKey }, ['artifactId', 'idempotencyKey'])),
103
+ };
12
104
  export const ARTIFACTS_TOOL_SPECS = ARTIFACTS_TOOL_NAMES.map((name) => ({ name,
13
- description: name === 'artifacts_get_source'
14
- ? 'Artifacts get source: verified files of the current or a selected release as `text` (encoding "utf8") '
15
- + 'or `base64` (encoding "base64"), never an integer array, plus a guideRef instead of the guide body.'
16
- : `Artifacts ${name.slice('artifacts_'.length).replaceAll('_', ' ')}.`,
17
- mutability: (['artifacts_list', 'artifacts_get', 'artifacts_get_template', 'artifacts_get_api_guide',
18
- 'artifacts_get_source', 'artifacts_list_versions'].includes(name) ? 'read-only' : name === 'artifacts_publish' ? 'append' : 'state-transition'),
19
- }));
105
+ description: ARTIFACTS_TOOL_DEFINITIONS[name].description,
106
+ mutability: ARTIFACTS_TOOL_DEFINITIONS[name].mutability }));
20
107
  export const ARTIFACTS_PARAMETER_SCHEMA = { properties: {}, required: [] };
21
108
  export function createArtifactsManifest(options) {
22
109
  assertArtifactsTransportProfile(options?.profile);
@@ -26,17 +113,20 @@ export function createArtifactsManifest(options) {
26
113
  appId: ARTIFACTS_APP_ID, providerId: ARTIFACTS_PROVIDER_ID, version: ARTIFACTS_PROVIDER_VERSION,
27
114
  displayName: options.displayName ?? 'Sentropic Artifacts',
28
115
  resources: [], prompts: [],
29
- tools: ARTIFACTS_TOOL_SPECS.filter((spec) => profile.selectedCapabilities.includes(spec.name)).map((spec) => ({
30
- kind: 'tool', name: spec.name,
31
- description: spec.description + (profile.profileRevisionId
32
- ? ` Active profile: ${profile.profileRevisionId}; resultEnvelopeVersion: ${profile.resultEnvelopeVersion}.` : ''),
33
- inputSchema: profile.schemas[spec.name], outputSchema: profile.resultEnvelopeVersion === 2
34
- ? ARTIFACT_RESULT_SCHEMA : { type: 'object', additionalProperties: true },
35
- requiredScopes: [...scopes], requiredClaims: [], redactionClass: 'low',
36
- mutability: spec.mutability, mutatesExternalSystem: spec.mutability !== 'read-only',
37
- idempotency: profile.idempotency[spec.name] ?? { required: false },
38
- gates: { requiresElicitation: false, requiresHumanConfirmation: spec.name === 'artifacts_delete', requiresPrincipalGate: false },
39
- })),
116
+ // Tool definitions come only from ARTIFACTS_TOOL_DEFINITIONS: the profile selects
117
+ // which tools exist, but never what a definition says.
118
+ tools: ARTIFACTS_TOOL_NAMES.filter((name) => profile.selectedCapabilities.includes(name)).map((name) => {
119
+ const definition = ARTIFACTS_TOOL_DEFINITIONS[name];
120
+ return {
121
+ kind: 'tool', name,
122
+ description: definition.description,
123
+ inputSchema: definition.inputSchema, outputSchema: definition.outputSchema,
124
+ requiredScopes: [...scopes], requiredClaims: [], redactionClass: 'low',
125
+ mutability: definition.mutability, mutatesExternalSystem: definition.mutability !== 'read-only',
126
+ idempotency: definition.idempotency,
127
+ gates: definition.gates,
128
+ };
129
+ }),
40
130
  authz: { requiredClaims: [], scopes, tenantResolution: 'custom-resolver' },
41
131
  // The existing manifest codec includes audit metadata, including for an empty tool set.
42
132
  audit: { eventKinds: ['invoke'], artifactsProfileDigest: profile.profileDigest }, durability: {},
@@ -20,6 +20,8 @@ export interface ArtifactProfileRules {
20
20
  readonly forbiddenPathPattern: string;
21
21
  readonly reservedFirstSegments: readonly string[];
22
22
  readonly mimeTypes: readonly string[];
23
+ /** G1 lock 1 (deployment): allow the `public` sharing mode; absent ⇒ closed. */
24
+ readonly allowPublicSharing?: boolean;
23
25
  }
24
26
  export interface ArtifactProviderProfile {
25
27
  /** Trusted public contract revision; independent from the host policy revision. */
@@ -66,9 +66,11 @@ export function compileArtifactsProfile(input) {
66
66
  }
67
67
  const rules = profile.rules;
68
68
  const ruleKeys = ['lengthUnit', 'textEncoding', 'callerKeyNormalization', 'rejectLoneSurrogates',
69
- 'provenance', 'keyDerivationAlgorithm', 'pathMaxBytes', 'forbiddenPathPattern', 'reservedFirstSegments', 'mimeTypes'];
69
+ 'provenance', 'keyDerivationAlgorithm', 'pathMaxBytes', 'forbiddenPathPattern', 'reservedFirstSegments', 'mimeTypes',
70
+ 'allowPublicSharing'];
70
71
  if (!rules || rules.lengthUnit !== 'utf16' || rules.textEncoding !== 'utf8' || rules.callerKeyNormalization !== 'none' ||
71
72
  Object.keys(rules).some((key) => !ruleKeys.includes(key)) ||
73
+ (rules.allowPublicSharing !== undefined && typeof rules.allowPublicSharing !== 'boolean') ||
72
74
  rules.rejectLoneSurrogates !== true || rules.provenance !== 'inline-original' ||
73
75
  typeof rules.keyDerivationAlgorithm !== 'string' || !rules.keyDerivationAlgorithm ||
74
76
  !Number.isSafeInteger(rules.pathMaxBytes) || rules.pathMaxBytes < 1 || rules.pathMaxBytes > 1024 ||