<rss version="2.0">
	<channel>
		<title>Ben O&apos;Mahony</title>
		<link>https://benomahony.com</link>
		<description>Writing by Ben O'Mahony</description>
		<generator>Zine: https://zine-ssg.io</generator>
		<language>en-GB</language>
		<lastBuildDate>Fri, 09 Oct 2026 14:48:29 +0000</lastBuildDate>
		
			<item>
				<title>My Ten Rules of Agentic Engineering</title>
				<description>&lt;p&gt;These are the rules I keep coming back to when building software with AI agents. Most of them aren’t about the agent at all. They’re about the system around it, and the judgement you still need to own.&lt;/p&gt;&lt;h2 id=&quot;natural-language-isnt-specific-enough-for-specification&quot;&gt;1. Natural language isn’t specific enough for specification&lt;/h2&gt;&lt;p&gt;&lt;em&gt;Don’t go chasing waterfalls&lt;/em&gt;&lt;/p&gt;&lt;p&gt;The more you write up front, the more room you leave for the agent to be confidently wrong. Specify in types, contracts and tests, and keep the batch small.&lt;/p&gt;&lt;h2 id=&quot;dont-confuse-guidance-for-guardrails&quot;&gt;2. Don’t confuse guidance for guardrails&lt;/h2&gt;&lt;p&gt;A prompt asking nicely is not a constraint. If it matters, it belongs in something that can fail the build.&lt;/p&gt;&lt;h2 id=&quot;dont-be-a-meat-proxy&quot;&gt;3. Don’t be a meat proxy&lt;/h2&gt;&lt;p&gt;Clicking approve on a diff you don’t understand is not review. Either you’re adding judgement or you should automate yourself out of the position.&lt;/p&gt;&lt;h2 id=&quot;trust-but-verify&quot;&gt;4. Trust but verify&lt;/h2&gt;&lt;p&gt;&lt;em&gt;Build feedback sensors&lt;/em&gt;&lt;/p&gt;&lt;p&gt;Verification can’t be a person watching. Instrument the environment so the loop closes itself, with compilers, types, LSP, tests and traces feeding back into the run.&lt;/p&gt;&lt;h2 id=&quot;earn-the-right-to-automate&quot;&gt;5. Earn the right to automate&lt;/h2&gt;&lt;p&gt;Run it by hand often enough to know its failure modes. Automation before evidence just industrialises the parts you haven’t seen go wrong yet.&lt;/p&gt;&lt;h2 id=&quot;tidy-first&quot;&gt;6. Tidy first&lt;/h2&gt;&lt;p&gt;Separate the structural change from the behavioural one. An agent will do both in a single diff, and then neither is reviewable.&lt;/p&gt;&lt;h2 id=&quot;know-the-value-not-just-the-cost&quot;&gt;7. Know the value, not just the cost&lt;/h2&gt;&lt;p&gt;Spend is trivially instrumented, so it becomes the metric by default. Nobody optimises what they can’t see, and almost nobody measures what the tokens bought.&lt;/p&gt;&lt;h2 id=&quot;make-the-implicit-explicit&quot;&gt;8. Make the implicit explicit&lt;/h2&gt;&lt;p&gt;Conventions, workarounds and tribal knowledge live in people’s heads. An agent can’t infer any of it, so it guesses. Write it down (or ideally make it a deterministic check) and the repo becomes somewhere agents can work.&lt;/p&gt;&lt;h2 id=&quot;every-failure-becomes-a-ratchet&quot;&gt;9. Every failure becomes a ratchet&lt;/h2&gt;&lt;p&gt;Fix the root cause, not the instance. Turn each failure into a check that can’t be unturned, or you’ll meet the same bug in eleven places.&lt;/p&gt;&lt;h2 id=&quot;sensible-defaults-are-still-sensible&quot;&gt;10. Sensible defaults are still sensible&lt;/h2&gt;&lt;p&gt;Agentic engineering is additive. It deprecates nothing. Containers, CI, small interfaces, composition over inheritance. All of it still holds, and holds harder when code arrives faster than you can read it.&lt;/p&gt;</description>
				<link>https://benomahony.com/blog/my-10-rules-for-agentic-engineering/</link>
				<pubDate>Thu, 08 Oct 2026 00:00:00 +0000</pubDate>
				<guid>https://benomahony.com/blog/my-10-rules-for-agentic-engineering/</guid>
			</item>
		
			<item>
				<title>The 45 Minute &apos;Long-Lived&apos; Feature Branch</title>
				<description>&lt;p&gt;We were mobbing with AI in the middle of a workshop when we hit an unexpected problem. One of us had started work on a slightly larger refactor and had branched off from our normal trunk-based workflow. It was a perfectly reasonable decision, but suddenly the rest of the room slowed to a crawl. Half of us were orbiting that feature branch instead of shipping.&lt;/p&gt;&lt;p&gt;When it finally merged, we all breathed a sigh of relief.&lt;/p&gt;&lt;p&gt;The branch had existed for forty-five minutes.&lt;/p&gt;&lt;p&gt;We started joking that forty-five minutes now counted as a long-lived feature branch.&lt;/p&gt;&lt;h2 id=&quot;workshop-structure&quot;&gt;The Workshop Structure&lt;/h2&gt;&lt;p&gt;We do a lot of workshops with companies looking to build agents and adopt agentic coding. The format is simple but incredibly effective. Day one is about understanding the product and mapping customer value. That gives everyone a shared understanding of the domain, the problems we’re trying to solve and where the product creates value. Days two and three are four short build sprints. We spend ten or fifteen minutes deciding what we’re going to build, two or three hours mobbing with AI, regroup to demo what we had built, then repeat. I’m not certain I’d want to work like this every day, but the amount you can achieve in a few days is astronomical.&lt;/p&gt;&lt;p&gt;This was Sprint two. By this point we’d settled into a comfortable rhythm. We’d whiteboard together, discuss the architecture, occasionally sketching ideas, then work with AI agents to build what we’d agreed. As soon as we were happy, everything went straight to main. We’d split a number of tools and features between us so we could move faster, and trunk-based development was simply working.&lt;/p&gt;&lt;p&gt;The problem came when we decided to switch from the basic agent to the new AWS Strands &lt;a href=&quot;https://strandsagents.com/docs/user-guide/sdk/bidi/agent/&quot;&gt;bidirectional conversation agent&lt;/a&gt;. None of us had used it before, and the change had knock-on effects across much of the codebase. The engineer working on it quite reasonably wanted to use a separate branch while he got it working and could test and deploy it independently.&lt;/p&gt;&lt;h2 id=&quot;problem&quot;&gt;The problem&lt;/h2&gt;&lt;p&gt;As we continued building, it became more and more obvious that the work we’d split out depended on this refactor landing. It stopped making sense to forge ahead. We were reading the Strands documentation, discussing different approaches, passing ideas to the AI, and the implementation took a couple more attempts than we’d hoped.&lt;/p&gt;&lt;p&gt;We all quickly mobbed on the problem, thrashed out the implementation we felt happiest with, and merged the ‘long-lived feature branch’. We all breathed a sigh of relief. CI passed, everyone rebased, and within a few minutes we were back to building features. The merge conflicts were tiny. We joked that forty-five minutes now counted as a long-lived feature branch.&lt;/p&gt;&lt;p&gt;What surprised me most was that we all agreed that it wasn’t the way. In the past, when I’ve introduced trunk-based development, teams have usually worried about giving up long-lived branches and formal pull-request reviews. Here it was the opposite. Working outside trunk felt slow. The engineers not on the feature branch could feel the loss of productivity almost immediately.&lt;/p&gt;&lt;h2 id=&quot;why-we-could-move-quickly&quot;&gt;There were two reasons we could move this quickly.&lt;/h2&gt;&lt;p&gt;The first is easy to admit: this was a throwaway proof of concept. That certainly helps.&lt;/p&gt;&lt;p&gt;The second matters much more. We had tests running in CI to protect the functionality we’d already built, so we knew we weren’t going to regress the pieces we’d finished. More importantly, we had a shared architecture in our heads before we asked AI to write code. We’d spent time understanding the domain, agreeing the architecture and sketching it out together. One of the most validating moments came after one of the sprints when we pointed &lt;a href=&quot;https://likec4.dev/&quot;&gt;LikeC4&lt;/a&gt; at the repository. It reconstructed almost exactly the same architecture we’d drawn on the whiteboard before we’d written the implementation.&lt;/p&gt;&lt;h2 id=&quot;takeaway&quot;&gt;My takeaway&lt;/h2&gt;&lt;p&gt;For me, that’s the key point. The shared context in people’s heads did more work than any tooling. AI was filling in an implementation we’d already agreed on, not inventing one. When that shared understanding is missing, AI code generation tends to introduce duplication and unnecessary complexity because everyone is working from a slightly different mental model.&lt;/p&gt;&lt;p&gt;Trunk-based development (like many other XP and Agile techniques) is becoming more and more important. AI can generate change far faster than a team can absorb it, making shared understanding and continuous integration even more important than they were before.&lt;/p&gt;</description>
				<link>https://benomahony.com/blog/the-45-min-long-lived-feature-branch/</link>
				<pubDate>Thu, 13 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://benomahony.com/blog/the-45-min-long-lived-feature-branch/</guid>
			</item>
		
			<item>
				<title>Sakana AI&apos;s Fugu: Is this where model routing should live?</title>
				<description>&lt;p&gt;This article is published on Thoughtworks Insights.&lt;/p&gt;</description>
				<link>https://www.thoughtworks.com/insights/blog/generative-ai/sakana-ai-fugu-is-this-where-model-routing-should-live</link>
				<pubDate>Thu, 23 Jul 2026 00:00:00 +0000</pubDate>
				<guid>https://www.thoughtworks.com/insights/blog/generative-ai/sakana-ai-fugu-is-this-where-model-routing-should-live</guid>
			</item>
		
			<item>
				<title>Knowledge Products</title>
				<description>&lt;p&gt;&lt;em&gt;If you want AI to do knowledge work, then you need to build knowledge products.&lt;/em&gt;&lt;/p&gt;&lt;p&gt;For AI to do knowledge work that creates tangible value, it needs something better than a search box pointed at a heap of files.&lt;/p&gt;&lt;p&gt;Over the past decade most large organizations have learned how to make structured data usable. Warehouses, then lakes, then semantic layers and most recently the shift to treating each dataset as a product with an owner and a contract. A well-run business can now hand an analyst or an agent a clean and governed path to its numbers.&lt;/p&gt;&lt;p&gt;The unstructured half of the estate has had no such journey. Policies, contracts, case notes, incident reports, research, the recorded reasoning behind past decisions: this is where most of what an organization actually knows is held, and it mostly sits as a heap of files behind a search box nobody trusts. That was tolerable while the only consumers were people who knew where to look. It stops being tolerable the moment you want an agent to do knowledge work. It is even worse if you consider the volume of dormant intellectual property that could be utilized for the benefit of the business.&lt;/p&gt;&lt;p&gt;Agents raise the stakes in both directions. For the first time something can read across the whole heap and reason over it. But an agent grounding an answer in a stale or mis-scoped document does so with the same fluent confidence it brings to a correct one. The heap used to be a productivity problem. Connected to an agent it becomes a correctness and trust problem.&lt;/p&gt;&lt;p&gt;We know how to make a dataset consumable, so the question is: what is the equivalent move for a body of unstructured knowledge? The answer is the knowledge product.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;A knowledge product is an owned, governed and versioned body of knowledge that people, systems and agents can safely ground decisions in.&lt;/strong&gt;&lt;/p&gt;&lt;h2 id=&quot;three-products-one-hotel&quot;&gt;Three products, one hotel&lt;/h2&gt;&lt;p&gt;Picture the systems for running a hotel.&lt;/p&gt;&lt;p&gt;The property management system is an operational product (read “normal” product). It is where a booking is taken, a room assigned, a payment settled, a guest checked in. The system of record the hotel runs on. It transacts.&lt;/p&gt;&lt;p&gt;The data product is the occupancy model. A revenue manager asks how full last Friday was and it answers 94%, nine points up on the same week last year. It measures.&lt;/p&gt;&lt;p&gt;The knowledge product tells that same revenue manager why. Taylor Swift is playing the stadium across the road, the announcement moved every hotel in the city the day it landed, and the three comparable event weekends last year all ran around twenty points above baseline. It explains.&lt;/p&gt;&lt;p&gt;The concert could be modelled as data eventually, but in most organisations it first appears as unstructured context: a press release, an events calendar, a news feed, a note from sales. None of that belongs in the product raw. It enters when the owner has verified it, or when enough independent authoritative sources agree that confidence is earned rather than assumed. That act of curation is the work and added value of the knowledge product, and it is what lets the revenue manager, or an agent acting for them, trust the answer rather than hope about it.&lt;/p&gt;&lt;h2 id=&quot;missing-twin-of-the-data-product&quot;&gt;The missing twin of the data product&lt;/h2&gt;&lt;p&gt;Start from the structured side, because it is settled. A data product is what you get when a team treats a dataset the way a product team treats a product. Dehghani made this one of the founding principles of data mesh and called the data product the unit the whole architecture is built from.&lt;sup class=&quot;footnote-ref&quot;&gt;&lt;a href=&quot;#fn-1&quot; id=&quot;fn-1-ref-1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; It has an owner, a published interface, documented quality, and consumers it is accountable to. DJ Patil framed the idea earlier still.&lt;sup class=&quot;footnote-ref&quot;&gt;&lt;a href=&quot;#fn-2&quot; id=&quot;fn-2-ref-1&quot;&gt;2&lt;/a&gt;&lt;/sup&gt; The point has been understood for years. A dataset becomes useful at scale when somebody owns it and promises something about it.&lt;/p&gt;&lt;p&gt;A knowledge product is the same move applied to the messy half of the estate. Take a body of unstructured knowledge, give it an owner, wrap it in a contract, set a service level objective, and guarantee where every answer came from and how much we can trust that source. What was a folder of documents becomes something an agent can ground in and a person can trust.&lt;/p&gt;&lt;p&gt;That requires a mindset shift. Corporate knowledge is often managed as something to hoard, archive or search. A knowledge product treats it as something to curate for consumers: people, systems and agents with a job to do. The question is no longer “where should we store this?” but “who needs to rely on this, for what decision, and under what promise?”&lt;/p&gt;&lt;p&gt;Structured data is consumed by querying. You pose a precise question and get an exact answer, and when it is wrong it is wrong in a way you can point at: a figure that will not reconcile. Unstructured knowledge is consumed by grounding. You retrieve the passages that bear on a question and reason from them, and when it fails it fails softly, with an answer that reads well and rests on a paragraph superseded eighteen months ago. Each shape needs a product. They are not the same product.&lt;/p&gt;&lt;p&gt;The structured side took roughly a decade to make the leap, from datasets thrown over the wall to products with owners and contracts. The unstructured side is at the start of the same journey. We have been standing up vector stores for a while now, but almost always single-use ones: one corpus, one index, one application, built by whoever needed it and quietly abandoned when they moved on. That is the unstructured equivalent of the one-off dataset. It works for the job it was built for and compounds into nothing. The knowledge product is the same leap, made for knowledge and its potential future use cases.&lt;/p&gt;&lt;p&gt;We can apply the same proven design principles from the data product world to knowledge products, specifically following the DATSIS principles. A knowledge product is only as reliable as the discipline behind it. It must be:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Discoverable&lt;/strong&gt;, so consumers can find it in a central catalog.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Addressable&lt;/strong&gt;, reachable via unique identifiers and standardized interfaces.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Trustworthy&lt;/strong&gt;, with transparent quality checks, lineage and SLOs.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Self-describing&lt;/strong&gt;, carrying the metadata necessary for understanding.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Interoperable&lt;/strong&gt;, adhering to shared protocols for easy integration.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Secure&lt;/strong&gt;, with strictly enforced access controls.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;By baking these principles into the product specification, we move beyond simple file storage to a governed asset that agents and systems can reliably depend on.&lt;/p&gt;&lt;h2 id=&quot;what-a-knowledge-product-is-not&quot;&gt;What a knowledge product is not&lt;/h2&gt;&lt;p&gt;A knowledge product is not merely a knowledge base, although this is where the journey often starts. A knowledge base is storage. It will hold a decade of decayed wiki pages and tell you nothing about which are still true, which are authoritative, or who is accountable for their quality. Making that knowledge base useful and reusable is what sets it on the path to becoming a knowledge product. It needs an owner, a contract, metadata, freshness expectations and a way to act when the agent gets the wrong context at the wrong moment. Storage rots in silence. A product has someone whose job is to notice.&lt;/p&gt;&lt;p&gt;A knowledge product is not a single-use vector store. Standing one up does its one job, and the failure is not in building it but in mistaking it for a product. The index has no notion of which document is authoritative, which is retired, or who is allowed to see what. It answers every question with equal confidence and no accountability. The work of becoming a product is the curation, the metadata, and the contract that the one-off skips. It is the measuring and testing of value with potential consumers and customers-to-be.&lt;/p&gt;&lt;p&gt;Nor is a knowledge product sealed off from the structured side. The relationship runs both ways. Classify a stream of customer comments into positive and negative and what was a knowledge product is now feeding a data product. The two product types are twins in discipline, not strangers in practice. They feed each other constantly, and a mature estate is the one that has made that exchange deliberate instead of accidental.&lt;/p&gt;&lt;h2 id=&quot;what-a-knowledge-product-can-be&quot;&gt;What a knowledge product can be&lt;/h2&gt;&lt;p&gt;Knowledge products are not a single thing. They range from document collections to formal models of meaning, and a mature estate will usually run several at once.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;A retrieval index over a curated document collection.&lt;/strong&gt; The common case: keyword search, vector search and metadata filters over a deliberately chosen set of documents. Use all three rather than vectors alone, because exact tokens such as policy numbers, part codes and customer IDs are often what embeddings blur.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Enterprise search.&lt;/strong&gt; The same idea widened across many document collections behind one entry point. The hard parts are federation, ranking and access control: reconciling results and permissions from systems that were never designed to agree.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A glossary or data dictionary.&lt;/strong&gt; A product whose job is to say what a term means and which definition is canonical, so “monthly active user” has one meaning and not three. Cheap to build, high leverage.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A taxonomy or ontology.&lt;/strong&gt; A taxonomy classifies. An ontology adds rules about what an entity is and how it may relate to others. Before commissioning a new one, look for the ones the organisation has already built and shelved.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A knowledge graph.&lt;/strong&gt; Entities, typed relationships and a way to ask about both. This is where structured and unstructured knowledge join. Entity resolution alone often earns its keep before any full ontology does.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;A domain AI model.&lt;/strong&gt; A fine-tuned model, classifier, reranker, extraction model or specialist agent can embody knowledge about how to classify cases, recognise risk or apply policy. If other systems depend on that behaviour, it needs ownership, versioning, evaluation, scope and a retirement path.&lt;/li&gt;&lt;/ul&gt;&lt;h2 id=&quot;retrieval-contract&quot;&gt;The retrieval contract&lt;/h2&gt;&lt;p&gt;For structured data the contract is the semantic layer, the thing that fixes what revenue means so an agent chooses a definition rather than guessing one from column names. For unstructured knowledge the equivalent is the retrieval contract. Retrieval is approximate by its nature. The contract is what makes it precise about which source, which version, and as of when.&lt;/p&gt;&lt;p&gt;The contract is also a product interface. It has to work for both machine and human consumption: how systems query it, how people inspect it, how citations are followed, how uncertainty is shown, and what job the consumer is trying to get done.&lt;/p&gt;&lt;p&gt;A retrieval contract sets out:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;How documents are split into retrievable units.&lt;/strong&gt; A contract and a chat transcript do not chunk the same way, and the choice trades precision against context.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Which embedding model built the index, and the discipline for changing it.&lt;/strong&gt; A new model is a migration. Stand up a parallel index, evaluate it, then cut over.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;What metadata travels with each unit.&lt;/strong&gt; Authority, effective dates, what supersedes what, when it was last reviewed.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;What a citation points at.&lt;/strong&gt; A document, a section, a passage.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;What the product promises.&lt;/strong&gt; Retrieval precision, citation coverage, a bound on how stale an answer may be. This is impossible to define generically but very important to do specifically for each product.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Encode it and enforce it and the heap becomes a governed product. Leave it implicit and you have storage with a vector index bolted on.&lt;/p&gt;&lt;h2 id=&quot;ownership-and-governance&quot;&gt;Ownership and governance&lt;/h2&gt;&lt;p&gt;Most governance for a knowledge product belongs with the product. The platform can provide tooling centrally, but the decisions have to be made locally: which sources are authoritative, who may use them, how freshness is defined, and what happens when the product fails.&lt;/p&gt;&lt;p&gt;The first control is access. Permissions on the source must follow the content into the product and be enforced wherever that knowledge is consumed: search, reporting, automation, human workflows or agentic systems. Access should also be explicit for non-human consumers. A service, workflow or agent using the product needs scoped, auditable authority of its own, not accidental reach inherited from whatever integration happened to be convenient. Skip this and the knowledge product becomes a breach waiting to happen.&lt;/p&gt;&lt;p&gt;The second is authority. The product must know which version of a thing is current, which is retired, and who has the right to decide. Knowledge has a lifetime: policies expire, guidance is superseded, product claims change, and local exceptions stop being valid. Without explicit review and QA, a knowledge product slowly becomes a better-organised archive.&lt;/p&gt;&lt;p&gt;The third is lineage. Every answer should trace to the source, version, timestamp and retrieval that produced it, so the product can tell whether the agent is grounded in something current or something overdue for review. A knowledge product is not fixed once it is built. The policy behind a refund changes, the chemical lookup gets a new entry, the taxonomy picks up a node it did not have last quarter. Each change has a downstream impact on whatever was grounded in the old version, just as a schema change in a data product can break whatever queried it. A mature knowledge product tracks those dependencies and knows when a change should trigger review elsewhere, not just how to serve the latest version. This is the line between a system you can defend to a regulator and one you can only demo.&lt;/p&gt;&lt;h2 id=&quot;scoping-agent-dependencies&quot;&gt;Scoping an agent’s dependencies&lt;/h2&gt;&lt;p&gt;The range of knowledge products is most useful when it is applied backwards from a use case. Take what an agent is meant to do and ask what it depends on. An anti-money-laundering check on a split payment might need an operational product to confirm the transaction happened, a data product to confirm the threshold, and a knowledge product to confirm the current compliance policy and why it applies. Once a use case is broken down this way, you can audit what already exists against what is needed. Some dependencies will already be products. Some will be a folder no one has touched in two years. The gap between the two is the actual scope of the agent build, and it is a smaller and more honest scope than “connect an agent to everything we have.”&lt;/p&gt;&lt;p&gt;This is also how the estate becomes tractable. Instead of connecting an agent to “all company knowledge”, you slice the problem into domain-owned knowledge products with clear consumers and explicit links to neighbouring products. Done well, that reduces cognitive load, accelerates reuse and starts to form something like a digital twin of the organisation’s working knowledge.&lt;/p&gt;&lt;h2 id=&quot;why-build-them&quot;&gt;Why build them&lt;/h2&gt;&lt;p&gt;The argument for building knowledge products, rather than creating a generic assistant pointed at your files, is trust. This is an engineered property of the knowledge product. If the sources behind an answer are owned, curated, versioned and fresh, the user does not have to guess whether the agent found the right page. The product carries that burden. It tells the agent what is authoritative, what is retired, what is overdue for review, and where each answer came from. A knowledge product does not make an agent correct by itself. It makes the evidence current, inspectable and governed; the agent (or human) still has to reason correctly from it.&lt;/p&gt;&lt;p&gt;The second argument is that you keep the feedback loop. An agent working against your knowledge products is the best instrumentation you have ever had on their quality. The questions it fails to answer become a ranked backlog of what is missing, mis-tagged or out of date. The sources nobody ever retrieves are the ones to retire. A drop in retrieval precision after a change tells you the change broke something before a user does.&lt;/p&gt;&lt;p&gt;Like any product, a knowledge product has a lifecycle. It is built, enriched, tested, contextualised, released, monitored and retired. That lifecycle is increasingly AI-supported and AI-supportive: AI can help classify, link, summarise and test knowledge, while the resulting product gives AI something governed to depend on. This is where a folder becomes a domain-aligned asset, closer to “our proprietary pricing engine” than “some documents in SharePoint.” As a side effect, the actual current benefit for an organisation can also be framed as follows: a knowledge product for an agent is a thin slice to evolve an AI-enabled product development lifecycle.&lt;/p&gt;&lt;p&gt;Capture that signal and the estate improves as a by-product of being used. Each interaction leaves the next one a little better off. Organizations that wire up this loop pull steadily away from the ones that treat their knowledge as a static pile, and the gap compounds.&lt;/p&gt;&lt;h2 id=&quot;in-short&quot;&gt;In short&lt;/h2&gt;&lt;p&gt;For AI to do knowledge work, it needs knowledge products: document collections, glossaries, graphs, embedding models and specialist AI models with owners, contracts, permissions, authority, freshness, lineage and evidence of quality. A data product stops an agent inventing the numbers, a knowledge product stops it silently trusting the wrong source. Product thinking is what turns either one from a pile of data into something people and systems can depend on. Customer centricity is what helps you find out what part of the organisation’s IP might become a knowledge product.&lt;/p&gt;&lt;h2 id=&quot;acknowledgements&quot;&gt;Acknowledgements&lt;/h2&gt;&lt;p&gt;Big thanks to many of my Thoughtworks colleagues for their additions, questions and downright disagreement! Those who have made additions have been added as co-authors, but I would like to mention the following (in no particular order) for their discussions, comments and suggestions: Fabian Nonnenmacher, Moritz Wilke, Danilo Sato, Paola Attadio and Tim Harrison.&lt;/p&gt;</description>
				<link>https://benomahony.com/blog/knowledge-products/</link>
				<pubDate>Mon, 22 Jun 2026 00:00:00 +0000</pubDate>
				<guid>https://benomahony.com/blog/knowledge-products/</guid>
			</item>
		
			<item>
				<title>Does every feature we build with AI need a token budget?</title>
				<description>&lt;p&gt;This article is published on Thoughtworks Insights.&lt;/p&gt;</description>
				<link>https://www.thoughtworks.com/insights/blog/generative-ai/does-every-feature-build-ai-token-budget</link>
				<pubDate>Fri, 05 Jun 2026 00:00:00 +0000</pubDate>
				<guid>https://www.thoughtworks.com/insights/blog/generative-ai/does-every-feature-build-ai-token-budget</guid>
			</item>
		
			<item>
				<title>From API-First to API-Complete</title>
				<description>&lt;p&gt;API-first has been one of the most successful design philosophies in modern software. The idea is straightforward: define the interface before you build the implementation. Design the contract, agree on the shapes, then write the code behind it. It encourages loose coupling, parallel development, and clean boundaries between systems. Most mature engineering organisations have adopted it in some form, and it has worked well.&lt;/p&gt;&lt;p&gt;But API-first has always had an implicit constraint that we rarely talk about. It only applies to things that are already software.&lt;/p&gt;&lt;p&gt;The billing system got an API. The CRM got an API. The CI pipeline got an API. The authentication layer got an API. These were all systems with code behind them, and the discipline of API-first meant that code was accessed through a well-defined interface rather than through direct integration. Good practice, widely adopted.&lt;/p&gt;&lt;p&gt;Now consider a different kind of organisational capability: getting a contract reviewed by the legal team. In most enterprises, this process exists as a combination of email threads, shared drives, and the institutional knowledge of whoever has been on the team longest. There is no API. There is no interface at all. There is just the knowledge of how things get done, passed from person to person, and varying by office, by region, and by how recently someone joined.&lt;/p&gt;&lt;p&gt;Nobody ever thought to give this an API because it was not software. It was a human process, and human processes lived outside the API-first world. That was a reasonable boundary in 2015. It is not a reasonable boundary when the consumer of the interface is an AI agent acting on behalf of an employee.&lt;/p&gt;&lt;h2 id=&quot;agent-forces-the-question&quot;&gt;The agent forces the question&lt;/h2&gt;&lt;p&gt;When you build a customer-facing API, you can choose which capabilities to expose. You publish endpoints for the things you want external consumers to access and you leave everything else internal. The gaps in the API surface are deliberate. They are a feature.&lt;/p&gt;&lt;p&gt;When you build an AI agent that serves your own employees, the gaps are not a feature. They are the places where the agent says “I cannot help you with that” and the employee goes back to sending emails and hoping for the best. Every organisational capability that lacks a typed interface is invisible to the agent. And an agent that can only see half the organisation is an agent that employees will stop trusting very quickly.&lt;/p&gt;&lt;p&gt;This is the forcing function. API-first was a design philosophy you could adopt incrementally, system by system, as it made sense. An employee-facing AI agent demands the complete surface. It needs to be able to route any employee request to the right place, or at the very least say with confidence that no handler exists yet. It cannot do either of those things if most of the organisation has no interface at all.&lt;/p&gt;&lt;h2 id=&quot;api-complete&quot;&gt;API-complete&lt;/h2&gt;&lt;p&gt;I have started using the term API-complete to describe an organisation where every capability, whether it is fulfilled by software, by a human workflow, by an outsourced provider, or by an AI agent, is addressable through a typed interface with a stable contract.&lt;/p&gt;&lt;p&gt;This is not the same as saying everything must be automated. The handler behind the interface might be a Jira ticket that a person triages manually. It might be a SaaS integration. It might be an AI agent that the legal team deployed to handle contract risk classification. The protocol does not care. What matters is that the interface exists, that it has a known shape, and that its presence or absence is a matter of record rather than a matter of folklore.&lt;/p&gt;&lt;p&gt;The analogy I find useful is Turing-completeness. A system is Turing-complete when it can express any computation. An organisation is API-complete when every capability an employee might need is expressible as a typed request with a known route. You can measure the distance between where you are and where that bar sits. That measurement turns out to be extraordinarily valuable.&lt;/p&gt;&lt;h2 id=&quot;what-the-gap-report-tells-you&quot;&gt;What the gap report tells you&lt;/h2&gt;&lt;p&gt;When you define the full surface of what an employee might request, a category of work I think of as the employee intent taxonomy, you can hold the organisation against it and ask a simple question: what percentage of these intents have a registered handler?&lt;/p&gt;&lt;p&gt;An intent without a handler is not a failure of the system. It is the system telling you something true about your organisation that was previously invisible. It means “this process exists, it matters to employees, and the organisation currently has no machine-addressable way of fulfilling it.” Maybe the process lives in someone’s head. Maybe it lives in a wiki page that was last updated in 2019. Maybe it was never documented at all.&lt;/p&gt;&lt;p&gt;This gap report is the single most useful artefact an enterprise can produce before spending a penny on AI agents. It tells you where automation is possible today, where process discovery is needed first, and where the organisation has been relying on institutional knowledge that is one resignation away from disappearing.&lt;/p&gt;&lt;h2 id=&quot;taxonomy-is-the-universal-layer&quot;&gt;The taxonomy is the universal layer&lt;/h2&gt;&lt;p&gt;The interesting property of employee needs is that they are remarkably stable across organisations. Whether you are a bank, a hospital, or a retailer, your employees need to book leave, request equipment, raise grievances, submit expenses, get contracts reviewed, report safety concerns, declare conflicts of interest, and ask how things work. The specifics vary. The categories do not.&lt;/p&gt;&lt;p&gt;This suggests a two-layer architecture. The first layer is a universal taxonomy of employee intents, grouped by the nature of the request: time, money, growth, tools, space, safety, identity, resources, and knowledge. This layer is common across organisations and provides the base vocabulary.&lt;/p&gt;&lt;p&gt;The second layer is domain-specific. Legal adopts the standard and extends it: &lt;code&gt;RequestContractReview&lt;/code&gt; becomes an intake protocol with risk classification, clause analysis, and escalation paths. Engineering extends it: &lt;code&gt;RequestInfrastructure&lt;/code&gt; carries provisioning workflows with approval chains and cost controls. Each domain publishes its own extension of the protocol, describing what it offers, what it requires, and what it does not yet handle. The universal layer is the index. The domain layers are the organisation’s own.&lt;/p&gt;&lt;p&gt;This is the same layering pattern we see in successful standards. HTTP defines the universal semantics. Application protocols build on top. Neither layer dictates the other.&lt;/p&gt;&lt;h2 id=&quot;organisational-implementation-detail&quot;&gt;The organisational implementation detail&lt;/h2&gt;&lt;p&gt;One consequence of this architecture is that the org chart becomes an implementation detail of the protocol rather than a prerequisite for understanding it. An employee does not need to know that contract review is handled by Legal in London and by an outsourced firm in Singapore. They express an intent. The protocol routes it. The routing is configuration, not architecture.&lt;/p&gt;&lt;p&gt;This decoupling is not just convenient. It is essential for organisations that reorganise frequently, which is to say most of them. When the routing is configuration, a reorg means updating a routing table. When the routing is tribal knowledge, a reorg means six months of people not knowing who to ask.&lt;/p&gt;&lt;p&gt;Be aware that changing technology is already often difficult. Changing ways of working and how things are done is harder. Evolving an entire organisation and decision making is an even bigger effort.&lt;/p&gt;&lt;h2 id=&quot;evolution&quot;&gt;The evolution&lt;/h2&gt;&lt;p&gt;API-first said: define the interface before you write the code. This was good discipline and it improved how we build software systems.&lt;/p&gt;&lt;p&gt;API-complete says: every organisational capability gets a typed interface, not just the ones that are already software. The interface exists before the implementation, even if the first implementation is a human being triaging a ticket.&lt;/p&gt;&lt;p&gt;The shift is not merely philosophical. It is forced by a practical reality: AI agents need the full surface to be useful, and employees will not trust an agent that can only navigate half the organisation. The enterprise that reaches API-complete first will have an AI capability that its competitors cannot match, not because its models are better, but because its organisation is legible.&lt;/p&gt;</description>
				<link>https://benomahony.com/blog/api-first-to-api-complete/</link>
				<pubDate>Tue, 07 Apr 2026 00:00:00 +0000</pubDate>
				<guid>https://benomahony.com/blog/api-first-to-api-complete/</guid>
			</item>
		
			<item>
				<title>Hardening Codebases for Agentic Coding: 10 Essential Techniques</title>
				<description>&lt;p&gt;&lt;em&gt;How to make your codebase safe and effective for AI agents to work with&lt;/em&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This article practices what it preaches! All code examples are validated using pytest-examples in pre-commit hooks. See &lt;a href=&quot;https://github.com/benomahony/benomahony.com/blob/main/tests/test_blog_examples.py&quot;&gt;tests/test_blog_examples.py&lt;/a&gt; for how we ensure documentation stays accurate.&lt;/p&gt;&lt;/blockquote&gt;&lt;hr&gt;&lt;h2 id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;&lt;p&gt;AI coding agents like Claude Code, GitHub Copilot, and Cursor are transforming how we write software. But there’s a catch: &lt;strong&gt;not all codebases are ready for agentic development&lt;/strong&gt;. Without proper guardrails, AI agents can introduce bugs, violate architecture boundaries, or create unsafe code.&lt;/p&gt;&lt;p&gt;After building the &lt;a href=&quot;https://github.com/thoughtworks/Taxonomy-Ontology-Accelerator&quot;&gt;Taxonomy-Ontology-Accelerator&lt;/a&gt;, a production system designed from the ground up for agentic coding, I’ve identified 10 essential techniques that make codebases safe and effective for AI agents to work with.&lt;/p&gt;&lt;p&gt;This isn’t theoretical. These are battle-tested patterns from a codebase with:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;1,927 defensive assertions&lt;/strong&gt; catching impossible conditions (NASA05 compliance)&lt;/li&gt;&lt;li&gt;&lt;strong&gt;29,157 lines of test code&lt;/strong&gt; across 89 test files&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Property-based fuzzing&lt;/strong&gt; with Hypothesis (NASA/TIGER style)&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Architecture tests&lt;/strong&gt; preventing forbidden dependencies&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Mock detection&lt;/strong&gt; enforcing real implementations&lt;/li&gt;&lt;li&gt;&lt;strong&gt;CLI quality assurance&lt;/strong&gt; with automated validation&lt;/li&gt;&lt;li&gt;&lt;strong&gt;62% minimum test coverage&lt;/strong&gt; enforced in CI&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Let’s dive into what makes a codebase “agent-ready.”&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;type-safety&quot;&gt;1. Type Safety: Teaching Agents Your Data Contracts&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: AI agents need to understand what data looks like. Without type hints, agents guess, and guesses introduce bugs.&lt;/p&gt;&lt;h3 id=&quot;pydantic-models&quot;&gt;Pydantic Models as Single Source of Truth&lt;/h3&gt;&lt;p&gt;Instead of loose dictionaries, use Pydantic models with validation:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;pydantic&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;BaseModel&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;Field&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;field_validator&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ExtractedConcept&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;BaseModel&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;A concept extracted from text by an LLM agent.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;name&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Field&lt;/span&gt;(..., &lt;span class=&quot;constructor constant variable&quot;&gt;min_length&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;)
    &lt;span class=&quot;constructor constant variable&quot;&gt;concept_type&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;description&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;confidence&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Field&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;ge&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;0.0&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;le&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1.0&lt;/span&gt;)

    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;field_validator&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;concept_type&amp;quot;&lt;/span&gt;)
    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;classmethod&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;normalize_concept_type&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;cls&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;v&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;:
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;v&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;concept_type must not be None&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;v&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;str&lt;/span&gt;), &lt;span class=&quot;string&quot;&gt;&amp;quot;concept_type must be a string&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;v&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;strip&lt;/span&gt;().&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;lower&lt;/span&gt;()
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What this gives you&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;AI agents see the structure and constraints&lt;/li&gt;&lt;li&gt;Invalid data fails immediately with clear errors&lt;/li&gt;&lt;li&gt;Validators document business rules&lt;/li&gt;&lt;li&gt;&lt;code&gt;Field&lt;/code&gt; constraints prevent out-of-range values&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;typed-dict&quot;&gt;TypedDict for Structured State&lt;/h3&gt;&lt;p&gt;For data structures that don’t need validation logic, use &lt;code&gt;TypedDict&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typing&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;TypedDict&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;FileProcessingStatus&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;TypedDict&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Status tracking for file processing during extraction.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;has_failed_chunks&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;bool&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;processed_chunks&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;total_chunks&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agents understand the structure, type checkers validate usage, and you avoid the overhead of full models.&lt;/p&gt;&lt;h3 id=&quot;protocol-classes&quot;&gt;Protocol Classes for Dependency Injection&lt;/h3&gt;&lt;p&gt;Define interfaces with Protocol classes to enable testability without mocks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typing&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;Protocol&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;StageValidator&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;Protocol&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Protocol for validators that run between pipeline stages.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;validate&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;, &lt;span class=&quot;operator&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;kwargs&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;Any&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant type variable&quot;&gt;ValidationResult&lt;/span&gt;:
        &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Validate stage preconditions or outputs.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agents can implement new validators without touching existing code. Tests use fake implementations instead of mocks.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Type safety reduces agent errors by &lt;strong&gt;~40%&lt;/strong&gt; in our experience. Agents know what’s expected and the type checker catches mistakes before runtime.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;defensive-assertions&quot;&gt;2. Defensive Assertions: NASA-Grade Safety&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: AI agents make assumptions. Assertions catch wrong assumptions before they corrupt state.&lt;/p&gt;&lt;h3 id=&quot;nasa05-two-assertion-rule&quot;&gt;NASA05: The Two-Assertion Rule&lt;/h3&gt;&lt;p&gt;NASA’s Power of 10 rules for safety-critical code require &lt;strong&gt;minimum 2 assertions per function&lt;/strong&gt;. This catches:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Invalid parameters before processing&lt;/li&gt;&lt;li&gt;Broken invariants before they propagate&lt;/li&gt;&lt;li&gt;State corruption before it cascades&lt;/li&gt;&lt;/ul&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;add_error&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;error_type&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;message&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;severity&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;error&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;operator&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;kwargs&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;object&lt;/span&gt;,
) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Add an error to the collection.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# First assertion: parameter validation&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;error_type&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;error_type must not be None&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;error_type&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;str&lt;/span&gt;), &lt;span class=&quot;string&quot;&gt;&amp;quot;error_type must be a string&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;# Second assertion: state validation&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;_errors&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;list&lt;/span&gt;), &lt;span class=&quot;string&quot;&gt;&amp;quot;Internal errors must be a list&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;severity&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; {&lt;span class=&quot;string&quot;&gt;&amp;quot;error&amp;quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;warning&amp;quot;&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;info&amp;quot;&lt;/span&gt;}, &lt;span class=&quot;string&quot;&gt;f&amp;quot;Invalid severity: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;severity&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;error_dict&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; {
        &lt;span class=&quot;string&quot;&gt;&amp;quot;type&amp;quot;&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;error_type&lt;/span&gt;,
        &lt;span class=&quot;string&quot;&gt;&amp;quot;message&amp;quot;&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;message&lt;/span&gt;,
        &lt;span class=&quot;string&quot;&gt;&amp;quot;severity&amp;quot;&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;severity&lt;/span&gt;,
        &lt;span class=&quot;operator&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;kwargs&lt;/span&gt;,
    }

    &lt;span class=&quot;comment&quot;&gt;# Third assertion: output validation&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;error_dict&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;dict&lt;/span&gt;), &lt;span class=&quot;string&quot;&gt;&amp;quot;Error must be a dictionary&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;type&amp;quot;&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;error_dict&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;Error must have a type field&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;_errors&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;error_dict&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;what-to-assert&quot;&gt;What to Assert&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Always assert&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Parameters are not &lt;code&gt;None&lt;/code&gt; (unless explicitly &lt;code&gt;Optional&lt;/code&gt;)&lt;/li&gt;&lt;li&gt;Types are correct (&lt;code&gt;isinstance&lt;/code&gt; checks)&lt;/li&gt;&lt;li&gt;Numeric values are in valid ranges&lt;/li&gt;&lt;li&gt;Data structures have required keys&lt;/li&gt;&lt;li&gt;State invariants hold before critical operations&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Never assert&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;User input validation (use proper error handling)&lt;/li&gt;&lt;li&gt;Expected runtime errors (use try/except)&lt;/li&gt;&lt;li&gt;Business logic conditions (use if/else)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: The TOA codebase has &lt;strong&gt;1,927 assertions&lt;/strong&gt; that have caught hundreds of bugs during development. Without them, those bugs would have caused silent data corruption.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;property-based-fuzzing&quot;&gt;3. Property-Based Fuzzing: NASA/TIGER Style Testing&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Example-based tests only cover cases you think of. Property-based testing (fuzzing) generates thousands of random inputs to find edge cases agents might create.&lt;/p&gt;&lt;h3 id=&quot;hypothesis-generative-testing&quot;&gt;Hypothesis: Generative Testing for Functions&lt;/h3&gt;&lt;p&gt;Instead of writing individual test cases, define properties that should always hold:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;math&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;hypothesis&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;assume&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;given&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;hypothesis&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;strategies&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Define strategies for valid inputs&lt;/span&gt;
