trinity-method-sdk 2.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 (191) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/LICENSE +21 -0
  3. package/README.md +555 -0
  4. package/dist/cli/commands/deploy/agents.d.ts +14 -0
  5. package/dist/cli/commands/deploy/agents.js +59 -0
  6. package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
  7. package/dist/cli/commands/deploy/ci-cd.js +50 -0
  8. package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
  9. package/dist/cli/commands/deploy/claude-setup.js +91 -0
  10. package/dist/cli/commands/deploy/configuration.d.ts +13 -0
  11. package/dist/cli/commands/deploy/configuration.js +215 -0
  12. package/dist/cli/commands/deploy/directories.d.ts +12 -0
  13. package/dist/cli/commands/deploy/directories.js +38 -0
  14. package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
  15. package/dist/cli/commands/deploy/gitignore.js +53 -0
  16. package/dist/cli/commands/deploy/index.d.ts +38 -0
  17. package/dist/cli/commands/deploy/index.js +156 -0
  18. package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
  19. package/dist/cli/commands/deploy/knowledge-base.js +75 -0
  20. package/dist/cli/commands/deploy/linting.d.ts +18 -0
  21. package/dist/cli/commands/deploy/linting.js +51 -0
  22. package/dist/cli/commands/deploy/metrics.d.ts +13 -0
  23. package/dist/cli/commands/deploy/metrics.js +34 -0
  24. package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
  25. package/dist/cli/commands/deploy/pre-flight.js +29 -0
  26. package/dist/cli/commands/deploy/root-files.d.ts +16 -0
  27. package/dist/cli/commands/deploy/root-files.js +178 -0
  28. package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
  29. package/dist/cli/commands/deploy/sdk-install.js +57 -0
  30. package/dist/cli/commands/deploy/summary.d.ts +14 -0
  31. package/dist/cli/commands/deploy/summary.js +130 -0
  32. package/dist/cli/commands/deploy/templates.d.ts +14 -0
  33. package/dist/cli/commands/deploy/templates.js +84 -0
  34. package/dist/cli/commands/deploy/types.d.ts +39 -0
  35. package/dist/cli/commands/deploy/types.js +5 -0
  36. package/dist/cli/commands/update/agents.d.ts +14 -0
  37. package/dist/cli/commands/update/agents.js +31 -0
  38. package/dist/cli/commands/update/backup.d.ts +31 -0
  39. package/dist/cli/commands/update/backup.js +97 -0
  40. package/dist/cli/commands/update/commands.d.ts +14 -0
  41. package/dist/cli/commands/update/commands.js +75 -0
  42. package/dist/cli/commands/update/index.d.ts +15 -0
  43. package/dist/cli/commands/update/index.js +118 -0
  44. package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
  45. package/dist/cli/commands/update/knowledge-base.js +38 -0
  46. package/dist/cli/commands/update/pre-flight.d.ts +13 -0
  47. package/dist/cli/commands/update/pre-flight.js +37 -0
  48. package/dist/cli/commands/update/summary.d.ts +20 -0
  49. package/dist/cli/commands/update/summary.js +47 -0
  50. package/dist/cli/commands/update/templates.d.ts +14 -0
  51. package/dist/cli/commands/update/templates.js +25 -0
  52. package/dist/cli/commands/update/types.d.ts +13 -0
  53. package/dist/cli/commands/update/types.js +7 -0
  54. package/dist/cli/commands/update/utils.d.ts +11 -0
  55. package/dist/cli/commands/update/utils.js +19 -0
  56. package/dist/cli/commands/update/verification.d.ts +20 -0
  57. package/dist/cli/commands/update/verification.js +54 -0
  58. package/dist/cli/commands/update/version.d.ts +18 -0
  59. package/dist/cli/commands/update/version.js +36 -0
  60. package/dist/cli/commands/update.d.ts +7 -0
  61. package/dist/cli/commands/update.js +7 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.js +36 -0
  64. package/dist/cli/types.d.ts +77 -0
  65. package/dist/cli/types.js +5 -0
  66. package/dist/cli/utils/deploy-ci.d.ts +22 -0
  67. package/dist/cli/utils/deploy-ci.js +138 -0
  68. package/dist/cli/utils/deploy-linting.d.ts +3 -0
  69. package/dist/cli/utils/deploy-linting.js +136 -0
  70. package/dist/cli/utils/detect-stack.d.ts +3 -0
  71. package/dist/cli/utils/detect-stack.js +270 -0
  72. package/dist/cli/utils/error-classes.d.ts +63 -0
  73. package/dist/cli/utils/error-classes.js +84 -0
  74. package/dist/cli/utils/error-handler.d.ts +59 -0
  75. package/dist/cli/utils/error-handler.js +127 -0
  76. package/dist/cli/utils/errors.d.ts +52 -0
  77. package/dist/cli/utils/errors.js +102 -0
  78. package/dist/cli/utils/get-sdk-path.d.ts +18 -0
  79. package/dist/cli/utils/get-sdk-path.js +31 -0
  80. package/dist/cli/utils/inject-dependencies.d.ts +2 -0
  81. package/dist/cli/utils/inject-dependencies.js +55 -0
  82. package/dist/cli/utils/linting-tools.d.ts +8 -0
  83. package/dist/cli/utils/linting-tools.js +206 -0
  84. package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
  85. package/dist/cli/utils/metrics/code-quality.js +122 -0
  86. package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
  87. package/dist/cli/utils/metrics/dependency-parser.js +153 -0
  88. package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
  89. package/dist/cli/utils/metrics/file-complexity.js +77 -0
  90. package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
  91. package/dist/cli/utils/metrics/framework-detector.js +120 -0
  92. package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
  93. package/dist/cli/utils/metrics/git-metrics.js +83 -0
  94. package/dist/cli/utils/metrics/index.d.ts +28 -0
  95. package/dist/cli/utils/metrics/index.js +100 -0
  96. package/dist/cli/utils/template-processor.d.ts +10 -0
  97. package/dist/cli/utils/template-processor.js +188 -0
  98. package/dist/cli/utils/validate-path.d.ts +80 -0
  99. package/dist/cli/utils/validate-path.js +180 -0
  100. package/dist/index.d.ts +6 -0
  101. package/dist/index.js +8 -0
  102. package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
  103. package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
  104. package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
  105. package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
  106. package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
  107. package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
  108. package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
  109. package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
  110. package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
  111. package/dist/templates/agents/deployment/ino-context.md.template +733 -0
  112. package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
  113. package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
  114. package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
  115. package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
  116. package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
  117. package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
  118. package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
  119. package/dist/templates/agents/planning/ror-design.md.template +465 -0
  120. package/dist/templates/agents/planning/tra-planner.md.template +432 -0
  121. package/dist/templates/ci/cd.yml.template +175 -0
  122. package/dist/templates/ci/ci.yml.template +196 -0
  123. package/dist/templates/ci/generic-ci.yml +115 -0
  124. package/dist/templates/ci/github-actions.yml +86 -0
  125. package/dist/templates/ci/gitlab-ci.yml +103 -0
  126. package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
  127. package/dist/templates/documentation/ROOT-README.md.template +307 -0
  128. package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
  129. package/dist/templates/investigations/bug.md.template +484 -0
  130. package/dist/templates/investigations/feature.md.template +564 -0
  131. package/dist/templates/investigations/performance.md.template +625 -0
  132. package/dist/templates/investigations/security.md.template +714 -0
  133. package/dist/templates/investigations/technical.md.template +433 -0
  134. package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
  135. package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
  136. package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
  137. package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
  138. package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
  139. package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
  140. package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
  141. package/dist/templates/knowledge-base/To-do.md.template +407 -0
  142. package/dist/templates/knowledge-base/Trinity.md.template +464 -0
  143. package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
  144. package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
  145. package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
  146. package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
  147. package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
  148. package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
  149. package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
  150. package/dist/templates/linting/python/.flake8.template +16 -0
  151. package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
  152. package/dist/templates/linting/python/pyproject.toml.template +38 -0
  153. package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
  154. package/dist/templates/linting/rust/clippy.toml.template +14 -0
  155. package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
  156. package/dist/templates/root/CLAUDE.md.template +65 -0
  157. package/dist/templates/root/TRINITY.md.template +52 -0
  158. package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
  159. package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
  160. package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
  161. package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
  162. package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
  163. package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
  164. package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
  165. package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
  166. package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
  167. package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
  168. package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
  169. package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
  170. package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
  171. package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
  172. package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
  173. package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
  174. package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
  175. package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
  176. package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
  177. package/dist/templates/source/base-CLAUDE.md.template +310 -0
  178. package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
  179. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
  180. package/dist/templates/source/python-CLAUDE.md.template +510 -0
  181. package/dist/templates/source/react-CLAUDE.md.template +513 -0
  182. package/dist/templates/source/rust-CLAUDE.md.template +653 -0
  183. package/dist/templates/source/tests-CLAUDE.md.template +432 -0
  184. package/dist/templates/trinity/CLAUDE.md.template +372 -0
  185. package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
  186. package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
  187. package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
  188. package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
  189. package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
  190. package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
  191. package/package.json +94 -0
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Framework Detection Module
3
+ * Detects framework versions and package managers
4
+ * @module cli/utils/metrics/framework-detector
5
+ */
6
+ import fs from 'fs-extra';
7
+ import { execSync } from 'child_process';
8
+ /**
9
+ * Detect React version from package.json
10
+ */
11
+ async function detectReactVersion() {
12
+ if (!(await fs.pathExists('package.json')))
13
+ return 'Unknown';
14
+ const pkg = await fs.readJson('package.json');
15
+ if (pkg.dependencies?.react) {
16
+ return pkg.dependencies.react.replace(/[\^~]/, '');
17
+ }
18
+ return detectNodeVersion();
19
+ }
20
+ /**
21
+ * Detect Next.js version from package.json
22
+ */
23
+ async function detectNextVersion() {
24
+ if (!(await fs.pathExists('package.json')))
25
+ return 'Unknown';
26
+ const pkg = await fs.readJson('package.json');
27
+ if (pkg.dependencies?.next) {
28
+ return pkg.dependencies.next.replace(/[\^~]/, '');
29
+ }
30
+ return detectNodeVersion();
31
+ }
32
+ /**
33
+ * Detect Node.js version
34
+ */
35
+ function detectNodeVersion() {
36
+ const nodeVersion = execSync('node --version', {
37
+ encoding: 'utf8',
38
+ stdio: ['pipe', 'pipe', 'ignore'],
39
+ });
40
+ return nodeVersion.trim();
41
+ }
42
+ /**
43
+ * Detect Flutter version from pubspec.yaml
44
+ */
45
+ async function detectFlutterVersion() {
46
+ if (!(await fs.pathExists('pubspec.yaml')))
47
+ return 'Unknown';
48
+ const yaml = await fs.readFile('pubspec.yaml', 'utf8');
49
+ const match = yaml.match(/sdk:\s*["']>=?(\d+\.\d+\.\d+)/);
50
+ return match ? match[1] : 'Unknown';
51
+ }
52
+ /**
53
+ * Detect Python version
54
+ */
55
+ function detectPythonVersion() {
56
+ const version = execSync('python --version 2>&1', {
57
+ encoding: 'utf8',
58
+ stdio: ['pipe', 'pipe', 'ignore'],
59
+ });
60
+ return version.trim().replace('Python ', '');
61
+ }
62
+ /**
63
+ * Detect Rust version
64
+ */
65
+ function detectRustVersion() {
66
+ const version = execSync('rustc --version', {
67
+ encoding: 'utf8',
68
+ stdio: ['pipe', 'pipe', 'ignore'],
69
+ });
70
+ return version.trim().replace('rustc ', '');
71
+ }
72
+ /**
73
+ * Framework version detector map
74
+ */
75
+ const VERSION_DETECTORS = {
76
+ React: detectReactVersion,
77
+ 'Next.js': detectNextVersion,
78
+ 'Node.js': detectNodeVersion,
79
+ Flutter: detectFlutterVersion,
80
+ Python: detectPythonVersion,
81
+ Rust: detectRustVersion,
82
+ };
83
+ /**
84
+ * Detect framework version
85
+ * @param framework - Framework name
86
+ * @returns Version string
87
+ */
88
+ export async function detectFrameworkVersion(framework) {
89
+ try {
90
+ const detector = VERSION_DETECTORS[framework];
91
+ if (detector) {
92
+ return await detector();
93
+ }
94
+ }
95
+ catch {
96
+ // Framework version detection failed
97
+ }
98
+ return 'Unknown';
99
+ }
100
+ /**
101
+ * Detect package manager
102
+ * @returns Package manager name
103
+ */
104
+ export async function detectPackageManager() {
105
+ // Check in priority order (pnpm should be checked before npm/yarn)
106
+ if (await fs.pathExists('pnpm-lock.yaml'))
107
+ return 'pnpm';
108
+ if (await fs.pathExists('yarn.lock'))
109
+ return 'yarn';
110
+ if (await fs.pathExists('package-lock.json'))
111
+ return 'npm';
112
+ if (await fs.pathExists('pubspec.yaml'))
113
+ return 'pub';
114
+ if (await fs.pathExists('requirements.txt'))
115
+ return 'pip';
116
+ if (await fs.pathExists('Cargo.toml'))
117
+ return 'cargo';
118
+ return 'Unknown';
119
+ }
120
+ //# sourceMappingURL=framework-detector.js.map
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Git Metrics Collection
3
+ * Collects commit counts, contributor counts, and last commit date
4
+ * @module cli/utils/metrics/git-metrics
5
+ */
6
+ /**
7
+ * Get total commit count
8
+ * @returns Commit count
9
+ */
10
+ export declare function getCommitCount(): Promise<number>;
11
+ /**
12
+ * Get contributor count
13
+ * @returns Contributor count
14
+ */
15
+ export declare function getContributorCount(): Promise<number>;
16
+ /**
17
+ * Get last commit date
18
+ * @returns Last commit date (ISO format)
19
+ */
20
+ export declare function getLastCommitDate(): Promise<string>;
21
+ /**
22
+ * Collect git metrics
23
+ * @returns Git metrics
24
+ */
25
+ export declare function collectGitMetrics(): Promise<{
26
+ commitCount: number;
27
+ contributors: number;
28
+ lastCommitDate: string;
29
+ }>;
30
+ //# sourceMappingURL=git-metrics.d.ts.map
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Git Metrics Collection
3
+ * Collects commit counts, contributor counts, and last commit date
4
+ * @module cli/utils/metrics/git-metrics
5
+ */
6
+ import { execSync } from 'child_process';
7
+ /**
8
+ * Get total commit count
9
+ * @returns Commit count
10
+ */
11
+ export async function getCommitCount() {
12
+ try {
13
+ const count = execSync('git rev-list --count HEAD', {
14
+ encoding: 'utf8',
15
+ stdio: ['pipe', 'pipe', 'ignore'],
16
+ });
17
+ return parseInt(count.trim(), 10);
18
+ }
19
+ catch {
20
+ return 0;
21
+ }
22
+ }
23
+ /**
24
+ * Get contributor count
25
+ * @returns Contributor count
26
+ */
27
+ export async function getContributorCount() {
28
+ try {
29
+ const output = execSync('git shortlog -sn --all', {
30
+ encoding: 'utf8',
31
+ stdio: ['pipe', 'pipe', 'ignore'],
32
+ });
33
+ const lines = output
34
+ .trim()
35
+ .split('\n')
36
+ .filter((line) => line.length > 0);
37
+ return lines.length;
38
+ }
39
+ catch {
40
+ return 1;
41
+ }
42
+ }
43
+ /**
44
+ * Get last commit date
45
+ * @returns Last commit date (ISO format)
46
+ */
47
+ export async function getLastCommitDate() {
48
+ try {
49
+ const date = execSync('git log -1 --format=%cI', {
50
+ encoding: 'utf8',
51
+ stdio: ['pipe', 'pipe', 'ignore'],
52
+ });
53
+ return date.trim();
54
+ }
55
+ catch {
56
+ return 'Unknown';
57
+ }
58
+ }
59
+ /**
60
+ * Collect git metrics
61
+ * @returns Git metrics
62
+ */
63
+ export async function collectGitMetrics() {
64
+ try {
65
+ const commitCount = await getCommitCount();
66
+ const contributors = await getContributorCount();
67
+ const lastCommitDate = await getLastCommitDate();
68
+ return {
69
+ commitCount,
70
+ contributors,
71
+ lastCommitDate,
72
+ };
73
+ }
74
+ catch {
75
+ // Git not available or not a git repo
76
+ return {
77
+ commitCount: 0,
78
+ contributors: 0,
79
+ lastCommitDate: 'Unknown',
80
+ };
81
+ }
82
+ }
83
+ //# sourceMappingURL=git-metrics.js.map
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Codebase Metrics Collection Utility - Main Orchestrator
3
+ * Trinity Method SDK - Hybrid Audit System
4
+ *
5
+ * Collects scriptable metrics from codebase without semantic analysis.
6
+ * Designed for cross-platform compatibility (Node.js, Flutter, React, Python, Rust).
7
+ * @module cli/utils/metrics
8
+ */
9
+ import { CodebaseMetrics } from '../../types.js';
10
+ import { analyzeFileComplexity } from './file-complexity.js';
11
+ import { parseDependencies } from './dependency-parser.js';
12
+ import { detectFrameworkVersion, detectPackageManager } from './framework-detector.js';
13
+ /**
14
+ * Create an empty CodebaseMetrics object with default values
15
+ */
16
+ export declare function createEmptyMetrics(): CodebaseMetrics;
17
+ /**
18
+ * Main entry point for metrics collection
19
+ * @param sourceDir - Source code directory (src/, lib/, app/)
20
+ * @param framework - Detected framework (Node.js, Flutter, React, Python, Rust)
21
+ * @returns Collected metrics
22
+ */
23
+ declare function collectCodebaseMetrics(sourceDir: string, framework: string): Promise<CodebaseMetrics>;
24
+ export { collectCodebaseMetrics, analyzeFileComplexity, parseDependencies, detectFrameworkVersion, detectPackageManager, };
25
+ export { countPattern } from './code-quality.js';
26
+ export type { FileComplexityMetrics } from './file-complexity.js';
27
+ export type { DependencyMetrics } from './dependency-parser.js';
28
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Codebase Metrics Collection Utility - Main Orchestrator
3
+ * Trinity Method SDK - Hybrid Audit System
4
+ *
5
+ * Collects scriptable metrics from codebase without semantic analysis.
6
+ * Designed for cross-platform compatibility (Node.js, Flutter, React, Python, Rust).
7
+ * @module cli/utils/metrics
8
+ */
9
+ import { collectCodeQualityMetrics } from './code-quality.js';
10
+ import { analyzeFileComplexity } from './file-complexity.js';
11
+ import { parseDependencies } from './dependency-parser.js';
12
+ import { collectGitMetrics } from './git-metrics.js';
13
+ import { detectFrameworkVersion, detectPackageManager } from './framework-detector.js';
14
+ /**
15
+ * Create an empty CodebaseMetrics object with default values
16
+ */
17
+ export function createEmptyMetrics() {
18
+ return {
19
+ // Code Quality Metrics
20
+ todoCount: 0,
21
+ todoComments: 0,
22
+ fixmeComments: 0,
23
+ hackComments: 0,
24
+ consoleStatements: 0,
25
+ commentedCodeBlocks: 0,
26
+ // File Complexity Metrics
27
+ totalFiles: 0,
28
+ filesOver500: 0,
29
+ filesOver1000: 0,
30
+ filesOver3000: 0,
31
+ avgFileLength: 0,
32
+ largestFiles: [],
33
+ // Dependency Metrics
34
+ dependencies: {},
35
+ dependencyCount: 0,
36
+ devDependencies: {},
37
+ devDependencyCount: 0,
38
+ // Git Metrics
39
+ commitCount: 0,
40
+ contributors: 0,
41
+ lastCommitDate: 'Unknown',
42
+ // Framework-Specific
43
+ frameworkVersion: 'Unknown',
44
+ packageManager: 'Unknown',
45
+ };
46
+ }
47
+ /**
48
+ * Main entry point for metrics collection
49
+ * @param sourceDir - Source code directory (src/, lib/, app/)
50
+ * @param framework - Detected framework (Node.js, Flutter, React, Python, Rust)
51
+ * @returns Collected metrics
52
+ */
53
+ async function collectCodebaseMetrics(sourceDir, framework) {
54
+ console.log(` Collecting metrics from ${sourceDir} (${framework})...`);
55
+ const metrics = createEmptyMetrics();
56
+ try {
57
+ // Code Quality Metrics
58
+ const codeQuality = await collectCodeQualityMetrics(sourceDir);
59
+ Object.assign(metrics, codeQuality);
60
+ // File Complexity Metrics
61
+ const fileStats = await analyzeFileComplexity(sourceDir);
62
+ metrics.totalFiles = fileStats.totalFiles;
63
+ metrics.filesOver500 = fileStats.filesOver500;
64
+ metrics.filesOver1000 = fileStats.filesOver1000;
65
+ metrics.filesOver3000 = fileStats.filesOver3000;
66
+ metrics.avgFileLength = fileStats.avgFileLength;
67
+ metrics.largestFiles = fileStats.largestFiles;
68
+ // Dependency Metrics
69
+ const deps = await parseDependencies(framework);
70
+ metrics.dependencies = deps.dependencies;
71
+ metrics.dependencyCount = deps.dependencyCount;
72
+ metrics.devDependencies = deps.devDependencies;
73
+ metrics.devDependencyCount = deps.devDependencyCount;
74
+ // Git Metrics (optional)
75
+ try {
76
+ const gitMetrics = await collectGitMetrics();
77
+ metrics.commitCount = gitMetrics.commitCount;
78
+ metrics.contributors = gitMetrics.contributors;
79
+ metrics.lastCommitDate = gitMetrics.lastCommitDate;
80
+ }
81
+ catch {
82
+ // Git not available or not a git repo
83
+ console.log(' Git metrics unavailable (not a git repository)');
84
+ }
85
+ // Framework-Specific
86
+ metrics.frameworkVersion = await detectFrameworkVersion(framework);
87
+ metrics.packageManager = await detectPackageManager();
88
+ }
89
+ catch (error) {
90
+ const { displayError, getErrorMessage } = await import('../errors.js');
91
+ displayError(`Error collecting metrics: ${getErrorMessage(error)}`);
92
+ throw error;
93
+ }
94
+ return metrics;
95
+ }
96
+ // Export everything for backward compatibility
97
+ export { collectCodebaseMetrics, analyzeFileComplexity, parseDependencies, detectFrameworkVersion, detectPackageManager, };
98
+ // Re-export from submodules for direct access
99
+ export { countPattern } from './code-quality.js';
100
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ import { Stack, CodebaseMetrics } from '../types.js';
2
+ export declare function processTemplate(content: string, variables: Record<string, string | number>): string;
3
+ export declare function extractVariables(stack: Stack, projectName: string): Record<string, string>;
4
+ /**
5
+ * Format metrics for template variable replacement
6
+ * @param metrics - Collected codebase metrics
7
+ * @returns Formatted metric variables
8
+ */
9
+ export declare function formatMetrics(metrics?: CodebaseMetrics): Record<string, string | number>;
10
+ //# sourceMappingURL=template-processor.d.ts.map
@@ -0,0 +1,188 @@
1
+ /**
2
+ * Convert value to string safely
3
+ */
4
+ function toString(value) {
5
+ return value !== undefined ? String(value) : '';
6
+ }
7
+ /**
8
+ * Resolve PROJECT_VAR_NAME variable
9
+ */
10
+ function resolveProjectVarName(variables) {
11
+ return (toString(variables.PROJECT_VAR_NAME) ||
12
+ String(variables.PROJECT_NAME || variables.projectName || 'project')
13
+ .toLowerCase()
14
+ .replace(/[^a-z0-9]/g, ''));
15
+ }
16
+ /**
17
+ * Variable resolvers - maps placeholder names to resolution functions
18
+ */
19
+ const VARIABLE_RESOLVERS = {
20
+ PROJECT_NAME: (v) => toString(v.PROJECT_NAME || v.projectName) || 'Unknown Project',
21
+ TECH_STACK: (v) => toString(v.TECH_STACK || v.techStack) || 'Unknown',
22
+ FRAMEWORK: (v) => toString(v.FRAMEWORK || v.framework) || 'Generic',
23
+ SOURCE_DIR: (v) => toString(v.SOURCE_DIR || v.sourceDir) || 'src',
24
+ DEPLOYMENT_TIMESTAMP: (v) => toString(v.DEPLOYMENT_TIMESTAMP || v.timestamp) || new Date().toISOString(),
25
+ LANGUAGE: (v) => toString(v.LANGUAGE || v.language) || 'Unknown',
26
+ PACKAGE_MANAGER: (v) => toString(v.PACKAGE_MANAGER || v.packageManager) || 'npm',
27
+ TRINITY_VERSION: (v) => toString(v.TRINITY_VERSION) || '2.0.0',
28
+ TECHNOLOGY_STACK: (v) => toString(v.TECHNOLOGY_STACK || v.TECH_STACK || v.techStack) || 'Unknown',
29
+ PRIMARY_FRAMEWORK: (v) => toString(v.PRIMARY_FRAMEWORK || v.FRAMEWORK || v.framework) || 'Generic',
30
+ CURRENT_DATE: (v) => toString(v.CURRENT_DATE) || new Date().toISOString().split('T')[0],
31
+ PROJECT_VAR_NAME: (v) => resolveProjectVarName(v),
32
+ TRINITY_HOME: (v) => toString(v.TRINITY_HOME) ||
33
+ process.env.TRINITY_HOME ||
34
+ 'C:/Users/lukaf/Desktop/Dev Work/trinity-method',
35
+ };
36
+ export function processTemplate(content, variables) {
37
+ let processed = content;
38
+ // Replace each placeholder using resolver functions
39
+ for (const [key, resolver] of Object.entries(VARIABLE_RESOLVERS)) {
40
+ const value = resolver(variables);
41
+ const regex = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
42
+ processed = processed.replace(regex, value);
43
+ }
44
+ return processed;
45
+ }
46
+ export function extractVariables(stack, projectName) {
47
+ return {
48
+ projectName: projectName || 'My Project',
49
+ techStack: `${stack.language} / ${stack.framework}`,
50
+ framework: stack.framework,
51
+ sourceDir: stack.sourceDir,
52
+ language: stack.language,
53
+ packageManager: stack.packageManager || 'npm',
54
+ timestamp: new Date().toISOString(),
55
+ };
56
+ }
57
+ /**
58
+ * Get placeholder metrics object
59
+ */
60
+ function getPlaceholderMetrics() {
61
+ return {
62
+ // Code Quality
63
+ TODO_COUNT: '{{TODO_COUNT}}',
64
+ TODO_COMMENTS: '{{TODO_COMMENTS}}',
65
+ FIXME_COUNT: '{{FIXME_COUNT}}',
66
+ HACK_COUNT: '{{HACK_COUNT}}',
67
+ CONSOLE_COUNT: '{{CONSOLE_COUNT}}',
68
+ COMMENTED_BLOCKS: '{{COMMENTED_BLOCKS}}',
69
+ // File Complexity
70
+ TOTAL_FILES: '{{TOTAL_FILES}}',
71
+ FILES_500: '{{FILES_500}}',
72
+ FILES_1000: '{{FILES_1000}}',
73
+ FILES_3000: '{{FILES_3000}}',
74
+ AVG_LENGTH: '{{AVG_LENGTH}}',
75
+ // Dependencies
76
+ DEPENDENCY_COUNT: '{{DEPENDENCY_COUNT}}',
77
+ DEV_DEPENDENCY_COUNT: '{{DEV_DEPENDENCY_COUNT}}',
78
+ FRAMEWORK_VERSION: '{{FRAMEWORK_VERSION}}',
79
+ PACKAGE_MANAGER: '{{PACKAGE_MANAGER}}',
80
+ // Git
81
+ COMMIT_COUNT: '{{COMMIT_COUNT}}',
82
+ CONTRIBUTOR_COUNT: '{{CONTRIBUTOR_COUNT}}',
83
+ LAST_COMMIT: '{{LAST_COMMIT}}',
84
+ // Agent-only
85
+ OVERALL_COVERAGE: '{{OVERALL_COVERAGE}}',
86
+ UNIT_COVERAGE: '{{UNIT_COVERAGE}}',
87
+ DEPRECATED_COUNT: '{{DEPRECATED_COUNT}}',
88
+ ANTIPATTERN_COUNT: '{{ANTIPATTERN_COUNT}}',
89
+ PERF_ISSUE_COUNT: '{{PERF_ISSUE_COUNT}}',
90
+ SECURITY_COUNT: '{{SECURITY_COUNT}}',
91
+ // Architecture
92
+ COMPONENT_1: '{{COMPONENT_1}}',
93
+ RESPONSIBILITY_1: '{{RESPONSIBILITY_1}}',
94
+ BACKEND_FRAMEWORK: '{{BACKEND_FRAMEWORK}}',
95
+ DATABASE_TYPE: '{{DATABASE_TYPE}}',
96
+ AUTH_TYPE: '{{AUTH_TYPE}}',
97
+ STYLING_SOLUTION: '{{STYLING_SOLUTION}}',
98
+ };
99
+ }
100
+ /**
101
+ * Get agent-only placeholder metrics
102
+ */
103
+ function getAgentOnlyPlaceholders() {
104
+ return {
105
+ OVERALL_COVERAGE: '{{OVERALL_COVERAGE}}',
106
+ UNIT_COVERAGE: '{{UNIT_COVERAGE}}',
107
+ DEPRECATED_COUNT: '{{DEPRECATED_COUNT}}',
108
+ ANTIPATTERN_COUNT: '{{ANTIPATTERN_COUNT}}',
109
+ PERF_ISSUE_COUNT: '{{PERF_ISSUE_COUNT}}',
110
+ SECURITY_COUNT: '{{SECURITY_COUNT}}',
111
+ COMPONENT_1: '{{COMPONENT_1}}',
112
+ RESPONSIBILITY_1: '{{RESPONSIBILITY_1}}',
113
+ BACKEND_FRAMEWORK: '{{BACKEND_FRAMEWORK}}',
114
+ DATABASE_TYPE: '{{DATABASE_TYPE}}',
115
+ AUTH_TYPE: '{{AUTH_TYPE}}',
116
+ STYLING_SOLUTION: '{{STYLING_SOLUTION}}',
117
+ };
118
+ }
119
+ /**
120
+ * Format code quality metrics
121
+ */
122
+ function formatCodeQualityMetrics(metrics) {
123
+ return {
124
+ TODO_COUNT: metrics.todoCount || 0,
125
+ TODO_COMMENTS: metrics.todoComments || 0,
126
+ FIXME_COUNT: metrics.fixmeComments || 0,
127
+ HACK_COUNT: metrics.hackComments || 0,
128
+ CONSOLE_COUNT: metrics.consoleStatements || 0,
129
+ COMMENTED_BLOCKS: metrics.commentedCodeBlocks || 0,
130
+ };
131
+ }
132
+ /**
133
+ * Format file complexity metrics
134
+ */
135
+ function formatFileComplexityMetrics(metrics) {
136
+ return {
137
+ TOTAL_FILES: metrics.totalFiles || 0,
138
+ FILES_500: metrics.filesOver500 || 0,
139
+ FILES_1000: metrics.filesOver1000 || 0,
140
+ FILES_3000: metrics.filesOver3000 || 0,
141
+ AVG_LENGTH: Math.round(metrics.avgFileLength || 0),
142
+ };
143
+ }
144
+ /**
145
+ * Format dependency metrics
146
+ */
147
+ function formatDependencyMetrics(metrics) {
148
+ return {
149
+ DEPENDENCY_COUNT: metrics.dependencyCount || 0,
150
+ DEV_DEPENDENCY_COUNT: metrics.devDependencyCount || 0,
151
+ FRAMEWORK_VERSION: metrics.frameworkVersion || 'Unknown',
152
+ PACKAGE_MANAGER: metrics.packageManager || 'Unknown',
153
+ };
154
+ }
155
+ /**
156
+ * Format git metrics
157
+ */
158
+ function formatGitMetrics(metrics) {
159
+ return {
160
+ COMMIT_COUNT: metrics.commitCount || 0,
161
+ CONTRIBUTOR_COUNT: metrics.contributors || 1,
162
+ LAST_COMMIT: metrics.lastCommitDate || 'Unknown',
163
+ };
164
+ }
165
+ /**
166
+ * Format actual metrics from codebase
167
+ */
168
+ function formatActualMetrics(metrics) {
169
+ return {
170
+ ...formatCodeQualityMetrics(metrics),
171
+ ...formatFileComplexityMetrics(metrics),
172
+ ...formatDependencyMetrics(metrics),
173
+ ...formatGitMetrics(metrics),
174
+ ...getAgentOnlyPlaceholders(),
175
+ };
176
+ }
177
+ /**
178
+ * Format metrics for template variable replacement
179
+ * @param metrics - Collected codebase metrics
180
+ * @returns Formatted metric variables
181
+ */
182
+ export function formatMetrics(metrics) {
183
+ if (!metrics || Object.keys(metrics).length === 0) {
184
+ return getPlaceholderMetrics();
185
+ }
186
+ return formatActualMetrics(metrics);
187
+ }
188
+ //# sourceMappingURL=template-processor.js.map
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Path Validation Utility
3
+ * Security module for preventing path traversal and symlink attacks
4
+ * @module cli/utils/validate-path
5
+ */
6
+ /**
7
+ * Validate that a path is safe and within project directory
8
+ *
9
+ * Security checks:
10
+ * - Rejects absolute paths (Unix: /path, Windows: C:\path, UNC: \\server\share)
11
+ * - Rejects path traversal attempts (../)
12
+ * - Normalizes path separators for cross-platform compatibility
13
+ * - Ensures resolved path is within baseDir
14
+ *
15
+ * @param userPath - User-provided path (potentially malicious)
16
+ * @param baseDir - Base directory (defaults to current working directory)
17
+ * @throws Error if path is invalid, absolute, or attempts traversal
18
+ * @returns Validated absolute path within baseDir
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * // Valid usage
23
+ * const safe = validatePath('trinity/agents'); // OK
24
+ * const safe2 = validatePath('./trinity/agents'); // OK
25
+ *
26
+ * // Blocked - path traversal
27
+ * validatePath('../../../etc/passwd'); // throws Error
28
+ *
29
+ * // Blocked - absolute path
30
+ * validatePath('/etc/passwd'); // throws Error
31
+ * validatePath('C:\\Windows\\System32'); // throws Error
32
+ * ```
33
+ */
34
+ export declare function validatePath(userPath: string, baseDir?: string): string;
35
+ /**
36
+ * Validate that a path is not a symlink
37
+ *
38
+ * Security rationale:
39
+ * - Prevents symlink attacks where malicious symlinks point to sensitive files
40
+ * - Ensures file operations act on actual files, not symlink references
41
+ * - Protects against symlink race conditions
42
+ *
43
+ * @param filePath - Path to validate (should be absolute path from validatePath)
44
+ * @throws Error if path is a symlink
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * await validateNotSymlink('/project/trinity/agents/mon.md'); // OK
49
+ * await validateNotSymlink('/project/link-to-passwd'); // throws Error
50
+ * ```
51
+ */
52
+ export declare function validateNotSymlink(filePath: string): Promise<void>;
53
+ /**
54
+ * Safely copy files or directories with security validation
55
+ *
56
+ * Security features:
57
+ * - Validates both source and destination paths
58
+ * - Rejects symlinks (prevents symlink attacks)
59
+ * - Doesn't follow symlinks during copy (dereference: false)
60
+ * - Ensures copy stays within project directory
61
+ *
62
+ * @param src - Source path (relative to baseDir)
63
+ * @param dest - Destination path (relative to baseDir)
64
+ * @param baseDir - Base directory (defaults to current working directory)
65
+ * @throws Error if paths are invalid or contain symlinks
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * // Safe copy
70
+ * await safeCopy('templates/agent.md', 'trinity/agents/new-agent.md');
71
+ *
72
+ * // Blocked - path traversal
73
+ * await safeCopy('file.txt', '../outside/file.txt'); // throws Error
74
+ *
75
+ * // Blocked - symlink source
76
+ * await safeCopy('symlink-to-file', 'dest.txt'); // throws Error
77
+ * ```
78
+ */
79
+ export declare function safeCopy(src: string, dest: string, baseDir?: string): Promise<void>;
80
+ //# sourceMappingURL=validate-path.d.ts.map