rafcode 2.1.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands/do.d.ts.map +1 -1
- package/dist/commands/do.js +5 -24
- package/dist/commands/do.js.map +1 -1
- package/dist/core/claude-runner.d.ts +0 -13
- package/dist/core/claude-runner.d.ts.map +1 -1
- package/dist/core/claude-runner.js +25 -187
- package/dist/core/claude-runner.js.map +1 -1
- package/dist/core/shutdown-handler.d.ts.map +1 -1
- package/dist/core/shutdown-handler.js +0 -4
- package/dist/core/shutdown-handler.js.map +1 -1
- package/dist/parsers/stream-renderer.d.ts +0 -3
- package/dist/parsers/stream-renderer.d.ts.map +1 -1
- package/dist/parsers/stream-renderer.js +1 -1
- package/dist/parsers/stream-renderer.js.map +1 -1
- package/dist/types/config.d.ts +0 -1
- package/dist/types/config.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/commands/do.ts +5 -24
- package/src/core/claude-runner.ts +27 -224
- package/src/core/shutdown-handler.ts +0 -5
- package/src/parsers/stream-renderer.ts +1 -4
- package/src/types/config.ts +0 -1
- package/tests/unit/claude-runner.test.ts +55 -406
- package/tests/unit/stream-renderer.test.ts +0 -30
- package/RAF/ahrtxf-session-sentinel/decisions.md +0 -19
- package/RAF/ahrtxf-session-sentinel/input.md +0 -1
- package/RAF/ahrtxf-session-sentinel/outcomes/01-capture-session-id.md +0 -37
- package/RAF/ahrtxf-session-sentinel/outcomes/02-resume-flag.md +0 -45
- package/RAF/ahrtxf-session-sentinel/plans/01-capture-session-id.md +0 -41
- package/RAF/ahrtxf-session-sentinel/plans/02-resume-flag.md +0 -51
|
@@ -14,36 +14,6 @@ describe('renderStreamEvent', () => {
|
|
|
14
14
|
expect(result.display).toBe('');
|
|
15
15
|
expect(result.textContent).toBe('');
|
|
16
16
|
});
|
|
17
|
-
|
|
18
|
-
it('should extract session_id from system init events', () => {
|
|
19
|
-
const line = JSON.stringify({
|
|
20
|
-
type: 'system',
|
|
21
|
-
subtype: 'init',
|
|
22
|
-
session_id: 'abc123-session-id',
|
|
23
|
-
tools: ['Read', 'Write', 'Bash'],
|
|
24
|
-
model: 'claude-opus-4-6',
|
|
25
|
-
});
|
|
26
|
-
const result = renderStreamEvent(line);
|
|
27
|
-
expect(result.sessionId).toBe('abc123-session-id');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('should return undefined sessionId for system events without session_id', () => {
|
|
31
|
-
const line = JSON.stringify({
|
|
32
|
-
type: 'system',
|
|
33
|
-
subtype: 'other',
|
|
34
|
-
});
|
|
35
|
-
const result = renderStreamEvent(line);
|
|
36
|
-
expect(result.sessionId).toBeUndefined();
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should not return sessionId for non-system events', () => {
|
|
40
|
-
const line = JSON.stringify({
|
|
41
|
-
type: 'assistant',
|
|
42
|
-
message: { content: [{ type: 'text', text: 'hello' }] },
|
|
43
|
-
});
|
|
44
|
-
const result = renderStreamEvent(line);
|
|
45
|
-
expect(result.sessionId).toBeUndefined();
|
|
46
|
-
});
|
|
47
17
|
});
|
|
48
18
|
|
|
49
19
|
describe('assistant events with text', () => {
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Project Decisions
|
|
2
|
-
|
|
3
|
-
## What's the main use case for logging the session ID?
|
|
4
|
-
Resume interrupted sessions. Capture session ID so RAF can attempt to resume interrupted Claude sessions using `claude --resume <id>`, and also allow manual inspection. Add `raf do <project> --resume <session-id>` flag for resuming after Ctrl+C interruption.
|
|
5
|
-
|
|
6
|
-
## Should the session ID be captured in all execution modes?
|
|
7
|
-
Verbose + non-interactive. Both modes that run tasks should capture session ID. Interactive planning mode can be skipped.
|
|
8
|
-
|
|
9
|
-
## When a session is interrupted, should the session ID be displayed to the user?
|
|
10
|
-
Print to terminal. Display session ID in terminal output on interruption so user can copy it for `--resume`.
|
|
11
|
-
|
|
12
|
-
## For `raf do --resume`, should it resume the exact interrupted task or restart from scratch?
|
|
13
|
-
Resume exact task. Pass `--resume` to Claude CLI for the specific interrupted task, continuing from where Claude left off mid-task. Add metadata (task ID) to support this. Format could be `--resume <task-id>:<session-id>` or assume it's the last unfinished task.
|
|
14
|
-
|
|
15
|
-
## How should non-interactive mode get access to the session ID?
|
|
16
|
-
Always use `--output-format stream-json` for both verbose and non-interactive modes. Parse the init event to capture session_id. Only render/display the stream output when `--verbose` flag is passed. This gives us session IDs universally without changing user-visible behavior.
|
|
17
|
-
|
|
18
|
-
## When resuming, should RAF pass the original task's system prompt again?
|
|
19
|
-
Rely on session state. Trust that Claude's `--resume` restores the full context including the original prompt. Don't re-send system prompt or task context.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
check if it's possible to log claude session id if session got interrupted
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
# Outcome: Capture Session ID from Claude CLI Output
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
Implemented session ID extraction from Claude CLI's `system.init` NDJSON event in both `run()` and `runVerbose()` methods. The session ID is now captured, returned in `RunResult`, and printed to the terminal on interruption.
|
|
6
|
-
|
|
7
|
-
## Key Changes
|
|
8
|
-
|
|
9
|
-
### `src/parsers/stream-renderer.ts`
|
|
10
|
-
- Added `session_id` field to `StreamEvent` interface
|
|
11
|
-
- Added `sessionId` field to `RenderResult` interface
|
|
12
|
-
- Modified `renderStreamEvent()` to extract and return `session_id` from system init events
|
|
13
|
-
|
|
14
|
-
### `src/core/claude-runner.ts`
|
|
15
|
-
- Added `sessionId?: string` field to `RunResult` interface
|
|
16
|
-
- Added `_sessionId` private field and public `sessionId` getter to `ClaudeRunner` class
|
|
17
|
-
- Refactored `run()` to use `--output-format stream-json --verbose` with silent NDJSON parsing (no stdout display), enabling session ID extraction
|
|
18
|
-
- Updated `runVerbose()` to capture `sessionId` from stream events
|
|
19
|
-
- Both methods return `sessionId` in `RunResult`
|
|
20
|
-
- Session ID is printed via `logger.info()` on timeout and context overflow in both methods
|
|
21
|
-
|
|
22
|
-
### `src/core/shutdown-handler.ts`
|
|
23
|
-
- Added session ID logging in `handleShutdown()` — prints `Session ID: <id>` when a Claude session is interrupted via Ctrl+C/SIGTERM
|
|
24
|
-
|
|
25
|
-
### `tests/unit/stream-renderer.test.ts`
|
|
26
|
-
- Added 3 new tests: session_id extraction, undefined for missing session_id, undefined for non-system events
|
|
27
|
-
|
|
28
|
-
### `tests/unit/claude-runner.test.ts`
|
|
29
|
-
- Updated existing `run()` tests to emit NDJSON events (since `run()` now uses stream-json format)
|
|
30
|
-
- Updated flag assertion: `run()` now includes `--output-format stream-json --verbose`
|
|
31
|
-
- Added 5 new tests: sessionId extraction in run(), runVerbose(), undefined when missing, getter exposure, deduplication
|
|
32
|
-
|
|
33
|
-
## Test Results
|
|
34
|
-
|
|
35
|
-
All 986 tests pass (45 test suites). No regressions introduced.
|
|
36
|
-
|
|
37
|
-
<promise>COMPLETE</promise>
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# Outcome: Add --resume Flag to raf do Command
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
Added `--resume <session-id>` option to `raf do` that resumes an interrupted Claude session for a specific task. When used, Claude is spawned with `--resume` flag only (no prompt/model/system-prompt flags), and completion monitoring works identically to normal execution.
|
|
6
|
-
|
|
7
|
-
## Key Changes
|
|
8
|
-
|
|
9
|
-
### `src/types/config.ts`
|
|
10
|
-
- Added `resume?: string` field to `DoCommandOptions` interface
|
|
11
|
-
|
|
12
|
-
### `src/commands/do.ts`
|
|
13
|
-
- Added `-r, --resume <session-id>` option to the `do` command definition
|
|
14
|
-
- Added `resumeSessionId` to `SingleProjectOptions` interface
|
|
15
|
-
- In the task execution loop: when `activeResumeSessionId` is set, calls `runResume()` instead of `run()`/`runVerbose()` for the first attempt
|
|
16
|
-
- Clears `activeResumeSessionId` after the first task completes, so subsequent tasks use normal execution
|
|
17
|
-
- Prints clear user-facing message: `Resuming task <id> with session <session-id>` in both verbose and minimal modes
|
|
18
|
-
|
|
19
|
-
### `src/core/claude-runner.ts`
|
|
20
|
-
- Added `runResume(sessionId, options)` method that spawns Claude with:
|
|
21
|
-
- `--resume <session-id>` — restores the interrupted session
|
|
22
|
-
- `--dangerously-skip-permissions` — required for non-interactive operation
|
|
23
|
-
- `--output-format stream-json --verbose` — enables NDJSON event parsing
|
|
24
|
-
- Does NOT pass `--model`, `--append-system-prompt`, or `-p` (Claude restores these from session state)
|
|
25
|
-
- Same completion detection, timeout handling, context overflow detection, and session ID extraction as existing methods
|
|
26
|
-
|
|
27
|
-
### `tests/unit/claude-runner.test.ts`
|
|
28
|
-
- Added 11 new tests in `runResume()` describe block:
|
|
29
|
-
- Spawns with `--resume` flag and session ID
|
|
30
|
-
- Does NOT include `--model`, `--append-system-prompt`, or `-p` flags
|
|
31
|
-
- Includes `--dangerously-skip-permissions` flag
|
|
32
|
-
- Includes `--output-format stream-json` and `--verbose` flags
|
|
33
|
-
- Collects output from NDJSON events
|
|
34
|
-
- Handles timeout correctly
|
|
35
|
-
- Detects completion markers
|
|
36
|
-
- Extracts session ID from resumed session
|
|
37
|
-
- Passes cwd to spawn (worktree support)
|
|
38
|
-
- Detects context overflow
|
|
39
|
-
- Sets CLAUDE_CODE_EFFORT_LEVEL env var when provided
|
|
40
|
-
|
|
41
|
-
## Test Results
|
|
42
|
-
|
|
43
|
-
All 997 tests pass (45 test suites). No regressions introduced.
|
|
44
|
-
|
|
45
|
-
<promise>COMPLETE</promise>
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
# Task: Capture Session ID from Claude CLI Output
|
|
2
|
-
|
|
3
|
-
## Objective
|
|
4
|
-
Extract and store the Claude session ID from stream-json output in both verbose and non-interactive execution modes.
|
|
5
|
-
|
|
6
|
-
## Context
|
|
7
|
-
Claude CLI emits a `session_id` in its `system.init` NDJSON event when using `--output-format stream-json`. RAF currently discards this event entirely. We need to capture and surface this ID so it can be used for session resumption and debugging.
|
|
8
|
-
|
|
9
|
-
## Requirements
|
|
10
|
-
- Unify both `run()` (non-interactive) and `runVerbose()` methods to use `--output-format stream-json` so that the system init event is always available
|
|
11
|
-
- In non-verbose mode, parse NDJSON events silently (extract textContent for output accumulation and detect completion markers) without rendering anything to stdout
|
|
12
|
-
- In verbose mode, continue rendering stream events to stdout as before
|
|
13
|
-
- Extract `session_id` from the `system.init` event (first event in the stream)
|
|
14
|
-
- Add `sessionId?: string` field to the `RunResult` type returned by both `run()` and `runVerbose()`
|
|
15
|
-
- Modify `renderStreamEvent()` in `stream-renderer.ts` to return the session_id when it encounters a system init event, rather than discarding it
|
|
16
|
-
- When a session is interrupted (Ctrl+C, timeout, context overflow), print the session ID to terminal: `Session ID: <id>` so the user can copy it
|
|
17
|
-
- Add tests for the session ID extraction from system init events
|
|
18
|
-
- Add tests verifying session ID is included in RunResult
|
|
19
|
-
|
|
20
|
-
## Implementation Steps
|
|
21
|
-
1. Update the `RunResult` type to include an optional `sessionId` field
|
|
22
|
-
2. Modify `renderStreamEvent()` to extract and return `session_id` from system init events (add a new field to the return type, e.g. `sessionId?: string`)
|
|
23
|
-
3. Refactor `run()` to use `--output-format stream-json` internally, parsing NDJSON lines the same way `runVerbose()` does, but without writing display output to stdout
|
|
24
|
-
4. In both `run()` and `runVerbose()`, capture the session_id from the first system init event and include it in the returned `RunResult`
|
|
25
|
-
5. In the shutdown handler and timeout/overflow paths, print the captured session ID to the terminal before exiting
|
|
26
|
-
6. Write unit tests for session ID extraction from stream events
|
|
27
|
-
7. Write integration-style tests verifying RunResult includes sessionId
|
|
28
|
-
|
|
29
|
-
## Acceptance Criteria
|
|
30
|
-
- [ ] `run()` uses stream-json format internally and parses events silently
|
|
31
|
-
- [ ] `runVerbose()` continues to display stream events as before
|
|
32
|
-
- [ ] Both methods return `sessionId` in `RunResult` when available
|
|
33
|
-
- [ ] On interruption (Ctrl+C, timeout, overflow), session ID is printed to terminal
|
|
34
|
-
- [ ] Existing tests continue to pass
|
|
35
|
-
- [ ] New tests cover session ID extraction
|
|
36
|
-
|
|
37
|
-
## Notes
|
|
38
|
-
- The system init event format is: `{ type: 'system', subtype: 'init', session_id: string, tools: string[], model: string }`
|
|
39
|
-
- Currently `stream-renderer.ts` line 96 returns `{ display: '', textContent: '' }` for all system events — this is where extraction should happen
|
|
40
|
-
- The `run()` method currently uses plain text output with `child_process.spawn` — it needs to switch to stream-json parsing similar to `runVerbose()`. Consider extracting shared NDJSON parsing logic to avoid duplication.
|
|
41
|
-
- Be careful: `run()` has its own completion marker detection and timeout logic that must continue to work with the new stream-json parsing
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
# Task: Add --resume Flag to raf do Command
|
|
2
|
-
|
|
3
|
-
## Objective
|
|
4
|
-
Add a `--resume` option to `raf do` that resumes an interrupted Claude session for a specific task.
|
|
5
|
-
|
|
6
|
-
## Context
|
|
7
|
-
After task 01 captures the session ID and displays it on interruption, users need a way to actually resume the interrupted session. This task adds `raf do <project> --resume <session-id>` which passes Claude CLI's `--resume` flag to continue a session from where it left off.
|
|
8
|
-
|
|
9
|
-
## Dependencies
|
|
10
|
-
01
|
|
11
|
-
|
|
12
|
-
## Requirements
|
|
13
|
-
- Add `--resume <session-id>` option to the `raf do` command in Commander.js
|
|
14
|
-
- When `--resume` is provided, RAF should:
|
|
15
|
-
1. Identify the task to resume — find the first task that is in-progress (has no outcome file, or has a partial/missing completion marker)
|
|
16
|
-
2. Skip the normal task execution flow and instead spawn Claude with `--resume <session-id>` flag
|
|
17
|
-
3. Do NOT pass `-p` (prompt), `--append-system-prompt`, or `--model` flags — rely on Claude's session state to restore these
|
|
18
|
-
4. DO pass `--dangerously-skip-permissions` as it's required for non-interactive operation
|
|
19
|
-
5. Still use `--output-format stream-json` so we can capture the new session's events and detect completion
|
|
20
|
-
6. Continue monitoring for completion markers and outcome file as usual
|
|
21
|
-
- After the resumed session completes, normal post-task flow should apply (outcome validation, commit verification, next task, etc.)
|
|
22
|
-
- If `--resume` is used with `--worktree`, ensure the CWD is set to the worktree path
|
|
23
|
-
- Print a clear message indicating which task is being resumed: `Resuming task <id> with session <session-id>`
|
|
24
|
-
- Add a new method to `ClaudeRunner` (e.g. `runResume(sessionId, options)`) that spawns Claude with the `--resume` flag
|
|
25
|
-
- Cover the new flag and resume method with tests
|
|
26
|
-
|
|
27
|
-
## Implementation Steps
|
|
28
|
-
1. Add `--resume <session-id>` option to the `do` command definition in `src/commands/do.ts`
|
|
29
|
-
2. Add a `runResume()` method to `ClaudeRunner` that spawns Claude with `--resume <session-id> --dangerously-skip-permissions --output-format stream-json` and the same completion monitoring as existing methods
|
|
30
|
-
3. In the task execution loop, when `--resume` is provided:
|
|
31
|
-
- Determine the current task (first task without a valid outcome)
|
|
32
|
-
- Call `runResume()` instead of the normal `run()`/`runVerbose()` method
|
|
33
|
-
- After the resumed task completes, clear the `--resume` flag so subsequent tasks use normal execution
|
|
34
|
-
4. Handle edge cases: invalid session ID format, all tasks already complete, resumed session fails
|
|
35
|
-
5. Write tests for the new `runResume()` method
|
|
36
|
-
6. Write tests for the `--resume` flag integration in the do command
|
|
37
|
-
|
|
38
|
-
## Acceptance Criteria
|
|
39
|
-
- [ ] `raf do <project> --resume <session-id>` resumes the interrupted session
|
|
40
|
-
- [ ] Claude is spawned with `--resume` flag and without prompt/model/system-prompt flags
|
|
41
|
-
- [ ] Completion monitoring works the same as normal execution
|
|
42
|
-
- [ ] After resumed task completes, subsequent tasks run normally
|
|
43
|
-
- [ ] Works with `--worktree` mode
|
|
44
|
-
- [ ] Clear user-facing message on resume start
|
|
45
|
-
- [ ] Tests cover resume path
|
|
46
|
-
|
|
47
|
-
## Notes
|
|
48
|
-
- Claude CLI's `--resume` flag restores the full session context including the system prompt, so we must NOT pass those flags again (they may conflict or be rejected)
|
|
49
|
-
- The `--resume` flag only applies to a single task — after it completes (or fails), remaining tasks use normal execution
|
|
50
|
-
- Consider what happens if the user provides a session ID for a task that already completed — should gracefully handle this
|
|
51
|
-
- Check Claude CLI docs/help to verify exact `--resume` flag syntax: `claude --resume <session-id>`
|