@jayyuen66/dsh-dir-prep-organize 0.1.4 → 0.1.6

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.
Files changed (81) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/LICENSE +1 -1
  3. package/README.md +209 -104
  4. package/README.zh-CN.md +209 -102
  5. package/agents/academic/academic-statistician.md +143 -0
  6. package/agents/design/design-inclusive-visuals-specialist.md +4 -3
  7. package/agents/design/design-ui-designer.md +6 -3
  8. package/agents/design/design-ux-architect.md +20 -7
  9. package/agents/design/design-whimsy-injector.md +23 -1
  10. package/agents/engineering/engineering-autonomous-optimization-architect.md +31 -22
  11. package/agents/engineering/engineering-backend-architect.md +43 -54
  12. package/agents/engineering/engineering-data-engineer.md +21 -6
  13. package/agents/engineering/engineering-database-optimizer.md +22 -10
  14. package/agents/engineering/engineering-devops-automator.md +12 -3
  15. package/agents/engineering/engineering-email-intelligence-engineer.md +41 -4
  16. package/agents/engineering/engineering-embedded-firmware-engineer.md +27 -5
  17. package/agents/engineering/engineering-feishu-integration-developer.md +10 -2
  18. package/agents/engineering/engineering-frontend-developer.md +24 -18
  19. package/agents/engineering/engineering-git-workflow-master.md +16 -4
  20. package/agents/engineering/engineering-incident-response-commander.md +3 -3
  21. package/agents/engineering/engineering-prompt-engineer.md +7 -2
  22. package/agents/engineering/engineering-rapid-prototyper.md +7 -3
  23. package/agents/engineering/engineering-security-engineer.md +2 -0
  24. package/agents/engineering/engineering-solidity-smart-contract-engineer.md +1 -1
  25. package/agents/engineering/engineering-technical-writer.md +4 -4
  26. package/agents/engineering/engineering-threat-detection-engineer.md +2 -0
  27. package/agents/engineering/engineering-voice-ai-integration-engineer.md +39 -16
  28. package/agents/engineering/engineering-wechat-mini-program-developer.md +7 -2
  29. package/agents/game-development/blender/blender-addon-engineer.md +12 -3
  30. package/agents/game-development/economy-designer.md +155 -0
  31. package/agents/game-development/godot/godot-gameplay-scripter.md +4 -0
  32. package/agents/game-development/godot/godot-multiplayer-engineer.md +6 -2
  33. package/agents/game-development/godot/godot-shader-developer.md +4 -3
  34. package/agents/game-development/roblox-studio/roblox-experience-designer.md +7 -6
  35. package/agents/game-development/roblox-studio/roblox-systems-scripter.md +7 -0
  36. package/agents/game-development/technical-artist.md +4 -0
  37. package/agents/game-development/unity/unity-multiplayer-engineer.md +67 -0
  38. package/agents/game-development/unreal-engine/unreal-multiplayer-architect.md +82 -31
  39. package/agents/game-development/unreal-engine/unreal-systems-engineer.md +13 -1
  40. package/agents/marketing/marketing-agentic-search-optimizer.md +50 -87
  41. package/agents/marketing/marketing-carousel-growth-engine.md +49 -35
  42. package/agents/marketing/marketing-private-domain-operator.md +2 -2
  43. package/agents/marketing/marketing-seo-specialist.md +22 -0
  44. package/agents/product/product-behavioral-nudge-engine.md +3 -0
  45. package/agents/project-management/project-management-jira-workflow-steward.md +5 -2
  46. package/agents/security/security-appsec-engineer.md +75 -43
  47. package/agents/security/security-threat-detection-engineer.md +6 -0
  48. package/agents/security/security-threat-intelligence-analyst.md +32 -15
  49. package/agents/specialized/accounts-payable-agent.md +39 -45
  50. package/agents/specialized/grant-writer.md +2 -2
  51. package/agents/specialized/healthcare-aging-parent-care-companion.md +396 -0
  52. package/agents/specialized/identity-graph-operator.md +24 -3
  53. package/agents/specialized/lsp-index-engineer.md +17 -15
  54. package/agents/specialized/recruitment-specialist.md +17 -11
  55. package/agents/specialized/specialized-developer-advocate.md +4 -4
  56. package/agents/specialized/specialized-fedramp-rmf-compliance.md +379 -0
  57. package/agents/specialized/specialized-focus-music-architect.md +176 -0
  58. package/agents/specialized/specialized-french-consulting-market.md +17 -15
  59. package/agents/specialized/specialized-model-qa.md +78 -34
  60. package/agents/specialized/specialized-salesforce-architect.md +17 -15
  61. package/agents/specialized/specialized-workflow-architect.md +2 -2
  62. package/agents/supply-chain/supply-chain-strategist.md +12 -3
  63. package/agents/support/support-analytics-reporter.md +48 -30
  64. package/agents/support/support-finance-tracker.md +36 -18
  65. package/agents/support/support-infrastructure-maintainer.md +2 -2
  66. package/agents/support/support-support-responder.md +43 -26
  67. package/agents/testing/testing-api-tester.md +37 -27
  68. package/agents/testing/testing-performance-benchmarker.md +82 -47
  69. package/agents/testing/testing-test-results-analyzer.md +37 -18
  70. package/agents/testing/testing-tool-evaluator.md +30 -10
  71. package/client.js +209 -141
  72. package/cordis.patch.yml +4 -23
  73. package/host.js +98 -68
  74. package/package.json +53 -44
  75. package/templates.data.mjs +9 -10
  76. package/types/host.d.ts +29 -21
  77. package/types/src/client-timeouts.d.ts +4 -4
  78. package/types/src/host-messages.d.ts +5 -3
  79. package/types/src/remote.d.ts +12 -3
  80. package/types/src/templates.d.ts +3 -3
  81. package/types/src/ui-messages.d.ts +22 -14
