@zenalexa/unicli 0.210.0 → 0.211.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/AGENTS.md +21 -7
- package/README.md +680 -83
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +5 -0
- package/dist/cli.js.map +1 -1
- package/dist/commands/agents.d.ts +14 -3
- package/dist/commands/agents.d.ts.map +1 -1
- package/dist/commands/agents.js +369 -140
- package/dist/commands/agents.js.map +1 -1
- package/dist/commands/mcp.d.ts +3 -4
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +47 -62
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/schema.d.ts +12 -0
- package/dist/commands/schema.d.ts.map +1 -0
- package/dist/commands/schema.js +72 -0
- package/dist/commands/schema.js.map +1 -0
- package/dist/commands/search.d.ts +12 -0
- package/dist/commands/search.d.ts.map +1 -0
- package/dist/commands/search.js +47 -0
- package/dist/commands/search.js.map +1 -0
- package/dist/discovery/aliases.d.ts +31 -0
- package/dist/discovery/aliases.d.ts.map +1 -0
- package/dist/discovery/aliases.js +477 -0
- package/dist/discovery/aliases.js.map +1 -0
- package/dist/discovery/loader.d.ts.map +1 -1
- package/dist/discovery/loader.js +25 -0
- package/dist/discovery/loader.js.map +1 -1
- package/dist/discovery/search.d.ts +73 -0
- package/dist/discovery/search.d.ts.map +1 -0
- package/dist/discovery/search.js +355 -0
- package/dist/discovery/search.js.map +1 -0
- package/dist/manifest-compact.txt +15 -0
- package/dist/manifest-search.json +1 -0
- package/dist/manifest.json +433 -244
- package/dist/mcp/oauth.d.ts +33 -0
- package/dist/mcp/oauth.d.ts.map +1 -0
- package/dist/mcp/oauth.js +220 -0
- package/dist/mcp/oauth.js.map +1 -0
- package/dist/mcp/schema.d.ts +65 -0
- package/dist/mcp/schema.d.ts.map +1 -0
- package/dist/mcp/schema.js +136 -0
- package/dist/mcp/schema.js.map +1 -0
- package/dist/mcp/server.d.ts +23 -10
- package/dist/mcp/server.d.ts.map +1 -1
- package/dist/mcp/server.js +350 -182
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/sse-transport.d.ts +34 -0
- package/dist/mcp/sse-transport.d.ts.map +1 -0
- package/dist/mcp/sse-transport.js +182 -0
- package/dist/mcp/sse-transport.js.map +1 -0
- package/dist/mcp/streamable-http.d.ts +64 -0
- package/dist/mcp/streamable-http.d.ts.map +1 -0
- package/dist/mcp/streamable-http.js +312 -0
- package/dist/mcp/streamable-http.js.map +1 -0
- package/dist/permissions/sensitive-paths.js +2 -2
- package/dist/permissions/sensitive-paths.js.map +1 -1
- package/package.json +7 -7
- package/src/adapters/1688/_site.json +9 -0
- package/src/adapters/barchart/_site.json +10 -0
- package/src/adapters/jd/_site.json +9 -0
- package/src/adapters/linkedin/_site.json +10 -0
- package/src/adapters/macos/finder-copy.yaml +40 -0
- package/src/adapters/macos/finder-move.yaml +40 -0
- package/src/adapters/macos/finder-new-folder.yaml +36 -0
- package/src/adapters/macos/safari-history.yaml +23 -0
- package/src/adapters/macos/safari-url.yaml +22 -0
- package/src/adapters/macos/screen-recording.yaml +32 -0
- package/src/adapters/macos/wallpaper.yaml +33 -0
- package/src/adapters/reuters/_site.json +9 -0
- package/src/adapters/sinablog/_site.json +9 -0
- package/src/adapters/smzdm/_site.json +9 -0
- package/src/adapters/weixin/_site.json +9 -0
- package/src/adapters/1688/manifest.yaml +0 -7
- package/src/adapters/barchart/manifest.yaml +0 -8
- package/src/adapters/jd/manifest.yaml +0 -7
- package/src/adapters/linkedin/manifest.yaml +0 -8
- package/src/adapters/reuters/manifest.yaml +0 -7
- package/src/adapters/sinablog/manifest.yaml +0 -7
- package/src/adapters/smzdm/manifest.yaml +0 -7
- package/src/adapters/weixin/manifest.yaml +0 -7
package/dist/commands/mcp.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP gateway CLI — wrapper around src/mcp/server.ts.
|
|
3
3
|
*
|
|
4
|
-
* unicli mcp serve [--transport stdio|http] [--port 19826] [--
|
|
5
|
-
* unicli mcp health #
|
|
4
|
+
* unicli mcp serve [--transport stdio|http] [--port 19826] [--expanded]
|
|
5
|
+
* unicli mcp health # pre-flight check (no server)
|
|
6
6
|
*
|
|
7
7
|
* `serve` shells out to the same `src/mcp/server.ts` entry point as
|
|
8
8
|
* `npm run mcp` so the two paths share exactly one implementation.
|
|
9
9
|
*
|
|
10
10
|
* `health` is intentionally fast and offline: it loads adapters into the
|
|
11
|
-
* registry and prints
|
|
12
|
-
* binding stdio or HTTP. Useful as a Claude Desktop / Cursor pre-flight.
|
|
11
|
+
* registry and prints a structured health report. Exit 0 if healthy, 1 if not.
|
|
13
12
|
*/
|
|
14
13
|
import chalk from "chalk";
|
|
15
14
|
import { spawn } from "node:child_process";
|
|
@@ -26,14 +25,8 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
26
25
|
* stable relative position from this commands file.
|
|
27
26
|
*/
|
|
28
27
|
function resolveServerEntry() {
|
|
29
|
-
// After build: __dirname is dist/commands → ../mcp/server.js
|
|
30
|
-
// In dev (tsx): __dirname is src/commands → ../mcp/server.ts
|
|
31
28
|
const candidateJs = join(__dirname, "..", "mcp", "server.js");
|
|
32
29
|
const candidateTs = join(__dirname, "..", "mcp", "server.ts");
|
|
33
|
-
// Prefer TS if it exists (dev mode); otherwise JS.
|
|
34
|
-
// We can't easily statSync here without importing fs, but join + spawn will
|
|
35
|
-
// surface the error if neither exists. Use TS by default in dev.
|
|
36
|
-
// The simpler heuristic: if __dirname contains "/dist/", we're built.
|
|
37
30
|
if (__dirname.includes("/dist/")) {
|
|
38
31
|
return { kind: "js", path: candidateJs };
|
|
39
32
|
}
|
|
@@ -48,16 +41,12 @@ export function registerMcpCommand(program) {
|
|
|
48
41
|
.description("Start the MCP server (stdio default, --transport http for HTTP/JSON-RPC)")
|
|
49
42
|
.option("--transport <kind>", "stdio or http", "stdio")
|
|
50
43
|
.option("--port <n>", "Port for http transport", "19826")
|
|
51
|
-
.option("--
|
|
44
|
+
.option("--expanded", "Register one tool per adapter command (full catalog)")
|
|
52
45
|
.action((opts) => {
|
|
53
46
|
const entry = resolveServerEntry();
|
|
54
|
-
const args = [];
|
|
55
|
-
if (
|
|
56
|
-
args.
|
|
57
|
-
else
|
|
58
|
-
args.unshift(entry.path);
|
|
59
|
-
if (opts.lazy)
|
|
60
|
-
args.push("--lazy");
|
|
47
|
+
const args = [entry.path];
|
|
48
|
+
if (opts.expanded)
|
|
49
|
+
args.push("--expanded");
|
|
61
50
|
if (opts.transport) {
|
|
62
51
|
args.push("--transport", opts.transport);
|
|
63
52
|
}
|
|
@@ -81,55 +70,51 @@ export function registerMcpCommand(program) {
|
|
|
81
70
|
});
|
|
82
71
|
mcp
|
|
83
72
|
.command("health")
|
|
84
|
-
.description("Pre-flight check —
|
|
85
|
-
.option("--json", "Output as JSON")
|
|
73
|
+
.description("Pre-flight check — verify adapters load and report tool counts")
|
|
74
|
+
.option("--json", "Output as JSON (default when piped)")
|
|
86
75
|
.action(async (opts) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
for (const adapter of adapters) {
|
|
99
|
-
for (const [cmdName, cmd] of Object.entries(adapter.commands)) {
|
|
100
|
-
const toolName = `unicli_${adapter.name}_${cmdName}`.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
101
|
-
tools.push({
|
|
102
|
-
name: toolName,
|
|
103
|
-
description: cmd.description?.trim() ||
|
|
104
|
-
adapter.description?.trim() ||
|
|
105
|
-
`${cmdName} for ${adapter.name}`,
|
|
106
|
-
});
|
|
76
|
+
const useJson = opts.json || !process.stdout.isTTY;
|
|
77
|
+
try {
|
|
78
|
+
// Load adapters into the registry the same way the server does
|
|
79
|
+
loadAllAdapters();
|
|
80
|
+
await loadTsAdapters();
|
|
81
|
+
const adapters = getAllAdapters();
|
|
82
|
+
const commands = listCommands();
|
|
83
|
+
// Count expanded tools (1 per command + 3 default)
|
|
84
|
+
let expandedToolCount = 3; // unicli_run, unicli_list, unicli_discover
|
|
85
|
+
for (const adapter of adapters) {
|
|
86
|
+
expandedToolCount += Object.keys(adapter.commands).length;
|
|
107
87
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
version: VERSION,
|
|
112
|
-
sites: adapters.length,
|
|
88
|
+
const health = {
|
|
89
|
+
status: "ok",
|
|
90
|
+
adapters: adapters.length,
|
|
113
91
|
commands: commands.length,
|
|
114
|
-
tools:
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
console.log(
|
|
92
|
+
tools: { default: 3, expanded: expandedToolCount },
|
|
93
|
+
version: VERSION,
|
|
94
|
+
};
|
|
95
|
+
if (useJson) {
|
|
96
|
+
console.log(JSON.stringify(health, null, 2));
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.log(chalk.bold(`unicli MCP health v${VERSION}`));
|
|
100
|
+
console.log(` status: ${chalk.green("ok")}`);
|
|
101
|
+
console.log(` adapters: ${chalk.green(adapters.length)}`);
|
|
102
|
+
console.log(` commands: ${chalk.green(commands.length)}`);
|
|
103
|
+
console.log(` tools: ${chalk.green("3")} default, ${chalk.green(expandedToolCount)} expanded`);
|
|
104
|
+
console.log();
|
|
105
|
+
console.log(chalk.dim("Default tools: unicli_run, unicli_list, unicli_discover"));
|
|
106
|
+
console.log(chalk.dim("To start: unicli mcp serve [--expanded] [--transport http]"));
|
|
127
107
|
}
|
|
128
|
-
|
|
129
|
-
|
|
108
|
+
catch (err) {
|
|
109
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
110
|
+
if (useJson) {
|
|
111
|
+
console.log(JSON.stringify({ status: "error", error: message, version: VERSION }, null, 2));
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
console.error(chalk.red(`Health check failed: ${message}`));
|
|
115
|
+
}
|
|
116
|
+
process.exit(1);
|
|
130
117
|
}
|
|
131
|
-
console.log();
|
|
132
|
-
console.log(chalk.dim("To start: unicli mcp serve [--transport http]"));
|
|
133
118
|
});
|
|
134
119
|
}
|
|
135
120
|
//# sourceMappingURL=mcp.js.map
|
package/dist/commands/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAY1C,MAAM,SAAS,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAE1D;;;;;GAKG;AACH,SAAS,kBAAkB;IACzB,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC9D,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC;IAC9D,IAAI,SAAS,C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AO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CACZ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,EACrD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;YACJ,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,OAAO,EAAE,CAAC,CAAC,CAAC;YAC9D,CAAC;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema command — output JSON Schema for adapter command input/output.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* unicli schema <site> <command> — Schema for a specific command
|
|
6
|
+
* unicli schema --all — Schema for ALL commands
|
|
7
|
+
*
|
|
8
|
+
* Output is always JSON, suitable for machine consumption.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
export declare function registerSchemaCommand(program: Command): void;
|
|
12
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/commands/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAqCpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAkE5D"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Schema command — output JSON Schema for adapter command input/output.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* unicli schema <site> <command> — Schema for a specific command
|
|
6
|
+
* unicli schema --all — Schema for ALL commands
|
|
7
|
+
*
|
|
8
|
+
* Output is always JSON, suitable for machine consumption.
|
|
9
|
+
*/
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import { getAllAdapters, resolveCommand } from "../registry.js";
|
|
12
|
+
import { ExitCode } from "../types.js";
|
|
13
|
+
import { buildInputSchema, buildOutputSchema, } from "../mcp/schema.js";
|
|
14
|
+
function buildCommandSchema(site, cmdName, cmd) {
|
|
15
|
+
return {
|
|
16
|
+
site,
|
|
17
|
+
command: cmdName,
|
|
18
|
+
description: cmd.description ?? "",
|
|
19
|
+
input: buildInputSchema(cmd),
|
|
20
|
+
output: buildOutputSchema(cmd, "flat"),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
// ── Command registration ─────────────────────────────────────────────────
|
|
24
|
+
export function registerSchemaCommand(program) {
|
|
25
|
+
program
|
|
26
|
+
.command("schema [site] [command]")
|
|
27
|
+
.description("Output JSON Schema for adapter command input/output")
|
|
28
|
+
.option("--all", "output schema for ALL commands")
|
|
29
|
+
.action((site, command, opts) => {
|
|
30
|
+
if (opts.all) {
|
|
31
|
+
// Schema for all commands
|
|
32
|
+
const schemas = [];
|
|
33
|
+
for (const adapter of getAllAdapters()) {
|
|
34
|
+
for (const [cmdName, cmd] of Object.entries(adapter.commands)) {
|
|
35
|
+
schemas.push(buildCommandSchema(adapter.name, cmdName, cmd));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (schemas.length === 0) {
|
|
39
|
+
console.error(chalk.red("No adapters loaded"));
|
|
40
|
+
process.exit(ExitCode.GENERIC_ERROR);
|
|
41
|
+
}
|
|
42
|
+
console.log(JSON.stringify(schemas, null, 2));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (!site || !command) {
|
|
46
|
+
console.error(chalk.red("Usage: unicli schema <site> <command> or unicli schema --all"));
|
|
47
|
+
process.exit(ExitCode.USAGE_ERROR);
|
|
48
|
+
}
|
|
49
|
+
const resolved = resolveCommand(site, command);
|
|
50
|
+
if (!resolved) {
|
|
51
|
+
// Try to suggest similar commands
|
|
52
|
+
const adapters = getAllAdapters();
|
|
53
|
+
const matching = adapters
|
|
54
|
+
.filter((a) => a.name.includes(site))
|
|
55
|
+
.map((a) => ({
|
|
56
|
+
site: a.name,
|
|
57
|
+
commands: Object.keys(a.commands),
|
|
58
|
+
}));
|
|
59
|
+
if (matching.length > 0) {
|
|
60
|
+
console.error(chalk.red(`Unknown command: ${site} ${command}`));
|
|
61
|
+
console.error(chalk.dim(`Available for matching sites: ${JSON.stringify(matching)}`));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
console.error(chalk.red(`Unknown site: ${site}`));
|
|
65
|
+
}
|
|
66
|
+
process.exit(ExitCode.USAGE_ERROR);
|
|
67
|
+
}
|
|
68
|
+
const schema = buildCommandSchema(site, command, resolved.command);
|
|
69
|
+
console.log(JSON.stringify(schema, null, 2));
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../../src/commands/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAEL,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAY1B,SAAS,kBAAkB,CACzB,IAAY,EACZ,OAAe,EACf,GAAmB;IAEnB,OAAO;QACL,IAAI;QACJ,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,EAAE;QAClC,KAAK,EAAE,gBAAgB,CAAC,GAAG,CAAC;QAC5B,MAAM,EAAE,iBAAiB,CAAC,GAA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**
|
|
2
|
+
* Search command — bilingual semantic search across all adapters.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* unicli search "推特热门" → finds twitter/trending
|
|
6
|
+
* unicli search "download video" → finds bilibili/download, youtube/download, ...
|
|
7
|
+
* unicli search "股票行情" → finds xueqiu/stock, eastmoney/stock, ...
|
|
8
|
+
* unicli search --category finance → lists all finance commands
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from "commander";
|
|
11
|
+
export declare function registerSearchCommand(program: Command): void;
|
|
12
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAsD5D"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search command — bilingual semantic search across all adapters.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* unicli search "推特热门" → finds twitter/trending
|
|
6
|
+
* unicli search "download video" → finds bilibili/download, youtube/download, ...
|
|
7
|
+
* unicli search "股票行情" → finds xueqiu/stock, eastmoney/stock, ...
|
|
8
|
+
* unicli search --category finance → lists all finance commands
|
|
9
|
+
*/
|
|
10
|
+
import chalk from "chalk";
|
|
11
|
+
import { search } from "../discovery/search.js";
|
|
12
|
+
import { format, detectFormat } from "../output/formatter.js";
|
|
13
|
+
export function registerSearchCommand(program) {
|
|
14
|
+
program
|
|
15
|
+
.command("search [query...]")
|
|
16
|
+
.description("Search commands by intent (bilingual). Example: unicli search 推特热门")
|
|
17
|
+
.option("-n, --limit <n>", "max results", "8")
|
|
18
|
+
.option("--category <cat>", "filter by category")
|
|
19
|
+
.action((queryParts, opts) => {
|
|
20
|
+
const query = queryParts.join(" ");
|
|
21
|
+
const limit = parseInt(opts.limit, 10) || 8;
|
|
22
|
+
if (!query && !opts.category) {
|
|
23
|
+
console.error(chalk.red("Usage: unicli search <query> or unicli search --category <cat>"));
|
|
24
|
+
process.exitCode = 2;
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const effectiveQuery = opts.category
|
|
28
|
+
? `${opts.category} ${query}`.trim()
|
|
29
|
+
: query;
|
|
30
|
+
const results = search(effectiveQuery, limit);
|
|
31
|
+
if (results.length === 0) {
|
|
32
|
+
console.error(chalk.yellow(`No commands found for: ${effectiveQuery}`));
|
|
33
|
+
process.exitCode = 66; // EX_EMPTY
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const fmt = detectFormat(program.parent?.opts().format);
|
|
37
|
+
const rows = results.map((r) => ({
|
|
38
|
+
command: `${r.site} ${r.command}`,
|
|
39
|
+
description: r.description || `${r.command} for ${r.site}`,
|
|
40
|
+
score: r.score,
|
|
41
|
+
category: r.category,
|
|
42
|
+
usage: r.usage,
|
|
43
|
+
}));
|
|
44
|
+
console.log(format(rows, ["command", "description", "score", "usage"], fmt));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG9D,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO;SACJ,OAAO,CAAC,mBAAmB,CAAC;SAC5B,WAAW,CACV,oEAAoE,CACrE;SACA,MAAM,CAAC,iBAAiB,EAAE,aAAa,EAAE,GAAG,CAAC;SAC7C,MAAM,CAAC,kBAAkB,E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EAAE;YAC1D,KAAK,EAAE,CAAC,CAAC,KAAK;YACd,QAAQ,EAAE,CAAC,CAAC,QAAQ;YACpB,KAAK,EAAE,CAAC,CAAC,KAAK;SACf,CAAC,CAAC,CAAC;QAEJ,OAAO,CAAC,GAAG,CACT,MAAM,CAAC,IAAI,EAAE,CAAC,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,GAAG,CAAC,CAChE,CAAC;IACJ,CAAC,CACF,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bilingual alias table for command discovery.
|
|
3
|
+
*
|
|
4
|
+
* Three alias categories enable Chinese↔English search:
|
|
5
|
+
* 1. Site aliases — 推特→twitter, B站→bilibili
|
|
6
|
+
* 2. Action verbs — 搜索→[search, find], 下载→[download]
|
|
7
|
+
* 3. Domain terms — 股票→[stock, quote, finance]
|
|
8
|
+
*
|
|
9
|
+
* Used by the BM25 search engine to expand queries before scoring.
|
|
10
|
+
* Curated for quality over quantity — ~200 entries covering common
|
|
11
|
+
* agent intents across all supported categories.
|
|
12
|
+
*/
|
|
13
|
+
export declare const SITE_ALIASES: ReadonlyMap<string, string>;
|
|
14
|
+
export declare const ACTION_ALIASES: ReadonlyMap<string, readonly string[]>;
|
|
15
|
+
export declare const DOMAIN_ALIASES: ReadonlyMap<string, readonly string[]>;
|
|
16
|
+
export declare const SITE_CATEGORIES: ReadonlyMap<string, string>;
|
|
17
|
+
export declare const CATEGORY_ALIASES: ReadonlyMap<string, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Expand a single query token using all alias tables.
|
|
20
|
+
* Returns an array of canonical English terms.
|
|
21
|
+
*/
|
|
22
|
+
export declare function expandToken(token: string): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Tokenize a query string, handling both Chinese and English.
|
|
25
|
+
*
|
|
26
|
+
* Strategy: accumulate characters into segments by script type.
|
|
27
|
+
* Chinese chars form contiguous phrases that get sub-phrase expanded.
|
|
28
|
+
* English/Latin chars form words split by whitespace.
|
|
29
|
+
*/
|
|
30
|
+
export declare function tokenizeQuery(query: string): string[];
|
|
31
|
+
//# sourceMappingURL=aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../../src/discovery/aliases.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAKH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAkEnD,CAAC;AAKH,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAqEhE,CAAC;AAKH,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAoFhE,CAAC;AAKH,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAsJtD,CAAC;AAKH,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CA4BvD,CAAC;AAIH;;;GAGG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAkBnD;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CA4DrD"}
|