skillhub/cli/src/platform/paths.ts
dongmucat ccacb530e3
feat(cli): add AStudio agent profile (#840)
* feat(cli): add AstronStudio agent profile

Signed-off-by: dongmucat <1127093059@qq.com>

* test(cli): make AstronStudio path assertions portable

Signed-off-by: dongmucat <1127093059@qq.com>

* docs(cli): document AstronStudio install target

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(cli): rename AstronStudio profile to AStudio

Signed-off-by: dongmucat <1127093059@qq.com>

* fix(cli): use stable lowercase AStudio agent id

Signed-off-by: dongmucat <1127093059@qq.com>

---------

Signed-off-by: dongmucat <1127093059@qq.com>
2026-09-09 17:26:34 +08:00

49 lines
1.3 KiB
TypeScript

export function userStateDir(home = process.env.HOME || process.env.USERPROFILE || ''): string {
if (!home) {
throw new Error('Cannot resolve user home directory')
}
return `${home.replace(/\\/g, '/')}/.skillhub`
}
export function joinPath(...parts: string[]): string {
return parts.join('/').replace(/\/+/g, '/')
}
export async function ensureDir(dir: string): Promise<void> {
const { mkdir } = await import('node:fs/promises')
await mkdir(dir, { recursive: true })
}
export async function pathExists(path: string): Promise<boolean> {
const { access } = await import('node:fs/promises')
try {
await access(path)
return true
} catch {
return false
}
}
export async function directoryExists(path: string): Promise<boolean> {
const { stat } = await import('node:fs/promises')
try {
return (await stat(path)).isDirectory()
} catch {
return false
}
}
export async function canonicalizeExistingPath(path: string): Promise<string> {
const { realpath } = await import('node:fs/promises')
try {
return await realpath(path)
} catch {
return path
}
}
export async function applyCredentialPermissions(path: string): Promise<void> {
if (process.platform === 'win32') return
const { chmod } = await import('node:fs/promises')
await chmod(path, 0o600)
}