mapfolder

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

The map

This is the product's map: why the product is the way it is.

  • Read product/ first. Its rules apply to every change.
  • Each folder in capabilities/ is one promise the product makes. Read the ones your task touches.
  • glossary.md holds the words to use, and the words to avoid.

Each capability folder holds:

  • index.md: the promise, a short overview, and links to the files below.
  • rules.md: every rule. Always read it in full; there are no more to fetch.
  • decisions.md and questions.md: a contents list of every entry, then the entries. Read the contents, then take only the entries your task touches.

To cut one entry out by its slug (the first word of the line after its heading), run this in the file:

awk '/^### /{h=$0;p=0;next} h&&/^`the-slug`/{print h;p=1} p' decisions.md

With the CLI, physa map slice <capability> gives the rules and the headings of the decisions and questions, and physa map slice --entry <slug>... gives the entries you choose.

Which entries to take:

  • A decision bears on your task if its heading names something you will change, choose between, or might undo. When in doubt, take it.
  • Read each Rejected: list. Those options were tried or argued and turned down; don't bring one back without saying why.
  • An open question your task would answer: don't settle it silently. Ask, or say in your PR how you answered it.
  • Slice another capability only when your plan names it.
  • If your task would break a rule or reverse a decision, stop and ask.

Anchor each commit to the capability it serves with a trailer: Capability: <folder name>.

Documentation

Overview

Package mapfolder knows where each part of a capability lives in its folder and writes the contents that link to its entries: index.md with the promise, overview and links, and one file of entries per kind. It splits a capability's single text into its folder and formats a map's folders, never changing an entry's text.

Index

Constants

View Source
const (
	Dir             = ".physa"
	ProductDir      = Dir + "/product"
	CapabilitiesDir = Dir + "/capabilities"
)

Where the map lives, relative to the repo's root.

View Source
const (
	IndexFile     = "index.md"
	RulesFile     = "rules.md"
	DecisionsFile = "decisions.md"
	QuestionsFile = "questions.md"
)

The files of a capability's folder.

Variables

Kinds lists every kind in index.md's order.

View Source
var Products = []string{Dir + "/product.md", ProductDir + "/" + IndexFile}

Products are where a map's product is, in the old layout and in folders; either means a map.

View Source
var Readme string

Readme is .physa/README.md's text, the map's fallback for agents without the CLI (design 01 section 6). It carries the slice skill's judgment, the folder layout and how to cut one entry out by its slug. The text lives in readme.md.

Functions

func AddEntry

func AddEntry(dir, title string, k Kind, entry string) (int, int, error)

AddEntry appends entry, one entry's text, last under ## Entries of the kind file of the capability folder dir whose title is title, and regenerates that file's contents. A kind file the folder lacks is made, and index.md then links it. It returns the first and last line (from 1) the entry takes in its file. A file outside its format, with the entry appended, is an error naming the file and wrapping its *FormatError, whose line counts in that appended text; the folder is then as it was. When index.md cannot link a kind file just made, that file is left for the caller's Snapshot to remove.

func Anchor

func Anchor(heading string) string

Anchor is the link anchor GitHub makes from a heading: lowercase, every character other than a letter, a digit, a space, a hyphen or an underscore dropped, and each space turned into a hyphen. Repeated hyphens stay.

func CapabilityDir

func CapabilityDir(slug string) string

CapabilityDir is the folder of the capability named slug.

func Contents

func Contents(headings []string) []string

Contents is a kind file's contents: one line per entry, in entry order, each the heading verbatim linked to its anchor.

func Format

func Format(file, text string) (string, error)

Format rebuilds the folder file named file and normalises its spacing: a kind file's contents are regenerated from its entries, and index.md keeps its links (FormatIndex sets them). Every byte of an entry, from its heading to its last non-blank line, is kept. A file outside its format is a *FormatError.

func FormatIndex

func FormatIndex(text string, kinds []Kind) (string, error)

FormatIndex formats index.md with a link to each of kinds' files.

func HeadingProblem

func HeadingProblem(heading string) string

HeadingProblem says why a heading cannot make a stable contents line (brackets, angle brackets and asterisks break it), or is empty.

func Index

func Index(frontMatter, title, overview string, kinds []Kind) string

Index renders index.md: the front matter block with its --- lines, the title, the overview paragraph and a link to each of kinds' files, in the order rules, decisions, questions.

