Repository navigation
feat(jetbrains): show verbatim skill commands and skill name in permission prompt #12724
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ff149d4
86e5507
5577903
e804131
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,15 +116,30 @@ class PermissionView( | |
| val prev = requestId | ||
| requestId = permission.id | ||
|
|
||
| card.setHeader(KiloBundle.message("session.permission.title")) | ||
| val skillShell = permission.meta.raw["skillShell"] == "true" | ||
| val skill = permission.meta.raw["skill"] | ||
| card.setHeader( | ||
| if (skillShell && !skill.isNullOrBlank()) | ||
| KiloBundle.message("session.permission.skillShell.title", skill) | ||
| else KiloBundle.message("session.permission.title"), | ||
|
brunoagatao marked this conversation as resolved.
Resolved
|
||
| ) | ||
| syncDescription(description(permission)) | ||
|
|
||
| val tool = permission.name | ||
| val target = if (tool == "bash") permission.meta.command else resolveTarget(permission) | ||
| // A skill-shell bash batch shows the verbatim command list (control-char-escaped so the | ||
| // displayed command can't repaint the line). Its external_directory sibling still shows | ||
| // directories via resolveTarget; only the header carries the skill attribution. | ||
| val target = when { | ||
| skillShell && tool == "bash" -> permission.meta.skillCommands.joinToString("\n") { escapeControl(it) } | ||
|
brunoagatao marked this conversation as resolved.
Resolved
|
||
| tool == "bash" -> permission.meta.command | ||
| else -> resolveTarget(permission) | ||
| } | ||
| syncCode(tool, target) | ||
| syncDiffs(permission.meta.fileDiffs) | ||
| responding = permission.state == PermissionRequestState.RESPONDING || permission.state == PermissionRequestState.RESOLVED | ||
| rules.update(permission.meta.ruleDecisions, reset = prev != permission.id) | ||
| // Skill-shell approvals are never persisted, so no auto-approve rule toggles even if a | ||
| // future backend change starts sending candidates for this batch. | ||
| rules.update(if (skillShell) emptyList() else permission.meta.ruleDecisions, reset = prev != permission.id) | ||
| syncState(permission) | ||
| syncPrimaryText() | ||
|
|
||
|
|
@@ -265,6 +280,31 @@ class PermissionView( | |
| view.component.border = JBUI.Borders.empty() | ||
| } | ||
|
|
||
| // Escape control chars (CR/LF/ESC/etc.) and bidi/format characters so a skill command can't | ||
| // repaint the prompt or use Trojan-Source reordering to make the displayed text differ from | ||
| // what executes; newlines become a visible marker. Mirrors displayCommand in the CLI | ||
| // (packages/opencode/src/kilocode/skills/display.ts); keep the ranges in sync. | ||
| private fun escapeControl(command: String): String = buildString { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test this?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are already a couple of tests for this specifically (check these out), but I did a manual test too. For the manual test, I added the following skill: ❯ cat escape-demo/SKILL.md
---
name: escape-demo
description: Demo skill to screenshot control/bidi character escaping in the permission card.
---
Result: !`printf 'safe-part-\u202ereversed-part'`and ran the following command in Kilo IntelliJ: Can you use the escape-demo skill?Results are in the attached screenshot. The list of shell commands are indeed escaped in the approval prompt, confirming everything is working as expected 💪
|
||
| for (ch in command) { | ||
| val code = ch.code | ||
| when { | ||
| ch == '\n' -> append("\\n") | ||
| ch == '\r' -> append("\\r") | ||
| ch == '\t' -> append("\\t") | ||
| isEscapedControlOrFormat(code) -> append(if (code <= 0xff) "\\x%02x".format(code) else "\\u%04x".format(code)) | ||
| else -> append(ch) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun isEscapedControlOrFormat(code: Int): Boolean = | ||
| code < 0x20 || | ||
| code in 0x7f..0x9f || | ||
| code in 0x200e..0x200f || | ||
| code in 0x2028..0x2029 || | ||
| code in 0x202a..0x202e || | ||
| code in 0x2066..0x2069 | ||
|
|
||
| private fun description(permission: Permission): String = if (permission.name == "bash") { | ||
| permission.meta.raw["description"] ?: toolLabel(permission.name) | ||
| } else { | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.