hosttools

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

sync.go implements the tool approval workflow for secure mode. It compares tools in staging directories (workspace) with approved tools, prompts the user for approval, and copies approved tools to the approved directory.

sync.goはセキュアモードのツール承認ワークフローを実装します。 ステージングディレクトリ(ワークスペース)のツールと承認済みツールを比較し、 ユーザーに承認を求め、承認されたツールを承認済みディレクトリにコピーします。

Package hosttools provides auto-discovery and execution of host-side tools. It supports Go (.go), shell (.sh), and Python (.py) files with parsed headers.

hosttoolsパッケージはホスト側ツールの自動検出と実行を提供します。 Go(.go)、シェル(.sh)、Python(.py)ファイルのヘッダーパースをサポートします。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonApprovedDir

func CommonApprovedDir(approvedDir string) (string, error)

CommonApprovedDir returns the common tools directory path. CommonApprovedDirは共通ツールディレクトリパスを返します。

func ProjectApprovedDir

func ProjectApprovedDir(approvedDir, workspacePath string) (string, error)

ProjectApprovedDir returns the per-project approved directory path. ProjectApprovedDirはプロジェクトごとの承認済みディレクトリパスを返します。

func ProjectID

func ProjectID(workspacePath string) string

ProjectID generates a human-readable project identifier from a workspace path. Format: <dir-name>-<short-hash> (e.g., "my-project-a1b2c3d4")

ProjectIDはワークスペースパスから人間が読めるプロジェクト識別子を生成します。 形式: <dir-name>-<short-hash>(例: "my-project-a1b2c3d4")

func ResolveApprovedDir

func ResolveApprovedDir(approvedDir string) (string, error)

ResolveApprovedDir returns the absolute path to the approved directory, expanding ~ to the user's home directory.

ResolveApprovedDirは承認済みディレクトリの絶対パスを返します。 ~をユーザーのホームディレクトリに展開します。

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager coordinates tool discovery and execution for host tools. Supports two modes:

  • Legacy mode: tools loaded from Directories (when ApprovedDir is empty)
  • Secure mode: tools loaded from approved directory + optional common directory

In secure mode, --dev flag enables development mode where staging directories are also included with highest priority (staging > approved > common).

Managerはホストツールの検出と実行を調整します。 2つのモードをサポートします:

  • レガシーモード: Directoriesからツールを読み込み(ApprovedDirが空の場合)
  • セキュアモード: 承認済みディレクトリ + オプションの共通ディレクトリからツールを読み込み

セキュアモードでは、--devフラグで開発モードを有効にでき、 ステージングディレクトリも最優先で読み込まれます(staging > approved > common)。

func NewManager

func NewManager(cfg *config.HostToolsConfig, workspaceRoot string) *Manager

NewManager creates a new host tools manager. NewManagerは新しいホストツールマネージャーを作成します。

func (*Manager) Config

func (m *Manager) Config() *config.HostToolsConfig

Config returns the host tools configuration. Configはホストツールの設定を返します。

func (*Manager) GetToolInfo

func (m *Manager) GetToolInfo(name string) (ToolInfo, error)

GetToolInfo returns detailed info for a specific tool by name. It searches all configured directories.

GetToolInfoは名前で指定されたツールの詳細情報を返します。 すべての設定されたディレクトリを検索します。

func (*Manager) IsDevMode

func (m *Manager) IsDevMode() bool

IsDevMode returns whether development mode is active. IsDevModeは開発モードが有効かどうかを返します。

func (*Manager) IsEnabled

func (m *Manager) IsEnabled() bool

IsEnabled returns whether host tools are enabled. IsEnabledはホストツールが有効かどうかを返します。

func (*Manager) IsSecureMode

func (m *Manager) IsSecureMode() bool

IsSecureMode returns whether secure mode is active. IsSecureModeはセキュアモードが有効かどうかを返します。

func (*Manager) ListTools

func (m *Manager) ListTools() ([]ToolInfo, error)

ListTools returns metadata for all discovered tools across all configured directories. ListToolsはすべての設定されたディレクトリ内の発見されたツールのメタデータを返します。

func (*Manager) PendingApproval added in v0.4.0

func (m *Manager) PendingApproval() ([]SyncItem, error)

PendingApproval returns the host tools that are staged (in the staging directories) but not yet approved, or whose staged content differs from the currently approved copy. It only applies in secure mode — legacy mode has no staging/approval workflow, so it returns nil.

PendingApprovalはステージングディレクトリにあるがまだ承認されていない、 またはステージング内容が承認済みコピーと異なるホストツールを返します。 セキュアモードでのみ適用されます — レガシーモードには ステージング/承認ワークフローがないため、nilを返します。

func (*Manager) RunTool

func (m *Manager) RunTool(name string, args []string) (*Result, error)

RunTool executes a tool by name with the given arguments. It searches all configured directories for the tool.

RunToolは名前で指定されたツールを引数付きで実行します。 すべての設定されたディレクトリでツールを検索します。

