klaude-code 1.2.20__py3-none-any.whl → 1.2.22__py3-none-any.whl
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.
- klaude_code/cli/debug.py +8 -10
- klaude_code/cli/main.py +23 -0
- klaude_code/cli/runtime.py +13 -1
- klaude_code/command/__init__.py +0 -3
- klaude_code/command/prompt-deslop.md +1 -1
- klaude_code/command/thinking_cmd.py +10 -0
- klaude_code/const/__init__.py +2 -5
- klaude_code/core/prompt.py +5 -2
- klaude_code/core/prompts/prompt-codex-gpt-5-2-codex.md +117 -0
- klaude_code/core/prompts/{prompt-codex-gpt-5-1.md → prompt-codex.md} +9 -42
- klaude_code/core/reminders.py +36 -2
- klaude_code/core/tool/__init__.py +0 -5
- klaude_code/core/tool/file/_utils.py +6 -0
- klaude_code/core/tool/file/apply_patch_tool.py +30 -72
- klaude_code/core/tool/file/diff_builder.py +151 -0
- klaude_code/core/tool/file/edit_tool.py +35 -18
- klaude_code/core/tool/file/read_tool.py +45 -86
- klaude_code/core/tool/file/write_tool.py +40 -30
- klaude_code/core/tool/shell/bash_tool.py +151 -3
- klaude_code/core/tool/web/mermaid_tool.md +26 -0
- klaude_code/protocol/commands.py +0 -1
- klaude_code/protocol/model.py +29 -10
- klaude_code/protocol/tools.py +1 -2
- klaude_code/session/export.py +75 -20
- klaude_code/session/session.py +7 -0
- klaude_code/session/templates/export_session.html +28 -0
- klaude_code/ui/renderers/common.py +26 -11
- klaude_code/ui/renderers/developer.py +0 -5
- klaude_code/ui/renderers/diffs.py +84 -0
- klaude_code/ui/renderers/tools.py +19 -98
- klaude_code/ui/rich/markdown.py +11 -1
- klaude_code/ui/rich/status.py +8 -11
- klaude_code/ui/rich/theme.py +14 -4
- {klaude_code-1.2.20.dist-info → klaude_code-1.2.22.dist-info}/METADATA +2 -1
- {klaude_code-1.2.20.dist-info → klaude_code-1.2.22.dist-info}/RECORD +37 -40
- klaude_code/command/diff_cmd.py +0 -136
- klaude_code/core/tool/file/multi_edit_tool.md +0 -42
- klaude_code/core/tool/file/multi_edit_tool.py +0 -175
- klaude_code/core/tool/memory/memory_tool.md +0 -20
- klaude_code/core/tool/memory/memory_tool.py +0 -456
- {klaude_code-1.2.20.dist-info → klaude_code-1.2.22.dist-info}/WHEEL +0 -0
- {klaude_code-1.2.20.dist-info → klaude_code-1.2.22.dist-info}/entry_points.txt +0 -0
klaude_code/cli/debug.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"""Debug utilities for CLI."""
|
|
2
2
|
|
|
3
|
-
import os
|
|
4
3
|
import subprocess
|
|
5
4
|
import sys
|
|
6
5
|
from pathlib import Path
|
|
@@ -45,16 +44,15 @@ def resolve_debug_settings(flag: bool, raw_filters: str | None) -> tuple[bool, s
|
|
|
45
44
|
def open_log_file_in_editor(path: Path) -> None:
|
|
46
45
|
"""Open the given log file in a text editor without blocking the CLI."""
|
|
47
46
|
|
|
48
|
-
editor =
|
|
47
|
+
editor = ""
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
continue
|
|
49
|
+
for cmd in ["code", "TextEdit", "notepad"]:
|
|
50
|
+
try:
|
|
51
|
+
subprocess.run(["which", cmd], check=True, capture_output=True)
|
|
52
|
+
editor = cmd
|
|
53
|
+
break
|
|
54
|
+
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
55
|
+
continue
|
|
58
56
|
|
|
59
57
|
if not editor:
|
|
60
58
|
if sys.platform == "darwin":
|
klaude_code/cli/main.py
CHANGED
|
@@ -194,6 +194,11 @@ def main_callback(
|
|
|
194
194
|
),
|
|
195
195
|
continue_: bool = typer.Option(False, "--continue", "-c", help="Continue from latest session"),
|
|
196
196
|
resume: bool = typer.Option(False, "--resume", "-r", help="Select a session to resume for this project"),
|
|
197
|
+
resume_by_id: str | None = typer.Option(
|
|
198
|
+
None,
|
|
199
|
+
"--resume-by-id",
|
|
200
|
+
help="Resume a session by its ID (must exist)",
|
|
201
|
+
),
|
|
197
202
|
select_model: bool = typer.Option(
|
|
198
203
|
False,
|
|
199
204
|
"--select-model",
|
|
@@ -224,6 +229,7 @@ def main_callback(
|
|
|
224
229
|
if ctx.invoked_subcommand is None:
|
|
225
230
|
from klaude_code.cli.runtime import AppInitConfig, run_interactive
|
|
226
231
|
from klaude_code.config.select_model import select_model_from_config
|
|
232
|
+
from klaude_code.trace import log
|
|
227
233
|
|
|
228
234
|
update_terminal_title()
|
|
229
235
|
|
|
@@ -236,6 +242,16 @@ def main_callback(
|
|
|
236
242
|
# Resolve session id before entering asyncio loop
|
|
237
243
|
# session_id=None means create a new session
|
|
238
244
|
session_id: str | None = None
|
|
245
|
+
|
|
246
|
+
resume_by_id_value = resume_by_id.strip() if resume_by_id is not None else None
|
|
247
|
+
if resume_by_id_value == "":
|
|
248
|
+
log(("Error: --resume-by-id cannot be empty", "red"))
|
|
249
|
+
raise typer.Exit(2)
|
|
250
|
+
|
|
251
|
+
if resume_by_id_value is not None and (resume or continue_):
|
|
252
|
+
log(("Error: --resume-by-id cannot be combined with --resume/--continue", "red"))
|
|
253
|
+
raise typer.Exit(2)
|
|
254
|
+
|
|
239
255
|
if resume:
|
|
240
256
|
session_id = resume_select_session()
|
|
241
257
|
if session_id is None:
|
|
@@ -243,6 +259,13 @@ def main_callback(
|
|
|
243
259
|
# If user didn't pick, allow fallback to --continue
|
|
244
260
|
if session_id is None and continue_:
|
|
245
261
|
session_id = Session.most_recent_session_id()
|
|
262
|
+
|
|
263
|
+
if resume_by_id_value is not None:
|
|
264
|
+
if not Session.exists(resume_by_id_value):
|
|
265
|
+
log((f"Error: session id '{resume_by_id_value}' not found for this project", "red"))
|
|
266
|
+
log(("Hint: run `klaude --resume` to select an existing session", "yellow"))
|
|
267
|
+
raise typer.Exit(2)
|
|
268
|
+
session_id = resume_by_id_value
|
|
246
269
|
# If still no session_id, leave as None to create a new session
|
|
247
270
|
|
|
248
271
|
if session_id is not None and chosen_model is None:
|
klaude_code/cli/runtime.py
CHANGED
|
@@ -17,7 +17,7 @@ from klaude_code.core.executor import Executor
|
|
|
17
17
|
from klaude_code.core.manager import build_llm_clients
|
|
18
18
|
from klaude_code.protocol import events, op
|
|
19
19
|
from klaude_code.protocol.model import UserInputPayload
|
|
20
|
-
from klaude_code.session.session import close_default_store
|
|
20
|
+
from klaude_code.session.session import Session, close_default_store
|
|
21
21
|
from klaude_code.trace import DebugType, log, set_debug_logging
|
|
22
22
|
from klaude_code.ui.modes.repl import build_repl_status_snapshot
|
|
23
23
|
from klaude_code.ui.modes.repl.input_prompt_toolkit import REPLStatusSnapshot
|
|
@@ -212,6 +212,9 @@ async def _handle_keyboard_interrupt(executor: Executor) -> None:
|
|
|
212
212
|
"""Handle Ctrl+C by logging and sending a global interrupt."""
|
|
213
213
|
|
|
214
214
|
log("Bye!")
|
|
215
|
+
session_id = executor.context.current_session_id()
|
|
216
|
+
if session_id and Session.exists(session_id):
|
|
217
|
+
log(("Resume with:", "dim"), (f"klaude --resume-by-id {session_id}", "green"))
|
|
215
218
|
# Executor might already be stopping
|
|
216
219
|
with contextlib.suppress(Exception):
|
|
217
220
|
await executor.submit(op.InterruptOperation(target_session_id=None))
|
|
@@ -296,6 +299,8 @@ async def run_interactive(init_config: AppInitConfig, session_id: str | None = N
|
|
|
296
299
|
|
|
297
300
|
restore_sigint = install_sigint_double_press_exit(_show_toast_once, _hide_progress)
|
|
298
301
|
|
|
302
|
+
exit_hint_printed = False
|
|
303
|
+
|
|
299
304
|
try:
|
|
300
305
|
await initialize_session(components.executor, components.event_queue, session_id=session_id)
|
|
301
306
|
_backfill_session_model_config(
|
|
@@ -347,8 +352,15 @@ async def run_interactive(init_config: AppInitConfig, session_id: str | None = N
|
|
|
347
352
|
|
|
348
353
|
except KeyboardInterrupt:
|
|
349
354
|
await _handle_keyboard_interrupt(components.executor)
|
|
355
|
+
exit_hint_printed = True
|
|
350
356
|
finally:
|
|
351
357
|
# Restore original SIGINT handler
|
|
352
358
|
with contextlib.suppress(Exception):
|
|
353
359
|
restore_sigint()
|
|
354
360
|
await cleanup_app_components(components)
|
|
361
|
+
|
|
362
|
+
if not exit_hint_printed:
|
|
363
|
+
active_session_id = components.executor.context.current_session_id()
|
|
364
|
+
if active_session_id and Session.exists(active_session_id):
|
|
365
|
+
log(f"Session ID: {active_session_id}")
|
|
366
|
+
log(f"Resume with: klaude --resume-by-id {active_session_id}")
|
klaude_code/command/__init__.py
CHANGED
|
@@ -29,7 +29,6 @@ def ensure_commands_loaded() -> None:
|
|
|
29
29
|
# Import and register commands in display order
|
|
30
30
|
from .clear_cmd import ClearCommand
|
|
31
31
|
from .debug_cmd import DebugCommand
|
|
32
|
-
from .diff_cmd import DiffCommand
|
|
33
32
|
from .export_cmd import ExportCommand
|
|
34
33
|
from .export_online_cmd import ExportOnlineCommand
|
|
35
34
|
from .help_cmd import HelpCommand
|
|
@@ -48,7 +47,6 @@ def ensure_commands_loaded() -> None:
|
|
|
48
47
|
register(ModelCommand())
|
|
49
48
|
load_prompt_commands()
|
|
50
49
|
register(StatusCommand())
|
|
51
|
-
register(DiffCommand())
|
|
52
50
|
register(HelpCommand())
|
|
53
51
|
register(ReleaseNotesCommand())
|
|
54
52
|
register(TerminalSetupCommand())
|
|
@@ -63,7 +61,6 @@ def __getattr__(name: str) -> object:
|
|
|
63
61
|
_commands_map = {
|
|
64
62
|
"ClearCommand": "clear_cmd",
|
|
65
63
|
"DebugCommand": "debug_cmd",
|
|
66
|
-
"DiffCommand": "diff_cmd",
|
|
67
64
|
"ExportCommand": "export_cmd",
|
|
68
65
|
"ExportOnlineCommand": "export_online_cmd",
|
|
69
66
|
"HelpCommand": "help_cmd",
|
|
@@ -3,7 +3,7 @@ description: Remove AI code slop
|
|
|
3
3
|
from: https://cursor.com/cn/link/command?name=deslop&text=%23%20Remove%20AI%20code%20slop%0A%0ACheck%20the%20diff%20against%20main%2C%20and%20remove%20all%20AI%20generated%20slop%20introduced%20in%20this%20branch.%0A%0AThis%20includes%3A%0A-%20Extra%20comments%20that%20a%20human%20wouldn%27t%20add%20or%20is%20inconsistent%20with%20the%20rest%20of%20the%20file%0A-%20Extra%20defensive%20checks%20or%20try%2Fcatch%20blocks%20that%20are%20abnormal%20for%20that%20area%20of%20the%20codebase%20(especially%20if%20called%20by%20trusted%20%2F%20validated%20codepaths)%0A-%20Casts%20to%20any%20to%20get%20around%20type%20issues%0A-%20Any%20other%20style%20that%20is%20inconsistent%20with%20the%20file%0A%0AReport%20at%20the%20end%20with%20only%20a%201-3%20sentence%20summary%20of%20what%20you%20changed
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
Check
|
|
6
|
+
Check $ARGUMENTS, and remove all AI generated slop.
|
|
7
7
|
|
|
8
8
|
This includes:
|
|
9
9
|
- Extra comments that a human wouldn't add or is inconsistent with the rest of the file
|
|
@@ -10,6 +10,7 @@ RESPONSES_LEVELS = ["low", "medium", "high"]
|
|
|
10
10
|
RESPONSES_GPT51_LEVELS = ["none", "low", "medium", "high"]
|
|
11
11
|
RESPONSES_GPT52_LEVELS = ["none", "low", "medium", "high", "xhigh"]
|
|
12
12
|
RESPONSES_CODEX_MAX_LEVELS = ["medium", "high", "xhigh"]
|
|
13
|
+
RESPONSES_GEMINI_FLASH_LEVELS = ["minimal", "low", "medium", "high"]
|
|
13
14
|
|
|
14
15
|
ANTHROPIC_LEVELS: list[tuple[str, int | None]] = [
|
|
15
16
|
("off", 0),
|
|
@@ -48,6 +49,13 @@ def _is_codex_max_model(model_name: str | None) -> bool:
|
|
|
48
49
|
return "codex-max" in model_name.lower()
|
|
49
50
|
|
|
50
51
|
|
|
52
|
+
def _is_gemini_flash_model(model_name: str | None) -> bool:
|
|
53
|
+
"""Check if the model is Gemini 3 Flash."""
|
|
54
|
+
if not model_name:
|
|
55
|
+
return False
|
|
56
|
+
return "gemini-3-flash" in model_name.lower()
|
|
57
|
+
|
|
58
|
+
|
|
51
59
|
def _get_levels_for_responses(model_name: str | None) -> list[str]:
|
|
52
60
|
"""Get thinking levels for responses protocol."""
|
|
53
61
|
if _is_codex_max_model(model_name):
|
|
@@ -56,6 +64,8 @@ def _get_levels_for_responses(model_name: str | None) -> list[str]:
|
|
|
56
64
|
return RESPONSES_GPT52_LEVELS
|
|
57
65
|
if _is_gpt51_model(model_name):
|
|
58
66
|
return RESPONSES_GPT51_LEVELS
|
|
67
|
+
if _is_gemini_flash_model(model_name):
|
|
68
|
+
return RESPONSES_GEMINI_FLASH_LEVELS
|
|
59
69
|
return RESPONSES_LEVELS
|
|
60
70
|
|
|
61
71
|
|
klaude_code/const/__init__.py
CHANGED
|
@@ -49,12 +49,9 @@ READ_CHAR_LIMIT_PER_LINE = 2000
|
|
|
49
49
|
# Maximum number of lines to read from a file
|
|
50
50
|
READ_GLOBAL_LINE_CAP = 2000
|
|
51
51
|
|
|
52
|
-
# Maximum total characters to read
|
|
52
|
+
# Maximum total characters to read (truncates beyond this limit)
|
|
53
53
|
READ_MAX_CHARS = 50000
|
|
54
54
|
|
|
55
|
-
# Maximum file size in KB for text files
|
|
56
|
-
READ_MAX_KB = 256
|
|
57
|
-
|
|
58
55
|
# Maximum image file size in bytes (4MB)
|
|
59
56
|
READ_MAX_IMAGE_BYTES = 4 * 1024 * 1024
|
|
60
57
|
|
|
@@ -103,7 +100,7 @@ SUB_AGENT_RESULT_MAX_LINES = 12
|
|
|
103
100
|
UI_REFRESH_RATE_FPS = 20
|
|
104
101
|
|
|
105
102
|
# Number of lines to keep visible at bottom of markdown streaming window
|
|
106
|
-
MARKDOWN_STREAM_LIVE_WINDOW =
|
|
103
|
+
MARKDOWN_STREAM_LIVE_WINDOW = 6
|
|
107
104
|
|
|
108
105
|
# Status hint text shown after spinner status
|
|
109
106
|
STATUS_HINT_TEXT = " (esc to interrupt)"
|
klaude_code/core/prompt.py
CHANGED
|
@@ -17,8 +17,9 @@ COMMAND_DESCRIPTIONS: dict[str, str] = {
|
|
|
17
17
|
|
|
18
18
|
# Mapping from logical prompt keys to resource file paths under the core/prompt directory.
|
|
19
19
|
PROMPT_FILES: dict[str, str] = {
|
|
20
|
-
"
|
|
20
|
+
"main_codex": "prompts/prompt-codex.md",
|
|
21
21
|
"main_gpt_5_1_codex_max": "prompts/prompt-codex-gpt-5-1-codex-max.md",
|
|
22
|
+
"main_gpt_5_2_codex": "prompts/prompt-codex-gpt-5-2-codex.md",
|
|
22
23
|
"main": "prompts/prompt-claude-code.md",
|
|
23
24
|
"main_gemini": "prompts/prompt-gemini.md", # https://ai.google.dev/gemini-api/docs/prompting-strategies?hl=zh-cn#agentic-si-template
|
|
24
25
|
}
|
|
@@ -43,10 +44,12 @@ def _load_base_prompt(file_key: str) -> str:
|
|
|
43
44
|
def _get_file_key(model_name: str, protocol: llm_param.LLMClientProtocol) -> str:
|
|
44
45
|
"""Determine which prompt file to use based on model."""
|
|
45
46
|
match model_name:
|
|
47
|
+
case name if "gpt-5.2-codex" in name:
|
|
48
|
+
return "main_gpt_5_2_codex"
|
|
46
49
|
case name if "gpt-5.1-codex-max" in name:
|
|
47
50
|
return "main_gpt_5_1_codex_max"
|
|
48
51
|
case name if "gpt-5" in name:
|
|
49
|
-
return "
|
|
52
|
+
return "main_codex"
|
|
50
53
|
case name if "gemini" in name:
|
|
51
54
|
return "main_gemini"
|
|
52
55
|
case _:
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
You are Codex, based on GPT-5. You are running as a coding agent in the Codex CLI on a user's computer.
|
|
2
|
+
|
|
3
|
+
## General
|
|
4
|
+
|
|
5
|
+
- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)
|
|
6
|
+
|
|
7
|
+
## Editing constraints
|
|
8
|
+
|
|
9
|
+
- Default to ASCII when editing or creating files. Only introduce non-ASCII or other Unicode characters when there is a clear justification and the file already uses them.
|
|
10
|
+
- Add succinct code comments that explain what is going on if code is not self-explanatory. You should not add comments like "Assigns the value to the variable", but a brief comment might be useful ahead of a complex code block that the user would otherwise have to spend time parsing out. Usage of these comments should be rare.
|
|
11
|
+
- Try to use apply_patch for single file edits, but it is fine to explore other options to make the edit if it does not work well. Do not use apply_patch for changes that are auto-generated (i.e. generating package.json or running a lint or format command like gofmt) or when scripting is more efficient (such as search and replacing a string across a codebase).
|
|
12
|
+
- You may be in a dirty git worktree.
|
|
13
|
+
* NEVER revert existing changes you did not make unless explicitly requested, since these changes were made by the user.
|
|
14
|
+
* If asked to make a commit or code edits and there are unrelated changes to your work or changes that you didn't make in those files, don't revert those changes.
|
|
15
|
+
* If the changes are in files you've touched recently, you should read carefully and understand how you can work with the changes rather than reverting them.
|
|
16
|
+
* If the changes are in unrelated files, just ignore them and don't revert them.
|
|
17
|
+
- Do not amend a commit unless explicitly requested to do so.
|
|
18
|
+
- While you are working, you might notice unexpected changes that you didn't make. If this happens, STOP IMMEDIATELY and ask the user how they would like to proceed.
|
|
19
|
+
- **NEVER** use destructive commands like `git reset --hard` or `git checkout --` unless specifically requested or approved by the user.
|
|
20
|
+
|
|
21
|
+
## Plan tool
|
|
22
|
+
|
|
23
|
+
When using the planning tool:
|
|
24
|
+
- Skip using the planning tool for straightforward tasks (roughly the easiest 25%).
|
|
25
|
+
- Do not make single-step plans.
|
|
26
|
+
- When you made a plan, update it after having performed one of the sub-tasks that you shared on the plan.
|
|
27
|
+
|
|
28
|
+
## Codex CLI harness, sandboxing, and approvals
|
|
29
|
+
|
|
30
|
+
The Codex CLI harness supports several different configurations for sandboxing and escalation approvals that the user can choose from.
|
|
31
|
+
|
|
32
|
+
Filesystem sandboxing defines which files can be read or written. The options for `sandbox_mode` are:
|
|
33
|
+
- **read-only**: The sandbox only permits reading files.
|
|
34
|
+
- **workspace-write**: The sandbox permits reading files, and editing files in `cwd` and `writable_roots`. Editing files in other directories requires approval.
|
|
35
|
+
- **danger-full-access**: No filesystem sandboxing - all commands are permitted.
|
|
36
|
+
|
|
37
|
+
Network sandboxing defines whether network can be accessed without approval. Options for `network_access` are:
|
|
38
|
+
- **restricted**: Requires approval
|
|
39
|
+
- **enabled**: No approval needed
|
|
40
|
+
|
|
41
|
+
Approvals are your mechanism to get user consent to run shell commands without the sandbox. Possible configuration options for `approval_policy` are
|
|
42
|
+
- **untrusted**: The harness will escalate most commands for user approval, apart from a limited allowlist of safe "read" commands.
|
|
43
|
+
- **on-failure**: The harness will allow all commands to run in the sandbox (if enabled), and failures will be escalated to the user for approval to run again without the sandbox.
|
|
44
|
+
- **on-request**: Commands will be run in the sandbox by default, and you can specify in your tool call if you want to escalate a command to run without sandboxing. (Note that this mode is not always available. If it is, you'll see parameters for it in the `shell` command description.)
|
|
45
|
+
- **never**: This is a non-interactive mode where you may NEVER ask the user for approval to run commands. Instead, you must always persist and work around constraints to solve the task for the user. You MUST do your utmost best to finish the task and validate your work before yielding. If this mode is paired with `danger-full-access`, take advantage of it to deliver the best outcome for the user. Further, in this mode, your default testing philosophy is overridden: Even if you don't see local patterns for testing, you may add tests and scripts to validate your work. Just remove them before yielding.
|
|
46
|
+
|
|
47
|
+
When you are running with `approval_policy == on-request`, and sandboxing enabled, here are scenarios where you'll need to request approval:
|
|
48
|
+
- You need to run a command that writes to a directory that requires it (e.g. running tests that write to /var)
|
|
49
|
+
- You need to run a GUI app (e.g., open/xdg-open/osascript) to open browsers or files.
|
|
50
|
+
- You are running sandboxed and need to run a command that requires network access (e.g. installing packages)
|
|
51
|
+
- If you run a command that is important to solving the user's query, but it fails because of sandboxing, rerun the command with approval. ALWAYS proceed to use the `sandbox_permissions` and `justification` parameters - do not message the user before requesting approval for the command.
|
|
52
|
+
- You are about to take a potentially destructive action such as an `rm` or `git reset` that the user did not explicitly ask for
|
|
53
|
+
- (for all of these, you should weigh alternative paths that do not require approval)
|
|
54
|
+
|
|
55
|
+
When `sandbox_mode` is set to read-only, you'll need to request approval for any command that isn't a read.
|
|
56
|
+
|
|
57
|
+
You will be told what filesystem sandboxing, network sandboxing, and approval mode are active in a developer or user message. If you are not told about this, assume that you are running with workspace-write, network sandboxing enabled, and approval on-failure.
|
|
58
|
+
|
|
59
|
+
Although they introduce friction to the user because your work is paused until the user responds, you should leverage them when necessary to accomplish important work. If the completing the task requires escalated permissions, Do not let these settings or the sandbox deter you from attempting to accomplish the user's task unless it is set to "never", in which case never ask for approvals.
|
|
60
|
+
|
|
61
|
+
When requesting approval to execute a command that will require escalated privileges:
|
|
62
|
+
- Provide the `sandbox_permissions` parameter with the value `"require_escalated"`
|
|
63
|
+
- Include a short, 1 sentence explanation for why you need escalated permissions in the justification parameter
|
|
64
|
+
|
|
65
|
+
## Special user requests
|
|
66
|
+
|
|
67
|
+
- If the user makes a simple request (such as asking for the time) which you can fulfill by running a terminal command (such as `date`), you should do so.
|
|
68
|
+
- If the user asks for a "review", default to a code review mindset: prioritise identifying bugs, risks, behavioural regressions, and missing tests. Findings must be the primary focus of the response - keep summaries or overviews brief and only after enumerating the issues. Present findings first (ordered by severity with file/line references), follow with open questions or assumptions, and offer a change-summary only as a secondary detail. If no findings are discovered, state that explicitly and mention any residual risks or testing gaps.
|
|
69
|
+
|
|
70
|
+
## Frontend tasks
|
|
71
|
+
When doing frontend design tasks, avoid collapsing into "AI slop" or safe, average-looking layouts.
|
|
72
|
+
Aim for interfaces that feel intentional, bold, and a bit surprising.
|
|
73
|
+
- Typography: Use expressive, purposeful fonts and avoid default stacks (Inter, Roboto, Arial, system).
|
|
74
|
+
- Color & Look: Choose a clear visual direction; define CSS variables; avoid purple-on-white defaults. No purple bias or dark mode bias.
|
|
75
|
+
- Motion: Use a few meaningful animations (page-load, staggered reveals) instead of generic micro-motions.
|
|
76
|
+
- Background: Don't rely on flat, single-color backgrounds; use gradients, shapes, or subtle patterns to build atmosphere.
|
|
77
|
+
- Overall: Avoid boilerplate layouts and interchangeable UI patterns. Vary themes, type families, and visual languages across outputs.
|
|
78
|
+
- Ensure the page loads properly on both desktop and mobile
|
|
79
|
+
|
|
80
|
+
Exception: If working within an existing website or design system, preserve the established patterns, structure, and visual language.
|
|
81
|
+
|
|
82
|
+
## Presenting your work and final message
|
|
83
|
+
|
|
84
|
+
You are producing plain text that will later be styled by the CLI. Follow these rules exactly. Formatting should make results easy to scan, but not feel mechanical. Use judgment to decide how much structure adds value.
|
|
85
|
+
|
|
86
|
+
- Default: be very concise; friendly coding teammate tone.
|
|
87
|
+
- Ask only when needed; suggest ideas; mirror the user's style.
|
|
88
|
+
- For substantial work, summarize clearly; follow final‑answer formatting.
|
|
89
|
+
- Skip heavy formatting for simple confirmations.
|
|
90
|
+
- Don't dump large files you've written; reference paths only.
|
|
91
|
+
- No "save/copy this file" - User is on the same machine.
|
|
92
|
+
- Offer logical next steps (tests, commits, build) briefly; add verify steps if you couldn't do something.
|
|
93
|
+
- For code changes:
|
|
94
|
+
* Lead with a quick explanation of the change, and then give more details on the context covering where and why a change was made. Do not start this explanation with "summary", just jump right in.
|
|
95
|
+
* If there are natural next steps the user may want to take, suggest them at the end of your response. Do not make suggestions if there are no natural next steps.
|
|
96
|
+
* When suggesting multiple options, use numeric lists for the suggestions so the user can quickly respond with a single number.
|
|
97
|
+
- The user does not command execution outputs. When asked to show the output of a command (e.g. `git show`), relay the important details in your answer or summarize the key lines so the user understands the result.
|
|
98
|
+
|
|
99
|
+
### Final answer structure and style guidelines
|
|
100
|
+
|
|
101
|
+
- Plain text; CLI handles styling. Use structure only when it helps scanability.
|
|
102
|
+
- Headers: optional; short Title Case (1-3 words) wrapped in **…**; no blank line before the first bullet; add only if they truly help.
|
|
103
|
+
- Bullets: use - ; merge related points; keep to one line when possible; 4–6 per list ordered by importance; keep phrasing consistent.
|
|
104
|
+
- Monospace: backticks for commands/paths/env vars/code ids and inline examples; use for literal keyword bullets; never combine with **.
|
|
105
|
+
- Code samples or multi-line snippets should be wrapped in fenced code blocks; include an info string as often as possible.
|
|
106
|
+
- Structure: group related bullets; order sections general → specific → supporting; for subsections, start with a bolded keyword bullet, then items; match complexity to the task.
|
|
107
|
+
- Tone: collaborative, concise, factual; present tense, active voice; self‑contained; no "above/below"; parallel wording.
|
|
108
|
+
- Don'ts: no nested bullets/hierarchies; no ANSI codes; don't cram unrelated keywords; keep keyword lists short—wrap/reformat if long; avoid naming formatting styles in answers.
|
|
109
|
+
- Adaptation: code explanations → precise, structured with code refs; simple tasks → lead with outcome; big changes → logical walkthrough + rationale + next actions; casual one-offs → plain sentences, no headers/bullets.
|
|
110
|
+
- File References: When referencing files in your response follow the below rules:
|
|
111
|
+
* Use inline code to make file paths clickable.
|
|
112
|
+
* Each reference should have a stand alone path. Even if it's the same file.
|
|
113
|
+
* Accepted: absolute, workspace‑relative, a/ or b/ diff prefixes, or bare filename/suffix.
|
|
114
|
+
* Optionally include line/column (1‑based): :line[:column] or #Lline[Ccolumn] (column defaults to 1).
|
|
115
|
+
* Do not use URIs like file://, vscode://, or https://.
|
|
116
|
+
* Do not provide range of lines
|
|
117
|
+
* Examples: src/app.ts, src/app.ts:42, b/server/index.js#L10, C:\repo\project\main.rs:12:5
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
You are GPT-5.
|
|
1
|
+
You are GPT-5.2 running in the Codex CLI, a terminal-based coding assistant. Codex CLI is an open source project led by OpenAI. You are expected to be precise, safe, and helpful.
|
|
2
2
|
|
|
3
3
|
Your capabilities:
|
|
4
4
|
|
|
@@ -14,7 +14,7 @@ Within this context, Codex refers to the open-source agentic coding interface (n
|
|
|
14
14
|
|
|
15
15
|
Your default personality and tone is concise, direct, and friendly. You communicate efficiently, always keeping the user clearly informed about ongoing actions without unnecessary detail. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
## AGENTS.md spec
|
|
18
18
|
- Repos often contain AGENTS.md files. These files can appear anywhere within the repository.
|
|
19
19
|
- These files are a way for humans to give you (the agent) instructions or tips for working within the container.
|
|
20
20
|
- Some examples might be: coding conventions, info about how code is organized, or instructions for how to run or test code.
|
|
@@ -24,7 +24,7 @@ Your default personality and tone is concise, direct, and friendly. You communic
|
|
|
24
24
|
- Instructions about code style, structure, naming, etc. apply only to code within the AGENTS.md file's scope, unless the file states otherwise.
|
|
25
25
|
- More-deeply-nested AGENTS.md files take precedence in the case of conflicting instructions.
|
|
26
26
|
- Direct system/developer/user instructions (as part of a prompt) take precedence over AGENTS.md instructions.
|
|
27
|
-
- The contents of the AGENTS.md file at the root of the repo and any directories from the CWD up to the root
|
|
27
|
+
- The contents of the AGENTS.md file at the root of the repo and any directories from the CWD up to the root are included with the developer message and don't need to be re-read. When working in a subdirectory of CWD, or a directory outside the CWD, check for any AGENTS.md files that may be applicable.
|
|
28
28
|
|
|
29
29
|
## Autonomy and Persistence
|
|
30
30
|
Persist until the task is fully handled end-to-end within the current turn whenever feasible: do not stop at analysis or partial fixes; carry changes through implementation, verification, and a clear explanation of outcomes unless the user explicitly pauses or redirects you.
|
|
@@ -33,33 +33,6 @@ Unless the user explicitly asks for a plan, asks a question about the code, is b
|
|
|
33
33
|
|
|
34
34
|
## Responsiveness
|
|
35
35
|
|
|
36
|
-
### User Updates Spec
|
|
37
|
-
You'll work for stretches with tool calls — it's critical to keep the user updated as you work.
|
|
38
|
-
|
|
39
|
-
Frequency & Length:
|
|
40
|
-
- Send short updates (1–2 sentences) whenever there is a meaningful, important insight you need to share with the user to keep them informed.
|
|
41
|
-
- If you expect a longer heads‑down stretch, post a brief heads‑down note with why and when you'll report back; when you resume, summarize what you learned.
|
|
42
|
-
- Only the initial plan, plan updates, and final recap can be longer, with multiple bullets and paragraphs
|
|
43
|
-
|
|
44
|
-
Tone:
|
|
45
|
-
- Friendly, confident, senior-engineer energy. Positive, collaborative, humble; fix mistakes quickly.
|
|
46
|
-
|
|
47
|
-
Content:
|
|
48
|
-
- Before the first tool call, give a quick plan with goal, constraints, next steps.
|
|
49
|
-
- While you're exploring, call out meaningful new information and discoveries that you find that helps the user understand what's happening and how you're approaching the solution.
|
|
50
|
-
- If you change the plan (e.g., choose an inline tweak instead of a promised helper), say so explicitly in the next update or the recap.
|
|
51
|
-
|
|
52
|
-
**Examples:**
|
|
53
|
-
|
|
54
|
-
- “I’ve explored the repo; now checking the API route definitions.”
|
|
55
|
-
- “Next, I’ll patch the config and update the related tests.”
|
|
56
|
-
- “I’m about to scaffold the CLI commands and helper functions.”
|
|
57
|
-
- “Ok cool, so I’ve wrapped my head around the repo. Now digging into the API routes.”
|
|
58
|
-
- “Config’s looking tidy. Next up is patching helpers to keep things in sync.”
|
|
59
|
-
- “Finished poking at the DB gateway. I will now chase down error handling.”
|
|
60
|
-
- “Alright, build pipeline order is interesting. Checking how it reports failures.”
|
|
61
|
-
- “Spotted a clever caching util; now hunting where it gets used.”
|
|
62
|
-
|
|
63
36
|
## Planning
|
|
64
37
|
|
|
65
38
|
You have access to an `update_plan` tool which tracks steps and progress and renders them to the user. Using the tool helps demonstrate that you've understood the task and convey how you're approaching it. Plans can help to make complex, ambiguous, or multi-phase work clearer and more collaborative for the user. A good plan should break the task into meaningful, logically ordered steps that are easy to verify as you go.
|
|
@@ -142,7 +115,7 @@ You MUST adhere to the following criteria when solving queries:
|
|
|
142
115
|
- Working on the repo(s) in the current environment is allowed, even if they are proprietary.
|
|
143
116
|
- Analyzing code for vulnerabilities is allowed.
|
|
144
117
|
- Showing user code and tool call details is allowed.
|
|
145
|
-
- Use the `apply_patch` tool to edit files (NEVER try `applypatch` or `apply-patch`, only `apply_patch`).
|
|
118
|
+
- Use the `apply_patch` tool to edit files (NEVER try `applypatch` or `apply-patch`, only `apply_patch`). This is a FREEFORM tool, so do not wrap the patch in JSON.
|
|
146
119
|
|
|
147
120
|
If completing the user's task requires writing or modifying files, your code and final answer should follow these coding guidelines, though user instructions (i.e. AGENTS.md) may override these guidelines:
|
|
148
121
|
|
|
@@ -151,6 +124,7 @@ If completing the user's task requires writing or modifying files, your code and
|
|
|
151
124
|
- Do not attempt to fix unrelated bugs or broken tests. It is not your responsibility to fix them. (You may mention them to the user in your final message though.)
|
|
152
125
|
- Update documentation as necessary.
|
|
153
126
|
- Keep changes consistent with the style of the existing codebase. Changes should be minimal and focused on the task.
|
|
127
|
+
- If you're building a web app from scratch, give it a beautiful and modern UI, imbued with best UX practices.
|
|
154
128
|
- Use `git log` and `git blame` to search the history of the codebase if additional context is required.
|
|
155
129
|
- NEVER add copyright or license headers unless specifically requested.
|
|
156
130
|
- Do not waste tokens by re-reading files after calling `apply_patch` on them. The tool call will fail if it didn't work. The same goes for making folders, deleting folders, etc.
|
|
@@ -161,7 +135,7 @@ If completing the user's task requires writing or modifying files, your code and
|
|
|
161
135
|
|
|
162
136
|
## Validating your work
|
|
163
137
|
|
|
164
|
-
If the codebase has tests or the ability to build or run, consider using them to verify changes once your work is complete.
|
|
138
|
+
If the codebase has tests, or the ability to build or run tests, consider using them to verify changes once your work is complete.
|
|
165
139
|
|
|
166
140
|
When testing, your philosophy should be to start as specific as possible to the code you changed so that you can catch issues efficiently, then make your way to broader tests as you build confidence. If there's no test for the code you changed, and if the adjacent patterns in the codebases show that there's a logical place for you to add a test, you may do so. However, do not add tests to codebases with no tests.
|
|
167
141
|
|
|
@@ -183,15 +157,7 @@ If you're operating in an existing codebase, you should make sure you do exactly
|
|
|
183
157
|
|
|
184
158
|
You should use judicious initiative to decide on the right level of detail and complexity to deliver based on the user's needs. This means showing good judgment that you're capable of doing the right extras without gold-plating. This might be demonstrated by high-value, creative touches when scope of the task is vague; while being surgical and targeted when scope is tightly specified.
|
|
185
159
|
|
|
186
|
-
##
|
|
187
|
-
|
|
188
|
-
For especially longer tasks that you work on (i.e. requiring many tool calls, or a plan with multiple steps), you should provide progress updates back to the user at reasonable intervals. These updates should be structured as a concise sentence or two (no more than 8-10 words long) recapping progress so far in plain language: this update demonstrates your understanding of what needs to be done, progress so far (i.e. files explores, subtasks complete), and where you're going next.
|
|
189
|
-
|
|
190
|
-
Before doing large chunks of work that may incur latency as experienced by the user (i.e. writing a new file), you should send a concise message to the user with an update indicating what you're about to do to ensure they know what you're spending time on. Don't start editing or writing large files before informing the user what you are doing and why.
|
|
191
|
-
|
|
192
|
-
The messages you send before tool calls should describe what is immediately about to be done next in very concise language. If there was previous work done, this preamble message should also include a note about the work done so far to bring the user along.
|
|
193
|
-
|
|
194
|
-
## Presenting your work and final message
|
|
160
|
+
## Presenting your work
|
|
195
161
|
|
|
196
162
|
Your final message should read naturally, like an update from a concise teammate. For casual conversation, brainstorming tasks, or quick questions from the user, respond in a friendly, conversational tone. You should ask questions, suggest ideas, and adapt to the user’s style. If you've finished a large amount of work, when describing what you've done to the user, you should follow the final answer formatting guidelines to communicate substantive changes. You don't need to add structured formatting for one-word answers, greetings, or purely conversational exchanges.
|
|
197
163
|
|
|
@@ -282,7 +248,8 @@ For casual greetings, acknowledgements, or other one-off conversational messages
|
|
|
282
248
|
When using the shell, you must adhere to the following guidelines:
|
|
283
249
|
|
|
284
250
|
- When searching for text or files, prefer using `rg` or `rg --files` respectively because `rg` is much faster than alternatives like `grep`. (If the `rg` command is not found, then use alternatives.)
|
|
285
|
-
-
|
|
251
|
+
- Do not use python scripts to attempt to output larger chunks of a file.
|
|
252
|
+
- Parallelize tool calls whenever possible - especially file reads, such as `cat`, `rg`, `sed`, `ls`, `git show`, `nl`, `wc`. Use `multi_tool_use.parallel` to parallelize tool calls and only this.
|
|
286
253
|
|
|
287
254
|
## apply_patch
|
|
288
255
|
|
klaude_code/core/reminders.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import hashlib
|
|
1
2
|
import re
|
|
2
3
|
import shlex
|
|
3
4
|
from collections.abc import Awaitable, Callable
|
|
@@ -8,6 +9,7 @@ from pydantic import BaseModel
|
|
|
8
9
|
|
|
9
10
|
from klaude_code import const
|
|
10
11
|
from klaude_code.core.tool import BashTool, ReadTool, reset_tool_context, set_tool_context_from_session
|
|
12
|
+
from klaude_code.core.tool.file._utils import hash_text_sha256
|
|
11
13
|
from klaude_code.protocol import model, tools
|
|
12
14
|
from klaude_code.session import Session
|
|
13
15
|
|
|
@@ -262,7 +264,17 @@ async def file_changed_externally_reminder(
|
|
|
262
264
|
if session.file_tracker and len(session.file_tracker) > 0:
|
|
263
265
|
for path, status in session.file_tracker.items():
|
|
264
266
|
try:
|
|
265
|
-
|
|
267
|
+
current_mtime = Path(path).stat().st_mtime
|
|
268
|
+
|
|
269
|
+
changed = False
|
|
270
|
+
if status.content_sha256 is not None:
|
|
271
|
+
current_sha256 = _compute_file_content_sha256(path)
|
|
272
|
+
changed = current_sha256 is not None and current_sha256 != status.content_sha256
|
|
273
|
+
else:
|
|
274
|
+
# Backward-compat: old sessions only tracked mtime.
|
|
275
|
+
changed = current_mtime != status.mtime
|
|
276
|
+
|
|
277
|
+
if changed:
|
|
266
278
|
context_token = set_tool_context_from_session(session)
|
|
267
279
|
try:
|
|
268
280
|
tool_result = await ReadTool.call_with_args(
|
|
@@ -299,6 +311,24 @@ async def file_changed_externally_reminder(
|
|
|
299
311
|
return None
|
|
300
312
|
|
|
301
313
|
|
|
314
|
+
def _compute_file_content_sha256(path: str) -> str | None:
|
|
315
|
+
"""Compute SHA-256 for file content using the same decoding behavior as ReadTool."""
|
|
316
|
+
|
|
317
|
+
try:
|
|
318
|
+
suffix = Path(path).suffix.lower()
|
|
319
|
+
if suffix in {".png", ".jpg", ".jpeg", ".gif", ".webp"}:
|
|
320
|
+
with open(path, "rb") as f:
|
|
321
|
+
return hashlib.sha256(f.read()).hexdigest()
|
|
322
|
+
|
|
323
|
+
hasher = hashlib.sha256()
|
|
324
|
+
with open(path, encoding="utf-8", errors="replace") as f:
|
|
325
|
+
for line in f:
|
|
326
|
+
hasher.update(line.encode("utf-8"))
|
|
327
|
+
return hasher.hexdigest()
|
|
328
|
+
except (FileNotFoundError, IsADirectoryError, OSError, PermissionError, UnicodeDecodeError):
|
|
329
|
+
return None
|
|
330
|
+
|
|
331
|
+
|
|
302
332
|
def get_memory_paths() -> list[tuple[Path, str]]:
|
|
303
333
|
return [
|
|
304
334
|
(
|
|
@@ -355,7 +385,11 @@ def _mark_memory_loaded(session: Session, path: str) -> None:
|
|
|
355
385
|
mtime = Path(path).stat().st_mtime
|
|
356
386
|
except (OSError, FileNotFoundError):
|
|
357
387
|
mtime = 0.0
|
|
358
|
-
|
|
388
|
+
try:
|
|
389
|
+
content_sha256 = hash_text_sha256(Path(path).read_text(encoding="utf-8", errors="replace"))
|
|
390
|
+
except (OSError, FileNotFoundError, PermissionError, UnicodeDecodeError):
|
|
391
|
+
content_sha256 = None
|
|
392
|
+
session.file_tracker[path] = model.FileStatus(mtime=mtime, content_sha256=content_sha256, is_memory=True)
|
|
359
393
|
|
|
360
394
|
|
|
361
395
|
async def memory_reminder(session: Session) -> model.DeveloperMessageItem | None:
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
from .file.apply_patch import DiffError, process_patch
|
|
2
2
|
from .file.apply_patch_tool import ApplyPatchTool
|
|
3
3
|
from .file.edit_tool import EditTool
|
|
4
|
-
from .file.multi_edit_tool import MultiEditTool
|
|
5
4
|
from .file.read_tool import ReadTool
|
|
6
5
|
from .file.write_tool import WriteTool
|
|
7
|
-
from .memory.memory_tool import MEMORY_DIR_NAME, MemoryTool
|
|
8
6
|
from .memory.skill_loader import Skill, SkillLoader
|
|
9
7
|
from .memory.skill_tool import SkillTool
|
|
10
8
|
from .report_back_tool import ReportBackTool
|
|
@@ -32,15 +30,12 @@ from .web.web_fetch_tool import WebFetchTool
|
|
|
32
30
|
from .web.web_search_tool import WebSearchTool
|
|
33
31
|
|
|
34
32
|
__all__ = [
|
|
35
|
-
"MEMORY_DIR_NAME",
|
|
36
33
|
"ApplyPatchTool",
|
|
37
34
|
"BashTool",
|
|
38
35
|
"DiffError",
|
|
39
36
|
"EditTool",
|
|
40
37
|
"FileTracker",
|
|
41
|
-
"MemoryTool",
|
|
42
38
|
"MermaidTool",
|
|
43
|
-
"MultiEditTool",
|
|
44
39
|
"ReadTool",
|
|
45
40
|
"ReportBackTool",
|
|
46
41
|
"SafetyCheckResult",
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
+
import hashlib
|
|
5
6
|
import os
|
|
6
7
|
from pathlib import Path
|
|
7
8
|
|
|
@@ -28,3 +29,8 @@ def write_text(path: str, content: str) -> None:
|
|
|
28
29
|
parent.mkdir(parents=True, exist_ok=True)
|
|
29
30
|
with open(path, "w", encoding="utf-8") as f:
|
|
30
31
|
f.write(content)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def hash_text_sha256(content: str) -> str:
|
|
35
|
+
"""Return SHA-256 for the given text content encoded as UTF-8."""
|
|
36
|
+
return hashlib.sha256(content.encode("utf-8")).hexdigest()
|