@oml/cli 0.13.0 → 0.14.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.
- package/README.md +28 -21
- package/out/{auth.d.ts → auth/auth.d.ts} +7 -0
- package/out/{auth.js → auth/auth.js} +42 -3
- package/out/auth/auth.js.map +1 -0
- package/out/{platform-constants.js → auth/constants.js} +1 -1
- package/out/auth/constants.js.map +1 -0
- package/out/{platform.d.ts → auth/platform.d.ts} +5 -7
- package/out/{platform.js → auth/platform.js} +13 -19
- package/out/auth/platform.js.map +1 -0
- package/out/cli.d.ts +6 -0
- package/out/cli.js +175 -62
- package/out/cli.js.map +1 -1
- package/out/commands/export.d.ts +8 -0
- package/out/commands/export.js +27 -0
- package/out/commands/export.js.map +1 -0
- package/out/commands/lint.d.ts +22 -2
- package/out/commands/lint.js +64 -18
- package/out/commands/lint.js.map +1 -1
- package/out/commands/reason.d.ts +2 -9
- package/out/commands/reason.js +52 -48
- package/out/commands/reason.js.map +1 -1
- package/out/commands/render.d.ts +1 -9
- package/out/commands/render.js +15 -726
- package/out/commands/render.js.map +1 -1
- package/out/commands/server/actions.d.ts +22 -0
- package/out/commands/server/actions.js +394 -0
- package/out/commands/server/actions.js.map +1 -0
- package/out/commands/server/require.d.ts +1 -0
- package/out/commands/server/require.js +89 -0
- package/out/commands/server/require.js.map +1 -0
- package/out/commands/server/rest.d.ts +2 -0
- package/out/commands/server/rest.js +117 -0
- package/out/commands/server/rest.js.map +1 -0
- package/out/commands/validate.d.ts +3 -3
- package/out/commands/validate.js +35 -171
- package/out/commands/validate.js.map +1 -1
- package/package.json +5 -7
- package/src/{auth.ts → auth/auth.ts} +54 -3
- package/src/{platform.ts → auth/platform.ts} +13 -19
- package/src/cli.ts +207 -63
- package/src/commands/export.ts +54 -0
- package/src/commands/lint.ts +88 -18
- package/src/commands/reason.ts +69 -56
- package/src/commands/render.ts +23 -995
- package/src/commands/server/actions.ts +480 -0
- package/src/commands/server/require.ts +99 -0
- package/src/commands/server/rest.ts +135 -0
- package/src/commands/validate.ts +46 -207
- package/out/auth.js.map +0 -1
- package/out/backend/backend-types.d.ts +0 -21
- package/out/backend/backend-types.js +0 -3
- package/out/backend/backend-types.js.map +0 -1
- package/out/backend/create-backend.d.ts +0 -2
- package/out/backend/create-backend.js +0 -6
- package/out/backend/create-backend.js.map +0 -1
- package/out/backend/direct-backend.d.ts +0 -20
- package/out/backend/direct-backend.js +0 -150
- package/out/backend/direct-backend.js.map +0 -1
- package/out/backend/reasoned-output.d.ts +0 -38
- package/out/backend/reasoned-output.js +0 -568
- package/out/backend/reasoned-output.js.map +0 -1
- package/out/commands/closure.d.ts +0 -33
- package/out/commands/closure.js +0 -537
- package/out/commands/closure.js.map +0 -1
- package/out/commands/compile.d.ts +0 -11
- package/out/commands/compile.js +0 -63
- package/out/commands/compile.js.map +0 -1
- package/out/platform-constants.js.map +0 -1
- package/out/platform.js.map +0 -1
- package/src/backend/backend-types.ts +0 -27
- package/src/backend/create-backend.ts +0 -8
- package/src/backend/direct-backend.ts +0 -169
- package/src/backend/reasoned-output.ts +0 -697
- package/src/commands/closure.ts +0 -624
- package/src/commands/compile.ts +0 -88
- /package/out/{platform-constants.d.ts → auth/constants.d.ts} +0 -0
- /package/src/{platform-constants.ts → auth/constants.ts} +0 -0
package/src/cli.ts
CHANGED
|
@@ -5,19 +5,56 @@ import { Command } from 'commander';
|
|
|
5
5
|
import * as fs from 'node:fs/promises';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
import * as url from 'node:url';
|
|
8
|
-
import { OmlCliAuthService } from './auth.js';
|
|
9
|
-
import {
|
|
8
|
+
import { OmlCliAuthService } from './auth/auth.js';
|
|
9
|
+
import { exchangeApiToken } from '@oml/platform';
|
|
10
|
+
import { DEFAULT_API_BASE_URL } from './auth/constants.js';
|
|
11
|
+
import { exportAction } from './commands/export.js';
|
|
10
12
|
import { lintAction } from './commands/lint.js';
|
|
11
13
|
import { renderAction } from './commands/render.js';
|
|
14
|
+
import { serverStartAction, serverRunAction, serverStatusAction, serverStopAction } from './commands/server/actions.js';
|
|
15
|
+
import { assertServerRunning } from './commands/server/require.js';
|
|
12
16
|
import { notifyIfCliUpdateAvailable } from './update.js';
|
|
13
17
|
import { validateAction } from './commands/validate.js';
|
|
14
18
|
import { CliExitError } from './cli-error.js';
|
|
15
|
-
import { initializePlatform, disposePlatform, trackCommand } from './platform.js';
|
|
19
|
+
import { initializePlatform, disposePlatform, trackCommand } from './auth/platform.js';
|
|
16
20
|
|
|
17
21
|
const __dirname = url.fileURLToPath(new URL('.', import.meta.url));
|
|
18
22
|
let debugEnabled = false;
|
|
19
23
|
|
|
24
|
+
export interface CliCommandInfo {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
usage?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getWorkspaceCommands(): CliCommandInfo[] {
|
|
31
|
+
return [
|
|
32
|
+
{ name: 'lint', description: 'lints OML files and prints any syntax or validation errors' },
|
|
33
|
+
{
|
|
34
|
+
name: 'render [options]',
|
|
35
|
+
description: 'lint the workspace, then render markdown files to static html',
|
|
36
|
+
usage: 'render -m <input-folder> -b <output-folder> [-c <ontology-iri>] [--only]'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: 'export [options]',
|
|
40
|
+
description: 'export OWL files including reasoned entailments',
|
|
41
|
+
usage: 'export [-o <dir>] [-f <ext>] [--clean] [--pretty] [--only]'
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: 'reason [options]',
|
|
45
|
+
description: 'run workspace consistency checks via /v0/reason (check-only)',
|
|
46
|
+
usage: 'reason [-e <true|false>] [--only]'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
name: 'validate [options]',
|
|
50
|
+
description: 'validate table-editor SHACL blocks in workspace markdown files',
|
|
51
|
+
usage: 'validate [--only]'
|
|
52
|
+
},
|
|
53
|
+
];
|
|
54
|
+
}
|
|
55
|
+
|
|
20
56
|
export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
57
|
+
assertNoMalformedShortFlags(argv);
|
|
21
58
|
debugEnabled = hasDebugFlag(argv);
|
|
22
59
|
if (debugEnabled) {
|
|
23
60
|
process.env.OML_PLATFORM_DEBUG = '1';
|
|
@@ -28,8 +65,8 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
28
65
|
const updateCheck = notifyIfCliUpdateAvailable(packageJson.version);
|
|
29
66
|
|
|
30
67
|
const program = new Command();
|
|
31
|
-
program.version(packageJson.version);
|
|
32
|
-
program.option('--debug', 'print detailed error diagnostics (stack traces and nested causes)');
|
|
68
|
+
program.version(packageJson.version, '-v, --version', 'output the version number');
|
|
69
|
+
program.option('-d, --debug', 'print detailed error diagnostics (stack traces and nested causes)');
|
|
33
70
|
const authService = new OmlCliAuthService();
|
|
34
71
|
|
|
35
72
|
program
|
|
@@ -55,12 +92,15 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
55
92
|
|
|
56
93
|
program
|
|
57
94
|
.command('lint')
|
|
58
|
-
.option('-w, --workspace <dir>', 'workspace root used to resolve cross-file references', '.')
|
|
59
95
|
.description('lints OML files and prints any syntax or validation errors')
|
|
60
96
|
.action(async (...args: unknown[]) => {
|
|
61
97
|
const done = trackCommand('oml-lint');
|
|
62
98
|
try {
|
|
63
|
-
|
|
99
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
100
|
+
await lintAction({
|
|
101
|
+
...(args[0] as Record<string, unknown> | undefined ?? {}),
|
|
102
|
+
authToken,
|
|
103
|
+
});
|
|
64
104
|
done();
|
|
65
105
|
} catch (err) {
|
|
66
106
|
done(err);
|
|
@@ -70,23 +110,18 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
70
110
|
|
|
71
111
|
program
|
|
72
112
|
.command('render')
|
|
73
|
-
.
|
|
74
|
-
.requiredOption('-
|
|
75
|
-
.
|
|
76
|
-
.
|
|
77
|
-
.option('-f, --format <ext>', 'RDF format extension for compile/reason output: ttl, trig, nt, nq, or n3', 'ttl')
|
|
78
|
-
.option('-c, --context <model-uri>', 'default model URI/path used for markdown files without contextUri; also enables wikilink template page generation')
|
|
79
|
-
.option('--clean', 'remove output folders before rebuilding')
|
|
80
|
-
.option('--only', 'skip reason/compile/lint and render from the existing owl output folder')
|
|
81
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
82
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
83
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
84
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
85
|
-
.description('reason the workspace, then render markdown files under the selected markdown folder to static html and copy referenced non-markdown assets')
|
|
113
|
+
.requiredOption('-m, --md <input-folder>', 'folder containing markdown files to render')
|
|
114
|
+
.requiredOption('-b, --web <output-folder>', 'folder where rendered static site files are written')
|
|
115
|
+
.option('-c, --context <ontology-iri>', 'ontology IRI used as default navigation context for wikilinks')
|
|
116
|
+
.description('lint the workspace, then render markdown files to static html')
|
|
86
117
|
.action(async (...args: unknown[]) => {
|
|
87
118
|
const done = trackCommand('oml-render');
|
|
88
119
|
try {
|
|
89
|
-
|
|
120
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
121
|
+
await renderAction({
|
|
122
|
+
...(args[0] as Record<string, unknown> | undefined ?? {}),
|
|
123
|
+
authToken,
|
|
124
|
+
} as Parameters<typeof renderAction>[0]);
|
|
90
125
|
done();
|
|
91
126
|
} catch (err) {
|
|
92
127
|
done(err);
|
|
@@ -95,18 +130,20 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
95
130
|
});
|
|
96
131
|
|
|
97
132
|
program
|
|
98
|
-
.command('
|
|
99
|
-
.option('-
|
|
100
|
-
.option('-owl, --owl <dir>', 'folder where compiled RDF files are written')
|
|
133
|
+
.command('export')
|
|
134
|
+
.option('-o, --owl <dir>', 'folder where RDF output files are written')
|
|
101
135
|
.option('-f, --format <ext>', 'RDF format extension: ttl, trig, nt, nq, or n3', 'ttl')
|
|
102
|
-
.option('--clean', 'remove output folder before
|
|
103
|
-
.option('--only', 'skip lint and compile from the current workspace state')
|
|
136
|
+
.option('--clean', 'remove output folder before export')
|
|
104
137
|
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
105
|
-
.description('
|
|
138
|
+
.description('export OWL files including reasoned entailments')
|
|
106
139
|
.action(async (...args: unknown[]) => {
|
|
107
|
-
const done = trackCommand('oml-
|
|
140
|
+
const done = trackCommand('oml-export');
|
|
108
141
|
try {
|
|
109
|
-
|
|
142
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
143
|
+
await exportAction({
|
|
144
|
+
...(args[0] as Record<string, unknown> | undefined ?? {}),
|
|
145
|
+
authToken,
|
|
146
|
+
} as Parameters<typeof exportAction>[0]);
|
|
110
147
|
done();
|
|
111
148
|
} catch (err) {
|
|
112
149
|
done(err);
|
|
@@ -116,22 +153,15 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
116
153
|
|
|
117
154
|
program
|
|
118
155
|
.command('reason')
|
|
119
|
-
.option('-
|
|
120
|
-
.option('
|
|
121
|
-
.
|
|
122
|
-
.option('--clean', 'remove output folder before compiling')
|
|
123
|
-
.option('--only', 'skip compile/lint and reason from the existing owl output folder')
|
|
124
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
125
|
-
.option('-c, --check-only', 'only check consistency; skip entailment materialization and file output')
|
|
126
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
127
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
128
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
129
|
-
.description('compile OML files, then run consistency checking for every ontology in dependency order')
|
|
156
|
+
.option('-e, --explanation [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
157
|
+
.option('--only', 'skip lint and reason from the current server workspace state')
|
|
158
|
+
.description('run workspace consistency checks via /v0/reason (check-only)')
|
|
130
159
|
.action(async (opts) => {
|
|
131
160
|
const done = trackCommand('oml-reason');
|
|
132
161
|
try {
|
|
133
162
|
const { reasonAction } = await import('./commands/reason.js');
|
|
134
|
-
await
|
|
163
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
164
|
+
await reasonAction({ ...(opts as Record<string, unknown>), authToken } as Parameters<typeof reasonAction>[0]);
|
|
135
165
|
done();
|
|
136
166
|
} catch (err) {
|
|
137
167
|
done(err);
|
|
@@ -141,21 +171,16 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
141
171
|
|
|
142
172
|
program
|
|
143
173
|
.command('validate')
|
|
144
|
-
.
|
|
145
|
-
.
|
|
146
|
-
.option('-owl, --owl <dir>', 'folder where compiled RDF and entailment files are written')
|
|
147
|
-
.option('-f, --format <ext>', 'RDF format extension for compile output: ttl, trig, nt, nq, or n3', 'ttl')
|
|
148
|
-
.option('--clean', 'remove output folder before compiling')
|
|
149
|
-
.option('--only', 'skip compile/lint and reason from the existing owl output folder')
|
|
150
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
151
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
152
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
153
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
154
|
-
.description('compile and reason the workspace, then validate nested markdown table-editor SHACL blocks against their context models')
|
|
174
|
+
.option('--only', 'skip lint and validate markdown blocks only')
|
|
175
|
+
.description('validate table-editor SHACL blocks in workspace markdown files')
|
|
155
176
|
.action(async (...args: unknown[]) => {
|
|
156
177
|
const done = trackCommand('oml-validate');
|
|
157
178
|
try {
|
|
158
|
-
|
|
179
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
180
|
+
await validateAction({
|
|
181
|
+
...(args[0] as Record<string, unknown> | undefined ?? {}),
|
|
182
|
+
authToken,
|
|
183
|
+
} as Parameters<typeof validateAction>[0]);
|
|
159
184
|
done();
|
|
160
185
|
} catch (err) {
|
|
161
186
|
done(err);
|
|
@@ -163,10 +188,55 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
163
188
|
}
|
|
164
189
|
});
|
|
165
190
|
|
|
191
|
+
const server = program
|
|
192
|
+
.command('server')
|
|
193
|
+
.description('manage the standalone OML language server daemon');
|
|
194
|
+
|
|
195
|
+
server
|
|
196
|
+
.command('start [port]')
|
|
197
|
+
.option('-p, --port <port>', 'bind port (default: auto-select free port)')
|
|
198
|
+
.option('--workspace <workspace>', 'workspace root used by REST facade initialize (default: cwd)')
|
|
199
|
+
.description('start the OML server as a background daemon (CI/CD, requires OML_PLATFORM_API_KEY)')
|
|
200
|
+
.action(async (port: string | undefined, options: { port?: string; workspace?: string }) => {
|
|
201
|
+
await serverStartAction(port, { ...options, auth: await resolveServerStartAuth() });
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
server
|
|
205
|
+
.command('run [port]')
|
|
206
|
+
.option('-p, --port <port>', 'bind port (default: auto-select free port)')
|
|
207
|
+
.option('--workspace <workspace>', 'workspace root (default: cwd)')
|
|
208
|
+
.description('run the OML server in the foreground with interactive authentication (Ctrl-C to stop)')
|
|
209
|
+
.action(async (port: string | undefined, options: { port?: string; workspace?: string }) => {
|
|
210
|
+
await serverRunAction(port, { ...options, auth: await resolveServerRunAuth(authService) });
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
server
|
|
214
|
+
.command('stop')
|
|
215
|
+
.description('stop the OML language server daemon')
|
|
216
|
+
.action(async () => {
|
|
217
|
+
await serverStopAction();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
server
|
|
221
|
+
.command('status')
|
|
222
|
+
.description('print server daemon status')
|
|
223
|
+
.action(async () => {
|
|
224
|
+
await serverStatusAction();
|
|
225
|
+
});
|
|
226
|
+
|
|
166
227
|
program.hook('preAction', async (_thisCommand, actionCommand) => {
|
|
167
|
-
if (
|
|
228
|
+
if (
|
|
229
|
+
actionCommand.name() === 'login'
|
|
230
|
+
|| actionCommand.name() === 'logout'
|
|
231
|
+
|| actionCommand.name() === 'whoami'
|
|
232
|
+
|| actionCommand.name() === 'start'
|
|
233
|
+
|| actionCommand.name() === 'run'
|
|
234
|
+
|| actionCommand.name() === 'stop'
|
|
235
|
+
|| actionCommand.name() === 'status'
|
|
236
|
+
) {
|
|
168
237
|
return;
|
|
169
238
|
}
|
|
239
|
+
await assertServerRunning();
|
|
170
240
|
// Require either GitHub auth or API key, then connect to platform
|
|
171
241
|
if (!process.env.OML_PLATFORM_API_KEY) {
|
|
172
242
|
await authService.ensureAuthenticated('OML CLI');
|
|
@@ -182,6 +252,36 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
182
252
|
await updateCheck;
|
|
183
253
|
}
|
|
184
254
|
|
|
255
|
+
function assertNoMalformedShortFlags(argv: string[]): void {
|
|
256
|
+
// Enforce explicit short-flag syntax (`-m value`) and long flags (`--md`).
|
|
257
|
+
// This prevents accidental typos like `-md`, which Commander interprets as `-m d`.
|
|
258
|
+
let stopOptionParsing = false;
|
|
259
|
+
for (const token of argv.slice(2)) {
|
|
260
|
+
if (stopOptionParsing) {
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
if (token === '--') {
|
|
264
|
+
stopOptionParsing = true;
|
|
265
|
+
continue;
|
|
266
|
+
}
|
|
267
|
+
if (token.startsWith('---')) {
|
|
268
|
+
throw new Error(
|
|
269
|
+
`Malformed flag '${token}'. Use long flags as '--name <value>' or '--name=<value>'.`,
|
|
270
|
+
);
|
|
271
|
+
}
|
|
272
|
+
if (token === '--=' || token.startsWith('--=')) {
|
|
273
|
+
throw new Error(
|
|
274
|
+
`Malformed flag '${token}'. Use long flags as '--name <value>' or '--name=<value>'.`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
if (/^-[^-].+/.test(token) && token.length > 2) {
|
|
278
|
+
throw new Error(
|
|
279
|
+
`Malformed flag '${token}'. Use short flags as '-x <value>' or long flags as '--name <value>'.`,
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
185
285
|
export function reportCliError(error: unknown): number {
|
|
186
286
|
const exitCode = error instanceof CliExitError ? error.exitCode : 1;
|
|
187
287
|
const message = debugEnabled
|
|
@@ -193,6 +293,14 @@ export function reportCliError(error: unknown): number {
|
|
|
193
293
|
return exitCode;
|
|
194
294
|
}
|
|
195
295
|
|
|
296
|
+
process.on('unhandledRejection', (error) => {
|
|
297
|
+
const message = debugEnabled
|
|
298
|
+
? formatDetailedError(error)
|
|
299
|
+
: (error instanceof Error ? error.message : String(error));
|
|
300
|
+
console.error(chalk.red(message));
|
|
301
|
+
process.exitCode = 1;
|
|
302
|
+
});
|
|
303
|
+
|
|
196
304
|
function parseBooleanOption(value: string | boolean): boolean {
|
|
197
305
|
if (typeof value === 'boolean') {
|
|
198
306
|
return value;
|
|
@@ -207,16 +315,52 @@ function parseBooleanOption(value: string | boolean): boolean {
|
|
|
207
315
|
throw new Error(`Expected a boolean value, received '${value}'.`);
|
|
208
316
|
}
|
|
209
317
|
|
|
210
|
-
process.on('unhandledRejection', (error) => {
|
|
211
|
-
const message = debugEnabled
|
|
212
|
-
? formatDetailedError(error)
|
|
213
|
-
: (error instanceof Error ? error.message : String(error));
|
|
214
|
-
console.error(chalk.red(message));
|
|
215
|
-
process.exitCode = 1;
|
|
216
|
-
});
|
|
217
|
-
|
|
218
318
|
function hasDebugFlag(argv: string[]): boolean {
|
|
219
|
-
return argv.includes('--debug');
|
|
319
|
+
return argv.includes('--debug') || argv.includes('-d');
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
async function resolveServerRequestToken(authService: OmlCliAuthService): Promise<string | undefined> {
|
|
323
|
+
const apiKey = process.env.OML_PLATFORM_API_KEY?.trim();
|
|
324
|
+
if (apiKey && apiKey.length > 0) {
|
|
325
|
+
return apiKey;
|
|
326
|
+
}
|
|
327
|
+
const snapshot = await authService.getServerAuthSnapshot();
|
|
328
|
+
return snapshot.accessToken;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async function resolveServerStartAuth(): Promise<{ accessToken: string }> {
|
|
332
|
+
const apiKey = process.env.OML_PLATFORM_API_KEY?.trim();
|
|
333
|
+
if (!apiKey) {
|
|
334
|
+
throw new CliExitError(
|
|
335
|
+
'OML_PLATFORM_API_KEY is not set. oml server start requires an API key for non-interactive use. ' +
|
|
336
|
+
'For interactive use, run \'oml server run\' instead.'
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
const oidcToken = process.env.OML_CI_TOKEN?.trim();
|
|
340
|
+
const apiBaseUrl = process.env.OML_PLATFORM_API_URL?.trim() ?? DEFAULT_API_BASE_URL;
|
|
341
|
+
const result = await exchangeApiToken(apiBaseUrl, apiKey, oidcToken || undefined);
|
|
342
|
+
return { accessToken: result.accessToken };
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
async function resolveServerRunAuth(authService: OmlCliAuthService): Promise<{
|
|
346
|
+
accessToken: string;
|
|
347
|
+
refreshToken: string;
|
|
348
|
+
expiresAtMs: number;
|
|
349
|
+
onRefresh: (newAccessToken: string, newRefreshToken: string, newExpiresAtMs: number) => Promise<void>;
|
|
350
|
+
}> {
|
|
351
|
+
await authService.ensureAuthenticated('oml server run');
|
|
352
|
+
const snapshot = await authService.getServerAuthSnapshot();
|
|
353
|
+
if (!snapshot.refreshToken || snapshot.expiresAtMs === undefined) {
|
|
354
|
+
throw new CliExitError('Authentication session is incomplete. Run oml login again.');
|
|
355
|
+
}
|
|
356
|
+
return {
|
|
357
|
+
accessToken: snapshot.accessToken,
|
|
358
|
+
refreshToken: snapshot.refreshToken,
|
|
359
|
+
expiresAtMs: snapshot.expiresAtMs,
|
|
360
|
+
onRefresh: async (newAccessToken, newRefreshToken, newExpiresAtMs) => {
|
|
361
|
+
await authService.storeRefreshedTokens(newAccessToken, newRefreshToken, newExpiresAtMs);
|
|
362
|
+
},
|
|
363
|
+
};
|
|
220
364
|
}
|
|
221
365
|
|
|
222
366
|
function formatDetailedError(error: unknown): string {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import chalk from 'chalk';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { failCli } from '../cli-error.js';
|
|
6
|
+
import { formatDuration } from '../util.js';
|
|
7
|
+
import { restPost } from './server/rest.js';
|
|
8
|
+
import { lintAction } from './lint.js';
|
|
9
|
+
|
|
10
|
+
export type ExportOptions = {
|
|
11
|
+
owl?: string,
|
|
12
|
+
format?: string,
|
|
13
|
+
clean?: boolean,
|
|
14
|
+
pretty?: boolean,
|
|
15
|
+
authToken?: string
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const exportAction = async (opts: ExportOptions): Promise<void> => {
|
|
19
|
+
await lintAction({ authToken: opts.authToken });
|
|
20
|
+
const startedAt = Date.now();
|
|
21
|
+
|
|
22
|
+
const result = await restPost<{
|
|
23
|
+
success: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
assertedExport?: {
|
|
26
|
+
success: boolean;
|
|
27
|
+
filesWritten: number;
|
|
28
|
+
outputDir: string;
|
|
29
|
+
format: string;
|
|
30
|
+
error?: string;
|
|
31
|
+
};
|
|
32
|
+
reason?: {
|
|
33
|
+
success: boolean;
|
|
34
|
+
ontologiesReasoned: number;
|
|
35
|
+
inconsistent: Array<{ modelUri: string; validationWarnings: string[] }>;
|
|
36
|
+
failed: Array<{ modelUri: string; error: string }>;
|
|
37
|
+
};
|
|
38
|
+
}>('/v0/export', {
|
|
39
|
+
...opts,
|
|
40
|
+
only: true,
|
|
41
|
+
} as unknown as Record<string, unknown>, opts.authToken);
|
|
42
|
+
|
|
43
|
+
if (!result.success) {
|
|
44
|
+
failCli(chalk.red(result.error?.trim() || result.assertedExport?.error?.trim() || 'export failed.'));
|
|
45
|
+
}
|
|
46
|
+
const written = Number(result.assertedExport?.filesWritten ?? 0);
|
|
47
|
+
if (written === 0) {
|
|
48
|
+
console.log(chalk.yellow('No .oml files found in server workspace.'));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const outputDir = result.assertedExport?.outputDir ?? opts.owl ?? path.join(process.cwd(), 'build', 'owl');
|
|
52
|
+
const reasoned = Number(result.reason?.ontologiesReasoned ?? written);
|
|
53
|
+
console.log(chalk.green(`export: ${written} OML file(s) exported with entailments (${reasoned} ontology checks) in ${path.relative(process.cwd(), outputDir) || outputDir} [${formatDuration(Date.now() - startedAt)}]`));
|
|
54
|
+
};
|
package/src/commands/lint.ts
CHANGED
|
@@ -1,31 +1,101 @@
|
|
|
1
1
|
// Copyright (c) 2026 Modelware. All rights reserved.
|
|
2
2
|
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
-
import
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
5
6
|
import { failCli } from '../cli-error.js';
|
|
6
7
|
import { formatDuration } from '../util.js';
|
|
8
|
+
import { restPost } from './server/rest.js';
|
|
9
|
+
|
|
10
|
+
export type LintProblem = {
|
|
11
|
+
uri: string;
|
|
12
|
+
line: number;
|
|
13
|
+
column: number;
|
|
14
|
+
kind: 'error' | 'warning' | 'information' | 'hint' | 'unknown';
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type LintPayload = {
|
|
19
|
+
success: boolean;
|
|
20
|
+
filesChecked: number;
|
|
21
|
+
errors: number;
|
|
22
|
+
warnings: number;
|
|
23
|
+
elapsedMs?: number;
|
|
24
|
+
returnedProblems?: number;
|
|
25
|
+
totalProblems?: number;
|
|
26
|
+
truncated?: boolean;
|
|
27
|
+
problems?: LintProblem[];
|
|
28
|
+
error?: string;
|
|
29
|
+
};
|
|
7
30
|
|
|
8
31
|
export type LintOptions = {
|
|
9
|
-
|
|
10
|
-
workspaceRoot?: string
|
|
32
|
+
authToken?: string
|
|
11
33
|
};
|
|
12
34
|
|
|
35
|
+
export function printLintDiagnostics(result: LintPayload): void {
|
|
36
|
+
const problems = Array.isArray(result.problems) ? result.problems : [];
|
|
37
|
+
if (problems.length === 0) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
for (const problem of problems) {
|
|
41
|
+
const location = `${formatProblemUri(problem.uri)}:${Math.max(1, Number(problem.line ?? 1))}:${Math.max(1, Number(problem.column ?? 1))}`;
|
|
42
|
+
const kind = String(problem.kind ?? 'unknown').toLowerCase();
|
|
43
|
+
const kindLabel = kind === 'error'
|
|
44
|
+
? chalk.red(kind)
|
|
45
|
+
: (kind === 'warning'
|
|
46
|
+
? chalk.yellow(kind)
|
|
47
|
+
: chalk.cyan(kind));
|
|
48
|
+
console.log(`${location} ${kindLabel} ${String(problem.message ?? '').trim()}`);
|
|
49
|
+
}
|
|
50
|
+
if (result.truncated) {
|
|
51
|
+
const returned = Number(result.returnedProblems ?? problems.length);
|
|
52
|
+
const total = Number(result.totalProblems ?? returned);
|
|
53
|
+
console.log(chalk.yellow(`lint: showing ${returned} of ${total} problem(s); increase lint limit to see all.`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function formatLintSummary(result: LintPayload, elapsedMs: number): string {
|
|
58
|
+
if (result.errors > 0 || result.warnings > 0) {
|
|
59
|
+
return `lint: ${result.filesChecked} OML file(s) checked with ${result.errors} error(s) and ${result.warnings} warning(s). [${formatDuration(elapsedMs)}]`;
|
|
60
|
+
}
|
|
61
|
+
return `lint: ${result.filesChecked} OML file(s) checked. [${formatDuration(elapsedMs)}]`;
|
|
62
|
+
}
|
|
63
|
+
|
|
13
64
|
export const lintAction = async (opts: LintOptions): Promise<void> => {
|
|
14
65
|
const startedAt = Date.now();
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
await backend.dispose();
|
|
66
|
+
const result = await restPost<LintPayload>('/v0/lint', {}, opts.authToken);
|
|
67
|
+
if (result.error && result.error.trim().length > 0) {
|
|
68
|
+
failCli(chalk.red(result.error.trim()));
|
|
69
|
+
}
|
|
70
|
+
if (result.filesChecked === 0) {
|
|
71
|
+
console.log(chalk.yellow('No .oml files found in server workspace.'));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
printLintDiagnostics(result);
|
|
75
|
+
const elapsedMs = typeof result.elapsedMs === 'number' && Number.isFinite(result.elapsedMs) && result.elapsedMs >= 0
|
|
76
|
+
? result.elapsedMs
|
|
77
|
+
: Date.now() - startedAt;
|
|
78
|
+
if (result.errors > 0) {
|
|
79
|
+
failCli(chalk.red(formatLintSummary(result, elapsedMs)));
|
|
30
80
|
}
|
|
81
|
+
if (result.warnings > 0) {
|
|
82
|
+
failCli(chalk.yellow(formatLintSummary(result, elapsedMs)));
|
|
83
|
+
}
|
|
84
|
+
console.log(chalk.green(formatLintSummary(result, elapsedMs)));
|
|
31
85
|
};
|
|
86
|
+
|
|
87
|
+
function formatProblemUri(uri: string): string {
|
|
88
|
+
const text = String(uri ?? '').trim();
|
|
89
|
+
if (!text) {
|
|
90
|
+
return '<unknown>';
|
|
91
|
+
}
|
|
92
|
+
if (!text.startsWith('file://')) {
|
|
93
|
+
return text;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const filePath = fileURLToPath(text);
|
|
97
|
+
return path.relative(process.cwd(), filePath) || '.';
|
|
98
|
+
} catch {
|
|
99
|
+
return text;
|
|
100
|
+
}
|
|
101
|
+
}
|