seihou-core 0.16.0.2 → 0.17.0.0
raw patch · 8 files changed
+190/−69 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
- Seihou.Prelude: ($dm_1) :: (Field1 s t a b, Generic s, Generic t, GIxed N0 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_10) :: (Field10 s t a b, Generic s, Generic t, GIxed N9 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_11) :: (Field11 s t a b, Generic s, Generic t, GIxed N10 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_12) :: (Field12 s t a b, Generic s, Generic t, GIxed N11 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_13) :: (Field13 s t a b, Generic s, Generic t, GIxed N12 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_14) :: (Field14 s t a b, Generic s, Generic t, GIxed N13 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_15) :: (Field15 s t a b, Generic s, Generic t, GIxed N14 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_16) :: (Field16 s t a b, Generic s, Generic t, GIxed N15 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_17) :: (Field17 s t a b, Generic s, Generic t, GIxed N16 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_18) :: (Field18 s t a b, Generic s, Generic t, GIxed N17 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_19) :: (Field19 s t a b, Generic s, Generic t, GIxed N18 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_2) :: (Field2 s t a b, Generic s, Generic t, GIxed N1 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_3) :: (Field3 s t a b, Generic s, Generic t, GIxed N2 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_4) :: (Field4 s t a b, Generic s, Generic t, GIxed N3 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_5) :: (Field5 s t a b, Generic s, Generic t, GIxed N4 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_6) :: (Field6 s t a b, Generic s, Generic t, GIxed N5 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_7) :: (Field7 s t a b, Generic s, Generic t, GIxed N6 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_8) :: (Field8 s t a b, Generic s, Generic t, GIxed N7 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_9) :: (Field9 s t a b, Generic s, Generic t, GIxed N8 (Rep s) (Rep t) a b) => Lens s t a b
- Seihou.Prelude: ($dm_Empty) :: (AsEmpty a, Monoid a, Eq a) => Prism' a ()
- Seihou.Prelude: ($dm_Wrapped') :: forall (d :: Meta) (c :: Meta) (s' :: Meta) a. (Wrapped s, Generic s, D1 d (C1 c (S1 s' (Rec0 a))) ~ Rep s, Unwrapped s ~ GUnwrapped (Rep s)) => Iso' s (Unwrapped s)
- Seihou.Prelude: ($dmeach) :: forall (g :: Type -> Type). (Each s t a b, Traversable g, s ~ g a, t ~ g b) => Traversal s t a b
- Seihou.Prelude: ($dmifoldMap) :: (FoldableWithIndex i f, TraversableWithIndex i f, Monoid m) => (i -> a -> m) -> f a -> m
- Seihou.Prelude: ($dmimap) :: (FunctorWithIndex i f, TraversableWithIndex i f) => (i -> a -> b) -> f a -> f b
- Seihou.Prelude: ($dmitraverse) :: (TraversableWithIndex i t, i ~ Int, Applicative f) => (i -> a -> f b) -> t a -> f (t b)
- Seihou.Prelude: ($dmix) :: (Ixed m, At m) => Index m -> Traversal' m (IxValue m)
- Seihou.Prelude: ($dmplate) :: (Plated a, Data a) => Traversal' a a
- Seihou.Prelude: infixl 5 `failing`
- Seihou.Prelude: infixl 8 ^#
- Seihou.Prelude: infixr 2 `zoom`
- Seihou.Prelude: infixr 4 ||~
- Seihou.Prelude: infixr 8 #
- Seihou.Prelude: infixr 9 ...
+ Seihou.Core.Types: CallerToolPolicy :: ![Text] -> !Maybe SHA256 -> !Maybe SHA256 -> !Maybe SHA256 -> CallerToolPolicy
+ Seihou.Core.Types: CallerToolPolicyEvidence :: ManifestCapability
+ Seihou.Core.Types: [callerToolPolicy] :: AppliedBlueprintMigration -> !Maybe CallerToolPolicy
+ Seihou.Core.Types: [codexHooksSha256] :: CallerToolPolicy -> !Maybe SHA256
+ Seihou.Core.Types: [codexRulesSha256] :: CallerToolPolicy -> !Maybe SHA256
+ Seihou.Core.Types: [settingsSha256] :: CallerToolPolicy -> !Maybe SHA256
+ Seihou.Core.Types: data CallerToolPolicy
+ Seihou.Core.Types: instance GHC.Classes.Eq Seihou.Core.Types.CallerToolPolicy
+ Seihou.Core.Types: instance GHC.Internal.Generics.Generic Seihou.Core.Types.CallerToolPolicy
+ Seihou.Core.Types: instance GHC.Internal.Show.Show Seihou.Core.Types.CallerToolPolicy
+ Seihou.Manifest.Hash: hashBytes :: ByteString -> SHA256
+ Seihou.Manifest.Types: blueprintToJSON :: ManifestSchemaVersion -> AppliedBlueprint -> Value
+ Seihou.Manifest.Types: instance Data.Aeson.Types.FromJSON.FromJSON Seihou.Core.Types.CallerToolPolicy
+ Seihou.Manifest.Types: instance Data.Aeson.Types.ToJSON.ToJSON Seihou.Core.Types.CallerToolPolicy
+ Seihou.Manifest.Upgrade: AddUnknownCallerToolPolicy :: UpgradeStepAction
- Seihou.Core.Types: AppliedBlueprint :: !ModuleName -> !ArtifactOrigin -> !Maybe Text -> !UTCTime -> ![ModuleName] -> !Bool -> !Maybe Text -> !Maybe Text -> AppliedBlueprint
+ Seihou.Core.Types: AppliedBlueprint :: !ModuleName -> !ArtifactOrigin -> !Maybe Text -> !UTCTime -> ![ModuleName] -> !Bool -> !Maybe Text -> !Maybe Text -> !Maybe CallerToolPolicy -> AppliedBlueprint
- Seihou.Core.Types: AppliedBlueprintMigration :: !ModuleName -> !ArtifactOrigin -> !Maybe Text -> !Text -> !Text -> !MigrationOutcome -> !UTCTime -> !Maybe Text -> AppliedBlueprintMigration
+ Seihou.Core.Types: AppliedBlueprintMigration :: !ModuleName -> !ArtifactOrigin -> !Maybe Text -> !Text -> !Text -> !MigrationOutcome -> !UTCTime -> !Maybe Text -> !Maybe CallerToolPolicy -> AppliedBlueprintMigration
- Seihou.Core.Types: [allowedTools] :: AgentPrompt -> !Maybe [Text]
+ Seihou.Core.Types: [allowedTools] :: CallerToolPolicy -> ![Text]
- Seihou.Prelude: infixl 1 ??
+ Seihou.Prelude: infixl 1 <&>
Files
- seihou-core.cabal +1/−1
- src/Seihou/Core/Types.hs +16/−2
- src/Seihou/Manifest/Hash.hs +5/−5
- src/Seihou/Manifest/Types.hs +101/−53
- src/Seihou/Manifest/Upgrade.hs +20/−1
- test/Seihou/Core/JudgementSpec.hs +1/−1
- test/Seihou/Manifest/TypesSpec.hs +39/−6
- test/Seihou/Manifest/UpgradeSpec.hs +7/−0
seihou-core.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: seihou-core-version: 0.16.0.2+version: 0.17.0.0 synopsis: Core library for Seihou project scaffolding description: Core library for Seihou, a composable project scaffolding system.
src/Seihou/Core/Types.hs view
@@ -68,6 +68,7 @@ AppliedRecipeNode (..), AppliedModule (..), AppliedRecipe (..),+ CallerToolPolicy (..), AppliedBlueprint (..), MigrationOutcome (..), AppliedBlueprintMigration (..),@@ -681,6 +682,7 @@ | CheckoutLocalCommands | -- | Active judgement definitions and their policy (schema 15). JudgementState+ | CallerToolPolicyEvidence deriving stock (Eq, Ord, Show, Enum, Bounded, Generic) -- | What the manifest knows about how the owners of a path write it.@@ -864,6 +866,16 @@ } deriving stock (Eq, Show, Generic) +-- | Invocation inputs attested by the provider's run or migration receipt.+-- File paths and hook contents stay local to the caller.+data CallerToolPolicy = CallerToolPolicy+ { allowedTools :: ![Text],+ settingsSha256 :: !(Maybe SHA256),+ codexHooksSha256 :: !(Maybe SHA256),+ codexRulesSha256 :: !(Maybe SHA256)+ }+ deriving stock (Eq, Show, Generic)+ -- | Blueprint provenance recorded in the manifest after a successful -- @seihou agent run@ invocation. The agent owns file output, so this -- entry describes the *invocation* (which blueprint, which baseline, the@@ -892,7 +904,8 @@ baselineModules :: ![ModuleName], noBaseline :: !Bool, userPrompt :: !(Maybe Text),- agentSessionId :: !(Maybe Text)+ agentSessionId :: !(Maybe Text),+ callerToolPolicy :: !(Maybe CallerToolPolicy) } deriving stock (Eq, Show, Generic) @@ -940,7 +953,8 @@ toVersion :: !Text, outcome :: !MigrationOutcome, appliedAt :: !UTCTime,- agentSessionId :: !(Maybe Text)+ agentSessionId :: !(Maybe Text),+ callerToolPolicy :: !(Maybe CallerToolPolicy) } deriving stock (Eq, Show, Generic)
src/Seihou/Manifest/Hash.hs view
@@ -1,5 +1,6 @@ module Seihou.Manifest.Hash ( hashContent,+ hashBytes, baselineRefForContent, baselineRefFromText, )@@ -17,11 +18,10 @@ -- | Compute the SHA256 hash of text content, returning a hex-encoded digest. -- The text is UTF-8 encoded before hashing. hashContent :: Text -> SHA256-hashContent t =- let bytes = TE.encodeUtf8 t- digest = SHA256.hash bytes- hex = Base16.encode digest- in SHA256 (TE.decodeUtf8 hex)+hashContent = hashBytes . TE.encodeUtf8++hashBytes :: BS.ByteString -> SHA256+hashBytes = SHA256 . TE.decodeUtf8 . Base16.encode . SHA256.hash -- | Hash generated content into its content-addressed baseline reference. baselineRefForContent :: Text -> BaselineRef
src/Seihou/Manifest/Types.hs view
@@ -8,6 +8,7 @@ sharedWriteModeToText, sharedWriteModeFromText, manifestToJSON,+ blueprintToJSON, manifestFromJSON, writeAppliedBlueprint, writeAppliedBlueprintMigration,@@ -90,7 +91,7 @@ -- Schema 15 records active judgements: a definition snapshot, its digest and -- the project policy. 14 -> 15 adds an empty judgement list. currentManifestVersion :: ManifestSchemaVersion-currentManifestVersion = ManifestSchemaVersion 15+currentManifestVersion = ManifestSchemaVersion 16 -- | The oldest schema the ordinary decoder reads. Anything older records -- machine-specific absolute paths and must go through the explicit@@ -111,6 +112,7 @@ minimumManifestVersion CheckoutLocalOutputs = ManifestSchemaVersion 9 minimumManifestVersion CheckoutLocalCommands = ManifestSchemaVersion 10 minimumManifestVersion JudgementState = ManifestSchemaVersion 15+minimumManifestVersion CallerToolPolicyEvidence = ManifestSchemaVersion 16 -- | Whether a manifest's schema can express everything a capability needs. -- A decoded schema-6 manifest answers 'False' for@@ -160,8 +162,8 @@ } -- | Insert or replace one exact blueprint migration receipt. Replacement is--- performed in place, while adding a v5-only receipt upgrades the manifest--- version and preserves every unrelated field.+-- performed in place. The publisher prepares the manifest schema before+-- attaching the receipt. -- -- The receipt's 'outcome' is deliberately excluded from the edge comparison, -- which is the one place it is left out of one. An edge that reported itself@@ -170,7 +172,7 @@ writeAppliedBlueprintMigration :: AppliedBlueprintMigration -> Manifest -> Manifest writeAppliedBlueprintMigration receipt manifest = Manifest- { version = currentManifestVersion,+ { version = manifest ^. #version, genAt = manifest ^. #genAt, modules = manifest ^. #modules, vars = manifest ^. #vars,@@ -238,13 +240,13 @@ "variables" .= varsToJSON (m ^. #vars), "files" .= filesToJSON (m ^. #version) (m ^. #files), "applications" .= map (applicationToJSON (m ^. #version)) (m ^. #applications),- "blueprintMigrations" .= (m ^. #blueprintMigrations)+ "blueprintMigrations" .= map (blueprintMigrationToJSON (m ^. #version)) (m ^. #blueprintMigrations) ] ++ ["checkoutOutputs" .= Map.map checkoutToJSON (m ^. #checkoutOutputs) | m ^. #version >= ManifestSchemaVersion 9] ++ ["seeds" .= Map.map (seedToJSON (m ^. #version)) (m ^. #seeds) | m ^. #version >= ManifestSchemaVersion 8] ++ ["judgements" .= map activeJudgementToJSON (m ^. #judgements) | manifestSupports JudgementState m] ++ maybe [] (\r -> ["recipe" .= r]) (m ^. #recipe)- ++ maybe [] (\b -> ["blueprint" .= b]) (m ^. #blueprint)+ ++ maybe [] (\b -> ["blueprint" .= blueprintToJSON (m ^. #version) b]) (m ^. #blueprint) -- | The version is read and checked before anything else, because the -- file-record representation depends on it.@@ -263,8 +265,8 @@ <*> (if v >= ManifestSchemaVersion 9 then Map.traverseWithKey (\_ -> parseCheckout) =<< o .: "checkoutOutputs" else pure Map.empty) <*> (o Aeson..:? "applications" Aeson..!= [] >>= mapM (parseApplication v)) <*> o Aeson..:? "recipe"- <*> o Aeson..:? "blueprint"- <*> o Aeson..:? "blueprintMigrations" Aeson..!= []+ <*> (o Aeson..:? "blueprint" >>= traverse (parseBlueprint v))+ <*> (o Aeson..:? "blueprintMigrations" Aeson..!= [] >>= traverse (parseBlueprintMigration v)) <*> (if v >= minimumManifestVersion JudgementState then mapM parseActiveJudgement =<< o .: "judgements" else pure []) let judgementNames = map (^. #definition . #name) (manifest ^. #judgements) unless (Set.size (Set.fromList judgementNames) == length judgementNames) $ fail "manifest records the same judgement name more than once"@@ -546,31 +548,68 @@ <$> o Aeson..:? "version" <*> o .: "appliedAt" -instance ToJSON AppliedBlueprint where- toJSON ab =- Aeson.object $- [ "name" .= (ab ^. #name . #unModuleName),- "origin" .= (ab ^. #origin),- "appliedAt" .= (ab ^. #appliedAt),- "baselineModules" .= map (^. #unModuleName) (ab ^. #baselineModules),- "noBaseline" .= (ab ^. #noBaseline)+instance ToJSON CallerToolPolicy where+ toJSON policy =+ Aeson.object+ [ "allowedTools" .= (policy ^. #allowedTools),+ "settingsSha256" .= (policy ^. #settingsSha256),+ "codexHooksSha256" .= (policy ^. #codexHooksSha256),+ "codexRulesSha256" .= (policy ^. #codexRulesSha256) ]- ++ maybe [] (\v -> ["version" .= v]) (ab ^. #blueprintVersion)- ++ maybe [] (\p -> ["userPrompt" .= p]) (ab ^. #userPrompt)- ++ maybe [] (\s -> ["agentSessionId" .= s]) (ab ^. #agentSessionId) +instance FromJSON CallerToolPolicy where+ parseJSON = Aeson.withObject "CallerToolPolicy" $ \o -> do+ rules <- o .: "allowedTools"+ settings <- o .: "settingsSha256"+ hooks <- o .: "codexHooksSha256"+ policyRules <- o .: "codexRulesSha256"+ when (any (T.null . T.strip) rules) $ fail "caller tool rules must be nonblank"+ forM_ [settings, hooks, policyRules] $ mapM_ $ \(SHA256 digest) ->+ unless (T.length digest == 64 && T.all isHexDigit digest && T.toLower digest == digest) $+ fail "caller policy digests must be lowercase SHA-256"+ when ((not (null rules) || isJust settings) == (isJust hooks || isJust policyRules)) $+ fail "callerToolPolicy must identify inputs for exactly one provider"+ pure (CallerToolPolicy rules settings hooks policyRules)++parseCallerToolPolicy :: ManifestSchemaVersion -> Aeson.Object -> Aeson.Parser (Maybe CallerToolPolicy)+parseCallerToolPolicy version o+ | version >= minimumManifestVersion CallerToolPolicyEvidence = o .: "callerToolPolicy"+ | KM.member "callerToolPolicy" o = fail "callerToolPolicy requires manifest schema 16"+ | otherwise = pure Nothing++instance ToJSON AppliedBlueprint where+ toJSON = blueprintToJSON currentManifestVersion++blueprintToJSON :: ManifestSchemaVersion -> AppliedBlueprint -> Aeson.Value+blueprintToJSON version ab =+ Aeson.object $+ [ "name" .= (ab ^. #name . #unModuleName),+ "origin" .= (ab ^. #origin),+ "appliedAt" .= (ab ^. #appliedAt),+ "baselineModules" .= map (^. #unModuleName) (ab ^. #baselineModules),+ "noBaseline" .= (ab ^. #noBaseline)+ ]+ ++ ["callerToolPolicy" .= (ab ^. #callerToolPolicy) | version >= minimumManifestVersion CallerToolPolicyEvidence]+ ++ maybe [] (\v -> ["version" .= v]) (ab ^. #blueprintVersion)+ ++ maybe [] (\p -> ["userPrompt" .= p]) (ab ^. #userPrompt)+ ++ maybe [] (\s -> ["agentSessionId" .= s]) (ab ^. #agentSessionId)+ instance FromJSON AppliedBlueprint where- parseJSON = Aeson.withObject "AppliedBlueprint" $ \o -> do- name <- ModuleName <$> o .: "name"- origin <- legacyLocalOrigin (name ^. #unModuleName) <$> o Aeson..:? "origin"- AppliedBlueprint name origin- <$> o Aeson..:? "version"- <*> o .: "appliedAt"- <*> (map ModuleName <$> o Aeson..:? "baselineModules" Aeson..!= [])- <*> o Aeson..:? "noBaseline" Aeson..!= False- <*> o Aeson..:? "userPrompt"- <*> o Aeson..:? "agentSessionId"+ parseJSON = parseBlueprint currentManifestVersion +parseBlueprint :: ManifestSchemaVersion -> Aeson.Value -> Aeson.Parser AppliedBlueprint+parseBlueprint version = Aeson.withObject "AppliedBlueprint" $ \o -> do+ name <- ModuleName <$> o .: "name"+ origin <- legacyLocalOrigin (name ^. #unModuleName) <$> o Aeson..:? "origin"+ AppliedBlueprint name origin+ <$> o Aeson..:? "version"+ <*> o .: "appliedAt"+ <*> (map ModuleName <$> o Aeson..:? "baselineModules" Aeson..!= [])+ <*> o Aeson..:? "noBaseline" Aeson..!= False+ <*> o Aeson..:? "userPrompt"+ <*> o Aeson..:? "agentSessionId"+ <*> parseCallerToolPolicy version o+ -- | A nested object with a discriminator, matching 'ArtifactOrigin', because -- the not-applicable case carries a reason and a bare string would have -- nowhere to put it.@@ -598,33 +637,41 @@ unstatedReason = "(no reason recorded)" instance ToJSON AppliedBlueprintMigration where- toJSON receipt =- Aeson.object $- [ "name" .= (receipt ^. #name . #unModuleName),- "origin" .= (receipt ^. #origin),- "from" .= (receipt ^. #fromVersion),- "to" .= (receipt ^. #toVersion),- "outcome" .= (receipt ^. #outcome),- "appliedAt" .= (receipt ^. #appliedAt)- ]- ++ maybe [] (\version -> ["version" .= version]) (receipt ^. #blueprintVersion)- ++ maybe [] (\sessionId -> ["agentSessionId" .= sessionId]) (receipt ^. #agentSessionId)+ toJSON = blueprintMigrationToJSON currentManifestVersion +blueprintMigrationToJSON :: ManifestSchemaVersion -> AppliedBlueprintMigration -> Aeson.Value+blueprintMigrationToJSON version receipt =+ Aeson.object $+ [ "name" .= (receipt ^. #name . #unModuleName),+ "origin" .= (receipt ^. #origin),+ "from" .= (receipt ^. #fromVersion),+ "to" .= (receipt ^. #toVersion),+ "outcome" .= (receipt ^. #outcome),+ "appliedAt" .= (receipt ^. #appliedAt)+ ]+ ++ ["callerToolPolicy" .= (receipt ^. #callerToolPolicy) | version >= minimumManifestVersion CallerToolPolicyEvidence]+ ++ maybe [] (\version -> ["version" .= version]) (receipt ^. #blueprintVersion)+ ++ maybe [] (\sessionId -> ["agentSessionId" .= sessionId]) (receipt ^. #agentSessionId)+ instance FromJSON AppliedBlueprintMigration where- parseJSON = Aeson.withObject "AppliedBlueprintMigration" $ \o -> do- name <- ModuleName <$> o .: "name"- origin <- legacyLocalOrigin (name ^. #unModuleName) <$> o Aeson..:? "origin"- AppliedBlueprintMigration name origin- <$> o Aeson..:? "version"- <*> o .: "from"- <*> o .: "to"- -- A receipt written before the field existed records an edge whose- -- session returned, which is exactly what 'MigrationApplied' means, so- -- reading it that way preserves its meaning rather than inventing one.- <*> o Aeson..:? "outcome" Aeson..!= MigrationApplied- <*> o .: "appliedAt"- <*> o Aeson..:? "agentSessionId"+ parseJSON = parseBlueprintMigration currentManifestVersion +parseBlueprintMigration :: ManifestSchemaVersion -> Aeson.Value -> Aeson.Parser AppliedBlueprintMigration+parseBlueprintMigration version = Aeson.withObject "AppliedBlueprintMigration" $ \o -> do+ name <- ModuleName <$> o .: "name"+ origin <- legacyLocalOrigin (name ^. #unModuleName) <$> o Aeson..:? "origin"+ AppliedBlueprintMigration name origin+ <$> o Aeson..:? "version"+ <*> o .: "from"+ <*> o .: "to"+ -- A receipt written before the field existed records an edge whose+ -- session returned, which is exactly what 'MigrationApplied' means, so+ -- reading it that way preserves its meaning rather than inventing one.+ <*> o Aeson..:? "outcome" Aeson..!= MigrationApplied+ <*> o .: "appliedAt"+ <*> o Aeson..:? "agentSessionId"+ <*> parseCallerToolPolicy version o+ instance ToJSON AppliedModule where toJSON am = Aeson.object $@@ -948,6 +995,7 @@ <> ["removal commands cannot declare checkout setup" | applied <- manifest ^. #modules, removal <- maybe [] pure (applied ^. #removal), any ((== CheckoutCommandLifecycle) . (^. #lifecycle)) (removal ^. #commands)] <> ["checkout commands require manifest schema 10" | manifest ^. #version < ManifestSchemaVersion 10, any (not . null . (^. #checkoutCommands)) (manifest ^. #applications)] <> ["checkout outputs require manifest schema 9" | manifest ^. #version < ManifestSchemaVersion 9, not (Map.null (manifest ^. #checkoutOutputs))]+ <> ["caller tool policy requires manifest schema 16" | not (manifestSupports CallerToolPolicyEvidence manifest), isJust ((^. #callerToolPolicy) =<< manifest ^. #blueprint) || any (isJust . (^. #callerToolPolicy)) (manifest ^. #blueprintMigrations)] <> ["judgements require manifest schema 15" | not (manifestSupports JudgementState manifest), not (null (manifest ^. #judgements))] <> ["seed receipts require manifest schema 8" | manifest ^. #version < ManifestSchemaVersion 8, not (Map.null (manifest ^. #seeds))]
src/Seihou/Manifest/Upgrade.hs view
@@ -65,6 +65,7 @@ | MakeSeedOwnershipExplicit | AddEmptyCheckoutCommands | AddEmptyJudgements+ | AddUnknownCallerToolPolicy deriving stock (Eq, Ord, Show, Enum, Bounded, Generic) -- | Whether a step may be staged automatically.@@ -130,7 +131,8 @@ step 11 AddUnknownRecipeInputs "recipe inputs", step 12 AddUnknownRecipeChain "recipe inheritance provenance", step 13 IntroduceConditionalRemoval "conditional removal policies and recorded root retirement",- step 14 AddEmptyJudgements "active judgements"+ step 14 AddEmptyJudgements "active judgements",+ step 15 AddUnknownCallerToolPolicy "caller tool policy receipts" ] where step from stepAction =@@ -148,6 +150,7 @@ upgradeStepKind AddEmptyCheckoutCommands = LosslessUpgrade upgradeStepKind MakeSeedOwnershipExplicit = LosslessUpgrade upgradeStepKind AddEmptyJudgements = LosslessUpgrade+upgradeStepKind AddUnknownCallerToolPolicy = LosslessUpgrade -- | The contiguous steps from @source@ to @target@. Planning from a version -- to itself is an empty path.@@ -222,6 +225,7 @@ Aeson.Object fields -> Right (Aeson.Object (KeyMap.insert "applications" (addInputs (fromMaybe (Aeson.Array mempty) (KeyMap.lookup "applications" fields))) fields)) _ -> Right document StampVersion -> Right document+ AddUnknownCallerToolPolicy -> first (MalformedDocument actual) (addUnknownCallerToolPolicy document) AddEmptyJudgements -> case document of Aeson.Object fields -> case KeyMap.lookup "judgements" fields of Nothing -> Right (Aeson.Object (KeyMap.insert "judgements" (Aeson.toJSON ([] :: [Aeson.Value])) fields))@@ -258,6 +262,21 @@ first (MalformedDocument actual) (makeSharedWriteEvidenceExplicit document) ConvertMachineLocalPaths -> Left (StepRequiresInference upgradeStep) pure (setDocumentSchemaVersion (upgradeStep ^. #toVersion) transformed)++addUnknownCallerToolPolicy :: Aeson.Value -> Either Text Aeson.Value+addUnknownCallerToolPolicy (Aeson.Object fields) =+ Aeson.Object <$> KeyMap.traverseWithKey update fields+ where+ update "blueprint" Aeson.Null = Right Aeson.Null+ update "blueprint" receipt = addPolicy receipt+ update "blueprintMigrations" (Aeson.Array receipts) = Aeson.Array <$> traverse addPolicy receipts+ update "blueprintMigrations" _ = Left "blueprintMigrations must be an array"+ update _ value = Right value+ addPolicy (Aeson.Object receipt)+ | KeyMap.member "callerToolPolicy" receipt = Left "schema 15 cannot contain callerToolPolicy"+ | otherwise = Right (Aeson.Object (KeyMap.insert "callerToolPolicy" Aeson.Null receipt))+ addPolicy _ = Left "blueprint receipt must be an object"+addUnknownCallerToolPolicy _ = Left "manifest must be an object" -- | Upgrade a raw document to @target@ using lossless steps only. Stops with -- 'StepRequiresInference' before changing anything if the path crosses an
test/Seihou/Core/JudgementSpec.hs view
@@ -83,7 +83,7 @@ describe "manifest state" $ do let def = definition (mkCheck "a" Yes strictBand :| [mkCheck "b" No lenientBand]) active = ActiveJudgement BundledJudgement def (definitionDigest def) (defaultPolicy ApprovedRemote False def & #checks . ix "b" . #enforcement .~ Advisory) [DirectAdoption, ApplicationOwner (ApplicationId "app-1")]- manifest = emptyManifest (UTCTime (fromGregorian 2026 11 11) 0) & #judgements .~ [active]+ manifest = emptyManifest (UTCTime (fromGregorian 2026 11 11) 0) & #version .~ ManifestSchemaVersion 15 & #judgements .~ [active] reencode :: (Aeson.Value -> Aeson.Value) -> Either String Manifest reencode f = manifestFromJSON . Aeson.encode . f =<< Aeson.eitherDecode (manifestToJSON manifest) it "round-trips the definition snapshot, digest and per-check policy at schema 15" $ do
test/Seihou/Manifest/TypesSpec.hs view
@@ -40,7 +40,8 @@ toVersion = toVersion, outcome = MigrationApplied, appliedAt = appliedAt,- agentSessionId = Nothing+ agentSessionId = Nothing,+ callerToolPolicy = Nothing } -- | The identity the @payments@ blueprint carries in the receipt cases below.@@ -177,7 +178,8 @@ baselineModules = [ModuleName "haskell-base"], noBaseline = False, userPrompt = Just "build a service",- agentSessionId = Just "session-abc"+ agentSessionId = Just "session-abc",+ callerToolPolicy = Nothing } ) & #blueprintMigrations .~ [mkBlueprintMigrationReceipt "service-blueprint" "1.0.0" "2.0.0" fixedTime2]@@ -641,7 +643,8 @@ baselineModules = [ModuleName "nix-flake", ModuleName "haskell-base"], noBaseline = False, userPrompt = Just "set this up for a payments microservice",- agentSessionId = Nothing+ agentSessionId = Nothing,+ callerToolPolicy = Nothing } Aeson.eitherDecode (Aeson.encode ab) `shouldBe` Right ab @@ -655,7 +658,8 @@ baselineModules = [], noBaseline = True, userPrompt = Nothing,- agentSessionId = Nothing+ agentSessionId = Nothing,+ callerToolPolicy = Nothing } Aeson.eitherDecode (Aeson.encode ab) `shouldBe` Right ab @@ -671,6 +675,7 @@ False Nothing Nothing+ Nothing ab2 = AppliedBlueprint (ModuleName "second")@@ -681,6 +686,7 @@ False (Just "do the thing") Nothing+ Nothing m1 = writeAppliedBlueprint ab1 m0 m2 = writeAppliedBlueprint ab2 m1 (m1 ^. #blueprint) `shouldBe` Just ab1@@ -698,6 +704,7 @@ MigrationApplied fixedTime (Just "session-123")+ Nothing Aeson.eitherDecode (Aeson.encode receipt) `shouldBe` Right receipt it "round-trips a not-applicable receipt with its reason" $ do@@ -711,6 +718,7 @@ (MigrationNotApplicable "the project has not adopted the bundle") fixedTime Nothing+ Nothing Aeson.eitherDecode (Aeson.encode receipt) `shouldBe` Right receipt it "round-trips a version-5 manifest containing a receipt" $ do@@ -731,6 +739,7 @@ MigrationApplied fixedTime2 (Just "rerun")+ Nothing manifest1 = writeAppliedBlueprintMigration unrelated (writeAppliedBlueprintMigration first (emptyManifest fixedTime)) manifest2 = writeAppliedBlueprintMigration replacement manifest1 (manifest2 ^. #blueprintMigrations) `shouldBe` [replacement, unrelated]@@ -752,7 +761,7 @@ it "treats equivalent public GitHub transports as one receipt identity, both ways" $ do let ssh = RemoteOrigin "git@github.com:acme/payments.git" "payments" Nothing https = RemoteOrigin "https://github.com/acme/payments.git" "payments" Nothing- edgeFrom origin at = AppliedBlueprintMigration (ModuleName "payments") origin (Just "0.5.0") "1.0.0" "2.0.0" MigrationApplied at Nothing+ edgeFrom origin at = AppliedBlueprintMigration (ModuleName "payments") origin (Just "0.5.0") "1.0.0" "2.0.0" MigrationApplied at Nothing Nothing forM_ [(ssh, https), (https, ssh)] $ \(recorded, installed) -> do let original = edgeFrom recorded fixedTime manifest1 = writeAppliedBlueprintMigration original (emptyManifest fixedTime)@@ -796,7 +805,7 @@ } fileRecord = FileRecord (SHA256 "hash") "base" Template fixedTime Nothing mempty SharedWriteUnknown recipe = AppliedRecipe "recipe" (LocalOrigin "recipe") (Just "1.0.0") fixedTime- normalBlueprint = AppliedBlueprint "payments" (LocalOrigin "payments") (Just "0.4.0") fixedTime [] False Nothing Nothing+ normalBlueprint = AppliedBlueprint "payments" (LocalOrigin "payments") (Just "0.4.0") fixedTime [] False Nothing Nothing Nothing seed = ( (emptyManifest fixedTime) & #modules .~ [appliedModule]@@ -929,6 +938,30 @@ case manifestFromJSON (LBS8.pack (schema7Json ",\"additiveOnly\":true")) of Right _ -> expectationFailure "schema 7 requires sharedWriteMode even when additiveOnly is present" Left err -> err `shouldSatisfy` isInfixOf "sharedWriteMode"++ describe "caller tool policy receipts" $ do+ it "requires the policy key at schema 16 and rejects it on receipts labeled schema 15" $ do+ let run = AppliedBlueprint "demo" (LocalOrigin "demo") Nothing fixedTime [] False Nothing Nothing Nothing+ edge = mkBlueprintMigrationReceipt "demo" "1" "2" fixedTime+ base = emptyManifest fixedTime+ checkVersion m (encoded, labeled) = do+ let value = Aeson.toJSON (m & #version .~ ManifestSchemaVersion encoded)+ case value of+ Aeson.Object fields -> do+ let mislabeled = Aeson.encode (Aeson.Object (KeyMap.insert "version" (Aeson.toJSON (labeled :: Int)) fields))+ manifestFromJSON mislabeled `shouldSatisfy` either (isInfixOf "callerToolPolicy") (const False)+ _ -> expectationFailure "expected a manifest object"+ forM_ [base & #blueprint .~ Just run, base & #blueprintMigrations .~ [edge]] $ \m ->+ mapM_ (checkVersion m) [(15, 16), (16, 15)]++ it "validates nullability, provider exclusivity, and exact lowercase digests" $ do+ let evidence rules settings hooks = Aeson.object ["allowedTools" Aeson..= (rules :: [T.Text]), "settingsSha256" Aeson..= (settings :: Maybe T.Text), "codexHooksSha256" Aeson..= (hooks :: Maybe T.Text), "codexRulesSha256" Aeson..= Aeson.Null]+ digest = Just (T.replicate 64 "a")+ invalid value = case Aeson.fromJSON @CallerToolPolicy value of Aeson.Error _ -> True; _ -> False+ mapM_+ (\value -> value `shouldSatisfy` invalid)+ [Aeson.object [], evidence [] Nothing Nothing, evidence [" "] Nothing Nothing, evidence ["Read"] Nothing digest, evidence [] (Just "abcd") Nothing, evidence [] (Just (T.replicate 64 "F")) Nothing]+ Aeson.fromJSON (evidence ["Read"] digest Nothing) `shouldBe` Aeson.Success (CallerToolPolicy ["Read"] (SHA256 <$> digest) Nothing Nothing) describe "manifest capabilities" $ do it "requires schema 7 for targeted additive shared-path updates" $
test/Seihou/Manifest/UpgradeSpec.hs view
@@ -63,6 +63,13 @@ spec :: Spec spec = do+ it "adds null caller evidence to both schema-15 receipt forms and preserves producer fields" $ do+ let receipt fields = Aeson.object (("producer" Aeson..= True) : fields)+ doc version r = Aeson.object ["version" Aeson..= (version :: Int), "blueprint" Aeson..= r, "blueprintMigrations" Aeson..= [r], "unrelated" Aeson..= True]+ old = doc 15 (receipt [])+ upgraded = doc 16 (receipt ["callerToolPolicy" Aeson..= Aeson.Null])+ fmap snd (upgradeDocumentLosslessly (v 16) old) `shouldBe` Right upgraded+ upgradeDocumentLosslessly (v 16) (doc 15 (receipt ["callerToolPolicy" Aeson..= True])) `shouldSatisfy` either (const True) (const False) it "adds an empty judgement list at schema 15 and refuses a forged one" $ do let document = Aeson.object ["version" Aeson..= (14 :: Int), "producerField" Aeson..= True] expected = Aeson.object ["version" Aeson..= (15 :: Int), "producerField" Aeson..= True, "judgements" Aeson..= ([] :: [Aeson.Value])]