thatgfsj-code 0.3.0 → 0.3.1
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/CHANGELOG.md +229 -0
- package/DEVELOPMENT.md +286 -0
- package/README.md +144 -79
- package/dist/agent/core.d.ts +56 -0
- package/dist/agent/core.d.ts.map +1 -0
- package/dist/agent/core.js +142 -0
- package/dist/agent/core.js.map +1 -0
- package/dist/agent/index.d.ts +8 -0
- package/dist/agent/index.d.ts.map +1 -0
- package/dist/agent/index.js +8 -0
- package/dist/agent/index.js.map +1 -0
- package/dist/agent/intent.d.ts +36 -0
- package/dist/agent/intent.d.ts.map +1 -0
- package/dist/agent/intent.js +146 -0
- package/dist/agent/intent.js.map +1 -0
- package/dist/agent/streaming.d.ts +50 -0
- package/dist/agent/streaming.d.ts.map +1 -0
- package/dist/agent/streaming.js +110 -0
- package/dist/agent/streaming.js.map +1 -0
- package/dist/core/ai-engine.d.ts +76 -0
- package/dist/core/ai-engine.d.ts.map +1 -0
- package/dist/core/ai-engine.js +394 -0
- package/dist/core/ai-engine.js.map +1 -0
- package/dist/core/cli.d.ts +21 -0
- package/dist/core/cli.d.ts.map +1 -0
- package/dist/core/cli.js +143 -0
- package/dist/core/cli.js.map +1 -0
- package/dist/core/config.d.ts +55 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +162 -0
- package/dist/core/config.js.map +1 -0
- package/dist/core/context-compactor.d.ts +54 -0
- package/dist/core/context-compactor.d.ts.map +1 -0
- package/dist/core/context-compactor.js +197 -0
- package/dist/core/context-compactor.js.map +1 -0
- package/dist/core/hooks.d.ts +75 -0
- package/dist/core/hooks.d.ts.map +1 -0
- package/dist/core/hooks.js +146 -0
- package/dist/core/hooks.js.map +1 -0
- package/dist/core/permissions.d.ts +52 -0
- package/dist/core/permissions.d.ts.map +1 -0
- package/dist/core/permissions.js +237 -0
- package/dist/core/permissions.js.map +1 -0
- package/dist/core/session.d.ts +54 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/session.js +147 -0
- package/dist/core/session.js.map +1 -0
- package/dist/core/skills.d.ts +60 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/core/skills.js +175 -0
- package/dist/core/skills.js.map +1 -0
- package/dist/core/state.d.ts +60 -0
- package/dist/core/state.d.ts.map +1 -0
- package/dist/core/state.js +106 -0
- package/dist/core/state.js.map +1 -0
- package/dist/core/subagent.d.ts +68 -0
- package/dist/core/subagent.d.ts.map +1 -0
- package/dist/core/subagent.js +142 -0
- package/dist/core/subagent.js.map +1 -0
- package/dist/core/system-prompt.d.ts +40 -0
- package/dist/core/system-prompt.d.ts.map +1 -0
- package/dist/core/system-prompt.js +138 -0
- package/dist/core/system-prompt.js.map +1 -0
- package/dist/core/tool-registry.d.ts +53 -0
- package/dist/core/tool-registry.d.ts.map +1 -0
- package/dist/core/tool-registry.js +138 -0
- package/dist/core/tool-registry.js.map +1 -0
- package/dist/core/types.d.ts +206 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +127 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/{cmd/index.d.ts.map → index.d.ts.map} +1 -1
- package/dist/index.js +472 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +1 -1
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/repl/index.d.ts +8 -0
- package/dist/repl/index.d.ts.map +1 -0
- package/dist/repl/index.js +8 -0
- package/dist/repl/index.js.map +1 -0
- package/dist/repl/input.d.ts +69 -0
- package/dist/repl/input.d.ts.map +1 -0
- package/dist/repl/input.js +139 -0
- package/dist/repl/input.js.map +1 -0
- package/dist/repl/loop.d.ts +184 -0
- package/dist/repl/loop.d.ts.map +1 -0
- package/dist/repl/loop.js +932 -0
- package/dist/repl/loop.js.map +1 -0
- package/dist/repl/output.d.ts +105 -0
- package/dist/repl/output.d.ts.map +1 -0
- package/dist/repl/output.js +199 -0
- package/dist/repl/output.js.map +1 -0
- package/dist/repl/welcome.d.ts +68 -0
- package/dist/repl/welcome.d.ts.map +1 -0
- package/dist/repl/welcome.js +254 -0
- package/dist/repl/welcome.js.map +1 -0
- package/dist/tools/file.d.ts +1 -1
- package/dist/tools/file.d.ts.map +1 -1
- package/dist/tools/git.d.ts +1 -1
- package/dist/tools/git.d.ts.map +1 -1
- package/dist/tools/index.d.ts +15 -35
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +31 -80
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/search.d.ts +1 -1
- package/dist/tools/search.d.ts.map +1 -1
- package/dist/tools/shell.d.ts +11 -4
- package/dist/tools/shell.d.ts.map +1 -1
- package/dist/tools/shell.js +78 -42
- package/dist/tools/shell.js.map +1 -1
- package/dist/utils/diff-preview.d.ts +42 -0
- package/dist/utils/diff-preview.d.ts.map +1 -0
- package/dist/utils/diff-preview.js +174 -0
- package/dist/utils/diff-preview.js.map +1 -0
- package/dist/utils/index.d.ts +8 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +8 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/memory.d.ts +81 -0
- package/dist/utils/memory.d.ts.map +1 -0
- package/dist/utils/memory.js +186 -0
- package/dist/utils/memory.js.map +1 -0
- package/dist/utils/project-context.d.ts +62 -0
- package/dist/utils/project-context.d.ts.map +1 -0
- package/dist/utils/project-context.js +197 -0
- package/dist/utils/project-context.js.map +1 -0
- package/docs/API_KEY_GUIDE.md +6 -0
- package/docs/FAQ.md +25 -3
- package/package.json +41 -9
- package/ROADMAP.md +0 -61
- package/dist/app/agent.d.ts +0 -31
- package/dist/app/agent.d.ts.map +0 -1
- package/dist/app/agent.js +0 -106
- package/dist/app/agent.js.map +0 -1
- package/dist/app/index.d.ts +0 -39
- package/dist/app/index.d.ts.map +0 -1
- package/dist/app/index.js +0 -80
- package/dist/app/index.js.map +0 -1
- package/dist/cmd/index.d.ts +0 -12
- package/dist/cmd/index.js +0 -85
- package/dist/cmd/index.js.map +0 -1
- package/dist/config/index.d.ts +0 -39
- package/dist/config/index.d.ts.map +0 -1
- package/dist/config/index.js +0 -110
- package/dist/config/index.js.map +0 -1
- package/dist/config/providers.d.ts +0 -23
- package/dist/config/providers.d.ts.map +0 -1
- package/dist/config/providers.js +0 -152
- package/dist/config/providers.js.map +0 -1
- package/dist/config/types.d.ts +0 -33
- package/dist/config/types.d.ts.map +0 -1
- package/dist/config/types.js +0 -5
- package/dist/config/types.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -31
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -71
- package/dist/hooks/index.js.map +0 -1
- package/dist/llm/anthropic.d.ts +0 -17
- package/dist/llm/anthropic.d.ts.map +0 -1
- package/dist/llm/anthropic.js +0 -126
- package/dist/llm/anthropic.js.map +0 -1
- package/dist/llm/gemini.d.ts +0 -16
- package/dist/llm/gemini.d.ts.map +0 -1
- package/dist/llm/gemini.js +0 -107
- package/dist/llm/gemini.js.map +0 -1
- package/dist/llm/index.d.ts +0 -48
- package/dist/llm/index.d.ts.map +0 -1
- package/dist/llm/index.js +0 -174
- package/dist/llm/index.js.map +0 -1
- package/dist/llm/openai.d.ts +0 -17
- package/dist/llm/openai.d.ts.map +0 -1
- package/dist/llm/openai.js +0 -113
- package/dist/llm/openai.js.map +0 -1
- package/dist/llm/provider.d.ts +0 -33
- package/dist/llm/provider.d.ts.map +0 -1
- package/dist/llm/provider.js +0 -6
- package/dist/llm/provider.js.map +0 -1
- package/dist/prompts/index.d.ts +0 -27
- package/dist/prompts/index.d.ts.map +0 -1
- package/dist/prompts/index.js +0 -102
- package/dist/prompts/index.js.map +0 -1
- package/dist/session/compactor.d.ts +0 -48
- package/dist/session/compactor.d.ts.map +0 -1
- package/dist/session/compactor.js +0 -77
- package/dist/session/compactor.js.map +0 -1
- package/dist/session/index.d.ts +0 -48
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -69
- package/dist/session/index.js.map +0 -1
- package/dist/session/message.d.ts +0 -26
- package/dist/session/message.d.ts.map +0 -1
- package/dist/session/message.js +0 -34
- package/dist/session/message.js.map +0 -1
- package/dist/tools/types.d.ts +0 -68
- package/dist/tools/types.d.ts.map +0 -1
- package/dist/tools/types.js +0 -57
- package/dist/tools/types.js.map +0 -1
- package/dist/tui/index.d.ts +0 -8
- package/dist/tui/index.d.ts.map +0 -1
- package/dist/tui/index.js +0 -8
- package/dist/tui/index.js.map +0 -1
- package/dist/tui/input.d.ts +0 -14
- package/dist/tui/input.d.ts.map +0 -1
- package/dist/tui/input.js +0 -50
- package/dist/tui/input.js.map +0 -1
- package/dist/tui/output.d.ts +0 -20
- package/dist/tui/output.d.ts.map +0 -1
- package/dist/tui/output.js +0 -70
- package/dist/tui/output.js.map +0 -1
- package/dist/tui/repl.d.ts +0 -25
- package/dist/tui/repl.d.ts.map +0 -1
- package/dist/tui/repl.js +0 -114
- package/dist/tui/repl.js.map +0 -1
- package/dist/tui/welcome.d.ts +0 -15
- package/dist/tui/welcome.d.ts.map +0 -1
- package/dist/tui/welcome.js +0 -86
- package/dist/tui/welcome.js.map +0 -1
- package/dist/types.d.ts +0 -38
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -6
- package/dist/types.js.map +0 -1
- package/dist/utils/diff.d.ts +0 -22
- package/dist/utils/diff.d.ts.map +0 -1
- package/dist/utils/diff.js +0 -60
- package/dist/utils/diff.js.map +0 -1
- package/dist/utils/project.d.ts +0 -32
- package/dist/utils/project.d.ts.map +0 -1
- package/dist/utils/project.js +0 -89
- package/dist/utils/project.js.map +0 -1
- package/src/app/agent.ts +0 -140
- package/src/app/index.ts +0 -101
- package/src/cmd/index.ts +0 -96
- package/src/config/index.ts +0 -130
- package/src/config/providers.ts +0 -160
- package/src/config/types.ts +0 -46
- package/src/hooks/index.ts +0 -111
- package/src/llm/anthropic.ts +0 -146
- package/src/llm/gemini.ts +0 -127
- package/src/llm/index.ts +0 -209
- package/src/llm/openai.ts +0 -132
- package/src/llm/provider.ts +0 -38
- package/src/mcp/client.ts +0 -330
- package/src/prompts/index.ts +0 -123
- package/src/session/compactor.ts +0 -103
- package/src/session/index.ts +0 -81
- package/src/session/message.ts +0 -42
- package/src/tools/file.ts +0 -117
- package/src/tools/git.ts +0 -132
- package/src/tools/index.ts +0 -108
- package/src/tools/search.ts +0 -263
- package/src/tools/shell.ts +0 -136
- package/src/tools/types.ts +0 -122
- package/src/tui/index.ts +0 -8
- package/src/tui/input.ts +0 -56
- package/src/tui/output.ts +0 -83
- package/src/tui/repl.ts +0 -131
- package/src/tui/welcome.ts +0 -101
- package/src/types.ts +0 -42
- package/src/utils/diff.ts +0 -71
- package/src/utils/project.ts +0 -99
- package/tsconfig.json +0 -19
package/dist/tools/shell.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shell Tool - Execute shell commands with security checks
|
|
3
|
-
* Migrated from old src/tools/shell.ts (permission logic inlined)
|
|
4
3
|
*/
|
|
5
4
|
import { exec } from 'child_process';
|
|
6
5
|
import { promisify } from 'util';
|
|
6
|
+
// Shared permission checker instance
|
|
7
|
+
let permissionChecker = null;
|
|
8
|
+
export function setPermissionChecker(checker) {
|
|
9
|
+
permissionChecker = checker;
|
|
10
|
+
}
|
|
7
11
|
const execAsync = promisify(exec);
|
|
8
|
-
// Dangerous command patterns
|
|
12
|
+
// Dangerous command patterns
|
|
9
13
|
const DANGEROUS_PATTERNS = [
|
|
10
|
-
/^rm\s+-rf\s+\//i,
|
|
11
|
-
/^del\s+\/f\s+\/s\s+\/q/i,
|
|
12
|
-
/^format\s+[a-z]:/i,
|
|
13
|
-
/^mkfs/i,
|
|
14
|
-
/^dd\s+if=/i,
|
|
15
|
-
/^shred/i,
|
|
16
|
-
/^cat\s+\/dev\/null\s*>/i,
|
|
17
|
-
/>\s*\/dev\/sda/i,
|
|
18
|
-
/^rm\s+-rf\s+\$HOME/i,
|
|
19
|
-
/^rm\s+-rf\s+%USERPROFILE%/i
|
|
20
|
-
/^curl\s+.*\|.*sh/i,
|
|
21
|
-
/^wget\s+.*\|.*sh/i,
|
|
22
|
-
/^eval\s+/i,
|
|
23
|
-
/base64\s+-d\s+.*\|/i,
|
|
14
|
+
/^rm\s+-rf\s+\//i, // rm -rf /
|
|
15
|
+
/^del\s+\/f\s+\/s\s+\/q/i, // del /f /s /q
|
|
16
|
+
/^format\s+[a-z]:/i, // format c:
|
|
17
|
+
/^mkfs/i, // mkfs
|
|
18
|
+
/^dd\s+if=/i, // dd if=
|
|
19
|
+
/^shred/i, // shred
|
|
20
|
+
/^cat\s+\/dev\/null\s*>/i, // cat /dev/null >
|
|
21
|
+
/>\s*\/dev\/sda/i, // Write to disk
|
|
22
|
+
/^rm\s+-rf\s+\$HOME/i, // rm -rf $HOME
|
|
23
|
+
/^rm\s+-rf\s+%USERPROFILE%/i // Windows user profile
|
|
24
24
|
];
|
|
25
|
-
// Commands that need
|
|
25
|
+
// Commands that need confirmation
|
|
26
26
|
const CONFIRM_REQUIRED = [
|
|
27
27
|
'rm -rf',
|
|
28
28
|
'rmdir',
|
|
@@ -31,64 +31,94 @@ const CONFIRM_REQUIRED = [
|
|
|
31
31
|
'mkfs',
|
|
32
32
|
'dd',
|
|
33
33
|
'shutdown',
|
|
34
|
-
'
|
|
35
|
-
'
|
|
36
|
-
'
|
|
37
|
-
'
|
|
38
|
-
'
|
|
34
|
+
'restart',
|
|
35
|
+
'init 0',
|
|
36
|
+
'init 6',
|
|
37
|
+
'poweroff',
|
|
38
|
+
'reboot'
|
|
39
39
|
];
|
|
40
40
|
export class ShellTool {
|
|
41
41
|
name = 'shell';
|
|
42
|
-
description = 'Execute shell commands and scripts.
|
|
42
|
+
description = 'Execute shell commands and scripts. Use with caution - some commands require user confirmation.';
|
|
43
|
+
/** S02: Input schema for shell command */
|
|
43
44
|
inputSchema = {
|
|
44
45
|
type: 'object',
|
|
45
46
|
properties: {
|
|
46
47
|
command: { type: 'string', description: 'Shell command to execute' },
|
|
47
48
|
cwd: { type: 'string', description: 'Working directory' },
|
|
48
|
-
timeout: { type: 'number', description: 'Timeout in seconds', default: 30 }
|
|
49
|
+
timeout: { type: 'number', description: 'Timeout in seconds', default: 30 }
|
|
49
50
|
},
|
|
50
|
-
required: ['command']
|
|
51
|
+
required: ['command']
|
|
51
52
|
};
|
|
53
|
+
/** S02: Tool metadata — permission and category info */
|
|
52
54
|
metadata = {
|
|
53
55
|
permissions: ['execute', 'write', 'network'],
|
|
54
56
|
tags: ['shell', 'system', 'dangerous'],
|
|
55
|
-
maxDuration: 120000,
|
|
56
|
-
version: '1.0.0'
|
|
57
|
+
maxDuration: 120000, // 2 min max
|
|
58
|
+
version: '1.0.0'
|
|
57
59
|
};
|
|
58
60
|
parameters = [
|
|
59
61
|
{ name: 'command', type: 'string', description: 'Shell command to execute', required: true },
|
|
60
62
|
{ name: 'cwd', type: 'string', description: 'Working directory', required: false },
|
|
61
|
-
{ name: 'timeout', type: 'number', description: 'Timeout in seconds', required: false }
|
|
63
|
+
{ name: 'timeout', type: 'number', description: 'Timeout in seconds', required: false }
|
|
62
64
|
];
|
|
63
65
|
/**
|
|
64
|
-
* Check if command
|
|
66
|
+
* Check if command is dangerous
|
|
65
67
|
*/
|
|
66
68
|
isDangerous(command) {
|
|
67
69
|
return DANGEROUS_PATTERNS.some(pattern => pattern.test(command.trim()));
|
|
68
70
|
}
|
|
69
71
|
/**
|
|
70
|
-
* Check if command needs
|
|
72
|
+
* Check if command needs confirmation
|
|
71
73
|
*/
|
|
72
74
|
needsConfirmation(command) {
|
|
73
75
|
const lower = command.toLowerCase();
|
|
74
76
|
return CONFIRM_REQUIRED.some(cmd => lower.includes(cmd.toLowerCase()));
|
|
75
77
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Validate command before execution
|
|
80
|
+
*/
|
|
81
|
+
validateCommand(command) {
|
|
78
82
|
if (!command || typeof command !== 'string') {
|
|
79
|
-
return
|
|
83
|
+
return 'Command is required and must be a string';
|
|
80
84
|
}
|
|
81
85
|
const trimmed = command.trim();
|
|
82
|
-
//
|
|
86
|
+
// Check for dangerous commands
|
|
83
87
|
if (this.isDangerous(trimmed)) {
|
|
84
|
-
return
|
|
88
|
+
return `Dangerous command blocked: ${trimmed.substring(0, 50)}...`;
|
|
85
89
|
}
|
|
90
|
+
// Check command length
|
|
86
91
|
if (trimmed.length > 10000) {
|
|
87
|
-
return
|
|
92
|
+
return 'Command too long (max 10000 characters)';
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
async execute(params, ctx) {
|
|
97
|
+
const { command, cwd, timeout = 30 } = params;
|
|
98
|
+
// Validate command
|
|
99
|
+
const validationError = this.validateCommand(command);
|
|
100
|
+
if (validationError) {
|
|
101
|
+
return { success: false, error: validationError };
|
|
88
102
|
}
|
|
89
|
-
//
|
|
90
|
-
if (
|
|
91
|
-
const
|
|
103
|
+
// S03: 6-stage permission check
|
|
104
|
+
if (permissionChecker) {
|
|
105
|
+
const result = await permissionChecker.check('shell', params, ctx || {});
|
|
106
|
+
if (!result.allowed) {
|
|
107
|
+
return { success: false, error: `Permission denied: ${result.reason}` };
|
|
108
|
+
}
|
|
109
|
+
if (result.requiresConfirmation) {
|
|
110
|
+
// Ask user for confirmation
|
|
111
|
+
if (ctx?.confirmAction) {
|
|
112
|
+
const confirmed = await ctx.confirmAction(`⚠️ Confirm command:\n ${command}\n\n[y] Yes [n] No`);
|
|
113
|
+
if (!confirmed) {
|
|
114
|
+
return { success: false, error: 'Command cancelled by user' };
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else if (ctx?.confirmAction && this.needsConfirmation(command)) {
|
|
120
|
+
// Fallback confirmation
|
|
121
|
+
const confirmed = await ctx.confirmAction(`Execute this command?\n ${command}\n\nType 'y' to confirm or 'n' to cancel:`);
|
|
92
122
|
if (!confirmed) {
|
|
93
123
|
return { success: false, error: 'Command cancelled by user' };
|
|
94
124
|
}
|
|
@@ -96,21 +126,27 @@ export class ShellTool {
|
|
|
96
126
|
try {
|
|
97
127
|
const options = {
|
|
98
128
|
timeout: timeout * 1000,
|
|
99
|
-
maxBuffer: 10 * 1024 * 1024
|
|
129
|
+
maxBuffer: 10 * 1024 * 1024 // 10MB
|
|
100
130
|
};
|
|
101
|
-
if (cwd)
|
|
131
|
+
if (cwd) {
|
|
102
132
|
options.cwd = cwd;
|
|
133
|
+
}
|
|
103
134
|
const { stdout, stderr } = await execAsync(command, options);
|
|
104
135
|
const stdoutStr = stdout?.toString() || '';
|
|
105
136
|
const stderrStr = stderr?.toString() || '';
|
|
137
|
+
// Combine output, prioritize stdout
|
|
106
138
|
const output = stdoutStr + (stderrStr ? `\n[stderr]: ${stderrStr}` : '');
|
|
107
139
|
return { success: true, output: output.trim() || '(command executed successfully with no output)' };
|
|
108
140
|
}
|
|
109
141
|
catch (error) {
|
|
142
|
+
// Handle timeout
|
|
110
143
|
if (error.killed) {
|
|
111
144
|
return { success: false, error: 'Command timed out' };
|
|
112
145
|
}
|
|
113
|
-
return {
|
|
146
|
+
return {
|
|
147
|
+
success: false,
|
|
148
|
+
error: error.message || 'Command execution failed'
|
|
149
|
+
};
|
|
114
150
|
}
|
|
115
151
|
}
|
|
116
152
|
}
|
package/dist/tools/shell.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/tools/shell.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shell.js","sourceRoot":"","sources":["../../src/tools/shell.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,OAAO,EAAE,IAAI,EAAS,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAEjC,qCAAqC;AACrC,IAAI,iBAAiB,GAA6B,IAAI,CAAC;AAEvD,MAAM,UAAU,oBAAoB,CAAC,OAA0B;IAC7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AAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Preview - Show file changes before modification
|
|
3
|
+
* Simple implementation without external dependencies
|
|
4
|
+
*/
|
|
5
|
+
export interface DiffResult {
|
|
6
|
+
hasChanges: boolean;
|
|
7
|
+
oldContent?: string;
|
|
8
|
+
newContent?: string;
|
|
9
|
+
diff?: string;
|
|
10
|
+
preview?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare class DiffPreview {
|
|
13
|
+
/**
|
|
14
|
+
* Compare old and new content and generate diff
|
|
15
|
+
*/
|
|
16
|
+
static compare(oldContent: string, newContent: string): DiffResult;
|
|
17
|
+
/**
|
|
18
|
+
* Compute simple line-by-line diff
|
|
19
|
+
*/
|
|
20
|
+
private static computeDiff;
|
|
21
|
+
/**
|
|
22
|
+
* Find longest common subsequence
|
|
23
|
+
*/
|
|
24
|
+
private static longestCommonSubsequence;
|
|
25
|
+
/**
|
|
26
|
+
* Show diff between file and proposed changes
|
|
27
|
+
*/
|
|
28
|
+
static diffFile(filePath: string, newContent: string): DiffResult;
|
|
29
|
+
/**
|
|
30
|
+
* Format diff for display with colors
|
|
31
|
+
*/
|
|
32
|
+
private static formatDiff;
|
|
33
|
+
/**
|
|
34
|
+
* Format a compact preview
|
|
35
|
+
*/
|
|
36
|
+
private static formatPreview;
|
|
37
|
+
/**
|
|
38
|
+
* Check if changes are significant
|
|
39
|
+
*/
|
|
40
|
+
static isSignificant(oldContent: string, newContent: string, threshold?: number): boolean;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=diff-preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diff-preview.d.ts","sourceRoot":"","sources":["../../src/utils/diff-preview.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,MAAM,WAAW,UAAU;IACzB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,WAAW;IACtB;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU;IAmBlE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,WAAW;IA+C1B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,wBAAwB;IAiCvC;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,UAAU;IAcjE;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAoBzB;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IAgB5B;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,OAAO;CAU/F"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diff Preview - Show file changes before modification
|
|
3
|
+
* Simple implementation without external dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { readFileSync, existsSync } from 'fs';
|
|
6
|
+
export class DiffPreview {
|
|
7
|
+
/**
|
|
8
|
+
* Compare old and new content and generate diff
|
|
9
|
+
*/
|
|
10
|
+
static compare(oldContent, newContent) {
|
|
11
|
+
const oldLines = oldContent.split('\n');
|
|
12
|
+
const newLines = newContent.split('\n');
|
|
13
|
+
const diff = this.computeDiff(oldLines, newLines);
|
|
14
|
+
if (diff.length === 0) {
|
|
15
|
+
return { hasChanges: false };
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
hasChanges: true,
|
|
19
|
+
oldContent,
|
|
20
|
+
newContent,
|
|
21
|
+
diff: this.formatDiff(diff),
|
|
22
|
+
preview: this.formatPreview(diff)
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Compute simple line-by-line diff
|
|
27
|
+
*/
|
|
28
|
+
static computeDiff(oldLines, newLines) {
|
|
29
|
+
const result = [];
|
|
30
|
+
// Simple LCS-based diff
|
|
31
|
+
const lcs = this.longestCommonSubsequence(oldLines, newLines);
|
|
32
|
+
let oldIdx = 0;
|
|
33
|
+
let newIdx = 0;
|
|
34
|
+
let lcsIdx = 0;
|
|
35
|
+
while (oldIdx < oldLines.length || newIdx < newLines.length) {
|
|
36
|
+
if (lcsIdx < lcs.length) {
|
|
37
|
+
// Output removed lines from old
|
|
38
|
+
while (oldIdx < oldLines.length && oldLines[oldIdx] !== lcs[lcsIdx]) {
|
|
39
|
+
result.push({ type: 'removed', content: oldLines[oldIdx] });
|
|
40
|
+
oldIdx++;
|
|
41
|
+
}
|
|
42
|
+
// Output added lines from new
|
|
43
|
+
while (newIdx < newLines.length && newLines[newIdx] !== lcs[lcsIdx]) {
|
|
44
|
+
result.push({ type: 'added', content: newLines[newIdx] });
|
|
45
|
+
newIdx++;
|
|
46
|
+
}
|
|
47
|
+
// Output common line
|
|
48
|
+
if (oldIdx < oldLines.length && newIdx < newLines.length) {
|
|
49
|
+
result.push({ type: 'unchanged', content: oldLines[oldIdx] });
|
|
50
|
+
oldIdx++;
|
|
51
|
+
newIdx++;
|
|
52
|
+
lcsIdx++;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// Remaining lines
|
|
57
|
+
while (oldIdx < oldLines.length) {
|
|
58
|
+
result.push({ type: 'removed', content: oldLines[oldIdx] });
|
|
59
|
+
oldIdx++;
|
|
60
|
+
}
|
|
61
|
+
while (newIdx < newLines.length) {
|
|
62
|
+
result.push({ type: 'added', content: newLines[newIdx] });
|
|
63
|
+
newIdx++;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Find longest common subsequence
|
|
71
|
+
*/
|
|
72
|
+
static longestCommonSubsequence(a, b) {
|
|
73
|
+
const m = a.length;
|
|
74
|
+
const n = b.length;
|
|
75
|
+
const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
|
|
76
|
+
for (let i = 1; i <= m; i++) {
|
|
77
|
+
for (let j = 1; j <= n; j++) {
|
|
78
|
+
if (a[i - 1] === b[j - 1]) {
|
|
79
|
+
dp[i][j] = dp[i - 1][j - 1] + 1;
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
dp[i][j] = Math.max(dp[i - 1][j], dp[i][j - 1]);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
// Backtrack to find LCS
|
|
87
|
+
const lcs = [];
|
|
88
|
+
let i = m, j = n;
|
|
89
|
+
while (i > 0 && j > 0) {
|
|
90
|
+
if (a[i - 1] === b[j - 1]) {
|
|
91
|
+
lcs.unshift(a[i - 1]);
|
|
92
|
+
i--;
|
|
93
|
+
j--;
|
|
94
|
+
}
|
|
95
|
+
else if (dp[i - 1][j] > dp[i][j - 1]) {
|
|
96
|
+
i--;
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
j--;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return lcs;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Show diff between file and proposed changes
|
|
106
|
+
*/
|
|
107
|
+
static diffFile(filePath, newContent) {
|
|
108
|
+
let oldContent = '';
|
|
109
|
+
if (existsSync(filePath)) {
|
|
110
|
+
try {
|
|
111
|
+
oldContent = readFileSync(filePath, 'utf-8');
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// File exists but can't read
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return this.compare(oldContent, newContent);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Format diff for display with colors
|
|
121
|
+
*/
|
|
122
|
+
static formatDiff(diff) {
|
|
123
|
+
const lines = [];
|
|
124
|
+
const green = '\x1b[32m';
|
|
125
|
+
const red = '\x1b[31m';
|
|
126
|
+
const gray = '\x1b[90m';
|
|
127
|
+
const reset = '\x1b[0m';
|
|
128
|
+
for (const chunk of diff) {
|
|
129
|
+
if (chunk.type === 'added') {
|
|
130
|
+
lines.push(`${green}+ ${chunk.content}${reset}`);
|
|
131
|
+
}
|
|
132
|
+
else if (chunk.type === 'removed') {
|
|
133
|
+
lines.push(`${red}- ${chunk.content}${reset}`);
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
lines.push(`${gray} ${chunk.content}${reset}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return lines.join('\n');
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Format a compact preview
|
|
143
|
+
*/
|
|
144
|
+
static formatPreview(diff) {
|
|
145
|
+
let added = 0;
|
|
146
|
+
let removed = 0;
|
|
147
|
+
for (const chunk of diff) {
|
|
148
|
+
if (chunk.type === 'added')
|
|
149
|
+
added++;
|
|
150
|
+
if (chunk.type === 'removed')
|
|
151
|
+
removed++;
|
|
152
|
+
}
|
|
153
|
+
const parts = [];
|
|
154
|
+
if (added > 0)
|
|
155
|
+
parts.push(`+${added}`);
|
|
156
|
+
if (removed > 0)
|
|
157
|
+
parts.push(`-${removed}`);
|
|
158
|
+
return parts.join(' ') || 'No changes';
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Check if changes are significant
|
|
162
|
+
*/
|
|
163
|
+
static isSignificant(oldContent, newContent, threshold = 0.1) {
|
|
164
|
+
if (!oldContent && !newContent)
|
|
165
|
+
return false;
|
|
166
|
+
if (!oldContent || !newContent)
|
|
167
|
+
return true;
|
|
168
|
+
const oldLines = oldContent.split('\n').length;
|
|
169
|
+
const newLines = newContent.split('\n').length;
|
|
170
|
+
const changeRatio = Math.abs(newLines - oldLines) / oldLines;
|
|
171
|
+
return changeRatio > threshold;
|
|
172
|
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C,CAAC;QAE3C,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,UAAkB,EAAE,UAAkB,EAAE,YAAoB,GAAG;QAClF,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU;YAAE,OAAO,KAAK,CAAC;QAC7C,IAAI,CAAC,UAAU,IAAI,CAAC,UAAU;YAAE,OAAO,IAAI,CAAC;QAE5C,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QAC/C,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;QAE/C,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC;QAC7D,OAAO,WAAW,GAAG,SAAS,CAAC;IACjC,CAAC;CACF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils Module
|
|
3
|
+
* Utility functions for diff, project context, and memory
|
|
4
|
+
*/
|
|
5
|
+
export { DiffPreview, type DiffResult } from './diff-preview.js';
|
|
6
|
+
export { ProjectContext, type ProjectInfo, type PackageJson } from './project-context.js';
|
|
7
|
+
export { SessionMemory, type MemoryEntry } from './memory.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utils Module
|
|
3
|
+
* Utility functions for diff, project context, and memory
|
|
4
|
+
*/
|
|
5
|
+
export { DiffPreview } from './diff-preview.js';
|
|
6
|
+
export { ProjectContext } from './project-context.js';
|
|
7
|
+
export { SessionMemory } from './memory.js';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,WAAW,EAAmB,MAAM,mBAAmB,CAAC;AACjE,OAAO,EAAE,cAAc,EAAsC,MAAM,sBAAsB,CAAC;AAC1F,OAAO,EAAE,aAAa,EAAoB,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Memory - Remember modifications during conversation
|
|
3
|
+
*/
|
|
4
|
+
export interface MemoryEntry {
|
|
5
|
+
id: string;
|
|
6
|
+
timestamp: number;
|
|
7
|
+
type: 'file_read' | 'file_write' | 'file_edit' | 'command' | 'git' | 'note';
|
|
8
|
+
description: string;
|
|
9
|
+
details: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export declare class SessionMemory {
|
|
12
|
+
private entries;
|
|
13
|
+
private sessionId;
|
|
14
|
+
private memoryFile?;
|
|
15
|
+
constructor(sessionId?: string);
|
|
16
|
+
/**
|
|
17
|
+
* Add an entry to memory
|
|
18
|
+
*/
|
|
19
|
+
add(entry: Omit<MemoryEntry, 'id' | 'timestamp'>): void;
|
|
20
|
+
/**
|
|
21
|
+
* Record file read
|
|
22
|
+
*/
|
|
23
|
+
recordRead(path: string, lines?: number): void;
|
|
24
|
+
/**
|
|
25
|
+
* Record file write
|
|
26
|
+
*/
|
|
27
|
+
recordWrite(path: string, content?: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Record file edit
|
|
30
|
+
*/
|
|
31
|
+
recordEdit(path: string, operation: string): void;
|
|
32
|
+
/**
|
|
33
|
+
* Record command execution
|
|
34
|
+
*/
|
|
35
|
+
recordCommand(command: string, output?: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Record git operation
|
|
38
|
+
*/
|
|
39
|
+
recordGit(operation: string, result: string): void;
|
|
40
|
+
/**
|
|
41
|
+
* Record a note
|
|
42
|
+
*/
|
|
43
|
+
recordNote(note: string): void;
|
|
44
|
+
/**
|
|
45
|
+
* Get all entries
|
|
46
|
+
*/
|
|
47
|
+
getEntries(): MemoryEntry[];
|
|
48
|
+
/**
|
|
49
|
+
* Get recent entries
|
|
50
|
+
*/
|
|
51
|
+
getRecent(count?: number): MemoryEntry[];
|
|
52
|
+
/**
|
|
53
|
+
* Get entries by type
|
|
54
|
+
*/
|
|
55
|
+
getByType(type: MemoryEntry['type']): MemoryEntry[];
|
|
56
|
+
/**
|
|
57
|
+
* Search entries
|
|
58
|
+
*/
|
|
59
|
+
search(query: string): MemoryEntry[];
|
|
60
|
+
/**
|
|
61
|
+
* Get summary
|
|
62
|
+
*/
|
|
63
|
+
getSummary(): string;
|
|
64
|
+
/**
|
|
65
|
+
* Export to file
|
|
66
|
+
*/
|
|
67
|
+
save(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Load from file
|
|
70
|
+
*/
|
|
71
|
+
load(sessionId: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Clear memory
|
|
74
|
+
*/
|
|
75
|
+
clear(): void;
|
|
76
|
+
/**
|
|
77
|
+
* Generate unique ID
|
|
78
|
+
*/
|
|
79
|
+
private generateId;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../../src/utils/memory.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAA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