jiema-workbuddy-mcp 0.1.12 → 0.1.14

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
@@ -1,6 +1,6 @@
1
1
  # 捷码 WorkBuddy MCP Server
2
2
 
3
- 0.1.12使用协议1,配套技能3.10.3。WorkBuddy 宿主可将本包作为 stdio MCP 服务托管;macOS 独立技能还可通过 npm 用户级安装后用本地 MCP Client 调用,不修改宿主工具配置。保留27个工具;SQL与已有项目配置使用正式预览和保存合同。npm发布以公共 registry 回读为准,市场连接器与独立技能各自验收。
3
+ 0.1.14使用协议1,配套技能3.10.5。WorkBuddy 宿主可将本包作为 stdio MCP 服务托管;技能随包提供同一份 mcpServers 配置,由模型交给 WorkBuddy 原生配置入口;宿主负责 Node/npm、服务进程及工具加载,macOS 和 Windows 使用相同声明。保留27个工具;SQL与已有项目配置使用正式预览和保存合同。npm发布以公共 registry 回读为准,市场连接器与独立技能各自验收。
4
4
 
5
5
  SQL的正式手工决策新增SET_PROJECT_CONFIGURATION和SET_ENTITY_PRESENTATION;评论、游客读取和字段类型复用生成器规则。PUBLIC_CLIENT登录不自动注册,公开内容不扩大角色权限。WorkBuddy仍不调用站内AI或接受ACCEPT_AI_SELECTION。来源和计费边界保持不变。
6
6
 
@@ -28,9 +28,9 @@ npm ci
28
28
  JIEMA_WORKBUDDY_BASE_URL=http://127.0.0.1:3000 node ./bin/server.mjs
29
29
  ```
30
30
 
31
- `JIEMA_WORKBUDDY_BASE_URL` 是 MCP 进程级配置,不由模型通过工具参数修改。正式环境默认 `https://www.jiemaai.com`;HTTP 仅接受回环地址。下载及源码摘要默认仅允许用户主目录下的 `WorkBuddy`,可在 MCP 进程配置 `JIEMA_WORKBUDDY_ALLOWED_ROOTS` 为系统路径分隔符连接的绝对目录列表。macOS 默认将凭据保存在 Keychain,Keychain 不可用时仅保存在当前 MCP 进程内;其他系统目前也仅保留当前会话,重启后须重新授权。旧明文凭据只有迁移到 Keychain 成功才删除;读取时仅进入会话内存会保留旧副本。`XDG_CONFIG_HOME` 只用于隔离设备码状态与图稿回执;设置 `JIEMA_WORKBUDDY_CREDENTIAL_STORE=session` 会主动关闭 Keychain,新授权仅对当前 MCP 进程有效。MCP 服务通过设备码向用户申请授权,不向模型输出凭据。
31
+ `JIEMA_WORKBUDDY_BASE_URL` 是 MCP 进程级配置,不由模型通过工具参数修改。正式环境默认 `https://www.jiemaai.com`;HTTP 仅接受回环地址。下载及源码摘要默认仅允许用户主目录下的 `WorkBuddy`,可在 MCP 进程配置 `JIEMA_WORKBUDDY_ALLOWED_ROOTS` 为系统路径分隔符连接的绝对目录列表。macOS 默认将凭据保存在 Keychain;Windows 默认用当前用户 DPAPI 加密后保存在用户配置目录;安全存储不可用时普通宿主托管模式仅保存在当前 MCP 进程内。重启后须用 connect_status 回读实际授权状态。旧明文凭据只有迁移到对应安全存储成功才删除;读取时仅进入会话内存会保留旧副本。`XDG_CONFIG_HOME` 只用于隔离设备码状态与图稿回执;设置 `JIEMA_WORKBUDDY_CREDENTIAL_STORE=session` 会主动关闭系统安全存储,新授权仅对当前 MCP 进程有效。MCP 服务通过设备码向用户申请授权,不向模型输出凭据。
32
32
 
