skill-any-code 1.0.0 → 1.0.1

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 (68) hide show
  1. package/dist/adapters/command.schemas.js +18 -0
  2. package/dist/application/analysis.app.service.js +264 -0
  3. package/dist/application/bootstrap.js +21 -0
  4. package/dist/application/services/llm.analysis.service.js +170 -0
  5. package/dist/common/config.js +213 -0
  6. package/dist/common/constants.js +11 -0
  7. package/dist/common/errors.js +37 -0
  8. package/dist/common/logger.js +77 -0
  9. package/dist/common/types.js +2 -0
  10. package/dist/common/ui.js +201 -0
  11. package/dist/common/utils.js +117 -0
  12. package/dist/domain/index.js +17 -0
  13. package/dist/domain/interfaces.js +2 -0
  14. package/dist/domain/services/analysis.service.js +696 -0
  15. package/dist/domain/services/incremental.service.js +81 -0
  16. package/dist/infrastructure/blacklist.service.js +71 -0
  17. package/dist/infrastructure/cache/file.hash.cache.js +140 -0
  18. package/dist/infrastructure/git/git.service.js +159 -0
  19. package/dist/infrastructure/git.service.js +157 -0
  20. package/dist/infrastructure/index.service.js +108 -0
  21. package/dist/infrastructure/llm/llm.usage.tracker.js +58 -0
  22. package/dist/infrastructure/llm/openai.client.js +141 -0
  23. package/{src/infrastructure/llm/prompt.template.ts → dist/infrastructure/llm/prompt.template.js} +31 -36
  24. package/dist/infrastructure/llm.service.js +61 -0
  25. package/dist/infrastructure/skill/skill.generator.js +83 -0
  26. package/{src/infrastructure/skill/templates/resolve.script.ts → dist/infrastructure/skill/templates/resolve.script.js} +18 -15
  27. package/dist/infrastructure/skill/templates/skill.md.template.js +47 -0
  28. package/dist/infrastructure/splitter/code.splitter.js +137 -0
  29. package/dist/infrastructure/storage.service.js +409 -0
  30. package/dist/infrastructure/worker-pool/parse.worker.impl.js +137 -0
  31. package/dist/infrastructure/worker-pool/parse.worker.js +43 -0
  32. package/dist/infrastructure/worker-pool/worker-pool.service.js +171 -0
  33. package/package.json +5 -1
  34. package/jest.config.js +0 -27
  35. package/src/adapters/command.schemas.ts +0 -21
  36. package/src/application/analysis.app.service.ts +0 -272
  37. package/src/application/bootstrap.ts +0 -35
  38. package/src/application/services/llm.analysis.service.ts +0 -237
  39. package/src/cli.ts +0 -297
  40. package/src/common/config.ts +0 -209
  41. package/src/common/constants.ts +0 -8
  42. package/src/common/errors.ts +0 -34
  43. package/src/common/logger.ts +0 -82
  44. package/src/common/types.ts +0 -385
  45. package/src/common/ui.ts +0 -228
  46. package/src/common/utils.ts +0 -81
  47. package/src/domain/index.ts +0 -1
  48. package/src/domain/interfaces.ts +0 -188
  49. package/src/domain/services/analysis.service.ts +0 -735
  50. package/src/domain/services/incremental.service.ts +0 -50
  51. package/src/index.ts +0 -6
  52. package/src/infrastructure/blacklist.service.ts +0 -37
  53. package/src/infrastructure/cache/file.hash.cache.ts +0 -119
  54. package/src/infrastructure/git/git.service.ts +0 -120
  55. package/src/infrastructure/git.service.ts +0 -121
  56. package/src/infrastructure/index.service.ts +0 -94
  57. package/src/infrastructure/llm/llm.usage.tracker.ts +0 -65
  58. package/src/infrastructure/llm/openai.client.ts +0 -162
  59. package/src/infrastructure/llm.service.ts +0 -70
  60. package/src/infrastructure/skill/skill.generator.ts +0 -53
  61. package/src/infrastructure/skill/templates/skill.md.template.ts +0 -45
  62. package/src/infrastructure/splitter/code.splitter.ts +0 -176
  63. package/src/infrastructure/storage.service.ts +0 -413
  64. package/src/infrastructure/worker-pool/parse.worker.impl.ts +0 -135
  65. package/src/infrastructure/worker-pool/parse.worker.ts +0 -9
  66. package/src/infrastructure/worker-pool/worker-pool.service.ts +0 -173
  67. package/tsconfig.json +0 -24
  68. package/tsconfig.test.json +0 -5
