agentsys 5.0.3 → 5.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 (264) hide show
  1. package/.claude-plugin/marketplace.json +21 -14
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/AGENTS.md +2 -1
  4. package/CHANGELOG.md +18 -0
  5. package/README.md +7 -6
  6. package/adapters/codex/skills/agnix/SKILL.md +0 -1
  7. package/adapters/codex/skills/audit-project/SKILL.md +0 -1
  8. package/adapters/codex/skills/audit-project-agents/SKILL.md +0 -1
  9. package/adapters/codex/skills/audit-project-github/SKILL.md +0 -1
  10. package/adapters/codex/skills/consult/SKILL.md +132 -57
  11. package/adapters/codex/skills/debate/SKILL.md +214 -0
  12. package/adapters/codex/skills/delivery-approval/SKILL.md +0 -1
  13. package/adapters/codex/skills/deslop/SKILL.md +0 -1
  14. package/adapters/codex/skills/drift-detect/SKILL.md +0 -1
  15. package/adapters/codex/skills/enhance/SKILL.md +0 -1
  16. package/adapters/codex/skills/learn/SKILL.md +0 -1
  17. package/adapters/codex/skills/next-task/SKILL.md +0 -1
  18. package/adapters/codex/skills/perf/SKILL.md +0 -1
  19. package/adapters/codex/skills/repo-map/SKILL.md +0 -1
  20. package/adapters/codex/skills/ship/SKILL.md +0 -1
  21. package/adapters/codex/skills/ship-ci-review-loop/SKILL.md +0 -1
  22. package/adapters/codex/skills/ship-deployment/SKILL.md +0 -1
  23. package/adapters/codex/skills/ship-error-handling/SKILL.md +0 -1
  24. package/adapters/codex/skills/sync-docs/SKILL.md +0 -1
  25. package/adapters/opencode/agents/agent-enhancer.md +0 -1
  26. package/adapters/opencode/agents/agnix-agent.md +0 -1
  27. package/adapters/opencode/agents/ci-fixer.md +0 -1
  28. package/adapters/opencode/agents/ci-monitor.md +0 -1
  29. package/adapters/opencode/agents/claudemd-enhancer.md +0 -1
  30. package/adapters/opencode/agents/consult-agent.md +122 -30
  31. package/adapters/opencode/agents/cross-file-enhancer.md +0 -1
  32. package/adapters/opencode/agents/debate-orchestrator.md +169 -0
  33. package/adapters/opencode/agents/delivery-validator.md +0 -1
  34. package/adapters/opencode/agents/deslop-agent.md +0 -1
  35. package/adapters/opencode/agents/docs-enhancer.md +0 -1
  36. package/adapters/opencode/agents/exploration-agent.md +0 -1
  37. package/adapters/opencode/agents/hooks-enhancer.md +0 -1
  38. package/adapters/opencode/agents/implementation-agent.md +0 -1
  39. package/adapters/opencode/agents/learn-agent.md +0 -1
  40. package/adapters/opencode/agents/map-validator.md +0 -1
  41. package/adapters/opencode/agents/perf-analyzer.md +0 -1
  42. package/adapters/opencode/agents/perf-code-paths.md +0 -1
  43. package/adapters/opencode/agents/perf-investigation-logger.md +0 -1
  44. package/adapters/opencode/agents/perf-orchestrator.md +0 -1
  45. package/adapters/opencode/agents/perf-theory-gatherer.md +0 -1
  46. package/adapters/opencode/agents/perf-theory-tester.md +0 -1
  47. package/adapters/opencode/agents/plan-synthesizer.md +0 -1
  48. package/adapters/opencode/agents/planning-agent.md +0 -1
  49. package/adapters/opencode/agents/plugin-enhancer.md +0 -1
  50. package/adapters/opencode/agents/prompt-enhancer.md +0 -1
  51. package/adapters/opencode/agents/simple-fixer.md +0 -1
  52. package/adapters/opencode/agents/skills-enhancer.md +0 -1
  53. package/adapters/opencode/agents/sync-docs-agent.md +0 -1
  54. package/adapters/opencode/agents/task-discoverer.md +0 -1
  55. package/adapters/opencode/agents/test-coverage-checker.md +0 -1
  56. package/adapters/opencode/agents/worktree-manager.md +0 -1
  57. package/adapters/opencode/commands/agnix.md +0 -1
  58. package/adapters/opencode/commands/audit-project-agents.md +0 -1
  59. package/adapters/opencode/commands/audit-project-github.md +0 -1
  60. package/adapters/opencode/commands/audit-project.md +0 -1
  61. package/adapters/opencode/commands/consult.md +133 -57
  62. package/adapters/opencode/commands/debate.md +224 -0
  63. package/adapters/opencode/commands/delivery-approval.md +0 -1
  64. package/adapters/opencode/commands/deslop.md +0 -1
  65. package/adapters/opencode/commands/drift-detect.md +0 -1
  66. package/adapters/opencode/commands/enhance.md +0 -1
  67. package/adapters/opencode/commands/learn.md +0 -1
  68. package/adapters/opencode/commands/next-task.md +0 -1
  69. package/adapters/opencode/commands/perf.md +0 -1
  70. package/adapters/opencode/commands/repo-map.md +0 -1
  71. package/adapters/opencode/commands/ship-ci-review-loop.md +0 -1
  72. package/adapters/opencode/commands/ship-deployment.md +0 -1
  73. package/adapters/opencode/commands/ship-error-handling.md +0 -1
  74. package/adapters/opencode/commands/ship.md +0 -1
  75. package/adapters/opencode/commands/sync-docs.md +0 -1
  76. package/adapters/opencode/skills/agnix/SKILL.md +1 -2
  77. package/adapters/opencode/skills/consult/SKILL.md +33 -23
  78. package/adapters/opencode/skills/debate/SKILL.md +245 -0
  79. package/adapters/opencode/skills/deslop/SKILL.md +1 -2
  80. package/adapters/opencode/skills/discover-tasks/SKILL.md +1 -2
  81. package/adapters/opencode/skills/drift-analysis/SKILL.md +1 -2
  82. package/adapters/opencode/skills/enhance-agent-prompts/SKILL.md +1 -2
  83. package/adapters/opencode/skills/enhance-claude-memory/SKILL.md +1 -2
  84. package/adapters/opencode/skills/enhance-cross-file/SKILL.md +1 -2
  85. package/adapters/opencode/skills/enhance-docs/SKILL.md +1 -2
  86. package/adapters/opencode/skills/enhance-hooks/SKILL.md +1 -2
  87. package/adapters/opencode/skills/enhance-orchestrator/SKILL.md +1 -2
  88. package/adapters/opencode/skills/enhance-plugins/SKILL.md +1 -2
  89. package/adapters/opencode/skills/enhance-prompts/SKILL.md +1 -2
  90. package/adapters/opencode/skills/enhance-skills/SKILL.md +1 -2
  91. package/adapters/opencode/skills/learn/SKILL.md +1 -2
  92. package/adapters/opencode/skills/orchestrate-review/SKILL.md +0 -1
  93. package/adapters/opencode/skills/perf-analyzer/SKILL.md +1 -2
  94. package/adapters/opencode/skills/perf-baseline-manager/SKILL.md +1 -2
  95. package/adapters/opencode/skills/perf-benchmarker/SKILL.md +1 -2
  96. package/adapters/opencode/skills/perf-code-paths/SKILL.md +1 -2
  97. package/adapters/opencode/skills/perf-investigation-logger/SKILL.md +1 -2
  98. package/adapters/opencode/skills/perf-profiler/SKILL.md +1 -2
  99. package/adapters/opencode/skills/perf-theory-gatherer/SKILL.md +1 -2
  100. package/adapters/opencode/skills/perf-theory-tester/SKILL.md +1 -2
  101. package/adapters/opencode/skills/repo-mapping/SKILL.md +1 -2
  102. package/adapters/opencode/skills/sync-docs/SKILL.md +1 -2
  103. package/adapters/opencode/skills/validate-delivery/SKILL.md +1 -2
  104. package/lib/adapter-transforms.js +24 -4
  105. package/package.json +1 -1
  106. package/plugins/agnix/.claude-plugin/plugin.json +1 -1
  107. package/plugins/agnix/skills/agnix/SKILL.md +1 -1
  108. package/plugins/audit-project/.claude-plugin/plugin.json +1 -1
  109. package/plugins/audit-project/lib/adapter-transforms.js +24 -4
  110. package/plugins/consult/.claude-plugin/plugin.json +1 -1
  111. package/plugins/consult/agents/consult-agent.md +122 -29
  112. package/plugins/consult/commands/consult.md +135 -58
  113. package/plugins/consult/skills/consult/SKILL.md +31 -20
  114. package/plugins/debate/.claude-plugin/plugin.json +21 -0
  115. package/plugins/debate/agents/debate-orchestrator.md +175 -0
  116. package/plugins/debate/commands/debate.md +221 -0
  117. package/plugins/debate/lib/adapter-transforms.js +298 -0
  118. package/plugins/debate/lib/collectors/codebase.js +392 -0
  119. package/plugins/debate/lib/collectors/docs-patterns.js +713 -0
  120. package/plugins/debate/lib/collectors/documentation.js +219 -0
  121. package/plugins/debate/lib/collectors/github.js +330 -0
  122. package/plugins/debate/lib/collectors/index.js +126 -0
  123. package/plugins/debate/lib/config/index.js +14 -0
  124. package/plugins/debate/lib/cross-platform/index.js +539 -0
  125. package/plugins/debate/lib/discovery/index.js +352 -0
  126. package/plugins/debate/lib/drift-detect/collectors.js +37 -0
  127. package/plugins/debate/lib/enhance/agent-analyzer.js +421 -0
  128. package/plugins/debate/lib/enhance/agent-patterns.js +571 -0
  129. package/plugins/debate/lib/enhance/auto-suppression.js +622 -0
  130. package/plugins/debate/lib/enhance/benchmark.js +417 -0
  131. package/plugins/debate/lib/enhance/cross-file-analyzer.js +930 -0
  132. package/plugins/debate/lib/enhance/cross-file-patterns.js +370 -0
  133. package/plugins/debate/lib/enhance/docs-analyzer.js +325 -0
  134. package/plugins/debate/lib/enhance/docs-patterns.js +671 -0
  135. package/plugins/debate/lib/enhance/fixer.js +721 -0
  136. package/plugins/debate/lib/enhance/hook-analyzer.js +135 -0
  137. package/plugins/debate/lib/enhance/hook-patterns.js +40 -0
  138. package/plugins/debate/lib/enhance/index.js +127 -0
  139. package/plugins/debate/lib/enhance/plugin-analyzer.js +402 -0
  140. package/plugins/debate/lib/enhance/plugin-patterns.js +326 -0
  141. package/plugins/debate/lib/enhance/projectmemory-analyzer.js +551 -0
  142. package/plugins/debate/lib/enhance/projectmemory-patterns.js +617 -0
  143. package/plugins/debate/lib/enhance/prompt-analyzer.js +457 -0
  144. package/plugins/debate/lib/enhance/prompt-patterns.js +1484 -0
  145. package/plugins/debate/lib/enhance/reporter.js +1348 -0
  146. package/plugins/debate/lib/enhance/security-patterns.js +284 -0
  147. package/plugins/debate/lib/enhance/skill-analyzer.js +182 -0
  148. package/plugins/debate/lib/enhance/skill-patterns.js +147 -0
  149. package/plugins/debate/lib/enhance/suppression.js +352 -0
  150. package/plugins/debate/lib/enhance/tool-patterns.js +373 -0
  151. package/plugins/debate/lib/index.js +270 -0
  152. package/plugins/debate/lib/patterns/cli-enhancers.js +611 -0
  153. package/plugins/debate/lib/patterns/pipeline.js +948 -0
  154. package/plugins/debate/lib/patterns/review-patterns.js +558 -0
  155. package/plugins/debate/lib/patterns/slop-analyzers.js +2305 -0
  156. package/plugins/debate/lib/patterns/slop-patterns.js +1187 -0
  157. package/plugins/debate/lib/perf/analyzer/index.js +22 -0
  158. package/plugins/debate/lib/perf/argument-parser.js +105 -0
  159. package/plugins/debate/lib/perf/baseline-comparator.js +50 -0
  160. package/plugins/debate/lib/perf/baseline-store.js +127 -0
  161. package/plugins/debate/lib/perf/benchmark-runner.js +404 -0
  162. package/plugins/debate/lib/perf/breaking-point-finder.js +52 -0
  163. package/plugins/debate/lib/perf/breaking-point-runner.js +60 -0
  164. package/plugins/debate/lib/perf/checkpoint.js +123 -0
  165. package/plugins/debate/lib/perf/code-paths.js +86 -0
  166. package/plugins/debate/lib/perf/consolidation.js +37 -0
  167. package/plugins/debate/lib/perf/constraint-runner.js +71 -0
  168. package/plugins/debate/lib/perf/experiment-runner.js +32 -0
  169. package/plugins/debate/lib/perf/index.js +41 -0
  170. package/plugins/debate/lib/perf/investigation-state.js +874 -0
  171. package/plugins/debate/lib/perf/optimization-runner.js +79 -0
  172. package/plugins/debate/lib/perf/profilers/go.js +22 -0
  173. package/plugins/debate/lib/perf/profilers/index.js +46 -0
  174. package/plugins/debate/lib/perf/profilers/java.js +23 -0
  175. package/plugins/debate/lib/perf/profilers/node.js +27 -0
  176. package/plugins/debate/lib/perf/profilers/python.js +23 -0
  177. package/plugins/debate/lib/perf/profilers/rust.js +23 -0
  178. package/plugins/debate/lib/perf/profiling-runner.js +75 -0
  179. package/plugins/debate/lib/perf/schemas.js +140 -0
  180. package/plugins/debate/lib/platform/detect-platform.js +413 -0
  181. package/plugins/debate/lib/platform/detection-configs.js +93 -0
  182. package/plugins/debate/lib/platform/state-dir.js +132 -0
  183. package/plugins/debate/lib/platform/verify-tools.js +182 -0
  184. package/plugins/debate/lib/repo-map/cache.js +152 -0
  185. package/plugins/debate/lib/repo-map/concurrency.js +29 -0
  186. package/plugins/debate/lib/repo-map/index.js +222 -0
  187. package/plugins/debate/lib/repo-map/installer.js +212 -0
  188. package/plugins/debate/lib/repo-map/queries/go.js +27 -0
  189. package/plugins/debate/lib/repo-map/queries/index.js +100 -0
  190. package/plugins/debate/lib/repo-map/queries/java.js +38 -0
  191. package/plugins/debate/lib/repo-map/queries/javascript.js +55 -0
  192. package/plugins/debate/lib/repo-map/queries/python.js +24 -0
  193. package/plugins/debate/lib/repo-map/queries/rust.js +73 -0
  194. package/plugins/debate/lib/repo-map/queries/typescript.js +38 -0
  195. package/plugins/debate/lib/repo-map/runner.js +1364 -0
  196. package/plugins/debate/lib/repo-map/updater.js +562 -0
  197. package/plugins/debate/lib/repo-map/usage-analyzer.js +407 -0
  198. package/plugins/debate/lib/schemas/plugin-manifest.schema.json +57 -0
  199. package/plugins/debate/lib/schemas/validator.js +247 -0
  200. package/plugins/debate/lib/sources/custom-handler.js +199 -0
  201. package/plugins/debate/lib/sources/policy-questions.js +246 -0
  202. package/plugins/debate/lib/sources/source-cache.js +165 -0
  203. package/plugins/debate/lib/state/workflow-state.js +576 -0
  204. package/plugins/debate/lib/types/agent-frontmatter.d.ts +134 -0
  205. package/plugins/debate/lib/types/command-frontmatter.d.ts +107 -0
  206. package/plugins/debate/lib/types/hook-frontmatter.d.ts +115 -0
  207. package/plugins/debate/lib/types/index.d.ts +84 -0
  208. package/plugins/debate/lib/types/plugin-manifest.d.ts +102 -0
  209. package/plugins/debate/lib/types/skill-frontmatter.d.ts +89 -0
  210. package/plugins/debate/lib/utils/atomic-write.js +94 -0
  211. package/plugins/debate/lib/utils/cache-manager.js +159 -0
  212. package/plugins/debate/lib/utils/command-parser.js +0 -0
  213. package/plugins/debate/lib/utils/context-optimizer.js +300 -0
  214. package/plugins/debate/lib/utils/deprecation.js +37 -0
  215. package/plugins/debate/lib/utils/shell-escape.js +88 -0
  216. package/plugins/debate/lib/utils/state-helpers.js +61 -0
  217. package/plugins/debate/skills/debate/SKILL.md +264 -0
  218. package/plugins/deslop/.claude-plugin/plugin.json +1 -1
  219. package/plugins/deslop/lib/adapter-transforms.js +24 -4
  220. package/plugins/deslop/skills/deslop/SKILL.md +1 -1
  221. package/plugins/drift-detect/.claude-plugin/plugin.json +1 -1
  222. package/plugins/drift-detect/lib/adapter-transforms.js +24 -4
  223. package/plugins/drift-detect/skills/drift-analysis/SKILL.md +1 -1
  224. package/plugins/enhance/.claude-plugin/plugin.json +1 -1
  225. package/plugins/enhance/lib/adapter-transforms.js +24 -4
  226. package/plugins/enhance/skills/enhance-agent-prompts/SKILL.md +1 -1
  227. package/plugins/enhance/skills/enhance-claude-memory/SKILL.md +1 -1
  228. package/plugins/enhance/skills/enhance-cross-file/SKILL.md +1 -1
  229. package/plugins/enhance/skills/enhance-docs/SKILL.md +1 -1
  230. package/plugins/enhance/skills/enhance-hooks/SKILL.md +1 -1
  231. package/plugins/enhance/skills/enhance-orchestrator/SKILL.md +1 -1
  232. package/plugins/enhance/skills/enhance-plugins/SKILL.md +1 -1
  233. package/plugins/enhance/skills/enhance-prompts/SKILL.md +1 -1
  234. package/plugins/enhance/skills/enhance-skills/SKILL.md +1 -1
  235. package/plugins/learn/.claude-plugin/plugin.json +1 -1
  236. package/plugins/learn/agents/learn-agent.md +1 -1
  237. package/plugins/learn/lib/adapter-transforms.js +24 -4
  238. package/plugins/learn/skills/learn/SKILL.md +1 -1
  239. package/plugins/next-task/.claude-plugin/plugin.json +1 -1
  240. package/plugins/next-task/agents/exploration-agent.md +1 -1
  241. package/plugins/next-task/lib/adapter-transforms.js +24 -4
  242. package/plugins/next-task/skills/discover-tasks/SKILL.md +1 -1
  243. package/plugins/next-task/skills/validate-delivery/SKILL.md +1 -1
  244. package/plugins/perf/.claude-plugin/plugin.json +1 -1
  245. package/plugins/perf/lib/adapter-transforms.js +24 -4
  246. package/plugins/perf/skills/perf-analyzer/SKILL.md +1 -1
  247. package/plugins/perf/skills/perf-baseline-manager/SKILL.md +1 -1
  248. package/plugins/perf/skills/perf-benchmarker/SKILL.md +1 -1
  249. package/plugins/perf/skills/perf-code-paths/SKILL.md +1 -1
  250. package/plugins/perf/skills/perf-investigation-logger/SKILL.md +1 -1
  251. package/plugins/perf/skills/perf-profiler/SKILL.md +1 -1
  252. package/plugins/perf/skills/perf-theory-gatherer/SKILL.md +1 -1
  253. package/plugins/perf/skills/perf-theory-tester/SKILL.md +1 -1
  254. package/plugins/repo-map/.claude-plugin/plugin.json +1 -1
  255. package/plugins/repo-map/lib/adapter-transforms.js +24 -4
  256. package/plugins/ship/.claude-plugin/plugin.json +1 -1
  257. package/plugins/ship/lib/adapter-transforms.js +24 -4
  258. package/plugins/sync-docs/.claude-plugin/plugin.json +1 -1
  259. package/plugins/sync-docs/lib/adapter-transforms.js +24 -4
  260. package/plugins/sync-docs/skills/sync-docs/SKILL.md +1 -1
  261. package/scripts/gen-adapters.js +6 -7
  262. package/scripts/generate-docs.js +4 -2
  263. package/scripts/plugins.txt +1 -0
  264. package/site/content.json +6 -6
