gaunt-sloth-assistant 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.
Files changed (40) hide show
  1. package/.gsloth.guidelines.md +112 -102
  2. package/.gsloth.review.md +8 -2
  3. package/dist/commands/askCommand.js +1 -2
  4. package/dist/commands/askCommand.js.map +1 -1
  5. package/dist/commands/reviewCommand.js +2 -4
  6. package/dist/commands/reviewCommand.js.map +1 -1
  7. package/dist/config.js +44 -16
  8. package/dist/config.js.map +1 -1
  9. package/dist/filePathUtils.d.ts +25 -0
  10. package/dist/filePathUtils.js +66 -0
  11. package/dist/filePathUtils.js.map +1 -0
  12. package/dist/modules/questionAnsweringModule.js +4 -4
  13. package/dist/modules/questionAnsweringModule.js.map +1 -1
  14. package/dist/modules/reviewModule.js +5 -4
  15. package/dist/modules/reviewModule.js.map +1 -1
  16. package/dist/prompt.js +5 -2
  17. package/dist/prompt.js.map +1 -1
  18. package/dist/utils.d.ts +10 -0
  19. package/dist/utils.js +29 -8
  20. package/dist/utils.js.map +1 -1
  21. package/docs/CONFIGURATION.md +21 -0
  22. package/docs/RELEASE-HOWTO.md +8 -6
  23. package/package.json +1 -1
  24. package/src/commands/askCommand.ts +1 -2
  25. package/src/commands/reviewCommand.ts +2 -4
  26. package/src/config.ts +47 -19
  27. package/src/filePathUtils.ts +79 -0
  28. package/src/modules/questionAnsweringModule.ts +4 -7
  29. package/src/modules/reviewModule.ts +5 -7
  30. package/src/prompt.ts +5 -2
  31. package/src/utils.ts +33 -8
  32. package/UX-RESEARCH.md +0 -78
  33. package/gth-ASK-2025-05-16T14-11-39.md +0 -3
  34. package/gth-ASK-2025-05-16T14-18-27.md +0 -3
  35. package/gth-ASK-2025-05-16T14-18-56.md +0 -1
  36. package/gth-ASK-2025-05-16T14-41-20.md +0 -3
  37. package/gth-ASK-2025-05-16T14-43-31.md +0 -51
  38. package/gth-ASK-2025-05-16T16-05-52.md +0 -62
  39. package/gth-DIFF-review-2025-05-16T16-07-53.md +0 -56
  40. package/gth-DIFF-review-2025-05-16T16-18-55.md +0 -292