&lt;span class=&quot;constructor constant variable&quot;&gt;finite_floats&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;floats&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;min_value&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e10&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;max_value&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e10&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;allow_infinity&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constant_builtin&quot;&gt;False&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;allow_nan&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constant_builtin&quot;&gt;False&lt;/span&gt;,
)


&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;TestSafeDivide&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Property-based tests for safe_divide function.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;finite_floats&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;floats&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;min_value&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e-10&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;max_value&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e10&lt;/span&gt;))
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_division_reversibility&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;):
        &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Property: safe_divide(a*b, b) == a when b &amp;gt; 0.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;constructor constant variable&quot;&gt;product&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;assume&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;isfinite&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;product&lt;/span&gt;))
        &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;safe_divide&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;product&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;)
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;math&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;isclose&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;rel_tol&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e-9&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;abs_tol&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1e-9&lt;/span&gt;)

    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;numerator&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;finite_floats&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;denominator&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;finite_floats&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_non_positive_denominator_returns_default&lt;/span&gt;(
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;numerator&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;denominator&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;
    ):
        &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Property: safe_divide returns default when denominator &amp;lt;= 0.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;assume&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;denominator&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;)
        &lt;span class=&quot;constructor constant variable&quot;&gt;custom_default&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;42.0&lt;/span&gt;
        &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;safe_divide&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;numerator&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;denominator&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;custom_default&lt;/span&gt;)
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;custom_default&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What Hypothesis does&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Generates thousands of test inputs automatically&lt;/li&gt;&lt;li&gt;Finds edge cases you didn’t think of&lt;/li&gt;&lt;li&gt;Shrinks failing inputs to minimal examples&lt;/li&gt;&lt;li&gt;Pairs perfectly with assertions (NASA/TIGER style)&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;testing-profiles&quot;&gt;Multiple Testing Profiles&lt;/h3&gt;&lt;p&gt;Configure Hypothesis for different contexts:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;hypothesis&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;HealthCheck&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;Verbosity&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Configure profiles in conftest.py&lt;/span&gt;
&lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;register_profile&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;ci&amp;quot;&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;max_examples&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1000&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;verbosity&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;Verbosity&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;verbose&lt;/span&gt;)
&lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;register_profile&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;dev&amp;quot;&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;max_examples&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;100&lt;/span&gt;)
&lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;register_profile&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;debug&amp;quot;&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;max_examples&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;10&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;verbosity&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;Verbosity&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;verbose&lt;/span&gt;)
&lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;register_profile&lt;/span&gt;(
    &lt;span class=&quot;string&quot;&gt;&amp;quot;fast&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;max_examples&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;50&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;suppress_health_check&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;[&lt;span class=&quot;constructor constant variable&quot;&gt;HealthCheck&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;too_slow&lt;/span&gt;],
)

