-
Notifications
You must be signed in to change notification settings - Fork 2
feat(progress): replace file-based comment ID with CASCADE_PROGRESS_COMMENT_ID env var #638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ac4fa11
feat(progress): replace file-based comment ID with CASCADE_PROGRESS_C…
d098c91
chore: remove .cascade-progress-comment-id state file from repo
6fc98d5
fix(progress): use ENV_VAR_NAME constant and add injection tests
f5e2ba4
Merge remote-tracking branch 'origin/dev' into feat/env-var-progress-…
f9193ff
fix(test): update progressMonitor.test.ts for env-var-based progress …
7a511ed
fix(ci): restore .cascade-progress-comment-id in .gitignore
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,55 @@ | ||
| /** | ||
| * File-based state bridge for sharing the progress comment ID between | ||
| * Env-var-based state bridge for sharing the progress comment ID between | ||
| * the ProgressMonitor (which creates the initial comment) and the | ||
| * PostComment gadget (which posts the final summary). | ||
| * | ||
| * Uses a state file `.cascade-progress-comment-id` written to the repo | ||
| * working directory. This approach works for both the llmist backend | ||
| * (same process) and the Claude Code backend (subprocess), since both | ||
| * share the same filesystem. | ||
| * Uses the `CASCADE_PROGRESS_COMMENT_ID` environment variable following | ||
| * the existing `CASCADE_*` naming pattern. The env var format is | ||
| * `<workItemId>:<commentId>`. | ||
| * | ||
| * File format: `<workItemId>:<commentId>` | ||
| * For the pre-seeded case (~90% of runs), the env var is injected into | ||
| * the Claude Code subprocess via `projectSecrets` before subprocess launch, | ||
| * so it is available from startup. For the dynamic case (ProgressMonitor | ||
| * `postInitial()`), `process.env` is updated in-process — same-process | ||
| * consumers see it immediately; cross-process visibility is an accepted gap. | ||
| */ | ||
|
|
||
| import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs'; | ||
| import { join } from 'node:path'; | ||
|
|
||
| export const STATE_FILE_NAME = '.cascade-progress-comment-id'; | ||
| export const ENV_VAR_NAME = 'CASCADE_PROGRESS_COMMENT_ID'; | ||
|
|
||
| /** | ||
| * Writes the progress comment ID to the state file in the given repo directory. | ||
| * Writes the progress comment ID to the env var. | ||
| * | ||
| * @param repoDir - The working directory where the state file will be written. | ||
| * @param workItemId - The work item ID (Trello card ID or JIRA issue key). | ||
| * @param commentId - The comment ID returned by addComment(). | ||
| */ | ||
| export function writeProgressCommentId( | ||
| repoDir: string, | ||
| workItemId: string, | ||
| commentId: string, | ||
| ): void { | ||
| const filePath = join(repoDir, STATE_FILE_NAME); | ||
| writeFileSync(filePath, `${workItemId}:${commentId}`, 'utf-8'); | ||
| export function writeProgressCommentId(workItemId: string, commentId: string): void { | ||
| process.env[ENV_VAR_NAME] = `${workItemId}:${commentId}`; | ||
| } | ||
|
|
||
| /** | ||
| * Reads the progress comment state from the state file. | ||
| * Reads the progress comment state from the env var. | ||
| * | ||
| * @param repoDir - Optional directory containing the state file. Defaults to | ||
| * `process.cwd()` if not provided. For cross-process usage | ||
| * (e.g., Claude Code subprocess), the caller should ensure | ||
| * `process.chdir(repoDir)` has been called, or pass `repoDir` | ||
| * explicitly. | ||
| * @returns `{ workItemId, commentId }` if the state file exists and is valid, | ||
| * @returns `{ workItemId, commentId }` if the env var is set and valid, | ||
| * or `null` if not found or malformed. | ||
| */ | ||
| export function readProgressCommentId( | ||
| repoDir?: string, | ||
| ): { workItemId: string; commentId: string } | null { | ||
| const dir = repoDir ?? process.cwd(); | ||
| const filePath = join(dir, STATE_FILE_NAME); | ||
|
|
||
| if (!existsSync(filePath)) return null; | ||
| export function readProgressCommentId(): { workItemId: string; commentId: string } | null { | ||
| const value = process.env[ENV_VAR_NAME]; | ||
| if (!value) return null; | ||
|
|
||
| try { | ||
| const content = readFileSync(filePath, 'utf-8').trim(); | ||
| const colonIndex = content.indexOf(':'); | ||
| if (colonIndex === -1) return null; | ||
| const colonIndex = value.indexOf(':'); | ||
| if (colonIndex === -1) return null; | ||
|
|
||
| const workItemId = content.slice(0, colonIndex); | ||
| const commentId = content.slice(colonIndex + 1); | ||
| const workItemId = value.slice(0, colonIndex); | ||
| const commentId = value.slice(colonIndex + 1); | ||
|
|
||
| if (!workItemId || !commentId) return null; | ||
| if (!workItemId || !commentId) return null; | ||
|
|
||
| return { workItemId, commentId }; | ||
| } catch { | ||
| return null; | ||
| } | ||
| return { workItemId, commentId }; | ||
| } | ||
|
|
||
| /** | ||
| * Deletes the progress comment state file. | ||
| * | ||
| * @param repoDir - Optional directory containing the state file. Defaults to | ||
| * `process.cwd()` if not provided. | ||
| * Clears the progress comment state by deleting the env var. | ||
| */ | ||
| export function clearProgressCommentId(repoDir?: string): void { | ||
| const dir = repoDir ?? process.cwd(); | ||
| const filePath = join(dir, STATE_FILE_NAME); | ||
|
|
||
| if (existsSync(filePath)) { | ||
| rmSync(filePath); | ||
| } | ||
| export function clearProgressCommentId(): void { | ||
| delete process.env[ENV_VAR_NAME]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No unit tests for
injectProgressCommentId. The existingsecretBuilder.test.tshas thorough coverage for the other two exports — adding a few cases (string ackCommentId with cardId injects, numeric ackCommentId skips, missing cardId skips) would maintain the same standard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added 5 unit tests for
injectProgressCommentIdinsecretBuilder.test.ts, covering all branches: string ackCommentId with cardId (injects), numeric ackCommentId (skips), missing cardId (skips), undefined ackCommentId (skips), and empty string ackCommentId (skips).