Skip to content

Commit b179ccf

Browse files
bwlclaude
andcommitted
Fix document reconstruction in node read command
When reading a chunk node or document root, the system now automatically reconstructs the full document from all chunks and displays it seamlessly. Changes: - Import reconstructDocument from reconstruction module - Call reconstructDocument() before displaying node content - Show "[Document with N chunks - automatically reconstructed]" header - Display full reconstructed body instead of individual chunk - List all chunk IDs at bottom for reference - Handle both JSON and text output modes This completes the invisible chunking UX - users never see individual chunks, only complete documents. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent c568989 commit b179ccf

1 file changed

Lines changed: 73 additions & 20 deletions

File tree

src/cli/commands/node.ts

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { COMMAND_TLDR, emitTldrAndExit } from '../tldr';
1818
import { synthesizeNodesCore, SynthesisModel, ReasoningEffort, TextVerbosity } from '../../core/synthesize';
1919
import { createNodeCore } from '../../core/nodes';
2020
import { importDocumentCore } from '../../core/import';
21+
import { reconstructDocument } from '../../lib/reconstruction';
2122

2223
import type { HandlerContext } from '@clerc/core';
2324

@@ -457,32 +458,84 @@ async function runNodeRead(idRef: string | undefined, flags: NodeReadFlags) {
457458
return;
458459
}
459460

461+
// Check if this node is part of a chunked document
462+
const reconstructed = await reconstructDocument(node);
463+
460464
if (flags.json) {
461-
console.log(
462-
JSON.stringify(
463-
{
464-
node: {
465-
id: node.id,
466-
title: node.title,
467-
tags: node.tags,
468-
createdAt: node.createdAt,
469-
updatedAt: node.updatedAt,
465+
if (reconstructed) {
466+
// For reconstructed documents, return full document in JSON
467+
console.log(
468+
JSON.stringify(
469+
{
470+
node: {
471+
id: reconstructed.rootNode.id,
472+
title: reconstructed.rootNode.title,
473+
tags: reconstructed.rootNode.tags,
474+
createdAt: reconstructed.rootNode.createdAt,
475+
updatedAt: reconstructed.rootNode.updatedAt,
476+
},
477+
body: reconstructed.fullBody,
478+
metadata: {
479+
isReconstructed: true,
480+
totalChunks: reconstructed.metadata.totalChunks,
481+
chunks: reconstructed.chunks.map((c) => ({
482+
id: c.id,
483+
title: c.title,
484+
order: c.chunkOrder,
485+
})),
486+
},
470487
},
471-
body: node.body,
472-
},
473-
null,
474-
2,
475-
),
476-
);
488+
null,
489+
2,
490+
),
491+
);
492+
} else {
493+
// Regular node output
494+
console.log(
495+
JSON.stringify(
496+
{
497+
node: {
498+
id: node.id,
499+
title: node.title,
500+
tags: node.tags,
501+
createdAt: node.createdAt,
502+
updatedAt: node.updatedAt,
503+
},
504+
body: node.body,
505+
},
506+
null,
507+
2,
508+
),
509+
);
510+
}
477511
return;
478512
}
479513

480-
const { directEdges } = await buildNeighborhoodPayload(node.id, 1, DEFAULT_NEIGHBORHOOD_LIMIT);
481-
printNodeOverview(node, directEdges, { longIds: Boolean(flags.longIds) });
514+
// Text output
515+
if (reconstructed) {
516+
// Use the root node for overview
517+
const displayNode = reconstructed.rootNode;
518+
const { directEdges } = await buildNeighborhoodPayload(displayNode.id, 1, DEFAULT_NEIGHBORHOOD_LIMIT);
519+
printNodeOverview(displayNode, directEdges, { longIds: Boolean(flags.longIds) });
520+
521+
if (!flags.meta) {
522+
console.log('');
523+
console.log(`[Document with ${reconstructed.metadata.totalChunks} chunks - automatically reconstructed]`);
524+
console.log('');
525+
console.log(reconstructed.fullBody);
526+
console.log('');
527+
console.log('---');
528+
console.log(`Chunks: ${reconstructed.chunks.map((c) => formatId(c.id)).join(', ')}`);
529+
}
530+
} else {
531+
// Regular node output
532+
const { directEdges } = await buildNeighborhoodPayload(node.id, 1, DEFAULT_NEIGHBORHOOD_LIMIT);
533+
printNodeOverview(node, directEdges, { longIds: Boolean(flags.longIds) });
482534

483-
if (!flags.meta) {
484-
console.log('');
485-
console.log(node.body);
535+
if (!flags.meta) {
536+
console.log('');
537+
console.log(node.body);
538+
}
486539
}
487540
}
488541

0 commit comments

Comments
 (0)