@sequenceholdings/studio-cli 0.4.7 → 0.5.2

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 (73) hide show
  1. package/README.md +162 -84
  2. package/dist/agents/commands.js +7 -0
  3. package/dist/app/adapters.d.ts +2 -2
  4. package/dist/app/adapters.js +15 -14
  5. package/dist/app/commands.d.ts +1 -1
  6. package/dist/app/commands.js +77 -14
  7. package/dist/app/deploy.d.ts +2 -0
  8. package/dist/app/deploy.js +25 -13
  9. package/dist/app/kinds.d.ts +6 -0
  10. package/dist/app/kinds.js +6 -0
  11. package/dist/app/manifest.js +1 -1
  12. package/dist/app/official-source.d.ts +10 -0
  13. package/dist/app/official-source.js +23 -0
  14. package/dist/app/prepare.d.ts +27 -0
  15. package/dist/app/prepare.js +58 -0
  16. package/dist/app/primitive-ids.d.ts +6 -0
  17. package/dist/app/primitive-ids.js +16 -0
  18. package/dist/app/primitive-scaffold.d.ts +0 -4
  19. package/dist/app/primitive-scaffold.js +7 -18
  20. package/dist/app/readme.js +23 -16
  21. package/dist/app/repository-index.d.ts +19 -0
  22. package/dist/app/repository-index.js +86 -0
  23. package/dist/app/scaffold.d.ts +12 -1
  24. package/dist/app/scaffold.js +32 -19
  25. package/dist/app/workspace-compile.d.ts +9 -0
  26. package/dist/app/workspace-compile.js +13 -1
  27. package/dist/app/workspace-scaffold.js +5 -1
  28. package/dist/artifact/delegate.js +4 -4
  29. package/dist/auth-cmds/commands.d.ts +1 -13
  30. package/dist/auth-cmds/commands.js +11 -246
  31. package/dist/auth.d.ts +17 -0
  32. package/dist/auth.js +29 -0
  33. package/dist/bin.js +1 -1
  34. package/dist/command-contract.d.ts +11 -5
  35. package/dist/command-contract.js +4 -3
  36. package/dist/command-help.d.ts +2 -2
  37. package/dist/command-help.js +14 -16
  38. package/dist/config.d.ts +16 -0
  39. package/dist/config.js +38 -5
  40. package/dist/env-registry.d.ts +8 -0
  41. package/dist/env-registry.js +9 -1
  42. package/dist/envs/commands.js +14 -1
  43. package/dist/functions/manifest.d.ts +4 -1
  44. package/dist/functions/manifest.js +8 -2
  45. package/dist/main.d.ts +3 -2
  46. package/dist/main.js +12 -6
  47. package/dist/orm/delegate.js +5 -2
  48. package/dist/pipeline/clone-deploy.d.ts +2 -3
  49. package/dist/pipeline/clone-deploy.js +9 -10
  50. package/dist/pipeline/commands.js +4 -3
  51. package/dist/pipeline/lifecycle.d.ts +3 -1
  52. package/dist/pipeline/lifecycle.js +12 -4
  53. package/dist/process/commands.d.ts +6 -3
  54. package/dist/process/commands.js +26 -10
  55. package/dist/repos/commands.d.ts +2 -11
  56. package/dist/repos/commands.js +71 -157
  57. package/dist/repos/git-clone.d.ts +1 -10
  58. package/dist/repos/git-clone.js +1 -49
  59. package/dist/repos/git-credential.d.ts +15 -0
  60. package/dist/repos/git-credential.js +91 -0
  61. package/dist/repos/pulls.d.ts +19 -1
  62. package/dist/repos/pulls.js +15 -2
  63. package/dist/templates/catalog.d.ts +69 -0
  64. package/dist/templates/catalog.js +68 -0
  65. package/dist/templates/commands.d.ts +29 -0
  66. package/dist/templates/commands.js +443 -0
  67. package/dist/templates/process/example-process/process.ts +2 -0
  68. package/dist/templates/process/package.json +1 -1
  69. package/package.json +13 -11
  70. package/templates/process/example-process/process.ts +2 -0
  71. package/templates/process/package.json +1 -1
  72. package/dist/pat-hints.d.ts +0 -15
  73. package/dist/pat-hints.js +0 -28
