Documentation
¶
Overview ¶
Package atomize ports orchestrator/atomize.py: parsing markdown specs (docs/SPEC-FORMAT.md) into tasks, and merging them non-destructively into an existing tasks.json. See parse.go (parser), merge.go (merge rules), diff.go (human-readable diff), write.go (Apply/backup) and atomize.go (the top-level Atomize entry point).
Index ¶
- func AllocateImportPackages(srcs []ImportSource, owned map[string]int, used map[int]bool) map[string]int
- func Apply(path string, tf model.TasksFile, backup bool) (string, error)
- func AtomizeDir(docsRoot, expectedProjectID string, existing model.TasksFile) (model.TasksFile, MergeDiff, ParseResult, error)
- func ImportDeps(doc ImportDoc) map[string][]string
- func ImportSpec(in ImportSpecInput) string
- func ImportSpecFileName(src ImportSource) string
- func ImportedPackage(text string, format ImportFormat) (int, bool)
- func IsImportSpec(text string, format ImportFormat) bool
- func IsIssueSpecFile(base string, number int) bool
- func IssueSpec(issue SourceIssue, projectID, model string) string
- func IssueSpecFileName(number int, title string) string
- func IssueTaskID(number int) string
- func LoadExisting(path string) (model.TasksFile, error)
- func PreferredPackage(src ImportSource) int
- func ReadFirstFiles(format ImportFormat) []string
- func RenderDiff(diff MergeDiff, parse ParseResult) string
- func WalkSpecFiles(root string) ([]string, error)
- type Frontmatter
- type ImportDoc
- type ImportFormat
- type ImportSource
- type ImportSpecInput
- type ImportTask
- type MergeDiff
- type ParseResult
- func ParseFile(path, docsRoot, expectedProjectID string) (ParseResult, error)
- func ParseFiles(paths []string, docsRoot, expectedProjectID string) (ParseResult, error)
- func ParseFilesWith(paths []string, overrides map[string]string, ...) (ParseResult, error)
- func ParseText(text, sourcePath, docsRoot, expectedProjectID string) ParseResult
- type ParsedTask
- type SourceIssue
- type UpdatedTask
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllocateImportPackages ¶ added in v0.31.0
func AllocateImportPackages(srcs []ImportSource, owned map[string]int, used map[int]bool) map[string]int
AllocateImportPackages gives every source a package number, the middle part of its tasks' ids (F<phase>.<package>.T<n>), so that two features' T001 never meet: the one an earlier import gave it (owned, by name), else the one it asks for (PreferredPackage) when no other task uses it, else one past the highest in use. used holds the packages other specs and tasks.json already use.
func Apply ¶
Apply writes tf to path through model.SaveTasksFile (atomic), backing up any existing file first (tasks.json.bak-<timestamp>, skipped when backup is false or path doesn't exist yet). Returns the backup path written, or "" when none was made. Ports write_tasks_json.
It does not lock: a read-modify-write of tasks.json goes through project.MutateTasks, which holds the task editor's lock around it (#531).
func AtomizeDir ¶
func AtomizeDir(docsRoot, expectedProjectID string, existing model.TasksFile) (model.TasksFile, MergeDiff, ParseResult, error)
AtomizeDir walks docsRoot for *.md spec files (matching --specs-dir mode of the Python CLI), parses and aggregates them, and merges the result into existing. expectedProjectID, when non-empty, is cross-checked against each file's frontmatter project_id.
func ImportDeps ¶ added in v0.31.0
ImportDeps works out what each open task waits on, by key, the way spec-kit's /implement runs a tasks.md: phase by phase, and within a phase in order, except that a run of [P] tasks under one heading goes together. An explicit `depends on` replaces the order for its task. A task with nothing to wait on inside its phase waits on the previous phase's last tasks (those nothing in that phase waits on). Done tasks are not imported and nothing waits on them. OpenSpec has no [P]: a change's tasks run in the order written.
func ImportSpec ¶ added in v0.31.0
func ImportSpec(in ImportSpecInput) string
ImportSpec is the orch spec `orch atomize --from` writes for one spec-kit feature or OpenSpec change: one task per open checkbox, id F<phase>.<package>.T<n>, with ImportDeps' dependencies, the files the line names, and a description that says where the task comes from — file, line and key — and quotes it. The quote (every line behind "> ") keeps the source's markdown away from the spec parser, as IssueSpec does with an issue body. Deterministic: the same tasks.md gives the same bytes, so a re-run sees nothing to change.
func ImportSpecFileName ¶ added in v0.31.0
func ImportSpecFileName(src ImportSource) string
ImportSpecFileName is the orch spec an import writes for src, in the spec root: speckit-<feature>.md or openspec-<change>.md.
func ImportedPackage ¶ added in v0.31.0
func ImportedPackage(text string, format ImportFormat) (int, bool)
ImportedPackage reads back the package an earlier import of format gave the spec in text; false when text is not such an import.
func IsImportSpec ¶ added in v0.31.0
func IsImportSpec(text string, format ImportFormat) bool
IsImportSpec reports whether text is a spec an import of format wrote, the only kind of file a re-run overwrites.
func IsIssueSpecFile ¶ added in v0.31.0
IsIssueSpecFile reports whether base (a file name, no directory) is the spec `--from-issues` writes for issue number, whatever its slug says now.
func IssueSpec ¶ added in v0.31.0
func IssueSpec(issue SourceIssue, projectID, model string) string
IssueSpec is the spec `orch atomize --from-issues` writes for one issue: one task, `IssueTaskID`, whose description is the issue's URL followed by its body.
The body is quoted (every line behind "> ") on purpose. It is free markdown somebody typed on GitHub, and the spec parser acts on lines: a `- **Type**: feature` bullet would be read as an unknown field and end the description there, a `# F1 — ...` heading would start a phase, and a fence would hide the rest of the file. No parser rule matches a line that starts with ">", so the body reaches the task whole and the agent reads it as the quote it is.
The issue's URL goes in the frontmatter too (`source_issue`), so every task the file defines carries it — including the ones an operator adds when splitting the issue into several tasks.
func IssueSpecFileName ¶ added in v0.31.0
IssueSpecFileName is `issue-<n>-<slug>.md`, the slug the title in lowercase ASCII words joined by dashes and cut at a word boundary; `issue-<n>.md` when the title has no ASCII letter or digit to slug.
func IssueTaskID ¶ added in v0.31.0
IssueTaskID is the id of the one task IssueSpec writes for issue number: phase 0, the issue number as the package, task 1. The package number is what keeps two issues' tasks apart, in the atomizer's own id format so the spec can be split by hand into F0.<n>.T2, T3, ... and atomized as usual.
func LoadExisting ¶
LoadExisting reads path as a TasksFile, matching load_raw_tasks_json's retrocompat: a missing file loads as an empty TasksFile{} (meta/phases/ tasks all zero-valued, which MarshalJSON already renders as {}/[]/[]) — this is Atomize's "project has no tasks.json yet" starting point.
func PreferredPackage ¶ added in v0.31.0
func PreferredPackage(src ImportSource) int
PreferredPackage is the package number src asks for: a spec-kit feature's own number (001-photo-albums is 1). 0 when it has none — an OpenSpec change, or a timestamp-named feature too long to be a package.
func ReadFirstFiles ¶ added in v0.31.0
func ReadFirstFiles(format ImportFormat) []string
ReadFirstFiles are the documents beside a tasks.md an agent reads before its task, in the order it should: spec-kit's spec and plan and their companions, OpenSpec's proposal, design and spec deltas.
func RenderDiff ¶
func RenderDiff(diff MergeDiff, parse ParseResult) string
RenderDiff renders diff as human-readable, deterministic plain text — the CLI's "--apply not passed" preview and the body of a dry-run report. It follows the same section layout as Python's render_diff (rich-colored console output) but is plain text: parity here is about which sections exist and what they say, not byte-identical formatting — Python's own tests for this function only assert on substrings too.
func WalkSpecFiles ¶
WalkSpecFiles lists the *.md files under root in the same deterministic (lexicographic) order Python's `sorted(root.rglob("*.md"))` produces. A missing root is not an error — it returns no files, matching _iter_spec_files's `if not root.exists(): return []`.
Types ¶
type Frontmatter ¶
type Frontmatter struct {
Present bool
Type string
ProjectID string
Phase *int // nil when absent or not a valid int
Package string
Version string
DependsOn []string
ConsumedBy []string
GeneratedBy string
GeneratedAt string
Title string
// SourceIssue is the URL of the GitHub issue the spec was imported from
// (`orch atomize --from-issues`, #525); every task in the file carries it.
SourceIssue string
Warnings []string
}
Frontmatter is the metadata parsed from a spec's optional YAML frontmatter. Every field is optional — a spec with no frontmatter block parses to Frontmatter{Present: false} and every other field zero.
type ImportDoc ¶ added in v0.31.0
type ImportDoc struct {
Title string
Tasks []ImportTask
Warnings []string
}
ImportDoc is a parsed tasks.md.
func ParseImportTasks ¶ added in v0.31.0
func ParseImportTasks(format ImportFormat, text string) ImportDoc
ParseImportTasks parses a tasks.md in format.
func ParseOpenSpecTasks ¶ added in v0.31.0
ParseOpenSpecTasks reads an OpenSpec change's tasks.md: `## 1. Group` headings and `- [ ] 1.1 Description` lines, `[x]` for done.
func ParseSpecKitTasks ¶ added in v0.31.0
ParseSpecKitTasks reads a spec-kit tasks.md (templates/tasks-template.md): `## Phase N: Title` headings and `- [ ] T001 [P] [US1] Description` lines, `[x]`/`[X]` for done. Phases numbered 3.1, 3.2 (older spec-kit) are renumbered 1, 2, ... in order.
type ImportFormat ¶ added in v0.31.0
type ImportFormat string
ImportFormat names a spec-driven tool whose task lists `orch atomize --from` reads (#526).
const ( // FormatSpecKit is github/spec-kit: specs/<NNN-feature>/tasks.md, with // `- [ ] T001 [P] [US1] ...` lines under `## Phase N: ...` headings. FormatSpecKit ImportFormat = "spec-kit" // FormatOpenSpec is Fission-AI/OpenSpec: openspec/changes/<change>/tasks.md, // with `- [ ] 1.1 ...` lines under `## 1. ...` headings. FormatOpenSpec ImportFormat = "openspec" )
func ParseImportFormat ¶ added in v0.31.0
func ParseImportFormat(s string) (ImportFormat, error)
ParseImportFormat reads --from's value: spec-kit (or speckit) and openspec, in any case.
type ImportSource ¶ added in v0.31.0
type ImportSource struct {
Format ImportFormat
Name string // the directory's name: 001-photo-albums, add-dark-mode
Dir string
TasksPath string
}
ImportSource is one spec-kit feature or one OpenSpec change: a directory with a tasks.md.
func FindImportSources ¶ added in v0.31.0
func FindImportSources(format ImportFormat, dir string) ([]ImportSource, []string, error)
FindImportSources lists the features (spec-kit) or changes (OpenSpec) under dir that have a tasks.md, sorted by name, and the directories that have none yet. dir may be one feature or change, the directory holding them (spec-kit's specs/, OpenSpec's openspec/changes/), or the repository root. OpenSpec's archive/ holds finished changes and is not read.
type ImportSpecInput ¶ added in v0.31.0
type ImportSpecInput struct {
Source ImportSource
Doc ImportDoc
Package int
ProjectID string
Model string
// SourceDir is the feature or change directory as the agent will find it
// (relative to the project root, slash-separated).
SourceDir string
// ReadFirst are the documents beside tasks.md that exist, same form.
ReadFirst []string
}
ImportSpecInput is what ImportSpec writes a spec from.
type ImportTask ¶ added in v0.31.0
type ImportTask struct {
// Key is the id the source gives the task: T001, T006a, 1.2.
Key string
// Phase is spec-kit's phase number, or OpenSpec's group number.
Phase int
PhaseTitle string
// Num is the task number in its orch id: spec-kit's T012 is 12, and a
// lettered T006a is 1006 (b is 2006, ...); OpenSpec's 2.3 is 3.
Num int
Parallel bool // spec-kit's [P]
Story string // spec-kit's [US1]
Title string
// Text is the task as written: its line and any indented lines under it.
Text []string
Line int // 1-based line of the checkbox in tasks.md
Done bool
// After lists the keys of an explicit `(depends on T012, T013)`.
After []string
Files []string
// Section counts headings: tasks under different ### subsections never
// share a run of [P] tasks.
Section int
}
ImportTask is one checkbox line of a tasks.md.
type MergeDiff ¶
type MergeDiff struct {
NewTasks []model.Task
Updated []UpdatedTask
Unchanged []model.Task
Orphans []model.Task
DepWarnings []string
}
MergeDiff buckets the result of MergeTasks for diff rendering and for tests. Ports MergeDiff.
func Atomize ¶
func Atomize(sourcePath, docsRoot, specMD string, existing model.TasksFile) (model.TasksFile, MergeDiff, error)
Atomize parses one spec file's markdown (already read into specMD, from sourcePath under docsRoot — needed to compute SpecRef the same way ParseFile does) and merges the result into existing, returning the merged TasksFile and the diff. It never writes anything; call Apply on the result to persist it.
This fuses ParseText + MergeTasks for the single-spec-file case. Real projects have many spec files under docs/ (that's the whole point of the atomizer), so internal/cli's `orch atomize` wires WalkSpecFiles + ParseFiles + MergeTasks directly rather than calling this per file — Atomize exists for the common single-file/programmatic case (e.g. a skill that just produced one spec and wants an immediate merge).
func MergeTasks ¶
MergeTasks applies the atomizer's non-destructive merge and returns the merged TasksFile plus a bucketed diff. Ports merge_tasks:
- a task ID not already in existing is appended (NewTasks);
- a task ID already present has its declarative fields updated and its runtime fields (status/comments/files) preserved (Updated, or Unchanged when nothing declarative changed);
- an existing row whose ID is not in parsed is never removed, only reported (Orphans) — this is what makes the merge non-destructive, and it applies equally to legacy pre-atomizer IDs (R-001, ...), which the parser never generates and therefore never matches;
- meta and phases are carried over from existing untouched;
- every dependency in the final task set is checked against the final ID set, independent of whether the task carrying it was touched by this merge (DepWarnings).
type ParseResult ¶
type ParseResult struct {
Tasks []ParsedTask
FilesScanned []string
Warnings []string
}
ParseResult bundles what parsing one or more spec files produced — useful for the CLI's diff/list rendering and for tests.
func ParseFile ¶
func ParseFile(path, docsRoot, expectedProjectID string) (ParseResult, error)
ParseFile reads path and parses it with ParseText.
func ParseFiles ¶
func ParseFiles(paths []string, docsRoot, expectedProjectID string) (ParseResult, error)
ParseFiles parses every file in paths (in the given order — callers pass WalkSpecFiles's output for the deterministic on-disk walk) and aggregates the results. A task ID defined in more than one file keeps the LAST file's definition and records a warning; ordering paths lexicographically makes "last" mean "alphabetically last", matching parse_specs.
func ParseFilesWith ¶ added in v0.31.0
func ParseFilesWith(paths []string, overrides map[string]string, docsRoot, expectedProjectID string) (ParseResult, error)
ParseFilesWith is ParseFiles where a path in overrides is parsed from that text instead of from disk (the file need not exist): the preview of an import, whose specs are not written yet, diffs exactly what --apply would.
func ParseText ¶
func ParseText(text, sourcePath, docsRoot, expectedProjectID string) ParseResult
ParseText parses spec markdown already read into memory. sourcePath is used exactly as Python uses `path`: its basename prefixes warnings, its full form (as given) is stored on each ParsedTask.SourceFile, and its relation to docsRoot produces SpecRef. expectedProjectID, when non-empty, is cross-checked against the frontmatter's project_id (a mismatch is a warning, not an error). Ports parse_spec_file.
type ParsedTask ¶
type ParsedTask struct {
ID string
Phase int
Package int
TaskNum int
Title string
Description string
Model string
Reason string
EstimateHours float64
Dependencies []string
Files []string
SpecRef string
// SourceIssue comes from the spec's `source_issue` frontmatter (#525).
SourceIssue string
SourceFile string
Line int
}
ParsedTask is one task extracted from a spec markdown file, before merge. Field names mirror ParsedTask in orchestrator/atomize.py (snake_case Python attributes become Go's exported CamelCase, matched 1:1).
type SourceIssue ¶ added in v0.31.0
SourceIssue is the slice of a GitHub issue a spec is written from. Its own type, not vcs.Issue: atomize turns markdown into tasks and has no business knowing how gh spells an issue.