dsh-agency-agents 0.3.4 → 0.4.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/README.md CHANGED
@@ -46,16 +46,14 @@ plugin_manager: action=install_bundle, target=file:C:/Users/63676/dsh-bundles/di
46
46
  maxTeamMembers: 6 # 团队上限;实际还会被 maxActiveSubagents 夹取
47
47
  strictValidation: false # true = 上游任何一个坏文件都整体拒绝;false = 跳过并标注
48
48
  autoTeamMode: true # 团队任务板清空后自动关闭 Team 模式(见下)
49
- githubToken: '' # secret 字段:在 Plugins → Agency Agents 配置里填,不要写进文件
50
49
  repository: msitarzewski/agency-agents
51
50
  branch: main
52
51
  proxy: '' # 例如 http://127.0.0.1:7890
53
52
  ```
54
53
 
55
- ### GitHub Token
54
+ ### GitHub 访问(零配置)
56
55
 
57
- 匿名调用 GitHub API 只有 60 次/小时(本机实测很快就 403)。Token 是配置里的 **`role('secret')` 字段**:在插件配置页填写,DSH 读取时脱敏、不会回传页面(`/ping` 也不含它),日志与错误信息一律脱敏。没有 Token 也能用,只是更容易被限流。
58
- 从 0.2.x 升级:旧版本把 Token 存在 DSH 凭据库(`AGENCY_AGENTS_GITHUB_TOKEN`),0.3.0 起不再读取该凭据,需要在插件配置页重新填写(旧的凭据可以删了)。
56
+ 不需要配置任何 Token:Host 启动时自动复用本机的 **GitHub CLI**(`gh auth token`)作为上游凭据;`gh` 未安装或未登录时自动退回匿名请求(60 次/小时)。Token 只停留在进程内,不写配置、不回传页面、不进日志。
59
57
 
60
58
  代理与离线:`proxy` 为空表示直连;填了就走该代理。断网/限流/上游坏文件时插件**不会清空已有版本**,继续使用上一个有效版本并在面板显示原因。
61
59
 
@@ -69,7 +67,7 @@ plugin_manager: action=install_bundle, target=file:C:/Users/63676/dsh-bundles/di
69
67
  | **版本** | 列出已保存版本;对非当前版本「切换到此版本」会原子切换 active 指针,页面立刻回退到旧版本。 |
70
68
  | ~~**设置**~~ | 已移除:配置全部交给 DSH 插件页的原生配置表单(Plugins → Agency Agents → 该行「配置」) |
71
69
 
72
- > **配置在哪里**:全部配置都在 **Plugins → Agency Agents → 行右侧「配置」**(DSH 原生插件配置表单,直接写 Loader 行)。插件面板只保留角色 / 协作流程 / 团队编排 / 版本四个页签,没有自己的设置页,也没有偏好文件。GitHub Token 是 `role('secret')` 配置字段:读取时被 DSH 脱敏,不会回传页面。
70
+ > **配置在哪里**:装好即可用,**零配置**(上游凭据自动复用本机 `gh`)。需要调优时再去 **Plugins → Agency Agents → 行「配置」**:间隔 / 团队上限 / 代理 / 严格校验 / 自动关闭。没有 Token 设置项,也没有自己的设置页与偏好文件。
73
71
 
74
72
  **从 runbook 起团队**:协作流程页选 runbook → 「根据此流程组建团队」→ 填目标与规模 → 「生成编排」→ 启动。
75
73
 
@@ -199,7 +197,7 @@ GET /agency-agents/api/v1/events # SSE: sync/status, catalog/changed,
199
197
  | 服务注入 | `ctx.inject(['webServer'])`、`ctx.inject(['tools'])` + `ctx.get(...)` | webServer 重启后路由自动重建 |
200
198
  | Agent Team | `agentTeams.setEnabled` + 原生 `subagent`/`team_task_*` | 会话内 `teamMode:'enabled'` |
201
199
  | Session 控制 | `sessionController.create/resolveAgent/prompt` | `/session/start`、`agency_team_start` |
202
- | 凭据 | 配置里的 `role('secret')` Token 字段(DSH 读取脱敏) | 页面与 `/ping` 都拿不到 Token;日志脱敏 |
200
+ | 凭据 | 复用本机 `gh auth token`(无配置项) | 插件不接触用户输入的 Token;没装 gh 时匿名 |
203
201
  | 卸载清理 | 所有注册都挂在 `ctx.effect` 上 | 停用插件后槽占用与工具同时消失 |
204
202
 
205
203
  ### 依赖与安装(从 0.2.0 起)
@@ -278,7 +276,7 @@ node --test
278
276
  | 侧边栏没有图标 | 确认 Plugins 里该 bundle 已启用;`cordis_inspect_query` 查 Client `Slots.listSubTree` 的 `sidebar.panellist` 是否有 `agency-agents` |
279
277
  | 页面显示 "Host API unavailable" | 该组合没有 `webServer`(非 HTTP 载体),面板只能只读;用 `dsh web`/Desktop 的 HTTP 页面 |
280
278
  | 一直 "Update available" 但不切换 | 看 `~/.dsh/agency-agents/state.json` 的 `lastError`(常见:磁盘不足、校验失败) |
281
- | 同步失败 403 | 配置 GitHub Token,或等 `x-ratelimit-reset` |
279
+ | 同步失败 403 | 确认本机 `gh auth status` 已登录(插件会自动复用其 token);否则等 `x-ratelimit-reset` |
282
280
  | 想彻底重置 | 停用插件后删 `~/.dsh/agency-agents/`,重新启用 |
283
281
 
284
282
  ## 升级记录
@@ -286,6 +284,7 @@ node --test
286
284
  | 迁移 | 做了什么 | 证据 |
287
285
  |---|---|---|
288
286
  | **插件 0.3.3(修复浏览器端注册)** | 包名改为 `dsh-agency-agents` 后,`client.js` 的 `__ModuleLoader__.load({ id })` 仍是旧名,导致整包客户端加载失败(页面同步报错、面板与配置入口消失);已把 id 对齐包名,并新增 `plugins.bundle.config` / `plugins.row.config` 两个原生配置入口 | 刷新后 Plugins → Agency Agents 详情页出现配置区,行也有「配置」入口;工具与面板恢复 |
287
+ | **插件 0.4.0(零配置)** | 删除 `githubToken` 配置字段;Host 新增 `gh auth token` 解析器(10 分钟缓存、失败/未登录自动匿名回退),上游鉴权完全复用本机 GitHub CLI;配置页只剩可选调优项 | `gh.test.mjs` 5 例(取值/缓存/超时重取/失败/并发共享);本机实测 `gh auth token` 40 字符并被解析器读到;`node --test` 91 pass |
289
288
  | **插件 0.3.1(补回配置入口)** | 把配置页注册到 DSH 插件页的原生槽 `plugins.row.config`(键 `dsh-agency-agents#agency-agents`):页面 chrome、表单状态与写入全部由宿主提供(`form.mutate` → 配置文档),插件不再有 `/settings` 接口或偏好文件 | Plugins → Agency Agents → 行右侧「配置」可编辑全部 16 个字段;Token 为 secret 字段,读取脱敏 |
