开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 129

monkey_cici/claude-code-source-code

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
标签 (1)
main
v0.1.0
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
main
分支 (1)
标签 (1)
main
v0.1.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
标签 (1)
main
v0.1.0
claude-code-source-code
/
src
/
utils
/
githubRepoPathMapping.ts
claude-code-source-code
/
src
/
utils
/
githubRepoPathMapping.ts
githubRepoPathMapping.ts 5.01 KB
一键复制 编辑 原始数据 按行查看 历史
sanbucat 提交于 2026年03月31日 17:08 +08:00 . v2.1.88 反编译源码
import { realpath } from 'fs/promises'
import { getOriginalCwd } from '../bootstrap/state.js'
import { getGlobalConfig, saveGlobalConfig } from './config.js'
import { logForDebugging } from './debug.js'
import {
detectCurrentRepository,
parseGitHubRepository,
} from './detectRepository.js'
import { pathExists } from './file.js'
import { getRemoteUrlForDir } from './git/gitFilesystem.js'
import { findGitRoot } from './git.js'
/**
* Updates the GitHub repository path mapping in global config.
* Called at startup (fire-and-forget) to track known local paths for repos.
* This is non-blocking and errors are logged silently.
*
* Stores the git root (not cwd) so the mapping always points to the
* repository root regardless of which subdirectory the user launched from.
* If the path is already tracked, it is promoted to the front of the list
* so the most recently used clone appears first.
*/
export async function updateGithubRepoPathMapping(): Promise<void> {
try {
const repo = await detectCurrentRepository()
if (!repo) {
logForDebugging(
'Not in a GitHub repository, skipping path mapping update',
)
return
}
// Use the git root as the canonical path for this repo clone.
// This ensures we always store the repo root, not an arbitrary subdirectory.
const cwd = getOriginalCwd()
const gitRoot = findGitRoot(cwd)
const basePath = gitRoot ?? cwd
// Resolve symlinks for canonical storage
let currentPath: string
try {
currentPath = (await realpath(basePath)).normalize('NFC')
} catch {
currentPath = basePath
}
// Normalize repo key to lowercase for case-insensitive matching
const repoKey = repo.toLowerCase()
const config = getGlobalConfig()
const existingPaths = config.githubRepoPaths?.[repoKey] ?? []
if (existingPaths[0] === currentPath) {
// Already at the front — nothing to do
logForDebugging(`Path ${currentPath} already tracked for repo ${repoKey}`)
return
}
// Remove if present elsewhere (to promote to front), then prepend
const withoutCurrent = existingPaths.filter(p => p !== currentPath)
const updatedPaths = [currentPath, ...withoutCurrent]
saveGlobalConfig(current => ({
...current,
githubRepoPaths: {
...current.githubRepoPaths,
[repoKey]: updatedPaths,
},
}))
logForDebugging(`Added ${currentPath} to tracked paths for repo ${repoKey}`)
} catch (error) {
logForDebugging(`Error updating repo path mapping: ${error}`)
// Silently fail - this is non-blocking startup work
}
}
/**
* Gets known local paths for a given GitHub repository.
* @param repo The repository in "owner/repo" format
* @returns Array of known absolute paths, or empty array if none
*/
export function getKnownPathsForRepo(repo: string): string[] {
const config = getGlobalConfig()
const repoKey = repo.toLowerCase()
return config.githubRepoPaths?.[repoKey] ?? []
}
/**
* Filters paths to only those that exist on the filesystem.
* @param paths Array of absolute paths to check
* @returns Array of paths that exist
*/
export async function filterExistingPaths(paths: string[]): Promise<string[]> {
const results = await Promise.all(paths.map(pathExists))
return paths.filter((_, i) => results[i])
}
/**
* Validates that a path contains the expected GitHub repository.
* @param path Absolute path to check
* @param expectedRepo Expected repository in "owner/repo" format
* @returns true if the path contains the expected repo, false otherwise
*/
export async function validateRepoAtPath(
path: string,
expectedRepo: string,
): Promise<boolean> {
try {
const remoteUrl = await getRemoteUrlForDir(path)
if (!remoteUrl) {
return false
}
const actualRepo = parseGitHubRepository(remoteUrl)
if (!actualRepo) {
return false
}
// Case-insensitive comparison
return actualRepo.toLowerCase() === expectedRepo.toLowerCase()
} catch {
return false
}
}
/**
* Removes a path from the tracked paths for a given repository.
* Used when a path is found to be invalid during selection.
* @param repo The repository in "owner/repo" format
* @param pathToRemove The path to remove from tracking
*/
export function removePathFromRepo(repo: string, pathToRemove: string): void {
const config = getGlobalConfig()
const repoKey = repo.toLowerCase()
const existingPaths = config.githubRepoPaths?.[repoKey] ?? []
const updatedPaths = existingPaths.filter(path => path !== pathToRemove)
if (updatedPaths.length === existingPaths.length) {
// Path wasn't in the list, nothing to do
return
}
const updatedMapping = { ...config.githubRepoPaths }
if (updatedPaths.length === 0) {
// Remove the repo key entirely if no paths remain
delete updatedMapping[repoKey]
} else {
updatedMapping[repoKey] = updatedPaths
}
saveGlobalConfig(current => ({
...current,
githubRepoPaths: updatedMapping,
}))
logForDebugging(
`Removed ${pathToRemove} from tracked paths for repo ${repoKey}`,
)
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

Claude Code v2.1.88 源码,原仓库地址:https://github.com/sanbuphy/claude-code-source-code
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/monkeycc/claude-code-source-code.git
git@gitee.com:monkeycc/claude-code-source-code.git
monkeycc
claude-code-source-code
claude-code-source-code
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /