Help us shape the future of Go! Take the 2026 Go Developer Survey

render

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package render turns the server's model into the readable half of a tool result, and prepares text other people wrote before anything shows it (docs/architecture.md §4.1, §4.8).

The preparation is the part that matters for safety: hidden text is removed and counted, links show where they go, long text is cut at a budget that is stated, and everything someone else wrote is rendered inside a boundary whose token is drawn per call, so the content cannot close it.

Index

Constants

View Source
const (
	// DescriptionBudget bounds an issue or merge request description.
	DescriptionBudget = 20000
	// FileBudget bounds the text of one file.
	FileBudget = 60000
	// DiscussionBudget bounds the comment text of one page of threads.
	DiscussionBudget = 30000
	// NoteBudget bounds one comment within that.
	NoteBudget = 6000
	// DiffBudget bounds the diffs of one commit.
	DiffBudget = 40000
	// CommitMessageBudget bounds a commit message.
	CommitMessageBudget = 8000
	// TitleChars bounds a one-line title.
	TitleChars = 200
)

Budgets in characters (§4.8). A result states the one it used, so a cut text is never mistaken for a short one.

View Source
const (
	JobLogBytes    = 40000
	MaxJobLogBytes = 100000
)

JobLogBytes is the default window of a job log, in bytes of the stored log, and MaxJobLogBytes the most one call reads (§4.8).

View Source
const TimestampPrefix = `[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\.[0-9]+)?Z [0-9a-fA-F]{2}[OE](\+| ?)`

TimestampPrefix matches a runner's per-line timestamp and stream marker; group 1 is "+" on a line that continues the one before.

Variables

This section is empty.

Functions

func ApprovalWrite

func ApprovalWrite(w model.ApprovalWrite, _ Boundary) string

ApprovalWrite renders approve_merge_request and unapprove_merge_request.

func Artifact

func Artifact(a model.Artifact, bd Boundary) string

Artifact renders get_job_artifact.

func Artifacts

func Artifacts(l model.Artifacts, _ Boundary) string

Artifacts renders list_job_artifacts.

func Blame

func Blame(bl model.Blame, bd Boundary) string

Blame renders get_blame.

func BranchDelete

func BranchDelete(w model.BranchDelete, _ Boundary) string

BranchDelete renders delete_branch.

func BranchWrite

func BranchWrite(w model.BranchWrite, _ Boundary) string

BranchWrite renders create_branch.

func Branches

func Branches(l model.Branches, bd Boundary) string

Branches renders list_branches.

func Code

func Code(s string) (string, int)

Code prepares text that is not rendered as Markdown — file contents, diffs, commit messages. Nothing is dropped, because the text may be edited later on the strength of what was shown; each hidden character is written out as <U+202E> instead, which is also how a reviewer would want to see it. It returns the text and how many were made visible.

func CommentDelete

func CommentDelete(w model.CommentDelete, _ Boundary) string

CommentDelete renders delete_comment.

func CommentWrite

func CommentWrite(w model.CommentWrite, _ Boundary) string

CommentWrite renders add_comment and add_review_comment.

func Commit

func Commit(c model.Commit, bd Boundary) string

Commit renders get_commit.

func CommitWrite

func CommitWrite(w model.CommitWrite, _ Boundary) string

CommitWrite renders create_commit.

func Commits

func Commits(l model.Commits, bd Boundary) string

Commits renders list_commits.

func Compare

func Compare(c model.Compare, bd Boundary) string

Compare renders compare_refs.

func ContentType

func ContentType(b []byte) string

ContentType guesses a media type from the first bytes.

func Cut

func Cut(text string, offset, budget int) (string, model.Budget)

Cut returns the part of text that starts at offset and fits budget, ending at a paragraph boundary when one falls in the second half of the window, else at a line boundary there, else at the budget. Offsets and counts are in characters (runes), never bytes, so a continue offset never lands inside one.

An offset past the end yields nothing and a budget whose ContinueOffset is null; the caller decides whether that is an error.

func Deployments

func Deployments(l model.Deployments, _ Boundary) string

Deployments renders list_deployments.

func DiscussionWrite

func DiscussionWrite(w model.DiscussionWrite, _ Boundary) string

DiscussionWrite renders resolve_discussion.

func Discussions

func Discussions(d model.Discussions, bd Boundary) string

Discussions renders list_discussions.

func DraftDelete

func DraftDelete(w model.DraftDelete, _ Boundary) string

DraftDelete renders delete_review_comment.

func DraftNotes

func DraftNotes(d model.DraftNotes, bd Boundary) string

DraftNotes renders list_review_comments.

func Environments

func Environments(l model.Environments, _ Boundary) string

