Skip to content

Commit 66acfb1

Browse files
TheStreamCodeMichael Gasperini
andauthored
fix(login): keep the credential reference fresh for the native row dot (#7)
The Models row paints its credential dot only for a route that names a credential reference, so the `meta` route now declares `apiKeyEnv: MUSE_CODE_SUB_TOKEN`. An explicit reference is also DSH's highest-priority auth override, so the plugin mirrors the OAuth record's minted key into that reference and re-mints it ahead of Meta's ~24 h expiry (preserving the non-renewable identity token when the record is replaced by a fresh sign-in). Also fixes the live catalog sync treating the empty `models` array that the Settings form projects as a user-owned list, which would have kept Muse Wonder out of the route; documents the Meta prompt-cache keying and the meaning of the generic Edit/Delete row actions. Co-authored-by: Michael Gasperini <michael@mikesoft.it>
1 parent cde54b7 commit 66acfb1

10 files changed

Lines changed: 698 additions & 27 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.2] - 2026-10-26
9+
10+
### Added
11+
12+
- Native credential dot on the **Muse Code (Meta subscription)** row: the route names
13+
`apiKeyEnv: MUSE_CODE_SUB_TOKEN`; the plugin mirrors the OAuth record's minted key into that
14+
reference (red without a credential, green with one) and re-mints it before Meta's ~24 h
15+
expiry, because an explicit reference is DSH's highest-priority auth override.
16+
- Documented the Meta prompt-cache behavior (`prompt_cache_key` = DSH session id) and the
17+
meaning/consequences of the generic **Edit** and **Delete** row actions.
18+
19+
### Fixed
20+
21+
- The live catalog sync no longer mistakes the empty `models` array that the Settings form
22+
projects for a user-owned catalog, so Muse Wonder keeps being filled into the route.
23+
824
## [0.2.1] - 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.1
4+
version: 0.2.2
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: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,11 @@ cannot reach the Host falls back to that command.
9090
direct Meta page link, backed by the routes above, plus the `/muse-login` chat command. Both
9191
start DSH's own device-code flow (`llm-pi-ai/meta`) and open the verification page in the
9292
default browser.
93+
- Paints the native credential dot on the **Muse Code (Meta subscription)** row: the route names
94+
`apiKeyEnv: MUSE_CODE_SUB_TOKEN`, and the plugin mirrors the OAuth record's minted key into that
95+
reference (red without a credential, green with one) and re-mints it before Meta's ~24 h expiry.
9396
- Leaves credential handling to DSH: the shipped flow stores the sign-in as an OAuth credential
94-
record and re-mints Meta's short-lived inference key automatically, so the route keeps
97+
record and the plugin keeps the route's credential-reference copy fresh, so the route keeps
9598
working after the key rotates.
9699

97100
## Requirements
@@ -126,8 +129,9 @@ see the upgrade note under Troubleshooting.
126129
- The local `POST /muse-code/login`, `GET /muse-code/login`, and `GET /muse-code/status` routes
127130
only start the flow and report its state; they transmit no credential and are reachable only
128131
on the Host's own loopback listener.
129-
- The stored credential is the `llm-pi-ai/meta` record in the DSH credential store. It never
130-
appears in configuration or logs.
132+
- The stored credential is the `llm-pi-ai/meta` record in the DSH credential store; the
133+
`MUSE_CODE_SUB_TOKEN` reference the row reads is a copy of its minted key and is refreshed by
134+
the plugin. Neither ever appears in configuration or logs.
131135
- To remove access, remove the bundle, remove the declared provider from **Settings → Models**
132136
(or from the profile's `cordis.patch.yml`), and delete the `llm-pi-ai/meta` record while DSH
133137
is stopped (the file is `$DSH_HOME/.credentials.yaml`), or run the sign-in again to replace
@@ -137,6 +141,25 @@ see the upgrade note under Troubleshooting.
137141
See [SECURITY.md](SECURITY.md) for vulnerability reporting and
138142
[AUTH_CONTRACT.md](AUTH_CONTRACT.md) for the pinned login contract that DSH implements.
139143

144+
## Prompt caching
145+
146+
The Meta Model API caches the request prefix per `prompt_cache_key`, and a request without that
147+
key gets no reuse at all. DSH's pi-ai adapter sends the session id as the key for every call, so
148+
turns in the same session reuse the prefix Meta already saw. Measured against the live API with
149+
an identical 1.6k-token prefix: same key → 1521 of 1600 tokens cached on the second call;
150+
different key or no key → 0.
151+
152+
The ratio you see in the usage panel therefore depends on how the session is used:
153+
154+
- the cache is per key and per model — switching model or route starts a fresh prefix;
155+
- a short session, or turns spaced far apart, shows a low ratio, because the first call of every
156+
cache window pays full price;
157+
- editing the system prompt or compacting the history invalidates the prefix once.
158+
159+
The plugin does not change the request shape, so this behaves like any other pi-ai route in the
160+
same harness (for example `opencode-go`). DeepSeek's first-party routes report their own cache
161+
counters and are not directly comparable.
162+
140163
## Troubleshooting
141164

142165
### Nothing named Muse Code appears under Settings → Models
@@ -192,6 +215,36 @@ before it expires.
192215
DSH re-mints the inference key from the stored session. When Meta ends that session, run the
193216
sign-in again (Sign in control or `/muse-login`) to sign in and replace the record.
194217

218+
### The credential dot stays red after signing in
219+
220+
The route's credential reference is a copy of the record's minted key; the plugin mirrors it on
221+
boot and on every record update. If the dot stays red while the card says **Signed in**, restart
222+
DSH and check that the `llm-pi-ai/meta` record still exists in the credential store.
223+
224+
### Requests fail after about a day without the plugin running
225+
226+
The route authenticates through the mirrored reference, and the plugin re-mints the key before
227+
its ~24 h expiry. If DSH ran with the plugin disabled long enough for the key to lapse, sign in
228+
again (Sign in card or `/muse-login`).
229+
230+
### Edit and Delete on the Muse Code row
231+
232+
Both are DSH's generic provider-row actions and a plugin cannot hide them.
233+
234+
- **Edit** writes the route profile into your profile patch: display name, models, and the
235+
`apiKeyEnv` reference. The plugin restores the reference on the next boot and refills an
236+
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:
243+
244+
```bash
245+
dsh plugin --profile desktop remove @thestreamcode/dsh-muse-code
246+
```
247+
195248
### Upgrading from 0.1.x
196249

197250
0.1.x inserted a second `@deepseek-ai/dsh-llm-pi-ai` instance, which DSH refuses to activate

‎client/client.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ loader?.load({
8383
function statusView(phase) {
8484
if (phase === "authorized") return { label: "Signed in", color: COLOR.labelSuccess }
8585
if (phase === "pending" || phase === "starting") return { label: "Waiting for Meta…", color: COLOR.labelWarn }
86-
if (phase === "failed") return { label: "Sign-in failed", color: COLOR.labelError }
8786
if (phase === "checking") return { label: "Checking…", color: COLOR.labelTertiary }
88-
return { label: "Not signed in", color: COLOR.labelTertiary }
87+
// Not signed in, or the last attempt failed: the row reads red.
88+
return { label: phase === "failed" ? "Sign-in failed" : "Not signed in", color: COLOR.labelError }
8989
}
9090

9191
function MuseCodeSignIn() {

‎lib/index.d.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import type { IncomingMessage, ServerResponse } from "node:http";
22
export declare const name = "dsh-muse-code";
33
export declare const inject: string[];
4+
/**
5+
* Credential reference the route reads through `apiKeyEnv`.
6+
*
7+
* DSH paints the Models row's credential dot only for a route that names a
8+
* reference, so the route reads the minted inference key through this reference
9+
* and the plugin keeps it in step with the OAuth record.
10+
*/
11+
export declare const CREDENTIAL_REFERENCE = "MUSE_CODE_SUB_TOKEN";
412
/** Web route the Settings control calls to start the sign-in. */
513
export declare const LOGIN_ROUTE = "/muse-code/login";
614
/** Web route that reports whether the sign-in completed. */
@@ -84,6 +92,14 @@ type CredentialsFace = {
8492
describeRecord(key: string): Promise<{
8593
configured: boolean;
8694
}>;
95+
/** Stored reference state, used to avoid rewriting an unchanged key. */
96+
resolve?(reference: string): Promise<{
97+
value?: string;
98+
source?: string;
99+
} | undefined>;
100+
set?(reference: string, value: string): Promise<void>;
101+
unset?(reference: string): Promise<void>;
102+
modifyRecord?(key: string, update: (current: CredentialRecord | undefined) => Promise<CredentialRecord | undefined>): Promise<unknown>;
87103
};
88104
type WebRoute = {
89105
kind: "exact" | "prefix";
@@ -259,6 +275,56 @@ export declare function prettifyModelName(id: string): string;
259275
* @returns the chat model ids, or null on any failure.
260276
*/
261277
export declare function fetchLiveModelIds(accessKey: string, timeoutMs?: number): Promise<string[] | null>;
278+
/** Injected side effects for the credential bridge, overridable in tests. */
279+
export type CredentialSyncOptions = {
280+
logger?: Logger;
281+
fetchImpl?: typeof fetch;
282+
now?: () => number;
283+
refreshWindowMs?: number;
284+
};
285+
/**
286+
* Keep the route's credential reference equal to the OAuth record's minted key
287+
* and re-mint that key before it expires.
288+
*
289+
* The route names `apiKeyEnv: MUSE_CODE_SUB_TOKEN` so DSH paints its credential
290+
* dot; an explicit reference is also the highest-priority auth override, which
291+
* means the plugin must keep it fresh itself. The OAuth record stays the source
292+
* of truth (the shipped flow wrote it, and it carries the non-renewable identity
293+
* token), so this only mirrors its `access` field and rotates it ahead of
294+
* expiry through the pinned key-mint endpoint.
295+
*
296+
* @param credentials - the credential seam.
297+
* @param options - injected side effects, overridable in tests.
298+
* @returns which steps ran.
299+
*/
300+
export declare function syncCredentialState(credentials: CredentialsFace, options?: CredentialSyncOptions): Promise<{
301+
refreshed: boolean;
302+
mirrored: boolean;
303+
}>;
304+
/**
305+
* Copy the record's minted inference key into the route's credential reference,
306+
* or clear the reference when the record is gone (the row then shows red).
307+
* @param credentials - the credential seam.
308+
* @param options - injected side effects.
309+
* @returns whether the stored reference now carries a key.
310+
*/
311+
export declare function mirrorCredentialReference(credentials: CredentialsFace, options?: CredentialSyncOptions): Promise<boolean>;
312+
/**
313+
* Re-mint the inference key from the record's identity token when the current
314+
* key is close to expiry, and store it back into the record.
315+
* @param credentials - the credential seam.
316+
* @param options - injected side effects.
317+
* @returns whether a fresh key was minted and stored.
318+
*/
319+
export declare function refreshCredentialRecord(credentials: CredentialsFace, options?: CredentialSyncOptions): Promise<boolean>;
320+
/**
321+
* Exchange the non-renewable Meta identity token for a fresh inference key.
322+
* @param identityToken - the record's `refresh` field.
323+
* @param fetchImpl - injectable fetch.
324+
* @param timeoutMs - request bound.
325+
* @returns the minted key, or undefined on any failure.
326+
*/
327+
export declare function mintInferenceKey(identityToken: string, fetchImpl?: typeof fetch, timeoutMs?: number): Promise<string | undefined>;
262328
/**
263329
* The page a plain navigation to {@link LOGIN_ROUTE} receives: the code, a link
264330
* to Meta, and a poll of {@link STATUS_ROUTE} until the sign-in completes.

0 commit comments

Comments
 (0)