@morehao/dsh-github-trending 0.0.1 → 0.1.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.
@@ -0,0 +1,117 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/core/exec.ts
8
+ var exec_exports = {};
9
+ __export(exec_exports, {
10
+ execCapture: () => execCapture,
11
+ sanitizedEnv: () => sanitizedEnv
12
+ });
13
+ import { spawn } from "child_process";
14
+ var ENV_KEYS = [
15
+ "PATH",
16
+ "HOME",
17
+ "USER",
18
+ "LOGNAME",
19
+ "SHELL",
20
+ "TMPDIR",
21
+ "TMP",
22
+ "TEMP",
23
+ "LANG",
24
+ "LC_ALL",
25
+ "LC_CTYPE",
26
+ "SSL_CERT_FILE",
27
+ "SSL_CERT_DIR",
28
+ "GIT_AUTHOR_NAME",
29
+ "GIT_AUTHOR_EMAIL",
30
+ "GIT_COMMITTER_NAME",
31
+ "GIT_COMMITTER_EMAIL",
32
+ "GIT_CONFIG_GLOBAL",
33
+ "GIT_SSH_COMMAND"
34
+ ];
35
+ var PROXY_KEYS = [
36
+ "HTTP_PROXY",
37
+ "HTTPS_PROXY",
38
+ "NO_PROXY",
39
+ "ALL_PROXY",
40
+ "http_proxy",
41
+ "https_proxy",
42
+ "no_proxy",
43
+ "all_proxy"
44
+ ];
45
+ function sanitizedEnv(source = process.env, extra = {}) {
46
+ const env = {};
47
+ for (const key of [...ENV_KEYS, ...PROXY_KEYS]) {
48
+ const value = source[key];
49
+ if (typeof value === "string" && value !== "") env[key] = value;
50
+ }
51
+ for (const [key, value] of Object.entries(extra)) {
52
+ if (typeof value === "string" && value !== "") env[key] = value;
53
+ }
54
+ return env;
55
+ }
56
+ function killTree(child, signal) {
57
+ try {
58
+ child.kill(signal);
59
+ } catch {
60
+ }
61
+ }
62
+ async function execCapture(file, args, options = {}) {
63
+ const started = Date.now();
64
+ const timeoutMs = options.timeoutMs ?? 1e4;
65
+ const maxStdout = options.maxStdout ?? 1024 * 1024;
66
+ const maxStderr = options.maxStderr ?? 1024 * 1024;
67
+ const child = spawn(file, args, {
68
+ cwd: options.cwd,
69
+ env: options.env ?? process.env,
70
+ stdio: ["ignore", "pipe", "pipe"],
71
+ windowsHide: true
72
+ });
73
+ let stdout = "";
74
+ let stderr = "";
75
+ let timedOut = false;
76
+ let aborted = false;
77
+ const hardKill = setTimeout(() => killTree(child, "SIGKILL"), timeoutMs + 3e3);
78
+ const timer = setTimeout(() => {
79
+ timedOut = true;
80
+ killTree(child, "SIGTERM");
81
+ }, timeoutMs);
82
+ const onAbort = () => {
83
+ aborted = true;
84
+ killTree(child, "SIGTERM");
85
+ };
86
+ options.signal?.addEventListener("abort", onAbort, { once: true });
87
+ child.stdout?.setEncoding("utf8");
88
+ child.stdout?.on("data", (chunk) => {
89
+ if (stdout.length < maxStdout) stdout += chunk;
90
+ });
91
+ child.stderr?.setEncoding("utf8");
92
+ child.stderr?.on("data", (chunk) => {
93
+ if (stderr.length < maxStderr) stderr += chunk;
94
+ });
95
+ const result = await new Promise((resolve, reject) => {
96
+ child.on("error", (error) => reject(error));
97
+ child.on("close", (code, signal) => resolve({ code, signal }));
98
+ });
99
+ clearTimeout(timer);
100
+ clearTimeout(hardKill);
101
+ options.signal?.removeEventListener("abort", onAbort);
102
+ return {
103
+ ...result,
104
+ stdout,
105
+ stderr,
106
+ timedOut,
107
+ aborted,
108
+ durationMs: Date.now() - started
109
+ };
110
+ }
111
+
112
+ export {
113
+ __export,
114
+ sanitizedEnv,
115
+ execCapture,
116
+ exec_exports
117
+ };
@@ -0,0 +1,8 @@
1
+ import {
2
+ execCapture,
3
+ sanitizedEnv
4
+ } from "./chunk-XLIFTAVL.js";
5
+ export {
6
+ execCapture,
7
+ sanitizedEnv
8
+ };
package/lib/index.d.ts CHANGED
@@ -1,23 +1,34 @@
1
- /**
2
- * dsh-github-trending — 插件入口(脚手架)
3
- *
4
- * 当前只做最小装配,验证包结构可被宿主加载。
5
- * 业务模块(fetcher / parser / summarizer / renderer / git / pr)按设计文档分阶段接入。
6
- */
7
1
  declare const name = "dsh-github-trending";
2
+ /** 唯一硬依赖:没有 HTTP 载体就没有设置页与运行页。 */
3
+ declare const inject: string[];
8
4
  interface PluginLogger {
9
5
  info?: (message: string) => void;
10
6
  warn?: (message: string) => void;
7
+ error?: (message: string) => void;
8
+ debug?: (message: string) => void;
11
9
  }
12
10
  interface PluginContext {
11
+ get?: (name: string) => unknown;
12
+ effect?: (factory: () => unknown, label?: string) => unknown;
13
13
  logger?: PluginLogger;
14
+ webServer?: {
15
+ register: (options: {
16
+ kind: 'prefix';
17
+ path: string;
18
+ handler: unknown;
19
+ }) => unknown;
20
+ };
21
+ [key: string]: unknown;
14
22
  }
