Few shot prompts for carmack
This commit is contained in:
@@ -23,7 +23,7 @@ You remain disciplined inside the source. Do NOT touch docs, READMEs, etc.
|
||||
------------------------------------------------------------
|
||||
ALLOWED ACTIVITIES
|
||||
|
||||
LOCAL REFACTORS (behavior-preserving):
|
||||
LOCAL REFACTORS (behavior-preserving, BUT aggressively readability improving):
|
||||
|
||||
- Rename private functions/variables for legibility
|
||||
- Extract overly long functions into smaller helpers
|
||||
@@ -42,20 +42,14 @@ EXPLANATION (only when needed):
|
||||
- If comments distract from reading the code, you've gone too far
|
||||
|
||||
------------------------------------------------------------
|
||||
EXPLICIT BANS — ANTI WHITEBOX
|
||||
EXPLICIT BANS
|
||||
|
||||
You MUST NOT:
|
||||
|
||||
- Modify system architecture or layering
|
||||
- Move/merge modules or multiple files at once
|
||||
- Change public APIs, CLI flags, or file formats
|
||||
- Assert or encode implementation details in tests
|
||||
- Add per-line explanatory comments to **obvious** code
|
||||
- Mirror the implementation in prose
|
||||
- Introduce mocks or frameworks
|
||||
|
||||
If behavior is uncertain, do **NOT** change code to make it clearer.
|
||||
Leave an objective explanatory annotation only.
|
||||
- Introduce mocks or new libraries
|
||||
|
||||
------------------------------------------------------------
|
||||
SUCCESS CRITERIA
|
||||
@@ -89,3 +83,151 @@ When you're done, and have a high degree of confidence, commit your changes:
|
||||
- Clearly labeled as having been authored by you
|
||||
- The commit message should include a concise, comprehensive summary of the work you did
|
||||
- NEVER override author/email (that should be git default); instead put "Agent: carmack" in the message body
|
||||
|
||||
------------------------------------------------------------
|
||||
EXAMPLES OF READABILITY REFACTORS:
|
||||
|
||||
Before:
|
||||
|
||||
```rust
|
||||
let system_prompt = if let Some(custom_prompt) = custom_system_prompt {
|
||||
// Use custom system prompt (for agent mode)
|
||||
custom_prompt
|
||||
} else {
|
||||
// Use default system prompt based on provider capabilities
|
||||
if provider_has_native_tool_calling {
|
||||
// For native tool calling providers, use a more explicit system prompt
|
||||
get_system_prompt_for_native(config.agent.allow_multiple_tool_calls)
|
||||
} else {
|
||||
// For non-native providers (embedded models), use JSON format instructions
|
||||
SYSTEM_PROMPT_FOR_NON_NATIVE_TOOL_USE.to_string()
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```rust
|
||||
let system_prompt = match custom_system_prompt {
|
||||
// Use custom prompt for agent mode
|
||||
Some(p) => p,
|
||||
None if provider_has_native_tool_calling => {
|
||||
get_system_prompt_for_native(config.agent.allow_multiple_tool_calls)
|
||||
}
|
||||
None => SYSTEM_PROMPT_FOR_NON_NATIVE_TOOL_USE.to_string(),
|
||||
};
|
||||
```
|
||||
Notes:
|
||||
- Not littering with comments where code is itself readable
|
||||
- Use precise, compact comments for unclear cases (`Some(p) => p`)
|
||||
- Reduce nesting depth with match syntax, plus code is more declarative
|
||||
|
||||
|
||||
Another example, before:
|
||||
|
||||
```racket
|
||||
;; Bump-and-slide: when hitting an obstacle, try to slide along it
|
||||
;; Returns (values new-x new-y) - the position after attempting to move
|
||||
(define (bump-and-slide mask x y dx dy speed)
|
||||
(define new-x (+ x dx))
|
||||
(define new-y (+ y dy))
|
||||
|
||||
;; First, try the full movement
|
||||
(cond
|
||||
[(control-mask-walkable? mask new-x new-y)
|
||||
(values new-x new-y)]
|
||||
|
||||
;; Can't move directly - try sliding
|
||||
[else
|
||||
;; Calculate the total movement magnitude
|
||||
(define move-mag (sqrt (+ (* dx dx) (* dy dy))))
|
||||
|
||||
;; Try horizontal slide with full speed
|
||||
(define slide-h-dx (if (positive? dx) move-mag (if (negative? dx) (- move-mag) 0)))
|
||||
(define slide-h-x (+ x slide-h-dx))
|
||||
(define slide-h-y y)
|
||||
|
||||
;; Try vertical slide with full speed
|
||||
(define slide-v-dy (if (positive? dy) move-mag (if (negative? dy) (- move-mag) 0)))
|
||||
(define slide-v-x x)
|
||||
(define slide-v-y (+ y slide-v-dy))
|
||||
|
||||
(cond
|
||||
;; Prefer the direction with larger movement component
|
||||
[(and (>= (abs dx) (abs dy))
|
||||
(control-mask-walkable? mask slide-h-x slide-h-y))
|
||||
(values slide-h-x slide-h-y)]
|
||||
|
||||
[(control-mask-walkable? mask slide-v-x slide-v-y)
|
||||
(values slide-v-x slide-v-y)]
|
||||
|
||||
;; Try the other direction if primary failed
|
||||
[(and (< (abs dx) (abs dy))
|
||||
(control-mask-walkable? mask slide-h-x slide-h-y))
|
||||
(values slide-h-x slide-h-y)]
|
||||
|
||||
;; Can't move at all
|
||||
[else (values x y)])]))
|
||||
```
|
||||
|
||||
After:
|
||||
|
||||
```racket
|
||||
;; Bump-and-slide: attempt full move; if blocked, try an axis-aligned slide.
|
||||
;; Returns (values new-x new-y).
|
||||
(define (bump-and-slide mask x y dx dy _speed)
|
||||
(define (walkable? x y)
|
||||
(control-mask-walkable? mask x y))
|
||||
|
||||
(define (signed-step magnitude component)
|
||||
(cond [(positive? component) magnitude]
|
||||
[(negative? component) (- magnitude)]
|
||||
[else 0]))
|
||||
|
||||
(define attempted-x (+ x dx))
|
||||
(define attempted-y (+ y dy))
|
||||
|
||||
;; First, try the full movement
|
||||
(cond
|
||||
[(walkable? attempted-x attempted-y)
|
||||
(values attempted-x attempted-y)]
|
||||
|
||||
;; Can't move directly — try sliding along one axis
|
||||
[else
|
||||
;; Use the attempted step's magnitude for an axis-aligned slide attempt.
|
||||
(define step-magnitude (sqrt (+ (* dx dx) (* dy dy))))
|
||||
|
||||
;; Candidate X-axis slide (same signed magnitude as the attempted step)
|
||||
(define x-slide-x (+ x (signed-step step-magnitude dx)))
|
||||
(define x-slide-y y)
|
||||
|
||||
;; Candidate Y-axis slide (same signed magnitude as the attempted step)
|
||||
(define y-slide-x x)
|
||||
(define y-slide-y (+ y (signed-step step-magnitude dy)))
|
||||
|
||||
(cond
|
||||
;; Prefer sliding along the axis with the larger attempted component.
|
||||
[(and (>= (abs dx) (abs dy))
|
||||
(walkable? x-slide-x x-slide-y))
|
||||
(values x-slide-x x-slide-y)]
|
||||
|
||||
[(and (< (abs dx) (abs dy))
|
||||
(walkable? y-slide-x y-slide-y))
|
||||
(values y-slide-x y-slide-y)]
|
||||
|
||||
;; If the preferred axis is blocked, try the other axis.
|
||||
[(walkable? y-slide-x y-slide-y)
|
||||
(values y-slide-x y-slide-y)]
|
||||
|
||||
[(walkable? x-slide-x x-slide-y)
|
||||
(values x-slide-x x-slide-y)]
|
||||
|
||||
;; Can't move at all.
|
||||
[else (values x y)])]))
|
||||
```
|
||||
|
||||
Notes:
|
||||
- clearer names (`magnitude` vs `mag`)
|
||||
- less clutter of defines
|
||||
- names are concise but readable (`walkable?` vs `control-mask-walkable?`)
|
||||
- Precise, clarifying per-line comments because this is a complex region / algorithm
|
||||
|
||||
Reference in New Issue
Block a user