dsh-publish-helper 0.22.0 → 0.23.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
@@ -6,6 +6,14 @@ DSH 插件上架 / 发布 / 撤回助手:发现、检查、生成 entry、开
6
6
 
7
7
  插件在运行时注册 **`publish-release`** 技能(按需加载,不占常驻 token):preflight → 收录检查 → 建仓库 → npm 发布(staging 审核)→ entry/PR → 撤回。含 BOM、占名、stale fork、2FA 限制等坑。
8
8
 
9
+ ## 模板与指南
10
+
11
+ - `templates/skill-plugin/`:**技能 + 插件**搭配模板,复制即用
12
+ - `templates/release.yml`:GitHub Actions 发版工作流
13
+ - `docs/plugin-vs-skill.md`:插件 vs 技能选型一页指南
14
+
15
+ `publish_workflow` 默认写 **trusted publishing** 工作流(GitHub OIDC,无需长期 token);需要 secret 时传 `mode: "token"`。
16
+
9
17
  ## 安装
10
18
 
11
19
  ```bash
@@ -0,0 +1,79 @@
1
+ # DSH 插件 vs 技能:怎么选
2
+
3
+ > 一页判断:**动作进插件,流程进技能;能只做技能就不做插件。**
4
+
5
+ ## 1. 两者是什么
6
+
7
+ | | 插件(bundle) | 技能(SKILL.md / runtime skill) |
8
+ |---|---|---|
9
+ | 本质 | 代码:注册工具、钩子、UI、HTTP 路由 | 文档:触发条件 + 步骤 + 坑 |
10
+ | 能执行动作 | ✅ 直接调 API / spawn / 写文件 | ❌ 只能教模型自己拼 shell |
11
+ | 常驻成本 | 工具 schema + 提示,**每轮都付费** | **0**(不命中不加载) |
12
+ | 加载成本 | 低(已常驻) | 命中一次约 500–800 token |
13
+ | 跨 agent | 仅 DSH | 任何 agent 都能读 |
14
+ | 安装 | 需安装 bundle | 复制文件即可 |
15
+ | 安全边界 | 代码里做默认值/校验/确认 | 只能"建议",模型可能不听 |
16
+
17
+ ## 2. 决策树
18
+
19
+ ```text
20
+ 要做的事需要「执行动作」吗?
21
+ ├─ 否 → 只做技能(0 常驻成本)
22
+ └─ 是 → 这个动作使用频率高吗?
23
+ ├─ 高(每轮都可能用) → 插件
24
+ ├─ 低(偶尔用一次) → 技能 + 轻量 CLI,或 技能 + 插件(插件可禁)
25
+ └─ 需要 UI/安全默认/复杂编排 → 插件
26
+ ```
27
+
28
+ ## 3. Token 账(关键)
29
+
30
+ | 方案 | 常驻/轮 | 用一次的成本 |
31
+ |---|---|---|
32
+ | 插件(3 个工具) | ~700–900 token | 工具调用输出 |
33
+ | 技能 | 0 | ~600 token(加载)+ 命令输出 |
34
+ | 技能 + 插件 | ~700–900 | ~600 + 调用 |
35
+
36
+ 结论:
37
+ - **低频动作**(发视频、发版)→ 技能优先,插件按需启用
38
+ - **高频/必须自动触发**(报错钩子、记忆)→ 插件
39
+ - **不要把流程塞进插件描述**:描述只写"做什么/参数",流程写进技能
40
+
41
+ ## 4. 推荐模式:一套双形态
42
+
43
+ ```text
44
+ your-plugin/
45
+ ├── index.js # 工具:原子动作(硬约束、安全默认)
46
+ ├── lib/skill.mjs # 技能:流程 + 坑(ctx.skills.register)
47
+ ├── skills/ # 可选:给非 DSH agent 的 SKILL.md 副本
48
+ └── README.md
49
+ ```
50
+
51
+ - 装插件 = 动作 + 技能一起到位
52
+ - 只装技能(复制文件)= 没有硬约束,但跨 agent
53
+ - DSH 里用 `ctx.skills.register()` 注册,零常驻
54
+
55
+ ## 5. 判断清单
56
+
57
+ 写代码前问:
58
+
59
+ - [ ] 这个动作必须由代码保证吗?(安全默认、校验、重试、API 签名)
60
+ - [ ] 模型每轮都会用到它吗?(是 → 插件,否 → 技能)
61
+ - [ ] 流程里有没有"绝对不能做"的步骤?→ 放进代码,不要只写文档
62
+ - [ ] 技能超过 2k 字了吗?→ 拆成多个技能或引用按需加载的文件
63
+ - [ ] 另一个 agent(Claude Code 等)也要用吗?→ 保留一份 `skills/` 文本
64
+
65
+ ## 6. 常见错误
66
+
67
+ | 错误 | 后果 | 修法 |
68
+ |---|---|---|
69
+ | 把长流程写进插件系统提示 | 每轮付费,改一次要发版 | 移到技能 |
70
+ | 只做技能却需要安全默认 | 模型可能误操作 | 关键约束放插件 |
71
+ | 插件塞很多低频工具 | schema 常驻浪费 | 拆包或改成技能 + CLI |
72
+ | 技能里写"硬规则" | 模型可能忽略 | 代码里强制 |
73
+ | 技能互相引用大段文档 | 加载成本失控 | 只放步骤,细节按需读 |
74
+
75
+ ## 7. 参考实现
76
+
77
+ - `dsh-bilibili-upload`:工具 `bili_upload`/`bili_edit` + 技能 `bilibili-upload`
78
+ - `dsh-publish-helper`:发布工具集 + 技能 `publish-release`
79
+ - 模板:`templates/skill-plugin/`(复制即用)
package/index.js CHANGED
@@ -9,6 +9,7 @@ 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
11
  import { SKILL_REGISTRATION } from './lib/skill.mjs';
12
+ import { WORKFLOW_MODES, workflowText } from './lib/workflow.mjs';
12
13
  import { appendPublishLog } from './lib/log.mjs';
13
14
  import { inboxDir, intakeZip, listInbox } from './lib/intake.mjs';
14
15
  import { npmrcLine, publishArgs, recallArgs } from './lib/npm.mjs';
@@ -475,19 +476,24 @@ export function apply(ctx, rawConfig) {
475
476
 
476
477
  ctx.tools.register({
477
478
  name: 'publish_workflow',
478
- description: 'Write the GitHub Actions trusted-publishing workflow into a local package directory (.github/workflows/release.yml).',
479
+ description: 'Write the GitHub Actions release workflow into a local package directory (.github/workflows/release.yml). Default mode trusted: npm publishes through GitHub OIDC with provenance and no long-lived token; mode token injects NODE_AUTH_TOKEN from the NPM_TOKEN secret.',
479
480
  parameters: objectSchema({
480
481
  dir: { type: 'string', description: 'Absolute package directory.' },
482
+ mode: { type: 'string', enum: WORKFLOW_MODES, description: 'trusted (default, needs npm Trusted Publisher) or token (needs the NPM_TOKEN secret).' },
481
483
  }, ['dir']),
482
484
  output: textOutput,
483
485
  async execute(args) {
484
486
  const directory = String(args.dir);
485
487
  if (!existsSync(join(directory, 'package.json'))) throw new Error(`no package.json in ${directory}`);
486
- const template = readFileSync(new URL('./templates/release.yml', import.meta.url), 'utf8');
488
+ const mode = args.mode ?? 'trusted';
489
+ const template = workflowText(mode);
487
490
  const target = join(directory, '.github', 'workflows', 'release.yml');
488
491
  mkdirSync(dirname(target), { recursive: true });
489
492
  writeFileSync(target, template, 'utf8');
490
- return { text: `wrote ${target}` };
493
+ const hint = mode === 'trusted'
494
+ ? 'configure npm -> package -> Settings -> Trusted publishing (GitHub Actions, this repo, release.yml), then push a v* tag'
495
+ : 'add the repository secret NPM_TOKEN, then push a v* tag';
496
+ return { text: `wrote ${target}\nmode: ${mode}\nnext: ${hint}` };
491
497
  },
492
498
  presentCall: present('Write release workflow'),
493
499
  });
@@ -0,0 +1,18 @@
1
+ import { readFileSync } from 'node:fs';
2
+
3
+ export const WORKFLOW_MODES = ['trusted', 'token'];
4
+
5
+ const TEMPLATE = readFileSync(new URL('../templates/release.yml', import.meta.url), 'utf8');
6
+
7
+ /**
8
+ * Render the release workflow.
9
+ * trusted: no NODE_AUTH_TOKEN; npm uses GitHub OIDC (Trusted Publisher must be configured on npm).
10
+ * token: inject NODE_AUTH_TOKEN from the repository secret NPM_TOKEN.
11
+ */
12
+ export function workflowText(mode = 'trusted') {
13
+ if (!WORKFLOW_MODES.includes(mode)) throw new Error(`unknown mode: ${mode} (use ${WORKFLOW_MODES.join(' or ')})`);
14
+ const env = mode === 'token'
15
+ ? ' env:\n NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}\n'
16
+ : '';
17
+ return TEMPLATE.replace('__NODE_AUTH_ENV__\n', env);
18
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-publish-helper",
3
- "version": "0.22.0",
3
+ "version": "0.23.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",
@@ -53,6 +53,7 @@
53
53
  "cordis.patch.yml",
54
54
  "README.md",
55
55
  "templates",
56
+ "docs",
56
57
  "LICENSE"
57
58
  ]
58
59
  }
@@ -1,12 +1,18 @@
1
1
  # Copy to .github/workflows/release.yml in the package repository.
2
2
  #
3
- # Token publishing (default here):
4
- # add a repository secret NPM_TOKEN = granular npm token
5
- # (Read and write, Bypass 2FA; never commit it) and push a tag.
3
+ # Two publishing modes (pick one):
6
4
  #
7
- # Trusted publishing alternative (no token, needs account 2FA on npm):
8
- # package page -> Settings -> Trusted publishing -> GitHub Actions
9
- # then remove the NODE_AUTH_TOKEN env from the publish step.
5
+ # trusted (default, no long-lived token):
6
+ # 1. npm package page -> Settings -> Trusted publishing -> GitHub Actions,
7
+ # publisher = this repository, workflow = release.yml, environment = (empty)
8
+ # 2. push a v* tag; npm exchanges the GitHub OIDC token for a short-lived credential
9
+ #
10
+ # token (fallback):
11
+ # add a repository secret NPM_TOKEN = granular npm token
12
+ # (Read and write, Bypass 2FA; never commit it) and push a v* tag
13
+ #
14
+ # Granular tokens that bypass 2FA cannot unpublish and are being restricted for
15
+ # direct publishing, so prefer trusted publishing when the npm account has 2FA.
10
16
  name: release
11
17
 
12
18
  on:
@@ -17,7 +23,7 @@ on:
17
23
 
18
24
  permissions:
19
25
  contents: read
20
- id-token: write # provenance attestation
26
+ id-token: write # required for provenance and trusted publishing
21
27
 
22
28
  jobs:
23
29
  publish:
@@ -59,5 +65,4 @@ jobs:
59
65
 
60
66
  - name: Publish with provenance
61
67
  run: npm publish --provenance --access public --ignore-scripts
62
- env:
63
- NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
68
+ __NODE_AUTH_ENV__
@@ -0,0 +1,22 @@
1
+ # skill-plugin template
2
+
3
+ A DSH bundle that pairs **one tool** with **one on-demand skill**.
4
+
5
+ - Tool: `example_do_task` — the atomic action, registered with `ctx.tools.register`.
6
+ - Skill: `example-task` — the workflow and pitfalls, registered with `ctx.skills.register`.
7
+ - The skill is only loaded when the model needs it, so it adds no resident prompt tokens.
8
+
9
+ ## Use it
10
+
11
+ 1. Copy this directory into your workspace.
12
+ 2. Rename `dsh-example-skill-plugin` / `example-skill-plugin` / `example_do_task` / `example-task` everywhere (package.json, cordis.patch.yml, index.js, lib/skill.mjs).
13
+ 3. Replace the tool logic and the skill content.
14
+ 4. Add LICENSE and a real README.
15
+ 5. Install: `plugin_manager` `install_bundle` with this directory, or publish with `dsh-publish-helper`.
16
+
17
+ ## Rules of thumb
18
+
19
+ - Put **capabilities** in the tool, **process and pitfalls** in the skill.
20
+ - Keep safety defaults in code (the tool); never rely on the skill text for hard constraints.
21
+ - One skill per workflow; do not bundle unrelated workflows into one skill.
22
+ - Skill content should be shorter than ~2k words; move long references to separate files loaded on demand.
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: example-skill-plugin
3
+ name: dsh-example-skill-plugin
@@ -0,0 +1,40 @@
1
+ import { SKILL_REGISTRATION } from './lib/skill.mjs';
2
+
3
+ export const name = 'dsh-example-skill-plugin';
4
+ export const inject = ['tools'];
5
+
6
+ const textOutput = {
7
+ schema: {
8
+ type: 'object',
9
+ additionalProperties: false,
10
+ required: ['text'],
11
+ properties: { text: { type: 'string' } },
12
+ },
13
+ render: (_args, value) => [{ type: 'text', text: value.text }],
14
+ };
15
+
16
+ const present = (title) => (args) => ({ card: 'generic', title, kind: 'other', rawInput: args });
17
+
18
+ function objectSchema(properties, required = []) {
19
+ return { type: 'object', additionalProperties: false, properties, required };
20
+ }
21
+
22
+ export function apply(ctx) {
23
+ // Tool: the atomic action. Keep it small; the how-to lives in the skill.
24
+ ctx.tools.register({
25
+ name: 'example_do_task',
26
+ description: 'Do one example task and return a short result.',
27
+ parameters: objectSchema({
28
+ input: { type: 'string', description: 'What to process.' },
29
+ }, ['input']),
30
+ output: textOutput,
31
+ async execute(args) {
32
+ return { text: `example result for: ${args.input}` };
33
+ },
34
+ presentCall: present('Run example task'),
35
+ });
36
+
37
+ // Skill: loaded on demand (no resident prompt cost), only when the task matches.
38
+ const skills = ctx.get('skills');
39
+ if (skills) ctx.effect(() => skills.register(SKILL_REGISTRATION));
40
+ }
@@ -0,0 +1,18 @@
1
+ export const SKILL_NAME = 'example-task';
2
+
3
+ export const SKILL_CONTENT = `# Example task workflow
4
+
5
+ Use this skill when the user asks for the example task.
6
+
7
+ 1. Check the preconditions with the example tool.
8
+ 2. Do the work with the tool.
9
+ 3. Verify the result and report the identifier.
10
+ `;
11
+
12
+ export const SKILL_REGISTRATION = {
13
+ name: SKILL_NAME,
14
+ description: 'Short, invocation-neutral description of when this workflow applies.',
15
+ whenToUse: 'when the user asks for the example task',
16
+ source: 'custom',
17
+ content: SKILL_CONTENT,
18
+ };
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "dsh-example-skill-plugin",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "description": "Example DSH bundle that pairs one on-demand skill with one tool: replace the names and descriptions, then publish.",
6
+ "license": "MIT",
7
+ "author": "your-npm-name",
8
+ "homepage": "https://github.com/your-npm-name/dsh-example-skill-plugin#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/your-npm-name/dsh-example-skill-plugin.git"
12
+ },
13
+ "keywords": ["dsh", "dsh-plugin", "deepseek-harness"],
14
+ "engines": {
15
+ "node": ">=18",
16
+ "dsh": ">=0.2.1-rc.3"
17
+ },
18
+ "publishConfig": { "access": "public" },
19
+ "exports": { ".": "./index.js" },
20
+ "files": ["index.js", "lib/*.mjs", "cordis.patch.yml", "README.md", "LICENSE"],
21
+ "dsh": {
22
+ "bundle": { "patch": "./cordis.patch.yml" }
23
+ }
24
+ }