Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(watch-link): Stop all reaches other machines' links when it is needed, and says what it reached

reviewd47149be70ce
diff --git a/src/core/watch-link/service.test.ts b/src/core/watch-link/service.test.ts
index 8c6dc652f..34a52a034 100644
--- a/src/core/watch-link/service.test.ts
+++ b/src/core/watch-link/service.test.ts
@@ -387,7 +387,7 @@ describe('createWatchLinkService — create', () => {
await t.s.init()
expect(await t.s.create(req())).toEqual({ ok: false, error: 'unsupported' })
expect(t.s.list()).toEqual([])
- await t.s.revokeAll()
+ expect(await t.s.revokeAll()).toBe('unsupported')
t.s.onWorkspaceChanged()
await flush()
expect(load).not.toHaveBeenCalled()
@@ -444,6 +444,49 @@ describe('createWatchLinkService — ending a link', () => {
expect(f.saves.at(-1)).toEqual([])
})
+ // R62: Stop all is the only control that reaches links on OTHER machines, so its server call is
+ // awaited and its answer reported — a failed call must not look like a stop.
+ it('revokeAll AWAITS the server and answers what it reached; this machine stops first, whatever the answer', async () => {
+ const answer = deferred<boolean>()
+ const t = service({ api: { revokeAll: () => answer.promise } })
+ await t.s.create(req())
+ let settled: string | null = null
+ const p = t.s.revokeAll().then((o) => (settled = o))
+ await flush()
+ // Local first: stopped and listed as gone before the server answered.
+ expect(t.hosts.made[0].stopped).toEqual(['revoked'])
+ expect(t.s.list()).toEqual([])
+ expect(settled).toBeNull()
+ answer.resolve(true)
+ await p
+ expect(settled).toBe('stopped')
+ })
+
+ it("revokeAll: a refused or failed server call is 'failed', never 'stopped'", async () => {
+ const refused = service({ api: { revokeAll: async () => false } })
+ await refused.s.create(req())
+ expect(await refused.s.revokeAll()).toBe('failed')
+ expect(refused.s.list()).toEqual([]) // this machine's links are stopped all the same
+ const thrown = service({
+ api: {
+ revokeAll: async () => {
+ throw new Error('offline')
+ }
+ }
+ })
+ expect(await thrown.s.revokeAll()).toBe('failed')
+ })
+
+ it("revokeAll with no entitlement stops this machine and answers 'no-entitlement' — no request", async () => {
+ const t = service({ entitlement: null })
+ t.ent.value = 'ent'
+ await t.s.create(req())
+ t.ent.value = null
+ expect(await t.s.revokeAll()).toBe('no-entitlement')
+ expect(t.s.list()).toEqual([])
+ expect(t.calls.filter((c) => c === 'revokeAll')).toEqual([])
+ })
+
it('Stop all reaches the server even when the boot load hangs (a stop never waits on the disk)', async () => {
const f = fakeStore({ load: () => new Promise(() => {}) })
const t = service({ store: f.store, persistTimeoutMs: 20, workspaceWaitMs: 20 })
@@ -764,7 +807,7 @@ describe('registerWatchLinkIpc / sendToOwners', () => {
const made = (await p.handlers[IPC.watchLinkCreate](1, req())) as { ok: boolean; link: WatchLinkView }
expect(made.ok).toBe(true)
expect(await p.handlers[IPC.watchLinkRevoke](2, made.link.linkId)).toBeUndefined()
- await p.handlers[IPC.watchLinkRevokeAll](2)
+ expect(await p.handlers[IPC.watchLinkRevokeAll](2)).toBe('unsupported')
expect((await p.handlers[IPC.watchLinkList](1)) as WatchLinkView[]).toHaveLength(1) // a non-owner stopped nothing
await p.handlers[IPC.watchLinkRevoke](1, made.link.linkId)
expect(await p.handlers[IPC.watchLinkList](1)).toEqual([])
diff --git a/src/core/watch-link/service.ts b/src/core/watch-link/service.ts
index b1ff906b7..a56069a0c 100644
--- a/src/core/watch-link/service.ts
+++ b/src/core/watch-link/service.ts
@@ -4,7 +4,7 @@
// view carries the link's URL, and the URL carries the secret.
//
// A LINK ENDS on: the owner's Stop (`revoke`, no notice — the owner did it), Stop all (`revokeAll`,
-// one server call), its expiry (a timer, plus a re-check on every host change because timers are
+// one server call, awaited and reported — it is what reaches other machines' links), its expiry (a timer, plus a re-check on every host change because timers are
// monotonic and a closed lid pauses them — G24), the node leaving every project, or the server saying
// it is gone (a mint or status answering 410 — `onGone`, which does raise a notice).
//
@@ -54,6 +54,7 @@ import {
type CreateWatchLinkError,
type CreateWatchLinkRequest,
type CreateWatchLinkResult,
+ type RevokeAllOutcome,
type WatchLinkNotice,
type WatchLinkView,
type WatchLinkViewerView
@@ -112,7 +113,9 @@ export interface WatchLinkService {
create(req: unknown): Promise<CreateWatchLinkResult>
list(): WatchLinkView[]
revoke(linkId: string): Promise<void>
- revokeAll(): Promise<void>
+ /** Stop this machine's links at once, then ask the server to revoke every link of the license and
+ * answer what that reached (`RevokeAllOutcome`). Never rejects. */
+ revokeAll(): Promise<RevokeAllOutcome>
kick(linkId: string, viewerId: string): boolean
sendChat(linkId: string, text: string): WatchChatMessage | null
chatHistory(linkId: string): WatchChatMessage[]
@@ -608,7 +611,7 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
},
async revokeAll() {
- if (unsupported) return
+ if (unsupported) return 'unsupported'
// Bounded like revoke: on a disk that hangs, "Stop all" still reaches the server below.
await within(init(), initWaitMs)
const gone = [...records.keys()].map(drop)
@@ -621,8 +624,21 @@ export function createWatchLinkService(deps: WatchLinkServiceDeps): WatchLinkSer
void persist()
for (const g of gone) stopHost(g?.host, 'revoked')
emitState()
- const ent = deps.entitlement()
- if (ent) void deps.api.revokeAll(ent).catch(() => false)
+ // This machine's links are stopped. The server call is the only thing that reaches the links of
+ // OTHER machines on the license, so it is AWAITED and its answer reported (R62): a stop that did
+ // not reach the server must not look like one that did.
+ let ent: string | null
+ try {
+ ent = deps.entitlement()
+ } catch {
+ ent = null
+ }
+ if (!ent) return 'no-entitlement'
+ try {
+ return (await deps.api.revokeAll(ent)) ? 'stopped' : 'failed'
+ } catch {
+ return 'failed'
+ }
},
kick(linkId, viewerId) {
@@ -722,7 +738,8 @@ export function registerWatchLinkIpc(
p.handleWithSender(IPC.watchLinkList, (sender: number) => (owner(sender) ? s.list() : []))
p.handleWithSender(IPC.watchLinkRevoke, (sender: number, id: unknown) =>
owner(sender) && str(id) ? s.revoke(id) : undefined)
- p.handleWithSender(IPC.watchLinkRevokeAll, (sender: number) => (owner(sender) ? s.revokeAll() : undefined))
+ p.handleWithSender(IPC.watchLinkRevokeAll, (sender: number) =>
+ owner(sender) ? s.revokeAll() : ('unsupported' satisfies RevokeAllOutcome))
p.handleWithSender(IPC.watchLinkKick, (sender: number, id: unknown, viewer: unknown) =>
owner(sender) && str(id) && str(viewer) ? s.kick(id, viewer) : false)
p.handleWithSender(IPC.watchLinkChatSend, (sender: number, id: unknown, text: unknown) =>
diff --git a/src/renderer/bridge/stubs.ts b/src/renderer/bridge/stubs.ts
index 520a1c787..db4414503 100644
--- a/src/renderer/bridge/stubs.ts
+++ b/src/renderer/bridge/stubs.ts
@@ -641,7 +641,7 @@ export function buildStubApi(): Omit<
create: async () => ({ ok: false, error: 'unsupported' }),
list: async () => [],
revoke: async () => {},
- revokeAll: async () => {},
+ revokeAll: async () => 'unsupported' as const,
kick: async () => false,
sendChat: async () => null,
chatHistory: async () => [],
diff --git a/src/renderer/bridge/ws-bridge.ts b/src/renderer/bridge/ws-bridge.ts
index 8bfa04f4e..b56c6046f 100644
--- a/src/renderer/bridge/ws-bridge.ts
+++ b/src/renderer/bridge/ws-bridge.ts
@@ -77,6 +77,7 @@ import { sanitizeOutcomeRecords } from '@shared/station-outcome'
import { sanitizeHandoverRecords } from '@shared/station-handover'
import type {
CreateWatchLinkResult,
+ RevokeAllOutcome,
WatchChatMessage,
WatchLinkNotice,
WatchLinkView
@@ -1009,9 +1010,8 @@ export function buildWatchLinkApi(client: RpcClient): Pick<NodeTerminalApi, 'wat
revoke: async (linkId) => {
await client.request(IPC.watchLinkRevoke, linkId)
},
- revokeAll: async () => {
- await client.request(IPC.watchLinkRevokeAll)
- },
+ // Rejects on a dropped socket, like revoke: the server half did not happen and the UI must say so.
+ revokeAll: () => client.request(IPC.watchLinkRevokeAll) as Promise<RevokeAllOutcome>,
kick: (linkId, viewerId) =>
(client.request(IPC.watchLinkKick, linkId, viewerId) as Promise<boolean>).catch(() => false),
sendChat: (linkId, text) =>
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 9fa5189ef..41a80d6c5 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -252,7 +252,7 @@ import {
liveLinkPrepare,
openLiveLink,
stopAllConfirm,
- stopLiveLinks,
+ stopAllLiveLinks,
type LiveLinkAvailabilityFacts,
type LiveLinkTarget
} from '../lib/liveLinkEntry'
@@ -3623,16 +3623,17 @@ export function Canvas() {
)
/** R48: "Stop all" revokes every link of the LICENSE — other machines' included — and cannot be
- * undone, so the palette asks first, with the same sentence and danger button as Settings. */
+ * undone, so the palette asks first, with the same sentence and danger button as Settings. R62:
+ * what it reached is ALWAYS said — a success too, since with no link listed here nothing else on
+ * screen changes, and a server call that failed leaves other machines' links running. */
const confirmStopAllLiveLinks = useCallback(
() =>
setConfirm(
stopAllConfirm({
close: () => setConfirm(null),
stop: () =>
- void stopLiveLinks(
- () => window.nodeTerminal.watchLink.revokeAll(),
- (text) => setNotice({ kind: 'error', text })
+ void stopAllLiveLinks(() => window.nodeTerminal.watchLink.revokeAll()).then((r) =>
+ setNotice({ kind: r.ok ? 'info' : 'error', text: r.text })
)
})
),
@@ -17437,6 +17438,8 @@ export function Canvas() {
// Live links: Manage (the Settings section), and Stop all — which CONFIRMS (R48).
...liveLinkCommands({
activeLinks: useWatchLinks.getState().links.length,
+ entitled: useEntitlement.getState().isPremium,
+ serverEdition: isBrowserRuntime(),
icon: <IconBroadcast />,
manage: () => {
setSettingsSection('live-links')
diff --git a/src/renderer/canvas/live-link-wiring.test.ts b/src/renderer/canvas/live-link-wiring.test.ts
index ff2069d6e..715401950 100644
--- a/src/renderer/canvas/live-link-wiring.test.ts
+++ b/src/renderer/canvas/live-link-wiring.test.ts
@@ -63,6 +63,14 @@ describe('Canvas live-link wiring', () => {
expect(src).toContain('confirmStopAll: confirmStopAllLiveLinks')
})
+ it('R62: what Stop all reached is always said, and it is offered to a Pro owner with no link here', () => {
+ const confirm = callback('confirmStopAllLiveLinks')
+ expect(confirm).toMatch(/stopAllLiveLinks\(\(\) => window\.nodeTerminal\.watchLink\.revokeAll\(\)\)\.then\(\(r\) =>\s*setNotice\(\{ kind: r\.ok \? 'info' : 'error', text: r\.text \}\)/)
+ const cmds = src.slice(src.indexOf('...liveLinkCommands({'))
+ expect(cmds.slice(0, 400)).toContain('entitled: useEntitlement.getState().isPremium,')
+ expect(cmds.slice(0, 400)).toContain('serverEdition: isBrowserRuntime(),')
+ })
+
it('one row builder, declared before selectionItems and listed in its deps (H15)', () => {
const builder = src.indexOf('const liveLinkMenuItems = useCallback(')
const selection = src.indexOf('const selectionItems = useCallback(')
diff --git a/src/renderer/components/settings/sections/LiveLinksSection.test.tsx b/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
index 5ed7fe54b..26a10fd7d 100644
--- a/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
+++ b/src/renderer/components/settings/sections/LiveLinksSection.test.tsx
@@ -21,7 +21,7 @@ pinNeutralMachineNoun()
const api = {
revoke: vi.fn(async (_id: string) => {}),
- revokeAll: vi.fn(async () => {})
+ revokeAll: vi.fn(async (): Promise<string> => 'stopped')
}
const writeText = vi.fn()
const upgrade = vi.fn(async () => ({ tier: null, active: false, expiresAt: null, termEndsAt: null, seats: 0, error: null }))
@@ -67,7 +67,7 @@ beforeEach(() => {
flags.browser = false
flags.relay.clear()
api.revoke.mockReset().mockImplementation(async () => {})
- api.revokeAll.mockReset().mockImplementation(async () => {})
+ api.revokeAll.mockReset().mockImplementation(async () => 'stopped')
writeText.mockClear()
upgrade.mockClear()
useEntitlement.setState({ isPremium: true })
@@ -177,7 +177,7 @@ describe('LiveLinksSection', () => {
click(buttons('Stop all')[0])
const dialog = document.querySelector<HTMLElement>('.confirm')!
expect(dialog.textContent).toContain(
- 'Stop every live link on your license? This also ends links shared from other computers. Viewers are disconnected at once.'
+ 'Stop every live link on your license? This also ends links shared from other computers. Viewers on this computer are disconnected at once; links on other computers stop within a few minutes.'
)
expect(api.revokeAll).not.toHaveBeenCalled()
click([...dialog.querySelectorAll('button')].find((b) => b.textContent === 'Cancel')!)
@@ -194,6 +194,48 @@ describe('LiveLinksSection', () => {
expect(document.querySelector('.confirm')).toBeNull()
})
+ // R62: Stop all is the one control that reaches links shared from OTHER machines — so it is there
+ // whenever the owner could have one, not only when THIS machine lists a link.
+ it('R62: Pro with no link listed here still offers Stop all, says why, and reports the success', async () => {
+ render()
+ expect(host.textContent).toContain('No live links are shared from this computer. Stop all also ends the ones shared from other computers on your license.')
+ click(buttons('Stop all')[0])
+ click([...document.querySelectorAll<HTMLButtonElement>('.confirm button')].find((b) => b.textContent === 'Stop all')!)
+ await flush()
+ expect(api.revokeAll).toHaveBeenCalledTimes(1)
+ const said = host.querySelector('[role="status"]')
+ expect(said?.textContent).toBe('Stopped every live link on your license. Links on other computers end within a few minutes.')
+ })
+
+ it('R62: no Stop all without a link or Pro, and never in the Server Edition', () => {
+ useEntitlement.setState({ isPremium: false })
+ render()
+ expect(buttons('Stop all')).toEqual([])
+ act(() => root.unmount())
+ root = createRoot(host)
+ flags.browser = true
+ useEntitlement.setState({ isPremium: true })
+ render()
+ expect(buttons('Stop all')).toEqual([])
+ })
+
+ it('R62: a server call that failed, or no entitlement, is NOT reported as stopped', async () => {
+ render()
+ setLinks([link()])
+ api.revokeAll.mockResolvedValueOnce('failed')
+ click(buttons('Stop all')[0])
+ click([...document.querySelectorAll<HTMLButtonElement>('.confirm button')].find((b) => b.textContent === 'Stop all')!)
+ await flush()
+ expect(host.querySelector('[role="alert"]')?.textContent).toBe(
+ "The stop didn't reach nodeterm — try again. Links on this computer are stopped; links shared from other computers may still be running."
+ )
+ api.revokeAll.mockResolvedValueOnce('no-entitlement')
+ click(buttons('Stop all')[0])
+ click([...document.querySelectorAll<HTMLButtonElement>('.confirm button')].find((b) => b.textContent === 'Stop all')!)
+ await flush()
+ expect(host.querySelector('[role="alert"]')?.textContent).toContain("can't be stopped from here: this computer has no Pro license")
+ })
+
it('a rejected Stop all says so (H23)', async () => {
render()
setLinks([link()])
diff --git a/src/renderer/components/settings/sections/LiveLinksSection.tsx b/src/renderer/components/settings/sections/LiveLinksSection.tsx
index d8b4f2853..0179dcae9 100644
--- a/src/renderer/components/settings/sections/LiveLinksSection.tsx
+++ b/src/renderer/components/settings/sections/LiveLinksSection.tsx
@@ -14,10 +14,12 @@ import {
NOT_IN_OPEN_PROJECT,
ROLE_LABEL,
SERVER_EDITION_UNSUPPORTED,
+ showsStopAll,
statusLine,
- STOP_ALL_BUTTON
+ STOP_ALL_BUTTON,
+ stopAllElsewhereNote
} from '../../../lib/liveLink'
-import { stopAllConfirm, stopLiveLinks } from '../../../lib/liveLinkEntry'
+import { stopAllConfirm, stopAllLiveLinks, stopLiveLinks } from '../../../lib/liveLinkEntry'
import { stripBidiControls, type WatchLinkView } from '@shared/watch-link-types'
import type { Project } from '@shared/types'
@@ -94,7 +96,11 @@ export function LiveLinksSection({ isActive }: { isActive: boolean }): React.JSX
const serverEdition = isBrowserRuntime()
const [now, setNow] = useState(() => Date.now())
const [confirmStopAll, setConfirmStopAll] = useState(false)
- const [stopAllError, setStopAllError] = useState<string | null>(null)
+ /** What the last Stop all reached (R62) — said for a success too: with no link listed on this
+ * machine, nothing else on this page changes. */
+ const [stopAllResult, setStopAllResult] = useState<{ ok: boolean; text: string } | null>(null)
+ const [stoppingAll, setStoppingAll] = useState(false)
+ const stopAllShown = showsStopAll({ serverEdition, entitled: premium, activeLinks: links.length })
useEffect(() => {
if (!isActive) return
setNow(Date.now())
@@ -104,8 +110,12 @@ export function LiveLinksSection({ isActive }: { isActive: boolean }): React.JSX
const confirm = stopAllConfirm({
close: () => setConfirmStopAll(false),
stop: () => {
- setStopAllError(null)
- void stopLiveLinks(() => window.nodeTerminal.watchLink.revokeAll(), setStopAllError)
+ setStopAllResult(null)
+ setStoppingAll(true)
+ void stopAllLiveLinks(() => window.nodeTerminal.watchLink.revokeAll()).then((r) => {
+ setStoppingAll(false)
+ setStopAllResult(r)
+ })
}
})
return (
@@ -127,22 +137,19 @@ export function LiveLinksSection({ isActive }: { isActive: boolean }): React.JSX
<LinkRow key={l.linkId} link={l} now={now} projects={projects} />
))}
</div>
- <div className="flex items-center gap-3">
- <Button onClick={() => setConfirmStopAll(true)}>{STOP_ALL_BUTTON}</Button>
- {stopAllError && (
- <span className="text-xs" role="alert" style={{ color: 'var(--danger)' }}>
- {stopAllError}
- </span>
- )}
- </div>
</div>
) : serverEdition ? (
// R43: no license layer in the Server Edition yet — say so, never offer an Upgrade.
<p className="text-sm text-muted">{SERVER_EDITION_UNSUPPORTED}</p>
) : premium ? (
- <p className="text-sm text-muted">
- No active live links. Right-click a terminal and choose "Share live link…".
- </p>
+ <div className="space-y-1">
+ <p className="text-sm text-muted">
+ No active live links. Right-click a terminal and choose "Share live link…".
+ </p>
+ {/* Links shared from OTHER machines are invisible here, and Stop all is the one control
+ that reaches them (R62): say so, beside the button. */}
+ <p className="text-xs text-muted">{stopAllElsewhereNote()}</p>
+ </div>
) : (
<div className="space-y-3">
<p className="text-sm text-muted">
@@ -154,6 +161,22 @@ export function LiveLinksSection({ isActive }: { isActive: boolean }): React.JSX
</Button>
</div>
)}
+ {stopAllShown && (
+ <div className="mt-3 flex items-center gap-3">
+ <Button disabled={stoppingAll} onClick={() => setConfirmStopAll(true)}>
+ {STOP_ALL_BUTTON}
+ </Button>
+ {stopAllResult && (
+ <span
+ className="text-xs"
+ role={stopAllResult.ok ? 'status' : 'alert'}
+ style={stopAllResult.ok ? undefined : { color: 'var(--danger)' }}
+ >
+ {stopAllResult.text}
+ </span>
+ )}
+ </div>
+ )}
</SearchableRow>
{confirmStopAll && (
<ConfirmDialog
diff --git a/src/renderer/lib/liveLink.test.ts b/src/renderer/lib/liveLink.test.ts
index 759e96642..ce579924f 100644
--- a/src/renderer/lib/liveLink.test.ts
+++ b/src/renderer/lib/liveLink.test.ts
@@ -234,7 +234,7 @@ describe('copy Task 17 reads (R47, R48, R52, H11, H23, H26)', () => {
expect(STOP_ALL_PALETTE_LABEL).toBe('Stop all live links (every machine on this license)')
expect(STOP_ALL_BUTTON).toBe('Stop all')
expect(stopAllConfirmMessage()).toBe(
- 'Stop every live link on your license? This also ends links shared from other computers. Viewers are disconnected at once.'
+ 'Stop every live link on your license? This also ends links shared from other computers. Viewers on this computer are disconnected at once; links on other computers stop within a few minutes.'
)
expect(STOP_FAILED_MESSAGE).toBe("The stop didn't reach nodeterm — try again.")
expect(KICK_FAILED_MESSAGE).toBe("The kick didn't reach nodeterm — try again.")
diff --git a/src/renderer/lib/liveLink.ts b/src/renderer/lib/liveLink.ts
index a1d2e4c59..53f6a1efc 100644
--- a/src/renderer/lib/liveLink.ts
+++ b/src/renderer/lib/liveLink.ts
@@ -8,6 +8,7 @@
// display side's own belt), and every caller renders the result as TEXT, never as HTML.
import type {
CreateWatchLinkError,
+ RevokeAllOutcome,
WatchChatMessage,
WatchLinkNotice,
WatchLinkRole,
@@ -65,8 +66,52 @@ export const CHAT_NOT_SENT_MESSAGE = "Your reply wasn't sent — viewers didn't
/** R48: Stop all revokes every link of the LICENSE, other machines included — both entry points confirm. */
export const STOP_ALL_PALETTE_LABEL = 'Stop all live links (every machine on this license)'
export const STOP_ALL_BUTTON = 'Stop all'
+/** The timing is part of the promise (R62): this machine cuts its own viewers itself, while another
+ * machine learns of the revoke at its next mint (≤ ~90 s) or, for a full link, its status poll. */
export function stopAllConfirmMessage(): string {
- return `Stop every live link on your license? This also ends links shared from ${otherMachines()}. Viewers are disconnected at once.`
+ return `Stop every live link on your license? This also ends links shared from ${otherMachines()}. Viewers on ${thisMachine()} are disconnected at once; links on ${otherMachines()} stop within a few minutes.`
+}
+/** Settings, beside Stop all when THIS machine lists no link: the button still reaches the others. */
+export function stopAllElsewhereNote(): string {
+ return `No live links are shared from ${thisMachine()}. Stop all also ends the ones shared from ${otherMachines()} on your license.`
+}
+
+/**
+ * Where "Stop all" is offered (R62): wherever the owner could have links to stop — this machine lists
+ * one, or holds a Pro license (its links on OTHER machines are invisible here, and Stop all is the one
+ * control that reaches them: an office desktop left sharing, a lost laptop whose links resume at
+ * launch). Never in the Server Edition (R43: no license layer, nothing to stop).
+ */
+export function showsStopAll(o: { serverEdition: boolean; entitled: boolean; activeLinks: number }): boolean {
+ return !o.serverEdition && (o.activeLinks > 0 || o.entitled)
+}
+
+/**
+ * What Stop all says once core answered (R62). This machine's links are always stopped by then; the
+ * outcome is about the server revoke, the only thing that reaches other machines' links, and a
+ * success is reported too — with nothing listed here, the sentence is the only sign anything happened.
+ */
+export function stopAllOutcomeText(o: RevokeAllOutcome | unknown): { ok: boolean; text: string } {
+ switch (o) {
+ case 'stopped':
+ return {
+ ok: true,
+ text: `Stopped every live link on your license. Links on ${otherMachines()} end within a few minutes.`
+ }
+ case 'no-entitlement':
+ return {
+ ok: false,
+ text: `Stopped the live links on ${thisMachine()}. Links shared from ${otherMachines()} can't be stopped from here: ${thisMachine()} has no Pro license. Activate Pro here, or stop them on the machine that shared them.`
+ }
+ case 'unsupported':
+ return { ok: false, text: "Live links can't be stopped from here." }
+ // `failed`, and anything an older core might answer: the server was not reached.
+ default:
+ return {
+ ok: false,
+ text: `${STOP_FAILED_MESSAGE} Links on ${thisMachine()} are stopped; links shared from ${otherMachines()} may still be running.`
+ }
+ }
}
/** H11: a Settings row whose node no open project holds. */
export const NOT_IN_OPEN_PROJECT = 'not in an open project'
diff --git a/src/renderer/lib/liveLinkEntry.test.tsx b/src/renderer/lib/liveLinkEntry.test.tsx
index c1e3bd7be..ee500e84d 100644
--- a/src/renderer/lib/liveLinkEntry.test.tsx
+++ b/src/renderer/lib/liveLinkEntry.test.tsx
@@ -9,6 +9,7 @@ import {
liveLinkUnavailable,
openLiveLink,
stopAllConfirm,
+ stopAllLiveLinks,
stopLiveLinks,
type LiveLinkAvailabilityFacts
} from './liveLinkEntry'
@@ -210,8 +211,9 @@ describe('Stop all (R48)', () => {
const close = vi.fn()
const stop = vi.fn()
const spec = stopAllConfirm({ close, stop })
+ // R62: the timing is part of the promise — at once HERE, within minutes elsewhere.
expect(spec.message).toBe(
- 'Stop every live link on your license? This also ends links shared from other computers. Viewers are disconnected at once.'
+ 'Stop every live link on your license? This also ends links shared from other computers. Viewers on this computer are disconnected at once; links on other computers stop within a few minutes.'
)
expect(spec.confirmLabel).toBe('Stop all')
expect(spec.danger).toBe(true)
@@ -231,13 +233,54 @@ describe('Stop all (R48)', () => {
})
})
+// R62: what Stop all reached is always said. This machine's links are stopped whatever the answer;
+// the outcome is about the server revoke, the only thing that reaches the OTHER machines' links.
+describe('stopAllLiveLinks (R62)', () => {
+ it('a success is reported too (with nothing listed here, nothing else on screen changes)', async () => {
+ expect(await stopAllLiveLinks(async () => 'stopped')).toEqual({
+ ok: true,
+ text: 'Stopped every live link on your license. Links on other computers end within a few minutes.'
+ })
+ })
+ it('no entitlement: this machine stopped, the others could not be — and why', async () => {
+ const r = await stopAllLiveLinks(async () => 'no-entitlement')
+ expect(r.ok).toBe(false)
+ expect(r.text).toBe(
+ "Stopped the live links on this computer. Links shared from other computers can't be stopped from here: this computer has no Pro license. Activate Pro here, or stop them on the machine that shared them."
+ )
+ })
+ it('a failed server call is NOT a success: the others may still be running', async () => {
+ const r = await stopAllLiveLinks(async () => 'failed')
+ expect(r).toEqual({
+ ok: false,
+ text: `${STOP_FAILED_MESSAGE} Links on this computer are stopped; links shared from other computers may still be running.`
+ })
+ // An answer this build does not know (an older core) reads the same way, never as a success.
+ expect((await stopAllLiveLinks(async () => undefined as never)).ok).toBe(false)
+ })
+ it('a rejection (the Server Edition socket was down) says nothing reached nodeterm', async () => {
+ expect(await stopAllLiveLinks(() => Promise.reject(new Error('socket')))).toEqual({ ok: false, text: STOP_FAILED_MESSAGE })
+ })
+ it('unsupported says so', async () => {
+ expect((await stopAllLiveLinks(async () => 'unsupported')).ok).toBe(false)
+ })
+})
+
describe('liveLinkCommands (palette)', () => {
- it('Manage always; Stop all only with links, labelled for every machine, and it CONFIRMS', () => {
+ const base = { entitled: false, serverEdition: false, icon: null }
+ it('Manage always; Stop all with links OR a Pro license (R62), labelled for every machine, and it CONFIRMS', () => {
const manage = vi.fn()
const confirmStopAll = vi.fn()
- const none = liveLinkCommands({ activeLinks: 0, icon: null, manage, confirmStopAll })
+ const none = liveLinkCommands({ ...base, activeLinks: 0, manage, confirmStopAll })
expect(none.map((c) => c.id)).toEqual(['live-links-manage'])
- const some = liveLinkCommands({ activeLinks: 2, icon: null, manage, confirmStopAll })
+ // Pro, and nothing listed HERE: links shared from another machine are invisible on this one,
+ // and Stop all is the only control that reaches them.
+ const entitled = liveLinkCommands({ ...base, entitled: true, activeLinks: 0, manage, confirmStopAll })
+ expect(entitled.map((c) => c.id)).toEqual(['live-links-manage', 'live-links-stop-all'])
+ // Never in the Server Edition (R43): no license layer, nothing to stop.
+ const server = liveLinkCommands({ ...base, serverEdition: true, entitled: true, activeLinks: 3, manage, confirmStopAll })
+ expect(server.map((c) => c.id)).toEqual(['live-links-manage'])
+ const some = liveLinkCommands({ ...base, activeLinks: 2, manage, confirmStopAll })
expect(some.map((c) => c.id)).toEqual(['live-links-manage', 'live-links-stop-all'])
expect(some[0].label).toBe('Manage live links')
expect(some[1].label).toBe('Stop all live links (every machine on this license)')
diff --git a/src/renderer/lib/liveLinkEntry.tsx b/src/renderer/lib/liveLinkEntry.tsx
index f9d7c1c97..fcae60e1c 100644
--- a/src/renderer/lib/liveLinkEntry.tsx
+++ b/src/renderer/lib/liveLinkEntry.tsx
@@ -11,14 +11,17 @@ import type { ReactNode } from 'react'
import type { Command } from '../components/CommandPalette'
import type { MenuItem } from '../components/ContextMenu'
import type { SessionSource } from '../session/session'
+import type { RevokeAllOutcome } from '@shared/watch-link-types'
import {
PRO_GATE_FEATURE,
SAVE_FIRST_MESSAGE,
shareDisabledReason,
+ showsStopAll,
STOP_ALL_BUTTON,
STOP_ALL_PALETTE_LABEL,
STOP_FAILED_MESSAGE,
- stopAllConfirmMessage
+ stopAllConfirmMessage,
+ stopAllOutcomeText
} from './liveLink'
import { syncMessageScope } from './messageScopeSync'
import { isHidden } from './ui-visibility'
@@ -168,9 +171,9 @@ export function stopAllConfirm(o: { close: () => void; stop: () => void }): {
}
}
-/** Run a stop (one revoke, or revoke-all) and report a rejection (H23 — the Server Edition's
- * socket can be down). Desktop IPC never rejects; this is the belt, not the common path.
- * Resolves true when the stop went through. */
+/** Run one link's stop and report a rejection (H23 — the Server Edition's socket can be down).
+ * Desktop IPC never rejects; this is the belt, not the common path. Resolves true when the stop
+ * went through. Stop all is `stopAllLiveLinks`: it has an answer to report, not just a rejection. */
export async function stopLiveLinks(stop: () => Promise<void>, onError: (text: string) => void): Promise<boolean> {
try {
await stop()
@@ -181,10 +184,31 @@ export async function stopLiveLinks(stop: () => Promise<void>, onError: (text: s
}
}
-/** The palette's live-link entries. "Stop all" appears only while this machine lists a link, and
- * its `run` opens the confirm — it never stops anything itself. */
+/**
+ * R62: run Stop all and say what it reached — a success too (with no link listed here, that sentence
+ * is the only sign anything happened). This machine's links are stopped whatever the answer; the
+ * outcome is about the server revoke that reaches the others. A rejection (the Server Edition's socket
+ * was down) means nothing reached nodeterm. Never rejects.
+ */
+export async function stopAllLiveLinks(
+ revokeAll: () => Promise<RevokeAllOutcome>
+): Promise<{ ok: boolean; text: string }> {
+ try {
+ return stopAllOutcomeText(await revokeAll())
+ } catch {
+ return { ok: false, text: STOP_FAILED_MESSAGE }
+ }
+}
+
+/** The palette's live-link entries. "Stop all" appears wherever the owner could have links to stop
+ * (`showsStopAll`: a link listed here, OR a Pro license — its links on other machines are invisible
+ * here), and its `run` opens the confirm — it never stops anything itself. */
export function liveLinkCommands(o: {
activeLinks: number
+ /** Pro is active on this machine (`useEntitlement` `isPremium`). */
+ entitled: boolean
+ /** `isBrowserRuntime()`: no license layer there (R43), so nothing to stop. */
+ serverEdition: boolean
icon: ReactNode
manage: () => void
confirmStopAll: () => void
@@ -197,7 +221,7 @@ export function liveLinkCommands(o: {
icon: o.icon,
run: o.manage
},
- ...(o.activeLinks > 0
+ ...(showsStopAll({ serverEdition: o.serverEdition, entitled: o.entitled, activeLinks: o.activeLinks })
? [
{
id: 'live-links-stop-all',
diff --git a/src/shared/watch-link-types.ts b/src/shared/watch-link-types.ts
index 9d187930c..65c4e87ca 100644
--- a/src/shared/watch-link-types.ts
+++ b/src/shared/watch-link-types.ts
@@ -95,13 +95,27 @@ export type WatchLinkNotice =
* saved" unless the renderer knows it is the first cause. */
| { kind: 'not-persistent' }
+/**
+ * What "Stop all" reached. THIS machine's links always stop at once, before the answer; the answer
+ * is about the license-wide server revoke, the only thing that ends links shared from other machines:
+ * - `stopped` — the server accepted it: every other machine's links end at their next mint (≤ ~90 s)
+ * or, while a link is full, at its status poll (≤ 5 min).
+ * - `no-entitlement` — no Pro entitlement is stored here, so the server was not asked: links on
+ * other machines keep running.
+ * - `failed` — the server call failed (no answer, a refusal, an expired token): they keep running.
+ * - `unsupported` — this surface stops nothing (the Server Edition until it has a license layer, a
+ * relay tab, a client that is not the machine's owner).
+ */
+export type RevokeAllOutcome = 'stopped' | 'no-entitlement' | 'failed' | 'unsupported'
+
/** `window.nodeTerminal.watchLink`. Desktop: real (preload). Server Edition: real bridge, and create
* answers `unsupported` until that edition has a license layer. Relay tab: an inert stub. */
export interface WatchLinkApi {
create(req: CreateWatchLinkRequest): Promise<CreateWatchLinkResult>
list(): Promise<WatchLinkView[]>
revoke(linkId: string): Promise<void>
- revokeAll(): Promise<void>
+ /** Stop every link of the license, other machines included. Resolves once the server answered. */
+ revokeAll(): Promise<RevokeAllOutcome>
kick(linkId: string, viewerId: string): Promise<boolean>
/** A Commenter link's owner reply; null when the link is not a Commenter link or the text is empty. */
sendChat(linkId: string, text: string): Promise<WatchChatMessage | null>