How prinova/pi-agent-codebase-workflows works
1. What this repository is
- This is not an application runtime; it is a Pi package of agent workflows.
- Its job is to supply skills, prompt templates, and shared schemas that Pi can install and use for codebase understanding, safe changes, architecture review, validation, and doc migration.
2. Primary packaging boundary
- The package is discovered through package.json entries for pi.skills and pi.prompts.
- At runtime, Pi loads the content in skills/ and prompts/; there is no server, CLI daemon, or compiled code path in this repo.
3. Skill subsystem
- Each skill lives in skills/<skill-name>/SKILL.md.
- The included skills form the main execution workflows:
- safe-start
- codebase-recon
- safe-change
- arch-code-review
- structured-doc-validate
- structured-docs-migration
- These are the agent-facing “entrypoints” for structured repo work.
4. Prompt-template subsystem
- The prompts/ directory contains task-specific markdown templates used by those skills.
- They are grouped by workflow family:
- reconstruction (recon-*)
- greenfield start (safe-start-*)
- change/bug/feature/refactor/risk workflows
- architecture review and validation
- The prompts are orchestration artifacts, not executable logic.
5. Shared schema and reference layer
- skills/_shared/references/ is the package’s canonical contract layer.
- It contains:
- artifact-api.md
- JSON schemas for all structured artifact types
- These schemas define the shape of the YAML docs the workflows produce and validate.
6. Structured-docs architecture
- The repo is built around a structured YAML artifact model, not prose docs.
- The logical docs layout is:
- <docs-root>/repo/*.yaml
- <docs-root>/scopes/by-path/.../*.yaml
- <docs-root>/scopes/by-domain/.../*.yaml
- Core artifacts include inventory, architecture, data flow, invariants, dependency rules, risks, contracts, testing strategy, ADRs, and change guides.
7. Workspace resolution and storage boundary
- Workflows target either a repo-local structured docs root or a global overlay root under ~/.pi/agent/workspaces/<workspace-fingerprint>/docs/agent/api.
- safe-start is special: it creates the initial repo-local root at <workspace_root>/docs/agent/api.
- Other skills use the repo-local root only if it already exists; otherwise they fall back to the global overlay.
- This is a key architectural boundary between the source repository being analyzed and the agent artifact store.
8. Data flow through the workflows
- Typical flow is: user invokes a skill/prompt → the agent resolves workspace root and docs root → reads existing structured artifacts and source evidence → writes or updates YAML artifacts → validates references and schema shape.
- The workflows are designed to preserve stable IDs, update by source-of-truth fields, and mark unsupported records stale rather than deleting them.
9. Scope routing model
- scopes.yaml is the routing layer for artifact ownership.
- Path scopes map to <docs-root>/scopes/by-path/<repo-relative-path>/.
- Domain scopes map to <docs-root>/scopes/by-domain/<slug>/.
- This makes the system capable of organizing architecture and change context by code path or by business/domain boundary.
10. Governance and safety controls
- The repo emphasizes validation-first and evidence-backed updates.
- structured-doc-validate is the explicit audit workflow for schema validity, reference integrity, evidence quality, and granularity.
- The structured artifact protocol also requires deterministic YAML formatting, read-before-write behavior, and explicit reporting of validation results.
11. Operational compatibility layer
- Root AGENTS.md is intentionally kept as a compact harness-facing file.
- It is generated from agent-operating-guide.yaml so systems that do not consume Pi skills/prompts directly still have a minimal operational contract.
12. Important exclusions
- The repo intentionally does not generate legacy docs/agent/*.md project-agent prose docs as its primary output.
- The structured YAML artifacts are the canonical interface for downstream automation and agent ingestion.
13. What to draw in an architecture diagram
- Draw the repo as a content package with three internal layers:
- workflow definitions in skills/
- task prompts in prompts/
- shared artifact schemas/contracts in skills/_shared/references/
- Then show outputs going to a workspace-scoped structured docs root and, secondarily, to a root AGENTS.md compatibility file.
- The main external dependency is the Pi runtime/installer, which interprets these assets and applies them to target workspaces.
14. Overall architectural summary
- This repository is a documentation-and-governance framework for agentic repo work.
- Its architecture centers on standardized artifacts, schema enforcement, scope routing, and workspace-aware storage, rather than code execution or service composition.
Main entry points: safe-start/SKILL.md safe-start · safe-change/SKILL.md safe-change · schemas schemas · package.json package.json
Components 19
Package
Manifest and installable asset boundary
- package.json · Declares the package entrypoints for Pi skills and prompts
package.json
Workflows
Agent-facing skills that orchestrate repo tasks
- safe-start · Bootstraps a new structured-docs workspace and initial docs root
skills/safe-start/SKILL.md - codebase-recon · Reconstructs inventory, architecture, data flow, and governance artifacts
skills/codebase-recon/SKILL.md - safe-change · Coordinates scoped code or docs changes with validation-aware workflow selection
skills/safe-change/SKILL.md - arch-code-review · Runs architecture-focused review workflows and feedback synthesis
skills/arch-code-review/SKILL.md - structured-doc-validate · Audits schema validity, evidence quality, and reference integrity
skills/structured-doc-validate/SKILL.md - structured-docs-migration · Migrates and consolidates legacy structured docs into the canonical model
skills/structured-docs-migration/SKILL.md
Prompts
Task templates consumed by workflows
- safe-start-all · Staged greenfield workflow template set for initial workspace setup
prompts/safe-start-all.md - recon-all · Orchestrates the repository reconstruction prompt sequence
prompts/recon-all.md - change prompts · Bug, feature, refactor, risk, and preflight templates
prompts/bug-implement.md - review-arch · Architecture review task template
prompts/review-arch.md - validate docs · Structured-doc validation task template
prompts/validate-structured-docs.md
Contracts
Shared artifact API and schema layer
- artifact API · Canonical contract for structured artifact handling and deterministic YAML updates
skills/_shared/references/artifact-api.md - schemas · Schemas for inventory, architecture, scopes, risks, ADRs, and related artifacts
skills/_shared/references/schemas - scopes routing · Defines path and domain ownership for artifact routing
skills/_shared/references/schemas/scopes.schema.json
Storage
Workspace-scoped structured docs outputs
- docs root · Repo-local structured YAML artifact root used by workflows
- overlay root · Fallback global workspace artifact store under ~/.pi/agent/workspaces/.../docs/agent/api
- AGENTS.md · Compact harness-facing compatibility file generated from operating guidance
Other components
- Pi runtime · Loads skills and prompts, resolves workspace roots, and applies workflows
Connections 26
- package.json → safe-start: registers skills · package.json advertises the skill entrypoints consumed by Pi
- package.json → recon-all: registers prompts · package.json advertises prompt templates consumed by Pi
- package.json → Pi runtime: package metadata · Pi uses the package manifest to discover installable assets
- Pi runtime → safe-start: loads · Runtime loads skill definitions from skills/
- Pi runtime → safe-change: loads · Runtime loads skill definitions from skills/
- Pi runtime → validate docs: loads · Runtime loads prompt templates from prompts/
- safe-start → safe-start-all: uses prompts · Skill orchestrates the staged safe-start prompt flow
- codebase-recon → recon-all: uses prompts · Skill orchestrates repository reconstruction prompts
- safe-change → change prompts: uses prompts · Skill selects the appropriate change workflow templates
- arch-code-review → review-arch: uses prompt · Architecture review skill is driven by the review template
- structured-doc-validate → validate docs: uses prompt · Validation skill is driven by the validation template
- structured-docs-migration → artifact API: depends on · Migration relies on the canonical artifact contract
- codebase-recon → schemas: reads/writes · Reconstruction updates structured YAML artifacts through schemas
- safe-change → schemas: reads/writes · Change workflows preserve and update structured artifact records
- structured-doc-validate → schemas: validates · Validation checks schema shape and reference integrity
- schemas → scopes routing: includes · The schema set includes scope-routing definitions
- safe-start → docs root: creates · Safe-start bootstraps the repo-local structured docs root
- codebase-recon → docs root: prefers · Uses repo-local docs root when available
- safe-change → docs root: reads/writes · Updates repo-local structured artifacts when present
- structured-doc-validate → docs root: audits · Validation inspects the current structured docs root
- docs root → overlay root: falls back to · Workflows use the global overlay when repo-local docs are absent
- safe-start → AGENTS.md: generates · Operational guidance is rendered into a compact harness-facing AGENTS.md
- artifact API → docs root: governs · Defines how structured artifacts are authored and updated
- scopes routing → docs root: routes · Scope mapping assigns artifacts to path or domain subtrees
- Pi runtime → docs root: resolves root · Runtime determines the workspace-aware storage location
- Pi runtime → overlay root: resolves fallback · Runtime can target the global overlay workspace store