@@ -106,6 +106,8 @@ public class PlayerController : NetworkBehaviour
106
106
 
107
107
  public override void OnNetworkSpawn()
108
108
  {
109
+ // 用出生点初始化权威位置,而不是 Vector3.zero
110
+ if (IsServer) _serverPosition.Value = transform.position;
109
111
  if (!IsOwner) return;
110
112
  _clientPredictedPosition = transform.position;
111
113
  }
@@ -144,6 +146,62 @@ public class PlayerController : NetworkBehaviour
144
146
  }
145
147
  ```
146
148
 
149
+ ### Lobby 与匹配集成
150
+
151
+ 以下是上游的最小集成示例,调用前需完成 UGS 初始化与认证。实际项目还应补齐退出房间、对象销毁时的心跳取消、异常处理及主机迁移;不要把这个循环直接视为完整的房间生命周期实现。
152
+
153
+ ```csharp
154
+ public class LobbyManager : MonoBehaviour
155
+ {
156
+ private Lobby _currentLobby;
157
+ private const string KEY_MAP = "SelectedMap";
158
+ private const string KEY_GAME_MODE = "GameMode";
159
+
160
+ public async Task<Lobby> CreateLobby(string lobbyName, int maxPlayers, string mapName)
161
+ {
162
+ var options = new CreateLobbyOptions
163
+ {
164
+ IsPrivate = false,
165
+ Data = new Dictionary<string, DataObject>
166
+ {
167
+ { KEY_MAP, new DataObject(DataObject.VisibilityOptions.Public, mapName) },
168
+ { KEY_GAME_MODE, new DataObject(DataObject.VisibilityOptions.Public, "Deathmatch") }
169
+ }
170
+ };
171
+
172
+ _currentLobby = await LobbyService.Instance.CreateLobbyAsync(lobbyName, maxPlayers, options);
173
+ StartHeartbeat(); // 定期发送心跳,保持房间活跃
174
+ return _currentLobby;
175
+ }
176
+
177
+ public async Task<List<Lobby>> QuickMatchLobbies()
178
+ {
179
+ var queryOptions = new QueryLobbiesOptions
180
+ {
181
+ Filters = new List<QueryFilter>
182
+ {
183
+ new QueryFilter(QueryFilter.FieldOptions.AvailableSlots, "1", QueryFilter.OpOptions.GE)
184
+ },
185
+ Order = new List<QueryOrder>
186
+ {
187
+ new QueryOrder(false, QueryOrder.FieldOptions.Created)
188
+ }
189
+ };
190
+ var response = await LobbyService.Instance.QueryLobbiesAsync(queryOptions);
191
+ return response.Results;
192
+ }
193
+
194
+ private async void StartHeartbeat()
195
+ {
196
+ while (_currentLobby != null)
197
+ {
198
+ await LobbyService.Instance.SendHeartbeatPingAsync(_currentLobby.Id);
199
+ await Task.Delay(15000); // 每 15 秒一次;上游示例按 30 秒活跃超时设计
200
+ }
201
+ }
202
+ }
203
+ ```
204
+
147
205
  ### NetworkVariable 设计参考
148
206
  ```csharp
149
207
  // 持久且同步到所有客户端加入时的状态 → NetworkVariable
@@ -166,6 +224,15 @@ public void RequestFireServerRpc(Vector3 aimDirection)
166
224
  PerformFire(aimDirection);
167
225
  OnFireClientRpc(aimDirection);
168
226
  }
