deepspider 0.1.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.
Files changed (261) hide show
  1. package/.claude/agents/check.md +122 -0
  2. package/.claude/agents/debug.md +106 -0
  3. package/.claude/agents/dispatch.md +214 -0
  4. package/.claude/agents/implement.md +96 -0
  5. package/.claude/agents/plan.md +396 -0
  6. package/.claude/agents/research.md +120 -0
  7. package/.claude/commands/evolve/merge.md +80 -0
  8. package/.claude/commands/trellis/before-backend-dev.md +13 -0
  9. package/.claude/commands/trellis/before-frontend-dev.md +13 -0
  10. package/.claude/commands/trellis/break-loop.md +107 -0
  11. package/.claude/commands/trellis/check-backend.md +13 -0
  12. package/.claude/commands/trellis/check-cross-layer.md +153 -0
  13. package/.claude/commands/trellis/check-frontend.md +13 -0
  14. package/.claude/commands/trellis/create-command.md +154 -0
  15. package/.claude/commands/trellis/finish-work.md +129 -0
  16. package/.claude/commands/trellis/integrate-skill.md +219 -0
  17. package/.claude/commands/trellis/onboard.md +358 -0
  18. package/.claude/commands/trellis/parallel.md +193 -0
  19. package/.claude/commands/trellis/record-session.md +62 -0
  20. package/.claude/commands/trellis/start.md +280 -0
  21. package/.claude/commands/trellis/update-spec.md +213 -0
  22. package/.claude/hooks/inject-subagent-context.py +758 -0
  23. package/.claude/hooks/ralph-loop.py +374 -0
  24. package/.claude/hooks/session-start.py +126 -0
  25. package/.claude/settings.json +41 -0
  26. package/.claude/skills/deepagents-guide/SKILL.md +428 -0
  27. package/.cursor/commands/trellis-before-backend-dev.md +13 -0
  28. package/.cursor/commands/trellis-before-frontend-dev.md +13 -0
  29. package/.cursor/commands/trellis-break-loop.md +107 -0
  30. package/.cursor/commands/trellis-check-backend.md +13 -0
  31. package/.cursor/commands/trellis-check-cross-layer.md +153 -0
  32. package/.cursor/commands/trellis-check-frontend.md +13 -0
  33. package/.cursor/commands/trellis-create-command.md +154 -0
  34. package/.cursor/commands/trellis-finish-work.md +129 -0
  35. package/.cursor/commands/trellis-integrate-skill.md +219 -0
  36. package/.cursor/commands/trellis-onboard.md +358 -0
  37. package/.cursor/commands/trellis-record-session.md +62 -0
  38. package/.cursor/commands/trellis-start.md +156 -0
  39. package/.cursor/commands/trellis-update-spec.md +213 -0
  40. package/.env.example +11 -0
  41. package/.husky/pre-commit +1 -0
  42. package/.mcp.json +8 -0
  43. package/.trellis/.template-hashes.json +65 -0
  44. package/.trellis/.version +1 -0
  45. package/.trellis/scripts/add-session.sh +384 -0
  46. package/.trellis/scripts/common/developer.sh +129 -0
  47. package/.trellis/scripts/common/git-context.sh +263 -0
  48. package/.trellis/scripts/common/paths.sh +208 -0
  49. package/.trellis/scripts/common/phase.sh +150 -0
  50. package/.trellis/scripts/common/registry.sh +247 -0
  51. package/.trellis/scripts/common/task-queue.sh +142 -0
  52. package/.trellis/scripts/common/task-utils.sh +151 -0
  53. package/.trellis/scripts/common/worktree.sh +128 -0
  54. package/.trellis/scripts/create-bootstrap.sh +299 -0
  55. package/.trellis/scripts/get-context.sh +7 -0
  56. package/.trellis/scripts/get-developer.sh +15 -0
  57. package/.trellis/scripts/init-developer.sh +34 -0
  58. package/.trellis/scripts/multi-agent/cleanup.sh +396 -0
  59. package/.trellis/scripts/multi-agent/create-pr.sh +241 -0
  60. package/.trellis/scripts/multi-agent/plan.sh +207 -0
  61. package/.trellis/scripts/multi-agent/start.sh +310 -0
  62. package/.trellis/scripts/multi-agent/status.sh +828 -0
  63. package/.trellis/scripts/task.sh +1118 -0
  64. package/.trellis/spec/backend/deepagents-guide.md +337 -0
  65. package/.trellis/spec/backend/directory-structure.md +126 -0
  66. package/.trellis/spec/backend/examples/skills/deepagents-guide/README.md +11 -0
  67. package/.trellis/spec/backend/examples/skills/deepagents-guide/agent.js.template +20 -0
  68. package/.trellis/spec/backend/examples/skills/deepagents-guide/skills-config.js.template +13 -0
  69. package/.trellis/spec/backend/examples/skills/deepagents-guide/subagent.js.template +19 -0
  70. package/.trellis/spec/backend/hook-guidelines.md +178 -0
  71. package/.trellis/spec/backend/index.md +36 -0
  72. package/.trellis/spec/backend/quality-guidelines.md +201 -0
  73. package/.trellis/spec/backend/state-management.md +76 -0
  74. package/.trellis/spec/backend/tool-guidelines.md +144 -0
  75. package/.trellis/spec/backend/type-safety.md +71 -0
  76. package/.trellis/spec/guides/code-reuse-thinking-guide.md +92 -0
  77. package/.trellis/spec/guides/cross-layer-thinking-guide.md +94 -0
  78. package/.trellis/spec/guides/index.md +79 -0
  79. package/.trellis/tasks/archive/02-02-evolving-skills/prd.md +61 -0
  80. package/.trellis/tasks/archive/02-02-evolving-skills/task.json +29 -0
  81. package/.trellis/tasks/archive/2026-02/00-bootstrap-guidelines/prd.md +86 -0
  82. package/.trellis/tasks/archive/2026-02/00-bootstrap-guidelines/task.json +27 -0
  83. package/.trellis/tasks/archive/2026-02/02-02-skills-system/check.jsonl +3 -0
  84. package/.trellis/tasks/archive/2026-02/02-02-skills-system/debug.jsonl +2 -0
  85. package/.trellis/tasks/archive/2026-02/02-02-skills-system/implement.jsonl +5 -0
  86. package/.trellis/tasks/archive/2026-02/02-02-skills-system/prd.md +33 -0
  87. package/.trellis/tasks/archive/2026-02/02-02-skills-system/task.json +41 -0
  88. package/.trellis/workflow.md +407 -0
  89. package/.trellis/workspace/index.md +123 -0
  90. package/.trellis/workspace/pony/index.md +40 -0
  91. package/.trellis/workspace/pony/journal-1.md +7 -0
  92. package/.trellis/worktree.yaml +47 -0
  93. package/AGENTS.md +18 -0
  94. package/CLAUDE.md +292 -0
  95. package/README.md +134 -0
  96. package/agents/deepspider.md +142 -0
  97. package/docs/DEBUG.md +42 -0
  98. package/docs/GUIDE.md +334 -0
  99. package/docs/PROMPT.md +60 -0
  100. package/docs/USAGE.md +226 -0
  101. package/eslint.config.js +51 -0
  102. package/package.json +78 -0
  103. package/requirements-crypto.txt +14 -0
  104. package/src/agent/index.js +97 -0
  105. package/src/agent/logger.js +164 -0
  106. package/src/agent/middleware/filterTools.js +64 -0
  107. package/src/agent/middleware/report.js +79 -0
  108. package/src/agent/prompts/system.js +315 -0
  109. package/src/agent/run.js +575 -0
  110. package/src/agent/skills/anti-detect/SKILL.md +28 -0
  111. package/src/agent/skills/anti-detect/evolved.md +12 -0
  112. package/src/agent/skills/captcha/SKILL.md +37 -0
  113. package/src/agent/skills/captcha/evolved.md +12 -0
  114. package/src/agent/skills/config.js +30 -0
  115. package/src/agent/skills/crawler/SKILL.md +9 -0
  116. package/src/agent/skills/crawler/evolved.md +16 -0
  117. package/src/agent/skills/dynamic-analysis/SKILL.md +91 -0
  118. package/src/agent/skills/dynamic-analysis/evolved.md +12 -0
  119. package/src/agent/skills/env/SKILL.md +72 -0
  120. package/src/agent/skills/env/evolved.md +12 -0
  121. package/src/agent/skills/evolve.js +79 -0
  122. package/src/agent/skills/general/SKILL.md +12 -0
  123. package/src/agent/skills/general/evolved.md +12 -0
  124. package/src/agent/skills/js2python/SKILL.md +30 -0
  125. package/src/agent/skills/js2python/evolved.md +13 -0
  126. package/src/agent/skills/report/SKILL.md +21 -0
  127. package/src/agent/skills/report/evolved.md +12 -0
  128. package/src/agent/skills/sandbox/SKILL.md +22 -0
  129. package/src/agent/skills/sandbox/evolved.md +16 -0
  130. package/src/agent/skills/static-analysis/SKILL.md +93 -0
  131. package/src/agent/skills/static-analysis/evolved.md +12 -0
  132. package/src/agent/skills/xpath/SKILL.md +119 -0
  133. package/src/agent/subagents/anti-detect.js +45 -0
  134. package/src/agent/subagents/captcha.js +51 -0
  135. package/src/agent/subagents/crawler.js +138 -0
  136. package/src/agent/subagents/dynamic.js +64 -0
  137. package/src/agent/subagents/env-agent.js +82 -0
  138. package/src/agent/subagents/index.js +37 -0
  139. package/src/agent/subagents/js2python.js +72 -0
  140. package/src/agent/subagents/sandbox.js +55 -0
  141. package/src/agent/subagents/static.js +66 -0
  142. package/src/agent/tools/analysis.js +135 -0
  143. package/src/agent/tools/analyzer.js +85 -0
  144. package/src/agent/tools/anti-detect.js +89 -0
  145. package/src/agent/tools/antidebug.js +64 -0
  146. package/src/agent/tools/async.js +43 -0
  147. package/src/agent/tools/browser.js +324 -0
  148. package/src/agent/tools/captcha.js +223 -0
  149. package/src/agent/tools/capture.js +179 -0
  150. package/src/agent/tools/correlate.js +303 -0
  151. package/src/agent/tools/crawler.js +116 -0
  152. package/src/agent/tools/cryptohook.js +80 -0
  153. package/src/agent/tools/debug.js +246 -0
  154. package/src/agent/tools/deobfuscator.js +90 -0
  155. package/src/agent/tools/env.js +83 -0
  156. package/src/agent/tools/envdump.js +92 -0
  157. package/src/agent/tools/evolve.js +164 -0
  158. package/src/agent/tools/extract.js +114 -0
  159. package/src/agent/tools/extractor.js +54 -0
  160. package/src/agent/tools/file.js +224 -0
  161. package/src/agent/tools/hook.js +84 -0
  162. package/src/agent/tools/hookManager.js +178 -0
  163. package/src/agent/tools/index.js +137 -0
  164. package/src/agent/tools/nodejs.js +101 -0
  165. package/src/agent/tools/patch.js +46 -0
  166. package/src/agent/tools/preprocess.js +71 -0
  167. package/src/agent/tools/profile.js +122 -0
  168. package/src/agent/tools/python.js +627 -0
  169. package/src/agent/tools/report.js +124 -0
  170. package/src/agent/tools/runtime.js +132 -0
  171. package/src/agent/tools/sandbox.js +79 -0
  172. package/src/agent/tools/store.js +73 -0
  173. package/src/agent/tools/trace.js +74 -0
  174. package/src/agent/tools/tracing.js +201 -0
  175. package/src/agent/tools/utils.js +51 -0
  176. package/src/agent/tools/verify.js +184 -0
  177. package/src/agent/tools/webcrack.js +109 -0
  178. package/src/analyzer/ASTAnalyzer.js +387 -0
  179. package/src/analyzer/CallStackAnalyzer.js +379 -0
  180. package/src/analyzer/Deobfuscator.js +289 -0
  181. package/src/analyzer/EncryptionAnalyzer.js +99 -0
  182. package/src/analyzer/index.js +22 -0
  183. package/src/browser/EnvBridge.js +186 -0
  184. package/src/browser/cdp.js +168 -0
  185. package/src/browser/client.js +197 -0
  186. package/src/browser/collector.js +444 -0
  187. package/src/browser/collectors/RequestCryptoLinker.js +109 -0
  188. package/src/browser/collectors/ResponseSearcher.js +107 -0
  189. package/src/browser/collectors/ScriptCollector.js +158 -0
  190. package/src/browser/collectors/index.js +26 -0
  191. package/src/browser/defaultHooks.js +932 -0
  192. package/src/browser/hooks/crypto.js +55 -0
  193. package/src/browser/hooks/index.js +64 -0
  194. package/src/browser/hooks/native.js +9 -0
  195. package/src/browser/hooks/network.js +33 -0
  196. package/src/browser/index.js +42 -0
  197. package/src/browser/interceptors/NetworkInterceptor.js +116 -0
  198. package/src/browser/interceptors/ScriptInterceptor.js +76 -0
  199. package/src/browser/interceptors/index.js +6 -0
  200. package/src/browser/ui/analysisPanel.js +1782 -0
  201. package/src/browser/ui/confirmDialog.js +158 -0
  202. package/src/browser/ui/panel.html +152 -0
  203. package/src/browser/ui/selector.js +170 -0
  204. package/src/config/index.js +5 -0
  205. package/src/config/paths.js +71 -0
  206. package/src/config/patterns/crypto.js +36 -0
  207. package/src/config/profiles/chrome.json +71 -0
  208. package/src/config/profiles/firefox.json +44 -0
  209. package/src/config/profiles/safari.json +38 -0
  210. package/src/core/EnvMonitor.js +200 -0
  211. package/src/core/PatchGenerator.js +278 -0
  212. package/src/core/Sandbox.js +181 -0
  213. package/src/env/AntiAntiDebug.js +111 -0
  214. package/src/env/AsyncHook.js +68 -0
  215. package/src/env/BrowserAPIList.js +265 -0
  216. package/src/env/CookieHook.js +48 -0
  217. package/src/env/CryptoHook.js +205 -0
  218. package/src/env/EnvCodeGenerator.js +157 -0
  219. package/src/env/EnvDumper.js +356 -0
  220. package/src/env/EnvExtractor.js +220 -0
  221. package/src/env/HookBase.js +618 -0
  222. package/src/env/NetworkHook.js +159 -0
  223. package/src/env/modules/bom/history.js +29 -0
  224. package/src/env/modules/bom/location.js +26 -0
  225. package/src/env/modules/bom/navigator.js +70 -0
  226. package/src/env/modules/bom/screen.js +26 -0
  227. package/src/env/modules/bom/storage.js +23 -0
  228. package/src/env/modules/dom/document.js +110 -0
  229. package/src/env/modules/dom/event.js +51 -0
  230. package/src/env/modules/index.js +34 -0
  231. package/src/env/modules/webapi/fetch.js +46 -0
  232. package/src/env/modules/webapi/url.js +47 -0
  233. package/src/env/modules/webapi/xhr.js +48 -0
  234. package/src/index.js +27 -0
  235. package/src/mcp/server.js +89 -0
  236. package/src/store/DataStore.js +708 -0
  237. package/src/store/Store.js +158 -0
  238. package/src/store/Validator.js +24 -0
  239. package/test/analyze.test.js +90 -0
  240. package/test/envdump.test.js +74 -0
  241. package/test/flow.test.js +90 -0
  242. package/test/hooks.test.js +138 -0
  243. package/test/plugin.test.js +35 -0
  244. package/test/refactor-full.test.js +30 -0
  245. package/test/refactor.test.js +21 -0
  246. package/test/samples/obfuscated.js +61 -0
  247. package/test/samples/original.js +66 -0
  248. package/test/samples/v10_eval_chain.js +52 -0
  249. package/test/samples/v11_bytecode_vm.js +81 -0
  250. package/test/samples/v12_polymorphic.js +69 -0
  251. package/test/samples/v1_ob_basic.js +98 -0
  252. package/test/samples/v2_ob_advanced.js +99 -0
  253. package/test/samples/v3_jjencode.js +77 -0
  254. package/test/samples/v4_aaencode.js +73 -0
  255. package/test/samples/v5_control_flow.js +86 -0
  256. package/test/samples/v6_string_encryption.js +71 -0
  257. package/test/samples/v7_jsvmp.js +83 -0
  258. package/test/samples/v8_anti_debug.js +79 -0
  259. package/test/samples/v9_proxy_trap.js +49 -0
  260. package/test/samples.test.js +96 -0
  261. package/test/webcrack.test.js +55 -0