@@ -0,0 +1,91 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { promisify } from 'node:util';
3
+ import { getAccessTokenWithMode } from '../auth.js';
4
+ import { resolveConfiguredEnv } from '../config.js';
5
+ const exec = promisify(execFile);
6
+ function matchesGitDestination(input, url) {
7
+ const fields = new Map();
8
+ for (const line of input.split('\n')) {
9
+ if (!line)
10
+ break;
11
+ const index = line.indexOf('=');
12
+ if (index < 1)
13
+ return false;
14
+ const key = line.slice(0, index);
15
+ // Git sends repeatable capability[]/wwwauth[] fields. Ignore extensions;
16
+ // only duplicate destination fields make credential routing ambiguous.
17
+ if (!['protocol', 'host', 'path'].includes(key))
18
+ continue;
19
+ if (fields.has(key))
20
+ return false;
21
+ fields.set(key, line.slice(index + 1));
22
+ }
23
+ if (url.username || url.password || url.search || url.hash ||
24
+ !/^\/api\/git-service\/repos\/[\w-]+(?:\/git|\.git)$/.test(url.pathname) ||
25
+ fields.get('protocol') !== url.protocol.slice(0, -1) ||
26
+ fields.get('host') !== url.host ||
27
+ fields.get('path') !== url.pathname.slice(1))
28
+ return false;
29
+ return true;
30
+ }
31
+ /** Only send a login credential to the exact repository pinned at clone time. */
32
+ export async function gitCredentialResponse({ input, operation, envName, cloneUrl, }) {
33
+ // Git asks helpers to store/erase credentials after success/failure. Our source
34
+ // of truth is the CLI session; never persist its token or erase it on a Git 401.
35
+ if (operation === 'store' || operation === 'erase')
36
+ return '';
37
+ if (operation !== 'get')
38
+ throw new Error('Expected Git credential operation: get, store, or erase.');
39
+ const url = new URL(cloneUrl);
40
+ if (!matchesGitDestination(input, url))
41
+ return '';
42
+ const env = await resolveConfiguredEnv({ requested: envName });
43
+ if (url.origin !== new URL(env.url).origin)
44
+ throw new Error('Git remote origin no longer matches the registered environment.');
45
+ if (url.protocol !== 'https:' && !(url.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname))) {
46
+ throw new Error('Git login credentials require HTTPS (except local loopback).');
47
+ }
48
+ try {
49
+ const auth = await getAccessTokenWithMode({ env: env.name, targetUrl: env.url, allowInteractiveLogin: false });
50
+ if (auth.authMode !== 'user' || !auth.token || /[\r\n\0]/.test(auth.token))
51
+ throw new Error('User login required');
52
+ return `username=git\npassword=${auth.token}\n\n`;
53
+ }
54
+ catch {
55
+ throw new Error(`Git login unavailable. Run seq-studio login --env ${envName}, then retry. Machine identities cannot authenticate Git; use supported JSON source workflows.`);
56
+ }
57
+ }
58
+ function shellQuote(value) {
59
+ return `'${value.replace(/'/g, "'\\''")}'`;
60
+ }
61
+ /** Store only a helper command, bound to this environment and repository URL. */
62
+ export async function configureGitLogin({ destDir, envName, cloneUrl, }) {
63
+ // Resolve the installed CLI via PATH so package/Node upgrades do not leave
64
+ // existing repositories pinned to a deleted version-specific executable.
65
+ const helper = `!seq-studio auth git-credential --env ${shellQuote(envName)} --url ${shellQuote(cloneUrl)}`;
66
+ const config = async (...args) => { await exec('git', ['-C', destDir, 'config', '--local', ...args]); };
67
+ // An empty helper resets inherited credential stores for this URL. That keeps
68
+ // an Auth0 access token out of the user's global store/keychain on approval.
69
+ await config('--replace-all', `credential.${cloneUrl}.helper`, '');
70
+ await config('--add', `credential.${cloneUrl}.helper`, helper);
71
+ await config(`credential.${cloneUrl}.useHttpPath`, 'true');
72
+ await config(`http.${cloneUrl}.followRedirects`, 'false');
73
+ }
74
+ export async function gitCredentialCommand(args) {
75
+ const envName = args.flags.env ?? args.flags.e;
76
+ const cloneUrl = args.flags.url;
77
+ const operation = args.positional[0];
78
+ if (typeof envName !== 'string' || typeof cloneUrl !== 'string' || !operation || args.positional.length !== 1) {
79
+ throw new Error('usage: seq-studio auth git-credential --env <env> --url <clone-url> <get|store|erase>');
80
+ }
81
+ let input = '';
82
+ for await (const chunk of process.stdin) {
83
+ input += chunk.toString();
84
+ if (input.length > 16_384)
85
+ throw new Error('Git credential input too large.');
86
+ if (input.includes('\n\n'))
87
+ break;
88
+ }
89
+ process.stdout.write(await gitCredentialResponse({ input, operation, envName, cloneUrl }));
90
+ return 0;
91
+ }
@@ -1,3 +1,21 @@
1
1
  import type { ParsedArgs } from '../process/commands.js';
