@morehao/dsh-github-trending 0.7.10 → 0.8.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/lib/internal.d.ts CHANGED
@@ -17,7 +17,7 @@ import { Updater, PluginMeta, Logger } from '@morehao/dsh-plugin-kit/update';
17
17
  */
18
18
 
19
19
  /** 插件在核心之外新增的码。前缀统一避免与核心码冲突。 */
20
- declare const PLUGIN_CODES: readonly ["CORE_UNAVAILABLE", "CORE_INCOMPATIBLE", "CORE_SPAWN_FAILED", "CORE_TIMEOUT", "CORE_CANCELLED", "CORE_CONFIG_CHANNEL_FAILED", "CORE_NOT_DOWNLOADED", "CORE_CHECKSUM_MISMATCH", "IPC_INVALID", "MODEL_KEY_MISSING", "MODEL_NOT_FOUND", "MODEL_PROVIDER_UNSUPPORTED", "GITHUB_AUTH", "PUSH_FAILED", "REPO_DIRTY", "SUBSCRIBE_FAILED"];
20
+ declare const PLUGIN_CODES: readonly ["CORE_UNAVAILABLE", "CORE_INCOMPATIBLE", "CORE_SPAWN_FAILED", "CORE_TIMEOUT", "CORE_CANCELLED", "CORE_CONFIG_CHANNEL_FAILED", "CORE_NOT_DOWNLOADED", "CORE_CHECKSUM_MISMATCH", "IPC_INVALID", "MODEL_KEY_MISSING", "MODEL_NOT_FOUND", "MODEL_PROVIDER_UNSUPPORTED", "GITHUB_AUTH", "GITHUB_AUTH_CANCELLED", "GITHUB_AUTH_EXPIRED", "GITHUB_AUTH_STATE", "GITHUB_AUTH_EXCHANGE", "GITHUB_AUTH_UNAVAILABLE", "PUSH_FAILED", "REPO_DIRTY", "SUBSCRIBE_FAILED"];
21
21
  type PluginCode = (typeof PLUGIN_CODES)[number];
22
22
  type AnyCode = ErrorCode | PluginCode;
23
23
  interface ClassifiedError {
@@ -211,8 +211,11 @@ declare namespace ipc {
211
211
 
212
212
  type Provider = string;
213
213
  type CommitMode = 'branch' | 'direct';
214
- /** 只保留两种真正可用的方式:本机 `gh` 登录态、手动 PAT。历史的 `device` 在归一化时迁移为 `gh`。 */
215
- type AuthMode = 'pat' | 'gh';
214
+ /**
215
+ * 三种可用方式:本机 `gh` 登录态、手动 PAT、浏览器 GitHub 登录(读核心凭据记录)。
216
+ * 历史的 `device` 在归一化时迁移为 `gh`;`browser` 无记录时会降级到 ref/env 兜底。
217
+ */
218
+ type AuthMode = 'pat' | 'gh' | 'browser';
216
219
  /**
217
220
  * 榜单周期(core 0.4.0 的 `--period` 三取值)。
218
221
  * `trending.since` 复用同一枚举:单次运行「抓取窗口 = 标注周期」由核心保证
@@ -1084,16 +1087,27 @@ interface ResolvedSecret {
1084
1087
  value?: string;
1085
1088
  source?: string;
1086
1089
  }
1090
+ interface CredentialRecord {
1091
+ kind: string;
1092
+ payload: unknown;
1093
+ }
1087
1094
  interface CredentialServices {
1088
1095
  describe?: (ref: string) => Promise<CredentialDescription> | CredentialDescription;
1089
1096
  resolve?: (ref: string) => Promise<ResolvedSecret | undefined | null> | ResolvedSecret | undefined | null;
1090
1097
  set?: (ref: string, value: string) => Promise<unknown> | unknown;
1098
+ /**
1099
+ * record 半边(`<scope>/<id>` 键):只读,用于 `authMode=browser` 读 GitHub 登录记录。
1100
+ * 由核心 `dsh-credentials-local` 的同一对象提供(与 ref 半边并存);缺失时 browser 模式退回 ref/env。
1101
+ */
1102
+ readRecord?: (key: string) => Promise<CredentialRecord | undefined> | CredentialRecord | undefined;
1091
1103
  }
1104
+ /** 浏览器登录写入核心凭据记录的键(与核心 `@deepseek-ai/dsh-github-auth` 提案同名同构)。 */
1105
+ declare const GITHUB_RECORD_KEY$1 = "github/default";
1092
1106
  declare function credentialServices(get: (name: string) => unknown): CredentialServices | undefined;
1093
1107
  declare function describeRef(services: CredentialServices | undefined, ref: string, env?: NodeJS.ProcessEnv): Promise<CredentialDescription>;
1094
1108
  declare function resolveRef(services: CredentialServices | undefined, ref: string, env?: NodeJS.ProcessEnv): Promise<ResolvedSecret>;
1095
- /** GitHub token:按 authMode 取,`gh` 模式读本机 gh 的登录态,`pat` 读凭据/环境变量。 */
1096
- declare function resolveGithubToken(services: CredentialServices | undefined, authMode: 'pat' | 'gh', tokenRef: string, deps?: {
1109
+ /** GitHub token:按 authMode 取,`gh` 读本机 gh 登录态,`browser` 读核心凭据记录,`pat` 读 ref/env。 */
1110
+ declare function resolveGithubToken(services: CredentialServices | undefined, authMode: 'pat' | 'gh' | 'browser', tokenRef: string, deps?: {
1097
1111
  env?: NodeJS.ProcessEnv;
1098
1112
  execGh?: () => Promise<string | undefined>;
1099
1113
  freshGh?: boolean;
@@ -1103,6 +1117,7 @@ declare function resolveGithubToken(services: CredentialServices | undefined, au
1103
1117
  }>;
1104
1118
 
1105
1119
  type credentials_CredentialDescription = CredentialDescription;
1120
+ type credentials_CredentialRecord = CredentialRecord;
1106
1121
  type credentials_CredentialServices = CredentialServices;
1107
1122
  type credentials_ResolvedSecret = ResolvedSecret;
1108
1123
  declare const credentials_credentialServices: typeof credentialServices;
@@ -1110,7 +1125,7 @@ declare const credentials_describeRef: typeof describeRef;
1110
1125
  declare const credentials_resolveGithubToken: typeof resolveGithubToken;
1111
1126
  declare const credentials_resolveRef: typeof resolveRef;
1112
1127
  declare namespace credentials {
1113
- export { type credentials_CredentialDescription as CredentialDescription, type credentials_CredentialServices as CredentialServices, type credentials_ResolvedSecret as ResolvedSecret, credentials_credentialServices as credentialServices, credentials_describeRef as describeRef, credentials_resolveGithubToken as resolveGithubToken, credentials_resolveRef as resolveRef };
1128
+ export { type credentials_CredentialDescription as CredentialDescription, type credentials_CredentialRecord as CredentialRecord, type credentials_CredentialServices as CredentialServices, GITHUB_RECORD_KEY$1 as GITHUB_RECORD_KEY, type credentials_ResolvedSecret as ResolvedSecret, credentials_credentialServices as credentialServices, credentials_describeRef as describeRef, credentials_resolveGithubToken as resolveGithubToken, credentials_resolveRef as resolveRef };
1114
1129
  }
1115
1130
 
1116
1131
  /**
@@ -1130,7 +1145,7 @@ interface GithubProbeResult {
1130
1145
  }
1131
1146
  declare function probeGithubAuth(options: {
1132
1147
  credentials: CredentialServices | undefined;
1133
- authMode: 'pat' | 'gh';
1148
+ authMode: 'pat' | 'gh' | 'browser';
1134
1149
  tokenRef: string;
1135
1150
  env?: NodeJS.ProcessEnv;
1136
1151
  fetchImpl?: typeof fetch;
@@ -1142,6 +1157,140 @@ declare namespace github {
1142
1157
  export { type github_GithubProbeResult as GithubProbeResult, github_probeGithubAuth as probeGithubAuth };
1143
1158
  }
1144
1159
 
1160
+ /** 与核心 `@deepseek-ai/dsh-github-auth` 提案保持同 key;迁移时消费端无需改。 */
1161
+ declare const GITHUB_RECORD_KEY = "github/default";
1162
+ /** 本地回调路径(带集成前缀,避免多 provider 撞 webServer 的 `(kind,path)` 唯一约束)。 */
1163
+ declare const CALLBACK_PATH = "/api/morehao/github-trending/oauth/github/callback";
1164
+ /** 本插件运行需要 push / 建 PR,`read:user` 不够;一次授权到 `repo`。 */
1165
+ declare const DEFAULT_SCOPE = "repo";
1166
+ interface AuthorizationFlow {
1167
+ key: string;
1168
+ label: string;
1169
+ methods: Array<{
1170
+ id: string;
1171
+ label: string;
1172
+ }>;
1173
+ run: (session: AuthorizationSessionLike) => Promise<void> | void;
1174
+ }
1175
+ interface AuthorizationSessionLike {
1176
+ method?: string;
1177
+ signal?: AbortSignal;
1178
+ notify?: (notice: {
1179
+ message: string;
1180
+ url?: string;
1181
+ code?: string;
1182
+ }) => void;
1183
+ prompt?: (prompt: unknown) => Promise<unknown>;
1184
+ commit?: (record: {
1185
+ kind: 'grant';
1186
+ payload: unknown;
1187
+ }) => Promise<unknown>;
1188
+ }
1189
+ interface AuthorizationLike {
1190
+ registerFlow?: (flow: AuthorizationFlow) => unknown;
1191
+ begin?: (request: unknown) => Promise<{
1192
+ status: 'authorized' | 'cancelled';
1193
+ }>;
1194
+ cancel?: (key: string) => void;
1195
+ }
1196
+ interface WebServerLike {
1197
+ register?: (route: {
1198
+ kind: 'exact';
1199
+ path: string;
1200
+ handler: (req: any, res: any) => void;
1201
+ }) => () => void;
1202
+ port?: number;
1203
+ host?: string;
1204
+ }
1205
+ type FetchLike = typeof fetch;
1206
+ interface GithubAuthDeps {
1207
+ get: (name: string) => unknown;
1208
+ fetchImpl?: FetchLike;
1209
+ logger?: (event: string, data?: Record<string, unknown>) => void;
1210
+ /** 覆盖端点(测试用);生产留空走 GitHub 官方。 */
1211
+ endpoints?: {
1212
+ authorize?: string;
1213
+ accessToken?: string;
1214
+ deviceCode?: string;
1215
+ user?: string;
1216
+ };
1217
+ /** GitHub OAuth App 的 public client_id(无需 secret)。 */
1218
+ clientId?: string;
1219
+ scope?: string;
1220
+ attemptTimeoutMs?: number;
1221
+ }
1222
+ type GithubAttemptPhase = 'idle' | 'waiting-browser' | 'waiting-device' | 'exchanging' | 'done' | 'error';
1223
+ interface GithubAttemptView {
1224
+ phase: GithubAttemptPhase;
1225
+ authorizeUrl?: string;
1226
+ verificationUri?: string;
1227
+ userCode?: string;
1228
+ expiresAt?: number;
1229
+ login?: string;
1230
+ error?: string;
1231
+ }
1232
+ declare function attemptView(): GithubAttemptView;
1233
+ /** PKCE:返回 verifier 与 S256 challenge。 */
1234
+ declare function createPkce(): {
1235
+ verifier: string;
1236
+ challenge: string;
1237
+ };
1238
+ /** 常量时间比较 state(长度不等直接 false,避免 timingSafeEqual 抛错)。 */
1239
+ declare function verifyState(received: string, expected: string): boolean;
1240
+ /** 拼授权页 URL。 */
1241
+ declare function buildAuthorizeUrl(params: {
1242
+ authorizeEndpoint: string;
1243
+ clientId: string;
1244
+ redirectUri: string;
1245
+ scope: string;
1246
+ state: string;
1247
+ challenge: string;
1248
+ }): string;
1249
+ interface GithubGrantPayload {
1250
+ version: 1;
1251
+ token: string;
1252
+ login?: string;
1253
+ tokenType?: string;
1254
+ scope?: string;
1255
+ }
1256
+ /**
1257
+ * 向 `ctx.authorization` 注册 GitHub flow(若核心没有该服务则降级 no-op)。
1258
+ * 在 `apply()` 里调用一次。
1259
+ */
1260
+ declare function registerGithubFlow(deps: GithubAuthDeps): void;
1261
+ /**
1262
+ * 启动一次浏览器登录 attempt(进程内 `authorization.begin`,不阻塞请求)。
1263
+ * @returns 当前 attempt 视图(含 authorizeUrl,供前端打开)。二次调用在已有进行中时抛错。
1264
+ */
1265
+ declare function beginGithubSignIn(deps: GithubAuthDeps, method?: 'browser' | 'device'): Promise<GithubAttemptView>;
1266
+ /** 取消进行中的 attempt。 */
1267
+ declare function cancelGithubSignIn(deps: GithubAuthDeps): void;
1268
+ /** 仅测试用:清空内存 attempt。 */
1269
+ declare function resetAttemptForTest(): void;
1270
+
1271
+ type githubAuth_AuthorizationFlow = AuthorizationFlow;
1272
+ type githubAuth_AuthorizationLike = AuthorizationLike;
1273
+ type githubAuth_AuthorizationSessionLike = AuthorizationSessionLike;
1274
+ declare const githubAuth_CALLBACK_PATH: typeof CALLBACK_PATH;
1275
+ declare const githubAuth_DEFAULT_SCOPE: typeof DEFAULT_SCOPE;
1276
+ declare const githubAuth_GITHUB_RECORD_KEY: typeof GITHUB_RECORD_KEY;
1277
+ type githubAuth_GithubAttemptPhase = GithubAttemptPhase;
1278
+ type githubAuth_GithubAttemptView = GithubAttemptView;
1279
+ type githubAuth_GithubAuthDeps = GithubAuthDeps;
1280
+ type githubAuth_GithubGrantPayload = GithubGrantPayload;
1281
+ type githubAuth_WebServerLike = WebServerLike;
1282
+ declare const githubAuth_attemptView: typeof attemptView;
1283
+ declare const githubAuth_beginGithubSignIn: typeof beginGithubSignIn;
1284
+ declare const githubAuth_buildAuthorizeUrl: typeof buildAuthorizeUrl;
1285
+ declare const githubAuth_cancelGithubSignIn: typeof cancelGithubSignIn;
1286
+ declare const githubAuth_createPkce: typeof createPkce;
1287
+ declare const githubAuth_registerGithubFlow: typeof registerGithubFlow;
1288
+ declare const githubAuth_resetAttemptForTest: typeof resetAttemptForTest;
1289
+ declare const githubAuth_verifyState: typeof verifyState;
1290
+ declare namespace githubAuth {
1291
+ export { type githubAuth_AuthorizationFlow as AuthorizationFlow, type githubAuth_AuthorizationLike as AuthorizationLike, type githubAuth_AuthorizationSessionLike as AuthorizationSessionLike, githubAuth_CALLBACK_PATH as CALLBACK_PATH, githubAuth_DEFAULT_SCOPE as DEFAULT_SCOPE, githubAuth_GITHUB_RECORD_KEY as GITHUB_RECORD_KEY, type githubAuth_GithubAttemptPhase as GithubAttemptPhase, type githubAuth_GithubAttemptView as GithubAttemptView, type githubAuth_GithubAuthDeps as GithubAuthDeps, type githubAuth_GithubGrantPayload as GithubGrantPayload, type githubAuth_WebServerLike as WebServerLike, githubAuth_attemptView as attemptView, githubAuth_beginGithubSignIn as beginGithubSignIn, githubAuth_buildAuthorizeUrl as buildAuthorizeUrl, githubAuth_cancelGithubSignIn as cancelGithubSignIn, githubAuth_createPkce as createPkce, githubAuth_registerGithubFlow as registerGithubFlow, githubAuth_resetAttemptForTest as resetAttemptForTest, githubAuth_verifyState as verifyState };
1292
+ }
1293
+
1145
1294
  interface DefaultBranchResult {
1146
1295
  branch?: string;
1147
1296
  /** `origin-head` = 远端默认分支;`head` = 本地当前分支兜底;`none` = 读不到。 */
@@ -1823,6 +1972,8 @@ interface RouteDeps {
1823
1972
  /** 包名与仓库地址都来自 package.json,由 src/index.ts 传入。 */
1824
1973
  pluginName?: string;
1825
1974
  repository?: string;
1975
+ /** 浏览器 GitHub 登录用的 public client_id(由 apply 的 config 传入;缺省时按钮会提示未配置)。 */
1976
+ githubClientId?: string;
1826
1977
  logger?: (event: string, data?: Record<string, unknown>) => void;
1827
1978
  }
1828
1979
  declare function createRoutes(deps: RouteDeps): (request: http.IncomingMessage, response: http.ServerResponse) => Promise<void>;
@@ -2145,4 +2296,4 @@ declare namespace tools {
2145
2296
  export { tools_createTrendingHistoryTool as createTrendingHistoryTool, tools_createTrendingRunTool as createTrendingRunTool };
2146
2297
  }
2147
2298
 
2148
- export { channel, config, core, credentials, errors, github, handshake$1 as handshake, importCli, ipc, locate, paths, pendingPr, pluginInfo, preflight, proxy, quickfill, release, repo, routes, run, runner, schedule, state, subscribe, tools, update as updateService, version };
2299
+ export { channel, config, core, credentials, errors, github, githubAuth, handshake$1 as handshake, importCli, ipc, locate, paths, pendingPr, pluginInfo, preflight, proxy, quickfill, release, repo, routes, run, runner, schedule, state, subscribe, tools, update as updateService, version };
package/lib/internal.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  core_exports,
5
5
  credentials_exports,
6
6
  errors_exports,
7
+ github_auth_exports,
7
8
  github_exports,
8
9
  handshake_exports,
9
10
  import_cli_exports,
@@ -26,7 +27,7 @@ import {
26
27
  tools_exports,
27
28
  update_exports,
28
29
  version_exports
29
- } from "./chunk-YJ5GF3MW.js";
30
+ } from "./chunk-6PVBPJXO.js";
30
31
 
31
32
  // src/internal.ts
32
33
  import * as exec from "@morehao/dsh-plugin-kit/exec";
@@ -38,6 +39,7 @@ export {
38
39
  errors_exports as errors,
39
40
  exec,
40
41
  github_exports as github,
42
+ github_auth_exports as githubAuth,
41
43
  handshake_exports as handshake,
42
44
  import_cli_exports as importCli,
43
45
  ipc_exports as ipc,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@morehao/dsh-github-trending",
3
- "version": "0.7.10",
3
+ "version": "0.8.0",
4
4
  "description": "GitHub 趋势日报的 DeepSeek Harness 插件:按日 / 周 / 月周期定时 spawn 本地 trendradar 核心,抓取 Trending、生成中文简介与周期总结,并可选把订阅仓库的新 Release 合成中文摘要,一起提交到你的仓库、自动开 PR 合并;内置概览 / 榜单 / 运行记录 / 订阅 / 设置工作台。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -23,6 +23,7 @@
23
23
  "cordis.patch.yml",
24
24
  "icon.svg",
25
25
  "README.md",
26
+ "README.en.md",
26
27
  "CHANGELOG.md",
27
28
  "LICENSE"
28
29
  ],