174 lines
7.9 KiB
JavaScript
174 lines
7.9 KiB
JavaScript
// Regenerate the QQ plugin market index (DSH plugin-market index format 1).
|
||
//
|
||
// The index lists the four QQ-dsh component plugins, plus one external plugin
|
||
// (ds-harness-remote-fast) whose canonical source is GitHub's rainow fork, not
|
||
// our Gitea mirror. Each entry's install source is a git source pinned to the
|
||
// repo HEAD commit; versions are read live from each repo's package.json, so
|
||
// re-running this after a release is the whole maintenance story. The repos are
|
||
// public, so the endpoints are read anonymously. Output: ./index.json next to
|
||
// this script.
|
||
//
|
||
// Why git and not the org's Gitea npm registry (tried 2026-11-12, reverted
|
||
// the same day): Gitea's npm registry strips the `dsh` field from the
|
||
// package metadata it serves, and the Discover UI's pre-install inspect
|
||
// (pluginManager.inspect, kind=registry) refuses any package whose registry
|
||
// metadata lacks dsh.bundle — every install failed with "declares no
|
||
// dsh.bundle" on the user's machine. Git sources skip that check and the
|
||
// installer reads the repo's real package.json. Updates for git installs
|
||
// go through dsh-better-chat's Discover update button (installBundle
|
||
// overwrite); DSH's native update button does not apply to git sources.
|
||
//
|
||
// node make-index.mjs
|
||
import { writeFileSync } from 'node:fs'
|
||
import { dirname, join } from 'node:path'
|
||
import { fileURLToPath } from 'node:url'
|
||
|
||
const API = 'https://git.qyhhh.top/api/v1'
|
||
const WEB = 'https://git.qyhhh.top/DeepsSeekHarness'
|
||
const GITHUB = 'https://api.github.com'
|
||
|
||
const PLUGINS = [
|
||
{
|
||
name: 'dsh-sansheng-liubu',
|
||
icon: 'icons/sansheng.png',
|
||
repo: 'dsh-sansheng-liubu',
|
||
branch: 'release/v1.1.5',
|
||
title: '三省六部 · 十席工作台',
|
||
description: '每个项目固定十席角色与独立会话。丞相自然下派,关键歧义才启动 Grill Me。门下通过后尚书并行派工,部门可在任务里会商。项目决定与原生审批集中在「待你处理」,丞相可用原生后台助手整理需求、跟踪进度和汇总反馈。',
|
||
keywords: ['workbench', 'sansheng', '三省六部'],
|
||
},
|
||
{
|
||
name: 'dsh-brain',
|
||
icon: 'icons/brain.png',
|
||
repo: 'dsh-brain',
|
||
branch: 'main',
|
||
title: 'dsh-brain · 云端记忆',
|
||
description: '把 DSH 接到自托管的 LongMemory:Mnemon 供应方、技能双向同步、从其他软件导入技能。',
|
||
keywords: ['memory', 'longmemory', 'mnemon', 'skills'],
|
||
},
|
||
{
|
||
name: 'workspace-groups-remote',
|
||
icon: 'icons/groups.png',
|
||
repo: 'workspace-groups-remote',
|
||
branch: 'main',
|
||
title: '工作区分组与远程',
|
||
description: '多文件夹分组与远程 SSH 工作区:镜像、终端直连与重复目录防护。',
|
||
keywords: ['workspace', 'ssh', 'remote', 'groups'],
|
||
},
|
||
{
|
||
name: 'dsh-better-chat',
|
||
icon: 'icons/chat.png',
|
||
repo: 'dsh-better-chat',
|
||
branch: 'main',
|
||
title: 'dsh-better-chat · 聊天增强',
|
||
description: '审批卡快捷键(可自定义)、权限界面移除「完全权限」、插件商店更新按钮。',
|
||
keywords: ['chat', 'approval', 'permission'],
|
||
},
|
||
{
|
||
name: 'ds-harness-remote-fast',
|
||
icon: 'icons/remote-fast.png',
|
||
repo: 'ds-harness-remote-fast',
|
||
branch: 'lite',
|
||
github: true,
|
||
owner: 'rainow',
|
||
title: 'ds-harness-remote-fast · 远程极速版',
|
||
description: 'ds-harness-remote 的极速分支(rainow):主机端首屏快照裁剪,解决大会话帧超限断连;服务端与客户端不用换,加密与配对与原版一致。安装源为 GitHub 上的 rainow/ds-harness-remote-fast。',
|
||
keywords: ['remote', '远程', 'fast'],
|
||
},
|
||
{
|
||
name: 'dsh-better-sidebar',
|
||
icon: 'icons/better-sidebar.svg',
|
||
repo: 'DSH-better-sidebar',
|
||
branch: 'v0.33.0',
|
||
github: true,
|
||
owner: 'omdsh-dev',
|
||
author: 'omdsh-dev',
|
||
title: 'Better Sidebar · 右栏整合',
|
||
description: '把文件树、编辑器、改动、任务与侧边对话收进一列右栏,按会话分开;并向其他插件提供注册右栏标签与文件查看器的服务。三省六部的 Better Sidebar 子插件依赖它。安装源为 GitHub 上的 omdsh-dev/DSH-better-sidebar,固定到 v0.33.0。',
|
||
keywords: ['sidebar', 'editor', 'files', 'better-sidebar'],
|
||
},
|
||
]
|
||
|
||
// Transient resets to GitHub are common from this host; retry a few times
|
||
// with a growing pause before giving up (the unattended updater relies on it).
|
||
async function fetchRetry(url, options = {}, attempts = 5) {
|
||
let lastError
|
||
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
||
try {
|
||
return await fetch(url, options)
|
||
} catch (error) {
|
||
lastError = error
|
||
if (attempt < attempts) await new Promise((resolve) => setTimeout(resolve, attempt * 500))
|
||
}
|
||
}
|
||
throw lastError
|
||
}
|
||
|
||
async function headOf(repo, branch) {
|
||
const response = await fetchRetry(`${API}/repos/DeepsSeekHarness/${repo}/branches/${encodeURIComponent(branch)}`)
|
||
if (!response.ok) throw new Error(`branch lookup failed for ${repo}/${branch}: HTTP ${response.status}`)
|
||
const body = await response.json()
|
||
return { commit: body.commit.id, timestamp: Math.floor(Date.parse(body.commit.timestamp) / 1000) }
|
||
}
|
||
|
||
async function githubHead(owner, repo, branch) {
|
||
const response = await fetchRetry(`${GITHUB}/repos/${owner}/${repo}/commits/${encodeURIComponent(branch)}`, {
|
||
headers: { Accept: 'application/vnd.github+json', 'User-Agent': 'dsh-market-index' },
|
||
})
|
||
if (!response.ok) throw new Error(`github commit lookup failed for ${owner}/${repo}@${branch}: HTTP ${response.status}`)
|
||
const body = await response.json()
|
||
return { commit: body.sha, timestamp: Math.floor(Date.parse(body.commit.committer.date) / 1000) }
|
||
}
|
||
|
||
const plugins = []
|
||
for (const plugin of PLUGINS) {
|
||
const onGithub = plugin.github === true
|
||
const head = onGithub ? await githubHead(plugin.owner, plugin.repo, plugin.branch) : await headOf(plugin.repo, plugin.branch)
|
||
const web = onGithub ? `https://github.com/${plugin.owner}/${plugin.repo}` : `${WEB}/${plugin.repo}`
|
||
// Read package.json through each host's API. For GitHub we deliberately use
|
||
// the contents API (api.github.com), not raw.githubusercontent.com: the raw
|
||
// host resets TLS connections from this machine while the API stays reliable.
|
||
const pkgUrl = onGithub
|
||
? `${GITHUB}/repos/${plugin.owner}/${plugin.repo}/contents/package.json?ref=${head.commit}`
|
||
: `${API}/repos/DeepsSeekHarness/${plugin.repo}/contents/package.json?ref=${head.commit}`
|
||
const pkgResponse = await fetchRetry(pkgUrl, onGithub
|
||
? { headers: { Accept: 'application/vnd.github+json', 'User-Agent': 'dsh-market-index' } }
|
||
: {})
|
||
if (!pkgResponse.ok) throw new Error(`package.json fetch failed for ${plugin.repo}: HTTP ${pkgResponse.status}`)
|
||
const pkgFile = await pkgResponse.json()
|
||
const pkg = JSON.parse(Buffer.from(pkgFile.content, 'base64').toString('utf8'))
|
||
if (pkg.name !== plugin.name) throw new Error(`name mismatch for ${plugin.repo}: index says ${plugin.name}, package.json says ${pkg.name}`)
|
||
const version = pkg.version
|
||
plugins.push({
|
||
name: plugin.name,
|
||
title: plugin.title,
|
||
icon: plugin.icon,
|
||
description: plugin.description,
|
||
author: plugin.author || 'newbie',
|
||
homepage: web,
|
||
repository: { url: web },
|
||
metadata: { keywords: plugin.keywords, labels: [], sortKeys: {} },
|
||
versions: [
|
||
{
|
||
version: version,
|
||
publishTimestamp: head.timestamp,
|
||
source: { type: 'git', url: web, commit: head.commit },
|
||
engines: {},
|
||
},
|
||
],
|
||
})
|
||
console.log(`${plugin.name} ${version} @ ${head.commit.slice(0, 8)}`)
|
||
}
|
||
|
||
const index = {
|
||
format: 1,
|
||
title: 'QQ 插件索引',
|
||
description: 'newbie 的 DSH 插件索引:QQ-dsh 全家桶及其四个组件,另收录外部依赖 Better Sidebar;源码托管在 git.qyhhh.top 的 DeepsSeekHarness 组织。',
|
||
metadata: { categories: {}, labels: {}, sortKeys: {} },
|
||
plugins,
|
||
}
|
||
|
||
const out = join(dirname(fileURLToPath(import.meta.url)), 'index.json')
|
||
writeFileSync(out, `${JSON.stringify(index, null, 2)}\n`, 'utf8')
|
||
console.log(`wrote ${out}`)
|