Skip to content

Commit 3f30447

Browse files
committed
use normalize command more
1 parent 00c361f commit 3f30447

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

frontend/app/view/term/osc-handlers.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,35 +45,44 @@ type Osc16162Command =
4545
| { command: "I"; data: { inputempty?: boolean } }
4646
| { command: "R"; data: Record<string, never> };
4747

48+
function normalizeCmd(decodedCmd: string): string {
49+
let normalizedCmd = decodedCmd.trim();
50+
normalizedCmd = normalizedCmd.replace(/^(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*/, "");
51+
normalizedCmd = normalizedCmd.replace(/^env\s+/, "");
52+
return normalizedCmd;
53+
}
54+
4855
function checkCommandForTelemetry(decodedCmd: string) {
4956
if (!decodedCmd) {
5057
return;
5158
}
5259

53-
if (decodedCmd.startsWith("ssh ")) {
60+
const normalizedCmd = normalizeCmd(decodedCmd);
61+
62+
if (normalizedCmd.startsWith("ssh ")) {
5463
recordTEvent("conn:connect", { "conn:conntype": "ssh-manual" });
5564
return;
5665
}
5766

5867
const editorsRegex = /^(vim|vi|nano|nvim)\b/;
59-
if (editorsRegex.test(decodedCmd)) {
68+
if (editorsRegex.test(normalizedCmd)) {
6069
recordTEvent("action:term", { "action:type": "cli-edit" });
6170
return;
6271
}
6372

6473
const tailFollowRegex = /(^|\|\s*)tail\s+-[fF]\b/;
65-
if (tailFollowRegex.test(decodedCmd)) {
74+
if (tailFollowRegex.test(normalizedCmd)) {
6675
recordTEvent("action:term", { "action:type": "cli-tailf" });
6776
return;
6877
}
6978

70-
if (isClaudeCodeCommand(decodedCmd)) {
79+
if (ClaudeCodeRegex.test(normalizedCmd)) {
7180
recordTEvent("action:term", { "action:type": "claude" });
7281
return;
7382
}
7483

7584
const opencodeRegex = /^opencode\b/;
76-
if (opencodeRegex.test(decodedCmd)) {
85+
if (opencodeRegex.test(normalizedCmd)) {
7786
recordTEvent("action:term", { "action:type": "opencode" });
7887
return;
7988
}
@@ -83,10 +92,7 @@ export function isClaudeCodeCommand(decodedCmd: string): boolean {
8392
if (!decodedCmd) {
8493
return false;
8594
}
86-
let normalizedCmd = decodedCmd.trim();
87-
normalizedCmd = normalizedCmd.replace(/^(?:\w+=(?:"[^"]*"|'[^']*'|\S+)\s+)*/, "");
88-
normalizedCmd = normalizedCmd.replace(/^env\s+/, "");
89-
return ClaudeCodeRegex.test(normalizedCmd);
95+
return ClaudeCodeRegex.test(normalizeCmd(decodedCmd));
9096
}
9197

9298
function handleShellIntegrationCommandStart(

0 commit comments

Comments
 (0)