instructions

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package instructions discovers and composes workspace project instructions.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalid means resolver configuration or a requested scope is invalid.
	ErrInvalid = errors.New("coding instructions: invalid configuration")
	// ErrFile means a project instruction file is unsafe or unreadable.
	ErrFile = errors.New("coding instructions: file error")
	// ErrTooLarge means an instruction file or combined source set exceeds its
	// configured byte budget.
	ErrTooLarge = errors.New("coding instructions: content too large")
	// ErrBinary means an instruction source is not UTF-8 text.
	ErrBinary = errors.New("coding instructions: binary content")
)

Functions

This section is empty.

Types

type Limits

type Limits struct {
	FileBytes  int64
	TotalBytes int64
}

Limits bounds project instruction discovery.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits returns the production project-instruction budgets.

type Resolver

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

Resolver discovers AGENTS.md files within one workspace tree.

func New

func New(tree *workspace.Tree, limits Limits) (*Resolver, error)

New returns a project-instruction Resolver.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, scope string) (Set, error)

Resolve discovers AGENTS.md from the workspace root through scope. Later sources have higher precedence when their instructions conflict.

Example
package main

import (
	"context"
	"fmt"
	"os"
	"path/filepath"

	"github.com/rsbin1178/pips/agent/harness"
	"github.com/rsbin1178/pips/internal/coding/instructions"
	"github.com/rsbin1178/pips/internal/coding/workspace"
)

func main() {
	root, err := os.MkdirTemp("", "pips-instructions-")
	if err != nil {
		panic(err)
	}
	defer func() { _ = os.RemoveAll(root) }()

	if err := os.WriteFile(filepath.Join(root, "AGENTS.md"), []byte("Run tests before finishing."), 0o600); err != nil {
		panic(err)
	}

	opened, err := workspace.Open(root)
	if err != nil {
		panic(err)
	}

	tree, err := workspace.OpenTree(opened)
	if err != nil {
		panic(err)
	}
	defer func() { _ = tree.Close() }()

	resolver, err := instructions.New(tree, instructions.DefaultLimits())
	if err != nil {
		panic(err)
	}

	set, err := resolver.Resolve(context.Background(), ".")
	if err != nil {
		panic(err)
	}

	option := harness.WithSystemFunc(func(harness.SystemContext) string {
		return set.SystemPrompt()
	})

	fmt.Println(set.Sources()[0].Path, option != nil)
}
Output:
AGENTS.md true

type Set

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

Set is an immutable-by-API project instruction snapshot.

func (Set) Bytes

func (s Set) Bytes() int

Bytes returns the total source content size.

func (Set) Sources

func (s Set) Sources() []Source

Sources returns root-to-scope instruction sources as a defensive copy.

func (Set) SystemPrompt

func (s Set) SystemPrompt() string

SystemPrompt returns the deterministic text for Harness system injection.

type Source

type Source struct {
	Path    string
	Scope   string
	Content string
	Bytes   int
}

Source is one project instruction file and its workspace-relative scope.

Jump to

Keyboard shortcuts

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