Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion atomic-agent/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ pub struct TurnEvent {
#[serde(default, skip_serializing_if = "Option::is_none")]
pub tool_use_id: Option<String>,

/// When this event occurred.
/// Source event time, normalized to UTC without discarding subsecond precision.
/// Hook adapters use receipt time only when the source timestamp is absent/null.
pub timestamp: DateTime<Utc>,

/// The raw JSON input from the agent hook, preserved for debugging.
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/agy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ use serde_json::Value;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

// Constants

Expand Down Expand Up @@ -244,6 +244,8 @@ impl AgentHook for AgyHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::TurnStart => {
// Antigravity: PreInvocation → TurnStart
Expand Down Expand Up @@ -318,6 +320,7 @@ impl AgentHook for AgyHook {
reason: format!("hook type {:?} is not supported by agy", hook_type),
}),
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/claude_code/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

// ============================================================================
// CLAUDE CODE JSON INPUT TYPES
Expand Down Expand Up @@ -115,6 +115,8 @@ pub(super) fn parse_hook_event(
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(agent_name, hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => parse_session_start(agent_name, hook_type, raw_json),
HookType::SessionEnd | HookType::TurnEnd => {
Expand All @@ -124,6 +126,7 @@ pub(super) fn parse_hook_event(
HookType::PreToolUse => parse_pre_tool(agent_name, hook_type, raw_json),
HookType::PostToolUse => parse_post_tool(agent_name, hook_type, raw_json),
}
.map(|event| event.with_timestamp(timestamp))
}

/// Extract the session_id from parsed input, returning a default if missing.
Expand Down
7 changes: 6 additions & 1 deletion atomic-agent/src/hooks/cline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

// =============================================================================
// Constants
Expand Down Expand Up @@ -145,6 +145,7 @@ struct ClineInput {
hook_name: Option<String>,
#[serde(default, alias = "clineVersion")]
cline_version: Option<String>,
/// Decimal epoch milliseconds (`Date.now().toString()` in Cline's hook factory).
#[serde(default)]
timestamp: Option<String>,
#[serde(default, alias = "workspaceRoots")]
Expand Down Expand Up @@ -245,6 +246,9 @@ impl AgentHook for ClineHook {
reason: e.to_string(),
})?;

let timestamp =
TimestampFormat::UnixMillisString.parse(self.name(), hook_type, &raw_json)?;

let parsed: ClineInput =
serde_json::from_value(raw_json.clone()).map_err(|e| AgentError::HookParseFailed {
agent: self.name().to_string(),
Expand Down Expand Up @@ -416,6 +420,7 @@ impl AgentHook for ClineHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
4 changes: 3 additions & 1 deletion atomic-agent/src/hooks/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use serde_json::{Map, Value};
use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};

use super::AgentHook;
use super::{timestamp::TimestampFormat, AgentHook};

const CODEX_DIR: &str = ".codex";
const HOOKS_FILE: &str = "hooks.json";
Expand Down Expand Up @@ -222,6 +222,7 @@ impl AgentHook for CodexHook {

fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
let raw_json = self.parse_json(hook_type, input)?;
let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => {
Expand Down Expand Up @@ -306,6 +307,7 @@ impl AgentHook for CodexHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, repo_root: &Path) -> AgentResult<usize> {
Expand Down
25 changes: 9 additions & 16 deletions atomic-agent/src/hooks/copilot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,18 @@
//! | Command key | `command` | `bash` / `powershell` |
//! | TurnEnd / Stop | `Stop` event | No `stop` event |
//! | JSON fields | snake_case | camelCase with snake aliases |
//!
//! Source timestamps are integer epoch milliseconds in camelCase hook payloads
//! and RFC-3339 strings in VS Code-compatible payloads. See
//! <https://docs.github.com/en/copilot/reference/hooks-configuration#hook-event-input-payloads>.

use std::path::Path;

use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

// =============================================================================
// Constants
Expand All @@ -87,9 +91,6 @@ const GITHUB_DIR: &str = ".github";
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct SessionStartInput {
#[serde(default)]
timestamp: Option<u64>,

#[serde(default)]
cwd: Option<String>,

Expand All @@ -106,9 +107,6 @@ struct SessionStartInput {
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct SessionEndInput {
#[serde(default)]
timestamp: Option<u64>,

#[serde(default)]
cwd: Option<String>,

Expand All @@ -128,9 +126,6 @@ struct SessionEndInput {
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct UserPromptInput {
#[serde(default)]
timestamp: Option<u64>,

#[serde(default)]
cwd: Option<String>,

Expand All @@ -150,9 +145,6 @@ struct UserPromptInput {
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct PreToolUseInput {
#[serde(default)]
timestamp: Option<u64>,

#[serde(default)]
cwd: Option<String>,

Expand All @@ -178,9 +170,6 @@ struct PreToolUseInput {
#[derive(Debug, Deserialize)]
#[allow(dead_code)]
struct PostToolUseInput {
#[serde(default)]
timestamp: Option<u64>,

#[serde(default)]
cwd: Option<String>,

Expand Down Expand Up @@ -278,6 +267,9 @@ impl AgentHook for CopilotHook {
reason: e.to_string(),
})?;

let timestamp =
TimestampFormat::Rfc3339OrUnixMillis.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => {
let parsed: SessionStartInput =
Expand Down Expand Up @@ -408,6 +400,7 @@ impl AgentHook for CopilotHook {
.to_string(),
}),
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

/// The Cursor config directory name.
const CURSOR_DIR: &str = ".cursor";
Expand Down Expand Up @@ -410,6 +410,8 @@ impl AgentHook for CursorHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => {
let parsed: SessionStartInput =
Expand Down Expand Up @@ -702,6 +704,7 @@ impl AgentHook for CursorHook {
}
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/devin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

/// The Devin Desktop config directory name.
const DEVIN_DIR: &str = ".devin";
Expand Down Expand Up @@ -222,6 +222,8 @@ impl AgentHook for DevinHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => {
let parsed: SessionStartInput =
Expand Down Expand Up @@ -348,6 +350,7 @@ impl AgentHook for DevinHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/gemini_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use serde::{Deserialize, Serialize};

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

// Constants

Expand Down Expand Up @@ -513,6 +513,8 @@ impl AgentHook for GeminiCliHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::SessionStart => {
let parsed: SessionStartInput =
Expand Down Expand Up @@ -662,6 +664,7 @@ impl AgentHook for GeminiCliHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 3 additions & 2 deletions atomic-agent/src/hooks/grok.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use serde_json::Value;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

/// User-level Grok config directory name under `$HOME`.
const GROK_DIR: &str = ".grok";
Expand Down Expand Up @@ -170,6 +170,7 @@ impl AgentHook for GrokHook {

fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
let raw_json = self.parse_json(hook_type, input)?;
let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
let parsed = self.parse_common(hook_type, raw_json.clone())?;

let mut raw_json = with_xai_provider(raw_json);
Expand Down Expand Up @@ -220,7 +221,7 @@ impl AgentHook for GrokHook {
HookType::SessionStart | HookType::SessionEnd | HookType::TurnEnd => {}
}

Ok(event)
Ok(event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 3 additions & 2 deletions atomic-agent/src/hooks/hermes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use serde_json::Value;
use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};

use super::AgentHook;
use super::{timestamp::TimestampFormat, AgentHook};

const HERMES_DIR: &str = ".hermes";

Expand Down Expand Up @@ -108,6 +108,7 @@ impl AgentHook for HermesHook {

fn parse_event(&self, hook_type: HookType, input: &[u8]) -> AgentResult<TurnEvent> {
let raw_json = self.parse_json(hook_type, input)?;
let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;
let mut event = TurnEvent::new(Self::extract_session_id(&raw_json), hook_type)
.with_raw_json(with_hermes_provider(raw_json.clone()));

Expand All @@ -130,7 +131,7 @@ impl AgentHook for HermesHook {
}
}

Ok(event)
Ok(event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/kilo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

/// The Kilo Code config directory name.
const KILO_DIR: &str = ".kilo";
Expand Down Expand Up @@ -203,6 +203,8 @@ impl AgentHook for KiloHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::TurnStart => {
let parsed: PromptSubmitInput =
Expand Down Expand Up @@ -333,6 +335,7 @@ impl AgentHook for KiloHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
5 changes: 4 additions & 1 deletion atomic-agent/src/hooks/kiro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ use serde::Deserialize;

use crate::error::{AgentError, AgentResult};
use crate::event::{HookType, TurnEvent};
use crate::hooks::AgentHook;
use crate::hooks::{timestamp::TimestampFormat, AgentHook};

/// The Kiro config directory name.
const KIRO_DIR: &str = ".kiro";
Expand Down Expand Up @@ -232,6 +232,8 @@ impl AgentHook for KiroHook {
reason: e.to_string(),
})?;

let timestamp = TimestampFormat::Rfc3339.parse(self.name(), hook_type, &raw_json)?;

match hook_type {
HookType::TurnStart => {
let parsed: PromptSubmitInput =
Expand Down Expand Up @@ -363,6 +365,7 @@ impl AgentHook for KiroHook {
Ok(event)
}
}
.map(|event| event.with_timestamp(timestamp))
}

fn install(&self, _repo_root: &Path) -> AgentResult<usize> {
Expand Down
Loading
Loading