@sequenceholdings/studio-cli 0.1.31 → 0.2.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 (38) hide show
  1. package/README.md +335 -26
  2. package/dist/artifact/delegate.js +11 -2
  3. package/dist/atlas-client.d.ts +16 -0
  4. package/dist/atlas-client.js +26 -0
  5. package/dist/functions/bundle.js +4 -2
  6. package/dist/functions/commands.d.ts +12 -2
  7. package/dist/functions/commands.js +176 -14
  8. package/dist/functions/dev.d.ts +3 -0
  9. package/dist/functions/dev.js +97 -0
  10. package/dist/functions/egress-preview.d.ts +2 -1
  11. package/dist/functions/egress-preview.js +3 -2
  12. package/dist/functions/manifest.d.ts +18 -1
  13. package/dist/functions/manifest.js +19 -29
  14. package/dist/main.js +6 -1
  15. package/dist/pipeline/commands.js +16 -10
  16. package/dist/pipeline/lifecycle.d.ts +1 -0
  17. package/dist/pipeline/lifecycle.js +105 -28
  18. package/dist/pipeline/migrations.js +6 -1
  19. package/dist/pipeline/stage-secrets.d.ts +95 -0
  20. package/dist/pipeline/stage-secrets.js +166 -0
  21. package/dist/pipeline/templates.d.ts +1 -1
  22. package/dist/pipeline/templates.js +37 -3
  23. package/dist/process/build.js +1 -0
  24. package/dist/process/codegen.js +1 -0
  25. package/dist/process/lint.js +12 -7
  26. package/dist/process/plan-diff.js +1 -0
  27. package/dist/process/safety-baseline.d.ts +3 -3
  28. package/dist/process/safety-baseline.js +4 -5
  29. package/dist/process/simulate.js +7 -2
  30. package/dist/repos/commands.d.ts +11 -1
  31. package/dist/repos/commands.js +37 -11
  32. package/dist/secrets/commands.d.ts +1 -1
  33. package/dist/secrets/commands.js +73 -3
  34. package/dist/storage/commands.d.ts +2 -0
  35. package/dist/storage/commands.js +215 -0
  36. package/dist/templates/process/pnpm-workspace.yaml +3 -0
  37. package/package.json +7 -5
  38. package/templates/process/pnpm-workspace.yaml +3 -0
