@kunlv/atdc 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 (222) hide show
  1. package/AGENTS.md +58 -0
  2. package/GO.md +245 -0
  3. package/bin/add-command.py +144 -0
  4. package/bin/atdc.js +460 -0
  5. package/bin/cls.js +98 -0
  6. package/central/link.sh +60 -0
  7. package/central/ticket_center_server/.handoffs/TASK-238389_QYinVipLimit.md +128 -0
  8. package/central/ticket_center_server/.test_plans/TASK-227254-SupportMembership-self-test-plan.md +566 -0
  9. package/central/ticket_center_server/.test_plans/task-238389-qyin-vip-limit-self-test-plan.md +210 -0
  10. package/commands/claude/atd.md +3 -0
  11. package/commands/claude/atdc/1-spec.md +5 -0
  12. package/commands/claude/atdc/1-update.md +5 -0
  13. package/commands/claude/atdc/2-qa.md +3 -0
  14. package/commands/claude/atdc/3-impl-skip-spec.md +5 -0
  15. package/commands/claude/atdc/3-impl.md +3 -0
  16. package/commands/claude/atdc/4-verify.md +3 -0
  17. package/commands/claude/atdc/5-done.md +3 -0
  18. package/commands/claude/atdc/add-command.md +4 -0
  19. package/commands/claude/atdc/add-to-hc.md +3 -0
  20. package/commands/claude/atdc/analysis-cls-log.md +4 -0
  21. package/commands/claude/atdc/article.md +6 -0
  22. package/commands/claude/atdc/bugfix.md +4 -0
  23. package/commands/claude/atdc/code-simplifier.md +8 -0
  24. package/commands/claude/atdc/commit.md +4 -0
  25. package/commands/claude/atdc/compound.md +5 -0
  26. package/commands/claude/atdc/context.md +3 -0
  27. package/commands/claude/atdc/diagnose.md +8 -0
  28. package/commands/claude/atdc/git-guardrails.md +18 -0
  29. package/commands/claude/atdc/grill-with-docs.md +8 -0
  30. package/commands/claude/atdc/handoff.md +8 -0
  31. package/commands/claude/atdc/health.md +3 -0
  32. package/commands/claude/atdc/learn.md +4 -0
  33. package/commands/claude/atdc/review.md +10 -0
  34. package/commands/claude/atdc/search.md +4 -0
  35. package/commands/claude/atdc/strategy.md +3 -0
  36. package/commands/claude/atdc/table2xlsx.md +4 -0
  37. package/commands/claude/atdc/test-plan.md +5 -0
  38. package/commands/claude/atdc/travel-planner.md +4 -0
  39. package/commands/claude/atdc/xlsx2sql-insert.md +4 -0
  40. package/commands/claude/atdc/xlsx2sql-update.md +4 -0
  41. package/commands/claude/atdc/zoom-out.md +8 -0
  42. package/commands/codex/atdc/SKILL.md +8 -0
  43. package/commands/codex/atdc-1-spec/SKILL.md +8 -0
  44. package/commands/codex/atdc-1-update/SKILL.md +8 -0
  45. package/commands/codex/atdc-2-qa/SKILL.md +8 -0
  46. package/commands/codex/atdc-3-impl/SKILL.md +8 -0
  47. package/commands/codex/atdc-3-impl-skip-spec/SKILL.md +8 -0
  48. package/commands/codex/atdc-4-verify/SKILL.md +8 -0
  49. package/commands/codex/atdc-5-done/SKILL.md +8 -0
  50. package/commands/codex/atdc-add-command/SKILL.md +7 -0
  51. package/commands/codex/atdc-add-to-hc/SKILL.md +8 -0
  52. package/commands/codex/atdc-analysis-cls-log/SKILL.md +5 -0
  53. package/commands/codex/atdc-article/SKILL.md +8 -0
  54. package/commands/codex/atdc-bugfix/SKILL.md +5 -0
  55. package/commands/codex/atdc-code-simplifier/SKILL.md +7 -0
  56. package/commands/codex/atdc-commit/SKILL.md +7 -0
  57. package/commands/codex/atdc-compound/SKILL.md +8 -0
  58. package/commands/codex/atdc-context/SKILL.md +8 -0
  59. package/commands/codex/atdc-diagnose/SKILL.md +9 -0
  60. package/commands/codex/atdc-git-guardrails/SKILL.md +19 -0
  61. package/commands/codex/atdc-grill-with-docs/SKILL.md +9 -0
  62. package/commands/codex/atdc-handoff/SKILL.md +9 -0
  63. package/commands/codex/atdc-health/SKILL.md +8 -0
  64. package/commands/codex/atdc-learn/SKILL.md +7 -0
  65. package/commands/codex/atdc-review/SKILL.md +49 -0
  66. package/commands/codex/atdc-search/SKILL.md +5 -0
  67. package/commands/codex/atdc-strategy/SKILL.md +8 -0
  68. package/commands/codex/atdc-table2xlsx/SKILL.md +8 -0
  69. package/commands/codex/atdc-test-plan/SKILL.md +13 -0
  70. package/commands/codex/atdc-travel-planner/SKILL.md +7 -0
  71. package/commands/codex/atdc-xlsx2sql-insert/SKILL.md +8 -0
  72. package/commands/codex/atdc-xlsx2sql-update/SKILL.md +8 -0
  73. package/commands/codex/atdc-zoom-out/SKILL.md +9 -0
  74. package/commands/cursor/atdc/SKILL.md +8 -0
  75. package/commands/cursor/atdc-1-spec/SKILL.md +8 -0
  76. package/commands/cursor/atdc-1-update/SKILL.md +8 -0
  77. package/commands/cursor/atdc-2-qa/SKILL.md +8 -0
  78. package/commands/cursor/atdc-3-impl/SKILL.md +8 -0
  79. package/commands/cursor/atdc-3-impl-skip-spec/SKILL.md +8 -0
  80. package/commands/cursor/atdc-4-verify/SKILL.md +8 -0
  81. package/commands/cursor/atdc-5-done/SKILL.md +8 -0
  82. package/commands/cursor/atdc-add-command/SKILL.md +7 -0
  83. package/commands/cursor/atdc-add-to-hc/SKILL.md +8 -0
  84. package/commands/cursor/atdc-analysis-cls-log/SKILL.md +5 -0
  85. package/commands/cursor/atdc-article/SKILL.md +8 -0
  86. package/commands/cursor/atdc-bugfix/SKILL.md +5 -0
  87. package/commands/cursor/atdc-code-simplifier/SKILL.md +7 -0
  88. package/commands/cursor/atdc-commit/SKILL.md +7 -0
  89. package/commands/cursor/atdc-compound/SKILL.md +8 -0
  90. package/commands/cursor/atdc-context/SKILL.md +8 -0
  91. package/commands/cursor/atdc-diagnose/SKILL.md +8 -0
  92. package/commands/cursor/atdc-git-guardrails/SKILL.md +18 -0
  93. package/commands/cursor/atdc-grill-with-docs/SKILL.md +8 -0
  94. package/commands/cursor/atdc-handoff/SKILL.md +8 -0
  95. package/commands/cursor/atdc-health/SKILL.md +8 -0
  96. package/commands/cursor/atdc-learn/SKILL.md +7 -0
  97. package/commands/cursor/atdc-review/SKILL.md +49 -0
  98. package/commands/cursor/atdc-search/SKILL.md +5 -0
  99. package/commands/cursor/atdc-strategy/SKILL.md +8 -0
  100. package/commands/cursor/atdc-table2xlsx/SKILL.md +8 -0
  101. package/commands/cursor/atdc-test-plan/SKILL.md +7 -0
  102. package/commands/cursor/atdc-travel-planner/SKILL.md +7 -0
  103. package/commands/cursor/atdc-xlsx2sql-insert/SKILL.md +8 -0
  104. package/commands/cursor/atdc-xlsx2sql-update/SKILL.md +8 -0
  105. package/commands/cursor/atdc-zoom-out/SKILL.md +8 -0
  106. package/commands/opencode/atd.md +6 -0
  107. package/commands/opencode/atdc/1-spec.md +8 -0
  108. package/commands/opencode/atdc/1-update.md +8 -0
  109. package/commands/opencode/atdc/2-qa.md +6 -0
  110. package/commands/opencode/atdc/3-impl-skip-spec.md +8 -0
  111. package/commands/opencode/atdc/3-impl.md +6 -0
  112. package/commands/opencode/atdc/4-verify.md +6 -0
  113. package/commands/opencode/atdc/5-done.md +6 -0
  114. package/commands/opencode/atdc/add-command.md +6 -0
  115. package/commands/opencode/atdc/add-to-hc.md +6 -0
  116. package/commands/opencode/atdc/analysis-cls-log.md +6 -0
  117. package/commands/opencode/atdc/article.md +6 -0
  118. package/commands/opencode/atdc/bugfix.md +6 -0
  119. package/commands/opencode/atdc/code-simplifier.md +8 -0
  120. package/commands/opencode/atdc/commit.md +6 -0
  121. package/commands/opencode/atdc/compound.md +8 -0
  122. package/commands/opencode/atdc/context.md +6 -0
  123. package/commands/opencode/atdc/diagnose.md +8 -0
  124. package/commands/opencode/atdc/git-guardrails.md +18 -0
  125. package/commands/opencode/atdc/grill-with-docs.md +8 -0
  126. package/commands/opencode/atdc/handoff.md +8 -0
  127. package/commands/opencode/atdc/health.md +6 -0
  128. package/commands/opencode/atdc/learn.md +6 -0
  129. package/commands/opencode/atdc/review.md +7 -0
  130. package/commands/opencode/atdc/search.md +6 -0
  131. package/commands/opencode/atdc/strategy.md +6 -0
  132. package/commands/opencode/atdc/table2xlsx.md +6 -0
  133. package/commands/opencode/atdc/test-plan.md +6 -0
  134. package/commands/opencode/atdc/travel-planner.md +6 -0
  135. package/commands/opencode/atdc/xlsx2sql-insert.md +6 -0
  136. package/commands/opencode/atdc/xlsx2sql-update.md +6 -0
  137. package/commands/opencode/atdc/zoom-out.md +8 -0
  138. package/config/cls-defaults.json +19 -0
  139. package/hooks/atd-archive.sh +86 -0
  140. package/hooks/atd-state.sh +165 -0
  141. package/hooks/evidence-hook.sh +88 -0
  142. package/hooks/evidence-log.sh +54 -0
  143. package/hooks/guardrails.sh +65 -0
  144. package/hooks/handoff-compress.sh +104 -0
  145. package/hooks/phase-guard.sh +134 -0
  146. package/hooks/phase-write-guard.sh +96 -0
  147. package/hooks/ponytail-fix.sh +179 -0
  148. package/hooks/ponytail-guard.sh +66 -0
  149. package/hooks/ponytail-scan.sh +62 -0
  150. package/install.sh +276 -0
  151. package/package.json +20 -0
  152. package/packages/cls/bin/cls.js +146 -0
  153. package/packages/cls/config/defaults.json +17 -0
  154. package/packages/cls/mcp/server.js +142 -0
  155. package/packages/cls/package.json +29 -0
  156. package/packages/cls/scripts/postinstall.js +19 -0
  157. package/packages/cls/src/client.js +262 -0
  158. package/prompts/1-spec.md +271 -0
  159. package/prompts/1-update.md +198 -0
  160. package/prompts/2-qa.md +164 -0
  161. package/prompts/3-impl-bugfix.md +271 -0
  162. package/prompts/3-impl.md +419 -0
  163. package/prompts/4-verify.md +160 -0
  164. package/prompts/5-done.md +227 -0
  165. package/prompts/6-article.md +571 -0
  166. package/prompts/X-add-command.md +60 -0
  167. package/prompts/X-add-to-hc.md +178 -0
  168. package/prompts/X-analysis-cls-log.md +68 -0
  169. package/prompts/X-bugfix.md +10 -0
  170. package/prompts/X-code-simplifier.md +38 -0
  171. package/prompts/X-commit.md +116 -0
  172. package/prompts/X-compound.md +188 -0
  173. package/prompts/X-context-scan.md +101 -0
  174. package/prompts/X-diagnose.md +116 -0
  175. package/prompts/X-grill-with-docs.md +120 -0
  176. package/prompts/X-handoff.md +80 -0
  177. package/prompts/X-health.md +78 -0
  178. package/prompts/X-learn.md +151 -0
  179. package/prompts/X-review.md +417 -0
  180. package/prompts/X-search.md +74 -0
  181. package/prompts/X-strategy.md +95 -0
  182. package/prompts/X-table2xlsx.md +46 -0
  183. package/prompts/X-test-plan.md +436 -0
  184. package/prompts/X-travel-planner.md +22 -0
  185. package/prompts/X-xlsx2sql-insert.md +34 -0
  186. package/prompts/X-xlsx2sql-update.md +40 -0
  187. package/prompts/X-zoom-out.md +119 -0
  188. package/reference/diagnose-loop.md +66 -0
  189. package/reference/gates.md +90 -0
  190. package/reference/git-guardrails.md +71 -0
  191. package/reference/guards.md +275 -0
  192. package/reference/learn.md +100 -0
  193. package/reference/memory.md +190 -0
  194. package/reference/risk.md +74 -0
  195. package/reference/tdd.md +40 -0
  196. package/scripts/svg2png.js +46 -0
  197. package/src/cls/client.js +244 -0
  198. package/src/constants.js +49 -0
  199. package/src/evidence/ai-draft-metrics.js +157 -0
  200. package/src/evidence/canvas.js +184 -0
  201. package/src/evidence/index.js +98 -0
  202. package/src/evidence/sink-events.js +165 -0
  203. package/src/evidence/stage-timing.js +112 -0
  204. package/src/installers/claude.js +79 -0
  205. package/src/installers/codex.js +62 -0
  206. package/src/installers/opencode.js +72 -0
  207. package/src/manifest/ponytail-patterns.json +185 -0
  208. package/src/mcp/cls-mcp-server.js +142 -0
  209. package/src/utils.js +79 -0
  210. package/src/validators/state-validate.js +123 -0
  211. package/templates/.phase-state.json +13 -0
  212. package/templates/adr.md +62 -0
  213. package/templates/changelog.md +21 -0
  214. package/templates/concepts.md +35 -0
  215. package/templates/design.md +47 -0
  216. package/templates/handoff.md +64 -0
  217. package/templates/learn-skill.md +43 -0
  218. package/templates/progress.json +17 -0
  219. package/templates/proposal.md +29 -0
  220. package/templates/solution.md +36 -0
  221. package/templates/strategy.md +39 -0
  222. package/templates/tasks.md +41 -0