33
- Keychain 写入通过 `security -i` 的标准输入传递命令,凭据不进入进程参数或磁盘;写后必须逐字回读一致才返回 `credentialStorage:keychain`。非终端环境下向末尾 `-w` 直接管道输入会出现退出码成功却存入空串,不能据退出码删除旧副本。macOS 可用 `JIEMA_WORKBUDDY_TEST_KEYCHAIN=1 npm test` 执行真实钥匙串跨进程回归;测试只创建并清理自身独占的合成条目。
33
+ Keychain 写入通过 `security -i` 的标准输入传递命令,凭据不进入进程参数或磁盘;写后必须逐字回读一致才返回 `credentialStorage:keychain`。Windows 通过 PowerShell DPAPI CurrentUser 加解密,明文只经过标准输入/输出和进程内存,不进入参数或磁盘。非终端环境下向 macOS `-w` 直接管道输入会出现退出码成功却存入空串,不能据退出码删除旧副本。macOS 可用 `JIEMA_WORKBUDDY_TEST_KEYCHAIN=1 npm test` 执行真实钥匙串跨进程回归;Windows 真机回归需在 Windows 用户环境执行。
34
34
 
35
35
  本地 WorkBuddy 自定义连接器可在 `mcpServers` 中配置 `type: "stdio"`、`command: "node"`、绝对脚本路径和 Node runtime。用户在 WorkBuddy 内使用技能与 MCP 工具,无需手工运行上面的调试命令。`connector/mcp.json` 使用固定版本的公开 npm 包;发布前须确认该版本在公共 registry 可获取,并验证平台连接与认证流程。发布状态以 npm 回读和 WorkBuddy 开放平台审核回执为准,本机自定义连接器通过不等于市场上架通过。
36
36
 
@@ -1,8 +1,8 @@
1
- import { createHash } from 'node:crypto'
1
+ import { createHash, randomUUID } from 'node:crypto'
2
2
  import { spawn } from 'node:child_process'
3
- import { readFile, rm } from 'node:fs/promises'
3
+ import { mkdir, readFile, rename, rm, writeFile } from 'node:fs/promises'
4
4
  import { homedir } from 'node:os'
5
- import { join } from 'node:path'
5
+ import { dirname, join } from 'node:path'
6
6
 
7
7
  const SERVICE = 'com.jiema.workbuddy.mcp'
8
8
  const sessionCredentials = new Map()
@@ -23,10 +23,18 @@ export function credentialPath(baseUrl) {
23
23
  return join(configRoot(), `${profile(baseUrl)}.json`)
24
24
  }
25
25
 
26
+ export function protectedCredentialPath(baseUrl) {
27
+ return join(configRoot(), `${profile(baseUrl)}.dpapi`)
28
+ }
29
+
26
30
  function useKeychain() {
27
31
  return process.platform === 'darwin' && process.env.JIEMA_WORKBUDDY_CREDENTIAL_STORE !== 'session'
28
32
  }
29
33
 