&lt;span class=&quot;comment&quot;&gt;# Load profile from environment&lt;/span&gt;
&lt;span class=&quot;constructor constant variable&quot;&gt;settings&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;load_profile&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;dev&amp;quot;&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Usage&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;dev&lt;/strong&gt;: 100 examples, fast feedback during development&lt;/li&gt;&lt;li&gt;&lt;strong&gt;ci&lt;/strong&gt;: 1,000 examples, thorough validation before merge&lt;/li&gt;&lt;li&gt;&lt;strong&gt;debug&lt;/strong&gt;: 10 examples with verbose output for investigating failures&lt;/li&gt;&lt;li&gt;&lt;strong&gt;fast&lt;/strong&gt;: 50 examples, skip slow checks for quick iterations&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;properties-to-test&quot;&gt;Properties to Test&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Mathematical properties&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;floats&lt;/span&gt;(), &lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;floats&lt;/span&gt;())
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_addition_commutative&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;a + b == b + a&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;add&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;add&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;b&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;a&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Idempotency&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;text&lt;/span&gt;())
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_normalization_idempotent&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;text&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;normalize(normalize(x)) == normalize(x)&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;once&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;normalize&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;text&lt;/span&gt;)
    &lt;span class=&quot;constructor constant variable&quot;&gt;twice&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;normalize&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;once&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;once&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;twice&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Invariants&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;lists&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;integers&lt;/span&gt;()))
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_sort_preserves_length&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;lst&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;len(sort(x)) == len(x)&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;sort&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;lst&lt;/span&gt;)) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;lst&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Round-trip properties&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;given&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;st&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;text&lt;/span&gt;())
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_encode_decode_roundtrip&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;text&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;decode(encode(x)) == x&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;decode&lt;/span&gt;(&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;encode&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;text&lt;/span&gt;)) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;text&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Hypothesis found &lt;strong&gt;~30 edge case bugs&lt;/strong&gt; in TOA that manual tests missed. The combination of property-based fuzzing + defensive assertions catches bugs that neither technique alone would find.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;comprehensive-testing&quot;&gt;4. Comprehensive Testing: Documentation That Runs&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Agents need to understand what code does and be confident their changes don’t break things.&lt;/p&gt;&lt;h3 id=&quot;test-documentation-examples&quot;&gt;Test Your Documentation Examples&lt;/h3&gt;&lt;p&gt;Use &lt;code&gt;pytest-examples&lt;/code&gt; to test code examples in docstrings and markdown:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# In conftest.py&lt;/span&gt;
&lt;span class=&quot;constructor constant variable&quot;&gt;pytest_plugins&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; [&lt;span class=&quot;string&quot;&gt;&amp;quot;pytest_examples&amp;quot;&lt;/span&gt;]


