Merge claude/1
This commit is contained in:
commit
68bade609b
@ -37,28 +37,41 @@ _writeTaskFile() {
|
||||
local task_id="$1" command="$2" task_type="$3" app_name="$4"
|
||||
local task_dir; task_dir=$(_taskDir)
|
||||
local task_file="$task_dir/${task_id}.json"
|
||||
local created_at; created_at=$(date -Iseconds 2>/dev/null || date '+%Y-%m-%dT%H:%M:%S')
|
||||
# ISO-8601 UTC with milliseconds. Matches the format the WebUI's
|
||||
# tasks-manager.js emits (Date.now() → toISOString()), so the tasks
|
||||
# panel's `new Date(task.createdAt).toLocaleString()` renders correctly.
|
||||
# Falls back to seconds-precision if %3N isn't supported (busybox).
|
||||
local created_at
|
||||
created_at=$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ" 2>/dev/null) \
|
||||
|| created_at=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
[[ -d "$task_dir" ]] || runFileOp mkdir -p "$task_dir"
|
||||
|
||||
# CamelCase initial fields match the WebUI's task shape; processor adds
|
||||
# snake_case status fields on top as it runs. Both task-manager.js and
|
||||
# tasks-manager.js read camelCase directly (no alias needed for createdAt).
|
||||
local task_json
|
||||
if command -v jq >/dev/null 2>&1; then
|
||||
task_json=$(jq -n \
|
||||
--arg id "$task_id" \
|
||||
--arg command "$command" \
|
||||
--arg status queued \
|
||||
--arg created_at "$created_at" \
|
||||
--arg createdAt "$created_at" \
|
||||
--arg type "${task_type:-}" \
|
||||
--arg app "${app_name:-}" \
|
||||
'{id:$id, command:$command, status:$status, created_at:$created_at}
|
||||
'{id:$id, command:$command, status:$status, createdAt:$createdAt,
|
||||
startedAt:null, completedAt:null, heartbeatAt:null,
|
||||
exitCode:null, errorMessage:null}
|
||||
+ (if $type != "" then {type:$type} else {} end)
|
||||
+ (if $app != "" then {app:$app} else {} end)')
|
||||
else
|
||||
# Plain string interpolation — command is the only field that needs
|
||||
# escaping. Strip control chars; the install dispatcher uses ascii
|
||||
# only so this is sufficient without pulling jq in.
|
||||
# escaping. Strip control chars; the dispatcher uses ascii only so
|
||||
# this is sufficient without pulling jq in.
|
||||
local esc="${command//\\/\\\\}"; esc="${esc//\"/\\\"}"
|
||||
task_json="{\"id\":\"$task_id\",\"command\":\"$esc\",\"status\":\"queued\",\"created_at\":\"$created_at\""
|
||||
task_json="{\"id\":\"$task_id\",\"command\":\"$esc\",\"status\":\"queued\",\"createdAt\":\"$created_at\""
|
||||
task_json+=",\"startedAt\":null,\"completedAt\":null,\"heartbeatAt\":null"
|
||||
task_json+=",\"exitCode\":null,\"errorMessage\":null"
|
||||
[[ -n "$task_type" ]] && task_json+=",\"type\":\"$task_type\""
|
||||
[[ -n "$app_name" ]] && task_json+=",\"app\":\"$app_name\""
|
||||
task_json+="}"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user