Skip to content

Add standard frontmatter fields with typed generic Markdown (metadata-only)#122

Merged
alexec merged 18 commits into
mainfrom
copilot/add-standard-frontmatter-fields
Nov 22, 2025
Merged

Add standard frontmatter fields with typed generic Markdown (metadata-only)#122
alexec merged 18 commits into
mainfrom
copilot/add-standard-frontmatter-fields

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 21, 2025

Summary

This PR adds standard frontmatter fields with typed generic Markdown, reinstates the -r and -a flags, and adds MCP server collection functionality.

Changes

Standard Frontmatter Fields

  • Added typed frontmatter structures for tasks and rules
  • Generic Markdown[T] type for type-safe frontmatter handling
  • Standard fields: agent, languages, model, single_shot, timeout, mcp_servers, resume, selectors

Reinstated Flags

  • -r flag: Resume mode that skips rule discovery and bootstrap scripts
  • -a flag: Target agent flag that excludes that agent's own rules
    • Not used as a selector
    • Excludes agent-specific paths (e.g., CLAUDE.md for -a claude)
    • Excludes rules with matching agent field in frontmatter
    • Task frontmatter agent field overrides -a flag when present

Type Simplification

  • Merged TargetAgent type into Agent type
  • Renamed targetAgent field to agent throughout codebase

Library Enhancements

  • Added WithResume option for programmatic resume mode
  • Added WithAgent option for programmatic agent specification
  • Added Result.MCPServers() method to collect all MCP servers from rules and task

Behavior

  • Resume mode (-r): Skips all rule discovery and bootstrap scripts, returns only task content
  • Agent exclusion (-a): Prevents loading rules that the agent would load itself
  • Task frontmatter agent field takes precedence over -a flag
  • MCP servers are collected from both task and all included rules via Result.MCPServers()

Testing

  • All existing tests pass
  • Added comprehensive tests for resume mode with bootstrap script verification
  • Added tests for agent exclusion functionality
  • Added tests for MCP server collection method

Copilot AI and others added 2 commits November 21, 2025 15:50
- Implemented agent field as default selector (filters rules)
- Implemented language field as default selector (supports string or array)
- Added model, single_shot, timeout, mcp_servers as metadata fields
- Added comprehensive tests for all new functionality
- Updated documentation with detailed examples
- Added example files demonstrating standard fields

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Use type switching for agent field similar to language field for better consistency and code clarity

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot AI changed the title [WIP] Add standard FrontMatter fields for task management Add standard frontmatter fields with automatic selector behavior Nov 21, 2025
Copilot AI requested a review from alexec November 21, 2025 15:55
@alexec
Copy link
Copy Markdown
Contributor

alexec commented Nov 21, 2025

@copilot Languages should be lower-case. E.g. "go" not "Go".

- Changed all language examples from uppercase (Go, Python, JavaScript) to lowercase (go, python, javascript)
- Updated timeout field to use time.Duration format (e.g., "10m") instead of numeric seconds
- Fixed agent field behavior: now excludes agent's own directories (like -a flag) instead of acting as selector
- Added types.go with TaskFrontMatter and RuleFrontMatter struct definitions
- Updated all tests to reflect new behavior
- Updated documentation to correctly describe agent field behavior

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot Languages should be lower-case. E.g. "go" not "Go".

Fixed in 4b5c2b4. All language references changed to lowercase (go, python, javascript) throughout documentation, examples, and tests.

Log a warning when an invalid agent name is found in task frontmatter to help users identify configuration issues

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
@alexec
Copy link
Copy Markdown
Contributor

alexec commented Nov 21, 2025

@copilot Both TaskFrontMatter and RuleFrontMatter should extend FrontMatter. That type is a map[string]any, so it probably needs to change to a

type FrontMatter struct {
Content map[string]anyjson:-
}

- Changed FrontMatter from type alias to struct with Content field
- Made TaskFrontMatter and RuleFrontMatter extend FrontMatter
- Split types into separate files (frontmatter.go, task_frontmatter.go, rule_frontmatter.go)
- Added MCP server config types in pkg/config package
- Updated all code and tests to work with new FrontMatter structure
- All tests passing

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot Both TaskFrontMatter and RuleFrontMatter should extend FrontMatter. That type is a map[string]any, so it probably needs to change to a

