## ADDED Requirements ### Requirement: Node interrupt function The system SHALL provide an `interrupt(value)` function that pauses graph execution and returns a resume value when the graph is continued. #### Scenario: Interrupt pauses execution with value - **WHEN** a node calls `const approval = interrupt({ question: "Approve this action?" })` - **THEN** execution SHALL pause and the interrupt value SHALL be available in the stream output #### Scenario: Resume returns value to interrupt - **WHEN** the graph is resumed with `Command({ resume: "approved" })` - **THEN** the `interrupt()` call SHALL return `"approved"` #### Scenario: Multiple interrupts are supported - **WHEN** a node calls `interrupt()` twice - **THEN** each interrupt SHALL be resolved sequentially, requiring two resume commands ### Requirement: Command-based graph resumption The system SHALL provide a `Command` class that supports: - `Command.RESUME` — resume value for pending interrupts - `Command.GOTO` — Send or node name for dynamic routing - `Command.PARENT` — bubble up to parent graph #### Scenario: Command with resume continues execution - **WHEN** `await graph.stream(new Command({ resume: "user input" }))` is called - **THEN** the interrupted node SHALL continue with the resume value #### Scenario: Command with goto routes dynamically - **WHEN** a node returns `new Command({ goto: "human_review" })` - **THEN** execution SHALL route to `human_review` node ### Requirement: Automated interrupts at node boundaries The system SHALL support `interruptBefore` and `interruptAfter` in `compile()` options to automatically pause at specific nodes. #### Scenario: InterruptBefore pauses before node execution - **WHEN** `graph.compile({ interruptBefore: ["approval_node"] })` is used - **THEN** the graph SHALL pause just before executing `approval_node` ### Requirement: State snapshots on interrupt When a graph uses a checkpointer, interrupt states SHALL be persisted so execution can be resumed across process boundaries. #### Scenario: Interrupted state is checkpointed - **WHEN** a graphed with a checkpointer is interrupted - **THEN** the checkpoint SHALL contain the interrupt state - **THEN** restoring from that checkpoint SHALL yield the same interrupt state