From b170094a996f3abe88c1bab2fb43f814223fda34 Mon Sep 17 00:00:00 2001 From: Rin Date: Sun, 8 Feb 2026 19:19:50 +0800 Subject: [PATCH] fix(minecraft): add toJSON/inspect.custom serialization to query chains for cleaner REPL output --- .../src/cognitive/conscious/query-dsl.ts | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/services/minecraft/src/cognitive/conscious/query-dsl.ts b/services/minecraft/src/cognitive/conscious/query-dsl.ts index 927ca14d1..0a155f754 100644 --- a/services/minecraft/src/cognitive/conscious/query-dsl.ts +++ b/services/minecraft/src/cognitive/conscious/query-dsl.ts @@ -3,6 +3,8 @@ import type { Item } from 'prismarine-item' import type { Mineflayer } from '../../libs/mineflayer' +import { inspect } from 'node:util' + import { Vec3 } from 'vec3' import { computeNearbyPlayerGaze } from '../perception/gaze' @@ -90,6 +92,23 @@ class BlockQueryChain { private readonly state: BlockQueryState = { range: 16, limit: 200, predicates: [] }, ) {} + private summarize() { + return { + type: 'BlockQueryChain', + range: this.state.range, + limit: this.state.limit, + predicates: this.state.predicates.length, + } + } + + public toJSON() { + return this.summarize() + } + + public [inspect.custom]() { + return this.summarize() + } + public within(range: number): BlockQueryChain { return this.clone({ range: clamp(Math.floor(range), 1, 64) }) } @@ -150,6 +169,23 @@ class EntityQueryChain { private readonly state: EntityQueryState = { range: 16, limit: 200, predicates: [] }, ) {} + private summarize() { + return { + type: 'EntityQueryChain', + range: this.state.range, + limit: this.state.limit, + predicates: this.state.predicates.length, + } + } + + public toJSON() { + return this.summarize() + } + + public [inspect.custom]() { + return this.summarize() + } + public within(range: number): EntityQueryChain { return this.clone({ range: clamp(Math.floor(range), 1, 128) }) } @@ -198,6 +234,21 @@ class InventoryQueryChain { private readonly state: InventoryQueryState = { predicates: [] }, ) {} + private summarize() { + return { + type: 'InventoryQueryChain', + predicates: this.state.predicates.length, + } + } + + public toJSON() { + return this.summarize() + } + + public [inspect.custom]() { + return this.summarize() + } + public whereName(nameOrNames: string | string[]): InventoryQueryChain { const names = new Set((Array.isArray(nameOrNames) ? nameOrNames : [nameOrNames]).map(name => name.toLowerCase())) return this.clone({