@gaunt-sloth/core 0.0.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.
Files changed (89) hide show
  1. package/.gsloth.backstory.md +17 -0
  2. package/.gsloth.chat.md +11 -0
  3. package/.gsloth.code.md +27 -0
  4. package/.gsloth.guidelines.md +1 -0
  5. package/.gsloth.review.md +15 -0
  6. package/.gsloth.system.md +10 -0
  7. package/README.md +27 -0
  8. package/dist/config.d.ts +533 -0
  9. package/dist/config.js +412 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/constants.d.ts +13 -0
  12. package/dist/constants.js +14 -0
  13. package/dist/constants.js.map +1 -0
  14. package/dist/core/GthAgentRunner.d.ts +27 -0
  15. package/dist/core/GthAgentRunner.js +109 -0
  16. package/dist/core/GthAgentRunner.js.map +1 -0
  17. package/dist/core/GthLangChainAgent.d.ts +56 -0
  18. package/dist/core/GthLangChainAgent.js +355 -0
  19. package/dist/core/GthLangChainAgent.js.map +1 -0
  20. package/dist/core/types.d.ts +39 -0
  21. package/dist/core/types.js +16 -0
  22. package/dist/core/types.js.map +1 -0
  23. package/dist/index.d.ts +3 -0
  24. package/dist/index.js +4 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/providers/anthropic.d.ts +7 -0
  27. package/dist/providers/anthropic.js +34 -0
  28. package/dist/providers/anthropic.js.map +1 -0
  29. package/dist/providers/deepseek.d.ts +4 -0
  30. package/dist/providers/deepseek.js +30 -0
  31. package/dist/providers/deepseek.js.map +1 -0
  32. package/dist/providers/fake.d.ts +3 -0
  33. package/dist/providers/fake.js +12 -0
  34. package/dist/providers/fake.js.map +1 -0
  35. package/dist/providers/google-genai.d.ts +7 -0
  36. package/dist/providers/google-genai.js +34 -0
  37. package/dist/providers/google-genai.js.map +1 -0
  38. package/dist/providers/groq.d.ts +4 -0
  39. package/dist/providers/groq.js +30 -0
  40. package/dist/providers/groq.js.map +1 -0
  41. package/dist/providers/openai.d.ts +5 -0
  42. package/dist/providers/openai.js +46 -0
  43. package/dist/providers/openai.js.map +1 -0
  44. package/dist/providers/openrouter.d.ts +5 -0
  45. package/dist/providers/openrouter.js +57 -0
  46. package/dist/providers/openrouter.js.map +1 -0
  47. package/dist/providers/vertexai.d.ts +7 -0
  48. package/dist/providers/vertexai.js +41 -0
  49. package/dist/providers/vertexai.js.map +1 -0
  50. package/dist/providers/xai.d.ts +4 -0
  51. package/dist/providers/xai.js +30 -0
  52. package/dist/providers/xai.js.map +1 -0
  53. package/dist/state/artifactStore.d.ts +21 -0
  54. package/dist/state/artifactStore.js +30 -0
  55. package/dist/state/artifactStore.js.map +1 -0
  56. package/dist/utils/ProgressIndicator.d.ts +7 -0
  57. package/dist/utils/ProgressIndicator.js +26 -0
  58. package/dist/utils/ProgressIndicator.js.map +1 -0
  59. package/dist/utils/aiignoreUtils.d.ts +29 -0
  60. package/dist/utils/aiignoreUtils.js +82 -0
  61. package/dist/utils/aiignoreUtils.js.map +1 -0
  62. package/dist/utils/binaryOutputUtils.d.ts +13 -0
  63. package/dist/utils/binaryOutputUtils.js +138 -0
  64. package/dist/utils/binaryOutputUtils.js.map +1 -0
  65. package/dist/utils/consoleUtils.d.ts +76 -0
  66. package/dist/utils/consoleUtils.js +230 -0
  67. package/dist/utils/consoleUtils.js.map +1 -0
  68. package/dist/utils/debugUtils.d.ts +20 -0
  69. package/dist/utils/debugUtils.js +89 -0
  70. package/dist/utils/debugUtils.js.map +1 -0
  71. package/dist/utils/fileUtils.d.ts +68 -0
  72. package/dist/utils/fileUtils.js +216 -0
  73. package/dist/utils/fileUtils.js.map +1 -0
  74. package/dist/utils/globalConfigUtils.d.ts +28 -0
  75. package/dist/utils/globalConfigUtils.js +61 -0
  76. package/dist/utils/globalConfigUtils.js.map +1 -0
  77. package/dist/utils/llmUtils.d.ts +39 -0
  78. package/dist/utils/llmUtils.js +153 -0
  79. package/dist/utils/llmUtils.js.map +1 -0
  80. package/dist/utils/stringUtils.d.ts +4 -0
  81. package/dist/utils/stringUtils.js +10 -0
  82. package/dist/utils/stringUtils.js.map +1 -0
  83. package/dist/utils/systemUtils.d.ts +70 -0
  84. package/dist/utils/systemUtils.js +207 -0
  85. package/dist/utils/systemUtils.js.map +1 -0
  86. package/dist/utils/vertexaiUtils.d.ts +2 -0
  87. package/dist/utils/vertexaiUtils.js +18 -0
  88. package/dist/utils/vertexaiUtils.js.map +1 -0
  89. package/package.json +57 -0