290
289
  | **插件 0.2.2 → 0.3.0(交接 DSH 统一管理)** | ① 删除插件自管的设置页/保存按钮/`preferences.json` 与 `/settings` 接口;② 16 个配置字段全部回到 DSH 的插件配置页(`Config` → Loader 行),Token 改为 `role('secret')` 配置字段(读取脱敏);③ 旧技能维护动作移入面板(检测到才显示);④ 补 `LICENSE`、`icon`、打包元数据,`pnpm pack` 产物可安装并加载 | 单测 87 pass;`pnpm pack` 34 个文件;tarball 装进临时工程 + 加载 `Config({})` 成功;插件重载后 5 个工具注册 |
291
290
  | **0.2.2-rc.5 → 0.2.3-alpha.2**(本插件 0.2.1 → 0.2.2) | ① `dsh-tools` peer+dev → `0.2.3-alpha.2`,`schemastery` → `~3.20.0-alpha.1`(宿主已升到 3.20.0-alpha.1);② `engines.dsh` 按官方新规范改为 `^0.2.3-alpha.2`(caret + prerelease 下界);③ 全量测试对 0.2.3-alpha.2 SDK 重跑;④ 适配**新增强制鉴权**:`dsh-host-authentication-token` 让所有路由默认 `auth: 'required'`,我们把插件路由显式声明为 `required`,并给客户端补了 401 专属提示("此页面未通过 DSH 鉴权") | `node --test` → 81 pass;`index.js` 在 schemastery 3.20.0-alpha.1 下可加载且 `Config({})` 正常;无 cookie 探针 → `GET /agency-agents/api/v1/ping` = **401 `unauthorized`**(证明路由已注册且受鉴权保护);5 个工具在 0.2.3-alpha.2 上注册成功、`agency_roles_search` 实际调用成功 |
