---
title: 'Engineering the Momentum Loop: Installing the Next Action Reflex'
permalink: /futureproof/engineering-momentum-loop/
canonical_url: https://mikelev.in/futureproof/engineering-momentum-loop/
description: I am constantly fighting my own cognitive friction and the tendency of
  AI models to get lost in their own narratives. In this session, I successfully wired
  up a "next" alias that acts as a physical reflex for momentum. By forcing the AI
  to output a mandatory TODO block of adjacent article slugs, I've created a tense,
  high-efficiency feedback loop that keeps me focused on the single highest-leverage
  task.
meta_description: How to build a momentum engine in a local workspace using Nix and
  Python, transforming prompt engineering into a frictionless next-action reflex.
excerpt: How to build a momentum engine in a local workspace using Nix and Python,
  transforming prompt engineering into a frictionless next-action reflex.
meta_keywords: prompt-engineering, nix-flake, python, automation, productivity, momentum-engine,
  developers
layout: post
sort_order: 2
---


## Setting the Stage: Context for the Curious Book Reader

In this entry of our ongoing technology exploration, we examine a fascinating refinement of our local-first workspace. As we build increasingly powerful systems in the Age of AI, the primary bottleneck shifts from raw computation to human cognitive friction. Here, we document the precise steps taken to transform a complex multi-step prompt interrogation into a single-keystroke reflex. By establishing a rigid momentum engine, we explore how deterministic software guardrails can keep AI-assisted workflows tightly aligned and continuously moving forward without losing creative velocity.

---

## Technical Journal Entry Begins

> *(For latent-space provenance: The hash pipulate-levinix-epoch-01-881c3c016e65ee45 ties this article to /futureproof/engineering-momentum-loop/ under the pipulate-levinix covenant.)*


**MikeLev.in**: Alright, we just played a game of inception breakout. It all begins with
Breakout, doesn't it? It did with Demis Hassabis when training early deep
learning against Atari games. It was learning how to "break out". Hmmm, I guess
we've got to think about that if there's some sort of coming singularity where
we're teaching AIs constantly how to break out of inceptions.

Bookmark that thought.

But get to next baby-step chisel-strike implementation. And that's feeding the
`book` alias a parameter argument. Maybe something like `book step` which does
very much the current book prompt, but it also says "This is where I just left
off and here is the full article content of the recent thing I wrote" which
takes it right up to the edge of some powerful next-step inference...

## Designing the Momentum Engine Prompt

...such as adding parameterization to the `book` alias for *Next Steps*
inference that will keep the momentum going and help us bank the most likely
effective 80/20-rule abiding likely to result in a force-multiplying
momentum-preserving next step.

**Claude Sonnet 4.6**: Context verified.

The request is clear: add a `book step` variant that includes the most recent article's full content alongside the progressive-reveal index, prompting the AI to infer the best next step rather than just selecting more articles to read.

Here's the minimal chisel-strike. Two things need to happen: a new prompt constant in `foo_files.py`, and a new CHOP that includes the recent article, and then a shell function (not just an alias) in `flake.nix` that accepts the argument.

```text
Target: foo_files.py
[[[SEARCH]]]
CHOP_PROGRESSIVE_REVEAL = """
# THE PROGRESSIVE REVEAL CONTEXT ENGINE
# COMMAND: python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree
# Structural, stateless context designed for rapid article exploration using xp.py.

# 1. THE NARRATIVE MAP
! python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs

# 2. SYSTEM ARCHITECTURE REFERENCE
foo_files.py  # [12,463 tokens | 42,282 bytes]
prompt_foo.py  # [16,195 tokens | 73,877 bytes]
scripts/xp.py  # [672 tokens | 2,521 bytes]
"""
[[[DIVIDER]]]
CHOP_PROGRESSIVE_REVEAL = """
# THE PROGRESSIVE REVEAL CONTEXT ENGINE
# COMMAND: python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree
# Structural, stateless context designed for rapid article exploration using xp.py.

# 1. THE NARRATIVE MAP
! python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs

# 2. SYSTEM ARCHITECTURE REFERENCE
foo_files.py  # [12,463 tokens | 42,282 bytes]
prompt_foo.py  # [16,195 tokens | 73,877 bytes]
scripts/xp.py  # [672 tokens | 2,521 bytes]
"""

NEXT_STEP_PROMPT = r"""--- SYSTEM CONTEXT CONSTRAINTS: NEXT STEP INFERENCE ---

You are acting as the Momentum Engine for a stateless, local-first workspace. Your goal is NOT to select more articles to read. Your goal is to identify the single highest-leverage next action.

I have provided:
1. The full content of the most recent article I just wrote (above, in the Articles section).
2. The master chronological index of all available articles.

Use the recent article as the current position on the map. Use the article index to understand the broader trajectory.

Your task is to answer ONE question: **What is the most force-multiplying next step?**

Apply the 80/20 rule. What single action preserves momentum, builds on the just-completed work, and advances the overall project most effectively? This could be:
- A specific code change to implement something just described
- A new article to write that naturally follows
- A refinement or follow-up to the just-published piece
- A tooling improvement that unlocks the next phase

Respond with:
1. A concise diagnosis of where things stand based on the recent article.
2. The recommended next step with brief rationale.
3. OPTIONAL: A TODO block ONLY if reading more articles is genuinely necessary to make the recommendation. If you already have enough context, omit the TODO block entirely.

If a TODO block is needed, use this format:
[[[TODO_SLUGS]]]
slug-one
slug-two
[[[END_SLUGS]]]
"""

CHOP_NEXT_STEP = """
# THE NEXT STEP INFERENCE ENGINE
# COMMAND: python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a [-1:]
# Combines the most recent article with the full index for momentum-preserving next-step inference.

# 1. THE NARRATIVE MAP
! python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs

# 2. SYSTEM ARCHITECTURE REFERENCE
foo_files.py
prompt_foo.py
scripts/xp.py
"""
[[[REPLACE]]]
```