&lt;span class=&quot;comment&quot;&gt;# In test_doc_examples.py&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_readme_examples&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;README.md&amp;quot;&lt;/span&gt;):
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Ensure all code examples in README actually work.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;pytest_examples&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;process_file&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Documentation never goes stale&lt;/li&gt;&lt;li&gt;Agents see working examples&lt;/li&gt;&lt;li&gt;Examples serve as integration tests&lt;/li&gt;&lt;/ul&gt;&lt;h3 id=&quot;architecture-tests&quot;&gt;Architecture Tests: Enforce Boundaries with Code&lt;/h3&gt;&lt;p&gt;Prevent agents from violating architecture rules using executable tests:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;pathlib&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;Path&lt;/span&gt;

&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;pytest&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;get_imports_from_file&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;Path&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;set&lt;/span&gt;[&lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;]:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Extract all imports from a Python file using AST.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt;) &lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;:
        &lt;span class=&quot;constructor constant variable&quot;&gt;tree&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;parse&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;read&lt;/span&gt;())

    &lt;span class=&quot;constructor constant variable&quot;&gt;imports&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;set&lt;/span&gt;()
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;walk&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;tree&lt;/span&gt;):
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;Import&lt;/span&gt;):
            &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;names&lt;/span&gt;:
                &lt;span class=&quot;constructor constant variable&quot;&gt;imports&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;add&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;alias&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;name&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;split&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;.&amp;quot;&lt;/span&gt;)[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;])
        &lt;span class=&quot;keyword&quot;&gt;elif&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;ImportFrom&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;module&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;imports&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;add&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;module&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;split&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;.&amp;quot;&lt;/span&gt;)[&lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;])
    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;imports&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;check_no_cross_imports&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;source_package&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;Path&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;forbidden_package_name&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;,
) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;list&lt;/span&gt;[&lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;]:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Check that source_package doesn&amp;apos;t import from forbidden_package_name.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;py_file&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;source_package&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;rglob&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;*.py&amp;quot;&lt;/span&gt;):
        &lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;py_file&lt;/span&gt;) &lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;content&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;read&lt;/span&gt;()

        &lt;span class=&quot;comment&quot;&gt;# Check for forbidden imports&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;f&amp;quot;from &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;forbidden_package_name&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;content&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;f&amp;quot;&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;py_file&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;: imports from &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;forbidden_package_name&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;)
        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;f&amp;quot;import &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;forbidden_package_name&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;content&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;f&amp;quot;&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;py_file&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;: imports &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;forbidden_package_name&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;