@@ -0,0 +1,215 @@
1
+ import { createReadStream, createWriteStream } from 'node:fs';
2
+ import { readFile, stat, writeFile } from 'node:fs/promises';
3
+ import { basename, resolve } from 'node:path';
4
+ import { Readable } from 'node:stream';
5
+ import { pipeline } from 'node:stream/promises';
6
+ import { randomUUID } from 'node:crypto';
7
+ import { load as yaml } from 'js-yaml';
8
+ import { storageClient, workspaceManifestSchema, startUploadSchema, updateStorageAccessSchema, } from '@sequenceholdings/storage';
9
+ import { getAccessTokenWithMode } from '../auth.js';
10
+ import { resolveEnvWithDiscovery } from '../config.js';
11
+ import { getJson, postJson, putJson, patchJson, deleteJson, } from '../atlas-client.js';
12
+ import { printCliError } from '../cli-errors.js';
13
+ import { REQUIRE_EXPLICIT_ENV_MESSAGE } from '../env-flags.js';
14
+ const usage = `usage:
15
+ seq-studio storage init <workspace-name> [--out workspace.yml]
16
+ seq-studio storage validate [workspace.yml]
17
+ seq-studio storage apply [workspace.yml] -e <env>
18
+ seq-studio storage list -e <env> [--workspace <id>] [--parent <id>] [--trash] [--cursor <cursor>]
19
+ seq-studio storage show --workspace <id> [--node <id>] -e <env>
20
+ seq-studio storage mkdir <name> --workspace <id> [--parent <id>] -e <env>
21
+ seq-studio storage upload <file> --workspace <id> [--path <path>] [--parent <id>] [--replace <file-id> --revision <n>] [--resume <upload-id>] -e <env>
22
+ seq-studio storage download --workspace <id> --node <id> --out <file> [--version <id>] -e <env>
23
+ seq-studio storage trash|restore|purge --workspace <id> --node <id> --revision <n> [-e <env>] [--yes]
24
+ seq-studio storage access --workspace <id> [--node <id>] [--file <access.json>] -e <env>
25
+ seq-studio storage operations --workspace <id> [--retry <operation-id>] -e <env>
26
+ seq-studio storage abort --workspace <id> --upload <id> -e <env>
27
+ seq-studio storage delete --workspace <id> --revision <n> --yes -e <env>
28
+
29
+ Workspaces are provisioned from YAML; paths create folders at upload time.
30
+ Uploads print their session ID to stderr for retry. Resume uses the same original file.
31
+ Use -e local or -e local:<worktree> for the standard local Atlas target.`;
32
+ export async function runStorageCommand(sub, args) {
33
+ if (!sub || sub === 'help' || args.flags.help) {
34
+ console.log(usage);
35
+ return sub ? 0 : 1;
36
+ }
37
+ try {
38
+ const flag = (name) => typeof args.flags[name] === 'string' ? args.flags[name] : undefined;
39
+ const required = (name) => {
40
+ const value = flag(name);
41
+ if (!value)
42
+ throw new Error(`--${name} is required`);
43
+ return value;
44
+ };
45
+ const print = (value) => console.log(JSON.stringify(value, null, 2));
46
+ if (sub === 'init') {
47
+ const name = args.positional[0];
48
+ const manifest = workspaceManifestSchema.parse({ workspace: { name } });
49
+ const output = resolve(flag('out') ?? 'workspace.yml');
50
+ await writeFile(output, `workspace:\n name: ${manifest.workspace.name}\n description: ""\n`, { flag: 'wx' });
51
+ console.log(output);
52
+ return 0;
53
+ }
54
+ const manifest = sub === 'validate' || sub === 'apply'
55
+ ? workspaceManifestSchema.parse(yaml(await readFile(resolve(args.positional[0] ?? 'workspace.yml'), 'utf8')))
56
+ : null;
57
+ if (sub === 'validate') {
58
+ console.log('Workspace manifest is valid');
59
+ return 0;
60
+ }
61
+ if (!flag('env'))
62
+ throw new Error(REQUIRE_EXPLICIT_ENV_MESSAGE);
63
+ const env = await resolveEnvWithDiscovery({ requested: flag('env') });
64
+ const { token } = await getAccessTokenWithMode({
65
+ env: env.name,
66
+ targetUrl: env.url,
67
+ });
68
+ const client = storageClient({
69
+ async request(method, path, body) {
70
+ const options = { baseUrl: env.url, token, path, body };
71
+ switch (method) {
72
+ case 'GET':
73
+ return getJson(options);
74
+ case 'POST':
75
+ return postJson(options);
76
+ case 'PUT':
77
+ return putJson(options);
78
+ case 'PATCH':
79
+ return patchJson(options);
80
+ case 'DELETE':
81
+ return deleteJson(options);
82
+ default:
83
+ throw new Error('Unsupported storage method');
84
+ }
85
+ },
86
+ });
87
+ if (sub === 'apply' && manifest) {
88
+ print(await client.apply(manifest));
89
+ return 0;
90
+ }
91
+ const list = {
92
+ cursor: flag('cursor'),
93
+ q: flag('q'),
94
+ limit: flag('limit') ? Number(flag('limit')) : undefined,
95
+ };
96
+ if (sub === 'list' && !flag('workspace')) {
97
+ print(await client.list(list));
98
+ return 0;
99
+ }
100
+ const workspace = client.workspace(required('workspace'));
101
+ const revision = () => {
102
+ const n = Number(required('revision'));
103
+ if (!Number.isInteger(n) || n < 0)
104
+ throw new Error('--revision must be a nonnegative integer');
105
+ return n;
106
+ };
107
+ switch (sub) {
108
+ case 'list':
109
+ print(await workspace.list({
110
+ ...list,
111
+ parentId: flag('parent'),
112
+ trash: args.flags.trash === true,
113
+ }));
114
+ break;
115
+ case 'show':
116
+ print(flag('node')
117
+ ? await workspace.getNode(required('node'))
118
+ : await workspace.get());
119
+ break;
120
+ case 'mkdir': {
121
+ if (!args.positional[0])
122
+ throw new Error('Folder name is required');
123
+ print(await workspace.createFolder(args.positional[0], flag('parent') ?? null));
124
+ break;
125
+ }
126
+ case 'upload': {
127
+ if (!args.positional[0])
128
+ throw new Error('Source file is required');
129
+ const file = resolve(args.positional[0]);
130
+ const info = await stat(file);
131
+ if (!info.isFile())
132
+ throw new Error('Upload source must be a regular file');
133
+ const session = flag('resume')
134
+ ? await workspace.uploads.get(required('resume'))
135
+ : await workspace.uploads.start(startUploadSchema.parse({
136
+ path: flag('path') ?? basename(file),
137
+ parentId: flag('parent') ?? null,
138
+ size: info.size,
139
+ fileId: flag('replace'),
140
+ expectedRevision: flag('replace') ? revision() : undefined,
141
+ contentType: flag('content-type') ?? 'application/octet-stream',
142
+ idempotencyKey: flag('idempotency-key') ?? randomUUID(),
143
+ }));
144
+ console.error(`Upload session: ${session.id}`);
145
+ const controller = new AbortController();
146
+ const cancel = () => controller.abort();
147
+ process.once('SIGINT', cancel);
148
+ try {
149
+ print(await workspace.uploads.resume(session.id, createReadStream(file), {
150
+ size: info.size,
151
+ signal: controller.signal,
152
+ }));
153
+ }
154
+ finally {
155
+ process.removeListener('SIGINT', cancel);
156
+ }
157
+ break;
158
+ }
159
+ case 'download': {
160
+ const output = resolve(required('out'));
161
+ const signed = await workspace.download(required('node'), {
162
+ versionId: flag('version'),
163
+ });
164
+ const response = await fetch(signed.url, { redirect: 'error' });
165
+ if (!response.ok || !response.body)
166
+ throw new Error(`Download failed (${response.status})`);
167
+ await pipeline(Readable.fromWeb(response.body), createWriteStream(output, { flags: 'wx' }));
168
+ console.log(output);
169
+ break;
170
+ }
171
+ case 'trash':
172
+ print(await workspace.trash(required('node'), revision()));
173
+ break;
174
+ case 'restore':
175
+ print(await workspace.restore(required('node'), revision()));
176
+ break;
177
+ case 'purge':
178
+ if (args.flags.yes !== true)
179
+ throw new Error('Permanent deletion requires --yes; trash is recoverable until purge');
180
+ print(await workspace.purge(required('node'), revision()));
181
+ break;
182
+ case 'delete':
183
+ if (args.flags.yes !== true)
184
+ throw new Error('Workspace deletion requires --yes and permanently deletes its files and history');
185
+ print(await workspace.delete(revision()));
186
+ break;
187
+ case 'access': {
188
+ const input = flag('file')
189
+ ? updateStorageAccessSchema.parse(JSON.parse(await readFile(required('file'), 'utf8')))
190
+ : null;
191
+ print(input
192
+ ? await workspace.setAccess(input, flag('node'))
193
+ : await workspace.access(flag('node')));
194
+ break;
195
+ }
196
+ case 'operations':
197
+ print(flag('retry')
198
+ ? await workspace.retryOperation(required('retry'))
199
+ : await workspace.operations({ before: flag('cursor') }));
200
+ break;
201
+ case 'abort': {
202
+ const aborted = await workspace.uploads.abort(required('upload'));
203
+ print({ id: aborted.id, state: aborted.state });
204
+ break;
205
+ }
206
+ default:
207
+ throw new Error(`Unknown storage command: ${sub}\n${usage}`);
208
+ }
209
+ return 0;
210
+ }
211
+ catch (error) {
212
+ printCliError(error);
213
+ return 1;
214
+ }
215
+ }
@@ -16,6 +16,9 @@ minimumReleaseAge: 10080
16
16
  minimumReleaseAgeExclude:
17
17
  - '@sequenceholdings/atlas-ui'
18
18
  - '@sequenceholdings/lattice-form-renderer'
19
+ - '@sequenceholdings/storage'
19
20
  - '@sequenceholdings/artifact-studio'
20
21
  - '@sequenceholdings/lattice'
22
+ - '@sequenceholdings/orm'
23
+ - '@sequenceholdings/managed-functions'
21
24
  - '@sequenceholdings/studio-cli'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequenceholdings/studio-cli",
3
- "version": "0.1.31",
3
+ "version": "0.2.0",
4
4
  "description": "Unified Sequence Studio CLI — `seq-studio init` / `add` / `deploy` (app monorepos), `seq-studio agents`, `seq-studio process` (Lattice), `seq-studio artifact`, `seq-studio functions` / `secrets`, `seq-studio repos`, and `seq-studio auth pat`. Includes Auth0 browser login shared with seqapi.",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -42,11 +42,13 @@
42
42
  "tsx": "^4.20.3",
43
43
  "zod": "^4.1.13",
44
44
  "@sequenceholdings/agent-spec": "0.1.2",
45
- "@sequenceholdings/artifact-studio": "0.2.5",
45
+ "@sequenceholdings/artifact-studio": "0.3.0",
46
+ "@sequenceholdings/managed-functions": "0.1.1",
47
+ "@sequenceholdings/storage": "0.1.0",
46
48
  "@sequenceholdings/lattice": "0.1.3"
47
49
  },
48
50
  "peerDependencies": {
49
- "@sequenceholdings/orm": "2.0.0",
51
+ "@sequenceholdings/orm": "2.1.0",
50
52
  "@sequenceholdings/pipeline-spec": "0.1.0"
51
53
  },
52
54
  "peerDependenciesMeta": {
@@ -62,8 +64,8 @@
62
64
  "@types/node": "^22.0.0",
63
65
  "typescript": "^5.6.0",
64
66
  "vitest": "^4.1.11",
65
- "@sequenceholdings/pipeline-spec": "0.1.0",
66
- "@sequenceholdings/orm": "2.0.0"
67
+ "@sequenceholdings/orm": "2.1.0",
68
+ "@sequenceholdings/pipeline-spec": "0.1.0"
67
69
  },
68
70
  "engines": {
69
71
  "node": ">=20"
@@ -16,6 +16,9 @@ minimumReleaseAge: 10080
16
16
  minimumReleaseAgeExclude:
17
17
  - '@sequenceholdings/atlas-ui'
18
18
  - '@sequenceholdings/lattice-form-renderer'
19
+ - '@sequenceholdings/storage'
19
20
  - '@sequenceholdings/artifact-studio'
20
21
  - '@sequenceholdings/lattice'
22
+ - '@sequenceholdings/orm'
23
+ - '@sequenceholdings/managed-functions'
21
24
  - '@sequenceholdings/studio-cli'