Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ci-baseline.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "./ci-baseline.schema.json",
"policy": "ratchet: counts are upper bounds — current or lower passes; exceeding blocks push. Update via `pnpm baseline:ci` after a genuine reduction.",
"recordedAt": "2026-04-19",
"recordedAt": "2026-04-21",
"lint": {
"errors": 0,
"warnings": 247
Expand All @@ -10,8 +10,8 @@
"errors": 0
},
"test": {
"failedFiles": 1,
"failedTests": 1,
"failedFiles": 0,
"failedTests": 0,
"runtimeErrors": 0
}
}
43 changes: 24 additions & 19 deletions src/interactive-os/engine/shallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,36 @@
*
* Supports plain objects, arrays, `Map`, and `Set`. Matches Zustand semantics.
*/
export function shallow<T>(a: T, b: T): boolean {
if (Object.is(a, b)) return true
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false

if (a instanceof Map && b instanceof Map) {
if (a.size !== b.size) return false
for (const [k, v] of a) {
if (!b.has(k) || !Object.is(v, b.get(k))) return false
}
return true
function shallowMap(a: Map<unknown, unknown>, b: Map<unknown, unknown>): boolean {
if (a.size !== b.size) return false
for (const [k, v] of a) {
if (!b.has(k) || !Object.is(v, b.get(k))) return false
}
if (a instanceof Set && b instanceof Set) {
if (a.size !== b.size) return false
for (const v of a) {
if (!b.has(v)) return false
}
return true
return true
}

function shallowSet(a: Set<unknown>, b: Set<unknown>): boolean {
if (a.size !== b.size) return false
for (const v of a) {
if (!b.has(v)) return false
}
return true
}

const keysA = Object.keys(a as object)
const keysB = Object.keys(b as object)
if (keysA.length !== keysB.length) return false
function shallowObject(a: object, b: object): boolean {
const keysA = Object.keys(a)
if (keysA.length !== Object.keys(b).length) return false
for (const key of keysA) {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false
if (!Object.is((a as Record<string, unknown>)[key], (b as Record<string, unknown>)[key])) return false
}
return true
}

export function shallow<T>(a: T, b: T): boolean {
if (Object.is(a, b)) return true
if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) return false
if (a instanceof Map && b instanceof Map) return shallowMap(a, b)
if (a instanceof Set && b instanceof Set) return shallowSet(a, b)
return shallowObject(a as object, b as object)
}
Loading