gaunt-sloth-assistant 0.2.2 → 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/.gsloth.guidelines.md +127 -0
- package/.gsloth.review.md +13 -0
- package/README.md +1 -1
- package/dist/commands/askCommand.js +4 -4
- package/dist/commands/askCommand.js.map +1 -1
- package/dist/commands/reviewCommand.js +20 -8
- package/dist/commands/reviewCommand.js.map +1 -1
- package/dist/config.d.ts +8 -4
- package/dist/config.js +49 -19
- package/dist/config.js.map +1 -1
- package/dist/configs/anthropic.d.ts +2 -3
- package/dist/configs/anthropic.js.map +1 -1
- package/dist/configs/vertexai.d.ts +2 -2
- package/dist/configs/vertexai.js.map +1 -1
- package/dist/filePathUtils.d.ts +25 -0
- package/dist/filePathUtils.js +66 -0
- package/dist/filePathUtils.js.map +1 -0
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/llmUtils.d.ts +4 -0
- package/dist/llmUtils.js +39 -0
- package/dist/llmUtils.js.map +1 -0
- package/dist/modules/questionAnsweringModule.d.ts +0 -11
- package/dist/modules/questionAnsweringModule.js +8 -47
- package/dist/modules/questionAnsweringModule.js.map +1 -1
- package/dist/modules/reviewModule.d.ts +0 -3
- package/dist/modules/reviewModule.js +8 -38
- package/dist/modules/reviewModule.js.map +1 -1
- package/dist/prompt.d.ts +3 -2
- package/dist/prompt.js +28 -12
- package/dist/prompt.js.map +1 -1
- package/dist/systemUtils.d.ts +10 -0
- package/dist/systemUtils.js +34 -0
- package/dist/systemUtils.js.map +1 -1
- package/dist/utils.d.ts +15 -5
- package/dist/utils.js +74 -47
- package/dist/utils.js.map +1 -1
- package/docs/CONFIGURATION.md +25 -4
- package/docs/RELEASE-HOWTO.md +13 -5
- package/package.json +1 -1
- package/src/commands/askCommand.ts +4 -4
- package/src/commands/reviewCommand.ts +21 -9
- package/src/config.ts +59 -28
- package/src/configs/anthropic.ts +5 -3
- package/src/configs/vertexai.ts +2 -2
- package/src/filePathUtils.ts +79 -0
- package/src/index.ts +12 -3
- package/src/llmUtils.ts +54 -0
- package/src/modules/questionAnsweringModule.ts +10 -66
- package/src/modules/reviewModule.ts +8 -60
- package/src/prompt.ts +35 -17
- package/src/systemUtils.ts +38 -0
- package/src/utils.ts +82 -50
- package/.gsloth.preamble.review.md +0 -125
- package/UX-RESEARCH.md +0 -78
package/dist/llmUtils.js
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
2
|
+
import { END, MemorySaver, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
|
3
|
+
const llmGlobalSettings = {
|
4
|
+
verbose: false,
|
5
|
+
};
|
6
|
+
export async function invoke(llm, options, systemMessage, prompt) {
|
7
|
+
if (llmGlobalSettings.verbose) {
|
8
|
+
llm.verbose = true;
|
9
|
+
}
|
10
|
+
// This node receives the current state (messages) and invokes the LLM
|
11
|
+
const callModel = async (state) => {
|
12
|
+
// state.messages will contain the list including the system systemMessage and user diff
|
13
|
+
const response = await llm.invoke(state.messages);
|
14
|
+
// MessagesAnnotation expects the node to return the new message(s) to be added to the state.
|
15
|
+
// Wrap the response in an array if it's a single message object.
|
16
|
+
return { messages: response };
|
17
|
+
};
|
18
|
+
// Define the graph structure with MessagesAnnotation state
|
19
|
+
const workflow = new StateGraph(MessagesAnnotation)
|
20
|
+
// Define the node and edge
|
21
|
+
.addNode('model', callModel)
|
22
|
+
.addEdge(START, 'model') // Start at the 'model' node
|
23
|
+
.addEdge('model', END); // End after the 'model' node completes
|
24
|
+
// Set up memory (optional but good practice for potential future multi-turn interactions)
|
25
|
+
const memory = new MemorySaver();
|
26
|
+
// Compile the workflow into a runnable app
|
27
|
+
const app = workflow.compile({ checkpointer: memory });
|
28
|
+
// Construct the initial the messages including the systemMessage as a system message
|
29
|
+
const messages = [new SystemMessage(systemMessage), new HumanMessage(prompt)];
|
30
|
+
const output = await app.invoke({ messages }, options);
|
31
|
+
const lastMessage = output.messages[output.messages.length - 1];
|
32
|
+
return typeof lastMessage.content === 'string'
|
33
|
+
? lastMessage.content
|
34
|
+
: JSON.stringify(lastMessage.content);
|
35
|
+
}
|
36
|
+
export function setVerbose(debug) {
|
37
|
+
llmGlobalSettings.verbose = debug;
|
38
|
+
}
|
39
|
+
//# sourceMappingURL=llmUtils.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"llmUtils.js","sourceRoot":"","sources":["../src/llmUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAkB,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEvF,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,kBAAkB,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAG/F,MAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,KAAK;CACf,CAAC;AAEF,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,GAAkB,EAClB,OAA8C,EAC9C,aAAqB,EACrB,MAAc;IAEd,IAAI,iBAAiB,CAAC,OAAO,EAAE,CAAC;QAC9B,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;IACrB,CAAC;IACD,sEAAsE;IACtE,MAAM,SAAS,GAAG,KAAK,EAAE,KAAY,EAAyC,EAAE;QAC9E,wFAAwF;QACxF,MAAM,QAAQ,GAAG,MAAO,GAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACrE,6FAA6F;QAC7F,iEAAiE;QACjE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC;IAChC,CAAC,CAAC;IAEF,2DAA2D;IAC3D,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,kBAAkB,CAAC;QACjD,2BAA2B;SAC1B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;SAC3B,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,4BAA4B;SACpD,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC,uCAAuC;IAEjE,0FAA0F;IAC1F,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;IAEjC,2CAA2C;IAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,CAAC;IAEvD,qFAAqF;IACrF,MAAM,QAAQ,GAAc,CAAC,IAAI,aAAa,CAAC,aAAa,CAAC,EAAE,IAAI,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;IAEzF,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAC;IACvD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAChE,OAAO,OAAO,WAAW,CAAC,OAAO,KAAK,QAAQ;QAC5C,CAAC,CAAC,WAAW,CAAC,OAAO;QACrB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,iBAAiB,CAAC,OAAO,GAAG,KAAK,CAAC;AACpC,CAAC"}
|
@@ -1,5 +1,3 @@
|
|
1
|
-
import type { SlothContext } from '#src/config.js';
|
2
|
-
import type { ProgressCallback } from '#src/modules/types.js';
|
3
1
|
/**
|
4
2
|
* Ask a question and get an answer from the LLM
|
5
3
|
* @param source - The source of the question (used for file naming)
|
@@ -7,12 +5,3 @@ import type { ProgressCallback } from '#src/modules/types.js';
|
|
7
5
|
* @param content - The content of the question
|
8
6
|
*/
|
9
7
|
export declare function askQuestion(source: string, preamble: string, content: string): Promise<void>;
|
10
|
-
/**
|
11
|
-
* Inner function to ask a question and get an answer from the LLM
|
12
|
-
* @param context - The context object
|
13
|
-
* @param indicateProgress - Function to indicate progress
|
14
|
-
* @param preamble - The preamble to send to the LLM
|
15
|
-
* @param content - The content of the question
|
16
|
-
* @returns The answer from the LLM
|
17
|
-
*/
|
18
|
-
export declare function askQuestionInner(context: SlothContext, indicateProgress: ProgressCallback, preamble: string, content: string): Promise<string>;
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import { slothContext } from '#src/config.js';
|
2
2
|
import { display, displayError, displaySuccess } from '#src/consoleUtils.js';
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
6
|
-
import { END, MemorySaver, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
|
3
|
+
import { getGslothFilePath } from '#src/filePathUtils.js';
|
4
|
+
import { generateStandardFileName, ProgressIndicator } from '#src/utils.js';
|
7
5
|
import { writeFileSync } from 'node:fs';
|
8
|
-
import
|
6
|
+
import { invoke } from '#src/llmUtils.js';
|
9
7
|
/**
|
10
8
|
* Ask a question and get an answer from the LLM
|
11
9
|
* @param source - The source of the question (used for file naming)
|
@@ -14,10 +12,12 @@ import * as path from 'node:path';
|
|
14
12
|
*/
|
15
13
|
export async function askQuestion(source, preamble, content) {
|
16
14
|
const progressIndicator = new ProgressIndicator('Thinking.');
|
17
|
-
const outputContent = await
|
18
|
-
|
15
|
+
const outputContent = await invoke(slothContext.config.llm, slothContext.session, preamble, content);
|
16
|
+
progressIndicator.stop();
|
17
|
+
const filename = generateStandardFileName(source);
|
18
|
+
const filePath = getGslothFilePath(filename);
|
19
19
|
display(`\nwriting ${filePath}`);
|
20
|
-
// TODO highlight LLM output with something like Prism.JS
|
20
|
+
// TODO highlight LLM output with something like Prism.JS (maybe system emoj are enough ✅⚠️❌)
|
21
21
|
display('\n' + outputContent);
|
22
22
|
try {
|
23
23
|
writeFileSync(filePath, outputContent);
|
@@ -30,43 +30,4 @@ export async function askQuestion(source, preamble, content) {
|
|
30
30
|
// exit(1);
|
31
31
|
}
|
32
32
|
}
|
33
|
-
/**
|
34
|
-
* Inner function to ask a question and get an answer from the LLM
|
35
|
-
* @param context - The context object
|
36
|
-
* @param indicateProgress - Function to indicate progress
|
37
|
-
* @param preamble - The preamble to send to the LLM
|
38
|
-
* @param content - The content of the question
|
39
|
-
* @returns The answer from the LLM
|
40
|
-
*/
|
41
|
-
export async function askQuestionInner(context, indicateProgress, preamble, content) {
|
42
|
-
// This node receives the current state (messages) and invokes the LLM
|
43
|
-
const callModel = async (state) => {
|
44
|
-
// state.messages will contain the list including the system preamble and user diff
|
45
|
-
const response = await context.config.llm.invoke(state.messages);
|
46
|
-
// MessagesAnnotation expects the node to return the new message(s) to be added to the state.
|
47
|
-
// Wrap the response in an array if it's a single message object.
|
48
|
-
return { messages: response };
|
49
|
-
};
|
50
|
-
// Define the graph structure with MessagesAnnotation state
|
51
|
-
const workflow = new StateGraph(MessagesAnnotation)
|
52
|
-
// Define the node and edge
|
53
|
-
.addNode('model', callModel)
|
54
|
-
.addEdge(START, 'model') // Start at the 'model' node
|
55
|
-
.addEdge('model', END); // End after the 'model' node completes
|
56
|
-
// Set up memory (optional but good practice for potential future multi-turn interactions)
|
57
|
-
const memory = new MemorySaver();
|
58
|
-
// Compile the workflow into a runnable app
|
59
|
-
const app = workflow.compile({ checkpointer: memory });
|
60
|
-
// Construct the initial the messages including the preamble as a system message
|
61
|
-
const messages = [new SystemMessage(preamble), new HumanMessage(content)];
|
62
|
-
indicateProgress();
|
63
|
-
// TODO create proper progress indicator for async tasks.
|
64
|
-
const progress = setInterval(() => indicateProgress(), 1000);
|
65
|
-
const output = await app.invoke({ messages }, context.session);
|
66
|
-
clearInterval(progress);
|
67
|
-
const lastMessage = output.messages[output.messages.length - 1];
|
68
|
-
return typeof lastMessage.content === 'string'
|
69
|
-
? lastMessage.content
|
70
|
-
: JSON.stringify(lastMessage.content);
|
71
|
-
}
|
72
33
|
//# sourceMappingURL=questionAnsweringModule.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"questionAnsweringModule.js","sourceRoot":"","sources":["../../src/modules/questionAnsweringModule.ts"],"names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AAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;QACrE,yDAAyD;QACzD,WAAW;IACb,CAAC;AACH,CAAC"}
|
@@ -1,4 +1 @@
|
|
1
|
-
import type { SlothContext } from '#src/config.js';
|
2
|
-
import type { ProgressCallback } from '#src/modules/types.js';
|
3
1
|
export declare function review(source: string, preamble: string, diff: string): Promise<void>;
|
4
|
-
export declare function reviewInner(context: SlothContext, indicateProgress: ProgressCallback, preamble: string, diff: string): Promise<string>;
|
@@ -1,15 +1,16 @@
|
|
1
1
|
import { slothContext } from '#src/config.js';
|
2
2
|
import { display, displayDebug, displayError, displaySuccess } from '#src/consoleUtils.js';
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
6
|
-
import { END, MemorySaver, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
|
3
|
+
import { stdout } from '#src/systemUtils.js';
|
4
|
+
import { generateStandardFileName, ProgressIndicator } from '#src/utils.js';
|
7
5
|
import { writeFileSync } from 'node:fs';
|
8
|
-
import
|
6
|
+
import { invoke } from '#src/llmUtils.js';
|
7
|
+
import { getGslothFilePath } from '#src/filePathUtils.js';
|
9
8
|
export async function review(source, preamble, diff) {
|
10
9
|
const progressIndicator = new ProgressIndicator('Reviewing.');
|
11
|
-
const outputContent = await
|
12
|
-
|
10
|
+
const outputContent = await invoke(slothContext.config.llm, slothContext.session, preamble, diff);
|
11
|
+
progressIndicator.stop();
|
12
|
+
const filename = generateStandardFileName(source);
|
13
|
+
const filePath = getGslothFilePath(filename);
|
13
14
|
stdout.write('\n');
|
14
15
|
display(`writing ${filePath}`);
|
15
16
|
stdout.write('\n');
|
@@ -26,35 +27,4 @@ export async function review(source, preamble, diff) {
|
|
26
27
|
// exit(1);
|
27
28
|
}
|
28
29
|
}
|
29
|
-
export async function reviewInner(context, indicateProgress, preamble, diff) {
|
30
|
-
// This node receives the current state (messages) and invokes the LLM
|
31
|
-
const callModel = async (state) => {
|
32
|
-
// state.messages will contain the list including the system preamble and user diff
|
33
|
-
const response = await context.config.llm.invoke(state.messages);
|
34
|
-
// MessagesAnnotation expects the node to return the new message(s) to be added to the state.
|
35
|
-
// Wrap the response in an array if it's a single message object.
|
36
|
-
return { messages: response };
|
37
|
-
};
|
38
|
-
// Define the graph structure with MessagesAnnotation state
|
39
|
-
const workflow = new StateGraph(MessagesAnnotation)
|
40
|
-
// Define the node and edge
|
41
|
-
.addNode('model', callModel)
|
42
|
-
.addEdge(START, 'model') // Start at the 'model' node
|
43
|
-
.addEdge('model', END); // End after the 'model' node completes
|
44
|
-
// Set up memory (optional but good practice for potential future multi-turn interactions)
|
45
|
-
const memory = new MemorySaver(); // TODO extract to config
|
46
|
-
// Compile the workflow into a runnable app
|
47
|
-
const app = workflow.compile({ checkpointer: memory });
|
48
|
-
// Construct the initial the messages including the preamble as a system message
|
49
|
-
const messages = [new SystemMessage(preamble), new HumanMessage(diff)];
|
50
|
-
indicateProgress();
|
51
|
-
// TODO create proper progress indicator for async tasks.
|
52
|
-
const progress = setInterval(() => indicateProgress(), 1000);
|
53
|
-
const output = await app.invoke({ messages }, context.session);
|
54
|
-
clearInterval(progress);
|
55
|
-
const lastMessage = output.messages[output.messages.length - 1];
|
56
|
-
return typeof lastMessage.content === 'string'
|
57
|
-
? lastMessage.content
|
58
|
-
: JSON.stringify(lastMessage.content);
|
59
|
-
}
|
60
30
|
//# sourceMappingURL=reviewModule.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"reviewModule.js","sourceRoot":"","sources":["../../src/modules/reviewModule.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"reviewModule.js","sourceRoot":"","sources":["../../src/modules/reviewModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,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QAC7D,YAAY,CAAC,mCAAmC,QAAQ,EAAE,CAAC,CAAC;QAC5D,qDAAqD;QACrD,WAAW;IACb,CAAC;AACH,CAAC"}
|
package/dist/prompt.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
export declare function
|
2
|
-
export declare function
|
1
|
+
export declare function readBackstory(): string;
|
2
|
+
export declare function readGuidelines(guidelinesFilename: string): string;
|
3
|
+
export declare function readReviewInstructions(reviewInstructions: string): string;
|
3
4
|
/**
|
4
5
|
* This function expects https://cli.github.com/ to be installed and authenticated.
|
5
6
|
* It does something like `gh pr diff 42`
|
package/dist/prompt.js
CHANGED
@@ -1,17 +1,33 @@
|
|
1
|
-
import {
|
2
|
-
import { GSLOTH_BACKSTORY } from '#src/config.js';
|
3
|
-
import { readFileSyncWithMessages, spawnCommand } from '#src/utils.js';
|
1
|
+
import { readFileFromCurrentDir, readFileFromCurrentOrInstallDir, spawnCommand, } from '#src/utils.js';
|
4
2
|
import { displayError } from '#src/consoleUtils.js';
|
5
|
-
import { exit
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
return
|
3
|
+
import { exit } from '#src/systemUtils.js';
|
4
|
+
import { GSLOTH_BACKSTORY } from '#src/config.js';
|
5
|
+
import { getGslothConfigReadPath } from '#src/filePathUtils.js';
|
6
|
+
export function readBackstory() {
|
7
|
+
return readFileFromCurrentOrInstallDir(GSLOTH_BACKSTORY, true);
|
8
|
+
}
|
9
|
+
export function readGuidelines(guidelinesFilename) {
|
10
|
+
try {
|
11
|
+
const filePath = getGslothConfigReadPath(guidelinesFilename);
|
12
|
+
return readFileFromCurrentDir(filePath);
|
13
|
+
}
|
14
|
+
catch (error) {
|
15
|
+
displayError('Consider running `gsloth init` to set up your project. Check `gsloth init --help` to see options.');
|
16
|
+
throw error;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
export function readReviewInstructions(reviewInstructions) {
|
20
|
+
return readConfigPromptFile(reviewInstructions);
|
10
21
|
}
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
function readConfigPromptFile(guidelinesFilename) {
|
23
|
+
try {
|
24
|
+
const filePath = getGslothConfigReadPath(guidelinesFilename);
|
25
|
+
return readFileFromCurrentOrInstallDir(filePath);
|
26
|
+
}
|
27
|
+
catch (error) {
|
28
|
+
displayError('Consider running `gsloth init` to set up your project. Check `gsloth init --help` to see options.');
|
29
|
+
throw error;
|
30
|
+
}
|
15
31
|
}
|
16
32
|
/**
|
17
33
|
* This function expects https://cli.github.com/ to be installed and authenticated.
|
package/dist/prompt.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"prompt.js","sourceRoot":"","sources":["../src/prompt.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,+BAA+B,EAC/B,YAAY,GACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAEhE,MAAM,UAAU,aAAa;IAC3B,OAAO,+BAA+B,CAAC,gBAAgB,EAAE,IAAI,CAAC,CAAC;AACjE,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,kBAA0B;IACvD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;QAC7D,OAAO,sBAAsB,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,YAAY,CACV,mGAAmG,CACpG,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,kBAA0B;IAC/D,OAAO,oBAAoB,CAAC,kBAAkB,CAAC,CAAC;AAClD,CAAC;AAED,SAAS,oBAAoB,CAAC,kBAA0B;IACtD,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;QAC7D,OAAO,+BAA+B,CAAC,QAAQ,CAAC,CAAC;IACnD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,YAAY,CACV,mGAAmG,CACpG,CAAC;QACF,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,EAAU;IACxC,iEAAiE;IACjE,IAAI,CAAC;QACH,OAAO,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,oBAAoB,EAAE,iBAAiB,CAAC,CAAC;IAC/F,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,YAAY,CAAC,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,YAAY,CAAC,8BAA8B,EAAE,mCAAmC,CAAC,CAAC;QAClF,IAAI,EAAE,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,gDAAgD;IAC7D,CAAC;AACH,CAAC"}
|
package/dist/systemUtils.d.ts
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
import { Command } from 'commander';
|
1
2
|
export declare const getCurrentDir: () => string;
|
2
3
|
export declare const getInstallDir: () => string;
|
4
|
+
/**
|
5
|
+
* Cached string from stdin. Should only be called after readStdin completes execution.
|
6
|
+
*/
|
7
|
+
export declare const getStringFromStdin: () => string;
|
3
8
|
export declare const exit: (code?: number) => never;
|
4
9
|
export declare const stdin: NodeJS.ReadStream & {
|
5
10
|
fd: 0;
|
@@ -15,6 +20,11 @@ export declare const env: NodeJS.ProcessEnv;
|
|
15
20
|
* This is called from index.js root entry point.
|
16
21
|
*/
|
17
22
|
export declare const setEntryPoint: (indexJs: string) => void;
|
23
|
+
/**
|
24
|
+
* Asynchronously reads the stdin and stores it as a string,
|
25
|
+
* it can later be retrieved with getStringFromStdin.
|
26
|
+
*/
|
27
|
+
export declare function readStdin(program: Command): Promise<void>;
|
18
28
|
export declare const log: (message: string) => void;
|
19
29
|
export declare const error: (message: string) => void;
|
20
30
|
export declare const warn: (message: string) => void;
|
package/dist/systemUtils.js
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
import { dirname, resolve } from 'node:path';
|
2
2
|
import { fileURLToPath } from 'url';
|
3
|
+
import { ProgressIndicator } from '#src/utils.js';
|
3
4
|
const innerState = {
|
4
5
|
installDir: undefined,
|
6
|
+
stringFromStdin: '',
|
5
7
|
};
|
6
8
|
// Process-related functions and objects
|
7
9
|
export const getCurrentDir = () => process.cwd();
|
@@ -11,6 +13,12 @@ export const getInstallDir = () => {
|
|
11
13
|
}
|
12
14
|
throw new Error('Install directory not set');
|
13
15
|
};
|
16
|
+
/**
|
17
|
+
* Cached string from stdin. Should only be called after readStdin completes execution.
|
18
|
+
*/
|
19
|
+
export const getStringFromStdin = () => {
|
20
|
+
return innerState.stringFromStdin;
|
21
|
+
};
|
14
22
|
export const exit = (code) => process.exit(code || 0);
|
15
23
|
export const stdin = process.stdin;
|
16
24
|
export const stdout = process.stdout;
|
@@ -27,6 +35,32 @@ export const setEntryPoint = (indexJs) => {
|
|
27
35
|
const dirPath = dirname(filePath);
|
28
36
|
innerState.installDir = resolve(dirPath);
|
29
37
|
};
|
38
|
+
/**
|
39
|
+
* Asynchronously reads the stdin and stores it as a string,
|
40
|
+
* it can later be retrieved with getStringFromStdin.
|
41
|
+
*/
|
42
|
+
export function readStdin(program) {
|
43
|
+
return new Promise((resolvePromise) => {
|
44
|
+
if (stdin.isTTY) {
|
45
|
+
program.parseAsync().then(() => resolvePromise());
|
46
|
+
}
|
47
|
+
else {
|
48
|
+
// Support piping diff into gsloth
|
49
|
+
const progressIndicator = new ProgressIndicator('reading STDIN', true);
|
50
|
+
stdin.on('readable', function () {
|
51
|
+
const chunk = this.read();
|
52
|
+
progressIndicator.indicate();
|
53
|
+
if (chunk !== null) {
|
54
|
+
const chunkStr = chunk.toString('utf8');
|
55
|
+
innerState.stringFromStdin = innerState.stringFromStdin + chunkStr;
|
56
|
+
}
|
57
|
+
});
|
58
|
+
stdin.on('end', function () {
|
59
|
+
program.parseAsync(argv).then(() => resolvePromise());
|
60
|
+
});
|
61
|
+
}
|
62
|
+
});
|
63
|
+
}
|
30
64
|
// Console-related functions
|
31
65
|
export const log = (message) => console.log(message);
|
32
66
|
export const error = (message) => console.error(message);
|
package/dist/systemUtils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"systemUtils.js","sourceRoot":"","sources":["../src/systemUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;
|
1
|
+
{"version":3,"file":"systemUtils.js","sourceRoot":"","sources":["../src/systemUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAgBlD,MAAM,UAAU,GAAe;IAC7B,UAAU,EAAE,SAAS;IACrB,eAAe,EAAE,EAAE;CACpB,CAAC;AAEF,wCAAwC;AACxC,MAAM,CAAC,MAAM,aAAa,GAAG,GAAW,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAW,EAAE;IACxC,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;QAC1B,OAAO,UAAU,CAAC,UAAU,CAA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AAE;gBACnB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC1B,iBAAiB,CAAC,QAAQ,EAAE,CAAC;gBAC7B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;oBACnB,MAAM,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;oBACxC,UAAU,CAAC,eAAe,GAAG,UAAU,CAAC,eAAe,GAAG,QAAQ,CAAC;gBACrE,CAAC;YACH,CAAC,CAAC,CAAC;YAEH,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE;gBACd,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,cAAc,EAAE,CAAC,CAAC;YACxD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,4BAA4B;AAC5B,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,OAAe,EAAQ,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAe,EAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;AACvE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC,OAAe,EAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACrE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,OAAe,EAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC"}
|
package/dist/utils.d.ts
CHANGED
@@ -1,18 +1,28 @@
|
|
1
1
|
import { SlothConfig } from '#src/config.js';
|
2
|
-
import { Command } from 'commander';
|
3
2
|
export declare function toFileSafeString(string: string): string;
|
3
|
+
/**
|
4
|
+
* Returns a formatted date string in the format YYYY-MM-DD_HH-MM-SS using local time
|
5
|
+
* @returns A formatted date string
|
6
|
+
*/
|
4
7
|
export declare function fileSafeLocalDate(): string;
|
8
|
+
/**
|
9
|
+
* Generates a standardized filename with the format: gth_YYYY-MM-DD_HH-MM-SS_COMMAND.md
|
10
|
+
* @param command - The command that created the file (ASK, REVIEW, PR, etc.)
|
11
|
+
* @returns A standardized filename string
|
12
|
+
*/
|
13
|
+
export declare function generateStandardFileName(command: string): string;
|
5
14
|
export declare function readFileFromCurrentDir(fileName: string): string;
|
15
|
+
export declare function readFileFromCurrentOrInstallDir(filePath: string, silentCurrent?: boolean): string;
|
6
16
|
export declare function writeFileIfNotExistsWithMessages(filePath: string, content: string): void;
|
7
17
|
export declare function readFileSyncWithMessages(filePath: string, errorMessageIn?: string, noFileMessage?: string): string;
|
8
|
-
export declare function readStdin(program: Command): Promise<void>;
|
9
18
|
export declare function spawnCommand(command: string, args: string[], progressMessage: string, successMessage: string): Promise<string>;
|
10
19
|
export declare function getSlothVersion(): string;
|
11
20
|
export declare class ProgressIndicator {
|
12
|
-
private
|
13
|
-
|
14
|
-
|
21
|
+
private interval;
|
22
|
+
constructor(initialMessage: string, manual?: boolean);
|
23
|
+
private indicateInner;
|
15
24
|
indicate(): void;
|
25
|
+
stop(): void;
|
16
26
|
}
|
17
27
|
interface LLMOutput {
|
18
28
|
messages: Array<{
|
package/dist/utils.js
CHANGED
@@ -1,31 +1,75 @@
|
|
1
1
|
import { display, displayError, displaySuccess, displayWarning } from '#src/consoleUtils.js';
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from 'node:fs';
|
3
|
-
import {
|
4
|
-
import { resolve } from 'node:path';
|
2
|
+
import { existsSync, readFileSync, writeFileSync, mkdirSync } from 'node:fs';
|
3
|
+
import { resolve, dirname } from 'node:path';
|
5
4
|
import { spawn } from 'node:child_process';
|
6
|
-
import {
|
5
|
+
import { getCurrentDir, getInstallDir, stdout } from '#src/systemUtils.js';
|
7
6
|
import url from 'node:url';
|
8
7
|
export function toFileSafeString(string) {
|
9
8
|
return string.replace(/[^A-Za-z0-9]/g, '-');
|
10
9
|
}
|
10
|
+
/**
|
11
|
+
* Returns a formatted date string in the format YYYY-MM-DD_HH-MM-SS using local time
|
12
|
+
* @returns A formatted date string
|
13
|
+
*/
|
11
14
|
export function fileSafeLocalDate() {
|
12
15
|
const date = new Date();
|
13
|
-
|
14
|
-
const
|
15
|
-
const
|
16
|
-
const
|
17
|
-
const
|
18
|
-
|
16
|
+
// Format: YYYY-MM-DD_HH-MM-SS using local time directly
|
17
|
+
const year = date.getFullYear();
|
18
|
+
const month = String(date.getMonth() + 1).padStart(2, '0');
|
19
|
+
const day = String(date.getDate()).padStart(2, '0');
|
20
|
+
const hours = String(date.getHours()).padStart(2, '0');
|
21
|
+
const minutes = String(date.getMinutes()).padStart(2, '0');
|
22
|
+
const seconds = String(date.getSeconds()).padStart(2, '0');
|
23
|
+
return `${year}-${month}-${day}_${hours}-${minutes}-${seconds}`;
|
24
|
+
}
|
25
|
+
/**
|
26
|
+
* Generates a standardized filename with the format: gth_YYYY-MM-DD_HH-MM-SS_COMMAND.md
|
27
|
+
* @param command - The command that created the file (ASK, REVIEW, PR, etc.)
|
28
|
+
* @returns A standardized filename string
|
29
|
+
*/
|
30
|
+
export function generateStandardFileName(command) {
|
31
|
+
const dateTimeStr = fileSafeLocalDate();
|
32
|
+
const commandStr = toFileSafeString(command.toUpperCase());
|
33
|
+
return `gth_${dateTimeStr}_${commandStr}.md`;
|
19
34
|
}
|
20
35
|
export function readFileFromCurrentDir(fileName) {
|
21
36
|
const currentDir = getCurrentDir();
|
22
37
|
const filePath = resolve(currentDir, fileName);
|
23
|
-
display(`Reading file ${
|
38
|
+
display(`Reading file ${filePath}...`);
|
24
39
|
return readFileSyncWithMessages(filePath);
|
25
40
|
}
|
41
|
+
export function readFileFromCurrentOrInstallDir(filePath, silentCurrent) {
|
42
|
+
const currentDir = getCurrentDir();
|
43
|
+
const currentFilePath = resolve(currentDir, filePath);
|
44
|
+
if (!silentCurrent) {
|
45
|
+
display(`Reading file ${currentFilePath}...`);
|
46
|
+
}
|
47
|
+
try {
|
48
|
+
return readFileSync(currentFilePath, { encoding: 'utf8' });
|
49
|
+
}
|
50
|
+
catch (_error) {
|
51
|
+
if (!silentCurrent) {
|
52
|
+
display(`The ${currentFilePath} not found or can\'t be read, trying install directory...`);
|
53
|
+
}
|
54
|
+
const installDir = getInstallDir();
|
55
|
+
const installFilePath = resolve(installDir, filePath);
|
56
|
+
try {
|
57
|
+
return readFileSync(installFilePath, { encoding: 'utf8' });
|
58
|
+
}
|
59
|
+
catch (readFromInstallDirError) {
|
60
|
+
displayError(`The ${installFilePath} not found or can\'t be read.`);
|
61
|
+
throw readFromInstallDirError;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
26
65
|
export function writeFileIfNotExistsWithMessages(filePath, content) {
|
27
66
|
display(`checking ${filePath} existence`);
|
28
67
|
if (!existsSync(filePath)) {
|
68
|
+
// Create parent directories if they don't exist
|
69
|
+
const parentDir = dirname(filePath);
|
70
|
+
if (!existsSync(parentDir)) {
|
71
|
+
mkdirSync(parentDir, { recursive: true });
|
72
|
+
}
|
29
73
|
writeFileSync(filePath, content);
|
30
74
|
displaySuccess(`Created ${filePath}`);
|
31
75
|
}
|
@@ -46,36 +90,12 @@ export function readFileSyncWithMessages(filePath, errorMessageIn, noFileMessage
|
|
46
90
|
else {
|
47
91
|
displayError(error.message);
|
48
92
|
}
|
49
|
-
|
50
|
-
throw error; // This line will never be reached due to exit(1), but satisfies TypeScript
|
93
|
+
throw error;
|
51
94
|
}
|
52
95
|
}
|
53
|
-
export function readStdin(program) {
|
54
|
-
return new Promise((resolvePromise) => {
|
55
|
-
if (stdin.isTTY) {
|
56
|
-
program.parseAsync().then(() => resolvePromise());
|
57
|
-
}
|
58
|
-
else {
|
59
|
-
// Support piping diff into gsloth
|
60
|
-
const progressIndicator = new ProgressIndicator('reading STDIN');
|
61
|
-
progressIndicator.indicate();
|
62
|
-
stdin.on('readable', function () {
|
63
|
-
const chunk = this.read();
|
64
|
-
progressIndicator.indicate();
|
65
|
-
if (chunk !== null) {
|
66
|
-
const chunkStr = chunk.toString('utf8');
|
67
|
-
slothContext.stdin = slothContext.stdin + chunkStr;
|
68
|
-
}
|
69
|
-
});
|
70
|
-
stdin.on('end', function () {
|
71
|
-
program.parseAsync(argv).then(() => resolvePromise());
|
72
|
-
});
|
73
|
-
}
|
74
|
-
});
|
75
|
-
}
|
76
96
|
export async function spawnCommand(command, args, progressMessage, successMessage) {
|
77
97
|
return new Promise((resolve, reject) => {
|
78
|
-
const progressIndicator = new ProgressIndicator(progressMessage);
|
98
|
+
const progressIndicator = new ProgressIndicator(progressMessage, true);
|
79
99
|
const out = { stdout: '', stderr: '' };
|
80
100
|
const spawned = spawn(command, args);
|
81
101
|
spawned.stdout.on('data', async (stdoutChunk) => {
|
@@ -109,20 +129,27 @@ export function getSlothVersion() {
|
|
109
129
|
return JSON.parse(projectJson).version;
|
110
130
|
}
|
111
131
|
export class ProgressIndicator {
|
112
|
-
|
113
|
-
initialMessage
|
114
|
-
|
115
|
-
|
116
|
-
|
132
|
+
interval = undefined;
|
133
|
+
constructor(initialMessage, manual) {
|
134
|
+
stdout.write(initialMessage);
|
135
|
+
if (!manual) {
|
136
|
+
this.interval = setInterval(this.indicateInner, 1000);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
indicateInner() {
|
140
|
+
stdout.write('.');
|
117
141
|
}
|
118
142
|
indicate() {
|
119
|
-
if (this.
|
120
|
-
|
143
|
+
if (this.interval) {
|
144
|
+
throw new Error('ProgressIndicator.indicate only to be called in manual mode');
|
121
145
|
}
|
122
|
-
|
123
|
-
|
124
|
-
|
146
|
+
this.indicateInner();
|
147
|
+
}
|
148
|
+
stop() {
|
149
|
+
if (this.interval) {
|
150
|
+
clearInterval(this.interval);
|
125
151
|
}
|
152
|
+
stdout.write('\n');
|
126
153
|
}
|
127
154
|
}
|
128
155
|
/**
|
package/dist/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7F,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE7E,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,GAAG,MAAM,UAAU,CAAC;AAE3B,MAAM,UAAU,gBAAgB,CAAC,MAAc;IAC7C,OAAO,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;IAExB,wDAAwD;IACxD,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAChC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAC3D,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,EAA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