@@ -305,7 +304,7 @@ node --test
305
304
  |---|---|---|
306
305
  | **唯一性** | 配置默认值与范围只写一次:`src/host/config.js` 的 `CONFIG_DEFAULTS` / `CONFIG_BOUNDS`;`index.js` 的 `Config` schema 由这张表生成,`resolveConfig` 也用它夹取 | 单测「one defaults table feeds the schema, the resolver and the tests」逐字段比对 schema 投影与默认表 |
307
306
  | | 版本只写一次:`PLUGIN_VERSION` 读 `package.json`,不手写 | `index.js` 里已无字面量版本 |
308
- | | 有效配置只有一个来源:Loader 行(`Config` schema 的默认值 + 用户在 Plugins 页的编辑);Token 是该行里的 `role('secret')` 字段,DSH 负责脱敏 | `resolveConfig(raw)`;单测覆盖默认表、越界夹取、secret 声明 |
307
+ | | 有效配置只有一个来源:Loader 行(`Config` schema 的默认值 + 用户在 Plugins 页的编辑);上游凭据复用本机 `gh`,不是配置项 | `resolveConfig(raw)`;单测覆盖默认表、越界夹取、无 Token 字段 |
309
308
  | | 交付物只有一份:调研报告只留 `docs/research/` | 目录核对 |
310
309
  | **复用性** | 组队只有一条管线:`composeTeam`/`buildTeamPrompt`/`isThinObjective` 由工具、HTTP 路由、启动逻辑共用 | `tools.js`、`routes.js` 均 `import` 自 `compose.js` |
311
310
  | | 客户端只有一套设置 UI 与一套 `api()`/`StateBlock`/`Skeleton` | 设置节是唯一表单;面板不再有第二份 |