&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;pytest&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;mark&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;architecture&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_commons_does_not_import_engines&lt;/span&gt;():
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Commons module should NOT import from any engine.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;commons_dir&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/commons&amp;quot;&lt;/span&gt;)

    &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []
    &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;check_no_cross_imports&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;commons_dir&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;engine_a&amp;quot;&lt;/span&gt;))
    &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;check_no_cross_imports&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;commons_dir&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;engine_b&amp;quot;&lt;/span&gt;))

    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; (
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    ), &lt;span class=&quot;string&quot;&gt;&amp;quot;Commons should not import from engines:&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;join&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;)


&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;pytest&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;mark&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;architecture&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_no_wildcard_imports&lt;/span&gt;():
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Main code should not use wildcard imports (from x import *).&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []
    &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;py_file&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/src&amp;quot;&lt;/span&gt;).&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;rglob&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;*.py&amp;quot;&lt;/span&gt;):
        &lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;open&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;py_file&lt;/span&gt;) &lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;tree&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;parse&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;f&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;read&lt;/span&gt;())

        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;walk&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;tree&lt;/span&gt;):
            &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;ast&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;ImportFrom&lt;/span&gt;):
                &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;alias&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;node&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;names&lt;/span&gt;:
                    &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;alias&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;*&amp;quot;&lt;/span&gt;:
                        &lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;str&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;py_file&lt;/span&gt;))

    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;violations&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;Found wildcard imports&amp;quot;&lt;/span&gt;


&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;pytest&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;mark&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;constructor property constant variable function&quot;&gt;architecture&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_expected_directory_structure&lt;/span&gt;():
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Verify the expected directory structure exists.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;expected_dirs&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; [
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/commons&amp;quot;&lt;/span&gt;),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/engine_a&amp;quot;&lt;/span&gt;),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/engine_a/core&amp;quot;&lt;/span&gt;),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Path&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject/engine_a/config&amp;quot;&lt;/span&gt;),
    ]

    &lt;span class=&quot;constructor constant variable&quot;&gt;missing&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; [&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;str&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;d&lt;/span&gt;) &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;d&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;expected_dirs&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;d&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;exists&lt;/span&gt;()]
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;missing&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;f&amp;quot;Missing expected directories: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;missing&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What architecture tests enforce&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;strong&gt;Layer boundaries&lt;/strong&gt;: Commons can’t import from engines&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Import hygiene&lt;/strong&gt;: No wildcard imports&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Structural rules&lt;/strong&gt;: Required directories exist&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Naming conventions&lt;/strong&gt;: Test files only in tests/&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Module independence&lt;/strong&gt;: Engines don’t cross-import&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Run separately with markers&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# Run only architecture tests&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;pytest&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;architecture&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Run everything except architecture tests&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;pytest&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;-m&lt;/span&gt; &lt;span class=&quot;string constant&quot;&gt;&amp;quot;not architecture&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Architecture tests caught &lt;strong&gt;~15 boundary violations&lt;/strong&gt; during development. Agents can’t accidentally create circular dependencies or violate layer rules.&lt;/p&gt;&lt;h3 id=&quot;test-markers&quot;&gt;Test Markers: Speed vs Thoroughness&lt;/h3&gt;&lt;p&gt;Organize tests by speed and scope:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# pytest.ini / pyproject.toml&lt;/span&gt;
[&lt;span class=&quot;constructor constant variable&quot;&gt;tool&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;pytest&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;ini_options&lt;/span&gt;]
&lt;span class=&quot;constructor constant variable&quot;&gt;markers&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; [
    &lt;span class=&quot;string&quot;&gt;&amp;quot;unit: Fast unit tests (&amp;lt; 100ms)&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&amp;quot;integration: Slower integration tests requiring APIs&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&amp;quot;architecture: Architectural boundary tests&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&amp;quot;examples: Tests from documentation examples&amp;quot;&lt;/span&gt;,
]
&lt;span class=&quot;constructor constant variable&quot;&gt;addopts&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; [
    &lt;span class=&quot;string&quot;&gt;&amp;quot;-m&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&amp;quot;not integration&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;comment&quot;&gt;# Skip integration tests by default&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;&amp;quot;--ff&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;comment&quot;&gt;# Run failures first&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;&amp;quot;-n&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;string&quot;&gt;&amp;quot;auto&amp;quot;&lt;/span&gt;,  &lt;span class=&quot;comment&quot;&gt;# Parallel execution&lt;/span&gt;
]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Fast feedback for agents: run unit tests in &lt;1 second, integration tests only in CI.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: &lt;strong&gt;29,157 lines of test code&lt;/strong&gt; provide a safety net. Agents can refactor confidently, knowing tests catch regressions.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;pre-commit-quality-gates&quot;&gt;5. Pre-Commit Quality Gates: Fail Fast, Fail Local&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Agents generate code fast. Quality gates catch issues before they reach CI or production.&lt;/p&gt;&lt;h3 id=&quot;essential-pre-commit-stack&quot;&gt;The Essential Pre-Commit Stack&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;yaml&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# .pre-commit-config.yaml&lt;/span&gt;
&lt;span class=&quot;string property&quot;&gt;repos&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;comment&quot;&gt;# 1. Format and lint&lt;/span&gt;
  &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;repo&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;local&lt;/span&gt;
    &lt;span class=&quot;string property&quot;&gt;hooks&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;ruff-format&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;ruff format&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run ruff format&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;ruff-check&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;ruff check&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run ruff check --fix&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 2. Type checking&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;basedpyright&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;basedpyright&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run basedpyright&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;pass_filenames&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;boolean&quot;&gt;false&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 3. Dead code detection&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;vulture&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;vulture&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run vulture --min-confidence 80&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 4. Security scanning&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;bandit&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;bandit&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run bandit -c pyproject.toml&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 5. Dependency auditing&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;deptry&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;deptry&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run deptry .&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;pass_filenames&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;boolean&quot;&gt;false&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 6. Mock detection (CRITICAL)&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;mockbuster&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;mockbuster&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run mockbuster&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;types&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;python&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 7. CLI quality assurance&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;cliqa&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;cliqa&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run cliqa analyze myapp&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;^.*cli\.py$&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;pass_filenames&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;boolean&quot;&gt;false&lt;/span&gt;

      &lt;span class=&quot;comment&quot;&gt;# 8. Documentation example tests&lt;/span&gt;
      &lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;runbook-examples&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;runbook examples&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run pytest docs/RUNBOOK.md --examples-only&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
        &lt;span class=&quot;string property&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;^docs/RUNBOOK\.md$&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;why-each-hook-matters&quot;&gt;Why Each Hook Matters&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;ruff&lt;/strong&gt;: Format and lint in one pass. Agents follow consistent style.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;basedpyright&lt;/strong&gt;: Type checking catches type errors before runtime.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;vulture&lt;/strong&gt;: Detects unused code. Prevents dead code accumulation.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;bandit&lt;/strong&gt;: Security scanning. Prevents &lt;code&gt;eval()&lt;/code&gt;, unsafe &lt;code&gt;yaml.load()&lt;/code&gt;, etc.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;deptry&lt;/strong&gt;: Dependency health. Catches unused imports and missing dependencies.&lt;/li&gt;&lt;li&gt;&lt;strong&gt;mockbuster&lt;/strong&gt;: Prevents mock usage. Enforces real implementations (see below).&lt;/li&gt;&lt;li&gt;&lt;strong&gt;cliqa&lt;/strong&gt;: CLI quality assurance. Validates CLI help text, examples, commands (see below).&lt;/li&gt;&lt;li&gt;&lt;strong&gt;runbook examples&lt;/strong&gt;: Documentation stays up-to-date.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Configuration tip&lt;/strong&gt;: Configure tools in &lt;code&gt;pyproject.toml&lt;/code&gt; for single source of truth:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;toml&quot;&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;tool&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;ruff&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;line-length&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;100&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;target-version&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;py313&amp;quot;&lt;/span&gt;

&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;tool&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;ruff&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;lint&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;select&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;E&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;W&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;F&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;I&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;B&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;UP&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;SIM&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;PT&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;ignore&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;E501&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;  &lt;span class=&quot;comment&quot;&gt;# Line too long (handled by formatter)&lt;/span&gt;

