@dreamlake/dreamlake-cli 0.116.0 → 0.118.0

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 (52) hide show
  1. package/dist/api/file-multipart.d.ts +6 -0
  2. package/dist/api/file-multipart.js +11 -0
  3. package/dist/api/index.d.ts +70 -2
  4. package/dist/api/index.js +2 -0
  5. package/dist/api/native-experiments.d.ts +25 -0
  6. package/dist/api/native-experiments.js +49 -3
  7. package/dist/api/project-access.d.ts +42 -0
  8. package/dist/api/project-access.js +67 -0
  9. package/dist/api/project-audience.d.ts +32 -0
  10. package/dist/api/project-audience.js +23 -0
  11. package/dist/api/workspace.d.ts +14 -1
  12. package/dist/api/workspace.js +5 -0
  13. package/dist/cli/create/index.d.ts +1 -0
  14. package/dist/cli/create/index.js +25 -7
  15. package/dist/cli/experiments/index.js +4 -0
  16. package/dist/cli/experiments/management.d.ts +16 -0
  17. package/dist/cli/experiments/management.js +82 -0
  18. package/dist/cli/experiments/transfer/adapter.d.ts +86 -0
  19. package/dist/cli/experiments/transfer/adapter.js +637 -0
  20. package/dist/cli/experiments/transfer/context.d.ts +13 -0
  21. package/dist/cli/experiments/transfer/context.js +20 -0
  22. package/dist/cli/experiments/transfer/download.d.ts +24 -0
  23. package/dist/cli/experiments/transfer/download.js +516 -0
  24. package/dist/cli/experiments/transfer/index.d.ts +2 -0
  25. package/dist/cli/experiments/transfer/index.js +38 -0
  26. package/dist/cli/experiments/transfer/local/safe-path.d.ts +29 -0
  27. package/dist/cli/experiments/transfer/local/safe-path.js +106 -0
  28. package/dist/cli/experiments/transfer/local/storage.d.ts +125 -0
  29. package/dist/cli/experiments/transfer/local/storage.js +432 -0
  30. package/dist/cli/experiments/transfer/transport.d.ts +7 -0
  31. package/dist/cli/experiments/transfer/transport.js +31 -0
  32. package/dist/cli/experiments/transfer/types.d.ts +48 -0
  33. package/dist/cli/experiments/transfer/types.js +1 -0
  34. package/dist/cli/experiments/transfer/upload.d.ts +58 -0
  35. package/dist/cli/experiments/transfer/upload.js +665 -0
  36. package/dist/cli/experiments/transfer/util/ansi.d.ts +24 -0
  37. package/dist/cli/experiments/transfer/util/ansi.js +70 -0
  38. package/dist/cli/experiments/transfer/util/glob.d.ts +4 -0
  39. package/dist/cli/experiments/transfer/util/glob.js +39 -0
  40. package/dist/cli/experiments/transfer/util/json.d.ts +6 -0
  41. package/dist/cli/experiments/transfer/util/json.js +58 -0
  42. package/dist/cli/experiments/transfer/util/pool.d.ts +5 -0
  43. package/dist/cli/experiments/transfer/util/pool.js +21 -0
  44. package/dist/cli/help-examples.generated.js +16 -0
  45. package/dist/cli/project/access.d.ts +10 -0
  46. package/dist/cli/project/access.js +43 -0
  47. package/dist/cli/project/index.js +19 -0
  48. package/dist/cli/project/permissions.d.ts +10 -0
  49. package/dist/cli/project/permissions.js +202 -0
  50. package/dist/cli/version.d.ts +1 -1
  51. package/dist/cli/version.js +1 -1
  52. package/package.json +9 -9
@@ -0,0 +1,6 @@
1
+ export interface FileMultipart {
2
+ body: Blob;
3
+ contentType: string;
4
+ }
5
+ /** Keep filenames literal: FormData percent-escapes quotes, which multipart receivers retain. */
6
+ export declare function fileMultipart(fields: Record<string, string>, file: Blob, filename: string): FileMultipart;
@@ -0,0 +1,11 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ /** Keep filenames literal: FormData percent-escapes quotes, which multipart receivers retain. */
3
+ export function fileMultipart(fields, file, filename) {
4
+ const boundary = `dreamlake-${randomUUID()}`;
5
+ const parts = [];
6
+ for (const [name, value] of Object.entries(fields))
7
+ parts.push(`--${boundary}\r\nContent-Disposition: form-data; name="${name}"\r\n\r\n${value}\r\n`);
8
+ const encoded = encodeURIComponent(filename).replace(/['()*]/g, c => `%${c.charCodeAt(0).toString(16).toUpperCase()}`);
9
+ parts.push(`--${boundary}\r\nContent-Disposition: form-data; name="file"; filename="file"; filename*=UTF-8''${encoded}\r\nContent-Type: ${file.type || 'application/octet-stream'}\r\n\r\n`, file, `\r\n--${boundary}--\r\n`);
10
+ return { body: new Blob(parts), contentType: `multipart/form-data; boundary=${boundary}` };
11
+ }
@@ -343,6 +343,28 @@ export declare function createApi(transport: Transport): {
343
343
  signal?: AbortSignal;
344
344
  }) => Promise<Response>;
345
345
  };