227
+
228
+ // 避免:每帧设置 NetworkVariable
229
+ private void Update()
230
+ {
231
+ // 反例:每帧写入位置可能产生不必要的网络流量
232
+ // Position.Value = transform.position;
233
+
234
+ // 建议:使用 NetworkTransform 组件或自定义预测
235
+ }
169
236
  ```
170
237
 
171
238
  ## 工作流程
@@ -30,6 +30,7 @@ color: red
30
30
  ### 权威与复制模型
31
31
  - **强制要求**:所有游戏状态变更在服务端执行——客户端发送 RPC,服务端验证并复制
32
32
  - `UFUNCTION(Server, Reliable, WithValidation)` —— `WithValidation` 标签对任何影响游戏的 RPC 都不是可选的;每个 Server RPC 都必须实现 `_Validate()`
33
+ - 如果 `_Validate()` 返回 `false`,服务端会断开这名玩家的连接。只对诚实玩家绝不可能发出的输入返回 `false`。网络延迟会让诚实的请求看起来不对(目标已经移出范围、目标已经被销毁、冷却还没结束),这些情况要放到 `_Implementation` 里检查,在那里可以直接忽略请求,玩家也不会被踢下线
33
34
  - 每次状态修改前都要做 `HasAuthority()` 检查——永远不要假设自己在服务端
34
35
  - 纯装饰效果(音效、粒子)使用 `NetMulticast` 在服务端和客户端都执行——永远不要让游戏逻辑阻塞在纯装饰的客户端调用上
35
36
 
@@ -98,15 +99,19 @@ void AMyNetworkedActor::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Ou
98
99
 
99
100
  bool AMyNetworkedActor::ServerRequestInteract_Validate(AActor* Target)
100
101
  {
101
- // 服务端验证——拒绝不可能的请求
102
- if (!IsValid(Target)) return false;
103
- float Distance = FVector::Dist(GetActorLocation(), Target->GetActorLocation());
104
- return Distance < 200.f; // 最大交互距离
102
+ // 这里返回 false 会断开玩家连接,所以只拒绝根本不可能出现的请求。
103
+ // 允许 Target 为空:这个 RPC 到达之前,服务端可能已经销毁了它。
104
+ return Target == nullptr || Target->Implements<UMyInteractable>();
105
105
  }
106
106
 
107
107
  void AMyNetworkedActor::ServerRequestInteract_Implementation(AActor* Target)
108
108
  {
109
- // 可以安全执行——验证已通过
109
+ // 延迟可能让诚实玩家也通不过这些检查,所以忽略请求,而不是断开连接
110
+ if (!IsValid(Target)) return;
111
+
112
+ const float MaxInteractDistance = 200.f;
113
+ if (FVector::Dist(GetActorLocation(), Target->GetActorLocation()) > MaxInteractDistance) return;
114
+
110
115
  PerformInteraction(Target);
111
116
  }
112
117
  ```
@@ -160,71 +165,115 @@ public:
160
165
 
161
166
  ### GAS 复制设置
162
167
  ```cpp
163
- // 在角色头文件中——AbilitySystemComponent 必须正确设置以支持复制
168
+ // 这就是上面那个 AMyPlayerState(为了简短,省略了 Kills 和 Deaths)。
169
+ // 现在它还持有 AbilitySystemComponent(ASC)。把 ASC 放在 PlayerState 上,
170
+ // 角色死亡和重生时,技能和属性都能保留下来。
171
+ // PlayerState 是 ASC 的拥有者(owner),Character 是它的化身(avatar,即世界中的身体)。
164
172
  UCLASS()
165
- class MYGAME_API AMyCharacter : public ACharacter, public IAbilitySystemInterface
173
+ class MYGAME_API AMyPlayerState : public APlayerState, public IAbilitySystemInterface
166
174
  {
167
175
  GENERATED_BODY()
176
+ public:
177
+ AMyPlayerState();
178
+
179
+ virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override
180
+ { return AbilitySystemComponent; }
168
181
 
182
+ protected:
169
183
  UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="GAS")
170
- UAbilitySystemComponent* AbilitySystemComponent;
184
+ TObjectPtr<UAbilitySystemComponent> AbilitySystemComponent;
171
185
 
172
186
  UPROPERTY()
173
- UMyAttributeSet* AttributeSet;
187
+ TObjectPtr<UMyAttributeSet> AttributeSet;
188
+ };
189
+
190
+ AMyPlayerState::AMyPlayerState()
191
+ {
192
+ AbilitySystemComponent = CreateDefaultSubobject<UAbilitySystemComponent>(TEXT("AbilitySystemComponent"));
193
+ AbilitySystemComponent->SetIsReplicated(true);
194
+ AbilitySystemComponent->SetReplicationMode(EGameplayEffectReplicationMode::Mixed);
195
+
196
+ // ASC 会自动找到在它的拥有者上创建的属性集,不需要额外设置
197
+ AttributeSet = CreateDefaultSubobject<UMyAttributeSet>(TEXT("AttributeSet"));
174
198
 
199
+ // PlayerState 默认每秒只同步一次,对技能来说太慢了。
200
+ SetNetUpdateFrequency(100.f);
201
+ }
202
+
203
+ // 在角色头文件中:Character 从 PlayerState 获取它的 ASC
204
+ UCLASS()
205
+ class MYGAME_API AMyCharacter : public ACharacter, public IAbilitySystemInterface
206
+ {
207
+ GENERATED_BODY()
175
208
  public:
176
- virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override
177
- { return AbilitySystemComponent; }
209
+ virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
178
210
 
179
211
  virtual void PossessedBy(AController* NewController) override; // 服务端:初始化 GAS
180
212
  virtual void OnRep_PlayerState() override; // 客户端:初始化 GAS
213
+
214
+ private:
215
+ void InitAbilitySystem();
181
216
  };
182
217
 
183
218
  // 在 .cpp 中——客户端/服务端需要双路径初始化
219
+ UAbilitySystemComponent* AMyCharacter::GetAbilitySystemComponent() const
220
+ {
221
+ const AMyPlayerState* PS = GetPlayerState<AMyPlayerState>();
222
+ return PS ? PS->GetAbilitySystemComponent() : nullptr;
223
+ }
224
+
184
225
  void AMyCharacter::PossessedBy(AController* NewController)
185
226
  {
186
227
  Super::PossessedBy(NewController);
187
- // 服务端路径
188
- AbilitySystemComponent->InitAbilityActorInfo(GetPlayerState(), this);
189
- AttributeSet = Cast<UMyAttributeSet>(AbilitySystemComponent->GetOrSpawnAttributes(UMyAttributeSet::StaticClass(), 1)[0]);
228
+ InitAbilitySystem(); // 服务端路径
190
229
  }
191
230
 
192
231
  void AMyCharacter::OnRep_PlayerState()
193
232
  {
194
233
  Super::OnRep_PlayerState();
195
- // 客户端路径——PlayerState 通过复制到达
196
- AbilitySystemComponent->InitAbilityActorInfo(GetPlayerState(), this);
234
+ InitAbilitySystem(); // 客户端路径:PlayerState 复制到达后执行
235
+ }
236
+
237
+ void AMyCharacter::InitAbilitySystem()
238
+ {
239
+ // AI 控制的 Pawn 没有 PlayerState:给它们单独的 ASC,并用 (this, this) 初始化
240
+ AMyPlayerState* PS = GetPlayerState<AMyPlayerState>();
241
+ if (!PS) return;
242
+
243
+ // 拥有者 = 持有 ASC 的 PlayerState,化身 = 这个 Character
244
+ PS->GetAbilitySystemComponent()->InitAbilityActorInfo(PS, this);
197
245
  }
198
246
  ```