package/client.js CHANGED
@@ -140,6 +140,7 @@ window.__ModuleLoader__.load({
140
140
  'legacy.parked': '已停用 {count} 个旧技能(保存在 {target})',
141
141
  'legacy.restore': '恢复旧技能',
142
142
  'legacy.restored': '已恢复 {count} 个旧技能',
143
+ 'config.nav': 'Agency Agents 专家库',
143
144
  'config.summary': '每 {interval} 分钟检查 · 团队上限 {cap} · 自动关闭:{auto}',
144
145
  'config.summaryPending': '正在读取配置…',
145
146
  'config.on': '开',
@@ -149,10 +150,6 @@ window.__ModuleLoader__.load({
149
150
  'config.maxTeam': '团队上限',
150
151
  'config.proxy': '代理',
151
152
  'config.proxyPlaceholder': 'http://127.0.0.1:7890(留空表示直连)',
152
- 'config.token': 'GitHub Token(留空不修改)',
153
- 'config.tokenPlaceholder': '粘贴 token 后保存',
154
- 'config.tokenHint': 'Token 是 secret 字段:DSH 读取时脱敏,页面不会再显示已保存的值。',
155
- 'config.tokenClear': '清除 Token',
156
153
  'config.strict': '严格校验(上游有坏文件就整体拒绝)',
157
154
  'config.autoTeamMode': '任务板清空后自动关闭 Team 模式',
158
155
  'config.saved': '已保存',
@@ -282,6 +279,7 @@ window.__ModuleLoader__.load({
282
279
  'legacy.parked': '{count} legacy skill(s) parked in {target}',
283
280
  'legacy.restore': 'Restore legacy skills',
284
281
  'legacy.restored': 'Restored {count} legacy skill(s)',
282
+ 'config.nav': 'Agency Agents roster',
285
283
  'config.summary': 'Checks every {interval} min · team cap {cap} · auto-off: {auto}',
286
284
  'config.summaryPending': 'Loading configuration…',
287
285
  'config.on': 'on',
@@ -291,10 +289,6 @@ window.__ModuleLoader__.load({
291
289
  'config.maxTeam': 'Team cap',
292
290
  'config.proxy': 'Proxy',
293
291
  'config.proxyPlaceholder': 'http://127.0.0.1:7890 (empty = direct)',
294
- 'config.token': 'GitHub token (leave empty to keep)',
295
- 'config.tokenPlaceholder': 'Paste a token and save',
296
- 'config.tokenHint': 'The token is a secret field: DSH redacts it on every read, so a saved value is never shown again.',
297
- 'config.tokenClear': 'Clear token',
298
292
  'config.strict': 'Strict validation (reject a sync with a bad file)',
299
293
  'config.autoTeamMode': 'Switch Team mode off automatically once the board is empty',
300
294
  'config.saved': 'Saved',
@@ -533,36 +527,62 @@ animation:aag-spin .8s linear infinite}
533
527
  */
534
528
  function AgencyConfigPage(props) {
535
529
  const t = typeof props.t === 'function' ? props.t : key => key
536
- const provided = props.form
537
- // The row page passes a Host-owned form; the bundle page does not, so fall
538
- // back to the shared client ConfigForms service for the same namespace.
539
- const fetchForm = React.useCallback(() => {
540
- const service = ctx0.get('configForms')
541
- return service?.get?.('agency-agents')
542
- }, [])
543
- const [form] = React.useState(() => provided ?? fetchForm())
544
- const [fallback, setFallback] = React.useState(undefined)
545
- React.useEffect(() => {
546
- if (provided !== undefined || form === undefined) return undefined
547
- setFallback(form.getSnapshot())
548
- return form.subscribe(() => setFallback(form.getSnapshot()))
549
- }, [provided, form])
550
- const snapshot = provided?.state ?? fallback
551
- const values = snapshot?.value
552
- const [draft, setDraft] = React.useState(undefined)
553
- const [busy, setBusy] = React.useState(false)
554
- const [notice, setNotice] = React.useState(undefined)
530
+ // The row page passes a Host-owned form; the bundle and settings pages do not,
531
+ // so fall back to the shared client ConfigForms service. The namespace is
532
+ // found by name, then by the schema field only this plugin declares, and no
533
+ // failure here may take the containing page down.
534
+ const fetchForm = React.useCallback(() => {
535
+ try {
536
+ const service = ctx0.get('configForms')
537
+ if (service === undefined || typeof service.get !== 'function') return undefined
538
+ const names = ['agency-agents']
539
+ if (typeof service.describe === 'function') {
540
+ for (const entry of service.describe() ?? []) {
541
+ const ns = entry?.ns
542
+ if (typeof ns !== 'string') continue
543
+ if (JSON.stringify(entry?.schema ?? {}).includes('maxSnapshotFiles')) names.push(ns)
544
+ }
545
+ }
546
+ for (const ns of names) {
547
+ try {
548
+ const candidate = service.get(ns)
549
+ if (candidate !== undefined && typeof candidate.getSnapshot === 'function') return candidate
550
+ } catch {
551
+ /* try the next namespace */
552
+ }
553
+ }
554
+ } catch {
555
+ /* a host without configForms simply has no form to show */
556
+ }
557
+ return undefined
558
+ }, [])
559
+ const [form] = React.useState(() => provided ?? fetchForm())
560
+ const [fallback, setFallback] = React.useState(undefined)
561
+ React.useEffect(() => {
562
+ if (provided !== undefined || form === undefined) return undefined
563
+ try {
564
+ setFallback(form.getSnapshot())
565
+ return form.subscribe(() => setFallback(form.getSnapshot()))
566
+ } catch {
567
+ return undefined
568
+ }
569
+ }, [provided, form])
570
+ const snapshot = provided?.state ?? fallback
571
+ const values = snapshot?.value
555
572
 
556
- React.useEffect(() => {
557
- if (values === undefined) return
558
- setDraft({
559
- intervalMinutes: values.intervalMinutes,
560
- maxTeamMembers: values.maxTeamMembers,
561
- strictValidation: values.strictValidation === true,
562
- autoTeamMode: values.autoTeamMode !== false,
563
- proxy: values.proxy ?? '',
564
- githubToken: '',
565
- })
573
+ const [draft, setDraft] = React.useState(undefined)
574
+ const [busy, setBusy] = React.useState(false)
575
+ const [notice, setNotice] = React.useState(undefined)
576
+
577
+ React.useEffect(() => {
578
+ if (values === undefined) return
579
+ setDraft({
580
+ intervalMinutes: values.intervalMinutes,
581
+ maxTeamMembers: values.maxTeamMembers,
582
+ strictValidation: values.strictValidation === true,
583
+ autoTeamMode: values.autoTeamMode !== false,
584
+ proxy: values.proxy ?? '',
585
+ })
566
586
  }, [values])
567
587
 
568
588
  if (props.view === 'summary') {
@@ -585,7 +605,6 @@ animation:aag-spin .8s linear infinite}
585
605
  try {
586
606
  const accepted = await form.mutate(ops)
587
607
  setNotice({ kind: accepted ? 'ok' : 'bad', text: accepted ? t('config.saved') : t('config.refused') })
588
- if (accepted) setDraft(current => (current === undefined ? current : { ...current, githubToken: '' }))
589
608
  } catch (error) {
590
609
  setNotice({ kind: 'bad', text: t('config.failed').replace('{message}', error instanceof Error ? error.message : String(error)) })
591
610
  } finally {
@@ -607,9 +626,6 @@ animation:aag-spin .8s linear infinite}
607
626
  { op: 'set', path: ['autoTeamMode'], value: draft.autoTeamMode !== false },
608
627
  { op: 'set', path: ['proxy'], value: typeof draft.proxy === 'string' ? draft.proxy.trim() : '' },
609
628
  ]
610
- if (typeof draft.githubToken === 'string' && draft.githubToken.trim() !== '') {
611
- ops.push({ op: 'set', path: ['githubToken'], value: draft.githubToken.trim() })
612
- }
613
629
  void persist(ops)
614
630
  }
615
631
 
@@ -633,10 +649,6 @@ animation:aag-spin .8s linear infinite}
633
649
  t('config.proxy'),
634
650
  h('input', { type: 'text', placeholder: t('config.proxyPlaceholder'), value: draft.proxy, onChange: event => setDraft({ ...draft, proxy: event.target.value }) }),
635
651
  ),
636
- field(
637
- t('config.token'),
638
- h('input', { type: 'password', placeholder: t('config.tokenPlaceholder'), value: draft.githubToken, onChange: event => setDraft({ ...draft, githubToken: event.target.value }) }),
639
- ),
640
652
  ),
641
653
  h(
642
654
  'div',
@@ -650,18 +662,11 @@ animation:aag-spin .8s linear infinite}
650
662
  h('span', null, t('config.autoTeamMode')),
651
663
  ),
652
664
  ),
653
- h('p', { className: 'aag-configHint' }, t('config.tokenHint')),
654
665
  h(
655
666
  'div',
656
667
  { className: 'aag-toolbar' },
657
668
  h('button', { type: 'button', className: 'aag-button primary', disabled: busy, onClick: save },
658
669
  busy ? h('span', { className: 'aag-spin' }) : null, t('action.save')),
659
- h('button', {
660
- type: 'button',
661
- className: 'aag-button ghost',
662
- disabled: busy || typeof values?.githubToken === 'string' && values.githubToken !== '',
663
- onClick: () => void persist([{ op: 'unset', path: ['githubToken'] }]),
664
- }, t('config.tokenClear')),
665
670
  ),
666
671
  )
667
672
  }
@@ -1654,6 +1659,12 @@ animation:aag-spin .8s linear infinite}
1654
1659
  )
