-
Notifications
You must be signed in to change notification settings - Fork 244
Expand file tree
/
Copy pathsetup.py
More file actions
55 lines (44 loc) · 1.29 KB
/
Copy pathsetup.py
File metadata and controls
55 lines (44 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
Session setup – initialize project environment before starting REPL.
Port of: src/setup.ts
"""
from __future__ import annotations
import os
from typing import Any
from hare.bootstrap.state import (
get_session_id,
set_original_cwd,
set_project_root,
switch_session,
)
from hare.utils.config import get_global_config
from hare.utils.cwd import get_cwd
from hare.utils.git import find_git_root
async def setup(
cwd: str,
permission_mode: str = "default",
allow_dangerously_skip_permissions: bool = False,
worktree_enabled: bool = False,
) -> dict[str, Any]:
"""
Initialize project environment.
Returns setup result with project root, git status, session info.
"""
set_original_cwd(cwd)
os.chdir(cwd)
git_root = await find_git_root(cwd)
project_root = git_root or cwd
set_project_root(project_root)
session_id = get_session_id()
config = get_global_config()
result: dict[str, Any] = {
"cwd": cwd,
"project_root": project_root,
"git_root": git_root,
"session_id": session_id,
"permission_mode": permission_mode,
"worktree_enabled": worktree_enabled,
}
if worktree_enabled and git_root:
result["worktree"] = {"enabled": True, "branch": None}
return result