Files
start-os/sdk/base/lib/util/deepMerge.ts
Aiden McClelland f2142f0bb3 add documentation for ai agents (#3115)
* add documentation for ai agents

* docs: consolidate CLAUDE.md and CONTRIBUTING.md, add style guidelines

- Refactor CLAUDE.md to reference CONTRIBUTING.md for build/test/format info
- Expand CONTRIBUTING.md with comprehensive build targets, env vars, and testing
- Add code style guidelines section with conventional commits
- Standardize SDK prettier config to use single quotes (matching web)
- Add project-level Claude Code settings to disable co-author attribution

* style(sdk): apply prettier with single quotes

Run prettier across sdk/base and sdk/package to apply the
standardized quote style (single quotes matching web).

* docs: add USER.md for per-developer TODO filtering

- Add agents/USER.md to .gitignore (contains user identifier)
- Document session startup flow in CLAUDE.md:
  - Create USER.md if missing, prompting for identifier
  - Filter TODOs by @username tags
  - Offer relevant TODOs on session start

* docs: add i18n documentation task to agent TODOs

* docs: document i18n ID patterns in core/

Add agents/i18n-patterns.md covering rust-i18n setup, translation file
format, t!() macro usage, key naming conventions, and locale selection.
Remove completed TODO item and add reference in CLAUDE.md.

* chore: clarify that all builds work on any OS with Docker
2026-02-06 00:10:16 +01:00

88 lines
2.3 KiB
TypeScript

export function partialDiff<T>(
prev: T,
next: T,
): { diff: Partial<T> } | undefined {
if (prev === next) {
return
} else if (Array.isArray(prev) && Array.isArray(next)) {
const res = { diff: [] as any[] }
for (let newItem of next) {
let anyEq = false
for (let oldItem of prev) {
if (!partialDiff(oldItem, newItem)) {
anyEq = true
break
}
}
if (!anyEq) {
res.diff.push(newItem)
}
}
if (res.diff.length) {
return res as any
} else {
return
}
} else if (typeof prev === 'object' && typeof next === 'object') {
if (prev === null || next === null) return { diff: next }
const res = { diff: {} as Record<keyof T, any> }
const keys = Object.keys(next) as (keyof T)[]
for (let key in prev) {
if (!keys.includes(key)) keys.push(key)
}
for (let key of keys) {
const diff = partialDiff(prev[key], next[key])
if (diff) {
res.diff[key] = diff.diff
}
}
if (Object.keys(res.diff).length) {
return res
} else {
return
}
} else {
return { diff: next }
}
}
export function deepMerge(...args: unknown[]): unknown {
const lastItem = (args as any)[args.length - 1]
if (typeof lastItem !== 'object' || !lastItem) return lastItem
if (Array.isArray(lastItem))
return deepMergeList(
...(args.filter((x) => Array.isArray(x)) as unknown[][]),
)
return deepMergeObject(
...(args.filter(
(x) => typeof x === 'object' && x && !Array.isArray(x),
) as object[]),
)
}
function deepMergeList(...args: unknown[][]): unknown[] {
const res: unknown[] = []
for (let arg of args) {
for (let item of arg) {
if (!res.some((x) => !partialDiff(x, item))) {
res.push(item)
}
}
}
return res
}
function deepMergeObject(...args: object[]): object {
const lastItem = (args as any)[args.length - 1]
if (args.length === 0) return lastItem as any
if (args.length === 1) args.unshift({})
const allKeys = new Set(args.flatMap((x) => Object.keys(x)))
for (const key of allKeys) {
const filteredValues = args.flatMap((x) =>
key in x ? [(x as any)[key]] : [],
)
;(args as any)[0][key] = deepMerge(...filteredValues)
}
return args[0] as any
}