Skip to content

Commit 40ad671

Browse files
committed
fix: avoid static memory method bindings
1 parent 6e2b916 commit 40ad671

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

inc/Workspace/WorktreeContextInjector.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,16 +834,24 @@ public static function build_payload(): ?array {
834834
$user_id = $dm->get_effective_user_id( 0 );
835835
$agent_slug = $dm->resolve_agent_slug( array( 'user_id' => $user_id ) );
836836

837-
$files = array();
837+
$files = array();
838+
$memory_class = '\\DataMachine\\Core\\FilesRepository\\AgentMemory';
838839
foreach ( self::MEMORY_FILES as $filename ) {
839-
$memory = new \DataMachine\Core\FilesRepository\AgentMemory( $user_id, 0, $filename );
840-
$file_path = $memory->get_file_path();
841-
if ( is_readable( $file_path ) ) {
842-
$content = file_get_contents( $file_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- AgentMemory returns a validated local file path, not a remote URL.
843-
if ( is_string( $content ) && '' !== trim( $content ) ) {
844-
$files[ $filename ] = $content;
840+
$memory = new $memory_class( $user_id, 0, $filename );
841+
$content = null;
842+
if ( is_callable( array( $memory, 'get_all' ) ) ) {
843+
$result = call_user_func( array( $memory, 'get_all' ) );
844+
$content = is_array( $result ) && ! empty( $result['success'] ) && is_string( $result['content'] ?? null ) ? $result['content'] : null;
845+
} elseif ( is_callable( array( $memory, 'get_file_path' ) ) ) {
846+
$file_path = call_user_func( array( $memory, 'get_file_path' ) );
847+
if ( is_string( $file_path ) && is_readable( $file_path ) ) {
848+
$content = file_get_contents( $file_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- AgentMemory returns a validated local file path, not a remote URL.
845849
}
846850
}
851+
852+
if ( is_string( $content ) && '' !== trim( $content ) ) {
853+
$files[ $filename ] = $content;
854+
}
847855
}
848856

849857
$abspath = defined( 'ABSPATH' ) ? rtrim( ABSPATH, '/' ) : '';

0 commit comments

Comments
 (0)