346
+ writers: {
347
+ list: (query?: {
348
+ limit?: number;
349
+ cursor?: string;
350
+ }) => Promise<unknown>;
351
+ get: (id: string) => Promise<unknown>;
352
+ create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
353
+ rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
354
+ retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
355
+ };
356
+ jobs: {
357
+ submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
358
+ list: (query?: {
359
+ limit?: number;
360
+ cursor?: string;
361
+ }) => Promise<unknown>;
362
+ summary: (id: string) => Promise<unknown>;
363
+ cancel: (id: string) => Promise<unknown>;
364
+ logs: (id: string, query?: {
365
+ cursor?: string;
366
+ }) => Promise<unknown>;
367
+ };
346
368
  setStatus: (id: string, status: import("./native-experiments.js").NativeRunStatus) => Promise<unknown>;
347
369
  };
348
370
  machine: {
@@ -706,6 +728,13 @@ export declare function createApi(transport: Transport): {
706
728
  }) => Promise<import("./skills.js").SkillFileResult>;
707
729
  };
708
730
  projects: (namespace: string) => {
731
+ create: (input: import("./workspace.js").ProjectInput) => Promise<{
732
+ [key: string]: unknown;
733
+ id: string;
734
+ slug?: string;
735
+ visibility?: string;
736
+ accessMode?: import("./project-access.js").ProjectAccessMode;
737
+ }>;
709
738
  grants: (project: string) => Promise<unknown>;
710
739
  grant: (project: string, input: ({
711
740
  granteeSlug: string;
@@ -819,11 +848,15 @@ export declare function createApi(transport: Transport): {
819
848
  update: (id: string, input: Partial<import("./common.js").JsonObject>) => Promise<import("./common.js").Resource>;
820
849
  delete: (id: string) => Promise<unknown>;
821
850
  };
851
+ audience: ({ project }: {
852
+ project: string;
853
+ }) => Promise<import("./project-audience.js").ProjectAudience>;
854
+ access: ({ project }: import("./project-access.js").ProjectAccessTarget) => Promise<import("./project-access.js").ProjectAccess>;
855
+ setAccess: ({ project, accessMode, visibility }: import("./project-access.js").ProjectAccessUpdate) => Promise<import("./project-access.js").ProjectAccess>;
822
856
  list: (query?: import("./common.js").Query) => Promise<{
823
857
  [key: string]: unknown;
824
858
  }>;
825
859
  get: (id: string) => Promise<import("./common.js").Resource>;
826
- create: (input: import("./workspace.js").ProjectInput) => Promise<import("./common.js").Resource>;
827
860
  update: (id: string, input: Partial<import("./workspace.js").ProjectInput>) => Promise<import("./common.js").Resource>;
828
861
  delete: (id: string) => Promise<unknown>;
829
862
  };
@@ -1631,6 +1664,28 @@ export declare function createClient(options: ClientOptions): {
1631
1664
  signal?: AbortSignal;
1632
1665
  }) => Promise<Response>;
1633
1666
  };
1667
+ writers: {
1668
+ list: (query?: {
1669
+ limit?: number;
1670
+ cursor?: string;
1671
+ }) => Promise<unknown>;
1672
+ get: (id: string) => Promise<unknown>;
1673
+ create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
1674
+ rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
1675
+ retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
1676
+ };
1677
+ jobs: {
1678
+ submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
1679
+ list: (query?: {
1680
+ limit?: number;
1681
+ cursor?: string;
1682
+ }) => Promise<unknown>;
1683
+ summary: (id: string) => Promise<unknown>;
1684
+ cancel: (id: string) => Promise<unknown>;
1685
+ logs: (id: string, query?: {
1686
+ cursor?: string;
1687
+ }) => Promise<unknown>;
1688
+ };
1634
1689
  setStatus: (id: string, status: import("./native-experiments.js").NativeRunStatus) => Promise<unknown>;
1635
1690
  };
1636
1691
  machine: {
@@ -1994,6 +2049,13 @@ export declare function createClient(options: ClientOptions): {
1994
2049
  }) => Promise<import("./skills.js").SkillFileResult>;
1995
2050
  };