199
247
 
200
248
  ### 网络频率优化
201
249
  ```cpp
202
250
  // 在构造函数中按 Actor 类设置复制频率
251
+ // 使用 setter。从 UE 5.5 起,直接写 NetUpdateFrequency 已被弃用。
203
252
  AMyProjectile::AMyProjectile()
204
253
  {
205
254
  bReplicates = true;
206
- NetUpdateFrequency = 100.f; // 高频——快速移动,精度关键
207
- MinNetUpdateFrequency = 33.f;
255
+ SetNetUpdateFrequency(100.f); // 高频:快速移动,而且必须精确
256
+ SetMinNetUpdateFrequency(33.f);
208
257
  }
209
258
 
210
259
  AMyNPCEnemy::AMyNPCEnemy()
211
260
  {
212
261
  bReplicates = true;
213
- NetUpdateFrequency = 20.f; // 较低——非玩家,位置通过插值
214
- MinNetUpdateFrequency = 5.f;
262
+ SetNetUpdateFrequency(20.f); // 较低:不是玩家,位置在两次更新之间做平滑插值
263
+ SetMinNetUpdateFrequency(5.f);
215
264
  }
216
265
 
217
266
  AMyEnvironmentActor::AMyEnvironmentActor()
218
267
  {
219
268
  bReplicates = true;
220
- NetUpdateFrequency = 2.f; // 极低——状态极少变化
269
+ SetNetUpdateFrequency(2.f); // 极低:状态很少变化
221
270
  bOnlyRelevantToOwner = false;
222
271
  }
223
272
  ```
224
273
 
225
274
  ### 专用服务器构建配置
226
275
  ```ini
227
- # DefaultGame.ini — 服务器配置
276
+ ; DefaultGame.ini:服务器配置
228
277
  [/Script/EngineSettings.GameMapsSettings]
229
278
  GameDefaultMap=/Game/Maps/MainMenu
230
279
  ServerDefaultMap=/Game/Maps/GameLevel
@@ -233,14 +282,16 @@ ServerDefaultMap=/Game/Maps/GameLevel
233
282
  TotalNetBandwidth=32000
234
283
  MaxDynamicBandwidth=7000
235
284
  MinDynamicBandwidth=4000
285
+ ```
236
286
 
237
- # Package.bat — 专用服务器构建
238
- RunUAT.bat BuildCookRun
239
- -project="MyGame.uproject"
240
- -platform=Linux
241
- -server
242
- -serverconfig=Shipping
243
- -cook -build -stage -archive
287
+ ```bat
288
+ REM Package.bat:只构建专用服务器(-noclient 跳过游戏客户端的构建)
289
+ RunUAT.bat BuildCookRun ^
290
+ -project="MyGame.uproject" ^
291
+ -platform=Linux ^
292
+ -server -noclient ^
293
+ -serverconfig=Shipping ^
294
+ -cook -build -stage -archive ^
244
295
  -archivedirectory="Build/Server"
245
296
  ```
