Documentation
¶
Overview ¶
Package regex defines compiled regular expressions for parsing context files and CLI output.
Index ¶
Constants ¶
const EntryHeaderGroups = 4
EntryHeaderGroups is the expected number of groups (including full match) returned by EntryHeader.FindStringSubmatch.
const (
// TaskCompleteReplace is the regex replacement string for marking a task done.
TaskCompleteReplace = "$1- [x] $3"
)
Runtime configuration.
Variables ¶
var AbsoluteSep = regexp.MustCompile(`(&&|;|\|\||\|)\s*(/home/|/tmp/|/var/)\S*/ctx(\s|$)`)
AbsoluteSep matches absolute paths to ctx after command separator.
var BulletItem = regexp.MustCompile(`(?m)^-\s*(.+)$`)
BulletItem matches any Markdown bullet item (not just tasks).
Groups:
- 1: item content
var CodeFenceClose = regexp.MustCompile("(```+) *(\\S)")
CodeFenceClose matches code fences immediately followed by text. E.g., "```text" where text should be on its own line after the fence. Groups:
- 1: the code fence (3+ backticks)
- 2: following non-whitespace character
var CodeFenceInline = regexp.MustCompile("(\\S) *(```+)")
CodeFenceInline matches code fences that appear inline after text. E.g., "some text: ```code" where fence should be on its own line. Groups:
- 1: preceding non-whitespace character
- 2: the code fence (3+ backticks)
var CodeFenceLine = regexp.MustCompile("^\\s*(`{3,}|~{3,})(.*)$")
CodeFenceLine matches lines that are code fence markers (3+ backticks or tildes, optionally followed by a language tag).
var CodeFencePath = regexp.MustCompile("`([^`]+\\.[a-zA-Z]{1,5})`")
CodeFencePath matches file paths in Markdown backticks.
Groups:
- 1: file path
var CpMvToBin = regexp.MustCompile(`(cp|mv)\s+\S+\s+(/usr/local/bin|/usr/bin|~/go/bin|~/.local/bin|/home/\S+/go/bin|/home/\S+/.local/bin)`)
CpMvToBin matches cp/mv to bin directories.
var CtxAbsoluteStart = regexp.MustCompile(`^\s*(/home/|/tmp/|/var/)\S*/ctx(\s|$)`)
CtxAbsoluteStart matches absolute paths to ctx at start of command.
var CtxGoRun = regexp.MustCompile(`go run \./cmd/ctx`)
CtxGoRun matches go run ./cmd/ctx.
var CtxRelativeSep = regexp.MustCompile(`(&&|;|\|\||\|)\s*(\./ctx(\s|$)|\./dist/ctx)`)
CtxRelativeSep matches ./ctx or ./dist/ctx after command separator.
var CtxRelativeStart = regexp.MustCompile(`^\s*(\./ctx(\s|$)|\./dist/ctx)`)
CtxRelativeStart matches ./ctx or ./dist/ctx at start of command.
var CtxTestException = regexp.MustCompile(`/tmp/ctx-test`)
CtxTestException matches /tmp/ctx-test for integration test exemption.
var EntryHeader = regexp.MustCompile(
`## \[(\d{4}-\d{2}-\d{2})-(\d{6})] (.+)`,
)
EntryHeader matches entry headers like "## [2026-01-28-051426] Title here".
Groups:
- 1: date (YYYY-MM-DD)
- 2: time (HHMMSS)
- 3: title
var EntryHeading = regexp.MustCompile(`(?m)^## \[`)
EntryHeading matches any entry heading (## [timestamp]). Use for counting entries without capturing groups.
var FileNameChar = regexp.MustCompile(`[^a-zA-Z0-9-]+`)
FileNameChar matches characters not allowed in file names.
var GlobStar = regexp.MustCompile(`\*(\.\w+|[/)])`)
GlobStar matches glob-like wildcards: *.ext, */, *) etc.
var Glossary = regexp.MustCompile(`(?m)(?:^|\n)\s*(?:-\s*)?\*\*[^*]+\*\*`)
Glossary matches glossary definition entries (lines with **term**).
var InlineCodeAngle = regexp.MustCompile("`([^`\n]*[<>][^`\n]*)`")
InlineCodeAngle matches single-line inline code spans containing angle brackets (e.g., `</com`). Backticks are replaced with quotes and angles with HTML entities to prevent broken HTML in rendered output.
var InstallToLocalBin = regexp.MustCompile(`(cp|install)\s.*~/\.local/bin`)
InstallToLocalBin matches cp/install to ~/.local/bin.
var LineNumber = regexp.MustCompile(`(?m)^\s*\d+→`)
LineNumber matches Claude Code's line number prefixes like " 1→".
var ListStart = regexp.MustCompile(`^(\d+\.|[-*]) `)
ListStart matches lines that begin an ordered or unordered list item.
var MarkdownHeading = regexp.MustCompile(`^(#{1,6}) (.+)$`)
MarkdownHeading matches Markdown heading lines (1-6 hashes + space).
Groups:
- 1: hash prefix (e.g., "##")
- 2: heading text
var MarkdownImage = regexp.MustCompile(`^\s*!\[.*]\(.*\)\s*$`)
MarkdownImage matches Markdown image lines.
var MarkdownLink = regexp.MustCompile(`\[([^]]+)]\([^)]*\.md[^)]*\)`)
MarkdownLink matches Markdown links with relative .md targets.
var MidGitPush = regexp.MustCompile(`(;|&&|\|\|)\s*git\s+push`)
MidGitPush matches mid-command git push after && || ;
var MidSudo = regexp.MustCompile(`(;|&&|\|\|)\s*sudo\s`)
MidSudo matches mid-command sudo after && || ;
var MultiPart = regexp.MustCompile(`-p\d+\.md$`)
MultiPart matches session part files like "...-p2.md", "...-p3.md", etc.
var OversizeTokens = regexp.MustCompile(`Injected:\s+(\d+)\s+tokens`)
OversizeTokens matches "Injected: NNNNN tokens" in the injection-oversize flag file.
Groups:
- 1: token count digits
var Phase = regexp.MustCompile(`^#{1,6}\s+Phase`)
Phase matches phase headers at any heading level (e.g., "## Phase 1", "### Phase").
var SystemClaudeTag = regexp.MustCompile(`</?(?:command-message|command-name|local-command-caveat)>`)
SystemClaudeTag matches Claude Code internal markup tags that leak into session titles via the first user message. This MUST remain an allowlist of known Claude Code tags: do NOT replace with a blanket regex.
var SystemContextUpdate = regexp.MustCompile(`<context-update(\s+[^>]+)>([^<]+)</context-update>`)
SystemContextUpdate matches context-update XML tags.
Groups:
- 1: opening tag attributes (e.g., ` type="task" context="..."`)
- 2: content between tags
var SystemReminder = regexp.MustCompile(`(?s)<system-reminder>\s*(.*?)\s*</system-reminder>`)
SystemReminder matches <system-reminder>...</system-reminder> blocks. These are injected by Claude Code into tool results. Groups:
- 1: content between tags
var Task = regexp.MustCompile(taskPattern)
Task matches a task item on a single line.
Use with MatchString or FindStringSubmatch on individual lines. For multiline content, use TaskMultiline.
var TaskDoneTimestamp = regexp.MustCompile(`#done:(\d{4}-\d{2}-\d{2}-\d{6})`)
TaskDoneTimestamp extracts the #done: timestamp from a task line.
Groups:
- 1: timestamp (YYYY-MM-DD-HHMMSS)
var TaskMultiline = regexp.MustCompile(`(?m)` + taskPattern)
TaskMultiline matches task items across multiple lines.
Use with FindAllStringSubmatch on multiline content.
var ToolBold = regexp.MustCompile(`🔧\s*\*\*(.+?)\*\*`)
ToolBold matches tool-use lines like "🔧 **Glob: .context/journal/*.md**".
var TurnHeader = regexp.MustCompile(`^### (\d+)\. (.+?) \((\d{2}:\d{2}:\d{2})\)$`)
TurnHeader matches conversation turn headers.
Groups:
- 1: turn number
- 2: role (e.g. "Assistant", "Tool Output")
- 3: timestamp (HH:MM:SS)
Functions ¶
This section is empty.
Types ¶
This section is empty.