Fork tasks from snapshots; snapshot only when text follows tool calls
This commit is contained in:
+45
-10
@@ -257,6 +257,11 @@ WHERE kind = 'user.message' AND actor = 'byre' AND json_extract(payload, '$.text
|
||||
UPDATE users SET focus = json_set(focus,
|
||||
'$.tab', CASE json_extract(focus, '$.tab') WHEN 'todo' THEN 'project' ELSE json_extract(focus, '$.tab') END,
|
||||
'$.tabs', json((SELECT json_group_array(CASE value WHEN 'todo' THEN 'project' ELSE value END) FROM json_each(users.focus, '$.tabs'))));
|
||||
`}, {"add-snapshot-forks", `
|
||||
ALTER TABLE tasks ADD COLUMN forked_from TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE tasks ADD COLUMN forked_at INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE agent_sessions ADD COLUMN forked_from TEXT NOT NULL DEFAULT '';
|
||||
ALTER TABLE agent_sessions ADD COLUMN forked_at TEXT NOT NULL DEFAULT '';
|
||||
`}}
|
||||
|
||||
type Store struct {
|
||||
@@ -520,11 +525,23 @@ func (s *Store) CreateTask(ctx context.Context, t api.Task, actor string) error
|
||||
if t.TodoItem != nil {
|
||||
todoItem = *t.TodoItem
|
||||
}
|
||||
mergeTitle := ""
|
||||
if t.MergeTitle != t.Title {
|
||||
mergeTitle = t.MergeTitle
|
||||
}
|
||||
forkedFrom := ""
|
||||
if t.ForkedFrom != nil {
|
||||
forkedFrom = *t.ForkedFrom
|
||||
}
|
||||
forkedAt := 0
|
||||
if t.ForkedAt != nil {
|
||||
forkedAt = *t.ForkedAt
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO tasks (id, project_id, title, branch, worktree_path, base_ref, status, created_by, created_at, todo_item)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, t.Branch, t.WorktreePath, t.BaseRef, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem)
|
||||
INSERT INTO tasks (id, project_id, title, merge_title, branch, worktree_path, base_ref, status, created_by, created_at, todo_item, forked_from, forked_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, t.Id, t.ProjectId, t.Title, mergeTitle, t.Branch, t.WorktreePath, t.BaseRef, string(t.Status), t.CreatedBy, formatTime(t.CreatedAt), todoItem, forkedFrom, forkedAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -744,11 +761,17 @@ func (s *Store) Broadcast(ev api.Event) {
|
||||
}
|
||||
|
||||
func (s *Store) CreateSession(ctx context.Context, sess api.AgentSession, projectID string) error {
|
||||
forkedFrom := ""
|
||||
forkedAt := ""
|
||||
if sess.ForkedFrom != nil && sess.ForkedAt != nil {
|
||||
forkedFrom = *sess.ForkedFrom
|
||||
forkedAt = *sess.ForkedAt
|
||||
}
|
||||
return s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `
|
||||
INSERT INTO agent_sessions (id, task_id, owner, vendor, model, vendor_session_id, state, role, created_by, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, sess.Id, nullable(sess.TaskId), sess.Owner, string(sess.Vendor), sess.Model, sess.VendorSessionId, string(sess.State), string(sess.Role), sess.CreatedBy, formatTime(sess.CreatedAt))
|
||||
INSERT INTO agent_sessions (id, task_id, owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||
`, sess.Id, nullable(sess.TaskId), sess.Owner, string(sess.Vendor), sess.Model, sess.VendorSessionId, string(sess.State), string(sess.Role), sess.CreatedBy, formatTime(sess.CreatedAt), forkedFrom, forkedAt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -964,9 +987,9 @@ func (s *Store) write(ctx context.Context, fn func(tx *sql.Tx, emit emitFunc) er
|
||||
|
||||
const projectColumns = `id, name, repo_path, default_branch, remote, created_by, created_at`
|
||||
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, status, created_by, created_at, closed_at, merge_commit, todo_item`
|
||||
const taskColumns = `id, project_id, title, merge_title, branch, worktree_path, base_ref, status, created_by, created_at, closed_at, merge_commit, todo_item, forked_from, forked_at`
|
||||
|
||||
const sessionColumns = `id, coalesce(task_id, ''), owner, vendor, model, vendor_session_id, state, role, created_by, created_at`
|
||||
const sessionColumns = `id, coalesce(task_id, ''), owner, vendor, model, vendor_session_id, state, role, created_by, created_at, forked_from, forked_at`
|
||||
|
||||
type scanner interface {
|
||||
Scan(dest ...any) error
|
||||
@@ -990,7 +1013,9 @@ func scanTask(row scanner) (api.Task, error) {
|
||||
closedAt := sql.NullString{}
|
||||
mergeCommit := ""
|
||||
todoItem := ""
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem)
|
||||
forkedFrom := ""
|
||||
forkedAt := 0
|
||||
err := row.Scan(&t.Id, &t.ProjectId, &t.Title, &t.MergeTitle, &t.Branch, &t.WorktreePath, &t.BaseRef, &status, &t.CreatedBy, &createdAt, &closedAt, &mergeCommit, &todoItem, &forkedFrom, &forkedAt)
|
||||
if err != nil {
|
||||
return t, err
|
||||
}
|
||||
@@ -1015,6 +1040,10 @@ func scanTask(row scanner) (api.Task, error) {
|
||||
if todoItem != "" {
|
||||
t.TodoItem = &todoItem
|
||||
}
|
||||
if forkedFrom != "" {
|
||||
t.ForkedFrom = &forkedFrom
|
||||
t.ForkedAt = &forkedAt
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
|
||||
@@ -1024,10 +1053,16 @@ func scanSession(row scanner) (api.AgentSession, error) {
|
||||
state := ""
|
||||
role := ""
|
||||
createdAt := ""
|
||||
err := row.Scan(&sess.Id, &sess.TaskId, &sess.Owner, &vendor, &sess.Model, &sess.VendorSessionId, &state, &role, &sess.CreatedBy, &createdAt)
|
||||
forkedFrom := ""
|
||||
forkedAt := ""
|
||||
err := row.Scan(&sess.Id, &sess.TaskId, &sess.Owner, &vendor, &sess.Model, &sess.VendorSessionId, &state, &role, &sess.CreatedBy, &createdAt, &forkedFrom, &forkedAt)
|
||||
if err != nil {
|
||||
return sess, err
|
||||
}
|
||||
if forkedFrom != "" {
|
||||
sess.ForkedFrom = &forkedFrom
|
||||
sess.ForkedAt = &forkedAt
|
||||
}
|
||||
sess.Vendor = api.AgentSessionVendor(vendor)
|
||||
sess.State = api.AgentSessionState(state)
|
||||
sess.Role = api.AgentSessionRole(role)
|
||||
|
||||
Reference in New Issue
Block a user