@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,82 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { createTransport, ApiError } from '../../api/client.js';
3
+ import { nativeExperimentsApi } from '../../api/native-experiments.js';
4
+ import { resolveRemote, resolveToken } from '../config.js';
5
+ import { emitJson, fail } from '../helpers.js';
6
+ const id = (v) => { if (!/^[a-f0-9]{24}$/.test(v))
7
+ throw Error('Expected a native run or job ID (24 hex characters).'); return v; };
8
+ const uuid = (v) => { if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(v))
9
+ throw Error('Expected a UUID writer or idempotency key.'); return v.toLowerCase(); };
10
+ export async function runExperimentManagement(group, action, opts, subject) {
11
+ try {
12
+ const token = resolveToken();
13
+ if (!token)
14
+ throw Error('DreamLake login is required; run dl login.');
15
+ const api = nativeExperimentsApi(createTransport({ remote: resolveRemote(), token }), opts.namespace, opts.project);
16
+ let result;
17
+ const query = { ...(opts.limit !== undefined ? { limit: Number(opts.limit) } : {}), ...(opts.cursor !== undefined ? { cursor: opts.cursor } : {}) };
18
+ if (opts.limit !== undefined && (!/^[1-9][0-9]*$/.test(opts.limit) || !Number.isSafeInteger(query.limit) || query.limit > 100))
19
+ throw Error('--limit must be 1-100.');
20
+ if (group === 'writers') {
21
+ if (action === 'list')
22
+ result = await api.writers.list(query);
23
+ else if (action === 'create')
24
+ result = await api.writers.create(uuid(opts.idempotencyKey), opts.runId === undefined ? undefined : id(opts.runId));
25
+ else if (action === 'inspect')
26
+ result = await api.writers.get(uuid(subject));
27
+ else {
28
+ const generation = Number(opts.expectedGeneration);
29
+ if (!/^[1-9][0-9]*$/.test(opts.expectedGeneration ?? '') || !Number.isSafeInteger(generation))
30
+ throw Error('--expected-generation must be the writer generation you inspected.');
31
+ result = await api.writers[action](uuid(subject), generation);
32
+ }
33
+ }
34
+ else {
35
+ if (action === 'submit') {
36
+ const spec = JSON.parse(readFileSync(opts.spec, 'utf8'));
37
+ if (!spec || typeof spec !== 'object' || Array.isArray(spec) || typeof spec.requestId !== 'string' || typeof spec.target !== 'string' || !spec.execution || !spec.source)
38
+ throw Error('--spec must contain requestId, target, execution and explicit source.files.');
39
+ result = await api.jobs.submit(spec);
40
+ }
41
+ else if (action === 'list')
42
+ result = await api.jobs.list(query);
43
+ else if (action === 'logs')
44
+ result = await api.jobs.logs(id(subject), { cursor: opts.cursor });
45
+ else if (action === 'cancel')
46
+ result = await api.jobs.cancel(id(subject));
47
+ else
48
+ result = await api.jobs.summary(id(subject));
49
+ }
50
+ emitJson(result);
51
+ return 0;
52
+ }
53
+ catch (error) {
54
+ const code = error instanceof ApiError ? error.code : 'NATIVE_INVALID_REQUEST';
55
+ const message = error instanceof ApiError ? `Experiment request failed (HTTP ${error.status}); inspect the original operation before retrying.` : error instanceof Error ? error.message : 'Experiment request failed.';
56
+ if (opts.json)
57
+ emitJson({ ok: false, error: { code, message } });
58
+ else
59
+ fail(`${code}: ${message}`);
60
+ return 1;
61
+ }
62
+ }
63
+ export function registerExperimentManagementCommands(parent) {
64
+ const common = (c) => c.requiredOption('--namespace <slug>', 'DreamLake namespace').requiredOption('--project <slug>', 'DreamLake project').option('--json', 'structured errors (success is JSON)');
65
+ for (const group of ['writers', 'jobs']) {
66
+ const root = parent.command(group).description(group === 'writers' ? 'native project writer metadata and session lifecycle' : 'native project compute jobs on configured hosts');
67
+ const act = (action) => (...input) => { const options = input.find(v => v && typeof v === 'object' && !v.commands); return runExperimentManagement(group, action, options, input.find(v => typeof v === 'string')).then(code => { process.exitCode = code; }); };
68
+ common(root.command('list').description(`list project ${group}`)).option('--limit <count>', 'page size, 1-100').option('--cursor <cursor>', 'server nextCursor').action(act('list'));
69
+ if (group === 'writers') {
70
+ common(root.command('create').description('register or recover one writer intent')).requiredOption('--idempotency-key <uuid>', 'stable creation intent UUID').option('--run-id <id>', 'bind to exactly this existing run').action(act('create'));
71
+ common(root.command('inspect <writer-id>').description('inspect one writer')).action(act('inspect'));
72
+ for (const action of ['rotate', 'retire'])
73
+ common(root.command(`${action} <writer-id>`).description(`${action} the inspected writer generation`)).requiredOption('--expected-generation <number>', 'generation from inspect').action(act(action));
74
+ }
75
+ else {
76
+ common(root.command('submit').description('submit an explicit native job manifest')).requiredOption('--spec <path>', 'JSON manifest: requestId, target, enrollmentId?, execution, source, timeoutSeconds?').action(act('submit'));
77
+ common(root.command('show <job-id>').description('show job receipt and native run binding')).action(act('summary'));
78
+ common(root.command('cancel <job-id>').description('request cancellation of a job in this project')).action(act('cancel'));
79
+ common(root.command('logs <job-id>').description('read job output after checking project binding')).option('--cursor <cursor>', 'server output cursor').action(act('logs'));
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,86 @@
1
+ import type { ParsedArgs } from './types.js';
2
+ import type { LocalStorage } from './local/storage.js';
3
+ import type { ExperimentInfo, ExperimentUploadClient } from './upload.js';
4
+ import type { ExperimentDownloadClient, RemoteExperiment } from './download.js';
5
+ import { type Context } from './context.js';
6
+ import { validName } from './transport.js';
7
+ /**
8
+ * Make sure a canonical DreamLake project exists, creating it PRIVATE when it does not, as the old
9
+ * uploader's upsert did. A readable project is used as is; a slug held by a project the caller cannot
10
+ * see is reported, never taken over; a missing namespace is never created. Auth, network and other
11
+ * errors propagate unchanged, so only a real "not found" leads to a create.
12
+ */
13
+ export declare function ensureProject(c: Context, ns: string, project: string, description?: string): Promise<{
14
+ created: boolean;
15
+ project: Record<string, any>;
16
+ }>;
17
+ export { validName };
18
+ /** RemoteClient's upload surface over native REST. Run IDs map to their project route. */
19
+ declare class NativeUploadClient implements ExperimentUploadClient {
20
+ readonly c: Context;
21
+ private readonly bases;
22
+ /** Capabilities per `namespace/project`, read in the preflight (after the project exists). */
23
+ readonly caps: Map<string, string[]>;
24
+ personal: string | null;
25
+ constructor(c: Context);
26
+ private run;
27
+ createOrUpdateExperiment(args: Parameters<ExperimentUploadClient['createOrUpdateExperiment']>[0]): Promise<any>;
28
+ /** `write_protected`: a person's protection, set last (PATCH `writeProtected: true`), after all data was written. */
29
+ protectExperiment(id: string): Promise<void>;
30
+ setParameters(id: string, data: Record<string, unknown>): Promise<any>;
31
+ createLogEntries(id: string, logs: Record<string, unknown>[]): Promise<any>;
32
+ appendBatchToMetric(id: string, name: string, points: unknown[]): Promise<any>;
33
+ uploadFile(args: Parameters<ExperimentUploadClient['uploadFile']>[0]): Promise<any>;
34
+ }
35
+ interface PreflightItem {
36
+ info: ExperimentInfo;
37
+ validation: {
38
+ metadata?: Record<string, any>;
39
+ };
40
+ fullPrefix: string;
41
+ targetProject: string;
42
+ }
43
+ /** The upload pipeline's native target: its client, state identity and pre-write check. */
44
+ export declare function nativeUploadTarget(args: ParsedArgs): {
45
+ client: NativeUploadClient;
46
+ server: string;
47
+ stateIdentity: string;
48
+ preflight: (storage: LocalStorage, items: PreflightItem[], skipLogs: boolean, skipMetrics: boolean) => Promise<string[]>;
49
+ };
50
+ /** RemoteClient's download surface over native REST, for one DreamLake project. */
51
+ declare class NativeDownloadClient implements ExperimentDownloadClient {
52
+ private readonly c;
53
+ private readonly fileRuns;
54
+ private readonly bindrSupport;
55
+ /** The project route of each discovered run: a glob may select runs of several projects. */
56
+ readonly bases: Map<string, string>;
57
+ constructor(c: Context);
58
+ private run;
59
+ getParameters(id: string): Promise<Record<string, unknown>>;
60
+ queryLogs(id: string, opts?: Parameters<ExperimentDownloadClient['queryLogs']>[1]): Promise<any>;
61
+ listMetrics(id: string): Promise<any[]>;
62
+ /** Native metrics have no chunk index: the pipeline reads them by index pages instead. */
63
+ getMetricStats(): Promise<any>;
64
+ downloadMetricChunk(): Promise<any>;
65
+ getMetricData(id: string, name: string, opts?: {
66
+ startIndex?: number;
67
+ limit?: number;
68
+ bufferOnly?: boolean;
69
+ }): Promise<any>;
70
+ /** Native file listing is one response: the first page holds every file. */
71
+ listFiles(id: string, _limit?: number, offset?: number): Promise<any>;
72
+ bindrs(id: string, itemKind?: string, itemId?: string): Promise<string[]>;
73
+ downloadFileStreaming(fileId: string, destPath: string): Promise<string>;
74
+ }
75
+ /** The download pipeline's native source: `-p namespace/project[/folder…|/glob]` (globs anywhere), every page of runs. */
76
+ export declare function nativeDownloadSource(args: ParsedArgs): {
77
+ client: NativeDownloadClient;
78
+ stateIdentity: string;
79
+ discover(experiment?: string): Promise<RemoteExperiment[]>;
80
+ };
81
+ export declare function reportNativeError(e: unknown): number;
82
+ /** `upload --tracks FILE --remote-path ns/project/run/topic --backend native` */
83
+ export declare function uploadTrackNative(args: ParsedArgs): Promise<number>;
84
+ /** `download --tracks ns/project/run/topic [--format F] [-o FILE] --backend native` */
85
+ export declare function downloadTrackNative(args: ParsedArgs): Promise<number>;
86
+ export declare function runNativeTransfer(work: () => Promise<number>): Promise<number>;