mirror of
https://github.com/aljazceru/claude-code-viewer.git
synced 2026-01-30 19:04:34 +01:00
chore: inject global claude directory by using GLOBAL_CLAUDE_DIR environment variables
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { readdir } from "node:fs/promises";
|
||||
import { homedir } from "node:os";
|
||||
import { resolve } from "node:path";
|
||||
import { zValidator } from "@hono/zod-validator";
|
||||
import { setCookie } from "hono/cookie";
|
||||
@@ -18,6 +17,7 @@ import { getBranches } from "../service/git/getBranches";
|
||||
import { getCommits } from "../service/git/getCommits";
|
||||
import { getDiff } from "../service/git/getDiff";
|
||||
import { getMcpList } from "../service/mcp/getMcpList";
|
||||
import { claudeCommandsDirPath } from "../service/paths";
|
||||
import { getProject } from "../service/project/getProject";
|
||||
import { getProjects } from "../service/project/getProjects";
|
||||
import { getSession } from "../service/session/getSession";
|
||||
@@ -194,7 +194,7 @@ export const routes = (app: HonoAppType) => {
|
||||
const { project } = await getProject(projectId);
|
||||
|
||||
const [globalCommands, projectCommands] = await Promise.allSettled([
|
||||
readdir(resolve(homedir(), ".claude", "commands"), {
|
||||
readdir(claudeCommandsDirPath, {
|
||||
withFileTypes: true,
|
||||
}).then((dirents) =>
|
||||
dirents
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type FSWatcher, watch } from "node:fs";
|
||||
import z from "zod";
|
||||
import { claudeProjectPath } from "../paths";
|
||||
import { claudeProjectsDirPath } from "../paths";
|
||||
import { getEventBus, type IEventBus } from "./EventBus";
|
||||
|
||||
const fileRegExp = /(?<projectId>.*?)\/(?<sessionId>.*?)\.jsonl/;
|
||||
@@ -24,10 +24,10 @@ export class FileWatcherService {
|
||||
this.isWatching = true;
|
||||
|
||||
try {
|
||||
console.log("Starting file watcher on:", claudeProjectPath);
|
||||
console.log("Starting file watcher on:", claudeProjectsDirPath);
|
||||
// メインプロジェクトディレクトリを監視
|
||||
this.watcher = watch(
|
||||
claudeProjectPath,
|
||||
claudeProjectsDirPath,
|
||||
{ persistent: false, recursive: true },
|
||||
(eventType, filename) => {
|
||||
if (!filename) return;
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
import { homedir } from "node:os";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
export const claudeProjectPath = resolve(homedir(), ".claude", "projects");
|
||||
// biome-ignore lint/complexity/useLiteralKeys: typescript restriction
|
||||
const GLOBAL_CLAUDE_DIR = process.env["GLOBAL_CLAUDE_DIR"];
|
||||
|
||||
export const globalClaudeDirectoryPath =
|
||||
GLOBAL_CLAUDE_DIR === undefined
|
||||
? resolve(homedir(), ".claude")
|
||||
: resolve(GLOBAL_CLAUDE_DIR);
|
||||
|
||||
export const claudeProjectsDirPath = resolve(
|
||||
globalClaudeDirectoryPath,
|
||||
"projects",
|
||||
);
|
||||
|
||||
export const claudeCommandsDirPath = resolve(
|
||||
globalClaudeDirectoryPath,
|
||||
"commands",
|
||||
);
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { constants } from "node:fs";
|
||||
import { access, readdir } from "node:fs/promises";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
import { claudeProjectPath } from "../paths";
|
||||
import { claudeProjectsDirPath } from "../paths";
|
||||
import type { Project } from "../types";
|
||||
import { getProjectMeta } from "./getProjectMeta";
|
||||
import { encodeProjectId } from "./id";
|
||||
@@ -10,20 +9,24 @@ import { encodeProjectId } from "./id";
|
||||
export const getProjects = async (): Promise<{ projects: Project[] }> => {
|
||||
try {
|
||||
// Check if the claude projects directory exists
|
||||
await access(claudeProjectPath, constants.F_OK);
|
||||
await access(claudeProjectsDirPath, constants.F_OK);
|
||||
} catch (_error) {
|
||||
// Directory doesn't exist, return empty array
|
||||
console.warn(`Claude projects directory not found at ${claudeProjectPath}`);
|
||||
console.warn(
|
||||
`Claude projects directory not found at ${claudeProjectsDirPath}`,
|
||||
);
|
||||
return { projects: [] };
|
||||
}
|
||||
|
||||
try {
|
||||
const dirents = await readdir(claudeProjectPath, { withFileTypes: true });
|
||||
const dirents = await readdir(claudeProjectsDirPath, {
|
||||
withFileTypes: true,
|
||||
});
|
||||
const projects = await Promise.all(
|
||||
dirents
|
||||
.filter((d) => d.isDirectory())
|
||||
.map(async (d) => {
|
||||
const fullPath = resolve(claudeProjectPath, d.name);
|
||||
const fullPath = resolve(claudeProjectsDirPath, d.name);
|
||||
const id = encodeProjectId(fullPath);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user