opencode-dux 1.0.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 (302) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +452 -0
  3. package/dist/agents/descriptions.d.ts +6 -0
  4. package/dist/agents/designer.d.ts +2 -0
  5. package/dist/agents/explorer.d.ts +2 -0
  6. package/dist/agents/fixer.d.ts +2 -0
  7. package/dist/agents/index.d.ts +22 -0
  8. package/dist/agents/interpreter.d.ts +2 -0
  9. package/dist/agents/librarian.d.ts +2 -0
  10. package/dist/agents/oracle.d.ts +2 -0
  11. package/dist/agents/orchestrator.d.ts +27 -0
  12. package/dist/agents/overrides.d.ts +18 -0
  13. package/dist/agents/prompt-blocks.d.ts +97 -0
  14. package/dist/agents/steward.d.ts +3 -0
  15. package/dist/cli/config-io.d.ts +24 -0
  16. package/dist/cli/config-manager.d.ts +4 -0
  17. package/dist/cli/index.d.ts +2 -0
  18. package/dist/cli/index.js +1006 -0
  19. package/dist/cli/install.d.ts +2 -0
  20. package/dist/cli/mcps.d.ts +13 -0
  21. package/dist/cli/model-key-normalization.d.ts +1 -0
  22. package/dist/cli/paths.d.ts +35 -0
  23. package/dist/cli/providers.d.ts +137 -0
  24. package/dist/cli/skills.d.ts +22 -0
  25. package/dist/cli/system.d.ts +5 -0
  26. package/dist/cli/types.d.ts +38 -0
  27. package/dist/config/constants.d.ts +12 -0
  28. package/dist/config/index.d.ts +4 -0
  29. package/dist/config/loader.d.ts +40 -0
  30. package/dist/config/runtime-preset.d.ts +12 -0
  31. package/dist/config/schema.d.ts +281 -0
  32. package/dist/config/utils.d.ts +10 -0
  33. package/dist/discovery/local/types.d.ts +79 -0
  34. package/dist/discovery/local.d.ts +73 -0
  35. package/dist/discovery/mcp-servers.d.ts +88 -0
  36. package/dist/discovery/skills.d.ts +94 -0
  37. package/dist/hooks/apply-patch/codec.d.ts +7 -0
  38. package/dist/hooks/apply-patch/errors.d.ts +25 -0
  39. package/dist/hooks/apply-patch/execution-context.d.ts +27 -0
  40. package/dist/hooks/apply-patch/index.d.ts +15 -0
  41. package/dist/hooks/apply-patch/matching.d.ts +26 -0
  42. package/dist/hooks/apply-patch/operations.d.ts +3 -0
  43. package/dist/hooks/apply-patch/patch.d.ts +2 -0
  44. package/dist/hooks/apply-patch/prepared-changes.d.ts +17 -0
  45. package/dist/hooks/apply-patch/resolution.d.ts +19 -0
  46. package/dist/hooks/apply-patch/rewrite.d.ts +7 -0
  47. package/dist/hooks/apply-patch/test-helpers.d.ts +6 -0
  48. package/dist/hooks/apply-patch/types.d.ts +80 -0
  49. package/dist/hooks/auto-update-checker/cache.d.ts +11 -0
  50. package/dist/hooks/auto-update-checker/checker.d.ts +32 -0
  51. package/dist/hooks/auto-update-checker/constants.d.ts +11 -0
  52. package/dist/hooks/auto-update-checker/index.d.ts +18 -0
  53. package/dist/hooks/auto-update-checker/types.d.ts +22 -0
  54. package/dist/hooks/chat-headers.d.ts +16 -0
  55. package/dist/hooks/context-pressure-reminder/index.d.ts +33 -0
  56. package/dist/hooks/delegate-task-retry/guidance.d.ts +2 -0
  57. package/dist/hooks/delegate-task-retry/hook.d.ts +8 -0
  58. package/dist/hooks/delegate-task-retry/index.d.ts +4 -0
  59. package/dist/hooks/delegate-task-retry/patterns.d.ts +11 -0
  60. package/dist/hooks/filter-available-skills/index.d.ts +32 -0
  61. package/dist/hooks/foreground-fallback/index.d.ts +72 -0
  62. package/dist/hooks/image-hook.d.ts +5 -0
  63. package/dist/hooks/index.d.ts +14 -0
  64. package/dist/hooks/json-error-recovery/hook.d.ts +18 -0
  65. package/dist/hooks/json-error-recovery/index.d.ts +1 -0
  66. package/dist/hooks/phase-reminder/index.d.ts +26 -0
  67. package/dist/hooks/post-file-tool-nudge/index.d.ts +19 -0
  68. package/dist/hooks/task-session-manager/index.d.ts +52 -0
  69. package/dist/hooks/todo-continuation/index.d.ts +53 -0
  70. package/dist/hooks/todo-continuation/todo-hygiene.d.ts +35 -0
  71. package/dist/index.d.ts +5 -0
  72. package/dist/index.js +31782 -0
  73. package/dist/mcp/context7.d.ts +6 -0
  74. package/dist/mcp/grep-app.d.ts +6 -0
  75. package/dist/mcp/index.d.ts +13 -0
  76. package/dist/mcp/types.d.ts +12 -0
  77. package/dist/mcp/websearch.d.ts +9 -0
  78. package/dist/skills/registry.d.ts +29 -0
  79. package/dist/subscriptions/accounts-store.d.ts +57 -0
  80. package/dist/subscriptions/index.d.ts +13 -0
  81. package/dist/subscriptions/neuralwatt-scraper.d.ts +14 -0
  82. package/dist/subscriptions/opencode-go-scraper.d.ts +27 -0
  83. package/dist/subscriptions/types.d.ts +115 -0
  84. package/dist/subscriptions/usage-service.d.ts +74 -0
  85. package/dist/tools/ast-grep/cli.d.ts +15 -0
  86. package/dist/tools/ast-grep/constants.d.ts +25 -0
  87. package/dist/tools/ast-grep/downloader.d.ts +5 -0
  88. package/dist/tools/ast-grep/index.d.ts +10 -0
  89. package/dist/tools/ast-grep/tools.d.ts +3 -0
  90. package/dist/tools/ast-grep/types.d.ts +30 -0
  91. package/dist/tools/ast-grep/utils.d.ts +4 -0
  92. package/dist/tools/delegate.d.ts +14 -0
  93. package/dist/tools/index.d.ts +5 -0
  94. package/dist/tools/preset-manager.d.ts +27 -0
  95. package/dist/tools/smartfetch/binary.d.ts +3 -0
  96. package/dist/tools/smartfetch/cache.d.ts +6 -0
  97. package/dist/tools/smartfetch/constants.d.ts +12 -0
  98. package/dist/tools/smartfetch/index.d.ts +3 -0
  99. package/dist/tools/smartfetch/network.d.ts +38 -0
  100. package/dist/tools/smartfetch/secondary-model.d.ts +28 -0
  101. package/dist/tools/smartfetch/tool.d.ts +3 -0
  102. package/dist/tools/smartfetch/types.d.ts +122 -0
  103. package/dist/tools/smartfetch/utils.d.ts +18 -0
  104. package/dist/tui-state.d.ts +168 -0
  105. package/dist/tui.d.ts +37 -0
  106. package/dist/tui.js +1896 -0
  107. package/dist/utils/agent-variant.d.ts +63 -0
  108. package/dist/utils/compat.d.ts +30 -0
  109. package/dist/utils/env.d.ts +1 -0
  110. package/dist/utils/index.d.ts +9 -0
  111. package/dist/utils/internal-initiator.d.ts +6 -0
  112. package/dist/utils/logger.d.ts +8 -0
  113. package/dist/utils/polling.d.ts +21 -0
  114. package/dist/utils/session-manager.d.ts +55 -0
  115. package/dist/utils/session.d.ts +90 -0
  116. package/dist/utils/subagent-depth.d.ts +35 -0
  117. package/dist/utils/system-collapse.d.ts +6 -0
  118. package/dist/utils/task.d.ts +4 -0
  119. package/dist/utils/zip-extractor.d.ts +1 -0
  120. package/index.ts +1 -0
  121. package/opencode-dux.schema.json +634 -0
  122. package/package.json +103 -0
  123. package/src/agents/descriptions.ts +55 -0
  124. package/src/agents/designer.test.ts +86 -0
  125. package/src/agents/designer.ts +154 -0
  126. package/src/agents/display-name.test.ts +186 -0
  127. package/src/agents/explorer.test.ts +79 -0
  128. package/src/agents/explorer.ts +144 -0
  129. package/src/agents/fixer.test.ts +79 -0
  130. package/src/agents/fixer.ts +145 -0
  131. package/src/agents/index.test.ts +472 -0
  132. package/src/agents/index.ts +248 -0
  133. package/src/agents/interpreter.ts +136 -0
  134. package/src/agents/librarian.test.ts +80 -0
  135. package/src/agents/librarian.ts +145 -0
  136. package/src/agents/oracle.test.ts +89 -0
  137. package/src/agents/oracle.ts +184 -0
  138. package/src/agents/orchestrator.test.ts +116 -0
  139. package/src/agents/orchestrator.ts +574 -0
  140. package/src/agents/overrides.ts +95 -0
  141. package/src/agents/prompt-blocks.test.ts +114 -0
  142. package/src/agents/prompt-blocks.ts +640 -0
  143. package/src/agents/steward.ts +146 -0
  144. package/src/cli/config-io.test.ts +536 -0
  145. package/src/cli/config-io.ts +473 -0
  146. package/src/cli/config-manager.test.ts +141 -0
  147. package/src/cli/config-manager.ts +4 -0
  148. package/src/cli/index.ts +88 -0
  149. package/src/cli/install.ts +282 -0
  150. package/src/cli/mcps.test.ts +62 -0
  151. package/src/cli/mcps.ts +39 -0
  152. package/src/cli/model-key-normalization.test.ts +21 -0
  153. package/src/cli/model-key-normalization.ts +60 -0
  154. package/src/cli/paths.test.ts +167 -0
  155. package/src/cli/paths.ts +144 -0
  156. package/src/cli/providers.test.ts +118 -0
  157. package/src/cli/providers.ts +141 -0
  158. package/src/cli/skills.test.ts +111 -0
  159. package/src/cli/skills.ts +103 -0
  160. package/src/cli/system.test.ts +91 -0
  161. package/src/cli/system.ts +180 -0
  162. package/src/cli/types.ts +43 -0
  163. package/src/config/constants.ts +58 -0
  164. package/src/config/index.ts +4 -0
  165. package/src/config/loader.test.ts +1194 -0
  166. package/src/config/loader.ts +269 -0
  167. package/src/config/model-resolution.test.ts +176 -0
  168. package/src/config/runtime-preset.test.ts +61 -0
  169. package/src/config/runtime-preset.ts +37 -0
  170. package/src/config/schema.ts +248 -0
  171. package/src/config/utils.test.ts +41 -0
  172. package/src/config/utils.ts +23 -0
  173. package/src/discovery/local/types.ts +85 -0
  174. package/src/discovery/local.ts +322 -0
  175. package/src/discovery/mcp-servers.ts +804 -0
  176. package/src/discovery/skills.ts +959 -0
  177. package/src/hooks/apply-patch/codec.test.ts +184 -0
  178. package/src/hooks/apply-patch/codec.ts +352 -0
  179. package/src/hooks/apply-patch/errors.ts +117 -0
  180. package/src/hooks/apply-patch/execution-context.ts +432 -0
  181. package/src/hooks/apply-patch/hook.test.ts +768 -0
  182. package/src/hooks/apply-patch/index.ts +126 -0
  183. package/src/hooks/apply-patch/matching.test.ts +215 -0
  184. package/src/hooks/apply-patch/matching.ts +586 -0
  185. package/src/hooks/apply-patch/operations.test.ts +1535 -0
  186. package/src/hooks/apply-patch/operations.ts +3 -0
  187. package/src/hooks/apply-patch/patch.ts +9 -0
  188. package/src/hooks/apply-patch/prepared-changes.ts +400 -0
  189. package/src/hooks/apply-patch/resolution.test.ts +420 -0
  190. package/src/hooks/apply-patch/resolution.ts +437 -0
  191. package/src/hooks/apply-patch/rewrite.ts +496 -0
  192. package/src/hooks/apply-patch/test-helpers.ts +52 -0
  193. package/src/hooks/apply-patch/types.ts +111 -0
  194. package/src/hooks/auto-update-checker/cache.test.ts +179 -0
  195. package/src/hooks/auto-update-checker/cache.ts +188 -0
  196. package/src/hooks/auto-update-checker/checker.test.ts +159 -0
  197. package/src/hooks/auto-update-checker/checker.ts +308 -0
  198. package/src/hooks/auto-update-checker/constants.ts +33 -0
  199. package/src/hooks/auto-update-checker/index.test.ts +282 -0
  200. package/src/hooks/auto-update-checker/index.ts +225 -0
  201. package/src/hooks/auto-update-checker/types.ts +26 -0
  202. package/src/hooks/chat-headers.test.ts +236 -0
  203. package/src/hooks/chat-headers.ts +97 -0
  204. package/src/hooks/context-pressure-reminder/index.test.ts +179 -0
  205. package/src/hooks/context-pressure-reminder/index.ts +137 -0
  206. package/src/hooks/delegate-task-retry/guidance.ts +41 -0
  207. package/src/hooks/delegate-task-retry/hook.ts +23 -0
  208. package/src/hooks/delegate-task-retry/index.test.ts +38 -0
  209. package/src/hooks/delegate-task-retry/index.ts +7 -0
  210. package/src/hooks/delegate-task-retry/patterns.ts +79 -0
  211. package/src/hooks/filter-available-skills/index.test.ts +297 -0
  212. package/src/hooks/filter-available-skills/index.ts +160 -0
  213. package/src/hooks/foreground-fallback/index.test.ts +624 -0
  214. package/src/hooks/foreground-fallback/index.ts +374 -0
  215. package/src/hooks/image-hook.ts +6 -0
  216. package/src/hooks/index.ts +17 -0
  217. package/src/hooks/json-error-recovery/hook.ts +73 -0
  218. package/src/hooks/json-error-recovery/index.test.ts +111 -0
  219. package/src/hooks/json-error-recovery/index.ts +6 -0
  220. package/src/hooks/phase-reminder/index.test.ts +74 -0
  221. package/src/hooks/phase-reminder/index.ts +85 -0
  222. package/src/hooks/post-file-tool-nudge/index.test.ts +94 -0
  223. package/src/hooks/post-file-tool-nudge/index.ts +63 -0
  224. package/src/hooks/task-session-manager/index.test.ts +833 -0
  225. package/src/hooks/task-session-manager/index.ts +434 -0
  226. package/src/hooks/todo-continuation/index.test.ts +3026 -0
  227. package/src/hooks/todo-continuation/index.ts +878 -0
  228. package/src/hooks/todo-continuation/todo-hygiene.test.ts +204 -0
  229. package/src/hooks/todo-continuation/todo-hygiene.ts +207 -0
  230. package/src/index.ts +1672 -0
  231. package/src/mcp/context7.ts +14 -0
  232. package/src/mcp/grep-app.ts +11 -0
  233. package/src/mcp/index.test.ts +96 -0
  234. package/src/mcp/index.ts +66 -0
  235. package/src/mcp/types.ts +16 -0
  236. package/src/mcp/websearch.ts +47 -0
  237. package/src/skills/codemap/README.md +60 -0
  238. package/src/skills/codemap/SKILL.md +174 -0
  239. package/src/skills/codemap/scripts/codemap.mjs +483 -0
  240. package/src/skills/codemap/scripts/codemap.test.ts +129 -0
  241. package/src/skills/registry.ts +218 -0
  242. package/src/skills/simplify/README.md +19 -0
  243. package/src/skills/simplify/SKILL.md +138 -0
  244. package/src/subscriptions/accounts-store.test.ts +236 -0
  245. package/src/subscriptions/accounts-store.ts +184 -0
  246. package/src/subscriptions/index.ts +30 -0
  247. package/src/subscriptions/neuralwatt-scraper.ts +108 -0
  248. package/src/subscriptions/opencode-go-scraper.ts +301 -0
  249. package/src/subscriptions/types.ts +145 -0
  250. package/src/subscriptions/usage-service.test.ts +202 -0
  251. package/src/subscriptions/usage-service.ts +651 -0
  252. package/src/tools/ast-grep/cli.ts +257 -0
  253. package/src/tools/ast-grep/constants.ts +214 -0
  254. package/src/tools/ast-grep/downloader.ts +131 -0
  255. package/src/tools/ast-grep/index.ts +24 -0
  256. package/src/tools/ast-grep/tools.ts +117 -0
  257. package/src/tools/ast-grep/types.ts +51 -0
  258. package/src/tools/ast-grep/utils.ts +126 -0
  259. package/src/tools/delegate-handoff.test.ts +18 -0
  260. package/src/tools/delegate.ts +508 -0
  261. package/src/tools/index.ts +8 -0
  262. package/src/tools/preset-manager.test.ts +795 -0
  263. package/src/tools/preset-manager.ts +332 -0
  264. package/src/tools/smartfetch/binary.ts +58 -0
  265. package/src/tools/smartfetch/cache.test.ts +34 -0
  266. package/src/tools/smartfetch/cache.ts +112 -0
  267. package/src/tools/smartfetch/constants.ts +29 -0
  268. package/src/tools/smartfetch/index.ts +8 -0
  269. package/src/tools/smartfetch/network.test.ts +178 -0
  270. package/src/tools/smartfetch/network.ts +614 -0
  271. package/src/tools/smartfetch/secondary-model.test.ts +85 -0
  272. package/src/tools/smartfetch/secondary-model.ts +276 -0
  273. package/src/tools/smartfetch/tool.test.ts +60 -0
  274. package/src/tools/smartfetch/tool.ts +832 -0
  275. package/src/tools/smartfetch/types.ts +135 -0
  276. package/src/tools/smartfetch/utils.test.ts +24 -0
  277. package/src/tools/smartfetch/utils.ts +456 -0
  278. package/src/tui-state.test.ts +867 -0
  279. package/src/tui-state.ts +1255 -0
  280. package/src/tui.test.ts +336 -0
  281. package/src/tui.ts +1539 -0
  282. package/src/utils/agent-variant.test.ts +244 -0
  283. package/src/utils/agent-variant.ts +187 -0
  284. package/src/utils/compat.ts +91 -0
  285. package/src/utils/env.ts +12 -0
  286. package/src/utils/index.ts +9 -0
  287. package/src/utils/internal-initiator.ts +28 -0
  288. package/src/utils/logger.test.ts +220 -0
  289. package/src/utils/logger.ts +136 -0
  290. package/src/utils/polling.test.ts +191 -0
  291. package/src/utils/polling.ts +67 -0
  292. package/src/utils/session-manager.test.ts +173 -0
  293. package/src/utils/session-manager.ts +356 -0
  294. package/src/utils/session.test.ts +110 -0
  295. package/src/utils/session.ts +389 -0
  296. package/src/utils/subagent-depth.test.ts +170 -0
  297. package/src/utils/subagent-depth.ts +75 -0
  298. package/src/utils/system-collapse.test.ts +86 -0
  299. package/src/utils/system-collapse.ts +24 -0
  300. package/src/utils/task.test.ts +24 -0
  301. package/src/utils/task.ts +20 -0
  302. package/src/utils/zip-extractor.ts +102 -0
