Skip to content

fix: lifecycle scripts getting recognized in resource monitor#2222

Open
janburzinski wants to merge 2 commits into
mainfrom
emdash/resource-monitir-scripts-ntnrh
Open

fix: lifecycle scripts getting recognized in resource monitor#2222
janburzinski wants to merge 2 commits into
mainfrom
emdash/resource-monitir-scripts-ntnrh

Conversation

@janburzinski
Copy link
Copy Markdown
Collaborator

summary

  • before those lifecycle scripts were not grouped correclty in the resourcemonitor

this is after:
Screenshot 2026-05-25 at 11 18 44

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 25, 2026

Greptile Summary

This PR fixes lifecycle scripts (setup/run/teardown) not being grouped under their owning task in the resource monitor. The root cause was that agent PTYs use a task ID as their scopeId, while lifecycle-script PTYs use the workspace ID — so the direct task lookup always missed them.

  • buildGroups in resource-monitor-utils.ts: adds a fallback loop that matches a lifecycle-script entry's scopeId (workspace ID) against task.workspaceId, resolving it to the correct task bucket key so scripts appear under the right branch.
  • entryLabel / isLifecycleScriptEntry: promoted to exported helpers with a LIFECYCLE_SCRIPT_LABELS map to display friendly names ("Setup script", "Run script", "Teardown script") instead of the truncated raw terminal ID.
  • resource-monitor-view.tsx: consumes the new helpers and renders a Terminal icon for lifecycle-script rows.

Confidence Score: 4/5

Safe to merge — the grouping fix is well-scoped and the label map keys match what createLifecycleScriptTerminalId produces today.

The bucketing logic correctly handles both agent PTYs and lifecycle-script PTYs. The LIFECYCLE_SCRIPT_LABELS keys are verified against the shared terminals.ts source but are hardcoded string literals that could silently drift if the shared function's naming pattern changes.

The LIFECYCLE_SCRIPT_LABELS constant in resource-monitor-utils.ts is worth a second look — its string keys duplicate the output of createLifecycleScriptTerminalId and could drift silently.

Important Files Changed

Filename Overview
src/renderer/features/command-palette/resource-monitor-utils.ts Adds LIFECYCLE_SCRIPT_LABELS, exports entryLabel and isLifecycleScriptEntry, and updates buildGroups to resolve lifecycle-script PTYs (scoped by workspaceId) to their owning task bucket. The label map hardcodes strings that should derive from createLifecycleScriptTerminalId.
src/renderer/features/command-palette/resource-monitor-view.tsx Imports and uses the new entryLabel and isLifecycleScriptEntry helpers; adds a Terminal icon for lifecycle-script rows. Changes look correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[ResourcePtyEntry] --> B{projectStore found?}
    B -- No --> C[Use scopeId as bucketKey, group under Other]
    B -- Yes --> D{Direct task lookup via tasks.get scopeId}
    D -- Hit --> E[bucketKey equals taskId, agent PTY path]
    D -- Miss --> F{Fallback: scan tasks for matching workspaceId}
    F -- Found --> G[bucketKey equals taskId, lifecycle script path]
    F -- Not Found --> H[bucketKey equals scopeId, grouped under Other]
    E --> I[Push entry into task bucket]
    G --> I
    H --> I
    C --> I
    I --> J[Group by project, sort and return Groups]
Loading
Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/renderer/features/command-palette/resource-monitor-utils.ts:40-44
The keys in `LIFECYCLE_SCRIPT_LABELS` are string literals that duplicate the output of `createLifecycleScriptTerminalId` from `@shared/terminals`. If that function's naming pattern ever changes, this map will silently keep returning `undefined` for every lifecycle-script entry, causing them to fall back to the truncated `leafId` label — the very problem this PR fixes. Using computed property keys from the shared function keeps both in sync automatically.

```suggestion
import { createLifecycleScriptTerminalId } from '@shared/terminals';

const LIFECYCLE_SCRIPT_LABELS: Record<string, string> = {
  [createLifecycleScriptTerminalId('setup')]: 'Setup script',
  [createLifecycleScriptTerminalId('run')]: 'Run script',
  [createLifecycleScriptTerminalId('teardown')]: 'Teardown script',
};
```

Reviews (1): Last reviewed commit: "feat(resource-monitor): lifecycle script..." | Re-trigger Greptile

Comment thread src/renderer/features/command-palette/resource-monitor-utils.ts
Copy link
Copy Markdown
Contributor

@arnestrickmann arnestrickmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good addition

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants