Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(maker-shared): 隐式正文子节点复用前校验 kind,删除子树时清理映射
Zhang Yunjin440b5555142f
diff --git a/packages/maker-shared/src/__tests__/richAnswer.test.ts b/packages/maker-shared/src/__tests__/richAnswer.test.tsindex 0d9e966b8c..363c73e901 100644--- a/packages/maker-shared/src/__tests__/richAnswer.test.ts+++ b/packages/maker-shared/src/__tests__/richAnswer.test.ts@@ -475,6 +475,43 @@ describe('append to a container stays readable', () => {expect(doc.nodes.get('stat')?.props.text).toBeUndefined();expect(doc.issues).toBe(1);});++ // Greptile P1:删除容器后旧映射仍在,重建同名容器时同 id 可能换成别的 kind,+ // 正文会写进不渲染 props.text 的节点并且不计 issues。+ it('keeps prose out of a rebuilt container child that is not the implicit one', () => {+ const doc = new RichAnswerStream().update(+ line(1, { op: 'create', id: 'card', kind: 'stack' }) ++ line(2, { op: 'append', id: 'card', text: 'one' }) ++ line(3, { op: 'remove', id: 'card' }) ++ line(4, { op: 'create', id: 'card', kind: 'stack', props: { children: [{ kind: 'stat', props: { value: 1 } }] } }) ++ line(5, { op: 'append', id: 'card', text: 'two' }),+ );+ const children = doc.nodes.get('card')?.children ?? [];+ expect(children).toHaveLength(2);+ const stat = doc.nodes.get(children[0]);+ expect(stat?.kind).toBe('stat');+ expect(stat?.props.text).toBeUndefined();+ const body = doc.nodes.get(children[1]);+ expect(body?.kind).toBe('markdown');+ expect(body?.props.text).toBe('two');+ });++ // Greptile P2:节点数上限只在真要新建节点时才拦,追加到已有隐式子节点不受限。+ it('appends to an existing implicit child after the node limit is reached', () => {+ const head =+ line(1, { op: 'create', id: 'card', kind: 'stack' }) ++ line(2, { op: 'append', id: 'card', text: 'one' });+ const filler = Array.from({ length: 2046 }, (_, i) =>+ line(i + 3, { op: 'create', id: `n${i}`, kind: 'text', props: { text: 'x' } }),+ ).join('');+ const doc = new RichAnswerStream().update(+ head + filler + line(2049, { op: 'append', id: 'card', text: 'two' }),+ true,+ );+ expect(doc.nodes.size).toBe(2048);+ expect(doc.nodes.get('card-1')?.props.text).toBe('onetwo');+ expect(doc.issues).toBe(0);+ });});describe('inline draft limits', () => {it('caps nested inline drafts at the depth limit', () => {diff --git a/packages/maker-shared/src/richAnswer.ts b/packages/maker-shared/src/richAnswer.tsindex 65d5890c53..47adc5121c 100644--- a/packages/maker-shared/src/richAnswer.ts+++ b/packages/maker-shared/src/richAnswer.ts@@ -279,16 +279,17 @@ export class RichAnswerStream {// appends onto stack/details lost their whole body). Containers render// no text, so the prose lands in one implicit markdown child per// container instead of being dropped, like the #7627 salvages.- if (this.nodes.size >= MAX_NODES || this.depth(current.id) >= MAX_DEPTH)- throw Error("depth");const existing = this.implicitText.get(current.id);+ const child = existing ? this.nodes.get(existing) : undefined;+ // Reuse only the implicit markdown child this container owns: a+ // rebuilt container may already hold a different node under the same+ // id, and prose written into e.g. a stat would never be displayed.if (- existing &&- this.nodes.has(existing) &&- current.children.includes(existing)+ child &&+ child.kind === "markdown" &&+ current.children.includes(existing!)) {- const child = this.nodes.get(existing)!;- this.nodes.set(existing, {+ this.nodes.set(child.id, {...child,props: {...child.props,@@ -296,6 +297,13 @@ export class RichAnswerStream {},});} else {+ // Only creating a node is bounded by the node and depth limits;+ // appending to an existing child needs neither.+ if (+ this.nodes.size >= MAX_NODES ||+ this.depth(current.id) >= MAX_DEPTH+ )+ throw Error("depth");const id = this.inlineChildId(current.id, 1);this.nodes.set(id, {id,@@ -321,8 +329,12 @@ export class RichAnswerStream {const remove = (id: string) => {this.nodes.get(id)?.children.forEach(remove);this.nodes.delete(id);+ // The subtree is gone; its implicit-text mapping must not be reused.+ this.implicitText.delete(id);};remove(current.id);+ for (const [container, child] of this.implicitText)+ if (!this.nodes.has(child)) this.implicitText.delete(container);this.roots = this.roots.filter((id) => id !== current.id);for (const [id, node] of this.nodes)if (node.children.includes(current.id))