refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조

에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Antigravity Agent
2026-07-11 11:05:56 +09:00
parent 6549ead309
commit c24165b8bc
6193 changed files with 1717 additions and 31 deletions
@@ -0,0 +1,102 @@
---
id: js-structured-clone
title: JS Structured Clone & Deep Equality 함정
category: Coding
status: draft
source_trust_level: B
verification_status: conceptual
created_at: 2026-05-09
updated_at: 2026-05-09
tags: [javascript, deep-clone, structured-clone, vibe-coding]
tech_stack: { language: "JavaScript / TypeScript", applicable_to: ["Web", "Node"] }
applied_in: []
aliases: [deep clone, JSON.parse hack, structuredClone, lodash isEqual]
---
# Structured Clone & Deep Equality
> `JSON.parse(JSON.stringify(x))` 가 deep clone 의 default 였던 시절은 끝. **`structuredClone()`** 가 native (Node 17+/모던 브라우저). 단 함수, DOM, class instance 일부는 여전히 못 함.
## 📖 핵심 개념
- structuredClone: HTML structured clone algorithm. 깊은 복사. circular ref OK. Map/Set/Date/RegExp/TypedArray 지원. 함수/Symbol/DOM 못 함.
- JSON 방식: 함수/undefined/Date 손실, circular 폭사. 절대 production default X.
- Lodash `_.cloneDeep`: 거의 모든 형식 지원. 외부 의존성.
## 💻 코드 패턴
### 기본 deep clone
```ts
const original = { a: 1, b: { c: [1, 2, 3] }, d: new Date() };
const clone = structuredClone(original);
clone.b.c.push(4);
// original.b.c === [1,2,3] 그대로
```
### 못 하는 것
```ts
const obj = {
fn: () => 1, // ❌ throws DataCloneError
el: document.body, // ❌ DOM
cls: new MyClass(), // ❌ class instance (plain prototype 만)
sym: Symbol('s'), // ❌
};
structuredClone(obj); // 폭사
```
### Class instance 클로닝
```ts
class User {
constructor(public name: string, public meta: object) {}
}
// structuredClone 은 prototype 잃음
const u = new User('a', { x: 1 });
const c = structuredClone(u); // c instanceof User === false
// 해결: clone 메서드 직접
class User {
clone(): User { return new User(this.name, structuredClone(this.meta)); }
}
```
### Deep equality
```ts
import { dequal } from 'dequal'; // 또는 lodash isEqual
dequal({ a: 1, b: [2] }, { a: 1, b: [2] }); // true
// Reference equality (===)는 빠르지만 객체 내부 같은지 모름
// JSON.stringify 비교는 키 순서 / NaN / Date 정확 X
```
### Circular safe stringify
```ts
import { stringify } from 'safe-stable-stringify';
// circular 있으면 [Circular] 마커
```
## 🤔 의사결정 기준
| 데이터 | 도구 |
|---|---|
| Plain object / array / Date / Map / Set | `structuredClone` |
| 함수 / DOM / class instance | 직접 clone 메서드 + structuredClone 재귀 |
| 비교 (deep eq) | `dequal` 또는 `lodash isEqual` |
| 빠른 immutability + structural sharing | Immer / immutable.js |
| 직렬화 (network, storage) | JSON or msgpack — 의도적 손실 OK |
## ❌ 안티패턴
- **JSON.parse(JSON.stringify(x))** 를 deep clone default: Date → string, undefined 손실, circular 폭사. 알면서 쓰는 경우만.
- **`Object.assign({}, x)` 으로 deep clone 기대**: shallow.
- **`{...x}` 로 deep clone 기대**: shallow.
- **가변 객체에 structuredClone 매번**: 성능. 진짜 필요할 때만 clone.
- **lodash isEqual 매 렌더**: 큰 객체 비교 비용. memo + selector.
- **NaN === NaN false 예상 못함**: deep eq 라이브러리 사용.
- **TypedArray byteOffset 바뀜**: structuredClone OK 지만 이후 backing buffer 다름.
## 🤖 LLM 활용 힌트
- "deep clone = structuredClone, deep eq = dequal" 디폴트.
- 함수 / class instance 가 있으면 명시적 clone 메서드.
## 🔗 관련 문서
- [[Defensive_Copying]]
- [[Pure_Functions_in_Practice]]