trace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2026 License: MIT Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package trace は対応関係の追跡(対応表・影響範囲分析・欠落検出・ グラフ出力)と、文書を読む経路(索引・本文取り出し・検索)を提供する。

Index

Constants

View Source
const (
	StatusComplete = "complete" // すべての経路が連鎖の最終段まで届いている
	StatusPartial  = "partial"  // 一部の経路が途中で途切れている
	StatusMissing  = "missing"  // 下流へ辿る経路が 1 本も無い
)

行の状態。機械可読な出力にはこの語がそのまま載る。 表示の記号にしないのは、絵文字を線上の契約にすると 消費側が表示の都合の変更で壊れるため。

View Source
const (
	// DefaultSearchLimit は返す節の上限。
	DefaultSearchLimit = 20
	// DefaultSearchMaxHits は 1 節あたりに表示する一致行の上限。
	DefaultSearchMaxHits = 3
)

検索の既定値。出力が文脈を圧迫しない大きさに収める。

Variables

This section is empty.

Functions

func StatusGlyph

func StatusGlyph(status string) string

StatusGlyph は状態の表示記号を返す。人が読む表と文書へ貼る表で使う。

Types

type Entry

type Entry struct {
	ID         string   `json:"id"`
	Type       string   `json:"type"`
	Title      string   `json:"title,omitempty"`
	File       string   `json:"file"`
	Line       int      `json:"line"`
	EndLine    int      `json:"end_line"`
	Refs       []string `json:"refs"`       // このセクションが本文で参照している識別子(上流)
	Downstream []string `json:"downstream"` // このセクションから影響が及ぶ識別子(参照元と、入れ子の子)
}

Entry は索引の 1 件。識別子が「どの文書のどこにあるか」を示す。

type GapsReport

type GapsReport struct {
	Type    string      `json:"type"`
	Chain   []string    `json:"chain"`
	Items   []MatrixRow `json:"items"`
	Summary struct {
		Total      int `json:"total"`
		Complete   int `json:"complete"`
		RatePct    int `json:"coverage_percent"`
		Incomplete int `json:"incomplete"`
	} `json:"summary"`
}

GapsReport は最終段まで辿り切れなかった起点の一覧。

判定は対応表と同じものを使う。別に数えると、対応表が ✅ と言う行を こちらが未達と数える、という食い違いが起きる。

func (*GapsReport) Render

func (r *GapsReport) Render(format string) (string, error)

Render は欠落レポートを text / json で整形する。

type Hit

type Hit struct {
	Line int    `json:"line"`
	Text string `json:"text"`
}

Hit は一致した行 1 件。

type Impact

type Impact struct {
	Target   string     `json:"target"`
	Direct   []Location `json:"direct_impact"`
	Indirect []Location `json:"indirect_impact"`
	Summary  struct {
		DirectCount   int `json:"direct_count"`
		IndirectCount int `json:"indirect_count"`
	} `json:"summary"`
}

Impact は影響範囲分析の結果。

func (*Impact) Render

func (im *Impact) Render(format string) (string, error)

Render は影響範囲を text / json で整形する。

type Index

type Index struct {
	Entries []Entry  `json:"entries"`
	Files   []string `json:"files"`
}

Index は識別子の索引。文書が増えても、この一覧から所在を辿れる。

func (*Index) Render

func (idx *Index) Render(format string) (string, error)

Render は索引を text / tree / json で整形する。

type Location

type Location struct {
	ID    string `json:"id"`
	File  string `json:"file"`
	Line  int    `json:"line"`
	Title string `json:"title,omitempty"`
}

Location は ID の定義位置。

type Match

type Match struct {
	ID    string `json:"id"`
	Type  string `json:"type,omitempty"`
	Title string `json:"title,omitempty"`
	File  string `json:"file"`
	Line  int    `json:"line"`
	Hits  []Hit  `json:"hits"`
	// HitCount は絞り込む前の一致行数。Hits より大きければ表示を打ち切っている。
	HitCount int `json:"hit_count"`
}

Match は一致した節 1 件。ID が空なら、どの節にも属さない本文(前文など)。

type Matrix

type Matrix struct {
	Rows []MatrixRow `json:"rows"`
	// Chain は連鎖の各段。段数が可変なので、JSON の消費側が列の意味を知るために出す。
	Chain   []string `json:"chain"`
	Summary struct {
		Total    int `json:"total"`
		Complete int `json:"complete"`
		Partial  int `json:"partial"`
		Missing  int `json:"missing"`
		RatePct  int `json:"coverage_percent"`
	} `json:"summary"`
}

Matrix は対応表。列は連鎖の段数だけあり、3 段に限らない。

func (*Matrix) Render

func (m *Matrix) Render(format string) (string, error)

Render は対応表を markdown / json で整形する。

type MatrixRow

