@sequenceholdings/studio-cli 0.9.0 → 0.9.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.
- package/README.md +75 -12
- package/dist/agents/commands.d.ts +1 -1
- package/dist/app/repository-index.d.ts +6 -0
- package/dist/app/repository-index.js +2 -2
- package/dist/command-help.d.ts +7 -7
- package/dist/command-help.js +23 -9
- package/dist/functions/commands.js +0 -23
- package/dist/machine-output.d.ts +7 -0
- package/dist/machine-output.js +56 -0
- package/dist/main.js +20 -1
- package/dist/orm/delegate.js +1 -1
- package/dist/orm/execute.js +2 -2
- package/dist/orm/read.d.ts +1 -1
- package/dist/orm/read.js +3 -3
- package/dist/process/commands.js +9 -3
- package/dist/process/human-input-probe.d.ts +23 -0
- package/dist/process/human-input-probe.js +118 -0
- package/dist/process/lint.d.ts +2 -0
- package/dist/process/lint.js +10 -0
- package/dist/process/run-steps.d.ts +112 -0
- package/dist/process/run-steps.js +123 -0
- package/dist/process/runs.d.ts +2 -2
- package/dist/process/runs.js +20 -14
- package/dist/repos/commands.d.ts +13 -0
- package/dist/repos/commands.js +28 -0
- package/dist/repos/primitive-declaration.d.ts +43 -0
- package/dist/repos/primitive-declaration.js +212 -0
- package/package.json +8 -8
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declare a primitive scaffolded on its own (`orm init`, `functions init`,
|
|
3
|
+
* `artifact init`) in its git-service repository's `.seq/repository.yml`, as a
|
|
4
|
+
* `resources` entry, so repository CI checks and deploys it. Without one, CI
|
|
5
|
+
* fails `undeclared-manifest` on the scaffold's manifest.
|
|
6
|
+
*
|
|
7
|
+
* Only git-service checkouts are touched (an origin under
|
|
8
|
+
* `/api/git-service/repos/`, or an existing index): other repositories have no
|
|
9
|
+
* repository CI to satisfy. A primitive inside a declared application belongs
|
|
10
|
+
* in that application's manifest (`seq-studio add`), never in `resources`.
|
|
11
|
+
*/
|
|
12
|
+
import { execFile } from 'node:child_process';
|
|
13
|
+
import { existsSync } from 'node:fs';
|
|
14
|
+
import { mkdir, readFile, writeFile } from 'node:fs/promises';
|
|
15
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
16
|
+
import { promisify } from 'node:util';
|
|
17
|
+
import { Document, isSeq, parseDocument } from 'yaml';
|
|
18
|
+
import { z } from 'zod';
|
|
19
|
+
import { parseArgs } from '../argv.js';
|
|
20
|
+
import { APP_MANIFEST_FILENAME } from '../app/manifest.js';
|
|
21
|
+
import { primitiveIdFor } from '../app/primitive-ids.js';
|
|
22
|
+
import { findGitRoot, REPOSITORY_INDEX_PATH, under } from '../app/repository-index.js';
|
|
23
|
+
import { LOG } from '../functions/commands.js';
|
|
24
|
+
const exec = promisify(execFile);
|
|
25
|
+
const indexSchema = z.looseObject({
|
|
26
|
+
schema_version: z.literal(1),
|
|
27
|
+
applications: z.array(z.looseObject({ path: z.string().min(1) })).nullish(),
|
|
28
|
+
resources: z.array(z.looseObject({
|
|
29
|
+
id: z.string().min(1),
|
|
30
|
+
path: z.string().min(1),
|
|
31
|
+
kind: z.string().optional(),
|
|
32
|
+
namespace: z.string().optional(),
|
|
33
|
+
slug: z.string().optional(),
|
|
34
|
+
project_id: z.string().optional(),
|
|
35
|
+
name: z.string().optional(),
|
|
36
|
+
})).nullish(),
|
|
37
|
+
ignore: z.array(z.string().min(1)).nullish(),
|
|
38
|
+
});
|
|
39
|
+
const IDENTITY_FIELD = {
|
|
40
|
+
orm: 'the namespace in sequence.config.ts',
|
|
41
|
+
function: 'function.id in managed-function.yml',
|
|
42
|
+
artifact: 'artifact.project_id in artifact.bundle.yml',
|
|
43
|
+
};
|
|
44
|
+
const NEW_INDEX_HEADER = '# Repository CI checks every application and resource listed here and deploys it when changes merge to main.\n';
|
|
45
|
+
const GIT_SERVICE_ORIGIN = /\/api\/git-service\/repos\/[^/]+(?:\/git|\.git)?\/?$/;
|
|
46
|
+
async function hasGitServiceOrigin(gitRoot) {
|
|
47
|
+
try {
|
|
48
|
+
const { stdout } = await exec('git', ['-C', gitRoot, 'remote', 'get-url', 'origin'], { encoding: 'utf8', timeout: 10_000 });
|
|
49
|
+
return GIT_SERVICE_ORIGIN.test(stdout.trim());
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function readYaml(path) {
|
|
56
|
+
if (!existsSync(path))
|
|
57
|
+
return undefined;
|
|
58
|
+
try {
|
|
59
|
+
return parseDocument(await readFile(path, 'utf8')).toJS();
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function stringAt(value, ...keys) {
|
|
66
|
+
let current = value;
|
|
67
|
+
for (const key of keys)
|
|
68
|
+
current = current && typeof current === 'object' ? Reflect.get(current, key) : undefined;
|
|
69
|
+
return typeof current === 'string' && current.length > 0 ? current : undefined;
|
|
70
|
+
}
|
|
71
|
+
/** The deployed identity the scaffold wrote, read as data (never imported). */
|
|
72
|
+
async function readIdentity({ kind, dir }) {
|
|
73
|
+
switch (kind) {
|
|
74
|
+
case 'function': {
|
|
75
|
+
const slug = stringAt(await readYaml(join(dir, 'managed-function.yml')), 'function', 'id');
|
|
76
|
+
return slug ? { id: slug, slug } : null;
|
|
77
|
+
}
|
|
78
|
+
case 'artifact': {
|
|
79
|
+
const projectId = stringAt(await readYaml(join(dir, 'artifact.bundle.yml')), 'artifact', 'project_id');
|
|
80
|
+
return projectId ? { id: primitiveIdFor({ kind: 'artifact', name: projectId }), project_id: projectId } : null;
|
|
81
|
+
}
|
|
82
|
+
case 'orm': {
|
|
83
|
+
const config = join(dir, 'sequence.config.ts');
|
|
84
|
+
const namespace = existsSync(config)
|
|
85
|
+
? /\bnamespace:\s*['"]([a-z][a-z0-9_]*)['"]/.exec(await readFile(config, 'utf8'))?.[1]
|
|
86
|
+
: undefined;
|
|
87
|
+
return namespace ? { id: primitiveIdFor({ kind: 'orm', name: namespace }), namespace } : null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
/** The deployed identity repository CI compares (its `resourceIdentity`), per kind. */
|
|
92
|
+
function deployedIdentity(resource) {
|
|
93
|
+
return resource.namespace ?? resource.slug ?? resource.project_id ?? resource.name ?? resource.id;
|
|
94
|
+
}
|
|
95
|
+
function uniqueId(id, taken) {
|
|
96
|
+
if (!taken.has(id))
|
|
97
|
+
return id;
|
|
98
|
+
for (let n = 2;; n++)
|
|
99
|
+
if (!taken.has(`${id}-${n}`))
|
|
100
|
+
return `${id}-${n}`;
|
|
101
|
+
}
|
|
102
|
+
/** The existing index (with its document, to edit in place), none, or why it cannot be edited. */
|
|
103
|
+
async function readIndex({ indexPath, path }) {
|
|
104
|
+
if (!existsSync(indexPath))
|
|
105
|
+
return null;
|
|
106
|
+
const document = parseDocument(await readFile(indexPath, 'utf8'));
|
|
107
|
+
if (document.errors.length > 0)
|
|
108
|
+
return { reason: `${REPOSITORY_INDEX_PATH} is not valid YAML; declare ${path} under resources by hand` };
|
|
109
|
+
const parsed = indexSchema.safeParse(document.toJS());
|
|
110
|
+
if (!parsed.success) {
|
|
111
|
+
return { reason: `${REPOSITORY_INDEX_PATH} is not a schema_version 1 repository index; declare ${path} under resources by hand` };
|
|
112
|
+
}
|
|
113
|
+
return { document, index: parsed.data };
|
|
114
|
+
}
|
|
115
|
+
/** Why `path` must not become a resource, or null when it can. */
|
|
116
|
+
function conflict({ path, gitRoot, index }) {
|
|
117
|
+
const applications = index
|
|
118
|
+
? (index.applications ?? []).map((application) => application.path)
|
|
119
|
+
: existsSync(join(gitRoot, APP_MANIFEST_FILENAME)) ? ['.'] : [];
|
|
120
|
+
const application = applications.find((root) => under({ path, root }));
|
|
121
|
+
if (application !== undefined) {
|
|
122
|
+
return `${path} is inside the application at ${application}; add it to that application's ${APP_MANIFEST_FILENAME} (seq-studio add) so repository CI checks it`;
|
|
123
|
+
}
|
|
124
|
+
const overlap = (index?.resources ?? []).find((resource) => resource.path !== path &&
|
|
125
|
+
(under({ path, root: resource.path }) || under({ path: resource.path, root: path })));
|
|
126
|
+
if (overlap !== undefined)
|
|
127
|
+
return `${path} overlaps the declared resource ${overlap.id} at ${overlap.path}; move one so their roots are separate`;
|
|
128
|
+
const ignored = (index?.ignore ?? []).find((root) => under({ path, root }) || under({ path: root, root: path }));
|
|
129
|
+
if (ignored !== undefined)
|
|
130
|
+
return `${REPOSITORY_INDEX_PATH} ignores ${ignored}, so repository CI leaves ${path} unmanaged`;
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
/** Plan the index change for a primitive just scaffolded at `dir`. */
|
|
134
|
+
export async function planResourceDeclaration({ kind, dir }) {
|
|
135
|
+
const gitRoot = findGitRoot(dir);
|
|
136
|
+
if (gitRoot === null)
|
|
137
|
+
return { action: 'skip' };
|
|
138
|
+
const path = relative(gitRoot, resolve(dir)).split(sep).join('/') || '.';
|
|
139
|
+
if (path.startsWith('..'))
|
|
140
|
+
return { action: 'skip' };
|
|
141
|
+
const indexPath = join(gitRoot, REPOSITORY_INDEX_PATH);
|
|
142
|
+
const existing = await readIndex({ indexPath, path });
|
|
143
|
+
if (existing && 'reason' in existing)
|
|
144
|
+
return { action: 'skip', reason: existing.reason };
|
|
145
|
+
if (!existing && !(await hasGitServiceOrigin(gitRoot)))
|
|
146
|
+
return { action: 'skip' };
|
|
147
|
+
const resources = existing?.index.resources ?? [];
|
|
148
|
+
if (resources.some((resource) => resource.path === path))
|
|
149
|
+
return { action: 'skip' };
|
|
150
|
+
const reason = conflict({ path, gitRoot, index: existing?.index });
|
|
151
|
+
if (reason !== null)
|
|
152
|
+
return { action: 'skip', reason };
|
|
153
|
+
const identity = await readIdentity({ kind, dir });
|
|
154
|
+
if (!identity?.id)
|
|
155
|
+
return { action: 'skip', reason: `could not read the ${kind} identity in ${path}; declare it under resources in ${REPOSITORY_INDEX_PATH} by hand` };
|
|
156
|
+
const { id, ...fields } = identity;
|
|
157
|
+
const entry = { id: uniqueId(id, new Set(resources.map((resource) => resource.id))), kind, path, ...fields };
|
|
158
|
+
const twin = resources.find((resource) => resource.kind === kind && deployedIdentity(resource) === deployedIdentity(entry));
|
|
159
|
+
if (twin !== undefined) {
|
|
160
|
+
return {
|
|
161
|
+
action: 'skip',
|
|
162
|
+
reason: `${path} deploys the same ${kind} "${deployedIdentity(entry)}" as the declared resource ${twin.id} at ${twin.path}; ` +
|
|
163
|
+
`rename one (${IDENTITY_FIELD[kind]}) and declare it under resources in ${REPOSITORY_INDEX_PATH}`,
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (!existing) {
|
|
167
|
+
const fresh = new Document({ schema_version: 1, resources: [entry] });
|
|
168
|
+
return { action: 'write', indexPath, content: `${NEW_INDEX_HEADER}${fresh.toString()}`, entry, created: true };
|
|
169
|
+
}
|
|
170
|
+
const { document } = existing;
|
|
171
|
+
const list = document.get('resources');
|
|
172
|
+
if (isSeq(list))
|
|
173
|
+
list.add(document.createNode(entry));
|
|
174
|
+
else
|
|
175
|
+
document.set('resources', [entry]);
|
|
176
|
+
return { action: 'write', indexPath, content: document.toString(), entry, created: false };
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* After a successful standalone init, declare the scaffold for repository CI.
|
|
180
|
+
* Never changes the init's exit code: a declaration problem is a warning with
|
|
181
|
+
* the manual fix.
|
|
182
|
+
*/
|
|
183
|
+
export async function declareScaffoldedPrimitive({ kind, dir }) {
|
|
184
|
+
try {
|
|
185
|
+
const plan = await planResourceDeclaration({ kind, dir });
|
|
186
|
+
if (plan.action === 'skip') {
|
|
187
|
+
if (plan.reason)
|
|
188
|
+
console.error(`${LOG} not declared for repository CI: ${plan.reason}`);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
await mkdir(dirname(plan.indexPath), { recursive: true });
|
|
192
|
+
await writeFile(plan.indexPath, plan.content, 'utf8');
|
|
193
|
+
console.log(`${LOG} ${plan.created ? 'created' : 'updated'} ${REPOSITORY_INDEX_PATH}: declared ${kind} "${plan.entry.id}" at ${plan.entry.path} ` +
|
|
194
|
+
'so repository CI checks and deploys it; commit it with the scaffold');
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
console.error(`${LOG} could not update ${REPOSITORY_INDEX_PATH} for ${basename(dir)}: ${error instanceof Error ? error.message : String(error)}`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Run a standalone init (`argv` is everything after `init`), then declare its
|
|
202
|
+
* scaffold. `defaultDir` is where the init scaffolds without a positional.
|
|
203
|
+
*/
|
|
204
|
+
export async function runStandaloneInit({ kind, argv, defaultDir, run }) {
|
|
205
|
+
const code = await run();
|
|
206
|
+
if (code !== 0 || argv.includes('--help') || argv.includes('-h'))
|
|
207
|
+
return code;
|
|
208
|
+
const target = parseArgs([...argv]).positional[0] ?? defaultDir;
|
|
209
|
+
if (target !== undefined)
|
|
210
|
+
await declareScaffoldedPrimitive({ kind, dir: resolve(target) });
|
|
211
|
+
return code;
|
|
212
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequenceholdings/studio-cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
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": {
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"yaml": "^2.8.4",
|
|
46
46
|
"zod": "^4.1.13",
|
|
47
47
|
"@sequenceholdings/agent-spec": "0.1.5",
|
|
48
|
-
"@sequenceholdings/artifact-studio": "0.11.
|
|
49
|
-
"@sequenceholdings/lattice": "0.1.
|
|
50
|
-
"@sequenceholdings/managed-functions": "0.5.
|
|
51
|
-
"@sequenceholdings/storage": "0.1.
|
|
52
|
-
"@sequenceholdings/platform": "0.1.
|
|
48
|
+
"@sequenceholdings/artifact-studio": "0.11.2",
|
|
49
|
+
"@sequenceholdings/lattice": "0.1.8",
|
|
50
|
+
"@sequenceholdings/managed-functions": "0.5.2",
|
|
51
|
+
"@sequenceholdings/storage": "0.1.4",
|
|
52
|
+
"@sequenceholdings/platform": "0.1.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@sequenceholdings/orm": "2.8.1",
|
|
@@ -69,8 +69,8 @@
|
|
|
69
69
|
"@types/semver": "^7.8.0",
|
|
70
70
|
"typescript": "^5.6.0",
|
|
71
71
|
"vitest": "^4.1.11",
|
|
72
|
-
"@sequenceholdings/
|
|
73
|
-
"@sequenceholdings/
|
|
72
|
+
"@sequenceholdings/orm": "2.8.1",
|
|
73
|
+
"@sequenceholdings/pipeline-spec": "0.3.1"
|
|
74
74
|
},
|
|
75
75
|
"engines": {
|
|
76
76
|
"node": ">=20"
|