diff --git a/apps/cli/package.json b/apps/cli/package.json index f77368c..d53b011 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,6 +1,6 @@ { "name": "@profullstack/myna", - "version": "0.55.1", + "version": "0.56.0", "description": "A terminal social media manager. Log in, compose, schedule and post to every network from one TUI.", "license": "MIT", "type": "module", diff --git a/apps/cli/src/cli/headless.ts b/apps/cli/src/cli/headless.ts index 821857d..c99dd6a 100644 --- a/apps/cli/src/cli/headless.ts +++ b/apps/cli/src/cli/headless.ts @@ -245,7 +245,7 @@ export function parseFlags(argv: string[]): { positional: string[]; flags: Flags const OWN_FLAGS = new Set([ "to", "title", "media", "json", "yes", "style", "at", "thread", "dryRun", "limit", "output", "keepSvg", "server", "overwrite", "settings", "once", "interval", "refresh", "theme", "force", "weight", "source", "network", - "now", "gap", "drip", "repost", "every", "cooldown", "off", "on", "port", "open", "noOpen", + "now", "gap", "drip", "repost", "horizon", "every", "cooldown", "off", "on", "port", "open", "noOpen", "days", "send", "command", "check", "version", "allowDuplicate", "from", "type", "rotate", ]); @@ -937,7 +937,7 @@ export async function runHeadless(command: string, argv: string[]): Promise ({ id: entry.id, account: entry.targets[0], at: entry.scheduledFor })), - skipped: paced.skipped.map((entry) => ({ account: entry.account.id, reason: entry.reason })), + skipped: paced.skipped.map((entry) => ({ account: entry.account.id, reason: entry.reason, full: entry.full || undefined })), reflowed: paced.reflowed.map((move) => ({ id: move.id, from: new Date(move.from).toISOString(), to: new Date(move.to).toISOString() })), hooks: [...results.hooks, ...paced.scheduleHooks], }, null, 2)); @@ -959,7 +959,10 @@ export async function runHeadless(command: string, argv: string[]): Promise entry.full).length; + const repeats = paced.skipped.length - full; + if (repeats) line.push(`${repeats} skipped as a repeat`); + if (full) line.push(`${full} refused, the queue is full for ${settings.pacing.horizon}`); out(`\n${line.join(" — ")}`); if (paced.queued.length && !flags.now) { const window = flags.front || flags.skipQueue ? settings.pacing.minGap : settings.pacing.drip; @@ -969,6 +972,9 @@ export async function runHeadless(command: string, argv: string[]): Promise entry.full)) return 1; return results.every((result) => result.ok) ? 0 : 1; } @@ -1007,6 +1013,13 @@ export async function runHeadless(command: string, argv: string[]): Promise [text] Queue a post: "in 2h", "tomorrow 9am" pace [--gap 2h] [--drip 48h] The pacing rules: one post per network [--repost 7d] per gap, several accounts spread over - the drip, a repeat waits out the repost gap + [--horizon 24h|off] the drip, a repeat waits out the repost gap. + With a horizon the queue reaches no further + ahead: a post past it is refused, exit 1 utm [--add example.com] Campaign tags on the links you post, so [--exclude host] [--off] the site can see which network sent the visit. Sites your accounts publish to are diff --git a/bun.lock b/bun.lock index f55a21b..fc125fe 100644 --- a/bun.lock +++ b/bun.lock @@ -25,7 +25,7 @@ }, "apps/cli": { "name": "@profullstack/myna", - "version": "0.55.1", + "version": "0.56.0", "bin": { "myna": "./bin/myna.mjs", }, @@ -60,7 +60,7 @@ }, "packages/core": { "name": "@profullstack/myna-core", - "version": "0.55.1", + "version": "0.56.0", "dependencies": { "@anthropic-ai/sdk": "^0.123.0", "@profullstack/ai-providers": "^0.3.1", @@ -84,7 +84,7 @@ }, "packages/mcp": { "name": "@profullstack/myna-mcp", - "version": "0.55.1", + "version": "0.56.0", "bin": { "myna-mcp": "./src/server.ts", }, diff --git a/packages/core/package.json b/packages/core/package.json index 7f88e6a..e91fee5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@profullstack/myna-core", - "version": "0.55.1", + "version": "0.56.0", "description": "Network adapters, credential vault, scheduling and the AI writer behind myna.", "license": "MIT", "type": "module", diff --git a/packages/core/src/core/pacing.ts b/packages/core/src/core/pacing.ts index 14204ea..e5dcb7f 100644 --- a/packages/core/src/core/pacing.ts +++ b/packages/core/src/core/pacing.ts @@ -38,6 +38,12 @@ export interface PacingSettings { drip: string; /** Same text to the same account again waits this long. "7d". */ repostGap: string; + /** + * How far ahead the queue may reach. "24h": a paced post whose slot would + * land further out than this is refused instead of queued, so a feeder that + * never stops cannot stretch the queue over months. Unset: no limit. + */ + horizon?: string; } export const DEFAULT_PACING: PacingSettings = { minGap: "2h", drip: "48h", repostGap: "7d" }; @@ -46,6 +52,8 @@ export interface PacingRules { minGapMs: number; dripMs: number; repostGapMs: number; + /** Unset: the queue may reach any distance ahead. */ + horizonMs?: number; } export function pacingRules(settings: PacingSettings): PacingRules { @@ -54,6 +62,7 @@ export function pacingRules(settings: PacingSettings): PacingRules { minGapMs: read(settings.minGap, DEFAULT_PACING.minGap), dripMs: read(settings.drip, DEFAULT_PACING.drip), repostGapMs: read(settings.repostGap, DEFAULT_PACING.repostGap), + horizonMs: (settings.horizon && parseDuration(settings.horizon)) || undefined, }; } @@ -279,8 +288,11 @@ export interface PlannedTarget { export interface Plan { now: Account[]; later: PlannedTarget[]; - /** Targets refused outright: the same text went to that account too recently. */ - skipped: Array<{ account: Account; reason: string }>; + /** + * Targets refused outright: the same text went to that account too + * recently, or (`full`) its slot would land past the queue's horizon. + */ + skipped: Array<{ account: Account; reason: string; full?: boolean }>; /** * Every slot this plan claimed, now and later alike. A front-of-line plan * hands these to `reflowQueue` so what it jumped ahead of gets pushed back @@ -450,6 +462,17 @@ export function planTargets(input: PlanInput): Plan { at = clear; } } + // The queue holds no more than the horizon. A post dated by hand (--at) + // is the person's own choice of day and is not measured against it. + const horizonMs = input.rules.horizonMs; + if (horizonMs && from <= now && at > now + horizonMs) { + plan.skipped.push({ + account, + full: true, + reason: `${account.network} is booked for the next ${describeMs(horizonMs)}, and the queue holds no more than that`, + }); + return; + } // Book it so the next account on the same network is pushed past it. const list = booked.get(account.network); if (list) { diff --git a/packages/core/src/core/poster.ts b/packages/core/src/core/poster.ts index ad73a6f..eb6b3d9 100644 --- a/packages/core/src/core/poster.ts +++ b/packages/core/src/core/poster.ts @@ -272,7 +272,7 @@ export interface PacedOutcome { results: PostOutcome; /** One queued post per account whose turn is later. */ queued: QueuedPost[]; - skipped: Array<{ account: Account; reason: string }>; + skipped: Array<{ account: Account; reason: string; full?: boolean }>; plan: Plan; /** What plugins said about the queued ones (a calendar entry, say). */ scheduleHooks: HookOutcome[]; diff --git a/packages/core/src/version.ts b/packages/core/src/version.ts index 3b630cc..4af144b 100644 --- a/packages/core/src/version.ts +++ b/packages/core/src/version.ts @@ -6,4 +6,4 @@ * binary reporting the wrong version, and nothing would fail. A test asserts * this matches the package.json it is published under. */ -export const VERSION = "0.55.1"; +export const VERSION = "0.56.0"; diff --git a/packages/core/test/pacing.test.ts b/packages/core/test/pacing.test.ts index c6cfe8a..8e68cfe 100644 --- a/packages/core/test/pacing.test.ts +++ b/packages/core/test/pacing.test.ts @@ -337,3 +337,28 @@ test("a skill's wider gap widens the network gap for that account, and a narrowe const narrow = planTargets({ accounts: [bsky], text: "hi", now: NOW, history, queue: [], rules, accountNetwork, order: stable, limitsFor: () => ({ minGapMs: 1 * H }) }); expect(narrow.later[0].at).toBe(NOW + 3 * H); }); + +test("horizon: a slot past it is refused, not queued; inside it queues as before", () => { + const capped = { ...rules, horizonMs: 24 * H }; + const queued = (at: number): QueuedPost => ({ id: `q${at}`, scheduledFor: new Date(at).toISOString(), targets: [li.id], text: `t${at}`, createdAt: "", status: "pending" }); + // LinkedIn is booked every 4h through the next 24h: the next slot is 28h out. + const fullQueue = [0, 4, 8, 12, 16, 20, 24].map((h) => queued(NOW + h * H)); + const refused = planTargets({ accounts: [li], text: "new", now: NOW, history: [], queue: fullQueue, rules: capped, accountNetwork, order: stable }); + expect(refused.later).toEqual([]); + expect(refused.now).toEqual([]); + expect(refused.skipped).toHaveLength(1); + expect(refused.skipped[0].full).toBe(true); + expect(refused.taken).toEqual([]); + // Room inside the horizon: queued at the next free slot. + const room = planTargets({ accounts: [li], text: "new", now: NOW, history: [], queue: fullQueue.slice(0, 3), rules: capped, accountNetwork, order: stable }); + expect(room.later.map((t) => t.at)).toEqual([NOW + 12 * H]); + expect(room.skipped).toEqual([]); + // No horizon set: the old behaviour, however far out. + const open = planTargets({ accounts: [li], text: "new", now: NOW, history: [], queue: fullQueue, rules, accountNetwork, order: stable }); + expect(open.later.map((t) => t.at)).toEqual([NOW + 28 * H]); + // A post dated by hand is not measured against it. + const dated = planTargets({ accounts: [li], text: "new", now: NOW, from: NOW + 90 * 24 * H, history: [], queue: [], rules: capped, accountNetwork, order: stable }); + expect(dated.later.map((t) => t.at)).toEqual([NOW + 90 * 24 * H]); + expect(pacingRules({ ...DEFAULT_PACING, horizon: "24h" }).horizonMs).toBe(24 * H); + expect(pacingRules(DEFAULT_PACING).horizonMs).toBeUndefined(); +}); diff --git a/packages/mcp/package.json b/packages/mcp/package.json index f96443d..688dfce 100644 --- a/packages/mcp/package.json +++ b/packages/mcp/package.json @@ -1,6 +1,6 @@ { "name": "@profullstack/myna-mcp", - "version": "0.55.1", + "version": "0.56.0", "description": "MCP server for myna. Lets an agent post, schedule and read across every connected social account.", "license": "MIT", "type": "module",