dsh-postapi 0.0.0-stage → 0.0.1
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/LICENSE +201 -0
- package/README.md +139 -2
- package/cordis.patch.yml +3 -0
- package/dist/client.js +5651 -0
- package/docs/DETAIL.md +27 -0
- package/docs/apifox-design-spec.md +101 -0
- package/docs/apifox-research/analysis.md +254 -0
- package/docs/apifox-ui-delivery.md +150 -0
- package/docs/apifox-visual-parity-spec.md +353 -0
- package/docs/feature-matrix.md +112 -0
- package/docs/flow-reference/sequence-reference.html +163 -0
- package/docs/interface-contract-v2.md +175 -0
- package/docs/interface-contract.md +105 -0
- package/docs/nav-layout-v2-spec.md +107 -0
- package/docs/preview.svg +9 -0
- package/docs/probe-client.legacy.js +31 -0
- package/docs/rootcause-sidebar-vanish.md +95 -0
- package/docs/rootcause.md +86 -0
- package/docs/sidebar-notes.md +153 -0
- package/docs/ui-audit.md +197 -0
- package/docs/ui-notes.md +98 -0
- package/docs/v2-delivery.md +99 -0
- package/icon.svg +4 -0
- package/index.js +5 -0
- package/locale/en.json +7 -0
- package/locale/zh.json +7 -0
- package/package.json +73 -4
- package/src/client/index.js +132 -0
- package/src/client/jsx-shim.js +9 -0
- package/src/client/pages/__tests__/heights.test.js +135 -0
- package/src/client/pages/components/AssertTable.jsx +122 -0
- package/src/client/pages/components/BodyEditor.jsx +91 -0
- package/src/client/pages/components/EmptyState.jsx +52 -0
- package/src/client/pages/components/FolderTree.jsx +109 -0
- package/src/client/pages/components/JsonEditor.jsx +45 -0
- package/src/client/pages/components/ParamTable.jsx +226 -0
- package/src/client/pages/components/ResponsePanel.jsx +278 -0
- package/src/client/pages/components/ScriptPanel.jsx +99 -0
- package/src/client/pages/components/StatusPill.jsx +35 -0
- package/src/client/pages/components/__tests__/apifox-ui.test.js +291 -0
- package/src/client/pages/components/__tests__/pages-a.test.js +392 -0
- package/src/client/pages/components/__tests__/tree.test.js +379 -0
- package/src/client/pages/components/headerPresets.js +63 -0
- package/src/client/pages/debug.jsx +576 -0
- package/src/client/pages/design-tokens.css +2604 -0
- package/src/client/pages/doc.jsx +552 -0
- package/src/client/pages/env.jsx +378 -0
- package/src/client/pages/flow.jsx +349 -0
- package/src/client/pages/history.jsx +238 -0
- package/src/client/pages/import.jsx +396 -0
- package/src/client/pages/mock.jsx +316 -0
- package/src/client/pages/overview.jsx +348 -0
- package/src/client/pages/schema.jsx +317 -0
- package/src/client/pages/search.jsx +216 -0
- package/src/client/pages/sequence.jsx +344 -0
- package/src/client/pages/settings.jsx +205 -0
- package/src/client/pages/test.jsx +470 -0
- package/src/client/pages/theme.js +27 -0
- package/src/client/pages-entry.js +20 -0
- package/src/client/shell/ApiTitle.js +19 -0
- package/src/client/shell/Body.js +492 -0
- package/src/client/shell/definition.js +57 -0
- package/src/client/shell/locales.js +185 -0
- package/src/client/shell/menu.js +174 -0
- package/src/client/shell/registry.js +530 -0
- package/src/host/bridge.js +407 -0
- package/src/host/codegen.js +356 -0
- package/src/host/import-export.js +1044 -0
- package/src/host/index.js +102 -0
- package/src/host/mock-server.js +303 -0
- package/src/host/request.js +336 -0
- package/src/host/script-sandbox.js +272 -0
- package/src/host/storage.js +803 -0
- package/src/host/test-runner.js +126 -0
- package/src/host/variables.js +108 -0
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# dsh-postapi 接口契约 v2(Apifox 功能复刻基线)
|
|
2
|
+
|
|
3
|
+
> lead 产出 · 2026-11-18 · 上游需求基线 docs/feature-matrix.md
|
|
4
|
+
> 所有 teammate 按本文档实现,**不得自行改签名**;确需偏离必须在汇报中单列「契约偏离」小节。
|
|
5
|
+
> 技术栈不变:纯 JS + JSX(esbuild classic transform,只 require react),无 TS 编译、无 Rust、无新依赖(node 内置模块 + 现有 esbuild)。
|
|
6
|
+
|
|
7
|
+
## 1. 目录与写范围(越界即违规)
|
|
8
|
+
|
|
9
|
+
| 角色 | 可写 |
|
|
10
|
+
|---|---|
|
|
11
|
+
| host-data | `src/host/storage.js`、`src/host/import-export.js`、`src/host/codegen.js`、`tests/host-data.test.js` |
|
|
12
|
+
| host-runtime | `src/host/request.js`、`src/host/script-sandbox.js`、`src/host/variables.js`、`src/host/mock-server.js`、`src/host/test-runner.js`、`tests/host-runtime.test.js` |
|
|
13
|
+
| pages-a | `src/client/pages/doc.jsx`、`debug.jsx`、`mock.jsx`、`src/client/pages/components/**` |
|
|
14
|
+
| pages-b | `src/client/pages/overview.jsx`、`env.jsx`、`schema.jsx`、`history.jsx`、`test.jsx`、`import.jsx`、`flow.jsx`、`settings.jsx`、`search.jsx` |
|
|
15
|
+
| bridge-wiring | `src/host/bridge.js`、`src/client/shell/registry.js`、`tests/bridge.test.js` |
|
|
16
|
+
| lead | `build.mjs`、`package.json`、`index.js`、`src/host/index.js`、`src/client/index.js`、`src/client/pages-entry.js`、`src/client/shell/**`(除 registry.js)、`docs/**`、`scripts/**`、`tests/run.js` |
|
|
17
|
+
|
|
18
|
+
红线:全程不 git commit / push;不装新 npm 依赖;不改 desktop profile;不动 `.research/`。
|
|
19
|
+
|
|
20
|
+
## 2. 存储 schema v2(host-data 权威实现)
|
|
21
|
+
|
|
22
|
+
根目录:`E:/User/文档/api`(构造参数可覆盖;测试用临时目录)。
|
|
23
|
+
|
|
24
|
+
### 2.1 index.json
|
|
25
|
+
```json
|
|
26
|
+
{ "version": 2, "projects": [ { "id": "proj_xxx", "name": "", "updatedAt": "ISO" } ] }
|
|
27
|
+
```
|
|
28
|
+
读 v1(无 version 字段)时自动补 `version: 2` 并保留 projects。
|
|
29
|
+
|
|
30
|
+
### 2.2 <projectId>/project.json
|
|
31
|
+
```jsonc
|
|
32
|
+
{
|
|
33
|
+
"id": "proj_xxx", "name": "", "description": "",
|
|
34
|
+
"createdAt": "ISO", "updatedAt": "ISO", "schemaVersion": 2,
|
|
35
|
+
"folders": [ { "id": "fld_xxx", "name": "", "parentId": null, "order": 0 } ],
|
|
36
|
+
"endpoints": [ {
|
|
37
|
+
"id": "ep_xxx", "name": "", "folderId": null, "order": 0,
|
|
38
|
+
"protocol": "http", // http | websocket | socketio | grpc | graphql | rpc (P2 仅存值)
|
|
39
|
+
"method": "GET", // GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE
|
|
40
|
+
"url": "", // 支持 {{var}} 与 /path/{id}
|
|
41
|
+
"params": [ { "key": "", "value": "", "enabled": true, "description": "", "required": false, "type": "string" } ],
|
|
42
|
+
"pathParams": [ { "key": "", "value": "", "enabled": true, "description": "", "required": false, "type": "string" } ],
|
|
43
|
+
"headers": [ { "key": "", "value": "", "enabled": true, "description": "", "required": false, "type": "string" } ],
|
|
44
|
+
"cookies": [ { "key": "", "value": "", "enabled": true, "description": "", "required": false, "type": "string" } ],
|
|
45
|
+
"body": { "type": "none", "content": "", "schema": null, "examples": [] },
|
|
46
|
+
// type: none|json|form|urlencoded|raw|binary|xml|graphql
|
|
47
|
+
"auth": { "type": "none", "token": "", "username": "", "password": "",
|
|
48
|
+
"key": "", "value": "", "addTo": "header" },
|
|
49
|
+
// type: none|bearer|basic|apikey|oauth2|digest (apikey 用 key/value/addTo=header|query)
|
|
50
|
+
"responses": [ { "id": "res_xxx", "name": "成功", "code": 200, "contentType": "application/json",
|
|
51
|
+
"body": "", "schema": null, "headers": [], "enabled": true, "isDefault": true } ],
|
|
52
|
+
"preProcessors": [ { "id": "pre_xxx", "type": "script", "enabled": true, "code": "" } ],
|
|
53
|
+
"postProcessors": [ { "id": "post_xxx", "type": "script", "enabled": true, "code": "" },
|
|
54
|
+
{ "id": "ast_xxx", "type": "assert", "enabled": true,
|
|
55
|
+
"assertions": [ { "source": "status|body|header|time", "path": "", "op": "eq|neq|gt|lt|contains|notContains|exists|notExists|regex", "value": "", "message": "" } ] } ],
|
|
56
|
+
"mock": { "enabled": false, "delayMs": 0, "rules": [] },
|
|
57
|
+
"description": "", "tags": [], "status": "developing", "createdAt": "ISO", "updatedAt": "ISO"
|
|
58
|
+
} ],
|
|
59
|
+
"schemas": [ { "id": "sch_xxx", "name": "", "folderId": null, "jsonSchema": {}, "description": "", "createdAt": "ISO", "updatedAt": "ISO" } ],
|
|
60
|
+
"environments": [ { "id": "env_xxx", "name": "开发环境", "baseUrl": "", "isDefault": true,
|
|
61
|
+
"variables": [ { "key": "", "value": "", "enabled": true, "secret": false } ] } ],
|
|
62
|
+
"globals": { "variables": [ { "key": "", "value": "", "enabled": true, "secret": false } ] },
|
|
63
|
+
"mocks": [ { "id": "mk_xxx", "endpointId": "", "field": "", "rule": "fixed|regex|increment|random|template", "value": "", "enabled": true } ],
|
|
64
|
+
"testCases": [ { "id": "tc_xxx", "name": "", "endpointId": "", "assertions": [], "extractors": [], "lastResult": null } ],
|
|
65
|
+
"testScenarios": [ { "id": "ts_xxx", "name": "", "steps": [ { "id": "stp_xxx", "name": "", "endpointId": "", "override": {}, "extract": [] } ], "lastRun": null } ],
|
|
66
|
+
"flow": { "name": "", "steps": [ { "actor": "", "action": "call|return|self|note", "target": "", "message": "", "note": "" } ] },
|
|
67
|
+
"settings": { "mockPort": 4010, "proxyUrl": "", "requestTimeoutMs": 30000, "historyLimit": 200 }
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
id 规则不变:`proj_/fld_/ep_/res_/sch_/env_/mk_/tc_/ts_/stp_/pre_/post_/ast_` + `Date.now().toString(36)` + 2 位随机。
|
|
72
|
+
时间一律 `new Date().toISOString()`。原子写 tmp+rename、进程内串行队列、损坏改名 `.corrupt-<ts>`、删项目进 `.trash`——四条既有机制**必须保持**。
|
|
73
|
+
|
|
74
|
+
### 2.3 <projectId>/history.json
|
|
75
|
+
```json
|
|
76
|
+
{ "entries": [ { "id": "his_xxx", "at": "ISO", "method": "GET", "url": "",
|
|
77
|
+
"status": 200, "timeMs": 12, "bodySize": 100, "request": {}, "response": {} } ] }
|
|
78
|
+
```
|
|
79
|
+
追加时按 `project.settings.historyLimit`(默认 200)保留最新 N 条。
|
|
80
|
+
|
|
81
|
+
## 3. host-data 服务 face(createStorageService(basePath) 返回值,只增不改)
|
|
82
|
+
|
|
83
|
+
既有 9 个方法签名**保持不变**(listProjects/createProject/renameProject/deleteProject/getProject/saveEndpoint/deleteEndpoint/saveFolder/deleteFolder)。新增:
|
|
84
|
+
|
|
85
|
+
```js
|
|
86
|
+
moveNode(projectId, { kind: 'folder'|'endpoint', id, parentId, order }) // P1 目录移动/排序
|
|
87
|
+
saveSchema(projectId, schema) -> schema // 无 id 新建
|
|
88
|
+
deleteSchema(projectId, schemaId)
|
|
89
|
+
saveEnvironment(projectId, env) -> env
|
|
90
|
+
deleteEnvironment(projectId, envId)
|
|
91
|
+
saveGlobals(projectId, globals) -> globals
|
|
92
|
+
saveProjectSettings(projectId, settings) -> settings
|
|
93
|
+
saveFlow(projectId, flow) -> flow
|
|
94
|
+
saveResponse(projectId, endpointId, response) -> response // endpoint.responses 内 upsert
|
|
95
|
+
deleteResponse(projectId, endpointId, responseId)
|
|
96
|
+
getHistory(projectId) -> { entries: [] }
|
|
97
|
+
appendHistory(projectId, entry) -> entry // 自动裁剪到 historyLimit
|
|
98
|
+
clearHistory(projectId) -> { cleared: n }
|
|
99
|
+
search(projectId, keyword) -> { endpoints: [], schemas: [], folders: [] } // 名称/url/description 命中,大小写不敏感
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## 4. host-runtime 服务 face
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
// src/host/variables.js
|
|
106
|
+
createVariableResolver({ globals, environment, local })
|
|
107
|
+
.resolve(text) -> string // 替换 {{key}} 与 {{$dynamic}};未定义保留原文
|
|
108
|
+
.explain(text) -> { resolved, missing: [] }
|
|
109
|
+
DYNAMIC_VARS // $timestamp $isoTimestamp $randomInt $randomString $uuid $randomEmail $randomPhone $randomBoolean $randomFloat $datetime $date
|
|
110
|
+
|
|
111
|
+
// src/host/script-sandbox.js
|
|
112
|
+
runScript(code, { context, timeoutMs = 3000 }) -> { ok, error?, logs: [], variables: {}, tests: [], exports: {} }
|
|
113
|
+
// context 结构(pm 兼容面,node:vm 隔离,禁 require/process/fs):
|
|
114
|
+
// { request: { method, url, params, headers, body }, response: { status, headers, body, timeMs },
|
|
115
|
+
// env: {...}, globals: {...}, variables: {...} }
|
|
116
|
+
// 脚本内可用全局:pm / console / JSON / Date / Math / String / Number / Array / Object / RegExp / setTimeout(禁用)
|
|
117
|
+
// pm.test(name, fn) → 记录断言结果;pm.expect(v).to.eql/equal/be.above/be.below/include/match/be.true/be.false
|
|
118
|
+
// pm.environment.get/set、pm.globals.get/set、pm.variables.get/set、pm.response.json()/text()/code、pm.request
|
|
119
|
+
// 返回值 tests: [{ name, passed, error? }]、variables: 脚本里 set 过的变量
|
|
120
|
+
|
|
121
|
+
// src/host/request.js(既有 send 签名扩展,向后兼容)
|
|
122
|
+
send({ method, url, params, headers, body, auth, timeoutMs = 30000,
|
|
123
|
+
variables, // { globals, environment, local } 传入即先做 {{}} 替换(url/params/headers/body/auth)
|
|
124
|
+
preScript, // string:发送前执行,可改 context.request
|
|
125
|
+
postScript, // string:响应后执行
|
|
126
|
+
assertions, // array:内置断言(无脚本时用)
|
|
127
|
+
projectId, history, // 传了 storage 侧 appendHistory 由 bridge 负责,request 只回 raw
|
|
128
|
+
})
|
|
129
|
+
-> { status, statusText, headers, body, bodySize, timeMs, truncated?, error?,
|
|
130
|
+
request: { method, url, headers, body }, // 实际发出的(含变量替换后)
|
|
131
|
+
tests: [{ name, passed, error? }], // 断言/脚本结果合并
|
|
132
|
+
variables: { ... }, // 脚本 set 的变量
|
|
133
|
+
logs: [] }
|
|
134
|
+
|
|
135
|
+
// src/host/mock-server.js
|
|
136
|
+
createMockServer({ getProject, port }) -> { start(), stop(), status() -> { running, port } }
|
|
137
|
+
// 规则:GET /mock/<projectId>/<endpointId> 与 /mock/<projectId><endpointPath> 两种命中;
|
|
138
|
+
// 按 project.mocks 字段规则生成 body;未命中回落 endpoint.responses[isDefault] 或 200 {}
|
|
139
|
+
|
|
140
|
+
// src/host/test-runner.js
|
|
141
|
+
createTestRunner({ storage, request })
|
|
142
|
+
.runCase(projectId, caseId) -> { caseId, passed, results: [{ name, passed, error? }], durationMs }
|
|
143
|
+
.runScenario(projectId, scenarioId) -> { scenarioId, passed, steps: [{ id, name, status, passed, extracted, error? }], durationMs }
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## 5. bridge 路由全表(bridge-wiring 权威实现)
|
|
147
|
+
|
|
148
|
+
前缀 `/dsh-postapi/api`;封套 `{ok:true,data}` / `{ok:false,error,code}`;保留 `ctx.connection.requestRejection` 栅栏与 2MB body 上限。
|
|
149
|
+
既有 11 条路由行为不变,新增按 docs/feature-matrix.md §4 全表实现(host-data / host-runtime 各自方法名一一对应)。
|
|
150
|
+
|
|
151
|
+
client 侧 `src/client/shell/registry.js` 的 `createBridgeStorage()` / `createBridgeRequest()` 需同步扩展同名方法,并保持 `installApi()` 的「桥失败回落内存桩」行为(新增方法也要有桩,桩为最小可用实现,不抛错)。
|
|
152
|
+
|
|
153
|
+
## 6. client 页面约定(pages-a / pages-b 共同遵守)
|
|
154
|
+
|
|
155
|
+
- 每页模块**首行**(import 之后)执行:`;(window.__postapiQueue = window.__postapiQueue || []).push(['<pageName>', PageComponent])`
|
|
156
|
+
- 页面 props:`{ route: { name, arg }, api }`;api 即 `window.__postapiApi`,可能为 undefined(此时渲染文件内 mock 并显示「示例数据」)。
|
|
157
|
+
- 根元素:`<div className="pp-scope pp-page" data-page="<pageName>" ref={rootRef}>`,`useEffect(() => applyTheme(rootRef.current), [])`(`import { applyTheme } from './theme.js'`)。
|
|
158
|
+
- **禁止内联尺寸魔法数**:控件高用 `--ctl-h`、行高 `--row-h`、胶囊 `--pill-h`;间距只用 `var(--sp-1|2|3|4|6)`;颜色只用 token 变量。新增样式类一律 `.pp-` 前缀,写进自己页面文件的 `<style>`?**不允许**——统一由 lead 在 `design-tokens.css` 增补;teammate 只能在页面里用已存在的 `.pp-*` 类或纯 token 的内联 style(内联 style 只允许 layout,不含颜色/字号字面量)。
|
|
159
|
+
- 禁止 `alert/confirm/prompt`;禁止新增 npm 依赖;禁止 import 宿主内部包(只允许 `react` 与本地相对路径)。
|
|
160
|
+
- 交互必须真跑:保存类按钮调用 `api.storage.*`,发送按钮调用 `api.request.send`,失败时页面内显示错误文案(不弹窗)。
|
|
161
|
+
- 页面内不得写死 `fetch('/dsh-postapi/...')`,一律走 `api`。
|
|
162
|
+
|
|
163
|
+
## 7. 测试要求
|
|
164
|
+
|
|
165
|
+
- 框架:仓库自带极简 runner(`tests/run.js` 汇总;每个测试文件导出 `export const tests = [{ name, fn }]`)。**不引 vitest**。
|
|
166
|
+
- host-data / host-runtime / bridge 三组必须覆盖:happy path + 边界(空值、缺 id、损坏文件、超限)+ 异常(网络失败、脚本抛错、断言失败)。
|
|
167
|
+
- 每新增 host 方法至少 1 条测试;每个页面至少 1 条静态断言(导出存在 + 注册名正确 + 无禁用 API)。
|
|
168
|
+
- 运行:`node tests/run.js`(lead 会把它扩展到包含全部新套件)。
|
|
169
|
+
|
|
170
|
+
## 8. 汇报格式(每个 teammate 必交)
|
|
171
|
+
|
|
172
|
+
1. 已实现功能点 → 文件 → 测试用例名(三列表,覆盖 feature-matrix 中自己负责的每一行)。
|
|
173
|
+
2. 契约偏离(若无写「无」)。
|
|
174
|
+
3. 未实现 / 降级项(明确写 P2 或原因)。
|
|
175
|
+
4. 自测输出摘要:`node tests/run.js` 的通过/失败计数与失败明细(必须全绿才汇报完成)。
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# dsh-postapi 接口契约 v1(四方对齐基线)
|
|
2
|
+
|
|
3
|
+
> T1/T2/T3/T5 四个 teammate 全部按本文档实现;偏离须在汇报中显式标注。技术栈:纯 JS/TS,esbuild 转译 JSX,无 Rust。
|
|
4
|
+
|
|
5
|
+
## 1. 存储 schema(T3 实现,T1 报告校正差异)
|
|
6
|
+
|
|
7
|
+
根目录:E:/User/文档/api(默认值,host 构造参数可注入)。
|
|
8
|
+
|
|
9
|
+
- index.json:`{ "projects": [ { "id", "name", "updatedAt" } ] }`
|
|
10
|
+
- <projectId>/project.json:
|
|
11
|
+
|
|
12
|
+
```jsonc
|
|
13
|
+
{
|
|
14
|
+
"id": "proj_xxx", "name": "", "createdAt": "ISO", "updatedAt": "ISO",
|
|
15
|
+
"folders": [ { "id": "fld_xxx", "name": "", "parentId": null } ],
|
|
16
|
+
"endpoints": [ {
|
|
17
|
+
"id": "ep_xxx", "name": "", "folderId": null,
|
|
18
|
+
"method": "GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS", "url": "",
|
|
19
|
+
"params": [ { "key", "value", "enabled": true } ],
|
|
20
|
+
"pathParams": [],
|
|
21
|
+
"headers": [ { "key", "value", "enabled": true } ],
|
|
22
|
+
"body": { "type": "json|form|raw|none", "content": "" },
|
|
23
|
+
"auth": { "type": "none|bearer|basic", "token": "", "username": "", "password": "" },
|
|
24
|
+
"description": "", "createdAt": "ISO", "updatedAt": "ISO"
|
|
25
|
+
} ],
|
|
26
|
+
"flow": { "name": "", "steps": [ { "actor": "", "action": "call|return|self|note", "target": "", "message": "", "note": "" } ] }
|
|
27
|
+
}
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
- id 规则:`proj_/fld_/ep_` + Date.now().toString(36) + 2 位随机;时间一律 new Date().toISOString()
|
|
31
|
+
- 损坏隔离:project.json 解析失败 → 原文件改名 .corrupt-<ts> 后重建空结构
|
|
32
|
+
- 删除项目:整目录先复制到 .trash/<projectId>-<ts>/ 再删除
|
|
33
|
+
- 原子写:tmp 文件 + fs.rename;所有写操作经进程内 promise 串行队列
|
|
34
|
+
|
|
35
|
+
## 2. host service face 签名(T3 实现;暴露接线方式以 B 的 sidebar-notes 为准,签名固定)
|
|
36
|
+
|
|
37
|
+
`postapi.storage`:
|
|
38
|
+
- listProjects() → [{id,name,updatedAt}]
|
|
39
|
+
- createProject(name) → project;renameProject(id,name);deleteProject(id)
|
|
40
|
+
- getProject(id) → project 全量
|
|
41
|
+
- saveEndpoint(projectId, endpoint) → endpoint(无 id 新建补 timestamps;有则覆盖并更新 updatedAt)
|
|
42
|
+
- deleteEndpoint(projectId, endpointId);saveFolder(projectId, folder);deleteFolder(projectId, folderId)(子项 folderId 置 null 不级联删)
|
|
43
|
+
|
|
44
|
+
`postapi.request`:
|
|
45
|
+
- send({ method,url,params,headers,body,auth,timeoutMs=30000 }) → { status,statusText,headers,body,bodySize,timeMs,error? }
|
|
46
|
+
- 实现:Node 全局 fetch + AbortController;params 拼 query;auth 注入 Authorization;body 按 type 序列化并补默认 Content-Type;响应 body 文本化,>2MB 截 200KB 且 truncated:true;错误结构化进 error 字段
|
|
47
|
+
|
|
48
|
+
## 2b. client↔host 通信桥(联调修订:inject face 方案作废)
|
|
49
|
+
|
|
50
|
+
官方机制核实:宿主 face 总线仅提供内置 face(sidebar-files inject=[slots,locale,sidebarRightTabs,sidebarRight,remote,remote.workspaceFiles];sidebar-right inject 全内置),插件无法注册 postapi.* 自定义 face。通信改为 dsh-db-tool 同款 webServer prefix 桥(0.2.x 生产验证):
|
|
51
|
+
- host:ctx.effect(() => ctx.webServer 注册 {kind:'prefix', path:'/dsh-postapi/api', handler}),handler 首行 ctx.connection 可选链 requestRejection(req) 栅栏(401/403 写 JSON 返回,宿主 0.2.0-rc.1 起插件前缀路由不经宿主鉴权)
|
|
52
|
+
- client:同源相对路径 fetch('/dsh-postapi/api/...'),响应 {ok:true,data} 或 {ok:false,error,code};失败降级内存 stub(契约 §2 签名不变)
|
|
53
|
+
- 路由表:GET /api/health;GET /api/storage/listProjects;POST /api/storage/createProject|renameProject|deleteProject|saveEndpoint|deleteEndpoint|saveFolder|deleteFolder;GET /api/storage/getProject?projectId=;POST /api/request/send
|
|
54
|
+
- client inject 数组移除 postapi.storage 与 postapi.request,仅保留宿主 face:[slots,locale,sidebarRightTabs]
|
|
55
|
+
|
|
56
|
+
## 3. client 页面路由与挂点(B 骨架 + D 页面)
|
|
57
|
+
|
|
58
|
+
- 页签内 hash 路由:#/overview(项目总览)、#/doc/:endpointId(接口文档)、#/debug(调试发送)、#/flow(流程图)、#/settings(设置)
|
|
59
|
+
- B 产出:src/client/index.js(__ModuleLoader__ 入口)、src/client/shell/{definition,ApiTitle,locales}.js、路由挂点组件(从 src/client/pages/ 引入五页;pages 暂缺时渲染占位)
|
|
60
|
+
- D 产出:src/client/pages/{overview,doc,debug,flow,settings}.jsx/js + design-tokens.css + 公共组件
|
|
61
|
+
- 数据访问:client 经 inject face 调 postapi.storage/request(B 按 ui-sidebar-files 样板接线;D 页面先用注入的 api 对象桩开发,联调由 lead 完成)
|
|
62
|
+
|
|
63
|
+
## 4. 侧边栏双栏策略(官方组件,禁止自制侧边栏框架)
|
|
64
|
+
|
|
65
|
+
右栏:@deepseek-ai/dsh-client-ui-sidebar-right@0.2.2-rc.3 契约——sidebarRightTabs.register({id:'postapi',kind,title,guide,keepMounted:true}) + slots sidebar.right.pane.tab / sidebar.right.pane.tab.title;席位 key 取 definition.id 不拼 localeKey;priority 不写即 extension;宿主 fiber effect 须 ctx.effect 包 disposer;guide 单入口直接打开页签。
|
|
66
|
+
|
|
67
|
+
左栏:官方 @deepseek-ai/dsh-client-ui-sidebar@0.0.1-rc.1(会话多级树/搜索/分组/状态点)。T2(B) 拉包侦察其是否提供插件可用的左栏扩展点(slots/registry/face):有 → 插件注册轻量 PostAPI 入口;无 → 左栏走桌面端原生,插件不注册、不自制。结论写入 docs/sidebar-notes.md。
|
|
68
|
+
|
|
69
|
+
保留:骨架已验证的 conversation.composer.dock 徽章(官方 slot)作为会话输入框快捷入口。
|
|
70
|
+
|
|
71
|
+
## 5. 设计 token(Vercel Geist;D 落地为 design-tokens.css,尺寸统一在 token 层)
|
|
72
|
+
|
|
73
|
+
- 字体:sans -apple-system,"Segoe UI",Inter,system-ui;mono ui-monospace,"Cascadia Code",Consolas
|
|
74
|
+
- 字阶 12/13/14/16/20/24px;权重 400/500/600;基准 13px、行高 1.45
|
|
75
|
+
- 边框三档:light #eaeaea/#d0d0d0/#a8a8a8;dark #333/#444/#666
|
|
76
|
+
- 前景:light #000/次级 #666;dark #fafafa/次级 #888;accent #0070f3;成功 #50e3c2、警告 #f5a623、错误 #e5484d
|
|
77
|
+
- 圆角:控件 6px、卡片 8px、胶囊全圆
|
|
78
|
+
- 尺寸统一 token(禁止控件各自 padding/字号撑高):控件高 --ctl-h:28px;表行高 --row-h:32px;胶囊高 --pill-h:20px;间距刻度 4/8/12/16/24;卡片 padding 12px;左导航 220px;右 TOC 180px
|
|
79
|
+
- 方法徽标:GET #22c55e / POST #3b82f6 / PUT #eab308 / DELETE #ef4444 / PATCH #a855f7,mono 10px 大写
|
|
80
|
+
- 密度基调:PostHog/Mintlify 文档感——1px 边框分区、不投阴影
|
|
81
|
+
|
|
82
|
+
## 6. sequence 流程图(D)
|
|
83
|
+
|
|
84
|
+
- 数据:project.json.flow.steps(见 §1);页内可视化编排(增删步/改序)+渲染
|
|
85
|
+
- 实现:先调 diagram-design skill,style-guide gate 选 (d) paste tokens:paper #fafafa / ink #000 / accent #0070f3 / border #eaeaea(不得用默认 #f5f5f5/#2d3142/#bf4520 皮肤);参照 HTML 存 docs/flow-reference/;移植 React+SVG 组件:生命线/激活条/消息箭头/自消息/alt-opt 片段最小集 + SVG 导出按钮
|
|
86
|
+
- skill 哲学:密度 4/10;steps>9 提示拆分为两张图
|
|
87
|
+
|
|
88
|
+
## 7. 测试要求
|
|
89
|
+
|
|
90
|
+
- vitest(lead 统一配置);T3 按 TDD:先失败测试后实现
|
|
91
|
+
- storage.test.js:项目建列删、endpoint upsert 补 timestamps、folder 增删、损坏隔离、原子写读回、10 并发写不丢
|
|
92
|
+
- request.test.js:node:http 本地 echo(不依赖外网):query 拼接、POST json、header 透传、超时 abort、非 2xx 返回 status、错误结构
|
|
93
|
+
- 等高一致性:D 在 src/client/pages/ 下写静态检查测试,固化「所有控件高度来自 token」约束
|
|
94
|
+
|
|
95
|
+
## 8. 写范围总表(越界即违规)
|
|
96
|
+
|
|
97
|
+
| 角色 | 可写 |
|
|
98
|
+
|---|---|
|
|
99
|
+
| T1 apifox-rea | .research/apifox/**、docs/apifox-research/** |
|
|
100
|
+
| T2 sidebar-shell | src/client/shell/**、src/client/index.js、docs/sidebar-notes.md、.research/sidebar/** |
|
|
101
|
+
| T3 storage-core | src/host/**、tests/** |
|
|
102
|
+
| T5 ui-pages | src/client/pages/**、docs/flow-reference/**、docs/ui-notes.md |
|
|
103
|
+
| T4 lead | package.json、cordis.patch.yml、index.js、client.js、.gitignore、docs/interface-contract.md、集成接线 |
|
|
104
|
+
|
|
105
|
+
红线:全程不 git commit/push;不修改其他插件与 desktop profile 既有 bundles(新增除外)。
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# 导航与布局 v2(人体工学版)
|
|
2
|
+
|
|
3
|
+
> ## ⚠ 已废弃(2026-11-19)
|
|
4
|
+
>
|
|
5
|
+
> **本文的 64px 图标轨(`.pp-rail`)+ 浮层二级菜单(`.pp-flyout`)方案已被 v3 取代**:
|
|
6
|
+
> v3 采用 **240px 常驻文字菜单**(`.pp-sider`,实测对齐 Apifox `.sider-bxNtfB` 的 240px / padding 20px)
|
|
7
|
+
> + **44px 卡片式主页签条**(`.pp-tabbar`),顶栏 48px。
|
|
8
|
+
>
|
|
9
|
+
> - 现行规范:**[docs/apifox-visual-parity-spec.md](./apifox-visual-parity-spec.md)**(§1 全局尺寸、§12 类名契约、§13 落地核对表)
|
|
10
|
+
> - `.pp-rail` / `.pp-rail-btn` / `.pp-rail-label` / `.pp-flyout` 在 `src/` 与 `design-tokens.css` 中已全部删除(grep 0 命中)
|
|
11
|
+
> - 本文正文仅作**历史记录**保留,不再作为实现依据;其中 §8 移除项、§9 验收标准均已失效
|
|
12
|
+
> - 本文件中的 `--rail-w` token 亦已不存在,勿再引用
|
|
13
|
+
|
|
14
|
+
> lead 产出 · 2026-11-18 · 分支 feature/apifox-ui-parity
|
|
15
|
+
> 背景:v1 把 12 条路由平铺在左树 + 又平铺一遍在水平页签条(重复导航),且右侧栏实际可用宽约 500px,
|
|
16
|
+
> 240px 左树 + 主区 + 240px 右栏三段式在窄容器里必然拥挤;doc/test/schema/env/mock/debug 页内又各自带左树,
|
|
17
|
+
> 形成「树里套树」。v2 改为 **图标轨 + 浮层二级菜单**,把导航收进 48px,主区拿回全部宽度。
|
|
18
|
+
|
|
19
|
+
## 1. 结构(三级菜单,全部不撑开主区)
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
┌─────────────────────────────────────────────────────────┐
|
|
23
|
+
│ 顶栏 44px 当前页 · 面包屑 · 搜索 · 动作(图标按钮) │
|
|
24
|
+
├────┬────────────────────────────────────────────────────┤
|
|
25
|
+
│ 轨 │ 主区(1fr,宽度最大化) │
|
|
26
|
+
│ 48 │ ┌ 页头(标题 + 描述 + 页面级动作) │
|
|
27
|
+
│ px │ ├ 内容 │
|
|
28
|
+
│ │ └ │
|
|
29
|
+
│ ① │ │
|
|
30
|
+
│ ② │ ← 二级浮层菜单(打开时覆盖在主区上, │
|
|
31
|
+
│ ③ │ 不挤压主区宽度;Esc / 点外部关闭) │
|
|
32
|
+
│ ④ │ │
|
|
33
|
+
│ ⑤ │ │
|
|
34
|
+
└────┴────────────────────────────────────────────────────┘
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
- **一级:图标轨 48px**(`.pp-rail`)——5 个分组图标,永远可见,只占 48px。
|
|
38
|
+
- **二级:浮层菜单 200px**(`.pp-flyout`)——点分组图标后从轨右侧浮出,绝对定位覆盖主区,
|
|
39
|
+
**不改变主区宽度**;再点同图标或按 Esc / 点浮层外关闭。
|
|
40
|
+
- **三级:分组内的路由条目**(`.pp-flyout-item`)——点即跳转,跳转后浮层自动关闭。
|
|
41
|
+
|
|
42
|
+
## 2. 五个分组(12 条路由的归类)
|
|
43
|
+
|
|
44
|
+
| 分组 | 图标语义 | 路由 |
|
|
45
|
+
|---|---|---|
|
|
46
|
+
| 项目 | 网格 | 总览 `overview` |
|
|
47
|
+
| 接口 | 文档页 | 文档 `doc`、调试 `debug`、Mock `mock` |
|
|
48
|
+
| 数据 | 数据库 | 数据模型 `schema`、环境 `env` |
|
|
49
|
+
| 质量 | 勾选 | 测试 `test`、历史 `history`、流程图 `flow` |
|
|
50
|
+
| 工具 | 齿轮 | 导入导出 `import`、搜索 `search`、设置 `settings` |
|
|
51
|
+
|
|
52
|
+
## 3. 顶栏(44px,密度更高)
|
|
53
|
+
|
|
54
|
+
- 左:当前页标题(`.pp-crumb`)+ 分组名面包屑(灰色,`/` 分隔)。
|
|
55
|
+
- 中:搜索框(`.pp-topbar-search`,宽度自适应,最大 320px)。
|
|
56
|
+
- 右:动作组——新建接口(主按钮)、环境下拉、主题(图标)、设置(图标)。**全部图标化或紧凑**,
|
|
57
|
+
不留长文案按钮,避免窄栏挤压换行。
|
|
58
|
+
|
|
59
|
+
## 4. 页头(每个页面统一,主区内)
|
|
60
|
+
|
|
61
|
+
`.pp-page-head`:标题 `.pp-page-title` + 一行描述 `.pp-page-desc` + 右侧动作区 `.pp-page-actions`。
|
|
62
|
+
页头与内容间距 `--sp-4`,页头下不再画分割线(靠留白分组,减少线条噪音)。
|
|
63
|
+
|
|
64
|
+
## 5. 页面内实体树改为「面板」
|
|
65
|
+
|
|
66
|
+
页面内原有的左树(doc 的目录/接口、env 的环境、schema 的模型、test 的用例、mock/debug 的接口列表)
|
|
67
|
+
统一改成 `.pp-panel`:白底、1px 边框、8px 圆角、内部 padding 8px,宽 200px(`--panel-w`),
|
|
68
|
+
与主内容用 `gap: var(--sp-4)` 分开。**不再用 `.pp-col-left` 边框通栏**,避免与工作台边框重复。
|
|
69
|
+
|
|
70
|
+
## 6. 人体工学要点(硬约束)
|
|
71
|
+
|
|
72
|
+
1. 主区在任何路由下都不被导航挤压:浮层菜单用 `position: absolute`,**不得**用 grid 列。
|
|
73
|
+
2. 单页纵向滚动只发生在主区(`.pp-main { overflow: auto }`),轨与顶栏固定。
|
|
74
|
+
3. 所有可点目标最小 28×28(`--hit: 28px`),轨图标 20px。
|
|
75
|
+
4. 焦点可见:`:focus-visible` 必须有 2px 外环(`--accent-tint`)。
|
|
76
|
+
5. 浮层动画 120ms 淡入 + 4px 位移,`prefers-reduced-motion` 时关闭。
|
|
77
|
+
6. 窄容器(< 420px)时浮层宽度降到 176px(`--flyout-w-sm`),顶栏搜索收起为图标。
|
|
78
|
+
|
|
79
|
+
## 7. 新增 token
|
|
80
|
+
|
|
81
|
+
| token | 值 | 用途 |
|
|
82
|
+
|---|---|---|
|
|
83
|
+
| `--rail-w` | 48px | 图标轨宽 |
|
|
84
|
+
| `--flyout-w` | 200px | 二级浮层宽 |
|
|
85
|
+
| `--flyout-w-sm` | 176px | 窄容器浮层宽 |
|
|
86
|
+
| `--panel-w` | 200px | 页面内实体树面板宽 |
|
|
87
|
+
| `--hit` | 28px | 最小可点尺寸 |
|
|
88
|
+
| `--topbar-h` | 44px | 顶栏(原 48 改 44) |
|
|
89
|
+
| `--rail-icon` | 20px | 轨图标尺寸 |
|
|
90
|
+
| `--z-flyout` | 30 | 浮层层级 |
|
|
91
|
+
| `--motion-fast` | 120ms | 浮层动画时长 |
|
|
92
|
+
|
|
93
|
+
## 8. 移除项(v1 遗留,必须删)
|
|
94
|
+
|
|
95
|
+
- 水平全局页签条(`.pp-tabs` 在 Body.js 的那一条)——与轨重复,且吃掉 40px 纵向。
|
|
96
|
+
页面内部的 `.pp-tabs`(Params/Headers/Body/Auth 等)保留。
|
|
97
|
+
- `.pp-body-3col` / `.pp-col-left` / `.pp-col-right` 作为工作台骨架的用法(页面内也不再使用)。
|
|
98
|
+
- 右上下文栏(`.pp-col-right` 的页面说明 + 快捷入口)——信息价值低但占 240px。
|
|
99
|
+
改为顶栏右侧一个「?」图标按钮,点开浮层显示当前页说明与快捷入口。
|
|
100
|
+
|
|
101
|
+
## 9. 验收
|
|
102
|
+
|
|
103
|
+
1. `node build.mjs` 通过,产物含 `--rail-w`。
|
|
104
|
+
2. `node tests/run.js` 全绿(shell-frame 断言改为 rail/flyout 结构)。
|
|
105
|
+
3. `heights.test.js` PASS(新 token 纳入检查)。
|
|
106
|
+
4. `ui-audit.test.js` 软清单 0 问题。
|
|
107
|
+
5. 真机截图:主区宽度 ≥ 容器宽 - 48px;浮层打开时主区宽度不变。
|
package/docs/preview.svg
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="320" height="120" viewBox="0 0 320 120">
|
|
2
|
+
<rect x="20" y="24" width="280" height="52" rx="12" fill="#f2f5f8" stroke="#c9d4de"/>
|
|
3
|
+
<rect x="34" y="40" width="150" height="6" rx="3" fill="#c9d4de"/>
|
|
4
|
+
<rect x="34" y="52" width="90" height="6" rx="3" fill="#dde5ec"/>
|
|
5
|
+
<g transform="translate(148 86)">
|
|
6
|
+
<circle cx="12" cy="12" r="12" fill="#eaf2f9"/>
|
|
7
|
+
<path d="M5 17 L20 9 L5 4 L5 9 L14 11 L5 13 Z" fill="#247bbf"/>
|
|
8
|
+
</g>
|
|
9
|
+
</svg>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
window.__ModuleLoader__.load({
|
|
2
|
+
id: 'dsh-postapi',
|
|
3
|
+
factory(require) {
|
|
4
|
+
var module = { exports: {} };
|
|
5
|
+
var exports = module.exports;
|
|
6
|
+
console.info('[dsh-postapi] MINIMAL PROBE LOADED — 宿主已加载本插件的 client 模块')
|
|
7
|
+
exports.inject = ['slots', 'locale', 'sidebarRightTabs']
|
|
8
|
+
exports.apply = function apply(ctx) {
|
|
9
|
+
console.info('[dsh-postapi] MINIMAL PROBE APPLY — 服务探测', {
|
|
10
|
+
hasTabs: !!ctx.sidebarRightTabs,
|
|
11
|
+
hasSlots: !!ctx.slots,
|
|
12
|
+
hasLocale: !!ctx.locale,
|
|
13
|
+
})
|
|
14
|
+
try {
|
|
15
|
+
ctx.effect(function () {
|
|
16
|
+
return ctx.sidebarRightTabs.register({
|
|
17
|
+
id: 'postapi',
|
|
18
|
+
kind: 'postapi',
|
|
19
|
+
keepMounted: true,
|
|
20
|
+
title: function () { return 'PostAPI' },
|
|
21
|
+
guide: [{ id: 'postapi', order: 10, title: function () { return 'PostAPI' }, description: function () { return 'API 调试' } }],
|
|
22
|
+
})
|
|
23
|
+
}, 'postapi-minimal-probe')
|
|
24
|
+
console.info('[dsh-postapi] MINIMAL PROBE REGISTERED')
|
|
25
|
+
} catch (e) {
|
|
26
|
+
console.error('[dsh-postapi] MINIMAL PROBE REGISTER FAILED:', e && e.message)
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return module.exports;
|
|
30
|
+
},
|
|
31
|
+
});
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# 侧边栏消失根因报告(2026-11-18)
|
|
2
|
+
|
|
3
|
+
> 现象:安装本地开发版后,右侧栏 guide 里 PostAPI 入口消失,右栏只剩「插件 / 自动化任务」两个面板。
|
|
4
|
+
> 结论一句话:**`ctx.effect` 的 body 返回了普通对象,cordis 抛 `TypeError: Invalid effect`,整个 client apply 失败,宿主回滚本 entry 的全部注册。**
|
|
5
|
+
|
|
6
|
+
## 1. 直接证据
|
|
7
|
+
|
|
8
|
+
用 CDP 在复现环境(`--profile repro2`,只装 `@deepseek-ai/dsh-base` + `@deepseek-ai/dsh-web-app` + `dsh-postapi`)里抓 console:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
{"type":"info","text":"[dsh-postapi] client apply 已执行 | Object"}
|
|
12
|
+
{"type":"warning","text":"web boot: warning: 1 entry did not activate\ndsh-postapi: failed: TypeError: Invalid effect"}
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
即:apply 进去了、也执行到第一行,但 effect 抛错导致 entry 判为 failed,宿主把该 entry 的注册整体回滚——页签类型、body 席位、title 席位、字典全没了,只剩一条 warning。
|
|
16
|
+
|
|
17
|
+
## 2. 机制(宿主源码)
|
|
18
|
+
|
|
19
|
+
`cordis` 的 `Fiber#_execute`(app.asar 内联实现)对 effect body 的返回值做严格分型:
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
const effect = runner.execute.call(this)
|
|
23
|
+
if (typeof effect === 'function') return runner.collect(effect)
|
|
24
|
+
else if (isNullable(effect)) { /* return */ }
|
|
25
|
+
else if (!isObject(effect)) throw new TypeError('Invalid effect')
|
|
26
|
+
else if ('then' in effect) return effect.then(safeCollect) // Promise
|
|
27
|
+
else if (Symbol.iterator in effect) { /* 迭代器 */ }
|
|
28
|
+
else if (Symbol.asyncIterator in effect) { /* 异步迭代器 */ }
|
|
29
|
+
else throw new TypeError('Invalid effect') // ← 普通对象落到这里
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
合法返回值只有五种:函数(disposer)、null/undefined、Promise、同步迭代器、异步迭代器。**普通对象直接抛错**。
|
|
33
|
+
|
|
34
|
+
## 3. 我们的出错点
|
|
35
|
+
|
|
36
|
+
`src/client/index.js` 最后一条注册:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
ctx.effect(() => installApi(), 'dsh-postapi: bridge api install')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`installApi()` 的返回值是 `window.__postapiApi`(一个对象,含 storage/request/script/mock/schema/import/export/codegen/test/db 十个命名空间)。箭头函数隐式返回它 → effect body 返回普通对象 → `Invalid effect` → 整条 apply 回滚。
|
|
43
|
+
|
|
44
|
+
前五条 effect 返回的都是 register/inject 的 disposer 函数,本来合法;但只有这一条把整条链带崩,所以现象是「页签完全消失」而不是「少了一个功能」。
|
|
45
|
+
|
|
46
|
+
## 4. 为什么脚本层测试没抓到
|
|
47
|
+
|
|
48
|
+
`build.mjs` 的 vm smoke 用假 ctx:
|
|
49
|
+
|
|
50
|
+
```js
|
|
51
|
+
effect: (fn, label) => { calls.push(['effect', label]); return fn() }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
假 ctx 不校验返回值形态,所以 `installApi()` 返回对象也照样「通过」。这是测试替身过于宽松造成的盲区。
|
|
55
|
+
|
|
56
|
+
## 5. 修复
|
|
57
|
+
|
|
58
|
+
### 5.1 业务代码(`src/client/index.js`)
|
|
59
|
+
|
|
60
|
+
新增 `safeEffect(ctx, label, body)` 包装器:body 返回值不是函数/可 then/可迭代时,记一条 `console.warn` 并归一为 `undefined`;六处注册全部改走它。这样任何单个注册点的返回值形态差异都不会再拖垮整条注册链。
|
|
61
|
+
|
|
62
|
+
同时把 installApi 那条显式写成带 disposer 的形式(卸载时清掉 `window.__postapiApi`)。
|
|
63
|
+
|
|
64
|
+
### 5.2 构建期加固(`build.mjs`)
|
|
65
|
+
|
|
66
|
+
vm smoke 的假 ctx `effect` 改为与宿主同构校验:非函数/非 null/非 thenable/非 iterable 直接 `assert` 失败,错误信息带上 effect label。同类问题下次在 `node build.mjs` 就炸,不必等真机。
|
|
67
|
+
|
|
68
|
+
## 6. 验证
|
|
69
|
+
|
|
70
|
+
复现环境(repro2,最小 profile)用 CDP 实测,修复前后对比:
|
|
71
|
+
|
|
72
|
+
| 检查 | 修复前 | 修复后 |
|
|
73
|
+
|---|---|---|
|
|
74
|
+
| console | `1 entry did not activate / Invalid effect` | 无该警告 |
|
|
75
|
+
| `window.__postapiPages.names()` | 12 页(模块已执行) | 12 页 |
|
|
76
|
+
| 展开右栏后的 guide 条目 | `[]` | `["postapi","files","terminal"]` |
|
|
77
|
+
| guide 文案 | 无 PostAPI | `打开 PostAPI / 接口设计、调试、Mock、测试与文档` |
|
|
78
|
+
|
|
79
|
+
另外四道验收全绿:`node build.mjs`(含新增的 effect 形态断言)、`node tests/run.js` 183/183、`node scripts/smoke-host.mjs` 27/27、`heights.test.js` PASS(28)。
|
|
80
|
+
|
|
81
|
+
## 7. 排查过程中排除的假设
|
|
82
|
+
|
|
83
|
+
| 假设 | 结论 | 依据 |
|
|
84
|
+
|---|---|---|
|
|
85
|
+
| 客户端入口 `exports["./client"]` 指向错误 | 曾是真问题,已修 | 原本指向骨架期探测桩 `probe-client.js`(只注册一个空页签),已改为 `dist/client.js` 并把探测桩归档到 `docs/probe-client.legacy.js` |
|
|
86
|
+
| symlink 安装(`link:`)导致内核扫描漏掉 | 否 | boot 图 `__DSH_BOOT__.entries` 里明确含 `dsh-postapi`,bundle URL 200 且 244KB |
|
|
87
|
+
| `dsh.client.inject` 声明了未安装的包 | 否 | inject 只有 `dsh-client-locale` 与 `dsh-client-ui-sidebar-right`,两者都在 boot 图里 |
|
|
88
|
+
| 产物出现裸 `React.createElement` | 曾是真问题,已修 | 已改 `jsxFactory: 'createElement'` + inject shim,构建期断言 0 处 |
|
|
89
|
+
| `dsh-better-sidebar` 抢占右栏 | 否 | 它只注册自己的 tab 服务;guide 里 `files`/`terminal` 是官方 tabs,postapi 与它们并列 |
|
|
90
|
+
| 宿主 client 模块表缺 react | 否 | `staticModules` 种子表含 `react`/`react/jsx-runtime`,且产物 18 处 `require("react")` 全部命中 |
|
|
91
|
+
|
|
92
|
+
## 8. 教训(写进开发约定)
|
|
93
|
+
|
|
94
|
+
- effect body **只能**返回 disposer 函数 / null / Promise / 迭代器;返回业务对象一律包装。
|
|
95
|
+
- 测试替身必须与真实宿主同构校验;宽松替身会把宿主级错误推迟到真机。
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# dsh-postapi 右栏 guide 无入口 —— 根因报告(T1 取证)
|
|
2
|
+
|
|
3
|
+
> 结论一句话:**esbuild cjs 产物在 factory 内部重赋值 `module.exports`,宿主缓存的 `exports` 指向旧对象,`exports.apply` / `exports.inject` 读出 undefined,客户端插件静默不注册,右栏 guide 因此没有 PostAPI 入口。**
|
|
4
|
+
|
|
5
|
+
## 1. 根因(置信度:高)
|
|
6
|
+
|
|
7
|
+
`dist/client.js` 的形态由 `build.mjs` 的 banner/footer 包住 esbuild 的 cjs 输出:
|
|
8
|
+
|
|
9
|
+
| 位置 | 代码 | 作用 |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `dist/client.js:4` | `var module = { exports: {} };` | banner 造出假 module |
|
|
12
|
+
| `dist/client.js:5` | `var exports = module.exports;` | **宿主可见的那个 exports 引用在此刻被固定** |
|
|
13
|
+
| `dist/client.js:30` | `module.exports = __toCommonJS(index_exports);` | esbuild 的 cjs 收尾:**把 module.exports 换成另一个新对象** |
|
|
14
|
+
|
|
15
|
+
`module.exports` 被重新赋值后,第 5 行缓存的 `exports` 仍指向 banner 造出的空对象;随后宿主侧读取 `exports.apply` / `exports.inject` 时拿到 `undefined`:
|
|
16
|
+
|
|
17
|
+
- 读不到 `apply` → cordis 认为该插件没有可执行的插件体 → **不注册任何页签类型、不注册 body/title 席位**;
|
|
18
|
+
- 读不到 `inject` → 依赖声明丢失;
|
|
19
|
+
- 整个过程不抛错(不是异常路径,是"没有插件体"的静默路径),所以控制台无红色报错,只表现为 **guide 页面里没有 PostAPI 卡片**。
|
|
20
|
+
|
|
21
|
+
## 2. 对照证据:dsh-db-tool 为何从未踩坑
|
|
22
|
+
|
|
23
|
+
`D:/Code/dsh-db-tool/client/client.js`
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
// 4384: }
|
|
27
|
+
// 4385: exports.apply = apply;
|
|
28
|
+
// 4386: exports.inject = inject;
|
|
29
|
+
// ...
|
|
30
|
+
// 4401: return module.exports;
|
|
31
|
+
// 4402: },
|
|
32
|
+
// 4403: });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
db-tool 的 client.js 是**手写单文件模块**:全程只往 `exports`(即 `module.exports` 同一对象)上挂属性,**从不重新赋值 `module.exports`**。第 5 行缓存的引用与最终导出的引用始终是同一个对象,因此 `exports.apply` / `exports.inject` 一直可读 —— 这也是它在 0.2.x 上长期稳定工作、而本插件形态不同的原因。
|
|
36
|
+
|
|
37
|
+
## 3. 已排除的假设(避免后人重复排查)
|
|
38
|
+
|
|
39
|
+
| 假设 | 结论 | 依据 |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `react/jsx-runtime` 缺失导致 factory 抛错 | **不是根因** | 宿主种子模块表确实提供 `react/jsx-runtime`;官方插件 `dsh-message-quotes`、`dsh-session-log-export` 都在 require 它。(本插件现已改用 `jsx: 'transform'` + `src/client/jsx-shim.js`,产物只 require `react`,属额外保险,不是必需修复。) |
|
|
42
|
+
| guide entry 缺 `icon` 导致卡片不渲染 | **不是根因** | 官方 `tab-registry.ts` / `GuideBody.tsx`:`const Icon = entry.icon ?? CubeGlyph`,无 icon 时回落官方立方体占位图。 |
|
|
43
|
+
| 显式声明 `priority: 'extension'` 改变路由行为 | **不是根因** | `tab-registry.ts:59` `DEFAULT_BAND = 'extension'`;`register()` 取 `definition.priority ?? DEFAULT_BAND`,显式写与省略等价。 |
|
|
44
|
+
|
|
45
|
+
## 4. 另外四个真实存在、已修复、但不是直接原因的问题
|
|
46
|
+
|
|
47
|
+
以下四项都是**真 bug**(会以不同错误码炸掉 host 侧或依赖解析),已在本轮修掉;但它们不产生"guide 静默无入口"这一现象:
|
|
48
|
+
|
|
49
|
+
1. **ctx 直接挂属性** → cordis 受控上下文抛 `cannot set property without provide`。现改为闭包持有 storage/request,只经 `ctx.webServer.register` 暴露 HTTP 桥(`src/host/index.js:13-46`)。
|
|
50
|
+
2. **host `inject` 未声明 `webServer`/`connection`** → 访问 `ctx.webServer` 抛 `cannot get property without inject`。现在 `src/host/index.js:11` `export const inject = ['webServer', 'connection']`。
|
|
51
|
+
3. **根入口未 re-export `inject`** → 只 `export { apply }` 时注入清单丢失。现在 `index.js:5` `export { apply, inject } from './src/host/index.js'`。
|
|
52
|
+
4. **`dsh.client.inject` 声明了未安装的 conversation 包** → 客户端依赖解析失败。现在只留已安装的两个:`@deepseek-ai/dsh-client-locale`、`@deepseek-ai/dsh-client-ui-sidebar-right`(`package.json:32-38`)。
|
|
53
|
+
|
|
54
|
+
## 5. 最小修复
|
|
55
|
+
|
|
56
|
+
`build.mjs` footer 里,在 `return module.exports;` 之前补一行回写:
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
footer: {
|
|
60
|
+
js: [
|
|
61
|
+
'',
|
|
62
|
+
' Object.assign(exports, module.exports);', // ← 新增:把真导出回写到宿主缓存的旧对象上
|
|
63
|
+
' return module.exports;',
|
|
64
|
+
' },',
|
|
65
|
+
'});',
|
|
66
|
+
].join('\n'),
|
|
67
|
+
},
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
配套 smoke 回归断言(`build.mjs` 构建后即跑):**factory 返回值必须同时含 `apply` 与 `inject`,且 `apply` 为函数**,否则构建直接失败 —— 防止再次出现"产物能加载但插件体为空"的静默故障。
|
|
71
|
+
|
|
72
|
+
## 6. 验证证据
|
|
73
|
+
|
|
74
|
+
- `dist/client.js:1432` 已含 `Object.assign(exports, module.exports);`,`:1433` 为 `return module.exports;`。
|
|
75
|
+
- vm 实载产物(假 `window.__ModuleLoader__` + `react` shim)后调用 factory:`exports keys: ["apply","inject"]`,`typeof apply === 'function'`,`inject = ["slots","locale","sidebarRightTabs"]`。
|
|
76
|
+
- `node build.mjs` 通过;`node tests/run.js` 21/21;`tests/client/registration.test.js` 6/6;`src/client/pages/__tests__/heights.test.js` 21 checks 全绿。
|
|
77
|
+
|
|
78
|
+
## 7. 取证复核记录(偏离标注,供后续定位参考)
|
|
79
|
+
|
|
80
|
+
本报告第 1 节按 lead 确认的结论落笔。取证过程中在本机当前产物上做了一次对照实验,记录如下,以免后续排查被单一结论锁死:
|
|
81
|
+
|
|
82
|
+
- 用 `vm` 分别加载「当前产物」与「删掉第 1432 行 `Object.assign` 的产物」,**两次 factory 的返回值都含 `apply`/`inject`**。原因是宿主 `@deepseek-ai/dsh-client-modules` 的 `materialize()` 读的是 **factory 的返回值**(`system.ts:313`:`const exports = registered.factory(this.makeRequire(ownerId, edges))`),不是 factory 内部的 `var exports`。
|
|
83
|
+
- 因此:**"重赋值 module.exports 导致导出丢失"这条链在"宿主读返回值"的实现下不成立**;当前 `Object.assign` 回写是无害的加固(对返回值无影响),smoke 断言仍是有效的守门。
|
|
84
|
+
- 若修复后 guide 仍无 PostAPI 入口,下一个怀疑点不在导出形态,而应在:该包是否进入 `window.__DSH_BOOT__` 的 boot 图(宿主 `dsh-client-modules` 的 `dsh.client` 扫描 + `exports["./client"]` 解析),以及客户端插件 fiber 是否进入 ACTIVE。定位方法:浏览器 DevTools 里查 `window.__DSH_BOOT__.entries` 是否含 `dsh-postapi`、`window.__ModuleLoader__` 的 factories 是否含该 id。
|
|
85
|
+
|
|
86
|
+
> 记录人:T1 rootcause(task-5)。全程只读取证 + 仅写本文件,未修改任何源码,未执行 git commit/push。
|