feat(tasks): run lifecycle script on task creation#1888
feat(tasks): run lifecycle script on task creation#1888Godzilaa wants to merge 1 commit intogeneralaction:mainfrom
Conversation
…-task checkbox to run the configured Run lifecycle script after provisioning.\n- Threads runScriptOnCreate through task creation params.\n- Starts the existing lifecycle runner in the main process and logs failures without blocking task creation.
Greptile SummaryThis PR adds a "Run script after task creation" toggle to the Create Task modal that fires the project's configured
Confidence Score: 4/5Safe to merge; the change is additive and existing guards prevent any unintended script execution. The implementation is clean and the double guard prevents accidental execution. The trade-off worth noting is that when both the run script and an initial conversation are provided, the script executes concurrently with the agent rather than before it. src/main/core/tasks/operations/createTask.ts — the ordering of the lifecycle script relative to createConversation is worth a second look for use cases where runScriptOnCreate and initialConversation are both set.
|
| Filename | Overview |
|---|---|
| src/main/core/tasks/operations/createTask.ts | Adds non-blocking lifecycle script invocation after provisioning; workspaceId access is safe, error is caught and logged, but the script races with any initialConversation that is also provided. |
| src/renderer/features/tasks/create-task-modal/create-task-modal.tsx | Adds runScriptOnCreate switch, gated behind hasRunScript, correctly threaded through all three creation strategies and reset on project change. |
| src/shared/tasks.ts | Adds optional runScriptOnCreate field to CreateTaskParams; additive, non-breaking change. |
Sequence Diagram
sequenceDiagram
participant UI as CreateTaskModal
participant TM as taskManager
participant LS as runLifecycleScript
participant CC as createConversation
UI->>TM: createTask(params)
TM->>TM: provisionTask(project, task)
TM-->>UI: provisionResult
alt params.runScriptOnCreate
TM-)LS: void runLifecycleScript({ type: 'run' }) [fire-and-forget]
end
alt params.initialConversation
TM->>CC: await createConversation(...)
CC-->>TM: done
end
Note over TM,LS: Script and conversation can run concurrently
Comments Outside Diff (1)
-
src/main/core/tasks/operations/createTask.ts, line 231-254 (link)Lifecycle script races with initial conversation
runLifecycleScriptis fired-and-forgotten, thencreateConversationisawait-ed immediately after. When bothrunScriptOnCreateandinitialConversationare set, the AI agent can begin executing commands in the workspace while therunscript is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup.Prompt To Fix With AI
This is a comment left during a code review. Path: src/main/core/tasks/operations/createTask.ts Line: 231-254 Comment: **Lifecycle script races with initial conversation** `runLifecycleScript` is fired-and-forgotten, then `createConversation` is `await`-ed immediately after. When both `runScriptOnCreate` and `initialConversation` are set, the AI agent can begin executing commands in the workspace while the `run` script is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup. How can I resolve this? If you propose a fix, please make it concise.
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/main/core/tasks/operations/createTask.ts:231-254
**Lifecycle script races with initial conversation**
`runLifecycleScript` is fired-and-forgotten, then `createConversation` is `await`-ed immediately after. When both `runScriptOnCreate` and `initialConversation` are set, the AI agent can begin executing commands in the workspace while the `run` script is still running. If the run script configures the environment (e.g., installs dependencies or starts a service the agent needs), the agent may encounter a partially initialised workspace on startup.
Reviews (1): Last reviewed commit: "feat(tasks): run lifecycle script on tas..." | Re-trigger Greptile
Validation passed: pnpm run format:check, pnpm run typecheck, pnpm run lint, pnpm run test