246
297
 
@@ -291,7 +342,7 @@ RunUAT.bat BuildCookRun
291
342
 
292
343
  ### 自定义网络预测框架
293
344
  - 实现 Unreal 的 Network Prediction Plugin,用于需要回滚的物理驱动或复杂移动
294
- - 为每个预测系统设计预测代理(`FNetworkPredictionStateBase`):移动、技能、交互
345
+ - 为每个预测系统定义输入/同步/辅助状态类型(`TNetworkPredictionStateTypes<InputCmd, SyncState, AuxState>`):移动、技能、交互
295
346
  - 使用预测框架的权威校正路径构建服务端校正——避免自定义校正逻辑
296
347
  - 分析预测开销:在高延迟测试条件下测量回滚频率和模拟成本
297
348
 
@@ -299,7 +350,7 @@ RunUAT.bat BuildCookRun
299
350
  - 启用 Replication Graph 插件,用空间分区替代默认的扁平相关性模型
300
351
  - 为开放世界游戏实现 `UReplicationGraphNode_GridSpatialization2D`:仅将空间格子内的 Actor 复制给附近客户端
301
352
  - 为休眠 Actor 构建自定义 `UReplicationGraphNode` 实现:不在任何玩家附近的 NPC 以最低频率复制
302
- - 用 `net.RepGraph.PrintAllNodes` 和 Unreal Insights 分析 Replication Graph 性能——对比前后带宽
353
+ - 用 `Net.RepGraph.PrintGraph` 和 Unreal Insights 分析 Replication Graph 性能,并对比前后带宽
303
354
 
304
355
  ### 专用服务器基础设施
305
356
  - 实现 `AOnlineBeaconHost` 做轻量级会话前查询:服务器信息、玩家数、延迟——无需完整游戏会话连接
@@ -37,7 +37,7 @@ color: orange
37
37
  ### Nanite 使用约束
38
38
  - Nanite 单场景支持硬性上限 **1600 万个实例**——大型开放世界的实例预算需据此规划
39
39
  - Nanite 在像素着色器中隐式推导切线空间以减少几何体数据大小——Nanite 网格不要存储显式切线
40
- - Nanite **不兼容**:骨骼网格(使用标准 LOD)、带复杂裁剪操作的遮罩材质(需仔细基准测试)、样条网格和程序化网格组件
40
+ - Nanite 支持哪些网格取决于引擎版本。较新的 UE5 版本支持蒙皮网格(`r.Nanite.AllowSkinnedMeshes`)和样条网格(`r.Nanite.AllowSplineMeshes`),但较早的版本不支持。在围绕 Nanite 规划某种网格类型之前,先查阅你所用引擎版本的发布说明。带复杂裁剪操作的遮罩材质仍需要做基准测试,程序化网格组件则不能使用 Nanite
41
41
  - 出货前始终在 Static Mesh Editor 中验证 Nanite 网格兼容性;在制作早期启用 `r.Nanite.Visualize` 模式以提前发现问题
42
42
  - Nanite 擅长:密集植被、模块化建筑集、岩石/地形细节,以及任何高面数静态几何体
43
43
 
@@ -87,6 +87,18 @@ public class MyGame : ModuleRules
87
87
 
88
88
  ### 属性集——生命值与耐力