@@ -1,51 +0,0 @@
1
- This `package.json` file is reasonably well-structured. I have a few observations:
2
-
3
- * ✅ **`name`, `version`, `license`, `author`, `type`, `main`, `repository`**: These fields are correctly defined. Using `"type": "module"` is a modern choice.
4
- * ✅ **`engines`**: Clearly specifies Node.js `>=22.0.0` and npm `>=10.9.0`. These are very recent versions, which is a deliberate choice that limits broader compatibility but ensures usage of newer features.
5
- * ✅ **`scripts`**:
6
- * `build`, `lint`, `format`: Standard and appropriate.
7
- * `test`: `"npm run build && vitest run"` is good practice, ensuring tests run against the compiled output.
8
- * `prepare`: `"npm run build"` is also standard, ensuring the package is built after installation and before publishing.
9
- * ✅ **`dependencies`** and **`devDependencies`**: The listed packages are appropriate for the described functionality (Langchain, CLI tools) and development (TypeScript, ESLint, Prettier, Vitest). Versions are up-to-date.
10
- * ✅ **`imports`**: The subpath import `"#src/*.js": "./dist/*.js"` is a modern way to define internal package aliases.
11
- * ⚠️ For a smoother development experience with TypeScript, ensure your `tsconfig.json` has a corresponding `paths` alias, for example:
12
- ```json
13
- {
14
- "compilerOptions": {
15
- "baseUrl": ".", // Or "./src"
16
- "paths": {
17
- "#src/*": ["src/*"] // Or just "*" if baseUrl is "./src"
18
- }
19
- }
20
- }
21
- ```
22
- This allows TypeScript to resolve `#src/...` imports to your source files during development and type-checking.
23
-
24
- Now, for more critical points:
25
-
26
- * ❌ **`bin` configuration**:
27
- ```json
28
- "bin": {
29
- "gsloth": "index.js",
30
- "gth": "index.js"
31
- }
32
- ```
33
- Your `main` field is `"dist/index.js"`, indicating that your compiled, runnable JavaScript code resides in the `dist` directory. However, your `bin` entries point to `index.js` in the project root.
34
- If `index.js` in the root is your TypeScript source file (or does not exist), this will not work when the package is installed globally or used via `npx`. The `bin` entries should point to the executable JavaScript files generated by your build process.
35
- Typically, this would be something like:
36
- ```json
37
- "bin": {
38
- "gsloth": "dist/index.js", // Or a specific CLI entry point like "dist/cli.js"
39
- "gth": "dist/index.js" // Same here
40
- }
41
- ```
42
- The target file (e.g., `dist/index.js` or `dist/cli.js`) must be executable and should start with a shebang line (e.g., `#!/usr/bin/env node`). If your main TypeScript entry point (e.g., `src/index.ts` or `src/cli.ts`) includes this shebang, `tsc` usually preserves it in the output JavaScript file.
43
-
44
- * ⚠️ **`description`**: The `description` field is empty.
45
- ```json
46
- "description": "",
47
- ```
48
- Providing a concise description is highly recommended. It improves the package's discoverability on npm and helps users understand its purpose quickly.
49
-
50
- In summary:
51
- The most critical issue is the `bin` configuration, which likely needs to be updated to point to files within your `dist` directory. The empty `description` is a minor omission. The `imports` setup is good, but ensure your TypeScript configuration complements it for development.
@@ -1,62 +0,0 @@
1
- Okay, I've reviewed your `package.json` file. Here's my assessment:
2
-
3
- ## `package.json` Review
4
-
5
- Overall, this `package.json` is well-structured and sets up a modern Node.js TypeScript project with appropriate tooling for LangChain/LangGraph development. However, there are a few points to address.
6
-
7
- ### ✅ Positive Aspects
8
-
9
- * **Modern Node.js Setup**:
10
- * `"type": "module"`: Correctly enables ES module syntax.
11
- * `"engines"`: Specifying Node.js (`>=22.0.0`) and npm (`>=10.9.0`) versions is good practice for ensuring environment compatibility.
12
- * **Build and Development Scripts**:
13
- * `"build": "tsc"`: Standard TypeScript compilation.
14
- * `"test": "npm run build && vitest run"`: Ensures code is built before tests run. `vitest` is a good choice for a modern testing framework.
15
- * `"lint": "eslint . --ext .js,.ts"`: Proper linting setup.
16
- * `"format": "prettier --write 'src/**/*.{js,ts}'"`: Standard code formatting.
17
- * `"prepare": "npm run build"`: Excellent practice to ensure the project is built after installation, making it ready for use, especially if it's a library or a CLI tool.
18
- * **Dependencies**:
19
- * The LangChain/LangGraph dependencies (`@langchain/anthropic`, `@langchain/core`, `@langchain/google-vertexai`, `@langchain/groq`, `@langchain/langgraph`) are correctly listed. Using `^` for versioning allows for non-breaking updates.
20
- * Utility dependencies like `chalk`, `commander`, and `uuid` are appropriate for a CLI/assistant type of project.
21
- * **Dev Dependencies**:
22
- * A comprehensive set of development tools is included: TypeScript, ESLint (with TypeScript and Prettier plugins), Prettier, and type definitions (`@types/node`, `@types/uuid`).
23
- * **Subpath Imports**:
24
- * `"imports": { "#src/*.js": "./dist/*.js" }`: This is a good use of Node.js subpath imports, allowing for cleaner import statements within your compiled code (e.g., `import ... from '#src/module.js'`).
25
-
26
- ### ⚠️ Areas for Improvement / Potential Issues
27
-
28
- * **Missing Description**:
29
- * The `"description"` field is empty. It's good practice to provide a brief description of your package. This is helpful for `npm search` and general understanding.
30
- * **Recommendation**: Add a concise description.
31
- * **`globals` Dependency**:
32
- * The `globals` package is listed in `devDependencies`. While it can be used to define global variables for ESLint, modern ESLint configurations (especially with `@eslint/js` and `@typescript-eslint/parser`) often handle this directly within the ESLint configuration file (e.g., `env` or `globals` sections in `.eslintrc.js`).
33
- * **Recommendation**: Verify if this dependency is actively used and necessary. If your ESLint configuration handles globals sufficiently, this might be redundant.
34
-
35
- ### ❌ Critical Issues
36
-
37
- * **Incorrect `bin` Path(s)**:
38
- * The `"bin"` field defines CLI commands:
39
- ```json
40
- "bin": {
41
- "gsloth": "index.js",
42
- "gth": "index.js"
43
- }
44
- ```
45
- * However, your `"main"` field is `"dist/index.js"`, and your build script (`tsc`) compiles TypeScript from `src` to `dist`. This strongly suggests that the executable entry point for your CLI should be within the `dist` directory (likely `dist/index.js` or a specific CLI entry file in `dist`).
46
- * Pointing `bin` to `index.js` in the project root will either:
47
- 1. Fail if `index.js` doesn't exist or isn't executable.
48
- 2. Run the wrong (uncompiled or placeholder) code if an `index.js` exists in the root but isn't the intended compiled entry point.
49
- * **Recommendation**: Change the `bin` paths to point to the compiled JavaScript entry file. For example:
50
- ```json
51
- "bin": {
52
- "gsloth": "dist/index.js",
53
- "gth": "dist/index.js"
54
- }
55
- ```
56
- Or, if you have a dedicated CLI entry point, adjust accordingly (e.g., `dist/cli.js`). Ensure the target file has a shebang (e.g., `#!/usr/bin/env node`) if it's meant to be directly executable.
57
-
58
- ### Summary
59
-
60
- The `package.json` is largely well-configured for a TypeScript-based LangChain/LangGraph project. The most critical issue to address is the `bin` path configuration to ensure your CLI commands work correctly after installation. The other points are minor improvements.
61
-
62
- Please provide the actual code files (TypeScript/JavaScript) when you're ready for a review of the LangChain/LangGraph logic itself.
@@ -1,56 +0,0 @@
1
- Greetings. I have reviewed the submitted diff. The changes introduce significant architectural improvements, enhance configuration flexibility, and refine the user experience.
2
-
3
- Here is my assessment:
4
-
5
- **Architectural and Flow Improvements:**
6
- * ✅ The introduction of `src/llmUtils.ts` is a commendable refactoring. Centralizing the LangChain/LangGraph LLM invocation logic into a reusable `invoke` function simplifies the `questionAnsweringModule` and `reviewModule` considerably. This promotes the DRY principle and makes the core LLM interaction logic easier to manage and test.
7
- * ✅ The use of `StateGraph`, `MessagesAnnotation`, and `MemorySaver` from `@langchain/langgraph` within `llmUtils.ts` is appropriate for managing the LLM interaction state.
8
- * ✅ The separation of prompt concerns into distinct files (`.gsloth.backstory.md`, `.gsloth.guidelines.md`, `.gsloth.review.md`) and corresponding loader functions (`readBackstory`, `readGuidelines`, `readReviewInstructions`) in `src/prompt.ts` provides better organization and clarity for prompt engineering.
9
- * ✅ Handling of standard input (`stdin`) has been cleanly moved to `src/systemUtils.ts` and cached, which is a more logical placement.
10
-
11
- **Configuration Enhancements:**
12
- * ✅ The `SlothConfig` interface and default configurations in `src/config.ts` have been updated to include `projectGuidelines` and `projectReviewInstructions`. This allows for more tailored prompting.
13
- * ✅ The type hint for the LLM instance in `SlothConfig` has been refined from `LanguageModelLike` to the more specific `BaseChatModel`.
14
- * ✅ Documentation (`README.md`, `docs/CONFIGURATION.md`) and initialization logic (`initCommand`) have been updated to reflect the new configuration file names (e.g., `.gsloth.guidelines.md`).
15
-
16
- **Code Quality and Testing:**
17
- * ✅ Test suites (`*.spec.ts`) have been diligently updated to reflect the refactoring. Mocks are handled more cleanly (e.g., top-level `vi.mock`), and tests cover the new `llmUtils.ts` and changes in existing modules.
18
- * ✅ The new output file prefix `gth-` (e.g., `gth-ASK`, `gth-DIFF-review`) is consistently applied across the codebase and tests, and is now included in `.gitignore`.
19
- * ✅ TypeScript types are used effectively, and improvements have been made (e.g., `BaseChatModel`).
20
- * ✅ The new global `--verbose` option in `src/index.ts` for enabling detailed LLM prompt logging is a useful debugging feature.
21
-
22
- **User Experience:**
23
- * ✅ The `ProgressIndicator` in `src/utils.ts` has been significantly improved. It now provides continuous feedback for long-running operations by default and includes a `stop()` method for clean termination. It also supports a manual indication mode.
24
-
25
- **Specific Feedback & Suggestions:**
26
-
27
- * ⚠️ **Security Suggestion (Important):** In `src/commands/reviewCommand.ts`, there's a `TODO` comment regarding `prId` sanitization:
28
- ```typescript
29
- // src/commands/reviewCommand.ts
30
- // ...
31
- // TODO sanitize prId
32
- await review(`gth-PR-${prId}-review`, systemMessage.join('\n'), content.join('\n'));
33
- ```
34
- If `prId` can be influenced by user input (e.g., from a command-line argument that might not be strictly numeric or could contain path characters), it's crucial to sanitize it before using it in a filename. This prevents potential path traversal or other file system vulnerabilities. Please ensure `prId` is appropriately validated or sanitized.
35
-
36
- * ✅ **Refactoring of `reviewInner` and `askQuestionInner`:** The logic previously in these internal functions has been effectively moved to the generic `llmUtils.invoke` function. This is a good simplification.
37
-
38
- * ✅ **File Reading Utilities:** The new `readFileFromCurrentOrInstallDir` utility in `src/utils.ts` is a good addition for robustly loading configuration/prompt files.
39
-
40
- * ⚠️ **Nitpick (Minor):** In `src/modules/questionAnsweringModule.ts`, the comment:
41
- ```typescript
42
- // TODO highlight LLM output with something like Prism.JS (maybe system emoj are enough ????????????)
43
- ```
44
- The series of question marks makes it appear less formal than typical `TODO` comments. This is a minor point of style.
45
-
46
- **Overall:**
47
-
48
- The submitted changes are of high quality and represent a significant improvement in the codebase's structure, maintainability, and user experience. The refactoring to centralize LLM interaction is particularly noteworthy.
49
-
50
- ---
51
-
52
- **Recommendation:**
53
-
54
- ✅ **I recommend approving this PR.**
55
-
56
- The changes are largely excellent. The primary point to consider before merging is the `prId` sanitization mentioned above to ensure robustness against potentially malformed inputs. The other points are minor.
@@ -1,292 +0,0 @@
1
- Okay, let's examine this diff.
2
-
3
- ## Code Review
4
-
5
- ### `.gitignore`
6
- * `+ /gth-*`
7
- * ✅ **Suggestion:** Adding `gth-*` to `.gitignore` is a good practice if these are generated files (e.g., output from the tool, which seems to be the case with the prefix change from `sloth-*` to `gth-*`). This prevents accidental commits of transient data.
8
-
9
- ### `.gsloth.guidelines.md` & `.gsloth.review.md`
10
- * The changes in `.gsloth.guidelines.md` remove instructions for *me* (the reviewer bot) from the guidelines file.
11
- * The new file `.gsloth.review.md` now contains these instructions.
12
- * ✅ **Observation:** This is a sensible refactoring to separate the project's code review guidelines from the instructions for the AI reviewer.
13
-
14
- ### `README.md` & `docs/CONFIGURATION.md`
15
- * `s/.gsloth.preamble.review.md/.gsloth.guidelines.md/g`
16
- * ✅ **Documentation:** The documentation has been updated to reflect the renaming of the primary user-provided guidelines file from `.gsloth.preamble.review.md` to `.gsloth.guidelines.md`. This is consistent with other changes.
17
-
18
- ### `spec/askCommand.spec.ts`
19
- * **Mocking Strategy:**
20
- * The mocking strategy has been changed from using `vi.hoisted()` and a `ctx` object to defining mocks at the top level and using `vi.mock()`.
21
- * ✅ **Suggestion:** This is generally a cleaner and more standard way to handle mocks in Vitest. It improves readability.
22
- * **Preamble/Guideline Handling:**
23
- * `ctx.prompt.readInternalPreamble.mockReturnValue('INTERNAL PREAMBLE');` changed to:
24
- ```typescript
25
- prompt.readBackstory.mockReturnValue('INTERNAL PREAMBLE');
26
- prompt.readGuidelines.mockReturnValue('PROJECT GUIDELINES');
27
- ```
28
- * The `askQuestion` mock is now expected to be called with a combined preamble: `'INTERNAL PREAMBLE\nPROJECT GUIDELINES'`.
29
- * ✅ **Correctness:** This aligns with the changes in `src/commands/askCommand.ts` where both backstory and project guidelines are now read and combined.
30
- * **Output File Prefix:**
31
- * `expect(ctx.questionAnsweringModule.askQuestion).toHaveBeenCalledWith('sloth-ASK', ...)` changed to `expect(askQuestion).toHaveBeenCalledWith('gth-ASK', ...)`.
32
- * ✅ **Correctness:** Reflects the change in the default output file prefix.
33
- * **General Test Logic:**
34
- * The tests correctly adapt to the new way preambles are constructed and the new output prefix.
35
- * ✅ **Test Coverage:** The tests cover cases with a message only, with a single file, and with multiple files.
36
-
37
- ### `spec/config.spec.ts`
38
- * **New Default Config Values:**
39
- * Tests now expect `projectGuidelines: '.gsloth.guidelines.md'` and `projectReviewInstructions: '.gsloth.review.md'` in the default configuration.
40
- * ✅ **Correctness:** This is consistent with the introduction of these new configuration options and their default file names.
41
- * **Type Safety:**
42
- * The tests for various LLM configurations (`vertexai`, `anthropic`, `groq`) correctly include these new default string properties.
43
- * ✅ **Consistency:** Ensures that all configuration paths are tested with the new defaults.
44
-
45
- ### `spec/initCommand.spec.ts`
46
- * `USER_PROJECT_REVIEW_PREAMBLE: '.gsloth.preamble.review.md'` changed to `USER_PROJECT_REVIEW_PREAMBLE: '.gsloth.guidelines.md'`.
47
- * ✅ **Correctness:** The test mock for `config.js` now uses the updated constant name for the project guidelines file, aligning with the changes in `src/config.ts`.
48
-
49
- ### `spec/llmUtils.spec.ts`
50
- * This is a new test file for the new `src/llmUtils.ts`.
51
- * **`invoke` Function Test:**
52
- * It tests the `invoke` function with a `FakeListChatModel`.
53
- * It correctly mocks the `SlothContext` (though it's simplified for this test, which is acceptable for a unit test of `invoke`).
54
- * The test verifies that the `invoke` function returns the content of the first LLM message.
55
- * ⚠️ **Suggestion:** The test for `invoke` is quite basic. It checks if *a* message is returned. It might be beneficial to also assert:
56
- * That the `llm.invoke` method was called with the correct `SystemMessage` and `HumanMessage` constructed from the input `systemMessage` and `prompt`.
57
- * That the `options` (like `configurable: { thread_id: ... }`) are passed through to the LangGraph app invocation.
58
- * If `llm.verbose` is set when `llmGlobalSettings.verbose` is true (though this might be better as a separate test for `setVerbose`'s effect).
59
- * The removal of `SlothContext` type import is fine as the test constructs a minimal context.
60
- * ✅ **Unit Test:** A good starting point for testing the core LLM invocation logic.
61
-
62
- ### `spec/questionAnsweringModule.spec.ts`
63
- * **Refactoring:**
64
- * The test for `askQuestionInner` has been removed, which is correct as this function was inlined/refactored into `llmUtils.invoke`.
65
- * **`ProgressIndicator` Mocking:**
66
- * `utilsMock.ProgressIndicator.prototype.stop = vi.fn();`
67
- * `utilsMock.ProgressIndicator.prototype.indicate = vi.fn();`
68
- * ✅ **Correctness:** Mocks the new `stop()` method and the existing `indicate()` method of the `ProgressIndicator`.
69
- * **Output File Prefix:**
70
- * `utilsMock.toFileSafeString.mockReturnValue('sloth-ASK');` changed to `utilsMock.toFileSafeString.mockReturnValue('gth-ASK');`.
71
- * `pathMock.resolve` mock adapted accordingly.
72
- * ✅ **Correctness:** Aligns with the prefix change.
73
- * **`invoke` Call:**
74
- * The tests now implicitly test the `invoke` function via `askQuestion`.
75
- * **Error Handling:**
76
- * The test for file write errors remains and is still relevant.
77
- * ✅ **Test Coverage:** Ensures that `displayError` is called and `ProgressIndicator.stop()` is called in error scenarios.
78
-
79
- ### `spec/reviewCommand.spec.ts`
80
- * **Preamble/Guideline Handling:**
81
- * Mocks for `prompt.readInternalPreamble` and `prompt.readPreamble` are replaced with mocks for `prompt.readBackstory`, `prompt.readGuidelines`, and `prompt.readReviewInstructions`.
82
- * The expected combined preamble string reflects this change: `'INTERNAL BACKSTORY\nPROJECT GUIDELINES\nREVIEW INSTRUCTIONS'`.
83
- * ✅ **Correctness:** Aligns with changes in `src/commands/reviewCommand.ts`.
84
- * **Output File Prefix:**
85
- * `sloth-DIFF-review` to `gth-DIFF-review`.
86
- * `sloth-PR-123-review` to `gth-PR-123-review`.
87
- * ✅ **Correctness:** Reflects the prefix change.
88
- * **`stdin` Handling:**
89
- * The tests involving `stdin` (e.g., "Should call review with stdin content") have been updated. The way `slothContext` is mocked for these tests has changed slightly (e.g., removing `stdin: ''` from the direct mock of `slothContext` as it's now handled by `systemUtils.getStringFromStdin`).
90
- * ⚠️ **Attention:** The tests for `stdin` now rely on the global `slothContext` from `#src/config.js`. While this works, it makes the tests less isolated. It might be cleaner to mock `getStringFromStdin` from `#src/systemUtils.js` directly within these specific tests if the goal is to unit test the command's logic independent of the `systemUtils` implementation. However, given the current structure, this is functional.
91
- * **`SlothContext` Mocking:**
92
- * The way `SlothContext` is constructed for tests involving specific providers (like Jira) has been updated. It now casts a partial `SlothConfig` to `SlothConfig`. This is a common pattern in testing.
93
- * ✅ **Test Setup:** The setup for different content/requirements providers seems correct and adapted to the changes.
94
-
95
- ### `spec/reviewModule.spec.ts`
96
- * **Refactoring:**
97
- * The test for `reviewInner` is removed, consistent with its refactoring.
98
- * **New Mocks:**
99
- * Extensive mocking for `fs`, `path`, `systemUtils`, `consoleUtils`, `utils`, and the new `llmUtils`.
100
- * ✅ **Thoroughness:** Good setup for testing the `review` function in isolation.
101
- * **`llmUtils.invoke` Mocking:**
102
- * `llmUtilsMock.invoke.mockResolvedValue('LLM Review Response');`
103
- * The test verifies that `llmUtils.invoke` is called with the correct parameters.
104
- * ✅ **Correctness:** This is the primary integration point with the new LLM utility.
105
- * **File Operations:**
106
- * Verifies `fs.writeFileSync` is called with the correct path and content.
107
- * Tests error handling for `writeFileSync`.
108
- * ✅ **Robustness:** Covers success and failure paths for file writing.
109
- * **`ProgressIndicator`:**
110
- * Verifies `ProgressIndicator.prototype.stop` is called.
111
- * ✅ **Correctness:** Ensures progress indication is properly managed.
112
- * **Output File Prefix:**
113
- * `utilsMock.toFileSafeString.mockReturnValue('gth-REVIEW');`
114
- * ✅ **Correctness:** Aligns with prefix change.
115
-
116
- ### `src/commands/askCommand.ts`
117
- * **Preamble/Guideline Reading:**
118
- * `readInternalPreamble()` changed to `readBackstory()` and `readGuidelines(slothContext.config.projectGuidelines)`.
119
- * The preamble is now a combination of these two.
120
- * ✅ **Logic Change:** Correctly implements the new way of constructing the system message for the LLM.
121
- * **Output File Prefix:**
122
- * `sloth-ASK` changed to `gth-ASK`.
123
- * `// TODO make the prefix configurable`
124
- * ✅ **Enhancement Noted:** Good that this is marked as a TODO.
125
- * **`slothContext` Usage:**
126
- * Uses `slothContext.config.projectGuidelines` to fetch the guidelines file path.
127
- * ✅ **Configuration:** Correctly uses the configured path.
128
-
129
- ### `src/commands/reviewCommand.ts`
130
- * **Preamble/Guideline Reading:**
131
- * Similar to `askCommand`, it now uses `readBackstory()`, `readGuidelines(slothContext.config.projectGuidelines)`, and `readReviewInstructions(slothContext.config.projectReviewInstructions)`.
132
- * ✅ **Logic Change:** Correctly implements the new system message construction.
133
- * **`stdin` Handling:**
134
- * `if (context.stdin)` changed to `let stringFromStdin = getStringFromStdin(); if (stringFromStdin)`.
135
- * ✅ **Refactoring:** Uses the new centralized way to get stdin content via `getStringFromStdin` from `systemUtils.ts`. This is a good separation of concerns.
136
- * **Output File Prefix:**
137
- * `sloth-DIFF-review` to `gth-DIFF-review`.
138
- * `sloth-PR-${prId}-review` to `gth-PR-${prId}-review`.
139
- * `// TODO make the prefix configurable`
140
- * `// TODO consider including requirements id`
141
- * `// TODO sanitize prId`
142
- * ✅ **Enhancements Noted:** Important TODOs, especially sanitizing `prId` for file system safety.
143
- * **`SlothContext` Usage:**
144
- * The command no longer takes `context: SlothContext` as a direct argument to the main action but uses the global `slothContext` for config values. The `program.command().action()` still receives `context` from Commander, but it's not the `SlothContext` we define. This is a subtle but important change. The `reviewCommand` function signature itself still takes `context: SlothContext` but it's the global one.
145
- * ⚠️ **Clarity/Potential Confusion:** The `context` parameter in `reviewCommand(program: Command, context: SlothContext)` refers to the global `slothContext`. Inside the `.action(async (contentId: string | undefined, options: ReviewCommandOptions) => { ... })`, if `context` were used, it would be Commander's context. The code correctly uses the global `slothContext` from import. This is fine, but worth noting the distinction.
146
-
147
- ### `src/config.ts`
148
- * **New Config Properties:**
149
- * `projectGuidelines: string;`
150
- * `projectReviewInstructions: string;`
151
- * ✅ **Feature:** Adds new configurable paths for different types of prompt files.
152
- * **Type Change for `llm`:**
153
- * `LanguageModelLike` to `BaseChatModel`.
154
- * ✅ **Type Safety:** `BaseChatModel` is more specific and appropriate for chat-based interactions, which LangChain.js is heavily geared towards. This is a good refinement.
155
- * **Removal of `stdin` from `SlothContext`:**
156
- * `stdin: string;` removed.
157
- * ✅ **Refactoring:** `stdin` is now handled by `systemUtils.ts`, which is a better place for system-level input.
158
- * **New Constants and Default Values:**
159
- * `PROJECT_GUIDELINES = '.gsloth.guidelines.md';`
160
- * `PROJECT_REVIEW_INSTRUCTIONS = '.gsloth.review.md';`
161
- * `USER_PROJECT_REVIEW_PREAMBLE` constant renamed/replaced by `PROJECT_GUIDELINES`.
162
- * `DEFAULT_CONFIG` updated with these new properties.
163
- * ✅ **Consistency:** All changes align with the new file naming and configuration structure.
164
- * **`writeProjectReviewPreamble` function:**
165
- * Now writes to `PROJECT_GUIDELINES` (formerly `USER_PROJECT_REVIEW_PREAMBLE`).
166
- * The default content and warning messages are updated to reflect the new file name.
167
- * ✅ **Correctness:** Updates initialization logic.
168
- * **`reset` function:**
169
- * `slothContext.stdin = '';` removed.
170
- * ✅ **Correctness:** Consistent with `stdin` removal from context.
171
-
172
- ### `src/configs/anthropic.ts` & `src/configs/vertexai.ts`
173
- * **Type Change:**
174
- * Return type of `processJsonConfig` changed from `Promise<LanguageModelLike>` to `Promise<BaseChatModel>`.
175
- * ✅ **Type Safety:** Consistent with the type change in `SlothConfig`.
176
-
177
- ### `src/index.ts`
178
- * **New Global Option `--verbose`:**
179
- * `program.option('--verbose', 'Print entire prompt sent to LLM.');`
180
- * `program.parseOptions(argv);`
181
- * `if (program.getOptionValue('verbose')) { setVerbose(true); }`
182
- * ✅ **Feature:** Adds a useful debugging feature. Parsing options before command binding is correct for global options.
183
- * **`readStdin` Import:**
184
- * Imported from `systemUtils.js` instead of `utils.js`.
185
- * ✅ **Refactoring:** Correctly reflects the move of this utility.
186
-
187
- ### `src/llmUtils.ts`
188
- * This is a new, crucial file.
189
- * **`invoke` function:**
190
- * Uses LangGraph (`StateGraph`, `MessagesAnnotation`, `MemorySaver`, `START`, `END`) to structure the LLM call.
191
- * ✅ **Architecture:** Using LangGraph provides a structured way to manage conversations, even if it's a single turn for now. It allows for easier extension to multi-turn conversations or more complex flows later.
192
- * Constructs `SystemMessage` and `HumanMessage`.
193
- * Handles LLM invocation and extracts the content from the last `AIMessageChunk`.
194
- * `llm.verbose = true;` if `llmGlobalSettings.verbose` is set.
195
- * ✅ **Debugging:** Integrates the verbose option.
196
- * ⚠️ **Error Handling:** The `invoke` function itself doesn't have explicit try-catch blocks for the `app.invoke` call. Errors from the LLM or graph execution would propagate up. This might be acceptable if handled by the callers (`askQuestion`, `review`), which they seem to do for file writing but not explicitly for the LLM call itself (though the `ProgressIndicator` might implicitly handle some visual feedback). Consider if more specific error handling or logging is needed directly within `invoke`.
197
- * ⚠️ **MemorySaver:** `const memory = new MemorySaver();` is created for each `invoke` call. If the `thread_id` in `options` is intended to persist memory across calls *within the same command execution but different logical invocations* (which is not the current pattern but could be a future one), this `MemorySaver` instance would be new each time. For the current single-call-per-command structure, this is fine. If true multi-turn state persistence across separate CLI executions is desired, `MemorySaver` would need to be configured with a persistent checkpointer.
198
- * **`setVerbose` function:**
199
- * Sets a global flag for verbose LLM logging.
200
- * ✅ **Utility:** Simple and effective.
201
-
202
- ### `src/modules/questionAnsweringModule.ts`
203
- * **Refactoring:**
204
- * `askQuestionInner` removed.
205
- * Now calls `invoke` from `llmUtils.ts`.
206
- * ✅ **Abstraction:** Good use of the new utility function.
207
- * **`ProgressIndicator` Usage:**
208
- * `progressIndicator.stop();` is called after `invoke` completes.
209
- * ✅ **Correctness:** Ensures the indicator is stopped.
210
- * **Error Handling:**
211
- * The existing `try-catch` for `writeFileSync` remains. Errors from `invoke` would propagate and potentially lead to an unhandled rejection if not caught by a higher-level mechanism (e.g., Node.js default behavior).
212
- * ⚠️ **Robustness:** While file write errors are handled, consider if errors from the `invoke` call itself (e.g., API errors from the LLM) should be caught and presented more gracefully to the user, perhaps with a specific message before falling into the file write error or generic exit.
213
-
214
- ### `src/modules/reviewModule.ts`
215
- * **Refactoring:**
216
- * `reviewInner` removed.
217
- * Now calls `invoke` from `llmUtils.ts`.
218
- * ✅ **Abstraction:** Good use of the new utility function.
219
- * **`ProgressIndicator` Usage:**
220
- * `progressIndicator.stop();` is called after `invoke` completes.
221
- * ✅ **Correctness:** Ensures the indicator is stopped.
222
- * **Error Handling:**
223
- * Similar to `questionAnsweringModule`, file write errors are handled. Errors from `invoke` might not be specifically caught here.
224
- * ⚠️ **Robustness:** Same consideration as for `questionAnsweringModule` regarding errors from `invoke`.
225
-
226
- ### `src/prompt.ts`
227
- * **Function Renaming and Logic Changes:**
228
- * `readInternalPreamble` -> `readBackstory`. Now uses `readFileFromCurrentOrInstallDir`.
229
- * `readPreamble` -> `readGuidelines`. Now uses `readFileFromCurrentDir` and has more specific error messaging.
230
- * New `readReviewInstructions` function, uses `readConfigPromptFile` (which is `readFileFromCurrentOrInstallDir`).
231
- * ✅ **Clarity & Flexibility:** The new function names are more descriptive. The use of `readFileFromCurrentOrInstallDir` for `readBackstory` and `readReviewInstructions` allows users to override these if needed, while `readGuidelines` enforces it from the current project directory. This seems like a reasonable design.
232
- * **Error Handling:**
233
- * The error messages are more specific and guide the user towards `gsloth init`.
234
- * ✅ **User Experience:** Improved error guidance.
235
-
236
- ### `src/systemUtils.ts`
237
- * **New `getStringFromStdin()`:**
238
- * Returns the cached `innerState.stringFromStdin`.
239
- * ✅ **Utility:** Provides a clean way to access stdin content after it has been read.
240
- * **`readStdin()` function:**
241
- * Moved from `utils.ts`.
242
- * Logic updated: `ProgressIndicator` is now instantiated with `manual = true` when reading stdin, and `indicate()` is called inside the `readable` event.
243
- * It now populates `innerState.stringFromStdin` instead of `slothContext.stdin`.
244
- * ✅ **Refactoring & Correctness:** This is a much cleaner way to handle stdin. The progress indication is more accurate. Storing it in `innerState` is good for encapsulation within this module.
245
- * **`ProgressIndicator` in `readStdin`:**
246
- * `const progressIndicator = new ProgressIndicator('reading STDIN', true);`
247
- * `progressIndicator.indicate();`
248
- * ⚠️ **Nitpick/Minor:** The `ProgressIndicator` in `readStdin` is not explicitly `stop()`-ed. Since `readStdin` resolves its promise after `program.parseAsync()` which happens on `stdin.on('end')`, the "reading STDIN" message with dots might remain on the screen if other operations are quick. It might be cleaner to call `progressIndicator.stop()` right before `resolvePromise()` in the `end` event handler. However, subsequent output will likely overwrite it, so it's a minor visual point.
249
-
250
- ### `src/utils.ts`
251
- * **Removal of `readStdin`:**
252
- * Correctly removed as it's now in `systemUtils.ts`.
253
- * **New `readFileFromCurrentOrInstallDir()`:**
254
- * Tries to read from the current directory first, then falls back to the install directory.
255
- * Includes logging about which path it's trying.
256
- * ✅ **Utility & Robustness:** Useful function for accessing configuration/template files that can be overridden by the user.
257
- * **`ProgressIndicator` Class Changes:**
258
- * Constructor now takes an optional `manual` flag. If not manual, it starts an interval timer to print dots.
259
- * `indicate()` method now throws an error if called in non-manual mode.
260
- * New `stop()` method to clear the interval and print a newline.
261
- * ✅ **Enhancement:** This makes the `ProgressIndicator` more versatile. The automatic dot printing is convenient for long-running async tasks where manual indication is cumbersome. The `stop()` method is crucial for cleaning up and ensuring the prompt is clean.
262
- * **`spawnCommand` `ProgressIndicator`:**
263
- * `const progressIndicator = new ProgressIndicator(progressMessage, true);`
264
- * The `indicate()` calls within `spawnCommand` are now correct for the manual mode.
265
- * `progressIndicator.stop()` is called in both `close` and `error` handlers.
266
- * ✅ **Correctness:** Proper usage of the updated `ProgressIndicator`.
267
-
268
- ## Overall Assessment
269
-
270
- This is a substantial refactoring and feature addition. The changes are largely positive:
271
-
272
- * **Improved Configuration:** More granular control over prompt files (`.gsloth.guidelines.md`, `.gsloth.review.md`).
273
- * **Centralized LLM Logic:** The new `llmUtils.ts` with the `invoke` function using LangGraph is a significant architectural improvement. It centralizes LLM interaction and makes it easier to manage and extend.
274
- * **Refined `stdin` Handling:** Moving `stdin` processing to `systemUtils.ts` and caching the result is cleaner.
275
- * **Enhanced `ProgressIndicator`:** The utility is now more flexible.
276
- * **Code Clarity:** Renaming of functions and constants (e.g., `readBackstory`, `PROJECT_GUIDELINES`) improves readability.
277
- * **Type Safety:** Consistent use of `BaseChatModel` is good.
278
- * **Test Updates:** Tests have been diligently updated to reflect the changes, and new tests for `llmUtils.ts` and `reviewModule.ts` have been added.
279
-
280
- **Minor areas for consideration/improvement:**
281
- * More detailed unit tests for `llmUtils.invoke` to assert message construction.
282
- * Explicit error handling for LLM API calls within `invoke` or its callers (`reviewModule`, `questionAnsweringModule`) for more user-friendly error messages.
283
- * Nitpick about `ProgressIndicator.stop()` in `systemUtils.readStdin`.
284
- * The TODOs noted in the code (configurable prefix, sanitizing `prId`) are important for future work.
285
-
286
- The developer has demonstrated a good understanding of the LangChain.js/LangGraph.js ecosystem and has applied it effectively. The code quality is high, and the changes are well-reasoned.
287
-
288
- ## Recommendation
289
-
290
- ✅ **Approve**
291
-
292
- This PR introduces significant improvements to the tool's architecture, configurability, and maintainability. The changes are well-implemented and tested. The minor points raised are suggestions for further refinement rather than blocking issues.