1655
1660
  ctx.slots.inject('plugins.bundle.config', () =>
1656
1661
  ctx.slots.register({ name: 'plugins.bundle.config', key: 'dsh-agency-agents', locale: NS }, AgencyConfigPage),
1662
+ )
1663
+ ctx.slots.inject('settings.section', () =>
1664
+ ctx.slots.register({ name: 'settings.section', id: 'agency-agents', order: 40, label: () => t('config.nav'), locale: NS }, AgencyConfigPage),
1665
+ )
1666
+ ctx.slots.inject('settings.section.icon', () =>
1667
+ ctx.slots.register({ name: 'settings.section.icon', id: 'agency-agents', locale: NS }, AgencyIcon),
1657
1668
  )
1658
1669
  },
1659
1670
  }
package/cordis.patch.yml CHANGED
@@ -12,5 +12,3 @@
12
12
  maxSnapshotBytes: 33554432
13
13
  # Maximum entries accepted from one upstream snapshot archive.
14
14
  maxSnapshotFiles: 2000
15
- # The GitHub token is a secret config field: set it in Plugins -> Agency Agents
16
- # configuration. DSH redacts it from every read; never commit a value here.
package/docs/DETAIL.md CHANGED
@@ -1 +1 @@
1
- ![Agency Agents panel: roster browser on the left and a composed Agent Team graph on the right](preview.svg)
1
+ ![Agency Agents panel: roster browser on the left and a composed Agent Team graph on the right](preview.svg)
package/index.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
 
