seihou-okf-extension 0.16.0.2 → 0.17.0.0
raw patch · 8 files changed
+251/−43 lines, 8 filesdep ~seihou-corePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: seihou-core
API changes (from Hackage documentation)
+ Seihou.OKF.Docs.Render: AmbiguousMigrationAnchor :: DocKind -> Text -> Text -> DocRenderError
Files
- profile/seihou-registry-docs.dhall +46/−11
- seihou-okf-extension.cabal +3/−3
- src/Seihou/OKF/Docs/Render.hs +134/−23
- src/Seihou/OKF/Extension/Docs.hs +2/−0
- test/Main.hs +9/−0
- test/Seihou/OKF/Docs/ModelSpec.hs +8/−4
- test/Seihou/OKF/Docs/RenderSpec.hs +29/−0
- test/Seihou/OKF/Extension/DocsSpec.hs +20/−2
profile/seihou-registry-docs.dhall view
@@ -168,13 +168,42 @@ let scalar = \(name : Text) -> \(description : Text) ->- field name description Cardinality.Scalar (None FieldFormat) (None NestedRules)+ field+ name+ description+ Cardinality.Scalar+ (None FieldFormat)+ (None NestedRules) let versionRule = scalar "version" "The version the registry catalog records for this artifact. Optional rather than required, because `seihou-registry.dhall` itself declares `version : Optional Text`; a profile that demanded it would refuse a valid registry." +let migrationEdgesRule =+ field+ "seihouMigrationEdges"+ "The observed owner edges. An empty list records no edges; older pages may omit the field."+ Cardinality.List+ (None FieldFormat)+ (None NestedRules)+ // { elementFields = Some+ ( emptyNestedRules+ // { required =+ [ nestedScalar "from" "The starting version."+ , nestedScalar "to" "The destination version."+ , nestedScalar+ "anchor"+ "The fragment of the migration section in the owner page."+ ]+ }+ )+ , uniqueBy = Some "anchor"+ }++let migrationOwnerRules =+ emptyRules // { optional = [ versionRule, migrationEdgesRule ] }+ let artifactType = \(name : Text) -> \(description : Text) ->@@ -198,9 +227,13 @@ , frontmatter = emptyRules // { required =- [ scalar "type" "Which kind of Seihou artifact this concept documents."- , scalar "title" "The artifact's name, exactly as the registry publishes it."+ [ scalar+ "type"+ "Which kind of Seihou artifact this concept documents." , scalar+ "title"+ "The artifact's name, exactly as the registry publishes it."+ , scalar "description" "What the artifact is for. Taken from the registry catalog entry, else the artifact's own description, else synthesized." , field@@ -253,18 +286,20 @@ , idField = None Text , requireBundleVersion = Some "0.2" , types =- [ artifactType- "SeihouModule"- "A deterministic file-generation template: variables, generation steps, shell commands, dependencies, managed/seed/checkout ownership, an optional removal procedure, judgement references and optional migration edges."- "modules"+ [ artifactType+ "SeihouModule"+ "A deterministic file-generation template: variables, generation steps, shell commands, dependencies, managed/seed/checkout ownership, an optional removal procedure, judgement references and optional migration edges."+ "modules"+ // { frontmatter = migrationOwnerRules } , artifactType "SeihouRecipe" "A declared composition of modules with sourced dependencies, preset variable bindings, an optional single base and explicit overrides." "recipes"- , artifactType- "SeihouBlueprint"- "An agent-driven scaffold: a prompt, optional base modules, reference files and optional agent-guided migration edges."- "blueprints"+ , artifactType+ "SeihouBlueprint"+ "An agent-driven scaffold: a prompt, optional base modules, reference files and optional agent-guided migration edges."+ "blueprints"+ // { frontmatter = migrationOwnerRules } , artifactType "SeihouPrompt" "A reusable agent-session template."
seihou-okf-extension.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: seihou-okf-extension-version: 0.16.0.2+version: 0.17.0.0 synopsis: OKF documentation extension for Seihou registries description: External Seihou extension executable for generating OKF documentation bundles@@ -60,7 +60,7 @@ lens >=5.2 && <6, okf-core ^>=0.13.0.0, optparse-applicative >=0.18 && <1,- seihou-core ^>=0.16.0.2,+ seihou-core ^>=0.17.0.0, temporary >=1.3 && <2, text >=2.0 && <3, @@ -120,7 +120,7 @@ hspec >=2.11 && <3, lens >=5.2 && <6, okf-core ^>=0.13.0.0,- seihou-core ^>=0.16.0.2,+ seihou-core ^>=0.17.0.0, seihou-okf-extension-internal, tasty >=1.4 && <2, tasty-hspec >=1.2 && <2,
src/Seihou/OKF/Docs/Render.hs view
@@ -15,9 +15,10 @@ where import Control.Lens ((^.))-import Data.Aeson (Value (..))+import Data.Aeson (Value (..), object, toJSON, (.=)) import Data.Aeson.Text qualified as Aeson import Data.Bifunctor (first)+import Data.Char (ord) import Data.Either (partitionEithers) import Data.FileEmbed (embedStringFile) import Data.Foldable (toList)@@ -25,10 +26,12 @@ import Data.List.NonEmpty (NonEmpty) import Data.Map.Strict (Map) import Data.Map.Strict qualified as Map+import Data.Set qualified as Set import Data.Text qualified as T import Data.Text.IO qualified as TIO import Data.Text.Lazy qualified as TL import GHC.Generics (Generic)+import Numeric (showHex) import Okf.Actor (Actor (..)) import Okf.Bundle (BundleError, Concept, bundleInventoryOfConcepts, conceptFromDocument, writeBundle) import Okf.ConceptId (ConceptId, parseConceptId, renderConceptLink)@@ -119,6 +122,7 @@ data DocRenderError = InvalidDocConceptId DocKind T.Text T.Text+ | AmbiguousMigrationAnchor DocKind T.Text T.Text deriving stock (Eq, Show) data DocBundleError@@ -238,18 +242,50 @@ case conceptIdFor (entry ^. #kind) (entry ^. #name) of Left err -> Left (InvalidDocConceptId (entry ^. #kind) (entry ^. #name) err)- Right conceptId ->- Right (conceptFromDocument conceptId (documentFor opts repoName entry))+ Right conceptId+ | anchor : _ <- ambiguous ->+ Left (AmbiguousMigrationAnchor (entry ^. #kind) (entry ^. #name) anchor)+ | otherwise ->+ Right (conceptFromDocument conceptId (Okf.OKFDocument (frontmatterFor opts repoName entry) body))+ where+ body = bodyFor repoName entry+ anchors = Set.fromList (map (uncurry migrationAnchor) (foldMap id (migrationPairs entry)))+ counts = Map.fromListWith (+) [(line, 1 :: Int) | line <- T.lines body]+ ambiguous =+ [anchor | anchor <- Set.toList anchors, Map.lookup (anchorTag anchor) counts /= Just 1] -documentFor :: RenderOptions -> T.Text -> DocEntry -> Okf.OKFDocument-documentFor opts repoName entry =- Okf.OKFDocument- (frontmatterFor opts repoName entry)- (bodyFor repoName entry)+migrationPairs :: DocEntry -> Maybe [(T.Text, T.Text)]+migrationPairs entry =+ case entry ^. #artifact of+ DocModuleArtifact Module {migrations} -> Just [(from, to) | Migration {from, to} <- migrations]+ DocBlueprintArtifact Blueprint {migrations} -> Just [(from, to) | BlueprintMigration {from, to} <- migrations]+ _ -> Nothing +migrationAnchor :: T.Text -> T.Text -> T.Text+migrationAnchor from to = "migration-" <> encode from <> "-" <> encode to+ where+ -- The separator never appears inside an encoded version. Escape underscores+ -- as well so literal text cannot be confused with an escaped code point.+ encode = T.concatMap encodeChar+ encodeChar c+ | ('a' <= c && c <= 'z') || ('0' <= c && c <= '9') = T.singleton c+ | otherwise = "_" <> T.pack (showHex (ord c) "") <> "_"++anchorTag :: T.Text -> T.Text+anchorTag anchor = "<a id=\"" <> anchor <> "\"></a>"++migrationHeading :: T.Text -> T.Text -> T.Text+migrationHeading from to =+ anchorTag (migrationAnchor from to) <> "\n\n### " <> versionLabel from <> " → " <> versionLabel to+ where+ versionLabel version+ | not (T.null version) && T.all (\c -> c `elem` ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+_" :: String)) version =+ T.replace "_" "\\_" version+ | otherwise = inlineCode version+ frontmatterFor :: RenderOptions -> T.Text -> DocEntry -> Okf.Frontmatter frontmatterFor opts repoName entry =- maybeSetVersion+ maybeSetEdges . maybeSetVersion $ ( baseFrontmatter opts (typeFor (entry ^. #kind))@@ -259,6 +295,10 @@ (entry ^. #tags) ) where+ maybeSetEdges =+ maybe id (Okf.setField "seihouMigrationEdges" . toJSON . fmap edgeField) (migrationPairs entry)+ edgeField (from, to) =+ object ["from" .= from, "to" .= to, "anchor" .= migrationAnchor from to] maybeSetVersion = maybe id (\version -> Okf.setField "version" (String version)) (entry ^. #version) @@ -394,6 +434,7 @@ T.intercalate "\n\n" ( baseSections repoName entry+ <> usageSections entry <> optionalSection "Declaration metadata" (renderDeclaredMetadata entry) <> optionalSection "Judgements" (renderJudgementRefs (entry ^. #judgementRefs)) <> kindSections entry@@ -407,6 +448,60 @@ ] <> foldMap (\version -> ["**Version:** " <> version]) (entry ^. #version) +-- The lead paragraph already gives the registry author's purpose. Add the+-- point in the project workflow where each kind is used and its normal commands.+usageSections :: DocEntry -> [T.Text]+usageSections entry =+ [ section "When to use" purpose,+ section "How to use" (T.intercalate "\n\n" [prerequisites, install, fencedBlock "bash" (T.unlines commands), result])+ ]+ where+ name = shellArgument (entry ^. #name)+ install =+ "If the artifact is not installed, set `REGISTRY_GIT_URL` to the Git URL of its publishing registry and run:\n\n"+ <> fencedBlock "bash" ("seihou install \"$REGISTRY_GIT_URL\" --module " <> name)+ (purpose, prerequisites, commands, result) =+ case entry ^. #artifact of+ DocModuleArtifact _ ->+ ( "Use this module to generate or manage the files listed under Generation steps.",+ "Run from the project directory. Supply the required Variables through Seihou configuration, its prompts or `--var KEY=VALUE`.",+ ["seihou run " <> name <> " --dry-run", "seihou run " <> name],+ "Review the planned files and commands in the preview. Applying the plan writes the files, runs the declared commands and records the application in the project manifest."+ )+ DocRecipeArtifact _ ->+ ( "Use this recipe to apply its module composition together.",+ "Run from the project directory. Seihou resolves the base recipe and inherited bindings where declared. Supply remaining required inputs through project configuration, prompts or `--var KEY=VALUE`.",+ ["seihou run " <> name <> " --dry-run", "seihou run " <> name],+ "Review the composed plan before applying it. The recipe's bindings configure its modules, and the CLI overrides let you choose different values for this run."+ )+ DocBlueprintArtifact _ ->+ ( "Use this blueprint when you want an agent to carry out the task under Agent prompt.",+ "Run from the target project directory with an authenticated Seihou agent provider. Supply the declared variables and prompt answers. Review Base modules, Reference files and Tools before starting.",+ ["seihou agent run " <> name],+ "Seihou applies the declared base modules, prepares the reference files and starts an agent session with the rendered task and tool permissions."+ )+ DocPromptArtifact _ ->+ ( "Use this prompt to start a reusable agent session for the task under Agent prompt.",+ "Run in the working directory for that task with an authenticated Seihou agent provider. Supply the declared variables and prompt answers. Review any command-derived inputs and allowed tools.",+ ["seihou prompt run " <> name],+ "Seihou resolves inputs, prepares the reference files and launches the session with the rendered prompt and guidance."+ )+ DocJudgementArtifact _ ->+ ( "Use this judgement to review staged changes against the checks below.",+ "Run in the consuming Git project. Offline evaluation requires the judgement's labelled `examples.json`. Activation requires a configured review provider and model and the project's consent to the review route's data policy.",+ [ "seihou judgement eval " <> name <> " --offline",+ "seihou run " <> name <> " --dry-run",+ "seihou run " <> name,+ "seihou check --staged"+ ],+ "Offline evaluation validates examples and runs the deterministic scan. The activation preview shows the route and policy. Applying records an active judgement in the project manifest and installs the hook. Use `seihou judgement configure` in the consuming project to set its route, thresholds and enforcement."+ )++shellArgument :: T.Text -> T.Text+shellArgument value+ | not (T.null value) && T.all (\c -> c `elem` ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._-" :: String)) value = value+ | otherwise = "'" <> T.replace "'" "'\"'\"'" value <> "'"+ -- | The per-kind body sections. -- -- A section that the artifact declares nothing for is omitted entirely, so a@@ -431,7 +526,7 @@ <> optionalSection "Generation steps" (renderSteps steps) <> optionalSection "Commands" (renderCommands commands) <> foldMap (optionalSection "Removal" . renderRemoval) removal- <> optionalSection "Migrations" (renderMigrations migrations)+ <> optionalSection "Migrations" (renderMigrations (entry ^. #name) migrations) DocRecipeArtifact Recipe {modules = recipeModules, vars, prompts, extends, moduleOverrides, promptOverrides} -> foldMap (\ref -> [section "Extends" (renderRecipeBase entry ref)]) extends <> [section "Composes" (renderDependencies entry (maybe "This recipe does not compose any modules." (const "Uses its inherited members without adding modules.") extends) recipeModules)]@@ -452,7 +547,7 @@ <> foldMap (optionalSection "Version probe" . renderVersionProbe) versionProbe <> optionalSection "Migrations"- (renderBlueprintMigrations (resolvedEntailedBlueprints entry) migrations)+ (renderBlueprintMigrations (entry ^. #name) (resolvedEntailedBlueprints entry) migrations) DocPromptArtifact AgentPrompt {prompt, vars, prompts, commandVars, guidance, files, allowedTools, launch} -> [section "Agent prompt" (renderAgentPrompt prompt)] <> optionalSection "Variables" (renderVarDecls' vars)@@ -729,13 +824,25 @@ renderRemovalAction RemoveSectionAction = "strip this module's section from" renderRemovalAction RewriteFileAction = "rewrite" -renderMigrations :: [Migration] -> T.Text-renderMigrations migrations =- T.intercalate "\n\n" (renderMigration <$> migrations)+renderMigrations :: T.Text -> [Migration] -> T.Text+renderMigrations name migrations =+ T.intercalate "\n\n" (renderMigration name <$> migrations) -renderMigration :: Migration -> T.Text-renderMigration Migration {from, to, ops} =- "### " <> from <> " → " <> to <> "\n\n" <> renderMigrationOps ops+renderMigration :: T.Text -> Migration -> T.Text+renderMigration name Migration {from, to, ops} =+ T.intercalate+ "\n\n"+ [ migrationHeading from to,+ "From a project with "+ <> inlineCode name+ <> " applied at "+ <> inlineCode from+ <> ", preview the migration to "+ <> inlineCode to+ <> ". Remove `--dry-run` to apply the operations below and advance the recorded version.",+ fencedBlock "bash" ("seihou migrate " <> shellArgument name <> " --to " <> shellArgument to <> " --dry-run"),+ renderMigrationOps ops+ ] renderMigrationOps :: [MigrationOp] -> T.Text renderMigrationOps [] = "This edge declares no operations; it advances the recorded version only."@@ -752,15 +859,19 @@ -- | Blueprint migration edges, each with the guidance the agent is given and -- the other blueprints' edges that crossing this one entails.-renderBlueprintMigrations :: [T.Text] -> [BlueprintMigration] -> T.Text-renderBlueprintMigrations resolvedBlueprints migrations =- T.intercalate "\n\n" (renderBlueprintMigration resolvedBlueprints <$> migrations)+renderBlueprintMigrations :: T.Text -> [T.Text] -> [BlueprintMigration] -> T.Text+renderBlueprintMigrations name resolvedBlueprints migrations =+ T.intercalate "\n\n" (renderBlueprintMigration name resolvedBlueprints <$> migrations) -renderBlueprintMigration :: [T.Text] -> BlueprintMigration -> T.Text-renderBlueprintMigration resolvedBlueprints BlueprintMigration {from, to, prompt, entails} =+renderBlueprintMigration :: T.Text -> [T.Text] -> BlueprintMigration -> T.Text+renderBlueprintMigration name resolvedBlueprints BlueprintMigration {from, to, prompt, entails} = T.intercalate "\n\n"- ( ["### " <> from <> " → " <> to, T.strip prompt]+ ( [ migrationHeading from to,+ "Run in the project using the library at " <> inlineCode from <> ", with the blueprint installed and an authenticated agent provider. Seihou gives the agent the instructions below for the move to " <> inlineCode to <> ".",+ fencedBlock "bash" ("seihou agent migrate " <> shellArgument name <> " --from " <> shellArgument from <> " --to " <> shellArgument to),+ T.strip prompt+ ] <> renderEntails resolvedBlueprints entails )
src/Seihou/OKF/Extension/Docs.hs view
@@ -187,6 +187,8 @@ renderDocRenderError :: DocRenderError -> T.Text renderDocRenderError (InvalidDocConceptId kind name err) = "invalid OKF concept ID for " <> T.pack (show kind) <> " " <> name <> ": " <> err+renderDocRenderError (AmbiguousMigrationAnchor kind name anchor) =+ "ambiguous migration anchor for " <> T.pack (show kind) <> " " <> name <> ": " <> anchor -- | Every 'BundleValidationError' constructor gets its own branch, deliberately -- with no catch-all: @-Werror=incomplete-patterns@ then turns the next okf-core
test/Main.hs view
@@ -5,12 +5,21 @@ import Seihou.OKF.Docs.RenderSpec qualified as RenderSpec import Seihou.OKF.Extension (okfSmoke) import Seihou.OKF.Extension.DocsSpec qualified as DocsSpec+import System.Environment (getArgs) import Test.Hspec import Test.Tasty import Test.Tasty.Hspec (testSpec) main :: IO () main = do+ args <- getArgs+ case args of+ ["--write-docs-fixture", "basic", directory] -> ModelSpec.writeFixtureRegistry directory+ ["--write-docs-fixture", "all-kinds", directory] -> ModelSpec.writeCurrentFixtureRegistry directory+ _ -> runTests++runTests :: IO ()+runTests = do smokeTests <- testSpec "Seihou.OKF.Extension" spec modelTests <- ModelSpec.tests renderTests <- RenderSpec.tests
test/Seihou/OKF/Docs/ModelSpec.hs view
@@ -1,4 +1,4 @@-module Seihou.OKF.Docs.ModelSpec (tests, writeCurrentFixtureRegistry) where+module Seihou.OKF.Docs.ModelSpec (tests, writeFixtureRegistry, writeCurrentFixtureRegistry) where import Control.Lens ((^.)) import Data.Generics.Labels ()@@ -155,6 +155,7 @@ writeFixtureRegistry :: FilePath -> IO () writeFixtureRegistry registryDir = do+ createDirectoryIfMissing True registryDir writeFile (registryDir </> "seihou-registry.dhall") registryDhall writeModule registryDir "modules/base" "base" [] "Base module" writeModule registryDir "modules/app" "app" ["base"] "Application module"@@ -165,6 +166,9 @@ writePrompt registryDir createDirectoryIfMissing True (registryDir </> "judgements/docs-review") writeFile (registryDir </> "judgements/docs-review/judgement.dhall") judgementDhall+ writeFile+ (registryDir </> "judgements/docs-review/examples.json")+ "{\"version\":1,\"examples\":[{\"id\":\"current-docs\",\"files\":[{\"path\":\"docs/usage.md\",\"content\":\"Describe the current CLI options.\"}],\"expect\":{\"stale-docs\":\"passed\"}}]}" writeModule :: FilePath -> FilePath -> String -> [String] -> String -> IO () writeModule registryDir relDir name dependencies description = do@@ -209,7 +213,7 @@ \, recipes = [ { name = \"app-recipe\", version = Some \"0.1.0\", path = \"recipes/app-recipe\", description = Some \"Recipe\", tags = [ \"recipe\" ] } ]\n\ \, blueprints =\n\ \ [ { name = \"app-blueprint\", version = Some \"0.1.0\", path = \"blueprints/app-blueprint\", description = Some \"Blueprint\", tags = [ \"blueprint\" ] }\n\- \ , { name = \"entailing-blueprint\", version = Some \"0.1.0\", path = \"blueprints/entailing-blueprint\", description = Some \"Entailing blueprint\", tags = [] : List Text }\n\+ \ , { name = \"entailing-blueprint\", version = Some \"0.1.0\", path = \"blueprints/entailing-blueprint\", description = Some \"Upgrade the application runtime and its dependent libraries\", tags = [] : List Text }\n\ \ ]\n\ \, prompts = [ { name = \"review\", version = Some \"0.1.0\", path = \"prompts/review\", description = Some \"Review prompt\", tags = [ \"prompt\" ] } ]\n\ \, judgements = [ { name = \"docs-review\", version = Some \"1.0.0\", path = \"judgements/docs-review\", description = Some \"Docs review\", tags = [] : List Text } ]\n\@@ -282,7 +286,7 @@ entailingBlueprintDhall = "{ name = \"entailing-blueprint\"\n\ \, version = Some \"0.1.0\"\n\- \, description = Some \"Entailing blueprint\"\n\+ \, description = Some \"Upgrade the application runtime and its dependent libraries\"\n\ \, prompt = \"Upgrade\"\n\ \, vars = [] : " <> varDeclListType@@ -387,7 +391,7 @@ writeCurrentFixtureRegistry :: FilePath -> IO () writeCurrentFixtureRegistry registryDir = do writeFixtureRegistry registryDir- overlay "modules/app/module.dhall" "let Op = < MoveFile : { src : Text, dest : Text } | MoveDir : { src : Text, dest : Text } | DeleteFile : { path : Text } | DeleteDir : { path : Text } | RemoveLine : { path : Text, line : Text } | RunCommand : { run : Text, workDir : Optional Text } >\nlet Action = < Apply : Text | Checkout : Text >\nin { dependencies = [ { module = \"base\", source = Some \"https://example.invalid/modules.git\", vars = [ {name=\"literal\",value=\"a|`b`\"} ] } ]\n, judgements = [ { name = \"docs-review\", source = None Text, when = Some \"IsSet project.name\" }, { name = \"docs-review\", source = Some \"https://example.invalid/reviews.git\", when = None Text }, { name = \"catalogue-review\", source = None Text, when = None Text } ]\n, steps = [ {strategy=\"template\",src=\"managed.tpl\",dest=\"managed\",when=None Text,patch=None Text,lifecycle=Some \"managed\"}, {strategy=\"template\",src=\"seed.tpl\",dest=\"seed\",when=None Text,patch=None Text,lifecycle=Some \"seed\"}, {strategy=\"symlink\",src=\"files\",dest=\"linked\",when=None Text,patch=None Text,lifecycle=Some \"checkout\"} ]\n, commands = [ {action=Action.Checkout \"touch SHOULD-NOT-EXIST\",workDir=None Text,when=None Text} ]\n, migrations = [ {from=\"1\",to=\"2\",ops=[Op.RemoveLine {path=\".gitignore\",line=\"exact|`literal`\"}]} ]\n}"+ overlay "modules/app/module.dhall" "let Op = < MoveFile : { src : Text, dest : Text } | MoveDir : { src : Text, dest : Text } | DeleteFile : { path : Text } | DeleteDir : { path : Text } | RemoveLine : { path : Text, line : Text } | RunCommand : { run : Text, workDir : Optional Text } >\nlet Action = < Apply : Text | Checkout : Text >\nin { dependencies = [ { module = \"base\", source = Some \"https://example.invalid/modules.git\", vars = [ {name=\"literal\",value=\"a|`b`\"} ] } ]\n, judgements = [ { name = \"docs-review\", source = None Text, when = Some \"IsSet project.name\" }, { name = \"docs-review\", source = Some \"https://example.invalid/reviews.git\", when = None Text }, { name = \"catalogue-review\", source = None Text, when = None Text } ]\n, steps = [ {strategy=\"template\",src=\"managed.tpl\",dest=\"managed\",when=None Text,patch=None Text,lifecycle=Some \"managed\"}, {strategy=\"template\",src=\"seed.tpl\",dest=\"seed\",when=None Text,patch=None Text,lifecycle=Some \"seed\"}, {strategy=\"symlink\",src=\"files\",dest=\"linked\",when=None Text,patch=None Text,lifecycle=Some \"checkout\"} ]\n, commands = [ {action=Action.Checkout \"touch SHOULD-NOT-EXIST\",workDir=None Text,when=None Text} ]\n, migrations = [ {from=\"2.4.0\",to=\"3.0.0\",ops=[Op.RemoveLine {path=\".gitignore\",line=\"exact|`literal`\"}]} ]\n}" overlay "recipes/app-recipe/recipe.dhall" "{ modules = [ { module = \"base\", source = None Text, vars = [] : List {name : Text,value : Text} }, { module = \"base\", source = Some \"https://example.invalid/modules.git\", vars = [] : List {name : Text,value : Text} } ]\n, extends = Some { recipe = \"app-recipe\", source = Some \"https://example.invalid/recipes.git\", versionRange = Some {minimum=\"1\",before=\"2\"} }\n, moduleOverrides = [ { module = \"inherited\", vars = [ {name=\"literal\",value=\"a|`b`\"} ] } ]\n, promptOverrides = [ {var=\"inherited\",text=\"First line\\n```text\\nsecond | line\",when=None Text,choices=None (List Text)} ]\n, judgements = [ { name = \"docs-review\", source = None Text, when = Some \"IsSet project.name\" }, { name = \"docs-review\", source = Some \"https://example.invalid/reviews.git\", when = None Text }, { name = \"catalogue-review\", source = None Text, when = None Text } ] }" overlay "blueprints/app-blueprint/blueprint.dhall" "{ baseModules = [ { module = \"base\", source = Some \"https://example.invalid/modules.git\", vars = [] : List {name : Text,value : Text} } ], allowedTools=Some ([] : List Text), prompt=\"First line\\n```text\\nsecond | line\",versionProbe=Some \"touch SHOULD-NOT-EXIST\\n```\",launch=Some {provider=Some \"test\",model=Some \"model\",effort=Some \"high\",mode=Some \"reserved\"} }" let judgementPath = registryDir </> "judgements/docs-review/judgement.dhall"
test/Seihou/OKF/Docs/RenderSpec.hs view
@@ -1,12 +1,14 @@ module Seihou.OKF.Docs.RenderSpec (tests) where import Control.Lens ((%~), (&), (.~), (?~), (^.))+import Data.Aeson (Value (..), object, toJSON, (.=)) import Data.Generics.Labels () import Data.List (sort) import Data.Map.Strict qualified as Map import Data.Text qualified as T import Okf.Bundle qualified as Okf import Okf.ConceptId qualified as Okf+import Okf.Document qualified as Okf import Okf.Validation (BundleValidationError (..), ValidationProfile (..)) import Seihou.Core.Migration ( BlueprintMigration (..),@@ -46,6 +48,33 @@ rendered `shouldSatisfy` T.isInfixOf "title: base" rendered `shouldSatisfy` T.isInfixOf "resource: seihou://fixture/modules/base" rendered `shouldSatisfy` T.isInfixOf "version: 1.0.0"++ it "publishes structured migration edges with a single target per anchor" $ do+ concept <- requireConcept "modules/rich" testOptions richModel+ let edge start end anchor =+ object ["from" .= String start, "to" .= String end, "anchor" .= String anchor]+ firstAnchor = "migration-0_2e_1_2e_0-0_2e_2_2e_0"+ secondAnchor = "migration-0_2e_2_2e_0-0_2e_3_2e_0"+ rendered = Okf.serializeConcept concept+ Okf.frontmatterLookup "seihouMigrationEdges" (Okf.frontmatter (Okf.conceptDocument concept))+ `shouldBe` Just (toJSON [edge "0.1.0" "0.2.0" firstAnchor, edge "0.2.0" "0.3.0" secondAnchor])+ T.count ("<a id=\"" <> firstAnchor <> "\"></a>") rendered `shouldBe` 1+ T.count ("<a id=\"" <> secondAnchor <> "\"></a>") rendered `shouldBe` 1+ owner <- requireConcept "modules/base" testOptions wellFormedModel+ Okf.frontmatterLookup "seihouMigrationEdges" (Okf.frontmatter (Okf.conceptDocument owner))+ `shouldBe` Just (toJSON ([] :: [Value]))+ nonOwner <- requireConcept "recipes/app-recipe" testOptions wellFormedModel+ Okf.frontmatterLookup "seihouMigrationEdges" (Okf.frontmatter (Okf.conceptDocument nonOwner))+ `shouldBe` Nothing++ it "refuses duplicate migration edges" $ do+ let duplicate entry =+ case entry ^. #artifact of+ DocModuleArtifact modl@Module {migrations} ->+ entry & #artifact .~ DocModuleArtifact (modl & #migrations .~ (migrations <> migrations))+ _ -> entry+ renderDocBundle testOptions (richModel & #entries %~ fmap duplicate)+ `shouldBe` Left [AmbiguousMigrationAnchor DocModuleKind "rich" "migration-0_2e_1_2e_0-0_2e_2_2e_0"] it "renders resolvable cross-links to composed modules" $ do concept <- requireConcept "recipes/app-recipe" testOptions wellFormedModel
test/Seihou/OKF/Extension/DocsSpec.hs view
@@ -136,6 +136,24 @@ "maxFindings: 20", "not calibrated risk estimates" ]+ prompt <- page "prompts/review.md"+ edgeOwner <- page "blueprints/entailing-blueprint.md"+ let guidance =+ [ (app, "seihou run app --dry-run"),+ (recipe, "seihou run app-recipe --dry-run"),+ (blueprint, "seihou agent run app-blueprint"),+ (prompt, "seihou prompt run review"),+ (judgement, "seihou judgement eval docs-review --offline")+ ]+ mapM_+ ( \(body, command) -> do+ body `shouldSatisfy` T.isInfixOf "## When to use"+ body `shouldSatisfy` T.isInfixOf "## How to use"+ body `shouldSatisfy` T.isInfixOf command+ )+ guidance+ app `shouldSatisfy` T.isInfixOf "seihou migrate app --to 3.0.0 --dry-run"+ edgeOwner `shouldSatisfy` T.isInfixOf "seihou agent migrate entailing-blueprint --from 2.4.0 --to 3.0.0" validateWritten outDir it "preserves every existing output file on invalid input and rejecting profiles even with force" $@@ -244,11 +262,11 @@ demandingProfile = T.replace demandingProfileAnchor- ("[ scalar \"stale_after\" \"A key this generator never emits.\"\n , scalar \"type\"")+ (demandingProfileAnchor <> "\n , scalar \"stale_after\" \"A key this generator never emits.\"") builtinProfileDescriptor demandingProfileAnchor :: T.Text-demandingProfileAnchor = "[ scalar \"type\""+demandingProfileAnchor = "\"Which kind of Seihou artifact this concept documents.\"" snapshot :: FilePath -> IO [(FilePath, T.Text)] snapshot root = do