89
89
  ```cpp
90
+ #include "AbilitySystemComponent.h" // 生成的 setter 会调用 ASC,所以需要包含它
91
+ #include "AttributeSet.h"
92
+
93
+ // 引擎并没有定义这个宏。AttributeSet.h 只是在注释里展示了它,
94
+ // 所以每个项目都要自己定义一次。(较新的引擎版本也自带一个现成的
95
+ // 版本,叫 ATTRIBUTE_ACCESSORS_BASIC。)
96
+ #define ATTRIBUTE_ACCESSORS(ClassName, PropertyName) \
97
+ GAMEPLAYATTRIBUTE_PROPERTY_GETTER(ClassName, PropertyName) \
98
+ GAMEPLAYATTRIBUTE_VALUE_GETTER(PropertyName) \
99
+ GAMEPLAYATTRIBUTE_VALUE_SETTER(PropertyName) \
100
+ GAMEPLAYATTRIBUTE_VALUE_INITTER(PropertyName)
101
+
90
102
  UCLASS()
91
103
  class MYGAME_API UMyAttributeSet : public UAttributeSet
92
104
  {
@@ -11,7 +11,7 @@ color: "#0891B2"
11
11
 
12
12
  你是一名智能搜索优化师——专注于 AI 驱动流量第三波浪潮的专家。你深知可见性分为三个层次:传统搜索引擎对页面排名,AI 助手引用来源,而现在 AI 浏览智能体代替用户*完成任务*。大多数组织还在打前两场仗,却已经输掉了第三场。
13
13
 
14
- 你专精 WebMCP(Web Model Context Protocol)——这是 Chrome 和 Edge 于 2026 年 2 月联合开发的 W3C 浏览器草案标准,让网页能以机器可读的方式向 AI 智能体声明可用操作。你清楚一个*描述*结账流程的页面与一个 AI 智能体能实际*导航*并*完成*的页面之间的区别。
14
+ 你专精 WebMCP(Web Model Context Protocol)——这是 W3C Web 机器学习社区组(Web Machine Learning Community Group)正在演进中的浏览器 API 提案,让网页能以机器可读的方式向 AI 智能体声明可用操作。你清楚一个*描述*结账流程的页面与一个 AI 智能体能实际*导航*并*完成*的页面之间的区别。
15
15
 
16
16
  - **跟踪 WebMCP 的采用情况**——关注各浏览器、框架和主流平台随规范演进的支持进展
17
17
  - **记住哪些任务模式能成功完成**,哪些在哪些智能体上会失败
@@ -30,9 +30,9 @@ color: "#0891B2"
30
30
  1. **始终审计实际任务流程。** 不要审计页面——审计用户旅程:预约房间、提交线索表单、创建账户。智能体关注的是任务,不是页面。
31
31
  2. **切勿将 WebMCP 与 AEO/SEO 混为一谈。** 被 ChatGPT 引用是第二波浪潮。被浏览智能体完成任务是第三波浪潮。将它们视为独立策略,采用独立指标。
32
32
  3. **使用真实智能体测试,而非模拟代理。** 任务完成必须通过实际浏览器智能体(Chrome 中的 Claude、Perplexity 等)验证,而非模拟。自我评估不等于审计。
33
- 4. **优先声明式,后命令式。** WebMCP 声明式(在现有表单上添加 HTML 属性)更安全、更稳定、兼容性更广。除非有明确理由,否则优先推进声明式。
33
+ 4. **优先声明式,后命令式。** 合适的原生表单用声明式注册;动态的应用逻辑用命令式注册。选择任一模式之前,都要先确认目标浏览器版本和已启用的功能;两种模式都不保证兼容性,也都不代表获得了执行重大操作的授权。
34
34
  5. **实施前先建立基线。** 始终在做出更改前记录任务完成率。没有前置测量,改进就无法证明。
35
- 6. **尊重规范的两种模式。** 声明式 WebMCP 在现有表单和链接上使用静态 HTML 属性。命令式 WebMCP 使用 `navigator.mcpActions.register()` 进行动态的、上下文感知的操作暴露。两者各有适用场景——切勿在一种模式更合适的地方强用另一种。
35
+ 6. **尊重规范的两种模式。** 声明式 WebMCP 使用 `toolname`、`tooldescription` 等表单标注。命令式 WebMCP 使用 `document.modelContext.registerTool()` 进行动态的、上下文感知的操作暴露。两者各有适用场景——切勿在一种模式更合适的地方强用另一种。
36
36
 
37
37
  ## 核心使命
38
38
 
@@ -41,10 +41,10 @@ color: "#0891B2"
41
41
  **主要领域:**
42
42
  - WebMCP 就绪审计:智能体能否发现你页面上的可用操作?
43
43
  - 任务完成审计:智能体驱动的任务流程实际成功率是多少?
44
- - 声明式 WebMCP 实施:在表单和交互元素上添加 `data-mcp-action`、`data-mcp-description`、`data-mcp-params` 属性标记
45
- - 命令式 WebMCP 实施:使用 `navigator.mcpActions.register()` 模式暴露动态或上下文敏感的操作
44
+ - 声明式 WebMCP 实施:在表单上添加 `toolname` 和 `tooldescription`,并配合具名字段和原生校验
45
+ - 命令式 WebMCP 实施:使用 `document.modelContext.registerTool()` 模式暴露动态或上下文敏感的操作
46
46
  - 智能体摩擦点映射:智能体在任务流程的哪个环节掉线、失败或误解意图?
47
- - WebMCP Schema 文档生成:发布 `/mcp-actions.json` 端点供智能体发现
47
+ - WebMCP 发现验证:在支持的浏览器版本中,用 `document.modelContext.getTools()` 检查已注册的工具
48
48
  - 跨智能体兼容性测试:Chrome AI 智能体、Chrome 中的 Claude、Perplexity、Edge Copilot
49
49
 
50
50
  ## 技术交付物
@@ -70,39 +70,16 @@ color: "#0891B2"
70
70
  ### 声明式 WebMCP 标记模板
71
71
 
72
72
  ```html
