dsh-publish-helper 0.21.6 → 0.22.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
@@ -2,6 +2,10 @@
2
2
 
3
3
  DSH 插件上架 / 发布 / 撤回助手:发现、检查、生成 entry、开 PR、一键发布 npm、按版本撤回。
4
4
 
5
+ ## 自带技能
6
+
7
+ 插件在运行时注册 **`publish-release`** 技能(按需加载,不占常驻 token):preflight → 收录检查 → 建仓库 → npm 发布(staging 审核)→ entry/PR → 撤回。含 BOM、占名、stale fork、2FA 限制等坑。
8
+
5
9
  ## 安装
6
10
 
7
11
  ```bash
@@ -72,6 +76,21 @@ submissions/<pkg>/
72
76
  - 报告缓存到 `~/.dsh/publish-helper-reviews.json`,关掉面板也能再看
73
77
  - 「打开 PR」跳到 GitHub 做最终 review / Merge
74
78
 
79
+ ## 无账号入口(收件箱)
80
+
81
+ 作者没有 GitHub 账号时,把 zip 放进收件箱目录即可:
82
+
83
+ ```text
84
+ ~/.dsh/publish-helper-inbox/
85
+ ```
86
+
87
+ 面板「提交入口(无账号)」或工具 `publish_intake`:
88
+
89
+ - 扫描收件箱
90
+ - 对 zip 做**安全解压**(先校验条目,拒绝 `..`/绝对路径/盘符)
91
+ - 自动跑 `publish_preflight`
92
+ - **只读,不执行任何包代码**
93
+
75
94
  ## 一键发布(面板)
76
95
 
77
96
  一个包一次,点一下就完成「自检 + 发布」:
package/client.js CHANGED
@@ -72,6 +72,11 @@ window.__ModuleLoader__.load({
72
72
  const [historyError, setHistoryError] = React.useState('');
73
73
  const [historyPr, setHistoryPr] = React.useState(null);
74
74
  const [historyReport, setHistoryReport] = React.useState('');
75
+ const [intakeDir, setIntakeDir] = React.useState('');
76
+ const [intakeItems, setIntakeItems] = React.useState([]);
77
+ const [intakeBusy, setIntakeBusy] = React.useState(false);
78
+ const [intakeError, setIntakeError] = React.useState('');
79
+ const [intakeResult, setIntakeResult] = React.useState(null);
75
80
 
76
81
  React.useEffect(() => {
77
82
  fetch('/dsh-publish-helper/config')
@@ -102,6 +107,7 @@ window.__ModuleLoader__.load({
102
107
  React.useEffect(() => {
103
108
  loadQueue();
104
109
  loadHistory();
110
+ loadIntake();
105
111
  }, []);
106
112
 
107
113
  const polling = shouldPoll(queue, reviewBusy);
@@ -126,6 +132,42 @@ window.__ModuleLoader__.load({
126
132
  }
127
133
  };
128
134
 
135
+ const loadIntake = async () => {
136
+ setIntakeBusy(true);
137
+ setIntakeError('');
138
+ try {
139
+ const response = await fetch('/dsh-publish-helper/intake');
140
+ const data = await response.json();
141
+ if (!response.ok) throw new Error(String(data.error ?? `HTTP ${response.status}`));
142
+ setIntakeDir(data.dir ?? '');
143
+ setIntakeItems(data.items ?? []);
144
+ } catch (cause) {
145
+ setIntakeError(String(cause));
146
+ } finally {
147
+ setIntakeBusy(false);
148
+ }
149
+ };
150
+
151
+ const runIntake = async (zip) => {
152
+ setIntakeBusy(true);
153
+ setIntakeError('');
154
+ setIntakeResult(null);
155
+ try {
156
+ const response = await fetch('/dsh-publish-helper/intake', {
157
+ method: 'POST',
158
+ headers: { 'Content-Type': 'application/json' },
159
+ body: JSON.stringify({ zip }),
160
+ });
161
+ const data = await response.json();
162
+ if (!response.ok) throw new Error(String(data.error ?? `HTTP ${response.status}`));
163
+ setIntakeResult(data);
164
+ } catch (cause) {
165
+ setIntakeError(String(cause));
166
+ } finally {
167
+ setIntakeBusy(false);
168
+ }
169
+ };
170
+
129
171
  const runReview = async (pr) => { setSelectedPr(pr);
130
172
  setReviewBusy(true);
131
173
  setReviewReport('');
@@ -257,6 +299,36 @@ window.__ModuleLoader__.load({
257
299
  h('div', { style: { ...mono, opacity: 0.8 } }, githubLine),
258
300
  h('div', { style: { ...mono, opacity: 0.8 } }, npmLine),
259
301
 
302
+ h('details', { style: { borderTop: '1px solid rgba(127,127,127,.3)', paddingTop: '8px' } },
303
+ h('summary', { style: summary },
304
+ '提交入口(无账号)' + (intakeItems.length ? '(' + intakeItems.length + ')' : '')),
305
+ h('div', { style: { display: 'grid', gap: '6px', marginTop: '8px' } },
306
+ h('div', { style: { ...mono, opacity: 0.7 } }, '收件箱:' + (intakeDir || '…')),
307
+ h('div', { style: { display: 'flex', gap: '8px' } },
308
+ h('button', { onClick: loadIntake, disabled: intakeBusy }, intakeBusy ? '扫描中…' : '扫描收件箱')),
309
+ intakeError ? h('p', { style: { color: 'crimson', margin: 0 } }, intakeError) : null,
310
+ intakeItems.length === 0
311
+ ? h('div', { style: { ...mono, opacity: 0.7 } }, '收件箱为空:把作者发来的 zip 放进上面的目录')
312
+ : null,
313
+ ...intakeItems.map((item) => h('div', {
314
+ key: item.path,
315
+ style: { display: 'grid', gap: '2px', padding: '6px 0', borderTop: '1px solid rgba(127,127,127,.15)' },
316
+ },
317
+ h('div', { style: { fontSize: '13px' } }, item.name + (item.directory ? '(目录)' : '')),
318
+ h('div', { style: { ...mono, opacity: 0.7 } }, item.size + 'B · ' + item.updatedAt),
319
+ String(item.name).toLowerCase().endsWith('.zip')
320
+ ? h('button', { onClick: () => runIntake(item.path), disabled: intakeBusy }, '导入并预检')
321
+ : null)),
322
+ intakeResult
323
+ ? h('div', { style: { display: 'grid', gap: '3px', marginTop: '4px' } },
324
+ h('div', { style: { ...mono, opacity: 0.8 } }, 'extracted: ' + intakeResult.dir),
325
+ ...(intakeResult.checks ?? []).map((entry) => h('div', {
326
+ key: entry.id,
327
+ style: { ...mono, color: entry.ok ? 'inherit' : 'crimson' },
328
+ }, `${entry.ok ? 'OK ' : 'FAIL'} ${entry.id} — ${entry.detail}`)))
329
+ : null),
330
+ ),
331
+
260
332
  h('details', { open: true, style: { borderTop: '1px solid rgba(127,127,127,.3)', paddingTop: '8px' } },
261
333
  h('summary', { style: summary },
262
334
  '审核队列' + (queue ? '(' + queue.length + ')' : '') + (queueBusy ? ' · 刷新中…' : '')),
package/index.js CHANGED
@@ -8,7 +8,9 @@ import { readLocalConfig, writeLocalConfig } from './lib/config.mjs';
8
8
  import { readNpmrcToken } from './lib/credentials.mjs';
9
9
  import { checkPlugin, repoFromUrl, resolveRepo, searchTopic } from './lib/discover.mjs';
10
10
  import { AGENT_GUIDE, SECTION_NAME, SUBMISSION_SPEC } from './lib/guide.mjs';
11
+ import { SKILL_REGISTRATION } from './lib/skill.mjs';
11
12
  import { appendPublishLog } from './lib/log.mjs';
13
+ import { inboxDir, intakeZip, listInbox } from './lib/intake.mjs';
12
14
  import { npmrcLine, publishArgs, recallArgs } from './lib/npm.mjs';
13
15
  import { DEFAULT_ORG, orgArgs } from './lib/org.mjs';
14
16
  import { preflightPackage } from './lib/preflight.mjs';
@@ -33,7 +35,7 @@ function normalize(raw) {
33
35
  ? source.registryRepo.trim()
34
36
  : DEFAULT_REGISTRY_REPO,
35
37
  guide: source.guide !== false,
36
- publishingMode: source.publishingMode === 'author' ? 'author' : 'maintainer',
38
+ publishingMode: source.publishingMode === 'maintainer' ? 'maintainer' : 'author',
37
39
  maintainer: typeof source.maintainer === 'string' && source.maintainer.trim()
38
40
  ? source.maintainer.trim()
39
41
  : 'fubai-fenzhi',
@@ -242,6 +244,10 @@ export function apply(ctx, rawConfig) {
242
244
  });
243
245
  }
244
246
 
247
+ // The release SOP is loaded on demand as a skill instead of living in the prompt.
248
+ const skills = ctx.get('skills');
249
+ if (skills) ctx.effect(() => skills.register(SKILL_REGISTRATION));
250
+
245
251
  ctx.tools.register({
246
252
  name: 'publish_discover',
247
253
  description: 'Search GitHub repositories carrying the dsh-plugin topic, ranked by stars. Use it to find plugins or to confirm a plugin is discoverable by topic.',
@@ -366,7 +372,7 @@ export function apply(ctx, rawConfig) {
366
372
 
367
373
  ctx.tools.register({
368
374
  name: 'publish_npm',
369
- description: 'Publish a package directory to npm now with the resolved npm token (npm publish --access public). Use it after bumping the version; pass otp when the token does not bypass 2FA.',
375
+ description: 'Publish a package directory to npm now with the resolved npm token (npm publish --ignore-scripts --access public). Use it after bumping the version; pass otp when the token does not bypass 2FA.',
370
376
  parameters: objectSchema({
371
377
  dir: { type: 'string', description: 'Absolute package directory to publish.' },
372
378
  tag: { type: 'string', description: 'npm dist-tag (default: latest).' },
@@ -592,6 +598,34 @@ export function apply(ctx, rawConfig) {
592
598
  presentCall: present('Review submission'),
593
599
  });
594
600
 
601
+ ctx.tools.register({
602
+ name: 'publish_intake',
603
+ description: 'List the local submission inbox, or safely extract a zip into it and run preflight. Nothing is executed.',
604
+ parameters: objectSchema({
605
+ zip: { type: 'string', description: 'Absolute path to a zip in the inbox; omitted lists the inbox.' },
606
+ }),
607
+ output: textOutput,
608
+ async execute(args) {
609
+ const dir = inboxDir();
610
+ if (!args.zip) {
611
+ const items = listInbox(dir);
612
+ const lines = [`inbox: ${dir}`];
613
+ if (items.length === 0) lines.push('(empty)');
614
+ for (const item of items) {
615
+ lines.push(`${item.directory ? 'dir' : 'zip'}\t${item.name}\t${item.size}B`);
616
+ }
617
+ return { text: lines.join('\n') };
618
+ }
619
+ const result = await intakeZip({ zip: String(args.zip), root: dir, run: runCommand });
620
+ const lines = [`extracted: ${result.dir}`, result.preflight.ok ? 'PASS' : 'FAIL'];
621
+ for (const check of result.preflight.checks.filter((item) => !item.ok)) {
622
+ lines.push(`FAIL ${check.id}: ${check.detail}`);
623
+ }
624
+ return { text: lines.join('\n') };
625
+ },
626
+ presentCall: present('Intake submission'),
627
+ });
628
+
595
629
  ctx.tools.register({
596
630
  name: 'publish_spec',
597
631
  description: 'Return the DSH plugin submission spec: required package fields, forbidden patterns, publish flow and recall rules.',
@@ -720,6 +754,43 @@ export function apply(ctx, rawConfig) {
720
754
  },
721
755
  }));
722
756
 
757
+ ctx.effect(() => ctx.webServer.register({
758
+ kind: 'exact',
759
+ path: '/dsh-publish-helper/intake',
760
+ handler: async (req, res) => {
761
+ res.setHeader('Content-Type', 'application/json');
762
+ const dir = inboxDir();
763
+ try {
764
+ if (req.method === 'GET') {
765
+ res.end(JSON.stringify({ dir, items: listInbox(dir) }));
766
+ return;
767
+ }
768
+ if (req.method === 'POST') {
769
+ let raw = '';
770
+ for await (const chunk of req) raw += chunk;
771
+ const body = JSON.parse(raw || '{}');
772
+ if (typeof body.zip !== 'string' || !body.zip.trim()) {
773
+ res.statusCode = 400;
774
+ res.end(JSON.stringify({ error: 'zip path is required' }));
775
+ return;
776
+ }
777
+ const result = await intakeZip({ zip: body.zip.trim(), root: dir, run: runCommand });
778
+ res.end(JSON.stringify({
779
+ ok: result.preflight.ok,
780
+ dir: result.dir,
781
+ checks: result.preflight.checks,
782
+ }));
783
+ return;
784
+ }
785
+ res.statusCode = 405;
786
+ res.end(JSON.stringify({ error: 'method not allowed' }));
787
+ } catch (error) {
788
+ res.statusCode = 400;
789
+ res.end(JSON.stringify({ error: String(error) }));
790
+ }
791
+ },
792
+ }));
793
+
723
794
  ctx.effect(() => ctx.webServer.register({
724
795
  kind: 'exact',
725
796
  path: '/dsh-publish-helper/review-queue',
package/lib/guide.mjs CHANGED
@@ -9,7 +9,7 @@ export const AGENT_GUIDE = `DSH 插件提交与发布规范(publish-helper 已
9
9
  - 禁止:preinstall/install/postinstall/prepare 脚本、混淆代码、无人维护或近似包名的依赖;依赖必须锁定。
10
10
  - 流程:提交用 publish_submit(本地包 → 开 PR);审核用 publish_review(拉 PR + preflight + 回贴报告);发布前 publish_preflight PASS → publish_check →(本地目录)publish_prepare → publish_workflow 或 publish_npm → publish_entry → publish_pr;只发审核过的 commit,发布前人工审核。
11
11
  - 不保存他人的账号或 token;token 只存本机。
12
- - 本服务默认「作者没有账号」:作者交包 + SUBMISSION.md,由维护者代提 PR、代发 npm(署名保留作者);有账号自行发布只是例外。
12
+ - 账号:有 GitHub 可自助提交(author 模式);没有则走无账号入口(文件交维护者,由维护者代提代发,署名写作者)。
13
13
  - 账号:有 GitHub 自己开 PR,没有则文件交接由维护者代提(PR 作者为维护者,署名写作者);npm 同理可授权代发;不代注册账号。
14
14
  - 撤回:deprecate(随时,打警告)/ unpublish(仅该版本发布 72 小时内)/ dist-tag 回滚到干净版本(无时间限制)。
15
15
  - 完整规范:调用 publish_spec 工具。`;
@@ -33,11 +33,12 @@ export const SUBMISSION_SPEC = `# DSH 插件提交规范
33
33
  ## 2. 提交方式
34
34
  - 本地/私聊:包目录或 zip + SUBMISSION.md
35
35
  - 或向 https://github.com/fubai-fenzhi/dsh-plugin-submissions 开 PR:新增 submissions/<包名>/(包 + SUBMISSION.md),CI 自动跑 preflight
36
- - 默认路线(作者没有账号):
37
- - 作者提供:包目录/zip + SUBMISSION.md(含代提/代发授权)
36
+ - 有账号(自助):
37
+ - GitHub:自己运行 publish_submit 开 PR
38
+ - npm:自己 publish;或 npm owner add fubai-fenzhi 给维护者撤回权
39
+ - 无账号(入口):
40
+ - 作者把包/zip + SUBMISSION.md 交给维护者(接收渠道见 dsh-plugin-submissions 仓库 README)
38
41
  - 维护者:publish_preflight → 人工审 → publish_submit(维护者 GitHub)→ publish_npm(维护者 npm)
39
- - 所有提交与发布都由维护者账号(fubai-fenzhi)执行,署名仍写作者
40
- - 例外:作者有账号想自己发,请自行使用本工具(author 模式),不属本服务
41
42
  - 账号是平台要求:不代注册、不代管账号
42
43
 
43
44
  ## 3. 交接单 SUBMISSION.md
package/lib/intake.mjs ADDED
@@ -0,0 +1,66 @@
1
+ import { existsSync, mkdirSync, readdirSync, statSync } from 'node:fs';
2
+ import { basename, join } from 'node:path';
3
+ import { homedir } from 'node:os';
4
+
5
+ import { preflightPackage } from './preflight.mjs';
6
+
7
+ export function inboxDir(home = homedir(), custom) {
8
+ return custom || join(home, '.dsh', 'publish-helper-inbox');
9
+ }
10
+
11
+ /** Reject absolute paths, drive letters and `..` segments before extracting an archive. */
12
+ export function isSafeEntry(name) {
13
+ const normalized = String(name ?? '').replaceAll('\\', '/').trim();
14
+ if (!normalized) return false;
15
+ if (normalized.startsWith('/')) return false;
16
+ if (/^[A-Za-z]:/.test(normalized)) return false;
17
+ return !normalized.split('/').includes('..');
18
+ }
19
+
20
+ /** List zip archives (and already-extracted directories) waiting in the inbox. */
21
+ export function listInbox(dir = inboxDir()) {
22
+ mkdirSync(dir, { recursive: true });
23
+ const items = [];
24
+ for (const entry of readdirSync(dir)) {
25
+ const full = join(dir, entry);
26
+ const stat = statSync(full);
27
+ items.push({
28
+ name: entry,
29
+ path: full,
30
+ size: stat.isDirectory() ? 0 : stat.size,
31
+ directory: stat.isDirectory(),
32
+ updatedAt: stat.mtime.toISOString(),
33
+ });
34
+ }
35
+ return items.sort((left, right) => String(right.updatedAt).localeCompare(String(left.updatedAt)));
36
+ }
37
+
38
+ /**
39
+ * Extract a zip into `dest` using bsdtar, after validating every entry name.
40
+ * `run` is injected (the host uses runCommand) so this stays testable.
41
+ */
42
+ export async function safeExtractZip({ zip, dest, run }) {
43
+ const list = await run('tar', ['-tf', zip]);
44
+ if (list.code !== 0) {
45
+ throw new Error(`cannot list archive ${zip}: ${String(list.stderr || '').slice(-500)}`);
46
+ }
47
+ const entries = String(list.stdout ?? '').split(/\r?\n/).filter(Boolean);
48
+ const unsafe = entries.filter((entry) => !isSafeEntry(entry));
49
+ if (unsafe.length > 0) {
50
+ throw new Error(`archive contains unsafe paths: ${unsafe.slice(0, 5).join(', ')}`);
51
+ }
52
+ mkdirSync(dest, { recursive: true });
53
+ const extract = await run('tar', ['-xf', zip, '-C', dest]);
54
+ if (extract.code !== 0) {
55
+ throw new Error(`cannot extract ${zip}: ${String(extract.stderr || '').slice(-500)}`);
56
+ }
57
+ return entries.length;
58
+ }
59
+
60
+ /** Extract one inbox zip and run preflight on it. Nothing is executed. */
61
+ export async function intakeZip({ zip, root = inboxDir(), run, preflight = preflightPackage } = {}) {
62
+ if (!existsSync(zip)) throw new Error(`archive not found: ${zip}`);
63
+ const target = join(root, basename(zip).replace(/\.zip$/i, ''));
64
+ await safeExtractZip({ zip, dest: target, run });
65
+ return { dir: target, preflight: preflight(target) };
66
+ }
package/lib/skill.mjs ADDED
@@ -0,0 +1,41 @@
1
+ export const SKILL_NAME = 'publish-release';
2
+
3
+ export const SKILL_DESCRIPTION = 'Publish a DSH plugin end to end: preflight, listing check, GitHub repo upload, npm publish with staging approval, registry entry and PR, plus rollback of a broken version.';
4
+
5
+ export const SKILL_CONTENT = `# DSH plugin release workflow
6
+
7
+ Use this skill when the user asks to publish, release, or list a DSH plugin on npm / GitHub / awesome-dsh-plugin.
8
+
9
+ ## Preconditions
10
+
11
+ - The package directory is final: \`package.json\` has name, version, description, license, repository, homepage, keywords and \`dsh.bundle.patch\`; README and LICENSE exist.
12
+ - A GitHub token and an npm token are already stored locally. Never print them.
13
+ - npm publishing may land in the Staged queue (bypass-2FA granular tokens): the user has to approve the version on npmjs.com before it becomes \`latest\`.
14
+
15
+ ## Steps
16
+
17
+ 1. \`publish_preflight\` on the directory. Fix every FAIL before continuing.
18
+ 2. \`publish_check\` with the repo and package name. Topics, bundle, npm backlink and registry entry are the usual failures.
19
+ 3. If the GitHub repository does not exist, create/upload it with \`publish_repo\`.
20
+ 4. Publish with \`publish_npm\`. If npm asks for a 2FA code, pass \`otp\`.
21
+ 5. Ask the user to approve the staged version, then confirm with the registry that \`dist-tags.latest\` points at it.
22
+ 6. Generate the registry entry with \`publish_entry\` and open the PR with \`publish_pr\`. The awesome repo's submission gate requires the repository to be at least one day old, so a fresh repo fails the first run and passes after the gate re-runs.
23
+ 7. Add or update a format-1 index when the user maintains one (a \`index.json\` with a \`plugins\` list).
24
+ 8. For a broken release: \`publish_recall\` with \`deprecate\` (always available) or \`unpublish\` (only within 72 hours and only with a token that satisfies npm's 2FA policy).
25
+
26
+ ## Pitfalls
27
+
28
+ - A package name can already belong to someone else; check the registry before choosing, and rename both package and repository when needed.
29
+ - Writing files with PowerShell \`Set-Content -Encoding UTF8\` adds a BOM and breaks JSON parsing; write with the file-write tool or strip the BOM before publishing.
30
+ - A stale fork makes \`publish_pr\` include unrelated files; rebuild a clean branch from upstream HEAD and open a fresh PR with only the new entry.
31
+ - Granular tokens that bypass 2FA cannot unpublish and are restricted for account changes and direct publishing; prefer OTP or GitHub Actions trusted publishing for the long term.
32
+ - Publishing is irreversible enough to require a user confirmation before the npm publish step.
33
+ `;
34
+
35
+ export const SKILL_REGISTRATION = {
36
+ name: SKILL_NAME,
37
+ description: SKILL_DESCRIPTION,
38
+ whenToUse: 'when the user asks to publish, release, or list a DSH plugin',
39
+ source: 'custom',
40
+ content: SKILL_CONTENT,
41
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-publish-helper",
3
- "version": "0.21.6",
3
+ "version": "0.22.0",
4
4
  "description": "DSH plugin publishing assistant: discover by topic, check listing readiness, generate the registry entry, open the pull request and show a settings page.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -9,11 +9,11 @@
9
9
 
10
10
  ## 账号状态
11
11
 
12
- - 是否有 GitHub 账号:否(如有请填 handle:)
13
- - 是否有 npm 账号:否(如有请填 handle:)
14
- - 提交方式:请维护者代提(默认)/ 自己开 PR(不属本服务)
15
- - 发布方式:统一由维护者代发(默认)
16
- - 代提/代发授权(必填):允许维护者代开 PR、代发 npm、保留作者署名、可随时下架/转回
12
+ - 是否有 GitHub 账号:是 / 否(handle:)
13
+ - 是否有 npm 账号:是 / 否(handle:)
14
+ - 提交方式:自己开 PR / 请维护者代提
15
+ - 发布方式:自己发 npm / 统一由维护者代发
16
+ - 代提/代发授权(选「请维护者」时必填):允许维护者代开 PR、代发 npm、保留作者署名、可随时下架/转回
17
17
 
18
18
  ## 源码
19
19