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,180 @@
1
+ /**
2
+ * Path Validation Utility
3
+ * Security module for preventing path traversal and symlink attacks
4
+ * @module cli/utils/validate-path
5
+ */
6
+ import path from 'path';
7
+ import fs from 'fs-extra';
8
+ /**
9
+ * Validate that a path is safe and within project directory
10
+ *
11
+ * Security checks:
12
+ * - Rejects absolute paths (Unix: /path, Windows: C:\path, UNC: \\server\share)
13
+ * - Rejects path traversal attempts (../)
14
+ * - Normalizes path separators for cross-platform compatibility
15
+ * - Ensures resolved path is within baseDir
16
+ *
17
+ * @param userPath - User-provided path (potentially malicious)
18
+ * @param baseDir - Base directory (defaults to current working directory)
19
+ * @throws Error if path is invalid, absolute, or attempts traversal
20
+ * @returns Validated absolute path within baseDir
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * // Valid usage
25
+ * const safe = validatePath('trinity/agents'); // OK
26
+ * const safe2 = validatePath('./trinity/agents'); // OK
27
+ *
28
+ * // Blocked - path traversal
29
+ * validatePath('../../../etc/passwd'); // throws Error
30
+ *
31
+ * // Blocked - absolute path
32
+ * validatePath('/etc/passwd'); // throws Error
33
+ * validatePath('C:\\Windows\\System32'); // throws Error
34
+ * ```
35
+ */
36
+ export function validatePath(userPath, baseDir = process.cwd()) {
37
+ // Check for null bytes (path injection attempt)
38
+ if (userPath.includes('\0')) {
39
+ throw new Error(`Invalid path: null byte detected in "${userPath}"\n` +
40
+ `Null bytes are not allowed in file paths.`);
41
+ }
42
+ // Normalize path separators (handles Windows \ and Unix /)
43
+ const normalized = path.normalize(userPath);
44
+ // Reject absolute paths (security policy: only relative paths allowed)
45
+ if (path.isAbsolute(normalized)) {
46
+ throw new Error(`Absolute paths are not allowed: ${userPath}\n` +
47
+ `Use relative paths within project directory.`);
48
+ }
49
+ // Resolve to absolute path (relative to baseDir)
50
+ const resolved = path.resolve(baseDir, normalized);
51
+ // Check if resolved path is within baseDir
52
+ // This is the core security check for path traversal
53
+ const relative = path.relative(baseDir, resolved);
54
+ // If relative path starts with ".." or is absolute, it's outside baseDir
55
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
56
+ throw new Error(`Path traversal detected: ${userPath}\n` +
57
+ `Path must be within project directory: ${baseDir}\n` +
58
+ `Attempted to access: ${resolved}`);
59
+ }
60
+ return resolved;
61
+ }
62
+ /**
63
+ * Validate that a path is not a symlink
64
+ *
65
+ * Security rationale:
66
+ * - Prevents symlink attacks where malicious symlinks point to sensitive files
67
+ * - Ensures file operations act on actual files, not symlink references
68
+ * - Protects against symlink race conditions
69
+ *
70
+ * @param filePath - Path to validate (should be absolute path from validatePath)
71
+ * @throws Error if path is a symlink
72
+ *
73
+ * @example
74
+ * ```typescript
75
+ * await validateNotSymlink('/project/trinity/agents/mon.md'); // OK
76
+ * await validateNotSymlink('/project/link-to-passwd'); // throws Error
77
+ * ```
78
+ */
79
+ export async function validateNotSymlink(filePath) {
80
+ try {
81
+ // Use lstat to get symlink info (stat would follow the symlink)
82
+ const stats = await fs.lstat(filePath);
83
+ if (stats.isSymbolicLink()) {
84
+ throw new Error(`Symlink detected: ${filePath}\n` +
85
+ `For security, symlinks are not allowed in Trinity operations.\n` +
86
+ `Please use the actual file or directory instead.`);
87
+ }
88
+ }
89
+ catch (error) {
90
+ // Re-throw if it's our symlink error
91
+ const { getErrorMessage } = await import('./errors.js');
92
+ const message = getErrorMessage(error);
93
+ if (message.includes('Symlink detected')) {
94
+ throw error;
95
+ }
96
+ // If file doesn't exist, that's OK (will be created)
97
+ // Other errors should be handled by caller
98
+ const err = error;
99
+ if (err.code !== 'ENOENT') {
100
+ throw error;
101
+ }
102
+ }
103
+ }
104
+ /**
105
+ * Safely copy files or directories with security validation
106
+ *
107
+ * Security features:
108
+ * - Validates both source and destination paths
109
+ * - Rejects symlinks (prevents symlink attacks)
110
+ * - Doesn't follow symlinks during copy (dereference: false)
111
+ * - Ensures copy stays within project directory
112
+ *
113
+ * @param src - Source path (relative to baseDir)
114
+ * @param dest - Destination path (relative to baseDir)
115
+ * @param baseDir - Base directory (defaults to current working directory)
116
+ * @throws Error if paths are invalid or contain symlinks
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * // Safe copy
121
+ * await safeCopy('templates/agent.md', 'trinity/agents/new-agent.md');
122
+ *
123
+ * // Blocked - path traversal
124
+ * await safeCopy('file.txt', '../outside/file.txt'); // throws Error
125
+ *
126
+ * // Blocked - symlink source
127
+ * await safeCopy('symlink-to-file', 'dest.txt'); // throws Error
128
+ * ```
129
+ */
130
+ export async function safeCopy(src, dest, baseDir = process.cwd()) {
131
+ // Validate paths are within project directory
132
+ const validSrc = validatePath(src, baseDir);
133
+ const validDest = validatePath(dest, baseDir);
134
+ // Check if source exists and is not a symlink
135
+ if (await fs.pathExists(validSrc)) {
136
+ await validateNotSymlink(validSrc);
137
+ // If source is a directory, recursively check for symlinks inside
138
+ const stats = await fs.stat(validSrc);
139
+ if (stats.isDirectory()) {
140
+ await validateDirectoryNoSymlinks(validSrc);
141
+ }
142
+ }
143
+ else {
144
+ throw new Error(`Source path does not exist: ${src}\n` + `Resolved to: ${validSrc}`);
145
+ }
146
+ // Copy with security options
147
+ await fs.copy(validSrc, validDest, {
148
+ dereference: false, // Don't follow symlinks (security)
149
+ overwrite: true, // Allow overwriting existing files
150
+ });
151
+ }
152
+ /**
153
+ * Recursively validate that a directory contains no symlinks
154
+ *
155
+ * Security rationale:
156
+ * - Prevents copying directories that contain malicious symlinks
157
+ * - Ensures all files in the directory tree are actual files, not symlinks
158
+ *
159
+ * @param dirPath - Directory path to validate recursively
160
+ * @throws Error if any symlink is found in the directory tree
161
+ * @private
162
+ */
163
+ async function validateDirectoryNoSymlinks(dirPath) {
164
+ const entries = await fs.readdir(dirPath, { withFileTypes: true });
165
+ for (const entry of entries) {
166
+ const fullPath = path.join(dirPath, entry.name);
167
+ // Check if this entry is a symlink using lstat
168
+ const stats = await fs.lstat(fullPath);
169
+ if (stats.isSymbolicLink()) {
170
+ throw new Error(`Symlink detected in directory: ${fullPath}\n` +
171
+ `For security, symlinks are not allowed in Trinity operations.\n` +
172
+ `Please remove the symlink and use the actual file or directory instead.`);
173
+ }
174
+ // Recursively check subdirectories
175
+ if (entry.isDirectory()) {
176
+ await validateDirectoryNoSymlinks(fullPath);
177
+ }
178
+ }
179
+ }
180
+ //# sourceMappingURL=validate-path.js.map
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Trinity Method SDK - Main Entry Point
3
+ * CLI-only deployment tool - no programmatic exports
4
+ */
5
+ export {};
6
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Trinity Method SDK - Main Entry Point
3
+ * CLI-only deployment tool - no programmatic exports
4
+ */
5
+ export {};
6
+ // This SDK is a CLI tool accessed via `npx trinity deploy` and `npx trinity update`
7
+ // It does not export any programmatic APIs for library usage
8
+ //# sourceMappingURL=index.js.map