9
9
  import { readFileSync } from 'node:fs'
10
+
11
+ import { createGhTokenResolver } from './src/host/gh.js'
10
12
  import { createRequire } from 'node:module'
11
13
 
12
14
  import z from '@deepseek-ai/schemastery'
@@ -46,7 +48,6 @@ export const Config = z.object({
46
48
  keepVersions: bounded('keepVersions', 'Snapshot versions kept on disk.'),
47
49
  maxSnapshotBytes: bounded('maxSnapshotBytes', 'Largest accepted upstream archive.'),
48
50
  maxSnapshotFiles: bounded('maxSnapshotFiles', 'Largest accepted file count in one snapshot.'),
49
- githubToken: z.string().default(CONFIG_DEFAULTS.githubToken).role('secret').description('Optional GitHub token raising the API rate limit; stored redacted by DSH.'),
50
51
  repository: z.string().default(CONFIG_DEFAULTS.repository).description('Upstream repository.'),
51
52
  branch: z.string().default(CONFIG_DEFAULTS.branch).description('Upstream branch.'),
52
53
  apiBase: z.string().default(CONFIG_DEFAULTS.apiBase).description('GitHub API base URL.'),
@@ -162,11 +163,15 @@ export function apply(ctx, rawConfig = {}) {
162
163
  })
163
164
 
164
165
 
166
+ // Zero setup: reuse the machine gh CLI when it is logged in.
167
+ const githubToken = createGhTokenResolver()
168
+
165
169
  const sync = createSyncService({
166
170
  config,
167
171
  root,
168
172
  hub,
169
173
  limits,
174
+ githubToken,
170
175
  logger: ctx.logger,
171
176
  onChange(view) {
172
177
  state.syncStatus = view
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-agency-agents",
3
- "version": "0.3.4",
3
+ "version": "0.4.0",
4
4
 
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -26,7 +26,6 @@ export const CONFIG_DEFAULTS = Object.freeze({
26
26
  keepVersions: 5,
27
27
  maxSnapshotBytes: 32 * 1024 * 1024,
28
28
  maxSnapshotFiles: 2000,
29
- githubToken: '',
30
29
  repository: 'msitarzewski/agency-agents',
31
30
  branch: 'main',
32
31
  apiBase: 'https://api.github.com',
@@ -72,7 +71,6 @@ export function resolveConfig(raw = {}) {
72
71
  checkOnStart: input.checkOnStart === undefined ? CONFIG_DEFAULTS.checkOnStart : input.checkOnStart === true,
73
72
  strictValidation: input.strictValidation === true,
74
73
  autoTeamMode: input.autoTeamMode === undefined ? CONFIG_DEFAULTS.autoTeamMode : input.autoTeamMode === true,
75
- githubToken: typeof input.githubToken === 'string' ? input.githubToken : '',
76
74
  repository: text('repository'),
77
75
  branch: text('branch'),
78
76
  apiBase: text('apiBase'),
package/src/host/gh.js ADDED
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Reuse the machine's authenticated GitHub CLI as the upstream credential.
3
+ *
4
+ * The plugin ships with no token setting: when `gh` is installed and logged in,
5
+ * `gh auth token` supplies the API credential, so anonymous rate limits do not
6
+ * apply. Without `gh`, the resolver returns undefined and the existing anonymous
7
+ * request path is used unchanged.
8
+ */
9
+
10
+ import { execFile } from 'node:child_process'
11
+
12
+ /**
13
+ * Run `gh auth token` and return its trimmed output.
14
+ * @returns {Promise<string>} Token text.
15
+ */
16
+ function defaultRun() {
17
+ return new Promise((resolve, reject) => {
18
+ execFile(
19
+ 'gh',
20
+ ['auth', 'token'],
21
+ { timeout: 5000, windowsHide: true, maxBuffer: 64 * 1024 },
22
+ (error, stdout) => {
23
+ if (error) reject(error)
24
+ else resolve(stdout)
25
+ },
26
+ )
27
+ })
28
+ }
29
+
30
+ /**
31
+ * Create a cached token resolver backed by the GitHub CLI.
32
+ * @param {object} [options] - Resolution options.
33
+ * @param {() => Promise<string>} [options.run] - Command runner returning the token text.
34
+ * @param {number} [options.ttlMs] - How long one resolution stays valid.
35
+ * @param {() => number} [options.now] - Clock, injectable for tests.
36
+ * @returns {() => Promise<string | undefined>} Async token reader.
37
+ */
38
+ export function createGhTokenResolver({ run = defaultRun, ttlMs = 10 * 60 * 1000, now = Date.now } = {}) {
39
+ let cachedAt = Number.NEGATIVE_INFINITY
40
+ /** @type {string | undefined} */
41
+ let value
42
+ let inFlight
43
+
44
+ return async function token() {
45
+ if (inFlight !== undefined) return inFlight
46
+ if (now() - cachedAt < ttlMs) return value
47
+ inFlight = (async () => {
48
+ cachedAt = now()
49
+ try {
50
+ const output = await run()
51
+ const text = typeof output === 'string' ? output.trim() : ''
52
+ value = text === '' ? undefined : text
53
+ } catch {
54
+ value = undefined
55
+ } finally {
56
+ inFlight = undefined
57
+ }
58
+ return value
59
+ })()
60
+ return inFlight
61
+ }
62
+ }
package/src/host/sync.js CHANGED
@@ -51,7 +51,7 @@ const STATUS = Object.freeze({
51
51
  * @param {{ info?: Function, warn?: Function }} [options.logger] - Host logger.
52
52
  * @returns {object} Sync service.
53
53
  */
54
- export function createSyncService({ config, root, hub, logger, onChange, limits }) {
54
+ export function createSyncService({ config, root, hub, logger, onChange, limits, githubToken }) {
55
55
  const requester = createRequester({ proxy: config.proxy, timeoutMs: config.requestTimeoutMs })
56
56
  const github = createGithub({ config, requester, token: readToken })
57
57
 
@@ -73,15 +73,9 @@ export function createSyncService({ config, root, hub, logger, onChange, limits
73
73
  transport: 'direct',
74
74
  }
75
75
 
76
- /**
77
- * Read the GitHub token from the Loader row. DSH settings redaction keeps the
78
- * secret out of every wire read; the runtime row carries the value the user
79
- * configured in the plugin configuration page.
80
- * @returns {string | undefined} Token value, or undefined.
81
- */
82
- function readToken() {
83
- const token = typeof config.githubToken === 'string' ? config.githubToken.trim() : ''
84
- return token === '' ? undefined : token
76
+ /** Read the GitHub credential through the local gh CLI resolver. */
77
+ async function readToken() {
78
+ return typeof githubToken === 'function' ? githubToken() : undefined
85
79
  }
86
80
 
87
81
  /**