@travisennis/acai 0.0.11 → 0.0.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/README.md +5 -5
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +2 -5
- package/dist/commands/history/types.d.ts +3 -2
- package/dist/commands/history/types.d.ts.map +1 -1
- package/dist/commands/init-project/utils.d.ts +0 -1
- package/dist/commands/init-project/utils.d.ts.map +1 -1
- package/dist/commands/init-project/utils.js +1 -12
- package/dist/commands/manager.d.ts.map +1 -1
- package/dist/commands/manager.js +6 -19
- package/dist/commands/resources/index.d.ts.map +1 -1
- package/dist/commands/resources/index.js +4 -1
- package/dist/commands/session/index.d.ts.map +1 -1
- package/dist/commands/session/index.js +6 -0
- package/dist/commands/session/types.d.ts +1 -0
- package/dist/commands/session/types.d.ts.map +1 -1
- package/dist/commands/share/html-renderer.d.ts.map +1 -1
- package/dist/commands/share/html-renderer.js +54 -48
- package/dist/commands/tools/index.d.ts +3 -0
- package/dist/commands/tools/index.d.ts.map +1 -0
- package/dist/commands/tools/index.js +191 -0
- package/dist/commands/tools/templates.d.ts +6 -0
- package/dist/commands/tools/templates.d.ts.map +1 -0
- package/dist/commands/tools/templates.js +97 -0
- package/dist/config/index.d.ts +5 -2
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +42 -6
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +98 -68
- package/dist/models/anthropic-provider.d.ts +1 -1
- package/dist/models/deepseek-provider.d.ts +3 -3
- package/dist/models/deepseek-provider.js +17 -17
- package/dist/models/google-provider.d.ts +2 -4
- package/dist/models/google-provider.d.ts.map +1 -1
- package/dist/models/google-provider.js +2 -17
- package/dist/models/groq-provider.d.ts +2 -4
- package/dist/models/groq-provider.d.ts.map +1 -1
- package/dist/models/groq-provider.js +3 -21
- package/dist/models/manager.d.ts +1 -10
- package/dist/models/manager.d.ts.map +1 -1
- package/dist/models/manager.js +2 -2
- package/dist/models/opencode-go-provider.d.ts +11 -1
- package/dist/models/opencode-go-provider.d.ts.map +1 -1
- package/dist/models/opencode-go-provider.js +130 -0
- package/dist/models/opencode-zen-provider.d.ts +3 -3
- package/dist/models/opencode-zen-provider.d.ts.map +1 -1
- package/dist/models/opencode-zen-provider.js +26 -32
- package/dist/models/openrouter-provider.d.ts +4 -15
- package/dist/models/openrouter-provider.d.ts.map +1 -1
- package/dist/models/openrouter-provider.js +26 -169
- package/dist/models/providers.d.ts +1 -1
- package/dist/models/providers.d.ts.map +1 -1
- package/dist/models/xai-provider.d.ts +1 -2
- package/dist/models/xai-provider.d.ts.map +1 -1
- package/dist/models/xai-provider.js +0 -13
- package/dist/prompts/manager.d.ts.map +1 -1
- package/dist/prompts/manager.js +5 -1
- package/dist/prompts/system-prompt.d.ts +1 -2
- package/dist/prompts/system-prompt.d.ts.map +1 -1
- package/dist/prompts/system-prompt.js +26 -15
- package/dist/repl/index.d.ts +28 -13
- package/dist/repl/index.d.ts.map +1 -1
- package/dist/repl/index.js +242 -305
- package/dist/skills/activated-tracker.d.ts +11 -0
- package/dist/skills/activated-tracker.d.ts.map +1 -0
- package/dist/skills/activated-tracker.js +16 -0
- package/dist/skills/index.d.ts +12 -2
- package/dist/skills/index.d.ts.map +1 -1
- package/dist/skills/index.js +127 -71
- package/dist/terminal/control.d.ts +1 -21
- package/dist/terminal/control.d.ts.map +1 -1
- package/dist/terminal/control.js +1 -32
- package/dist/terminal/formatting.d.ts +0 -33
- package/dist/terminal/formatting.d.ts.map +1 -1
- package/dist/terminal/formatting.js +0 -91
- package/dist/terminal/highlight/theme.d.ts +0 -37
- package/dist/terminal/highlight/theme.d.ts.map +1 -1
- package/dist/terminal/highlight/theme.js +1 -79
- package/dist/terminal/keys.d.ts +0 -97
- package/dist/terminal/keys.d.ts.map +1 -1
- package/dist/terminal/keys.js +0 -194
- package/dist/terminal/select-prompt.d.ts.map +1 -1
- package/dist/terminal/select-prompt.js +65 -51
- package/dist/terminal/style.d.ts +1 -1
- package/dist/terminal/style.d.ts.map +1 -1
- package/dist/terminal/supports-color.d.ts.map +1 -1
- package/dist/terminal/supports-color.js +38 -20
- package/dist/terminal/supports-hyperlinks.d.ts +3 -0
- package/dist/terminal/supports-hyperlinks.d.ts.map +1 -1
- package/dist/terminal/supports-hyperlinks.js +72 -31
- package/dist/terminal/table/layout-manager.d.ts +0 -20
- package/dist/terminal/table/layout-manager.d.ts.map +1 -1
- package/dist/terminal/table/layout-manager.js +68 -44
- package/dist/terminal/table/utils.d.ts +0 -1
- package/dist/terminal/table/utils.d.ts.map +1 -1
- package/dist/terminal/table/utils.js +2 -4
- package/dist/tools/apply-patch.d.ts +5 -3
- package/dist/tools/apply-patch.d.ts.map +1 -1
- package/dist/tools/apply-patch.js +154 -123
- package/dist/tools/bash.d.ts +4 -4
- package/dist/tools/bash.d.ts.map +1 -1
- package/dist/tools/bash.js +27 -13
- package/dist/tools/dynamic-tool-loader.d.ts +17 -3
- package/dist/tools/dynamic-tool-loader.d.ts.map +1 -1
- package/dist/tools/dynamic-tool-loader.js +360 -81
- package/dist/tools/edit-file.d.ts +2 -2
- package/dist/tools/index.d.ts +27 -151
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +16 -21
- package/dist/tools/read-file.d.ts +8 -8
- package/dist/tools/read-file.d.ts.map +1 -1
- package/dist/tools/read-file.js +32 -13
- package/dist/tools/save-file.d.ts +4 -4
- package/dist/tools/skill.d.ts +2 -1
- package/dist/tools/skill.d.ts.map +1 -1
- package/dist/tools/skill.js +64 -14
- package/dist/tools/types.d.ts +8 -2
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/web-fetch.d.ts +8 -12
- package/dist/tools/web-fetch.d.ts.map +1 -1
- package/dist/tools/web-fetch.js +86 -44
- package/dist/tools/web-search.d.ts +4 -8
- package/dist/tools/web-search.d.ts.map +1 -1
- package/dist/tools/web-search.js +41 -33
- package/dist/tui/autocomplete/utils.d.ts +0 -15
- package/dist/tui/autocomplete/utils.d.ts.map +1 -1
- package/dist/tui/autocomplete/utils.js +0 -85
- package/dist/tui/autocomplete.d.ts +1 -1
- package/dist/tui/autocomplete.d.ts.map +1 -1
- package/dist/tui/autocomplete.js +1 -1
- package/dist/tui/components/editor.d.ts +12 -0
- package/dist/tui/components/editor.d.ts.map +1 -1
- package/dist/tui/components/editor.js +181 -195
- package/dist/tui/components/footer.d.ts +0 -2
- package/dist/tui/components/footer.d.ts.map +1 -1
- package/dist/tui/components/footer.js +1 -17
- package/dist/tui/components/input.d.ts +4 -0
- package/dist/tui/components/input.d.ts.map +1 -1
- package/dist/tui/components/input.js +33 -31
- package/dist/tui/components/markdown.d.ts +30 -0
- package/dist/tui/components/markdown.d.ts.map +1 -1
- package/dist/tui/components/markdown.js +274 -242
- package/dist/tui/components/modal.d.ts.map +1 -1
- package/dist/tui/components/modal.js +11 -11
- package/dist/tui/components/select-list.d.ts +5 -0
- package/dist/tui/components/select-list.d.ts.map +1 -1
- package/dist/tui/components/select-list.js +69 -98
- package/dist/tui/components/table.d.ts +6 -0
- package/dist/tui/components/table.d.ts.map +1 -1
- package/dist/tui/components/table.js +61 -52
- package/dist/tui/index.d.ts +1 -8
- package/dist/tui/index.d.ts.map +1 -1
- package/dist/tui/index.js +0 -8
- package/dist/tui/tui.d.ts +9 -0
- package/dist/tui/tui.d.ts.map +1 -1
- package/dist/tui/tui.js +78 -48
- package/dist/tui/utils.d.ts +7 -0
- package/dist/tui/utils.d.ts.map +1 -1
- package/dist/tui/utils.js +117 -53
- package/dist/utils/bash.d.ts.map +1 -1
- package/dist/utils/bash.js +121 -104
- package/dist/utils/binary-output.d.ts +32 -0
- package/dist/utils/binary-output.d.ts.map +1 -0
- package/dist/utils/binary-output.js +127 -0
- package/dist/utils/command-protection.d.ts +3 -2
- package/dist/utils/command-protection.d.ts.map +1 -1
- package/dist/utils/command-protection.js +121 -29
- package/dist/utils/filesystem/operations.d.ts +0 -15
- package/dist/utils/filesystem/operations.d.ts.map +1 -1
- package/dist/utils/filesystem/operations.js +1 -38
- package/dist/utils/filesystem/security.d.ts.map +1 -1
- package/dist/utils/filesystem/security.js +22 -15
- package/dist/utils/filetype-detection.d.ts +0 -1
- package/dist/utils/filetype-detection.d.ts.map +1 -1
- package/dist/utils/filetype-detection.js +0 -12
- package/dist/utils/formatting.d.ts +0 -30
- package/dist/utils/formatting.d.ts.map +1 -1
- package/dist/utils/formatting.js +0 -44
- package/dist/utils/git.d.ts +4 -6
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +36 -46
- package/dist/utils/ignore.d.ts +1 -1
- package/dist/utils/ignore.d.ts.map +1 -1
- package/dist/utils/ignore.js +1 -1
- package/dist/utils/parsing.d.ts +1 -1
- package/dist/utils/parsing.d.ts.map +1 -1
- package/dist/utils/process.d.ts.map +1 -1
- package/dist/utils/process.js +77 -79
- package/dist/utils/yaml.d.ts +0 -1
- package/dist/utils/yaml.d.ts.map +1 -1
- package/dist/utils/yaml.js +80 -89
- package/dist/utils/zod.d.ts +0 -3
- package/dist/utils/zod.d.ts.map +1 -1
- package/dist/utils/zod.js +0 -7
- package/package.json +32 -29
- package/dist/agent/sub-agent.d.ts +0 -23
- package/dist/agent/sub-agent.d.ts.map +0 -1
- package/dist/agent/sub-agent.js +0 -109
- package/dist/commands/add-directory/index.d.ts +0 -3
- package/dist/commands/add-directory/index.d.ts.map +0 -1
- package/dist/commands/add-directory/index.js +0 -50
- package/dist/commands/add-directory/utils.d.ts +0 -3
- package/dist/commands/add-directory/utils.d.ts.map +0 -1
- package/dist/commands/add-directory/utils.js +0 -15
- package/dist/commands/clear/index.d.ts +0 -3
- package/dist/commands/clear/index.d.ts.map +0 -1
- package/dist/commands/clear/index.js +0 -13
- package/dist/commands/generate-rules/index.d.ts +0 -3
- package/dist/commands/generate-rules/index.d.ts.map +0 -1
- package/dist/commands/generate-rules/index.js +0 -206
- package/dist/commands/generate-rules/service.d.ts +0 -22
- package/dist/commands/generate-rules/service.d.ts.map +0 -1
- package/dist/commands/generate-rules/service.js +0 -103
- package/dist/commands/generate-rules/utils.d.ts +0 -5
- package/dist/commands/generate-rules/utils.d.ts.map +0 -1
- package/dist/commands/generate-rules/utils.js +0 -25
- package/dist/commands/handoff/index.d.ts +0 -3
- package/dist/commands/handoff/index.d.ts.map +0 -1
- package/dist/commands/handoff/index.js +0 -97
- package/dist/commands/handoff/utils.d.ts +0 -4
- package/dist/commands/handoff/utils.d.ts.map +0 -1
- package/dist/commands/handoff/utils.js +0 -123
- package/dist/commands/list-directories/index.d.ts +0 -3
- package/dist/commands/list-directories/index.d.ts.map +0 -1
- package/dist/commands/list-directories/index.js +0 -35
- package/dist/commands/pickup/index.d.ts +0 -3
- package/dist/commands/pickup/index.d.ts.map +0 -1
- package/dist/commands/pickup/index.js +0 -141
- package/dist/commands/pickup/types.d.ts +0 -6
- package/dist/commands/pickup/types.d.ts.map +0 -1
- package/dist/commands/pickup/types.js +0 -1
- package/dist/commands/pickup/utils.d.ts +0 -7
- package/dist/commands/pickup/utils.d.ts.map +0 -1
- package/dist/commands/pickup/utils.js +0 -56
- package/dist/commands/remove-directory/index.d.ts +0 -3
- package/dist/commands/remove-directory/index.d.ts.map +0 -1
- package/dist/commands/remove-directory/index.js +0 -55
- package/dist/commands/review/index.d.ts +0 -3
- package/dist/commands/review/index.d.ts.map +0 -1
- package/dist/commands/review/index.js +0 -12
- package/dist/commands/review/review-panel.d.ts +0 -3
- package/dist/commands/review/review-panel.d.ts.map +0 -1
- package/dist/commands/review/review-panel.js +0 -186
- package/dist/commands/review/utils.d.ts +0 -18
- package/dist/commands/review/utils.d.ts.map +0 -1
- package/dist/commands/review/utils.js +0 -146
- package/dist/commands/shell/index.d.ts +0 -3
- package/dist/commands/shell/index.d.ts.map +0 -1
- package/dist/commands/shell/index.js +0 -96
- package/dist/modes/manager.d.ts +0 -24
- package/dist/modes/manager.d.ts.map +0 -1
- package/dist/modes/manager.js +0 -77
- package/dist/modes/prompts.d.ts +0 -2
- package/dist/modes/prompts.d.ts.map +0 -1
- package/dist/modes/prompts.js +0 -142
- package/dist/subagents/index.d.ts +0 -16
- package/dist/subagents/index.d.ts.map +0 -1
- package/dist/subagents/index.js +0 -231
- package/dist/terminal/index.d.ts +0 -9
- package/dist/terminal/index.d.ts.map +0 -1
- package/dist/terminal/index.js +0 -8
- package/dist/tools/agent.d.ts +0 -27
- package/dist/tools/agent.d.ts.map +0 -1
- package/dist/tools/agent.js +0 -81
- package/dist/tools/directory-tree.d.ts +0 -28
- package/dist/tools/directory-tree.d.ts.map +0 -1
- package/dist/tools/directory-tree.js +0 -152
- package/dist/tools/glob.d.ts +0 -35
- package/dist/tools/glob.d.ts.map +0 -1
- package/dist/tools/glob.js +0 -159
- package/dist/tools/grep.d.ts +0 -100
- package/dist/tools/grep.d.ts.map +0 -1
- package/dist/tools/grep.js +0 -601
- package/dist/tools/ls.d.ts +0 -26
- package/dist/tools/ls.d.ts.map +0 -1
- package/dist/tools/ls.js +0 -82
- package/dist/tui/components/header.d.ts +0 -21
- package/dist/tui/components/header.d.ts.map +0 -1
- package/dist/tui/components/header.js +0 -63
- package/dist/utils/bash/parse.d.ts +0 -19
- package/dist/utils/bash/parse.d.ts.map +0 -1
- package/dist/utils/bash/parse.js +0 -223
- package/dist/utils/bash/quote.d.ts +0 -6
- package/dist/utils/bash/quote.d.ts.map +0 -1
- package/dist/utils/bash/quote.js +0 -23
- package/dist/utils/generators.d.ts +0 -3
- package/dist/utils/generators.d.ts.map +0 -1
- package/dist/utils/generators.js +0 -25
- package/dist/utils/glob.d.ts +0 -52
- package/dist/utils/glob.d.ts.map +0 -1
- package/dist/utils/glob.js +0 -376
|
@@ -8,13 +8,13 @@ export interface BlockedCommandResult {
|
|
|
8
8
|
command: string;
|
|
9
9
|
tip: string;
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
interface SafeCommandResult {
|
|
12
12
|
blocked: false;
|
|
13
13
|
}
|
|
14
14
|
/**
|
|
15
15
|
* Result type for command safety check
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
type CommandSafetyResult = BlockedCommandResult | SafeCommandResult;
|
|
18
18
|
/**
|
|
19
19
|
* Detects if a command is destructive and should be blocked
|
|
20
20
|
* @param command - The full command string to check
|
|
@@ -25,4 +25,5 @@ export declare function detectDestructiveCommand(command: string): CommandSafety
|
|
|
25
25
|
* Generate a user-friendly blocked command message
|
|
26
26
|
*/
|
|
27
27
|
export declare function formatBlockedCommandMessage(result: BlockedCommandResult): string;
|
|
28
|
+
export {};
|
|
28
29
|
//# sourceMappingURL=command-protection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-protection.d.ts","sourceRoot":"","sources":["../../source/utils/command-protection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,
|
|
1
|
+
{"version":3,"file":"command-protection.d.ts","sourceRoot":"","sources":["../../source/utils/command-protection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,IAAI,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,KAAK,CAAC;CAChB;AAED;;GAEG;AACH,KAAK,mBAAmB,GAAG,oBAAoB,GAAG,iBAAiB,CAAC;AA0EpE;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,mBAAmB,CA4B7E;AAqXD;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,oBAAoB,GAC3B,MAAM,CAQR"}
|
|
@@ -2,6 +2,66 @@
|
|
|
2
2
|
* Command Protection Module
|
|
3
3
|
* Detects and blocks destructive commands that could cause data loss
|
|
4
4
|
*/
|
|
5
|
+
/**
|
|
6
|
+
* Check if a git subcommand appears as an actual command (not inside quoted strings).
|
|
7
|
+
* This helps avoid false positives when destructive command text appears in
|
|
8
|
+
* commit messages or other quoted strings.
|
|
9
|
+
*/
|
|
10
|
+
function isActualGitCommand(command, subcommand) {
|
|
11
|
+
const pattern = new RegExp(`\\bgit\\s+${subcommand}\\b`, "gi");
|
|
12
|
+
// Find all matches of git <subcommand>
|
|
13
|
+
const matches = [];
|
|
14
|
+
let match = pattern.exec(command);
|
|
15
|
+
while (match !== null) {
|
|
16
|
+
matches.push({ index: match.index, text: match[0] });
|
|
17
|
+
match = pattern.exec(command);
|
|
18
|
+
}
|
|
19
|
+
if (matches.length === 0)
|
|
20
|
+
return false;
|
|
21
|
+
// For each match, check if it's inside quotes
|
|
22
|
+
for (const { index } of matches) {
|
|
23
|
+
if (!isInsideQuotes(command, index)) {
|
|
24
|
+
// Also check if it's at the start or after command separators
|
|
25
|
+
const beforeMatch = command.slice(0, index).trim();
|
|
26
|
+
if (beforeMatch === "" ||
|
|
27
|
+
beforeMatch.endsWith("&&") ||
|
|
28
|
+
beforeMatch.endsWith("||") ||
|
|
29
|
+
beforeMatch.endsWith(";") ||
|
|
30
|
+
beforeMatch.endsWith("|") ||
|
|
31
|
+
beforeMatch.endsWith("\n")) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Check if a position in a string is inside quotes (single or double).
|
|
40
|
+
* Handles escaped quotes.
|
|
41
|
+
*/
|
|
42
|
+
function isInsideQuotes(command, position) {
|
|
43
|
+
let inSingleQuote = false;
|
|
44
|
+
let inDoubleQuote = false;
|
|
45
|
+
let escaped = false;
|
|
46
|
+
for (let i = 0; i < position; i++) {
|
|
47
|
+
const char = command[i];
|
|
48
|
+
if (escaped) {
|
|
49
|
+
escaped = false;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (char === "\\") {
|
|
53
|
+
escaped = true;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (char === '"' && !inSingleQuote) {
|
|
57
|
+
inDoubleQuote = !inDoubleQuote;
|
|
58
|
+
}
|
|
59
|
+
else if (char === "'" && !inDoubleQuote) {
|
|
60
|
+
inSingleQuote = !inSingleQuote;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return inSingleQuote || inDoubleQuote;
|
|
64
|
+
}
|
|
5
65
|
/**
|
|
6
66
|
* Detects if a command is destructive and should be blocked
|
|
7
67
|
* @param command - The full command string to check
|
|
@@ -31,6 +91,34 @@ export function detectDestructiveCommand(command) {
|
|
|
31
91
|
}
|
|
32
92
|
return { blocked: false };
|
|
33
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Check if a git restore command will discard uncommitted changes
|
|
96
|
+
* (restore without --staged and not creating a branch with -b)
|
|
97
|
+
*/
|
|
98
|
+
function isDestructiveGitRestore(lowerCommand) {
|
|
99
|
+
if (!lowerCommand.startsWith("git restore"))
|
|
100
|
+
return false;
|
|
101
|
+
if (lowerCommand.includes(" --staged"))
|
|
102
|
+
return false;
|
|
103
|
+
const afterRestore = lowerCommand.substring("git restore".length).trim();
|
|
104
|
+
return !!afterRestore && !afterRestore.startsWith("-b");
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Check if a git branch command uses -D (force delete without merge check)
|
|
108
|
+
*/
|
|
109
|
+
function isDestructiveGitBranchD(command, lowerCommand) {
|
|
110
|
+
const branchMatch = lowerCommand.match(/git\s+branch\s+-([a-z])/);
|
|
111
|
+
if (!branchMatch)
|
|
112
|
+
return false;
|
|
113
|
+
// Check if the flag in the original command is uppercase
|
|
114
|
+
const flagInOriginal = command.match(/git\s+branch\s+-([A-Za-z])/i);
|
|
115
|
+
if (!flagInOriginal)
|
|
116
|
+
return false;
|
|
117
|
+
if (flagInOriginal[1] !== flagInOriginal[1].toUpperCase())
|
|
118
|
+
return false;
|
|
119
|
+
// Verify this is an actual git branch command, not text inside quotes
|
|
120
|
+
return isActualGitCommand(command, "branch");
|
|
121
|
+
}
|
|
34
122
|
/**
|
|
35
123
|
* Detect destructive git commands
|
|
36
124
|
*/
|
|
@@ -56,18 +144,13 @@ function detectDestructiveGitCommands(command) {
|
|
|
56
144
|
};
|
|
57
145
|
}
|
|
58
146
|
// Block git restore without --staged (discards uncommitted changes)
|
|
59
|
-
if (lowerCommand
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
reason: "git restore <file> (without --staged) discards uncommitted changes",
|
|
67
|
-
command,
|
|
68
|
-
tip: "Use 'git restore --staged <file>' to only unstage, or 'git stash' to save changes.",
|
|
69
|
-
};
|
|
70
|
-
}
|
|
147
|
+
if (isDestructiveGitRestore(lowerCommand)) {
|
|
148
|
+
return {
|
|
149
|
+
blocked: true,
|
|
150
|
+
reason: "git restore <file> (without --staged) discards uncommitted changes",
|
|
151
|
+
command,
|
|
152
|
+
tip: "Use 'git restore --staged <file>' to only unstage, or 'git stash' to save changes.",
|
|
153
|
+
};
|
|
71
154
|
}
|
|
72
155
|
// Block git clean -f (force deletes untracked files)
|
|
73
156
|
if (lowerCommand.includes("git clean -f") ||
|
|
@@ -91,23 +174,13 @@ function detectDestructiveGitCommands(command) {
|
|
|
91
174
|
};
|
|
92
175
|
}
|
|
93
176
|
// Block git branch -D (force delete without merge check)
|
|
94
|
-
if (lowerCommand
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const upperMatch = command.match(/git\s+branch\s+-[A-Z]/);
|
|
102
|
-
if (upperMatch) {
|
|
103
|
-
return {
|
|
104
|
-
blocked: true,
|
|
105
|
-
reason: "git branch -D force-deletes branches without checking if they're merged",
|
|
106
|
-
command,
|
|
107
|
-
tip: "Use 'git branch -d' (lowercase) to safely delete branches that are merged.",
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
}
|
|
177
|
+
if (isDestructiveGitBranchD(command, lowerCommand)) {
|
|
178
|
+
return {
|
|
179
|
+
blocked: true,
|
|
180
|
+
reason: "git branch -D force-deletes branches without checking if they're merged",
|
|
181
|
+
command,
|
|
182
|
+
tip: "Use 'git branch -d' (lowercase) to safely delete branches that are merged.",
|
|
183
|
+
};
|
|
111
184
|
}
|
|
112
185
|
// Block git stash drop and git stash clear
|
|
113
186
|
if (lowerCommand.includes("git stash drop") ||
|
|
@@ -216,8 +289,27 @@ function detectDangerousInlineScripts(command) {
|
|
|
216
289
|
}
|
|
217
290
|
/**
|
|
218
291
|
* Detect dangerous patterns in heredocs and here-strings
|
|
292
|
+
* Only blocks heredocs that are explicitly executed by a scripting language,
|
|
293
|
+
* not heredocs used as data (e.g., commit messages, config files).
|
|
219
294
|
*/
|
|
220
295
|
function detectDangerousHeredocs(command) {
|
|
296
|
+
// Check if heredoc is being executed by a scripting language
|
|
297
|
+
// Patterns that indicate execution:
|
|
298
|
+
// 1. bash <<EOF, sh <<EOF, python <<EOF, etc. (language reads from heredoc)
|
|
299
|
+
// 2. cat <<EOF | bash, <<EOF | python, etc. (heredoc piped to language)
|
|
300
|
+
const executionPatterns = [
|
|
301
|
+
// Shell languages reading heredoc directly
|
|
302
|
+
/\b(bash|sh|zsh|dash|ksh)\s*<<-?\s*['"]?\w+/i,
|
|
303
|
+
// Scripting languages reading heredoc directly
|
|
304
|
+
/\b(python\d?|ruby|perl|node)\s*<<-?\s*['"]?\w+/i,
|
|
305
|
+
// Heredoc piped to shell
|
|
306
|
+
/<<-?\s*['"]?\w+['"]?\s*\|\s*(bash|sh|zsh|dash|ksh)\b/i,
|
|
307
|
+
];
|
|
308
|
+
const isExecutableHeredoc = executionPatterns.some((pattern) => pattern.test(command));
|
|
309
|
+
// Only scan heredoc content if it's being executed by a scripting language
|
|
310
|
+
if (!isExecutableHeredoc) {
|
|
311
|
+
return { blocked: false };
|
|
312
|
+
}
|
|
221
313
|
// Match heredoc patterns: <<EOF ... EOF
|
|
222
314
|
const heredocPattern = /<<-?\s*['"]?(\w+)['"]?\s*([\s\S]*?)\n\1\b/gi;
|
|
223
315
|
let match = null;
|
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
export declare function toPath(urlOrPath: URL | string): string;
|
|
2
|
-
/**
|
|
3
|
-
* Converts Windows backslashes to POSIX forward slashes.
|
|
4
|
-
* Preserves UNC paths and extended-length paths.
|
|
5
|
-
* @param inputPath - Path to convert
|
|
6
|
-
* @returns Path with forward slashes
|
|
7
|
-
*/
|
|
8
|
-
export declare function slash(inputPath: string): string;
|
|
9
|
-
/**
|
|
10
|
-
* Checks if a path exists and is a directory.
|
|
11
|
-
* @param filePath - Path to check (URL or string)
|
|
12
|
-
* @returns Promise resolving to true if path is a directory
|
|
13
|
-
* @throws TypeError if input is invalid
|
|
14
|
-
*/
|
|
15
|
-
export declare function isDirectory(filePath: URL | string): Promise<boolean>;
|
|
16
1
|
/**
|
|
17
2
|
* Safely clears all contents of a directory.
|
|
18
3
|
* @param directoryPath - Path to the directory to clear (URL or string)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../source/utils/filesystem/operations.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../../source/utils/filesystem/operations.ts"],"names":[],"mappings":"AAQA;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,aAAa,EAAE,GAAG,GAAG,MAAM,GAC1B,OAAO,CAAC,IAAI,CAAC,CAuGf"}
|
|
@@ -1,46 +1,9 @@
|
|
|
1
1
|
import * as fsPromises from "node:fs/promises";
|
|
2
2
|
import * as path from "node:path";
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
4
|
+
function toPath(urlOrPath) {
|
|
5
5
|
return urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Converts Windows backslashes to POSIX forward slashes.
|
|
9
|
-
* Preserves UNC paths and extended-length paths.
|
|
10
|
-
* @param inputPath - Path to convert
|
|
11
|
-
* @returns Path with forward slashes
|
|
12
|
-
*/
|
|
13
|
-
export function slash(inputPath) {
|
|
14
|
-
const isExtendedLengthPath = inputPath.startsWith("\\\\?\\");
|
|
15
|
-
const isUncPath = inputPath.startsWith("\\\\");
|
|
16
|
-
if (isExtendedLengthPath || isUncPath) {
|
|
17
|
-
return inputPath;
|
|
18
|
-
}
|
|
19
|
-
return inputPath.replace(/\\/g, "/");
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Checks if a path exists and is a directory.
|
|
23
|
-
* @param filePath - Path to check (URL or string)
|
|
24
|
-
* @returns Promise resolving to true if path is a directory
|
|
25
|
-
* @throws TypeError if input is invalid
|
|
26
|
-
*/
|
|
27
|
-
export async function isDirectory(filePath) {
|
|
28
|
-
const resolvedPath = path.resolve(toPath(filePath));
|
|
29
|
-
if (typeof resolvedPath !== "string" || !resolvedPath.trim()) {
|
|
30
|
-
throw new TypeError(`Expected a non-empty string or URL, got ${typeof filePath}`);
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
const stats = await fsPromises.stat(resolvedPath);
|
|
34
|
-
return stats.isDirectory();
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
const err = error;
|
|
38
|
-
if (err.code === "ENOENT") {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
throw error;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
7
|
/**
|
|
45
8
|
* Safely clears all contents of a directory.
|
|
46
9
|
* @param directoryPath - Path to the directory to clear (URL or string)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../../source/utils/filesystem/security.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAsCpD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK3E;AAoCD,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../../../source/utils/filesystem/security.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAsCpD,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,CAK3E;AAoCD,wBAAgB,uBAAuB,CACrC,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,MAAM,EAAE,GACpB,OAAO,CAKT;AA2DD,wBAAsB,YAAY,CAChC,aAAa,EAAE,MAAM,EACrB,gBAAgB,EAAE,MAAM,GAAG,MAAM,EAAE,EACnC,OAAO,GAAE;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,WAAW,CAAA;CAAO,GACtE,OAAO,CAAC,MAAM,CAAC,CAuFjB;AA8BD,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,GACjB,IAAI,CAIN"}
|
|
@@ -75,7 +75,10 @@ function isPathWithinBaseDir(requestedPath, baseDir) {
|
|
|
75
75
|
}
|
|
76
76
|
// Check if path is within any of the allowed directories
|
|
77
77
|
export function isPathWithinAllowedDirs(requestedPath, allowedDirs) {
|
|
78
|
-
return allowedDirs.some((allowedDir) =>
|
|
78
|
+
return allowedDirs.some((allowedDir) => {
|
|
79
|
+
const expandedDir = expandHome(allowedDir);
|
|
80
|
+
return isPathWithinBaseDir(requestedPath, expandedDir);
|
|
81
|
+
});
|
|
79
82
|
}
|
|
80
83
|
async function resolveValidAncestor(startDir, isWithinAllowed) {
|
|
81
84
|
let current = startDir;
|
|
@@ -104,6 +107,21 @@ async function resolveValidAncestor(startDir, isWithinAllowed) {
|
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
}
|
|
110
|
+
async function ensurePathExists(validatedPath, requestedPath, abortSignal) {
|
|
111
|
+
if (abortSignal?.aborted) {
|
|
112
|
+
throw new Error("Path validation aborted during existence check");
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
await fs.stat(validatedPath);
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
const error = err;
|
|
119
|
+
if (error.code === "ENOENT") {
|
|
120
|
+
throw new Error(`The specified path does not exist: ${requestedPath} (${validatedPath})`);
|
|
121
|
+
}
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
107
125
|
// Security utilities
|
|
108
126
|
export async function validatePath(requestedPath, allowedDirectory, options = {}) {
|
|
109
127
|
const { requireExistence = true, abortSignal } = options;
|
|
@@ -121,7 +139,8 @@ export async function validatePath(requestedPath, allowedDirectory, options = {}
|
|
|
121
139
|
: [allowedDirectory];
|
|
122
140
|
// Resolve and normalize all allowed directories
|
|
123
141
|
const normalizedAllowedDirs = await Promise.all(allowedDirectories.map(async (dir) => {
|
|
124
|
-
|
|
142
|
+
const expandedDir = expandHome(dir);
|
|
143
|
+
let normalizedDir = normalizePath(path.resolve(expandedDir));
|
|
125
144
|
// Try to resolve real path for allowedDirectory when it exists to handle symlinked roots
|
|
126
145
|
try {
|
|
127
146
|
const stats = await fs.stat(normalizedDir);
|
|
@@ -171,19 +190,7 @@ export async function validatePath(requestedPath, allowedDirectory, options = {}
|
|
|
171
190
|
}
|
|
172
191
|
// Now, if requireExistence, check if the path exists
|
|
173
192
|
if (requireExistence) {
|
|
174
|
-
|
|
175
|
-
throw new Error("Path validation aborted during existence check");
|
|
176
|
-
}
|
|
177
|
-
try {
|
|
178
|
-
await fs.stat(validatedPath);
|
|
179
|
-
}
|
|
180
|
-
catch (err) {
|
|
181
|
-
const error = err;
|
|
182
|
-
if (error.code === "ENOENT") {
|
|
183
|
-
throw new Error(`The specified path does not exist: ${requestedPath} (${validatedPath})`);
|
|
184
|
-
}
|
|
185
|
-
throw error;
|
|
186
|
-
}
|
|
193
|
+
await ensurePathExists(validatedPath, requestedPath, abortSignal);
|
|
187
194
|
}
|
|
188
195
|
return validatedPath;
|
|
189
196
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"filetype-detection.d.ts","sourceRoot":"","sources":["../../source/utils/filetype-detection.ts"],"names":[],"mappings":"AA+FA,wBAAgB,
|
|
1
|
+
{"version":3,"file":"filetype-detection.d.ts","sourceRoot":"","sources":["../../source/utils/filetype-detection.ts"],"names":[],"mappings":"AA+FA,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW7E"}
|
|
@@ -86,18 +86,6 @@ const extensionToLanguageMap = {
|
|
|
86
86
|
".proto": { name: "Protocol Buffers", codeblock: "protobuf" },
|
|
87
87
|
".txt": { name: "Text", codeblock: "text" },
|
|
88
88
|
};
|
|
89
|
-
export function getLanguageFromFilePath(filePath) {
|
|
90
|
-
const extension = extname(filePath).toLowerCase();
|
|
91
|
-
const languageInfo = extension
|
|
92
|
-
? extensionToLanguageMap[extension]
|
|
93
|
-
: undefined;
|
|
94
|
-
if (languageInfo) {
|
|
95
|
-
return languageInfo.name;
|
|
96
|
-
}
|
|
97
|
-
const filename = basename(filePath).toLowerCase();
|
|
98
|
-
const filenameLanguageInfo = extensionToLanguageMap[`.${filename}`];
|
|
99
|
-
return filenameLanguageInfo?.name;
|
|
100
|
-
}
|
|
101
89
|
export function getCodeblockFromFilePath(filePath) {
|
|
102
90
|
const extension = extname(filePath).toLowerCase();
|
|
103
91
|
const languageInfo = extension
|
|
@@ -24,36 +24,6 @@ export type FormatType = "xml" | "markdown" | "bracket";
|
|
|
24
24
|
* ```
|
|
25
25
|
*/
|
|
26
26
|
export declare function formatFile(file: string, content: string, format: FormatType): string;
|
|
27
|
-
/**
|
|
28
|
-
* Formats URL content with metadata in the specified format.
|
|
29
|
-
*
|
|
30
|
-
* @param siteUrl - The URL to format
|
|
31
|
-
* @param content - The URL content to format
|
|
32
|
-
* @param format - The output format type
|
|
33
|
-
* @returns Formatted URL content with metadata
|
|
34
|
-
* @throws {Error} When an unsupported format is provided
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* formatUrl("https://example.com", "<html>...</html>", "xml")
|
|
39
|
-
* // Returns: "<webpage>\n<url>https://example.com</url>\n<content>\n<html>...</html>\n</content>\n</webpage>"
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function formatUrl(siteUrl: string, content: string, format: FormatType): string;
|
|
43
|
-
/**
|
|
44
|
-
* Formats content as a code block with appropriate language identifier.
|
|
45
|
-
*
|
|
46
|
-
* @param file - The file path used to determine the code block language
|
|
47
|
-
* @param content - The code content to format
|
|
48
|
-
* @returns Formatted code block with language identifier
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* formatCodeBlock("example.js", "console.log('hello');")
|
|
53
|
-
* // Returns: "``` javascript\nconsole.log('hello');\n```"
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export declare function formatCodeBlock(file: string, content: string): string;
|
|
57
27
|
/**
|
|
58
28
|
* Formats generic content blocks with a name in the specified format.
|
|
59
29
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../source/utils/formatting.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,GACjB,MAAM,CAaR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../source/utils/formatting.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,UAAU,GACjB,MAAM,CAaR;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,UAAU,GACjB,MAAM,CAWR;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,KAAG,MACG,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,MAAM,KAAG,MASjD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,cAAc,MAAM,KAAG,MAuCrD,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,GAAI,KAAK,MAAM,KAAG,MAwC1C,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,IAAI,KAAG,MASvC,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAGvD,CAAC"}
|
package/dist/utils/formatting.js
CHANGED
|
@@ -35,50 +35,6 @@ export function formatFile(file, content, format) {
|
|
|
35
35
|
throw new Error(`Unsupported format: ${format}`);
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Formats URL content with metadata in the specified format.
|
|
40
|
-
*
|
|
41
|
-
* @param siteUrl - The URL to format
|
|
42
|
-
* @param content - The URL content to format
|
|
43
|
-
* @param format - The output format type
|
|
44
|
-
* @returns Formatted URL content with metadata
|
|
45
|
-
* @throws {Error} When an unsupported format is provided
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* formatUrl("https://example.com", "<html>...</html>", "xml")
|
|
50
|
-
* // Returns: "<webpage>\n<url>https://example.com</url>\n<content>\n<html>...</html>\n</content>\n</webpage>"
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
export function formatUrl(siteUrl, content, format) {
|
|
54
|
-
switch (format) {
|
|
55
|
-
case "xml":
|
|
56
|
-
return `<webpage>\n<url>${siteUrl}</url>\n<content>\n${content}\n</content>\n</webpage>`;
|
|
57
|
-
case "markdown":
|
|
58
|
-
return `## URL: ${siteUrl}\n${MD_TRIPLE_QUOTE}\n${content}\n${MD_TRIPLE_QUOTE}`;
|
|
59
|
-
case "bracket":
|
|
60
|
-
return `[url]: ${siteUrl}\n[url content begin]\n${content}\n[url content end]`;
|
|
61
|
-
default:
|
|
62
|
-
throw new Error(`Unsupported format: ${format}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Formats content as a code block with appropriate language identifier.
|
|
67
|
-
*
|
|
68
|
-
* @param file - The file path used to determine the code block language
|
|
69
|
-
* @param content - The code content to format
|
|
70
|
-
* @returns Formatted code block with language identifier
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* formatCodeBlock("example.js", "console.log('hello');")
|
|
75
|
-
* // Returns: "``` javascript\nconsole.log('hello');\n```"
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
export function formatCodeBlock(file, content) {
|
|
79
|
-
const codeBlockName = getCodeblockFromFilePath(file) || path.extname(file).slice(1);
|
|
80
|
-
return `${MD_TRIPLE_QUOTE} ${codeBlockName}\n${content}\n${MD_TRIPLE_QUOTE}`;
|
|
81
|
-
}
|
|
82
38
|
/**
|
|
83
39
|
* Formats generic content blocks with a name in the specified format.
|
|
84
40
|
*
|
package/dist/utils/git.d.ts
CHANGED
|
@@ -3,17 +3,14 @@ export declare function getDiffStat(): Promise<{
|
|
|
3
3
|
insertions: number;
|
|
4
4
|
deletions: number;
|
|
5
5
|
}>;
|
|
6
|
-
|
|
6
|
+
interface GitCounts {
|
|
7
7
|
added: number;
|
|
8
8
|
modified: number;
|
|
9
9
|
deleted: number;
|
|
10
10
|
untracked: number;
|
|
11
|
-
}
|
|
11
|
+
}
|
|
12
|
+
export declare function getGitStatus(): Promise<GitCounts>;
|
|
12
13
|
export declare const inGitDirectory: () => Promise<boolean>;
|
|
13
|
-
/**
|
|
14
|
-
* Check if there are uncommitted changes
|
|
15
|
-
*/
|
|
16
|
-
export declare function hasUncommittedChanges(): Promise<boolean>;
|
|
17
14
|
/**
|
|
18
15
|
* Get the current git branch name
|
|
19
16
|
*/
|
|
@@ -22,4 +19,5 @@ export declare function getCurrentBranch(): Promise<string | null>;
|
|
|
22
19
|
* Count commits that exist locally but haven't been pushed to the remote branch
|
|
23
20
|
*/
|
|
24
21
|
export declare function getUnpushedCommitsCount(): Promise<number>;
|
|
22
|
+
export {};
|
|
25
23
|
//# sourceMappingURL=git.d.ts.map
|
package/dist/utils/git.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../source/utils/git.ts"],"names":[],"mappings":"AAIA,wBAAsB,WAAW;;;;GAyDhC;AAED,
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../source/utils/git.ts"],"names":[],"mappings":"AAIA,wBAAsB,WAAW;;;;GAyDhC;AAED,UAAU,SAAS;IACjB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,SAAS,CAAC,CAuBvD;AAyBD,eAAO,MAAM,cAAc,QAAqB,OAAO,CAAC,OAAO,CAS7D,CAAC;AAEH;;GAEG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAkB/D;AAED;;GAEG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,MAAM,CAAC,CAmC/D"}
|
package/dist/utils/git.js
CHANGED
|
@@ -56,41 +56,47 @@ export async function getDiffStat() {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
export async function getGitStatus() {
|
|
59
|
-
// Git status processing (optimized)
|
|
60
59
|
const result = await executeCommand(["git", "status", "--porcelain"], {
|
|
61
60
|
cwd: process.cwd(),
|
|
62
61
|
throwOnError: false,
|
|
63
62
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const lines = result.stdout.split("\n");
|
|
70
|
-
for (const line of lines) {
|
|
71
|
-
if (!line)
|
|
72
|
-
continue;
|
|
73
|
-
const s = line.slice(0, 2);
|
|
74
|
-
if (s[0] === "A" || s === "M ")
|
|
75
|
-
added++;
|
|
76
|
-
else if (s[1] === "M" || s === " M")
|
|
77
|
-
modified++;
|
|
78
|
-
else if (s[0] === "D" || s === " D")
|
|
79
|
-
deleted++;
|
|
80
|
-
else if (s === "??")
|
|
81
|
-
untracked++;
|
|
82
|
-
}
|
|
83
|
-
// if (added) gitStatus += ` +${added}`;
|
|
84
|
-
// if (modified) gitStatus += ` ~${modified}`;
|
|
85
|
-
// if (deleted) gitStatus += ` -${deleted}`;
|
|
86
|
-
// if (untracked) gitStatus += ` ?${untracked}`;
|
|
87
|
-
}
|
|
88
|
-
return {
|
|
89
|
-
added,
|
|
90
|
-
modified,
|
|
91
|
-
deleted,
|
|
92
|
-
untracked,
|
|
63
|
+
const counts = {
|
|
64
|
+
added: 0,
|
|
65
|
+
modified: 0,
|
|
66
|
+
deleted: 0,
|
|
67
|
+
untracked: 0,
|
|
93
68
|
};
|
|
69
|
+
if (result.code !== 0) {
|
|
70
|
+
return counts;
|
|
71
|
+
}
|
|
72
|
+
const lines = result.stdout.split("\n");
|
|
73
|
+
for (const line of lines) {
|
|
74
|
+
incrementCountsFromStatusLine(line, counts);
|
|
75
|
+
}
|
|
76
|
+
return counts;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Parse a single git status --porcelain line and increment the appropriate counter.
|
|
80
|
+
*/
|
|
81
|
+
function incrementCountsFromStatusLine(line, counts) {
|
|
82
|
+
if (!line)
|
|
83
|
+
return;
|
|
84
|
+
const s = line.slice(0, 2);
|
|
85
|
+
if (s === "??") {
|
|
86
|
+
counts.untracked++;
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (s[0] === "A" || s === "M ") {
|
|
90
|
+
counts.added++;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (s[1] === "M" || s === " M") {
|
|
94
|
+
counts.modified++;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (s[0] === "D" || s === " D") {
|
|
98
|
+
counts.deleted++;
|
|
99
|
+
}
|
|
94
100
|
}
|
|
95
101
|
export const inGitDirectory = memoize(async () => {
|
|
96
102
|
const { code } = await executeCommand(["git", "rev-parse", "--is-inside-work-tree"], {
|
|
@@ -99,22 +105,6 @@ export const inGitDirectory = memoize(async () => {
|
|
|
99
105
|
});
|
|
100
106
|
return code === 0;
|
|
101
107
|
});
|
|
102
|
-
/**
|
|
103
|
-
* Check if there are uncommitted changes
|
|
104
|
-
*/
|
|
105
|
-
export async function hasUncommittedChanges() {
|
|
106
|
-
try {
|
|
107
|
-
const result = await executeCommand(["git", "status", "--porcelain"], {
|
|
108
|
-
cwd: process.cwd(),
|
|
109
|
-
throwOnError: false,
|
|
110
|
-
});
|
|
111
|
-
// If there are uncommitted changes, --porcelain will output lines for each changed file
|
|
112
|
-
return result.stdout.trim().length > 0;
|
|
113
|
-
}
|
|
114
|
-
catch {
|
|
115
|
-
return false;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
108
|
/**
|
|
119
109
|
* Get the current git branch name
|
|
120
110
|
*/
|
package/dist/utils/ignore.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ignore.d.ts","sourceRoot":"","sources":["../../source/utils/ignore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqWH,UAAU,UAAU;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,cAAM,UAAU;IACd,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAGrC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAS;gBAG3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,OAAO,EACnB,QAAQ,EAAE,OAAO,EACjB,WAAW,EAAE,MAAM;IASrB,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,UAAU,IAAI,MAAM,CAKvB;IAED,OAAO,CAAC,YAAY;CAWrB;AA0MD,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,
|
|
1
|
+
{"version":3,"file":"ignore.d.ts","sourceRoot":"","sources":["../../source/utils/ignore.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAqWH,UAAU,UAAU;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAED,UAAU,aAAa;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED,cAAM,UAAU;IACd,SAAgB,OAAO,EAAE,MAAM,CAAC;IAChC,SAAgB,IAAI,CAAC,EAAE,OAAO,CAAC;IAC/B,SAAgB,QAAQ,EAAE,OAAO,CAAC;IAElC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAU;IACrC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IAGrC,OAAO,CAAC,MAAM,CAAC,CAAS;IACxB,OAAO,CAAC,WAAW,CAAC,CAAS;gBAG3B,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,GAAG,SAAS,EACzB,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,OAAO,EACnB,QAAQ,EAAE,OAAO,EACjB,WAAW,EAAE,MAAM;IASrB,IAAI,KAAK,IAAI,MAAM,CAKlB;IAED,IAAI,UAAU,IAAI,MAAM,CAKvB;IAED,OAAO,CAAC,YAAY;CAWrB;AA0MD,UAAU,aAAa;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,cAAM,MAAM;IACV,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAU;IAC3C,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,UAAU,CAAkC;IAEpD;;;;;;OAMG;gBACS,EACV,UAAiB,EACjB,UAAuB,EACvB,kBAA0B,GAC3B,GAAE,aAAkB;IASrB,OAAO,CAAC,UAAU;IAQlB;;OAEG;IACH,UAAU,IAAI,IAAI;IAKlB;;;;OAIG;IACH,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI;IAW9D;;;OAGG;IACH,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,aAAa,GAAG,IAAI;IAKrE,OAAO,CAAC,KAAK;IAuBb;;;;OAIG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IA0BrC,OAAO,CAAC,EAAE;IAgDV;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI9B;;;OAGG;IACH,YAAY,IAAI,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO;IAIzC;;;;OAIG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,MAAM,EAAE;IAI1C;;;;OAIG;IACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAI9B;;;;OAIG;IACH,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;CAKjC;AAED,QAAA,MAAM,OAAO;eAAc,aAAa,GAAG,MAAM;;CAAuB,CAAC;AA6BzE,eAAe,OAAO,CAAC"}
|
package/dist/utils/ignore.js
CHANGED
|
@@ -458,7 +458,7 @@ const isNotRelative = (path) => REGEX_TEST_INVALID_PATH.test(path);
|
|
|
458
458
|
checkPath.isNotRelative = isNotRelative;
|
|
459
459
|
// On windows, the following function will be replaced
|
|
460
460
|
checkPath.convert = (p) => p;
|
|
461
|
-
|
|
461
|
+
class Ignore {
|
|
462
462
|
_rules;
|
|
463
463
|
_strictPathCheck;
|
|
464
464
|
_ignoreCache = {};
|
package/dist/utils/parsing.d.ts
CHANGED