Environments renders list_environments.

func Events

func Events(l model.Events, bd Boundary) string

Events renders list_events.

func File

func File(f model.File, bd Boundary) string

File renders get_file.

func Ident

func Ident(s string) string

Ident prepares a name someone else chose — a file path, a branch, a label, a topic — for one line of text. Nothing is dropped, folded or cut, since the name may be passed back to a tool; each control or hidden character is written out as <U+000A> instead, so a newline in a file name cannot start a line that reads as the server's.

func IsBinary

func IsBinary(b []byte) bool

IsBinary reports content that is not text: a NUL byte, or bytes that are not UTF-8, in the first 8,000. Binary content is described by its metadata, never shown as lossy text (§4.8).

func Issue

func Issue(is model.Issue, bd Boundary) string

Issue renders get_issue.

func IssueLinkWrite

func IssueLinkWrite(w model.IssueLinkWrite, _ Boundary) string

IssueLinkWrite renders link_issues and unlink_issues.

func IssueMove

func IssueMove(w model.IssueMove, _ Boundary) string

IssueMove renders move_issue.

func IssueWrite

func IssueWrite(w model.IssueWrite, _ Boundary) string

IssueWrite renders create_issue and update_issue.

func ItemList

func ItemList(l model.ItemList, noun string, bd Boundary) string

ItemList renders search_issues and search_merge_requests. noun is "issues" or "merge requests".

func JobLog

func JobLog(l model.JobLog, bd Boundary) string

JobLog renders get_job_log.

func JobWrite

func JobWrite(w model.JobWrite, _ Boundary) string

JobWrite renders retry_job and play_job.

func Jobs

func Jobs(l model.Jobs, _ Boundary) string

Jobs renders list_jobs.

func LabelWrite

func LabelWrite(w model.LabelWrite, bd Boundary) string

LabelWrite renders create_label, update_label and delete_label.

func Labels

func Labels(l model.Labels, bd Boundary) string

Labels renders list_labels.

func Line

func Line(s string, max int) (string, int)

Line prepares a one-line field someone else wrote, such as a title: hidden characters dropped, runs of spaces and control characters (line and paragraph separators included) folded to one space, and the result cut to max characters. It returns the line and how many characters were dropped.

func Links(s, self string) string

Links rewrites Markdown links so the text shows where they go (§4.1.3). A link whose text says one thing and whose destination is another is the cheapest deception there is, and nothing is ever fetched, so what the reader needs is the host. A link on the configured instance, self, keeps its path, because that is how an issue points at another issue.

func Lint

func Lint(l model.Lint, bd Boundary) string

Lint renders lint_ci.

func Log

func Log(raw []byte) string

Log turns a window of a stored log into the text GitLab's job page shows (see above). It does not mask secrets or make hidden characters visible; the caller does both, on what this returns.

func MRCommits

func MRCommits(c model.MRCommits, bd Boundary) string

MRCommits renders list_mr_commits.

func MRDiff

func MRDiff(d model.MRDiff, bd Boundary) string

MRDiff renders get_mr_diff.

func MRFiles

func MRFiles(f model.MRFiles, _ Boundary) string

MRFiles renders list_mr_files.

func Markdown

func Markdown(s string, self string) (string, int)

Markdown prepares Markdown someone else wrote for display: HTML comments and reference definitions no link uses, outside code fences, are dropped, hidden characters are dropped everywhere, and links show their destination. It returns the text and how many characters were dropped.

Comments inside a fence are left, because there they are visible: the rule is to remove what a person reading the page would not see and the model would.

func Me

func Me(m model.Me, _ Boundary) string

Me renders get_me. It shows nothing that needs a boundary.

func Members

func Members(l model.Members, _ Boundary) string

Members renders list_members.

func MergeRequest

func MergeRequest(mr model.MergeRequest, bd Boundary) string

MergeRequest renders get_merge_request.

func MergeRequestWrite

func MergeRequestWrite(w model.MergeRequestWrite, _ Boundary) string

MergeRequestWrite renders create_merge_request and update_merge_request.

func MergeWrite

func MergeWrite(w model.MergeWrite, _ Boundary) string

MergeWrite renders merge_merge_request.

func MilestoneWrite

func MilestoneWrite(w model.MilestoneWrite, bd Boundary) string

MilestoneWrite renders create_milestone, update_milestone and delete_milestone.

func Milestones

func Milestones(m model.Milestones, bd Boundary) string

Milestones renders list_milestones.

func PickWrite

func PickWrite(w model.PickWrite, bd Boundary) string

PickWrite renders cherry_pick_commit and revert_commit.

func Pipeline

func Pipeline(p model.PipelineDetail, bd Boundary) string

