MergeSettings leaks raw __merge append annotations into settings.json when settings.system.json has no hooks key

Open Beginner friendly
#2,891 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 5 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, typescript
Domain
backend

Research direction

Read LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts, especially mergeSettings() around line 187, and reproduce the overlay-only hooks case with the provided probe. Confirm that an append annotation becomes an array when the system settings omit hooks; done when the probe exits successfully and the generated settings.json contains arrays for the hook events.

Written by the indexing model from the issue text.

Description

Version

LifeOS 8.761.0. The buggy line is present in v8.761.0 and in current main (both at line 187, checked via the GitHub API). This install now carries the fix below, so attestation reports LIFEOS/TOOLS/MergeSettings.ts as modified.

What is broken

When settings.system.json has no hooks key (as shipped) and the overlay LIFEOS/USER/CONFIG/settings.user.json writes a hook event as an append annotation ({ "__merge": "append", "values": [...] }, the form SettingsBackport.ts produces), MergeSettings.ts copies the annotation object into settings.json unchanged instead of resolving it to an array. Claude Code then rejects each such event at startup (Hook event "Stop" must be an array of matchers; received object. This entry was ignored.) and every hook under it stops running. On this install that was PostToolUse, SessionStart, Stop and UserPromptSubmit (38 matcher entries). MergeSettings.ts --check reports "no differences" in that state, because it compares the file against the same merge.

Where (file:line)

LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts:187, in mergeSettings(): the object branch requires isObjectRecord(system) && isObjectRecord(user), so an overlay-only object key falls through to cloneJsonValue(user) and nested annotations are never resolved.

Repro on a clean tree
  1. Leave settings.system.json without a hooks key (the shipped default).
  2. In LIFEOS/USER/CONFIG/settings.user.json, set "hooks": { "Stop": { "__merge": "append", "values": [ { "hooks": [ { "type": "command", "command": "true" } ] } ] } }.
  3. Run bun LIFEOS/TOOLS/MergeSettings.ts --system settings.system.json --user LIFEOS/USER/CONFIG/settings.user.json --output settings.json.
  4. hooks.Stop in settings.json is the raw annotation object, and the next Claude Code launch reports it as ignored.

Minimal probe, run next to a copy of LIFEOS/TOOLS/ (plus LIFEOS/PULSE/lib/atomic-write.ts):

import { mergeSettings } from "./LIFEOS/TOOLS/MergeSettings.ts";
const merged = mergeSettings({}, {
  hooks: { Stop: { __merge: "append", values: [{ hooks: [{ type: "command", command: "true" }] }] } },
});
const ok = Array.isArray(merged.hooks.Stop);
console.log(`hooks.Stop -> ${ok ? "array" : JSON.stringify(merged.hooks.Stop)}`);
process.exit(ok ? 0 : 1);
Negative control

Unpatched v8.761.0 file, bun probe.ts, exit 1:

hooks.Stop -> {"__merge":"append","values":[{"hooks":[{"type":"command","command":"true"}]}]}
Suggested fix

Recurse whenever the user value is an object, treating an absent system side as {}. Overlay-only keys then get the same annotation handling as shared keys, so a nested append annotation resolves through applyArrayMerge(undefined, annotation) to its values array. The patch applies cleanly to main.

diff --git a/LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts b/LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts
--- a/LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts
+++ b/LifeOS/install/LIFEOS/TOOLS/MergeSettings.ts
@@ -184,7 +184,11 @@ export function mergeSettings(system: any, user: any): any {
     );
   }
 
-  if (isObjectRecord(system) && isObjectRecord(user)) {
+  if (isObjectRecord(user)) {
+    // A user object whose system side is absent still recurses, so annotations nested under a key
+    // only the overlay defines resolve. settings.system.json omits `hooks`, and SettingsBackport
+    // writes hooks.<Event> as append annotations: cloning here leaked them raw into settings.json.
+    if (!isObjectRecord(system)) system = {};
     const merged: Record<string, any> = {};
 
     for (const key of Object.keys(system)) {
Verified after fix

Same probe, exit 0: hooks.Stop -> array. A real regeneration produces arrays for all four events.

Related: Report.ts cannot file this

This was written by hand because Tools/Report.ts could not produce it. Redact.ts swaps every configured name case-insensitively, and when the DA is named LifeOS every LifeOS/LIFEOS path, the repo name and the diff become <name>, and the send gate then refuses any body that still contains the name. Excluding the product name from the redaction list would fix it.

Environment
  • OS: macOS 27.3 (arm64)
  • Harness: claude-code
  • bun: 1.4.4
Dominant language
TypeScript
Stars
19.9k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from danielmiessler/LifeOS

All issues in danielmiessler/LifeOS

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.