report

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 25 Imported by: 0 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 report makes shareable session reports: a read-only, redacted page of one session that anyone with its link can open without signing in to the dashboard. Pull request descriptions link it so that reviewers without a dashboard account (outside contributors, readers of a public repository) can follow which step wrote each changed line.

A link is a token the server signs; kōjō stores no token. Which sessions may have one is the day-2 object settings/reports, read when a link is made and again each time one is opened. What the page leaves out is listed in build.go.

Index

Constants

View Source
const (
	// ActionLink is audited when a person makes a link (never with the
	// link itself).
	ActionLink = "report.link"
	// ActionRevoke is audited when an admin revokes a session's links. The
	// number of these entries is the revocation count every token carries:
	// the audit log is append-only, so a revocation cannot be undone.
	ActionRevoke = "report.revoke"
)

Audit actions.

View Source
const (

	// MaxRevocations bounds how often one session's links can be revoked,
	// so the count a token carries is always read exactly.
	MaxRevocations = 1000
)

Variables

View Source
var (
	// ErrInvalid is a token that is malformed or was not signed with the
	// server's key.
	ErrInvalid = errors.New("report: the link is not valid")
	// ErrExpired is a token whose expiry has passed. Its claims are
	// returned with it.
	ErrExpired = errors.New("report: the link has expired")
)

Errors of Parse.

View Source
var ErrUnavailable = errors.New("report links need server.auth.session_secret, which signs them, and server.public_url, which they point at")

ErrUnavailable is returned when the server cannot make links at all.

View Source
var LeftOut = []string{
	"What models wrote and read: prompts and their instructions, the orchestrator's and subagents' own text, and the tasks the orchestrator gave subagents. A model's text can repeat its instructions, and the conversation holds team memory and messages people sent.",
	"Team and personal memory: what memory_search found and what memory_save stored.",
	"Messages people sent the session while it worked, and who sent them.",
	"The request's text and who asked when it came from anywhere but the repository's own forge (chat, the dashboard, the CLI, MCP, a schedule).",
	"On GitLab, the output of the tools that read issues and comments (get_issue, list_issues, get_pr, get_review_comments): GitLab shows kōjō confidential issues and internal notes even of a public project.",
	"Sandbox details: images, egress lists, kit setup commands and their output (kits name credentials and registries), and the arguments and output of tools this page does not know.",
	"The config the session ran with, the session's error detail, and error text of steps other than tool calls and checks: they can name credentials, hosts and internal services.",
	"In what is shown, the user and password part of URLs (a sandbox's proxy token) and the names in credential placeholders. Credentials themselves never reach a sandbox.",
}

LeftOut lists what a report never shows, and why. The page and the docs say the same.

Functions

func Decide

func Decide(set config.ReportSettings, f Facts) error

Decide applies settings/reports to a session. A confidential session never has a report, whatever the settings say.

func Render

func Render(w io.Writer, r *Report) error

Render writes the report page.

func RenderError

func RenderError(w io.Writer, title, text string) error

RenderError writes the page a link that does not open a report gets.

func SetHeaders

func SetHeaders(h http.Header)

SetHeaders sets the security headers of a report page or a page of its errors. The link in the address bar is the report's key, so no Referer carries it anywhere and nothing indexes, caches or frames the page.

Types

type Claims

type Claims struct {
	// Session is the session the report is of.
	Session string
	// Revocations is how many times the session's links had been revoked
	// when the token was made. A token is valid while that number has not
	// changed.
	Revocations int
	// Expires is when the token stops working, to the second.
	Expires time.Time
}

Claims are what a token says.

type DiffFile

type DiffFile struct {
	// Name is the path in the workspace: a linked repository's files are
	// under .kojo/linked/<name>.
	Name    string
	Status  string // new, deleted or empty
	Added   int
	Removed int
	Rows    []DiffRow
}

DiffFile is one file of the session's change.

type DiffRow

type DiffRow struct {
	// Kind is hunk, add, del, ctx or meta.
	Kind string
	// A and B are the line's numbers in the old and the new version; 0
	// where it has none.
	A, B int
	Text string
	// Step is the replay number of the step that wrote the line, 0 for a
	// line no block covers; NoStep marks a changed line no tool call wrote
	// (a kit's setup, a check of the goal critic).
	Step   int
	NoStep bool
	// StepTitle says what the step was.
	StepTitle string
}

DiffRow is one line of a file's diff.

type Facts

type Facts struct {
	// Repo is the session's repository, forge/owner/name; empty for a
	// session about none.
	Repo string
	// Public is true only when the session's repository was public when
	// the session ran, and so was everything it read beside it (linked and
	// reference repositories). Unknown counts as private.
	Public bool
	// Confidential is set when the request was confidential or the session
	// ran a skill marked confidential.
	Confidential bool
	// Kind is the request's kind.
	Kind string
}

Facts are what decides, besides settings/reports, whether a session may have a report.

type Field

type Field struct {
	Key   string
	Value string
}

Field is a named value of a step.

