@sequenceholdings/studio-cli 0.6.1 → 0.6.3
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.
- package/README.md +186 -21
- package/dist/app/commands.d.ts +1 -1
- package/dist/app/commands.js +8 -4
- package/dist/app/deploy.js +4 -3
- package/dist/app/env-bindings.d.ts +3 -4
- package/dist/app/env-bindings.js +14 -77
- package/dist/app/readme.js +2 -2
- package/dist/app/repository-admission.d.ts +5 -0
- package/dist/app/repository-admission.js +32 -0
- package/dist/app/scaffold-files.js +8 -1
- package/dist/artifact/delegate.d.ts +4 -0
- package/dist/artifact/delegate.js +18 -8
- package/dist/artifact/sandbox.d.ts +29 -0
- package/dist/artifact/sandbox.js +109 -0
- package/dist/atlas-client.d.ts +1 -0
- package/dist/atlas-client.js +11 -2
- package/dist/command-contract.d.ts +8 -2
- package/dist/command-contract.js +3 -2
- package/dist/command-help.d.ts +7 -4
- package/dist/command-help.js +43 -3
- package/dist/feedback/commands.d.ts +3 -0
- package/dist/feedback/commands.js +108 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +8 -13
- package/dist/orm/delegate.js +30 -11
- package/dist/orm/discover-schema.d.ts +196 -0
- package/dist/orm/discover-schema.js +84 -0
- package/dist/orm/discover.d.ts +13 -0
- package/dist/orm/discover.js +289 -0
- package/dist/pipeline/source.js +3 -0
- package/dist/repos/commands.js +9 -0
- package/dist/repos/identity-file.d.ts +17 -0
- package/dist/repos/identity-file.js +39 -0
- package/dist/repos/identity.d.ts +2 -0
- package/dist/repos/identity.js +69 -0
- package/dist/update-check.d.ts +3 -1
- package/dist/update-check.js +38 -12
- package/package.json +3 -3
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `seq-studio orm namespaces` / `orm describe` — find the ORM data the caller
|
|
3
|
+
* can read before querying it with `orm read` / `orm sql`.
|
|
4
|
+
*
|
|
5
|
+
* Both are read-only views over Atlas's namespace registry, authorized as the
|
|
6
|
+
* caller: `namespaces` lists only namespaces the caller can read, and
|
|
7
|
+
* `describe` answers 404 for a namespace that is missing or unreadable alike.
|
|
8
|
+
* `describe` joins the active version's compiled schema with its active
|
|
9
|
+
* persisted-operation set.
|
|
10
|
+
*/
|
|
11
|
+
import { AtlasApiError, getJson } from '../atlas-client.js';
|
|
12
|
+
import { printCliError } from '../cli-errors.js';
|
|
13
|
+
import { validateCommandInput } from '../command-input.js';
|
|
14
|
+
import { buildContext, clientOptions } from '../functions/commands.js';
|
|
15
|
+
import { table } from '../text-table.js';
|
|
16
|
+
import { namespaceListSchema, operationsPageSchema, parseResponse, schemaViewSchema, } from './discover-schema.js';
|
|
17
|
+
/** The server's maximum operations page; describe pages until it has them all. */
|
|
18
|
+
const OPERATIONS_PAGE_SIZE = 500;
|
|
19
|
+
const DESCRIPTION_WIDTH = 60;
|
|
20
|
+
function pageFlag({ args, key, min }) {
|
|
21
|
+
const raw = args.flags[key];
|
|
22
|
+
if (raw === undefined)
|
|
23
|
+
return undefined;
|
|
24
|
+
const value = typeof raw === 'string' && /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
25
|
+
if (!Number.isSafeInteger(value) || value < min)
|
|
26
|
+
throw new Error(`--${key} must be an integer >= ${min}.`);
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
function truncate(text) {
|
|
30
|
+
const flat = (text ?? '').replace(/\s+/g, ' ').trim();
|
|
31
|
+
return flat.length > DESCRIPTION_WIDTH ? `${flat.slice(0, DESCRIPTION_WIDTH - 1)}…` : flat;
|
|
32
|
+
}
|
|
33
|
+
function formatLabel(format) {
|
|
34
|
+
return format === null ? 'not applied' : `v${format}`;
|
|
35
|
+
}
|
|
36
|
+
function requiresLabel(requires) {
|
|
37
|
+
if (!requires)
|
|
38
|
+
return '';
|
|
39
|
+
return [
|
|
40
|
+
...(requires.capability ? [`capability ${requires.capability}`] : []),
|
|
41
|
+
...(requires.role ? [`role ${requires.role}`] : []),
|
|
42
|
+
].join(', ');
|
|
43
|
+
}
|
|
44
|
+
export async function ormNamespacesCommand(args) {
|
|
45
|
+
try {
|
|
46
|
+
validateCommandInput({ args, flags: { limit: 'string', offset: 'string' }, positional: 0 });
|
|
47
|
+
const limit = pageFlag({ args, key: 'limit', min: 1 });
|
|
48
|
+
const offset = pageFlag({ args, key: 'offset', min: 0 });
|
|
49
|
+
const query = new URLSearchParams({
|
|
50
|
+
...(limit !== undefined ? { limit: String(limit) } : {}),
|
|
51
|
+
...(offset !== undefined ? { offset: String(offset) } : {}),
|
|
52
|
+
}).toString();
|
|
53
|
+
const options = clientOptions(await buildContext(args));
|
|
54
|
+
const page = parseResponse({
|
|
55
|
+
schema: namespaceListSchema,
|
|
56
|
+
body: await getJson({ ...options, path: `/api/orm/namespaces${query ? `?${query}` : ''}` }),
|
|
57
|
+
what: 'namespace list',
|
|
58
|
+
});
|
|
59
|
+
if (args.flags.json === true) {
|
|
60
|
+
console.log(JSON.stringify(page, null, 2));
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
table({
|
|
64
|
+
headers: ['NAMESPACE', 'FORMAT', 'TABLES', 'OPERATIONS', 'DESCRIPTION'],
|
|
65
|
+
rows: page.namespaces.map((namespace) => [
|
|
66
|
+
namespace.id,
|
|
67
|
+
`${formatLabel(namespace.definition_format)}${namespace.archived_at ? ' (archived)' : ''}`,
|
|
68
|
+
String(namespace.table_count ?? 0),
|
|
69
|
+
String(namespace.operation_count ?? 0),
|
|
70
|
+
truncate(namespace.description),
|
|
71
|
+
]),
|
|
72
|
+
});
|
|
73
|
+
if (page.namespaces.length === 0)
|
|
74
|
+
console.error(`No readable namespaces at offset ${page.offset} (${page.total} total).`);
|
|
75
|
+
else {
|
|
76
|
+
console.error(`${page.offset + 1}-${page.offset + page.namespaces.length} of ${page.total} readable namespace(s)`);
|
|
77
|
+
console.error('Describe one: seq-studio orm describe <namespace>');
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const next = page.offset + page.namespaces.length;
|
|
81
|
+
if (page.namespaces.length > 0 && next < page.total) {
|
|
82
|
+
console.error(`More namespaces exist. Next page: --offset ${next} --limit ${page.limit}`);
|
|
83
|
+
}
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
86
|
+
catch (error) {
|
|
87
|
+
printCliError(error);
|
|
88
|
+
return 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
async function getNamespaceJson({ options, namespace, path }) {
|
|
92
|
+
try {
|
|
93
|
+
return await getJson({ ...options, path });
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
// Missing and unreadable are deliberately indistinguishable on the server.
|
|
97
|
+
if (error instanceof AtlasApiError && error.status === 404) {
|
|
98
|
+
throw new Error(`Namespace '${namespace}' was not found, has no applied version, or you cannot read it. ` +
|
|
99
|
+
'List the namespaces you can read: seq-studio orm namespaces');
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function listAllOperations({ options, namespace }) {
|
|
105
|
+
const operations = [];
|
|
106
|
+
for (;;) {
|
|
107
|
+
const query = new URLSearchParams({ limit: String(OPERATIONS_PAGE_SIZE), offset: String(operations.length) });
|
|
108
|
+
const page = parseResponse({
|
|
109
|
+
schema: operationsPageSchema,
|
|
110
|
+
body: await getNamespaceJson({
|
|
111
|
+
options,
|
|
112
|
+
namespace,
|
|
113
|
+
path: `/api/orm/namespaces/${encodeURIComponent(namespace)}/operations?${query.toString()}`,
|
|
114
|
+
}),
|
|
115
|
+
what: 'operations',
|
|
116
|
+
});
|
|
117
|
+
operations.push(...page.operations);
|
|
118
|
+
if (page.operations.length === 0 || operations.length >= page.total)
|
|
119
|
+
return operations;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function findRelation({ schema, name }) {
|
|
123
|
+
const found = schema.tables.find((relation) => relation.table === name);
|
|
124
|
+
if (found)
|
|
125
|
+
return { kind: 'table', name, relation: found };
|
|
126
|
+
const view = schema.views.find((relation) => relation.view === name);
|
|
127
|
+
return view ? { kind: 'view', name, relation: view } : null;
|
|
128
|
+
}
|
|
129
|
+
function columnType(column) {
|
|
130
|
+
return column.enum_name ? `enum ${column.enum_name}` : column.type;
|
|
131
|
+
}
|
|
132
|
+
function columnKey(column) {
|
|
133
|
+
if (column.primary_key)
|
|
134
|
+
return 'primary';
|
|
135
|
+
return column.unique ? 'unique' : '';
|
|
136
|
+
}
|
|
137
|
+
function printOperations({ operations, heading }) {
|
|
138
|
+
console.log('');
|
|
139
|
+
console.log(heading);
|
|
140
|
+
if (operations.length === 0) {
|
|
141
|
+
console.log(' (none)');
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
table({
|
|
145
|
+
headers: ['OPERATION', 'KIND', 'REQUIRES'],
|
|
146
|
+
rows: operations.map((operation) => [operation.name, operation.kind, requiresLabel(operation.requires)]),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function printNamespace({ schema, operations }) {
|
|
150
|
+
console.log(`${schema.namespace} ${formatLabel(schema.definition_format)} version ${schema.version_id}`);
|
|
151
|
+
if (schema.description)
|
|
152
|
+
console.log(schema.description);
|
|
153
|
+
console.log('');
|
|
154
|
+
// Internal tables are system-owned backing storage with no query surface.
|
|
155
|
+
const relations = [
|
|
156
|
+
...schema.tables.filter((relation) => relation.internal !== true)
|
|
157
|
+
.map((relation) => ({ kind: 'table', name: relation.table, relation })),
|
|
158
|
+
...schema.views.map((relation) => ({ kind: 'view', name: relation.view, relation })),
|
|
159
|
+
];
|
|
160
|
+
table({
|
|
161
|
+
headers: ['TABLE', 'KIND', 'COLUMNS', 'ACTIONS', 'DESCRIPTION'],
|
|
162
|
+
rows: relations.map(({ kind, name, relation }) => [
|
|
163
|
+
name,
|
|
164
|
+
kind === 'table' && relation.source ? 'synced' : kind,
|
|
165
|
+
String(relation.columns.length),
|
|
166
|
+
kind === 'table' ? String(relation.actions.length) : '',
|
|
167
|
+
truncate(relation.description),
|
|
168
|
+
]),
|
|
169
|
+
});
|
|
170
|
+
printOperations({ operations, heading: 'Persisted operations:' });
|
|
171
|
+
}
|
|
172
|
+
function printRelation({ schema, found, operations }) {
|
|
173
|
+
const { relation } = found;
|
|
174
|
+
const key = relation.primary_key.length ? ` primary key: ${relation.primary_key.join(', ')}` : '';
|
|
175
|
+
console.log(`${schema.namespace}.${found.name} (${found.kind === 'table' && found.relation.source ? 'synced table' : found.kind})${key}`);
|
|
176
|
+
if (relation.description)
|
|
177
|
+
console.log(relation.description);
|
|
178
|
+
console.log('');
|
|
179
|
+
table({
|
|
180
|
+
headers: ['COLUMN', 'TYPE', 'NULLABLE', 'KEY', 'DESCRIPTION'],
|
|
181
|
+
rows: relation.columns.map((column) => [
|
|
182
|
+
column.deprecated ? `${column.name} (deprecated)` : column.name,
|
|
183
|
+
columnType(column),
|
|
184
|
+
column.nullable ? 'yes' : 'no',
|
|
185
|
+
columnKey(column),
|
|
186
|
+
truncate(column.description),
|
|
187
|
+
]),
|
|
188
|
+
});
|
|
189
|
+
const enumNames = new Set(relation.columns.flatMap((column) => (column.enum_name ? [column.enum_name] : [])));
|
|
190
|
+
const enums = schema.enums.filter((declared) => enumNames.has(declared.name));
|
|
191
|
+
if (enums.length > 0) {
|
|
192
|
+
console.log('');
|
|
193
|
+
console.log('Enums:');
|
|
194
|
+
for (const declared of enums)
|
|
195
|
+
console.log(` ${declared.name}: ${declared.values.join(', ')}`);
|
|
196
|
+
}
|
|
197
|
+
if (relation.links.length > 0) {
|
|
198
|
+
console.log('');
|
|
199
|
+
console.log('Links:');
|
|
200
|
+
table({
|
|
201
|
+
headers: ['LINK', 'KIND', 'TARGET', 'ON'],
|
|
202
|
+
rows: relation.links.map((link) => [
|
|
203
|
+
link.name,
|
|
204
|
+
link.kind ?? '',
|
|
205
|
+
link.target ? `${link.namespace ? `${link.namespace}.` : ''}${link.target}` : 'platform user',
|
|
206
|
+
link.on,
|
|
207
|
+
]),
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (found.kind === 'table') {
|
|
211
|
+
console.log('');
|
|
212
|
+
console.log('Actions:');
|
|
213
|
+
if (found.relation.actions.length === 0)
|
|
214
|
+
console.log(' (none)');
|
|
215
|
+
else {
|
|
216
|
+
table({
|
|
217
|
+
headers: ['ACTION', 'PARAMS', 'REQUIRES', 'DESCRIPTION'],
|
|
218
|
+
rows: found.relation.actions.map((action) => [
|
|
219
|
+
action.name,
|
|
220
|
+
action.params.map((param) => `${param.name}: ${param.type}${param.nullable ? '?' : ''}`).join(', '),
|
|
221
|
+
action.requires ?? '',
|
|
222
|
+
truncate(action.description),
|
|
223
|
+
]),
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
printOperations({ operations, heading: `Persisted operations that write ${found.name}:` });
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
/** Operations whose mutation roots write the table; query operations name no roots here. */
|
|
230
|
+
function operationsWriting({ operations, name }) {
|
|
231
|
+
return operations.filter((operation) => operation.mutation_roots.some((root) => root.table === name));
|
|
232
|
+
}
|
|
233
|
+
export async function ormDescribeCommand(args) {
|
|
234
|
+
try {
|
|
235
|
+
const [namespace, tableName] = args.positional;
|
|
236
|
+
validateCommandInput({ args, flags: {}, positional: tableName === undefined ? 1 : 2 });
|
|
237
|
+
const options = clientOptions(await buildContext(args));
|
|
238
|
+
const encoded = encodeURIComponent(namespace);
|
|
239
|
+
const [schemaBody, operations] = await Promise.all([
|
|
240
|
+
getNamespaceJson({ options, namespace: namespace, path: `/api/orm/namespaces/${encoded}/schema` }),
|
|
241
|
+
listAllOperations({ options, namespace: namespace }),
|
|
242
|
+
]);
|
|
243
|
+
const schema = parseResponse({ schema: schemaViewSchema, body: schemaBody, what: 'schema' });
|
|
244
|
+
if (tableName === undefined) {
|
|
245
|
+
// The generated GraphQL SDL is large and restates the tables; leave it out.
|
|
246
|
+
const { sdl: _sdl, ...described } = schema;
|
|
247
|
+
if (args.flags.json === true)
|
|
248
|
+
console.log(JSON.stringify({ ...described, operations }, null, 2));
|
|
249
|
+
else {
|
|
250
|
+
printNamespace({ schema, operations });
|
|
251
|
+
console.error(`Describe a table: seq-studio orm describe ${schema.namespace} <table>`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
const found = findRelation({ schema, name: tableName });
|
|
256
|
+
if (!found) {
|
|
257
|
+
const names = [...schema.tables.filter((relation) => relation.internal !== true).map((relation) => relation.table),
|
|
258
|
+
...schema.views.map((relation) => relation.view)];
|
|
259
|
+
throw new Error(`No table or view '${tableName}' in ${schema.namespace}. Available: ${names.join(', ') || '(none)'}.`);
|
|
260
|
+
}
|
|
261
|
+
const writing = found.kind === 'table' ? operationsWriting({ operations, name: found.name }) : [];
|
|
262
|
+
if (args.flags.json === true) {
|
|
263
|
+
console.log(JSON.stringify({
|
|
264
|
+
namespace: schema.namespace,
|
|
265
|
+
definition_format: schema.definition_format,
|
|
266
|
+
version_id: schema.version_id,
|
|
267
|
+
kind: found.kind,
|
|
268
|
+
[found.kind]: found.relation,
|
|
269
|
+
enums: schema.enums.filter((declared) => found.relation.columns.some((column) => column.enum_name === declared.name)),
|
|
270
|
+
operations: writing,
|
|
271
|
+
}, null, 2));
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
printRelation({ schema, found, operations: writing });
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (schema.definition_format !== 2) {
|
|
278
|
+
console.error('This is a v1 (YAML) namespace; orm read and orm sql support v2 namespaces only.');
|
|
279
|
+
}
|
|
280
|
+
else if (args.flags.json !== true) {
|
|
281
|
+
console.error(`Read rows: seq-studio orm read ${schema.namespace} ${tableName ?? '<table>'} --limit 5`);
|
|
282
|
+
}
|
|
283
|
+
return 0;
|
|
284
|
+
}
|
|
285
|
+
catch (error) {
|
|
286
|
+
printCliError(error);
|
|
287
|
+
return 1;
|
|
288
|
+
}
|
|
289
|
+
}
|
package/dist/pipeline/source.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { RepositoryIdentitySchema } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
2
3
|
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
3
4
|
import { getAccessToken } from '../auth.js';
|
|
4
5
|
import { resolveConfiguredEnv } from '../config.js';
|
|
@@ -43,6 +44,7 @@ const sourcePlanSchema = z.object({
|
|
|
43
44
|
repo: z.string(),
|
|
44
45
|
sourceEnvironment: z.string(),
|
|
45
46
|
sourceRepositoryId: z.string(),
|
|
47
|
+
repositoryIdentity: RepositoryIdentitySchema,
|
|
46
48
|
commit: z.string().regex(/^[a-f0-9]{40}$/),
|
|
47
49
|
digest: z.string().regex(/^[a-f0-9]{64}$/),
|
|
48
50
|
bytes: z.number().int().positive(),
|
|
@@ -61,6 +63,7 @@ export function assertPipelineSourcePlan({ plan, request }) {
|
|
|
61
63
|
const receipt = parsed.data.sourceSnapshot;
|
|
62
64
|
if (receipt.sourceEnvironment === request.sourceEnvironment
|
|
63
65
|
&& receipt.sourceRepositoryId === request.sourceRepositoryId
|
|
66
|
+
&& receipt.repositoryIdentity.repositoryId === receipt.sourceRepositoryId
|
|
64
67
|
&& receipt.repo === repo
|
|
65
68
|
&& parsed.data.repo === repo
|
|
66
69
|
&& parsed.data.environment === request.environment
|
package/dist/repos/commands.js
CHANGED
|
@@ -247,6 +247,11 @@ export async function reposShowCommand(args) {
|
|
|
247
247
|
console.log(`${LOG} repo on ${ctx.env.name}:`);
|
|
248
248
|
console.log(` path: ${namespace}/${name}`);
|
|
249
249
|
console.log(` id: ${repo.id}`);
|
|
250
|
+
const identity = repo.repositoryIdentity;
|
|
251
|
+
const identityLabel = identity
|
|
252
|
+
? `${identity.tenantId}/${identity.repositoryId} (generation ${identity.generation})`
|
|
253
|
+
: identity === null ? 'legacy — not adopted' : 'not available on this Atlas release';
|
|
254
|
+
console.log(` identity: ${identityLabel}`);
|
|
250
255
|
console.log(` default branch: ${repo.defaultBranch}`);
|
|
251
256
|
if (repo.gitBackend) {
|
|
252
257
|
console.log(` git backend: ${repo.gitBackend}`);
|
|
@@ -789,6 +794,10 @@ export async function runReposCommand(sub, args) {
|
|
|
789
794
|
return await reposNamespacesCommand(args);
|
|
790
795
|
case 'show':
|
|
791
796
|
return await reposShowCommand(args);
|
|
797
|
+
case 'identity': {
|
|
798
|
+
const { reposIdentityCommand } = await import('./identity.js');
|
|
799
|
+
return await reposIdentityCommand(args);
|
|
800
|
+
}
|
|
792
801
|
case 'create':
|
|
793
802
|
return await reposCreateCommand(args);
|
|
794
803
|
case 'clone':
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type RepositoryIdentity } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
2
|
+
export declare function readRepositoryIdentityFile({ directory }: {
|
|
3
|
+
directory: string;
|
|
4
|
+
}): Promise<{
|
|
5
|
+
schemaVersion: 1;
|
|
6
|
+
identity: {
|
|
7
|
+
tenantId: string;
|
|
8
|
+
repositoryId: string;
|
|
9
|
+
generation: number;
|
|
10
|
+
};
|
|
11
|
+
metadata: Record<string, import("zod").JSONType>;
|
|
12
|
+
} | null>;
|
|
13
|
+
/** Create-only: retain authored metadata and never silently rebind or overwrite a receipt. */
|
|
14
|
+
export declare function writeRepositoryIdentity({ directory, identity }: {
|
|
15
|
+
directory: string;
|
|
16
|
+
identity: RepositoryIdentity;
|
|
17
|
+
}): Promise<string>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { lstat, mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { join, resolve } from 'node:path';
|
|
3
|
+
import { assertRepositoryIdentity, parseRepositoryReceipt, renderRepositoryReceipt } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
4
|
+
export async function readRepositoryIdentityFile({ directory }) {
|
|
5
|
+
const configurationDirectory = join(resolve(directory), '.seq');
|
|
6
|
+
try {
|
|
7
|
+
if (!(await lstat(configurationDirectory)).isDirectory())
|
|
8
|
+
throw new Error('.seq must be a regular directory');
|
|
9
|
+
const filename = join(configurationDirectory, 'identity.json');
|
|
10
|
+
const stat = await lstat(filename);
|
|
11
|
+
if (!stat.isFile())
|
|
12
|
+
throw new Error('.seq/identity.json must be a regular file');
|
|
13
|
+
if (stat.size > 65_536)
|
|
14
|
+
throw new Error('Repository identity exceeds 64 KiB');
|
|
15
|
+
return parseRepositoryReceipt({ text: await readFile(filename, 'utf8') });
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (error instanceof Error && 'code' in error && error.code === 'ENOENT')
|
|
19
|
+
return null;
|
|
20
|
+
throw error;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/** Create-only: retain authored metadata and never silently rebind or overwrite a receipt. */
|
|
24
|
+
export async function writeRepositoryIdentity({ directory, identity }) {
|
|
25
|
+
const root = resolve(directory);
|
|
26
|
+
if (!(await lstat(root)).isDirectory())
|
|
27
|
+
throw new Error('Identity installation requires a regular repository directory');
|
|
28
|
+
const existing = await readRepositoryIdentityFile({ directory: root });
|
|
29
|
+
const filename = join(root, '.seq/identity.json');
|
|
30
|
+
if (existing) {
|
|
31
|
+
assertRepositoryIdentity({ receipt: existing, expected: identity });
|
|
32
|
+
return filename;
|
|
33
|
+
}
|
|
34
|
+
await mkdir(join(root, '.seq'), { recursive: true });
|
|
35
|
+
if (!(await lstat(join(root, '.seq'))).isDirectory())
|
|
36
|
+
throw new Error('.seq must be a regular directory');
|
|
37
|
+
await writeFile(filename, renderRepositoryReceipt({ identity }), { flag: 'wx' });
|
|
38
|
+
return filename;
|
|
39
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { realpathSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { resolveRepo } from '@sequenceholdings/artifact-studio/git-service-client';
|
|
5
|
+
import { RepositoryIdentitySchema, assertRepositoryIdentity, renderRepositoryReceipt } from '@sequenceholdings/artifact-studio/repository-identity';
|
|
6
|
+
import { getJson, patchJson } from '../atlas-client.js';
|
|
7
|
+
import { clientOptions, flagBool } from '../functions/commands.js';
|
|
8
|
+
import { cloneUrl, parseRepoPath, reposContext, stringFlag } from './commands.js';
|
|
9
|
+
import { readRepositoryIdentityFile, writeRepositoryIdentity } from './identity-file.js';
|
|
10
|
+
/** A local receipt may only be installed into the clone explicitly addressed by this command. */
|
|
11
|
+
function assertCloneOrigin({ directory, expected }) {
|
|
12
|
+
let origin;
|
|
13
|
+
let root;
|
|
14
|
+
try {
|
|
15
|
+
const options = { cwd: directory, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] };
|
|
16
|
+
root = execFileSync('git', ['rev-parse', '--show-toplevel'], options).trim();
|
|
17
|
+
origin = execFileSync('git', ['remote', 'get-url', 'origin'], options).trim();
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
throw new Error('Run identity --write in a git-service clone with an origin remote');
|
|
21
|
+
}
|
|
22
|
+
if (realpathSync(directory) !== realpathSync(root))
|
|
23
|
+
throw new Error('Identity installation requires the Git worktree root; run from that directory or pass it with --dir');
|
|
24
|
+
// Do not echo a remote: old checkouts may still contain credentials in it.
|
|
25
|
+
const normalize = (url) => url.replace(/\/$/, '').replace(/\.git$/, '');
|
|
26
|
+
if (normalize(origin) !== normalize(expected))
|
|
27
|
+
throw new Error('Clone origin does not match this repository/environment; refusing to install identity');
|
|
28
|
+
}
|
|
29
|
+
export async function reposIdentityCommand(args) {
|
|
30
|
+
if (args.positional.length !== 1)
|
|
31
|
+
throw new Error('Expected exactly one repository: repos identity <namespace/name> -e <env>');
|
|
32
|
+
for (const key of Object.keys(args.flags)) {
|
|
33
|
+
if (!['e', 'env', 'dir', 'write', 'adopt', 'yes', 'json'].includes(key))
|
|
34
|
+
throw new Error(`Unknown identity flag --${key}`);
|
|
35
|
+
}
|
|
36
|
+
const { namespace, name } = parseRepoPath(args.positional[0]);
|
|
37
|
+
const adopt = flagBool(args.flags, 'adopt');
|
|
38
|
+
const write = flagBool(args.flags, 'write');
|
|
39
|
+
if (adopt && (!write || !flagBool(args.flags, 'yes')))
|
|
40
|
+
throw new Error('Legacy adoption requires --write --yes; inspect repos show first. Adoption binds ownership but does not deploy anything.');
|
|
41
|
+
const directory = resolve(stringFlag(args.flags, 'dir') ?? '.');
|
|
42
|
+
const ctx = await reposContext(args);
|
|
43
|
+
const resolved = await resolveRepo({ ...clientOptions(ctx), namespace, name });
|
|
44
|
+
const path = `/api/git-service/repos/${resolved.id}`;
|
|
45
|
+
let repo = await getJson({ ...clientOptions(ctx), path });
|
|
46
|
+
if (repo.repositoryIdentity === undefined)
|
|
47
|
+
throw new Error('This Atlas release does not expose repository identities; upgrade Atlas before adoption');
|
|
48
|
+
if (write)
|
|
49
|
+
assertCloneOrigin({ directory, expected: cloneUrl(ctx, resolved.id) });
|
|
50
|
+
const existing = write ? await readRepositoryIdentityFile({ directory }) : null;
|
|
51
|
+
if (repo.repositoryIdentity === null) {
|
|
52
|
+
if (!adopt)
|
|
53
|
+
throw new Error('Legacy repository has no identity. An administrator can run repos identity <namespace/name> -e <env> --write --adopt --yes in its clone, then submit the file through a pull request.');
|
|
54
|
+
if (existing)
|
|
55
|
+
throw new Error('Unadopted repository already has an identity file; investigate its provenance before adoption');
|
|
56
|
+
repo = await patchJson({ ...clientOptions(ctx), path, body: { adoptIdentity: true } });
|
|
57
|
+
}
|
|
58
|
+
const identity = RepositoryIdentitySchema.parse(repo.repositoryIdentity);
|
|
59
|
+
if (identity.repositoryId !== resolved.id)
|
|
60
|
+
throw new Error('Platform identity does not match the addressed repository');
|
|
61
|
+
if (existing)
|
|
62
|
+
assertRepositoryIdentity({ receipt: existing, expected: identity });
|
|
63
|
+
if (write) {
|
|
64
|
+
const filename = await writeRepositoryIdentity({ directory, identity });
|
|
65
|
+
console.error(`[seq-studio] Identity retained at ${filename}. Commit and review it normally; no source was pushed or deployed.`);
|
|
66
|
+
}
|
|
67
|
+
console.log(renderRepositoryReceipt({ identity, metadata: existing?.metadata }).trimEnd());
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
package/dist/update-check.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export declare function currentVersion(): string;
|
|
|
3
3
|
export declare function updateCheckCachePath(): string;
|
|
4
4
|
/** Exclusive-create marker that makes "who spawns the refresh?" atomic. */
|
|
5
5
|
export declare function updateCheckClaimPath(): string;
|
|
6
|
+
/** Receipt is scoped to the local user cache and installed/available pair. */
|
|
7
|
+
export declare function updateNoticeReceiptPath(installed: string, available: string): string;
|
|
6
8
|
/**
|
|
7
9
|
* True when `candidate` is a strictly newer semver than `current`.
|
|
8
10
|
* Prerelease suffixes are ignored — the published channel is plain
|
|
@@ -19,7 +21,7 @@ export declare function isNewerVersion(candidate: string, current: string): bool
|
|
|
19
21
|
*/
|
|
20
22
|
export declare function refreshUpdateCache(): Promise<void>;
|
|
21
23
|
/**
|
|
22
|
-
* Print
|
|
24
|
+
* Print one structured upgrade notice to stderr when the cached registry
|
|
23
25
|
* state says a newer version is published, and kick off a detached refresh
|
|
24
26
|
* when the cache is stale. Reads only local state — adds no network latency
|
|
25
27
|
* to the command. Never throws.
|
package/dist/update-check.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
import { mkdir, readFile, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
4
|
import { readFileSync } from 'node:fs';
|
|
4
5
|
import { homedir } from 'node:os';
|
|
5
6
|
import { dirname, join } from 'node:path';
|
|
6
7
|
import { fileURLToPath } from 'node:url';
|
|
7
8
|
/**
|
|
8
|
-
* Update notice: tell
|
|
9
|
-
* on npm, and strongly recommend upgrading.
|
|
9
|
+
* Update notice: tell CLI users and agents when a newer version is on npm.
|
|
10
10
|
*
|
|
11
11
|
* Zero foreground latency is the design constraint. The command path only
|
|
12
12
|
* ever *reads* the on-disk cache (~/.config/lattice/update-check.json) and
|
|
@@ -15,10 +15,12 @@ import { fileURLToPath } from 'node:url';
|
|
|
15
15
|
* record their attempt time so a downed registry doesn't retry on every
|
|
16
16
|
* command. An exclusive claim file elects a single refresher even across
|
|
17
17
|
* concurrent CLI invocations. The notice is therefore at most one
|
|
18
|
-
* invocation stale,
|
|
18
|
+
* invocation stale. A separate, exclusive receipt records one notice per
|
|
19
|
+
* installed/available version pair for this local user. Its write is the
|
|
20
|
+
* notification claim, so concurrent invocations cannot print duplicates.
|
|
19
21
|
*
|
|
20
|
-
* The notice goes to stderr
|
|
21
|
-
*
|
|
22
|
+
* The structured notice goes to stderr, leaving JSON stdout intact. CI and
|
|
23
|
+
* explicitly offline commands skip discovery. Opt out entirely with
|
|
22
24
|
* SEQ_STUDIO_NO_UPDATE_CHECK=1. Everything is best-effort: failures are
|
|
23
25
|
* silent and never affect the command's exit code.
|
|
24
26
|
*/
|
|
@@ -41,6 +43,11 @@ export function updateCheckCachePath() {
|
|
|
41
43
|
export function updateCheckClaimPath() {
|
|
42
44
|
return updateCheckCachePath() + '.claim';
|
|
43
45
|
}
|
|
46
|
+
/** Receipt is scoped to the local user cache and installed/available pair. */
|
|
47
|
+
export function updateNoticeReceiptPath(installed, available) {
|
|
48
|
+
const installation = createHash('sha256').update(dirname(fileURLToPath(import.meta.url))).digest('hex').slice(0, 16);
|
|
49
|
+
return join(dirname(updateCheckCachePath()), 'update-notices', installation, `${encodeURIComponent(installed)}--${encodeURIComponent(available)}.receipt`);
|
|
50
|
+
}
|
|
44
51
|
/**
|
|
45
52
|
* True when `candidate` is a strictly newer semver than `current`.
|
|
46
53
|
* Prerelease suffixes are ignored — the published channel is plain
|
|
@@ -162,8 +169,25 @@ function spawnBackgroundRefresh() {
|
|
|
162
169
|
child.on('error', () => { });
|
|
163
170
|
child.unref();
|
|
164
171
|
}
|
|
172
|
+
/** Exclusive creation is also the cross-process notice election. */
|
|
173
|
+
async function tryRecordNotice(installed, available) {
|
|
174
|
+
// Version strings originate in package metadata and the npm response. Keep
|
|
175
|
+
// their use as local path components conservative even though encoded.
|
|
176
|
+
if (!/^[0-9A-Za-z.+-]{1,80}$/.test(installed) || !/^[0-9A-Za-z.+-]{1,80}$/.test(available))
|
|
177
|
+
return false;
|
|
178
|
+
const path = updateNoticeReceiptPath(installed, available);
|
|
179
|
+
try {
|
|
180
|
+
await mkdir(dirname(path), { recursive: true });
|
|
181
|
+
await writeFile(path, JSON.stringify({ installedVersion: installed, availableVersion: available }) + '\n', { flag: 'wx' });
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
catch {
|
|
185
|
+
// Existing receipt or read-only cache: never interrupt the actual command.
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
165
189
|
/**
|
|
166
|
-
* Print
|
|
190
|
+
* Print one structured upgrade notice to stderr when the cached registry
|
|
167
191
|
* state says a newer version is published, and kick off a detached refresh
|
|
168
192
|
* when the cache is stale. Reads only local state — adds no network latency
|
|
169
193
|
* to the command. Never throws.
|
|
@@ -174,8 +198,6 @@ export async function maybeNotifyUpdate() {
|
|
|
174
198
|
return;
|
|
175
199
|
if (isCiEnvironment())
|
|
176
200
|
return;
|
|
177
|
-
if (!process.stderr.isTTY)
|
|
178
|
-
return;
|
|
179
201
|
const cache = await readCache();
|
|
180
202
|
if (!cache || Date.now() - cache.lastCheckedAt > CHECK_INTERVAL_MS) {
|
|
181
203
|
// Exactly one process refreshes: the exclusive claim file elects a
|
|
@@ -189,10 +211,14 @@ export async function maybeNotifyUpdate() {
|
|
|
189
211
|
const current = currentVersion();
|
|
190
212
|
if (!latest || !isNewerVersion(latest, current))
|
|
191
213
|
return;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
214
|
+
if (!await tryRecordNotice(current, latest))
|
|
215
|
+
return;
|
|
216
|
+
process.stderr.write('SEQ_STUDIO_UPDATE_NOTICE ' + JSON.stringify({
|
|
217
|
+
installedVersion: current,
|
|
218
|
+
availableVersion: latest,
|
|
219
|
+
package: PACKAGE_NAME,
|
|
220
|
+
guidance: 'Check project pins and permissions before updating; then verify seq-studio version and relevant --help.',
|
|
221
|
+
}) + '\n');
|
|
196
222
|
}
|
|
197
223
|
catch {
|
|
198
224
|
// Best-effort by design — an update notice must never break a command.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/studio-cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
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 whoami`. Includes Auth0 browser login shared with seqapi.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"tsx": "^4.20.3",
|
|
43
43
|
"zod": "^4.1.13",
|
|
44
44
|
"yaml": "^2.8.4",
|
|
45
|
-
"@sequenceholdings/artifact-studio": "0.9.1",
|
|
46
45
|
"@sequenceholdings/lattice": "0.1.6",
|
|
47
|
-
"@sequenceholdings/agent-spec": "0.1.4",
|
|
48
46
|
"@sequenceholdings/managed-functions": "0.4.3",
|
|
47
|
+
"@sequenceholdings/agent-spec": "0.1.4",
|
|
48
|
+
"@sequenceholdings/artifact-studio": "0.9.2",
|
|
49
49
|
"@sequenceholdings/storage": "0.1.2"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|