&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;tool&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;basedpyright&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;typeCheckingMode&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;basic&amp;quot;&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;reportMissingImports&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;error&amp;quot;&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;reportUndefinedVariable&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;error&amp;quot;&lt;/span&gt;

&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;tool&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;bandit&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;exclude_dirs&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;tests/&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;scripts/&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;skips&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;B101&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;B404&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;B603&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;tool&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;property&quot;&gt;vulture&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;min_confidence&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;80&lt;/span&gt;
&lt;span class=&quot;property&quot;&gt;paths&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;punctuation_bracket&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;myproject&amp;quot;&lt;/span&gt;&lt;span class=&quot;punctuation_bracket&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Pre-commit hooks catch &lt;strong&gt;~80% of issues&lt;/strong&gt; before CI, giving agents instant feedback.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;mock-detection&quot;&gt;6. Mock Detection: Enforce Real Implementations&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Mocks hide bugs. Tests with mocks pass even when real code is broken. Agents should use real implementations or test doubles.&lt;/p&gt;&lt;h3 id=&quot;mockbuster&quot;&gt;mockbuster: Detect and Prevent Mock Usage&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# BAD: Using mocks (will be caught by mockbuster)&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;unittest&lt;/span&gt;.&lt;span class=&quot;constructor constant variable&quot;&gt;mock&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;Mock&lt;/span&gt;


&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_with_mock&lt;/span&gt;():
    &lt;span class=&quot;constructor constant variable&quot;&gt;mock_api&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Mock&lt;/span&gt;()
    &lt;span class=&quot;constructor constant variable&quot;&gt;mock_api&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;get_data&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;return_value&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; {&lt;span class=&quot;string&quot;&gt;&amp;quot;key&amp;quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;}
    &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;process&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;mock_api&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;


&lt;span class=&quot;comment&quot;&gt;# GOOD: Using dependency injection with real test implementation&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;FakeAPI&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Test double that implements the real API interface.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;__init__&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;calls&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []

    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;get_data&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;calls&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;get_data&amp;quot;&lt;/span&gt;)
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; {&lt;span class=&quot;string&quot;&gt;&amp;quot;key&amp;quot;&lt;/span&gt;: &lt;span class=&quot;string&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;}


&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_with_real_implementation&lt;/span&gt;():
    &lt;span class=&quot;constructor constant variable&quot;&gt;fake_api&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;FakeAPI&lt;/span&gt;()
    &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;process&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;fake_api&lt;/span&gt;)
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;value&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;&amp;quot;get_data&amp;quot;&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;fake_api&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;calls&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;allowed-exceptions&quot;&gt;Allowed Exceptions&lt;/h3&gt;&lt;p&gt;Sometimes mocks are necessary (CLI testing, system calls). Use inline comments:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;test_cli_with_system_interaction&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;monkeypatch&lt;/span&gt;):  &lt;span class=&quot;comment&quot;&gt;# mockbuster: ignore - testing CLI&lt;/span&gt;
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Test CLI without actually calling the system.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;monkeypatch&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;setattr&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;sys&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;exit&amp;quot;&lt;/span&gt;, &lt;span class=&quot;keyword&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;code&lt;/span&gt;: &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;)
    &lt;span class=&quot;comment&quot;&gt;# CLI test code...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What mockbuster enforces&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;No &lt;code&gt;unittest.mock.Mock&lt;/code&gt; or &lt;code&gt;unittest.mock.MagicMock&lt;/code&gt;&lt;/li&gt;&lt;li&gt;No &lt;code&gt;unittest.mock.patch&lt;/code&gt; or &lt;code&gt;@patch&lt;/code&gt; decorators&lt;/li&gt;&lt;li&gt;No &lt;code&gt;pytest.monkeypatch&lt;/code&gt; (unless explicitly allowed)&lt;/li&gt;&lt;li&gt;Forces dependency injection patterns&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: &lt;strong&gt;Zero production bugs&lt;/strong&gt; from mocked test dependencies. Tests use real implementations, catching integration issues early.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;cli-quality-assurance&quot;&gt;7. CLI Quality Assurance: Validate Command Interfaces&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: CLI commands are the interface agents use. Broken help text or missing examples make CLIs unusable for agents.&lt;/p&gt;&lt;h3 id=&quot;cliqa&quot;&gt;cliqa: Automated CLI Validation&lt;/h3&gt;&lt;p&gt;&lt;code&gt;cliqa&lt;/code&gt; validates that your Typer CLI follows best practices:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typer&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Create the app with examples in docstring for cliqa&lt;/span&gt;
&lt;span class=&quot;constructor constant variable&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typer&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;Typer&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;myapp&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;My Application CLI&amp;quot;&lt;/span&gt;,
    &lt;span class=&quot;constructor constant variable&quot;&gt;epilog&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Examples:&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;  myapp process path/to/data&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;  myapp info path/to/data&amp;quot;&lt;/span&gt;,
)


&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;variable constructor property constant function_method function&quot;&gt;command&lt;/span&gt;&lt;span class=&quot;function&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;process&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;data_path&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;Path&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typer&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;Argument&lt;/span&gt;(
        ...,
        &lt;span class=&quot;constructor constant variable&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Path to data directory containing input files&amp;quot;&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;exists&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constant_builtin&quot;&gt;True&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;file_okay&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constant_builtin&quot;&gt;False&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;dir_okay&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constant_builtin&quot;&gt;True&lt;/span&gt;,
    ),
    &lt;span class=&quot;constructor constant variable&quot;&gt;verbose&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;typer&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;Option&lt;/span&gt;(
        &lt;span class=&quot;constant_builtin&quot;&gt;False&lt;/span&gt;,
        &lt;span class=&quot;string&quot;&gt;&amp;quot;--verbose&amp;quot;&lt;/span&gt;,
        &lt;span class=&quot;string&quot;&gt;&amp;quot;-v&amp;quot;&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;Enable verbose output&amp;quot;&lt;/span&gt;,
    ),
) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;
    Process data from input files.

    Processes all files in the data directory
    and generates outputs.

    Examples:
        myapp process data/my_project
        myapp process data/my_project --verbose
    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# Implementation...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What cliqa validates&lt;/strong&gt;:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Help text exists&lt;/strong&gt;: Every command and option has help text&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Examples provided&lt;/strong&gt;: Commands include usage examples&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Argument descriptions&lt;/strong&gt;: All arguments documented&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Type hints present&lt;/strong&gt;: All parameters have type annotations&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Consistent naming&lt;/strong&gt;: Commands follow kebab-case convention&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Pre-commit integration&lt;/strong&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;yaml&quot;&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;string property&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;cliqa&lt;/span&gt;
  &lt;span class=&quot;string property&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;cliqa&lt;/span&gt;
  &lt;span class=&quot;string property&quot;&gt;entry&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;uv run cliqa analyze myapp&lt;/span&gt;
  &lt;span class=&quot;string property&quot;&gt;language&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;system&lt;/span&gt;
  &lt;span class=&quot;string property&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;^.*cli\.py$&lt;/span&gt;
  &lt;span class=&quot;string property&quot;&gt;pass_filenames&lt;/span&gt;&lt;span class=&quot;punctuation_delimiter&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;boolean&quot;&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: &lt;strong&gt;100% of CLI commands&lt;/strong&gt; have examples and documentation. Agents can discover and use commands correctly without guessing.&lt;/p&gt;&lt;h3 id=&quot;cli-agent-debugging-interface&quot;&gt;CLIs as Agent Debugging Interface&lt;/h3&gt;&lt;p&gt;&lt;strong&gt;Critical insight&lt;/strong&gt;: CLIs aren’t just for users. They’re how agents explore, test, and debug your codebase.&lt;/p&gt;&lt;p&gt;When an agent encounters an error or needs to understand behavior, they can:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# Discover available commands&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--help&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Run processing on a small test case&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test_data/&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--verbose&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Check configuration&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;show&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Validate outputs&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;validate&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;output/&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Run health checks&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;health&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Why this matters&lt;/strong&gt;:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Reproducibility&lt;/strong&gt;: Agents can reproduce issues in isolation&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# Instead of: &amp;quot;The processing is failing somewhere&amp;quot;&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;# Agents run: myapp process problematic_case/ --verbose&lt;/span&gt;
&lt;span class=&quot;comment&quot;&gt;# Get exact error with full context&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Incremental testing&lt;/strong&gt;: Test components independently&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# Test just the validation step&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;validate-config&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;config.yaml&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Test just data transformation&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;transform&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;input.json&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--dry-run&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Test just the connection&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test-connection&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;State inspection&lt;/strong&gt;: Examine system state at any point&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# Check what would be processed&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;list&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test_data/&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Show current configuration&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;show&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# Display processing statistics&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;stats&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Hypothesis generation&lt;/strong&gt;: Quickly test theories about bugs&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# &amp;quot;Maybe it&amp;apos;s the batch size?&amp;quot;&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--batch-size&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;10&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--batch-size&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;50&lt;/span&gt;

&lt;span class=&quot;comment&quot;&gt;# &amp;quot;Maybe it&amp;apos;s a specific file?&amp;quot;&lt;/span&gt;
&lt;span class=&quot;constant function&quot;&gt;myapp&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;process&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;test&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;--only&lt;/span&gt; &lt;span class=&quot;constant&quot;&gt;file1.json&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Design principle&lt;/strong&gt;: Every major component should have a CLI command. If an agent can’t invoke it from the command line, they can’t debug it effectively.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Example pattern&lt;/strong&gt;: Break your pipeline into discrete CLI commands:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;code&gt;myapp process&lt;/code&gt; - Full processing pipeline&lt;/li&gt;&lt;li&gt;&lt;code&gt;myapp transform&lt;/code&gt; - Just data transformation&lt;/li&gt;&lt;li&gt;&lt;code&gt;myapp validate&lt;/code&gt; - Just validation&lt;/li&gt;&lt;li&gt;&lt;code&gt;myapp config&lt;/code&gt; - Configuration management&lt;/li&gt;&lt;li&gt;&lt;code&gt;myapp health&lt;/code&gt; - System health check&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;This granularity lets agents isolate issues to specific stages without diving into code.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;modular-architecture&quot;&gt;8. Modular Architecture: Enforced Separation&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Agents need clear boundaries. Without them, they create spaghetti code.&lt;/p&gt;&lt;h3 id=&quot;layer-architecture&quot;&gt;Layer Architecture with Enforcement&lt;/h3&gt;&lt;pre&gt;&lt;code&gt;myproject/
├── commons/              # Shared utilities (no engine imports)
│   ├── config/          # Configuration loaders
│   ├── io/              # File I/O abstraction
│   ├── errors.py        # Error collection
│   └── utils/           # Logging, helpers
├── engine_a/            # Processing engine A
│   ├── config/          # Engine configuration
│   ├── core/            # Main processing logic
│   ├── transforms/      # Data transformations
│   └── storage/         # File management
└── engine_b/            # Processing engine B
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Enforced rules&lt;/strong&gt;:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;code&gt;commons/&lt;/code&gt; cannot import from engines&lt;/li&gt;&lt;li&gt;Engines are independent&lt;/li&gt;&lt;li&gt;Architecture tests fail if rules violated&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;dependency-injection&quot;&gt;Dependency Injection for Testability&lt;/h3&gt;&lt;p&gt;Make code testable without mocks:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;comment&quot;&gt;# BAD: Hard to test without mocks&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;OntologyExtractor&lt;/span&gt;:
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;__init__&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;agent&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Agent&lt;/span&gt;()  &lt;span class=&quot;comment&quot;&gt;# Hard dependency&lt;/span&gt;
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;db&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Neo4jConnection&lt;/span&gt;()  &lt;span class=&quot;comment&quot;&gt;# Hard dependency&lt;/span&gt;