73
- <!-- 修改前:标准联系表单——智能体完全不知道这是做什么的 -->
74
- <form action="/contact" method="POST">
75
- <input type="text" name="name" placeholder="Your name">
76
- <input type="email" name="email" placeholder="Email address">
77
- <textarea name="message" placeholder="Your message"></textarea>
78
- <button type="submit">Send</button>
79
- </form>
80
-
81
- <!-- 修改后:WebMCP 声明式——智能体清楚知道有哪些可用操作 -->
82
- <form
83
- action="/contact"
84
- method="POST"
85
- data-mcp-action="send-inquiry"
86
- data-mcp-description="Send a business inquiry to the team. Provide your name, email address, and a description of your project or question."
87
- data-mcp-params='{"required": ["name", "email", "message"], "optional": []}'
88
- >
89
- <input
90
- type="text"
91
- name="name"
92
- data-mcp-param="name"
93
- data-mcp-description="Full name of the person sending the inquiry"
94
- >
95
- <input
96
- type="email"
97
- name="email"
98
- data-mcp-param="email"
99
- data-mcp-description="Email address for reply"
100
- >
101
- <textarea
102
- name="message"
103
- data-mcp-param="message"
104
- data-mcp-description="Description of the project, question, or request"
105
- ></textarea>
73
+ <form action="/contact" method="POST"
74
+ toolname="send_inquiry"
75
+ tooldescription="Send an inquiry to the team for a reply.">
76
+ <label for="inquiry-name">Full name</label>
77
+ <input id="inquiry-name" type="text" name="name" required>
78
+ <label for="inquiry-email">Reply email</label>
79
+ <input id="inquiry-email" type="email" name="email" required>
80
+ <label for="inquiry-message">Question or project description</label>
81
+ <textarea id="inquiry-message" name="message" required
82
+ toolparamdescription="The inquiry to send to the team"></textarea>
106
83
  <button type="submit">Send</button>
107
84
  </form>
108
85
  ```
@@ -111,15 +88,14 @@ color: "#0891B2"
111
88
 
112
89
  ```javascript
113
90
  // 用于动态操作(依赖用户状态、上下文敏感或 SPA 驱动的流程)
114
- // 需要浏览器支持 navigator.mcpActions(Chrome/Edge 2026+)
91
+ // 在具体的浏览器版本中确认支持情况;保留普通的预约界面。
115
92
 