@@ -0,0 +1,428 @@
1
+ ---
2
+ name: deepagents-guide
3
+ description: DeepAgents JS 框架使用指南,包含 Agent 创建、后端存储、子代理、中间件、技能和人机交互配置。
4
+ ---
5
+
6
+ # DeepAgents JS 使用指南
7
+
8
+ ## 概述
9
+
10
+ DeepAgents 是基于 LangGraph 的 Agent 框架,提供:
11
+ - 模块化中间件架构
12
+ - 多种后端存储方案
13
+ - 子代理任务委派
14
+ - 人机交互审批流程
15
+ - 长期记忆持久化
16
+ - 技能系统
17
+
18
+ ## 快速开始
19
+
20
+ ### 安装
21
+
22
+ ```bash
23
+ npm install deepagents @langchain/core @langchain/anthropic zod
24
+ ```
25
+
26
+ ### 基础 Agent
27
+
28
+ ```typescript
29
+ import { createDeepAgent, StateBackend } from "deepagents";
30
+ import { tool } from "@langchain/core/tools";
31
+ import { z } from "zod";
32
+
33
+ // 定义工具
34
+ const myTool = tool(
35
+ async ({ input }) => {
36
+ return `处理结果: ${input}`;
37
+ },
38
+ {
39
+ name: "my_tool",
40
+ description: "工具描述",
41
+ schema: z.object({
42
+ input: z.string().describe("输入参数"),
43
+ }),
44
+ }
45
+ );
46
+
47
+ // 创建 Agent
48
+ const agent = createDeepAgent({
49
+ name: "my-agent",
50
+ model: "claude-sonnet-4-20250514",
51
+ tools: [myTool],
52
+ systemPrompt: "你是一个助手。",
53
+ backend: new StateBackend(),
54
+ });
55
+
56
+ // 调用
57
+ const config = { configurable: { thread_id: "session-1" } };
58
+ const result = await agent.invoke(
59
+ { messages: [{ role: "user", content: "你好" }] },
60
+ config
61
+ );
62
+ ```
63
+
64
+ ## 后端存储
65
+
66
+ ### StateBackend(默认)
67
+
68
+ 临时存储,数据保存在 Agent 状态中,线程结束后丢失。
69
+
70
+ ```typescript
71
+ import { StateBackend } from "deepagents";
72
+
73
+ const agent = createDeepAgent({
74
+ backend: new StateBackend(),
75
+ });
76
+ ```
77
+
78
+ ### FilesystemBackend
79
+
80
+ 基于本地文件系统的持久化存储。
81
+
82
+ ```typescript
83
+ import { FilesystemBackend } from "deepagents";
84
+
85
+ const agent = createDeepAgent({
86
+ backend: new FilesystemBackend({
87
+ rootDir: "./agent-data",
88
+ }),
89
+ });
90
+ ```
91
+
92
+ ### StoreBackend
93
+
94
+ 基于 LangGraph Store 的持久化存储,支持跨线程访问。
95
+
96
+ ```typescript
97
+ import { StoreBackend } from "deepagents";
98
+ import { InMemoryStore } from "@langchain/langgraph-checkpoint";
99
+
100
+ const store = new InMemoryStore();
101
+
102
+ const agent = createDeepAgent({
103
+ store,
104
+ backend: (config) => new StoreBackend(config),
105
+ });
106
+ ```
107
+
108
+ ### CompositeBackend(混合存储)
109
+
110
+ 组合多个后端,按路径前缀路由。
111
+
112
+ ```typescript
113
+ import { CompositeBackend, StateBackend, StoreBackend } from "deepagents";
114
+
115
+ const agent = createDeepAgent({
116
+ store: new InMemoryStore(),
117
+ backend: (config) => new CompositeBackend(
118
+ new StateBackend(config), // 默认:临时存储
119
+ { "/memories/": new StoreBackend(config) } // /memories/ 路径:持久化
120
+ ),
121
+ });
122
+ ```
123
+
124
+ **路径路由规则:**
125
+ - `/memories/*` → 持久化存储(跨线程)
126
+ - 其他路径 → 临时存储(仅当前线程)
127
+
128
+ ## 中间件
129
+
130
+ `createDeepAgent` 默认附加三个中间件:
131
+ - `TodoListMiddleware` - 任务规划
132
+ - `FilesystemMiddleware` - 文件操作
133
+ - `SubAgentMiddleware` - 子代理委派
134
+
135
+ ### TodoList 中间件
136
+
137
+ 提供 `write_todos` 工具用于任务管理。
138
+
139
+ ```typescript
140
+ import { createAgent, todoListMiddleware } from "langchain";
141
+
142
+ const agent = createAgent({
143
+ model: "claude-sonnet-4-20250514",
144
+ middleware: [
145
+ todoListMiddleware({
146
+ systemPrompt: "使用 write_todos 工具来...",
147
+ }),
148
+ ],
149
+ });
150
+ ```
151
+
152
+ ### Filesystem 中间件
153
+
154
+ 提供四个文件操作工具:
155
+ - `ls` - 列出文件
156
+ - `read_file` - 读取文件
157
+ - `write_file` - 创建文件
158
+ - `edit_file` - 编辑文件
159
+
160
+ ```typescript
161
+ import { createFilesystemMiddleware } from "deepagents";
162
+
163
+ const agent = createAgent({
164
+ middleware: [
165
+ createFilesystemMiddleware({
166
+ backend: undefined, // 可选自定义后端
167
+ systemPrompt: "当需要保存信息时写入文件系统...",
168
+ customToolDescriptions: {
169
+ ls: "使用 ls 工具来...",
170
+ read_file: "使用 read_file 工具来...",
171
+ },
172
+ }),
173
+ ],
174
+ });
175
+ ```
176
+
177
+ ### SubAgent 中间件
178
+
179
+ 启用任务委派给专门的子代理。
180
+
181
+ ```typescript
182
+ import { createSubAgentMiddleware } from "deepagents";
183
+
184
+ const agent = createAgent({
185
+ middleware: [
186
+ createSubAgentMiddleware({
187
+ defaultModel: "claude-sonnet-4-20250514",
188
+ defaultTools: [],
189
+ subagents: [
190
+ {
191
+ name: "weather",
192
+ description: "获取城市天气信息",
193
+ systemPrompt: "使用 get_weather 工具获取天气",
194
+ tools: [getWeather],
195
+ model: "gpt-4o", // 可选:覆盖默认模型
196
+ },
197
+ ],
198
+ }),
199
+ ],
200
+ });
201
+ ```
202
+
203
+ ## 子代理 (Subagents)
204
+
205
+ 子代理用于任务委派,保持主代理上下文清洁。
206
+
207
+ ### 使用场景
208
+
209
+ **适合使用:**
210
+ - 多步骤任务(避免主上下文膨胀)
211
+ - 需要专门指令/工具的领域
212
+ - 需要不同模型能力的任务
213
+
214
+ **不适合:**
215
+ - 简单单步任务
216
+ - 需要中间上下文的场景
217
+
218
+ ### 字典式子代理
219
+
220
+ ```typescript
221
+ const researchSubagent = {
222
+ name: "research-agent",
223
+ description: "深度研究问题",
224
+ systemPrompt: "你是一个优秀的研究员",
225
+ tools: [internetSearch],
226
+ model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
227
+ };
228
+
229
+ const agent = createDeepAgent({
230
+ model: new ChatAnthropic({ model: "claude-sonnet-4-20250514" }),
231
+ subagents: [researchSubagent],
232
+ });
233
+ ```
234
+
235
+ ### CompiledSubAgent
236
+
237
+ 使用预构建的 LangGraph 图作为子代理:
238
+
239
+ ```typescript
240
+ import { CompiledSubAgent } from "deepagents";
241
+
242
+ const customSubagent: CompiledSubAgent = {
243
+ name: "data-analyzer",
244
+ description: "复杂数据分析任务",
245
+ runnable: customGraph.compile(),
246
+ };
247
+ ```
248
+
249
+ ### 通用子代理
250
+
251
+ DeepAgents 自动提供 `general-purpose` 子代理:
252
+ - 共享主代理的系统提示
253
+ - 访问相同工具
254
+ - 用于上下文隔离
255
+
256
+ ## 人机交互 (Human-in-the-Loop)
257
+
258
+ 配置敏感工具需要人工审批。
259
+
260
+ ### 配置
261
+
262
+ ```typescript
263
+ import { MemorySaver } from "@langchain/langgraph";
264
+
265
+ const agent = createDeepAgent({
266
+ model: "claude-sonnet-4-20250514",
267
+ tools: [deleteFile, sendEmail],
268
+ interruptOn: {
269
+ delete_file: true,
270
+ send_email: { allowedDecisions: ["approve", "reject"] },
271
+ },
272
+ checkpointer: new MemorySaver(), // 必需!
273
+ });
274
+ ```
275
+
276
+ ### 决策类型
277
+
278
+ - `approve` - 使用原参数执行
279
+ - `edit` - 修改参数后执行
280
+ - `reject` - 跳过工具调用
281
+
282
+ ### 处理中断
283
+
284
+ ```typescript
285
+ import { Command } from "@langchain/langgraph";
286
+
287
+ let result = await agent.invoke({
288
+ messages: [{ role: "user", content: "删除 temp.txt" }]
289
+ }, config);
290
+
291
+ if (result.__interrupt__) {
292
+ const decisions = [{ type: "approve" }];
293
+ result = await agent.invoke(
294
+ new Command({ resume: { decisions } }),
295
+ config
296
+ );
297
+ }
298
+ ```
299
+
300
+ ## 长期记忆
301
+
302
+ 使用 `CompositeBackend` 实现跨线程持久化。
303
+
304
+ ### 配置
305
+
306
+ ```typescript
307
+ const agent = createDeepAgent({
308
+ store: new InMemoryStore(),
309
+ backend: (config) => new CompositeBackend(
310
+ new StateBackend(config),
311
+ { "/memories/": new StoreBackend(config) }
312
+ ),
313
+ });
314
+ ```
315
+
316
+ ### 跨线程访问
317
+
318
+ ```typescript
319
+ // 线程 1: 写入
320
+ await agent.invoke({
321
+ messages: [{ role: "user", content: "保存偏好到 /memories/prefs.txt" }],
322
+ }, { configurable: { thread_id: "thread-1" } });
323
+
324
+ // 线程 2: 读取(不同会话)
325
+ await agent.invoke({
326
+ messages: [{ role: "user", content: "读取我的偏好" }],
327
+ }, { configurable: { thread_id: "thread-2" } });
328
+ ```
329
+
330
+ ### 用例
331
+
332
+ - **用户偏好**: `/memories/user_preferences.txt`
333
+ - **自改进指令**: `/memories/instructions.txt`
334
+ - **知识库**: `/memories/research/notes.txt`
335
+
336
+ ## 技能系统 (Skills)
337
+
338
+ 技能是可复用的 Agent 能力,遵循 Agent Skills 标准。
339
+
340
+ ### 目录结构
341
+
342
+ ```
343
+ skills/
344
+ ├── langgraph-docs/
345
+ │ └── SKILL.md
346
+ └── arxiv_search/
347
+ ├── SKILL.md
348
+ └── arxiv_search.ts
349
+ ```
350
+
351
+ ### SKILL.md 格式
352
+
353
+ ```markdown
354
+ ---
355
+ name: skill-name
356
+ description: 技能描述
357
+ ---
358
+
359
+ # 技能标题
360
+
361
+ 详细使用说明...
362
+ ```
363
+
364
+ ### 配置技能
365
+
366
+ ```typescript
367
+ const agent = await createDeepAgent({
368
+ skills: ["/skills/"],
369
+ });
370
+ ```
371
+
372
+ ### 技能 vs 工具
373
+
374
+ | 场景 | 选择 |
375
+ |------|------|
376
+ | 大量上下文需要减少 token | 技能 |
377
+ | 多能力捆绑 | 技能 |
378
+ | 简单原子操作 | 工具 |
379
+
380
+ ## 最佳实践
381
+
382
+ ### 子代理描述
383
+
384
+ ```typescript
385
+ // ✅ 好
386
+ "分析财务数据并生成投资建议"
387
+
388
+ // ❌ 差
389
+ "处理财务"
390
+ ```
391
+
392
+ ### 最小化工具集
393
+
394
+ ```typescript
395
+ // ✅ 好: 专注
396
+ const emailAgent = {
397
+ name: "email-sender",
398
+ tools: [sendEmail, validateEmail],
399
+ };
400
+
401
+ // ❌ 差: 分散
402
+ tools: [sendEmail, webSearch, databaseQuery]
403
+ ```
404
+
405
+ ### 按任务选模型
406
+
407
+ ```typescript
408
+ const subagents = [
409
+ { name: "contract-reviewer", model: "claude-sonnet-4-20250514" },
410
+ { name: "quick-lookup", model: "gpt-4o-mini" },
411
+ ];
412
+ ```
413
+
414
+ ### 生产环境存储
415
+
416
+ ```typescript
417
+ import { PostgresStore } from "@langchain/langgraph-checkpoint-postgres";
418
+
419
+ const store = new PostgresStore({
420
+ connectionString: process.env.DATABASE_URL,
421
+ });
422
+ ```
423
+
424
+ ## 参考链接
425
+
426
+ - [DeepAgents 文档](https://docs.langchain.com/oss/javascript/deepagents)
427
+ - [LangGraph JS](https://langchain-ai.github.io/langgraphjs/)
428
+ - [Agent Skills 标准](https://agentskills.io/)
@@ -0,0 +1,13 @@
1
+ Read the backend development guidelines before starting your development task.
2
+
3
+ Execute these steps:
4
+ 1. Read `.trellis/spec/backend/index.md` to understand available guidelines
5
+ 2. Based on your task, read the relevant guideline files:
6
+ - Database work → `.trellis/spec/backend/database-guidelines.md`
7
+ - Error handling → `.trellis/spec/backend/error-handling.md`
8
+ - Logging → `.trellis/spec/backend/logging-guidelines.md`
9
+ - Type questions → `.trellis/spec/backend/type-safety.md`
10
+ 3. Understand the coding standards and patterns you need to follow
11
+ 4. Then proceed with your development plan
12
+
13
+ This step is **mandatory** before writing any backend code.
@@ -0,0 +1,13 @@
1
+ Read the frontend development guidelines before starting your development task.
2
+
3
+ Execute these steps:
4
+ 1. Read `.trellis/spec/frontend/index.md` to understand available guidelines
5
+ 2. Based on your task, read the relevant guideline files:
6
+ - Component work → `.trellis/spec/frontend/component-guidelines.md`
7
+ - Hook work → `.trellis/spec/frontend/hook-guidelines.md`
8
+ - State management → `.trellis/spec/frontend/state-management.md`
9
+ - Type questions → `.trellis/spec/frontend/type-safety.md`
10
+ 3. Understand the coding standards and patterns you need to follow
11
+ 4. Then proceed with your development plan
12
+
13
+ This step is **mandatory** before writing any frontend code.
@@ -0,0 +1,107 @@
1
+ # Break the Loop - Deep Bug Analysis
2
+
3
+ When debug is complete, use this command for deep analysis to break the "fix bug -> forget -> repeat" cycle.
4
+
5
+ ---
6
+
7
+ ## Analysis Framework
8
+
9
+ Analyze the bug you just fixed from these 5 dimensions:
10
+
11
+ ### 1. Root Cause Category
12
+
13
+ Which category does this bug belong to?
14
+
15
+ | Category | Characteristics | Example |
16
+ |----------|-----------------|---------|
17
+ | **A. Missing Spec** | No documentation on how to do it | New feature without checklist |
18
+ | **B. Cross-Layer Contract** | Interface between layers unclear | API returns different format than expected |
19
+ | **C. Change Propagation Failure** | Changed one place, missed others | Changed function signature, missed call sites |
20
+ | **D. Test Coverage Gap** | Unit test passes, integration fails | Works alone, breaks when combined |
21
+ | **E. Implicit Assumption** | Code relies on undocumented assumption | Timestamp seconds vs milliseconds |
22
+
23
+ ### 2. Why Fixes Failed (if applicable)
24
+
25
+ If you tried multiple fixes before succeeding, analyze each failure:
26
+
27
+ - **Surface Fix**: Fixed symptom, not root cause
28
+ - **Incomplete Scope**: Found root cause, didn't cover all cases
29
+ - **Tool Limitation**: grep missed it, type check wasn't strict
30
+ - **Mental Model**: Kept looking in same layer, didn't think cross-layer
31
+
32
+ ### 3. Prevention Mechanisms
33
+
34
+ What mechanisms would prevent this from happening again?
35
+
36
+ | Type | Description | Example |
37
+ |------|-------------|---------|
38
+ | **Documentation** | Write it down so people know | Update thinking guide |
39
+ | **Architecture** | Make the error impossible structurally | Type-safe wrappers |
40
+ | **Compile-time** | TypeScript strict, no any | Signature change causes compile error |
41
+ | **Runtime** | Monitoring, alerts, scans | Detect orphan entities |
42
+ | **Test Coverage** | E2E tests, integration tests | Verify full flow |
43
+ | **Code Review** | Checklist, PR template | "Did you check X?" |
44
+
45
+ ### 4. Systematic Expansion
46
+
47
+ What broader problems does this bug reveal?
48
+
49
+ - **Similar Issues**: Where else might this problem exist?
50
+ - **Design Flaw**: Is there a fundamental architecture issue?
51
+ - **Process Flaw**: Is there a development process improvement?
52
+ - **Knowledge Gap**: Is the team missing some understanding?
53
+
54
+ ### 5. Knowledge Capture
55
+
56
+ Solidify insights into the system:
57
+
58
+ - [ ] Update `.trellis/spec/guides/` thinking guides
59
+ - [ ] Update `.trellis/spec/backend/` or `frontend/` docs
60
+ - [ ] Create issue record (if applicable)
61
+ - [ ] Create feature ticket for root fix
62
+ - [ ] Update check commands if needed
63
+
64
+ ---
65
+
66
+ ## Output Format
67
+
68
+ Please output analysis in this format:
69
+
70
+ ```markdown
71
+ ## Bug Analysis: [Short Description]
72
+
73
+ ### 1. Root Cause Category
74
+ - **Category**: [A/B/C/D/E] - [Category Name]
75
+ - **Specific Cause**: [Detailed description]
76
+
77
+ ### 2. Why Fixes Failed (if applicable)
78
+ 1. [First attempt]: [Why it failed]
79
+ 2. [Second attempt]: [Why it failed]
80
+ ...
81
+
82
+ ### 3. Prevention Mechanisms
83
+ | Priority | Mechanism | Specific Action | Status |
84
+ |----------|-----------|-----------------|--------|
85
+ | P0 | ... | ... | TODO/DONE |
86
+
87
+ ### 4. Systematic Expansion
88
+ - **Similar Issues**: [List places with similar problems]
89
+ - **Design Improvement**: [Architecture-level suggestions]
90
+ - **Process Improvement**: [Development process suggestions]
91
+
92
+ ### 5. Knowledge Capture
93
+ - [ ] [Documents to update / tickets to create]
94
+ ```
95
+
96
+ ---
97
+
98
+ ## Core Philosophy
99
+
100
+ > **The value of debugging is not in fixing the bug, but in making this class of bugs never happen again.**
101
+
102
+ Three levels of insight:
103
+ 1. **Tactical**: How to fix THIS bug
104
+ 2. **Strategic**: How to prevent THIS CLASS of bugs
105
+ 3. **Philosophical**: How to expand thinking patterns
106
+
107
+ 30 minutes of analysis saves 30 hours of future debugging.
@@ -0,0 +1,13 @@
1
+ Check if the code you just wrote follows the backend development guidelines.
2
+
3
+ Execute these steps:
4
+ 1. Run `git status` to see modified files
5
+ 2. Read `.trellis/spec/backend/index.md` to understand which guidelines apply
6
+ 3. Based on what you changed, read the relevant guideline files:
7
+ - Database changes → `.trellis/spec/backend/database-guidelines.md`
8
+ - Error handling → `.trellis/spec/backend/error-handling.md`
9
+ - Logging changes → `.trellis/spec/backend/logging-guidelines.md`
10
+ - Type changes → `.trellis/spec/backend/type-safety.md`
11
+ - Any changes → `.trellis/spec/backend/quality-guidelines.md`
12
+ 4. Review your code against the guidelines
13
+ 5. Report any violations and fix them if found