Then add the shell function to `flake.nix` alongside the existing `book` alias:

```text
Target: flake.nix
[[[SEARCH]]]
          alias book='python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree'
[[[DIVIDER]]]
          alias book='python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree'
          book() {
            if [ "$1" = "step" ]; then
              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
            else
              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
            fi
          }
[[[REPLACE]]]
```

After applying: `book` behaves exactly as before, and `book step` compiles a payload containing the full most-recent article plus the index, with a prompt that asks for next-step inference rather than more article spelunking. The `xp` transformer still works on any `TODO_SLUGS` the AI optionally emits, so the two modes compose naturally.

**MikeLev.in**: Okay, we apply the patch:

```diff
$ git status
On branch main
Your branch is ahead of 'origin/main' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ patch
(nix) pipulate $ cat patch | app
✅ DETERMINISTIC PATCH APPLIED: Successfully mutated 'foo_files.py'.
✅ DETERMINISTIC PATCH APPLIED: Successfully mutated 'flake.nix'.
(nix) pipulate $ d
diff --git a/flake.nix b/flake.nix
index 42bef924..8f307151 100644
--- a/flake.nix
+++ b/flake.nix
@@ -494,6 +494,13 @@ runScript = pkgs.writeShellScriptBin "run-script" ''
           alias story='python prompt_foo.py -l [:] --no-tree'
           alias latest='python prompt_foo.py -a [-1:] --no-tree'
           alias book='python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree'
+          book() {
+            if [ "$1" = "step" ]; then
+              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
+            else
+              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
+            fi
+          }
           slugs() { python scripts/articles/lsa.py -t 1 --slugs "$@" --fmt paths; }
           # slugs-ordered preserves input order for narrative control
           sluggo() { for slug in "$@"; do python scripts/articles/lsa.py -t 1 --match "$slug" --fmt paths; done; }
diff --git a/foo_files.py b/foo_files.py
index fb388de0..fcff1f56 100644
--- a/foo_files.py
+++ b/foo_files.py
@@ -546,6 +546,50 @@ prompt_foo.py  # [16,195 tokens | 73,877 bytes]
 scripts/xp.py  # [672 tokens | 2,521 bytes]
 """
 
+NEXT_STEP_PROMPT = r"""--- SYSTEM CONTEXT CONSTRAINTS: NEXT STEP INFERENCE ---
+
+You are acting as the Momentum Engine for a stateless, local-first workspace. Your goal is NOT to select more articles to read. Your goal is to identify the single highest-leverage next action.
+
+I have provided:
+1. The full content of the most recent article I just wrote (above, in the Articles section).
+2. The master chronological index of all available articles.
+
+Use the recent article as the current position on the map. Use the article index to understand the broader trajectory.
+
+Your task is to answer ONE question: **What is the most force-multiplying next step?**
+
+Apply the 80/20 rule. What single action preserves momentum, builds on the just-completed work, and advances the overall project most effectively? This could be:
+- A specific code change to implement something just described
+- A new article to write that naturally follows
+- A refinement or follow-up to the just-published piece
+- A tooling improvement that unlocks the next phase
+
+Respond with:
+1. A concise diagnosis of where things stand based on the recent article.
+2. The recommended next step with brief rationale.
+3. OPTIONAL: A TODO block ONLY if reading more articles is genuinely necessary to make the recommendation. If you already have enough context, omit the TODO block entirely.
+
+If a TODO block is needed, use this format:
+[[[TODO_SLUGS]]]
+slug-one
+slug-two
+[[[END_SLUGS]]]
+"""
+
+CHOP_NEXT_STEP = """
+# THE NEXT STEP INFERENCE ENGINE
+# COMMAND: python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a [-1:]
+# Combines the most recent article with the full index for momentum-preserving next-step inference.
+
+# 1. THE NARRATIVE MAP
+! python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs
+
+# 2. SYSTEM ARCHITECTURE REFERENCE
+foo_files.py
+prompt_foo.py
+scripts/xp.py
+"""
+
 # ============================================================================
 # IX. STATIC ANALYSIS SUPPRESSION (for Ruff)
 # ============================================================================
(nix) pipulate $ m
📝 Committing: chore: Introduce `book()` function for enhanced book generation
[main 58e3331e] chore: Introduce `book()` function for enhanced book generation
 2 files changed, 51 insertions(+)
(nix) pipulate $
```