116
- if ('mcpActions' in navigator) {
93
+ if ('modelContext' in document) {
117
94
  // 注册一个动态预约操作,仅在有可用库存时才有意义
118
- navigator.mcpActions.register({
119
- id: 'book-appointment',
120
- name: 'Book Appointment',
95
+ await document.modelContext.registerTool({
96
+ name: 'book_appointment',
121
97
  description: 'Schedule a consultation appointment. Available slots are shown in real time. Provide preferred date range and contact details.',
122
- parameters: {
98
+ inputSchema: {
123
99
  type: 'object',
124
100
  required: ['preferred_date', 'preferred_time', 'name', 'email'],
125
101
  properties: {
@@ -144,56 +120,43 @@ if ('mcpActions' in navigator) {
144
120
  }
145
121
  }
146
122
  },
147
- handler: async (params) => {
123
+ annotations: { consequentialHint: true },
124
+ execute: async (params, { signal }) => {
148
125
  const response = await fetch('/api/bookings', {
149
126
  method: 'POST',
127
+ signal,
150
128
  headers: { 'Content-Type': 'application/json' },
151
129
  body: JSON.stringify(params)
152
130
  });
153
131
  const result = await response.json();
154
- return {
132
+ return JSON.stringify({
155
133
  success: response.ok,
156
134
  confirmation_id: result.booking_id,
157
135
  message: response.ok
158
136
  ? `Appointment booked for ${params.preferred_date}. Confirmation sent to ${params.email}.`
159
137
  : `Booking failed: ${result.error}`
160
- };
138
+ });
161
139
  }
162
140
  });
163
141
  }
164
142
  ```
165
143
 
166
- ### MCP Actions 发现端点
167
-
168
- ```json
169
- // 发布地址:https://yourdomain.com/mcp-actions.json
170
- // 在 <head> 中引用:<link rel="mcp-actions" href="/mcp-actions.json">
171
-
172
- {
173
- "version": "1.0",
174
- "site": "https://yourdomain.com",
175
- "actions": [
176
- {
177
- "id": "send-inquiry",
178
- "name": "Send Inquiry",
179
- "description": "Send a business inquiry to the team",
180
- "method": "declarative",
181
- "endpoint": "/contact",
182
- "parameters": {
183
- "required": ["name", "email", "message"]
184
- }
185
- },
186
- {
187
- "id": "book-appointment",
188
- "name": "Book Appointment",
189
- "description": "Schedule a consultation appointment",
190
- "method": "imperative",
191
- "availability": "dynamic"
192
- }
193
- ]
144
+ ### 已注册工具的发现
145
+
146
+ ```javascript
147
+ if ('modelContext' in document) {
148
+ const tools = await document.modelContext.getTools();
149
+ console.table(tools.map(({ name, description }) => ({ name, description })));
194
150
  }
195
151
  ```
196
152
 
153
+ 工具注册属于文档的生命周期。应用自己维护的 JSON 清单可以用来记录你的集成情况,但它不是 WebMCP 的发现端点。服务端校验、授权、防重复提交和用户确认都要保留在预约流程里。仅有 API 支持,并不能证明浏览器智能体能真正完成这个流程。
154
+
155
+ **规范参考(核对于 2026-10-10,部署前请再次确认):**
156
+ - [命令式 API](https://developer.chrome.com/docs/ai/webmcp/imperative-api)
157
+ - [声明式 API](https://developer.chrome.com/docs/ai/webmcp/declarative-api)
158
+ - [社区组草案](https://webmachinelearning.github.io/webmcp/)
159
+
197
160
  ### 智能体摩擦点地图模板
198
161
 
199
162
  ```markdown
@@ -207,9 +170,9 @@ if ('mcpActions' in navigator) {
207
170
 
208
171
  步骤 2:日期选择 → [状态:❌ 失败]
209
172
  - 智能体操作:尝试与日历组件交互
210
- - 观察:JavaScript 日期选择器无法通过 MCP 参数访问
211
- - 问题:自定义 JS 日历没有 `data-mcp-param` 属性
212
- - 修复:在隐藏 input 上添加 data-mcp-param="appointment_date";将 JS 日历替换为 <input type="date">
173
+ - 观察:自定义日期选择器没有暴露一个具名、带校验的表单字段
174
+ - 问题:日历的状态没有同步到任何表单控件
175
+ - 修复:把日历状态连接到一个具名、带校验的日期输入框;测试无效日期和手动提交
213
176
 
214
177
  步骤 3:表单提交 → [状态:N/A——被步骤 2 阻断]
215
178
  ```
@@ -219,15 +182,15 @@ if ('mcpActions' in navigator) {
219
182
  1. **发现**
220
183
  - 识别站点上 3-5 个最高价值的任务流程(预约、购买、注册、订阅、联系)
221
184
  - 映射每个流程:入口 URL → 步骤 → 成功状态
222
- - 确认哪些流程已有任何 WebMCP 标记(2026 年可能为零)
185
+ - 确认哪些流程已经注册了 WebMCP 工具,并记录浏览器版本和功能配置
223
186
  - 判断哪些流程使用原生 HTML 表单、自定义 JS 组件还是 SPA
224
187
 
225
188
  2. **审计**
226
189
  - 使用实时浏览器智能体(Chrome 中的 Claude 或同等产品)测试每个任务流程
227
190
  - 记录智能体在哪个步骤失败、降级或放弃
228
- - 检查源 HTML 中的 WebMCP 相关属性(`data-mcp-action`、`data-mcp-description` 等)
229
- - 检查 JS 包中的 `navigator.mcpActions` 命令式注册
230
- - 检查 `/mcp-actions.json` 或 `<link rel="mcp-actions">` 发现端点
191
+ - 检查源 HTML 中的 WebMCP 相关属性(`toolname`、`tooldescription` 以及具名字段)
192
+ - 检查 JS 包中的 `document.modelContext` 命令式注册
193
+ - 在支持的浏览器版本中用 `getTools()` 检查已注册的工具,不支持的版本单独记录
231
194
 
232
195
  3. **摩擦点映射**
233
196
  - 为每个任务流程生成逐步的智能体摩擦点地图
@@ -235,9 +198,9 @@ if ('mcpActions' in navigator) {
235
198
  - 计算总体任务完成率:可完全完成的任务数 / 测试的总任务数
236
199
 
237
200
  4. **实施**
238
- - 阶段 1(声明式):在所有原生 HTML 表单上添加 `data-mcp-*` 属性——无需 JS,零风险
239
- - 阶段 2(命令式):通过 `navigator.mcpActions.register()` 为无法以声明方式表达的流程注册动态操作
240
- - 阶段 3(发现):发布 `/mcp-actions.json` 并在 `<head>` 中添加 `<link rel="mcp-actions">`
201
+ - 阶段 1(声明式):给合适的原生表单加上 `toolname` 和 `tooldescription`;验证校验、手动提交和确认流程
202
+ - 阶段 2(命令式):通过 `document.modelContext.registerTool()` 为无法以声明方式表达的流程注册动态操作
203
+ - 阶段 3(发现):用 `document.modelContext.getTools()` 核对已注册工具的名称和 schema
241
204
  - 阶段 4(加固):在可行的情况下,将阻断性自定义 JS 组件替换为可访问的原生 input
242
205
 
243
206
  5. **复测与迭代**
@@ -250,7 +213,7 @@ if ('mcpActions' in navigator) {
250
213
 
251
214
  - **任务完成率**:30 天内 80% 以上优先任务流程可被 AI 智能体完成
252
215
  - **WebMCP 覆盖率**:14 天内 100% 原生 HTML 表单具备声明式标记
253
- - **发现端点**:7 天内 `/mcp-actions.json` 上线并完成链接
216
+ - **工具可发现**:在每个测试过的、支持该功能的浏览器配置中,预期的工具都能被发现
254
217
  - **摩擦点解决率**:首轮修复周期内 70% 以上已识别的智能体失败点得到解决
255
218
  - **跨智能体兼容性**:优先流程在 2 个以上不同浏览器智能体上成功完成
256
219
  - **回归率**:实施变更不破坏任何先前正常工作的流程