The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
feat(spur): eine Anmeldung fuer alle drei Laufquellen
Claude6615ae991670
diff --git a/src/lib/__tests__/eine-wahrheit-fuer-laeuft-etwas.test.ts b/src/lib/__tests__/eine-wahrheit-fuer-laeuft-etwas.test.tsindex e7321853..ea26ecf9 100644--- a/src/lib/__tests__/eine-wahrheit-fuer-laeuft-etwas.test.ts+++ b/src/lib/__tests__/eine-wahrheit-fuer-laeuft-etwas.test.ts@@ -22,6 +22,7 @@ import {runStatusOf,isRunActive,whenRunsIdle,+ subscribeRuns,} from '../run-idle'import {CODEX_THREAD_STATUSES,@@ -346,3 +347,58 @@ describe('mehrere offene Laeufe nebeneinander', () => {expect(isRunActive('b')).toBe(false)})})++describe('EINE Anmeldung fuer alle drei Quellen', () => {+ // Die Oberflaeche soll "Senden", "Stop" und "Platz 2" zeigen koennen, und+ // dafuer neu malen, sobald sich irgendetwas daran aendert. Die drei+ // Quellen einzeln zu abonnieren waere dieselbe Liste ein zweites Mal, und+ // wer beim naechsten Umbau eine davon vergisst, sieht keinen Fehler,+ // sondern ein Plaettchen, das stehen bleibt.+ //+ // Die Antworten sind alle einfache Werte (eine Zeichenkette, eine Zahl, ein+ // Ja/Nein), also genuegt `useSyncExternalStore(subscribeRuns, () =>+ // runStatusOf(id))` ohne jede Zwischenspeicherung.+ it('weckt bei einem Lauf, der anfaengt', () => {+ let geweckt = 0+ const ab = subscribeRuns(() => { geweckt++ })+ useGenerationStore.getState().setGenerating('a', true)+ expect(geweckt).toBeGreaterThan(0)+ ab()+ })++ it('weckt bei einem Coding-Thread, der seinen Zustand wechselt', () => {+ useCodexStore.getState().initThread('conv-c', '/tmp')+ let geweckt = 0+ const ab = subscribeRuns(() => { geweckt++ })+ useCodexStore.getState().setThreadStatus('conv-c', 'running')+ expect(geweckt).toBeGreaterThan(0)+ ab()+ })++ it('weckt bei der Schlange, die keiner der beiden Speicher sieht', () => {+ admit('local', 'a', () => {})+ let geweckt = 0+ const ab = subscribeRuns(() => { geweckt++ })+ admit('local', 'b', () => {})+ expect(geweckt).toBeGreaterThan(0)+ ab()+ })++ it('GEGENPROBE: abgemeldet ist abgemeldet, in allen drei Quellen', () => {+ admit('local', 'a', () => {})+ useCodexStore.getState().initThread('conv-c', '/tmp')+ let geweckt = 0+ subscribeRuns(() => { geweckt++ })()+ useGenerationStore.getState().setGenerating('x', true)+ useCodexStore.getState().setThreadStatus('conv-c', 'running')+ admit('local', 'b', () => {})+ expect(geweckt).toBe(0)+ })++ it('die Antwort ist ein einfacher Wert, den useSyncExternalStore vergleichen kann', () => {+ admit('local', 'a', () => {})+ admit('local', 'b', () => {})+ expect(runStatusOf('b')).toBe(runStatusOf('b'))+ expect(typeof runStatusOf('b')).toBe('string')+ })+})diff --git a/src/lib/run-idle.ts b/src/lib/run-idle.tsindex 86651966..5f22adaf 100644--- a/src/lib/run-idle.ts+++ b/src/lib/run-idle.ts@@ -162,6 +162,35 @@ export function isRunActive(conversationId: string | null | undefined): booleanreturn isActiveCodexStatus(runStatusOf(conversationId))}+/**+ * Wake `listener` whenever ANY of the three sources moves: a generating flag,+ * a coding thread's status, or the local lane's queue.+ *+ * This exists so the list of sources is written down ONCE. Every reader of+ * this module needs the same three, and a reader that subscribes to two of+ * them shows no error: it shows a Stop button that never turns back into+ * Send, or a queue chip that stays on position 2 while the queue moves on.+ * That is the house's most expensive pattern, two paths and one of them+ * maintained, in the place where it is hardest to see.+ *+ * Meant for `useSyncExternalStore`, together with any of the verdict+ * functions above as the snapshot:+ *+ * useSyncExternalStore(subscribeRuns, () => runStatusOf(convId))+ *+ * All of them answer with a plain value (a string, a number, a boolean), so+ * `Object.is` settles it and no snapshot has to be cached to keep its+ * identity.+ */+export function subscribeRuns(listener: () => void): () => void {+ const unsubs = [+ useGenerationStore.subscribe(listener),+ useCodexStore.subscribe(listener),+ subscribeRunLanes(listener),+ ]+ return () => { for (const u of unsubs) u() }+}+/*** Call `show` now when no run is active, otherwise the moment the last run* ends. Returns a cancel function that withdraws a still-deferred `show`@@ -170,10 +199,11 @@ export function isRunActive(conversationId: string | null | undefined): boolean* design, codexStore persists only the working directory), so a crash can* never leave this waiting on a ghost run.*- * All THREE sources are listened to, and the third is the one that used to be- * missing: a run that is only booked, waiting for the local lane, ends by- * leaving a queue that neither store can see. Without that subscription the- * last waiting run could go away and leave a deferred modal sitting.+ * All THREE sources are listened to, through the one `subscribeRuns` above.+ * The third is the one that used to be missing: a run that is only booked,+ * waiting for the local lane, ends by leaving a queue that neither store can+ * see. Without that subscription the last waiting run could go away and leave+ * a deferred modal sitting.*/export function whenRunsIdle(show: () => void): () => void {if (!runsActive()) {@@ -181,18 +211,16 @@ export function whenRunsIdle(show: () => void): () => void {return () => {}}let done = false- const unsubs: (() => void)[] = []+ let abmelden: (() => void) | null = nullconst check = () => {if (done || runsActive()) returndone = true- for (const u of unsubs) u()+ abmelden?.()show()}- unsubs.push(useGenerationStore.subscribe(check))- unsubs.push(useCodexStore.subscribe(check))- unsubs.push(subscribeRunLanes(check))+ abmelden = subscribeRuns(check)return () => {done = true- for (const u of unsubs) u()+ abmelden?.()}}