@kurokeita/add-skill 2.6.1 → 3.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.
Files changed (140) hide show
  1. package/README.md +43 -64
  2. package/dist/bin/cli.js +270 -478
  3. package/dist/skills/statusline-setup/.claude-plugin/plugin.json +1 -1
  4. package/dist/skills/statusline-setup/SKILL.md +48 -448
  5. package/dist/skills/statusline-setup/mod/hooks/register.tsx +93 -103
  6. package/dist/skills/statusline-setup/mod/tests/work.test.ts +28 -10
  7. package/dist/skills/statusline-setup/mod/types/index.d.ts +2 -1
  8. package/dist/skills/universalize-agents/reference/mapping.md +3 -2
  9. package/package.json +3 -3
  10. package/dist/agents/backend-specialist.md +0 -277
  11. package/dist/agents/code-archaeologist.md +0 -114
  12. package/dist/agents/database-architect.md +0 -238
  13. package/dist/agents/debugger.md +0 -231
  14. package/dist/agents/devops-engineer.md +0 -242
  15. package/dist/agents/documentation-writer.md +0 -104
  16. package/dist/agents/explorer-agent.md +0 -79
  17. package/dist/agents/frontend-specialist.md +0 -594
  18. package/dist/agents/game-developer.md +0 -162
  19. package/dist/agents/mobile-developer.md +0 -383
  20. package/dist/agents/orchestrator.md +0 -435
  21. package/dist/agents/penetration-tester.md +0 -188
  22. package/dist/agents/performance-optimizer.md +0 -191
  23. package/dist/agents/product-manager.md +0 -122
  24. package/dist/agents/product-owner.md +0 -106
  25. package/dist/agents/project-planner.md +0 -408
  26. package/dist/agents/qa-automation-engineer.md +0 -109
  27. package/dist/agents/security-auditor.md +0 -171
  28. package/dist/agents/test-engineer.md +0 -158
  29. package/dist/skills/agent-identifier/SKILL.md +0 -431
  30. package/dist/skills/agent-identifier/examples/agent-creation-prompt.md +0 -247
  31. package/dist/skills/agent-identifier/examples/complete-agent-examples.md +0 -432
  32. package/dist/skills/agent-identifier/references/agent-creation-system-prompt.md +0 -215
  33. package/dist/skills/agent-identifier/references/system-prompt-design.md +0 -419
  34. package/dist/skills/agent-identifier/references/triggering-examples.md +0 -508
  35. package/dist/skills/agent-identifier/scripts/validate-agent.sh +0 -217
  36. package/dist/skills/code-review-excellence/SKILL.md +0 -525
  37. package/dist/skills/component-refactoring/SKILL.md +0 -492
  38. package/dist/skills/component-refactoring/references/complexity-patterns.md +0 -493
  39. package/dist/skills/component-refactoring/references/component-splitting.md +0 -477
  40. package/dist/skills/component-refactoring/references/hook-extraction.md +0 -317
  41. package/dist/skills/context7-guidelines/SKILL.md +0 -31
  42. package/dist/skills/feature-design-assistant/SKILL.md +0 -371
  43. package/dist/skills/find-bugs/SKILL.md +0 -75
  44. package/dist/skills/frontend-design/SKILL.md +0 -45
  45. package/dist/skills/go-concurrency-patterns/SKILL.md +0 -657
  46. package/dist/skills/grill-me/SKILL.md +0 -9
  47. package/dist/skills/handoff/SKILL.md +0 -16
  48. package/dist/skills/koreader-plugin-development/SKILL.md +0 -141
  49. package/dist/skills/koreader-plugin-development/examples/2-example-patch.lua +0 -17
  50. package/dist/skills/koreader-plugin-development/examples/_meta.lua +0 -6
  51. package/dist/skills/koreader-plugin-development/examples/helloworld.lua +0 -36
  52. package/dist/skills/koreader-plugin-development/references/debugging.md +0 -92
  53. package/dist/skills/koreader-plugin-development/references/events-and-widgets.md +0 -102
  54. package/dist/skills/koreader-plugin-development/references/patches.md +0 -118
  55. package/dist/skills/koreader-plugin-development/references/plugin-anatomy.md +0 -97
  56. package/dist/skills/make-instruction/SKILL.md +0 -68
  57. package/dist/skills/make-prompt/SKILL.md +0 -70
  58. package/dist/skills/make-skill/SKILL.md +0 -147
  59. package/dist/skills/prd-to-tasks/SKILL.md +0 -164
  60. package/dist/skills/react-native-async-patterns/SKILL.md +0 -256
  61. package/dist/skills/react-native-performance/SKILL.md +0 -425
  62. package/dist/skills/react-native-testing/SKILL.md +0 -458
  63. package/dist/skills/react-native-zustand-patterns/SKILL.md +0 -343
  64. package/dist/skills/skill-creator/SKILL.md +0 -385
  65. package/dist/skills/skill-creator/scripts/init_skill.cjs +0 -235
  66. package/dist/skills/skill-creator/scripts/package_skill.cjs +0 -84
  67. package/dist/skills/skill-creator/scripts/validate_skill.cjs +0 -127
  68. package/dist/skills/skill-development/SKILL.md +0 -676
  69. package/dist/skills/skill-development/references/skill-creator-original.md +0 -210
  70. package/dist/skills/sql-optimization-patterns/SKILL.md +0 -509
  71. package/dist/skills/test-driven-development/SKILL.md +0 -114
  72. package/dist/skills/test-driven-development/deep-modules.md +0 -33
  73. package/dist/skills/test-driven-development/interface-design.md +0 -35
  74. package/dist/skills/test-driven-development/mocking.md +0 -68
  75. package/dist/skills/test-driven-development/refactoring.md +0 -10
  76. package/dist/skills/test-driven-development/tests.md +0 -61
  77. package/dist/skills/vercel-react-best-practices/AGENTS.md +0 -2410
  78. package/dist/skills/vercel-react-best-practices/SKILL.md +0 -127
  79. package/dist/skills/vercel-react-best-practices/rules/advanced-event-handler-refs.md +0 -55
  80. package/dist/skills/vercel-react-best-practices/rules/advanced-use-latest.md +0 -49
  81. package/dist/skills/vercel-react-best-practices/rules/async-api-routes.md +0 -38
  82. package/dist/skills/vercel-react-best-practices/rules/async-defer-await.md +0 -80
  83. package/dist/skills/vercel-react-best-practices/rules/async-dependencies.md +0 -36
  84. package/dist/skills/vercel-react-best-practices/rules/async-parallel.md +0 -28
  85. package/dist/skills/vercel-react-best-practices/rules/async-suspense-boundaries.md +0 -99
  86. package/dist/skills/vercel-react-best-practices/rules/bundle-barrel-imports.md +0 -59
  87. package/dist/skills/vercel-react-best-practices/rules/bundle-conditional.md +0 -31
  88. package/dist/skills/vercel-react-best-practices/rules/bundle-defer-third-party.md +0 -49
  89. package/dist/skills/vercel-react-best-practices/rules/bundle-dynamic-imports.md +0 -35
  90. package/dist/skills/vercel-react-best-practices/rules/bundle-preload.md +0 -50
  91. package/dist/skills/vercel-react-best-practices/rules/client-event-listeners.md +0 -74
  92. package/dist/skills/vercel-react-best-practices/rules/client-localstorage-schema.md +0 -71
  93. package/dist/skills/vercel-react-best-practices/rules/client-passive-event-listeners.md +0 -48
  94. package/dist/skills/vercel-react-best-practices/rules/client-swr-dedup.md +0 -56
  95. package/dist/skills/vercel-react-best-practices/rules/js-batch-dom-css.md +0 -82
  96. package/dist/skills/vercel-react-best-practices/rules/js-cache-function-results.md +0 -80
  97. package/dist/skills/vercel-react-best-practices/rules/js-cache-property-access.md +0 -28
  98. package/dist/skills/vercel-react-best-practices/rules/js-cache-storage.md +0 -70
  99. package/dist/skills/vercel-react-best-practices/rules/js-combine-iterations.md +0 -32
  100. package/dist/skills/vercel-react-best-practices/rules/js-early-exit.md +0 -50
  101. package/dist/skills/vercel-react-best-practices/rules/js-hoist-regexp.md +0 -45
  102. package/dist/skills/vercel-react-best-practices/rules/js-index-maps.md +0 -37
  103. package/dist/skills/vercel-react-best-practices/rules/js-length-check-first.md +0 -50
  104. package/dist/skills/vercel-react-best-practices/rules/js-min-max-loop.md +0 -82
  105. package/dist/skills/vercel-react-best-practices/rules/js-set-map-lookups.md +0 -24
  106. package/dist/skills/vercel-react-best-practices/rules/js-tosorted-immutable.md +0 -57
  107. package/dist/skills/vercel-react-best-practices/rules/rendering-activity.md +0 -26
  108. package/dist/skills/vercel-react-best-practices/rules/rendering-animate-svg-wrapper.md +0 -47
  109. package/dist/skills/vercel-react-best-practices/rules/rendering-conditional-render.md +0 -40
  110. package/dist/skills/vercel-react-best-practices/rules/rendering-content-visibility.md +0 -38
  111. package/dist/skills/vercel-react-best-practices/rules/rendering-hoist-jsx.md +0 -46
  112. package/dist/skills/vercel-react-best-practices/rules/rendering-hydration-no-flicker.md +0 -82
  113. package/dist/skills/vercel-react-best-practices/rules/rendering-svg-precision.md +0 -28
  114. package/dist/skills/vercel-react-best-practices/rules/rerender-defer-reads.md +0 -39
  115. package/dist/skills/vercel-react-best-practices/rules/rerender-dependencies.md +0 -45
  116. package/dist/skills/vercel-react-best-practices/rules/rerender-derived-state.md +0 -29
  117. package/dist/skills/vercel-react-best-practices/rules/rerender-functional-setstate.md +0 -74
  118. package/dist/skills/vercel-react-best-practices/rules/rerender-lazy-state-init.md +0 -58
  119. package/dist/skills/vercel-react-best-practices/rules/rerender-memo.md +0 -44
  120. package/dist/skills/vercel-react-best-practices/rules/rerender-transitions.md +0 -40
  121. package/dist/skills/vercel-react-best-practices/rules/server-after-nonblocking.md +0 -73
  122. package/dist/skills/vercel-react-best-practices/rules/server-cache-lru.md +0 -41
  123. package/dist/skills/vercel-react-best-practices/rules/server-cache-react.md +0 -76
  124. package/dist/skills/vercel-react-best-practices/rules/server-parallel-fetching.md +0 -83
  125. package/dist/skills/vercel-react-best-practices/rules/server-serialization.md +0 -38
  126. package/dist/skills/web-design-guidelines/SKILL.md +0 -40
  127. package/dist/skills/workflow-patterns/SKILL.md +0 -623
  128. package/dist/skills/write-prd/SKILL.md +0 -162
  129. package/dist/workflows/brainstorm.md +0 -113
  130. package/dist/workflows/create.md +0 -60
  131. package/dist/workflows/debug.md +0 -107
  132. package/dist/workflows/deploy.md +0 -178
  133. package/dist/workflows/enhance.md +0 -64
  134. package/dist/workflows/github-pull-request-create.md +0 -134
  135. package/dist/workflows/orchestrate.md +0 -246
  136. package/dist/workflows/plan.md +0 -90
  137. package/dist/workflows/preview.md +0 -83
  138. package/dist/workflows/status.md +0 -87
  139. package/dist/workflows/test.md +0 -144
  140. package/dist/workflows/ui-ux-pro-max.md +0 -315
