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.

feat(core): open-project count from the workspace index

review43c8c374e261
diff --git a/src/core/workspace-store.test.ts b/src/core/workspace-store.test.ts
index 47f8e78bf..4594f316e 100644
--- a/src/core/workspace-store.test.ts
+++ b/src/core/workspace-store.test.ts
@@ -2549,3 +2549,37 @@ describe('knownNodeIds — every node id in every project, or undefined when it
expect(new WorkspaceStore().knownNodeIdsStrict()).toBeUndefined() // not loaded: unknown to both
})
})
+
+describe('openProjectCount — open projects in the loaded index (the project-limit report)', () => {
+ it('is undefined before the index is loaded', () => {
+ expect(new WorkspaceStore().openProjectCount()).toBeUndefined()
+ })
+ it('counts the loaded entries that are not closed', async () => {
+ await new WorkspaceStore().save(ws([
+ project({ id: 'p-local', cwd: projRoot }),
+ project({ id: 'p-inline', nodes: [] }),
+ project({ id: 'p-closed', nodes: [], closed: true, closedAt: 1_700_000_000_000 })
+ ]))
+ const store = new WorkspaceStore()
+ await store.load()
+ expect(store.openProjectCount()).toBe(2)
+ })
+ // An index entry whose project file could not be read is still a tab on the user's screen.
+ it('counts an unavailable placeholder: it is still an open tab', async () => {
+ await new WorkspaceStore().save(ws([project({ id: 'p-local', cwd: projRoot }), project({ id: 'p-inline', nodes: [] })]))
+ await fs.rm(projRoot, { recursive: true, force: true })
+ const store = new WorkspaceStore()
+ const loaded = await store.load()
+ expect(loaded.projects.find((p) => p.id === 'p-local')?.unavailable).toBe(true)
+ expect(store.openProjectCount()).toBe(2)
+ })
+ // A relay tab is never written to the index, so it can never be counted from it.
+ it('never counts a relay tab', async () => {
+ const store = new WorkspaceStore()
+ await store.save(ws([project({ id: 'p-inline', nodes: [] }), project({ id: 'p-relay', nodes: [], remote: true })]))
+ expect(store.openProjectCount()).toBe(1)
+ const fresh = new WorkspaceStore()
+ await fresh.load()
+ expect(fresh.openProjectCount()).toBe(1)
+ })
+})
diff --git a/src/core/workspace-store.ts b/src/core/workspace-store.ts
index 3018bae25..a20614f8f 100644
--- a/src/core/workspace-store.ts
+++ b/src/core/workspace-store.ts
@@ -46,6 +46,7 @@ import { boardLabels, cardMeta } from '../shared/kanban-labels'
import { localizeAdoptedNode } from '../shared/adopt-cwd'
import { routeSshProjectNode, routeSshProjectNodes } from '../shared/ssh-project-nodes'
import { clampProjectName, folderName } from '../shared/project-name'
+import { countOpenProjects } from '../shared/project-limit'
import { SYSTEM_NODE_COLORS } from '../shared/node-colors'
import { codedError } from './relay/admin-error'
import { createLaunchClaimLedger } from './launch-claim-ledger'
@@ -2204,6 +2205,13 @@ export class WorkspaceStore {
.map((e) => ({ id: e.id, ssh: e.ssh as NonNullable<Project['ssh']> }))
}
+ /** How many projects of the loaded index are open (`countOpenProjects`), or undefined before the
+ * index is loaded. The index never holds a relay tab (`splitWorkspace` drops them), and an
+ * unavailable placeholder is an entry like any other — it is still an open tab. Sync. */
+ openProjectCount(): number | undefined {
+ return this.index ? countOpenProjects(this.index.entries) : undefined
+ }
+
/** Every project in the loaded index as a `nodeterm://open` link may name it (main/open-link.ts):
* id, name, folder, closed, and the two kinds a link never offers (SSH, handed to a hosted team).
* Undefined before the index is loaded. Sync, like `localCwdForProject`. */
diff --git a/src/shared/project-limit.test.ts b/src/shared/project-limit.test.ts
new file mode 100644
index 000000000..26bbd13fa
--- /dev/null
+++ b/src/shared/project-limit.test.ts
@@ -0,0 +1,12 @@
+import { describe, it, expect } from 'vitest'
+import { countOpenProjects } from './project-limit'
+
+describe('countOpenProjects — the one definition of an open project', () => {
+ it('counts every project that is neither closed nor a relay tab', () => {
+ expect(countOpenProjects([{}, { closed: true }, { remote: true }, { closed: false }])).toBe(2)
+ })
+
+ it('is 0 for an empty workspace', () => {
+ expect(countOpenProjects([])).toBe(0)
+ })
+})
diff --git a/src/shared/project-limit.ts b/src/shared/project-limit.ts
new file mode 100644
index 000000000..13d71ccc0
--- /dev/null
+++ b/src/shared/project-limit.ts
@@ -0,0 +1,16 @@
+/**
+ * The free-tier open-project limit (docs/superpowers/specs/2026-10-29-free-tier-project-limit-design.md).
+ */
+
+/**
+ * How many of `projects` are OPEN — the one definition, shared by the open-project report and the
+ * gate (spec §3). A project is open when it is in the workspace, not `closed` (a "Recently closed"
+ * entry) and not a relay tab (`remote` — a live connection to another machine's project, never a
+ * workspace on this disk). SSH projects, cwd-less canvases and unavailable placeholders all count:
+ * each is a tab on the user's screen.
+ */
+export function countOpenProjects(projects: readonly { closed?: boolean; remote?: boolean }[]): number {
+ let open = 0
+ for (const p of projects) if (!p.closed && !p.remote) open++
+ return open
+}