Merge branch 'worktree-agent-a26df8b0059ab1b12'

This commit is contained in:
2026-11-09 20:54:12 +00:00
43 changed files with 2689 additions and 274 deletions
+27 -8
View File
@@ -10,7 +10,9 @@ import (
// initChatShellRuns creates the additive table of operator shell commands. A
// run belongs to its chat session and is Pipelines' own record: it is never
// part of the harness transcript. Output holds only the retained tail.
// part of the harness transcript. Output holds only the retained tail (the raw
// terminal stream of a terminal run); output_text is its plain-text rendering.
// Typed input is never stored.
func (s *Store) initChatShellRuns() error {
_, err := s.db.Exec(`CREATE TABLE IF NOT EXISTS chat_shell_runs (
id TEXT PRIMARY KEY,
@@ -28,7 +30,20 @@ output TEXT NOT NULL DEFAULT '',
output_start INTEGER NOT NULL DEFAULT 0,
output_bytes INTEGER NOT NULL DEFAULT 0);
CREATE INDEX IF NOT EXISTS chat_shell_runs_session ON chat_shell_runs(session_id, started_at);`)
return err
if err != nil {
return err
}
for _, column := range [][2]string{
{"terminal", "INTEGER NOT NULL DEFAULT 0"},
{"cols", "INTEGER NOT NULL DEFAULT 0"},
{"rows", "INTEGER NOT NULL DEFAULT 0"},
{"output_text", "TEXT NOT NULL DEFAULT ''"},
} {
if err := s.addColumnIfMissing("chat_shell_runs", column[0], column[1]); err != nil {
return err
}
}
return nil
}
// SaveChatShellRun inserts or replaces one run. Inserting a new run prunes the
@@ -44,13 +59,16 @@ func (s *Store) SaveChatShellRun(ctx context.Context, run protocol.ChatShellRunR
exit = *run.ExitCode
}
if _, err := tx.ExecContext(ctx, `INSERT INTO chat_shell_runs
(id, session_id, command, directory, status, exit_code, signal, error, started_at, ended_at, duration_ms, output, output_start, output_bytes)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
(id, session_id, command, directory, status, exit_code, signal, error, started_at, ended_at, duration_ms, output, output_start, output_bytes,
terminal, cols, rows, output_text)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET status = excluded.status, exit_code = excluded.exit_code, signal = excluded.signal,
error = excluded.error, ended_at = excluded.ended_at, duration_ms = excluded.duration_ms, output = excluded.output,
output_start = excluded.output_start, output_bytes = excluded.output_bytes`,
output_start = excluded.output_start, output_bytes = excluded.output_bytes, terminal = excluded.terminal,
cols = excluded.cols, rows = excluded.rows, output_text = excluded.output_text`,
run.ID, run.SessionID, run.Command, run.Directory, run.Status, exit, run.Signal, run.Error,
run.StartedAt, run.EndedAt, run.DurationMS, run.Output, run.OutputStart, run.OutputBytes); err != nil {
run.StartedAt, run.EndedAt, run.DurationMS, run.Output, run.OutputStart, run.OutputBytes,
run.Terminal, run.Cols, run.Rows, run.Text); err != nil {
return err
}
if keep > 0 {
@@ -104,13 +122,14 @@ duration_ms = CASE WHEN ? > started_at THEN ? - started_at ELSE 0 END WHERE stat
return result.RowsAffected()
}
const chatShellRunSelect = `SELECT id, session_id, command, directory, status, exit_code, signal, error, started_at, ended_at, duration_ms, output, output_start, output_bytes FROM chat_shell_runs`
const chatShellRunSelect = `SELECT id, session_id, command, directory, status, exit_code, signal, error, started_at, ended_at, duration_ms, output, output_start, output_bytes, terminal, cols, rows, output_text FROM chat_shell_runs`
func scanChatShellRun(row chatQueueScanner) (protocol.ChatShellRunRecord, error) {
var run protocol.ChatShellRunRecord
var exit sql.NullInt64
err := row.Scan(&run.ID, &run.SessionID, &run.Command, &run.Directory, &run.Status, &exit, &run.Signal, &run.Error,
&run.StartedAt, &run.EndedAt, &run.DurationMS, &run.Output, &run.OutputStart, &run.OutputBytes)
&run.StartedAt, &run.EndedAt, &run.DurationMS, &run.Output, &run.OutputStart, &run.OutputBytes,
&run.Terminal, &run.Cols, &run.Rows, &run.Text)
if err != nil {
return protocol.ChatShellRunRecord{}, err
}