liwenjson 0.0.0-stage → 1.5.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/index.d.ts ADDED
@@ -0,0 +1,175 @@
1
+ export type Profile =
2
+ | "permissive"
3
+ | "interactive"
4
+ | "execution"
5
+ | "agent"
6
+ | "strict";
7
+
8
+ export type Decision =
9
+ | "safe"
10
+ | "cosmetic_repair"
11
+ | "lossy_repair"
12
+ | "ambiguous"
13
+ | "invalid";
14
+
15
+ export type Exactness = "exact" | "cosmetic" | "lossy";
16
+
17
+ export interface AnalyzeOptions {
18
+ /** Safety profile. Use `agent` or `execution` before executing arguments. */
19
+ profile?: Profile;
20
+ /** The library's declaration language, e.g. `{!query:string,!limit:integer}`. */
21
+ schema?: string;
22
+ /** A JSON Schema subset; takes precedence over `schema`. */
23
+ schemaJson?: object | string;
24
+ }
25
+
26
+ export interface RepairRecord {
27
+ rule: string;
28
+ name: string;
29
+ action: string;
30
+ offset: number;
31
+ line: number;
32
+ column: number;
33
+ severity: "info" | "warning";
34
+ ambiguity: string;
35
+ confidence: string;
36
+ confidence_value: number;
37
+ information_loss: boolean;
38
+ message: string;
39
+ }
40
+
41
+ export type RefusalKind =
42
+ | "none"
43
+ | "syntax"
44
+ | "schema_or_intent"
45
+ | "host_declaration"
46
+ | "provider";
47
+
48
+ export interface PlanError {
49
+ code: string;
50
+ message: string;
51
+ }
52
+
53
+ export interface RetryHint {
54
+ code: string;
55
+ prompt: string;
56
+ }
57
+
58
+ export interface Plan {
59
+ decision: Decision;
60
+ label: string;
61
+ exactness: Exactness;
62
+ ambiguous: boolean;
63
+ information_loss: boolean;
64
+ valid_json: boolean;
65
+ normalized: boolean;
66
+ ambiguity: string;
67
+ execution: "allowed" | "blocked";
68
+ executable: boolean;
69
+ syntax_ready_permille: number;
70
+ schema_total: number;
71
+ schema_satisfied: number;
72
+ schema_missing: string[];
73
+ error: PlanError | null;
74
+ repairs: RepairRecord[];
75
+ repairs_truncated: boolean;
76
+ retry: RetryHint | null;
77
+ /**
78
+ * Why the plan is not executable, or `null` when it is. `kind` is
79
+ * `"syntax"` (the text was not a complete, unambiguous document -- safe to
80
+ * re-emit), `"schema_or_intent"` (the document was complete but conflicts
81
+ * with the declaration -- re-emitting may change the *action*, so the host
82
+ * must not execute the retry automatically), `"host_declaration"` or
83
+ * `"provider"`.
84
+ */
85
+ refusal: { kind: RefusalKind; auto_retry: boolean } | null;
86
+ /**
87
+ * Always `false`. The gate checks JSON and the declared schema; it does not
88
+ * authorise the action.
89
+ */
90
+ business_authorized: boolean;
91
+ text: string;
92
+ value: unknown;
93
+ }
94
+
95
+ export interface RepairOutcome {
96
+ text: string;
97
+ exactness: Exactness;
98
+ ambiguous: boolean;
99
+ repairs: RepairRecord[];
100
+ decision: Decision;
101
+ executable: boolean;
102
+ error: PlanError | null;
103
+ retry: RetryHint | null;
104
+ }
105
+
106
+ /** Repair `input`; with `profile: "agent"` a lossy/ambiguous repair throws. */
107
+ export function repair(input: string, options?: AnalyzeOptions): string;
108
+
109
+ /** Repair and return the decision fields too. */
110
+ export function repairResult(input: string, options?: AnalyzeOptions): RepairOutcome;
111
+
112
+ /** The never-throwing decision call: returns the full plan object. */
113
+ export function analyze(input: string, options?: AnalyzeOptions): Plan;
114
+
115
+ /**
116
+ * The gate, with the profile the MCP tools use (`agent`).
117
+ *
118
+ * Use this rather than `analyze` when the question is "may I execute this?":
119
+ * it is the same call the `liwenjson_gate` MCP tool makes, so the npm package
120
+ * and the MCP server cannot disagree about the same input.
121
+ */
122
+ export function gate(input: string, options?: AnalyzeOptions): Plan;
123
+
124
+ /** One line per repair, or `-`. */
125
+ export function report(input: string): string;
126
+
127
+ /** The partial value of the first `upto` code units, as fields. */
128
+ export interface Snapshot {
129
+ /** The partial value, or `null` when nothing has been parsed yet. */
130
+ value: unknown;
131
+ /** `Empty`, `Partial` or `Complete`. */
132
+ completeness: string;
133
+ /** The path of the container still open, or `""`. */
134
+ openPath: string;
135
+ }
136
+ export function snapshot(input: string, upto: number): Snapshot;
137
+
138
+ /** The engine's own `value | completeness | openPath` string. */
139
+ export function snapshotText(input: string, upto: number): string;
140
+
141
+ /** One frame of the streaming view (a JSON object). */
142
+ export function live(input: string, upto: number, schema?: string): unknown;
143
+
144
+ /** The readiness curve for `input` against a skeleton declaration. */
145
+ export function readiness(input: string, schema?: string): unknown;
146
+
147
+ /** The delta stream for the first `upto` code units. */
148
+ export function deltas(input: string, upto: number): unknown;
149
+
150
+ /**
151
+ * A structured refusal: `code` is the `E` code (`E010`, `E011`, `E070`, …)
152
+ * and `detail` is the message without the code.
153
+ */
154
+ export class LIWENJSONError extends Error {
155
+ code: string;
156
+ detail: string;
157
+ }
158
+
159
+ export const version: string;
160
+
161
+ declare const api: {
162
+ LIWENJSONError: typeof LIWENJSONError;
163
+ repair: typeof repair;
164
+ repairResult: typeof repairResult;
165
+ analyze: typeof analyze;
166
+ gate: typeof gate;
167
+ report: typeof report;
168
+ snapshot: typeof snapshot;
169
+ snapshotText: typeof snapshotText;
170
+ live: typeof live;
171
+ readiness: typeof readiness;
172
+ deltas: typeof deltas;
173
+ version: string;
174
+ };
175
+ export default api;
package/index.mjs ADDED
@@ -0,0 +1,22 @@
1
+ // ESM wrapper around the CommonJS entry point. The engine itself is a
2
+ // side-effect-free script loaded once by `index.cjs`.
3
+
4
+ import { createRequire } from "node:module";
5
+
6
+ const require = createRequire(import.meta.url);
7
+ const api = require("./index.cjs");
8
+
9
+ export const LIWENJSONError = api.LIWENJSONError;
10
+ export const repair = api.repair;
11
+ export const repairResult = api.repairResult;
12
+ export const analyze = api.analyze;
13
+ export const gate = api.gate;
14
+ export const report = api.report;
15
+ export const snapshot = api.snapshot;
16
+ export const snapshotText = api.snapshotText;
17
+ export const live = api.live;
18
+ export const readiness = api.readiness;
19
+ export const deltas = api.deltas;
20
+ export const version = api.version;
21
+
22
+ export default api;
package/mcp.cjs ADDED
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+
4
+ // `liwenjson-mcp` — start the local MCP server from npm.
5
+ //
6
+ // The MCP implementation lives in the native binary (`liwenjson mcp`), not in
7
+ // this package: there is exactly one server, the same one the release assets
8
+ // and the pip package start. This launcher only finds that binary and hands it
9
+ // this process's stdin/stdout, so the JSON-RPC channel stays clean (no Node
10
+ // process in the middle, no banner on stdout).
11
+ //
12
+ // Resolution order, mirroring the Python client:
13
+ // 1. `LIWENJSON_BIN`
14
+ // 2. `liwenjson` on PATH
15
+ // 3. the development build inside this repository
16
+ //
17
+ // A binary that is not found is a startup error on stderr with the install
18
+ // command, never a half-working server.
19
+
20
+ const { spawn } = require("node:child_process");
21
+ const { existsSync } = require("node:fs");
22
+ const { dirname, join } = require("node:path");
23
+ const { fileURLToPath } = require("node:url");
24
+
25
+ function findBinary() {
26
+ const env = process.env.LIWENJSON_BIN;
27
+ if (env) return env;
28
+
29
+ const pathParts = (process.env.PATH || "").split(require("node:path").delimiter);
30
+ const names = process.platform === "win32" ? ["liwenjson.exe", "liwenjson"] : ["liwenjson"];
31
+ for (const dir of pathParts) {
32
+ if (!dir) continue;
33
+ for (const name of names) {
34
+ const candidate = join(dir, name);
35
+ if (existsSync(candidate)) return candidate;
36
+ }
37
+ }
38
+
39
+ // Development checkout: code/npm/mcp.cjs -> code/
40
+ const codeDir = join(__dirname, "..");
41
+ for (const name of ["liwenjson.exe", "liwenjson"]) {
42
+ const candidate = join(
43
+ codeDir,
44
+ "_build",
45
+ "native",
46
+ "release",
47
+ "build",
48
+ "cmd",
49
+ "liwenjson",
50
+ name,
51
+ );
52
+ if (existsSync(candidate)) return candidate;
53
+ }
54
+ return null;
55
+ }
56
+
57
+ function main() {
58
+ const binary = findBinary();
59
+ if (!binary) {
60
+ process.stderr.write(
61
+ [
62
+ "liwenjson-mcp: the LIWENJSON engine was not found.",
63
+ "",
64
+ "Install it in one of these ways:",
65
+ " - download a release binary and put `liwenjson` on PATH",
66
+ " - set LIWENJSON_BIN=/absolute/path/to/liwenjson",
67
+ " - build it: cd code && moon build cmd/liwenjson --target native --release",
68
+ "",
69
+ ].join("\n"),
70
+ );
71
+ process.exit(127);
72
+ }
73
+
74
+ const child = spawn(binary, ["mcp", ...process.argv.slice(2)], {
75
+ stdio: "inherit",
76
+ windowsHide: true,
77
+ });
78
+ child.on("error", (err) => {
79
+ process.stderr.write(`liwenjson-mcp: failed to start ${binary}: ${err.message}\n`);
80
+ process.exit(127);
81
+ });
82
+ child.on("exit", (code, signal) => {
83
+ if (signal) process.kill(process.pid, signal);
84
+ process.exit(code === null ? 1 : code);
85
+ });
86
+ }
87
+
88
+ main();
package/package.json CHANGED
@@ -1,6 +1,62 @@
1
1
  {
2
2
  "name": "liwenjson",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.5.2",
4
+ "description": "The local execution gate for LLM output, as a Model Context Protocol server and a library, powered by the MoonBit engine.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "LIWENJSON contributors"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/wenhuang2333/LIWENJSON.git",
12
+ "directory": "code/npm"
13
+ },
14
+ "homepage": "https://github.com/wenhuang2333/LIWENJSON#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/wenhuang2333/LIWENJSON/issues"
17
+ },
18
+ "type": "commonjs",
19
+ "main": "./index.cjs",
20
+ "module": "./index.mjs",
21
+ "types": "./index.d.ts",
22
+ "exports": {
23
+ ".": {
24
+ "types": "./index.d.ts",
25
+ "import": "./index.mjs",
26
+ "require": "./index.cjs"
27
+ }
28
+ },
29
+ "files": [
30
+ "index.cjs",
31
+ "index.mjs",
32
+ "index.d.ts",
33
+ "mcp.cjs",
34
+ "vendor/liwenjson.js",
35
+ "README.md",
36
+ "LICENSE",
37
+ "NOTICE"
38
+ ],
39
+ "scripts": {
40
+ "build": "bash build.sh",
41
+ "test": "node --test"
42
+ },
43
+ "engines": {
44
+ "node": ">=20"
45
+ },
46
+ "keywords": [
47
+ "json",
48
+ "repair",
49
+ "streaming",
50
+ "llm",
51
+ "tool-call",
52
+ "mcp",
53
+ "execution-gate",
54
+ "moonbit"
55
+ ],
56
+ "bin": {
57
+ "liwenjson-mcp": "mcp.cjs"
58
+ },
59
+ "publishConfig": {
60
+ "registry": "https://registry.npmjs.org/"
61
+ }
62
+ }