@@ -1,493 +0,0 @@
1
- # Complexity Reduction Patterns
2
-
3
- This document provides patterns for reducing cognitive complexity in Dify React components.
4
-
5
- ## Understanding Complexity
6
-
7
- ### SonarJS Cognitive Complexity
8
-
9
- The `pnpm analyze-component` tool uses SonarJS cognitive complexity metrics:
10
-
11
- - **Total Complexity**: Sum of all functions' complexity in the file
12
- - **Max Complexity**: Highest single function complexity
13
-
14
- ### What Increases Complexity
15
-
16
- | Pattern | Complexity Impact |
17
- |---------|-------------------|
18
- | `if/else` | +1 per branch |
19
- | Nested conditions | +1 per nesting level |
20
- | `switch/case` | +1 per case |
21
- | `for/while/do` | +1 per loop |
22
- | `&&`/`||` chains | +1 per operator |
23
- | Nested callbacks | +1 per nesting level |
24
- | `try/catch` | +1 per catch |
25
- | Ternary expressions | +1 per nesting |
26
-
27
- ## Pattern 1: Replace Conditionals with Lookup Tables
28
-
29
- **Before** (complexity: ~15):
30
-
31
- ```typescript
32
- const Template = useMemo(() => {
33
- if (appDetail?.mode === AppModeEnum.CHAT) {
34
- switch (locale) {
35
- case LanguagesSupported[1]:
36
- return <TemplateChatZh appDetail={appDetail} />
37
- case LanguagesSupported[7]:
38
- return <TemplateChatJa appDetail={appDetail} />
39
- default:
40
- return <TemplateChatEn appDetail={appDetail} />
41
- }
42
- }
43
- if (appDetail?.mode === AppModeEnum.ADVANCED_CHAT) {
44
- switch (locale) {
45
- case LanguagesSupported[1]:
46
- return <TemplateAdvancedChatZh appDetail={appDetail} />
47
- case LanguagesSupported[7]:
48
- return <TemplateAdvancedChatJa appDetail={appDetail} />
49
- default:
50
- return <TemplateAdvancedChatEn appDetail={appDetail} />
51
- }
52
- }
53
- if (appDetail?.mode === AppModeEnum.WORKFLOW) {
54
- // Similar pattern...
55
- }
56
- return null
57
- }, [appDetail, locale])
58
- ```
59
-
60
- **After** (complexity: ~3):
61
-
62
- ```typescript
63
- // Define lookup table outside component
64
- const TEMPLATE_MAP: Record<AppModeEnum, Record<string, FC<TemplateProps>>> = {
65
- [AppModeEnum.CHAT]: {
66
- [LanguagesSupported[1]]: TemplateChatZh,
67
- [LanguagesSupported[7]]: TemplateChatJa,
68
- default: TemplateChatEn,
69
- },
70
- [AppModeEnum.ADVANCED_CHAT]: {
71
- [LanguagesSupported[1]]: TemplateAdvancedChatZh,
72
- [LanguagesSupported[7]]: TemplateAdvancedChatJa,
73
- default: TemplateAdvancedChatEn,
74
- },
75
- [AppModeEnum.WORKFLOW]: {
76
- [LanguagesSupported[1]]: TemplateWorkflowZh,
77
- [LanguagesSupported[7]]: TemplateWorkflowJa,
78
- default: TemplateWorkflowEn,
79
- },
80
- // ...
81
- }
82
-
83
- // Clean component logic
84
- const Template = useMemo(() => {
85
- if (!appDetail?.mode) return null
86
-
87
- const templates = TEMPLATE_MAP[appDetail.mode]
88
- if (!templates) return null
89
-
90
- const TemplateComponent = templates[locale] ?? templates.default
91
- return <TemplateComponent appDetail={appDetail} />
92
- }, [appDetail, locale])
93
- ```
94
-
95
- ## Pattern 2: Use Early Returns
96
-
97
- **Before** (complexity: ~10):
98
-
99
- ```typescript
100
- const handleSubmit = () => {
101
- if (isValid) {
102
- if (hasChanges) {
103
- if (isConnected) {
104
- submitData()
105
- } else {
106
- showConnectionError()
107
- }
108
- } else {
109
- showNoChangesMessage()
110
- }
111
- } else {
112
- showValidationError()
113
- }
114
- }
115
- ```
116
-
117
- **After** (complexity: ~4):
118
-
119
- ```typescript
120
- const handleSubmit = () => {
121
- if (!isValid) {
122
- showValidationError()
123
- return
124
- }
125
-
126
- if (!hasChanges) {
127
- showNoChangesMessage()
128
- return
129
- }
130
-
131
- if (!isConnected) {
132
- showConnectionError()
133
- return
134
- }
135
-
136
- submitData()
137
- }
138
- ```
139
-
140
- ## Pattern 3: Extract Complex Conditions
141
-
142
- **Before** (complexity: high):
143
-
144
- ```typescript
145
- const canPublish = (() => {
146
- if (mode !== AppModeEnum.COMPLETION) {
147
- if (!isAdvancedMode)
148
- return true
149
-
150
- if (modelModeType === ModelModeType.completion) {
151
- if (!hasSetBlockStatus.history || !hasSetBlockStatus.query)
152
- return false
153
- return true
154
- }
155
- return true
156
- }
157
- return !promptEmpty
158
- })()
159
- ```
160
-
161
- **After** (complexity: lower):
162
-
163
- ```typescript
164
- // Extract to named functions
165
- const canPublishInCompletionMode = () => !promptEmpty
166
-
167
- const canPublishInChatMode = () => {
168
- if (!isAdvancedMode) return true
169
- if (modelModeType !== ModelModeType.completion) return true
170
- return hasSetBlockStatus.history && hasSetBlockStatus.query
171
- }
172
-
173
- // Clean main logic
174
- const canPublish = mode === AppModeEnum.COMPLETION
175
- ? canPublishInCompletionMode()
176
- : canPublishInChatMode()
177
- ```
178
-
179
- ## Pattern 4: Replace Chained Ternaries
180
-
181
- **Before** (complexity: ~5):
182
-
183
- ```typescript
184
- const statusText = serverActivated
185
- ? t('status.running')
186
- : serverPublished
187
- ? t('status.inactive')
188
- : appUnpublished
189
- ? t('status.unpublished')
190
- : t('status.notConfigured')
191
- ```
192
-
193
- **After** (complexity: ~2):
194
-
195
- ```typescript
196
- const getStatusText = () => {
197
- if (serverActivated) return t('status.running')
198
- if (serverPublished) return t('status.inactive')
199
- if (appUnpublished) return t('status.unpublished')
200
- return t('status.notConfigured')
201
- }
202
-
203
- const statusText = getStatusText()
204
- ```
205
-
206
- Or use lookup:
207
-
208
- ```typescript
209
- const STATUS_TEXT_MAP = {
210
- running: 'status.running',
211
- inactive: 'status.inactive',
212
- unpublished: 'status.unpublished',
213
- notConfigured: 'status.notConfigured',
214
- } as const
215
-
216
- const getStatusKey = (): keyof typeof STATUS_TEXT_MAP => {
217
- if (serverActivated) return 'running'
218
- if (serverPublished) return 'inactive'
219
- if (appUnpublished) return 'unpublished'
220
- return 'notConfigured'
221
- }
222
-
223
- const statusText = t(STATUS_TEXT_MAP[getStatusKey()])
224
- ```
225
-
226
- ## Pattern 5: Flatten Nested Loops
227
-
228
- **Before** (complexity: high):
229
-
230
- ```typescript
231
- const processData = (items: Item[]) => {
232
- const results: ProcessedItem[] = []
233
-
234
- for (const item of items) {
235
- if (item.isValid) {
236
- for (const child of item.children) {
237
- if (child.isActive) {
238
- for (const prop of child.properties) {
239
- if (prop.value !== null) {
240
- results.push({
241
- itemId: item.id,
242
- childId: child.id,
243
- propValue: prop.value,
244
- })
245
- }
246
- }
247
- }
248
- }
249
- }
250
- }
251
-
252
- return results
253
- }
254
- ```
255
-
256
- **After** (complexity: lower):
257
-
258
- ```typescript
259
- // Use functional approach
260
- const processData = (items: Item[]) => {
261
- return items
262
- .filter(item => item.isValid)
263
- .flatMap(item =>
264
- item.children
265
- .filter(child => child.isActive)
266
- .flatMap(child =>
267
- child.properties
268
- .filter(prop => prop.value !== null)
269
- .map(prop => ({
270
- itemId: item.id,
271
- childId: child.id,
272
- propValue: prop.value,
273
- }))
274
- )
275
- )
276
- }
277
- ```
278
-
279
- ## Pattern 6: Extract Event Handler Logic
280
-
281
- **Before** (complexity: high in component):
282
-
283
- ```typescript
284
- const Component = () => {
285
- const handleSelect = (data: DataSet[]) => {
286
- if (isEqual(data.map(item => item.id), dataSets.map(item => item.id))) {
287
- hideSelectDataSet()
288
- return
289
- }
290
-
291
- formattingChangedDispatcher()
292
- let newDatasets = data
293
- if (data.find(item => !item.name)) {
294
- const newSelected = produce(data, (draft) => {
295
- data.forEach((item, index) => {
296
- if (!item.name) {
297
- const newItem = dataSets.find(i => i.id === item.id)
298
- if (newItem)
299
- draft[index] = newItem
300
- }
301
- })
302
- })
303
- setDataSets(newSelected)
304
- newDatasets = newSelected
305
- }
306
- else {
307
- setDataSets(data)
308
- }
309
- hideSelectDataSet()
310
-
311
- // 40 more lines of logic...
312
- }
313
-
314
- return <div>...</div>
315
- }
316
- ```
317
-
318
- **After** (complexity: lower):
319
-
320
- ```typescript
321
- // Extract to hook or utility
322
- const useDatasetSelection = (dataSets: DataSet[], setDataSets: SetState<DataSet[]>) => {
323
- const normalizeSelection = (data: DataSet[]) => {
324
- const hasUnloadedItem = data.some(item => !item.name)
325
- if (!hasUnloadedItem) return data
326
-
327
- return produce(data, (draft) => {
328
- data.forEach((item, index) => {
329
- if (!item.name) {
330
- const existing = dataSets.find(i => i.id === item.id)
331
- if (existing) draft[index] = existing
332
- }
333
- })
334
- })
335
- }
336
-
337
- const hasSelectionChanged = (newData: DataSet[]) => {
338
- return !isEqual(
339
- newData.map(item => item.id),
340
- dataSets.map(item => item.id)
341
- )
342
- }
343
-
344
- return { normalizeSelection, hasSelectionChanged }
345
- }
346
-
347
- // Component becomes cleaner
348
- const Component = () => {
349
- const { normalizeSelection, hasSelectionChanged } = useDatasetSelection(dataSets, setDataSets)
350
-
351
- const handleSelect = (data: DataSet[]) => {
352
- if (!hasSelectionChanged(data)) {
353
- hideSelectDataSet()
354
- return
355
- }
356
-
357
- formattingChangedDispatcher()
358
- const normalized = normalizeSelection(data)
359
- setDataSets(normalized)
360
- hideSelectDataSet()
361
- }
362
-
363
- return <div>...</div>
364
- }
365
- ```
366
-
367
- ## Pattern 7: Reduce Boolean Logic Complexity
368
-
369
- **Before** (complexity: ~8):
370
-
371
- ```typescript
372
- const toggleDisabled = hasInsufficientPermissions
373
- || appUnpublished
374
- || missingStartNode
375
- || triggerModeDisabled
376
- || (isAdvancedApp && !currentWorkflow?.graph)
377
- || (isBasicApp && !basicAppConfig.updated_at)
378
- ```
379
-
380
- **After** (complexity: ~3):
381
-
382
- ```typescript
383
- // Extract meaningful boolean functions
384
- const isAppReady = () => {
385
- if (isAdvancedApp) return !!currentWorkflow?.graph
386
- return !!basicAppConfig.updated_at
387
- }
388
-
389
- const hasRequiredPermissions = () => {
390
- return isCurrentWorkspaceEditor && !hasInsufficientPermissions
391
- }
392
-
393
- const canToggle = () => {
394
- if (!hasRequiredPermissions()) return false
395
- if (!isAppReady()) return false
396
- if (missingStartNode) return false
397
- if (triggerModeDisabled) return false
398
- return true
399
- }
400
-
401
- const toggleDisabled = !canToggle()
402
- ```
403
-
404
- ## Pattern 8: Simplify useMemo/useCallback Dependencies
405
-
406
- **Before** (complexity: multiple recalculations):
407
-
408
- ```typescript
409
- const payload = useMemo(() => {
410
- let parameters: Parameter[] = []
411
- let outputParameters: OutputParameter[] = []
412
-
413
- if (!published) {
414
- parameters = (inputs || []).map((item) => ({
415
- name: item.variable,
416
- description: '',
417
- form: 'llm',
418
- required: item.required,
419
- type: item.type,
420
- }))
421
- outputParameters = (outputs || []).map((item) => ({
422
- name: item.variable,
423
- description: '',
424
- type: item.value_type,
425
- }))
426
- }
427
- else if (detail && detail.tool) {
428
- parameters = (inputs || []).map((item) => ({
429
- // Complex transformation...
430
- }))
431
- outputParameters = (outputs || []).map((item) => ({
432
- // Complex transformation...
433
- }))
434
- }
435
-
436
- return {
437
- icon: detail?.icon || icon,
438
- label: detail?.label || name,
439
- // ...more fields
440
- }
441
- }, [detail, published, workflowAppId, icon, name, description, inputs, outputs])
442
- ```
443
-
444
- **After** (complexity: separated concerns):
445
-
446
- ```typescript
447
- // Separate transformations
448
- const useParameterTransform = (inputs: InputVar[], detail?: ToolDetail, published?: boolean) => {
449
- return useMemo(() => {
450
- if (!published) {
451
- return inputs.map(item => ({
452
- name: item.variable,
453
- description: '',
454
- form: 'llm',
455
- required: item.required,
456
- type: item.type,
457
- }))
458
- }
459
-
460
- if (!detail?.tool) return []
461
-
462
- return inputs.map(item => ({
463
- name: item.variable,
464
- required: item.required,
465
- type: item.type === 'paragraph' ? 'string' : item.type,
466
- description: detail.tool.parameters.find(p => p.name === item.variable)?.llm_description || '',
467
- form: detail.tool.parameters.find(p => p.name === item.variable)?.form || 'llm',
468
- }))
469
- }, [inputs, detail, published])
470
- }
471
-
472
- // Component uses hook
473
- const parameters = useParameterTransform(inputs, detail, published)
474
- const outputParameters = useOutputTransform(outputs, detail, published)
475
-
476
- const payload = useMemo(() => ({
477
- icon: detail?.icon || icon,
478
- label: detail?.label || name,
479
- parameters,
480
- outputParameters,
481
- // ...
482
- }), [detail, icon, name, parameters, outputParameters])
483
- ```
484
-
485
- ## Target Metrics After Refactoring
486
-
487
- | Metric | Target |
488
- |--------|--------|
489
- | Total Complexity | < 50 |
490
- | Max Function Complexity | < 30 |
491
- | Function Length | < 30 lines |
492
- | Nesting Depth | ≤ 3 levels |
493
- | Conditional Chains | ≤ 3 conditions |