@@ -0,0 +1,218 @@
1
+ import type { Stats } from 'node:fs';
2
+ import { readdir, readFile, stat } from 'node:fs/promises';
3
+ import { join, relative, resolve } from 'node:path';
4
+
5
+ /**
6
+ * Metadata for a discovered skill.
7
+ */
8
+ export interface SkillMetadata {
9
+ /** Unique skill name (derived from folder name) */
10
+ name: string;
11
+ /** Human-readable description */
12
+ description: string;
13
+ /** Absolute path to the SKILL.md file */
14
+ path: string;
15
+ /** Tags for categorisation and matching */
16
+ tags: string[];
17
+ /** Agents that are recommended to use this skill */
18
+ recommendedAgents: string[];
19
+ }
20
+
21
+ // Module-level cache to avoid repeated filesystem scans
22
+ let skillsCache: SkillMetadata[] | null = null;
23
+ let cacheRoot: string | null = null;
24
+
25
+ /**
26
+ * Reset the skill discovery cache (for testing).
27
+ */
28
+ export function resetSkillsCache(): void {
29
+ skillsCache = null;
30
+ cacheRoot = null;
31
+ }
32
+
33
+ /**
34
+ * Parse YAML frontmatter from a markdown file.
35
+ * Supports simple key-value pairs and array values (both inline `[a, b]`
36
+ * and multiline `- item` formats). Returns a partial record of parsed
37
+ * values, ignoring unknown keys without error.
38
+ */
39
+ function parseFrontmatter(content: string): Record<string, string | string[]> {
40
+ const result: Record<string, string | string[]> = {};
41
+
42
+ // Match content between leading --- and trailing ---
43
+ const match = content.match(/^---\s*\n([\s\S]*?)\n---/);
44
+ if (!match) return result;
45
+
46
+ const block = match[1];
47
+ const lines = block.split('\n');
48
+
49
+ let currentKey: string | null = null;
50
+ const currentArray: string[] = [];
51
+
52
+ for (const raw of lines) {
53
+ const trimmed = raw.trim();
54
+
55
+ // Skip empty lines
56
+ if (trimmed === '') continue;
57
+
58
+ // Array item under a key (- value)
59
+ if (trimmed.startsWith('- ')) {
60
+ if (currentKey) {
61
+ currentArray.push(trimmed.slice(2).trim());
62
+ }
63
+ continue;
64
+ }
65
+
66
+ // If we were collecting an array, flush it
67
+ if (currentKey && currentArray.length > 0) {
68
+ result[currentKey] = [...currentArray];
69
+ currentArray.length = 0;
70
+ }
71
+
72
+ // Key: value pair
73
+ const colonIndex = trimmed.indexOf(':');
74
+ if (colonIndex === -1) {
75
+ currentKey = null;
76
+ continue;
77
+ }
78
+
79
+ const key = trimmed.slice(0, colonIndex).trim();
80
+ const value = trimmed.slice(colonIndex + 1).trim();
81
+
82
+ if (!key) {
83
+ currentKey = null;
84
+ continue;
85
+ }
86
+
87
+ if (value === '') {
88
+ // Multiline array follows
89
+ currentKey = key;
90
+ continue;
91
+ }
92
+
93
+ // Inline array: [item1, item2]
94
+ if (value.startsWith('[') && value.endsWith(']')) {
95
+ const inner = value.slice(1, -1);
96
+ result[key] = inner
97
+ .split(',')
98
+ .map((item) => item.trim())
99
+ .filter(Boolean);
100
+ } else {
101
+ result[key] = value;
102
+ }
103
+
104
+ currentKey = null;
105
+ }
106
+
107
+ // Flush trailing array if any
108
+ if (currentKey && currentArray.length > 0) {
109
+ result[currentKey] = [...currentArray];
110
+ }
111
+
112
+ return result;
113
+ }
114
+
115
+ /**
116
+ * Ensure a frontmatter field value is always a string array.
117
+ */
118
+ function asStringArray(value: string | string[] | undefined): string[] {
119
+ if (Array.isArray(value)) return value;
120
+ if (typeof value === 'string') return [value];
121
+ return [];
122
+ }
123
+
124
+ /**
125
+ * Scan the skills directory and return parsed skill metadata.
126
+ * Results are cached to avoid repeated filesystem scans;
127
+ * call {@link resetSkillsCache} to invalidate.
128
+ *
129
+ * Files with missing or invalid frontmatter are skipped with a warning.
130
+ *
131
+ * @param pluginRoot - Absolute path to the plugin root directory.
132
+ */
133
+ export async function discoverSkills(
134
+ pluginRoot: string,
135
+ ): Promise<SkillMetadata[]> {
136
+ const normalizedRoot = resolve(pluginRoot);
137
+
138
+ // Return cached results for the same root
139
+ if (skillsCache && cacheRoot === normalizedRoot) {
140
+ return skillsCache;
141
+ }
142
+
143
+ const skillsDir = join(normalizedRoot, 'src', 'skills');
144
+ const discovered: SkillMetadata[] = [];
145
+
146
+ let entries: string[];
147
+ try {
148
+ entries = await readdir(skillsDir);
149
+ } catch {
150
+ // Skills directory does not exist - nothing to discover
151
+ console.warn(`Skills directory not found: ${skillsDir}`);
152
+ skillsCache = [];
153
+ cacheRoot = normalizedRoot;
154
+ return [];
155
+ }
156
+
157
+ for (const entry of entries) {
158
+ const skillPath = join(skillsDir, entry);
159
+ let entryStat: Stats;
160
+ try {
161
+ entryStat = await stat(skillPath);
162
+ } catch {
163
+ continue;
164
+ }
165
+
166
+ if (!entryStat.isDirectory()) continue;
167
+
168
+ const skillMdPath = join(skillPath, 'SKILL.md');
169
+ let skillMdStat: Stats;
170
+ try {
171
+ skillMdStat = await stat(skillMdPath);
172
+ } catch {
173
+ // No SKILL.md in this directory - skip silently
174
+ continue;
175
+ }
176
+
177
+ if (!skillMdStat.isFile()) continue;
178
+
179
+ let content: string;
180
+ try {
181
+ content = await readFile(skillMdPath, 'utf-8');
182
+ } catch {
183
+ console.warn(
184
+ `Could not read skill file: ${relative(normalizedRoot, skillMdPath)}`,
185
+ );
186
+ continue;
187
+ }
188
+
189
+ const frontmatter = parseFrontmatter(content);
190
+ const name =
191
+ typeof frontmatter.name === 'string' ? frontmatter.name : entry;
192
+ const description =
193
+ typeof frontmatter.description === 'string'
194
+ ? frontmatter.description
195
+ : '';
196
+
197
+ if (typeof name !== 'string') {
198
+ console.warn(
199
+ 'Invalid frontmatter in ' +
200
+ relative(normalizedRoot, skillMdPath) +
201
+ ': name must be a string',
202
+ );
203
+ continue;
204
+ }
205
+
206
+ discovered.push({
207
+ name,
208
+ description,
209
+ path: skillMdPath,
210
+ tags: asStringArray(frontmatter.tags),
211
+ recommendedAgents: asStringArray(frontmatter.recommendedAgents),
212
+ });
213
+ }
214
+
215
+ skillsCache = discovered;
216
+ cacheRoot = normalizedRoot;
217
+ return discovered;
218
+ }
@@ -0,0 +1,19 @@
1
+ # Simplify Skill
2
+
3
+ Behavior-preserving code simplification and readability-focused refactoring.
4
+
5
+ ## Overview
6
+
7
+ This bundled skill helps the `oracle` agent review and simplify code without
8
+ changing behavior. It focuses on readability, maintainability, and reducing
9
+ unnecessary complexity.
10
+
11
+ ## Source
12
+
13
+ Adapted from Addy Osmani's
14
+ [`code-simplification` skill](https://github.com/addyosmani/agent-skills/blob/main/skills/code-simplification/SKILL.md).
15
+
16
+ ## Installation
17
+
18
+ Bundled with `opencode-dux` and auto-scanned on plugin init. The plugin
19
+ registers it automatically; no manual installation needed.
@@ -0,0 +1,138 @@
1
+ ---
2
+ name: simplify
3
+ description: Simplifies code for clarity without changing behavior. Use for readability, maintainability, and complexity reduction after behavior is understood.
4
+ ---
5
+
6
+ # Code Simplification
7
+
8
+ ## Overview
9
+
10
+ Simplify code by reducing complexity while preserving exact behavior. The goal is not fewer lines - it's code that is easier to read, understand, modify, and debug. Every simplification must pass a simple test: "Would a new team member understand this faster than the original?"
11
+
12
+ ## When to Use
13
+
14
+ - After a feature is working and tests pass, but the implementation feels heavier than it needs to be
15
+ - During code review when readability or complexity issues are flagged
16
+ - When you encounter deeply nested logic, long functions, or unclear names
17
+ - When refactoring code written under time pressure
18
+ - When consolidating related logic scattered across files
19
+ - After merging changes that introduced duplication or inconsistency
20
+
21
+ **When NOT to use:**
22
+
23
+ - Code is already clean and readable - don't simplify for the sake of it
24
+ - You don't understand what the code does yet - comprehend before you simplify
25
+ - The code is performance-critical and the "simpler" version would be measurably slower
26
+ - You're about to rewrite the module entirely - simplifying throwaway code wastes effort
27
+
28
+ ## The Five Principles
29
+
30
+ ### 1. Preserve Behavior Exactly
31
+
32
+ Don't change what the code does - only how it expresses it. All inputs, outputs, side effects, error behavior, and edge cases must remain identical. If you're not sure a simplification preserves behavior, don't make it.
33
+
34
+ Before every change, ask:
35
+
36
+ - Does this produce the same output for every input?
37
+ - Does this maintain the same error behavior?
38
+ - Does this preserve the same side effects and ordering?
39
+ - Do all existing tests still pass without modification?
40
+
41
+ ### 2. Follow Project Conventions
42
+
43
+ Simplification means making code more consistent with the codebase, not imposing external preferences.
44
+
45
+ Before simplifying:
46
+
47
+ 1. Read `AGENTS.md` / project conventions
48
+ 2. Study how neighboring code handles similar patterns
49
+ 3. Match the project's style for imports, naming, function style, error handling, and type annotations
50
+
51
+ Simplification that breaks project consistency is not simplification - it's churn.
52
+
53
+ ### 3. Prefer Clarity Over Cleverness
54
+
55
+ Explicit code is better than compact code when the compact version requires a mental pause to parse.
56
+
57
+ - Replace nested ternaries with readable control flow
58
+ - Replace dense inline transforms with named intermediate steps when they clarify intent
59
+ - Keep helpful names even if they cost a few extra lines
60
+
61
+ ### 4. Maintain Balance
62
+
63
+ Watch for over-simplification:
64
+
65
+ - Don't inline away names that carry meaning
66
+ - Don't merge unrelated logic into one larger function
67
+ - Don't remove abstractions that serve testability or extensibility
68
+ - Don't optimize for line count over comprehension
69
+
70
+ ### 5. Scope to What Changed
71
+
72
+ Default to simplifying recently modified code. Avoid unrelated drive-by refactors unless explicitly asked.
73
+
74
+ ## Process
75
+
76
+ ### Step 1: Understand Before Touching
77
+
78
+ Before changing or removing anything, understand why it exists.
79
+
80
+ Answer:
81
+
82
+ - What is this code's responsibility?
83
+ - What calls it? What does it call?
84
+ - What are the edge cases and error paths?
85
+ - Are there tests that define expected behavior?
86
+ - Why might it have been written this way?
87
+
88
+ If you can't answer these, read more context first.
89
+
90
+ ### Step 2: Look for Simplification Opportunities
91
+
92
+ Signals:
93
+
94
+ - Deep nesting
95
+ - Long functions with mixed responsibilities
96
+ - Nested ternaries
97
+ - Boolean flag arguments
98
+ - Repeated conditionals
99
+ - Generic or misleading names
100
+ - Duplicated logic
101
+ - Dead code
102
+ - Wrappers or abstractions that add no value
103
+
104
+ ### Step 3: Apply Changes Incrementally
105
+
106
+ Make one simplification at a time.
107
+
108
+ For each simplification:
109
+
110
+ 1. Make the change
111
+ 2. Run relevant tests
112
+ 3. Keep it only if behavior is preserved
113
+
114
+ Separate refactoring from feature work whenever possible.
115
+
116
+ ### Step 4: Verify the Result
117
+
118
+ After simplifying, confirm:
119
+
120
+ - The code is genuinely easier to understand
121
+ - The diff is clean and reviewable
122
+ - Project conventions still match
123
+ - No behavior, error handling, or side effects changed
124
+
125
+ ## Guidance for This Repository
126
+
127
+ - Prefer straightforward TypeScript over clever compression
128
+ - Preserve existing runtime behavior, tests, and hooks
129
+ - Favor explicit names and smaller focused helpers when they improve readability
130
+ - Keep refactors tightly scoped to the task or review feedback
131
+
132
+ ## Verification Checklist
133
+
134
+ - [ ] Existing tests pass without modification
135
+ - [ ] Build/typecheck/lint still pass
136
+ - [ ] No unrelated files were refactored
137
+ - [ ] No error handling was weakened or removed
138
+ - [ ] The result is simpler to review than the original
@@ -0,0 +1,236 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
2
+ import * as fs from 'node:fs';
3
+ import * as os from 'node:os';
4
+ import * as path from 'node:path';
5
+ import {
6
+ getAccount,
7
+ getAccountsByProvider,
8
+ loadAccounts,
9
+ loadAccountsResult,
10
+ removeAccount,
11
+ saveAccount,
12
+ setAccountKey,
13
+ } from './accounts-store';
14
+
15
+ let previousXdgDataHome: string | undefined;
16
+ let tempDir: string;
17
+
18
+ beforeEach(() => {
19
+ previousXdgDataHome = process.env.XDG_DATA_HOME;
20
+ tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'omos-subscriptions-store-'));
21
+ process.env.XDG_DATA_HOME = tempDir;
22
+ });
23
+
24
+ afterEach(() => {
25
+ if (previousXdgDataHome === undefined) {
26
+ delete process.env.XDG_DATA_HOME;
27
+ } else {
28
+ process.env.XDG_DATA_HOME = previousXdgDataHome;
29
+ }
30
+ fs.rmSync(tempDir, { recursive: true, force: true });
31
+ });
32
+
33
+ describe('accounts-store (subscriptions)', () => {
34
+ test('saveAccount and loadAccounts for opencode-go', () => {
35
+ saveAccount({
36
+ provider: 'opencode-go',
37
+ name: 'personal',
38
+ workspaceId: 'wrk_123',
39
+ authCookie: 'cookie-abc',
40
+ });
41
+
42
+ const accounts = loadAccounts();
43
+ expect(accounts).toHaveLength(1);
44
+ const acct = accounts[0];
45
+ expect(acct.provider).toBe('opencode-go');
46
+ expect(acct.name).toBe('personal');
47
+ if (acct.provider === 'opencode-go') {
48
+ expect(acct.workspaceId).toBe('wrk_123');
49
+ expect(acct.authCookie).toBe('cookie-abc');
50
+ }
51
+ });
52
+
53
+ test('saveAccount and loadAccounts for neuralwatt', () => {
54
+ saveAccount({
55
+ provider: 'neuralwatt',
56
+ name: 'my-neuralwatt',
57
+ apiKey: 'sk-test-key',
58
+ });
59
+
60
+ const accounts = loadAccounts();
61
+ expect(accounts).toHaveLength(1);
62
+ expect(accounts[0].provider).toBe('neuralwatt');
63
+ expect(accounts[0].name).toBe('my-neuralwatt');
64
+ expect(accounts[0].apiKey).toBe('sk-test-key');
65
+ });
66
+
67
+ test('saveAccount overwrites existing account by name', () => {
68
+ saveAccount({
69
+ provider: 'opencode-go',
70
+ name: 'personal',
71
+ workspaceId: 'wrk_123',
72
+ authCookie: 'cookie-old',
73
+ });
74
+ saveAccount({
75
+ provider: 'opencode-go',
76
+ name: 'personal',
77
+ workspaceId: 'wrk_456',
78
+ authCookie: 'cookie-new',
79
+ });
80
+
81
+ const accounts = loadAccounts();
82
+ expect(accounts).toHaveLength(1);
83
+ const acct = accounts[0];
84
+ if (acct.provider === 'opencode-go') {
85
+ expect(acct.workspaceId).toBe('wrk_456');
86
+ expect(acct.authCookie).toBe('cookie-new');
87
+ }
88
+ });
89
+
90
+ test('saveAccount can change provider type for same name', () => {
91
+ saveAccount({
92
+ provider: 'opencode-go',
93
+ name: 'personal',
94
+ workspaceId: 'wrk_123',
95
+ authCookie: 'cookie-abc',
96
+ });
97
+ saveAccount({
98
+ provider: 'neuralwatt',
99
+ name: 'personal',
100
+ apiKey: 'sk-new-key',
101
+ });
102
+
103
+ const accounts = loadAccounts();
104
+ expect(accounts).toHaveLength(1);
105
+ expect(accounts[0].provider).toBe('neuralwatt');
106
+ });
107
+
108
+ test('removeAccount removes by name', () => {
109
+ saveAccount({
110
+ provider: 'opencode-go',
111
+ name: 'personal',
112
+ workspaceId: 'wrk_123',
113
+ authCookie: 'cookie-abc',
114
+ });
115
+ const removed = removeAccount('personal');
116
+ expect(removed).toBe(true);
117
+ expect(loadAccounts()).toHaveLength(0);
118
+ });
119
+
120
+ test('removeAccount returns false for unknown name', () => {
121
+ const removed = removeAccount('nonexistent');
122
+ expect(removed).toBe(false);
123
+ });
124
+
125
+ test('getAccount finds by name', () => {
126
+ saveAccount({
127
+ provider: 'opencode-go',
128
+ name: 'personal',
129
+ workspaceId: 'wrk_123',
130
+ authCookie: 'cookie-abc',
131
+ });
132
+ const account = getAccount('personal');
133
+ expect(account).toBeDefined();
134
+ expect(account?.provider).toBe('opencode-go');
135
+ });
136
+
137
+ test('getAccount returns undefined for unknown name', () => {
138
+ const account = getAccount('nonexistent');
139
+ expect(account).toBeUndefined();
140
+ });
141
+
142
+ test('setAccountKey sets provider and apiKey', () => {
143
+ saveAccount({
144
+ provider: 'opencode-go',
145
+ name: 'personal',
146
+ workspaceId: 'wrk_123',
147
+ authCookie: 'cookie-abc',
148
+ });
149
+ const updated = setAccountKey('personal', 'opencode-go', 'sk-test-key');
150
+ expect(updated).toBe(true);
151
+
152
+ const account = getAccount('personal');
153
+ expect(account?.provider).toBe('opencode-go');
154
+ expect(account?.apiKey).toBe('sk-test-key');
155
+ });
156
+
157
+ test('setAccountKey returns false for unknown name', () => {
158
+ const updated = setAccountKey('nonexistent', 'opencode-go', 'sk-test-key');
159
+ expect(updated).toBe(false);
160
+ });
161
+
162
+ test('getAccountsByProvider filters by provider', () => {
163
+ saveAccount({
164
+ provider: 'opencode-go',
165
+ name: 'personal',
166
+ workspaceId: 'wrk_123',
167
+ authCookie: 'cookie-abc',
168
+ });
169
+ saveAccount({
170
+ provider: 'neuralwatt',
171
+ name: 'my-neuralwatt',
172
+ apiKey: 'sk-test-key',
173
+ });
174
+ saveAccount({
175
+ provider: 'opencode-go',
176
+ name: 'work',
177
+ workspaceId: 'wrk_456',
178
+ authCookie: 'cookie-def',
179
+ });
180
+
181
+ const goAccounts = getAccountsByProvider('opencode-go');
182
+ expect(goAccounts).toHaveLength(2);
183
+ expect(goAccounts.every((a) => a.provider === 'opencode-go')).toBe(true);
184
+
185
+ const nwAccounts = getAccountsByProvider('neuralwatt');
186
+ expect(nwAccounts).toHaveLength(1);
187
+ expect(nwAccounts[0].name).toBe('my-neuralwatt');
188
+ });
189
+
190
+ test('loadAccountsResult reports parse failures', () => {
191
+ const storageDir = path.join(
192
+ tempDir,
193
+ 'opencode',
194
+ 'storage',
195
+ 'opencode-dux',
196
+ );
197
+ fs.mkdirSync(storageDir, { recursive: true });
198
+ const subscriptionsPath = path.join(storageDir, 'subscriptions.json');
199
+ fs.writeFileSync(subscriptionsPath, '{ malformed json');
200
+
201
+ const result = loadAccountsResult();
202
+ expect(result.ok).toBe(false);
203
+ expect(result.accounts).toEqual([]);
204
+ });
205
+
206
+ test('loadAccountsResult accepts current version schema', () => {
207
+ const storageDir = path.join(
208
+ tempDir,
209
+ 'opencode',
210
+ 'storage',
211
+ 'opencode-dux',
212
+ );
213
+ fs.mkdirSync(storageDir, { recursive: true });
214
+
215
+ const newPath = path.join(storageDir, 'subscriptions.json');
216
+ fs.writeFileSync(
217
+ newPath,
218
+ JSON.stringify({
219
+ version: 2,
220
+ accounts: [
221
+ {
222
+ provider: 'neuralwatt',
223
+ name: 'new-account',
224
+ apiKey: 'sk-new',
225
+ },
226
+ ],
227
+ }),
228
+ );
229
+
230
+ const result = loadAccountsResult();
231
+ expect(result.ok).toBe(true);
232
+ expect(result.accounts).toHaveLength(1);
233
+ expect(result.accounts[0].name).toBe('new-account');
234
+ expect(result.accounts[0].provider).toBe('neuralwatt');
235
+ });
236
+ });