dsh-market-index/make-index.mjs

136 lines
6.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Regenerate the QQ plugin market index (DSH plugin-market index format 1).
//
// The index lists the four QQ-dsh component plugins. 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 Gitea repos are public, so the branch
// 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 { existsSync, readFileSync, 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 ROOT = dirname(fileURLToPath(import.meta.url))
const MANIFEST = join(ROOT, 'release-manifest.json')
const PLUGINS = [
{
name: 'dsh-sansheng-liubu-mode',
icon: 'icons/sansheng.png',
repo: 'dsh-sansheng-liubu',
branch: 'master',
title: '三省六部工作台',
description: '十个独立部门会话的派发、审批与三层记忆(部门 / 项目 / 长期),原生 DSH 工作台后端。右侧栏「朝堂」朝堂面板已并入本包,装这一条即可。',
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: '审批卡快捷键(可自定义)、权限界面移除「完全权限」、插件商店更新按钮,以及合并自 dsh-better-display 的阅读视图(过程折叠、毛玻璃、mcp-app 交互卡片)。',
keywords: ['chat', 'approval', 'permission', 'reader'],
},
]
async function headOf(repo, branch) {
const response = await fetch(`${API}/repos/DeepsSeekHarness/${repo}/branches/${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) }
}
const release = existsSync(MANIFEST) ? JSON.parse(readFileSync(MANIFEST, 'utf8')) : null
const componentByRepo = new Map()
for (const component of release?.components ?? []) componentByRepo.set(component.repo, component)
const plugins = []
for (const plugin of PLUGINS) {
let version
let commit
let timestamp
const pinned = componentByRepo.get(plugin.repo)
if (pinned !== undefined) {
// The checked-in release manifest is the source of truth for a published
// batch: version, commit and index entry are generated from the SAME record.
if (pinned.package !== plugin.name) throw new Error(`release manifest package mismatch for ${plugin.repo}: ${pinned.package} vs ${plugin.name}`)
version = pinned.version
commit = pinned.sourceCommit
timestamp = pinned.publishTimestamp ?? Math.floor(Date.now() / 1000)
if (!/^[0-9a-f]{40}$/i.test(commit)) throw new Error(`release manifest has no pinned commit for ${plugin.repo}`)
} else {
const head = await headOf(plugin.repo, plugin.branch)
const pkgResponse = await fetch(`${API}/repos/DeepsSeekHarness/${plugin.repo}/contents/package.json?ref=${plugin.branch}`)
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}`)
version = pkg.version
commit = head.commit
timestamp = head.timestamp
}
plugins.push({
name: plugin.name,
title: plugin.title,
icon: plugin.icon,
description: plugin.description,
author: 'newbie',
homepage: `${WEB}/${plugin.repo}`,
repository: { url: `${WEB}/${plugin.repo}` },
metadata: { keywords: plugin.keywords, labels: [], sortKeys: {} },
versions: [
{
version: version,
publishTimestamp: timestamp,
source: { type: 'git', url: `${WEB}/${plugin.repo}`, commit: commit },
engines: {},
},
],
})
console.log(`${plugin.name} ${version} @ ${String(commit).slice(0, 8)}${pinned ? ' (release-manifest)' : ' (live)'}`)
}
const index = {
format: 1,
title: 'QQ 插件索引',
description: 'newbie 的 DSH 插件索引:QQ-dsh 全家桶及其四个组件,源码托管在 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}`)