@@ -1,173 +0,0 @@
1
- import * as workerpool from 'workerpool'
2
- import * as path from 'path'
3
- import * as fs from 'fs'
4
- import { IWorkerPoolService } from '../../domain/interfaces'
5
- import { FileAnalysis, DirectoryAnalysis, ModificationLog, LLMConfig } from '../../common/types'
6
- import { AppError, ErrorCode } from '../../common/errors'
7
- import { DEFAULT_CONCURRENCY } from '../../common/constants'
8
- import os from 'os'
9
- import { aggregateDirectory, parseFile, validateResult } from './parse.worker.impl'
10
-
11
- export interface DirectoryAggregationPayload {
12
- childrenDirs: Array<{ name: string; summary: string; description?: string }>
13
- childrenFiles: Array<{ name: string; summary: string; description?: string }>
14
- }
15
-
16
- export interface DirectoryAggregationLLMResult {
17
- description: string
18
- summary: string
19
- }
20
-
21
- type WorkerUsageDelta = {
22
- totalPromptTokens: number
23
- totalCompletionTokens: number
24
- totalTokens: number
25
- totalCalls: number
26
- }
27
-
28
- export class WorkerPoolService implements IWorkerPoolService {
29
- private pool?: workerpool.Pool
30
- private pendingTasks: Promise<any>[] = []
31
- private currentConcurrency: number
32
- private llmConfig: LLMConfig
33
- private readonly localMode: boolean
34
-
35
- constructor(llmConfig: LLMConfig, concurrency: number = DEFAULT_CONCURRENCY) {
36
- this.currentConcurrency = concurrency
37
- this.llmConfig = {
38
- ...llmConfig,
39
- cache_dir: WorkerPoolService.expandTilde(llmConfig.cache_dir),
40
- }
41
-
42
- const workerScript = path.join(__dirname, 'parse.worker.js')
43
- this.localMode = !fs.existsSync(workerScript)
44
-
45
- // Jest/ts-jest 直接执行 src 时,parse.worker.js 不存在。此时回退到“本进程执行”以保证核心逻辑可测。
46
- // 生产构建(dist)与 CLI 运行时,parse.worker.js 存在,继续使用 worker threads 提升性能。
47
- if (!this.localMode) {
48
- this.pool = workerpool.pool(workerScript, {
49
- maxWorkers: concurrency,
50
- workerType: 'thread',
51
- })
52
- }
53
- }
54
-
55
- private static expandTilde(p: string): string {
56
- if (!p) return p
57
- if (p.startsWith('~') && (p.length === 1 || p[1] === '/' || p[1] === '\\')) {
58
- return path.join(os.homedir(), p.slice(1))
59
- }
60
- return p
61
- }
62
-
63
- async submitFileAnalysisTask(
64
- filePath: string,
65
- fileContent: string,
66
- fileHash: string,
67
- language?: string
68
- ): Promise<{ analysis: FileAnalysis; usage: WorkerUsageDelta }> {
69
- if (this.localMode) {
70
- const task = parseFile(filePath, fileContent, fileHash, language, this.llmConfig)
71
- this.pendingTasks.push(task)
72
- try {
73
- return await task
74
- } finally {
75
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
76
- }
77
- }
78
- try {
79
- const task = this.pool!.exec('parseFile', [filePath, fileContent, fileHash, language, this.llmConfig])
80
- this.pendingTasks.push(task)
81
-
82
- const result = await task
83
- // 移除已完成的任务
84
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
85
-
86
- return result
87
- } catch (e) {
88
- throw new AppError(ErrorCode.WORKER_SCHEDULE_FAILED, 'File analysis task failed', (e as Error).message)
89
- }
90
- }
91
-
92
- async submitDirectoryAggregationTask(
93
- dirPath: string,
94
- payload: DirectoryAggregationPayload
95
- ): Promise<DirectoryAggregationLLMResult & { usage: WorkerUsageDelta }> {
96
- if (this.localMode) {
97
- const task = aggregateDirectory(dirPath, payload, this.llmConfig)
98
- this.pendingTasks.push(task)
99
- try {
100
- return await task
101
- } finally {
102
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
103
- }
104
- }
105
- try {
106
- const task = this.pool!.exec('aggregateDirectory', [dirPath, payload, this.llmConfig])
107
- this.pendingTasks.push(task)
108
-
109
- const result = await task
110
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
111
-
112
- return result
113
- } catch (e) {
114
- throw new AppError(ErrorCode.WORKER_SCHEDULE_FAILED, 'Directory aggregation task failed', (e as Error).message)
115
- }
116
- }
117
-
118
- async submitValidationTask(parentResult: DirectoryAnalysis, childResult: FileAnalysis | DirectoryAnalysis): Promise<{
119
- valid: boolean
120
- corrections?: Partial<FileAnalysis | DirectoryAnalysis>
121
- log?: ModificationLog
122
- }> {
123
- if (this.localMode) {
124
- const task = validateResult(parentResult, childResult)
125
- this.pendingTasks.push(task)
126
- try {
127
- return await task
128
- } finally {
129
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
130
- }
131
- }
132
- try {
133
- const task = this.pool!.exec('validateResult', [parentResult, childResult])
134
- this.pendingTasks.push(task)
135
-
136
- const result = await task
137
- this.pendingTasks = this.pendingTasks.filter(t => t !== task)
138
-
139
- return result
140
- } catch (e) {
141
- throw new AppError(ErrorCode.WORKER_SCHEDULE_FAILED, 'Validation task failed', (e as Error).message)
142
- }
143
- }
144
-
145
- setConcurrency(concurrency: number): void {
146
- this.currentConcurrency = concurrency
147
- if (this.localMode) {
148
- return
149
- }
150
- // 立即终止旧 worker,避免遗留线程占用资源
151
- void this.pool!.terminate(true).catch(() => {})
152
- this.pool = workerpool.pool(path.join(__dirname, 'parse.worker.js'), {
153
- maxWorkers: concurrency,
154
- workerType: 'thread'
155
- })
156
- }
157
-
158
- async waitAll(): Promise<void> {
159
- await Promise.all(this.pendingTasks)
160
- }
161
-
162
- cancelAll(): void {
163
- void this.pool?.terminate(true).catch(() => {})
164
- this.pendingTasks = []
165
- }
166
-
167
- async terminate(force: boolean = true): Promise<void> {
168
- if (this.pool) {
169
- await this.pool.terminate(force)
170
- }
171
- this.pendingTasks = []
172
- }
173
- }
package/tsconfig.json DELETED
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2022",
4
- "module": "commonjs",
5
- "lib": ["ES2022"],
6
- "outDir": "./dist",
7
- "rootDir": "./src",
8
- "strict": true,
9
- "esModuleInterop": true,
10
- "skipLibCheck": true,
11
- "forceConsistentCasingInFileNames": true,
12
- "resolveJsonModule": true,
13
- "moduleResolution": "node",
14
- "experimentalDecorators": true,
15
- "emitDecoratorMetadata": true,
16
- "baseUrl": ".",
17
- "paths": {
18
- "@/*": ["src/*"]
19
- },
20
- "types": ["node", "jest"]
21
- },
22
- "include": ["src/**/*"],
23
- "exclude": ["node_modules", "dist", "coverage", "tests"]
24
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "include": ["src/**/*", "tests/**/*"],
4
- "exclude": ["node_modules", "dist", "coverage"]
5
- }