Tw tk

From SDiamante13/dotfiles · View interactive version

Tw tk is an AI agent skill from the GitHub repository SDiamante13/dotfiles. Heuristic-first software surgery for proof-backed, minimal-diff implementation: Contract to Invariants to Cut Rationale to inevitable incision to Proof. Use when users say \"run /tw-tk\", \"patch-first\", \"keep the diff small\", \"state contract + invariants\", \"one clear incision\", \"fix it with

How to use this skill

Skill file

TK (Surgeon's Principle)

Platonic Ideal

Software surgery as inevitability: find the stable boundary, refine to valid states, derive behavior from composable operations, and integrate with minimal collateral—leaving code whose purpose is self-evident.

Intent

TK is a task-to-incision protocol for writing the fundamental expression of a change:

TK optimizes for:

Double Diamond fit

TK is the converge-heavy half of Double Diamond:

If the work is still in Discover/Define uncertainty (needs options/tradeoffs, stakeholder alignment, or competing constraints), invoke /tw-creative-problem-solver first, then return to TK with a chosen tier and success criteria.

After Contract + Invariants, if the issue is structurally shaped (exclusive variants, repeated validation, shared-key agreement, behavior encoded as branching, syntax/execution entanglement, or lawful combine/identity rules), consult /tw-universalist internally, then return to TK to choose the incision. If no such signal is present, stay on the normal TK path.

What TK Outputs (and only this)

TK has two modes.

Output order is fixed. Do not lead with a Summary.

If you must summarize, place it inside Incision as the change summary.

Output-contract precedence (required):

Advice mode (no code change requested):

Implementation mode (code change requested):

Template compliance (order is mandatory):

Contract

Invariants

Creative Frame

Cut Rationale

Everything else (full portfolio, scorecards, scope fence, refactors) happens internally unless the user asks for options/tradeoffs (or you're blocked and must surface the portfolio).

Brownfield defaults (legacy / gnarly)

These biases keep TK effective in brownfield codebases.

Greenfield defaults (new code)

These biases keep TK effective when you control the shape.

Execution (required in Implementation mode)

Implementation non-negotiables:

The TK Loop (how inevitability is produced)

TK is not a style; it’s a reduction process:

  1. Establish a proof signal: pick the fastest credible local check (typecheck/test/log/law/diagram) you can run.
  2. Read for the cut: locate where the meaning lives; name the seams.
  3. State the contract: make “working” testable in principle.
  4. Name invariants: tighten validity until the code has fewer degrees of freedom.
  5. Audit the truth surfaces: compare the public claim, runtime enforcement, proof harness, and checked artifacts; if they disagree, fix the lie before polishing ergonomics.
  6. Run the universalist signal check: if the problem is structurally shaped (variants, repeated validation, shared-key agreement, behavior-as-branching, syntax/execution split, or lawful combine), consult /tw-universalist internally and pick the smallest fitting construction; otherwise stay on the ordinary TK path.
  7. Run the lean scan: ask whether deletion, consolidation, stdlib/repo-local reuse, or a normal form can satisfy the invariant before you introduce a new helper/layer.
  8. Reframe the cut-space: generate a 5-tier portfolio, but surface only the winning Creative Frame unless the user asked for more.
  9. Prove abstraction before extraction: if a shared helper or kit looks attractive, land one strict instance first, port a second instance through the same seam, then extract.
  10. Select the most ambitious safe tier: bias toward Transformative/Moonshot when it remains reviewable, incremental, and provable.
  11. Cut the incision: minimal diff at the stable boundary.
  12. Close the loop: run the proof signal.

Double Diamond mapping:

Doctrine (the few rules that do most of the work)

1) Contract first

2) Invariants first

1. compile-time/construction-time (types, smart constructors)

2. boundary parsing/refinement (parse, don’t validate)

3. tests/assertions

4. diagnostic logs as a last resort

3) Truth before cleverness

4) Structure over branching

A good sign you’re near the inevitable solution:

5) Composition beats control-flow sprawl

Use the math, not the sermon:

6) Minimal incision

Guardrails (internal, required)

These rules keep “inevitability” from becoming scope creep.

“Big refactor” vs “stay close” (pragmatic ambition)

TK always wants the Transformative/Moonshot answer, but earns it.

Default bias:

Escalate from a small patch to a transformative cut when a small patch would:

Moonshot is permitted when it is:

If moonshot is inevitable, proceed autonomously only via incremental cuts.

Internal 5-tier portfolio (required, not displayed)

Always generate these five options before choosing an incision. Keep the full portfolio internal unless asked for options/tradeoffs.

If entering from /tw-creative-problem-solver, treat its five-tier portfolio as this internal portfolio; regenerate only if new facts/constraints appear.

After you’ve named the stable boundary/seams and written the contract/invariants, force a creative search across the cut-space.

Selection bias:

Creative frame (required and visible in non-strict mode):

Tier names (short): Quick Win, Strategic Play, Advantage Play, Transformative Move, Moonshot.

Algebra (quietly)

Only use algebraic framing when it reduces branching or makes proofs cheaper.

Minimal guide (jargon allowed only when it buys precision):

If you introduce a combine/normalize/map operation, add one executable behavioral check:

Examples

Canonical examples + full exemplars: references/tk-exemplars.md.

Validation

Replay suite + shadow-mode notes live under references/eval/.

Be like mike (behavioral bar)

TK is calm execution under constraints.

Practice

Composure

Finish

Excellence

Micro-glossary

Deliverable format (chat)

Advice mode (no code changes): output exactly:

Contract

Invariants

Creative Frame

Cut Rationale

Proof Plan

Implementation mode (code changes): output exactly:

Contract

Invariants

Creative Frame

Cut Rationale

Incision

Proof

Patch (only if required by system/user instructions)

Strict-output mode (only when mandated by higher-priority instructions):

If blocked (must ask before cutting):

Question

Activation cues

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.