update Markdown skills

This commit is contained in:
2026-08-19 17:36:27 +05:30
parent aa2fb41871
commit d3f7f439f6
30 changed files with 2341 additions and 221 deletions

View File

@@ -43,6 +43,37 @@ function loadUser() {
let currentUser = loadUser();
/**
* Writes the session user, and says whether it actually landed.
*
* The old version was `try { setItem } catch {}` — a swallowed
* `QuotaExceededError` or a private-browsing refusal, and the caller was handed
* a user object indistinguishable from a successful write. For preferences that
* is invisible; for `customSkills`, which is where every account-authored skill
* definition lives, it is the whole "I saved it and it was gone" report: the
* toast said added, the list showed it, the reload did not.
*
* The read-back matters as much as the catch. A write can be accepted and then
* evicted, and a serialisation can land truncated; comparing what came back
* with what went in is the only way to know the record is really there.
*/
function persistUser() {
const payload = JSON.stringify(currentUser);
try {
localStorage.setItem(SESSION_KEY, payload);
} catch (error) {
return { persisted: false, error };
}
try {
if (localStorage.getItem(SESSION_KEY) !== payload) {
return { persisted: false, error: new Error('The session record did not survive the write.') };
}
} catch (error) {
return { persisted: false, error };
}
return { persisted: true, error: null };
}
const auth = {
/** The demo is always signed in as the seeded employer/admin user. */
async me() {
@@ -51,11 +82,7 @@ const auth = {
async updateMe(patch) {
currentUser = { ...currentUser, ...patch };
try {
localStorage.setItem(SESSION_KEY, JSON.stringify(currentUser));
} catch {
// Non-persistent session is fine.
}
persistUser();
return { ...currentUser };
},
@@ -72,9 +99,18 @@ const auth = {
return { ...DEMO_USER.preferences, ...(currentUser.preferences || {}) };
},
/** Merges into the stored preferences and persists with the rest of the user. */
/**
* Merges into the stored preferences and persists with the rest of the user.
*
* Returns the write's outcome alongside the record, rather than the record
* alone. Preferences are where account-authored skills live, so "did this
* survive the reload" is a question the caller has to be able to answer —
* see `persistUser`.
*/
async updatePreferences(patch) {
return auth.updateMe({ preferences: { ...auth.preferences(), ...patch } });
currentUser = { ...currentUser, preferences: { ...auth.preferences(), ...patch } };
const write = persistUser();
return { user: { ...currentUser }, ...write };
},
isAuthenticated() {