wdyt 0.1.11 → 0.1.13
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.
- package/package.json +3 -2
- package/src/parseExpression.ts +20 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wdyt",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Code review context builder for LLMs - what do you think?",
|
|
6
6
|
"license": "MIT",
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
"prepublishOnly": "bun test"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"citty": "^0.1.6"
|
|
48
|
+
"citty": "^0.1.6",
|
|
49
|
+
"shell-quote": "^1.8.3"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
52
|
"@types/bun": "^1.1.0"
|
package/src/parseExpression.ts
CHANGED
|
@@ -7,61 +7,35 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { parseArgs } from "node:util";
|
|
10
|
+
import { parse as shellParse } from "shell-quote";
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Tokenize a shell-like string
|
|
13
|
-
*
|
|
13
|
+
* Tokenize a shell-like string
|
|
14
|
+
*
|
|
15
|
+
* Uses shell-quote for most parsing, but preserves JSON objects literally
|
|
16
|
+
* since shell-quote would strip internal quotes from JSON.
|
|
14
17
|
*/
|
|
15
18
|
export function tokenize(input: string): string[] {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let inQuote: string | null = null;
|
|
19
|
-
let escape = false;
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < input.length; i++) {
|
|
22
|
-
const char = input[i];
|
|
23
|
-
|
|
24
|
-
if (escape) {
|
|
25
|
-
current += char;
|
|
26
|
-
escape = false;
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (char === "\\") {
|
|
31
|
-
escape = true;
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
19
|
+
// Check if input contains a JSON object (starts with {)
|
|
20
|
+
const jsonStart = input.indexOf("{");
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} else if (inQuote === null) {
|
|
40
|
-
// Start of quoted string
|
|
41
|
-
inQuote = char;
|
|
42
|
-
} else {
|
|
43
|
-
// Different quote inside a quoted string
|
|
44
|
-
current += char;
|
|
45
|
-
}
|
|
46
|
-
continue;
|
|
47
|
-
}
|
|
22
|
+
if (jsonStart !== -1) {
|
|
23
|
+
// Split into pre-JSON and JSON parts
|
|
24
|
+
const preJson = input.slice(0, jsonStart).trim();
|
|
25
|
+
const jsonPart = input.slice(jsonStart);
|
|
48
26
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
current += char;
|
|
58
|
-
}
|
|
27
|
+
// Parse the pre-JSON part with shell-quote
|
|
28
|
+
const preTokens = preJson
|
|
29
|
+
? shellParse(preJson).filter((t): t is string => typeof t === "string")
|
|
30
|
+
: [];
|
|
59
31
|
|
|
60
|
-
|
|
61
|
-
|
|
32
|
+
// Keep the JSON part as-is
|
|
33
|
+
return [...preTokens, jsonPart];
|
|
62
34
|
}
|
|
63
35
|
|
|
64
|
-
|
|
36
|
+
// No JSON, use shell-quote for everything
|
|
37
|
+
const parsed = shellParse(input);
|
|
38
|
+
return parsed.filter((t): t is string => typeof t === "string");
|
|
65
39
|
}
|
|
66
40
|
|
|
67
41
|
/**
|