Ignore dormant apps: per-app and per-store 'ignored' in the app list; apps ignore/unignore, watch, ws and apps list skip them; MCP tools

This commit is contained in:
CRTkafa 2026-10-23 00:57:42 +08:00
parent 75bf62e125
commit 13b91dd423
7 changed files with 278 additions and 30 deletions

View file

@ -27,7 +27,7 @@ import * as rt from './lib/rt';
import { existsSync, readFileSync } from 'node:fs';
import { basename, join, resolve } from 'node:path';
import { CONFIG_NAMES } from './lib/config';
import { addFolder, addStoreApp, applyRelink, configAppName, configFolders, readRegistry, registryFile, relinkPlan, removeFolder, removeStoreApp } from './lib/registry';
import { activeProjects, activeStoreApps, addFolder, withIgnore, addStoreApp, applyRelink, configAppName, configFolders, type IgnoreStore, ignoredStoreIds, ignoredStores, isIgnored, readRegistry, registryFile, relinkPlan, removeFolder, removeStoreApp, setIgnore } from './lib/registry';
import { homedir } from 'node:os';
type Store = 'apple' | 'play';
@ -170,13 +170,27 @@ async function folders(sub: string, args: Args): Promise<void> {
if (sub === 'folders' && args._[1]) throw new Error(`storebound apps folders ${args._[1]}: unknown; to add a folder: storebound apps add [<folder>] (or apps folders add [<folder>]), to list: storebound apps folders`);
if (sub === 'folders') {
const r = readRegistry();
if (args.has('json')) { printJson({ file: registryFile(), projects: r.projects.map(p => ({ ...p, missing: !existsSync(p.path) })), storeApps: r.storeApps ?? [] }); return; }
if (r.storeApps?.length) {
console.log(textTable(['store app', 'store', 'app id', 'profile', ''], r.storeApps.map(a => [a.name, a.store, a.appId, a.account ?? '(default)', 'no local project'])));
const ignoredCount = r.projects.filter(p => ignoredStores(p).length).length + (r.storeApps ?? []).filter(a => isIgnored(a)).length;
if (args.has('json')) {
printJson({ file: registryFile(), projects: r.projects.map(p => ({ ...p, missing: !existsSync(p.path), ignored: ignoredStores(p), allIgnored: isIgnored(p) })), storeApps: r.storeApps ?? [] });
return;
}
const liveStore = activeStoreApps(r);
if (liveStore.length) {
console.log(textTable(['store app', 'store', 'app id', 'profile', ''], liveStore.map(a => [a.name, a.store, a.appId, a.account ?? '(default)', 'no local project'])));
console.log('');
}
if (!r.projects.length) { console.log(`no app folders yet (${tilde(registryFile())}): storebound apps add, in an app folder (or storebound desktop there)`); return; }
console.log(textTable(['app', 'folder', ''], r.projects.map(p => [p.name, tilde(p.path), existsSync(p.path) ? '' : 'folder not found'])));
const live = activeProjects(r);
if (!r.projects.length && !liveStore.length) { console.log(`no app folders yet (${tilde(registryFile())}): storebound apps add, in an app folder (or storebound desktop there)`); return; }
if (live.length) console.log(textTable(['app', 'folder', ''], live.map(p => [p.name, tilde(p.path), [existsSync(p.path) ? '' : 'folder not found', ignoredStores(p).length ? `${ignoredStores(p).join('+')} ignored` : ''].filter(Boolean).join(', ')])));
if (ignoredCount) {
console.log(`
ignored (${ignoredCount}; storebound apps unignore <name|id> [--store apple|play] brings them back):`);
console.log(textTable(['app', 'where', 'ignored'], [
...r.projects.filter(p => isIgnored(p)).map(p => [p.name, tilde(p.path), 'apple+play']),
...(r.storeApps ?? []).filter(a => isIgnored(a)).map(a => [a.name, `${a.store}:${a.appId}`, a.store]),
]));
}
const missing = r.projects.filter(p => !existsSync(p.path)).length;
if (missing) console.log(`\n${missing} folder(s) not found (moved to another computer or folder?): storebound apps relink --dry finds them by path and app name`);
console.log(`
@ -222,6 +236,21 @@ ${tilde(registryFile())}: the same list as the desktop app's App folders`);
log('apps', removed ? `removed ${tilde(removed.path)} from the list (the folder and its files stay)` : `${tilde(dir)} is not in the list`);
}
/** apps ignore / unignore <name|id|folder|store:app id> [--store apple|play]: dormant apps, whole or one store side. */
function ignoreCmd(on: boolean, args: Args): void {
const key = args._[1];
const store = args.get('store') as IgnoreStore | undefined;
if (!key) throw new Error(`storebound apps ${on ? 'ignore' : 'unignore'} <name|id|folder|apple:<id>|play:<package>> [--store apple|play]`);
if (store !== undefined && store !== 'apple' && store !== 'play') throw new Error('--store: apple or play');
const { entry, changed } = args.has('dry') ? (({ entry, changed }) => ({ entry, changed }))(withIgnore(readRegistry(), key, store, on)) : setIgnore(key, store, on);
if (args.has('dry')) { log('apps', `dry run: ${changed ? `would ${on ? 'ignore' : 'restore'} ${store ? `the ${store} side of ` : ''}${entry.name}` : `${entry.name}: nothing to change`}`); return; }
const now = ignoredStores(entry);
const where = store ? `the ${store} side of ` : '';
if (args.has('json')) { printJson({ name: entry.name, id: entry.id, ignored: now, changed }); return; }
log('apps', changed ? `${on ? 'ignoring' : 'restored'} ${where}${entry.name}${now.length ? ` (ignored now: ${now.join(', ')})` : ''}: watch, events and portfolio reads ${on ? 'skip' : 'read'} it. Storebound only: the store listing is untouched`
: `${entry.name} was already ${on ? 'ignored' : 'not ignored'}${store ? ` on ${store}` : ''}`);
}
/** apps relink: point "folder not found" entries at the same app on this machine (after a move); ids stay. */
function relink(args: Args): void {
const home = homedir();
@ -242,6 +271,7 @@ export async function run(args: Args): Promise<void> {
const json = args.has('json');
if (sub === 'relink') return relink(args);
if (sub === 'folders' || sub === 'add' || sub === 'remove') return folders(sub, args);
if (sub === 'ignore' || sub === 'unignore') return ignoreCmd(sub === 'ignore', args);
if (sub === 'list') {
const out: AppsListResult[] = [];
for (const s of stores(args, root)) {
@ -253,10 +283,21 @@ export async function run(args: Args): Promise<void> {
warn('apps', `${s}: ${why}`);
}
}
if (json) { printJson(args.get('store') ? out[0] : out); return; }
// ignored apps (registry: whole app or this store's side) are listed apart, not with the live ones; --all keeps them in
const ign = ignoredStoreIds(readRegistry());
const sideOf = (r: AppsListResult) => (r.store === 'ios' ? ign.apple : ign.play);
const isIgn = (r: AppsListResult, a: { id: string; bundleId: string }) => sideOf(r).has(a.id) || sideOf(r).has(a.bundleId);
if (json) {
const marked = out.map(r => ({ ...r, apps: r.apps.map(a => (isIgn(r, a) ? { ...a, ignored: true } : a)) }));
printJson(args.get('store') ? marked[0] : marked);
return;
}
for (const r of out) {
log('apps', `${r.store === 'ios' ? 'App Store Connect' : 'Google Play'}: ${r.apps.length} apps`);
console.log(textTable(['name', 'id', 'bundle / package', 'platforms', 'newest'], r.apps.map(a => [a.name, a.id, a.bundleId, a.platforms.join(' '), a.latest ? `${a.latest.version} ${a.latest.state}` : ''])));
const mine = r.apps.filter(a => !isIgn(r, a)), hidden = r.apps.filter(a => isIgn(r, a));
const rows = (l: typeof r.apps) => l.map(a => [a.name, a.id, a.bundleId, a.platforms.join(' '), a.latest ? `${a.latest.version} ${a.latest.state}` : '']);
log('apps', `${r.store === 'ios' ? 'App Store Connect' : 'Google Play'}: ${mine.length} apps${hidden.length ? ` (+${hidden.length} ignored)` : ''}`);
console.log(textTable(['name', 'id', 'bundle / package', 'platforms', 'newest'], rows(mine)));
if (hidden.length) { console.log(`ignored (storebound apps unignore):`); console.log(textTable(['name', 'id', 'bundle / package', 'platforms', 'newest'], rows(hidden))); }
for (const w of r.warnings) warn('apps', w);
}
return;
@ -273,7 +314,7 @@ export async function run(args: Args): Promise<void> {
if (out.some(c => c.status !== 'ok')) process.exitCode = 1;
return;
}
console.error('usage: storebound apps list [--store apple|play] [--icons] [--json] | apps check [--store apple|play] [--json] | apps folders [--json] | apps add [<folder>] | apps add --store apple|play --app-id <id> [--account <profile>] | apps remove <folder> | apps remove apple:<id>');
console.error('usage: storebound apps list [--store apple|play] [--icons] [--json] | apps check [--store apple|play] [--json] | apps folders [--json] | apps ignore|unignore <name|id> [--store apple|play] | apps add [<folder>] | apps add --store apple|play --app-id <id> [--account <profile>] | apps remove <folder> | apps remove apple:<id>');
process.exit(2);
}

View file

@ -14,7 +14,7 @@ export const PLAIN: Record<string, [() => Promise<Plain>, string]> = {
'watch': [() => import('./watch'), 'store events for every app on this machine: rejected, approved, live, rollout halted, crash threshold, low reviews; loops every --every 15m or --once; sinks --notify os|ntfy|telegram|webhook; test sends a test event; --dry, --dir <folder>, --json (read-only on the stores)'],
'events': [() => import('./events'), '[--since 24h] [--app <name>] [--kind rejected] [--json]: the events watch recorded in ~/.storebound/events.jsonl (read-only)'],
'serve': [() => import('./serve'), '--stdio: JSON-RPC session for the storebound desktop app (dry runs; writes need a host confirm token)'],
'apps': [() => import('./apps'), 'list (every app the store keys can see: App Store Connect team, Play developer accounts; --icons) | check (key works / permission missing / revoked, with the fix); --store apple|play, --json; read-only | folders | add [<folder>] | remove <folder>: the app folders of this machine, the same list as the desktop app'],
'apps': [() => import('./apps'), 'list (every app the store keys can see: App Store Connect team, Play developer accounts; --icons) | check (key works / permission missing / revoked, with the fix); --store apple|play, --json; read-only | folders | add [<folder>] | remove <folder>: the app folders of this machine, the same list as the desktop app | ignore|unignore <name|id> [--store apple|play]: leave a dormant app (or one store side) out of watch, portfolio reads and the desktop lists; storebound only, the store is untouched'],
'desktop': [() => import('./desktop'), 'open the storebound desktop app on this folder; not installed or another version: download it for this system (size, SHA-256, signature checked), install it for this user (asks once; --yes) and open it; --download only saves the installer, --dry / --json change nothing'],
'accounts': [() => import('./accounts'), 'the store accounts of this machine (credential profiles in ~/.storebound/credentials, shared with the desktop app): list | import (a project\'s store keys -> a profile; --dry first) | use <profile> | default <profile> (the machine default; --clear)'],
'settings': [() => import('./settings'), 'per-machine settings: bypass on | off | status (owner opt-in: the agent also presses the owner-only buttons; default off)'],

View file

@ -16,10 +16,15 @@ import { copyFileSync, existsSync, mkdirSync, readdirSync, readFileSync, renameS
import { homedir } from 'node:os';
import { basename, dirname, join, resolve } from 'node:path';
export interface RegistryProject { id: string; path: string; name: string; added: string }
/** The store sides an entry can be ignored on. */
export type IgnoreStore = 'apple' | 'play';
export const IGNORE_STORES: IgnoreStore[] = ['apple', 'play'];
/** `ignored` (optional, on both kinds of entry): the store sides storebound leaves out of watch, events, portfolio reads and the
* desktop lists. Both listed = the whole app is ignored. Storebound-side visibility only: nothing changes in the stores. */
export interface RegistryProject { id: string; path: string; name: string; added: string; ignored?: IgnoreStore[] }
/** A store app without a local project: store + app id (Apple: the numeric app id; Play: the package name), the
* credential profile that reads it. */
export interface StoreOnlyApp { id: string; store: 'apple' | 'play'; appId: string; account: string | null; name: string; bundleId: string | null; added: string }
export interface StoreOnlyApp { id: string; store: 'apple' | 'play'; appId: string; account: string | null; name: string; bundleId: string | null; added: string; ignored?: IgnoreStore[] }
export interface Registry { version: 1; projects: RegistryProject[]; storeApps?: StoreOnlyApp[] }
export const registryFile = (env: Record<string, string | undefined> = process.env): string => env.STOREBOUND_REGISTRY || join(homedir(), '.storebound', 'projects.json');
@ -34,6 +39,9 @@ export const storeAppId = (store: 'apple' | 'play', appId: string): string => cr
export const APPLE_APP_ID = /^\d{6,12}$/;
export const PACKAGE_NAME = /^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)+$/;
/** The valid, unique, ordered store sides of a raw `ignored` value. */
const parseIgnored = (v: unknown): IgnoreStore[] => (Array.isArray(v) ? IGNORE_STORES.filter(x => v.includes(x)) : []);
/** Store-only entries of the file's JSON; malformed ones are dropped. Pure. */
function parseStoreApps(list: unknown): StoreOnlyApp[] {
const out: StoreOnlyApp[] = [];
@ -44,7 +52,7 @@ function parseStoreApps(list: unknown): StoreOnlyApp[] {
if (!(o.store === 'apple' ? APPLE_APP_ID : PACKAGE_NAME).test(appId) || out.some(a => a.store === o.store && a.appId === appId)) continue;
out.push({ id: storeAppId(o.store, appId), store: o.store, appId, account: typeof o.account === 'string' && o.account ? o.account : null,
name: typeof o.name === 'string' && o.name.trim() ? o.name : appId, bundleId: typeof o.bundleId === 'string' && o.bundleId ? o.bundleId : o.store === 'play' ? appId : null,
added: typeof o.added === 'string' ? o.added : '' });
added: typeof o.added === 'string' ? o.added : '', ...(parseIgnored(o.ignored).length ? { ignored: parseIgnored(o.ignored) } : {}) });
}
return out;
}
@ -60,7 +68,8 @@ export function parseRegistry(text: string): Registry {
if (typeof o?.path !== 'string' || !o.path.startsWith('/') && !/^[A-Za-z]:[\\/]/.test(o.path)) continue;
if (out.some(x => x.path === o.path)) continue;
out.push({ id: typeof o.id === 'string' && ID.test(o.id) && !out.some(x => x.id === o.id) ? o.id : folderId(o.path), path: o.path,
name: typeof o.name === 'string' && o.name.trim() ? o.name : basename(o.path), added: typeof o.added === 'string' ? o.added : '' });
name: typeof o.name === 'string' && o.name.trim() ? o.name : basename(o.path), added: typeof o.added === 'string' ? o.added : '',
...(parseIgnored(o.ignored).length ? { ignored: parseIgnored(o.ignored) } : {}) });
}
const storeApps = parseStoreApps((raw as { storeApps?: unknown })?.storeApps);
return storeApps.length ? { version: 1, projects: out, storeApps } : { version: 1, projects: out };
@ -98,7 +107,7 @@ export function withStoreApp(r: Registry, a: { store: 'apple' | 'play'; appId: s
const list = r.storeApps ?? [];
const have = list.find(x => x.store === a.store && x.appId === appId);
const app: StoreOnlyApp = { id: storeAppId(a.store, appId), store: a.store, appId, account: a.account ?? have?.account ?? null, name: a.name?.trim() || have?.name || appId,
bundleId: a.bundleId ?? have?.bundleId ?? (a.store === 'play' ? appId : null), added: have?.added ?? now };
bundleId: a.bundleId ?? have?.bundleId ?? (a.store === 'play' ? appId : null), added: have?.added ?? now, ...(have?.ignored?.length ? { ignored: have.ignored } : {}) };
if (have && JSON.stringify(have) === JSON.stringify(app)) return { registry: r, app: have, added: false };
return { registry: { ...r, version: 1, storeApps: [...list.filter(x => x !== have), app] }, app, added: !have };
}
@ -112,6 +121,86 @@ export function withoutStoreApp(r: Registry, key: string): { registry: Registry;
return { registry: rest.length ? { ...base, storeApps: rest } : base, removed };
}
// ---- ignore: dormant apps (whole app or one store side) ----
/** The store sides of an entry that are ignored. A store-only entry has one side: its store. */
export const ignoredStores = (e: RegistryProject | StoreOnlyApp): IgnoreStore[] => (e.ignored ?? []).filter(x => !('store' in e) || x === e.store);
/** Whether the entry is ignored on `store`, or (no store) entirely: every side it has. */
export function isIgnored(e: RegistryProject | StoreOnlyApp, store?: IgnoreStore): boolean {
const have = ignoredStores(e);
if (store) return have.includes(store);
return 'store' in e ? have.length > 0 : IGNORE_STORES.every(x => have.includes(x));
}
type Found = { entry: RegistryProject | StoreOnlyApp; kind: 'project' | 'storeApp' };
/** Finds one entry by id, folder path, "<store>:<app id>" or (unique, case-insensitive) name. Throws when it is ambiguous. */
export function findEntry(r: Registry, key: string): Found | null {
const all: Found[] = [...r.projects.map(entry => ({ entry, kind: 'project' as const })), ...(r.storeApps ?? []).map(entry => ({ entry, kind: 'storeApp' as const }))];
const abs = ID.test(key) ? '' : resolve(key);
const exact = all.filter(x => x.entry.id === key || ('path' in x.entry ? x.entry.path === abs : `${x.entry.store}:${x.entry.appId}` === key));
if (exact.length === 1) return exact[0]!;
const named = all.filter(x => x.entry.name.toLowerCase() === key.toLowerCase());
if (named.length > 1) throw new Error(`"${key}" matches ${named.length} apps (${named.map(x => ('path' in x.entry ? x.entry.path : `${x.entry.store}:${x.entry.appId}`)).join(', ')}): use the id, folder or <store>:<app id>`);
return named[0] ?? null;
}
/** Ignores (on) or restores one entry, on one store side or on all of it. Pure. */
export function withIgnore(r: Registry, key: string, store: IgnoreStore | undefined, on: boolean): { registry: Registry; entry: RegistryProject | StoreOnlyApp; changed: boolean } {
const f = findEntry(r, key);
if (!f) throw new Error(`${key}: not in the app list (storebound apps folders)`);
if (store && !IGNORE_STORES.includes(store)) throw new Error('--store: apple or play');
const only = f.kind === 'storeApp' ? (f.entry as StoreOnlyApp).store : null;
if (only && store && store !== only) throw new Error(`${f.entry.name} is a ${only} app only: it has no ${store} side to ${on ? 'ignore' : 'restore'}`);
const sides: IgnoreStore[] = only ? [only] : store ? [store] : IGNORE_STORES;
const cur = f.entry.ignored ?? [];
const next = IGNORE_STORES.filter(x => (on ? cur.includes(x) || sides.includes(x) : cur.includes(x) && !sides.includes(x)));
if (next.join() === cur.join()) return { registry: r, entry: f.entry, changed: false };
const { ignored: _drop, ...rest } = f.entry;
const entry = { ...rest, ...(next.length ? { ignored: next } : {}) } as RegistryProject | StoreOnlyApp;
const swap = <T extends RegistryProject | StoreOnlyApp>(list: T[]): T[] => list.map(x => (x === f.entry ? entry as T : x));
return {
registry: { ...r, projects: f.kind === 'project' ? swap(r.projects) : r.projects, ...(r.storeApps ? { storeApps: f.kind === 'storeApp' ? swap(r.storeApps) : r.storeApps } : {}) },
entry, changed: true,
};
}
export function setIgnore(key: string, store: IgnoreStore | undefined, on: boolean, file = registryFile()): { entry: RegistryProject | StoreOnlyApp; changed: boolean } {
const { registry, entry, changed } = withIgnore(readRegistry(file), key, store, on);
if (changed) writeRegistry(registry, file);
return { entry, changed };
}
/** The folders that are not ignored on `store` (no store: not ignored at all). */
export const activeProjects = (r: Registry, store?: IgnoreStore): RegistryProject[] => r.projects.filter(p => !isIgnored(p, store));
/** The store-only apps that are not ignored. */
export const activeStoreApps = (r: Registry): StoreOnlyApp[] => (r.storeApps ?? []).filter(a => !isIgnored(a));
/** Store ids the config of a folder names (read as text, never run): Apple app ids / bundle ids and the Play package. */
export function configStoreIds(dir: string): { apple: string[]; play: string[] } {
const out = { apple: [] as string[], play: [] as string[] };
for (const n of ['storebound.config.ts', 'storebound.config.mts', 'storebound.config.js', 'storebound.config.mjs', 'storebound.config.json']) {
let t: string;
try { t = readFileSync(join(dir, n), 'utf8'); } catch { continue; }
for (const m of t.matchAll(/\b(?:bundleId|appId)["']?\s*:\s*["'`]([A-Za-z0-9._-]+)["'`]/g)) out.apple.push(m[1]!);
for (const m of t.matchAll(/\bpackageName["']?\s*:\s*["'`]([A-Za-z]\w*(?:\.[A-Za-z]\w*)+)["'`]/g)) out.play.push(m[1]!);
break;
}
return out;
}
/** The store ids (Apple app ids and bundle ids, Play packages) of everything ignored on that store. */
export function ignoredStoreIds(r: Registry): { apple: Set<string>; play: Set<string> } {
const o = { apple: new Set<string>(), play: new Set<string>() };
for (const p of r.projects) {
const ids = configStoreIds(p.path);
for (const st of IGNORE_STORES) if (isIgnored(p, st)) for (const id of ids[st]) o[st].add(id);
}
for (const a of r.storeApps ?? []) if (isIgnored(a)) { o[a.store].add(a.appId); if (a.bundleId) o[a.store].add(a.bundleId); }
return o;
}
export function addStoreApp(a: Parameters<typeof withStoreApp>[1], file = registryFile()): { app: StoreOnlyApp; added: boolean; changed: boolean } {
const cur = readRegistry(file);
const { registry, app, added } = withStoreApp(cur, a, new Date().toISOString());

View file

@ -321,6 +321,17 @@ export const TOOLS: ToolDef[] = [
props: { dir: { type: 'string', pattern: '^(?!/)(?!.*\\.\\.)(?!.*,/)[A-Za-z0-9._ /,-]{1,400}$', description: 'fastlane folder(s) relative to the project, comma-separated (default: fastlane, ios/fastlane, android/fastlane)' },
profile: { type: 'string', enum: ['app', 'game', 'subscription-app'], description: 'Default: game for the GAMES category, else app' } },
args: i => [...opt('dir', i.dir), ...opt('profile', i.profile)] },
{ name: 'apps_ignore', title: 'Ignore an app', command: ['apps', 'ignore'], write: true, network: false, idempotent: true,
description: 'Ignores one app in the storebound app list (~/.storebound/projects.json), the whole app or one store side. Ignored apps are skipped by watch, events and portfolio reads and hidden from the desktop lists. Storebound-side visibility only: nothing changes in App Store Connect or Google Play (no removal from sale). dry_run shows the change.',
props: { app: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9 ._:/\\-]{0,200}$', description: 'App name, id, folder, apple:<app id> or play:<package>' }, store: { type: 'string', enum: ['apple', 'play'], description: 'Only this store side (default: the whole app)' } },
required: ['app'], args: i => [String(i.app), ...opt('store', i.store)] },
{ name: 'apps_unignore', title: 'Restore an ignored app', command: ['apps', 'unignore'], write: true, network: false, idempotent: true,
description: 'Restores (stops ignoring) one app in the storebound app list (~/.storebound/projects.json), the whole app or one store side. Ignored apps are skipped by watch, events and portfolio reads and hidden from the desktop lists. Storebound-side visibility only: nothing changes in App Store Connect or Google Play (no removal from sale). dry_run shows the change.',
props: { app: { type: 'string', pattern: '^[A-Za-z0-9][A-Za-z0-9 ._:/\\-]{0,200}$', description: 'App name, id, folder, apple:<app id> or play:<package>' }, store: { type: 'string', enum: ['apple', 'play'], description: 'Only this store side (default: the whole app)' } },
required: ['app'], args: i => [String(i.app), ...opt('store', i.store)] },
{ name: 'apps_folders', title: 'App list of this machine', command: ['apps', 'folders'], write: false, network: false,
description: 'Offline: the app folders and store-only apps of this machine (~/.storebound/projects.json) with which are ignored (whole app or per store side).',
props: { json: { type: 'boolean', default: true } }, args: () => ['--json'] },
{ name: 'workspace_list', title: 'Workspace apps', command: ['ws', 'list'], write: false, network: false,
description: 'Offline: the apps of the storebound.workspace.json above the project (app folders from its globs, store-only apps from `ws apps import`), paired across iOS and Android by the desktop\'s rules, with studios and accounts (credential profile names and whether their keys are there; never a key).',
props: { all: { type: 'boolean', default: false, description: 'Also the ignored apps' }, json: { type: 'boolean', default: false } },

View file

@ -19,7 +19,7 @@ import { CONFIG_NAMES } from './lib/config';
import { consoleIdsFromConfig } from './lib/console-links';
import { profileEnv } from './lib/credentials';
import { done, log, warn } from './lib/log';
import { readRegistry } from './lib/registry';
import { type IgnoreStore, ignoredStores, isIgnored, readRegistry } from './lib/registry';
import { runCommand } from './lib/runner';
import type { HealthSnapshot } from './lib/health';
import {
@ -36,7 +36,7 @@ const MAX_BACKOFF_MS = 4 * 60 * 60_000;
const CHILD_TIMEOUT_MS = 5 * 60_000;
const REVIEW_DAYS = 3;
interface Target extends PassTarget { dir: string; virtual: boolean; env: Record<string, string> }
interface Target extends PassTarget { dir: string; virtual: boolean; env: Record<string, string>; /** store sides the registry ignores: not read, no events */ skip: IgnoreStore[] }
/** Runs a storebound child command; a hung one is cancelled after the timeout. */
const exec = (env: Record<string, string>): Exec => async (argv, cwd) => {
@ -46,26 +46,28 @@ const exec = (env: Record<string, string>): Exec => async (argv, cwd) => {
};
/** The apps to watch: --dir, or the registry's folders and store-only apps (a store-only app that has a folder here is read once). */
async function listTargets(args: Args): Promise<Target[]> {
export async function listTargets(args: Args): Promise<Target[]> {
const dir = args.get('dir');
if (dir) {
const d = resolve(dir);
if (!CONFIG_NAMES.some(n => existsSync(join(d, n)))) throw new Error(`--dir: no storebound.config.ts in ${d}`);
return [{ key: `dir:${d}`, name: d.split(/[\\/]/).pop() ?? d, dir: d, virtual: false, env: {} }];
return [{ key: `dir:${d}`, name: d.split(/[\\/]/).pop() ?? d, dir: d, virtual: false, env: {}, skip: [] }];
}
const reg = readRegistry();
const out: Target[] = [];
for (const p of reg.projects) {
if (isIgnored(p)) continue; // ignored apps are not watched at all (storebound apps ignore / unignore)
if (!CONFIG_NAMES.some(n => existsSync(join(p.path, n)))) { warn(TAG, `${p.name}: no storebound.config.ts in ${p.path}, skipped (storebound apps remove ${p.path})`); continue; }
out.push({ key: `dir:${p.path}`, name: p.name, dir: p.path, virtual: false, env: {} });
out.push({ key: `dir:${p.path}`, name: p.name, dir: p.path, virtual: false, env: {}, skip: ignoredStores(p) });
}
if (reg.storeApps?.length) {
const { checkVirtual, virtualDir } = await import('./serve');
for (const s of reg.storeApps) {
if (isIgnored(s)) continue;
try {
if (s.store === 'apple' && !s.bundleId) throw new Error('no bundle id (storebound apps add --store apple --app-id <id> --bundle-id <id>)');
const v = checkVirtual({ name: s.name, ...(s.store === 'apple' ? { apple: { bundleId: s.bundleId, appId: s.appId } } : { play: { packageName: s.appId } }) });
out.push({ key: `store:${s.id}`, name: s.name, dir: virtualDir(v), virtual: true, env: s.account ? profileEnv(s.account) : {} });
out.push({ key: `store:${s.id}`, name: s.name, dir: virtualDir(v), virtual: true, env: s.account ? profileEnv(s.account) : {}, skip: [] });
} catch (e) { warn(TAG, `${s.name}: ${(e as Error).message}, skipped`); }
}
}
@ -80,24 +82,25 @@ async function readApp(t: Target, prev: AppSnap | undefined, now: number): Promi
const e = emptyStatus(t.dir);
try { await fillAppStatus(e, t.dir, { live: true, virtual: true, exec: run }); } catch (err) { return { snap: null, errors: [(err as Error).message] }; }
const s = e.summary!;
const useApple = !!s.apple && !t.skip.includes('apple'), usePlay = !!s.play && !t.skip.includes('play');
const snap: AppSnap = { name: s.name || t.name, ids: { appleAppId: s.apple?.appId ?? null } };
if (s.play && !t.virtual && !prev?.ids.playDeveloperId) {
if (usePlay && !t.virtual && !prev?.ids.playDeveloperId) {
try { const { loadConfig } = await import('./lib/config'); Object.assign(snap.ids, consoleIdsFromConfig((await loadConfig(undefined, t.dir)).config)); } catch { /* links fall back to the console home */ }
}
const all = e.release.all ?? [];
snap.releases = {};
if (s.apple) { if (e.storeErrors.ios) errors.push(`App Store: ${e.storeErrors.ios}`); else snap.releases.apple = releaseMap(all, 'ios'); }
if (s.play) { if (e.storeErrors.android) errors.push(`Google Play: ${e.storeErrors.android}`); else snap.releases.play = releaseMap(all, 'android'); }
if (useApple) { if (e.storeErrors.ios) errors.push(`App Store: ${e.storeErrors.ios}`); else snap.releases.apple = releaseMap(all, 'ios'); }
if (usePlay) { if (e.storeErrors.android) errors.push(`Google Play: ${e.storeErrors.android}`); else snap.releases.play = releaseMap(all, 'android'); }
const due = !prev?.healthAt || now - Date.parse(prev.healthAt) >= HEALTH_EVERY_MS;
if (due && (s.apple || s.play)) {
if (due && (useApple || usePlay)) {
const h = await run(['health', '--json'], t.dir);
if (h.data && typeof h.data === 'object') { snap.health = healthSnap(h.data as HealthSnapshot); snap.healthAt = new Date(now).toISOString(); }
if (h.data && typeof h.data === 'object') { snap.health = healthSnap({ ...(h.data as HealthSnapshot), ...(useApple ? {} : { apple: undefined }), ...(usePlay ? {} : { play: undefined }) } as HealthSnapshot); snap.healthAt = new Date(now).toISOString(); }
else errors.push(`health: ${lastLine(h.out) || `exit ${h.code}`}`);
}
snap.reviews = {};
for (const [store, on] of [['apple', !!s.apple], ['play', !!s.play]] as const) {
for (const [store, on] of [['apple', useApple], ['play', usePlay]] as const) {
if (!on) continue;
const r = await run(['reviews', 'list', '--store', store, '--days', String(REVIEW_DAYS), '--json'], t.dir);
if (r.code !== 0 || !Array.isArray(r.data)) { errors.push(`reviews ${store}: ${lastLine(r.out) || `exit ${r.code}`}`); continue; }

View file

@ -35,7 +35,7 @@ import {
findWorkspace, overridesOf, readStoreApps, resolveApps, selectApps, type Store, type StoreAppsCache, studiosOf, toDesktopState, type Workspace, WORKSPACE_NAMES,
} from './lib/workspace';
import { FORBIDDEN_ARGS, TOOLS } from './mcp-tools';
import { addFolder, readRegistry, registryFile } from './lib/registry';
import { activeProjects, addFolder, readRegistry, registryFile } from './lib/registry';
import { checkVirtual, VIRTUAL_READS, virtualDir } from './serve';
/** One app of the workspace: a folder or a store-only app, with the credentials env its commands get. */
@ -159,7 +159,7 @@ async function loadAll(args: Args): Promise<LoadedWorkspace> {
if (args.get('workspace') || findWorkspace(process.cwd())) return loadWorkspace(process.cwd(), args.get('workspace'));
const reg = readRegistry();
if (!reg.projects.length) return loadWorkspace(process.cwd());
return { file: registryFile(), root: homedir(), ws: { apps: reg.projects.map(p => ({ path: p.path, ...(p.name ? { name: p.name } : {}) })) } };
return { file: registryFile(), root: homedir(), ws: { apps: activeProjects(reg).map(p => ({ path: p.path, ...(p.name ? { name: p.name } : {}) })) } };
}
function concurrencyOf(args: Args, ws: Workspace): number {

View file

@ -0,0 +1,104 @@
// Dormant apps: `ignored` per entry, whole app or one store side (cli/lib/registry.ts); storebound-side only.
import { describe, expect, test } from 'bun:test';
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import {
activeProjects, activeStoreApps, findEntry, ignoredStoreIds, ignoredStores, isIgnored, parseRegistry, readRegistry, setIgnore, withIgnore, writeRegistry,
} from '../cli/lib/registry';
import { TOOLS, toArgv } from '../cli/mcp-tools';
const reg = () => parseRegistry(JSON.stringify({
version: 1,
projects: [{ id: 'aaaaaaaaaaaaaaaa', path: '/work/star-dash', name: 'Star Dash', added: '' }, { id: 'bbbbbbbbbbbbbbbb', path: '/work/puzzle', name: 'Puzzle', added: '' }],
storeApps: [{ store: 'apple', appId: '6400000000', account: 'teamA', name: 'Demo App', bundleId: 'com.example.demo' }, { store: 'play', appId: 'com.example.demo', name: 'Demo Play' }],
}));
describe('registry ignore', () => {
test('whole app, one store side, restore; only valid sides are kept', () => {
let r = reg();
r = withIgnore(r, 'Star Dash', 'apple', true).registry;
expect(ignoredStores(r.projects[0]!)).toEqual(['apple']);
expect(isIgnored(r.projects[0]!)).toBe(false);
expect(isIgnored(r.projects[0]!, 'apple')).toBe(true);
expect(isIgnored(r.projects[0]!, 'play')).toBe(false);
r = withIgnore(r, 'star dash', undefined, true).registry;
expect(isIgnored(r.projects[0]!)).toBe(true);
expect(activeProjects(r).map(p => p.name)).toEqual(['Puzzle']);
expect(activeProjects(r, 'play').map(p => p.name)).toEqual(['Puzzle']);
r = withIgnore(r, 'aaaaaaaaaaaaaaaa', 'play', false).registry;
expect(ignoredStores(r.projects[0]!)).toEqual(['apple']);
expect(activeProjects(r, 'play').map(p => p.name)).toEqual(['Star Dash', 'Puzzle']);
r = withIgnore(r, 'Star Dash', undefined, false).registry;
expect(r.projects[0]!.ignored).toBeUndefined();
expect(parseRegistry(JSON.stringify({ projects: [{ path: '/a', ignored: ['play', 'x', 'play', 'apple'] }] })).projects[0]!.ignored).toEqual(['apple', 'play']);
});
test('a store-only app has one side: its own store; the other store is an error', () => {
const r = reg();
expect(() => withIgnore(r, 'apple:6400000000', 'play', true)).toThrow('apple app only');
const o = withIgnore(r, 'apple:6400000000', 'apple', true);
expect(o.changed).toBe(true);
expect(activeStoreApps(o.registry).map(a => a.store)).toEqual(['play']);
expect(withIgnore(o.registry, 'apple:6400000000', undefined, true).changed).toBe(false);
});
test('ambiguous names and unknown keys fail loudly', () => {
const r = reg();
expect(() => withIgnore(r, 'nope', undefined, true)).toThrow('not in the app list');
expect(findEntry(r, 'Demo App')?.kind).toBe('storeApp');
const dup = parseRegistry(JSON.stringify({ projects: [{ path: '/a/x', name: 'Same' }, { path: '/b/x', name: 'Same' }] }));
expect(() => findEntry(dup, 'Same')).toThrow('matches 2 apps');
});
test('written to the file and read back; unrelated entries and storeApps stay', () => {
const dir = mkdtempSync(join(tmpdir(), 'sb-ign-'));
const file = join(dir, 'projects.json');
writeRegistry(reg(), file);
expect(setIgnore('Puzzle', 'play', true, file).changed).toBe(true);
expect(setIgnore('Puzzle', 'play', true, file).changed).toBe(false);
setIgnore('play:com.example.demo', undefined, true, file);
const back = readRegistry(file);
expect(back.projects.find(p => p.name === 'Puzzle')!.ignored).toEqual(['play']);
expect(back.storeApps!.find(a => a.store === 'play')!.ignored).toEqual(['play']);
expect(back.storeApps!.find(a => a.store === 'apple')!.ignored).toBeUndefined();
expect(JSON.parse(readFileSync(file, 'utf8')).projects[0].ignored).toBeUndefined();
});
test('store ids of ignored sides come from the config text, never by running it', () => {
const dir = mkdtempSync(join(tmpdir(), 'sb-ign-'));
const app = join(dir, 'game'); mkdirSync(app);
writeFileSync(join(app, 'storebound.config.ts'), "export default { apple: { bundleId: 'com.example.game', appId: '6400000123' }, play: { packageName: 'com.example.game.android' } };\n");
let r = parseRegistry(JSON.stringify({ projects: [{ path: app, name: 'Game' }] }));
r = withIgnore(r, 'Game', 'play', true).registry;
const ids = ignoredStoreIds(r);
expect([...ids.play]).toEqual(['com.example.game.android']);
expect(ids.apple.size).toBe(0);
});
test('MCP tools: ignore and unignore build the argv, writes default to dry run', () => {
const t = TOOLS.find(x => x.name === 'apps_ignore')!;
expect(t.write).toBe(true);
expect(toArgv(t, { app: 'Star Dash', store: 'apple' }).argv).toEqual(['apps', 'ignore', 'Star Dash', '--store', 'apple', '--dry']);
expect(TOOLS.some(x => x.name === 'apps_unignore')).toBe(true);
});
});
describe('watch and ws skip ignored apps', () => {
test('watch targets: a fully ignored app is not watched, a half-ignored one skips that store', async () => {
const { listTargets } = await import('../cli/watch');
const { parseArgs } = await import('../cli/lib/args');
const base = mkdtempSync(join(tmpdir(), 'sb-ign-watch-'));
const mk = (n: string) => { const d = join(base, n); mkdirSync(d); writeFileSync(join(d, 'storebound.config.ts'), 'export default {};\n'); return d; };
const file = join(base, 'projects.json');
writeRegistry(parseRegistry(JSON.stringify({ projects: [{ path: mk('a'), name: 'A' }, { path: mk('b'), name: 'B' }, { path: mk('c'), name: 'C' }] })), file);
setIgnore('B', undefined, true, file);
setIgnore('C', 'play', true, file);
const saved = process.env.STOREBOUND_REGISTRY;
process.env.STOREBOUND_REGISTRY = file;
try {
const t = await listTargets(parseArgs([]));
expect(t.map(x => [x.name, x.skip])).toEqual([['A', []], ['C', ['play']]]);
} finally { if (saved === undefined) delete process.env.STOREBOUND_REGISTRY; else process.env.STOREBOUND_REGISTRY = saved; }
});
});