mirror of
https://github.com/jlengrand/Maestro.git
synced 2026-03-10 08:31:19 +00:00
feat: add MAESTRO_SESSION_RESUMED env var for hook control
Add environment variable that allows agent hooks to differentiate between new sessions and resumed sessions. Since Maestro spawns a new process per message (batch mode), session start hooks fire on every turn. This env var lets users conditionally skip hooks. - Set MAESTRO_SESSION_RESUMED=1 when --resume or --session flags present - Document in README with example hook guard - Add note in Agent Provider UI linking to documentation Fixes #42 Co-authored-by: TQ White II (@tqwhite)
This commit is contained in:
20
README.md
20
README.md
@@ -437,6 +437,26 @@ Each task executes in a completely fresh AI session with its own unique session
|
||||
|
||||
This isolation is critical for playbooks with `Reset on Completion` documents that loop indefinitely. Without it, the AI might "remember" completing a task and skip re-execution on subsequent loops.
|
||||
|
||||
### Environment Variables {#environment-variables}
|
||||
|
||||
Maestro sets environment variables that your agent hooks can use to customize behavior:
|
||||
|
||||
| Variable | Value | Description |
|
||||
|----------|-------|-------------|
|
||||
| `MAESTRO_SESSION_RESUMED` | `1` | Set when resuming an existing session (not set for new sessions) |
|
||||
|
||||
**Example: Conditional Hook Execution**
|
||||
|
||||
Since Maestro spawns a new agent process for each message (batch mode), agent "session start" hooks will run on every turn. Use `MAESTRO_SESSION_RESUMED` to skip hooks on resumed sessions:
|
||||
|
||||
```bash
|
||||
# In your agent's session start hook
|
||||
[ "$MAESTRO_SESSION_RESUMED" = "1" ] && exit 0
|
||||
# ... rest of your hook logic for new sessions only
|
||||
```
|
||||
|
||||
This works with any agent provider (Claude Code, Codex, OpenCode) since the environment variable is set by Maestro before spawning the agent process.
|
||||
|
||||
### History & Tracking
|
||||
|
||||
Each completed task is logged to the History panel with:
|
||||
|
||||
@@ -289,6 +289,14 @@ export class ProcessManager extends EventEmitter {
|
||||
env.PATH = standardPaths;
|
||||
}
|
||||
|
||||
// Set MAESTRO_SESSION_RESUMED env var when resuming an existing session
|
||||
// This allows user hooks to differentiate between new sessions and resumed ones
|
||||
// See: https://github.com/pedramamini/Maestro/issues/42
|
||||
const isResuming = finalArgs.includes('--resume') || finalArgs.includes('--session');
|
||||
if (isResuming) {
|
||||
env.MAESTRO_SESSION_RESUMED = '1';
|
||||
}
|
||||
|
||||
logger.debug('[ProcessManager] About to spawn child process', 'ProcessManager', {
|
||||
command,
|
||||
finalArgs,
|
||||
|
||||
@@ -602,6 +602,21 @@ export function NewInstanceModal({ isOpen, onClose, onCreate, theme, existingSes
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Hook behavior note */}
|
||||
<p className="text-xs mt-2" style={{ color: theme.colors.textDim }}>
|
||||
Agent hooks run per-message. Use{' '}
|
||||
<a
|
||||
href="https://github.com/pedramamini/Maestro#environment-variables"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="underline hover:opacity-80"
|
||||
style={{ color: theme.colors.accent }}
|
||||
>
|
||||
MAESTRO_SESSION_RESUMED
|
||||
</a>
|
||||
{' '}to skip on resumed sessions.
|
||||
</p>
|
||||
|
||||
{/* Debug Info Display */}
|
||||
{debugInfo && (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user