@dannylee1020/kkt 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +275 -0
  3. package/assets/kkt-readme-modern.png +0 -0
  4. package/bin/kkt-install.mjs +25 -0
  5. package/cmd/kkt/main.go +15 -0
  6. package/go.mod +3 -0
  7. package/internal/workflow/cli.go +349 -0
  8. package/internal/workflow/cli_test.go +1266 -0
  9. package/internal/workflow/guardrails.go +900 -0
  10. package/internal/workflow/init.go +164 -0
  11. package/internal/workflow/init_test.go +113 -0
  12. package/internal/workflow/operations.go +1855 -0
  13. package/internal/workflow/validation_commands.go +291 -0
  14. package/internal/workflow/workspace.go +802 -0
  15. package/internal/workflow/workspace_test.go +285 -0
  16. package/package.json +45 -0
  17. package/scripts/install-cli.sh +210 -0
  18. package/scripts/install.sh +644 -0
  19. package/skills/kkt/SKILL.md +74 -0
  20. package/skills/kkt/references/discovery-tooling.md +53 -0
  21. package/skills/kkt/references/feature-optimization-model.md +120 -0
  22. package/skills/kkt/references/kkt-kernel.md +58 -0
  23. package/skills/kkt/references/layered-modeling-methods.md +101 -0
  24. package/skills/kkt/references/plan-assimilation.md +46 -0
  25. package/skills/kkt/references/schemas.md +231 -0
  26. package/skills/kkt/references/state-contract.md +76 -0
  27. package/skills/kkt-loop/SKILL.md +99 -0
  28. package/skills/kkt-loop/references/discovery-tooling.md +53 -0
  29. package/skills/kkt-loop/references/feature-optimization-model.md +120 -0
  30. package/skills/kkt-loop/references/kkt-kernel.md +58 -0
  31. package/skills/kkt-loop/references/layered-modeling-methods.md +101 -0
  32. package/skills/kkt-loop/references/plan-assimilation.md +46 -0
  33. package/skills/kkt-loop/references/schemas.md +231 -0
  34. package/skills/kkt-loop/references/state-contract.md +76 -0
  35. package/skills/kkt-model/SKILL.md +76 -0
  36. package/skills/kkt-model/references/discovery-tooling.md +53 -0
  37. package/skills/kkt-model/references/feature-optimization-model.md +120 -0
  38. package/skills/kkt-model/references/kkt-kernel.md +58 -0
  39. package/skills/kkt-model/references/layered-modeling-methods.md +101 -0
  40. package/skills/kkt-model/references/plan-assimilation.md +46 -0
  41. package/skills/kkt-model/references/schemas.md +231 -0
  42. package/skills/kkt-model/references/state-contract.md +76 -0
  43. package/skills/kkt-run/SKILL.md +62 -0
  44. package/skills/kkt-run/references/discovery-tooling.md +53 -0
  45. package/skills/kkt-run/references/feature-optimization-model.md +120 -0
  46. package/skills/kkt-run/references/kkt-kernel.md +58 -0
  47. package/skills/kkt-run/references/layered-modeling-methods.md +101 -0
  48. package/skills/kkt-run/references/plan-assimilation.md +46 -0
  49. package/skills/kkt-run/references/schemas.md +231 -0
  50. package/skills/kkt-run/references/state-contract.md +76 -0
