feat(settings): profiles write path + Test Connection (#136)
Profiles S3 over the S2 shell: every Settings change now persists. Model/effort writes ride the engine's own CLI — `hermes -p <profile> config set/unset` for model.provider / model.default / model.reasoning_effort / model.base_url (zai endpoint family written LAST: setting model.provider clears a stale base_url, live-probed; unset-when-absent is idempotent success). Provider keys upsert VAR=value into ALL THREE profiles' .env — a key entered before any surface is on its provider still persists and pre-lands for any later switch (maintainer ruling 2026-10-28; no switch re-fire). 0600, foreign lines preserved byte-for-byte, line-broken values refused at the shared sink (env-file injection guard), NSLock serializes the read-upsert-write across concurrent provider writes. Hydration reads model blocks and keys back at pane open — a restart neither blanks the key fields nor refuses Test Connection; an edit made mid-read owns the truth (no stomp), and a custom z.ai base_url seeds the endpoint field instead of being clobbered to a family default. Per-target writes coalesce AND chain past the debounce guard: cancellation can't stop a past-the-guard CLI write, so the newer write queues — the last edit is always the last write to land (finish-audit race fix, pinned). Test Connection = two-step probe (GET /models, then a minimal streaming chat) with honest decode per the factsheet: zai 1113 → wrong key type, 401s → auth failed (Anthropic request_id), finish=length → starved, empty 200 → request failed, errors riding a 2xx decoded as the provider error. Live-probed wire corrections (dogfood, 2026-10-28): Content-Type application/json on every request — URLSession defaults to form-urlencoded and providers diverge (zai 200+envelope, OpenAI 400, Anthropic tolerates); OpenAI speaks the Responses API (/responses, input + max_output_tokens, flagship gpt-6.1-sol); probe token cap 512 (64 starved reasoning models into "no content"); OpenAI's "error": null event snapshots don't decode as failures. Finish-audit (ponytail + security + general reviewers): write-ordering race + .env lost update + hydrate stomp + custom-endpoint clobber fixed and pinned (one-shot hold / latched read knobs in the test double); ~30 lines of dead flexibility cut (keyType protocol param, works(reply:) payload, unused timeout knob, double JSON round trips). Suite 468/468 xcresult-verified; swiftlint clean; factsheet §6 correction logged. Closes #136
This commit is contained in:
1 parent
42a27cc8a3
commit
5ad605eb3c
20 files changed
+1983
-161
No files matched your search
@@ -34,10 +34,62 @@ struct SeedSkill {
|
||||
/// invocation in `<binaryDir>/mcp-add-invocation-<profile>`, drops the
|
||||
/// per-profile marker, prints "Saved 'museion-tools' to …" (verified wire
|
||||
/// strings). `config set <key> <value> [--force]` appends the exact argv to
|
||||
/// `<binaryDir>/config-set-<profile>` and prints the verified "✓ Set …" line.
|
||||
/// `<binaryDir>/mcp-add-fails` / `config-set-fails` force the matching
|
||||
/// `<binaryDir>/config-set-<profile>` and prints the verified "✓ Set …"
|
||||
/// line. `<binaryDir>/mcp-add-fails` / `config-set-fails` force the matching
|
||||
/// failure. Every `profile create` name appends to
|
||||
/// `<binaryDir>/profile-create-log`.
|
||||
/// #136: `config set` also records KEY=VALUE into
|
||||
/// `<binaryDir>/config-store-<profile>` (dedup per key), and the fake speaks
|
||||
/// `config get <key>` (store value, or the not-set line on stderr exit 1)
|
||||
/// and `config unset <key>` (argv log `<binaryDir>/config-unset-<profile>`,
|
||||
/// store line removed, "✓ Unset …"; unset-when-absent = the not-set line,
|
||||
/// exit 1) — the live-probed wire shapes HermesSettingsWriter pins.
|
||||
// #136: the config rail (set/get/unset over the config-store map) — its
|
||||
// own literal so makeFakeHermes stays under its function-body ceiling.
|
||||
private func fakeHermesConfigCLI() -> String {
|
||||
"""
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "set" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ -f "${0:h}/config-set-fails" ]]; then
|
||||
print "Error: config set exploded"
|
||||
exit 1
|
||||
fi
|
||||
STORE="${0:h}/config-store-$PROFILE"
|
||||
touch "$STORE"
|
||||
grep -v "^$5=" "$STORE" > "$STORE.tmp" && mv "$STORE.tmp" "$STORE"
|
||||
print -r -- "$5=$6" >> "$STORE"
|
||||
print -r -- "$*" >> "${0:h}/config-set-$PROFILE"
|
||||
print "✓ Set $5 = $6 in ${0:h}/profiles/$PROFILE/config.yaml"
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "get" ]]; then
|
||||
PROFILE="$2"; KEY="$5"
|
||||
STORE="${0:h}/config-store-$PROFILE"
|
||||
if [[ -f "$STORE" ]]; then
|
||||
VAL="$(grep -m1 "^${KEY}=" "$STORE" | cut -d= -f2-)"
|
||||
if [[ -n "$VAL" ]]; then
|
||||
print -r -- "$VAL"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
print "Config key not set: $KEY" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "unset" ]]; then
|
||||
PROFILE="$2"; KEY="$5"
|
||||
print -r -- "$*" >> "${0:h}/config-unset-$PROFILE"
|
||||
STORE="${0:h}/config-store-$PROFILE"
|
||||
if [[ -f "$STORE" && -n "$(grep -m1 "^${KEY}=" "$STORE")" ]]; then
|
||||
grep -v "^${KEY}=" "$STORE" > "$STORE.tmp" && mv "$STORE.tmp" "$STORE"
|
||||
print "✓ Unset $KEY from ${0:h}/profiles/$PROFILE/config.yaml"
|
||||
exit 0
|
||||
fi
|
||||
print "Config key not set: $KEY" >&2
|
||||
exit 1
|
||||
fi
|
||||
"""
|
||||
}
|
||||
|
||||
func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> String {
|
||||
let path = (dir as NSString).appendingPathComponent(name)
|
||||
let createBlock = switch mode {
|
||||
@@ -64,6 +116,7 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
|
||||
exit 1
|
||||
"""
|
||||
}
|
||||
// #136: the config rail lives in fakeHermesConfigCLI().
|
||||
let script = """
|
||||
#!/bin/zsh
|
||||
if [[ "$1" == "profile" && "$2" == "create" ]]; then
|
||||
@@ -101,16 +154,7 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "set" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ -f "${0:h}/config-set-fails" ]]; then
|
||||
print "Error: config set exploded"
|
||||
exit 1
|
||||
fi
|
||||
print -r -- "$*" >> "${0:h}/config-set-$PROFILE"
|
||||
print "✓ Set $5 = $6 in ${0:h}/profiles/$PROFILE/config.yaml"
|
||||
exit 0
|
||||
fi
|
||||
\(fakeHermesConfigCLI())
|
||||
exit 97
|
||||
"""
|
||||
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
||||
|
||||
Reference in new issue
Block a user