@wei840222/qmd 2026.8.23
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/CHANGELOG.md +1373 -0
- package/LICENSE +45 -0
- package/README.md +1439 -0
- package/THIRD_PARTY_NOTICES.md +31 -0
- package/bin/qmd +192 -0
- package/dist/ast.d.ts +65 -0
- package/dist/ast.js +334 -0
- package/dist/bench/bench.d.ts +35 -0
- package/dist/bench/bench.js +338 -0
- package/dist/bench/cjk-baseline.d.ts +36 -0
- package/dist/bench/cjk-baseline.js +111 -0
- package/dist/bench/fixture.d.ts +2 -0
- package/dist/bench/fixture.js +84 -0
- package/dist/bench/score.d.ts +38 -0
- package/dist/bench/score.js +107 -0
- package/dist/bench/types.d.ts +110 -0
- package/dist/bench/types.js +8 -0
- package/dist/cli/build-info.json +4 -0
- package/dist/cli/embed-lock.d.ts +24 -0
- package/dist/cli/embed-lock.js +94 -0
- package/dist/cli/embedding-owner.d.ts +10 -0
- package/dist/cli/embedding-owner.js +20 -0
- package/dist/cli/formatter.d.ts +120 -0
- package/dist/cli/formatter.js +355 -0
- package/dist/cli/mcp-pid.d.ts +25 -0
- package/dist/cli/mcp-pid.js +86 -0
- package/dist/cli/qmd.d.ts +72 -0
- package/dist/cli/qmd.js +4806 -0
- package/dist/cli/version.d.ts +42 -0
- package/dist/cli/version.js +80 -0
- package/dist/collections.d.ts +200 -0
- package/dist/collections.js +433 -0
- package/dist/db.d.ts +65 -0
- package/dist/db.js +143 -0
- package/dist/diagnostics.d.ts +62 -0
- package/dist/diagnostics.js +260 -0
- package/dist/embedding/config.d.ts +52 -0
- package/dist/embedding/config.js +229 -0
- package/dist/embedding/identity.d.ts +58 -0
- package/dist/embedding/identity.js +321 -0
- package/dist/embedding/local-identity.d.ts +1 -0
- package/dist/embedding/local-identity.js +15 -0
- package/dist/embedding/local.d.ts +34 -0
- package/dist/embedding/local.js +290 -0
- package/dist/embedding/openai.d.ts +79 -0
- package/dist/embedding/openai.js +477 -0
- package/dist/embedding/owner.d.ts +13 -0
- package/dist/embedding/owner.js +36 -0
- package/dist/embedding/provider.d.ts +68 -0
- package/dist/embedding/provider.js +16 -0
- package/dist/embedding/remote-chunking.d.ts +22 -0
- package/dist/embedding/remote-chunking.js +83 -0
- package/dist/embedding/remote-embedding.d.ts +15 -0
- package/dist/embedding/remote-embedding.js +77 -0
- package/dist/hybrid-llm.d.ts +18 -0
- package/dist/hybrid-llm.js +53 -0
- package/dist/index.d.ts +244 -0
- package/dist/index.js +418 -0
- package/dist/llm.d.ts +566 -0
- package/dist/llm.js +1847 -0
- package/dist/maintenance.d.ts +33 -0
- package/dist/maintenance.js +52 -0
- package/dist/mcp/origin-guard.d.ts +67 -0
- package/dist/mcp/origin-guard.js +137 -0
- package/dist/mcp/server.d.ts +116 -0
- package/dist/mcp/server.js +919 -0
- package/dist/paths.d.ts +1 -0
- package/dist/paths.js +4 -0
- package/dist/remote-llm.d.ts +52 -0
- package/dist/remote-llm.js +464 -0
- package/dist/search/cjk-analyzer.d.ts +33 -0
- package/dist/search/cjk-analyzer.js +158 -0
- package/dist/search/cjk-index.d.ts +104 -0
- package/dist/search/cjk-index.js +1031 -0
- package/dist/search/jieba-loader.d.ts +23 -0
- package/dist/search/jieba-loader.js +79 -0
- package/dist/search/query-expansion.d.ts +23 -0
- package/dist/search/query-expansion.js +43 -0
- package/dist/search/zh-dict.txt +624013 -0
- package/dist/store.d.ts +1218 -0
- package/dist/store.js +6076 -0
- package/dist/trust.d.ts +152 -0
- package/dist/trust.js +249 -0
- package/package.json +139 -0
- package/scripts/build.mjs +83 -0
- package/scripts/check-package-grammars.mjs +29 -0
- package/scripts/package-smoke.mjs +205 -0
- package/scripts/sync-zh-dict.mjs +187 -0
- package/scripts/test-all.mjs +45 -0
- package/skills/qmd/SKILL.md +324 -0
- package/skills/qmd/references/mcp-setup.md +119 -0
- package/skills/release/SKILL.md +141 -0
- package/skills/release/scripts/install-hooks.sh +38 -0
- package/skills/release/scripts/release-context.sh +129 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface JiebaDiagnostic {
|
|
2
|
+
readonly code: "JIEBA_NATIVE_UNAVAILABLE";
|
|
3
|
+
readonly message: "Chinese word segmentation is unavailable for this runtime.";
|
|
4
|
+
readonly runtime: string;
|
|
5
|
+
readonly remediation: "Reinstall @node-rs/jieba with optional dependencies enabled on a supported OS, architecture, and libc.";
|
|
6
|
+
}
|
|
7
|
+
export type JiebaCapability = {
|
|
8
|
+
readonly available: true;
|
|
9
|
+
readonly cut: (text: string, hmm?: boolean) => string[];
|
|
10
|
+
} | {
|
|
11
|
+
readonly available: false;
|
|
12
|
+
readonly diagnostic: JiebaDiagnostic;
|
|
13
|
+
};
|
|
14
|
+
export type JiebaModuleImporter = (specifier: string) => Promise<unknown>;
|
|
15
|
+
export declare function createJiebaUnavailableCapability(): Extract<JiebaCapability, {
|
|
16
|
+
available: false;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function createJiebaLoader(importModule?: JiebaModuleImporter): (userDictionary?: Uint8Array) => Promise<JiebaCapability>;
|
|
19
|
+
export declare const loadJiebaCapability: (userDictionary?: Uint8Array) => Promise<JiebaCapability>;
|
|
20
|
+
/** @internal Override the synchronous mutation analyzer in tests. */
|
|
21
|
+
export declare function setSynchronousJiebaCapabilityForTests(capability?: JiebaCapability): void;
|
|
22
|
+
/** Load the same analyzer and versioned dictionary for synchronous mutation paths. */
|
|
23
|
+
export declare function loadJiebaCapabilitySync(userDictionary?: Uint8Array): JiebaCapability;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
function asRecord(value) {
|
|
4
|
+
return (typeof value === "object" && value !== null) || typeof value === "function"
|
|
5
|
+
? value
|
|
6
|
+
: null;
|
|
7
|
+
}
|
|
8
|
+
export function createJiebaUnavailableCapability() {
|
|
9
|
+
const diagnostic = Object.freeze({
|
|
10
|
+
code: "JIEBA_NATIVE_UNAVAILABLE",
|
|
11
|
+
message: "Chinese word segmentation is unavailable for this runtime.",
|
|
12
|
+
runtime: `${process.platform}-${process.arch}`,
|
|
13
|
+
remediation: "Reinstall @node-rs/jieba with optional dependencies enabled on a supported OS, architecture, and libc.",
|
|
14
|
+
});
|
|
15
|
+
return Object.freeze({
|
|
16
|
+
available: false,
|
|
17
|
+
diagnostic,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
function initializeCapability(packageModule, userDictionary) {
|
|
21
|
+
const packageRecord = asRecord(packageModule);
|
|
22
|
+
const Jieba = (packageRecord?.Jieba ?? null);
|
|
23
|
+
if (!Jieba
|
|
24
|
+
|| typeof Jieba.withDict !== "function") {
|
|
25
|
+
return createJiebaUnavailableCapability();
|
|
26
|
+
}
|
|
27
|
+
const instance = Jieba.withDict(readFileSync(new URL("./zh-dict.txt", import.meta.url)));
|
|
28
|
+
if (!instance
|
|
29
|
+
|| typeof instance.cut !== "function"
|
|
30
|
+
|| typeof instance.loadDict !== "function") {
|
|
31
|
+
return createJiebaUnavailableCapability();
|
|
32
|
+
}
|
|
33
|
+
if (userDictionary && userDictionary.byteLength > 0) {
|
|
34
|
+
instance.loadDict(userDictionary);
|
|
35
|
+
}
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
available: true,
|
|
38
|
+
cut: (text, hmm = false) => instance.cut(text, hmm),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async function loadCapability(importModule, userDictionary) {
|
|
42
|
+
try {
|
|
43
|
+
const packageModule = await importModule("@node-rs/jieba");
|
|
44
|
+
return initializeCapability(packageModule, userDictionary);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return createJiebaUnavailableCapability();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
export function createJiebaLoader(importModule = specifier => import(specifier)) {
|
|
51
|
+
let cached;
|
|
52
|
+
return (userDictionary) => {
|
|
53
|
+
if (userDictionary)
|
|
54
|
+
return loadCapability(importModule, userDictionary);
|
|
55
|
+
cached ??= loadCapability(importModule);
|
|
56
|
+
return cached;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export const loadJiebaCapability = createJiebaLoader();
|
|
60
|
+
const require = createRequire(import.meta.url);
|
|
61
|
+
let synchronousCapability;
|
|
62
|
+
/** @internal Override the synchronous mutation analyzer in tests. */
|
|
63
|
+
export function setSynchronousJiebaCapabilityForTests(capability) {
|
|
64
|
+
synchronousCapability = capability;
|
|
65
|
+
}
|
|
66
|
+
/** Load the same analyzer and versioned dictionary for synchronous mutation paths. */
|
|
67
|
+
export function loadJiebaCapabilitySync(userDictionary) {
|
|
68
|
+
if (synchronousCapability && !userDictionary)
|
|
69
|
+
return synchronousCapability;
|
|
70
|
+
try {
|
|
71
|
+
const cap = initializeCapability(require("@node-rs/jieba"), userDictionary);
|
|
72
|
+
if (!userDictionary)
|
|
73
|
+
synchronousCapability = cap;
|
|
74
|
+
return cap;
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return createJiebaUnavailableCapability();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export type ExpansionMode = "auto" | "force" | "skip";
|
|
2
|
+
export type ExpansionAction = "expand" | "skip";
|
|
3
|
+
export type ExpansionReason = "cjk-default" | "strong-signal" | "explicit-skip" | "explicit-force" | "auto-expand";
|
|
4
|
+
export type ExpansionDirective = {
|
|
5
|
+
directive: "force" | "skip" | null;
|
|
6
|
+
query: string;
|
|
7
|
+
};
|
|
8
|
+
export type ExpansionDecision = {
|
|
9
|
+
action: ExpansionAction;
|
|
10
|
+
reason: ExpansionReason;
|
|
11
|
+
query: string;
|
|
12
|
+
};
|
|
13
|
+
export declare class ExpansionPolicyError extends Error {
|
|
14
|
+
readonly reason: "conflicting-directives";
|
|
15
|
+
constructor(reason: "conflicting-directives", message: string);
|
|
16
|
+
}
|
|
17
|
+
export declare function parseExpansionDirective(input: string): ExpansionDirective;
|
|
18
|
+
export declare function resolveExpansionPolicy(options: {
|
|
19
|
+
query: string;
|
|
20
|
+
mode: ExpansionMode;
|
|
21
|
+
strongSignal: boolean;
|
|
22
|
+
allowCjkExpand?: boolean;
|
|
23
|
+
}): ExpansionDecision;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { containsCjk } from "./cjk-analyzer.js";
|
|
2
|
+
export class ExpansionPolicyError extends Error {
|
|
3
|
+
reason;
|
|
4
|
+
constructor(reason, message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = "ExpansionPolicyError";
|
|
7
|
+
this.reason = reason;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export function parseExpansionDirective(input) {
|
|
11
|
+
const trimmed = input.trim();
|
|
12
|
+
const match = /^(lex|expand)\s*:\s*(.*)$/isu.exec(trimmed);
|
|
13
|
+
if (!match)
|
|
14
|
+
return { directive: null, query: trimmed };
|
|
15
|
+
const query = (match[2] ?? "").trim();
|
|
16
|
+
if (!query)
|
|
17
|
+
throw new Error(`${match[1]?.toLowerCase()}: requires a non-empty query`);
|
|
18
|
+
return {
|
|
19
|
+
directive: match[1]?.toLowerCase() === "lex" ? "skip" : "force",
|
|
20
|
+
query,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export function resolveExpansionPolicy(options) {
|
|
24
|
+
const parsed = parseExpansionDirective(options.query);
|
|
25
|
+
if (!parsed.query)
|
|
26
|
+
throw new Error("query must not be empty");
|
|
27
|
+
if (options.mode === "force" && parsed.directive === "skip") {
|
|
28
|
+
throw new ExpansionPolicyError("conflicting-directives", "conflicting expansion directives: force cannot be combined with lex:");
|
|
29
|
+
}
|
|
30
|
+
if (options.mode === "skip" || parsed.directive === "skip") {
|
|
31
|
+
return { action: "skip", reason: "explicit-skip", query: parsed.query };
|
|
32
|
+
}
|
|
33
|
+
if (options.mode === "force" || parsed.directive === "force") {
|
|
34
|
+
return { action: "expand", reason: "explicit-force", query: parsed.query };
|
|
35
|
+
}
|
|
36
|
+
if (containsCjk(parsed.query) && !options.allowCjkExpand) {
|
|
37
|
+
return { action: "skip", reason: "cjk-default", query: parsed.query };
|
|
38
|
+
}
|
|
39
|
+
if (options.strongSignal) {
|
|
40
|
+
return { action: "skip", reason: "strong-signal", query: parsed.query };
|
|
41
|
+
}
|
|
42
|
+
return { action: "expand", reason: "auto-expand", query: parsed.query };
|
|
43
|
+
}
|