type MatrixRow struct {
	ID    string `json:"id"`
	Title string `json:"title,omitempty"`
	File  string `json:"file,omitempty"`
	Line  int    `json:"line,omitempty"`
	// Paths は起点から下流へ辿った経路。各要素が 1 経路で、起点自身は含まない。
	// 途中で下流が途切れた経路は連鎖の段数より短くなる。
	Paths  [][]string `json:"paths"`
	Status string     `json:"status"`
}

MatrixRow は連鎖の起点 1 件分の行。

type SearchOptions

type SearchOptions struct {
	Pattern string // 正規表現。Fixed が真なら文字列そのまま
	Fixed   bool
	Type    string // 文書タイプで絞る。空なら全部
	Limit   int    // 返す節の上限。0 で既定
	MaxHits int    // 1 節あたりの一致行の上限。0 で既定
}

SearchOptions は検索の指示。

type SearchResult

type SearchResult struct {
	Matches []Match `json:"matches"`
	// Total は Limit で絞る前の一致節数。絞り足りないかを呼び出し側が判断できる。
	Total     int  `json:"total"`
	Truncated bool `json:"truncated"`
}

SearchResult は検索結果。

func (*SearchResult) Render

func (r *SearchResult) Render(format string) (string, error)

Render は検索結果を text / json で整形する。

type Trace

type Trace struct {
	Cfg   *config.Config
	Docs  []*parser.Document
	Graph *graph.Graph
	Chain []string // 文書タイプの並び(上流から下流へ)
	// contains filtered or unexported fields
}

Trace は解析済みの文書群と ID 依存グラフ。

func Build

func Build(cfg *config.Config, paths []string) (*Trace, error)

Build は文書を解析して ID 依存グラフを構築する。 エッジは「参照された ID → 参照しているセクションの ID」(上流 → 下流)。

paths は呼び出し側で解決済みであることを前提とする(既定解決や 非通常ファイルの除去は行わない)。CLI は internal/cli.ExpandTargets を経由する。

func (*Trace) CheckIDs

func (t *Trace) CheckIDs(ids []string) error

CheckIDs は識別子の一覧がすべて定義済みかを検査する。 空要素(末尾カンマなど)は指定なしとして無視する。 graph のように、下位の出力が未知の識別子を黙って空の結果にする 経路の手前で使う。

func (*Trace) Gaps

func (t *Trace) Gaps(docType string) (*GapsReport, error)

Gaps は連鎖の最終段まで辿り切れない ID を列挙する。 docType が空なら連鎖の先頭を対象にする。

func (*Trace) GraphOutput

func (t *Trace) GraphOutput(filter []string) string

GraphOutput は依存グラフを Mermaid(flowchart LR)で出力する。 filter が非空ならその ID だけの部分グラフにする。

形式は Mermaid だけ。Markdown へそのまま貼れば図になるので、 出力を絵にするための外部コマンドが要らない。

func (*Trace) Impact

func (t *Trace) Impact(id string, depth int) (*Impact, error)

Impact は指定した識別子を変更した場合に影響を受ける識別子を返す。 depth <= 0 なら深さを制限しない。

func (*Trace) Index

func (t *Trace) Index(docType string) (*Index, error)

Index は全識別子の索引を作る。docType を指定するとその文書タイプだけに絞る。

文書が複数ファイルへ分かれると「どの識別子がどこにあるか」を人も道具も 見失いやすい。本文を開かずに所在を引けるようにするための出力。

func (*Trace) Matrix

func (t *Trace) Matrix(from string, filter []string) (*Matrix, error)

Matrix は連鎖に沿った対応表を構築する。

from が非空ならその文書タイプを起点の段にする(空なら連鎖の先頭)。 filter が非空の場合、その ID(起点)だけを対象にする。

段数は連鎖の宣言に従う。段飛ばしは経路として認めない。起点が最終段を直接 参照していても途中の段が空なら、そこで途切れた経路として扱う(途中が欠けて いること自体が知りたい情報のため)。

func (*Trace) Search

func (t *Trace) Search(opts SearchOptions) (*SearchResult, error)

Search は本文と見出しの表題から語を探し、一致を節へ帰属させて返す。

探すのは本文の行だけで、コードブロックの中は見ない。参照や用語の判定と 同じ本文の行(解析結果の Prose)を使うので、使用例として書いたコマンドが 検索にだけ引っかかることはない。

帰属は参照の紐付けと同じ規則で、一致行を含む直近の識別子付き見出しに属する。 見出しより前の本文はどの節にも属さないので、識別子を空にして位置だけ返す。

func (*Trace) Section

func (t *Trace) Section(id string) (string, error)

Section は識別子が指すセクションの本文を返す。

文書全体を読まずに該当箇所だけを取り出すための機能で、 分割された文書群から目的の節を引くのに使う。

func (*Trace) TypeAt

func (t *Trace) TypeAt(i int) string

TypeAt は連鎖の i 番目のタイプを返す(範囲外なら空)。

Jump to

Keyboard shortcuts

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