regex

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package regex defines compiled regular expressions for parsing context files and CLI output.

Index

Constants

View Source
const EntryHeaderGroups = 4

EntryHeaderGroups is the expected number of groups (including full match) returned by EntryHeader.FindStringSubmatch.

View Source
const (
	// TaskCompleteReplace is the regex replacement string for marking a task done.
	TaskCompleteReplace = "$1- [x] $3"
)

Runtime configuration.

Variables

View Source
var AbsoluteSep = regexp.MustCompile(`(&&|;|\|\||\|)\s*(/home/|/tmp/|/var/)\S*/ctx(\s|$)`)

AbsoluteSep matches absolute paths to ctx after command separator.

View Source
var BulletItem = regexp.MustCompile(`(?m)^-\s*(.+)$`)

BulletItem matches any Markdown bullet item (not just tasks).

Groups:

  • 1: item content
View Source
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
View Source
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)
View Source
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).

View Source
var CodeFencePath = regexp.MustCompile("`([^`]+\\.[a-zA-Z]{1,5})`")

CodeFencePath matches file paths in Markdown backticks.

Groups:

  • 1: file path
View Source
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.

View Source
var CtxAbsoluteStart = regexp.MustCompile(`^\s*(/home/|/tmp/|/var/)\S*/ctx(\s|$)`)

CtxAbsoluteStart matches absolute paths to ctx at start of command.

View Source
var CtxGoRun = regexp.MustCompile(`go run \./cmd/ctx`)

CtxGoRun matches go run ./cmd/ctx.

View Source
var CtxRelativeSep = regexp.MustCompile(`(&&|;|\|\||\|)\s*(\./ctx(\s|$)|\./dist/ctx)`)

CtxRelativeSep matches ./ctx or ./dist/ctx after command separator.

View Source
var CtxRelativeStart = regexp.MustCompile(`^\s*(\./ctx(\s|$)|\./dist/ctx)`)

CtxRelativeStart matches ./ctx or ./dist/ctx at start of command.

View Source
var CtxTestException = regexp.MustCompile(`/tmp/ctx-test`)

CtxTestException matches /tmp/ctx-test for integration test exemption.

View Source
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
View Source
var EntryHeading = regexp.MustCompile(`(?m)^## \[`)

EntryHeading matches any entry heading (## [timestamp]). Use for counting entries without capturing groups.

View Source
var FileNameChar = regexp.MustCompile(`[^a-zA-Z0-9-]+`)

FileNameChar matches characters not allowed in file names.

View Source
var GlobStar = regexp.MustCompile(`\*(\.\w+|[/)])`)

GlobStar matches glob-like wildcards: *.ext, */, *) etc.

View Source
var Glossary = regexp.MustCompile(`(?m)(?:^|\n)\s*(?:-\s*)?\*\*[^*]+\*\*`)

Glossary matches glossary definition entries (lines with **term**).

View Source
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.

View Source
var InstallToLocalBin = regexp.MustCompile(`(cp|install)\s.*~/\.local/bin`)

InstallToLocalBin matches cp/install to ~/.local/bin.

View Source
var LineNumber = regexp.MustCompile(`(?m)^\s*\d+→`)

LineNumber matches Claude Code's line number prefixes like " 1→".

View Source
var ListStart = regexp.MustCompile(`^(\d+\.|[-*]) `)

ListStart matches lines that begin an ordered or unordered list item.

View Source
var MarkdownHeading = regexp.MustCompile(`^(#{1,6}) (.+)$`)

MarkdownHeading matches Markdown heading lines (1-6 hashes + space).

Groups:

  • 1: hash prefix (e.g., "##")
  • 2: heading text
View Source
var MarkdownImage = regexp.MustCompile(`^\s*!\[.*]\(.*\)\s*$`)

MarkdownImage matches Markdown image lines.

View Source
var MarkdownLink = regexp.MustCompile(`\[([^]]+)]\([^)]*\.md[^)]*\)`)

MarkdownLink matches Markdown links with relative .md targets.

View Source
var MidGitPush = regexp.MustCompile(`(;|&&|\|\|)\s*git\s+push`)

MidGitPush matches mid-command git push after && || ;

View Source
var MidSudo = regexp.MustCompile(`(;|&&|\|\|)\s*sudo\s`)

MidSudo matches mid-command sudo after && || ;

View Source
var MultiPart = regexp.MustCompile(`-p\d+\.md$`)

MultiPart matches session part files like "...-p2.md", "...-p3.md", etc.

View Source
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
View Source
var Phase = regexp.MustCompile(`^#{1,6}\s+Phase`)

Phase matches phase headers at any heading level (e.g., "## Phase 1", "### Phase").

View Source
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.

View Source
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
View Source
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
View Source
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.

View Source
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)
View Source
var TaskMultiline = regexp.MustCompile(`(?m)` + taskPattern)

TaskMultiline matches task items across multiple lines.

Use with FindAllStringSubmatch on multiline content.

View Source
var ToolBold = regexp.MustCompile(`🔧\s*\*\*(.+?)\*\*`)

ToolBold matches tool-use lines like "🔧 **Glob: .context/journal/*.md**".

View Source
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.

Jump to

Keyboard shortcuts

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