&lt;span class=&quot;comment&quot;&gt;# GOOD: Easy to test with real test implementations&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;OntologyExtractor&lt;/span&gt;:
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;__init__&lt;/span&gt;(
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;agent&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;Agent&lt;/span&gt;[&lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;constructor constant type variable&quot;&gt;ExtractionResult&lt;/span&gt;],
        &lt;span class=&quot;constructor constant variable&quot;&gt;storage&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;StorageProtocol&lt;/span&gt;,
    ):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;agent&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;agent&lt;/span&gt;  &lt;span class=&quot;comment&quot;&gt;# Injected&lt;/span&gt;
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;storage&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;storage&lt;/span&gt;  &lt;span class=&quot;comment&quot;&gt;# Injected&lt;/span&gt;


&lt;span class=&quot;comment&quot;&gt;# Test with real implementation&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;FakeStorage&lt;/span&gt;:
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;__init__&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;stored_items&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []

    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;save&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;item&lt;/span&gt;):
        &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;stored_items&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;item&lt;/span&gt;)
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agents understand interfaces. Tests use real fakes, not mocks.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: Clear architecture prevents &lt;strong&gt;75% of coupling issues&lt;/strong&gt;. Agents understand boundaries and tests enforce them.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;documentation-as-code&quot;&gt;9. Documentation as Code: Contracts and Runbooks&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Agents need to understand system contracts. Comments go stale; executable contracts don’t.&lt;/p&gt;&lt;h3 id=&quot;contract-specifications&quot;&gt;Contract Specifications&lt;/h3&gt;&lt;p&gt;Document input/output structures in versioned files:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;markdown&quot;&gt;&lt;span class=&quot;punctuation_special&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Extraction Input Contract&lt;/span&gt;

&lt;span class=&quot;punctuation_special&quot;&gt;##&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;File Structure&lt;/span&gt;

Files must follow this structure:

&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`domain_name/`
&lt;span class=&quot;punctuation_special&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`config.yaml` - Configuration overrides
&lt;span class=&quot;punctuation_special&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`inputs/` - Input text files
&lt;span class=&quot;punctuation_special&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`file1.txt`
&lt;span class=&quot;punctuation_special&quot;&gt;    &lt;/span&gt;&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`file2.md`
&lt;span class=&quot;punctuation_special&quot;&gt;  &lt;/span&gt;&lt;span class=&quot;punctuation_special&quot;&gt;- &lt;/span&gt;`outputs/` - Generated outputs (created by system)

&lt;span class=&quot;punctuation_special&quot;&gt;##&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Configuration Schema&lt;/span&gt;

&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;yaml
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;llm:
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  model_name: &amp;quot;gemini-2.0-flash-001&amp;quot;  # KnownModelName from pydantic-ai
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  temperature: 0.7                     # Range: 0.0-2.0
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  max_tokens: 8192                     # Minimum: 100
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;extraction:
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  chunk_size: 4000                     # Range: 100-100000
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  chunk_overlap: 200                   # Minimum: 0
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  batch_size: 10                       # Range: 1-100
&lt;/span&gt;&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;punctuation_special&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Output Contract&lt;/span&gt;

&lt;span class=&quot;punctuation_special&quot;&gt;##&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Graph Structure (JSON)&lt;/span&gt;

&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;json
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;{
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  &amp;quot;nodes&amp;quot;: [
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;    {
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;id&amp;quot;: &amp;quot;concept_1&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;type&amp;quot;: &amp;quot;concept&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;properties&amp;quot;: {
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;        &amp;quot;name&amp;quot;: &amp;quot;Machine Learning&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;        &amp;quot;description&amp;quot;: &amp;quot;...&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;        &amp;quot;concept_type&amp;quot;: &amp;quot;technology&amp;quot;
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      }
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;    }
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  ],
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  &amp;quot;edges&amp;quot;: [
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;    {
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;source&amp;quot;: &amp;quot;concept_1&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;target&amp;quot;: &amp;quot;concept_2&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;type&amp;quot;: &amp;quot;relates_to&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      &amp;quot;properties&amp;quot;: {
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;        &amp;quot;relationship_type&amp;quot;: &amp;quot;uses&amp;quot;,
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;        &amp;quot;confidence&amp;quot;: 0.85
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;      }
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;    }
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;  ]
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;}
&lt;/span&gt;&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;
&lt;/span&gt;
Agents can read contracts and generate conforming code.
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;executable-runbooks&quot;&gt;Executable Runbooks&lt;/h3&gt;&lt;p&gt;Write runbooks as executable code:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;markdown&quot;&gt;&lt;span class=&quot;punctuation_special&quot;&gt;#&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Processing Runbook&lt;/span&gt;

&lt;span class=&quot;punctuation_special&quot;&gt;##&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Process data from source&lt;/span&gt;