@@ -0,0 +1,76 @@
1
+ # KKT State Contract
2
+
3
+ Use this when KKT state must survive across layers, turns, or coding agents. The goal is not to store everything in YAML; it is to make handoff state explicit, inspectable, and hard to confuse.
4
+
5
+ Load `schemas.md` only when a full `kkt.yaml`, layer output, or `guardrails.json` shape is needed.
6
+
7
+ ## Persistence Tiers
8
+
9
+ | Tier | Skill | Durable files | Use when |
10
+ | --- | --- | --- | --- |
11
+ | Plan | `kkt` | none by default; optional `.kkt/kkt.yaml` | ordinary work where Markdown artifacts would be overhead. |
12
+ | Model | `kkt-model` | `.kkt/model/<slug>/kkt.yaml`, `intent.md`, `discovery.md`, `model.md`, `guardrails.json` | durable model or decision brief before execution. |
13
+ | Run | `kkt-run` | `.kkt/run/<slug>/kkt.yaml`, imported artifacts, `guardrails.json`, `plan.md`, `progress.md`, `evidence.md`, `notes.md` | completed model should be implemented now without loop state. |
14
+ | Loop | `kkt-loop` | `.kkt/loop/<slug>/kkt.yaml`, layer artifacts, `guardrails.json`, `plan.md`, `progress.md`, `evidence.md`, `notes.md`, `events.jsonl` | long-running or resumable execution. |
15
+
16
+ Durable `.kkt/` paths are rooted at the nearest Git/worktree root. Outside Git, the CLI falls back to the current directory.
17
+
18
+ ## CLI Ownership
19
+
20
+ The `kkt` CLI is the canonical mutation interface for KKT state. Skills should use CLI commands for workspace creation, state reads, artifact recording, guardrails, approvals, progress, evidence, validation, and completion.
21
+
22
+ - `kkt.yaml`: current status, active layer, method choices, decisions, artifact references, approvals, stop conditions, and summaries.
23
+ - Markdown artifacts: detailed intent, discovery, modeling rationale, execution plan, progress, evidence, and notes.
24
+ - `guardrails.json`: modeled constraints, allowed paths, blocked paths, validation requirements, and drift policy.
25
+ - `events.jsonl`: loop-only append history for task transitions, evidence, approvals, blockers, validation, and completion.
26
+
27
+ Do not hand-edit `kkt.yaml` as the primary workflow operation when a CLI command exists.
28
+
29
+ ## Useful Commands
30
+
31
+ ```text
32
+ kkt start plan "<request>"
33
+ kkt start model "<request>"
34
+ kkt run from-model [model-workspace]
35
+ kkt start run "<request>"
36
+ kkt start loop "<request>"
37
+ kkt intent|discovery|model --method <method> "<layer output>"
38
+ kkt guardrails show|set|validate
39
+ kkt judge --checkpoint model-ready|pre-mutation|continuation|finalize --json
40
+ kkt validate [--run]
41
+ kkt done
42
+ ```
43
+
44
+ ## Artifact Boundaries
45
+
46
+ - `intent.md`: user meaning, success, scope, examples, priority signals, explicit constraints, unresolved meaning questions.
47
+ - `discovery.md`: files, symbols, components, workflows, discovered constraints, validation paths, coupling, evidence, confidence, unknowns.
48
+ - `model.md`: method selection, objective, constraints, decision variables, candidates, feasibility, selected plan, binding constraints, validation plan, sensitivity, execution implications, residual risk.
49
+ - `guardrails.json`: machine-readable drift contract; run and loop execution must not proceed when modeled constraints or allowed paths are empty.
50
+ - `plan.md`: execution tasks, acceptance criteria, validation plan, evidence required, stop conditions, continuation policy.
51
+ - `progress.md`: work log, progress narrative, blocker notes.
52
+ - `evidence.md`: validation map, command outputs, artifacts, final certificate.
53
+ - `notes.md`: observations, assumptions, open questions, deferred ideas.
54
+ - `events.jsonl`: append-only loop event history, not a competing source of truth for current state.
55
+
56
+ When `guardrails.json` lists `validation.required_commands`, run or loop workspaces must use `kkt validate --run` to record deterministic command proof. `kkt evidence` records narrative evidence and criterion mapping only.
57
+
58
+ ## Handoff Rules
59
+
60
+ 1. Read `kkt.yaml` first when it exists.
61
+ 2. Read the prior layer's artifact before acting.
62
+ 3. Update only the current layer unless repairing a stale reference.
63
+ 4. Append decisions instead of overwriting prior rationale.
64
+ 5. Set `next_layer_readiness` before handing off.
65
+ 6. Record blockers with the smallest user or system change that would unblock.
66
+ 7. If new evidence invalidates an earlier layer, mark the active layer blocked and re-open the earlier layer instead of silently continuing.
67
+
68
+ ## Judge Checkpoints
69
+
70
+ - `model-ready`: before implementation; blocks run/loop execution when model, guardrails, or allowed path bounds are incomplete.
71
+ - `pre-mutation`: before edits or side effects; blocks when approval is missing or explicitly blocked paths changed; unrelated dirty paths outside allowed bounds are ignored.
72
+ - `continuation`: before loop continuation; blocks on active stop conditions or replay drift.
73
+ - `finalize`: before `kkt done`; blocks when validation fails or explicitly blocked paths changed; unrelated dirty paths outside allowed bounds are ignored.
74
+ - `pre-tool`, `post-tool`, `pre-compact`, `post-compact`: portable hook names for adapters; enforce explicit blocked paths without requiring a clean worktree.
75
+
76
+ Treat `block` as a hard stop. Treat `warn` as a contract-quality issue to repair before risky work. Treat `allow` as permission to continue to the next workflow step.
@@ -0,0 +1,99 @@
1
+ ---
2
+ name: kkt-loop
3
+ description: Durable constrained optimization execution loop for long-running coding work. Use when a coding agent should capture user meaning, discover repo constraints and validation paths, build an optimization model and execution contract, create a file-backed workspace, execute with continuation, validate with evidence, re-optimize when new facts invalidate the plan, and continue through goal-mode tools until acceptance criteria or stop conditions are met.
4
+ license: Apache-2.0
5
+ ---
6
+
7
+ # KKT Loop
8
+
9
+ Use this skill for long-running, autonomous, or multi-step coding work where progress, evidence, and continuation state must survive across turns. It extends the KKT model into a durable execution loop.
10
+
11
+ Read `references/kkt-kernel.md`, `references/feature-optimization-model.md`, `references/layered-modeling-methods.md`, and `references/state-contract.md` before acting. Read `references/plan-assimilation.md` only when prior plan text exists. Read `references/discovery-tooling.md` during discovery. Read `references/schemas.md` only when writing or auditing full state, guardrail, or layer-output shapes. If `ultragoal` is available, use its goal-state and continuation semantics as the runtime pattern.
12
+
13
+ ## Core Rule
14
+
15
+ Complete intake and discovery before modeling. Show the final model and get explicit approval before launching goal mode or implementing. On every continuation, use the CLI to read current state, choose the next task, record progress/evidence, and stop only when acceptance criteria are proven or a stop condition is hit.
16
+
17
+ ## CLI-First Workflow
18
+
19
+ Use the `kkt` CLI as the workflow control path. The skill owns reasoning policy; the CLI owns workspace creation, current state, task state, criteria, approval, progress, evidence, validation, completion, and `events.jsonl`.
20
+
21
+ ```text
22
+ kkt start loop "<user request>"
23
+ kkt status [--json]
24
+ kkt next
25
+ kkt intent --method <goal_anti_goal|why_how|obstacle_questions|pairwise_questions> "<intent frame>"
26
+ kkt discovery --method <naive|traceability_matrix|coupling_map|dsm_lite> "<repo facts and constraints>"
27
+ kkt model --method <lexicographic|decision_tree|shortest_path|ordinal_mcda|pairwise_ahp|outranking> "<objective_function, files_to_modify, constraint_functions, decision_variables, validation_proof, and selected model>"
28
+ kkt guardrails validate
29
+ kkt judge --checkpoint model-ready --json
30
+ kkt plan "<execution contract>"
31
+ kkt criteria add "<acceptance criterion>"
32
+ kkt task add "<task>"
33
+ kkt approve "<approved scope>"
34
+ kkt judge --checkpoint pre-mutation --json
35
+ kkt task start <task-id>
36
+ kkt progress "<progress update>"
37
+ kkt evidence --for <criterion-id> --command "<validation command>" "<validation evidence>"
38
+ kkt task done <task-id>
39
+ kkt criteria satisfy <criterion-id>
40
+ kkt validate --run
41
+ kkt judge --checkpoint continuation --json
42
+ kkt judge --checkpoint finalize --json
43
+ kkt done
44
+ kkt resume
45
+ kkt replay --check
46
+ ```
47
+
48
+ If `kkt` is missing, stop and ask the user to install or upgrade KKT. Do not hand-write replacement state. Use `kkt validate --run` when guardrails list required commands; `kkt evidence` records narrative evidence and criterion mapping, not deterministic command proof.
49
+
50
+ ## Durable State
51
+
52
+ Create project-root `.kkt/loop/<slug>/` with `kkt start loop "<user request>"` so intent, discovery, model, guardrails, and approval state are durable. The workspace starts with approval pending; do not execute or launch continuation until approval is recorded. Use `references/state-contract.md` for file layout, artifact boundaries, and loop-state semantics. Load `references/schemas.md` only when a full YAML or JSON shape is needed.
53
+
54
+ Loop workspaces use:
55
+
56
+ - `kkt.yaml` as the current contract.
57
+ - Markdown artifacts for rich intent, discovery, model, plan, progress, evidence, and notes.
58
+ - `events.jsonl` as append-only history for task transitions, evidence, approval, blockers, validation, and completion. Use it for resume context and replay consistency checks, not as a replacement source of truth for `kkt.yaml`.
59
+
60
+ ## Workflow
61
+
62
+ 1. Check current goal state with `get_goal` if available; do not create a second active goal without explicit user direction.
63
+ 2. Capture intent: user goal, desired behavior, user-visible success, scope boundary, examples, priority signals, and explicit user constraints.
64
+ 3. If prior plan text exists, assimilate it as untrusted scaffold before modeling: extract signals, classify each claim, verify discoverable facts, and treat unverified claims as assumptions or candidates.
65
+ 4. Run the interactive intent checkpoint before deep discovery: after any quick inspection needed to avoid asking repo-fact questions, ask 1-3 owner-decision questions when goal, success, scope, risk, or tradeoff preference is still ambiguous. For large, high-risk, or especially ambiguous work, run a short Socratic pass.
66
+ 5. Apply the owner-decision filter before asking: inspect discoverable facts locally, assume low-risk reversible defaults, ask only for owner decisions, and stop for blocking unknowns.
67
+ 6. Inspect relevant repo context and validation paths before writing the model. Use `rg` directly for broad text and file discovery, `ast-grep` directly for structural search when syntax matters, `git` for repository state, optional helpers and language-native commands when they provide stronger evidence.
68
+ 7. Select one intent method, one discovery method, and one modeling method from the layered catalog; record each with the matching `kkt ... --method` command. When no specialized method fits, use the fallback set (`goal_anti_goal`, `traceability_matrix`, `lexicographic`) and record why the fallback is sufficient instead of forcing an advanced method.
69
+ 8. Build the optimization model and execution contract from intent and discovery using the loop profile. The pre-approval output must include objective function, known constraints, files to modify or affected surfaces, constraint functions, decision variables, candidate feasibility, selected plan, binding constraints, validation proof plan, execution implications, residual risk, acceptance criteria, evidence required, guardrail constraints, allowed paths, blocked paths, and stop conditions.
70
+ 9. Run `kkt guardrails validate` and `kkt judge --checkpoint model-ready --json`; repair or stop on any blocking result.
71
+ 10. Show the final model and wait for explicit approval.
72
+ 11. After approval, record the plan with CLI commands, add criteria/tasks, and record approval.
73
+ 12. Launch `create_goal` only when goal tools are available, no active goal exists, and the user asked to run now; otherwise output the exact `/goal` command.
74
+ 13. Before each work segment, run `kkt status --json`, `kkt next`, and `kkt judge --checkpoint continuation --json`; use `kkt next --json` when a machine-readable next action helps; inspect `kkt show state`, `kkt show progress`, and `kkt show evidence` as needed.
75
+ 14. Before modifying files or running side-effecting tools, run `kkt judge --checkpoint pre-mutation --json`; it blocks if existing git changes are outside `allowed_paths` or inside `blocked_paths`.
76
+ 15. Execute only the current or CLI-reported next task, update progress/evidence with criterion-linked evidence, update task and criteria state, and run `kkt validate --run` when required commands exist.
77
+ 16. Run `kkt judge --checkpoint finalize --json` before `kkt done`.
78
+ 17. Re-optimize with `kkt model --method <method>` only when new evidence changes feasibility, constraints, or objective fit.
79
+
80
+ ## Goal Objective Template
81
+
82
+ ```text
83
+ Execute the KKT workspace at the project root's .kkt/loop/<slug>/plan.md. Follow kkt.yaml, intent.md, discovery.md, model.md, guardrails.json, plan.md, progress.md, evidence.md, notes.md, and events.jsonl. Use kkt status --json, kkt next, kkt judge, kkt task, kkt progress, kkt evidence, kkt criteria, kkt validate --run when required commands exist, and kkt done as the workflow control surface. Re-read state and run the continuation judge before each continuation, re-optimize only when evidence changes feasibility, and stop only for blocking judge results, listed stop conditions, proven acceptance criteria, or explicit user input.
84
+ ```
85
+
86
+ Do not set a token budget unless the user explicitly provides one.
87
+
88
+ ## Stop Conditions
89
+
90
+ Stop before continuing when approval is missing, no feasible plan satisfies hard constraints, a destructive action is required, credentials/secrets/external access/paid services are required, a listed stop condition is active, a task or criterion is blocked, or continuing expands scope.
91
+
92
+ ## Do Not
93
+
94
+ - Do not use workspace files as a substitute for understanding the request.
95
+ - Do not create workspace files, launch goal mode, or begin implementation before approval.
96
+ - Do not create multiple workspaces for the same objective.
97
+ - Do not include secrets or credentials in workspace files.
98
+ - Do not continue past a stop condition or blocked criterion.
99
+ - Do not re-optimize on preference alone; re-optimize only when evidence changes feasibility, constraints, or objective fit.
@@ -0,0 +1,53 @@
1
+ # Discovery Tooling
2
+
3
+ Use this during discovery to prove repo facts accurately with direct agent tool calls.
4
+
5
+ ## Rule
6
+
7
+ Use the lightest reliable tool that can prove the needed fact. Start with `rg` for broad text/file discovery, then use `ast-grep` for structural questions. Prefer exact, inspectable evidence over broad inference. Record important negative searches when they shape the model.
8
+
9
+ Discovery tools are read-only during planning and modeling. Rewrite, update, or codegen modes belong to approved execution.
10
+
11
+ Do not route discovery through `kkt` CLI commands. The CLI owns deterministic workflow state; the agent owns repo inspection.
12
+
13
+ ## Tool Ladder
14
+
15
+ - Core: `git` for repository boundary, tracked files, status, diffs, history, and changed-path scope.
16
+ - Core: `rg` for strings, filenames, config keys, docs, tests, shell scripts, and negative searches.
17
+ - Core structural: `ast-grep` for syntax-aware search when call sites, imports, handlers, declarations, components, error handling, or API shapes matter.
18
+ - Optional: `fd`, `ctags`, `tokei`, `scc`, and repo-native commands when they add confidence.
19
+ - Language-native: `go list`, `go test`, `cargo metadata`, `npm` scripts, `tsc`, `pytest --collect-only`, Gradle, Maven, Rails, Django, or equivalent repo tooling.
20
+
21
+ ## Selection Rules
22
+
23
+ - Use `git ls-files` or `rg --files` before broad recursive scans.
24
+ - Use `rg` for text and file discovery.
25
+ - Use `ast-grep` when syntax matters and text evidence would be noisy or ambiguous.
26
+ - Use language-native tooling for package boundaries, route maps, type contracts, test commands, or generated-code boundaries.
27
+ - If `ast-grep` is unavailable, record the setup gap and fall back only as far as the evidence supports. Do not claim AST-level certainty from text search alone.
28
+
29
+ ## Ast-Grep Policy
30
+
31
+ Allowed during discovery:
32
+
33
+ ```text
34
+ ast-grep --pattern '<pattern>' --lang <language>
35
+ ast-grep --pattern '<pattern>' --lang <language> --json
36
+ ast-grep scan --config sgconfig.yml --json
37
+ ```
38
+
39
+ Forbidden during planning or modeling:
40
+
41
+ ```text
42
+ ast-grep --rewrite ...
43
+ ast-grep scan --update-all
44
+ ast-grep scan --interactive
45
+ ```
46
+
47
+ Rewrites require the execution layer, approval, and normal KKT guardrails.
48
+
49
+ ## Guardrails
50
+
51
+ - Do not add a KKT discovery command as a substitute for direct `rg` and `ast-grep` use.
52
+ - Do not claim structural certainty from plain text search when AST search or language-native tools are needed and available.
53
+ - Do not use generated, vendored, or build-output files as primary evidence unless the task explicitly targets them.
@@ -0,0 +1,120 @@
1
+ # Feature Optimization Model
2
+
3
+ Use this reference when building or reviewing a KKT model. Keep the active model compact; load `schemas.md` only when a full copyable shape is needed.
4
+
5
+ ## Intake
6
+
7
+ Start with user meaning, then let discovery fill in repo facts.
8
+
9
+ Capture:
10
+
11
+ - user goal;
12
+ - desired behavior;
13
+ - user-visible success;
14
+ - scope boundary;
15
+ - examples or counterexamples, if supplied;
16
+ - priority signals;
17
+ - explicit user constraints;
18
+ - execution mode: `implement`, `model_only`, `run`, or `loop`.
19
+
20
+ When prior plan text exists, read `plan-assimilation.md` first. Preserve the user's original request, classify prior-plan claims, verify discoverable facts, and keep unverified claims as assumptions or candidates.
21
+
22
+ Do not ask the user for repo facts that local discovery can verify. Use the question filter in `kkt-kernel.md`.
23
+
24
+ ## Model Shape
25
+
26
+ Treat the task as:
27
+
28
+ ```text
29
+ choose implementation decisions
30
+ that best satisfy the user's objective
31
+ subject to project, architecture, security, data, UI, infrastructure, validation, and scope constraints
32
+ ```
33
+
34
+ Build the model around:
35
+
36
+ - `objective_function`: ordered terms used to compare feasible plans.
37
+ - `system_state`: inspected facts plus labeled assumptions.
38
+ - `decision_variables`: choices the agent may make, each with an allowed domain.
39
+ - `files_to_modify`: expected files, modules, APIs, workflows, migrations, docs, or operational surfaces.
40
+ - `constraint_contract`: hard predicates for feasibility and soft preferences for ranking.
41
+ - `feasible_region`: candidate plans that satisfy all hard constraints.
42
+ - `selected_plan`: chosen feasible plan and why it wins.
43
+ - `binding_constraints`: active constraints that shape the selected plan.
44
+ - `validation_proof`: commands, checks, artifacts, or explicit limitations needed before completion.
45
+
46
+ ## Method Profiles
47
+
48
+ - Plan profile (`kkt`): compact intake, local discovery, hard-constraint feasibility, lexicographic ranking, approval before edits, validation certificate.
49
+ - Deep profile (`kkt-model`): layered method selection, candidate comparison, binding constraints, sensitivity, guardrail variables, and user tradeoff questions when needed.
50
+ - Run profile (`kkt-run`): import a completed model, validate guardrails, run deterministic checkpoints, execute only the selected plan.
51
+ - Loop profile (`kkt-loop`): durable model plus continuation state, task/criteria tracking, evidence-backed continuation, and re-optimization only on material new evidence.
52
+
53
+ Read `layered-modeling-methods.md` for deep or loop modeling choices. Do not expose formal method names in ordinary `$kkt` output unless they explain a material tradeoff.
54
+
55
+ ## Decision Variables
56
+
57
+ Decision variables are implementation choices with explicit domains. Common variables include:
58
+
59
+ - files or modules to modify;
60
+ - endpoint, CLI, schema, or event shape;
61
+ - data storage or migration strategy;
62
+ - state ownership;
63
+ - UI placement;
64
+ - validation strategy;
65
+ - compatibility strategy;
66
+ - dependency strategy;
67
+ - rollout or fallback strategy.
68
+
69
+ Poor: `database: decide storage`
70
+
71
+ Better: `persistence_strategy: add nullable fields to existing table`, with allowed and disallowed options recorded.
72
+
73
+ ## Constraints
74
+
75
+ Hard constraints make a plan infeasible when violated:
76
+
77
+ - explicit user constraints and non-goals;
78
+ - correctness, security, privacy, and data integrity;
79
+ - public API or persisted-data compatibility;
80
+ - framework, runtime, infrastructure, or deployment limits;
81
+ - no destructive action, credentials, paid services, or external side effects without approval.
82
+
83
+ Soft constraints rank feasible plans:
84
+
85
+ - minimal diff and blast radius;
86
+ - existing style and architecture fit;
87
+ - readability, maintainability, reversibility, and validation clarity.
88
+
89
+ Use lexicographic priority instead of fake numeric scores:
90
+
91
+ 1. Satisfy the user request.
92
+ 2. Preserve correctness, security, data integrity, and public contracts.
93
+ 3. Minimize blast radius.
94
+ 4. Match existing architecture and conventions.
95
+ 5. Improve maintainability where cheap.
96
+ 6. Prefer validation clarity over elegance.
97
+
98
+ ## Selected Plan Contract
99
+
100
+ An approval-ready plan or selected model must include:
101
+
102
+ - objective function;
103
+ - known constraints by source: explicit, discovered, inferred, assumptions;
104
+ - decision variables and chosen values;
105
+ - affected files or surfaces;
106
+ - feasible and rejected candidates;
107
+ - selected plan;
108
+ - binding constraints;
109
+ - validation plan and proof required;
110
+ - execution implications;
111
+ - guardrail variables when durable run or loop state will enforce scope;
112
+ - residual risk.
113
+
114
+ If a field is irrelevant, say `none` or give a short reason. Do not hide constraints inside prose.
115
+
116
+ ## Re-Optimization
117
+
118
+ Re-optimize when new evidence changes system state, feasible region, hard constraints, selected-plan binding constraints, selected decisions, or validation feasibility.
119
+
120
+ Do not re-optimize merely because another plan feels more elegant.
@@ -0,0 +1,58 @@
1
+ # KKT Kernel
2
+
3
+ This is the mandatory operating contract for every KKT skill. It should stay short enough to read on every invocation.
4
+
5
+ ## Invariants
6
+
7
+ - Capture user meaning before modeling.
8
+ - Discover repo facts before asking the user for file names, routes, schemas, tests, commands, or config.
9
+ - Treat prior host-agent or plan-mode output as scaffold, not truth.
10
+ - Check hard constraints before comparing plans.
11
+ - Pick the smallest feasible plan that satisfies the user's objective and protects existing contracts.
12
+ - Get approval before mutation when the skill is in a planning, model, run, or loop gate.
13
+ - Validate with evidence before completion.
14
+ - Re-optimize only when new evidence changes facts, constraints, feasible plans, selected decisions, or validation feasibility.
15
+
16
+ ## Question Filter
17
+
18
+ Before asking, classify the unknown:
19
+
20
+ - `discoverable_fact`: inspect the repo, docs, tests, config, schemas, routes, logs, or issues.
21
+ - `reversible_default`: choose the conservative low-risk default and label it as an assumption.
22
+ - `owner_decision`: ask when the answer changes product behavior, scope, risk, approval, destructive actions, external dependencies, credentials, paid services, or execution mode.
23
+ - `blocking_unknown`: stop when no conservative default keeps the hard constraints feasible.
24
+
25
+ ## Core Model
26
+
27
+ Every KKT model or approval-ready plan needs:
28
+
29
+ - objective function;
30
+ - known constraints, with explicit, discovered, inferred, and assumed sources separated;
31
+ - decision variables with allowed domains and chosen values;
32
+ - files, modules, APIs, workflows, docs, migrations, or operational surfaces expected to change;
33
+ - candidate plans, with infeasible options rejected before comparison;
34
+ - selected feasible plan and why it dominates alternatives;
35
+ - binding constraints that shaped the selected plan;
36
+ - validation plan and evidence required;
37
+ - residual risk.
38
+
39
+ ## Discovery Rules
40
+
41
+ - Use `git` for repository boundaries, status, diffs, history, and changed-path scope.
42
+ - Use `rg` immediately for broad text and file discovery.
43
+ - Use `ast-grep` immediately when syntax matters and text search would be ambiguous.
44
+ - Use language-native tools when they reveal package boundaries, types, route maps, generated-code boundaries, or test contracts.
45
+ - If `ast-grep` is unavailable in an already-installed environment, record the setup gap and do not claim AST-level certainty from text search alone.
46
+ - Record important negative searches when they shape the selected plan.
47
+
48
+ ## Completion Certificate
49
+
50
+ Finish with:
51
+
52
+ ```text
53
+ Objective: satisfied / not satisfied
54
+ Hard constraints: satisfied / violations listed
55
+ Binding constraints: respected / changed
56
+ Validation evidence: commands, checks, artifacts, or reason validation was not possible
57
+ Residual risk: concise notes
58
+ ```
@@ -0,0 +1,101 @@
1
+ # Layered Modeling Methods
2
+
3
+ Use this catalog for `$kkt-model`, `$kkt-loop`, or unusually complex `$kkt` work. Do not apply every method to every request.
4
+
5
+ Every layer must produce enough output for the next layer to continue without hidden session context. Load `schemas.md` only when a copyable layer-contract shape is needed.
6
+
7
+ ## Profiles
8
+
9
+ ### Plan Profile
10
+
11
+ Use for ordinary `$kkt` implementation work:
12
+
13
+ - compact intent frame;
14
+ - local discovery with `git`, `rg`, and structural search when useful;
15
+ - hard-constraint feasibility gate;
16
+ - lexicographic ranking of feasible plans;
17
+ - approval before implementation;
18
+ - validation certificate.
19
+
20
+ Keep formal method names out of normal output unless they explain a material tradeoff.
21
+
22
+ ### Deep Profile
23
+
24
+ Use for `$kkt-model` and complex planning:
25
+
26
+ - ask targeted owner-decision questions after quick inspection;
27
+ - build a discovery map with evidence confidence;
28
+ - select and record one intent, discovery, and modeling method;
29
+ - compare candidate models and reject infeasible options first;
30
+ - explain binding constraints, sensitivity, and execution implications.
31
+
32
+ Fallback set: `goal_anti_goal`, `traceability_matrix`, `lexicographic`. Use it when specialized methods do not materially improve reliability.
33
+
34
+ ### Loop Profile
35
+
36
+ Use for `$kkt-loop`:
37
+
38
+ - front-load deeper modeling before execution;
39
+ - write durable state through the CLI;
40
+ - require approval before workspace execution or goal launch;
41
+ - continue from CLI state and evidence;
42
+ - re-optimize only when new evidence changes feasibility, constraints, objective fit, or validation feasibility.
43
+
44
+ ## Intent Methods
45
+
46
+ Purpose: turn rough user input into a meaning frame discovery can test against the repo.
47
+
48
+ - Goal / anti-goal: desired outcome and explicit non-goals.
49
+ - WHY / HOW ladder: find the real objective; ask HOW only when it clarifies desired behavior.
50
+ - Obstacle questions: identify interpretations that would be unacceptable, too broad, or aimed at the wrong workflow.
51
+ - Example / counterexample: use when examples would prevent a materially wrong interpretation.
52
+ - Tradeoff prompt: ask only when competing priorities change the model.
53
+ - Owner-decision filter: classify possible questions as discoverable facts, reversible defaults, owner decisions, or blocking unknowns.
54
+
55
+ Question budget:
56
+
57
+ - clear task: 0-1 questions;
58
+ - medium ambiguity: 1-3 targeted questions;
59
+ - large, high-risk, or ambiguous work: short Socratic pass after quick inspection.
60
+
61
+ ## Discovery Methods
62
+
63
+ Purpose: convert intent into inspected facts and traceable system context.
64
+
65
+ - Naive/local discovery: direct `git`, `rg`, file reads, and tests for obvious locality.
66
+ - Traceability matrix: map intent to files, modules, routes, schemas, tests, docs, config, and runtime boundaries.
67
+ - Coupling map: identify callers, public interfaces, state owners, side effects, and downstream contracts.
68
+ - DSM-lite: use a small dependency matrix when several modules/workflows make blast radius unclear.
69
+ - Structural discovery: use `ast-grep` when syntax matters.
70
+
71
+ Discovery output must distinguish observed facts, inferred constraints, assumptions, unknowns, validation paths, unavailable preferred tools, fallback notes, and important negative searches.
72
+
73
+ ## Modeling Methods
74
+
75
+ Always apply the hard-constraint feasibility gate before ranking.
76
+
77
+ | Decision shape | Method | Use when |
78
+ | --- | --- | --- |
79
+ | Normal implementation choice | Lexicographic ranking | Priorities are clear and correctness / safety / contracts outrank lower preferences. |
80
+ | Branching facts determine feasibility | Decision tree | Repo facts eliminate paths. |
81
+ | Staged transition or rollout | Shortest path | There are real states, transitions, costs, and forbidden states. |
82
+ | Comparable feasible options | Ordinal MCDA | Alternatives differ across blast radius, maintainability, validation clarity, speed, or reversibility. |
83
+ | User priorities are unclear | AHP-style pairwise questions | Risk, speed, migration, or architecture preference determines the choice. |
84
+ | No feasible option clearly dominates | Outranking shortlist | Architecture choices need a defensible shortlist rather than a forced winner. |
85
+
86
+ Do not invent numeric scores for subjective criteria. Prefer ordinal labels unless the user supplies actual weights.
87
+
88
+ ## Execution Methods
89
+
90
+ - Smallest feasible step: edit only the surfaces selected by the model.
91
+ - Contract-preserving change: preserve public APIs, data contracts, security boundaries, and user non-goals unless approval changed them.
92
+ - Re-optimization trigger: stop when new evidence changes feasibility, selected decisions, or validation feasibility.
93
+
94
+ ## Validation Methods
95
+
96
+ - Acceptance-criteria map: map each criterion to evidence.
97
+ - Hard-constraint audit: explicitly check feasibility constraints.
98
+ - Binding-constraint audit: verify the selected plan still respects the constraints that shaped it.
99
+ - Residual-risk register: list claims not proven by validation.
100
+
101
+ Final validation must include commands, checks, artifacts, unavailable checks, residual risk, and a completion certificate.
@@ -0,0 +1,46 @@
1
+ # Plan Assimilation
2
+
3
+ Use this only when KKT is invoked after a host agent or default plan mode has already produced a plan.
4
+
5
+ ## Rule
6
+
7
+ Prior plan text is an untrusted scaffold. Consume whatever exists, extract useful signals, verify discoverable claims, and rebuild the KKT model from KKT's own intent, discovery, constraints, decision variables, selected plan, and validation proof.
8
+
9
+ Do not ask the user to reformat prior plan output.
10
+
11
+ ## Checklist
12
+
13
+ 1. Preserve the original user request and explicit user constraints.
14
+ 2. Extract signals from the prior plan:
15
+ - proposed goal and steps;
16
+ - suspected files, modules, APIs, schemas, routes, tests, docs, or operational surfaces;
17
+ - stated or implied constraints;
18
+ - validation suggestions;
19
+ - open questions and risk signals.
20
+ 3. Classify each signal:
21
+ - `explicit_user_input`;
22
+ - `plan_assumption`;
23
+ - `discoverable_fact`;
24
+ - `candidate_decision`;
25
+ - `candidate_constraint`;
26
+ - `candidate_validation`;
27
+ - `unknown_or_ambiguous`.
28
+ 4. Verify discoverable facts through repo inspection before using them as facts.
29
+ 5. Keep unverified claims as assumptions or candidates, never as discovered facts.
30
+ 6. Add missing KKT structure: objective, constraints, decision variables, candidate feasibility, selected plan, binding constraints, guardrails, and validation proof.
31
+ 7. Reject or revise the prior plan when it violates hard constraints, skips cheaper feasible paths, or names validation that does not exist.
32
+
33
+ ## Anti-Anchoring Checks
34
+
35
+ - Which prior-plan claims were verified?
36
+ - Which claims remain assumptions?
37
+ - Which constraints or decision variables did the plan miss?
38
+ - What smaller or safer feasible plan exists?
39
+ - What validation proof would certify the selected plan?
40
+
41
+ ## Guardrails
42
+
43
+ - Do not enforce a schema on host plan-mode output.
44
+ - Do not treat prior-plan file names, routes, commands, or architecture claims as facts before inspection.
45
+ - Do not rubber-stamp the prior plan as the selected KKT plan.
46
+ - Do not ask the user for repo facts the discovery layer can verify.