-
Notifications
You must be signed in to change notification settings - Fork 51
feat(kontext): add cross-file dependency graph tool #1458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
junghyeonsu
wants to merge
6
commits into
dev
Choose a base branch
from
feature/des-1580
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ce20a2b
feat(kontext): add dependency graph tool for cross-file relationships
junghyeonsu 6294d66
chore: resolve merge conflict with dev branch
junghyeonsu 56f19ed
fix(kontext): address CodeRabbit and CodeQL review findings
junghyeonsu 7d1e606
refactor(kontext): address CodeRabbit nitpick review findings
junghyeonsu 5301836
feat(kontext): redesign dashboard as unified view with shiki syntax h…
junghyeonsu e43a2be
refactor(kontext): simplify - delete dead code, fix perf issues
junghyeonsu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
| HOOK_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| bun run "$HOOK_DIR/kontext-deps-hook.ts" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { readFileSync, existsSync } from "node:fs"; | ||
| import { resolve, relative } from "node:path"; | ||
| import { execSync } from "node:child_process"; | ||
|
|
||
| const input = readFileSync("/dev/stdin", "utf-8"); | ||
| const { tool_response } = JSON.parse(input); | ||
| const filePath: string = tool_response?.filePath; | ||
|
|
||
| if (!filePath) process.exit(0); | ||
|
|
||
| const rootDir = resolve(import.meta.dirname, "../.."); | ||
| const relPath = relative(rootDir, resolve(filePath)); | ||
|
|
||
| // kontext 자체 파일 편집은 무시 | ||
| if (relPath.startsWith("ecosystem/kontext/") || relPath.startsWith(".kontext/")) { | ||
| process.exit(0); | ||
| } | ||
|
|
||
| // 그래프 로드 (없으면 자동 빌드) | ||
| const graphPath = resolve(rootDir, ".kontext/graph.json"); | ||
| if (!existsSync(graphPath)) { | ||
| try { | ||
| execSync("bun ecosystem/kontext/cli/bin/kontext.mjs build", { | ||
| cwd: rootDir, | ||
| stdio: "ignore", | ||
| timeout: 10000, | ||
| }); | ||
| } catch { | ||
| process.exit(0); | ||
| } | ||
| } | ||
| if (!existsSync(graphPath)) process.exit(0); | ||
|
|
||
| interface GraphEdge { | ||
| source: string; | ||
| target: string; | ||
| reason?: string; | ||
| generated: boolean; | ||
| command?: string; | ||
| } | ||
|
|
||
| interface KontextGraph { | ||
| edges: GraphEdge[]; | ||
| } | ||
|
|
||
| let graph: KontextGraph; | ||
| try { | ||
| graph = JSON.parse(readFileSync(graphPath, "utf-8")); | ||
| } catch { | ||
| process.exit(0); | ||
| } | ||
|
|
||
| // 해당 파일이 source인 엣지 찾기 | ||
| const deps = graph.edges.filter((e) => e.source === relPath); | ||
| if (deps.length === 0) process.exit(0); | ||
|
|
||
| // 결과 포맷팅 | ||
| const autoItems = deps.filter((d) => d.generated); | ||
| const manualItems = deps.filter((d) => !d.generated); | ||
|
|
||
| const lines: string[] = []; | ||
| lines.push(`KONTEXT: ${relPath}을(를) 수정했습니다.`); | ||
|
|
||
| if (manualItems.length > 0) { | ||
| lines.push(" 영향받는 파일:"); | ||
| for (const item of manualItems) { | ||
| const exists = existsSync(resolve(rootDir, item.target)); | ||
| const icon = exists ? "●" : "○"; | ||
| lines.push(` ${icon} ${item.target}${item.reason ? ` (${item.reason})` : ""}`); | ||
| } | ||
| } | ||
|
|
||
| if (autoItems.length > 0) { | ||
| lines.push(" 자동 생성 (명령 실행 필요):"); | ||
| for (const item of autoItems) { | ||
| lines.push(` ⚡ ${item.target} → ${item.command ?? "bun generate:all"}`); | ||
| } | ||
| } | ||
|
|
||
| // exit 0 + stdout JSON으로 additionalContext 전달 | ||
| // 에이전트가 다음 행동에 이 맥락을 참고함 | ||
| const output = { | ||
| additionalContext: lines.join("\n"), | ||
| }; | ||
| console.log(JSON.stringify(output)); | ||
| process.exit(0); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| *.log | ||
| *.tsbuildinfo | ||
| .ultra.cache.json | ||
| .kontext/ | ||
|
|
||
| .nyc_output/ | ||
|
|
||
|
|
||
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.