func IndexLink(k Kind) string

IndexLink is index.md's link line to the kind's file.

func KindFile

func KindFile(title string, kind Kind, entries []string) string

KindFile renders a kind file: its title, the contents generated from the entries, and each entry's text (its heading line through its last body line) verbatim, one blank line apart.

func SafeHeading

func SafeHeading(s string) string

SafeHeading is s without the characters HeadingProblem rejects, its words one space apart.

Types

type ErrOldLayout

type ErrOldLayout struct {
	Path string // slash-separated, relative to the root
}

ErrOldLayout says a map is still in the single-file layout, naming the first old file found.

func (ErrOldLayout) Error

func (e ErrOldLayout) Error() string

type Folder

type Folder struct {
	Files  map[string]string // file name, such as "index.md", to its text
	Source map[string][]int  // file name to, per line, the line of the single text it came from; 0 when generated
}

Folder is one capability's folder, split from its single text.

func Split

func Split(text string) (Folder, error)

Split turns one capability written as a single text (front matter, a "# " title, an optional overview paragraph, then "## Rules", "## Decisions" and "## Questions" sections of "### " entries) into its folder: index.md, plus one kind file for each kind with entries. Entry text is kept byte for byte. Without an overview the promise is the overview (its Source the promise's line), so every index has one. A text not in that shape is a *SplitError.

func (Folder) Origin

func (f Folder) Origin(file string, line int) int

Origin says which line of the single text the line numbered line (from 1) of the folder's file named file came from: 0 for a generated line, the whole file (line 0), or a line or file the folder lacks.

func (Folder) Write

func (f Folder) Write(root, dir string) error

Write writes every file of the folder into dir, a slash-separated folder under root such as CapabilityDir(slug), making the folder when needed.

type FormatError

type FormatError = LineError

type Kind

type Kind int

Kind says which kind of entry an entry is, and so which file holds it.

const (
	Rule Kind = iota + 1
	Decision
	Question
)

The entry kinds, in the order their files are linked from index.md.

func KindOfFile

func KindOfFile(name string) (Kind, bool)

KindOfFile says which kind a file name holds; false for any other name.

func (Kind) File

func (k Kind) File() string

File is the file of a folder that holds entries of this kind.

func (Kind) String

func (k Kind) String() string

func (Kind) Word

func (k Kind) Word() string

Word is the kind's word in titles, sections and index links: "Rules", "Decisions" or "Questions".

type LineError

type LineError struct {
	Line    int // 1-based line of the text
	Message string
}

LineError is a spot where a text is not in its file's shape: a SplitError for a single text, a FormatError for a folder file.

func (*LineError) Error

func (e *LineError) Error() string

type Problem

type Problem struct {
	Path    string // slash-separated, relative to the root
	Line    int
	Message string
}

Problem is a file FormatMap left unchanged, with the line that stopped it.

func FormatMap

func FormatMap(root string, write bool) (changed []string, problems []Problem, err error)

FormatMap formats every file in the map's folders under root: the product and each capability, with index links to the kind files each folder has. It returns the slash-separated paths whose text would change, and writes them only when write is true; it never creates or deletes a file. A file outside its format is left as it is and reported as a Problem, and the others are still formatted. A map still in the single-file layout is an ErrOldLayout, found before anything is formatted.

func (Problem) String

func (p Problem) String() string

type Snapshot

type Snapshot map[string][]byte

Snapshot is the files directly in a folder, by name, as they were when Take read them.

func Take

func Take(dir string) (Snapshot, error)

Take reads every regular file directly in the folder dir.

func (Snapshot) Restore

func (s Snapshot) Restore(dir string) error

Restore puts the folder dir back as s found it: every file s holds is written byte for byte, and every other regular file is removed.

type SplitError

type SplitError = LineError

SplitError and FormatError name LineError for Split and Format.

type Unsafe

type Unsafe struct {
	Kind            Kind
	Heading, Reason string
}

Unsafe is an entry SafeFiles took out of a folder, with why.

func SafeFiles

func SafeFiles(files map[string]string) (map[string]string, []Unsafe)

SafeFiles is a folder's files by name, as Split gives them, with each entry taken out whose heading the map check would reject: an empty one, one HeadingProblem names, and one with the anchor of the title, a section or an earlier heading of its file. A kind file left with no entries goes, and index.md's links follow. Every other byte is kept.

Jump to

Keyboard shortcuts

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