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
4 changes: 2 additions & 2 deletions inc/Abilities/AgentAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ public static function getAgent( array $input ): array {
'owner_id' => (int) $agent['owner_id'],
'agent_config' => is_array( $agent['agent_config'] ?? null )
? $agent['agent_config']
: ( json_decode( $agent['agent_config'] ?? '{}', true ) ?: array() ),
: ( json_decode( $agent['agent_config'] ?? '{}', true ) ? json_decode( $agent['agent_config'] ?? '{}', true ) : array() ),
'status' => (string) $agent['status'],
'created_at' => $agent['created_at'] ?? '',
'updated_at' => $agent['updated_at'] ?? '',
Expand Down Expand Up @@ -693,7 +693,7 @@ public static function deleteAgent( array $input ): array {
if ( $file->isDir() ) {
rmdir( $file->getRealPath() );
} else {
unlink( $file->getRealPath() );
wp_delete_file( $file->getRealPath( ) );
}
}
rmdir( $agent_dir );
Expand Down
12 changes: 6 additions & 6 deletions inc/Abilities/AgentMemoryAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ public static function getMemory( array $input ): array {
$user_id = (int) ( $input['user_id'] ?? 0 );
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$memory = new AgentMemory( $user_id, $agent_id );
$section = $input['section'] ?? null;
$section = $input['section'] ?? null;

if ( null === $section || '' === $section ) {
return $memory->get_all();
Expand All @@ -254,9 +254,9 @@ public static function updateMemory( array $input ): array {
$user_id = (int) ( $input['user_id'] ?? 0 );
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$memory = new AgentMemory( $user_id, $agent_id );
$section = $input['section'];
$content = $input['content'];
$mode = $input['mode'];
$section = $input['section'];
$content = $input['content'];
$mode = $input['mode'];

if ( 'append' === $mode ) {
return $memory->append_to_section( $section, $content );
Expand All @@ -275,8 +275,8 @@ public static function searchMemory( array $input ): array {
$user_id = (int) ( $input['user_id'] ?? 0 );
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$memory = new AgentMemory( $user_id, $agent_id );
$query = $input['query'];
$section = $input['section'] ?? null;
$query = $input['query'];
$section = $input['section'] ?? null;

return $memory->search( $query, $section );
}
Expand Down
10 changes: 5 additions & 5 deletions inc/Abilities/Chat/CreateChatSessionAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ private function registerAbility(): void {
'input_schema' => array(
'type' => 'object',
'properties' => array(
'user_id' => array(
'user_id' => array(
'type' => 'integer',
'description' => __( 'User ID who owns the session.', 'data-machine' ),
),
'agent_id' => array(
'agent_id' => array(
'type' => 'integer',
'description' => __( 'First-class agent ID for this session.', 'data-machine' ),
),
'context' => array(
'context' => array(
'type' => 'string',
'default' => 'chat',
'description' => __( 'Execution context (chat, pipeline, system).', 'data-machine' ),
),
'source' => array(
'source' => array(
'type' => 'string',
'description' => __( 'Session source identifier (e.g. ping, chat).', 'data-machine' ),
),
'metadata' => array(
'metadata' => array(
'type' => 'object',
'description' => __( 'Additional metadata for the session.', 'data-machine' ),
),
Expand Down
36 changes: 18 additions & 18 deletions inc/Abilities/Chat/ListChatSessionsAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ private function registerAbility(): void {
'input_schema' => array(
'type' => 'object',
'properties' => array(
'user_id' => array(
'user_id' => array(
'type' => 'integer',
'description' => __( 'User ID to list sessions for.', 'data-machine' ),
),
'agent_id' => array(
'agent_id' => array(
'type' => array( 'integer', 'null' ),
'description' => __( 'Agent ID to filter sessions by. Null or omitted returns all agents.', 'data-machine' ),
),
'limit' => array(
'limit' => array(
'type' => 'integer',
'default' => 20,
'description' => __( 'Maximum sessions to return (1-100).', 'data-machine' ),
),
'offset' => array(
'offset' => array(
'type' => 'integer',
'default' => 0,
'description' => __( 'Pagination offset.', 'data-machine' ),
),
'context' => array(
'context' => array(
'type' => 'string',
'description' => __( 'Context filter (chat, pipeline, system).', 'data-machine' ),
),
Expand All @@ -68,16 +68,16 @@ private function registerAbility(): void {
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'sessions' => array(
'success' => array( 'type' => 'boolean' ),
'sessions' => array(
'type' => 'array',
'items' => array( 'type' => 'object' ),
),
'total' => array( 'type' => 'integer' ),
'limit' => array( 'type' => 'integer' ),
'offset' => array( 'type' => 'integer' ),
'context' => array( 'type' => 'string' ),
'error' => array( 'type' => 'string' ),
'total' => array( 'type' => 'integer' ),
'limit' => array( 'type' => 'integer' ),
'offset' => array( 'type' => 'integer' ),
'context' => array( 'type' => 'string' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( $this, 'execute' ),
Expand Down Expand Up @@ -132,12 +132,12 @@ public function execute( array $input ): array {
$total = $this->chat_db->get_user_session_count( $user_id, $context, $agent_id );

return array(
'success' => true,
'sessions' => $sessions,
'total' => $total,
'limit' => $limit,
'offset' => $offset,
'context' => $context,
'success' => true,
'sessions' => $sessions,
'total' => $total,
'limit' => $limit,
'offset' => $offset,
'context' => $context,
);
}
}
12 changes: 6 additions & 6 deletions inc/Abilities/DailyMemoryAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public static function readDaily( array $input ): array {
$user_id = (int) ( $input['user_id'] ?? 0 );
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$daily = new DailyMemory( $user_id, $agent_id );
$date = $input['date'] ?? gmdate( 'Y-m-d' );
$date = $input['date'] ?? gmdate( 'Y-m-d' );

$parts = DailyMemory::parse_date( $date );
if ( ! $parts ) {
Expand Down Expand Up @@ -284,8 +284,8 @@ public static function writeDaily( array $input ): array {
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$daily = new DailyMemory( $user_id, $agent_id );
$content = $input['content'];
$date = $input['date'] ?? gmdate( 'Y-m-d' );
$mode = $input['mode'] ?? 'append';
$date = $input['date'] ?? gmdate( 'Y-m-d' );
$mode = $input['mode'] ?? 'append';

$parts = DailyMemory::parse_date( $date );
if ( ! $parts ) {
Expand Down Expand Up @@ -325,9 +325,9 @@ public static function searchDaily( array $input ): array {
$user_id = (int) ( $input['user_id'] ?? 0 );
$agent_id = (int) ( $input['agent_id'] ?? 0 );
$daily = new DailyMemory( $user_id, $agent_id );
$query = $input['query'];
$from = $input['from'] ?? null;
$to = $input['to'] ?? null;
$query = $input['query'];
$from = $input['from'] ?? null;
$to = $input['to'] ?? null;

return $daily->search( $query, $from, $to );
}
Expand Down
20 changes: 10 additions & 10 deletions inc/Abilities/DuplicateCheck/DuplicateCheckAbility.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,36 @@ private function registerCheckDuplicate(): void {
'type' => 'object',
'required' => array( 'title' ),
'properties' => array(
'title' => array(
'title' => array(
'type' => 'string',
'description' => __( 'Title or topic to check for duplicates', 'data-machine' ),
),
'post_type' => array(
'post_type' => array(
'type' => 'string',
'description' => __( 'WordPress post type to check against (default: "post")', 'data-machine' ),
),
'lookback_days' => array(
'lookback_days' => array(
'type' => 'integer',
'description' => __( 'How many days back to search (default: 14)', 'data-machine' ),
),
'scope' => array(
'scope' => array(
'type' => 'string',
'enum' => array( 'published', 'queue', 'both' ),
'description' => __( 'What to check: published posts, queue items, or both (default: "published")', 'data-machine' ),
),
'flow_id' => array(
'flow_id' => array(
'type' => 'integer',
'description' => __( 'Flow ID for queue check (required when scope includes queue)', 'data-machine' ),
),
'flow_step_id' => array(
'flow_step_id' => array(
'type' => 'string',
'description' => __( 'Flow step ID for queue check (required when scope includes queue)', 'data-machine' ),
),
'threshold' => array(
'threshold' => array(
'type' => 'number',
'description' => __( 'Jaccard similarity threshold for queue checks (default: 0.65)', 'data-machine' ),
),
'context' => array(
'context' => array(
'type' => 'object',
'description' => __( 'Domain-specific context for extension strategies (e.g., venue, startDate, ticketUrl for events)', 'data-machine' ),
),
Expand Down Expand Up @@ -478,8 +478,8 @@ private function checkQueueItems( string $title, float $threshold, int $flow_id,
'info',
'DuplicateCheck: found matching queue item',
array(
'title' => $title,
'match' => $best_match,
'title' => $title,
'match' => $best_match,
)
);

Expand Down
18 changes: 9 additions & 9 deletions inc/Abilities/InternalLinkingAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -1104,15 +1104,15 @@ private static function buildLinkGraph( string $post_type, string $category, arr
$inbound_total = array_sum( $inbound );

return array(
'success' => true,
'post_type' => $post_type,
'total_scanned' => $total_scanned,
'total_links' => $total_links,
'orphaned_count' => count( $orphaned ),
'avg_outbound' => $total_scanned > 0 ? round( $outbound_total / $total_scanned, 2 ) : 0,
'avg_inbound' => $total_scanned > 0 ? round( $inbound_total / $total_scanned, 2 ) : 0,
'orphaned_posts' => $orphaned,
'top_linked' => $top_linked,
'success' => true,
'post_type' => $post_type,
'total_scanned' => $total_scanned,
'total_links' => $total_links,
'orphaned_count' => count( $orphaned ),
'avg_outbound' => $total_scanned > 0 ? round( $outbound_total / $total_scanned, 2 ) : 0,
'avg_inbound' => $total_scanned > 0 ? round( $inbound_total / $total_scanned, 2 ) : 0,
'orphaned_posts' => $orphaned,
'top_linked' => $top_linked,
// Internal data for broken link checker (not exposed in REST).
'_all_links' => $all_links,
'_all_external_links' => $all_external_links,
Expand Down
60 changes: 30 additions & 30 deletions inc/Abilities/LogAbilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,14 @@ private function registerAbilities(): void {
'output_schema' => array(
'type' => 'object',
'properties' => array(
'success' => array( 'type' => 'boolean' ),
'file' => array( 'type' => 'string' ),
'entries' => array( 'type' => 'array' ),
'total' => array( 'type' => 'integer' ),
'filtered' => array( 'type' => 'integer' ),
'file_size' => array( 'type' => 'integer' ),
'success' => array( 'type' => 'boolean' ),
'file' => array( 'type' => 'string' ),
'entries' => array( 'type' => 'array' ),
'total' => array( 'type' => 'integer' ),
'filtered' => array( 'type' => 'integer' ),
'file_size' => array( 'type' => 'integer' ),
'last_modified' => array( 'type' => 'string' ),
'error' => array( 'type' => 'string' ),
'error' => array( 'type' => 'string' ),
),
),
'execute_callback' => array( self::class, 'readDebugLog' ),
Expand Down Expand Up @@ -471,7 +471,7 @@ public static function readDebugLog( array $input ): array {
// Filter by search.
if ( $search ) {
$search_lower = strtolower( $search );
$parsed = array_filter( $parsed, function ( $entry ) use ( $search_lower ) {
$parsed = array_filter( $parsed, function ( $entry ) use ( $search_lower ) {
return str_contains( strtolower( $entry['message'] ), $search_lower )
|| str_contains( strtolower( $entry['file'] ?? '' ), $search_lower );
});
Expand Down Expand Up @@ -517,7 +517,7 @@ private static function tailDebugLog( string $file, int $lines ): array {
$line_buffer = '';

while ( $pos > 0 && count( $found_lines ) < $lines ) {
$pos--;
--$pos;
fseek( $handle, $pos, SEEK_SET );
$char = fgetc( $handle );

Expand Down Expand Up @@ -569,13 +569,13 @@ private static function parseDebugLogLine( string $line ): ?array {
$message_part = $matches[3];

// Parse timestamp (WordPress format: 01-Jan-2026 12:34:56+00:00).
$timestamp = strtotime( $timestamp_str ) ?: 0;
$timestamp = strtotime( $timestamp_str ) ? strtotime( $timestamp_str ) : 0;

// Extract file and line from message if present.
$file = null;
$file = null;
$line_number = null;
if ( preg_match( '/in\s+(.+\.php)(?:\s+on\s+line\s+(\d+))?$/i', $message_part, $file_matches ) ) {
$file = $file_matches[1];
$file = $file_matches[1];
$line_number = isset( $file_matches[2] ) ? (int) $file_matches[2] : null;
// Remove file/line from message for cleaner output.
$message_part = trim( preg_replace( '/\s*in\s+.+\.php(?:\s+on\s+line\s+\d+)?$/i', '', $message_part ) );
Expand Down Expand Up @@ -630,24 +630,24 @@ private static function normalizeLogLevel( string $level ): string {
$level = strtoupper( trim( $level ) );

$map = array(
'FATAL ERROR' => 'FATAL',
'FATAL' => 'FATAL',
'ERROR' => 'ERROR',
'WARNING' => 'WARNING',
'PARSE ERROR' => 'PARSE',
'PARSE' => 'PARSE',
'NOTICE' => 'NOTICE',
'STRICT' => 'NOTICE',
'DEPRECATED' => 'DEPRECATED',
'CORE ERROR' => 'FATAL',
'CORE WARNING' => 'WARNING',
'COMPILE ERROR' => 'FATAL',
'COMPILE WARNING' => 'WARNING',
'USER ERROR' => 'ERROR',
'USER WARNING' => 'WARNING',
'USER NOTICE' => 'NOTICE',
'USER DEPRECATED' => 'DEPRECATED',
'RECOVERABLE ERROR' => 'ERROR',
'FATAL ERROR' => 'FATAL',
'FATAL' => 'FATAL',
'ERROR' => 'ERROR',
'WARNING' => 'WARNING',
'PARSE ERROR' => 'PARSE',
'PARSE' => 'PARSE',
'NOTICE' => 'NOTICE',
'STRICT' => 'NOTICE',
'DEPRECATED' => 'DEPRECATED',
'CORE ERROR' => 'FATAL',
'CORE WARNING' => 'WARNING',
'COMPILE ERROR' => 'FATAL',
'COMPILE WARNING' => 'WARNING',
'USER ERROR' => 'ERROR',
'USER WARNING' => 'WARNING',
'USER NOTICE' => 'NOTICE',
'USER DEPRECATED' => 'DEPRECATED',
'RECOVERABLE ERROR' => 'ERROR',
'CATCHABLE FATAL ERROR' => 'ERROR',
);

Expand Down
Loading
Loading