type FrontMatter struct {...

Implemented in dde4d2a. Changed FrontMatter to a struct with Content field, and made both TaskFrontMatter and RuleFrontMatter extend it using embedding. All types are now in separate files as requested.

@alexec
Copy link
Copy Markdown
Contributor

alexec commented Nov 21, 2025

@copilot move the MCP types into pkg/codingcontext

Moved all MCP server configuration types to pkg/codingcontext package as requested

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot move the MCP types into pkg/codingcontext

Moved in b2283d7. All MCP types (Config, MCPServerConfig, TransportType) are now in pkg/codingcontext package.

Copy link
Copy Markdown
Contributor

@alexec alexec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

FrontMatter is now typed. This means Markdown must be Markdown[T any].

Presumably

TaskMarkdown = Markdown[TaskFrontMatter]
RuleMarkdown = Markdown[RuleFrontMatter]

Comment thread pkg/codingcontext/context.go Outdated
Comment thread pkg/codingcontext/mcp_config.go Outdated
Comment thread pkg/codingcontext/result.go Outdated
Comment thread pkg/codingcontext/rule_frontmatter.go Outdated
Comment thread pkg/codingcontext/rule_frontmatter.go Outdated
Comment thread pkg/codingcontext/rule_frontmatter.go Outdated
Comment thread pkg/codingcontext/task_frontmatter.go Outdated
Comment thread pkg/codingcontext/context.go Outdated

// "languages" field: filters rules by language
// Array for OR logic
for _, lang := range cc.task.FrontMatter.Languages {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Remove this filter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in c71895d. The automatic language filtering loop has been deleted, so languages is now metadata-only. Users must use the selectors field to filter rules by language.

Comment thread pkg/codingcontext/context.go Outdated

// "agent" field: use as default agent if -a flag was not provided
// This is not used for selecting tasks or rules, only as a default
if cc.task.FrontMatter.Agent != "" && !cc.targetAgent.IsSet() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove this filter. The user must have specified the selector and so this is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 91ce062. Agent field now always sets the target agent when present (no conditional check for whether it was already set).

FrontMatter FrontMatter // Parsed YAML frontmatter
Content string // Expanded content of the markdown
Tokens int // Estimated token count
type Markdown[T any] struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot

Suggested change
type Markdown[T any] struct {
type Markdown[T FrontMatter] struct {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in 91ce062. Changed to Markdown[T FrontMatter] for better type safety.

Comment thread pkg/codingcontext/result.go Outdated
}

// NewMarkdown creates a new Markdown with the given frontmatter
func NewMarkdown[T any](t T) Markdown[T] {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot remove this unreachable code.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in 91ce062. Deleted the BootstrapPath() method entirely.

- Removed automatic filtering loop for languages field (lines 470-474)
- Languages field is now metadata only, does not filter rules
- Only the explicit selectors field filters rules
- Updated comments to clarify languages is metadata-only

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Comment thread pkg/codingcontext/result.go Outdated
Copilot AI changed the title Add standard frontmatter fields with typed generic Markdown Add standard frontmatter fields with typed generic Markdown (metadata-only) Nov 22, 2025
Copilot AI requested a review from alexec November 22, 2025 01:04
…ing, constrain Markdown generic

- Removed Path field from Markdown struct (unreachable/unused)
- Removed BootstrapPath() method (unreachable code)
- Changed Markdown[T any] to Markdown[T FrontMatter] for type constraint
- Removed agent default behavior check - agent field now always sets target agent when present
- Removed unused filepath and strings imports from result.go

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Comment thread pkg/codingcontext/context.go Outdated
- Task names now based on filename instead of task_name frontmatter field
- Removed resume flag (-r), resume is now a selector (-s resume=true)
- Tasks no longer have bootstrap scripts (only rules do)
- Language field is metadata only, not automatically added as selector
- Updated all tests to reflect these changes
@alexec alexec removed the request for review from swedishborgie November 22, 2025 04:21
@alexec
Copy link
Copy Markdown
Contributor

alexec commented Nov 22, 2025

@copilot Please reinstate the resume option.

@alexec
Copy link
Copy Markdown
Contributor

alexec commented Nov 22, 2025

@copilot Add back the -"a" flag. This time, it is for the default agent to be used. If the task file has an agent, that task flie agent overrides it. It is used, as it was previously, to prevent output of the files the agent already uses. E.g. CLAUDE.md for "claude".

- Reinstated -r flag in main.go that was removed
- Added WithResume option to codingcontext package
- Updated findExecuteRuleFiles to check cc.resume directly
- Added comprehensive tests for resume mode including bootstrap script verification
- Resume mode now properly skips all rule discovery and bootstrap scripts
- Reinstated -a flag for specifying target agent
- Merged TargetAgent type into Agent type
- Renamed targetAgent field to agent throughout codebase
- Agent type now handles both agent identification and exclusion logic
- Task frontmatter agent field overrides -a flag when set
- Excludes agent-specific paths and rules with matching agent field
- Added Result.MCPServers() method to collect all MCP servers
- Collects servers from both task and all included rules
- Task servers included first, followed by rule servers
- Added comprehensive tests for various scenarios
@alexec alexec marked this pull request as ready for review November 22, 2025 18:25
@alexec alexec enabled auto-merge (squash) November 22, 2025 18:25
@alexec alexec merged commit 4c030f9 into main Nov 22, 2025
1 check passed
@alexec alexec deleted the copilot/add-standard-frontmatter-fields branch November 22, 2025 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants