Skip to content

Commit d89e8b4

Browse files
author
Michael Gasperini
committed
feat(settings): sign out when the Muse Code route is deleted
The Models page Delete only unsets the user-layer route. For a plugin-managed provider that left a green credential dot behind with no row, so the plugin now watches its settings section and treats that removal as a sign-out: it deletes the `llm-pi-ai/meta` OAuth record and clears the mirrored `MUSE_CODE_SUB_TOKEN` reference. The row is re-declared with a red dot on the next refresh or restart. Also records the measured cache window in the docs: same-key entries still hit after 12 minutes, a fresh key reports zero, and `prompt_cache_retention: 24h` made no difference in that window.
1 parent 66acfb1 commit d89e8b4

9 files changed

Lines changed: 243 additions & 19 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ All notable changes to this project are documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.2.3] - 2026-10-26
9+
10+
### Added
11+
12+
- Measured the Meta prompt-cache window: same-key entries still hit after 12 minutes (2673 of
13+
2800 tokens), a fresh key reports 0, and `prompt_cache_retention: 24h` made no difference in
14+
that window — so there is no retention knob worth exposing.
15+
16+
### Changed
17+
18+
- **Delete on the Muse Code row now signs out.** The Models page's Delete only unsets the
19+
user-layer route; the plugin treats that removal as a sign-out and deletes the
20+
`llm-pi-ai/meta` OAuth record together with the mirrored `MUSE_CODE_SUB_TOKEN` reference,
21+
instead of leaving a green dot behind for a row that no longer exists. The row is re-declared
22+
(red dot) on the next refresh or restart.
23+
824
## [0.2.2] - 2026-10-26
925

1026
### Added

‎CITATION.cff‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cff-version: 1.2.0
22
message: "If you use this software, please cite it as below."
33
title: "dsh-muse-code"
4-
version: 0.2.2
4+
version: 0.2.3
55
date-released: "2026-10-26"
66
url: "https://github.com/TheStreamCode/dsh-muse-code"
77
repository-code: "https://github.com/TheStreamCode/dsh-muse-code"

‎README.md‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ The Meta Model API caches the request prefix per `prompt_cache_key`, and a reque
147147
key gets no reuse at all. DSH's pi-ai adapter sends the session id as the key for every call, so
148148
turns in the same session reuse the prefix Meta already saw. Measured against the live API with
149149
an identical 1.6k-token prefix: same key → 1521 of 1600 tokens cached on the second call;
150-
different key or no key → 0.
150+
different key or no key → 0. After a 12-minute pause the same-key entries still reported 2673 of
151+
2800 cached tokens, with or without `prompt_cache_retention`, and a fresh key still reported 0 —
152+
so the default retention is enough for normal turn pacing and there is no retention knob to tune.
151153

152154
The ratio you see in the usage panel therefore depends on how the session is used:
153155

@@ -234,12 +236,13 @@ Both are DSH's generic provider-row actions and a plugin cannot hide them.
234236
- **Edit** writes the route profile into your profile patch: display name, models, and the
235237
`apiKeyEnv` reference. The plugin restores the reference on the next boot and refills an
236238
emptied model list from the account catalog.
237-
- **Delete** removes only that user-layer route: the provider leaves Settings → Models and the
238-
model picker, and a hand-edited model list is lost; the credential record and its mirrored
239-
reference stay. The plugin re-declares the route on the next boot and resyncs the catalog. To
240-
actually remove Muse Code, uninstall the bundle and delete the credential record.
241-
242-
The supported off switch is the plugin itself:
239+
- **Delete** removes the user-layer route and the plugin treats that removal as a sign-out: it
240+
deletes the `llm-pi-ai/meta` OAuth record and clears the mirrored `MUSE_CODE_SUB_TOKEN`
241+
reference. The provider leaves Settings → Models and the picker, and a hand-edited model list
242+
is lost; the plugin re-declares the row on its next refresh (and on restart) with a red dot, so
243+
sign in again to keep using Muse Code.
244+
- To remove Muse Code for good, uninstall the bundle and delete the credential record; the
245+
supported off switch is the plugin itself:
243246

244247
```bash
245248
dsh plugin --profile desktop remove @thestreamcode/dsh-muse-code

‎lib/index.d.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ type CredentialsFace = {
9999
} | undefined>;
100100
set?(reference: string, value: string): Promise<void>;
101101
unset?(reference: string): Promise<void>;
102+
deleteRecord?(key: string): Promise<void>;
102103
modifyRecord?(key: string, update: (current: CredentialRecord | undefined) => Promise<CredentialRecord | undefined>): Promise<unknown>;
103104
};
104105
type WebRoute = {
@@ -275,6 +276,15 @@ export declare function prettifyModelName(id: string): string;
275276
* @returns the chat model ids, or null on any failure.
276277
*/
277278
export declare function fetchLiveModelIds(accessKey: string, timeoutMs?: number): Promise<string[] | null>;
279+
/**
280+
* Sign out of Muse Code: drop the OAuth record and the route's mirrored
281+
* credential reference. The Models page's **Delete** action only unsets the
282+
* user-layer route, so the plugin treats that removal as a sign-out rather
283+
* than leaving credentials behind for a row that no longer exists.
284+
* @param credentials - the credential seam.
285+
* @param logger - optional plugin logger.
286+
*/
287+
export declare function logoutMuseCode(credentials: CredentialsFace, logger?: Logger): Promise<void>;
278288
/** Injected side effects for the credential bridge, overridable in tests. */
279289
export type CredentialSyncOptions = {
280290
logger?: Logger;

‎lib/index.js‎

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ const KEY_LIFETIME_MS = 24 * 60 * 60 * 1000;
5050
const REFRESH_WINDOW_MS = 6 * 60 * 60 * 1000;
5151
/** How often the plugin re-checks the record while it runs. */
5252
const REFRESH_CHECK_MS = 15 * 60 * 1000;
53+
/** Settle time before treating a removed route as a user sign-out. */
54+
const ROUTE_DELETE_CHECK_MS = 400;
5355
/** Web route the Settings control calls to start the sign-in. */
5456
export const LOGIN_ROUTE = "/muse-code/login";
5557
/** Web route that reports whether the sign-in completed. */
@@ -146,20 +148,70 @@ export function apply(ctx) {
146148
const settings = child.settings;
147149
if (settings === undefined)
148150
return () => { };
151+
let sawRoute = false;
152+
let checkTimer;
153+
const routeIsDeclared = () => {
154+
const row = settings.describe().find((candidate) => candidate.ns === SETTINGS_NS);
155+
if (row === undefined)
156+
return false;
157+
const providers = row.value["providers"];
158+
return isRecord(providers) && isRecord(providers[PROVIDER]);
159+
};
149160
const refresh = () => {
150161
void (async () => {
151162
await ensureMuseRoute(settings, ctx.logger);
152163
await syncMuseModels(settings, ctx.logger, options);
164+
if (routeIsDeclared())
165+
sawRoute = true;
153166
})().catch((error) => {
154167
warn(ctx.logger, "dsh-muse-code: could not refresh the Muse Code settings", error);
155168
});
156169
};
170+
// The Models page Delete only unsets the user-layer route; for a
171+
// plugin-managed provider that reads as a sign-out, so drop the OAuth
172+
// record and its mirrored reference instead of leaving a green dot for a
173+
// row that no longer exists.
174+
const scheduleDeleteCheck = () => {
175+
if (checkTimer !== undefined)
176+
clearTimeout(checkTimer);
177+
checkTimer = setTimeout(() => {
178+
checkTimer = undefined;
179+
if (routeIsDeclared()) {
180+
sawRoute = true;
181+
return;
182+
}
183+
if (!sawRoute)
184+
return;
185+
sawRoute = false;
186+
const credentials = credentialsFace;
187+
if (credentials === undefined)
188+
return;
189+
void logoutMuseCode(credentials, ctx.logger).catch((error) => {
190+
warn(ctx.logger, "dsh-muse-code: could not sign out after the route was deleted", error);
191+
});
192+
}, ROUTE_DELETE_CHECK_MS);
193+
checkTimer.unref?.();
194+
};
157195
refresh();
158-
const dispose = ctx.on?.("credentials/record-updated", (key) => {
196+
const disposers = [];
197+
const onRecord = ctx.on?.("credentials/record-updated", (key) => {
159198
if (key === AUTH_KEY)
160199
refresh();
161200
});
162-
return dispose ?? (() => { });
201+
if (onRecord !== undefined)
202+
disposers.push(onRecord);
203+
const onDocument = ctx.on?.("settings/document-updated", (ns) => {
204+
if (ns === SETTINGS_NS)
205+
scheduleDeleteCheck();
206+
});
207+
if (onDocument !== undefined)
208+
disposers.push(onDocument);
209+
return () => {
210+
if (checkTimer !== undefined)
211+
clearTimeout(checkTimer);
212+
for (const dispose of disposers)
213+
dispose();
214+
};
163215
}, "dsh-muse-code: settings");
164216
});
165217
}
@@ -649,6 +701,33 @@ async function waitForCredentials(getter, attempts = 8, delayMs = 250) {
649701
}
650702
return undefined;
651703
}
704+
/**
705+
* Sign out of Muse Code: drop the OAuth record and the route's mirrored
706+
* credential reference. The Models page's **Delete** action only unsets the
707+
* user-layer route, so the plugin treats that removal as a sign-out rather
708+
* than leaving credentials behind for a row that no longer exists.
709+
* @param credentials - the credential seam.
710+
* @param logger - optional plugin logger.
711+
*/
712+
export async function logoutMuseCode(credentials, logger) {
713+
let failed = false;
714+
try {
715+
await credentials.deleteRecord?.(AUTH_KEY);
716+
}
717+
catch (error) {
718+
failed = true;
719+
warn(logger, "dsh-muse-code: could not delete the Muse Code record", error);
720+
}
721+
try {
722+
await credentials.unset?.(CREDENTIAL_REFERENCE);
723+
}
724+
catch (error) {
725+
failed = true;
726+
warn(logger, "dsh-muse-code: could not clear the Muse Code credential reference", error);
727+
}
728+
if (!failed)
729+
logger?.info?.("dsh-muse-code: deleted the route in Settings > Models; signed out");
730+
}
652731
/**
653732
* Keep the route's credential reference equal to the OAuth record's minted key
654733
* and re-mint that key before it expires.

‎package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@thestreamcode/dsh-muse-code",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "Unofficial DeepSeek Harness integration for Meta's Muse Code subscription: declares the shipped Meta provider route and adds its sign-in command. Use at your own risk.",
55
"license": "MIT",
66
"author": {

‎src/index.ts‎

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ const KEY_LIFETIME_MS = 24 * 60 * 60 * 1000
5555
const REFRESH_WINDOW_MS = 6 * 60 * 60 * 1000
5656
/** How often the plugin re-checks the record while it runs. */
5757
const REFRESH_CHECK_MS = 15 * 60 * 1000
58+
/** Settle time before treating a removed route as a user sign-out. */
59+
const ROUTE_DELETE_CHECK_MS = 400
5860
/** Web route the Settings control calls to start the sign-in. */
5961
export const LOGIN_ROUTE = "/muse-code/login"
6062
/** Web route that reports whether the sign-in completed. */
@@ -160,6 +162,7 @@ type CredentialsFace = {
160162
resolve?(reference: string): Promise<{ value?: string; source?: string } | undefined>
161163
set?(reference: string, value: string): Promise<void>
162164
unset?(reference: string): Promise<void>
165+
deleteRecord?(key: string): Promise<void>
163166
modifyRecord?(
164167
key: string,
165168
update: (current: CredentialRecord | undefined) => Promise<CredentialRecord | undefined>,
@@ -305,19 +308,59 @@ export function apply(ctx: HostContext): void {
305308
child.effect(() => {
306309
const settings = child.settings
307310
if (settings === undefined) return () => {}
311+
let sawRoute = false
312+
let checkTimer: ReturnType<typeof setTimeout> | undefined
313+
const routeIsDeclared = (): boolean => {
314+
const row = settings.describe().find((candidate) => candidate.ns === SETTINGS_NS)
315+
if (row === undefined) return false
316+
const providers = row.value["providers"]
317+
return isRecord(providers) && isRecord(providers[PROVIDER])
318+
}
308319
const refresh = () => {
309320
void (async () => {
310321
await ensureMuseRoute(settings, ctx.logger)
311322
await syncMuseModels(settings, ctx.logger, options)
323+
if (routeIsDeclared()) sawRoute = true
312324
})().catch((error: unknown) => {
313325
warn(ctx.logger, "dsh-muse-code: could not refresh the Muse Code settings", error)
314326
})
315327
}
328+
// The Models page Delete only unsets the user-layer route; for a
329+
// plugin-managed provider that reads as a sign-out, so drop the OAuth
330+
// record and its mirrored reference instead of leaving a green dot for a
331+
// row that no longer exists.
332+
const scheduleDeleteCheck = () => {
333+
if (checkTimer !== undefined) clearTimeout(checkTimer)
334+
checkTimer = setTimeout(() => {
335+
checkTimer = undefined
336+
if (routeIsDeclared()) {
337+
sawRoute = true
338+
return
339+
}
340+
if (!sawRoute) return
341+
sawRoute = false
342+
const credentials = credentialsFace
343+
if (credentials === undefined) return
344+
void logoutMuseCode(credentials, ctx.logger).catch((error: unknown) => {
345+
warn(ctx.logger, "dsh-muse-code: could not sign out after the route was deleted", error)
346+
})
347+
}, ROUTE_DELETE_CHECK_MS)
348+
checkTimer.unref?.()
349+
}
316350
refresh()
317-
const dispose = ctx.on?.("credentials/record-updated", (key: string) => {
351+
const disposers: Array<() => void> = []
352+
const onRecord = ctx.on?.("credentials/record-updated", (key: string) => {
318353
if (key === AUTH_KEY) refresh()
319354
})
320-
return dispose ?? (() => {})
355+
if (onRecord !== undefined) disposers.push(onRecord)
356+
const onDocument = ctx.on?.("settings/document-updated", (ns: string) => {
357+
if (ns === SETTINGS_NS) scheduleDeleteCheck()
358+
})
359+
if (onDocument !== undefined) disposers.push(onDocument)
360+
return () => {
361+
if (checkTimer !== undefined) clearTimeout(checkTimer)
362+
for (const dispose of disposers) dispose()
363+
}
321364
}, "dsh-muse-code: settings")
322365
})
323366
}
@@ -855,6 +898,31 @@ async function waitForCredentials(
855898
return undefined
856899
}
857900

901+
/**
902+
* Sign out of Muse Code: drop the OAuth record and the route's mirrored
903+
* credential reference. The Models page's **Delete** action only unsets the
904+
* user-layer route, so the plugin treats that removal as a sign-out rather
905+
* than leaving credentials behind for a row that no longer exists.
906+
* @param credentials - the credential seam.
907+
* @param logger - optional plugin logger.
908+
*/
909+
export async function logoutMuseCode(credentials: CredentialsFace, logger?: Logger): Promise<void> {
910+
let failed = false
911+
try {
912+
await credentials.deleteRecord?.(AUTH_KEY)
913+
} catch (error) {
914+
failed = true
915+
warn(logger, "dsh-muse-code: could not delete the Muse Code record", error)
916+
}
917+
try {
918+
await credentials.unset?.(CREDENTIAL_REFERENCE)
919+
} catch (error) {
920+
failed = true
921+
warn(logger, "dsh-muse-code: could not clear the Muse Code credential reference", error)
922+
}
923+
if (!failed) logger?.info?.("dsh-muse-code: deleted the route in Settings > Models; signed out")
924+
}
925+
858926
/** Injected side effects for the credential bridge, overridable in tests. */
859927
export type CredentialSyncOptions = {
860928
logger?: Logger

0 commit comments

Comments
 (0)