Pipeline renders get_pipeline.

func PipelineWrite

func PipelineWrite(w model.PipelineWrite, _ Boundary) string

PipelineWrite renders run_pipeline, retry_pipeline and cancel_pipeline.

func Pipelines

func Pipelines(l model.Pipelines, _ Boundary) string

Pipelines renders list_pipelines.

func Project

func Project(p model.Project, bd Boundary) string

Project renders get_project.

func ProjectList

func ProjectList(l model.ProjectList, bd Boundary) string

ProjectList renders search_projects.

func RebaseWrite

func RebaseWrite(w model.RebaseWrite, bd Boundary) string

RebaseWrite renders rebase_merge_request.

func Release

func Release(r model.Release, bd Boundary) string

Release renders get_release.

func ReleaseWrite

func ReleaseWrite(w model.ReleaseWrite, _ Boundary) string

ReleaseWrite renders create_release.

func Releases

func Releases(l model.Releases, bd Boundary) string

Releases renders list_releases.

func Resolved

func Resolved(r model.Resolved, _ Boundary) string

Resolved renders resolve_url. It shows nothing that needs a boundary.

func ReviewSubmit

func ReviewSubmit(w model.ReviewSubmit, _ Boundary) string

ReviewSubmit renders submit_review.

func Search(s model.Search, bd Boundary) string

Search renders search.

func Snippet

func Snippet(s model.Snippet, bd Boundary) string

Snippet renders get_snippet.

func SnippetWrite

func SnippetWrite(w model.SnippetWrite, _ Boundary) string

SnippetWrite renders create_snippet.

func Snippets

func Snippets(l model.Snippets, bd Boundary) string

Snippets renders list_snippets.

func StripANSI

func StripANSI(s string) string

StripANSI removes terminal escapes, which also hide a secret from the masks: a color code before a token leaves no word boundary to match.

func TagWrite

func TagWrite(w model.TagWrite, _ Boundary) string

TagWrite renders create_tag and delete_tag.

func Tags

func Tags(t model.Tags, bd Boundary) string

Tags renders list_tags.

func Todos

func Todos(l model.Todos, bd Boundary) string

Todos renders list_todos.

func TodosDone

func TodosDone(w model.TodosDone, _ Boundary) string

TodosDone renders mark_todos_done.

func Tree

func Tree(t model.Tree, _ Boundary) string

Tree renders list_tree.

func Users

func Users(l model.Users, _ Boundary) string

Users renders find_users.

func WikiDelete

func WikiDelete(w model.WikiDelete, _ Boundary) string

WikiDelete renders delete_wiki_page.

func WikiPage

func WikiPage(p model.WikiPage, bd Boundary) string

WikiPage renders get_wiki_page.

func WikiPages

func WikiPages(l model.WikiPages, bd Boundary) string

WikiPages renders list_wiki_pages.

func WikiWrite

func WikiWrite(w model.WikiWrite, _ Boundary) string

WikiWrite renders save_wiki_page.

Types

type Boundary

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

Boundary marks text someone else wrote (§4.1.1). Its token is drawn per tool call, so text written before the call cannot know it and cannot close the block early: a forged end marker carries the wrong token. Markers are also defused inside the text, so a forgery does not even look like one.

func NewBoundary

func NewBoundary() Boundary

NewBoundary draws a fresh token.

func (Boundary) Block

func (b Boundary) Block(o Origin, text string) string

Block wraps multi-line text:

<<<UNTRUSTED 0123abcd kind=description project=group/project item=#12 author=@alice>>>
text
<<<END 0123abcd>>>

func (Boundary) Inline

func (b Boundary) Inline(text string) string

Inline wraps one line of text, such as a title, in place.

func (Boundary) Notice

func (b Boundary) Notice() string

Notice is the line a result puts before its first block. It names the token, so the reader knows which markers are the server's.

func (Boundary) Token

func (b Boundary) Token() string

Token is the per-call token.

type LogSection

type LogSection struct {
	Name       string
	Start, End int
}

LogSection is one section of a stored log, by byte offsets: Start is where its start marker begins, or -1 when it began before the stretch read; End is where its end marker ends, or -1 when the stretch has no end marker for it.

func LogSections

func LogSections(raw []byte) []LogSection

LogSections finds the sections of a stretch of a stored log, in the order their markers appear. A section whose end marker is in the stretch and whose start is not began before it.

type Origin

type Origin struct {
	Kind    string
	Project string
	Item    string // "#12", "!3", a file path or a commit id
	Author  string // a username, without "@"
}

Origin says where a block of text came from: its kind, the project, the issue, merge request or path, and who wrote it.

Jump to

Keyboard shortcuts

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