mirror of
https://github.com/cexll/myclaude.git
synced 2026-02-15 03:32:43 +08:00
feat: add session resume support and improve output format
- Support session_id in parallel task config for resuming failed tasks - Change output format from JSON to human-readable text - Add helper functions (hello, greet, farewell) with tests - Clean up code formatting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -26,7 +26,6 @@ const (
|
|||||||
stdinSpecialChars = "\n\\\"'`$"
|
stdinSpecialChars = "\n\\\"'`$"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// Test hooks for dependency injection
|
// Test hooks for dependency injection
|
||||||
var (
|
var (
|
||||||
stdinReader io.Reader = os.Stdin
|
stdinReader io.Reader = os.Stdin
|
||||||
@@ -58,8 +57,8 @@ type TaskSpec struct {
|
|||||||
Task string `json:"task"`
|
Task string `json:"task"`
|
||||||
WorkDir string `json:"workdir,omitempty"`
|
WorkDir string `json:"workdir,omitempty"`
|
||||||
Dependencies []string `json:"dependencies,omitempty"`
|
Dependencies []string `json:"dependencies,omitempty"`
|
||||||
|
SessionID string `json:"session_id,omitempty"`
|
||||||
Mode string `json:"-"`
|
Mode string `json:"-"`
|
||||||
SessionID string `json:"-"`
|
|
||||||
UseStdin bool `json:"-"`
|
UseStdin bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +71,6 @@ type TaskResult struct {
|
|||||||
Error string `json:"error"`
|
Error string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func parseParallelConfig(data []byte) (*ParallelConfig, error) {
|
func parseParallelConfig(data []byte) (*ParallelConfig, error) {
|
||||||
trimmed := bytes.TrimSpace(data)
|
trimmed := bytes.TrimSpace(data)
|
||||||
if len(trimmed) == 0 {
|
if len(trimmed) == 0 {
|
||||||
@@ -115,6 +113,9 @@ func parseParallelConfig(data []byte) (*ParallelConfig, error) {
|
|||||||
task.ID = value
|
task.ID = value
|
||||||
case "workdir":
|
case "workdir":
|
||||||
task.WorkDir = value
|
task.WorkDir = value
|
||||||
|
case "session_id":
|
||||||
|
task.SessionID = value
|
||||||
|
task.Mode = "resume"
|
||||||
case "dependencies":
|
case "dependencies":
|
||||||
for _, dep := range strings.Split(value, ",") {
|
for _, dep := range strings.Split(value, ",") {
|
||||||
dep = strings.TrimSpace(dep)
|
dep = strings.TrimSpace(dep)
|
||||||
@@ -396,7 +397,6 @@ func run() int {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
logInfo("Script started")
|
logInfo("Script started")
|
||||||
|
|
||||||
cfg, err := parseArgs()
|
cfg, err := parseArgs()
|
||||||
@@ -856,8 +856,16 @@ func min(a, b int) int {
|
|||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
func test() string {
|
func hello() string {
|
||||||
return "hello $world"
|
return "hello world"
|
||||||
|
}
|
||||||
|
|
||||||
|
func greet(name string) string {
|
||||||
|
return "hello " + name
|
||||||
|
}
|
||||||
|
|
||||||
|
func farewell(name string) string {
|
||||||
|
return "goodbye " + name
|
||||||
}
|
}
|
||||||
|
|
||||||
func logInfo(msg string) {
|
func logInfo(msg string) {
|
||||||
|
|||||||
@@ -624,6 +624,34 @@ func TestMin(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHello(t *testing.T) {
|
||||||
|
got := hello()
|
||||||
|
if got != "hello world" {
|
||||||
|
t.Fatalf("hello() = %q, want %q", got, "hello world")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGreet(t *testing.T) {
|
||||||
|
got := greet("Linus")
|
||||||
|
if got != "hello Linus" {
|
||||||
|
t.Fatalf("greet() = %q, want %q", got, "hello Linus")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFarewell(t *testing.T) {
|
||||||
|
got := farewell("Linus")
|
||||||
|
if got != "goodbye Linus" {
|
||||||
|
t.Fatalf("farewell() = %q, want %q", got, "goodbye Linus")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFarewellEmpty(t *testing.T) {
|
||||||
|
got := farewell("")
|
||||||
|
if got != "goodbye " {
|
||||||
|
t.Fatalf("farewell(\"\") = %q, want %q", got, "goodbye ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestLogFunctions(t *testing.T) {
|
func TestLogFunctions(t *testing.T) {
|
||||||
// Capture stderr
|
// Capture stderr
|
||||||
oldStderr := os.Stderr
|
oldStderr := os.Stderr
|
||||||
|
|||||||
@@ -206,17 +206,36 @@ EOF
|
|||||||
- `id: <task-id>`: Required, unique task identifier
|
- `id: <task-id>`: Required, unique task identifier
|
||||||
- `workdir: <path>`: Optional, working directory (default: `.`)
|
- `workdir: <path>`: Optional, working directory (default: `.`)
|
||||||
- `dependencies: <id1>, <id2>`: Optional, comma-separated task IDs
|
- `dependencies: <id1>, <id2>`: Optional, comma-separated task IDs
|
||||||
|
- `session_id: <uuid>`: Optional, resume a previous session
|
||||||
- `---CONTENT---`: Separates metadata from task content
|
- `---CONTENT---`: Separates metadata from task content
|
||||||
- Task content: Any text, code, special characters (no escaping needed)
|
- Task content: Any text, code, special characters (no escaping needed)
|
||||||
|
|
||||||
**Output**: JSON with results and summary
|
**Resume Failed Tasks**:
|
||||||
```json
|
```bash
|
||||||
{
|
# Use session_id from previous output to resume
|
||||||
"results": [
|
codex-wrapper --parallel - <<'EOF'
|
||||||
{"task_id": "T1", "exit_code": 0, "message": "...", "session_id": "...", "error": ""}
|
---TASK---
|
||||||
],
|
id: T2
|
||||||
"summary": {"total": 3, "success": 3, "failed": 0}
|
session_id: 019xxx-previous-session-id
|
||||||
}
|
---CONTENT---
|
||||||
|
fix the previous error and retry
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
**Output**: Human-readable text format
|
||||||
|
```
|
||||||
|
=== Parallel Execution Summary ===
|
||||||
|
Total: 3 | Success: 2 | Failed: 1
|
||||||
|
|
||||||
|
--- Task: T1 ---
|
||||||
|
Status: SUCCESS
|
||||||
|
Session: 019xxx
|
||||||
|
|
||||||
|
Task output message...
|
||||||
|
|
||||||
|
--- Task: T2 ---
|
||||||
|
Status: FAILED (exit code 1)
|
||||||
|
Error: some error message
|
||||||
```
|
```
|
||||||
|
|
||||||
**Features**:
|
**Features**:
|
||||||
|
|||||||
Reference in New Issue
Block a user