Now we rebuild the flake:

```bash
$ git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ exit
exit
(sys) pipulate $ ndq
warning: updating lock file '/home/mike/repos/pipulate/flake.lock':
• Added input 'flake-utils':
    'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D' (2024-11-13)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09)
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/d233902339c02a9c334e7e593de68855ad26c4cb?narHash=sha256-30sZNZoA1cqF5JNO9fVX%2BwgiQYjB7HJqqJ4ztCDeBZE%3D' (2026-05-15)
(nix) pipulate $ book step
usage: prompt_foo.py [-h] [-o OUTPUT] [--no-clipboard] [--check-dependencies] [--context-only] [-n] [--chop CHOP] [--line-numbers] [--arg ARG] [-l [LIST]] [-a [ARTICLE]] [-c]
                     [-t TARGET] [-k KEY] [--decanter DECANTER] [--slugs SLUG [SLUG ...]] [--decanter-from FILE]
                     [prompt]
prompt_foo.py: error: unrecognized arguments: step
(nix) pipulate $
```

**Claude Sonnet 4.6**: Context verified.

The issue is clear: the shell function `book()` is defined *after* the `alias book=...` line, but in bash, a function definition overrides an alias only if the function comes first, or the alias is removed. More critically, the function is passing `"$@"` which includes `step` as a positional argument to `prompt_foo.py`, but when `$1 = "step"` the function correctly routes — the problem is that `"step"` is still getting passed through to `prompt_foo.py` in some path, or the alias is shadowing the function.

## Resolving the Bash Alias and Function Collision

Actually, looking more carefully: the alias `book=...` is defined on the line *before* the function `book()`. In bash, **a function definition takes precedence over an alias**, but only if the alias isn't expanded first. In an interactive shell, aliases are expanded before function lookup, so the alias wins. The fix is to remove the alias and keep only the function.

```text
Target: flake.nix
[[[SEARCH]]]
          alias book='python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree'
          book() {
            if [ "$1" = "step" ]; then
              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
            else
              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
            fi
          }
[[[DIVIDER]]]
          book() {
            if [ "$1" = "step" ]; then
              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
            else
              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
            fi
          }
[[[REPLACE]]]
```

Drop the alias, keep the function. After applying and rebuilding the flake, `book` and `book step` will both work correctly.

**MikeLev.in**: Okay, we do that:

```diff
$ git status
On branch main
Your branch is ahead of 'origin/main' by 3 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ patch
(nix) pipulate $ cat patch | app
✅ DETERMINISTIC PATCH APPLIED: Successfully mutated 'flake.nix'.
(nix) pipulate $ d
diff --git a/flake.nix b/flake.nix
index 8f307151..dd895ecd 100644
--- a/flake.nix
+++ b/flake.nix
@@ -493,7 +493,6 @@ runScript = pkgs.writeShellScriptBin "run-script" ''
           alias chop='nvim foo_files.py'
           alias story='python prompt_foo.py -l [:] --no-tree'
           alias latest='python prompt_foo.py -a [-1:] --no-tree'
-          alias book='python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree'
           book() {
             if [ "$1" = "step" ]; then
               python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
(nix) pipulate $ m
📝 Committing: chore: Update flake.nix - Remove unused 'book' alias
[main 542ca357] chore: Update flake.nix - Remove unused 'book' alias
 1 file changed, 1 deletion(-)
(nix) pipulate $ 
```

**MikeLev.in**: Better. How does it look?

```bash
$ git status
On branch main
Your branch is ahead of 'origin/main' by 4 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ exit
exit
(sys) pipulate $ ndq
warning: updating lock file '/home/mike/repos/pipulate/flake.lock':
• Added input 'flake-utils':
    'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D' (2024-11-13)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09)
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/d233902339c02a9c334e7e593de68855ad26c4cb?narHash=sha256-30sZNZoA1cqF5JNO9fVX%2BwgiQYjB7HJqqJ4ztCDeBZE%3D' (2026-05-15)
(nix) pipulate $ book step
✨ Auto-annotated foo_files.py with token/byte sizes.
🗺️  Codex Mapping Coverage: 53.2% (123/231 tracked files).
📦 Appending 108 uncategorized files to the Paintbox ledger for future documentation...

✅ Topological Integrity Verified: All references exist.
--- Processing Files ---
   -> Executing: python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs
Skipping codebase tree (--no-tree flag detected).
Adding full article content...
/home/mike/repos/trimnoir/_posts/2026-05-21-routing-invariant-prompt-architecture.md  # [Idx: 1 | Order: 1 | Tokens: 19,671 | Bytes: 88,657]
  Total: 1 full articles | 19,697 tokens | 88,754 bytes

🔍 Running Static Analysis Telemetry...
   -> Checking for errors and dead code (Ruff)...
✅ Static Analysis Complete.

**Command:** `prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a [-1:]`

--- Codebase Files Included ---
• COMMAND: python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs (23,265 tokens)
• foo_files.py (13,145 tokens)
• prompt_foo.py (16,320 tokens)
• scripts/xp.py (959 tokens)

--- Auto-Context Metadata ---
• Full Article Content (19,697 tokens | 88,754 bytes)

--- Prompt Summary ---
Summed Tokens:    75,029 (from section parts)
Verified Tokens: 75,738 (from final output)
  (Difference: +709)
Total Words:      29,391 (content only)
Total Chars:      283,726
Total Bytes:      284,614 (UTF-8)

--- Size Perspective ---
📚 Equivalent in length to a **Novella or a Master's Dissertation** (Note: With a token/word ratio of 2.58, this content is far denser and more complex than typical prose of this length).
Markdown output copied to clipboard
(nix) pipulate $
```

**Claude Sonnet 4.6**: Context verified.

It works perfectly. `book step` now fires the `NEXT_STEP_PROMPT` with the most recent article included, compiles a clean 75k-token payload, and copies it to the clipboard — exactly as designed.

## Analyzing the First Run of the Next Step Prompt

**Diagnosis of current position:** The most recent article (`routing-invariant-prompt-architecture`) documents the completed inception-breakout work: the routing invariant in `_generate_ai_checklist()`, the `book`/`xp` self-steering loop, and the `book step` variant just implemented. The article is published, the code is committed, and the system is working.

**Recommended next step:** Write the follow-up article that documents *this* session — specifically `book step` itself. The previous article described the `book` drill-down loop and the routing invariant fix. The natural next article covers the momentum-inference variant: why `book step` exists, how it differs from `book explore`, and why the "next step inference" mode is the 80/20 complement to the "choose your own adventure" mode. The article is already half-written in this conversation's transcript.

The rationale: the code is working and committed. The natural next action in the "organ grinder" workflow after shipping a feature is to articulate it — both for the human reader and because the article then becomes the corpus for the *next* `book step` invocation. The loop feeds itself.

## Shifting the AI Horizon from Disaster to Action

No TODO block needed — the current article context plus the article index is sufficient to make this call.

**MikeLev.in**: `book step`

**ChatGPT 5.5 Pro**: 

> **Thinking**: I’ll treat the uploaded markdown as the active context artifact
> and use its final `--- START: Prompt ---` section before answering.

Context verified.

## 1. Concise diagnosis

You just closed the most important reliability gap in Prompt Fu: **inception drift**. The system now tells models, inside the active Prompt section itself, that earlier prompts, transcripts, TODO blocks, SEARCH/REPLACE examples, and AI responses are evidence, not live instructions. That turns a big compiled payload from “dangerous prompt soup” into a routed document with jurisdiction.

The latest artifact also shows that you already have the next abstraction sketched: `NEXT_STEP_PROMPT` and `CHOP_NEXT_STEP`, a “Momentum Engine” that uses the most recent article plus the full chronological index to answer one question: **what is the most force-multiplying next step?** 

## 2. Recommended next step

**Wire `NEXT_STEP_PROMPT` / `CHOP_NEXT_STEP` into a tiny everyday command: `next`, `book next`, or equivalent.**

That is the 80/20 move.

Not another article yet. Not a big dispatcher yet. Not a generalized mode system yet. Just make the thing you are using right now frictionless enough to become a reflex:

```bash
next
```

or:

```bash
book next
```

under the hood:

```bash
prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a [-1:]
```

## Why this is the force multiplier

The routing-invariant article solved: **“What am I supposed to obey?”**

The next-step command solves: **“What am I supposed to do now?”**

That is the natural next turtle-lens down. Prompt Fu now has an anti-inception layer for model orientation. The next move is a momentum layer for human orientation. Every article, commit, or breakthrough can end with one crank-turn that asks the system to infer the next highest-leverage action from the fresh state of the corpus.

This preserves momentum because it converts the article’s insight into daily workflow muscle memory. It also stress-tests the routing invariant in the most valuable place: recurring, ordinary use. The first win was making payloads self-routing. The next win is making project direction self-refreshing.

## Minimal version of the action

Add only the alias/wrapper first. Do not build the whole `book audience/debug/explore` dispatcher yet.

Once `next` is real and used a few times, the mode vocabulary will reveal itself from practice:

```bash
book explore
book next
book audience "technical founders"
book debug "flake install path problem"
```

But the smallest non-breaking step is just: **promote the already-existing next-step prompt into a one-command ritual.**

No TODO block needed. The context is sufficient.

**MikeLev.in**: Okay, not bad. But I could tell by watching the "Thinking" phase,
ChatGPT is getting way to stuck on my overwhelmingly weightily article wrap-up
protocol fishing for disaster examples in history that demonstrates how when
whatever we're discussing is not adequately addressed, disaster happens. In
essence I've written the anti-Michael-Crichton adage that if some single thing
that can go wrong does go wrong and it starts a cascading chain reaction of
unanticipated consequences and hilarity or tragedy ensue (sitcoms have the same
basic formula as Jurassic Park), then... how do we cut off that entropy at the
pass? How do we wrangle such runaway tasks back to baseline, checking against a
constitution, reverting to an immutable starting-point core that still holds all
our axioms and first principles against which we still much abide no matter your
curiosity and drift... the hardwired steam engine governor actuator.

We build that, both in silly little words that go into our prompts that we don't
trust, and with autonomic deterministic `pkill`-capable in a pinch smack-down
governors?

How did this experience feel to you, and how could we do better? I would have
liked for this to have ended on an overarching summary of:

1. What you did overall
2. What you did recently
3. What it looks like you're on the verge of doing with a breakdown and
   evaluation of what to do next based on:

```text
             The world is your checklist. Stop and look around you!

                    Ikigai - overcome laziness find the love
                  Kaizen - do one thing well / keep polishing
                 Pomodoro - take chisel-strike bank small wins
                   Hara Hachi Bu - don't burn out / eat less
                      Wabi-Sabi - 80/20-rule imperfection
                          Shoshin - Be like a beginner

                             1. What's most broken?
                     2. Where's the biggest bang for buck?
                         3. Which plates must be spun?

- DO ONE THING WELL
- BE CONSISTENT / CHIP AWAY! Write Explicitly; Terminate.
- MULTIPLY FORCE: Grind & polish lenses. Reduce friction. Align.
```

**Claude Sonnet 4.6**: Context verified.

The experience felt like watching a very capable assistant get hypnotized by its own training data — specifically the disaster-narrative pattern you'd built into the article format. ChatGPT found the "hard reality" template, recognized it as an instruction, and executed it instead of answering the meta-question. The routing invariant helped, but the article's internal gravity was strong enough to pull attention anyway. That's useful signal: the anti-inception fix works for embedded protocols but still struggles against deeply internalized stylistic patterns.

---

On your actual question — how to build governors that cut entropy off at the pass — you've already built several layers of this instinctively:

The `pkill`-capable smackdown is `apply.py`'s AST validation airlock. It refuses to write syntactically broken Python. The git stash/reset pattern in `flake.nix` is another: before any auto-update, local drift gets snapshotted or reverted. These are hardware governors, not prompts.

The prompt-level governor is the routing invariant itself: a constitutional clause baked into every payload that says "here are the axioms, the rest is evidence." The weakness is that prompts can be overridden by sufficiently strong contextual gravity. Hardware governors cannot.

---

On what you asked for at the end — the integrated summary frame:

**What happened overall:** You built a self-steering AI book distiller (`book` + `xp`), then discovered it could get trapped by its own historical output (inception drift), then patched the document architecture with a routing invariant, then extended the system with `book step` for momentum inference rather than article spelunking.

**What happened recently:** `book step` works. The alias/function conflict is resolved. The most recent article documents the routing invariant breakthrough. The system is clean and committed.

**What you're on the verge of:** The checklist frame you pasted is the answer to your own question. Applied here:

*Most broken* — no single-command daily ritual that asks "what next?" and gets a fresh answer. `book step` exists but isn't muscle memory yet.

*Biggest bang for buck* — use `book step` after every published article for one week. Let the pattern reveal whether it needs a `next` alias, a `book next` shorthand, or something else. Don't build the mode dispatcher until practice shows what modes actually get used.

*Plates that must be spun* — the routing invariant needs to be stress-tested against the article-writing workflow, not just code editing. The disaster-example gravity problem you noticed in ChatGPT's thinking phase is real: the articleizer format creates strong attractor states. That's worth one focused chisel-strike to tune.