@@ -0,0 +1,617 @@
1
+ /**
2
+ * Project Memory Patterns
3
+ * Detection patterns for CLAUDE.md/AGENTS.md project memory files
4
+ */
5
+
6
+ /**
7
+ * Project memory patterns with certainty levels
8
+ * Following the agent-patterns model
9
+ */
10
+ const projectMemoryPatterns = {
11
+ // ============================================
12
+ // HIGH CERTAINTY PATTERNS
13
+ // ============================================
14
+
15
+ /**
16
+ * Missing critical rules section
17
+ * HIGH certainty - project memory should have critical rules
18
+ */
19
+ missing_critical_rules: {
20
+ id: 'missing_critical_rules',
21
+ category: 'structure',
22
+ certainty: 'HIGH',
23
+ autoFix: false,
24
+ description: 'No critical rules or priority rules section',
25
+ check: (content) => {
26
+ if (!content || typeof content !== 'string') return null;
27
+
28
+ // Look for critical rules indicators
29
+ const hasCriticalRules = /##\s+critical\s+rules/i.test(content);
30
+ const hasPriorityRules = /##\s+priority\s+rules/i.test(content);
31
+ const hasImportantRules = /<critical-rules>/i.test(content);
32
+ const hasMustKnow = /##\s+must[- ]know/i.test(content);
33
+
34
+ if (!hasCriticalRules && !hasPriorityRules && !hasImportantRules && !hasMustKnow) {
35
+ return {
36
+ issue: 'Missing critical rules section',
37
+ fix: 'Add "## Critical Rules" section with prioritized project rules'
38
+ };
39
+ }
40
+ return null;
41
+ }
42
+ },
43
+
44
+ /**
45
+ * Missing architecture section
46
+ * HIGH certainty - should have overview of project structure
47
+ */
48
+ missing_architecture: {
49
+ id: 'missing_architecture',
50
+ category: 'structure',
51
+ certainty: 'HIGH',
52
+ autoFix: false,
53
+ description: 'No architecture or project structure section',
54
+ check: (content) => {
55
+ if (!content || typeof content !== 'string') return null;
56
+
57
+ const hasArchitecture = /##\s+architecture/i.test(content);
58
+ const hasStructure = /##\s+(?:project\s+)?structure/i.test(content);
59
+ const hasOverview = /##\s+overview/i.test(content);
60
+ const hasDirectoryTree = content.includes('```') && /├──|└──|lib\/|src\//.test(content);
61
+
62
+ if (!hasArchitecture && !hasStructure && !hasOverview && !hasDirectoryTree) {
63
+ return {
64
+ issue: 'Missing architecture/structure section',
65
+ fix: 'Add "## Architecture" section with directory tree or project overview'
66
+ };
67
+ }
68
+ return null;
69
+ }
70
+ },
71
+
72
+ /**
73
+ * Missing key commands section
74
+ * HIGH certainty - should document common commands
75
+ */
76
+ missing_key_commands: {
77
+ id: 'missing_key_commands',
78
+ category: 'structure',
79
+ certainty: 'HIGH',
80
+ autoFix: false,
81
+ description: 'No commands or scripts section',
82
+ check: (content) => {
83
+ if (!content || typeof content !== 'string') return null;
84
+
85
+ const hasCommands = /##\s+(?:key\s+)?commands/i.test(content);
86
+ const hasScripts = /##\s+scripts/i.test(content);
87
+ const hasUsage = /##\s+usage/i.test(content);
88
+ const hasCodeBlocks = /```(?:bash|sh|shell)/i.test(content) && /\b(?:npm|yarn|pnpm|git|make)\b/i.test(content);
89
+
90
+ if (!hasCommands && !hasScripts && !hasUsage && !hasCodeBlocks) {
91
+ return {
92
+ issue: 'Missing key commands section',
93
+ fix: 'Add "## Key Commands" section with common development commands'
94
+ };
95
+ }
96
+ return null;
97
+ }
98
+ },
99
+
100
+ /**
101
+ * Broken file reference
102
+ * HIGH certainty - referenced files should exist
103
+ */
104
+ broken_file_reference: {
105
+ id: 'broken_file_reference',
106
+ category: 'reference',
107
+ certainty: 'HIGH',
108
+ autoFix: false,
109
+ description: 'References a file that does not exist',
110
+ check: (content, context = {}) => {
111
+ // This check requires file system access, handled in analyzer
112
+ // Pattern just defines the structure
113
+ if (!content || typeof content !== 'string') return null;
114
+ if (!context.brokenFiles || context.brokenFiles.length === 0) return null;
115
+
116
+ return {
117
+ issue: `Broken file references: ${context.brokenFiles.slice(0, 3).join(', ')}${context.brokenFiles.length > 3 ? '...' : ''}`,
118
+ fix: 'Update or remove references to non-existent files',
119
+ files: context.brokenFiles
120
+ };
121
+ }
122
+ },
123
+
124
+ /**
125
+ * Broken command reference
126
+ * HIGH certainty - documented commands should work
127
+ */
128
+ broken_command_reference: {
129
+ id: 'broken_command_reference',
130
+ category: 'reference',
131
+ certainty: 'HIGH',
132
+ autoFix: false,
133
+ description: 'Documents a command that does not exist in package.json',
134
+ check: (content, context = {}) => {
135
+ // This check requires package.json access, handled in analyzer
136
+ if (!content || typeof content !== 'string') return null;
137
+ if (!context.brokenCommands || context.brokenCommands.length === 0) return null;
138
+
139
+ return {
140
+ issue: `Broken command references: ${context.brokenCommands.join(', ')}`,
141
+ fix: 'Update or remove references to non-existent commands',
142
+ commands: context.brokenCommands
143
+ };
144
+ }
145
+ },
146
+
147
+ // ============================================
148
+ // MEDIUM CERTAINTY PATTERNS
149
+ // ============================================
150
+
151
+ /**
152
+ * README duplication
153
+ * MEDIUM certainty - should not duplicate README.md content
154
+ */
155
+ readme_duplication: {
156
+ id: 'readme_duplication',
157
+ category: 'efficiency',
158
+ certainty: 'MEDIUM',
159
+ autoFix: false,
160
+ description: 'Duplicates content from README.md',
161
+ check: (content, context = {}) => {
162
+ if (!content || typeof content !== 'string') return null;
163
+ if (!context.duplicationRatio) return null;
164
+
165
+ // Flag if more than 40% overlap with README
166
+ if (context.duplicationRatio > 0.4) {
167
+ return {
168
+ issue: `${Math.round(context.duplicationRatio * 100)}% content duplicated from README.md`,
169
+ fix: 'Reference README.md instead of duplicating content'
170
+ };
171
+ }
172
+ return null;
173
+ }
174
+ },
175
+
176
+ /**
177
+ * Excessive token count
178
+ * MEDIUM certainty - large files waste context tokens
179
+ */
180
+ excessive_token_count: {
181
+ id: 'excessive_token_count',
182
+ category: 'efficiency',
183
+ certainty: 'MEDIUM',
184
+ autoFix: false,
185
+ description: 'Project memory file exceeds recommended token count',
186
+ maxTokens: 1500,
187
+ check: (content) => {
188
+ if (!content || typeof content !== 'string') return null;
189
+
190
+ // Rough token estimate (1 token ~ 4 characters)
191
+ const estimatedTokens = Math.ceil(content.length / 4);
192
+
193
+ if (estimatedTokens > 1500) {
194
+ return {
195
+ issue: `Estimated ${estimatedTokens} tokens (recommended max: 1500)`,
196
+ fix: 'Condense content, use links to detailed docs, or move verbose sections elsewhere'
197
+ };
198
+ }
199
+ return null;
200
+ }
201
+ },
202
+
203
+ /**
204
+ * Verbose instructions
205
+ * MEDIUM certainty - project memory should be concise
206
+ */
207
+ verbose_instructions: {
208
+ id: 'verbose_instructions',
209
+ category: 'efficiency',
210
+ certainty: 'MEDIUM',
211
+ autoFix: false,
212
+ description: 'Instructions are too verbose for quick reference',
213
+ check: (content) => {
214
+ if (!content || typeof content !== 'string') return null;
215
+
216
+ // Check for verbose indicators
217
+ const lines = content.split('\n');
218
+ const avgLineLength = lines.reduce((sum, l) => sum + l.length, 0) / lines.length;
219
+ const longParagraphs = (content.match(/[^\n]{200,}/g) || []).length;
220
+
221
+ // Flag if average line is long OR many long paragraphs
222
+ if (avgLineLength > 80 && longParagraphs > 3) {
223
+ return {
224
+ issue: 'Content is verbose (avg line: ' + Math.round(avgLineLength) + ' chars)',
225
+ fix: 'Use bullet points, tables, and concise language'
226
+ };
227
+ }
228
+ return null;
229
+ }
230
+ },
231
+
232
+ /**
233
+ * Missing WHY explanations
234
+ * MEDIUM certainty - rules should explain rationale
235
+ */
236
+ missing_why: {
237
+ id: 'missing_why',
238
+ category: 'quality',
239
+ certainty: 'MEDIUM',
240
+ autoFix: false,
241
+ description: 'Rules lack WHY explanations',
242
+ check: (content) => {
243
+ if (!content || typeof content !== 'string') return null;
244
+
245
+ // Count rules/requirements
246
+ const ruleIndicators = content.match(/(?:must|never|always|do not|required|important)/gi) || [];
247
+ const whyExplanations = content.match(/(?:\*WHY:|WHY:|because|reason:|rationale:)/gi) || [];
248
+
249
+ // If many rules but few explanations
250
+ if (ruleIndicators.length > 5 && whyExplanations.length < ruleIndicators.length / 3) {
251
+ return {
252
+ issue: `Found ${ruleIndicators.length} rules but only ${whyExplanations.length} WHY explanations`,
253
+ fix: 'Add *WHY: explanation for each rule to help AI understand intent'
254
+ };
255
+ }
256
+ return null;
257
+ }
258
+ },
259
+
260
+ // ============================================
261
+ // LOW CERTAINTY PATTERNS
262
+ // ============================================
263
+
264
+ /**
265
+ * Example overload
266
+ * LOW certainty - too many examples waste tokens
267
+ */
268
+ example_overload: {
269
+ id: 'example_overload',
270
+ category: 'efficiency',
271
+ certainty: 'LOW',
272
+ autoFix: false,
273
+ description: 'Too many inline examples',
274
+ check: (content) => {
275
+ if (!content || typeof content !== 'string') return null;
276
+
277
+ // Count example blocks
278
+ const codeBlocks = (content.match(/```[\s\S]*?```/g) || []).length;
279
+ const exampleSections = (content.match(/##\s+example/gi) || []).length;
280
+ const inlineExamples = (content.match(/<(?:good-)?example>/gi) || []).length;
281
+
282
+ const totalExamples = codeBlocks + exampleSections + inlineExamples;
283
+
284
+ if (totalExamples > 10) {
285
+ return {
286
+ issue: `Found ${totalExamples} examples/code blocks (may be excessive)`,
287
+ fix: 'Consider moving examples to separate docs and linking'
288
+ };
289
+ }
290
+ return null;
291
+ }
292
+ },
293
+
294
+ /**
295
+ * Deep nesting in structure
296
+ * LOW certainty - deeply nested content is hard to scan
297
+ */
298
+ deep_nesting: {
299
+ id: 'deep_nesting',
300
+ category: 'quality',
301
+ certainty: 'LOW',
302
+ autoFix: false,
303
+ description: 'Content has deep nesting (>3 levels)',
304
+ check: (content) => {
305
+ if (!content || typeof content !== 'string') return null;
306
+
307
+ // Check header nesting depth
308
+ const h4Plus = (content.match(/^####/gm) || []).length;
309
+ const h5Plus = (content.match(/^#####/gm) || []).length;
310
+
311
+ // Check list nesting
312
+ const deepLists = (content.match(/^(?:\s{8,}[-*]|\t{3,}[-*])/gm) || []).length;
313
+
314
+ if (h5Plus > 2 || deepLists > 5 || (h4Plus > 5 && deepLists > 3)) {
315
+ return {
316
+ issue: 'Content has deep nesting structure',
317
+ fix: 'Flatten hierarchy for easier scanning'
318
+ };
319
+ }
320
+ return null;
321
+ }
322
+ },
323
+
324
+ // ============================================
325
+ // CROSS-PLATFORM PATTERNS
326
+ // ============================================
327
+
328
+ /**
329
+ * Hardcoded state directory
330
+ * HIGH certainty - breaks cross-platform compatibility
331
+ */
332
+ hardcoded_state_dir: {
333
+ id: 'hardcoded_state_dir',
334
+ category: 'cross-platform',
335
+ certainty: 'HIGH',
336
+ autoFix: false,
337
+ description: 'Hardcoded .claude/ directory (breaks OpenCode/Codex)',
338
+ check: (content) => {
339
+ if (!content || typeof content !== 'string') return null;
340
+
341
+ // Look for hardcoded .claude/ that should be ${STATE_DIR}/
342
+ const hasHardcodedClaude = /\.claude\//.test(content);
343
+ // Check if properly using platform-aware reference
344
+ const usesPlatformAware = /\$\{?STATE_DIR\}?|\.opencode\/|\.codex\/|Platform-aware/i.test(content);
345
+
346
+ if (hasHardcodedClaude && !usesPlatformAware) {
347
+ return {
348
+ issue: 'Hardcoded .claude/ directory path without cross-platform note',
349
+ fix: 'Use ${STATE_DIR}/ or document platform variations (.claude/, .opencode/, .codex/)'
350
+ };
351
+ }
352
+ return null;
353
+ }
354
+ },
355
+
356
+ /**
357
+ * Claude-only terminology
358
+ * MEDIUM certainty - should be tool-agnostic where possible
359
+ */
360
+ claude_only_terminology: {
361
+ id: 'claude_only_terminology',
362
+ category: 'cross-platform',
363
+ certainty: 'MEDIUM',
364
+ autoFix: false,
365
+ description: 'Uses Claude-specific terminology without alternatives',
366
+ check: (content) => {
367
+ if (!content || typeof content !== 'string') return null;
368
+
369
+ // Check for Claude-specific terms without alternatives
370
+ const claudeOnly = (content.match(/\bClaude Code\b/g) || []).length;
371
+ const hasAlternatives = /OpenCode|Codex|AI assistant|AI coding assistant/i.test(content);
372
+
373
+ if (claudeOnly > 3 && !hasAlternatives) {
374
+ return {
375
+ issue: 'Uses "Claude Code" frequently without mentioning alternatives',
376
+ fix: 'Use "AI assistant" or mention OpenCode/Codex alternatives for cross-platform support'
377
+ };
378
+ }
379
+ return null;
380
+ }
381
+ },
382
+
383
+ /**
384
+ * Missing file type recognition
385
+ * MEDIUM certainty - should mention AGENTS.md alternative
386
+ */
387
+ missing_agents_md_mention: {
388
+ id: 'missing_agents_md_mention',
389
+ category: 'cross-platform',
390
+ certainty: 'MEDIUM',
391
+ autoFix: false,
392
+ description: 'File is CLAUDE.md but does not mention AGENTS.md compatibility',
393
+ check: (content, context = {}) => {
394
+ if (!content || typeof content !== 'string') return null;
395
+
396
+ // Only applies to CLAUDE.md files
397
+ if (context.fileName && !context.fileName.includes('CLAUDE.md')) return null;
398
+
399
+ const mentionsAgentsMd = /AGENTS\.md/i.test(content);
400
+
401
+ if (!mentionsAgentsMd) {
402
+ return {
403
+ issue: 'CLAUDE.md does not mention AGENTS.md compatibility',
404
+ fix: 'Note: This file may also work as AGENTS.md for OpenCode/Codex'
405
+ };
406
+ }
407
+ return null;
408
+ }
409
+ },
410
+
411
+ // ============================================
412
+ // CONTENT QUALITY PATTERNS (from Claude Code Best Practices)
413
+ // ============================================
414
+
415
+ /**
416
+ * Includes obvious information Claude can infer
417
+ * MEDIUM certainty - wastes tokens on things Claude knows
418
+ * Source: https://code.claude.com/docs/en/best-practices
419
+ */
420
+ includes_obvious_information: {
421
+ id: 'includes_obvious_information',
422
+ category: 'efficiency',
423
+ certainty: 'MEDIUM',
424
+ autoFix: false,
425
+ description: 'Includes information Claude can infer from reading code',
426
+ check: (content) => {
427
+ if (!content || typeof content !== 'string') return null;
428
+
429
+ // Patterns that suggest obvious/inferable content
430
+ const obviousPatterns = [
431
+ /\bthis is a (?:node|python|rust|go|java)\s+project\b/i,
432
+ /\bwe use (?:npm|yarn|pnpm|pip|cargo)\b/i,
433
+ /\bthe (?:src|lib|test) folder contains\b/i,
434
+ /\bstandard (?:REST|HTTP|JSON) conventions\b/i,
435
+ /\bfollow (?:PEP|ESLint|standard) (?:style|conventions)\b/i,
436
+ /\bwrite clean code\b/i,
437
+ /\buse meaningful variable names\b/i,
438
+ /\bcomment your code\b/i,
439
+ /\bhandle errors appropriately\b/i
440
+ ];
441
+
442
+ const found = [];
443
+ for (const pattern of obviousPatterns) {
444
+ if (pattern.test(content)) {
445
+ found.push(pattern.source.slice(2, 40) + '...');
446
+ }
447
+ }
448
+
449
+ if (found.length >= 3) {
450
+ return {
451
+ issue: `Contains ${found.length} obvious/inferable items that waste tokens`,
452
+ fix: 'Remove information Claude can infer from code. Focus on what Claude CANNOT guess.',
453
+ details: found.slice(0, 3)
454
+ };
455
+ }
456
+ return null;
457
+ }
458
+ },
459
+
460
+ /**
461
+ * Missing emphasis markers on important rules
462
+ * MEDIUM certainty - IMPORTANT/MUST improves adherence
463
+ * Source: https://code.claude.com/docs/en/best-practices
464
+ */
465
+ missing_emphasis_markers: {
466
+ id: 'missing_emphasis_markers',
467
+ category: 'quality',
468
+ certainty: 'MEDIUM',
469
+ autoFix: false,
470
+ description: 'Critical rules lack emphasis markers (IMPORTANT, MUST, CRITICAL)',
471
+ check: (content) => {
472
+ if (!content || typeof content !== 'string') return null;
473
+
474
+ // Count strong rules without emphasis
475
+ const strongRules = (content.match(/\b(?:never|always|required|must not)\b/gi) || []).length;
476
+ const emphasisMarkers = (content.match(/\b(?:IMPORTANT|CRITICAL|MUST|YOU MUST|NEVER)\b/g) || []).length;
477
+
478
+ // If many rules but few emphasis markers
479
+ if (strongRules > 5 && emphasisMarkers < 2) {
480
+ return {
481
+ issue: `Found ${strongRules} strong rules but only ${emphasisMarkers} emphasis markers`,
482
+ fix: 'Add IMPORTANT: or MUST prefix to critical rules to improve adherence'
483
+ };
484
+ }
485
+ return null;
486
+ }
487
+ },
488
+
489
+ /**
490
+ * Self-evident practices that waste tokens
491
+ * LOW certainty - generic advice Claude already follows
492
+ * Source: https://code.claude.com/docs/en/best-practices
493
+ */
494
+ self_evident_practices: {
495
+ id: 'self_evident_practices',
496
+ category: 'efficiency',
497
+ certainty: 'LOW',
498
+ autoFix: false,
499
+ description: 'Contains self-evident practices Claude already follows',
500
+ check: (content) => {
501
+ if (!content || typeof content !== 'string') return null;
502
+
503
+ const selfEvident = [
504
+ /\bwrite tests\b/i,
505
+ /\bfollow best practices\b/i,
506
+ /\bbe consistent\b/i,
507
+ /\buse descriptive names\b/i,
508
+ /\bavoid code duplication\b/i,
509
+ /\bkeep functions small\b/i,
510
+ /\bsingle responsibility\b/i,
511
+ /\bDRY principle\b/i
512
+ ];
513
+
514
+ let count = 0;
515
+ for (const pattern of selfEvident) {
516
+ if (pattern.test(content)) count++;
517
+ }
518
+
519
+ if (count >= 4) {
520
+ return {
521
+ issue: `Contains ${count} self-evident practices that Claude already follows`,
522
+ fix: 'Remove generic best practices. Only document PROJECT-SPECIFIC rules.'
523
+ };
524
+ }
525
+ return null;
526
+ }
527
+ },
528
+
529
+ /**
530
+ * File too long causing rule ignorance
531
+ * HIGH certainty - long files cause Claude to miss rules
532
+ * Source: https://code.claude.com/docs/en/best-practices
533
+ */
534
+ file_too_long_rules_ignored: {
535
+ id: 'file_too_long_rules_ignored',
536
+ category: 'efficiency',
537
+ certainty: 'HIGH',
538
+ autoFix: false,
539
+ description: 'File is long enough that rules may be ignored',
540
+ maxLines: 150,
541
+ check: (content) => {
542
+ if (!content || typeof content !== 'string') return null;
543
+
544
+ const lines = content.split('\n').length;
545
+ const ruleCount = (content.match(/\b(?:must|never|always|required|important)\b/gi) || []).length;
546
+
547
+ // If file is long AND has many rules, some will be ignored
548
+ if (lines > 150 && ruleCount > 10) {
549
+ return {
550
+ issue: `File has ${lines} lines and ${ruleCount} rules - some rules will likely be ignored`,
551
+ fix: 'If Claude ignores rules despite them being documented, the file is too long. Prune ruthlessly.'
552
+ };
553
+ }
554
+ return null;
555
+ }
556
+ }
557
+ };
558
+
559
+ /**
560
+ * Get all patterns
561
+ * @returns {Object} All project memory patterns
562
+ */
563
+ function getAllPatterns() {
564
+ return projectMemoryPatterns;
565
+ }
566
+
567
+ /**
568
+ * Get patterns by certainty level
569
+ * @param {string} certainty - HIGH, MEDIUM, or LOW
570
+ * @returns {Object} Filtered patterns
571
+ */
572
+ function getPatternsByCertainty(certainty) {
573
+ const result = {};
574
+ for (const [name, pattern] of Object.entries(projectMemoryPatterns)) {
575
+ if (pattern.certainty === certainty) {
576
+ result[name] = pattern;
577
+ }
578
+ }
579
+ return result;
580
+ }
581
+
582
+ /**
583
+ * Get patterns by category
584
+ * @param {string} category - structure, reference, efficiency, quality, cross-platform
585
+ * @returns {Object} Filtered patterns
586
+ */
587
+ function getPatternsByCategory(category) {
588
+ const result = {};
589
+ for (const [name, pattern] of Object.entries(projectMemoryPatterns)) {
590
+ if (pattern.category === category) {
591
+ result[name] = pattern;
592
+ }
593
+ }
594
+ return result;
595
+ }
596
+
597
+ /**
598
+ * Get auto-fixable patterns
599
+ * @returns {Object} Patterns with autoFix: true
600
+ */
601
+ function getAutoFixablePatterns() {
602
+ const result = {};
603
+ for (const [name, pattern] of Object.entries(projectMemoryPatterns)) {
604
+ if (pattern.autoFix) {
605
+ result[name] = pattern;
606
+ }
607
+ }
608
+ return result;
609
+ }
610
+
611
+ module.exports = {
612
+ projectMemoryPatterns,
613
+ getAllPatterns,
614
+ getPatternsByCertainty,
615
+ getPatternsByCategory,
616
+ getAutoFixablePatterns
617
+ };