cast-code 1.0.8 → 1.0.10
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.
- package/dist/modules/core/services/deep-agent.service.js +1 -1
- package/dist/modules/core/services/deep-agent.service.js.map +1 -1
- package/dist/modules/git/services/commit-generator.service.js +432 -114
- package/dist/modules/git/services/commit-generator.service.js.map +1 -1
- package/dist/modules/kanban/kanban.module.js +36 -0
- package/dist/modules/kanban/kanban.module.js.map +1 -0
- package/dist/modules/kanban/services/kanban-server.service.js +322 -0
- package/dist/modules/kanban/services/kanban-server.service.js.map +1 -0
- package/dist/modules/kanban/views/kanban-ui.js +858 -0
- package/dist/modules/kanban/views/kanban-ui.js.map +1 -0
- package/dist/modules/repl/repl.module.js +3 -1
- package/dist/modules/repl/repl.module.js.map +1 -1
- package/dist/modules/repl/services/repl.service.js +13 -2
- package/dist/modules/repl/services/repl.service.js.map +1 -1
- package/dist/modules/tasks/services/plan-executor.service.js +2 -2
- package/dist/modules/tasks/services/plan-executor.service.js.map +1 -1
- package/dist/modules/tasks/services/task-management.service.js +35 -2
- package/dist/modules/tasks/services/task-management.service.js.map +1 -1
- package/dist/modules/tasks/types/task.types.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/git/services/commit-generator.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { execSync } from 'child_process';\nimport { HumanMessage, SystemMessage } from '@langchain/core/messages';\nimport { MultiLlmService } from '../../../common/services/multi-llm.service';\nimport { MonorepoDetectorService } from './monorepo-detector.service';\nimport { GitDiffInfo, SplitCommit, CommitGroup, MonorepoInfo } from '../types/git.types';\n\n@Injectable()\nexport class CommitGeneratorService {\n constructor(\n private readonly multiLlmService: MultiLlmService,\n private readonly monorepoDetector: MonorepoDetectorService,\n ) {}\n\n getDiffInfo(): GitDiffInfo | null {\n try {\n const cwd = process.cwd();\n const staged = execSync('git diff --cached', { cwd, encoding: 'utf-8' });\n const unstaged = execSync('git diff', { cwd, encoding: 'utf-8' });\n const stats = execSync('git diff --stat', { cwd, encoding: 'utf-8' });\n const untrackedRaw = execSync('git ls-files --others --exclude-standard', { cwd, encoding: 'utf-8' });\n const untrackedFiles = untrackedRaw.trim() ? untrackedRaw.trim().split('\\n').filter(f => f.trim()) : [];\n\n return {\n staged,\n unstaged,\n stagedFiles: this.extractFiles(staged),\n unstagedFiles: this.extractFiles(unstaged),\n untrackedFiles,\n stats,\n };\n } catch {\n return null;\n }\n }\n\n hasChanges(): boolean {\n try {\n const output = execSync('git status --porcelain', { cwd: process.cwd(), encoding: 'utf-8' });\n return output.trim().length > 0;\n } catch {\n return false;\n }\n }\n\n async generateCommitMessage(): Promise<string | null> {\n const diffInfo = this.getDiffInfo();\n if (!diffInfo) return null;\n\n const monorepoInfo = this.monorepoDetector.detectMonorepo(process.cwd());\n const allFiles = [...diffInfo.stagedFiles, ...diffInfo.unstagedFiles, ...diffInfo.untrackedFiles];\n const scope = this.monorepoDetector.determineScope(allFiles, monorepoInfo);\n\n const llm = this.multiLlmService.createModel('cheap');\n const prompt = this.buildCommitPrompt(diffInfo, scope);\n\n const response = await llm.invoke([\n new SystemMessage(this.getCommitSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n const message = this.extractContent(response.content);\n return this.cleanCommitMessage(message);\n }\n\n async splitCommits(): Promise<SplitCommit[] | null> {\n const diffInfo = this.getDiffInfo();\n if (!diffInfo) return null;\n\n const monorepoInfo = this.monorepoDetector.detectMonorepo(process.cwd());\n const allFiles = [...diffInfo.stagedFiles, ...diffInfo.unstagedFiles, ...diffInfo.untrackedFiles];\n\n const llm = this.multiLlmService.createModel('cheap');\n const splitPrompt = this.buildSplitPrompt(diffInfo, allFiles);\n\n const splitResponse = await llm.invoke([\n new SystemMessage(this.getSplitSystemPrompt()),\n new HumanMessage(splitPrompt),\n ]);\n\n const splitContent = this.extractContent(splitResponse.content);\n const commitGroups = this.parseCommitGroups(splitContent);\n\n if (!commitGroups?.length) return null;\n\n const validGroups = commitGroups.filter((group) => Array.isArray(group.files) && group.files.length > 0);\n if (validGroups.length === 0) return null;\n\n for (const group of validGroups) {\n if (!group.scope) {\n group.scope = this.monorepoDetector.determineScope(group.files, monorepoInfo);\n }\n }\n\n const splitCommits: SplitCommit[] = [];\n for (const group of validGroups) {\n const message = await this.generateMessageForGroup(group, diffInfo);\n splitCommits.push({ ...group, message });\n }\n\n return splitCommits;\n }\n\n executeCommit(message: string, autoStage = true): boolean {\n try {\n const cwd = process.cwd();\n if (autoStage) {\n execSync('git add -A', { cwd });\n }\n execSync('git commit -F -', { cwd, input: `${message}\\n`, encoding: 'utf-8' });\n return true;\n } catch {\n return false;\n }\n }\n\n executePush(): { success: boolean; error?: string } {\n try {\n const cwd = process.cwd();\n const branch = execSync('git branch --show-current', { cwd, encoding: 'utf-8' }).trim();\n execSync(`git push origin ${branch}`, { cwd, encoding: 'utf-8' });\n return { success: true };\n } catch (error: any) {\n const message = error.message || 'Push failed';\n if (message.includes('rejected') || message.includes('diverged')) {\n return { success: false, error: 'Push rejected. Run \"git pull --rebase\" first.' };\n }\n return { success: false, error: message };\n }\n }\n\n executeSplitCommits(commits: SplitCommit[]): { success: boolean; committed: number; error?: string; originalHead?: string } {\n const cwd = process.cwd();\n let committedCount = 0;\n let originalHead: string | undefined;\n\n try {\n originalHead = execSync('git rev-parse HEAD', { cwd, encoding: 'utf-8' }).trim();\n\n for (const commit of commits) {\n execSync('git reset', { cwd });\n\n for (const file of commit.files) {\n try {\n execSync(`git add \"${file}\"`, { cwd });\n } catch {}\n }\n\n const staged = execSync('git diff --cached --name-only', { cwd, encoding: 'utf-8' });\n if (!staged.trim()) continue;\n\n execSync('git commit -F -', { cwd, input: `${commit.message}\\n`, encoding: 'utf-8' });\n committedCount++;\n }\n\n return { success: true, committed: committedCount };\n } catch (error: any) {\n return {\n success: false,\n committed: committedCount,\n error: error.message || 'Failed to execute commits',\n originalHead\n };\n }\n }\n\n async refineCommitMessage(\n currentMessage: string,\n userSuggestion: string,\n diffInfo: GitDiffInfo,\n ): Promise<string> {\n const llm = this.multiLlmService.createModel('cheap');\n\n const prompt = `Current commit message: ${currentMessage}\\n\\nUser suggestion: ${userSuggestion}\\n\\nDiff:\\n${diffInfo.staged.slice(0, 3000)}`;\n\n const response = await llm.invoke([\n new SystemMessage(this.getRefineSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n const message = this.extractContent(response.content);\n return this.cleanCommitMessage(message);\n }\n\n private extractFiles(diff: string): string[] {\n const files = new Set<string>();\n const lines = diff.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('diff --git')) {\n const match = line.match(/diff --git a\\/(.+?) b\\/(.+?)$/);\n if (match) {\n files.add(match[2]);\n }\n }\n }\n\n return Array.from(files);\n }\n\n private extractContent(content: unknown): string {\n if (typeof content === 'string') return content;\n if (Array.isArray(content) && content.length > 0) {\n const first = content[0];\n if (typeof first === 'object' && first !== null && 'text' in first) {\n return String(first.text);\n }\n }\n return String(content);\n }\n\n private cleanCommitMessage(message: string): string {\n const lines = message.trim().split('\\n').map(l => l.trim()).filter(l => l.length > 0);\n const firstCommitLine = lines.find(l => l.includes(':')) || lines[0] || '';\n return firstCommitLine.replace(/^[\"']|[\"']$/g, '').trim();\n }\n\n private buildCommitPrompt(diffInfo: GitDiffInfo, scope?: string): string {\n const scopeHint = scope ? `\\n\\nThis is a monorepo. The changes are primarily in the \"${scope}\" module.` : '';\n\n let fullDiff = '';\n if (diffInfo.staged) {\n fullDiff += `=== Staged changes ===\\n${diffInfo.staged}\\n\\n`;\n }\n if (diffInfo.unstaged) {\n fullDiff += `=== Unstaged changes ===\\n${diffInfo.unstaged}\\n\\n`;\n }\n\n const untrackedHint = diffInfo.untrackedFiles.length > 0\n ? `\\nNew untracked files (will also be committed): ${diffInfo.untrackedFiles.join(', ')}\\n`\n : '';\n\n const maxLength = 10000;\n if (fullDiff.length > maxLength) {\n fullDiff = fullDiff.slice(0, maxLength) + '\\n\\n... (truncated)';\n }\n\n return `Generate a single conventional commit message for ALL of the following changes.${scopeHint}\\n\\nFiles changed:\\n${diffInfo.stats}${untrackedHint}\\n\\n${fullDiff}`;\n }\n\n private buildSplitPrompt(diffInfo: GitDiffInfo, files: string[]): string {\n let fullDiff = '';\n if (diffInfo.staged) {\n fullDiff += `=== Staged changes ===\\n${diffInfo.staged}\\n\\n`;\n }\n if (diffInfo.unstaged) {\n fullDiff += `=== Unstaged changes ===\\n${diffInfo.unstaged}\\n\\n`;\n }\n\n const allFiles = [...files, ...diffInfo.untrackedFiles.filter(f => !files.includes(f))];\n const untrackedHint = diffInfo.untrackedFiles.length > 0\n ? `\\nNew untracked files (must be included in commits): ${diffInfo.untrackedFiles.join(', ')}\\n`\n : '';\n\n const maxLength = 8000;\n if (fullDiff.length > maxLength) {\n fullDiff = fullDiff.slice(0, maxLength) + '\\n\\n... (truncated)';\n }\n\n return `Analyze all the files below and group them into logical commits. Include ALL files in the result.\\n\\nFiles: ${allFiles.join(', ')}${untrackedHint}\\n\\nStats:\\n${diffInfo.stats}\\n\\n${fullDiff}`;\n }\n\n private async generateMessageForGroup(group: CommitGroup, diffInfo: GitDiffInfo): Promise<string> {\n const llm = this.multiLlmService.createModel('cheap');\n\n const scopePart = group.scope ? `(${group.scope})` : '';\n\n const prompt = `Generate a conventional commit message (max 72 chars) for:\\n\\nType: ${group.type}${scopePart}\\nFiles: ${group.files.join(', ')}\\nDescription: ${group.description}\\n\\nIMPORTANT: Return ONLY the commit message in format: \"type(scope): description\" or \"type: description\"\\nThe message MUST be in English.`;\n\n const response = await llm.invoke([\n new SystemMessage(this.getCommitSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n let message = this.extractContent(response.content);\n message = this.cleanCommitMessage(message);\n\n if (!message.includes(':')) {\n const scope = group.scope ? `(${group.scope})` : '';\n message = `${group.type}${scope}: ${message}`;\n }\n\n return message;\n }\n\n private parseCommitGroups(content: string): CommitGroup[] | null {\n const jsonMatch = content.match(/```json\\s*([\\s\\S]*?)\\s*```/);\n if (jsonMatch) {\n try {\n const parsed = JSON.parse(jsonMatch[1]);\n if (parsed.commits && Array.isArray(parsed.commits)) {\n return parsed.commits;\n }\n } catch {}\n }\n\n try {\n const parsed = JSON.parse(content);\n if (parsed.commits && Array.isArray(parsed.commits)) {\n return parsed.commits;\n }\n } catch {}\n\n return null;\n }\n\n private getCommitSystemPrompt(): string {\n return `You are a Git commit message expert. Generate concise commit messages following Conventional Commits.\n\n**Available types:**\n- feat: new feature\n- fix: bug fix\n- docs: documentation\n- style: formatting (no logic change)\n- refactor: refactoring (no functionality change)\n- perf: performance improvement\n- test: tests\n- build: build/dependencies\n- ci: continuous integration\n- chore: general tasks\n- cleanup: code cleanup\n- remove: code removal\n\n**Format:**\n- With scope: <type>(<scope>): <description>\n- Without scope: <type>: <description>\n\n**Rules:**\n- Maximum 72 characters for the subject line\n- Description in English\n- No period at the end\n- Use imperative mood (\"add\" not \"added\")\n- Be specific but concise\n\nIf this is a monorepo and you can identify the module, include the scope.\n\nReturn ONLY the commit message, nothing else.`;\n }\n\n private getSplitSystemPrompt(): string {\n return `You are a Git commit organization expert. Analyze the changes and divide them into logical commits.\n\n**YOUR TASK:**\nGroup changes into logical commits based on:\n1. **Functional cohesion**: Changes that make sense together\n2. **Change type**: features, fixes, docs, refactorings separated\n3. **Related files**: Files that work together\n\n**RETURN FORMAT (JSON):**\nReturn ONLY valid JSON in this format:\n\\`\\`\\`json\n{\n \"commits\": [\n {\n \"type\": \"feat\",\n \"files\": [\"src/auth.ts\", \"src/models/user.ts\"],\n \"description\": \"add user authentication\"\n },\n {\n \"type\": \"docs\",\n \"files\": [\"README.md\"],\n \"description\": \"update documentation\"\n }\n ]\n}\n\\`\\`\\`\n\n**AVAILABLE TYPES:**\nfeat, fix, docs, style, refactor, perf, test, build, ci, chore\n\n**RULES:**\n- Each commit should have a clear purpose\n- Group functionally related files\n- Separate features from fixes from documentation\n- Maximum 5 files per commit (ideally fewer)\n- If diff is small (<3 files), can be 1 commit only\n- Description must ALWAYS be in English\n- Include ALL files in the result\n\n**IMPORTANT:** Return ONLY the JSON, no additional text.`;\n }\n\n private getRefineSystemPrompt(): string {\n return `You are refining a commit message based on user feedback.\n\n**Instructions:**\n- Keep the message concise (max 72 characters)\n- Follow Conventional Commits format\n- Incorporate the user's suggestion\n- Return ONLY the new commit message, without explanations\n- Message MUST be in English`;\n }\n}\n"],"names":["CommitGeneratorService","getDiffInfo","cwd","process","staged","execSync","encoding","unstaged","stats","untrackedRaw","untrackedFiles","trim","split","filter","f","stagedFiles","extractFiles","unstagedFiles","hasChanges","output","length","generateCommitMessage","diffInfo","monorepoInfo","monorepoDetector","detectMonorepo","allFiles","scope","determineScope","llm","multiLlmService","createModel","prompt","buildCommitPrompt","response","invoke","SystemMessage","getCommitSystemPrompt","HumanMessage","message","extractContent","content","cleanCommitMessage","splitCommits","splitPrompt","buildSplitPrompt","splitResponse","getSplitSystemPrompt","splitContent","commitGroups","parseCommitGroups","validGroups","group","Array","isArray","files","generateMessageForGroup","push","executeCommit","autoStage","input","executePush","branch","success","error","includes","executeSplitCommits","commits","committedCount","originalHead","commit","file","committed","refineCommitMessage","currentMessage","userSuggestion","slice","getRefineSystemPrompt","diff","Set","lines","line","startsWith","match","add","from","first","String","text","map","l","firstCommitLine","find","replace","scopeHint","fullDiff","untrackedHint","join","maxLength","scopePart","type","description","jsonMatch","parsed","JSON","parse"],"mappings":";;;;+BAQaA;;;eAAAA;;;wBARc;+BACF;0BACmB;iCACZ;yCACQ;;;;;;;;;;AAIjC,IAAA,AAAMA,yBAAN,MAAMA;IAMXC,cAAkC;QAChC,IAAI;YACF,MAAMC,MAAMC,QAAQD,GAAG;YACvB,MAAME,SAASC,IAAAA,uBAAQ,EAAC,qBAAqB;gBAAEH;gBAAKI,UAAU;YAAQ;YACtE,MAAMC,WAAWF,IAAAA,uBAAQ,EAAC,YAAY;gBAAEH;gBAAKI,UAAU;YAAQ;YAC/D,MAAME,QA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AAO;YACvB;QACF,EAAE,OAAM,CAAC;QAET,OAAO;IACT;IAEQ9B,wBAAgC;QACtC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6CA6BiC,CAAC;IAC5C;IAEQU,uBAA+B;QACrC,OAAO,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wDAuC4C,CAAC;IACvD;IAEQ8B,wBAAgC;QACtC,OAAO,CAAC;;;;;;;4BAOgB,CAAC;IAC3B;IA9XA,YACE,AAAiB/C,eAAgC,EACjD,AAAiBN,gBAAyC,CAC1D;aAFiBM,kBAAAA;aACAN,mBAAAA;IAChB;AA4XL"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/git/services/commit-generator.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { readFileSync } from 'fs';\nimport { execSync } from 'child_process';\nimport { HumanMessage, SystemMessage } from '@langchain/core/messages';\nimport { MultiLlmService } from '../../../common/services/multi-llm.service';\nimport { MonorepoDetectorService } from './monorepo-detector.service';\nimport { GitDiffInfo, SplitCommit, CommitGroup, ConventionalCommitType } from '../types/git.types';\n\nconst COMMIT_TYPES: ConventionalCommitType[] = [\n 'feat',\n 'fix',\n 'docs',\n 'style',\n 'refactor',\n 'perf',\n 'test',\n 'build',\n 'ci',\n 'chore',\n];\n\nconst COMMIT_TYPE_SET = new Set<string>(COMMIT_TYPES);\n\nconst COMMIT_TYPE_ALIASES: Record<string, ConventionalCommitType> = {\n feature: 'feat',\n features: 'feat',\n bug: 'fix',\n bugfix: 'fix',\n documentation: 'docs',\n docs: 'docs',\n test: 'test',\n tests: 'test',\n testing: 'test',\n performance: 'perf',\n optimize: 'perf',\n optimization: 'perf',\n dependency: 'build',\n dependencies: 'build',\n maintenance: 'chore',\n housekeeping: 'chore',\n cleanup: 'chore',\n remove: 'refactor',\n};\n\nconst LEADING_VERB_TRANSLATIONS: Record<string, string> = {\n add: 'adiciona',\n adds: 'adiciona',\n update: 'atualiza',\n updates: 'atualiza',\n upgrade: 'atualiza',\n upgrades: 'atualiza',\n fix: 'corrige',\n fixes: 'corrige',\n remove: 'remove',\n removes: 'remove',\n refactor: 'refatora',\n refactors: 'refatora',\n improve: 'melhora',\n improves: 'melhora',\n create: 'cria',\n creates: 'cria',\n implement: 'implementa',\n implements: 'implementa',\n rename: 'renomeia',\n renames: 'renomeia',\n};\n\n@Injectable()\nexport class CommitGeneratorService {\n constructor(\n private readonly multiLlmService: MultiLlmService,\n private readonly monorepoDetector: MonorepoDetectorService,\n ) {}\n\n getDiffInfo(): GitDiffInfo | null {\n try {\n const cwd = process.cwd();\n const staged = execSync('git diff --cached --unified=1 --no-ext-diff', { cwd, encoding: 'utf-8' });\n const unstaged = execSync('git diff --unified=1 --no-ext-diff', { cwd, encoding: 'utf-8' });\n const stagedStats = execSync('git diff --cached --stat', { cwd, encoding: 'utf-8' });\n const unstagedStats = execSync('git diff --stat', { cwd, encoding: 'utf-8' });\n const statusShort = execSync('git status --short', { cwd, encoding: 'utf-8' });\n const untrackedRaw = execSync('git ls-files --others --exclude-standard', { cwd, encoding: 'utf-8' });\n const untrackedFiles = untrackedRaw.trim() ? untrackedRaw.trim().split('\\n').filter(f => f.trim()) : [];\n\n return {\n staged,\n unstaged,\n stagedFiles: this.extractFiles(staged),\n unstagedFiles: this.extractFiles(unstaged),\n untrackedFiles,\n stats: this.buildStatsSummary(stagedStats, unstagedStats, statusShort, untrackedFiles),\n };\n } catch {\n return null;\n }\n }\n\n hasChanges(): boolean {\n try {\n const output = execSync('git status --porcelain', { cwd: process.cwd(), encoding: 'utf-8' });\n return output.trim().length > 0;\n } catch {\n return false;\n }\n }\n\n async generateCommitMessage(): Promise<string | null> {\n const diffInfo = this.getDiffInfo();\n if (!diffInfo) return null;\n\n const monorepoInfo = this.monorepoDetector.detectMonorepo(process.cwd());\n const allFiles = [...diffInfo.stagedFiles, ...diffInfo.unstagedFiles, ...diffInfo.untrackedFiles];\n const scope = this.monorepoDetector.determineScope(allFiles, monorepoInfo);\n\n const llm = this.multiLlmService.createModel('cheap');\n const prompt = this.buildCommitPrompt(diffInfo, scope);\n\n const response = await llm.invoke([\n new SystemMessage(this.getCommitSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n const message = this.extractContent(response.content);\n return this.normalizeCommitMessage(message, 'chore', scope);\n }\n\n async splitCommits(): Promise<SplitCommit[] | null> {\n const diffInfo = this.getDiffInfo();\n if (!diffInfo) return null;\n\n const monorepoInfo = this.monorepoDetector.detectMonorepo(process.cwd());\n const allFiles = [...diffInfo.stagedFiles, ...diffInfo.unstagedFiles, ...diffInfo.untrackedFiles];\n\n const llm = this.multiLlmService.createModel('cheap');\n const splitPrompt = this.buildSplitPrompt(diffInfo, allFiles);\n\n const splitResponse = await llm.invoke([\n new SystemMessage(this.getSplitSystemPrompt()),\n new HumanMessage(splitPrompt),\n ]);\n\n const splitContent = this.extractContent(splitResponse.content);\n const commitGroups = this.parseCommitGroups(splitContent);\n if (!commitGroups?.length) return null;\n\n const normalizedGroups = this.normalizeCommitGroups(commitGroups, allFiles);\n if (normalizedGroups.length === 0) return null;\n\n for (const group of normalizedGroups) {\n if (!group.scope) {\n group.scope = this.monorepoDetector.determineScope(group.files, monorepoInfo);\n }\n }\n\n const splitCommits: SplitCommit[] = [];\n for (const group of normalizedGroups) {\n const message = await this.generateMessageForGroup(group);\n splitCommits.push({ ...group, message });\n }\n\n return splitCommits;\n }\n\n executeCommit(message: string, autoStage = true): boolean {\n try {\n const cwd = process.cwd();\n if (autoStage) {\n execSync('git add -A', { cwd });\n }\n execSync('git commit -F -', { cwd, input: `${message}\\n`, encoding: 'utf-8' });\n return true;\n } catch {\n return false;\n }\n }\n\n executePush(): { success: boolean; error?: string } {\n try {\n const cwd = process.cwd();\n const branch = execSync('git branch --show-current', { cwd, encoding: 'utf-8' }).trim();\n execSync(`git push origin ${branch}`, { cwd, encoding: 'utf-8' });\n return { success: true };\n } catch (error: any) {\n const message = error.message || 'Push failed';\n if (message.includes('rejected') || message.includes('diverged')) {\n return { success: false, error: 'Push rejected. Run \"git pull --rebase\" first.' };\n }\n return { success: false, error: message };\n }\n }\n\n executeSplitCommits(commits: SplitCommit[]): { success: boolean; committed: number; error?: string; originalHead?: string } {\n const cwd = process.cwd();\n let committedCount = 0;\n let originalHead: string | undefined;\n\n try {\n originalHead = execSync('git rev-parse HEAD', { cwd, encoding: 'utf-8' }).trim();\n\n for (const commit of commits) {\n execSync('git reset', { cwd });\n\n for (const file of this.normalizeFiles(commit.files)) {\n try {\n execSync(`git add -- ${this.escapeShellArg(file)}`, { cwd });\n } catch {}\n }\n\n const staged = execSync('git diff --cached --name-only', { cwd, encoding: 'utf-8' });\n if (!staged.trim()) continue;\n\n execSync('git commit -F -', { cwd, input: `${commit.message}\\n`, encoding: 'utf-8' });\n committedCount++;\n }\n\n return { success: true, committed: committedCount };\n } catch (error: any) {\n return {\n success: false,\n committed: committedCount,\n error: error.message || 'Failed to execute commits',\n originalHead\n };\n }\n }\n\n async refineCommitMessage(\n currentMessage: string,\n userSuggestion: string,\n diffInfo: GitDiffInfo,\n ): Promise<string> {\n const llm = this.multiLlmService.createModel('cheap');\n const context = this.buildDiffContext(diffInfo, {\n maxLength: 6000,\n maxCharsPerFile: 1200,\n maxUntrackedFiles: 3,\n maxUntrackedLines: 40,\n });\n const currentMetadata = this.extractTypeAndScope(currentMessage);\n\n const prompt = `Mensagem atual: ${currentMessage}\n\nSugestão do usuário: ${userSuggestion}\n\nContexto do diff:\n${context}`;\n\n const response = await llm.invoke([\n new SystemMessage(this.getRefineSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n const message = this.extractContent(response.content);\n return this.normalizeCommitMessage(\n message,\n currentMetadata.type ?? 'chore',\n currentMetadata.scope,\n 'atualiza código',\n currentMetadata.breaking ?? false,\n );\n }\n\n private extractFiles(diff: string): string[] {\n const files = new Set<string>();\n const lines = diff.split('\\n');\n\n for (const line of lines) {\n if (line.startsWith('diff --git')) {\n const match = line.match(/diff --git a\\/(.+?) b\\/(.+?)$/);\n if (match) {\n files.add(match[2]);\n }\n }\n }\n\n return Array.from(files);\n }\n\n private extractContent(content: unknown): string {\n if (typeof content === 'string') return content;\n if (Array.isArray(content) && content.length > 0) {\n const first = content[0];\n if (typeof first === 'object' && first !== null && 'text' in first) {\n return String(first.text);\n }\n }\n return String(content);\n }\n\n private buildCommitPrompt(diffInfo: GitDiffInfo, scope?: string): string {\n const scopeHint = scope\n ? `Escopo provável do monorepo: \"${scope}\".`\n : 'Escopo do monorepo não identificado automaticamente.';\n const fullDiff = this.buildDiffContext(diffInfo, {\n maxLength: 12000,\n maxCharsPerFile: 1800,\n maxUntrackedFiles: 4,\n maxUntrackedLines: 60,\n });\n\n return `Analise TODO o contexto de mudanças e gere UMA mensagem de commit no padrão Conventional Commits.\n\n${scopeHint}\n\nRegras obrigatórias:\n- Formato: \"type(scope): descrição\", \"type: descrição\" ou com breaking \"type(scope)!: descrição\"\n- Tipos permitidos: ${COMMIT_TYPES.join(', ')}\n- Descrição em português (pt-BR), objetiva, no imperativo e sem ponto final\n- Máximo de 72 caracteres no assunto completo\n- A mensagem deve refletir a intenção principal do conjunto total de mudanças\n- Se for breaking change, inclua \"!\" após o type/scope\n- Considere staged, unstaged e arquivos novos\n\nContexto do diff:\n${fullDiff}`;\n }\n\n private buildSplitPrompt(diffInfo: GitDiffInfo, files: string[]): string {\n const allFiles = this.normalizeFiles([...files, ...diffInfo.untrackedFiles]);\n const fullDiff = this.buildDiffContext(diffInfo, {\n maxLength: 15000,\n maxCharsPerFile: 1600,\n maxUntrackedFiles: 6,\n maxUntrackedLines: 80,\n });\n\n return `Analise o diff completo e divida em commits lógicos no padrão Conventional Commits.\n\nRegras obrigatórias:\n- Cada arquivo da lista deve aparecer exatamente uma vez no resultado\n- Inclua TODOS os arquivos listados\n- Separe mudanças por coesão funcional (feature, fix, docs, refactor etc.)\n- Evite misturar objetivos diferentes no mesmo commit\n- Tipos permitidos: ${COMMIT_TYPES.join(', ')}\n- Descrição em português (pt-BR), no imperativo e sem ponto final\n\nArquivos esperados:\n${allFiles.join(', ') || '(nenhum arquivo detectado)'}\n\nContexto do diff:\n${fullDiff}`;\n }\n\n private async generateMessageForGroup(group: CommitGroup): Promise<string> {\n const llm = this.multiLlmService.createModel('cheap');\n const scopePart = group.scope ? `(${group.scope})` : '';\n const prompt = `Gere uma mensagem Conventional Commit (máximo 72 caracteres) para este grupo:\n\nTipo: ${group.type}${scopePart}\nArquivos: ${group.files.join(', ')}\nResumo: ${group.description}\n\nRetorne APENAS uma linha no formato:\n\"type(scope): descrição\", \"type: descrição\" ou \"type(scope)!: descrição\"\n\nDescrição obrigatoriamente em português (pt-BR).`;\n\n const response = await llm.invoke([\n new SystemMessage(this.getCommitSystemPrompt()),\n new HumanMessage(prompt),\n ]);\n\n const message = this.extractContent(response.content);\n return this.normalizeCommitMessage(message, group.type, group.scope, group.description);\n }\n\n private parseCommitGroups(content: string): CommitGroup[] | null {\n const jsonMatch = content.match(/```json\\s*([\\s\\S]*?)\\s*```/);\n if (jsonMatch) {\n try {\n const parsed = JSON.parse(jsonMatch[1]);\n if (parsed.commits && Array.isArray(parsed.commits)) {\n return parsed.commits;\n }\n } catch {}\n }\n\n try {\n const parsed = JSON.parse(content);\n if (parsed.commits && Array.isArray(parsed.commits)) {\n return parsed.commits;\n }\n } catch {}\n\n return null;\n }\n\n private getCommitSystemPrompt(): string {\n return `Você é especialista em mensagens de commit no padrão Conventional Commits.\n\nTipos permitidos:\n${COMMIT_TYPES.join(', ')}\n\nFormato obrigatório:\n- Com escopo: <type>(<scope>): <descrição>\n- Sem escopo: <type>: <descrição>\n- Breaking change no assunto: <type>(<scope>)!: <descrição> (ou <type>!: <descrição>)\n\nRegras:\n- Assunto completo com no máximo 72 caracteres\n- Descrição em português (pt-BR)\n- Verbo no imperativo\n- Sem ponto final\n- Seja específico e evite mensagens genéricas\n- Use escopo quando ele estiver claro\n- Tipos feat e fix devem ser usados de forma semântica (feature e correção)\n\nRetorne SOMENTE a linha do commit, sem explicações.`;\n }\n\n private getSplitSystemPrompt(): string {\n return `Você é especialista em organizar diffs em commits lógicos.\n\nTarefa:\n- Agrupar mudanças por coesão funcional\n- Separar corretamente feature, fix, docs, refactor etc.\n- Garantir que todos os arquivos apareçam exatamente uma vez\n\nFormato de resposta:\nRetorne SOMENTE JSON válido:\n\\`\\`\\`json\n{\n \"commits\": [\n {\n \"type\": \"feat\",\n \"files\": [\"src/chatbot/service.ts\"],\n \"description\": \"adiciona service de chatbot\"\n },\n {\n \"type\": \"docs\",\n \"files\": [\"README.md\"],\n \"description\": \"atualiza documentação de uso\"\n }\n ]\n}\n\\`\\`\\`\n\nRegras:\n- Tipos permitidos: ${COMMIT_TYPES.join(', ')}\n- Cada commit com propósito claro\n- Descrição em português (pt-BR), no imperativo, sem ponto final\n- Máximo recomendado de 5 arquivos por commit\n- Pode retornar 1 commit apenas se o diff for pequeno e coeso\n\nRetorne SOMENTE o JSON, sem texto adicional.`;\n }\n\n private getRefineSystemPrompt(): string {\n return `Você está refinando uma mensagem de commit a partir do feedback do usuário.\n\nInstruções:\n- Respeite Conventional Commits\n- Mantenha no máximo 72 caracteres\n- Mensagem em português (pt-BR), no imperativo e sem ponto final\n- Incorpore a sugestão do usuário sem perder precisão técnica\n\nRetorne SOMENTE a nova linha de commit.`;\n }\n\n private normalizeCommitGroups(commitGroups: CommitGroup[], files: string[]): CommitGroup[] {\n const expectedFiles = new Set(this.normalizeFiles(files));\n const usedFiles = new Set<string>();\n const normalizedGroups: CommitGroup[] = [];\n\n for (const group of commitGroups) {\n const filesFromGroup = this.normalizeFiles(Array.isArray(group.files) ? group.files : [])\n .filter((file) => expectedFiles.has(file))\n .filter((file) => {\n if (usedFiles.has(file)) {\n return false;\n }\n usedFiles.add(file);\n return true;\n });\n\n if (filesFromGroup.length === 0) continue;\n\n normalizedGroups.push({\n type: this.normalizeCommitType(group.type, this.inferTypeFromFiles(filesFromGroup)),\n files: filesFromGroup,\n description: this.normalizeDescription(group.description, 'organiza mudanças relacionadas'),\n scope: this.normalizeScope(group.scope),\n });\n }\n\n const missingFiles = this.normalizeFiles(files).filter((file) => !usedFiles.has(file));\n if (missingFiles.length > 0) {\n normalizedGroups.push({\n type: this.inferTypeFromFiles(missingFiles),\n files: missingFiles,\n description: 'organiza arquivos restantes do diff',\n });\n }\n\n return normalizedGroups;\n }\n\n private normalizeCommitMessage(\n rawMessage: string,\n fallbackType: ConventionalCommitType,\n fallbackScope?: string,\n fallbackDescription = 'atualiza código',\n fallbackBreaking = false,\n ): string {\n const candidateLine = this.extractCandidateCommitLine(rawMessage);\n const match = candidateLine.match(/^([a-zA-Z-]+)(?:\\(([^)]+)\\))?(!)?:\\s*(.+)$/);\n\n const type = this.normalizeCommitType(match?.[1], fallbackType);\n const scope = this.normalizeScope(match?.[2] ?? fallbackScope);\n const breaking = Boolean(match?.[3]) || fallbackBreaking;\n const rawDescription = match?.[4] ?? candidateLine;\n const description = this.normalizeDescription(rawDescription, fallbackDescription);\n\n const breakingFlag = breaking ? '!' : '';\n const prefix = scope\n ? `${type}(${scope})${breakingFlag}: `\n : `${type}${breakingFlag}: `;\n const maxDescriptionLength = Math.max(12, 72 - prefix.length);\n const truncatedDescription = this.truncateText(description, maxDescriptionLength);\n\n return `${prefix}${truncatedDescription}`;\n }\n\n private extractTypeAndScope(message: string): {\n type?: ConventionalCommitType;\n scope?: string;\n breaking?: boolean;\n } {\n const candidateLine = this.extractCandidateCommitLine(message);\n const match = candidateLine.match(/^([a-zA-Z-]+)(?:\\(([^)]+)\\))?(!)?:\\s*.+$/);\n if (!match) return {};\n\n return {\n type: this.normalizeCommitType(match[1], 'chore'),\n scope: this.normalizeScope(match[2]),\n breaking: Boolean(match[3]),\n };\n }\n\n private extractCandidateCommitLine(rawMessage: string): string {\n const withoutCodeBlock = rawMessage.replace(/```(?:[\\w-]+)?/g, '');\n const lines = withoutCodeBlock\n .split('\\n')\n .map((line) => line.trim())\n .filter((line) => line.length > 0)\n .map((line) => line.replace(/^[-*]\\s+/, ''));\n\n if (lines.length === 0) return '';\n\n const conventionalLine = lines.find((line) => /^[a-zA-Z-]+(?:\\([^)]+\\))?!?:\\s+/.test(line));\n if (conventionalLine) {\n return conventionalLine.replace(/^[\"'`]|[\"'`]$/g, '').trim();\n }\n\n const prefixedLine = lines.find((line) => /^commit\\s*:/i.test(line));\n if (prefixedLine) {\n return prefixedLine.replace(/^commit\\s*:/i, '').replace(/^[\"'`]|[\"'`]$/g, '').trim();\n }\n\n return lines[0].replace(/^[\"'`]|[\"'`]$/g, '').trim();\n }\n\n private normalizeCommitType(\n type: string | undefined,\n fallbackType: ConventionalCommitType,\n ): ConventionalCommitType {\n const normalized = (type || '')\n .toLowerCase()\n .trim()\n .replace(/[^a-z]/g, '');\n\n if (!normalized) return fallbackType;\n if (COMMIT_TYPE_SET.has(normalized)) return normalized as ConventionalCommitType;\n if (COMMIT_TYPE_ALIASES[normalized]) return COMMIT_TYPE_ALIASES[normalized];\n\n return fallbackType;\n }\n\n private normalizeScope(scope?: string): string | undefined {\n if (!scope) return undefined;\n\n const normalized = scope\n .trim()\n .replace(/^[\"'`]|[\"'`]$/g, '')\n .toLowerCase()\n .replace(/\\s+/g, '-')\n .replace(/[^a-z0-9/_-]/g, '-')\n .replace(/-+/g, '-')\n .replace(/^-|-$/g, '');\n\n return normalized || undefined;\n }\n\n private normalizeDescription(description: string, fallback: string): string {\n let normalized = description\n .replace(/^[\"'`]|[\"'`]$/g, '')\n .replace(/^([a-zA-Z-]+)(?:\\([^)]+\\))?!?:\\s*/, '')\n .replace(/\\s+/g, ' ')\n .trim();\n\n normalized = normalized.replace(/[.;:!?]+$/, '').trim();\n if (!normalized) normalized = fallback;\n\n normalized = this.translateLeadingVerb(normalized);\n\n if (/^[A-ZÀ-Ý]/.test(normalized)) {\n normalized = normalized.charAt(0).toLowerCase() + normalized.slice(1);\n }\n\n return normalized;\n }\n\n private translateLeadingVerb(description: string): string {\n const match = description.match(/^([a-zA-Z]+)(\\b.*)$/);\n if (!match) return description;\n\n const translated = LEADING_VERB_TRANSLATIONS[match[1].toLowerCase()];\n if (!translated) return description;\n\n return `${translated}${match[2]}`;\n }\n\n private truncateText(text: string, maxLength: number): string {\n if (text.length <= maxLength) return text;\n\n const truncated = text.slice(0, maxLength).trimEnd();\n const lastSpace = truncated.lastIndexOf(' ');\n if (lastSpace > maxLength * 0.6) {\n return truncated.slice(0, lastSpace).trimEnd();\n }\n\n return truncated;\n }\n\n private normalizeFiles(files: string[]): string[] {\n const unique = new Set<string>();\n\n for (const file of files) {\n if (typeof file !== 'string') continue;\n const normalized = file.trim().replace(/^[\"']|[\"']$/g, '');\n if (!normalized) continue;\n unique.add(normalized);\n }\n\n return Array.from(unique);\n }\n\n private buildStatsSummary(\n stagedStats: string,\n unstagedStats: string,\n statusShort: string,\n untrackedFiles: string[],\n ): string {\n const sections: string[] = [];\n\n if (statusShort.trim()) {\n sections.push(`Git status (--short):\\n${statusShort.trim()}`);\n }\n if (stagedStats.trim()) {\n sections.push(`Diff staged (--cached --stat):\\n${stagedStats.trim()}`);\n }\n if (unstagedStats.trim()) {\n sections.push(`Diff unstaged (--stat):\\n${unstagedStats.trim()}`);\n }\n if (untrackedFiles.length > 0) {\n sections.push(`Arquivos novos (${untrackedFiles.length}): ${untrackedFiles.join(', ')}`);\n }\n\n return sections.join('\\n\\n');\n }\n\n private buildDiffContext(\n diffInfo: GitDiffInfo,\n options: {\n maxLength: number;\n maxCharsPerFile: number;\n maxUntrackedFiles: number;\n maxUntrackedLines: number;\n },\n ): string {\n const sections: string[] = [];\n\n if (diffInfo.stats.trim()) {\n sections.push(`Resumo:\\n${diffInfo.stats.trim()}`);\n }\n\n sections.push(this.buildFilesSummary(diffInfo));\n\n const stagedByFile = this.limitDiffByFile(diffInfo.staged, options.maxCharsPerFile);\n if (stagedByFile) {\n sections.push(`=== STAGED ===\\n${stagedByFile}`);\n }\n\n const unstagedByFile = this.limitDiffByFile(diffInfo.unstaged, options.maxCharsPerFile);\n if (unstagedByFile) {\n sections.push(`=== UNSTAGED ===\\n${unstagedByFile}`);\n }\n\n const untrackedPreview = this.buildUntrackedPreview(\n diffInfo.untrackedFiles,\n options.maxUntrackedFiles,\n options.maxUntrackedLines,\n );\n if (untrackedPreview) {\n sections.push(`=== PREVIEW ARQUIVOS NOVOS ===\\n${untrackedPreview}`);\n }\n\n let combined = sections.filter(Boolean).join('\\n\\n');\n if (combined.length > options.maxLength) {\n combined = `${combined.slice(0, options.maxLength).trimEnd()}\\n\\n... (contexto truncado)`;\n }\n\n return combined;\n }\n\n private buildFilesSummary(diffInfo: GitDiffInfo): string {\n const lines: string[] = [];\n\n const stagedFiles = this.normalizeFiles(diffInfo.stagedFiles);\n const unstagedFiles = this.normalizeFiles(diffInfo.unstagedFiles);\n const untrackedFiles = this.normalizeFiles(diffInfo.untrackedFiles);\n\n if (stagedFiles.length > 0) {\n lines.push(`Staged (${stagedFiles.length}): ${this.summarizeFileList(stagedFiles)}`);\n }\n if (unstagedFiles.length > 0) {\n lines.push(`Unstaged (${unstagedFiles.length}): ${this.summarizeFileList(unstagedFiles)}`);\n }\n if (untrackedFiles.length > 0) {\n lines.push(`Novos (${untrackedFiles.length}): ${this.summarizeFileList(untrackedFiles)}`);\n }\n\n if (lines.length === 0) {\n return 'Arquivos afetados: nenhum arquivo identificado';\n }\n\n return `Arquivos afetados:\\n${lines.join('\\n')}`;\n }\n\n private summarizeFileList(files: string[], limit = 20): string {\n if (files.length <= limit) {\n return files.join(', ');\n }\n\n const remaining = files.length - limit;\n return `${files.slice(0, limit).join(', ')}, ... (+${remaining})`;\n }\n\n private limitDiffByFile(diff: string, maxCharsPerFile: number): string {\n if (!diff.trim()) return '';\n\n const sections = this.splitDiffByFile(diff);\n if (sections.length === 0) return '';\n\n const limitedSections = sections.map((section) => {\n if (section.length <= maxCharsPerFile) return section.trimEnd();\n return `${section.slice(0, maxCharsPerFile).trimEnd()}\\n... (diff deste arquivo truncado)`;\n });\n\n return limitedSections.join('\\n\\n');\n }\n\n private splitDiffByFile(diff: string): string[] {\n const rawSections = diff\n .split(/^diff --git /m)\n .map((section) => section.trim())\n .filter((section) => section.length > 0);\n\n return rawSections.map((section) => `diff --git ${section}`);\n }\n\n private buildUntrackedPreview(files: string[], maxFiles: number, maxLines: number): string {\n const selectedFiles = this.normalizeFiles(files).slice(0, maxFiles);\n const sections: string[] = [];\n\n for (const file of selectedFiles) {\n const preview = this.readTextFilePreview(file, maxLines);\n if (!preview) continue;\n sections.push(`--- ${file} ---\\n${preview}`);\n }\n\n if (files.length > maxFiles) {\n sections.push(`... ${files.length - maxFiles} arquivo(s) novo(s) omitido(s)`);\n }\n\n return sections.join('\\n\\n');\n }\n\n private readTextFilePreview(file: string, maxLines: number): string {\n try {\n const content = readFileSync(file, 'utf-8');\n if (content.includes('\\u0000')) {\n return '[arquivo binário omitido]';\n }\n\n if (!content.length) {\n return '[arquivo vazio]';\n }\n\n const lines = content.split('\\n');\n const preview = lines.slice(0, maxLines).join('\\n');\n const clippedPreview = preview.length > 2500 ? `${preview.slice(0, 2500)}\\n...` : preview;\n\n if (lines.length > maxLines && !clippedPreview.endsWith('\\n...')) {\n return `${clippedPreview}\\n...`;\n }\n\n return clippedPreview;\n } catch {\n return '';\n }\n }\n\n private inferTypeFromFiles(files: string[]): ConventionalCommitType {\n if (files.length === 0) return 'chore';\n\n const onlyDocs = files.every((file) =>\n /^docs\\//i.test(file)\n || /(^|\\/)README\\.md$/i.test(file)\n || /(^|\\/)CHANGELOG\\.md$/i.test(file)\n || /\\.(md|mdx|txt)$/i.test(file),\n );\n if (onlyDocs) return 'docs';\n\n const onlyTests = files.every((file) =>\n /(^|\\/)__tests__\\//.test(file)\n || /\\.(spec|test)\\.[cm]?[jt]sx?$/.test(file),\n );\n if (onlyTests) return 'test';\n\n const onlyInfra = files.every((file) =>\n /(^|\\/)package(-lock)?\\.json$/.test(file)\n || /(^|\\/)(pnpm-lock\\.yaml|yarn\\.lock)$/i.test(file)\n || /(^|\\/)Dockerfile/i.test(file)\n || /(^|\\/)docker-compose\\.ya?ml$/i.test(file)\n || /(^|\\/)\\.github\\/workflows\\//.test(file),\n );\n if (onlyInfra) return 'build';\n\n return 'chore';\n }\n\n private escapeShellArg(value: string): string {\n return `'${value.replace(/'/g, '\\'\\\\\\'\\'')}'`;\n }\n}\n"],"names":["CommitGeneratorService","COMMIT_TYPES","COMMIT_TYPE_SET","Set","COMMIT_TYPE_ALIASES","feature","features","bug","bugfix","documentation","docs","test","tests","testing","performance","optimize","optimization","dependency","dependencies","maintenance","housekeeping","cleanup","remove","LEADING_VERB_TRANSLATIONS","add","adds","update","updates","upgrade","upgrades","fix","fixes","removes","refactor","refactors","improve","improves","create","creates","implement","implements","rename","renames","getDiffInfo","cwd","process","staged","execSync","encoding","unstaged","stagedStats","unstagedStats","statusShort","untrackedRaw","untrackedFiles","trim","split","filter","f","stagedFiles","extractFiles","unstagedFiles","stats","buildStatsSummary","hasChanges","output","length","generateCommitMessage","diffInfo","monorepoInfo","monorepoDetector","detectMonorepo","allFiles","scope","determineScope","llm","multiLlmService","createModel","prompt","buildCommitPrompt","response","invoke","SystemMessage","getCommitSystemPrompt","HumanMessage","message","extractContent","content","normalizeCommitMessage","splitCommits","splitPrompt","buildSplitPrompt","splitResponse","getSplitSystemPrompt","splitContent","commitGroups","parseCommitGroups","normalizedGroups","normalizeCommitGroups","group","files","generateMessageForGroup","push","executeCommit","autoStage","input","executePush","branch","success","error","includes","executeSplitCommits","commits","committedCount","originalHead","commit","file","normalizeFiles","escapeShellArg","committed","refineCommitMessage","currentMessage","userSuggestion","context","buildDiffContext","maxLength","maxCharsPerFile","maxUntrackedFiles","maxUntrackedLines","currentMetadata","extractTypeAndScope","getRefineSystemPrompt","type","breaking","diff","lines","line","startsWith","match","Array","from","isArray","first","String","text","scopeHint","fullDiff","join","scopePart","description","jsonMatch","parsed","JSON","parse","expectedFiles","usedFiles","filesFromGroup","has","normalizeCommitType","inferTypeFromFiles","normalizeDescription","normalizeScope","missingFiles","rawMessage","fallbackType","fallbackScope","fallbackDescription","fallbackBreaking","candidateLine","extractCandidateCommitLine","Boolean","rawDescription","breakingFlag","prefix","maxDescriptionLength","Math","max","truncatedDescription","truncateText","withoutCodeBlock","replace","map","conventionalLine","find","prefixedLine","normalized","toLowerCase","undefined","fallback","translateLeadingVerb","charAt","slice","translated","truncated","trimEnd","lastSpace","lastIndexOf","unique","sections","options","buildFilesSummary","stagedByFile","limitDiffByFile","unstagedByFile","untrackedPreview","buildUntrackedPreview","combined","summarizeFileList","limit","remaining","splitDiffByFile","limitedSections","section","rawSections","maxFiles","maxLines","selectedFiles","preview","readTextFilePreview","readFileSync","clippedPreview","endsWith","onlyDocs","every","onlyTests","onlyInfra","value"],"mappings":";;;;+BAoEaA;;;eAAAA;;;wBApEc;oBACE;+BACJ;0BACmB;iCACZ;yCACQ;;;;;;;;;;AAGxC,MAAMC,eAAyC;IAC7C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,kBAAkB,IAAIC,IAAYF;AAExC,MAAMG,sBAA8D;IAClEC,SAAS;IACTC,UAAU;IACVC,KAAK;IACLC,QAAQ;IACRC,eAAe;IACfC,MAAM;IACNC,MAAM;IACNC,OAAO;IACPC,SAAS;IACTC,aAAa;IACbC,UAAU;IACVC,cAAc;IACdC,YAAY;IACZC,cAAc;IACdC,aAAa;IACbC,cAAc;IACdC,SAAS;IACTC,QAAQ;AACV;AAEA,MAAMC,4BAAoD;IACxDC,KAAK;IACLC,MAAM;IACNC,QAAQ;IACRC,SAAS;IACTC,SAAS;IACTC,UAAU;IACVC,KAAK;IACLC,OAAO;IACPT,QAAQ;IACRU,SAAS;IACTC,UAAU;IACVC,WAAW;IACXC,SAAS;IACTC,UAAU;IACVC,QAAQ;IACRC,SAAS;IACTC,WAAW;IACXC,YAAY;IACZC,QAAQ;IACRC,SAAS;AACX;AAGO,IAAA,AAAM1C,yBAAN,MAAMA;IAMX2C,cAAkC;QAChC,IAAI;YACF,M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MAAMC,YAAY7H,MAAM2H,KAAK,CAAC,CAAC3G,OAC7B,+BAA+BzG,IAAI,CAACyG,SACjC,uCAAuCzG,IAAI,CAACyG,SAC5C,oBAAoBzG,IAAI,CAACyG,SACzB,gCAAgCzG,IAAI,CAACyG,SACrC,8BAA8BzG,IAAI,CAACyG;QAExC,IAAI6G,WAAW,OAAO;QAEtB,OAAO;IACT;IAEQ3G,eAAe4G,KAAa,EAAU;QAC5C,OAAO,CAAC,CAAC,EAAEA,MAAM9C,OAAO,CAAC,MAAM,YAAY,CAAC,CAAC;IAC/C;IAxwBA,YACE,AAAiBxG,eAAgC,EACjD,AAAiBN,gBAAyC,CAC1D;aAFiBM,kBAAAA;aACAN,mBAAAA;IAChB;AAswBL"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "KanbanModule", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return KanbanModule;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _tasksmodule = require("../tasks/tasks.module");
|
|
13
|
+
const _kanbanserverservice = require("./services/kanban-server.service");
|
|
14
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
15
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
16
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
17
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
18
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
19
|
+
}
|
|
20
|
+
let KanbanModule = class KanbanModule {
|
|
21
|
+
};
|
|
22
|
+
KanbanModule = _ts_decorate([
|
|
23
|
+
(0, _common.Module)({
|
|
24
|
+
imports: [
|
|
25
|
+
_tasksmodule.TasksModule
|
|
26
|
+
],
|
|
27
|
+
providers: [
|
|
28
|
+
_kanbanserverservice.KanbanServerService
|
|
29
|
+
],
|
|
30
|
+
exports: [
|
|
31
|
+
_kanbanserverservice.KanbanServerService
|
|
32
|
+
]
|
|
33
|
+
})
|
|
34
|
+
], KanbanModule);
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=kanban.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/modules/kanban/kanban.module.ts"],"sourcesContent":["import { Module } from '@nestjs/common';\nimport { TasksModule } from '../tasks/tasks.module';\nimport { KanbanServerService } from './services/kanban-server.service';\n\n@Module({\n imports: [TasksModule],\n providers: [KanbanServerService],\n exports: [KanbanServerService],\n})\nexport class KanbanModule {}\n"],"names":["KanbanModule","imports","TasksModule","providers","KanbanServerService","exports"],"mappings":";;;;+BASaA;;;eAAAA;;;wBATU;6BACK;qCACQ;;;;;;;AAO7B,IAAA,AAAMA,eAAN,MAAMA;AAAc;;;QAJzBC,SAAS;YAACC,wBAAW;SAAC;QACtBC,WAAW;YAACC,wCAAmB;SAAC;QAChCC,SAAS;YAACD,wCAAmB;SAAC"}
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "KanbanServerService", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return KanbanServerService;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("@nestjs/common");
|
|
12
|
+
const _core = require("@nestjs/core");
|
|
13
|
+
const _http = /*#__PURE__*/ _interop_require_wildcard(require("http"));
|
|
14
|
+
const _child_process = require("child_process");
|
|
15
|
+
const _taskmanagementservice = require("../../tasks/services/task-management.service");
|
|
16
|
+
const _kanbanui = require("../views/kanban-ui");
|
|
17
|
+
const _tasktypes = require("../../tasks/types/task.types");
|
|
18
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
19
|
+
if (typeof WeakMap !== "function") return null;
|
|
20
|
+
var cacheBabelInterop = new WeakMap();
|
|
21
|
+
var cacheNodeInterop = new WeakMap();
|
|
22
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
23
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
24
|
+
})(nodeInterop);
|
|
25
|
+
}
|
|
26
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
27
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
28
|
+
return obj;
|
|
29
|
+
}
|
|
30
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
31
|
+
return {
|
|
32
|
+
default: obj
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
36
|
+
if (cache && cache.has(obj)) {
|
|
37
|
+
return cache.get(obj);
|
|
38
|
+
}
|
|
39
|
+
var newObj = {
|
|
40
|
+
__proto__: null
|
|
41
|
+
};
|
|
42
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
43
|
+
for(var key in obj){
|
|
44
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
45
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
46
|
+
if (desc && (desc.get || desc.set)) {
|
|
47
|
+
Object.defineProperty(newObj, key, desc);
|
|
48
|
+
} else {
|
|
49
|
+
newObj[key] = obj[key];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
newObj.default = obj;
|
|
54
|
+
if (cache) {
|
|
55
|
+
cache.set(obj, newObj);
|
|
56
|
+
}
|
|
57
|
+
return newObj;
|
|
58
|
+
}
|
|
59
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
60
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
61
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
62
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
63
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
64
|
+
}
|
|
65
|
+
function _ts_metadata(k, v) {
|
|
66
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
67
|
+
}
|
|
68
|
+
let KanbanServerService = class KanbanServerService {
|
|
69
|
+
async getDeepAgent() {
|
|
70
|
+
if (!this.deepAgent) {
|
|
71
|
+
const { DeepAgentService } = await Promise.resolve().then(()=>/*#__PURE__*/ _interop_require_wildcard(require("../../core/services/deep-agent.service")));
|
|
72
|
+
this.deepAgent = this.moduleRef.get(DeepAgentService, {
|
|
73
|
+
strict: false
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return this.deepAgent;
|
|
77
|
+
}
|
|
78
|
+
start() {
|
|
79
|
+
if (this.server) {
|
|
80
|
+
process.stdout.write(` Kanban already running at http://localhost:${this.port}\r\n`);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
this.server = _http.createServer((req, res)=>this.handleRequest(req, res));
|
|
84
|
+
this.server.listen(this.port, ()=>{
|
|
85
|
+
process.stdout.write(` Kanban: http://localhost:${this.port}\r\n`);
|
|
86
|
+
(0, _child_process.exec)(`xdg-open http://localhost:${this.port}`);
|
|
87
|
+
});
|
|
88
|
+
this.taskService.events.on('task:created', (task)=>this.broadcast('task:created', task));
|
|
89
|
+
this.taskService.events.on('task:updated', (task)=>this.broadcast('task:updated', task));
|
|
90
|
+
this.taskService.events.on('plan:created', (plan)=>this.broadcast('plan:created', plan));
|
|
91
|
+
process.on('exit', ()=>this.stop());
|
|
92
|
+
}
|
|
93
|
+
stop() {
|
|
94
|
+
if (!this.server) return;
|
|
95
|
+
for (const client of this.sseClients){
|
|
96
|
+
try {
|
|
97
|
+
client.end();
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
this.sseClients = [];
|
|
101
|
+
this.server.close();
|
|
102
|
+
this.server = null;
|
|
103
|
+
}
|
|
104
|
+
isRunning() {
|
|
105
|
+
return this.server !== null;
|
|
106
|
+
}
|
|
107
|
+
async handleRequest(req, res) {
|
|
108
|
+
const url = req.url || '/';
|
|
109
|
+
const method = req.method || 'GET';
|
|
110
|
+
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
111
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
|
|
112
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-Type');
|
|
113
|
+
if (method === 'OPTIONS') {
|
|
114
|
+
res.writeHead(204);
|
|
115
|
+
res.end();
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (url === '/api/events') {
|
|
119
|
+
this.handleSSE(res);
|
|
120
|
+
} else if (url === '/api/state') {
|
|
121
|
+
this.handleState(res);
|
|
122
|
+
} else if (url === '/api/tasks' && method === 'POST') {
|
|
123
|
+
await this.handleCreateTask(req, res);
|
|
124
|
+
} else if (url === '/api/tasks/auto-execute' && method === 'POST') {
|
|
125
|
+
await this.handleAutoExecute(res);
|
|
126
|
+
} else if (url.startsWith('/api/tasks/') && method === 'PATCH') {
|
|
127
|
+
const parts = url.split('/');
|
|
128
|
+
const taskId = parts[parts.length - 1];
|
|
129
|
+
await this.handleUpdateTask(taskId, req, res);
|
|
130
|
+
} else if (url.startsWith('/api/tasks/') && url.endsWith('/execute') && method === 'POST') {
|
|
131
|
+
const parts = url.split('/');
|
|
132
|
+
const taskId = parts[parts.length - 2];
|
|
133
|
+
await this.handleExecuteTask(taskId, res);
|
|
134
|
+
} else {
|
|
135
|
+
res.writeHead(200, {
|
|
136
|
+
'Content-Type': 'text/html; charset=utf-8'
|
|
137
|
+
});
|
|
138
|
+
res.end((0, _kanbanui.getKanbanHtml)());
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
handleSSE(res) {
|
|
142
|
+
res.writeHead(200, {
|
|
143
|
+
'Content-Type': 'text/event-stream',
|
|
144
|
+
'Cache-Control': 'no-cache',
|
|
145
|
+
'Connection': 'keep-alive'
|
|
146
|
+
});
|
|
147
|
+
res.write(':\n\n');
|
|
148
|
+
this.sseClients.push(res);
|
|
149
|
+
res.on('close', ()=>{
|
|
150
|
+
this.sseClients = this.sseClients.filter((c)=>c !== res);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
handleState(res) {
|
|
154
|
+
const tasks = this.taskService.listTasks();
|
|
155
|
+
const plans = Array.from(this.taskService.getPlans().values());
|
|
156
|
+
const body = JSON.stringify({
|
|
157
|
+
tasks,
|
|
158
|
+
plans
|
|
159
|
+
});
|
|
160
|
+
res.writeHead(200, {
|
|
161
|
+
'Content-Type': 'application/json'
|
|
162
|
+
});
|
|
163
|
+
res.end(body);
|
|
164
|
+
}
|
|
165
|
+
async handleCreateTask(req, res) {
|
|
166
|
+
let body = '';
|
|
167
|
+
req.on('data', (chunk)=>body += chunk);
|
|
168
|
+
req.on('end', ()=>{
|
|
169
|
+
try {
|
|
170
|
+
const { subject, description } = JSON.parse(body);
|
|
171
|
+
const task = this.taskService.createTask({
|
|
172
|
+
subject,
|
|
173
|
+
description
|
|
174
|
+
});
|
|
175
|
+
res.writeHead(201, {
|
|
176
|
+
'Content-Type': 'application/json'
|
|
177
|
+
});
|
|
178
|
+
res.end(JSON.stringify(task));
|
|
179
|
+
} catch (err) {
|
|
180
|
+
res.writeHead(400);
|
|
181
|
+
res.end(JSON.stringify({
|
|
182
|
+
error: 'Invalid JSON'
|
|
183
|
+
}));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
async handleUpdateTask(taskId, req, res) {
|
|
188
|
+
let body = '';
|
|
189
|
+
req.on('data', (chunk)=>body += chunk);
|
|
190
|
+
req.on('end', async ()=>{
|
|
191
|
+
try {
|
|
192
|
+
const updates = JSON.parse(body);
|
|
193
|
+
const oldTask = this.taskService.getTask(taskId);
|
|
194
|
+
const task = this.taskService.updateTask(taskId, updates);
|
|
195
|
+
if (task) {
|
|
196
|
+
res.writeHead(200, {
|
|
197
|
+
'Content-Type': 'application/json'
|
|
198
|
+
});
|
|
199
|
+
res.end(JSON.stringify(task));
|
|
200
|
+
if (updates.status === _tasktypes.TaskStatus.IN_PROGRESS && oldTask?.status !== _tasktypes.TaskStatus.IN_PROGRESS) {
|
|
201
|
+
this.runAgentForTask(task);
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
res.writeHead(404);
|
|
205
|
+
res.end(JSON.stringify({
|
|
206
|
+
error: 'Task not found'
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
} catch (err) {
|
|
210
|
+
res.writeHead(400);
|
|
211
|
+
res.end(JSON.stringify({
|
|
212
|
+
error: 'Invalid JSON'
|
|
213
|
+
}));
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async handleAutoExecute(res) {
|
|
218
|
+
const tasks = this.taskService.listTasks().filter((t)=>t.status === _tasktypes.TaskStatus.PENDING || t.status === _tasktypes.TaskStatus.FAILED);
|
|
219
|
+
if (tasks.length === 0) {
|
|
220
|
+
res.writeHead(200);
|
|
221
|
+
res.end(JSON.stringify({
|
|
222
|
+
message: 'No tasks to execute'
|
|
223
|
+
}));
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
res.writeHead(202);
|
|
227
|
+
res.end(JSON.stringify({
|
|
228
|
+
message: 'Auto-planning started'
|
|
229
|
+
}));
|
|
230
|
+
(async ()=>{
|
|
231
|
+
try {
|
|
232
|
+
const agent = await this.getDeepAgent();
|
|
233
|
+
const taskList = tasks.map((t)=>`- [${t.id}] ${t.subject}: ${t.description}`).join('\n');
|
|
234
|
+
const prompt = `Você é o Coordenador do Kanban. Existem as seguintes tarefas pendentes:\n\n${taskList}\n\n` + `Sua missão é executá-las. Para que o usuário veja seu progresso no Board, você DEVE seguir este protocolo rigidamente:\n` + `1. Escolha a tarefa mais prioritária.\n` + `2. Chame 'task_update' com status='in_progress' para o ID da tarefa ANTES de começar.\n` + `3. Execute o trabalho necessário.\n` + `4. Chame 'task_update' com status='completed' assim que terminar.\n` + `5. Repita para a próxima tarefa.\n\n` + `Pode começar agora.`;
|
|
235
|
+
process.stdout.write(`\n Kanban: Starting intelligent auto-planner for ${tasks.length} tasks...\r\n`);
|
|
236
|
+
for await (const chunk of agent.chat(prompt)){
|
|
237
|
+
process.stdout.write(chunk);
|
|
238
|
+
}
|
|
239
|
+
} catch (err) {
|
|
240
|
+
process.stdout.write(` Kanban: Auto-planner error: ${err}\r\n`);
|
|
241
|
+
}
|
|
242
|
+
})();
|
|
243
|
+
}
|
|
244
|
+
async handleExecuteTask(taskId, res) {
|
|
245
|
+
const task = this.taskService.getTask(taskId);
|
|
246
|
+
if (!task) {
|
|
247
|
+
res.writeHead(404);
|
|
248
|
+
res.end(JSON.stringify({
|
|
249
|
+
error: 'Task not found'
|
|
250
|
+
}));
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
if (task.status !== _tasktypes.TaskStatus.PENDING && task.status !== _tasktypes.TaskStatus.FAILED) {
|
|
254
|
+
res.writeHead(400);
|
|
255
|
+
res.end(JSON.stringify({
|
|
256
|
+
error: 'Task already in progress or completed'
|
|
257
|
+
}));
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
res.writeHead(202);
|
|
261
|
+
res.end(JSON.stringify({
|
|
262
|
+
message: 'Execution started'
|
|
263
|
+
}));
|
|
264
|
+
this.runAgentForTask(task);
|
|
265
|
+
}
|
|
266
|
+
async runAgentForTask(task) {
|
|
267
|
+
const taskId = task.id;
|
|
268
|
+
(async ()=>{
|
|
269
|
+
try {
|
|
270
|
+
process.stdout.write(`\n Kanban: Starting task ${taskId}: ${task.subject}\r\n`);
|
|
271
|
+
this.taskService.updateTask(taskId, {
|
|
272
|
+
status: _tasktypes.TaskStatus.IN_PROGRESS,
|
|
273
|
+
assignedAgent: 'deep-agent'
|
|
274
|
+
});
|
|
275
|
+
const agent = await this.getDeepAgent();
|
|
276
|
+
const result = await agent.executeTask(task);
|
|
277
|
+
if (result.success) {
|
|
278
|
+
this.taskService.updateTask(taskId, {
|
|
279
|
+
status: _tasktypes.TaskStatus.COMPLETED
|
|
280
|
+
});
|
|
281
|
+
process.stdout.write(` Kanban: Task ${taskId} completed\r\n`);
|
|
282
|
+
} else {
|
|
283
|
+
this.taskService.updateTask(taskId, {
|
|
284
|
+
status: _tasktypes.TaskStatus.FAILED
|
|
285
|
+
});
|
|
286
|
+
process.stdout.write(` Kanban: Task ${taskId} failed: ${result.error}\r\n`);
|
|
287
|
+
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
this.taskService.updateTask(taskId, {
|
|
290
|
+
status: _tasktypes.TaskStatus.FAILED
|
|
291
|
+
});
|
|
292
|
+
process.stdout.write(` Kanban: Error executing task ${taskId}: ${err}\r\n`);
|
|
293
|
+
}
|
|
294
|
+
})();
|
|
295
|
+
}
|
|
296
|
+
broadcast(event, data) {
|
|
297
|
+
const payload = `event: ${event}\ndata: ${JSON.stringify(data)}\n\n`;
|
|
298
|
+
for (const client of this.sseClients){
|
|
299
|
+
try {
|
|
300
|
+
client.write(payload);
|
|
301
|
+
} catch {}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
constructor(taskService, moduleRef){
|
|
305
|
+
this.taskService = taskService;
|
|
306
|
+
this.moduleRef = moduleRef;
|
|
307
|
+
this.server = null;
|
|
308
|
+
this.sseClients = [];
|
|
309
|
+
this.port = 3333;
|
|
310
|
+
this.deepAgent = null;
|
|
311
|
+
}
|
|
312
|
+
};
|
|
313
|
+
KanbanServerService = _ts_decorate([
|
|
314
|
+
(0, _common.Injectable)(),
|
|
315
|
+
_ts_metadata("design:type", Function),
|
|
316
|
+
_ts_metadata("design:paramtypes", [
|
|
317
|
+
typeof _taskmanagementservice.TaskManagementService === "undefined" ? Object : _taskmanagementservice.TaskManagementService,
|
|
318
|
+
typeof _core.ModuleRef === "undefined" ? Object : _core.ModuleRef
|
|
319
|
+
])
|
|
320
|
+
], KanbanServerService);
|
|
321
|
+
|
|
322
|
+
//# sourceMappingURL=kanban-server.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/kanban/services/kanban-server.service.ts"],"sourcesContent":["import { Injectable } from '@nestjs/common';\nimport { ModuleRef } from '@nestjs/core';\nimport * as http from 'http';\nimport { exec } from 'child_process';\nimport { TaskManagementService } from '../../tasks/services/task-management.service';\nimport { getKanbanHtml } from '../views/kanban-ui';\nimport { TaskStatus } from '../../tasks/types/task.types';\n\n@Injectable()\nexport class KanbanServerService {\n private server: http.Server | null = null;\n private sseClients: http.ServerResponse[] = [];\n private port = 3333;\n private deepAgent: any = null;\n\n constructor(\n private readonly taskService: TaskManagementService,\n private readonly moduleRef: ModuleRef\n ) {}\n\n private async getDeepAgent() {\n if (!this.deepAgent) {\n const { DeepAgentService } = await import('../../core/services/deep-agent.service');\n this.deepAgent = this.moduleRef.get(DeepAgentService, { strict: false });\n }\n return this.deepAgent;\n }\n\n start(): void {\n if (this.server) {\n process.stdout.write(` Kanban already running at http://localhost:${this.port}\\r\\n`);\n return;\n }\n\n this.server = http.createServer((req, res) => this.handleRequest(req, res));\n\n this.server.listen(this.port, () => {\n process.stdout.write(` Kanban: http://localhost:${this.port}\\r\\n`);\n exec(`xdg-open http://localhost:${this.port}`);\n });\n\n this.taskService.events.on('task:created', (task) => this.broadcast('task:created', task));\n this.taskService.events.on('task:updated', (task) => this.broadcast('task:updated', task));\n this.taskService.events.on('plan:created', (plan) => this.broadcast('plan:created', plan));\n\n process.on('exit', () => this.stop());\n }\n\n stop(): void {\n if (!this.server) return;\n for (const client of this.sseClients) {\n try { client.end(); } catch {}\n }\n this.sseClients = [];\n this.server.close();\n this.server = null;\n }\n\n isRunning(): boolean {\n return this.server !== null;\n }\n\n private async handleRequest(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {\n const url = req.url || '/';\n const method = req.method || 'GET';\n\n res.setHeader('Access-Control-Allow-Origin', '*');\n res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');\n res.setHeader('Access-Control-Allow-Headers', 'Content-Type');\n\n if (method === 'OPTIONS') {\n res.writeHead(204);\n res.end();\n return;\n }\n\n if (url === '/api/events') {\n this.handleSSE(res);\n } else if (url === '/api/state') {\n this.handleState(res);\n } else if (url === '/api/tasks' && method === 'POST') {\n await this.handleCreateTask(req, res);\n } else if (url === '/api/tasks/auto-execute' && method === 'POST') {\n await this.handleAutoExecute(res);\n } else if (url.startsWith('/api/tasks/') && method === 'PATCH') {\n const parts = url.split('/');\n const taskId = parts[parts.length - 1];\n await this.handleUpdateTask(taskId, req, res);\n } else if (url.startsWith('/api/tasks/') && url.endsWith('/execute') && method === 'POST') {\n const parts = url.split('/');\n const taskId = parts[parts.length - 2];\n await this.handleExecuteTask(taskId, res);\n } else {\n res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });\n res.end(getKanbanHtml());\n }\n }\n\n private handleSSE(res: http.ServerResponse): void {\n res.writeHead(200, {\n 'Content-Type': 'text/event-stream',\n 'Cache-Control': 'no-cache',\n 'Connection': 'keep-alive',\n });\n res.write(':\\n\\n');\n\n this.sseClients.push(res);\n\n res.on('close', () => {\n this.sseClients = this.sseClients.filter(c => c !== res);\n });\n }\n\n private handleState(res: http.ServerResponse): void {\n const tasks = this.taskService.listTasks();\n const plans = Array.from(this.taskService.getPlans().values());\n const body = JSON.stringify({ tasks, plans });\n\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(body);\n }\n\n private async handleCreateTask(req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {\n let body = '';\n req.on('data', chunk => body += chunk);\n req.on('end', () => {\n try {\n const { subject, description } = JSON.parse(body);\n const task = this.taskService.createTask({ subject, description });\n res.writeHead(201, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify(task));\n } catch (err) {\n res.writeHead(400);\n res.end(JSON.stringify({ error: 'Invalid JSON' }));\n }\n });\n }\n\n private async handleUpdateTask(taskId: string, req: http.IncomingMessage, res: http.ServerResponse): Promise<void> {\n let body = '';\n req.on('data', chunk => body += chunk);\n req.on('end', async () => {\n try {\n const updates = JSON.parse(body);\n const oldTask = this.taskService.getTask(taskId);\n const task = this.taskService.updateTask(taskId, updates);\n \n if (task) {\n res.writeHead(200, { 'Content-Type': 'application/json' });\n res.end(JSON.stringify(task));\n\n if (updates.status === TaskStatus.IN_PROGRESS && oldTask?.status !== TaskStatus.IN_PROGRESS) {\n this.runAgentForTask(task);\n }\n } else {\n res.writeHead(404);\n res.end(JSON.stringify({ error: 'Task not found' }));\n }\n } catch (err) {\n res.writeHead(400);\n res.end(JSON.stringify({ error: 'Invalid JSON' }));\n }\n });\n }\n\n private async handleAutoExecute(res: http.ServerResponse): Promise<void> {\n const tasks = this.taskService.listTasks().filter(t => t.status === TaskStatus.PENDING || t.status === TaskStatus.FAILED);\n \n if (tasks.length === 0) {\n res.writeHead(200);\n res.end(JSON.stringify({ message: 'No tasks to execute' }));\n return;\n }\n\n res.writeHead(202);\n res.end(JSON.stringify({ message: 'Auto-planning started' }));\n\n (async () => {\n try {\n const agent = await this.getDeepAgent();\n const taskList = tasks.map(t => `- [${t.id}] ${t.subject}: ${t.description}`).join('\\n');\n \n const prompt = `Você é o Coordenador do Kanban. Existem as seguintes tarefas pendentes:\\n\\n${taskList}\\n\\n` +\n `Sua missão é executá-las. Para que o usuário veja seu progresso no Board, você DEVE seguir este protocolo rigidamente:\\n` +\n `1. Escolha a tarefa mais prioritária.\\n` +\n `2. Chame 'task_update' com status='in_progress' para o ID da tarefa ANTES de começar.\\n` +\n `3. Execute o trabalho necessário.\\n` +\n `4. Chame 'task_update' com status='completed' assim que terminar.\\n` +\n `5. Repita para a próxima tarefa.\\n\\n` +\n `Pode começar agora.`;\n \n process.stdout.write(`\\n Kanban: Starting intelligent auto-planner for ${tasks.length} tasks...\\r\\n`);\n \n for await (const chunk of agent.chat(prompt)) {\n process.stdout.write(chunk);\n }\n } catch (err) {\n process.stdout.write(` Kanban: Auto-planner error: ${err}\\r\\n`);\n }\n })();\n }\n\n private async handleExecuteTask(taskId: string, res: http.ServerResponse): Promise<void> {\n const task = this.taskService.getTask(taskId);\n if (!task) {\n res.writeHead(404);\n res.end(JSON.stringify({ error: 'Task not found' }));\n return;\n }\n\n if (task.status !== TaskStatus.PENDING && task.status !== TaskStatus.FAILED) {\n res.writeHead(400);\n res.end(JSON.stringify({ error: 'Task already in progress or completed' }));\n return;\n }\n\n res.writeHead(202);\n res.end(JSON.stringify({ message: 'Execution started' }));\n\n this.runAgentForTask(task);\n }\n\n private async runAgentForTask(task: any): Promise<void> {\n const taskId = task.id;\n (async () => {\n try {\n process.stdout.write(`\\n Kanban: Starting task ${taskId}: ${task.subject}\\r\\n`);\n this.taskService.updateTask(taskId, { status: TaskStatus.IN_PROGRESS, assignedAgent: 'deep-agent' });\n \n const agent = await this.getDeepAgent();\n const result = await agent.executeTask(task);\n \n if (result.success) {\n this.taskService.updateTask(taskId, { status: TaskStatus.COMPLETED });\n process.stdout.write(` Kanban: Task ${taskId} completed\\r\\n`);\n } else {\n this.taskService.updateTask(taskId, { status: TaskStatus.FAILED });\n process.stdout.write(` Kanban: Task ${taskId} failed: ${result.error}\\r\\n`);\n }\n } catch (err) {\n this.taskService.updateTask(taskId, { status: TaskStatus.FAILED });\n process.stdout.write(` Kanban: Error executing task ${taskId}: ${err}\\r\\n`);\n }\n })();\n }\n\n private broadcast(event: string, data: unknown): void {\n const payload = `event: ${event}\\ndata: ${JSON.stringify(data)}\\n\\n`;\n for (const client of this.sseClients) {\n try { client.write(payload); } catch {}\n }\n }\n}\n"],"names":["KanbanServerService","getDeepAgent","deepAgent","DeepAgentService","moduleRef","get","strict","start","server","process","stdout","write","port","http","createServer","req","res","handleRequest","listen","exec","taskService","events","on","task","broadcast","plan","stop","client","sseClients","end","close","isRunning","url","method","setHeader","writeHead","handleSSE","handleState","handleCreateTask","handleAutoExecute","startsWith","parts","split","taskId","length","handleUpdateTask","endsWith","handleExecuteTask","getKanbanHtml","push","filter","c","tasks","listTasks","plans","Array","from","getPlans","values","body","JSON","stringify","chunk","subject","description","parse","createTask","err","error","updates","oldTask","getTask","updateTask","status","TaskStatus","IN_PROGRESS","runAgentForTask","t","PENDING","FAILED","message","agent","taskList","map","id","join","prompt","chat","assignedAgent","result","executeTask","success","COMPLETED","event","data","payload"],"mappings":";;;;+BASaA;;;eAAAA;;;wBATc;sBACD;8DACJ;+BACD;uCACiB;0BACR;2BACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGpB,IAAA,AAAMA,sBAAN,MAAMA;IAWX,MAAcC,eAAe;QAC3B,IAAI,CAAC,IAAI,CAACC,SAAS,EAAE;YACnB,MAAM,EAAEC,gBAAgB,EAAE,GAAG,MAAM,mEAAA,QAAO;YAC1C,IAAI,CAACD,SAAS,GAAG,IAAI,CAACE,SAAS,CAACC,GAAG,CAACF,kBAAkB;gBAAEG,QAAQ;YAAM;QACxE;QACA,OAAO,IAAI,CAACJ,SAAS;IACvB;IAEAK,QAAc;QACZ,IAAI,IAAI,CAACC,MAAM,EAAE;YACfC,QAAQC,MAAM,CAACC,KAAK,CAAC,CAAC,6CAA6C,EAAE,IAAI,CAACC,IAAI,CAAC,IAAI,CAAC;YACpF;QACF;QAEA,IAAI,CAACJ,MAAM,GAAGK,MAAKC,YAAY,CAAC,CAACC,KAAKC,MAAQ,IAAI,CAACC,aAAa,CAACF,KAAKC;QAEtE,IAAI,CAACR,MAAM,CAACU,MAAM,CAAC,IAAI,CAACN,I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