34
+ function useWindowsDpapi() {
35
+ return process.platform === 'win32' && process.env.JIEMA_WORKBUDDY_CREDENTIAL_STORE !== 'session'
36
+ }
37
+
30
38
  async function security(args, stdinText) {
31
39
  return new Promise((resolve, reject) => {
32
40
  const child = spawn('/usr/bin/security', args, { stdio: ['pipe', 'pipe', 'pipe'] })
@@ -36,6 +44,7 @@ async function security(args, stdinText) {
36
44
  child.stdout.setEncoding('utf8').on('data', (chunk) => { stdout += chunk })
37
45
  child.stderr.setEncoding('utf8').on('data', (chunk) => { stderr += chunk })
38
46
  child.on('error', (error) => { clearTimeout(timeout); reject(error) })
47
+ child.stdin.on('error', reject)
39
48
  child.on('close', (code) => {
40
49
  clearTimeout(timeout)
41
50
  if (code === 0) resolve(stdout.trimEnd())
@@ -45,6 +54,103 @@ async function security(args, stdinText) {
45
54
  })
46
55
  }
47
56
 
57
+ const POWERSHELL_UTF8 = [
58
+ "$utf8 = New-Object System.Text.UTF8Encoding($false)",
59
+ '[Console]::InputEncoding = $utf8',
60
+ '[Console]::OutputEncoding = $utf8',
61
+ '$OutputEncoding = $utf8',
62
+ ]
63
+
64
+ function powershellExecutable(env = process.env) {
65
+ const root = env.SystemRoot || env.WINDIR
66
+ return root ? join(root, 'System32', 'WindowsPowerShell', 'v1.0', 'powershell.exe') : 'powershell.exe'
67
+ }
68
+
69
+ async function runPowerShell(script, input) {
70
+ const source = [...POWERSHELL_UTF8, "$ErrorActionPreference = 'Stop'", script].join('; ')
71
+ const encoded = Buffer.from(source, 'utf16le').toString('base64')
72
+ return new Promise((resolve, reject) => {
73
+ const child = spawn(powershellExecutable(), [
74
+ '-NoLogo', '-NoProfile', '-NonInteractive', '-EncodedCommand', encoded,
75
+ ], { stdio: ['pipe', 'pipe', 'ignore'], windowsHide: true })
76
+ let stdout = ''
77
+ const timeout = setTimeout(() => child.kill(), 10_000)
78
+ child.stdout.setEncoding('utf8').on('data', (chunk) => {
79
+ stdout += chunk
80
+ if (stdout.length > 1024 * 1024) child.kill()
81
+ })
82
+ child.on('error', () => {
83
+ clearTimeout(timeout)
84
+ reject(new Error('Windows 当前用户凭据保护服务启动失败'))
85
+ })
86
+ child.stdin.on('error', () => reject(new Error('Windows 当前用户凭据保护服务输入失败')))
87
+ child.on('close', (code) => {
88
+ clearTimeout(timeout)
89
+ if (code !== 0 || stdout.length > 1024 * 1024) {
90
+ reject(new Error('Windows 当前用户凭据保护服务失败'))
91
+ return
92
+ }
93
+ resolve(stdout)
94
+ })
95
+ child.stdin.end(input)
96
+ })
97
+ }
98
+
99
+ const DPAPI_PROTECT = [
100
+ '$plain = [Console]::In.ReadToEnd()',
101
+ '$secure = ConvertTo-SecureString -String $plain -AsPlainText -Force',
102
+ '[Console]::Out.Write((ConvertFrom-SecureString -SecureString $secure))',
103
+ ].join('; ')
104
+
105
+ const DPAPI_UNPROTECT = [
106
+ '$encrypted = [Console]::In.ReadToEnd()',
107
+ '$secure = ConvertTo-SecureString -String $encrypted',
108
+ '$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)',
109
+ 'try { $plain = [Runtime.InteropServices.Marshal]::PtrToStringBSTR($ptr); [Console]::Out.Write([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($plain))) } finally { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) }',
110
+ ].join('; ')
111
+
112
+ // DPAPI CurrentUser:明文只经管道与内存,不进入进程参数或文件。
113
+ export function createWindowsCredentialStore({ filePath, run = runPowerShell }) {
114
+ async function decode(encrypted) {
115
+ try {
116
+ const encoded = (await run(DPAPI_UNPROTECT, encrypted)).trim()
117
+ const bytes = Buffer.from(encoded, 'base64')
118
+ if (!encoded || bytes.toString('base64') !== encoded) throw new Error('invalid')
119
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes)
120
+ } catch {
121
+ throw new Error('Windows DPAPI 凭据无法解密;已保留原文件,请在原 Windows 用户配置下恢复。')
122
+ }
123
+ }
124
+ return {
125
+ async read() {
126
+ let encrypted
127
+ try {
128
+ encrypted = (await readFile(filePath, 'utf8')).trim()
129
+ } catch (error) {
130
+ if (error?.code === 'ENOENT') return null
131
+ throw error
132
+ }
133
+ return decode(encrypted)
134
+ },
135
+ async write(credential) {
136
+ const encrypted = (await run(DPAPI_PROTECT, credential)).trim()
137
+ if (!encrypted || await decode(encrypted) !== credential) return false
138
+ await mkdir(dirname(filePath), { recursive: true, mode: 0o700 })
139
+ const temporary = `${filePath}.${randomUUID()}.tmp`
140
+ try {
141
+ await writeFile(temporary, `${encrypted}\n`, { flag: 'wx', mode: 0o600 })
142
+ await rename(temporary, filePath)
143
+ } finally {
144
+ await rm(temporary, { force: true })
145
+ }
146
+ return await this.read() === credential
147
+ },
148
+ async remove() {
149
+ await rm(filePath, { force: true })
150
+ },
151
+ }
152
+ }
153
+
48
154
  function isMissingKeychainItem(error) {
49
155
  return error?.code === 44 || /could not be found|指定的项目不存在|找不到指定的项目/iu.test(error?.message ?? '')
50
156
  }
@@ -80,13 +186,21 @@ export async function readCredential(baseUrl) {
80
186
  if (!isMissingKeychainItem(error)) throw error
81
187
  }
82
188
  }
189
+ if (useWindowsDpapi()) {
190
+ const store = createWindowsCredentialStore({ filePath: protectedCredentialPath(baseUrl) })
191
+ const stored = await store.read()
192
+ if (stored) {
193
+ sessionCredentials.set(baseUrl, stored)
194
+ return stored
195
+ }
196
+ }
83
197
  const legacy = await readLegacyCredential(baseUrl)
84
198
  if (!legacy) return null
85
- // 迁移时先不删旧明文:只有真正落到持久存储(钥匙串)才删。
199
+ // 迁移时先不删旧明文:只有真正落到系统安全存储才删。
86
200
  // 会话内存随进程结束消失,若此时删掉磁盘副本,下一次启动就没有任何可用凭据,
87
201
  // 表现为“刚连上又掉授权”。
88
202
  const storage = await writeCredential(baseUrl, legacy, { dropLegacy: false })
89
- if (storage === 'keychain') await rm(credentialPath(baseUrl), { force: true })
203
+ if (storage === 'keychain' || storage === 'windows-dpapi') await rm(credentialPath(baseUrl), { force: true })
90
204
  return legacy
91
205
  }
92
206
 
@@ -94,6 +208,18 @@ export async function writeCredential(baseUrl, credential, options = {}) {
94
208
  const dropLegacy = options.dropLegacy !== false
95
209
  sessionCredentials.set(baseUrl, credential)
96
210
  if (!useKeychain()) {
211
+ if (useWindowsDpapi()) {
212
+ try {
213
+ const store = createWindowsCredentialStore({ filePath: protectedCredentialPath(baseUrl) })
214
+ if (await store.write(credential)) {
215
+ if (dropLegacy) await rm(credentialPath(baseUrl), { force: true })
216
+ return 'windows-dpapi'
217
+ }
218
+ } catch {
219
+ return 'session'
220
+ }
221
+ return 'session'
222
+ }
97
223
  if (dropLegacy) await rm(credentialPath(baseUrl), { force: true })
98
224
  return 'session'
99
225
  }
@@ -104,7 +230,9 @@ export async function writeCredential(baseUrl, credential, options = {}) {
104
230
  .map(quoteSecurityArgument).join(' ')
105
231
  await security(['-i'], command)
106
232
  const stored = await security(['find-generic-password', '-a', profile(baseUrl), '-s', SERVICE, '-w'])
107
- if (stored !== credential) return 'session'
233
+ if (stored !== credential) {
234
+ return 'session'
235
+ }
108
236
  } catch {
109
237
  // 钥匙串写入失败时只在内存里生效,因此保留磁盘副本,下次启动仍可读取。
110
238
  return 'session'
@@ -116,6 +244,7 @@ export async function writeCredential(baseUrl, credential, options = {}) {
116
244
  export async function removeCredential(baseUrl) {
117
245
  sessionCredentials.delete(baseUrl)
118
246
  await rm(credentialPath(baseUrl), { force: true })
247
+ await rm(protectedCredentialPath(baseUrl), { force: true })
119
248
  if (!useKeychain()) return
120
249
  try {
121
250
  await security(['delete-generic-password', '-a', profile(baseUrl), '-s', SERVICE])
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "jiema-workbuddy-mcp",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
7
- "jiema-workbuddy-mcp": "./bin/server.mjs"
7
+ "jiema-workbuddy-mcp": "bin/server.mjs"
8
8
  },
9
9
  "files": ["bin", "lib", "README.md"],
10
10
  "engines": { "node": ">=20" },