&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;python
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;from myproject import process_data
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;result = await process_data(data_path=&amp;quot;data/my_dataset&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;print(f&amp;quot;Processed {result.items_count} items&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;
&lt;/span&gt;
&lt;span class=&quot;punctuation_special&quot;&gt;##&lt;/span&gt; &lt;span class=&quot;text_title&quot;&gt;Check processing metrics&lt;/span&gt;

&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;python
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;# Continuing from previous example
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;print(f&amp;quot;Files processed: {result.files_processed}&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;print(f&amp;quot;Files failed: {len(result.failed_files)}&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;print(f&amp;quot;Total items: {result.items_count}&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal none&quot;&gt;print(f&amp;quot;Total errors: {len(result.errors)}&amp;quot;)
&lt;/span&gt;&lt;span class=&quot;text_literal punctuation_delimiter&quot;&gt;```&lt;/span&gt;&lt;span class=&quot;text_literal&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Test the runbook with &lt;code&gt;pytest --examples-only docs/RUNBOOK.md&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: &lt;strong&gt;Zero stale documentation&lt;/strong&gt;. Contracts are tested, runbooks are executable.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;observability&quot;&gt;10. Observability: Rich Logging and Progress&lt;/h2&gt;&lt;p&gt;&lt;strong&gt;Why it matters&lt;/strong&gt;: Agents need feedback. Good observability helps agents and humans debug.&lt;/p&gt;&lt;h3 id=&quot;rich-console-logging&quot;&gt;Rich Console Logging&lt;/h3&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;rich&lt;/span&gt;.&lt;span class=&quot;constructor constant variable&quot;&gt;console&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;Console&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;rich&lt;/span&gt;.&lt;span class=&quot;constructor constant variable&quot;&gt;panel&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;Panel&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;rich&lt;/span&gt;.&lt;span class=&quot;constructor constant variable&quot;&gt;progress&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;BarColumn&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;Progress&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;SpinnerColumn&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;TextColumn&lt;/span&gt;

&lt;span class=&quot;constructor constant variable&quot;&gt;console&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Console&lt;/span&gt;()


&lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;log_extraction_start&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;domain&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;str&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;file_count&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Log extraction start with formatted output.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;domain&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;domain must not be None&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;file_count&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;file_count must be positive&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;console&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;print&lt;/span&gt;(
        &lt;span class=&quot;constructor constant variable&quot;&gt;Panel&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;fit&lt;/span&gt;(
            &lt;span class=&quot;string&quot;&gt;f&amp;quot;[bold blue]Starting extraction[/bold blue]&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;
            &lt;span class=&quot;string&quot;&gt;f&amp;quot;Domain: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;domain&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string escape&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;
            &lt;span class=&quot;string&quot;&gt;f&amp;quot;Files: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;file_count&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;,
            &lt;span class=&quot;constructor constant variable&quot;&gt;border_style&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;blue&amp;quot;&lt;/span&gt;,
        )
    )


&lt;span class=&quot;keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;process_with_progress&lt;/span&gt;(
    &lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;list&lt;/span&gt;[&lt;span class=&quot;constructor constant type variable&quot;&gt;Path&lt;/span&gt;],
) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;list&lt;/span&gt;[&lt;span class=&quot;constructor constant type variable&quot;&gt;ExtractionResult&lt;/span&gt;]:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Process files with progress bar.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;files must not be None&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;files must not be empty&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; []

    &lt;span class=&quot;keyword&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;Progress&lt;/span&gt;(
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;SpinnerColumn&lt;/span&gt;(),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;TextColumn&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;[progress.description]{task.description}&amp;quot;&lt;/span&gt;),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;BarColumn&lt;/span&gt;(),
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;TextColumn&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;[progress.percentage]{task.percentage:&amp;gt;3.0f}%&amp;quot;&lt;/span&gt;),
        &lt;span class=&quot;constructor constant variable&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;console&lt;/span&gt;,
    ) &lt;span class=&quot;keyword&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;progress&lt;/span&gt;:
        &lt;span class=&quot;constructor constant variable&quot;&gt;task&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;progress&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;add_task&lt;/span&gt;(&lt;span class=&quot;string&quot;&gt;&amp;quot;Processing files&amp;quot;&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;total&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt;))

        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt;:
            &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;extract_from_file&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;file_path&lt;/span&gt;)
            &lt;span class=&quot;constructor constant variable&quot;&gt;results&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;append&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt;)
            &lt;span class=&quot;constructor constant variable&quot;&gt;progress&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;update&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;task&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;advance&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;number&quot;&gt;1&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;results&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;structured-metrics&quot;&gt;Structured Metrics&lt;/h3&gt;&lt;p&gt;Track metrics for debugging and optimization:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;dataclass&lt;/span&gt;
&lt;span class=&quot;keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;ExtractionMetrics&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Metrics tracked during extraction.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;start_time&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;end_time&lt;/span&gt;: &lt;span class=&quot;constructor constant variable&quot;&gt;float&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;files_processed&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;files_failed&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;chunks_processed&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;concepts_extracted&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;relationships_extracted&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;

    &lt;span class=&quot;constructor constant variable&quot;&gt;llm_calls&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;llm_tokens_input&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;llm_tokens_output&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;

    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;property&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;duration_seconds&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;:
        &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Calculate total duration.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;start_time&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;start_time must be set&amp;quot;&lt;/span&gt;

        &lt;span class=&quot;constructor constant variable&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;or&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;time&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;time&lt;/span&gt;()
        &lt;span class=&quot;constructor constant variable&quot;&gt;duration&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;end&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;start_time&lt;/span&gt;

        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;duration&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;duration must be non-negative&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;duration&lt;/span&gt;

    &lt;span class=&quot;function&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;constructor constant variable function&quot;&gt;property&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;throughput_files_per_second&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant type variable&quot;&gt;float&lt;/span&gt;:
        &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;Calculate file processing throughput.&amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;files_processed&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;files_processed must be non-negative&amp;quot;&lt;/span&gt;

        &lt;span class=&quot;keyword&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;duration_seconds&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0&lt;/span&gt;:
            &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;0.0&lt;/span&gt;

        &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;files_processed&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;self&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;duration_seconds&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Benefits&lt;/strong&gt;:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Beautiful progress output&lt;/li&gt;&lt;li&gt;Structured metrics for analysis&lt;/li&gt;&lt;li&gt;Easy debugging&lt;/li&gt;&lt;li&gt;Performance optimization data&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&lt;strong&gt;Impact&lt;/strong&gt;: &lt;strong&gt;10x faster debugging&lt;/strong&gt;. Clear feedback helps agents and humans understand what’s happening.&lt;/p&gt;&lt;hr&gt;&lt;h2 id=&quot;putting-it-all-together&quot;&gt;Putting It All Together&lt;/h2&gt;&lt;p&gt;Here’s how these 10 techniques work together in a real extraction pipeline:&lt;/p&gt;&lt;pre&gt;&lt;code class=&quot;python&quot;&gt;&lt;span class=&quot;keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;constructor constant variable function&quot;&gt;process_pipeline&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;data_path&lt;/span&gt;: &lt;span class=&quot;constructor constant type variable&quot;&gt;Path&lt;/span&gt;) &lt;span class=&quot;operator&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;constructor constant type variable&quot;&gt;PipelineOutput&lt;/span&gt;:
    &lt;span class=&quot;string&quot;&gt;&amp;quot;&amp;quot;&amp;quot;
    Process data pipeline with full hardening.

    Demonstrates all 10 techniques:
    1. Type safety: Pydantic models
    2. Defensive assertions: 2+ per function (NASA05)
    3. Property-based fuzzing: Hypothesis for edge cases
    4. Comprehensive testing: pytest markers, doc tests, arch tests
    5. Pre-commit gates: enforced quality
    6. Mock detection: real implementations only
    7. CLI quality: validated with cliqa
    8. Modular architecture: dependency injection
    9. Documentation: contracts and runbooks
    10. Observability: rich logging and metrics
    &amp;quot;&amp;quot;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;comment&quot;&gt;# Defensive assertions (Technique 2)&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;constant_builtin&quot;&gt;None&lt;/span&gt;, &lt;span class=&quot;string&quot;&gt;&amp;quot;domain_path must not be None&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;exists&lt;/span&gt;(), &lt;span class=&quot;string&quot;&gt;f&amp;quot;domain_path must exist: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;domain_path&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;
    &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;is_dir&lt;/span&gt;(), &lt;span class=&quot;string&quot;&gt;f&amp;quot;domain_path must be directory: &lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;string embedded constructor constant variable&quot;&gt;domain_path&lt;/span&gt;&lt;span class=&quot;string embedded punctuation_special&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;&amp;quot;&lt;/span&gt;

    &lt;span class=&quot;comment&quot;&gt;# Structured configuration (Technique 6)&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;config&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;load_config&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;)

    &lt;span class=&quot;comment&quot;&gt;# State management (Technique 8)&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;ExtractionState&lt;/span&gt;(
        &lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;config&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;ErrorCollector&lt;/span&gt;(),
        &lt;span class=&quot;constructor constant variable&quot;&gt;metrics&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;ExtractionMetrics&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;start_time&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;time&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;time&lt;/span&gt;()),
    )

    &lt;span class=&quot;comment&quot;&gt;# Observability (Technique 10)&lt;/span&gt;
    &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;log_extraction_start&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;name&lt;/span&gt;, &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;len&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;files&lt;/span&gt;))

    &lt;span class=&quot;comment&quot;&gt;# Modular architecture with DI (Technique 5)&lt;/span&gt;
    &lt;span class=&quot;constructor constant variable&quot;&gt;agent&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;create_extraction_agent&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;config&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;llm&lt;/span&gt;)
    &lt;span class=&quot;constructor constant variable&quot;&gt;storage&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;create_storage&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;domain_path&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;try&lt;/span&gt;:
        &lt;span class=&quot;comment&quot;&gt;# Error collection (Technique 7)&lt;/span&gt;
        &lt;span class=&quot;constructor constant variable&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;process_with_error_collection&lt;/span&gt;(
            &lt;span class=&quot;constructor constant variable&quot;&gt;files&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;files&lt;/span&gt;,
            &lt;span class=&quot;constructor constant variable&quot;&gt;agent&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;agent&lt;/span&gt;,
            &lt;span class=&quot;constructor constant variable&quot;&gt;collector&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;errors&lt;/span&gt;,
        )

        &lt;span class=&quot;comment&quot;&gt;# Type safety (Technique 1)&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;results&lt;/span&gt;:
            &lt;span class=&quot;keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;isinstance&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;ExtractionResult&lt;/span&gt;), &lt;span class=&quot;string&quot;&gt;&amp;quot;Must be ExtractionResult&amp;quot;&lt;/span&gt;
            &lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;concepts&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;concepts&lt;/span&gt;)
            &lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;relationships&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;extend&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;result&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;relationships&lt;/span&gt;)

        &lt;span class=&quot;comment&quot;&gt;# Save outputs (contracts from Technique 9)&lt;/span&gt;
        &lt;span class=&quot;keyword&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;storage&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;save_graph&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;concepts&lt;/span&gt;, &lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;relationships&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;finally&lt;/span&gt;:
        &lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;metrics&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;end_time&lt;/span&gt; &lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;constructor constant variable&quot;&gt;time&lt;/span&gt;.&lt;span class=&quot;constructor property constant function_method variable&quot;&gt;time&lt;/span&gt;()
        &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;log_extraction_complete&lt;/span&gt;(&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;metrics&lt;/span&gt;)

    &lt;span class=&quot;keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;constructor function_builtin constant variable function&quot;&gt;OntologyOutput&lt;/span&gt;(
        &lt;span class=&quot;constructor constant variable&quot;&gt;concepts&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;concepts&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;relationships&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;relationships&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;metrics&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;metrics&lt;/span&gt;,
        &lt;span class=&quot;constructor constant variable&quot;&gt;errors&lt;/span&gt;&lt;span class=&quot;operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;constructor constant variable&quot;&gt;state&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;errors&lt;/span&gt;.&lt;span class=&quot;constructor property constant variable&quot;&gt;errors&lt;/span&gt;,
    )
&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;&lt;h2 id=&quot;measuring-success&quot;&gt;Measuring Success: Before and After&lt;/h2&gt;&lt;p&gt;Here’s what changed in the Taxonomy-Ontology-Accelerator after implementing these techniques:&lt;/p&gt;&lt;table&gt;&lt;tr&gt;&lt;th&gt;Metric&lt;/th&gt;&lt;th&gt;Before&lt;/th&gt;&lt;th&gt;After&lt;/th&gt;&lt;th&gt;Improvement&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Agent-introduced bugs&lt;/td&gt;&lt;td&gt;~15/week&lt;/td&gt;&lt;td&gt;~2/week&lt;/td&gt;&lt;td&gt;&lt;strong&gt;87% reduction&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Edge case bugs found&lt;/td&gt;&lt;td&gt;~5 (manual)&lt;/td&gt;&lt;td&gt;~35 (Hypothesis)&lt;/td&gt;&lt;td&gt;&lt;strong&gt;7x more found&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Time to debug issues&lt;/td&gt;&lt;td&gt;~2 hours&lt;/td&gt;&lt;td&gt;~15 minutes&lt;/td&gt;&lt;td&gt;&lt;strong&gt;88% faster&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Test coverage&lt;/td&gt;&lt;td&gt;45%&lt;/td&gt;&lt;td&gt;62%&lt;/td&gt;&lt;td&gt;&lt;strong&gt;+37%&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CI pass rate&lt;/td&gt;&lt;td&gt;78%&lt;/td&gt;&lt;td&gt;96%&lt;/td&gt;&lt;td&gt;&lt;strong&gt;+23%&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Architecture violations&lt;/td&gt;&lt;td&gt;~8/week&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;strong&gt;100% reduction&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Mock-related prod bugs&lt;/td&gt;&lt;td&gt;2/month&lt;/td&gt;&lt;td&gt;0/6 months&lt;/td&gt;&lt;td&gt;&lt;strong&gt;100% reduction&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;CLI usage errors&lt;/td&gt;&lt;td&gt;~10/month&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;&lt;strong&gt;100% reduction&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;Production incidents&lt;/td&gt;&lt;td&gt;3/month&lt;/td&gt;&lt;td&gt;0/3 months&lt;/td&gt;&lt;td&gt;&lt;strong&gt;100% reduction&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;hr&gt;&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started: Your Action Plan&lt;/h2&gt;&lt;p&gt;You don’t need to implement all 10 techniques at once. Start with the highest-impact changes:&lt;/p&gt;&lt;h3 id=&quot;week-1&quot;&gt;Week 1: Quick Wins (Critical Foundation)&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;Add &lt;strong&gt;pre-commit hooks&lt;/strong&gt; (ruff + basedpyright)&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;NASA05 assertions&lt;/strong&gt; (2+ per function)&lt;/li&gt;&lt;li&gt;Enable &lt;strong&gt;pytest coverage&lt;/strong&gt; reporting&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;mockbuster&lt;/strong&gt; to prevent mock usage&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;week-2&quot;&gt;Week 2: Type Safety &amp; Testing&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;Convert config to &lt;strong&gt;Pydantic models&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;type hints&lt;/strong&gt; to public APIs&lt;/li&gt;&lt;li&gt;Create &lt;strong&gt;Protocol classes&lt;/strong&gt; for interfaces&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;Hypothesis&lt;/strong&gt; property-based tests for critical functions&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;week-3&quot;&gt;Week 3: Architecture &amp; Quality Gates&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;Add &lt;strong&gt;architecture tests&lt;/strong&gt; for layer boundaries&lt;/li&gt;&lt;li&gt;Implement &lt;strong&gt;dependency injection&lt;/strong&gt; in main classes&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;cliqa&lt;/strong&gt; for CLI validation&lt;/li&gt;&lt;/ol&gt;&lt;h3 id=&quot;week-4&quot;&gt;Week 4: Documentation &amp; Observability&lt;/h3&gt;&lt;ol&gt;&lt;li&gt;Write &lt;strong&gt;contract specifications&lt;/strong&gt; for inputs/outputs&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;executable runbook&lt;/strong&gt; examples&lt;/li&gt;&lt;li&gt;Test documentation with &lt;strong&gt;pytest-examples&lt;/strong&gt;&lt;/li&gt;&lt;li&gt;Add &lt;strong&gt;Rich logging&lt;/strong&gt; with progress bars&lt;/li&gt;&lt;/ol&gt;&lt;hr&gt;&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;&lt;p&gt;Making codebases ready for agentic coding isn’t about preventing AI from working with your code. It’s about &lt;strong&gt;enabling AI to work safely and effectively&lt;/strong&gt;.&lt;/p&gt;&lt;p&gt;The 10 techniques described here create a &lt;strong&gt;multi-layered safety net&lt;/strong&gt; that catches mistakes before they reach production:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;strong&gt;Type safety&lt;/strong&gt; guides agents to correct usage&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Defensive assertions&lt;/strong&gt; catch wrong assumptions (NASA05)&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Property-based fuzzing&lt;/strong&gt; finds edge cases (NASA/TIGER style)&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Comprehensive testing&lt;/strong&gt; prevents regressions&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Pre-commit gates&lt;/strong&gt; fail fast locally&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Mock detection&lt;/strong&gt; enforces real implementations&lt;/li&gt;&lt;li&gt;&lt;strong&gt;CLI quality assurance&lt;/strong&gt; validates command interfaces&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Modular architecture&lt;/strong&gt; enforces boundaries&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Documentation as code&lt;/strong&gt; stays current&lt;/li&gt;&lt;li&gt;&lt;strong&gt;Observability&lt;/strong&gt; enables debugging&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;These aren’t theoretical ideas. They’re battle-tested patterns from a production system that AI agents work with daily.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Start small&lt;/strong&gt;. Pick one technique, implement it, measure the impact. Then add the next one.&lt;/p&gt;&lt;p&gt;The most impactful combo: &lt;strong&gt;NASA05 assertions + Hypothesis fuzzing + mockbuster&lt;/strong&gt; gives you 80% of the value with 20% of the effort.&lt;/p&gt;&lt;p&gt;Your future self (and your AI coding agent) will thank you.&lt;/p&gt;&lt;hr&gt;&lt;p&gt;&lt;em&gt;Have questions or want to share your own hardening techniques? Reach out on &lt;a href=&quot;https://github.com/benomahony&quot;&gt;GitHub&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;</description>
				<link>https://benomahony.com/blog/hardening-codebases-for-agentic-coding/</link>
				<pubDate>Wed, 11 Feb 2026 00:00:00 +0000</pubDate>
				<guid>https://benomahony.com/blog/hardening-codebases-for-agentic-coding/</guid>
			</item>
		
			<item>
				<title>Building your own CLI Coding Agent with Pydantic-AI</title>
				<description>&lt;p&gt;This article is published on MartinFowler.com.&lt;/p&gt;</description>
				<link>https://martinfowler.com/articles/build-own-coding-agent.html</link>
				<pubDate>Wed, 27 Aug 2025 00:00:00 +0000</pubDate>
				<guid>https://martinfowler.com/articles/build-own-coding-agent.html</guid>
			</item>
		
	</channel>
</rss>
