feat(tools): add session management tools for OpenCode sessions (#227)

* feat(tools): add session management tools for OpenCode sessions

- Add session_list tool for listing sessions with filtering
- Add session_read tool for reading session messages and history
- Add session_search tool for full-text search across sessions
- Add session_info tool for session metadata inspection
- Add comprehensive tests for storage, utils, and tools
- Update documentation in AGENTS.md

Closes #132

* fix(session-manager): add Windows compatibility for storage paths

- Create shared/data-path.ts utility for cross-platform data directory resolution
- On Windows: uses %LOCALAPPDATA% (e.g., C:\Users\Username\AppData\Local)
- On Unix: uses $XDG_DATA_HOME or ~/.local/share (XDG Base Directory spec)
- Update session-manager/constants.ts to use getOpenCodeStorageDir()
- Update hook-message-injector/constants.ts to use same utility
- Remove dependency on xdg-basedir package in session-manager
- Follows existing pattern from auto-update-checker for consistency

---------

Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
This commit is contained in:
Sisyphus
2025-12-25 17:04:16 +09:00
committed by GitHub
parent 41a7d032e1
commit ce4ceeefe8
14 changed files with 1022 additions and 4 deletions

29
src/shared/data-path.ts Normal file
View File

@@ -0,0 +1,29 @@
import * as path from "node:path"
import * as os from "node:os"
/**
* Returns the user-level data directory based on the OS.
* - Linux/macOS: XDG_DATA_HOME or ~/.local/share
* - Windows: %LOCALAPPDATA%
*
* This follows XDG Base Directory specification on Unix systems
* and Windows conventions on Windows.
*/
export function getDataDir(): string {
if (process.platform === "win32") {
// Windows: Use %LOCALAPPDATA% (e.g., C:\Users\Username\AppData\Local)
return process.env.LOCALAPPDATA ?? path.join(os.homedir(), "AppData", "Local")
}
// Unix: Use XDG_DATA_HOME or fallback to ~/.local/share
return process.env.XDG_DATA_HOME ?? path.join(os.homedir(), ".local", "share")
}
/**
* Returns the OpenCode storage directory path.
* - Linux/macOS: ~/.local/share/opencode/storage
* - Windows: %LOCALAPPDATA%\opencode\storage
*/
export function getOpenCodeStorageDir(): string {
return path.join(getDataDir(), "opencode", "storage")
}

View File

@@ -11,4 +11,5 @@ export * from "./deep-merge"
export * from "./file-utils"
export * from "./dynamic-truncator"
export * from "./config-path"
export * from "./data-path"
export * from "./config-errors"