plan

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package plan は計画の永続化を提供する

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainsFailure

func ContainsFailure(result string) (bool, string)

ContainsFailure はツール結果に失敗パターンが含まれるか検出 失敗を検出した場合、(true, 理由) を返す

NOTE: "error:" や "Error:" のような汎用パターンは使用しない。 コード検索結果(例: t.Errorf)やログ出力に含まれる "Error" 文字列で 誤検知してしまうため。実際のコマンド失敗を示す具体的なパターンのみ使用。

func ContainsPlanJSON added in v0.46.0

func ContainsPlanJSON(response string) bool

ContainsPlanJSON はレスポンスに Plan JSON が含まれるかを判定

func ExtractPlanJSON

func ExtractPlanJSON(response string) string

ExtractPlanJSON はレスポンスからPlan JSONを抽出 見つからない場合は空文字列を返す NOTE: ツール呼び出し JSON ({"tool": ...}) は plan ではないので除外する

func FormatConflictWarning

func FormatConflictWarning(c Conflict) string

FormatConflictWarning は競合情報を警告文字列に整形

func FormatPlan

func FormatPlan(plan *Plan) string

FormatPlan は計画を見やすく整形

Types

type Clarification added in v0.46.0

type Clarification struct {
	Question     string    `json:"question"`
	QuestionType string    `json:"question_type"` // single_choice, multi_choice, free_text
	Options      []string  `json:"options,omitempty"`
	Answer       string    `json:"answer,omitempty"`
	Answers      []string  `json:"answers,omitempty"`
	AskedAt      time.Time `json:"asked_at"`
}

Clarification はユーザーへの質問と回答

type Conflict

type Conflict struct {
	StepIDs      []int    // 競合するステップID
	ConflictType string   // "write-write", "read-write", "write-read"
	Files        []string // 競合ファイル
	Message      string   // 詳細メッセージ
}

Conflict は並列実行時の競合情報

type DependencyAnalyzer

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

DependencyAnalyzer はプランステップ間の依存関係を解析

func NewDependencyAnalyzer

func NewDependencyAnalyzer(lspClient *lsp.Client) *DependencyAnalyzer

NewDependencyAnalyzer は DependencyAnalyzer を作成

func (*DependencyAnalyzer) Analyze

func (da *DependencyAnalyzer) Analyze(steps []PlanStep) *DependencyResult

Analyze はステップ間の依存関係を解析

func (*DependencyAnalyzer) AnalyzeAndWarn

func (da *DependencyAnalyzer) AnalyzeAndWarn(steps []PlanStep, parallelStepIDs []int) ([]PlanStep, []string)

AnalyzeAndWarn は依存関係を解析し、競合があれば警告を返す

func (*DependencyAnalyzer) DetectConflicts

func (da *DependencyAnalyzer) DetectConflicts(parallelStepIDs []int, steps []PlanStep) []Conflict

DetectConflicts は並列実行時の競合を検出

func (*DependencyAnalyzer) EnhanceWithLSP

func (da *DependencyAnalyzer) EnhanceWithLSP(steps []PlanStep) []PlanStep

EnhanceWithLSP はLSPを使用して依存関係を強化 WriteFilesに含まれるファイルのシンボル参照を取得し、 参照元ファイルが他のステップで使用されていれば依存関係を追加

func (*DependencyAnalyzer) ExtractFilesFromStep

func (da *DependencyAnalyzer) ExtractFilesFromStep(step *PlanStep) (readFiles, writeFiles []string)

ExtractFilesFromStep はステップからファイルパスを抽出

func (*DependencyAnalyzer) InferDependencies

func (da *DependencyAnalyzer) InferDependencies(steps []PlanStep) []PlanStep

InferDependencies は依存関係を自動推論 RAW (Read After Write): BがAの書き込みファイルを読む WAW (Write After Write): 両方が同じファイルに書く WAR (Write After Read): BがAの読み取りファイルに書く

type DependencyResult

type DependencyResult struct {
	Steps     []PlanStep // 依存関係が補完されたステップ
	Conflicts []Conflict // 検出された競合
	Warnings  []string   // 警告メッセージ
}

DependencyResult は依存関係解析の結果

type FailureAction

type FailureAction string

FailureAction は失敗時のユーザー選択

const (
	FailureActionRetry   FailureAction = "retry"
	FailureActionComment FailureAction = "comment"
	FailureActionSkip    FailureAction = "skip"
	FailureActionAbort   FailureAction = "abort"
)

type Plan

type Plan struct {
	// 既存フィールド
	Summary string     `json:"summary"`
	Steps   []PlanStep `json:"steps"`

	// メタデータ(新規)
	ID             string          `json:"id,omitempty"`
	Title          string          `json:"title,omitempty"`
	CreatedAt      time.Time       `json:"created_at,omitempty"`
	UpdatedAt      time.Time       `json:"updated_at,omitempty"`
	Status         PlanStatus      `json:"status,omitempty"`
	Model          string          `json:"model,omitempty"`
	Provider       string          `json:"provider,omitempty"`
	UserRequest    string          `json:"user_request,omitempty"`
	Clarifications []Clarification `json:"clarifications,omitempty"`
	ExecutionLog   []StepLog       `json:"execution_log,omitempty"`
}

