Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
20 changes: 17 additions & 3 deletions apps/cli/src/cli/headless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]);

Expand Down Expand Up @@ -937,7 +937,7 @@ export async function runHeadless(command: string, argv: string[]): Promise<numb
error: result.error,
})),
queued: paced.queued.map((entry) => ({ 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));
Expand All @@ -959,7 +959,10 @@ export async function runHeadless(command: string, argv: string[]): Promise<numb
printHooks([...results.hooks, ...paced.scheduleHooks]);
const line = [results.length ? summarize(results) : "nothing sent yet"];
if (paced.queued.length) line.push(`${paced.queued.length} queued for the daemon (myna queue)`);
if (paced.skipped.length) line.push(`${paced.skipped.length} skipped as a repeat`);
const full = paced.skipped.filter((entry) => 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;
Expand All @@ -969,6 +972,9 @@ export async function runHeadless(command: string, argv: string[]): Promise<numb
if (!flags.front && !flags.skipQueue) out(`Pass --front to take the next free slot ahead of the queue, or --now to send everything at once.`);
}
}
// A post the full queue turned away entirely did not happen: say so in
// the exit code, so a feeder keeps it and tries again later.
if (!results.length && !paced.queued.length && paced.skipped.some((entry) => entry.full)) return 1;
return results.every((result) => result.ok) ? 0 : 1;
}

Expand Down Expand Up @@ -1007,6 +1013,13 @@ export async function runHeadless(command: string, argv: string[]): Promise<numb
// myna pace --gap 4h --drip 48h --repost 7d
const next = { ...settings.pacing };
let changed = false;
if (typeof flags.horizon === "string") {
// --horizon off lifts the limit; a duration sets it.
if (["off", "none", "0"].includes(flags.horizon)) delete next.horizon;
else if (parseDurationOr(flags.horizon, "") === undefined) throw new Error(`--horizon wants a duration like 24h, or off, not "${flags.horizon}".`);
else next.horizon = flags.horizon;
changed = true;
}
for (const key of ["gap", "drip", "repost"] as const) {
const value = flags[key];
if (typeof value !== "string") continue;
Expand All @@ -1019,6 +1032,7 @@ export async function runHeadless(command: string, argv: string[]): Promise<numb
out(`gap ${next.minGap} least time between two posts on the same network`);
out(`drip ${next.drip} a post to several accounts is spread over this window`);
out(`repost ${next.repostGap} the same text to the same account waits this long`);
out(`horizon ${next.horizon ?? "off"} the queue reaches no further ahead than this (--horizon 24h | off)`);
if (!changed) {
out("\nChange one: myna pace --gap 2h --drip 48h --repost 7d.");
out("Jump the queue but keep the gaps: myna post --front. Skip the gates outright: myna post --now.");
Expand Down
4 changes: 3 additions & 1 deletion apps/cli/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ Posting:
schedule <when> [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
Expand Down
6 changes: 3 additions & 3 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
27 changes: 25 additions & 2 deletions packages/core/src/core/pacing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" };
Expand All @@ -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 {
Expand All @@ -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,
};
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core/poster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
25 changes: 25 additions & 0 deletions packages/core/test/pacing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
2 changes: 1 addition & 1 deletion packages/mcp/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
Loading