Documentation
¶
Overview ¶
Package skill provides LLM-powered extraction of reusable patterns from tapes sessions, outputting Claude Code SKILL.md files.
Index ¶
- Variables
- func BuildSessionTranscript(ctx context.Context, query Querier, sessionID string, opts ...TranscriptOption) (string, error)
- func GlobalAgentsSkillsDir() (string, error)
- func GlobalClaudeSkillsDir() (string, error)
- func LocalAgentsSkillsDir() string
- func LocalClaudeSkillsDir() string
- func RenderSkillMD(sk *Skill) string
- func SkillsDir() (string, error)
- func Sync(name, sourceDir, targetDir string) (string, error)
- func TurnTranscript(ctx context.Context, query Querier, turn TraceSummary) string
- func ValidSkillType(t string) bool
- func Write(sk *Skill, dir string) (string, error)
- type APIClient
- type GenerateOptions
- type Generator
- type LLMCallFunc
- type LLMCallerConfig
- type Querier
- type Skill
- type Span
- type Trace
- type TraceSummary
- type TranscriptOption
Constants ¶
This section is empty.
Variables ¶
var ErrNoAPIKey = errors.New("no API key for skill-generation provider")
ErrNoAPIKey is returned by NewLLMCaller when no key resolves for the provider. Skill generation reuses the platform's search/embedding credential, so this means the tenant has search/embedding disabled — the handler maps it to a clear 4xx rather than an opaque 500.
var SkillTypes = []string{"workflow", "domain-knowledge", "prompt-template"}
SkillTypes enumerates valid skill type values.
Functions ¶
func BuildSessionTranscript ¶ added in v0.16.0
func BuildSessionTranscript(ctx context.Context, query Querier, sessionID string, opts ...TranscriptOption) (string, error)
BuildSessionTranscript renders the turn-grain transcript for one product session (a /v1/sessions UUID). It walks the trace surface: TraceSummaries for the session's user-visible turns, then Trace for each turn's spans. Per turn it emits the user prompt, then the main-thread conversation-spine ("main" call-kind, no sub-thread) llm responses in span order with tool usage summarized between them. Thinking blocks are dropped; when a turn carries no spine text the derive-time response preview stands in. Synthetic turns (compaction, resume replay) and turns outside the time window are filtered out.
This is the single transcript code path shared by skill generation and the checkout export.
func GlobalAgentsSkillsDir ¶
GlobalAgentsSkillsDir returns ~/.agents/skills/.
func GlobalClaudeSkillsDir ¶
GlobalClaudeSkillsDir returns ~/.claude/skills/.
func LocalAgentsSkillsDir ¶
func LocalAgentsSkillsDir() string
LocalAgentsSkillsDir returns .agents/skills/ relative to the current directory.
func LocalClaudeSkillsDir ¶
func LocalClaudeSkillsDir() string
LocalClaudeSkillsDir returns .claude/skills/ relative to the current directory.
func RenderSkillMD ¶
RenderSkillMD renders a Skill as its on-disk markdown representation (frontmatter + body).
func TurnTranscript ¶ added in v0.16.0
func TurnTranscript(ctx context.Context, query Querier, turn TraceSummary) string
TurnTranscript renders the [user]/[assistant]/[tools] lines for a single resolved turn, used when exporting one turn at a time.
func ValidSkillType ¶
ValidSkillType returns true if the given type is a recognized skill type.
Types ¶
type APIClient ¶ added in v0.16.0
type APIClient struct {
// contains filtered or unexported fields
}
APIClient implements Querier against a running tapes API server. The wire shapes mirror api.TraceListResponse / api.TraceDetail without importing the server package — same precedent as the other CLI-side clients.
func NewAPIClient ¶ added in v0.16.0
NewAPIClient constructs an APIClient pointed at apiTarget (e.g. "http://127.0.0.1:8081").
func (*APIClient) TraceSummaries ¶ added in v0.16.0
TraceSummaries implements Querier via GET /v1/traces?session_id=.
type GenerateOptions ¶
type GenerateOptions struct {
Since *time.Time // only include turns starting on or after this time
Until *time.Time // only include turns starting on or before this time
}
GenerateOptions controls filtering for skill generation.
type Generator ¶
type Generator struct {
// contains filtered or unexported fields
}
Generator extracts skills from session transcripts via an LLM.
Transcripts are built from the span model: each user-visible turn contributes its prompt plus the conversation-spine ("main" call-kind, main-thread) llm span outputs, with tool usage summarized between responses. Offshoot calls (permission checks, title-gen, …) and injected context never reach the prompt — the extraction LLM sees the actual conversation, not the harness's shadow traffic.
func NewGenerator ¶
func NewGenerator(query Querier, llmCall LLMCallFunc) *Generator
NewGenerator creates a new skill Generator.
func (*Generator) Generate ¶
func (g *Generator) Generate(ctx context.Context, sessionIDs []string, name, skillType string, opts *GenerateOptions) (*Skill, error)
Generate extracts a skill from one or more session IDs. Each ID is a product session (a /v1/sessions UUID); its derived turn/span projection is loaded as the conversation transcript.
type LLMCallFunc ¶ added in v0.16.0
LLMCallFunc is the signature for an LLM inference call.
func NewLLMCaller ¶ added in v0.16.0
func NewLLMCaller(cfg LLMCallerConfig) (LLMCallFunc, error)
NewLLMCaller creates an LLMCallFunc based on the provided configuration. Resolution order for API key:
- Explicit APIKey in config
- credentials.Manager (from tapes auth)
- Environment variables (OPENAI_API_KEY / ANTHROPIC_API_KEY)
type LLMCallerConfig ¶ added in v0.16.0
type LLMCallerConfig struct {
Provider string // "openai", "anthropic", or "ollama"
Model string // e.g. "gpt-4o-mini", "claude-haiku-4-5-20251001"
APIKey string // explicit API key (highest priority)
BaseURL string // override base URL
CredMgr *credentials.Manager // credentials from tapes auth
}
LLMCallerConfig holds configuration for creating an LLM caller.
type Querier ¶ added in v0.16.0
type Querier interface {
// TraceSummaries returns the user-visible turns of a session
// (GET /v1/traces?session_id=), newest derive's projection.
TraceSummaries(ctx context.Context, sessionID string) ([]TraceSummary, error)
// Trace returns one turn's spans with full payloads
// (GET /v1/traces/{trace_id}).
Trace(ctx context.Context, traceID string) (*Trace, error)
}
Querier is the read surface skill generation needs from the tapes trace API: turn summaries for a session, and span payloads for one turn. The HTTP client below implements it; tests substitute a fake.
type Skill ¶
type Skill struct {
Name string `json:"name"` // kebab-case identifier
Description string `json:"description"` // trigger description for Claude
Version string `json:"version"` // semver, default "0.1.0"
Tags []string `json:"tags"` // e.g. ["debugging", "react"]
Type string `json:"type"` // "workflow", "domain-knowledge", "prompt-template"
Content string `json:"content"` // markdown body (instructions)
Sessions []string `json:"sessions"` // source session IDs
CreatedAt time.Time `json:"created_at"`
}
Skill represents a Claude Code skill extracted from session data.
type Span ¶ added in v0.16.0
type Span struct {
SpanID string
ParentSpanID string
Kind string // "llm", "tool", "agent", "event"
Name string // tool name for tool spans
Seq int64
// CallKind is the derive-time taxonomy ("main", "offshoot:…",
// "injected:…") carried in span metadata; empty for tool spans.
CallKind string
// ThreadID is the harness sub-thread ("" = the main conversation).
ThreadID string
// Output is the decoded output content for llm spans (nil for
// tool spans — the builder only needs their Name).
Output []llm.ContentBlock
}
Span is the slice of the API's span shape the transcript builder consumes: identity, ordering, the call-kind taxonomy, and the decoded output content for llm spans.
type TraceSummary ¶ added in v0.16.0
type TraceSummary struct {
TraceID string
UserPrompt string
ResponsePreview string
// Synthetic is non-empty for turns the harness manufactured
// (compaction, resume replay); they carry no user intent and are
// excluded from skill transcripts.
Synthetic string
StartedAt time.Time
// Token counts folded by the deriver for the turn. Total* spans the
// whole turn (spine + harness shadow calls); Main* counts only the
// conversation-spine calls. Surfaced by the checkout export.
TotalInputTokens int64
TotalOutputTokens int64
MainInputTokens int64
MainOutputTokens int64
}
TraceSummary is one user-visible turn header — the turn-grain prompt/response pair the deriver folded for the session.
func SessionTurns ¶ added in v0.16.0
func SessionTurns(ctx context.Context, query Querier, sessionID string, opts ...TranscriptOption) ([]TraceSummary, error)
SessionTurns returns the filtered, user-visible turns of a session after applying any --trace and time-window options. It is the shared turn-resolution step behind BuildSessionTranscript and the structured (jsonl) export. Returns an error when no turns remain.
type TranscriptOption ¶ added in v0.16.0
type TranscriptOption func(*transcriptConfig)
TranscriptOption configures BuildSessionTranscript.
func WithTimeFilter ¶ added in v0.16.0
func WithTimeFilter(opts *GenerateOptions) TranscriptOption
WithTimeFilter applies the --since/--until turn window. A nil opts is a no-op, mirroring skill generation's filtering.
func WithTraceFilter ¶ added in v0.16.0
func WithTraceFilter(traceID string) TranscriptOption
WithTraceFilter restricts the transcript to a single turn (the --trace case). Other turns in the session are dropped before rendering.