@nowline/cli 0.12.0 → 0.13.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/dist/cli/args.d.ts +140 -0
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +57 -52
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/help.d.ts.map +1 -1
- package/dist/cli/help.js +15 -1
- package/dist/cli/help.js.map +1 -1
- package/dist/cli/options.d.ts +7 -3
- package/dist/cli/options.d.ts.map +1 -1
- package/dist/cli/options.js +22 -1
- package/dist/cli/options.js.map +1 -1
- package/dist/commands/mcp.d.ts +4 -3
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +16 -29
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/render.d.ts.map +1 -1
- package/dist/commands/render.js +9 -5
- package/dist/commands/render.js.map +1 -1
- package/dist/core/parse.d.ts.map +1 -1
- package/dist/core/parse.js +2 -6
- package/dist/core/parse.js.map +1 -1
- package/dist/generated/version.d.ts +1 -1
- package/dist/generated/version.js +2 -2
- package/man/fr/nowline.1 +30 -1
- package/man/nowline.1 +28 -0
- package/package.json +14 -14
- package/scripts/compile.mjs +3 -1
- package/src/cli/args.ts +67 -61
- package/src/cli/help.ts +15 -1
- package/src/cli/options.ts +28 -5
- package/src/commands/mcp.ts +17 -38
- package/src/commands/render.ts +11 -7
- package/src/core/parse.ts +2 -5
- package/src/generated/version.ts +2 -2
package/src/commands/mcp.ts
CHANGED
|
@@ -1,54 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
|
|
3
|
-
import { createMcpHttpHandler } from '@nowline/mcp/http';
|
|
4
|
-
import { createMcpServer } from '@nowline/mcp/server';
|
|
1
|
+
import { InvalidPortError, startMcpServer } from '@nowline/mcp/start';
|
|
5
2
|
import type { ParsedArgs } from '../cli/args.js';
|
|
3
|
+
import { CliError, ExitCode } from '../io/exit-codes.js';
|
|
6
4
|
import { createLog } from '../io/log.js';
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* `nowline --mcp` handler.
|
|
10
8
|
*
|
|
11
|
-
* Starts
|
|
12
|
-
*
|
|
9
|
+
* Starts the Model Context Protocol server through the same `startMcpServer`
|
|
10
|
+
* that `npx @nowline/mcp` calls, so `--root` (expansion and the binary-export
|
|
11
|
+
* delivery default), `--port` and the reported version behave identically.
|
|
13
12
|
*
|
|
14
13
|
* Transport selection:
|
|
15
14
|
* stdio (default) — when --port is absent.
|
|
16
|
-
* Streamable HTTP — when --port <N> is supplied; listens on
|
|
15
|
+
* Streamable HTTP — when --port <N> is supplied; listens on 127.0.0.1:<N>.
|
|
17
16
|
*
|
|
18
17
|
* Runs until the process receives SIGINT/SIGTERM or the client closes stdin.
|
|
19
18
|
*/
|
|
20
19
|
export async function mcpHandler({ args }: { args: ParsedArgs }): Promise<void> {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
28
|
-
throw new Error(
|
|
29
|
-
`nowline: --port must be a number between 1 and 65535 (got ${portStr}).`,
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const httpServer = createServer(
|
|
34
|
-
createMcpHttpHandler(() => createMcpServer({ allowedRoot: root })),
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
await new Promise<void>((resolve) => {
|
|
38
|
-
httpServer.listen(port, '127.0.0.1', () => {
|
|
39
|
-
createLog(args.logLevel).notice(
|
|
40
|
-
`nowline: MCP Streamable HTTP listening on http://127.0.0.1:${port}`,
|
|
41
|
-
);
|
|
42
|
-
});
|
|
43
|
-
httpServer.on('close', resolve);
|
|
44
|
-
process.on('SIGINT', () => httpServer.close());
|
|
45
|
-
process.on('SIGTERM', () => httpServer.close());
|
|
46
|
-
});
|
|
47
|
-
} else {
|
|
48
|
-
const transport = new StdioServerTransport();
|
|
49
|
-
await createMcpServer({ allowedRoot: root }).connect(transport);
|
|
50
|
-
await new Promise<void>((resolve) => {
|
|
51
|
-
transport.onclose = resolve;
|
|
20
|
+
try {
|
|
21
|
+
await startMcpServer({
|
|
22
|
+
root: args.root,
|
|
23
|
+
port: args.port,
|
|
24
|
+
onListening: (url) =>
|
|
25
|
+
createLog(args.logLevel).notice(`nowline: MCP Streamable HTTP listening on ${url}`),
|
|
52
26
|
});
|
|
27
|
+
} catch (err) {
|
|
28
|
+
if (err instanceof InvalidPortError) {
|
|
29
|
+
throw new CliError(ExitCode.InputError, `nowline: ${err.message}`);
|
|
30
|
+
}
|
|
31
|
+
throw err;
|
|
53
32
|
}
|
|
54
33
|
}
|
package/src/commands/render.ts
CHANGED
|
@@ -123,18 +123,18 @@ export async function renderHandler(options: RenderHandlerOptions): Promise<void
|
|
|
123
123
|
noLinks: args.noLinks,
|
|
124
124
|
strict: args.strict,
|
|
125
125
|
assetRoot: cliOptions.assetRoot,
|
|
126
|
-
// m2c format-specific options. The PDF settings
|
|
127
|
-
// after validation, for every format.
|
|
126
|
+
// m2c format-specific options. The PDF settings and `--start` are
|
|
127
|
+
// checked in `produce`, after validation, for every format.
|
|
128
128
|
pageSize: cliOptions.surface.pageSize,
|
|
129
129
|
orientation: cliOptions.orientation,
|
|
130
130
|
marginPt: cliOptions.margin,
|
|
131
|
-
|
|
131
|
+
assertExportSettingsValid: () => cliOptions.assertExportSettingsValid(),
|
|
132
132
|
fontSans: cliOptions.fontSans,
|
|
133
133
|
fontMono: cliOptions.fontMono,
|
|
134
134
|
headless: cliOptions.headless,
|
|
135
135
|
useSystemFonts: cliOptions.useSystemFonts,
|
|
136
136
|
scale: args.scale,
|
|
137
|
-
start:
|
|
137
|
+
start: cliOptions.start,
|
|
138
138
|
locale,
|
|
139
139
|
operatorLocale: opLocale,
|
|
140
140
|
resolvedLocale: resolved,
|
|
@@ -219,8 +219,8 @@ interface ProduceArgs {
|
|
|
219
219
|
orientation?: PdfOrientation;
|
|
220
220
|
/** Page margin in points. */
|
|
221
221
|
marginPt?: number;
|
|
222
|
-
/** Reports a bad PDF setting
|
|
223
|
-
|
|
222
|
+
/** Reports a bad PDF setting or `--start`; run after validation so its error follows any diagnostics. */
|
|
223
|
+
assertExportSettingsValid: () => void;
|
|
224
224
|
fontSans?: string;
|
|
225
225
|
fontMono?: string;
|
|
226
226
|
headless: boolean;
|
|
@@ -299,7 +299,7 @@ async function produce(args: ProduceArgs): Promise<ProduceResult> {
|
|
|
299
299
|
fonts = await resolveNodeFonts(args);
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
-
args.
|
|
302
|
+
args.assertExportSettingsValid();
|
|
303
303
|
|
|
304
304
|
const kernelInputs: RenderInputs = {
|
|
305
305
|
...layoutInputs,
|
|
@@ -445,9 +445,13 @@ async function resolveNodeFonts(
|
|
|
445
445
|
async function produceCanonicalNowline(args: ProduceArgs): Promise<string> {
|
|
446
446
|
if (args.inputFormat === 'json') {
|
|
447
447
|
const { ast } = parseNowlineJson(args.contents, args.displayPath);
|
|
448
|
+
args.assertExportSettingsValid();
|
|
448
449
|
return printNowlineFile(ast);
|
|
449
450
|
}
|
|
450
451
|
const parsed = await parseAndValidate(args.contents, args);
|
|
452
|
+
// The format-specific settings don't apply here, but a bad one is the same
|
|
453
|
+
// usage error for every format.
|
|
454
|
+
args.assertExportSettingsValid();
|
|
451
455
|
const doc = serializeToJson(parsed.document, args.contents);
|
|
452
456
|
return printNowlineFile(doc.ast);
|
|
453
457
|
}
|
package/src/core/parse.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
buildTransientDocument,
|
|
2
3
|
collectDocumentDiagnostics,
|
|
3
4
|
createNowlineServices,
|
|
4
5
|
type NowlineFile,
|
|
@@ -41,11 +42,7 @@ export async function parseSource(
|
|
|
41
42
|
filePath: string,
|
|
42
43
|
options: ParseOptions = {},
|
|
43
44
|
): Promise<ParseResult> {
|
|
44
|
-
const
|
|
45
|
-
const uri = uriFor(filePath);
|
|
46
|
-
const docFactory = services.shared.workspace.LangiumDocumentFactory;
|
|
47
|
-
const doc = docFactory.fromString<NowlineFile>(contents, uri);
|
|
48
|
-
await services.shared.workspace.DocumentBuilder.build([doc], {
|
|
45
|
+
const doc = await buildTransientDocument(getServices().shared, contents, uriFor(filePath), {
|
|
49
46
|
validation: options.validate ?? true,
|
|
50
47
|
});
|
|
51
48
|
|
package/src/generated/version.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Auto-generated by scripts/bundle-templates.mjs. Do not edit by hand.
|
|
2
2
|
|
|
3
|
-
export const CLI_VERSION = "0.
|
|
3
|
+
export const CLI_VERSION = "0.13.0";
|
|
4
4
|
|
|
5
5
|
export interface CliBuild {
|
|
6
6
|
/** Short git SHA at build time, or empty when not in a git checkout. */
|
|
@@ -12,7 +12,7 @@ export interface CliBuild {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const CLI_BUILD: CliBuild = {
|
|
15
|
-
"sha": "
|
|
15
|
+
"sha": "348d8c6",
|
|
16
16
|
"isRelease": true,
|
|
17
17
|
"isDirty": false
|
|
18
18
|
};
|