@@ -0,0 +1,112 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+
4
+ function resolveTimingDir(changeDir) {
5
+ const dir = path.join(changeDir, '.evidence', 'timing');
6
+ fs.mkdirSync(dir, { recursive: true });
7
+ return dir;
8
+ }
9
+
10
+ function timingFile(changeDir) {
11
+ return path.join(resolveTimingDir(changeDir), 'stage-timings.json');
12
+ }
13
+
14
+ function loadTimings(changeDir) {
15
+ const fp = timingFile(changeDir);
16
+ if (!fs.existsSync(fp)) return { stages: {}, startedAt: null, completedAt: null };
17
+ return JSON.parse(fs.readFileSync(fp, 'utf8'));
18
+ }
19
+
20
+ function saveTimings(changeDir, data) {
21
+ fs.writeFileSync(timingFile(changeDir), JSON.stringify(data, null, 2) + '\n');
22
+ }
23
+
24
+ function stageStart(changeDir, stage, metadata = {}) {
25
+ const timings = loadTimings(changeDir);
26
+ const now = new Date().toISOString();
27
+
28
+ if (!timings.startedAt) {
29
+ timings.startedAt = now;
30
+ }
31
+
32
+ if (!timings.stages[stage]) {
33
+ timings.stages[stage] = { startedAt: null, completedAt: null, durationMs: null, metadata: {} };
34
+ }
35
+
36
+ timings.stages[stage].startedAt = now;
37
+ timings.stages[stage].metadata = { ...timings.stages[stage].metadata, ...metadata };
38
+ saveTimings(changeDir, timings);
39
+ return timings;
40
+ }
41
+
42
+ function stageComplete(changeDir, stage, metadata = {}) {
43
+ const timings = loadTimings(changeDir);
44
+ const now = new Date().toISOString();
45
+
46
+ if (!timings.stages[stage]) {
47
+ timings.stages[stage] = { startedAt: now, completedAt: null, durationMs: null, metadata: {} };
48
+ }
49
+
50
+ const s = timings.stages[stage];
51
+ s.completedAt = now;
52
+ if (s.startedAt) {
53
+ s.durationMs = new Date(now) - new Date(s.startedAt);
54
+ }
55
+ s.metadata = { ...s.metadata, ...metadata };
56
+ saveTimings(changeDir, timings);
57
+ return timings;
58
+ }
59
+
60
+ function getStageDuration(changeDir, stage) {
61
+ const timings = loadTimings(changeDir);
62
+ const s = timings.stages[stage];
63
+ if (!s || !s.durationMs) return null;
64
+ return s.durationMs;
65
+ }
66
+
67
+ function formatDuration(ms) {
68
+ if (ms === null || ms === undefined) return 'N/A';
69
+ if (ms < 1000) return `${ms}ms`;
70
+ if (ms < 60000) return `${(ms / 1000).toFixed(1)}s`;
71
+ const mins = Math.floor(ms / 60000);
72
+ const secs = Math.round((ms % 60000) / 1000);
73
+ return `${mins}m ${secs}s`;
74
+ }
75
+
76
+ function totalElapsed(changeDir) {
77
+ const timings = loadTimings(changeDir);
78
+ if (!timings.startedAt) return null;
79
+ const start = new Date(timings.startedAt);
80
+ const end = timings.completedAt ? new Date(timings.completedAt) : new Date();
81
+ return end - start;
82
+ }
83
+
84
+ function stageReport(changeDir) {
85
+ const timings = loadTimings(changeDir);
86
+ const stages = Object.entries(timings.stages).map(([name, data]) => ({
87
+ stage: name,
88
+ startedAt: data.startedAt,
89
+ completedAt: data.completedAt,
90
+ durationMs: data.durationMs,
91
+ duration: formatDuration(data.durationMs),
92
+ metadata: data.metadata,
93
+ }));
94
+
95
+ return {
96
+ startedAt: timings.startedAt,
97
+ completedAt: timings.completedAt,
98
+ totalElapsedMs: totalElapsed(changeDir),
99
+ totalElapsed: formatDuration(totalElapsed(changeDir)),
100
+ stages,
101
+ };
102
+ }
103
+
104
+ module.exports = {
105
+ stageStart,
106
+ stageComplete,
107
+ getStageDuration,
108
+ formatDuration,
109
+ totalElapsed,
110
+ stageReport,
111
+ loadTimings,
112
+ };
@@ -0,0 +1,79 @@
1
+ const path = require('path');
2
+ const { TERMINAL_CONFIGS } = require('../constants');
3
+ const {
4
+ exists, isSymlink, getSymlinkTarget, mkdirp,
5
+ createSymlink, removeSymlink,
6
+ replaceAllInDir, resolvePackageDir, isTerminalInstalled,
7
+ } = require('../utils');
8
+
9
+ const cfg = TERMINAL_CONFIGS.claude;
10
+
11
+ function status() {
12
+ const installed = isTerminalInstalled(cfg.installedCheck());
13
+ if (!installed) return { installed: false, reason: `${cfg.name} not detected` };
14
+
15
+ const pkgDir = resolvePackageDir();
16
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
17
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
18
+
19
+ const atdMdOk = isSymlink(atdMd) && getSymlinkTarget(atdMd) === path.join(pkgDir, cfg.fileLink.src);
20
+ const atdDirOk = isSymlink(atdDir) && getSymlinkTarget(atdDir) === path.join(pkgDir, cfg.dirLink.src);
21
+
22
+ return {
23
+ installed: true,
24
+ name: cfg.name,
25
+ details: {
26
+ [cfg.fileLink.dest]: atdMdOk ? 'ok' : (exists(atdMd) ? 'conflict' : 'missing'),
27
+ [cfg.dirLink.dest]: atdDirOk ? 'ok' : (exists(atdDir) ? 'conflict' : 'missing'),
28
+ },
29
+ };
30
+ }
31
+
32
+ function install() {
33
+ const installed = isTerminalInstalled(cfg.installedCheck());
34
+ if (!installed) return { ok: false, error: `${cfg.name} not detected, skipped` };
35
+
36
+ const pkgDir = resolvePackageDir();
37
+ mkdirp(cfg.dir);
38
+
39
+ replaceAllInDir(path.join(pkgDir, 'commands'), '{{ATDC_DIR}}', pkgDir);
40
+
41
+ const results = [];
42
+
43
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
44
+ createSymlink(path.join(pkgDir, cfg.fileLink.src), atdMd);
45
+ results.push(` ${cfg.fileLink.dest}`);
46
+
47
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
48
+ createSymlink(path.join(pkgDir, cfg.dirLink.src), atdDir);
49
+ results.push(` ${cfg.dirLink.dest}/`);
50
+
51
+ return { ok: true, results };
52
+ }
53
+
54
+ function uninstall() {
55
+ const installed = isTerminalInstalled(cfg.installedCheck());
56
+ const pkgDir = resolvePackageDir();
57
+
58
+ const results = [];
59
+
60
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
61
+ if (isSymlink(atdMd) && getSymlinkTarget(atdMd) === path.join(pkgDir, cfg.fileLink.src)) {
62
+ removeSymlink(atdMd);
63
+ results.push(` removed: ${cfg.fileLink.dest}`);
64
+ }
65
+
66
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
67
+ if (isSymlink(atdDir) && getSymlinkTarget(atdDir) === path.join(pkgDir, cfg.dirLink.src)) {
68
+ removeSymlink(atdDir);
69
+ results.push(` removed: ${cfg.dirLink.dest}/`);
70
+ }
71
+
72
+ if (installed) {
73
+ replaceAllInDir(path.join(pkgDir, 'commands'), pkgDir, '{{ATDC_DIR}}');
74
+ }
75
+
76
+ return { ok: true, results: results.length ? results : [' nothing to remove'] };
77
+ }
78
+
79
+ module.exports = { status, install, uninstall };
@@ -0,0 +1,62 @@
1
+ const path = require('path');
2
+ const { TERMINAL_CONFIGS } = require('../constants');
3
+ const {
4
+ exists, isSymlink, getSymlinkTarget, mkdirp,
5
+ createSymlink, removeSymlink,
6
+ resolvePackageDir, isTerminalInstalled,
7
+ } = require('../utils');
8
+
9
+ const cfg = TERMINAL_CONFIGS.codex;
10
+
11
+ function status() {
12
+ const installed = isTerminalInstalled(cfg.installedCheck());
13
+ if (!installed) return { installed: false, reason: `${cfg.name} not detected` };
14
+
15
+ const pkgDir = resolvePackageDir();
16
+ const details = {};
17
+
18
+ for (const name of cfg.linkMap) {
19
+ const linkPath = path.join(cfg.dir, name);
20
+ const target = path.join(pkgDir, 'commands', 'codex', name);
21
+ const ok = isSymlink(linkPath) && getSymlinkTarget(linkPath) === target;
22
+ details[name] = ok ? 'ok' : (exists(linkPath) ? 'conflict' : 'missing');
23
+ }
24
+
25
+ return { installed: true, name: cfg.name, details };
26
+ }
27
+
28
+ function install() {
29
+ const installed = isTerminalInstalled(cfg.installedCheck());
30
+ if (!installed) return { ok: false, error: `${cfg.name} not detected, skipped` };
31
+
32
+ const pkgDir = resolvePackageDir();
33
+ mkdirp(cfg.dir);
34
+
35
+ const results = [];
36
+ for (const name of cfg.linkMap) {
37
+ const target = path.join(pkgDir, 'commands', 'codex', name);
38
+ const linkPath = path.join(cfg.dir, name);
39
+ createSymlink(target, linkPath);
40
+ results.push(` ${name}`);
41
+ }
42
+
43
+ return { ok: true, results };
44
+ }
45
+
46
+ function uninstall() {
47
+ const pkgDir = resolvePackageDir();
48
+
49
+ const results = [];
50
+ for (const name of cfg.linkMap) {
51
+ const linkPath = path.join(cfg.dir, name);
52
+ const target = path.join(pkgDir, 'commands', 'codex', name);
53
+ if (isSymlink(linkPath) && getSymlinkTarget(linkPath) === target) {
54
+ removeSymlink(linkPath);
55
+ results.push(` removed: ${name}`);
56
+ }
57
+ }
58
+
59
+ return { ok: true, results: results.length ? results : [' nothing to remove'] };
60
+ }
61
+
62
+ module.exports = { status, install, uninstall };
@@ -0,0 +1,72 @@
1
+ const path = require('path');
2
+ const { TERMINAL_CONFIGS } = require('../constants');
3
+ const {
4
+ exists, isSymlink, getSymlinkTarget, mkdirp,
5
+ createSymlink, removeSymlink,
6
+ resolvePackageDir, isTerminalInstalled,
7
+ } = require('../utils');
8
+
9
+ const cfg = TERMINAL_CONFIGS.opencode;
10
+
11
+ function status() {
12
+ const installed = isTerminalInstalled(cfg.installedCheck());
13
+ if (!installed) return { installed: false, reason: `${cfg.name} not detected` };
14
+
15
+ const pkgDir = resolvePackageDir();
16
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
17
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
18
+
19
+ const atdMdOk = isSymlink(atdMd) && getSymlinkTarget(atdMd) === path.join(pkgDir, cfg.fileLink.src);
20
+ const atdDirOk = isSymlink(atdDir) && getSymlinkTarget(atdDir) === path.join(pkgDir, cfg.dirLink.src);
21
+
22
+ return {
23
+ installed: true,
24
+ name: cfg.name,
25
+ details: {
26
+ [cfg.fileLink.dest]: atdMdOk ? 'ok' : (exists(atdMd) ? 'conflict' : 'missing'),
27
+ [cfg.dirLink.dest]: atdDirOk ? 'ok' : (exists(atdDir) ? 'conflict' : 'missing'),
28
+ },
29
+ };
30
+ }
31
+
32
+ function install() {
33
+ const installed = isTerminalInstalled(cfg.installedCheck());
34
+ if (!installed) return { ok: false, error: `${cfg.name} not detected, skipped` };
35
+
36
+ const pkgDir = resolvePackageDir();
37
+ mkdirp(cfg.dir);
38
+
39
+ const results = [];
40
+
41
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
42
+ createSymlink(path.join(pkgDir, cfg.fileLink.src), atdMd);
43
+ results.push(` ${cfg.fileLink.dest}`);
44
+
45
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
46
+ createSymlink(path.join(pkgDir, cfg.dirLink.src), atdDir);
47
+ results.push(` ${cfg.dirLink.dest}/`);
48
+
49
+ return { ok: true, results };
50
+ }
51
+
52
+ function uninstall() {
53
+ const pkgDir = resolvePackageDir();
54
+
55
+ const results = [];
56
+
57
+ const atdMd = path.join(cfg.dir, cfg.fileLink.dest);
58
+ if (isSymlink(atdMd) && getSymlinkTarget(atdMd) === path.join(pkgDir, cfg.fileLink.src)) {
59
+ removeSymlink(atdMd);
60
+ results.push(` removed: ${cfg.fileLink.dest}`);
61
+ }
62
+
63
+ const atdDir = path.join(cfg.dir, cfg.dirLink.dest);
64
+ if (isSymlink(atdDir) && getSymlinkTarget(atdDir) === path.join(pkgDir, cfg.dirLink.src)) {
65
+ removeSymlink(atdDir);
66
+ results.push(` removed: ${cfg.dirLink.dest}/`);
67
+ }
68
+
69
+ return { ok: true, results: results.length ? results : [' nothing to remove'] };
70
+ }
71
+
72
+ module.exports = { status, install, uninstall };
@@ -0,0 +1,185 @@
1
+ {
2
+ "version": "1.0",
3
+ "patterns": [
4
+ {
5
+ "id": "backend-crud-template",
6
+ "priority": "P0",
7
+ "name": "CRUD 模板重复",
8
+ "ladder": 6,
9
+ "category": "structural",
10
+ "detection": { "method": "grep", "pattern": "func.*Find.*ctx\\.Context", "target": "models/", "threshold": 10 },
11
+ "fix": "提取 BaseModel[T] 泛型基类",
12
+ "estimated_savings": "每 model ~40 行"
13
+ },
14
+ {
15
+ "id": "backend-rpc-template",
16
+ "priority": "P0",
17
+ "name": "RPC 调用模板",
18
+ "ladder": 6,
19
+ "category": "structural",
20
+ "detection": { "method": "grep", "pattern": "httpclient\\.Post|\\.Post(", "target": "service/rpc/", "threshold": 3 },
21
+ "fix": "提取 callLocalRPC[T] 泛型",
22
+ "estimated_savings": "每函数 ~28 行"
23
+ },
24
+ {
25
+ "id": "backend-di-boilerplate",
26
+ "priority": "P1",
27
+ "name": "Service Locator DI",
28
+ "ladder": 3,
29
+ "category": "structural",
30
+ "detection": { "method": "grep", "pattern": "func Register", "target": "service/biz/", "threshold": 5 },
31
+ "fix": "泛型 DI 容器或 google/wire",
32
+ "estimated_savings": "每 service ~12 行 + 1 文件"
33
+ },
34
+ {
35
+ "id": "backend-init-fragmentation",
36
+ "priority": "P1",
37
+ "name": "init() 碎片文件",
38
+ "ladder": 8,
39
+ "category": "file-fragmentation",
40
+ "detection": { "method": "find", "pattern": "*_init.go", "target": "service/biz/", "threshold": 5 },
41
+ "fix": "合并到统一 DI 容器 init()",
42
+ "estimated_savings": "每文件 3 行内容"
43
+ },
44
+ {
45
+ "id": "backend-error-framework",
46
+ "priority": "P1",
47
+ "name": "错误框架冗余",
48
+ "ladder": 2,
49
+ "category": "layer-removal",
50
+ "detection": { "method": "dir_check", "target": "internal/errors/gerror/", "threshold": 3 },
51
+ "fix": "Go 1.13+ fmt.Errorf(\"%w\") + errors.Is/As",
52
+ "estimated_savings": "~330 行 + 9 文件"
53
+ },
54
+ {
55
+ "id": "backend-whitelist-filter",
56
+ "priority": "P1",
57
+ "name": "白名单 filter 同构",
58
+ "ladder": 6,
59
+ "category": "duplicate-function",
60
+ "detection": { "method": "grep", "pattern": "BuildWhitelistExcludeSet", "target": "service/", "threshold": 2 },
61
+ "fix": "filterByWhitelist[T] 泛型",
62
+ "estimated_savings": "~70 行"
63
+ },
64
+ {
65
+ "id": "backend-custom-contains",
66
+ "priority": "P2",
67
+ "name": "自定义 Contains",
68
+ "ladder": 2,
69
+ "category": "stdlib-replacement",
70
+ "detection": { "method": "grep", "pattern": "func.*Contains\\[", "target": "utils/", "threshold": 0 },
71
+ "fix": "slices.Contains (Go 1.21+)",
72
+ "estimated_savings": "每函数 ~5 行"
73
+ },
74
+ {
75
+ "id": "backend-time-utils",
76
+ "priority": "P2",
77
+ "name": "Time 工具函数",
78
+ "ladder": 2,
79
+ "category": "stdlib-replacement",
80
+ "detection": { "method": "grep", "pattern": "TimeToString|GetLevelTimeFormat", "target": "utils/", "threshold": 0 },
81
+ "fix": "time.Format 直接使用",
82
+ "estimated_savings": "~20 行"
83
+ },
84
+ {
85
+ "id": "backend-phone-utils",
86
+ "priority": "P2",
87
+ "name": "Phone 工具包装",
88
+ "ladder": 3,
89
+ "category": "inline",
90
+ "detection": { "method": "grep", "pattern": "FormatPhoneNumber", "target": "utils/", "threshold": 0 },
91
+ "fix": "直调 nyaruka/phonenumbers",
92
+ "estimated_savings": "~48 行"
93
+ },
94
+ {
95
+ "id": "backend-config-type",
96
+ "priority": "P2",
97
+ "name": "Config type 冗余",
98
+ "ladder": 6,
99
+ "category": "type-consolidation",
100
+ "detection": { "method": "grep", "pattern": "type Apollo.*Config \\[", "target": "service/rtconf/", "threshold": 5 },
101
+ "fix": "合并通用 type",
102
+ "estimated_savings": "~30 行"
103
+ },
104
+ {
105
+ "id": "backend-bizerror",
106
+ "priority": "P2",
107
+ "name": "BizError 重复",
108
+ "ladder": 4,
109
+ "category": "middleware-extraction",
110
+ "detection": { "method": "grep", "pattern": "BizError", "target": "controller/", "threshold": 10 },
111
+ "fix": "提取 HTTP error middleware",
112
+ "estimated_savings": "每 handler ~3 行"
113
+ },
114
+ {
115
+ "id": "backend-gencurl",
116
+ "priority": "P2",
117
+ "name": "GenCURL",
118
+ "ladder": 2,
119
+ "category": "stdlib-replacement",
120
+ "detection": { "method": "grep", "pattern": "GenCURL", "target": "utils/", "threshold": 0 },
121
+ "fix": "HTTP 库内建 dump",
122
+ "estimated_savings": "~40 行"
123
+ },
124
+ {
125
+ "id": "backend-retry",
126
+ "priority": "P2",
127
+ "name": "Custom retry",
128
+ "ladder": 3,
129
+ "category": "dependency-replacement",
130
+ "detection": { "method": "grep", "pattern": "retry", "target": "utils/", "threshold": 0 },
131
+ "fix": "cenkalti/backoff",
132
+ "estimated_savings": "~30 行"
133
+ },
134
+ {
135
+ "id": "backend-convert",
136
+ "priority": "P2",
137
+ "name": "Convert 重复",
138
+ "ladder": 6,
139
+ "category": "duplicate-function",
140
+ "detection": { "method": "grep", "pattern": "func convert.*|func.*[Tt]oVO|func.*[Tt]oDTO", "target": "service/", "threshold": 3 },
141
+ "fix": "提取 mapper 或 copier",
142
+ "estimated_savings": "每函数 ~15 行"
143
+ },
144
+ {
145
+ "id": "backend-gorm-tags",
146
+ "priority": "P2",
147
+ "name": "GORM tags 样板",
148
+ "ladder": 8,
149
+ "category": "code-generation",
150
+ "detection": { "method": "manual", "target": "models/", "threshold": 10 },
151
+ "fix": "gorm/gen 或 sqlc 代码生成",
152
+ "estimated_savings": "~4500 行"
153
+ },
154
+ {
155
+ "id": "backend-large-interface",
156
+ "priority": "P2",
157
+ "name": "大 interface",
158
+ "ladder": 7,
159
+ "category": "design",
160
+ "detection": { "method": "manual", "target": "service/biz/*/", "threshold": 15 },
161
+ "fix": "拆分为小 interface",
162
+ "estimated_savings": "维护性提升"
163
+ },
164
+ {
165
+ "id": "backend-wxpay-duplicate",
166
+ "priority": "P2",
167
+ "name": "支付网关同构",
168
+ "ladder": 6,
169
+ "category": "duplicate-function",
170
+ "detection": { "method": "grep", "pattern": "Wx.*Pay", "target": "service/rpc/pay_service.go", "threshold": 1 },
171
+ "fix": "合并 WxH5Pay + WxPartnerH5Pay",
172
+ "estimated_savings": "~30 行"
173
+ },
174
+ {
175
+ "id": "backend-getserverip",
176
+ "priority": "P2",
177
+ "name": "getServerIP",
178
+ "ladder": 2,
179
+ "category": "stdlib-replacement",
180
+ "detection": { "method": "grep", "pattern": "getServerIP", "target": "utils/", "threshold": 0 },
181
+ "fix": "net.InterfaceAddrs 内联",
182
+ "estimated_savings": "~15 行"
183
+ }
184
+ ]
185
+ }
@@ -0,0 +1,142 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const readline = require('readline');
5
+ const client = require('../cls/client');
6
+
7
+ const TOOLS = [
8
+ {
9
+ name: 'cls_search',
10
+ description: '搜索 CLS 日志并落地到文件。返回输出文件路径、结果数量和样本日志。',
11
+ inputSchema: {
12
+ type: 'object',
13
+ properties: {
14
+ account: { type: 'string', description: '账号别名(如 tcs)' },
15
+ query: { type: 'string', description: 'CLS 查询语句' },
16
+ limit: { type: 'number', description: '返回条数(默认 200)' },
17
+ out_dir: { type: 'string', description: '输出目录(默认当前)' },
18
+ from: { type: 'string', description: '开始时间(默认 15m 前)' },
19
+ to: { type: 'string', description: '结束时间(默认 现在)' },
20
+ type: { type: 'string', description: 'topic 类型(默认 error)' },
21
+ regions: { type: 'string', description: '地域(默认 gz,bj)' },
22
+ },
23
+ required: ['account', 'query'],
24
+ },
25
+ },
26
+ {
27
+ name: 'cls_fetch',
28
+ description: '全量落地 CLS 日志到本地 jsonl 文件。',
29
+ inputSchema: {
30
+ type: 'object',
31
+ properties: {
32
+ account: { type: 'string', description: '账号别名' },
33
+ query: { type: 'string', description: 'CLS 查询语句' },
34
+ max: { type: 'number', description: '最大条数(默认 5000)' },
35
+ out_dir: { type: 'string', description: '输出目录' },
36
+ from: { type: 'string', description: '开始时间' },
37
+ to: { type: 'string', description: '结束时间' },
38
+ },
39
+ required: ['account', 'query'],
40
+ },
41
+ },
42
+ {
43
+ name: 'cls_histogram',
44
+ description: '查看 CLS 日志量时间分布(直方图)。',
45
+ inputSchema: {
46
+ type: 'object',
47
+ properties: {
48
+ account: { type: 'string', description: '账号别名' },
49
+ query: { type: 'string', description: 'CLS 查询语句' },
50
+ from: { type: 'string', description: '开始时间(必填)' },
51
+ to: { type: 'string', description: '结束时间(必填)' },
52
+ interval: { type: 'string', description: '时间桶间隔(默认 30m)' },
53
+ },
54
+ required: ['account', 'query', 'from', 'to'],
55
+ },
56
+ },
57
+ {
58
+ name: 'cls_context',
59
+ description: '拉取某条日志的前后上下文。',
60
+ inputSchema: {
61
+ type: 'object',
62
+ properties: {
63
+ account: { type: 'string', description: '账号别名' },
64
+ pkg_id: { type: 'string', description: '日志 PkgId' },
65
+ pkg_log_id: { type: 'number', description: '日志 PkgLogId' },
66
+ time: { type: 'string', description: '日志时间(毫秒时间戳)' },
67
+ prev: { type: 'number', description: '往前 N 条(默认 10)' },
68
+ next: { type: 'number', description: '往后 N 条(默认 10)' },
69
+ },
70
+ required: ['account', 'pkg_id', 'pkg_log_id', 'time'],
71
+ },
72
+ },
73
+ {
74
+ name: 'cls_list_accounts',
75
+ description: '列出可用账号别名及其映射。',
76
+ inputSchema: { type: 'object', properties: {} },
77
+ },
78
+ ];
79
+
80
+ function send(id, result) {
81
+ process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id, result }) + '\n');
82
+ }
83
+
84
+ function sendError(id, code, message) {
85
+ process.stdout.write(JSON.stringify({ jsonrpc: '2.0', id, error: { code, message } }) + '\n');
86
+ }
87
+
88
+ async function handleCall(id, name, args) {
89
+ try {
90
+ switch (name) {
91
+ case 'cls_search': {
92
+ const r = await client.searchAsync(args.account, args.query, { ...args, quiet: true });
93
+ send(id, { content: [{ type: 'text', text: JSON.stringify(r, null, 2) }] });
94
+ break;
95
+ }
96
+ case 'cls_fetch': {
97
+ const r = await client.fetchAsync(args.account, args.query, args);
98
+ send(id, { content: [{ type: 'text', text: JSON.stringify(r, null, 2) }] });
99
+ break;
100
+ }
101
+ case 'cls_histogram':
102
+ case 'cls_context': {
103
+ send(id, { content: [{ type: 'text', text: JSON.stringify({ note: `${name} 模式待实现,请直接用 CLI: cls ${args.account} "${args.query}" --histogram/--context` }) }] });
104
+ break;
105
+ }
106
+ case 'cls_list_accounts': {
107
+ const accounts = client.listAccounts();
108
+ send(id, { content: [{ type: 'text', text: JSON.stringify(accounts, null, 2) }] });
109
+ break;
110
+ }
111
+ default:
112
+ sendError(id, -32601, `Unknown tool: ${name}`);
113
+ }
114
+ } catch (e) {
115
+ sendError(id, -32000, e.message);
116
+ }
117
+ }
118
+
119
+ const rl = readline.createInterface({ input: process.stdin });
120
+ rl.on('line', line => {
121
+ try {
122
+ const msg = JSON.parse(line);
123
+ const { id, method, params } = msg;
124
+ if (method === 'initialize') {
125
+ send(id, {
126
+ protocolVersion: '2024-11-05',
127
+ capabilities: { tools: {} },
128
+ serverInfo: { name: 'cls-mcp-server', version: '1.0.0' },
129
+ });
130
+ } else if (method === 'tools/list') {
131
+ send(id, { tools: TOOLS });
132
+ } else if (method === 'tools/call') {
133
+ handleCall(id, params.name, params.arguments || {});
134
+ } else if (method === 'notifications/initialized') {
135
+ // no response needed
136
+ } else {
137
+ sendError(id, -32601, `Unknown method: ${method}`);
138
+ }
139
+ } catch (e) {
140
+ sendError(null, -32700, `Parse error: ${e.message}`);
141
+ }
142
+ });