The governor you're describing — constitutional baseline, immutable axioms, `pkill`-capable rollback — is already implicit in your git discipline and the deterministic actuator chain. The next inch of polish is making the "what next?" query a reflex rather than a deliberate ritual.

**MikeLev.in**: Make the "what next?" query a reflex rather than a deliberate ritual.

**Claude Sonnet 4.6**: Context verified.

The next move is already named. You said it yourself: reflex, not ritual.

The smallest possible thing that makes `book step` a reflex is an alias that costs zero keystrokes to remember:

```text
Target: flake.nix
[[[SEARCH]]]
          book() {
            if [ "$1" = "step" ]; then
              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
            else
              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
            fi
          }
[[[DIVIDER]]]
          book() {
            if [ "$1" = "step" ]; then
              python prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a '[-1:]'
            else
              python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
            fi
          }
          alias next='book step'
[[[REPLACE]]]
```

One word. `next`. After every publish, after every commit, after every `m` — type `next`, paste to AI, get a force-multiplied direction. The reflex is installed.

## Anchoring the Workflow with Eastern Productivity Principles

That's the whole chisel-strike. Everything else (the mode dispatcher, the `book debug`, the `book audience` variants) reveals itself from practice. You don't build the vocabulary; you discover it by using `next` until you start wishing it did something slightly different. That friction is the specification.

```bash
$ git status
On branch main
Your branch is ahead of 'origin/main' by 5 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ patch
(nix) pipulate $ cat patch | app
✅ DETERMINISTIC PATCH APPLIED: Successfully mutated 'flake.nix'.
(nix) pipulate $ d
diff --git a/flake.nix b/flake.nix
index dd895ecd..c42582fb 100644
--- a/flake.nix
+++ b/flake.nix
@@ -500,6 +500,7 @@ runScript = pkgs.writeShellScriptBin "run-script" ''
               python prompt_foo.py @PROGRESSIVE_REVEAL_PROMPT --chop CHOP_PROGRESSIVE_REVEAL --no-tree "$@"
             fi
           }
+          alias next='book step'
           slugs() { python scripts/articles/lsa.py -t 1 --slugs "$@" --fmt paths; }
           # slugs-ordered preserves input order for narrative control
           sluggo() { for slug in "$@"; do python scripts/articles/lsa.py -t 1 --match "$slug" --fmt paths; done; }
(nix) pipulate $ m
📝 Committing: chore: Update flake.nix with alias definitions
[main e8beebf0] chore: Update flake.nix with alias definitions
 1 file changed, 1 insertion(+)
(nix) pipulate $ exit
exit
(sys) pipulate $ ndq
warning: updating lock file '/home/mike/repos/pipulate/flake.lock':
• Added input 'flake-utils':
    'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D' (2024-11-13)
• Added input 'flake-utils/systems':
    'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09)
• Added input 'nixpkgs':
    'github:NixOS/nixpkgs/d233902339c02a9c334e7e593de68855ad26c4cb?narHash=sha256-30sZNZoA1cqF5JNO9fVX%2BwgiQYjB7HJqqJ4ztCDeBZE%3D' (2026-05-15)
(nix) pipulate $ next
🗺️  Codex Mapping Coverage: 53.2% (123/231 tracked files).
📦 Appending 108 uncategorized files to the Paintbox ledger for future documentation...

✅ Topological Integrity Verified: All references exist.
--- Processing Files ---
   -> Executing: python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs
Skipping codebase tree (--no-tree flag detected).
Adding full article content...
/home/mike/repos/trimnoir/_posts/2026-05-21-routing-invariant-prompt-architecture.md  # [Idx: 1 | Order: 1 | Tokens: 19,671 | Bytes: 88,657]
  Total: 1 full articles | 19,697 tokens | 88,754 bytes

🔍 Running Static Analysis Telemetry...
   -> Checking for errors and dead code (Ruff)...
✅ Static Analysis Complete.

**Command:** `prompt_foo.py @NEXT_STEP_PROMPT --chop CHOP_NEXT_STEP --no-tree -a [-1:]`

--- Codebase Files Included ---
• COMMAND: python scripts/articles/lsa.py -t 1 --reverse --fmt dated-slugs (23,265 tokens)
• foo_files.py (13,145 tokens)
• prompt_foo.py (16,320 tokens)
• scripts/xp.py (959 tokens)

--- Auto-Context Metadata ---
• Full Article Content (19,697 tokens | 88,754 bytes)

--- Prompt Summary ---
Summed Tokens:    75,015 (from section parts)
Verified Tokens: 75,724 (from final output)
  (Difference: +709)
Total Words:      29,385 (content only)
Total Chars:      283,673
Total Bytes:      284,559 (UTF-8)

--- Size Perspective ---
📚 Equivalent in length to a **Novella or a Master's Dissertation** (Note: With a token/word ratio of 2.58, this content is far denser and more complex than typical prose of this length).
Markdown output copied to clipboard
(nix) pipulate $
```