1996
2051
  projects: (namespace: string) => {
2052
+ create: (input: import("./workspace.js").ProjectInput) => Promise<{
2053
+ [key: string]: unknown;
2054
+ id: string;
2055
+ slug?: string;
2056
+ visibility?: string;
2057
+ accessMode?: import("./project-access.js").ProjectAccessMode;
2058
+ }>;
1997
2059
  grants: (project: string) => Promise<unknown>;
1998
2060
  grant: (project: string, input: ({
1999
2061
  granteeSlug: string;
@@ -2107,11 +2169,15 @@ export declare function createClient(options: ClientOptions): {
2107
2169
  update: (id: string, input: Partial<import("./common.js").JsonObject>) => Promise<import("./common.js").Resource>;
2108
2170
  delete: (id: string) => Promise<unknown>;
2109
2171
  };
2172
+ audience: ({ project }: {
2173
+ project: string;
2174
+ }) => Promise<import("./project-audience.js").ProjectAudience>;
2175
+ access: ({ project }: import("./project-access.js").ProjectAccessTarget) => Promise<import("./project-access.js").ProjectAccess>;
2176
+ setAccess: ({ project, accessMode, visibility }: import("./project-access.js").ProjectAccessUpdate) => Promise<import("./project-access.js").ProjectAccess>;
2110
2177
  list: (query?: import("./common.js").Query) => Promise<{
2111
2178
  [key: string]: unknown;
2112
2179
  }>;
2113
2180
  get: (id: string) => Promise<import("./common.js").Resource>;
2114
- create: (input: import("./workspace.js").ProjectInput) => Promise<import("./common.js").Resource>;
2115
2181
  update: (id: string, input: Partial<import("./workspace.js").ProjectInput>) => Promise<import("./common.js").Resource>;
2116
2182
  delete: (id: string) => Promise<unknown>;
2117
2183
  };
@@ -2553,3 +2619,5 @@ export * from "./memo-facade.js";
2553
2619
  export type { MemoReadingOptions, MemoReadingPage, MemoFocusedRead, NoteReadingOptions, NoteReadingPage, NoteFocusedRead } from "./memo-reading.js";
2554
2620
  export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
2555
2621
  export type { HostMovePreview, HostMoveRequest, HostMoveReceipt, HostMoveRetainedSessions, HostMoveRetainedRuns } from "./host-moves.js";
2622
+ export * from "./project-access.js";
2623
+ export * from "./project-audience.js";
package/dist/api/index.js CHANGED
@@ -139,3 +139,5 @@ export * from "./memo-write.js";
139
139
  export { documentEdits, documentInsertion } from "./memo-edits.js";
140
140
  export * from "./memo-facade.js";
141
141
  export { lineRange, focusedRead, InvalidLineRange } from "./memo-reading.js";
142
+ export * from "./project-access.js";
143
+ export * from "./project-audience.js";
@@ -1,3 +1,4 @@
1
+ import { type FileMultipart } from "./file-multipart.js";
1
2
  import { type Transport } from "./client.js";
2
3
  import { type Query } from "./common.js";
3
4
  export interface NativeExperimentRun {
@@ -94,6 +95,8 @@ export declare function nativeLogQuery(query?: NativeLogQuery): Query;
94
95
  * The multipart body of a file upload. Text fields precede the file part: the server reads
95
96
  * only the fields received before the file, and verifies `sizeBytes` and `checksum` against it.
96
97
  */
98
+ export declare function nativeFileMultipart(upload: NativeFileUpload): Promise<FileMultipart>;
99
+ /** @deprecated Prefer nativeFileMultipart for filenames containing quotes. Kept for source compatibility. */
97
100
  export declare function nativeFileForm(upload: NativeFileUpload): Promise<FormData>;
98
101
  export declare function nativeExperimentsApi(t: Transport, namespace: string, project: string): {
99
102
  status: () => Promise<unknown>;
@@ -284,5 +287,27 @@ export declare function nativeExperimentsApi(t: Transport, namespace: string, pr
284
287
  signal?: AbortSignal;
285
288
  }) => Promise<Response>;
286
289
  };
290
+ writers: {
291
+ list: (query?: {
292
+ limit?: number;
293
+ cursor?: string;
294
+ }) => Promise<unknown>;
295
+ get: (id: string) => Promise<unknown>;
296
+ create: (idempotencyKey: string, runId?: string) => Promise<unknown>;
297
+ rotate: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
298
+ retire: (credentialId: string, expectedGeneration: number) => Promise<unknown>;
299
+ };
300
+ jobs: {
301
+ submit: (input: import("./execution.js").RunInput) => Promise<unknown>;
302
+ list: (query?: {
303
+ limit?: number;
304
+ cursor?: string;
305
+ }) => Promise<unknown>;
306
+ summary: (id: string) => Promise<unknown>;
307
+ cancel: (id: string) => Promise<unknown>;
308
+ logs: (id: string, query?: {
309
+ cursor?: string;
310
+ }) => Promise<unknown>;
311
+ };
287
312
  setStatus: (id: string, status: NativeRunStatus) => Promise<unknown>;
288
313
  };
@@ -1,4 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
+ import { fileMultipart } from "./file-multipart.js";
2
3
  import { namespaceSeg, seg } from "./client.js";
3
4
  import { call } from "./common.js";
4
5
  function trackQuery(q) {
@@ -37,6 +38,27 @@ async function sha256(data) {
37
38
  * The multipart body of a file upload. Text fields precede the file part: the server reads
38
39
  * only the fields received before the file, and verifies `sizeBytes` and `checksum` against it.
39
40
  */
41
+ export async function nativeFileMultipart(upload) {
42
+ const blob = upload.data instanceof Uint8Array
43
+ ? new Blob([upload.data], { type: upload.contentType ?? "application/octet-stream" })
44
+ : upload.data;
45
+ const fields = {
46
+ sizeBytes: String(blob.size), checksum: upload.checksum ?? await sha256(upload.data),
47
+ };
48
+ if (upload.prefix !== undefined)
49
+ fields.prefix = upload.prefix;
50
+ if (upload.description !== undefined)
51
+ fields.description = upload.description;
52
+ if (upload.tags?.length)
53
+ fields.tags = upload.tags.join(",");
54
+ if (upload.metadata !== undefined)
55
+ fields.metadata = JSON.stringify(upload.metadata);
56
+ if (upload.folderId !== undefined)
57
+ fields.folderId = upload.folderId;
58
+ const typed = upload.contentType && blob.type !== upload.contentType ? new Blob([blob], { type: upload.contentType }) : blob;
59
+ return fileMultipart(fields, typed, upload.filename);
60
+ }
61
+ /** @deprecated Prefer nativeFileMultipart for filenames containing quotes. Kept for source compatibility. */
40
62
  export async function nativeFileForm(upload) {
41
63
  const blob = upload.data instanceof Uint8Array
42
64
  ? new Blob([upload.data], { type: upload.contentType ?? "application/octet-stream" })
@@ -61,6 +83,10 @@ export async function nativeFileForm(upload) {
61
83
  export function nativeExperimentsApi(t, namespace, project) {
62
84
  const p = nativeExperimentPaths(namespace, project);
63
85
  const { base, run } = p;
86
+ const sendFile = async (method, path, upload) => {
87
+ const form = await nativeFileMultipart(upload);
88
+ return t.request(method, path, { body: form.body, headers: { "content-type": form.contentType } });
89
+ };
64
90
  return {
65
91
  status: () => call(t, "GET", `${base}/status`),
66
92
  session: (mode) => call(t, "POST", `${base}/session`, { mode }),
@@ -114,7 +140,7 @@ export function nativeExperimentsApi(t, namespace, project) {
114
140
  files: {
115
141
  list: (id, query = {}) => call(t, "GET", p.files(id), undefined, { prefix: query.prefix, tags: query.tags?.join(",") }),
116
142
  get: (id, fileId) => call(t, "GET", p.file(id, fileId)),
117
- upload: async (id, upload) => t.request("POST", p.files(id), { body: await nativeFileForm(upload) }),
143
+ upload: async (id, upload) => sendFile("POST", p.files(id), upload),
118
144
  /** The file's bytes from the central API; redirects are refused, so the bearer never leaves it. */
119
145
  download: (id, fileId, options = {}) => {
120
146
  if (!t.raw)
@@ -129,7 +155,7 @@ export function nativeExperimentsApi(t, namespace, project) {
129
155
  /** Project and folder files (README.md, `.dashrc`): not a run's. `folderId` absent or "root": the project root. */
130
156
  projectFiles: {
131
157
  list: (query = {}) => call(t, "GET", `${base}/project-files`, undefined, query),
132
- upload: async (upload) => t.request("POST", `${base}/project-files`, { body: await nativeFileForm(upload) }),
158
+ upload: async (upload) => sendFile("POST", `${base}/project-files`, upload),
133
159
  get: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}`),
134
160
  /** UTF-8 text, at most 512 KiB (larger: 413, never truncated). */
135
161
  text: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}/text`),
@@ -140,7 +166,7 @@ export function nativeExperimentsApi(t, namespace, project) {
140
166
  },
141
167
  media: (fileId) => call(t, "GET", `${base}/project-files/${seg(fileId)}/media`),
142
168
  /** New bytes for the same file: its id, name and metadata stay. */
143
- replace: async (fileId, upload) => t.request("PUT", `${base}/project-files/${seg(fileId)}/content`, { body: await nativeFileForm(upload) }),
169
+ replace: async (fileId, upload) => sendFile("PUT", `${base}/project-files/${seg(fileId)}/content`, upload),
144
170
  /** description/tags/metadata, and/or `filename` and `folderId` (null: the root) to rename or move. */
145
171
  update: (fileId, patch) => call(t, "PATCH", `${base}/project-files/${seg(fileId)}`, patch),
146
172
  delete: (fileId) => call(t, "DELETE", `${base}/project-files/${seg(fileId)}`),
@@ -171,6 +197,26 @@ export function nativeExperimentsApi(t, namespace, project) {
171
197
  ...(options.signal ? { signal: options.signal, timeoutMs: null } : {}) });
172
198
  },
173
199
  },
200
+ writers: {
201
+ list: (query = {}) => call(t, "GET", `${base}/credentials`, undefined, query),
202
+ get: (id) => call(t, "GET", `${base}/credentials/${seg(id)}`),
203
+ create: (idempotencyKey, runId) => call(t, "POST", `${base}/credentials`, { operation: "create", idempotencyKey, ...(runId ? { runId } : {}) }),
204
+ rotate: (credentialId, expectedGeneration) => call(t, "POST", `${base}/credentials`, { operation: "rotate", credentialId, expectedGeneration }),
205
+ retire: (credentialId, expectedGeneration) => call(t, "POST", `${base}/credentials`, { operation: "retire", credentialId, expectedGeneration }),
206
+ },
207
+ jobs: {
208
+ submit: (input) => call(t, "POST", `${base}/jobs`, input),
209
+ list: (query = {}) => call(t, "GET", `${base}/jobs`, undefined, query),
210
+ summary: (id) => call(t, "GET", `${base}/jobs/${seg(id)}/summary`),
211
+ cancel: async (id) => {
212
+ await call(t, "GET", `${base}/jobs/${seg(id)}/summary`);
213
+ return call(t, "POST", `/namespaces/${namespaceSeg(namespace)}/runs/${seg(id)}/cancel`);
214
+ },
215
+ logs: async (id, query = {}) => {
216
+ await call(t, "GET", `${base}/jobs/${seg(id)}/summary`);
217
+ return call(t, "GET", `/namespaces/${namespaceSeg(namespace)}/runs/${seg(id)}/logs`, undefined, query);
218
+ },
219
+ },
174
220
  setStatus: (id, status) => call(t, "POST", `${run(id)}/status`, { status }),
175
221
  };
176
222
  }
@@ -0,0 +1,42 @@
1
+ import { type Transport } from './client.js';
2
+ export type ProjectAccessMode = 'workspace' | 'restricted';
3
+ export type ProjectVisibility = 'private' | 'public';
4
+ export interface ProjectAccess {
5
+ projectId: string;
6
+ namespace: string;
7
+ projectSlug: string;
8
+ accessMode: ProjectAccessMode;
9
+ visibility: ProjectVisibility;
10
+ baseline: {
11
+ orgMembers: 'READ' | null;
12
+ namespaceOwners: 'ADMIN';
13
+ public: 'READ' | null;
14
+ };
15
+ viewerRole: 'READ' | 'WRITE' | 'ADMIN';
16
+ manageGrants: boolean;
17
+ }
18
+ export interface ProjectAccessTarget {
19
+ project: string;
20
+ }
21
+ export interface ProjectAccessUpdate extends ProjectAccessTarget {
22
+ accessMode: ProjectAccessMode;
23
+ /** Explicitly make a public Project private when switching to restricted. */
24
+ visibility?: ProjectVisibility;
25
+ }
26
+ export declare function validateProjectAccess(value: unknown, namespace: string, project: string): ProjectAccess;
27
+ /** Same access endpoint used by the product; authorization remains server-side. */
28
+ export declare function projectAccessApi(t: Transport, namespace: string): {
29
+ access: ({ project }: ProjectAccessTarget) => Promise<ProjectAccess>;
30
+ setAccess: ({ project, accessMode, visibility }: ProjectAccessUpdate) => Promise<ProjectAccess>;
31
+ };
32
+ /** Restricted creation requires advertised atomic server support before POST. */
33
+ export declare function createProjectWithAccess<T extends {
34
+ accessMode?: ProjectAccessMode;
35
+ visibility?: string;
36
+ }>(t: Transport, namespace: string, input: T): Promise<{
37
+ id: string;
38
+ slug?: string;
39
+ visibility?: string;
40
+ accessMode?: ProjectAccessMode;
41
+ [key: string]: unknown;
42
+ }>;
@@ -0,0 +1,67 @@
1
+ import { ApiError, seg } from './client.js';
2
+ export function validateProjectAccess(value, namespace, project) {
3
+ const out = value;
4
+ if (!out || !/^[a-f0-9]{24}$/i.test(out.projectId ?? '') || out.namespace !== namespace ||
5
+ typeof out.projectSlug !== 'string' || !out.projectSlug ||
6
+ (/^[a-f0-9]{24}$/i.test(project) ? out.projectId.toLowerCase() !== project.toLowerCase() : out.projectSlug !== project) ||
7
+ !['workspace', 'restricted'].includes(out.accessMode) || !['private', 'public'].includes(out.visibility) ||
8
+ !['READ', 'WRITE', 'ADMIN'].includes(out.viewerRole) || typeof out.manageGrants !== 'boolean' ||
9
+ !out.baseline || ![null, 'READ'].includes(out.baseline.orgMembers) || out.baseline.namespaceOwners !== 'ADMIN' ||
10
+ out.baseline.public !== (out.visibility === 'public' ? 'READ' : null) ||
11
+ (out.accessMode === 'restricted' && (out.baseline.orgMembers !== null || out.visibility !== 'private'))) {
12
+ throw new ApiError(503, 'project_access_unconfirmed', { namespace, project });
13
+ }
14
+ return out;
15
+ }
16
+ /** Same access endpoint used by the product; authorization remains server-side. */
17
+ export function projectAccessApi(t, namespace) {
18
+ const path = (project) => {
19
+ if (!namespace?.trim() || !project?.trim())
20
+ throw new Error('Explicit namespace and project ID or slug are required');
21
+ return `/namespaces/${seg(namespace)}/projects/${seg(project)}/access`;
22
+ };
23
+ return {
24
+ access: async ({ project }) => validateProjectAccess(await t.request('GET', path(project)), namespace, project),
25
+ setAccess: async ({ project, accessMode, visibility }) => {
26
+ if (!['workspace', 'restricted'].includes(accessMode))
27
+ throw new Error('accessMode must be workspace or restricted');
28
+ if (visibility !== undefined && !['private', 'public'].includes(visibility))
29
+ throw new Error('visibility must be private or public');
30
+ if (accessMode === 'restricted' && visibility === 'public')
31
+ throw new Error('Restricted Projects cannot be public');
32
+ const result = validateProjectAccess(await t.request('PATCH', path(project), {
33
+ json: { accessMode, ...(visibility !== undefined ? { visibility } : {}) },
34
+ }), namespace, project);
35
+ if (result.accessMode !== accessMode || (visibility !== undefined && result.visibility !== visibility))
36
+ throw new ApiError(503, 'project_access_unconfirmed', { namespace, project, outcome: 'unknown' });
37
+ return result;
38
+ },
39
+ };
40
+ }
41
+ /** Restricted creation requires advertised atomic server support before POST. */
42
+ export async function createProjectWithAccess(t, namespace, input) {
43
+ if (input.accessMode !== undefined && !['workspace', 'restricted'].includes(input.accessMode))
44
+ throw new Error('accessMode must be workspace or restricted');
45
+ if (input.accessMode === 'restricted' && input.visibility === 'public')
46
+ throw new Error('Restricted Projects cannot be public');
47
+ const path = `/namespaces/${seg(namespace)}/projects`;
48
+ if (input.accessMode === 'restricted') {
49
+ const listing = await t.request('GET', path, { query: { pageSize: 1 } });
50
+ const policy = listing?.accessPolicy;
51
+ if (policy?.apiVersion !== 1 || policy.atomicCreate !== true || !Array.isArray(policy.modes) || !policy.modes.includes('restricted') || !policy.modes.includes('workspace'))
52
+ throw new ApiError(501, 'PROJECT_ACCESS_UNSUPPORTED', { namespace, outcome: 'not-submitted' });
53
+ }
54
+ let result;
55
+ try {
56
+ result = await t.request('POST', path, { json: input });
57
+ }
58
+ catch (error) {
59
+ // Only the dispatched POST can be uncertain; capability failures above submit nothing.
60
+ if (input.accessMode === 'restricted' && (!(error instanceof ApiError) || error.status >= 500))
61
+ throw new ApiError(503, 'project_creation_unconfirmed', { namespace, outcome: 'unknown' });
62
+ throw error;
63
+ }
64
+ if (input.accessMode === 'restricted' && (!result || !/^[a-f0-9]{24}$/i.test(result.id ?? '') || result.accessMode !== 'restricted' || result.visibility !== 'private'))
65
+ throw new ApiError(503, 'project_creation_unconfirmed', { namespace, projectId: result?.id, outcome: 'unknown' });
66
+ return result;
67
+ }
@@ -0,0 +1,32 @@
1
+ import { type Transport } from './client.js';
2
+ import { type ProjectAccess } from './project-access.js';
3
+ export type ProjectRole = 'READ' | 'WRITE' | 'ADMIN';
4
+ export interface AudienceSource {
5
+ kind: 'owner' | 'workspace' | 'public' | 'user' | 'team';
6
+ role: ProjectRole;
7
+ grantId?: string;
8
+ teamId?: string;
9
+ label?: string;
10
+ }
11
+ export interface AudiencePerson {
12
+ userId: string;
13
+ username: string | null;
14
+ name: string | null;
15
+ effectiveRole: ProjectRole | null;
16
+ sources: AudienceSource[];
17
+ }
18
+ export interface ProjectAudience extends ProjectAccess {
19
+ apiVersion: 1;
20
+ complete: true;
21
+ limit: number;
22
+ people: AudiencePerson[];
23
+ publicAudience: string | null;
24
+ resourceBoundary: string;
25
+ }
26
+ export declare function remainingRole(sources: AudienceSource[], removedGrant?: string): ProjectRole | null;
27
+ export declare function validateProjectAudience(value: unknown, namespace: string, project: string): ProjectAudience;
28
+ export declare function projectAudienceApi(t: Transport, namespace: string): {
29
+ audience: ({ project }: {
30
+ project: string;
31
+ }) => Promise<ProjectAudience>;
32
+ };
@@ -0,0 +1,23 @@
1
+ import { ApiError, seg } from './client.js';
2
+ import { validateProjectAccess } from './project-access.js';
3
+ const id = (value) => typeof value === 'string' && /^[a-f0-9]{24}$/i.test(value);
4
+ const role = (value) => ['READ', 'WRITE', 'ADMIN'].includes(value);
5
+ export function remainingRole(sources, removedGrant) {
6
+ return sources.filter(s => !removedGrant || s.grantId !== removedGrant).reduce((best, s) => !best || ['READ', 'WRITE', 'ADMIN'].indexOf(s.role) > ['READ', 'WRITE', 'ADMIN'].indexOf(best) ? s.role : best, null);
7
+ }
8
+ export function validateProjectAudience(value, namespace, project) {
9
+ validateProjectAccess(value, namespace, project);
10
+ const a = value;
11
+ if (a.apiVersion !== 1 || a.complete !== true || a.viewerRole !== 'ADMIN' || a.manageGrants !== true ||
12
+ !Array.isArray(a.people) || a.people.length > 1000 || new Set(a.people.map(p => p?.userId)).size !== a.people.length ||
13
+ a.people.some(p => !p || !id(p.userId) || !(p.username === null || typeof p.username === 'string') || !(p.name === null || typeof p.name === 'string') ||
14
+ !(p.effectiveRole === null || role(p.effectiveRole)) || !Array.isArray(p.sources) || p.sources.some(s => !s || !['owner', 'workspace', 'public', 'user', 'team'].includes(s.kind) || !role(s.role) ||
15
+ (['user', 'team'].includes(s.kind) && !id(s.grantId)) || (s.kind === 'team' && !id(s.teamId)) ||
16
+ (s.kind === 'owner' && s.role !== 'ADMIN') || (['workspace', 'public'].includes(s.kind) && s.role !== 'READ')) ||
17
+ remainingRole(p.sources) !== p.effectiveRole))
18
+ throw new ApiError(503, 'project_audience_unconfirmed', { namespace, project });
19
+ return a;
20
+ }
21
+ export function projectAudienceApi(t, namespace) {
22
+ return { audience: async ({ project }) => validateProjectAudience(await t.request('GET', `/namespaces/${seg(namespace)}/projects/${seg(project)}/audience`), namespace, project) };
23
+ }
@@ -1,13 +1,22 @@
1
1
  export * from "./bindrs.js";
2
+ import { type ProjectAccessMode } from "./project-access.js";
2
3
  /** Workspace resource APIs. Authentication/ACLs stay in the existing service routes. */
3
4
  import { type Transport } from "./client.js";
4
5
  import { type JsonObject, type Query, type Resource } from "./common.js";
5
6
  export interface ProjectInput {
6
7
  name: string;
8
+ accessMode?: ProjectAccessMode;
7
9
  description?: string;
8
10
  visibility?: "private" | "public" | "team";
9
11
  }
10
12
  export declare function projectsApi(t: Transport, namespace: string): {
13
+ create: (input: ProjectInput) => Promise<{
14
+ [key: string]: unknown;
15
+ id: string;
16
+ slug?: string;
17
+ visibility?: string;
18
+ accessMode?: ProjectAccessMode;
19
+ }>;
11
20
  grants: (project: string) => Promise<unknown>;
12
21
  grant: (project: string, input: ({
13
22
  granteeSlug: string;
@@ -122,11 +131,15 @@ export declare function projectsApi(t: Transport, namespace: string): {
122
131
  update: (id: string, input: Partial<JsonObject>) => Promise<Resource>;
123
132
  delete: (id: string) => Promise<unknown>;
124
133
  };
134
+ audience: ({ project }: {
135
+ project: string;
136
+ }) => Promise<import("./project-audience.js").ProjectAudience>;
137
+ access: ({ project }: import("./project-access.js").ProjectAccessTarget) => Promise<import("./project-access.js").ProjectAccess>;
138
+ setAccess: ({ project, accessMode, visibility }: import("./project-access.js").ProjectAccessUpdate) => Promise<import("./project-access.js").ProjectAccess>;
125
139
  list: (query?: Query) => Promise<{
126
140
  [key: string]: unknown;
127
141
  }>;
128
142
  get: (id: string) => Promise<Resource>;
129
- create: (input: ProjectInput) => Promise<Resource>;
130
143
  update: (id: string, input: Partial<ProjectInput>) => Promise<Resource>;
131
144
  delete: (id: string) => Promise<unknown>;
132
145
  };
@@ -1,5 +1,7 @@
1
+ import { projectAudienceApi } from "./project-audience.js";
1
2
  import { bindrsApi } from "./bindrs.js";
2
3
  export * from "./bindrs.js";
4
+ import { projectAccessApi, createProjectWithAccess } from "./project-access.js";
3
5
  /** Workspace resource APIs. Authentication/ACLs stay in the existing service routes. */
4
6
  import { seg } from "./client.js";
5
7
  import { namespacePath, resourceApi, call, } from "./common.js";
@@ -15,6 +17,9 @@ export function projectsApi(t, namespace) {
15
17
  }
16
18
  return {
17
19
  ...resourceApi(t, base),
20
+ ...projectAccessApi(t, namespace),
21
+ ...projectAudienceApi(t, namespace),
22
+ create: (input) => createProjectWithAccess(t, namespace, input),
18
23
  grants: (project) => call(t, "GET", path(project) + "/grants"),
19
24
  grant: async (project, input) => {
20
25
  await manageGrant(project);
@@ -9,6 +9,7 @@ interface CreateOpts {
9
9
  export declare function runCreateBindr(name: string, opts: CreateOpts): Promise<number>;
10
10
  export declare function runCreateDataset(name: string, opts: CreateOpts): Promise<number>;
11
11
  interface CreateProjectOpts {
12
+ accessMode?: string;
12
13
  namespace?: string;
13
14
  slug?: string;
14
15
  description?: string;
@@ -1,5 +1,8 @@
1
1
  import { bindrsApi, BindrMembersError } from "../../api/bindrs.js";
2
2
  import { createTransport, namespaceSeg, seg } from "../../api/client.js";
3
+ // `dl create bindr|dataset <name> --project <target> ...`.
4
+ import { ApiError } from '../../api/client.js';
5
+ import { createClient } from '../../api/index.js';
3
6
  import { HttpError, requestJson } from "../client.js";
4
7
  import { resolveNamespace, resolveRemote, resolveToken } from "../config.js";
5
8
  import { fail, ok, splitCsv } from "../helpers.js";
@@ -126,6 +129,14 @@ export async function runCreateProject(name, opts) {
126
129
  fail(`--visibility must be 'public' or 'private', got '${opts.visibility}'`);
127
130
  return 1;
128
131
  }
132
+ if (opts.accessMode !== undefined && !['workspace', 'restricted'].includes(opts.accessMode)) {
133
+ fail('--access-mode must be workspace or restricted');
134
+ return 1;
135
+ }
136
+ if (opts.accessMode === 'restricted' && opts.visibility === 'public') {
137
+ fail('Restricted Projects cannot be public');
138
+ return 1;
139
+ }
129
140
  const remote = resolveRemote();
130
141
  const token = resolveToken();
131
142
  if (!token) {
@@ -144,19 +155,25 @@ export async function runCreateProject(name, opts) {
144
155
  body.description = opts.description;
145
156
  if (opts.visibility)
146
157
  body.visibility = opts.visibility;
158
+ if (opts.accessMode !== undefined)
159
+ body.accessMode = opts.accessMode;
147
160
  const tags = splitCsv(opts.tags);
148
161
  if (tags.length)
149
162
  body.tags = tags;
150
163
  let created;
151
164
  try {
152
- created = await requestJson(remote, `/namespaces/${namespace}/projects`, {
153
- method: "POST",
154
- token,
155
- json: body,
156
- });
165
+ created = opts.accessMode === undefined
166
+ ? await requestJson(remote, `/namespaces/${namespaceSeg(namespace)}/projects`, { method: 'POST', token, json: body })
167
+ : await createClient({ remote, token }).projects(namespace).create(body);
157
168
  }
158
169
  catch (err) {
159
- if (err instanceof HttpError && err.status === 409) {
170
+ if (err instanceof ApiError && err.code === 'project_creation_unconfirmed') {
171
+ const createdId = err.body?.projectId;
172
+ const identity = typeof createdId === 'string' && /^[a-f0-9]{24}$/i.test(createdId) ? ` Project ID: ${createdId}.` : '';
173
+ fail(`project_creation_unconfirmed: creation outcome is unknown.${identity} Inspect the same namespace before retrying creation.`);
174
+ return 1;
175
+ }
176
+ if ((err instanceof HttpError || err instanceof ApiError) && err.status === 409) {
160
177
  // Report the server's reason: a 409 here is not always a duplicate
161
178
  // slug. OPERATION_CONFLICT is a write conflict the server gave up on.
162
179
  const transient = err.code === "OPERATION_CONFLICT" || err.message === "(409) OPERATION_CONFLICT";
@@ -165,7 +182,7 @@ export async function runCreateProject(name, opts) {
165
182
  : err.message);
166
183
  return 1;
167
184
  }
168
- if (err instanceof HttpError && err.status === 404) {
185
+ if ((err instanceof HttpError || err instanceof ApiError) && err.status === 404) {
169
186
  fail(`namespace '${namespace}' not found`);
170
187
  return 1;
171
188
  }
@@ -191,6 +208,7 @@ export function registerCreateCommand(program) {
191
208
  .option("--namespace <slug>", "namespace (default: your own)")
192
209
  .option("--slug <slug>", "URL-safe slug (auto-derived from name if omitted)")
193
210
  .option("--visibility <vis>", "'public' or 'private' (default: private)")
211
+ .option("--access-mode <mode>", "workspace or restricted; restricted requires advertised atomic server support")
194
212
  .option("--public", "shortcut for --visibility public")
195
213
  .option("--description <text>", "description")
196
214
  .option("--tags <list>", "comma-separated tags")
@@ -2,6 +2,8 @@ import { HttpError, requestJson } from "../client.js";
2
2
  import { resolveRemote, resolveToken } from "../config.js";
3
3
  import { emitJson, fail } from "../helpers.js";
4
4
  import { registerNativeExperimentCommands } from "./native-commands.js";
5
+ import { registerExperimentManagementCommands } from "./management.js";
6
+ import { registerExperimentTransferCommands } from "./transfer/index.js";
5
7
  class BindingError extends Error {
6
8
  code;
7
9
  remediation;
@@ -149,6 +151,8 @@ export async function runExperiments(action, opts, selection) {
149
151
  export function registerExperimentsCommand(program) {
150
152
  const command = program.command("experiments").description("discover and explicitly bind an existing managed Dash workspace (JSON receipts)");
151
153
  registerNativeExperimentCommands(command);
154
+ registerExperimentTransferCommands(command);
155
+ registerExperimentManagementCommands(command);
152
156
  for (const action of ["workspaces", "binding", "connect", "disconnect"]) {
153
157
  const sub = command.command(action)
154
158
  .description({ workspaces: "list verified eligible Dash organization workspaces", binding: "inspect the current binding and revision", connect: "preview a workspace binding; --apply commits it", disconnect: "preview detaching; remote experiments and SDK access are retained" }[action])
@@ -0,0 +1,16 @@
1
+ /** Native project writer metadata and compute jobs. All actions use the selected DreamLake login. */
2
+ import type { Command } from 'commander';
3
+ interface Options {
4
+ namespace: string;
5
+ project: string;
6
+ json?: boolean;
7
+ limit?: string;
8
+ cursor?: string;
9
+ runId?: string;
10
+ idempotencyKey?: string;
11
+ expectedGeneration?: string;
12
+ spec?: string;
13
+ }
14
+ export declare function runExperimentManagement(group: 'writers' | 'jobs', action: string, opts: Options, subject?: string): Promise<number>;
15
+ export declare function registerExperimentManagementCommands(parent: Command): void;
16
+ export {};