@@ -0,0 +1,216 @@
1
+ import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { getCurrentWorkDir } from '#src/utils/systemUtils.js';
5
+ import { GSLOTH_DIR, GSLOTH_SETTINGS_DIR } from '#src/constants.js';
6
+ import { displayError, displayInfo, displaySuccess, displayWarning, } from '#src/utils/consoleUtils.js';
7
+ import url from 'node:url';
8
+ /**
9
+ * Checks if .gsloth directory exists in the project root
10
+ * @returns Boolean indicating whether .gsloth directory exists
11
+ */
12
+ export function gslothDirExists() {
13
+ const currentDir = getCurrentWorkDir();
14
+ const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
15
+ return existsSync(gslothDirPath);
16
+ }
17
+ /**
18
+ * Gets the path where gsloth should write files based on .gsloth directory existence
19
+ * @param filename The filename to append to the path
20
+ * @returns The resolved path where the file should be written
21
+ */
22
+ export function getGslothFilePath(filename) {
23
+ const currentDir = getCurrentWorkDir();
24
+ if (gslothDirExists()) {
25
+ const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
26
+ return resolve(gslothDirPath, filename);
27
+ }
28
+ return resolve(currentDir, filename);
29
+ }
30
+ /**
31
+ * Gets the path where gsloth should write configuration files based on .gsloth directory existence.
32
+ * The main difference from {@link #getGslothConfigReadPath} is that this getGslothConfigWritePath
33
+ * method creates internal settings directory if it does not exist.
34
+ *
35
+ * If .gsloth dir exists returns `projectdir/.gsloth/.gsloth-settings`
36
+ * If .gsloth dir does not exist returns `projectdir`
37
+ *
38
+ * @param filename The configuration filename
39
+ * @returns The resolved path where the configuration file should be written
40
+ */
41
+ export function getGslothConfigWritePath(filename) {
42
+ const currentDir = getCurrentWorkDir();
43
+ if (gslothDirExists()) {
44
+ const gslothDirPath = resolve(currentDir, GSLOTH_DIR);
45
+ const gslothSettingsPath = resolve(gslothDirPath, GSLOTH_SETTINGS_DIR);
46
+ // Create .gsloth-settings directory if it doesn't exist
47
+ if (!existsSync(gslothSettingsPath)) {
48
+ mkdirSync(gslothSettingsPath, { recursive: true });
49
+ }
50
+ return resolve(gslothSettingsPath, filename);
51
+ }
52
+ return resolve(currentDir, filename);
53
+ }
54
+ /**
55
+ * Gets the path where gsloth should look for configuration files based on .gsloth directory existence
56
+ * @param filename The configuration filename to look for
57
+ * @param identityProfileRaw The identity profile dir within GSLOTH_SETTINGS_DIR to look for the configuration file in.
58
+ * @returns The resolved path where the configuration file should be found
59
+ */
60
+ export function getGslothConfigReadPath(filename, identityProfileRaw) {
61
+ const projectDir = getCurrentWorkDir();
62
+ const identityProfile = identityProfileRaw?.trim();
63
+ if (gslothDirExists()) {
64
+ const gslothDirPath = resolve(projectDir, GSLOTH_DIR);
65
+ const gslothSettingsPath = resolve(gslothDirPath, GSLOTH_SETTINGS_DIR);
66
+ const configPath = identityProfile
67
+ ? resolve(gslothSettingsPath, identityProfile, filename)
68
+ : resolve(gslothSettingsPath, filename);
69
+ if (existsSync(configPath)) {
70
+ return configPath;
71
+ }
72
+ }
73
+ return resolve(projectDir, filename);
74
+ }
75
+ /**
76
+ * Resolve an explicit output path string to an absolute file path.
77
+ * Concerned only with string values:
78
+ * - If the string includes a path separator, resolve relative to project root and ensure parent directories exist.
79
+ * - If it's a bare filename, place it under .gsloth/ when present, otherwise project root.
80
+ */
81
+ export function resolveOutputPath(writeOutputToFile) {
82
+ const currentDir = getCurrentWorkDir();
83
+ const provided = String(writeOutputToFile).trim();
84
+ // Detect if provided path contains path separators (cross-platform)
85
+ const hasSeparator = provided.includes('/') || provided.includes('\\');
86
+ // If no separators, treat as bare filename: prefer .gsloth/ when present
87
+ if (!hasSeparator) {
88
+ return getGslothFilePath(provided);
89
+ }
90
+ // If path contains directories, respect as-is and ensure parent dirs
91
+ const absolutePath = resolve(currentDir, provided);
92
+ const parentDir = dirname(absolutePath);
93
+ if (!existsSync(parentDir)) {
94
+ mkdirSync(parentDir, { recursive: true });
95
+ }
96
+ return absolutePath;
97
+ }
98
+ export function toFileSafeString(string) {
99
+ return string.replace(/[^A-Za-z0-9]/g, '-');
100
+ }
101
+ /**
102
+ * Returns a formatted date string in the format YYYY-MM-DD_HH-MM-SS using local time
103
+ * @returns A formatted date string
104
+ */
105
+ export function fileSafeLocalDate() {
106
+ const date = new Date();
107
+ // Format: YYYY-MM-DD_HH-MM-SS using local time directly
108
+ const year = date.getFullYear();
109
+ const month = String(date.getMonth() + 1).padStart(2, '0');
110
+ const day = String(date.getDate()).padStart(2, '0');
111
+ const hours = String(date.getHours()).padStart(2, '0');
112
+ const minutes = String(date.getMinutes()).padStart(2, '0');
113
+ const seconds = String(date.getSeconds()).padStart(2, '0');
114
+ return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;
115
+ }
116
+ /**
117
+ * Generates a standardized filename with the format: gth_YYYY-MM-DD_HH-MM-SS_COMMAND.md
118
+ * @param command - The command that created the file (ASK, REVIEW, PR, etc.)
119
+ * @returns A standardized filename string
120
+ */
121
+ export function generateStandardFileName(command) {
122
+ const dateTimeStr = fileSafeLocalDate();
123
+ const commandStr = toFileSafeString(command.toUpperCase());
124
+ return `gth_${dateTimeStr}_${commandStr}.md`;
125
+ }
126
+ export function readFileFromProjectDir(fileName) {
127
+ const currentDir = getCurrentWorkDir();
128
+ const filePath = resolve(currentDir, fileName);
129
+ displayInfo(`Reading file ${filePath}...`);
130
+ return readFileSyncWithMessages(filePath);
131
+ }
132
+ const corePackageDir = resolve(dirname(fileURLToPath(import.meta.url)), '..', '..');
133
+ export function readFileFromInstallDir(filePath) {
134
+ const installFilePath = resolve(corePackageDir, filePath);
135
+ try {
136
+ return readFileSync(installFilePath, { encoding: 'utf8' });
137
+ }
138
+ catch (readFromInstallDirError) {
139
+ displayError(`The ${installFilePath} not found or can\'t be read.`);
140
+ throw readFromInstallDirError;
141
+ }
142
+ }
143
+ export function writeFileIfNotExistsWithMessages(filePath, content) {
144
+ displayInfo(`checking ${filePath} existence`);
145
+ if (!existsSync(filePath)) {
146
+ // Create parent directories if they don't exist
147
+ const parentDir = dirname(filePath);
148
+ if (!existsSync(parentDir)) {
149
+ mkdirSync(parentDir, { recursive: true });
150
+ }
151
+ writeFileSync(filePath, content);
152
+ displaySuccess(`Created ${filePath}`);
153
+ }
154
+ else {
155
+ displayWarning(`${filePath} already exists`);
156
+ }
157
+ }
158
+ export function appendToFile(filePath, content) {
159
+ try {
160
+ const parentDir = dirname(filePath);
161
+ if (!existsSync(parentDir)) {
162
+ mkdirSync(parentDir, { recursive: true });
163
+ }
164
+ appendFileSync(filePath, content);
165
+ }
166
+ catch (e) {
167
+ displayError(`Failed to append to file ${filePath}: ${e.message}`);
168
+ }
169
+ }
170
+ export function readFileSyncWithMessages(filePath, errorMessageIn, noFileMessage) {
171
+ const errorMessage = errorMessageIn ?? 'Error reading file at: ';
172
+ try {
173
+ return readFileSync(filePath, { encoding: 'utf8' });
174
+ }
175
+ catch (error) {
176
+ displayError(errorMessage + filePath);
177
+ if (error.code === 'ENOENT') {
178
+ displayWarning(noFileMessage ?? 'Please ensure the file exists.');
179
+ }
180
+ else {
181
+ displayError(error.message);
182
+ }
183
+ throw error;
184
+ }
185
+ }
186
+ /**
187
+ * Dynamically imports a module from a file path from the outside of the installation dir
188
+ * @returns A promise that resolves to the imported module
189
+ */
190
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
191
+ export function importExternalFile(filePath) {
192
+ const configFileUrl = url.pathToFileURL(filePath).toString();
193
+ return import(configFileUrl);
194
+ }
195
+ /**
196
+ * Returns the output file path for a given command execution based on configuration.
197
+ * - If writeOutputToFile is false, returns null.
198
+ * - If writeOutputToFile is a string, resolves it without generating a default filename.
199
+ * - If writeOutputToFile is true, generates a standard filename from source and resolves it under .gsloth/ (when present) or project root.
200
+ */
201
+ export function getCommandOutputFilePath(config, source) {
202
+ const setting = config.writeOutputToFile;
203
+ if (setting === false) {
204
+ return null;
205
+ }
206
+ if (typeof setting === 'string') {
207
+ const trimmed = setting.trim();
208
+ if (trimmed.length === 0)
209
+ return null;
210
+ return resolveOutputPath(trimmed);
211
+ }
212
+ // setting === true -> generate filename and place it using getGslothFilePath
213
+ const filename = generateStandardFileName(source.toUpperCase());
214
+ return getGslothFilePath(filename);
215
+ }
216
+ //# sourceMappingURL=fileUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileUtils.js","sourceRoot":"","sources":["../../src/utils/fileUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACL,YAAY,EACZ,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,4BAA4B,CAAC;AACpC,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B;;;GAGG;AACH,MAAM,UAAU,eAAe;IAC7B,MAAM,UAAU,GAAG,iBAAiB,EAAE,CAAC;IACvC,MAAM,aAAa,GAAG,OAAO,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IACtD,OAAO,UAAU,CAAC,aAAa,CAAC,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,QAAgB;IACh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;IACd,CAAC;IAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;QAChC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,IAAI,CAAC;QACtC,OAAO,iBAAiB,CAAC,OAAO,CAAC,CAAC;IACpC,CAAC;IAED,6EAA6E;IAC7E,MAAM,QAAQ,GAAG,wBAAwB,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAChE,OAAO,iBAAiB,CAAC,QAAQ,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Gets the global .gsloth directory path in the user's home directory
3
+ * @returns The resolved path to the global .gsloth directory
4
+ */
5
+ export declare function getGlobalGslothDir(): string;
6
+ /**
7
+ * Ensures the global .gsloth directory exists in the user's home directory
8
+ * Creates it if it doesn't exist
9
+ * @returns The resolved path to the global .gsloth directory
10
+ */
11
+ export declare function ensureGlobalGslothDir(): string;
12
+ /**
13
+ * Gets the global auth directory path
14
+ * @returns The resolved path to the global auth directory
15
+ */
16
+ export declare function getGlobalAuthDir(): string;
17
+ /**
18
+ * Ensures the global auth directory exists
19
+ * Creates it if it doesn't exist
20
+ * @returns The resolved path to the global auth directory
21
+ */
22
+ export declare function ensureGlobalAuthDir(): string;
23
+ /**
24
+ * Gets the path for a specific OAuth provider's storage file
25
+ * @param serverUrl The server URL or identifier for the OAuth provider
26
+ * @returns The resolved path where the OAuth data should be stored
27
+ */
28
+ export declare function getOAuthStoragePath(serverUrl: string): string;
@@ -0,0 +1,61 @@
1
+ import { existsSync, mkdirSync } from 'node:fs';
2
+ import { resolve } from 'node:path';
3
+ import { homedir } from 'node:os';
4
+ import { GSLOTH_DIR, GSLOTH_AUTH } from '#src/constants.js';
5
+ /**
6
+ * Gets the global .gsloth directory path in the user's home directory
7
+ * @returns The resolved path to the global .gsloth directory
8
+ */
9
+ export function getGlobalGslothDir() {
10
+ return resolve(homedir(), GSLOTH_DIR);
11
+ }
12
+ /**
13
+ * Ensures the global .gsloth directory exists in the user's home directory
14
+ * Creates it if it doesn't exist
15
+ * @returns The resolved path to the global .gsloth directory
16
+ */
17
+ export function ensureGlobalGslothDir() {
18
+ const globalDir = getGlobalGslothDir();
19
+ if (!existsSync(globalDir)) {
20
+ mkdirSync(globalDir, { recursive: true });
21
+ }
22
+ return globalDir;
23
+ }
24
+ /**
25
+ * Gets the global auth directory path
26
+ * @returns The resolved path to the global auth directory
27
+ */
28
+ export function getGlobalAuthDir() {
29
+ const globalDir = getGlobalGslothDir();
30
+ return resolve(globalDir, GSLOTH_AUTH);
31
+ }
32
+ /**
33
+ * Ensures the global auth directory exists
34
+ * Creates it if it doesn't exist
35
+ * @returns The resolved path to the global auth directory
36
+ */
37
+ export function ensureGlobalAuthDir() {
38
+ // First ensure parent directory exists
39
+ ensureGlobalGslothDir();
40
+ const authDir = getGlobalAuthDir();
41
+ if (!existsSync(authDir)) {
42
+ mkdirSync(authDir, { recursive: true });
43
+ }
44
+ return authDir;
45
+ }
46
+ /**
47
+ * Gets the path for a specific OAuth provider's storage file
48
+ * @param serverUrl The server URL or identifier for the OAuth provider
49
+ * @returns The resolved path where the OAuth data should be stored
50
+ */
51
+ export function getOAuthStoragePath(serverUrl) {
52
+ const authDir = ensureGlobalAuthDir();
53
+ // Create a safe filename from the server URL
54
+ const safeFilename = serverUrl
55
+ .replace(/https?:\/\//, '')
56
+ .replace(/[^a-zA-Z0-9.-]/g, '_')
57
+ .replace(/_+/g, '_')
58
+ .toLowerCase();
59
+ return resolve(authDir, `${safeFilename}.json`);
60
+ }
61
+ //# sourceMappingURL=globalConfigUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"globalConfigUtils.js","sourceRoot":"","sources":["../../src/utils/globalConfigUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAChD,OAAO,EAAE,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AG,CAAC;SACnB,WAAW,EAAE,CAAC;IAEjB,OAAO,OAAO,CAAC,OAAO,EAAE,GAAG,YAAY,OAAO,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,39 @@
1
+ import { RunnableConfig } from '@langchain/core/runnables';
2
+ import { GthConfig } from '#src/config.js';
3
+ import { SystemMessage } from '@langchain/core/messages';
4
+ /**
5
+ * Creates new runnable config.
6
+ * configurable.thread_id is an important part of that because it helps to distinguish different chat sessions.
7
+ * We normally do not have multiple sessions in the terminal, but I had bad stuff happening in tests
8
+ * and in another prototype project where I was importing Gaunt Sloth.
9
+ */
10
+ export declare function getNewRunnableConfig(): RunnableConfig;
11
+ export declare function readBackstory(config: Pick<GthConfig, 'identityProfile' | 'noDefaultPrompts'>): string;
12
+ export declare function readGuidelines(config: Pick<GthConfig, 'projectGuidelines' | 'includeCurrentDateAfterGuidelines' | 'organization' | 'identityProfile' | 'noDefaultPrompts'> | string): string;
13
+ export declare function readReviewInstructions(config: Pick<GthConfig, 'projectReviewInstructions' | 'identityProfile' | 'noDefaultPrompts'> | string): string;
14
+ export declare function readSystemPrompt(config: Pick<GthConfig, 'identityProfile' | 'noDefaultPrompts'>): string;
15
+ export declare function readChatPrompt(config: Pick<GthConfig, 'identityProfile' | 'noDefaultPrompts'>): string;
16
+ export declare function buildSystemMessages(config: GthConfig, modePrompt?: string | null): SystemMessage[];
17
+ export declare function readCodePrompt(config: Pick<GthConfig, 'identityProfile' | 'noDefaultPrompts'>): string;
18
+ /**
19
+ * Wraps content within randomized block
20
+ */
21
+ export declare function wrapContent(content: string, wrapBlockPrefix?: string, prefix?: string, alwaysWrap?: boolean): string;
22
+ /**
23
+ * Utility function to execute hook(s) - either a single hook or an array of hooks
24
+ * Fully type-safe and works with any number of arguments
25
+ * @param hooks - Single hook function or array of hook functions (or undefined)
26
+ * @param args - Arguments to pass to each hook function
27
+ */
28
+ export declare function executeHooks<T extends (...args: any[]) => Promise<void>>(hooks: T | T[] | undefined, ...args: Parameters<T>): Promise<void>;
29
+ /**
30
+ * Format tool call arguments in a human-readable way
31
+ */
32
+ export declare function formatToolCallArgs(args: Record<string, unknown>): string;
33
+ /**
34
+ * Format multiple tool calls for display (matches Invocation.ts behavior)
35
+ */
36
+ export declare function formatToolCalls(toolCalls: Array<{
37
+ name: string;
38
+ args?: Record<string, unknown>;
39
+ }>, maxLength?: number): string;
@@ -0,0 +1,153 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import { GSLOTH_BACKSTORY, GSLOTH_CHAT_PROMPT, GSLOTH_CODE_PROMPT, GSLOTH_SYSTEM_PROMPT, } from '#src/constants.js';
3
+ import { getGslothConfigReadPath, readFileFromInstallDir } from '#src/utils/fileUtils.js';
4
+ import { existsSync, readFileSync } from 'node:fs';
5
+ import { debugLog } from '#src/utils/debugUtils.js';
6
+ import { truncateString } from '#src/utils/stringUtils.js';
7
+ import { SystemMessage } from '@langchain/core/messages';
8
+ /**
9
+ * Creates new runnable config.
10
+ * configurable.thread_id is an important part of that because it helps to distinguish different chat sessions.
11
+ * We normally do not have multiple sessions in the terminal, but I had bad stuff happening in tests
12
+ * and in another prototype project where I was importing Gaunt Sloth.
13
+ */
14
+ export function getNewRunnableConfig() {
15
+ return {
16
+ recursionLimit: 1000,
17
+ configurable: { thread_id: randomUUID() },
18
+ };
19
+ }
20
+ export function readBackstory(config) {
21
+ return readPromptFile(GSLOTH_BACKSTORY, config.identityProfile, config.noDefaultPrompts);
22
+ }
23
+ export function readGuidelines(config) {
24
+ if (typeof config === 'string') {
25
+ return readPromptFile(config, undefined);
26
+ }
27
+ const guidelines = readPromptFile(config.projectGuidelines, config.identityProfile, config.noDefaultPrompts);
28
+ if (config.includeCurrentDateAfterGuidelines) {
29
+ const currentDate = new Date();
30
+ const orgName = config.organization?.name;
31
+ const locale = config.organization?.locale;
32
+ const timezone = config.organization?.timezone;
33
+ const hasLocaleOrTimezone = Boolean((locale && locale.trim()) || (timezone && timezone.trim()));
34
+ const humanReadableDate = hasLocaleOrTimezone
35
+ ? new Intl.DateTimeFormat(locale?.trim() || undefined, {
36
+ dateStyle: 'full',
37
+ timeStyle: 'long',
38
+ timeZone: timezone?.trim() || undefined,
39
+ }).format(currentDate)
40
+ : '';
41
+ const lines = [guidelines];
42
+ if (orgName) {
43
+ lines.push(`Organization: ${orgName}`);
44
+ }
45
+ lines.push(`Current Date: ${currentDate.toISOString()}${hasLocaleOrTimezone ? ` - ${humanReadableDate}` : ''}`);
46
+ return lines.join('\n');
47
+ }
48
+ return guidelines;
49
+ }
50
+ export function readReviewInstructions(config) {
51
+ if (typeof config === 'string') {
52
+ return readPromptFile(config, undefined);
53
+ }
54
+ return readPromptFile(config.projectReviewInstructions, config.identityProfile, config.noDefaultPrompts);
55
+ }
56
+ export function readSystemPrompt(config) {
57
+ return readPromptFile(GSLOTH_SYSTEM_PROMPT, config.identityProfile, config.noDefaultPrompts);
58
+ }
59
+ export function readChatPrompt(config) {
60
+ return readPromptFile(GSLOTH_CHAT_PROMPT, config.identityProfile, config.noDefaultPrompts);
61
+ }
62
+ export function buildSystemMessages(config, modePrompt) {
63
+ const parts = [readBackstory(config), readGuidelines(config)];
64
+ if (modePrompt)
65
+ parts.push(modePrompt);
66
+ const systemPrompt = readSystemPrompt(config);
67
+ if (systemPrompt)
68
+ parts.push(systemPrompt);
69
+ const content = parts.filter(Boolean).join('\n');
70
+ return content.trim() ? [new SystemMessage(content)] : [];
71
+ }
72
+ export function readCodePrompt(config) {
73
+ return readPromptFile(GSLOTH_CODE_PROMPT, config.identityProfile, config.noDefaultPrompts);
74
+ }
75
+ function readPromptFile(filename, identityProfile, noDefaultPrompts) {
76
+ const path = getGslothConfigReadPath(filename, identityProfile);
77
+ if (existsSync(path)) {
78
+ return readFileSync(path, { encoding: 'utf8' });
79
+ }
80
+ if (noDefaultPrompts) {
81
+ return '';
82
+ }
83
+ return readFileFromInstallDir(filename);
84
+ }
85
+ /**
86
+ * Wraps content within randomized block
87
+ */
88
+ export function wrapContent(content, wrapBlockPrefix = 'block', prefix = 'content', alwaysWrap = false) {
89
+ if (content || alwaysWrap) {
90
+ const contentWrapper = [];
91
+ const block = wrapBlockPrefix + '-' + randomUUID().substring(0, 7);
92
+ contentWrapper.push(`\nProvided ${prefix} follows within ${block} block\n`);
93
+ contentWrapper.push(`<${block}>\n`);
94
+ contentWrapper.push(content);
95
+ contentWrapper.push(`\n</${block}>\n`);
96
+ return contentWrapper.join('');
97
+ }
98
+ return content;
99
+ }
100
+ /**
101
+ * Utility function to execute hook(s) - either a single hook or an array of hooks
102
+ * Fully type-safe and works with any number of arguments
103
+ * @param hooks - Single hook function or array of hook functions (or undefined)
104
+ * @param args - Arguments to pass to each hook function
105
+ */
106
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
+ export async function executeHooks(hooks, ...args) {
108
+ if (!hooks)
109
+ return;
110
+ if (Array.isArray(hooks)) {
111
+ for (const hook of hooks) {
112
+ await hook(...args);
113
+ }
114
+ }
115
+ else {
116
+ await hooks(...args);
117
+ }
118
+ }
119
+ /**
120
+ * Format tool call arguments in a human-readable way
121
+ */
122
+ export function formatToolCallArgs(args) {
123
+ return Object.entries(args)
124
+ .map(([key, value]) => {
125
+ let displayValue;
126
+ if (typeof value === 'string') {
127
+ displayValue = value;
128
+ }
129
+ else if (Array.isArray(value) || (typeof value === 'object' && value !== null)) {
130
+ displayValue = JSON.stringify(value);
131
+ }
132
+ else {
133
+ displayValue = String(value);
134
+ }
135
+ return `${key}: ${truncateString(displayValue, 50)}`;
136
+ })
137
+ .join(', ');
138
+ }
139
+ /**
140
+ * Format multiple tool calls for display (matches Invocation.ts behavior)
141
+ */
142
+ export function formatToolCalls(toolCalls, maxLength = 255) {
143
+ const formatted = toolCalls
144
+ .map((toolCall) => {
145
+ debugLog(JSON.stringify(toolCall));
146
+ const formattedArgs = formatToolCallArgs(toolCall.args || {});
147
+ return `${toolCall.name}(${formattedArgs})`;
148
+ })
149
+ .join(', ');
150
+ // Truncate to maxLength characters if needed
151
+ return formatted.length > maxLength ? formatted.slice(0, maxLength - 3) + '...' : formatted;
152
+ }
153
+ //# sourceMappingURL=llmUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"llmUtils.js","sourceRoot":"","sources":["../../src/utils/llmUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAC1F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEzD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO;QACL,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;KAC1C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,aAAa,CAC3B,MAA+D;IAE/D,OAAO,cAAc,CAAC,gBAAgB,EAAE,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;AAC3F,CAAC;AAED,MAAM,UAAU,cAAc,CAC5B,MASU;IAEV,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,cAAc,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAC3C,CAAC;IACD,MAAM,UAAU,GAAG,cAAc,CAC/B,MAAM,CAAC,iBAAiB,EACxB,MAAM,CAAC,eAAe,EACtB,MAAM,CAAC,gBAAgB,CACxB,CAAC;IACF,IAAI,MAAM,CAAC,iCAAiC,EAAE,CAAC;QAC7C,MAAM,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C,CAAC;IAEd,6CAA6C;IAC7C,OAAO,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9F,CAAC"}
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Truncate a string to a maximum length with ellipsis
3
+ */
4
+ export declare function truncateString(str: string, maxLength: number): string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Truncate a string to a maximum length with ellipsis
3
+ */
4
+ export function truncateString(str, maxLength) {
5
+ if (str.length <= maxLength) {
6
+ return str;
7
+ }
8
+ return str.slice(0, maxLength - 3) + '...';
9
+ }
10
+ //# sourceMappingURL=stringUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringUtils.js","sourceRoot":"","sources":["../../src/utils/stringUtils.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,SAAiB;IAC3D,IAAI,GAAG,CAAC,MAAM,IAAI,SAAS,EAAE,CAAC;QAC5B,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,GAAG,CAAC,CAAC,GAAG,KAAK,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { createInterface, type Interface as ReadLineInterface } from 'node:readline/promises';
2
+ /**
3
+ * Generic interface for program-like objects that can parse arguments.
4
+ * Allows decoupling from commander's Command type.
5
+ */
6
+ export interface ProgramLike {
7
+ getOptionValue(key: string): unknown;
8
+ parseAsync(args?: string[]): Promise<unknown>;
9
+ }
10
+ export declare const waitForEscape: (callback: () => void, enabled: boolean) => void;
11
+ export declare const stopWaitingForEscape: () => void;
12
+ export declare const setRawMode: (rawMode: boolean) => void;
13
+ export declare const initLogStream: (logFileName: string) => void;
14
+ export declare const writeToLogStream: (message: string) => void;
15
+ export declare const closeLogStream: () => void;
16
+ /**
17
+ * The process.cwd() has a weird behaviour when the app is a part of monorepo,
18
+ * always returning the directory of this specific project,
19
+ * this causes integration tests to fail, because they are specifically testing ability to respect actual current dirs.
20
+ * Gaunt Sloth is a command line tool and it is always supposed to function in the current directory.
21
+ * Using INIT_CWD forces to always use actual CWD. cwd() fallback is just in case.
22
+ * In environments where INIT_CWD is available (npm and alike) - INIT_CWD is the correct choice,
23
+ * since they are likely to juggle the process.cwd(), where it is unavailable process.cwd() is used.
24
+ */
25
+ export declare const getCurrentWorkDir: () => string;
26
+ export declare const getInstallDir: () => string;
27
+ /**
28
+ * Cached string from stdin. Should only be called after readStdin completes execution.
29
+ */
30
+ export declare const getStringFromStdin: () => string;
31
+ /**
32
+ * Get the current useColour setting.
33
+ */
34
+ export declare const getUseColour: () => boolean;
35
+ /**
36
+ * Set the useColour setting.
37
+ */
38
+ export declare const setUseColour: (useColour: boolean) => void;
39
+ export declare const isTTY: () => boolean;
40
+ export declare const exit: (code?: number) => never;
41
+ export declare const stdin: NodeJS.ReadStream & {
42
+ fd: 0;
43
+ };
44
+ export declare const stdout: NodeJS.WriteStream & {
45
+ fd: 1;
46
+ };
47
+ export declare const argv: string[];
48
+ export declare const env: NodeJS.ProcessEnv;
49
+ export declare const setExitCode: (code: number) => void;
50
+ export { createInterface };
51
+ export type { ReadLineInterface };
52
+ /**
53
+ * Provide the path to the entry point of the application.
54
+ * This is used to set the install directory.
55
+ * This is called from cli.js root entry point.
56
+ */
57
+ export declare const setEntryPoint: (indexJs: string) => void;
58
+ /**
59
+ * Asynchronously reads the stdin and stores it as a string,
60
+ * it can later be retrieved with getStringFromStdin.
61
+ */
62
+ export declare function readStdin(program: ProgramLike): Promise<void>;
63
+ export declare const log: (message: string) => void;
64
+ export declare const error: (message: string) => void;
65
+ export declare const warn: (message: string) => void;
66
+ export declare const info: (message: string) => void;
67
+ export declare const debug: (message: string) => void;
68
+ export declare const stream: (chunk: string) => boolean;
69
+ export declare function execAsync(command: string): Promise<string>;
70
+ export declare function getSlothVersion(): string;