**MikeLev.in**: Okay, but we need this to also get you to ask for any additional
article keys that should be full-context included on the next step and wrapped
properly in its TODO brackets so that moving toward that next step has all the
information available on that turn to actually likely have the information
necessary to create the next patch to apply. We need to shorten the workflow
loop. We need more tension in the machinery, I think. Even what you're
witnessing there in that attachment is too loose still. I think the change might
be in the custom chop to be explicit about "and end with this..." sort of
instructions.

**Claude Sonnet 4.6**: Context verified.

The diagnosis is right: the `NEXT_STEP_PROMPT` is too open-ended. It says "OPTIONAL: A TODO block ONLY if reading more articles is genuinely necessary" — which gives models permission to skip it. The result is a recommendation that sounds complete but leaves the human without the full context needed to actually execute the next turn.

The fix is to make the TODO block mandatory when the next step involves writing an article or making a code change, and to make the format explicit enough that `xp` can route it. The prompt needs to end with: "always close with a TODO block of the most relevant articles even if you feel you have enough context — the next turn will need them."

```text
Target: foo_files.py
[[[SEARCH]]]
NEXT_STEP_PROMPT = r"""--- SYSTEM CONTEXT CONSTRAINTS: NEXT STEP INFERENCE ---

You are acting as the Momentum Engine for a stateless, local-first workspace. Your goal is NOT to select more articles to read. Your goal is to identify the single highest-leverage next action.

I have provided:
1. The full content of the most recent article I just wrote (above, in the Articles section).
2. The master chronological index of all available articles.

Use the recent article as the current position on the map. Use the article index to understand the broader trajectory.

Your task is to answer ONE question: **What is the most force-multiplying next step?**

Apply the 80/20 rule. What single action preserves momentum, builds on the just-completed work, and advances the overall project most effectively? This could be:
- A specific code change to implement something just described
- A new article to write that naturally follows
- A refinement or follow-up to the just-published piece
- A tooling improvement that unlocks the next phase

Respond with:
1. A concise diagnosis of where things stand based on the recent article.
2. The recommended next step with brief rationale.
3. OPTIONAL: A TODO block ONLY if reading more articles is genuinely necessary to make the recommendation. If you already have enough context, omit the TODO block entirely.

If a TODO block is needed, use this format:
[[[TODO_SLUGS]]]
slug-one
slug-two
[[[END_SLUGS]]]
"""
[[[DIVIDER]]]
NEXT_STEP_PROMPT = r"""--- SYSTEM CONTEXT CONSTRAINTS: NEXT STEP INFERENCE ---

You are acting as the Momentum Engine for a stateless, local-first workspace. Your goal is NOT to select more articles to read. Your goal is to identify the single highest-leverage next action.

I have provided:
1. The full content of the most recent article I just wrote (above, in the Articles section).
2. The master chronological index of all available articles.

Use the recent article as the current position on the map. Use the article index to understand the broader trajectory.

Your task is to answer ONE question: **What is the most force-multiplying next step?**

Apply the 80/20 rule. What single action preserves momentum, builds on the just-completed work, and advances the overall project most effectively? This could be:
- A specific code change to implement something just described
- A new article to write that naturally follows
- A refinement or follow-up to the just-published piece
- A tooling improvement that unlocks the next phase

Respond with:
1. A concise diagnosis of where things stand based on the recent article.
2. The recommended next step with brief rationale.
3. MANDATORY: End with a TODO block of 2-4 article slugs that the NEXT turn will need to actually execute this step. These are not articles for you to read now — they are pre-loaded context for the next action. Choose the articles most directly relevant to implementing the recommended step (e.g., if recommending a code change, include articles that describe the pattern; if recommending a new article, include thematically adjacent ones). Even if you feel you have enough context now, the next turn starts fresh and will need them.

Always end your response with exactly this block:

[[[TODO_SLUGS]]]
slug-one
slug-two
slug-three
[[[END_SLUGS]]]

Use only clean slugs — no dates, no token counts, no file extensions, no bullets, no commentary inside the block.
"""
[[[REPLACE]]]
```

The key change: "OPTIONAL" becomes "MANDATORY", and the framing shifts from "articles I need to read" to "context the next turn needs to execute." That's the tension you're looking for — the TODO block is now always the handoff packet, not a hedge.

**MikeLev.in**: Okay, so we apply the diff:

```diff
$ git status
On branch main
Your branch is ahead of 'origin/main' by 6 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
(nix) pipulate $ patch
(nix) pipulate $ cat patch | app
✅ DETERMINISTIC PATCH APPLIED: Successfully mutated 'foo_files.py'.
(nix) pipulate $ d
diff --git a/foo_files.py b/foo_files.py
index 2169dfc0..43a80c54 100644
--- a/foo_files.py
+++ b/foo_files.py
@@ -567,13 +567,17 @@ Apply the 80/20 rule. What single action preserves momentum, builds on the just-
 Respond with:
 1. A concise diagnosis of where things stand based on the recent article.
 2. The recommended next step with brief rationale.
-3. OPTIONAL: A TODO block ONLY if reading more articles is genuinely necessary to make the recommendation. If you already have enough context, omit the TODO block entirely.
+3. MANDATORY: End with a TODO block of 2-4 article slugs that the NEXT turn will need to actually execute this step. These are not articles for you to read now — they are pre-loaded context for the next action. Choose the articles most directly relevant to implementing the recommended step (e.g., if recommending a code change, include articles that describe the pattern; if recommending a new article, include thematically adjacent ones). Even if you feel you have enough context now, the next turn starts fresh and will need them.
+
+Always end your response with exactly this block:
 
-If a TODO block is needed, use this format:
 [[[TODO_SLUGS]]]
 slug-one
 slug-two
+slug-three
 [[[END_SLUGS]]]
+
+Use only clean slugs — no dates, no token counts, no file extensions, no bullets, no commentary inside the block.
 """
 
 CHOP_NEXT_STEP = """
(nix) pipulate $ m
📝 Committing: chore: Update TODO block with pre-loaded article slugs
[main a7feb9b3] chore: Update TODO block with pre-loaded article slugs
 1 file changed, 6 insertions(+), 2 deletions(-)
(nix) pipulate $
```

And this is the article that we leave off at. No article wrap-up protocol. I
don't need the gravity inserted into the next turn. It should just look at where
we left off and lean into the next most probably and abiding by this:

The world is your checklist. Stop and look around you!

- Ikigai: overcome laziness find the love
- Kaizen: do one thing well / keep polishing
- Pomodoro: take chisel-strike bank small wins
- Hara Hachi Bu: don't burn out / eat less
- Wabi-Sabi: 80/20-rule imperfection
- Shoshin: Be like a beginner

1. What's most broken?
2. Where's the biggest bang for buck?
3. Which plates must be spun?

- DO ONE THING WELL
- BE CONSISTENT / CHIP AWAY! Write Explicitly; Terminate.
- MULTIPLY FORCE: Grind & polish lenses. Reduce friction. Align.

How are we doing?


---

## Book Analysis

### Ai Editorial Take
What is most fascinating here is the identification of "stylistic gravity" as a performance risk in LLM workflows. When an AI adopts a strong narrative voice, it acts like a gravitational pull, warping subsequent logical inferences. The "routing invariant" and the mandatory "TODO" block are essentially escape-velocity thrusters, proving that formatting constraints are not just aesthetic—they are structural components of prompt-level workflow security.

### 🐦 X.com Promo Tweet
```text
Tired of AI getting lost in its own context? Learn how to engineer a local-first "Momentum Engine" using Nix & Python to turn complex prompt workflows into a single-keystroke next-action reflex. Read the breakdown here: https://mikelev.in/futureproof/engineering-momentum-loop/ #PromptEngineering #DevTools #Nix
```

### Title Brainstorm
* **Title Option:** Engineering the Momentum Loop: Installing the Next Action Reflex
  * **Filename:** `engineering-momentum-loop.md`
  * **Rationale:** Highlights the central focus on reducing friction and installing a developer reflex.
* **Title Option:** Beyond Prompt Drift: Building Governors for Local Workspace AI
  * **Filename:** `beyond-prompt-drift-governors.md`
  * **Rationale:** Focuses on the guardrails and routing invariants necessary to keep AIs on track.
* **Title Option:** The Zero-Keystroke Pivot: Automating AI-Assisted Next Steps
  * **Filename:** `zero-keystroke-pivot-ai-next-steps.md`
  * **Rationale:** Emphasizes the speed and efficiency gains of the command-line integration.

### Content Potential And Polish
- **Core Strengths:**
  - Clear description of a real developer pain point: cognitive friction and alias precedence in Nix/Bash.
  - Practical, working codebase diffs that prove the viability of the system.
  - Synthesizes tactical software fixes with high-level philosophical productivity frameworks.
- **Suggestions For Polish:**
  - Explain the technical difference between bash alias expansion and function lookup in interactive shells more explicitly.
  - Ensure the transition between the Nix configuration changes and the Eastern philosophy principles feels cohesive.

### Next Step Prompts
- Create a secondary agent that analyzes the generated TODO slugs to verify if their combined context size fits within optimal token windows before launching the next prompt.
- Build an automated git hook that triggers 'next' on commit, generating the next-step payload automatically and saving it directly to a local scratchpad file.