type Link struct {
	Session   string    `json:"session"`
	URL       string    `json:"url"`
	ExpiresAt time.Time `json:"expires_at"`
}

Link is a link to a session's report.

type Options

type Options struct {
	// Secret is server.auth.session_secret. Without one, there are no links.
	Secret string
	// PublicURL is server.public_url: links are /r/<token> under it.
	PublicURL string
	Store     store.Store
	Config    *config.Manager
	// Public reports whether a stored session's repository, and every
	// repository the session read, was public when it ran
	// (core.PublicSession). Nil counts every session as private.
	Public func(ses *store.Session) bool
	// ConfidentialSkill reports whether a skill of that name is marked
	// confidential (the built-in skills).
	ConfidentialSkill func(name string) bool
	Log               *slog.Logger
	// Now is the clock; nil means time.Now.
	Now func() time.Time
}

Options configure a Service.

type PullRequest

type PullRequest struct {
	Repo   string
	Number int
	URL    string
	Draft  bool
}

PullRequest is one pull request the session opened.

type Refused

type Refused struct{ Reason string }

Refused says why a session may not have a report. Its text is shown to the operator who asked for one.

func (*Refused) Error

func (r *Refused) Error() string

type Report

type Report struct {
	ID      string
	Title   string
	Repo    string
	Status  string
	Outcome string
	Surface string
	Trigger string
	Actor   string
	// Target is the issue or pull request the request was about.
	Target string
	// Text is the request's text, when it came from the repository's own
	// forge; TextLeftOut says why it is not shown otherwise.
	Text        string
	TextLeftOut string
	DryRun      bool
	Failed      bool

	Summary      template.HTML
	CriticReport template.HTML
	Passed       bool
	Risk         *Risk
	PullRequests []PullRequest

	CostUSD   float64
	TokensIn  int64
	TokensOut int64
	Started   time.Time
	Ended     time.Time
	Duration  string

	Steps        []Step
	StepsLeftOut int

	Diff              []DiffFile
	DiffCut           bool
	ProvenanceMissing string

	// Expires is when the link the page was opened with stops working;
	// zero for a page written to a file.
	Expires time.Time
	// Dashboard is the session's page on the dashboard, for maintainers.
	Dashboard string
	LeftOut   []string
	Generated time.Time
}

Report is what the page shows of one session.

func Build

func Build(ses *store.Session, steps []store.Step) *Report

Build makes the report of a session from its record. Everything it keeps is plain text: the page escapes it.

type Risk

type Risk struct {
	Level   string
	Score   float64
	Reasons []string
	// Pin places the score on the scale, in steps of 5%: 0 to 20.
	Pin int
}

Risk is the merge policy's assessment.

type Service

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

Service makes, checks and serves report links.

func New

func New(o Options) *Service

New builds a Service.

func (*Service) Enabled

func (s *Service) Enabled() bool

Enabled reports whether links can be made.

func (*Service) For

func (s *Service) For(ctx context.Context, ses *store.Session, public, confidential bool) (string, error)

For is the core's way in: the address of a new link to the report of a session at work, or "" when settings/reports or the session do not allow one. public and confidential are what the session knows of itself.

func (*Service) HTML

func (s *Service) HTML(ctx context.Context, id string) ([]byte, error)

HTML is the report page of a session, under the same rules as a link, for an operator to save as a file.

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, id, actor string) (int, error)

Revoke ends every link to a session's report made so far, the ones in pull request descriptions included. A link made afterwards works.

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves GET /r/{token}: the report a link opens, or a page that says why it does not. Nothing it logs or audits holds the token.

func (*Service) Share

func (s *Service) Share(ctx context.Context, id string, ttl time.Duration, actor string) (*Link, error)

Share makes a link to a session's report for a person: the settings' lifetime, or ttl when it is shorter. It is audited without the link.

type Signer

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

Signer makes and checks tokens with a key derived from the server's session secret. Every replica with the same secret reads every token.

func NewSigner

func NewSigner(secret string) *Signer

NewSigner derives the token key from secret (server.auth.session_secret). It returns nil for an empty secret: a key that changed at every restart would break every link in every pull request.

func (*Signer) Mint

func (s *Signer) Mint(c Claims) string

Mint makes a token: the version, the revocation count, the expiry and the session ID, followed by their MAC, in URL-safe base64.

func (*Signer) Parse

func (s *Signer) Parse(token string, now time.Time) (Claims, error)

Parse checks a token's MAC and reads its claims. An expired token returns its claims with ErrExpired; anything else that does not verify is ErrInvalid, with no claims.

type Step

type Step struct {
	Seq       int
	Depth     int
	Kind      string
	Name      string
	Failed    bool
	Running   bool
	Duration  string
	Model     string
	TokensIn  int64
	TokensOut int64
	CostUSD   float64
	Purpose   string
	Command   string
	Fields    []Field
	Outputs   []Field
	ExitCode  string
	Error     string
	// Note says what the report leaves out of this step.
	Note string
	// Lines are the lines of the session's change this step wrote.
	Lines []string
}

Step is one recorded step, with only what the report may show.

Jump to

Keyboard shortcuts

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