Plan は実行計画を表す

func ParsePlan

func ParsePlan(jsonStr string) (*Plan, error)

ParsePlan はJSON文字列からPlanを解析

互換対応: - V2形式: {"plan": {...}} - 旧形式: {"summary": "...", "steps": [...]}

func (*Plan) AddLog added in v0.46.0

func (p *Plan) AddLog(log StepLog)

AddLog は実行ログを追加

func (*Plan) CanExecute

func (p *Plan) CanExecute(stepID int) bool

CanExecute はステップが実行可能かチェック

func (*Plan) GetNextStep

func (p *Plan) GetNextStep() int

GetNextStep は次に実行すべきステップIDを取得

func (*Plan) GetParallelSteps

func (p *Plan) GetParallelSteps() []int

GetParallelSteps は並列実行可能なステップを取得 depends_on が同じステップは並列実行可能と判定

func (*Plan) GetStep

func (p *Plan) GetStep(id int) *PlanStep

GetStep は指定IDのステップを取得

func (*Plan) GetToolsExecuted

func (p *Plan) GetToolsExecuted(stepID int) int

GetToolsExecuted は実行ツール数を取得

func (*Plan) HasFailed

func (p *Plan) HasFailed() bool

HasFailed は失敗したステップがあるかチェック

func (*Plan) IncrementToolsExecuted

func (p *Plan) IncrementToolsExecuted(stepID int)

IncrementToolsExecuted は実行ツール数をインクリメント

func (*Plan) IsCompleted

func (p *Plan) IsCompleted() bool

IsCompleted はすべてのステップが完了したかチェック

func (*Plan) UpdateStatus

func (p *Plan) UpdateStatus(stepID int, status, result string)

UpdateStatus はステップのステータスを更新

type PlanMetadata added in v0.46.0

type PlanMetadata struct {
	ID        string
	Title     string
	Status    PlanStatus
	CreatedAt time.Time
	UpdatedAt time.Time
	Filename  string
}

PlanMetadata は計画の概要情報

type PlanStatus added in v0.46.0

type PlanStatus string

PlanStatus は計画の全体ステータス

const (
	PlanStatusDraft     PlanStatus = "draft"
	PlanStatusPending   PlanStatus = "pending"
	PlanStatusApproved  PlanStatus = "approved"
	PlanStatusRunning   PlanStatus = "running"
	PlanStatusCompleted PlanStatus = "completed"
	PlanStatusFailed    PlanStatus = "failed"
	PlanStatusCancelled PlanStatus = "cancelled"
)

type PlanStep

type PlanStep struct {
	ID            int      `json:"id"`
	Description   string   `json:"description"`
	Tools         []string `json:"tools"`      // 使用予定ツール
	DependsOn     []int    `json:"depends_on"` // 依存するステップID
	Status        string   `json:"status"`     // "pending", "running", "completed", "failed"
	Result        string   `json:"result"`     // 実行結果
	ToolsExecuted int      `json:"-"`          // 実際に実行されたツール数

	// ファイルアクセス情報(依存関係解析で使用)
	TargetFiles []string `json:"-"` // 操作対象ファイル(推論結果)
	ReadFiles   []string `json:"-"` // 読み取りファイル
	WriteFiles  []string `json:"-"` // 書き込みファイル

	// 追加フィールド(Phase 1)
	Files       []string   `json:"files,omitempty"`        // 関連ファイル
	StartedAt   *time.Time `json:"started_at,omitempty"`   // 開始時刻
	CompletedAt *time.Time `json:"completed_at,omitempty"` // 完了時刻
}

PlanStep は計画の1ステップを表す

type PlanStorage added in v0.46.0

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

PlanStorage は計画の永続化を管理

func NewPlanStorage added in v0.46.0

func NewPlanStorage() (*PlanStorage, error)

NewPlanStorage はカレントディレクトリ基準で Storage を作成

func (*PlanStorage) Delete added in v0.46.0

func (s *PlanStorage) Delete(filename string) error

Delete は計画を削除

func (*PlanStorage) List added in v0.46.0

func (s *PlanStorage) List() ([]PlanMetadata, error)

List は全計画を一覧取得(新しい順)

func (*PlanStorage) Load added in v0.46.0

func (s *PlanStorage) Load(filename string) (*Plan, error)

Load は計画を Markdown ファイルから読み込み

func (*PlanStorage) LoadByID added in v0.46.0

func (s *PlanStorage) LoadByID(id string) (*Plan, string, error)

LoadByID は ID で計画を検索して読み込み

func (*PlanStorage) Save added in v0.46.0

func (s *PlanStorage) Save(p *Plan) (string, error)

Save は計画を Markdown ファイルとして保存

type StepLog added in v0.46.0

type StepLog struct {
	StepID     int               `json:"step_id"`
	ToolName   string            `json:"tool_name"`
	ToolArgs   map[string]string `json:"tool_args,omitempty"`
	Result     string            `json:"result,omitempty"`
	Error      string            `json:"error,omitempty"`
	ExecutedAt time.Time         `json:"executed_at"`
	DurationMs int64             `json:"duration_ms"`
}

StepLog はステップ実行の詳細ログ

Jump to

Keyboard shortcuts

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