2
- export declare const PULLS_USAGE = "usage:\n seq-studio repos pulls list <ns>/<name> -e <env> [--state open|closed|merged] [--limit N] [--cursor <cursor>]\n seq-studio repos pulls show <ns>/<name> <number> -e <env>\n seq-studio repos pulls create <ns>/<name> --head <branch> --base <branch> --title <title> -e <env> [--body-file <path>]\n seq-studio repos pulls diff <ns>/<name> <number> -e <env> [--max-files N]\n seq-studio repos pulls merge <ns>/<name> <number> -e <env> [--method squash|merge|ff] [--message <text>] [--yes]\n\n All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.\n create needs repository write; merge needs merge/admin authority and passing server\n review/check policy. There is no policy bypass. Review show and diff before merging.\n Merge operates on the current branch head under server policy; a displayed SHA is\n informational and is not a compare-and-swap guard. Default merge method: squash.\n list returns one page with nextCursor; pass --cursor to continue.\n diff compares live base/head branches for open Pulls, recorded SHAs for terminal\n Pulls, and reports truncated when its file\n limit is reached (default 100, maximum 500).\n repos pull (singular) materializes files; repos pulls manages review requests.\n";
2
+ export declare const PULLS_USAGE = "usage:\n seq-studio repos pulls list <ns>/<name> -e <env> [--state open|closed|merged] [--limit N] [--cursor <cursor>]\n seq-studio repos pulls show <ns>/<name> <number> -e <env>\n seq-studio repos pulls create <ns>/<name> --head <branch> --base <branch> --title <title> -e <env> [--body-file <path>]\n seq-studio repos pulls diff <ns>/<name> <number> -e <env> [--max-files N]\n seq-studio repos pulls merge <ns>/<name> <number> -e <env> [--method squash|merge|ff] [--message <text>] [--yes]\n\n All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.\n create needs repository write; merge needs merge/admin authority and passing server\n review/check policy. There is no policy bypass. Review show and diff before merging.\n Merge operates on the current branch head under server policy. When repository CI\n checks the branch, merge sends the checked head and base revisions; a newer push\n makes the server refuse until checks rerun. Default merge method: squash.\n list returns one page with nextCursor; pass --cursor to continue.\n diff compares live base/head branches for open Pulls, recorded SHAs for terminal\n Pulls, and reports truncated when its file\n limit is reached (default 100, maximum 500).\n repos pull (singular) materializes files; repos pulls manages review requests.\n";
3
+ /** Only the revisions this command needs from GET .../pulls/<n>/ci. */
4
+ interface PullCiStatus {
5
+ plan?: {
6
+ headSha?: string;
7
+ baseSha?: string;
8
+ } | null;
9
+ }
10
+ /**
11
+ * A branch under repository CI only merges the exact revisions its checks
12
+ * planned (the server returns 409 without them). Unchecked branches need none.
13
+ */
14
+ export declare function checkedMergeRevision({ fetchStatus }: {
15
+ fetchStatus: () => Promise<PullCiStatus>;
16
+ }): Promise<{
17
+ expectedHeadSha: string;
18
+ expectedBaseSha: string;
19
+ } | Record<string, never>>;
3
20
  export declare function reposPullsCommand(input: ParsedArgs): Promise<number>;