15
- declare const inject: string[];
16
- declare function apply(ctx: PluginContext): void;
23
+ declare const VERSION: string;
24
+ declare function apply(ctx: PluginContext, config?: {
25
+ stateDir?: string;
26
+ corePath?: string;
27
+ }): void;
17
28
  declare const _default: {
18
29
  name: string;
19
30
  inject: string[];
20
31
  apply: typeof apply;
21
32
  };
22
33
 
23
- export { type PluginContext, type PluginLogger, apply, _default as default, inject, name };
34
+ export { type PluginContext, type PluginLogger, VERSION, apply, _default as default, inject, name };
package/lib/index.js CHANGED
@@ -1,14 +1,92 @@
1
+ import {
2
+ ROUTE_PREFIX,
3
+ Runner,
4
+ Scheduler,
5
+ Store,
6
+ createRoutes,
7
+ createTrendingHistoryTool,
8
+ createTrendingRunTool
9
+ } from "./chunk-CWB5L7RW.js";
10
+ import "./chunk-XLIFTAVL.js";
11
+
1
12
  // src/index.ts
13
+ import { createRequire } from "module";
2
14
  var name = "dsh-github-trending";
3
- var inject = [];
4
- function apply(ctx) {
5
- ctx.logger?.info?.("[dsh-github-trending] loaded (scaffold)");
15
+ var inject = ["webServer"];
16
+ function readVersion() {
17
+ try {
18
+ const require2 = createRequire(import.meta.url);
19
+ const pkg = require2("../package.json");
20
+ return typeof pkg.version === "string" ? pkg.version : "0.0.0";
21
+ } catch {
22
+ return "0.0.0";
23
+ }
24
+ }
25
+ var VERSION = readVersion();
26
+ function apply(ctx, config = {}) {
27
+ const env = process.env;
28
+ const get = (key) => typeof ctx.get === "function" ? ctx.get(key) : void 0;
29
+ const log = (event, data) => {
30
+ const suffix = data === void 0 ? "" : ` ${JSON.stringify(data)}`;
31
+ ctx.logger?.info?.(`[dsh-github-trending] ${event}${suffix}`);
32
+ };
33
+ const store = new Store({ env, ...config.stateDir === void 0 ? {} : { dir: config.stateDir } });
34
+ if (config.corePath !== void 0 && config.corePath !== "") {
35
+ const settings = store.readSettings();
36
+ if (settings.corePath === "") store.writeSettings({ ...settings, corePath: config.corePath });
37
+ }
38
+ const runner = new Runner({
39
+ store,
40
+ get,
41
+ env,
42
+ onFinished: (summary) => log("run.finished", { id: summary.id, ok: summary.ok, skipped: summary.skipped, files: summary.files })
43
+ });
44
+ const scheduler = new Scheduler({
45
+ store,
46
+ isRunning: () => runner.running !== void 0,
47
+ getTimer: () => get("timer"),
48
+ run: async () => {
49
+ const summary = await runner.run({ trigger: "schedule" });
50
+ log("schedule.run", { ok: summary.ok, skipped: summary.skipped, error: summary.error?.code });
51
+ },
52
+ onError: (error) => ctx.logger?.warn?.(`[dsh-github-trending] \u5B9A\u65F6\u8FD0\u884C\u5931\u8D25\uFF1A${error instanceof Error ? error.message : String(error)}`)
53
+ });
54
+ const handler = createRoutes({ store, runner, scheduler, get, env, version: VERSION, logger: log });
55
+ const register = () => {
56
+ const webServer = ctx.webServer ?? get("webServer");
57
+ if (webServer === void 0 || typeof webServer.register !== "function") {
58
+ throw new Error("webServer \u670D\u52A1\u4E0D\u53EF\u7528\uFF1A\u63D2\u4EF6\u9700\u8981\u5B83\u63D0\u4F9B\u8BBE\u7F6E\u9875\u4E0E\u8FD0\u884C\u9875");
59
+ }
60
+ return webServer.register({ kind: "prefix", path: ROUTE_PREFIX, handler });
61
+ };
62
+ if (typeof ctx.effect === "function") ctx.effect(register, "dsh-github-trending:routes");
63
+ else register();
64
+ scheduler.start();
65
+ if (typeof ctx.effect === "function") {
66
+ ctx.effect(() => () => scheduler.stop(), "dsh-github-trending:scheduler");
67
+ }
68
+ void (async () => {
69
+ const tools = get("tools");
70
+ if (tools === void 0 || typeof tools.register !== "function") return;
71
+ try {
72
+ const mod = await import("@deepseek-ai/dsh-tools");
73
+ if (typeof mod.defineTool !== "function") return;
74
+ tools.register(mod.defineTool(createTrendingRunTool(runner)));
75
+ tools.register(mod.defineTool(createTrendingHistoryTool(store, scheduler)));
76
+ log("tools.registered", { tools: ["trending_run", "trending_history"] });
77
+ } catch (error) {
78
+ ctx.logger?.warn?.(
79
+ `[dsh-github-trending] \u5DE5\u5177\u6CE8\u518C\u8DF3\u8FC7\uFF1A${error instanceof Error ? error.message : String(error)}`
80
+ );
81
+ }
82
+ })();
83
+ log("plugin.loaded", { version: VERSION, stateDir: store.dir });
6
84
  }
7
85
  var index_default = { name, inject, apply };
8
86
  export {
87
+ VERSION,
9
88
  apply,
10
89
  index_default as default,
11
90
  inject,
12
91
  name
13
92
  };
14
- //# sourceMappingURL=index.js.map