@oml/cli 0.12.0 → 0.14.0
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 +29 -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} +39 -17
- package/out/auth/platform.js.map +1 -0
- package/out/cli.d.ts +6 -0
- package/out/cli.js +214 -59
- 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} +41 -17
- package/src/cli.ts +249 -59
- 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,25 +5,68 @@ 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));
|
|
22
|
+
let debugEnabled = false;
|
|
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
|
+
}
|
|
18
55
|
|
|
19
56
|
export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
57
|
+
assertNoMalformedShortFlags(argv);
|
|
58
|
+
debugEnabled = hasDebugFlag(argv);
|
|
59
|
+
if (debugEnabled) {
|
|
60
|
+
process.env.OML_PLATFORM_DEBUG = '1';
|
|
61
|
+
}
|
|
20
62
|
const packagePath = path.resolve(__dirname, '..', 'package.json');
|
|
21
63
|
const packageContent = await fs.readFile(packagePath, 'utf-8');
|
|
22
64
|
const packageJson = JSON.parse(packageContent) as { version: string };
|
|
23
65
|
const updateCheck = notifyIfCliUpdateAvailable(packageJson.version);
|
|
24
66
|
|
|
25
67
|
const program = new Command();
|
|
26
|
-
program.version(packageJson.version);
|
|
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)');
|
|
27
70
|
const authService = new OmlCliAuthService();
|
|
28
71
|
|
|
29
72
|
program
|
|
@@ -49,12 +92,15 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
49
92
|
|
|
50
93
|
program
|
|
51
94
|
.command('lint')
|
|
52
|
-
.option('-w, --workspace <dir>', 'workspace root used to resolve cross-file references', '.')
|
|
53
95
|
.description('lints OML files and prints any syntax or validation errors')
|
|
54
96
|
.action(async (...args: unknown[]) => {
|
|
55
97
|
const done = trackCommand('oml-lint');
|
|
56
98
|
try {
|
|
57
|
-
|
|
99
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
100
|
+
await lintAction({
|
|
101
|
+
...(args[0] as Record<string, unknown> | undefined ?? {}),
|
|
102
|
+
authToken,
|
|
103
|
+
});
|
|
58
104
|
done();
|
|
59
105
|
} catch (err) {
|
|
60
106
|
done(err);
|
|
@@ -64,23 +110,18 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
64
110
|
|
|
65
111
|
program
|
|
66
112
|
.command('render')
|
|
67
|
-
.
|
|
68
|
-
.requiredOption('-
|
|
69
|
-
.
|
|
70
|
-
.
|
|
71
|
-
.option('-f, --format <ext>', 'RDF format extension for compile/reason output: ttl, trig, nt, nq, or n3', 'ttl')
|
|
72
|
-
.option('-c, --context <model-uri>', 'default model URI/path used for markdown files without contextUri; also enables wikilink template page generation')
|
|
73
|
-
.option('--clean', 'remove output folders before rebuilding')
|
|
74
|
-
.option('--only', 'skip reason/compile/lint and render from the existing owl output folder')
|
|
75
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
76
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
77
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
78
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
79
|
-
.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')
|
|
80
117
|
.action(async (...args: unknown[]) => {
|
|
81
118
|
const done = trackCommand('oml-render');
|
|
82
119
|
try {
|
|
83
|
-
|
|
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]);
|
|
84
125
|
done();
|
|
85
126
|
} catch (err) {
|
|
86
127
|
done(err);
|
|
@@ -89,18 +130,20 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
89
130
|
});
|
|
90
131
|
|
|
91
132
|
program
|
|
92
|
-
.command('
|
|
93
|
-
.option('-
|
|
94
|
-
.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')
|
|
95
135
|
.option('-f, --format <ext>', 'RDF format extension: ttl, trig, nt, nq, or n3', 'ttl')
|
|
96
|
-
.option('--clean', 'remove output folder before
|
|
97
|
-
.option('--only', 'skip lint and compile from the current workspace state')
|
|
136
|
+
.option('--clean', 'remove output folder before export')
|
|
98
137
|
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
99
|
-
.description('
|
|
138
|
+
.description('export OWL files including reasoned entailments')
|
|
100
139
|
.action(async (...args: unknown[]) => {
|
|
101
|
-
const done = trackCommand('oml-
|
|
140
|
+
const done = trackCommand('oml-export');
|
|
102
141
|
try {
|
|
103
|
-
|
|
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]);
|
|
104
147
|
done();
|
|
105
148
|
} catch (err) {
|
|
106
149
|
done(err);
|
|
@@ -110,22 +153,15 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
110
153
|
|
|
111
154
|
program
|
|
112
155
|
.command('reason')
|
|
113
|
-
.option('-
|
|
114
|
-
.option('
|
|
115
|
-
.
|
|
116
|
-
.option('--clean', 'remove output folder before compiling')
|
|
117
|
-
.option('--only', 'skip compile/lint and reason from the existing owl output folder')
|
|
118
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
119
|
-
.option('-c, --check-only', 'only check consistency; skip entailment materialization and file output')
|
|
120
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
121
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
122
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
123
|
-
.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)')
|
|
124
159
|
.action(async (opts) => {
|
|
125
160
|
const done = trackCommand('oml-reason');
|
|
126
161
|
try {
|
|
127
162
|
const { reasonAction } = await import('./commands/reason.js');
|
|
128
|
-
await
|
|
163
|
+
const authToken = await resolveServerRequestToken(authService);
|
|
164
|
+
await reasonAction({ ...(opts as Record<string, unknown>), authToken } as Parameters<typeof reasonAction>[0]);
|
|
129
165
|
done();
|
|
130
166
|
} catch (err) {
|
|
131
167
|
done(err);
|
|
@@ -135,21 +171,16 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
135
171
|
|
|
136
172
|
program
|
|
137
173
|
.command('validate')
|
|
138
|
-
.
|
|
139
|
-
.
|
|
140
|
-
.option('-owl, --owl <dir>', 'folder where compiled RDF and entailment files are written')
|
|
141
|
-
.option('-f, --format <ext>', 'RDF format extension for compile output: ttl, trig, nt, nq, or n3', 'ttl')
|
|
142
|
-
.option('--clean', 'remove output folder before compiling')
|
|
143
|
-
.option('--only', 'skip compile/lint and reason from the existing owl output folder')
|
|
144
|
-
.option('--pretty', 'pretty-print Turtle/TriG output with blank lines between top-level blocks')
|
|
145
|
-
.option('-u, --unique-names-assumption [value]', 'enable or disable the unique names assumption', parseBooleanOption, true)
|
|
146
|
-
.option('-e, --explanations [value]', 'enable or disable inconsistency explanations', parseBooleanOption, true)
|
|
147
|
-
.option('-p, --profile [value]', 'include phase timings in the reasoner result', parseBooleanOption, false)
|
|
148
|
-
.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')
|
|
149
176
|
.action(async (...args: unknown[]) => {
|
|
150
177
|
const done = trackCommand('oml-validate');
|
|
151
178
|
try {
|
|
152
|
-
|
|
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]);
|
|
153
184
|
done();
|
|
154
185
|
} catch (err) {
|
|
155
186
|
done(err);
|
|
@@ -157,10 +188,55 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
157
188
|
}
|
|
158
189
|
});
|
|
159
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
|
+
|
|
160
227
|
program.hook('preAction', async (_thisCommand, actionCommand) => {
|
|
161
|
-
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
|
+
) {
|
|
162
237
|
return;
|
|
163
238
|
}
|
|
239
|
+
await assertServerRunning();
|
|
164
240
|
// Require either GitHub auth or API key, then connect to platform
|
|
165
241
|
if (!process.env.OML_PLATFORM_API_KEY) {
|
|
166
242
|
await authService.ensureAuthenticated('OML CLI');
|
|
@@ -176,15 +252,55 @@ export async function runCli(argv: string[] = process.argv): Promise<void> {
|
|
|
176
252
|
await updateCheck;
|
|
177
253
|
}
|
|
178
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
|
+
|
|
179
285
|
export function reportCliError(error: unknown): number {
|
|
180
286
|
const exitCode = error instanceof CliExitError ? error.exitCode : 1;
|
|
181
|
-
const message =
|
|
287
|
+
const message = debugEnabled
|
|
288
|
+
? formatDetailedError(error)
|
|
289
|
+
: (error instanceof Error ? error.message : String(error));
|
|
182
290
|
if (message) {
|
|
183
291
|
console.error(message);
|
|
184
292
|
}
|
|
185
293
|
return exitCode;
|
|
186
294
|
}
|
|
187
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
|
+
|
|
188
304
|
function parseBooleanOption(value: string | boolean): boolean {
|
|
189
305
|
if (typeof value === 'boolean') {
|
|
190
306
|
return value;
|
|
@@ -199,8 +315,82 @@ function parseBooleanOption(value: string | boolean): boolean {
|
|
|
199
315
|
throw new Error(`Expected a boolean value, received '${value}'.`);
|
|
200
316
|
}
|
|
201
317
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
318
|
+
function hasDebugFlag(argv: string[]): boolean {
|
|
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
|
+
};
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function formatDetailedError(error: unknown): string {
|
|
367
|
+
if (!(error instanceof Error)) {
|
|
368
|
+
return String(error);
|
|
369
|
+
}
|
|
370
|
+
const lines: string[] = [];
|
|
371
|
+
let current: unknown = error;
|
|
372
|
+
let depth = 0;
|
|
373
|
+
while (current instanceof Error && depth < 8) {
|
|
374
|
+
const prefix = depth === 0 ? 'Error' : `Caused by (${depth})`;
|
|
375
|
+
const code = getErrorCode(current);
|
|
376
|
+
lines.push(`${prefix}: ${code ? `[${code}] ` : ''}${current.name}: ${current.message}`);
|
|
377
|
+
if (current.stack) {
|
|
378
|
+
lines.push(current.stack);
|
|
379
|
+
}
|
|
380
|
+
current = getErrorCause(current);
|
|
381
|
+
depth += 1;
|
|
382
|
+
}
|
|
383
|
+
if (current !== undefined && current !== null) {
|
|
384
|
+
lines.push(`Caused by (${depth}): ${String(current)}`);
|
|
385
|
+
}
|
|
386
|
+
return lines.join('\n');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
function getErrorCode(error: Error): string | undefined {
|
|
390
|
+
const code = (error as Error & { code?: unknown }).code;
|
|
391
|
+
return typeof code === 'string' ? code : undefined;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function getErrorCause(error: Error): unknown {
|
|
395
|
+
return (error as Error & { cause?: unknown }).cause;
|
|
396
|
+
}
|
|
@@ -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
|
+
}
|