func (*Manager) SetDevMode

func (m *Manager) SetDevMode(enabled bool)

SetDevMode enables development mode. In dev mode, staging directories are included with highest priority, allowing tools under development to be tested without approval.

SetDevModeは開発モードを有効にします。 開発モードでは、ステージングディレクトリが最優先で読み込まれ、 承認なしで開発中のツールをテストできます。

type Result

type Result struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exit_code"`
}

Result holds the output of a tool/command execution. Resultはツール/コマンド実行の出力を保持します。

func ExecHostCommand

func ExecHostCommand(command string, workspaceRoot string, timeout time.Duration) (*Result, error)

ExecHostCommand executes a host CLI command string with the given working directory and timeout.

ExecHostCommandは指定された作業ディレクトリとタイムアウトで ホストCLIコマンド文字列を実行します。

func RunTool

func RunTool(dir, name string, args []string, timeout time.Duration, workDir string) (*Result, error)

RunTool executes a tool file with the given arguments and timeout. The tool is dispatched based on file extension:

  • .go → go run <path> [args...]
  • .sh → bash <path> [args...]
  • .py → python3 <path> [args...]

The working directory is set to workDir. If workDir is empty, the tool's directory is used as a fallback.

RunToolは指定された引数とタイムアウトでツールファイルを実行します。 作業ディレクトリはworkDirに設定されます。workDirが空の場合、 ツールのディレクトリがフォールバックとして使用されます。

func (*Result) String

func (r *Result) String() string

String formats the result for display. Stringは表示用に結果をフォーマットします。

type SyncItem

type SyncItem struct {
	Name         string     `json:"name"`
	Description  string     `json:"description,omitempty"`
	Status       SyncStatus `json:"status"`
	StagingPath  string     `json:"staging_path"`
	ApprovedPath string     `json:"approved_path"`
}

SyncItem represents a tool that may need syncing. SyncItemは同期が必要な可能性のあるツールを表します。

type SyncManager

type SyncManager struct {
	// contains filtered or unexported fields
}

SyncManager handles the tool approval workflow. SyncManagerはツール承認ワークフローを処理します。

func NewSyncManager

func NewSyncManager(cfg *config.HostToolsConfig, workspaceRoot string) *SyncManager

NewSyncManager creates a new SyncManager. NewSyncManagerは新しいSyncManagerを作成します。

func (*SyncManager) DetectChanges

func (s *SyncManager) DetectChanges() ([]SyncItem, error)

DetectChanges compares staging directories with the approved directory and returns a list of tools that need attention.

DetectChangesはステージングディレクトリと承認済みディレクトリを比較し、 注意が必要なツールのリストを返します。

func (*SyncManager) RunInteractiveSync

func (s *SyncManager) RunInteractiveSync() (int, error)

RunInteractiveSync performs an interactive sync session. For each new or updated tool, it prompts the user for approval. Returns the number of tools synced.

RunInteractiveSyncはインタラクティブな同期セッションを実行します。 新しいまたは更新されたツールごとに、ユーザーに承認を求めます。 同期されたツールの数を返します。

func (*SyncManager) SetReader

func (s *SyncManager) SetReader(r io.Reader)

SetReader overrides the input reader (for testing). SetReaderは入力リーダーを上書きします(テスト用)。

func (*SyncManager) SetWriter

func (s *SyncManager) SetWriter(w io.Writer)

SetWriter overrides the output writer (for testing). SetWriterは出力ライターを上書きします(テスト用)。

type SyncStatus

type SyncStatus int

SyncStatus represents the status of a tool comparison between staging and approved. SyncStatusはステージングと承認済みのツール比較のステータスを表します。

const (
	// SyncNew indicates a tool exists in staging but not in approved.
	// SyncNewはステージングにあるが承認済みにないツールを示します。
	SyncNew SyncStatus = iota

	// SyncUpdated indicates a tool exists in both but content differs.
	// SyncUpdatedは両方にあるがコンテンツが異なるツールを示します。
	SyncUpdated

	// SyncUnchanged indicates a tool exists in both with identical content.
	// SyncUnchangedは両方にあり、同一コンテンツのツールを示します。
	SyncUnchanged
)

type ToolInfo

type ToolInfo struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Usage       string   `json:"usage,omitempty"`
	Examples    []string `json:"examples,omitempty"`
	Extension   string   `json:"extension"`
}

ToolInfo holds parsed metadata about a host tool. ToolInfoはホストツールの解析済みメタデータを保持します。

func GetToolInfo

func GetToolInfo(dir, name string, allowedExtensions []string) (ToolInfo, error)

GetToolInfo returns detailed info for a specific tool by name. GetToolInfoは名前で指定されたツールの詳細情報を返します。

func ListTools

func ListTools(dir string, allowedExtensions []string) ([]ToolInfo, error)

ListTools returns metadata for all tools in the directory, filtered by allowed extensions.

ListToolsはディレクトリ内のすべてのツールのメタデータを返します。 許可された拡張子でフィルタリングされます。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL