@sequenceholdings/studio-cli 0.7.2 → 0.9.1

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 (89) hide show
  1. package/README.md +414 -55
  2. package/dist/access/commands.d.ts +1 -1
  3. package/dist/access/commands.js +102 -55
  4. package/dist/access/custom-role-hosts.d.ts +3 -0
  5. package/dist/access/custom-role-hosts.js +88 -0
  6. package/dist/access/group-rosters.d.ts +6 -0
  7. package/dist/access/group-rosters.js +33 -0
  8. package/dist/access/host-contract.d.ts +55 -0
  9. package/dist/access/host-contract.js +33 -0
  10. package/dist/access/hosts.d.ts +4 -0
  11. package/dist/access/hosts.js +60 -0
  12. package/dist/access/principal.d.ts +16 -0
  13. package/dist/access/principal.js +36 -0
  14. package/dist/access/roles.d.ts +18 -0
  15. package/dist/access/roles.js +89 -0
  16. package/dist/access/tier-hosts.d.ts +12 -0
  17. package/dist/access/tier-hosts.js +206 -0
  18. package/dist/agents/commands.d.ts +1 -1
  19. package/dist/agents/commands.js +76 -16
  20. package/dist/agents/scaffold.js +8 -3
  21. package/dist/app/commands.js +37 -12
  22. package/dist/app/manifest.d.ts +2 -2
  23. package/dist/app/official-source.d.ts +4 -2
  24. package/dist/app/official-source.js +6 -4
  25. package/dist/app/readme.js +2 -2
  26. package/dist/app/repository-index.d.ts +6 -0
  27. package/dist/app/repository-index.js +2 -2
  28. package/dist/app/workspace-model.js +4 -0
  29. package/dist/app/workspace-scaffold.js +5 -3
  30. package/dist/app/workspace.d.ts +2 -0
  31. package/dist/app/workspace.js +1 -1
  32. package/dist/artifact/delegate.js +26 -3
  33. package/dist/artifact/sandbox.js +2 -1
  34. package/dist/atlas-client.d.ts +15 -8
  35. package/dist/atlas-client.js +140 -64
  36. package/dist/bin.js +9 -1
  37. package/dist/cli-errors.js +4 -0
  38. package/dist/command-contract.d.ts +8 -2
  39. package/dist/command-contract.js +3 -2
  40. package/dist/command-help.d.ts +8 -6
  41. package/dist/command-help.js +65 -14
  42. package/dist/env-flags.d.ts +7 -0
  43. package/dist/env-flags.js +23 -0
  44. package/dist/functions/commands.js +66 -11
  45. package/dist/functions/manifest.d.ts +5 -0
  46. package/dist/functions/manifest.js +44 -23
  47. package/dist/functions/service-account-guidance.d.ts +21 -0
  48. package/dist/functions/service-account-guidance.js +62 -0
  49. package/dist/functions/workspace.d.ts +11 -0
  50. package/dist/functions/workspace.js +52 -0
  51. package/dist/machine-output.d.ts +7 -0
  52. package/dist/machine-output.js +56 -0
  53. package/dist/main.d.ts +2 -1
  54. package/dist/main.js +32 -4
  55. package/dist/orm/delegate.js +49 -6
  56. package/dist/orm/execute.js +11 -5
  57. package/dist/orm/failures.d.ts +32 -0
  58. package/dist/orm/failures.js +75 -0
  59. package/dist/orm/read.js +3 -3
  60. package/dist/orm/version-guard.d.ts +3 -0
  61. package/dist/orm/version-guard.js +63 -0
  62. package/dist/pipeline/commands.js +4 -1
  63. package/dist/principals/commands.d.ts +3 -0
  64. package/dist/principals/commands.js +124 -0
  65. package/dist/process/commands.js +9 -3
  66. package/dist/process/human-input-probe.d.ts +23 -0
  67. package/dist/process/human-input-probe.js +118 -0
  68. package/dist/process/lint.d.ts +2 -0
  69. package/dist/process/lint.js +10 -0
  70. package/dist/process/run-steps.d.ts +112 -0
  71. package/dist/process/run-steps.js +123 -0
  72. package/dist/process/runs.d.ts +4 -3
  73. package/dist/process/runs.js +69 -21
  74. package/dist/release-age.d.ts +1 -1
  75. package/dist/release-age.js +1 -0
  76. package/dist/repos/commands.d.ts +57 -0
  77. package/dist/repos/commands.js +83 -15
  78. package/dist/repos/init-repo.d.ts +45 -0
  79. package/dist/repos/init-repo.js +257 -0
  80. package/dist/repos/primitive-declaration.d.ts +43 -0
  81. package/dist/repos/primitive-declaration.js +212 -0
  82. package/dist/sandbox-unpushed-warning.d.ts +23 -0
  83. package/dist/sandbox-unpushed-warning.js +86 -0
  84. package/dist/service-accounts/commands.js +15 -3
  85. package/dist/templates/commands.d.ts +14 -2
  86. package/dist/templates/commands.js +70 -16
  87. package/dist/templates/process/pnpm-workspace.yaml +1 -0
  88. package/package.json +15 -12
  89. package/templates/process/pnpm-workspace.yaml +1 -0
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Human output for a refusal from the ORM data endpoint. The server's GraphQL
3
+ * envelope carries `{message, extensions: {code, details?}}`; `details` names
4
+ * the variable, column, constraint, or requirement at fault (schema names
5
+ * only, never values). Every ORM command prints refusals through here so the
6
+ * same error reads the same way from `execute`, `read`, and `sql`.
7
+ */
8
+ import { LOG, printCliError } from '../cli-errors.js';
9
+ function isRecord(value) {
10
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
11
+ }
12
+ function stringFields(value) {
13
+ if (!isRecord(value))
14
+ return {};
15
+ return Object.fromEntries(Object.entries(value).filter((entry) => typeof entry[1] === 'string'));
16
+ }
17
+ /** The first error of a data-plane envelope (or of an ORM client error's `errors`). */
18
+ export function dataPlaneFailure({ status, errors }) {
19
+ const first = Array.isArray(errors) ? errors[0] : undefined;
20
+ const extensions = isRecord(first) && isRecord(first.extensions) ? first.extensions : {};
21
+ return {
22
+ status,
23
+ code: typeof extensions.code === 'string' ? extensions.code : null,
24
+ message: isRecord(first) && typeof first.message === 'string' ? first.message : null,
25
+ details: stringFields(extensions.details),
26
+ };
27
+ }
28
+ /** `message (CODE) [variable: x, column: y]`, or `HTTP <status>` when the server sent no envelope. */
29
+ export function failureSummary(failure) {
30
+ const fields = Object.entries(failure.details).map(([key, value]) => `${key}: ${value}`);
31
+ const base = failure.message ?? (failure.status === null ? 'request failed' : `HTTP ${failure.status}`);
32
+ return `${base}${failure.code ? ` (${failure.code})` : ''}${fields.length ? ` [${fields.join(', ')}]` : ''}`;
33
+ }
34
+ /** One recovery step for the refusal, or null when the message already says it. */
35
+ export function failureNextStep({ failure, namespace }) {
36
+ const { code, details } = failure;
37
+ if (code === 'NOT_FOUND' && details.cause === 'unknown_operation') {
38
+ return `Next step: list the deployed operations with \`seq-studio orm describe ${namespace} --operations\`, and run one by name with \`seq-studio orm execute ${namespace} <operation>\`.`;
39
+ }
40
+ if (code === 'NOT_FOUND') {
41
+ return 'Next step: confirm `-e` targets the right environment; `seq-studio orm namespaces` lists the namespaces you can read. A namespace you cannot read looks the same as one that does not exist.';
42
+ }
43
+ if (code === 'FORBIDDEN' && details.requirement) {
44
+ return `Next step: ask an admin of ${namespace} to assign you a role that grants ${details.requirement.replace(/^(capability|role):/, '$1 ')} (\`seq-studio access\`).`;
45
+ }
46
+ if (code === 'BAD_USER_INPUT' && details.variable) {
47
+ return `Next step: fix variable $${details.variable}; \`seq-studio orm describe ${namespace} --operations\` lists each operation's variables and types.`;
48
+ }
49
+ return null;
50
+ }
51
+ /** An ORM client error (`@sequenceholdings/orm/client`), matched by name: the CLI may load its own copy. */
52
+ export function ormClientFailure(error) {
53
+ if (!(error instanceof Error) || error.name !== 'OrmOperationError')
54
+ return null;
55
+ const status = Reflect.get(error, 'status');
56
+ const failure = dataPlaneFailure({ status: typeof status === 'number' ? status : null, errors: Reflect.get(error, 'errors') });
57
+ const code = Reflect.get(error, 'code');
58
+ return {
59
+ ...failure,
60
+ code: failure.code ?? (typeof code === 'string' ? code : null),
61
+ message: failure.message ?? error.message,
62
+ };
63
+ }
64
+ /** Print any ORM command error: data-plane refusals with their details and next step, everything else as usual. */
65
+ export function printOrmCommandError({ error, namespace }) {
66
+ const failure = ormClientFailure(error);
67
+ if (!failure) {
68
+ printCliError(error);
69
+ return;
70
+ }
71
+ console.error(`${LOG} ${failureSummary(failure)}`);
72
+ const next = failureNextStep({ failure, namespace });
73
+ if (next)
74
+ console.error(`${LOG} ${next}`);
75
+ }
package/dist/orm/read.js CHANGED
@@ -12,9 +12,9 @@
12
12
  */
13
13
  import { readFile } from 'node:fs/promises';
14
14
  import { postJsonResponse } from '../atlas-client.js';
15
- import { printCliError } from '../cli-errors.js';
16
15
  import { validateCommandInput } from '../command-input.js';
17
16
  import { buildContext, clientOptions } from '../functions/commands.js';
17
+ import { printOrmCommandError } from './failures.js';
18
18
  import { table } from '../text-table.js';
19
19
  export const ORM_READ_USAGE = `usage:
20
20
  seq-studio orm read <namespace> <table> -e <env> [--where <column>=<op>.<value>]...
@@ -264,7 +264,7 @@ export async function ormReadCommand(args) {
264
264
  return 0;
265
265
  }
266
266
  catch (error) {
267
- printCliError(error);
267
+ printOrmCommandError({ error, namespace: args.positional[0] ?? '<namespace>' });
268
268
  return 1;
269
269
  }
270
270
  }
@@ -290,7 +290,7 @@ export async function ormSqlCommand(args) {
290
290
  return 0;
291
291
  }
292
292
  catch (error) {
293
- printCliError(error);
293
+ printOrmCommandError({ error, namespace: args.positional[0] ?? '<namespace>' });
294
294
  if (isRejectedSql(error))
295
295
  console.error(sqlGrammarHint(args.positional[0] ?? '<namespace>'));
296
296
  return 1;
@@ -0,0 +1,3 @@
1
+ export declare function requiresSchemaVersionCheck(sub: string): boolean;
2
+ /** Fail before compiling a v2 schema with an ORM outside its declared range. */
3
+ export declare function ormVersionMismatch(dir: string): Promise<string | null>;
@@ -0,0 +1,63 @@
1
+ import { readFile } from 'node:fs/promises';
2
+ import { join, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { satisfies, validRange } from 'semver';
5
+ const SCHEMA_SUBCOMMANDS = new Set(['generate', 'validate', 'plan', 'apply', 'diff']);
6
+ export function requiresSchemaVersionCheck(sub) {
7
+ return SCHEMA_SUBCOMMANDS.has(sub);
8
+ }
9
+ function missingFile(error) {
10
+ return error instanceof Error && 'code' in error && error.code === 'ENOENT';
11
+ }
12
+ function dependencyRange(manifest) {
13
+ if (typeof manifest !== 'object' || manifest === null)
14
+ return undefined;
15
+ for (const field of ['dependencies', 'devDependencies']) {
16
+ const section = Reflect.get(manifest, field);
17
+ if (typeof section === 'object' && section !== null) {
18
+ const range = Reflect.get(section, '@sequenceholdings/orm');
19
+ if (range !== undefined)
20
+ return range;
21
+ }
22
+ }
23
+ return undefined;
24
+ }
25
+ /** Fail before compiling a v2 schema with an ORM outside its declared range. */
26
+ export async function ormVersionMismatch(dir) {
27
+ const configPath = join(resolve(dir), 'sequence.config.ts');
28
+ try {
29
+ await readFile(configPath);
30
+ }
31
+ catch (error) {
32
+ if (missingFile(error))
33
+ return null; // v1 namespace
34
+ throw error;
35
+ }
36
+ const manifestPath = join(resolve(dir), 'package.json');
37
+ let manifest;
38
+ try {
39
+ manifest = JSON.parse(await readFile(manifestPath, 'utf8'));
40
+ }
41
+ catch (error) {
42
+ if (missingFile(error))
43
+ return null; // unversioned source
44
+ throw new Error(`could not read ${manifestPath}: ${error instanceof Error ? error.message : String(error)}`);
45
+ }
46
+ const range = dependencyRange(manifest);
47
+ if (range === undefined || (typeof range === 'string' && range.startsWith('workspace:')))
48
+ return null;
49
+ if (typeof range !== 'string' || !validRange(range)) {
50
+ return `invalid @sequenceholdings/orm range "${String(range)}" in ${manifestPath}`;
51
+ }
52
+ // Resolve beside this CLI, matching the delegated ORM import in every installation layout.
53
+ const ormPackagePath = fileURLToPath(new URL('../package.json', import.meta.resolve('@sequenceholdings/orm/cli')));
54
+ const ormManifest = JSON.parse(await readFile(ormPackagePath, 'utf8'));
55
+ const version = typeof ormManifest === 'object' && ormManifest !== null
56
+ ? Reflect.get(ormManifest, 'version') : undefined;
57
+ if (typeof version !== 'string' || !satisfies(version, range)) {
58
+ return `this seq-studio loads @sequenceholdings/orm ${typeof version === 'string' ? version : '(unknown version)'}, ` +
59
+ `but ${manifestPath} requires ${range}. Run the namespace-local CLI after installing its dependencies, ` +
60
+ 'or upgrade seq-studio and @sequenceholdings/orm together.';
61
+ }
62
+ return null;
63
+ }
@@ -58,7 +58,10 @@ ${PIPELINE_DISCOVERY_USAGE}
58
58
  For an existing target release unit, --source-env reads a repository
59
59
  from a separately authenticated registered
60
60
  environment; -e still selects the target. The target verifies and snapshots
61
- source bytes before queuing. Not available with --dir or migrations.
61
+ source bytes before queuing. Reviewed pipeline.config.yml source_paths
62
+ can select runtime files/directories while preserving pipeline metadata
63
+ and the release identity. Snapshot and Git-fetch size limits still apply.
64
+ Not available with --dir or migrations.
62
65
  enqueue a durable plan, poll progress, then print the completed
63
66
  materialize + SDK/graph + compile + live-diff + provision findings
64
67
  (no Databricks CLI / DAB validate on Atlas); exit 1 on destructive findings
@@ -0,0 +1,3 @@
1
+ import type { ParsedArgs } from '../process/commands.js';
2
+ export declare const PRINCIPALS_USAGE = "usage:\n seq-studio principals search <query> -e <env> [--types user,group,service-account,organization] [--limit <n>]\n seq-studio principals users search <query> -e <env> [--limit <n>]\n seq-studio principals groups list -e <env> [--search <query>] [--limit <n>] [--page <n>]\n seq-studio principals groups show <group-id> -e <env> [--limit <n>] [--offset <n>]\n\n Find the people, groups, service accounts and organizations YOU may grant\n access to, with the exact ids seq-studio access grant takes. Results are JSON;\n each principal carries \"grant\": { \"principalType\", \"principalId\" }.\n Queries need at least 2 characters. search defaults to user,group,service-account.\n\n You see exactly what the Atlas pickers show you, never more:\n people: active users in your organization (Sequence operators: everyone);\n groups: groups you belong to (platform admins: every group), never deleted ones;\n service accounts: accounts you hold actor on; organizations: your own tenant.\n groups show lists a visible group's active members, paged (default 50 per\n page); a group you can't see is reported as not found.\n Authenticate: seq-studio login --env <env> (agent sandbox tokens work too).\n";
3
+ export declare function runPrincipalsCommand(sub: string | undefined, args: ParsedArgs): Promise<number>;
@@ -0,0 +1,124 @@
1
+ import { getJson } from '../atlas-client.js';
2
+ import { printCliError } from '../cli-errors.js';
3
+ import { validateCommandInput, wantsHelp } from '../command-input.js';
4
+ import { buildContext, clientOptions } from '../functions/commands.js';
5
+ const SEARCH_TYPES = ['user', 'group', 'service-account', 'organization'];
6
+ export const PRINCIPALS_USAGE = `usage:
7
+ seq-studio principals search <query> -e <env> [--types user,group,service-account,organization] [--limit <n>]
8
+ seq-studio principals users search <query> -e <env> [--limit <n>]
9
+ seq-studio principals groups list -e <env> [--search <query>] [--limit <n>] [--page <n>]
10
+ seq-studio principals groups show <group-id> -e <env> [--limit <n>] [--offset <n>]
11
+
12
+ Find the people, groups, service accounts and organizations YOU may grant
13
+ access to, with the exact ids seq-studio access grant takes. Results are JSON;
14
+ each principal carries "grant": { "principalType", "principalId" }.
15
+ Queries need at least 2 characters. search defaults to user,group,service-account.
16
+
17
+ You see exactly what the Atlas pickers show you, never more:
18
+ people: active users in your organization (Sequence operators: everyone);
19
+ groups: groups you belong to (platform admins: every group), never deleted ones;
20
+ service accounts: accounts you hold actor on; organizations: your own tenant.
21
+ groups show lists a visible group's active members, paged (default 50 per
22
+ page); a group you can't see is reported as not found.
23
+ Authenticate: seq-studio login --env <env> (agent sandbox tokens work too).
24
+ `;
25
+ function withGrant(principal) {
26
+ const principalType = principal.type === 'service_account' ? 'service-account' : principal.type;
27
+ return { ...principal, grant: { principalType, principalId: principal.id } };
28
+ }
29
+ function numberFlag(args, key) {
30
+ const value = args.flags[key];
31
+ if (value === undefined)
32
+ return undefined;
33
+ if (typeof value !== 'string' || !/^\d+$/.test(value))
34
+ throw new Error(`--${key} must be a non-negative integer.`);
35
+ return value;
36
+ }
37
+ function query(params) {
38
+ const search = new URLSearchParams();
39
+ for (const [key, value] of Object.entries(params))
40
+ if (value !== undefined)
41
+ search.set(key, value);
42
+ const text = search.toString();
43
+ return text ? `?${text}` : '';
44
+ }
45
+ function searchQuery(args, index) {
46
+ const text = args.positional[index]?.trim() ?? '';
47
+ if (text.length < 2)
48
+ throw new Error('A search query of at least 2 characters is required.');
49
+ return text;
50
+ }
51
+ const DEFAULT_SEARCH_TYPES = 'user,group,service_account';
52
+ function parseTypes(raw) {
53
+ // Always explicit: the server's own default omits service accounts.
54
+ if (raw === undefined)
55
+ return DEFAULT_SEARCH_TYPES;
56
+ if (typeof raw !== 'string')
57
+ throw new Error(`--types takes a comma-separated list of ${SEARCH_TYPES.join(', ')}.`);
58
+ const types = raw.split(',').map((type) => type.trim()).filter(Boolean);
59
+ const unknown = types.find((type) => !SEARCH_TYPES.includes(type));
60
+ if (unknown || types.length === 0)
61
+ throw new Error(`--types takes a comma-separated list of ${SEARCH_TYPES.join(', ')}.`);
62
+ return types.map((type) => (type === 'service-account' ? 'service_account' : type)).join(',');
63
+ }
64
+ /** Resolve the request path for a subcommand; everything here runs before auth. */
65
+ function requestPath(sub, args) {
66
+ if (sub === 'search') {
67
+ validateCommandInput({ args, flags: { types: 'string', limit: 'string' }, positional: 1 });
68
+ const path = `/api/authz/principals/search${query({ q: searchQuery(args, 0), types: parseTypes(args.flags.types), limit: numberFlag(args, 'limit') })}`;
69
+ return { path, shape: 'principals' };
70
+ }
71
+ const [action, target] = [args.positional[0], args.positional[1]];
72
+ if (sub === 'users') {
73
+ if (action !== 'search')
74
+ throw new Error('Usage: seq-studio principals users search <query> -e <env>');
75
+ validateCommandInput({ args, flags: { limit: 'string' }, positional: 2 });
76
+ return { path: `/api/authz/principals/search${query({ q: searchQuery(args, 1), types: 'user', limit: numberFlag(args, 'limit') })}`, shape: 'principals' };
77
+ }
78
+ if (sub === 'groups' && action === 'list') {
79
+ validateCommandInput({ args, flags: { search: 'string', limit: 'string', page: 'string' }, positional: 1 });
80
+ const search = typeof args.flags.search === 'string' ? args.flags.search : undefined;
81
+ return { path: `/api/authz/principals/groups${query({ q: search, limit: numberFlag(args, 'limit'), page: numberFlag(args, 'page') })}`, shape: 'groups' };
82
+ }
83
+ if (sub === 'groups' && action === 'show') {
84
+ validateCommandInput({ args, flags: { limit: 'string', offset: 'string' }, positional: 2 });
85
+ if (!target?.trim())
86
+ throw new Error('A group id is required. Find it with seq-studio principals groups list.');
87
+ return { path: `/api/authz/principals/groups/${encodeURIComponent(target.trim())}${query({ limit: numberFlag(args, 'limit'), offset: numberFlag(args, 'offset') })}`, shape: 'group' };
88
+ }
89
+ if (sub === 'groups')
90
+ throw new Error('Usage: seq-studio principals groups list|show -e <env>');
91
+ throw new Error(`Unknown principals command: ${sub}. See: seq-studio principals --help`);
92
+ }
93
+ function present(shape, body) {
94
+ const record = body;
95
+ if (shape === 'principals') {
96
+ return { principals: (record.principals ?? []).map(withGrant) };
97
+ }
98
+ if (shape === 'groups') {
99
+ return { ...record, groups: (record.groups ?? []).map((group) => withGrant({ ...group, type: 'group' })) };
100
+ }
101
+ const group = record.group;
102
+ return {
103
+ ...record,
104
+ ...(group ? { group: withGrant({ ...group, type: 'group' }) } : {}),
105
+ members: (record.members ?? []).map(withGrant),
106
+ };
107
+ }
108
+ export async function runPrincipalsCommand(sub, args) {
109
+ if (!sub || wantsHelp({ sub, args })) {
110
+ console.log(PRINCIPALS_USAGE);
111
+ return sub ? 0 : 1;
112
+ }
113
+ try {
114
+ const { path, shape } = requestPath(sub, args);
115
+ const ctx = await buildContext(args);
116
+ const body = await getJson({ ...clientOptions(ctx), path });
117
+ console.log(JSON.stringify(present(shape, body), null, 2));
118
+ return 0;
119
+ }
120
+ catch (error) {
121
+ printCliError(error);
122
+ return 1;
123
+ }
124
+ }
@@ -262,13 +262,19 @@ async function buildBundleForPublish(args, compiled) {
262
262
  export async function planCommand(args) {
263
263
  const compiled = await compileLocalProcessSource(args);
264
264
  const bundle = await buildBundleForPublish(args, compiled);
265
- // Static graph limits (LAT-148): run limits lint so `process plan` matches registration.
265
+ // Static graph limits (LAT-148) and the definition lint `apply` enforces,
266
+ // so a plan that passes does not fail at apply or at run time (for example a
267
+ // human `input` projection without upstream).
266
268
  const limitLint = lintBundleStaticGraphLimits({ bundle });
267
- const formattedLint = formatLintResult(limitLint);
269
+ const planLint = {
270
+ errors: [...compiled.lint.errors, ...limitLint.errors],
271
+ warnings: [...compiled.lint.warnings, ...limitLint.warnings],
272
+ };
273
+ const formattedLint = formatLintResult(planLint);
268
274
  if (formattedLint.text)
269
275
  console.log(formattedLint.text);
270
276
  if (formattedLint.hasErrors) {
271
- console.error(`\nplan FAILED — ${limitLint.errors.length} static graph limit error(s), ${limitLint.warnings.length} warning(s)`);
277
+ console.error(`\nplan FAILED — ${planLint.errors.length} lint error(s), ${planLint.warnings.length} warning(s)`);
272
278
  return 1;
273
279
  }
274
280
  const summary = summarizeBundle(bundle);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Pre-deploy check for a human node's `input` projection. Atlas persists the
3
+ * projection as the step's ctx snapshot and fails the run at that node when it
4
+ * is not `{ entity, run, upstream }`. Lint reports a projection only when the
5
+ * problem cannot depend on the run's real data:
6
+ *
7
+ * - a JSONata projection whose root is an object constructor without one of
8
+ * the required literal keys (read from the parsed expression, not evaluated);
9
+ * - a JS projection that, run against a probe ctx, returns an object without a
10
+ * required key. Values read from upstream outputs are stand-ins that count as
11
+ * present, and a mapper that spreads or enumerates upstream data is
12
+ * inconclusive, because the real data could supply the keys.
13
+ *
14
+ * Anything else (a mapper that throws on probe data, returns a promise or a
15
+ * stand-in, or a JSONata root that is not an object constructor) passes.
16
+ */
17
+ /**
18
+ * The problem with a human node's `input` projection, or `undefined` when it
19
+ * is valid, absent, or the check was inconclusive.
20
+ */
21
+ export declare function probeHumanInputProjection({ input }: {
22
+ input: unknown;
23
+ }): string | undefined;
@@ -0,0 +1,118 @@
1
+ /**
2
+ * Pre-deploy check for a human node's `input` projection. Atlas persists the
3
+ * projection as the step's ctx snapshot and fails the run at that node when it
4
+ * is not `{ entity, run, upstream }`. Lint reports a projection only when the
5
+ * problem cannot depend on the run's real data:
6
+ *
7
+ * - a JSONata projection whose root is an object constructor without one of
8
+ * the required literal keys (read from the parsed expression, not evaluated);
9
+ * - a JS projection that, run against a probe ctx, returns an object without a
10
+ * required key. Values read from upstream outputs are stand-ins that count as
11
+ * present, and a mapper that spreads or enumerates upstream data is
12
+ * inconclusive, because the real data could supply the keys.
13
+ *
14
+ * Anything else (a mapper that throws on probe data, returns a promise or a
15
+ * stand-in, or a JSONata root that is not an object constructor) passes.
16
+ */
17
+ import { describeHumanCtxProjectionProblem, isJsonataExpr } from '@sequenceholdings/lattice/define';
18
+ import { jsonataObjectConstructorKeys } from '@sequenceholdings/lattice/jsonata-runtime';
19
+ const PROBE_RUN = {
20
+ id: 'lint-probe-run',
21
+ process_id: 'lint-probe-process',
22
+ version: 'lint-probe-version',
23
+ started_at: '2026-01-01T00:00:00.000Z',
24
+ started_by: null,
25
+ trigger_reason: null,
26
+ metadata: {},
27
+ };
28
+ /** Tracks the probe stand-ins one mapper call produced and touched. */
29
+ class ProbeSession {
30
+ standIns = new WeakSet();
31
+ /** Set when the mapper enumerated stand-in keys, e.g. `{ ...upstream.x }`. */
32
+ enumerated = false;
33
+ /**
34
+ * A stand-in for upstream data: every property read, call and coercion
35
+ * returns another stand-in, so a mapper that walks deep into
36
+ * `ctx.upstream.<node>` completes and its result shape can be checked.
37
+ */
38
+ standIn() {
39
+ const session = this;
40
+ const value = new Proxy(function probeValue() { }, {
41
+ get(_target, key) {
42
+ if (key === Symbol.toPrimitive)
43
+ return () => '';
44
+ if (key === Symbol.iterator)
45
+ return function* empty() { };
46
+ if (key === 'then' || typeof key === 'symbol')
47
+ return undefined;
48
+ if (key === 'toJSON')
49
+ return () => null;
50
+ return value;
51
+ },
52
+ apply: () => value,
53
+ has: () => true,
54
+ ownKeys(target) {
55
+ session.enumerated = true;
56
+ return Reflect.ownKeys(target);
57
+ },
58
+ });
59
+ this.standIns.add(value);
60
+ return value;
61
+ }
62
+ ctx() {
63
+ const nodeOutput = this.standIn();
64
+ const session = this;
65
+ return {
66
+ entity: { type: 'lint-probe', id: 'lint-probe' },
67
+ upstream: new Proxy({}, {
68
+ get: (target, key) => (typeof key === 'symbol' ? Reflect.get(target, key) : nodeOutput),
69
+ has: () => true,
70
+ ownKeys(target) {
71
+ session.enumerated = true;
72
+ return Reflect.ownKeys(target);
73
+ },
74
+ }),
75
+ state: {},
76
+ run: { ...PROBE_RUN },
77
+ };
78
+ }
79
+ /** The result with stand-in values replaced by `{}`, so they count as present objects. */
80
+ settle(result) {
81
+ if (typeof result !== 'object' || result === null || Array.isArray(result))
82
+ return result;
83
+ return Object.fromEntries(Object.entries(result).map(([key, value]) => [key, typeof value === 'function' && this.standIns.has(value) ? {} : value]));
84
+ }
85
+ }
86
+ function probeJsFunction(mapper) {
87
+ const session = new ProbeSession();
88
+ let projected;
89
+ try {
90
+ projected = mapper(session.ctx());
91
+ }
92
+ catch {
93
+ // Probe data the mapper did not expect: inconclusive, not a finding.
94
+ return undefined;
95
+ }
96
+ if (projected instanceof Promise || session.enumerated)
97
+ return undefined;
98
+ if (typeof projected === 'function' && session.standIns.has(projected))
99
+ return undefined;
100
+ return describeHumanCtxProjectionProblem(session.settle(projected));
101
+ }
102
+ function probeJsonata(expr) {
103
+ const keys = jsonataObjectConstructorKeys(expr);
104
+ if (keys === undefined)
105
+ return undefined;
106
+ return describeHumanCtxProjectionProblem(Object.fromEntries(keys.map((key) => [key, {}])));
107
+ }
108
+ /**
109
+ * The problem with a human node's `input` projection, or `undefined` when it
110
+ * is valid, absent, or the check was inconclusive.
111
+ */
112
+ export function probeHumanInputProjection({ input }) {
113
+ if (typeof input === 'function')
114
+ return probeJsFunction(input);
115
+ if (isJsonataExpr(input))
116
+ return probeJsonata(input.expr);
117
+ return undefined;
118
+ }
@@ -8,6 +8,8 @@
8
8
  * JSON Schema, confirm edge_id enum matches outgoing_edges
9
9
  * - Human timeout edge — if timeout is set and outgoing_edges.length > 0
10
10
  * but on_timeout_edge_id is unset, warn
11
+ * - Human input projection — probe the `input` mapper and fail when it
12
+ * does not return { entity, run, upstream }
11
13
  */
12
14
  import { type LatticeBundle } from '@sequenceholdings/lattice/bundle';
13
15
  import type { ProcessDefinition } from '@sequenceholdings/lattice/define';
@@ -8,12 +8,15 @@
8
8
  * JSON Schema, confirm edge_id enum matches outgoing_edges
9
9
  * - Human timeout edge — if timeout is set and outgoing_edges.length > 0
10
10
  * but on_timeout_edge_id is unset, warn
11
+ * - Human input projection — probe the `input` mapper and fail when it
12
+ * does not return { entity, run, upstream }
11
13
  */
12
14
  import { readFileSync } from 'node:fs';
13
15
  import { checkBundleStaticGraphLimits, forEachSerializedNode, measureBundleStaticGraph, } from '@sequenceholdings/lattice/bundle';
14
16
  import { DEFAULT_LATTICE_SAFETY_PROFILE, LATTICE_SAFETY_CEILINGS, } from '@sequenceholdings/lattice';
15
17
  import { isJsonataExpr, parallelSubNodes, validateEmailReminders } from '@sequenceholdings/lattice/define';
16
18
  import { assertJsonataExpr } from '@sequenceholdings/lattice/jsonata-runtime';
19
+ import { probeHumanInputProjection } from './human-input-probe.js';
17
20
  export async function lintProcesses(input) {
18
21
  const errors = [];
19
22
  const warnings = [];
@@ -745,6 +748,13 @@ function lintParallelJoin(processId, node, errors, warnings) {
745
748
  }
746
749
  }
747
750
  function lintHuman(processId, node, errors, warnings) {
751
+ // Atlas persists an `input` projection as the step's ctx snapshot and fails
752
+ // the run at this node when it is not { entity, run, upstream }. Only
753
+ // problems that cannot depend on the run's data are reported.
754
+ const projectionProblem = probeHumanInputProjection({ input: node.input });
755
+ if (projectionProblem !== undefined) {
756
+ errors.push({ process_id: processId, node_id: node.id, message: `input: ${projectionProblem}` });
757
+ }
748
758
  // Email reminders that can never fire (offset before the task is ready, or
749
759
  // after it times out / past the cap) are author bugs the runner silently
750
760
  // skips — catch them here. Only the object form carries reminders.
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Step-level detail for `seq-studio process runs show <run-id> --steps`: each
3
+ * step's status, edge, error, input and output, read from the same run-detail
4
+ * response `runs show` already fetches (run `viewer`). Large inputs and
5
+ * outputs are cut to a preview unless the caller asks for `--full`.
6
+ */
7
+ /** Characters kept from one serialized input, output or error. */
8
+ export declare const STEP_FIELD_PREVIEW_CHARS = 2000;
9
+ /** A step row as the run-detail route returns it (redacted, camelCase). */
10
+ export interface RunStepRow {
11
+ id?: string;
12
+ nodeId: string;
13
+ kind: string | null;
14
+ attempt: number | null;
15
+ status: string;
16
+ branchId?: string | null;
17
+ nextEdgeId?: string | null;
18
+ startedAt: string | null;
19
+ completedAt: string | null;
20
+ error?: unknown;
21
+ input?: unknown;
22
+ output?: unknown;
23
+ }
24
+ /**
25
+ * Which fields were cut, and the full serialized length of each. Kept apart
26
+ * from the values so a payload that happens to contain `truncated: true` is
27
+ * never mistaken for a cut one.
28
+ */
29
+ export type TruncatedFields<TField extends string> = Partial<Record<TField, {
30
+ chars: number;
31
+ }>>;
32
+ type StepField = 'error' | 'input' | 'output';
33
+ export interface StepDetail {
34
+ id: string | null;
35
+ nodeId: string;
36
+ kind: string | null;
37
+ attempt: number | null;
38
+ status: string;
39
+ branchId: string | null;
40
+ nextEdgeId: string | null;
41
+ startedAt: string | null;
42
+ completedAt: string | null;
43
+ error: unknown;
44
+ input: unknown;
45
+ output: unknown;
46
+ /** Fields replaced by their first {@link STEP_FIELD_PREVIEW_CHARS} characters. */
47
+ truncated: TruncatedFields<StepField>;
48
+ }
49
+ /**
50
+ * Bound each named field of `record`: a value whose serialized form is longer
51
+ * than {@link STEP_FIELD_PREVIEW_CHARS} becomes its preview string and is
52
+ * listed in `truncated` with its full length. `full` keeps every value whole.
53
+ */
54
+ export declare function boundFields<TField extends string>({ record, fields, full, }: {
55
+ record: Partial<Record<TField, unknown>>;
56
+ fields: readonly TField[];
57
+ full: boolean;
58
+ }): {
59
+ values: Record<TField, unknown>;
60
+ truncated: TruncatedFields<TField>;
61
+ };
62
+ /**
63
+ * The steps to show, in the route's order, optionally narrowed to one node,
64
+ * with their inputs, outputs and errors bounded unless `full`.
65
+ */
66
+ export declare function stepDetails({ steps, node, full, }: {
67
+ steps: readonly RunStepRow[];
68
+ node?: string;
69
+ full: boolean;
70
+ }): StepDetail[];
71
+ /** Human-readable blocks, one per step. */
72
+ export declare function formatStepDetails(steps: readonly StepDetail[]): string[];
73
+ export declare function errorText(error: unknown): string | undefined;
74
+ export interface StepOptions {
75
+ node?: string;
76
+ full: boolean;
77
+ }
78
+ /** `--steps` options, or `undefined` without `--steps`; `--node`/`--full` need it. */
79
+ export declare function stepOptions({ steps, node, full }: {
80
+ steps: boolean;
81
+ node?: string;
82
+ full: boolean;
83
+ }): StepOptions | undefined;
84
+ interface RunWithSteps<TRun> {
85
+ run: TRun;
86
+ steps: readonly RunStepRow[];
87
+ }
88
+ /** `--steps --json`: the run plus bounded step detail, never the raw rows. */
89
+ export declare function runWithSteps<TRun extends {
90
+ state?: unknown;
91
+ output?: unknown;
92
+ }>({ detail, options, }: {
93
+ detail: RunWithSteps<TRun>;
94
+ options: StepOptions;
95
+ }): {
96
+ run: TRun & {
97
+ truncated: Partial<Record<"state" | "output", {
98
+ chars: number;
99
+ }>>;
100
+ state: unknown;
101
+ output: unknown;
102
+ };
103
+ steps: StepDetail[];
104
+ };
105
+ export declare function printRunSteps<TRun extends {
106
+ error?: unknown;
107
+ }>({ detail, options, printHeader, }: {
108
+ detail: RunWithSteps<TRun>;
109
+ options: StepOptions;
110
+ printHeader: (run: TRun) => void;
111
+ }): void;
112
+ export {};