21
+ export {};
@@ -15,14 +15,25 @@ export const PULLS_USAGE = `usage:
15
15
  All results are JSON (--json is accepted). Authenticate: seq-studio login --env <env>.
16
16
  create needs repository write; merge needs merge/admin authority and passing server
17
17
  review/check policy. There is no policy bypass. Review show and diff before merging.
18
- Merge operates on the current branch head under server policy; a displayed SHA is
19
- informational and is not a compare-and-swap guard. Default merge method: squash.
18
+ Merge operates on the current branch head under server policy. When repository CI
19
+ checks the branch, merge sends the checked head and base revisions; a newer push
20
+ makes the server refuse until checks rerun. Default merge method: squash.
20
21
  list returns one page with nextCursor; pass --cursor to continue.
21
22
  diff compares live base/head branches for open Pulls, recorded SHAs for terminal
22
23
  Pulls, and reports truncated when its file
23
24
  limit is reached (default 100, maximum 500).
24
25
  repos pull (singular) materializes files; repos pulls manages review requests.
25
26
  `;
27
+ /**
28
+ * A branch under repository CI only merges the exact revisions its checks
29
+ * planned (the server returns 409 without them). Unchecked branches need none.
30
+ */
31
+ export async function checkedMergeRevision({ fetchStatus }) {
32
+ const status = await fetchStatus();
33
+ const headSha = status.plan?.headSha;
34
+ const baseSha = status.plan?.baseSha;
35
+ return headSha && baseSha ? { expectedHeadSha: headSha, expectedBaseSha: baseSha } : {};
36
+ }
26
37
  function integerFlag({ args, key, max }) {
27
38
  const value = args.flags[key];
28
39
  if (value === undefined)
@@ -66,9 +77,11 @@ async function mergePull({ args, ctx, path, repoPath }) {
66
77
  const confirmed = await confirmYes({ confirmed: args.flags.yes === true, preview: [] });
67
78
  if (!confirmed)
68
79
  return 1;
80
+ const revision = await checkedMergeRevision({ fetchStatus: () => getJson({ ...clientOptions(ctx), path: `${path}/ci` }) });
69
81
  const result = await postJson({ ...clientOptions(ctx), path: `${path}/merge`, body: {
70
82
  method: args.flags.method ?? 'squash',
71
83
  ...(args.flags.message === undefined ? {} : { message: args.flags.message }),
84
+ ...revision,
72
85
  } });
73
86
  console.log(JSON.stringify(result, null, 2));
74
87
  return 0;
@@ -0,0 +1,69 @@
1
+ import { z } from 'zod';
2
+ export declare const TEMPLATE_NAMESPACE = "templates";
3
+ export declare const TEMPLATE_CATALOG_REPO = "catalog";
4
+ export declare const TEMPLATE_METADATA_PATH = ".seq/template.json";
5
+ export declare const TEMPLATE_RELEASE_PATH = ".seq/template-release.json";
6
+ export declare const templateMetadataSchema: z.ZodObject<{
7
+ schemaVersion: z.ZodLiteral<1>;
8
+ name: z.ZodString;
9
+ description: z.ZodString;
10
+ includes: z.ZodArray<z.ZodEnum<{
11
+ function: "function";
12
+ process: "process";
13
+ artifact: "artifact";
14
+ pipeline: "pipeline";
15
+ orm: "orm";
16
+ agent: "agent";
17
+ workspace: "workspace";
18
+ }>>;
19
+ }, z.core.$strict>;
20
+ export declare const templateReleaseSchema: z.ZodObject<{
21
+ schemaVersion: z.ZodLiteral<1>;
22
+ name: z.ZodString;
23
+ version: z.ZodString;
24
+ description: z.ZodString;
25
+ includes: z.ZodArray<z.ZodEnum<{
26
+ function: "function";
27
+ process: "process";
28
+ artifact: "artifact";
29
+ pipeline: "pipeline";
30
+ orm: "orm";
31
+ agent: "agent";
32
+ workspace: "workspace";
33
+ }>>;
34
+ source: z.ZodObject<{
35
+ environment: z.ZodEnum<{
36
+ banksouth: "banksouth";
37
+ staging: "staging";
38
+ }>;
39
+ repo: z.ZodString;
40
+ commit: z.ZodString;
41
+ }, z.core.$strip>;
42
+ digest: z.ZodString;
43
+ scope: z.ZodUnion<readonly [z.ZodObject<{
44
+ kind: z.ZodLiteral<"all">;
45
+ }, z.core.$strip>, z.ZodObject<{
46
+ kind: z.ZodLiteral<"one">;
47
+ deployment: z.ZodString;
48
+ }, z.core.$strip>]>;
49
+ publishedAt: z.ZodString;
50
+ }, z.core.$strict>;
51
+ export type TemplateMetadata = z.infer<typeof templateMetadataSchema>;
52
+ export type TemplateRelease = z.infer<typeof templateReleaseSchema>;
53
+ export type TemplateFile = {
54
+ path: string;
55
+ content: string;
56
+ mode: '100644' | '100755';
57
+ };
58
+ export type TemplateSourceEnvironment = TemplateRelease['source']['environment'];
59
+ /** Staging rehearsal stays in staging; cross-deployment releases use BankSouth. */
60
+ export declare function validateTemplatePublishRoute(from: string | undefined, to: string): TemplateSourceEnvironment;
61
+ export declare function parseTemplateSelection(input: string): {
62
+ name: string;
63
+ version: string;
64
+ };
65
+ export declare function releaseBranch(value: string): string;
66
+ export declare function ledgerPath(name: string, releaseVersion: string): string;
67
+ /** Hash the actual source bytes and executable bits, independent of Git commit IDs. */
68
+ export declare function templateDigest(files: readonly TemplateFile[]): string;
69
+ export declare function targetIncludesRelease(release: TemplateRelease, deployment: string): boolean;
@@ -0,0 +1,68 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { z } from 'zod';
3
+ export const TEMPLATE_NAMESPACE = 'templates';
4
+ export const TEMPLATE_CATALOG_REPO = 'catalog';
5
+ export const TEMPLATE_METADATA_PATH = '.seq/template.json';
6
+ export const TEMPLATE_RELEASE_PATH = '.seq/template-release.json';
7
+ const slug = z.string().regex(/^[a-z][a-z0-9-]{0,63}$/);
8
+ const version = z.string().regex(/^[0-9]+\.[0-9]+\.[0-9]+(?:-[a-z0-9][a-z0-9.-]*)?$/);
9
+ export const templateMetadataSchema = z.object({
10
+ schemaVersion: z.literal(1),
11
+ name: slug,
12
+ description: z.string().trim().min(1).max(2000),
13
+ includes: z.array(z.enum(['orm', 'workspace', 'function', 'agent', 'process', 'pipeline', 'artifact'])).min(1),
14
+ }).strict();
15
+ export const templateReleaseSchema = z.object({
16
+ schemaVersion: z.literal(1),
17
+ name: slug,
18
+ version,
19
+ description: z.string().min(1),
20
+ includes: templateMetadataSchema.shape.includes,
21
+ source: z.object({ environment: z.enum(['banksouth', 'staging']), repo: z.string(), commit: z.string().regex(/^[0-9a-f]{40}$/) }),
22
+ digest: z.string().regex(/^[0-9a-f]{64}$/),
23
+ scope: z.union([z.object({ kind: z.literal('all') }), z.object({ kind: z.literal('one'), deployment: z.string().min(1) })]),
24
+ publishedAt: z.string().datetime(),
25
+ }).strict();
26
+ /** Staging rehearsal stays in staging; cross-deployment releases use BankSouth. */
27
+ export function validateTemplatePublishRoute(from, to) {
28
+ if (from !== 'banksouth' && from !== 'staging') {
29
+ throw new Error('publish requires --from banksouth or --from staging.');
30
+ }
31
+ if (to === 'local' || to.startsWith('local:') || to.startsWith('preview:')) {
32
+ throw new Error('--to must be a deployed environment or all.');
33
+ }
34
+ if (from === 'staging' && to !== 'staging') {
35
+ throw new Error('Staging-authored templates can only publish to staging; use BankSouth as the source for cross-deployment promotion.');
36
+ }
37
+ return from;
38
+ }
39
+ export function parseTemplateSelection(input) {
40
+ const match = /^([^@]+)@([^@]+)$/.exec(input);
41
+ if (!match)
42
+ throw new Error('Template must be <name>@<version>, for example full-stack@1.0.0.');
43
+ return { name: slug.parse(match[1]), version: version.parse(match[2]) };
44
+ }
45
+ export function releaseBranch(value) {
46
+ return `releases/${version.parse(value)}`;
47
+ }
48
+ export function ledgerPath(name, releaseVersion) {
49
+ return `releases/${slug.parse(name)}/${version.parse(releaseVersion)}.json`;
50
+ }
51
+ /** Hash the actual source bytes and executable bits, independent of Git commit IDs. */
52
+ export function templateDigest(files) {
53
+ const hash = createHash('sha256');
54
+ hash.update('seq-template-v2\0');
55
+ for (const file of [...files].sort((a, b) => a.path < b.path ? -1 : a.path > b.path ? 1 : 0)) {
56
+ if (file.path === TEMPLATE_RELEASE_PATH)
57
+ continue;
58
+ for (const field of [Buffer.from(file.path), Buffer.from(file.mode), Buffer.from(file.content, 'base64')]) {
59
+ const length = Buffer.alloc(4);
60
+ length.writeUInt32BE(field.length);
61
+ hash.update(length).update(field);
62
+ }
63
+ }
64
+ return hash.digest('hex');
65
+ }
66
+ export function targetIncludesRelease(release, deployment) {
67
+ return release.scope.kind === 'all' || release.scope.deployment === deployment;
68
+ }
@@ -0,0 +1,29 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ import { type TemplateFile, type TemplateRelease } from './catalog.js';
3
+ type RemoteFile = TemplateFile;
4
+ type TreeEntry = {
5
+ path: string;
6
+ type: string;
7
+ mode: string;
8
+ size?: number;
9
+ };
10
+ /** Resolve the platform's explicit deploy registry without teaching the public CLI deployment URLs. */
11
+ export declare function promotionTargetsFromRegistry(path: string, configuredUrls: Record<string, {
12
+ url: string;
13
+ }>, registeredUrls: Record<string, {
14
+ url: string;
15
+ }>): Promise<string[]>;
16
+ export declare function validateTemplateTree(entries: readonly TreeEntry[]): TreeEntry[];
17
+ export declare function verifyReleaseFiles(files: readonly RemoteFile[], release: TemplateRelease): void;
18
+ export declare function initFromTemplate({ selection, target, environment }: {
19
+ selection: string;
20
+ target: string;
21
+ environment: string;
22
+ }): Promise<void>;
23
+ export declare function writeTemplateToDirectory({ files, release, target }: {
24
+ files: RemoteFile[];
25
+ release: TemplateRelease;
26
+ target: string;
27
+ }): Promise<void>;
28
+ export declare function runTemplatesCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
29
+ export {};