/** User preferences. Plain JSON — no secrets here except by the user's choice. */ import { readJson, writeJson } from "../util/json.ts"; import { SETTINGS_FILE } from "../util/paths.ts"; import { DEFAULT_PACING, type PacingSettings } from "../core/pacing.ts"; import { DEFAULT_EVERGREEN, type EvergreenSettings } from "../core/evergreen.ts"; import { DEFAULT_RECAP, recapAddress, resolveRecapSettings, type RecapSettings } from "../core/recap.ts"; import { DEFAULT_LINKS, type LinksSettings } from "../core/links.ts"; import { session as cloudSession } from "./cloud.ts"; import { DEFAULT_BRAND, type NewsletterBrand } from "../core/newsletter-layout.ts"; import { DEFAULT_UTM, type UtmSettings } from "../core/utm.ts"; export interface Settings { /** Default `--to` value when none is given. "all" posts everywhere. */ defaultTargets: string; /** Appended to every post unless it is empty. */ signature: string; theme: string; /** Split over-limit text into a reply chain instead of truncating. */ threadByDefault: boolean; ai: { provider: "c0mpute" | "anthropic" | "openai" | "ollama"; model: string; /** Voice instructions handed to the writer on every draft. */ voice: string; maxHashtags: number; }; infographic: { accent: string; background: string; footer: string; }; /** The follow graph: read who your seeds follow, then follow the people they agree on. */ graph: { /** Off until a person turns it on. Following people is not something to do by accident. */ enabled: boolean; /** Ceiling per account. Networks throttle well below their published limits for new accounts. */ followsPerHour: number; followsPerDay: number; /** How many of each seed's follows to read. */ perSeed: number; /** Re-read a seed's list after this long. */ expandEveryHours: number; /** Follow the seeds themselves as well as who they follow. */ followSeeds: boolean; /** A candidate needs this many seeds following them before it is followed. 1 means any. */ minSeeds: number; /** Which networks the daemon follows on: "all" or a comma list. */ networks: string; /** * Which of a seed's lists to read: who they follow ("following", the * default), who follows them ("followers"), or both. Followers are the * noisier list, so they count for `followerWeight` of a follow. */ expand: "following" | "followers" | "both"; followerWeight: number; /** * Hand every account followed to OutreachGraph for assessment, the way * `--outreachgraph` does for one command. Needs `myna outreachgraph login`. */ outreachgraph: boolean; }; /** * How fast posts go out. Nothing is sent at the rate it was asked for: * one post per network per `minGap`, a multi-account post dripped over * `drip`, the same text to the same account not inside `repostGap`. */ pacing: PacingSettings; /** Old pages from a blog account, re-posted on a slow cadence with an ad. */ evergreen: EvergreenSettings; /** One email a day: what went out, what failed, what is booked next. */ recap: RecapSettings; /** One email a night with a link to every post that went live. Off by default. */ links: LinksSettings; /** * Caps that live outside the skill files. `maxPerDay` here stands in for the * blog template's default when no skill file names a value; a value in a * skill file always wins over it. */ blog: { maxPerDay?: number }; /** * Campaign tags added to the links in a post, so the site a post drives * people to can see which network sent them. See core/utm.ts. */ utm: UtmSettings; /** Which skill each account uses, and where its rotation stands. */ skills: SkillSettings; /** Who you are, for `myna profile`: the OpenProfile.md myna writes when there is no hand-written one. */ profile: ProfileSettings; /** The reshare network: what you offer to reshare for others, and what you ask for your own posts. */ reshare: ReshareSettings; /** Follow-ups: who replied, reposted or followed, and what to send them back. */ engage: EngageSettings; hubs: HubsSettings; /** Gap-fill posting: hold a cadence from the plan, never sooner than the hold window. */ autopilot: AutopilotSettings; /** The upvoter: finding posts worth a vote, and what myna may do about them. */ upvote: UpvoteSettings; /** Asks: people on Reddit asking for a site or app that does X, Y and Z, and what we did about it. */ asks: AsksSettings; /** Where a DID is proved: the CoinPay origin and the OAuth client myna is registered as there. */ did: DidSettings; /** Direct mail and texts: the most that go out in a rolling day. */ outreach: OutreachSettings; /** `myna newsletter`: the postal address every issue carries, and where unsubscribes land. */ newsletter: NewsletterSettings; /** Settings sync with myna cloud (@profullstack/synconfig): settings.json, OpenProfile, skills. */ synconfig: SynconfigSettings; /** Plugin specs: an absolute path, or a package name installed by `myna plugins add`. */ plugins: string[]; /** * Directories added by URL with `myna directory add`. Not secret — the id, * the endpoint and a name. The API key for each lives in the vault, like * every other credential. */ directories: CustomDirectorySetting[]; /** The linked brain repo (`myna brain link`). Absent means none: the writer reads brand.md only. */ brain?: BrainSettings; } /** A linked brain: where it comes from and where it sits on this machine. */ export interface BrainSettings { /** A git URL, or an absolute local path. */ source: string; /** The working copy. For a git source this is the clone under the config dir. */ dir: string; /** Also read knowledge//*.md, which overrides same-named root files. */ product?: string; /** ISO time of the last successful pull, or of the link/clone. */ lastPull?: string; } /** * Skill selection per account id. The skills themselves are files under * skills/; this is only the pointer into them, kept here so editing a skill * never moves the cursor and moving the cursor never rewrites a skill. */ export interface SkillSettings { /** Pinned default slug per account. Absent means the generated `skill`. */ defaults: Record; /** Accounts that rotate through every skill they have, in order. */ rotate: Record; /** The slug each rotating account used last. */ cursor: Record; } /** A directory reached generically over MCP, as it is stored. */ export interface CustomDirectorySetting { id: string; url: string; name?: string; homepage?: string; blurb?: string; } export interface ProfileSettings { name: string; kind: "" | "person" | "agent" | "organization"; handle: string; web: string; email: string; avatar: string; /** Where money for you goes: a CAIP-10 account, an address, a payment page. */ pay: string; /** An OpenResume.md URL. */ resume: string; headline: string; /** Comma list. What you write about; the reshare network matches on it. */ topics: string; /** For an agent: who is answerable for it. */ operatorName: string; operatorProfile: string; operatorEmail: string; } export interface ReshareSettings { /** Ask the network to reshare every post as it goes out. Off until turned on. */ auto: boolean; /** The most reshares this install does for other people in a rolling day. */ perDay: number; /** On a network with no repost API, post the link instead. */ quote: boolean; /** Networks you will reshare on: "all" or a comma list of network ids. */ networks: string; /** Comma list of topics you will reshare. Empty means your profile topics. */ topics: string; /** Comma list of topics you refuse. */ not: string; /** What one reshare by you costs the author, in USD. 0 is free. */ rateUsd: number; /** What you offer per reshare of your own posts, in USD. 0 asks for free reshares only. */ bountyUsd: number; /** How many people may reshare one of your posts. */ maxSharers: number; } export const DEFAULT_PROFILE: ProfileSettings = { name: "", kind: "", handle: "", web: "", email: "", avatar: "", pay: "", resume: "", headline: "", topics: "", operatorName: "", operatorProfile: "", operatorEmail: "", }; export const DEFAULT_RESHARE: ReshareSettings = { auto: false, perDay: 5, quote: true, networks: "all", topics: "", not: "", rateUsd: 0, bountyUsd: 0, maxSharers: 10, }; export interface AutopilotSettings { /** Off until somebody turns it on. Posting on your behalf is not a default. */ enabled: boolean; /** The cadence it holds to, counting everything you post yourself. */ perWeek: number; /** Nothing is booked closer than this. Your window to override. */ holdHours: number; /** Where gap-fills go: "all", a network, a comma list. Empty uses defaultTargets. */ to: string; /** Generate more angles when the plan runs dry. */ refillPlan: boolean; /** Keep at least this many days of plan ahead when refilling. */ planAheadDays: number; } export interface EngageSettings { /** Off until a person turns it on. Replying to people is not something to do by accident. */ enabled: boolean; /** Follow-ups sent per account in a rolling day. */ maxPerDay: number; /** Least time between two follow-ups from the same account. */ gapMinutes: number; /** One follow-up per person per account inside this window. */ cooldownDays: number; /** Follow whoever replied, reposted or followed. */ followBack: boolean; /** Answer a reply, mention or quote with a drafted reply. */ replyToMentions: boolean; /** Thank a repost under the post they shared. */ thankReposts: boolean; /** Follow people who only liked. Off: a like is not a conversation. */ followLikers: boolean; /** Which networks to engage on: "all" or a comma list. */ networks: string; /** How far back a scan reads, per account. */ scanLimit: number; } /** * The upvoter: what myna is allowed to do with somebody else's post. * * Every number here is a brake. The engine finds far more that it could vote * on than it should, and these decide how much of that actually goes out: * how close a match has to be, how fast an account may act, and how rarely a * reply is allowed to carry a link. The defaults are deliberately timid. */ export interface UpvoteSettings { /** Off until a person turns it on. Voting on strangers' posts is not something to do by accident. */ enabled: boolean; /** Votes and shares cast per account in a rolling day. */ maxPerDay: number; /** Least time between two actions from the same account. */ gapMinutes: number; /** One action per author per account inside this window, however many of their posts match. */ cooldownDays: number; /** Which networks to amplify on: "all" or a comma list. */ networks: string; /** * Networks that are found and queued but never acted on without a person, * whatever `networks` says. Reddit's API terms forbid automated voting, so * it ships here: the queue fills, and `myna upvote send --network reddit` * is a decision somebody makes. */ manualOnly: string; /** Results asked of each network per query. */ searchLimit: number; /** Queries built per scan, strongest topics first. */ queriesPerScan: number; /** How far back our own posts are read to work out what we are about. */ topicDays: number; /** A post older than this is stale; the vote reads as a sweep rather than a reader. */ maxAgeHours: number; /** 0-1. How well a post must match our topics before it is worth a vote. */ minScore: number; /** 0-1. Of the posts voted on, the share also shared onward. 0 turns resharing off. */ repostRatio: number; /** 0-1. Of the posts voted on, the share that also gets a reply carrying one of our links. */ linkRatio: number; /** A link drop has to be a better match than a bare vote does. */ linkMinScore: number; /** Replies carrying a link, per account, in a rolling day. The hard cap under `linkRatio`. */ linkPerDay: number; /** * Hand everybody the upvoter finds to the plugins that collect people, as * leads. The upvoter does not know what a lead is: it fires `afterDiscover` * and whatever is installed decides. OutreachGraph reads this one. */ leads: boolean; } /** * Asks: people asking, in public, for a site or an app that does X, Y and Z. * * Read from RSS Amplifier's subreddit mirrors (`/r/.json`) * because Reddit blocks this box outright; thread stats come from the Arctic * Shift archive for the same reason. Replies are never sent from here: each one * is a hand-off card a person pastes, which is the only honest Reddit adapter. */ export interface AsksSettings { /** Off until a person turns it on: the daemon then scans every half hour and refreshes stats every six. */ enabled: boolean; /** Comma list of subreddits to read, without the `r/`. */ subs: string; /** Where the subreddit feeds are read from. */ feedBase: string; /** The Reddit archive the thread and reply stats come from. */ statsBase: string; /** Read the archive for a subreddit RSS Amplifier has not crawled yet, rather than nothing. */ fallback: boolean; /** 0-1. How sure the detector must be that a post is somebody asking for a thing. */ minScore: number; /** Distinct people asking for the same idea, inside `windowDays`, before it is flagged "build". */ buildAt: number; /** How far back an ask counts toward an idea's demand. */ windowDays: number; /** How long after it was posted a thread keeps getting its stats refreshed. */ trackDays: number; /** Threads refreshed per stats run, oldest refresh first. The archive is a free service. */ statsPerRun: number; /** Our Reddit username, without `u/`, so stats can find the reply we pasted and count answers to it. */ redditUser: string; /** Hand each asker to the plugins that collect people (OutreachGraph) as a lead. */ leads: boolean; /** Draft replies with the writer when one is configured; the template otherwise. */ useWriter: boolean; /** * Archive searches per scan for the products' pain phrases (one phrase in one sub each, about * 2.5 s apart). They take turns, so a small number still reaches every phrase. 0 turns them off; * phrases still match every post the scan reads anyway. */ painSearches: number; } /** * Engage the hubs: the handful of accounts a campaign's buyers follow and answer, watched so a * reply under their posts reaches the audience where it talks. Drafts only: every reply waits for * a person to approve it, and an approved one goes through the queue and its pacing. */ export interface HubsSettings { /** Hubs whose posts a scan reads, best first. */ watch: number; /** Posts read per hub per scan. */ postsPerHub: number; /** Only posts newer than this get a draft: an old thread's replies are read by nobody. */ maxAgeHours: number; /** Drafts a scan writes at most, across every hub. */ draftsPerScan: number; /** Bluesky's public AppView, for reading hubs' posts without an account. */ bskyBase: string; } export interface DidSettings { server: string; /** A public OAuth client (PKCE, loopback redirect) registered at the server with the `did` scope. */ clientId: string; } export interface OutreachSettings { maxEmailsPerDay: number; maxSmsPerDay: number; /** * The mail provider `myna email` and newsletters use when none is named: * a `myna mail provider` id or a non-Google SMTP server id. Empty means the * first API provider, then the first non-Google SMTP server. Google SMTP * requires an explicit per-send selection. */ mailProvider: string; } export const DEFAULT_OUTREACH: OutreachSettings = { maxEmailsPerDay: 200, maxSmsPerDay: 100, mailProvider: "" }; export interface NewsletterSettings { /** * The sender's physical postal address, printed at the foot of every issue. * CAN-SPAM requires one; a newsletter will not send without it. */ address: string; /** * Your own one-click unsubscribe endpoint, with `{token}` where the * subscriber's token goes. Empty means myna cloud hosts it at * mynaposter.com, which needs `myna cloud login`. */ unsubscribeUrl: string; /** * The crawlproof.com tracking id (24 hex). Set, every issue gets signed * click links, an open pixel and crawlproof's signed unsubscribe link. Its * secret is in the vault, never here. */ trackingId: string; /** Where tracking lives. Only a test or a staging host changes it. */ trackingHost: string; /** Milliseconds between two messages of one send. */ paceMs: number; /** Named sets of calls to action; an issue with a set rotates through it, one per variant. */ ctaSets: Record; /** The links every issue's footer carries: book a demo, plans, shop, support us. */ footerLinks: NewsletterCta[]; /** Logo, name and accent colour. With a name or a logo set, issues go out in the branded layout. */ brand: NewsletterBrand; /** * Where an issue to a list also goes up on the web once it is sent: list → * account ids, e.g. `{"profullstack-users": ["bl0ggers:chovy"]}`. Each is * posted once, by the daemon, with the issue id as its idempotency key. */ publishTo: Record; } /** A call to action in a newsletter: the button text and where it goes. */ export interface NewsletterCta { label: string; url: string; } export const DEFAULT_CTAS: NewsletterCta[] = [ { label: "Book a demo", url: "https://profullstack.com/diagnostic" }, { label: "Schedule a call", url: "https://profullstack.com/contact" }, { label: "See our plans", url: "https://profullstack.com/plans" }, { label: "Support us", url: "https://profullstack.com/support-us" }, { label: "Get the Power Key", url: "https://profullstack.com/shop" }, ]; /** * The links every issue carries in its footer, whatever variant the reader * got: the standard Profullstack row. */ export const DEFAULT_FOOTER_LINKS: NewsletterCta[] = [ { label: "Book a demo", url: "https://profullstack.com/diagnostic" }, { label: "Schedule a call", url: "https://profullstack.com/contact" }, { label: "Plans", url: "https://profullstack.com/plans" }, { label: "Shop", url: "https://profullstack.com/shop" }, { label: "Support us", url: "https://profullstack.com/support-us" }, ]; export const DEFAULT_NEWSLETTER: NewsletterSettings = { address: "", unsubscribeUrl: "", trackingId: "", trackingHost: "https://crawlproof.com", paceMs: 1000, ctaSets: { default: DEFAULT_CTAS }, footerLinks: DEFAULT_FOOTER_LINKS, brand: DEFAULT_BRAND, publishTo: {}, }; /** Stored over the defaults, with the CTA sets copied so an edit never reaches the defaults. */ function newsletterSettings(stored: Partial | undefined): NewsletterSettings { const sets = stored?.ctaSets && typeof stored.ctaSets === "object" ? stored.ctaSets : DEFAULT_NEWSLETTER.ctaSets; const footerLinks = Array.isArray(stored?.footerLinks) ? stored.footerLinks : DEFAULT_FOOTER_LINKS; return { ...DEFAULT_NEWSLETTER, ...stored, ctaSets: structuredClone(sets), footerLinks: structuredClone(footerLinks), brand: { ...DEFAULT_BRAND, ...stored?.brand }, publishTo: publishToMap(stored?.publishTo) }; } /** list → account ids, with anything that is not a list of strings dropped. */ function publishToMap(stored: unknown): Record { if (!stored || typeof stored !== "object" || Array.isArray(stored)) return {}; const out: Record = {}; for (const [list, ids] of Object.entries(stored as Record)) { if (!Array.isArray(ids)) continue; const clean = ids.filter((id): id is string => typeof id === "string" && id.trim() !== "").map((id) => id.trim()); if (clean.length) out[list.trim().toLowerCase()] = clean; } return out; } export interface SynconfigSettings { /** Let the daemon pull and push on a schedule. On by default; it only runs once signed in to myna cloud. */ auto: boolean; everyMinutes: number; } export const DEFAULT_SYNCONFIG: SynconfigSettings = { auto: true, everyMinutes: 5 }; export const DEFAULT_DID: DidSettings = { server: "https://coinpayportal.com", // myna's public OAuth client at CoinPay: PKCE, loopback redirect, scopes openid profile did. clientId: "cp_3aedc5cd194ff147d86341a2", }; export const DEFAULT_AUTOPILOT: AutopilotSettings = { enabled: false, perWeek: 5, holdHours: 24, to: "", refillPlan: true, planAheadDays: 30, }; export const DEFAULT_ENGAGE: EngageSettings = { enabled: false, maxPerDay: 20, gapMinutes: 10, cooldownDays: 7, followBack: true, replyToMentions: true, thankReposts: true, followLikers: false, networks: "all", scanLimit: 40, }; export const DEFAULT_UPVOTE: UpvoteSettings = { enabled: false, maxPerDay: 30, gapMinutes: 4, cooldownDays: 3, networks: "all", manualOnly: "reddit", searchLimit: 25, queriesPerScan: 6, topicDays: 14, maxAgeHours: 48, // Scoring returns a hard zero for anything that is not on subject, so this // only decides how strong a match has to be, not whether it is one at all. // One narrow term on its own lands near 0.24 and is worth a vote. minScore: 0.2, repostRatio: 0.15, // Roughly one reply in sixteen, and never more than `linkPerDay` of them. linkRatio: 0.06, linkMinScore: 0.5, linkPerDay: 2, leads: true, }; export const DEFAULT_ASKS: AsksSettings = { enabled: false, subs: "AskProgramming,AskProgrammers,AskTechnology,AskNetsec,AskElectronics,AskEngineers,SomebodyMakeThis,AppIdeas,Lightbulb,software,webapps,macapps,androidapps,iosapps,selfhosted,productivity,SaaS,SideProject,Entrepreneur,smallbusiness,nocode,webdev", feedBase: "https://rssamplifier.com", statsBase: "https://arctic-shift.photon-reddit.com", fallback: true, minScore: 0.5, buildAt: 5, windowDays: 60, trackDays: 30, statsPerRun: 40, redditUser: "", leads: true, useWriter: true, painSearches: 6, }; export const DEFAULT_HUBS: HubsSettings = { watch: 8, postsPerHub: 10, maxAgeHours: 72, draftsPerScan: 10, bskyBase: "https://api.bsky.app", }; export const DEFAULT_SETTINGS: Settings = { defaultTargets: "all", signature: "", theme: "dark", threadByDefault: true, ai: { // c0mpute, our own peer network: no key, a fraction of a cent a draft. provider: "c0mpute", model: "claude-opus-5", voice: "Plain, specific, no hype. Never open with a hook cliché.", maxHashtags: 3, }, infographic: { accent: "#5eead4", background: "#0b1020", footer: "", }, graph: { enabled: false, followsPerHour: 10, followsPerDay: 80, perSeed: 200, expandEveryHours: 168, followSeeds: true, minSeeds: 1, networks: "all", expand: "following", followerWeight: 0.5, outreachgraph: false, }, pacing: { ...DEFAULT_PACING }, evergreen: { ...DEFAULT_EVERGREEN }, recap: { ...DEFAULT_RECAP }, links: { ...DEFAULT_LINKS }, blog: {}, utm: DEFAULT_UTM, skills: { defaults: {}, rotate: {}, cursor: {} }, profile: { ...DEFAULT_PROFILE }, reshare: { ...DEFAULT_RESHARE }, engage: { ...DEFAULT_ENGAGE }, hubs: { ...DEFAULT_HUBS }, autopilot: { ...DEFAULT_AUTOPILOT }, upvote: { ...DEFAULT_UPVOTE }, asks: { ...DEFAULT_ASKS }, did: { ...DEFAULT_DID }, outreach: { ...DEFAULT_OUTREACH }, newsletter: newsletterSettings(undefined), synconfig: { ...DEFAULT_SYNCONFIG }, plugins: [], directories: [], }; /** * MYNA_AI_PROVIDER and MYNA_AI_MODEL win over settings.json. A hosted API has * no settings file and no `myna config`, so the environment is its only knob. */ function aiFromEnv(): Partial { const out: Partial = {}; const provider = process.env.MYNA_AI_PROVIDER; if (provider === "c0mpute" || provider === "anthropic" || provider === "openai" || provider === "ollama") out.provider = provider; if (process.env.MYNA_AI_MODEL) out.model = process.env.MYNA_AI_MODEL; return out; } export function loadSettings(): Settings { const stored = readJson>(SETTINGS_FILE, {}); return { ...DEFAULT_SETTINGS, ...stored, ai: { ...DEFAULT_SETTINGS.ai, ...stored.ai, ...aiFromEnv() }, infographic: { ...DEFAULT_SETTINGS.infographic, ...stored.infographic }, graph: { ...DEFAULT_SETTINGS.graph, ...stored.graph }, pacing: { ...DEFAULT_SETTINGS.pacing, ...stored.pacing }, evergreen: { ...DEFAULT_SETTINGS.evergreen, ...stored.evergreen }, recap: resolveRecapSettings(stored.recap), links: { ...DEFAULT_LINKS, ...stored.links }, blog: { ...DEFAULT_SETTINGS.blog, ...stored.blog }, utm: { ...DEFAULT_UTM, ...stored.utm }, profile: { ...DEFAULT_PROFILE, ...stored.profile }, reshare: { ...DEFAULT_RESHARE, ...stored.reshare }, engage: { ...DEFAULT_ENGAGE, ...stored.engage }, hubs: { ...DEFAULT_HUBS, ...stored.hubs }, autopilot: { ...DEFAULT_AUTOPILOT, ...stored.autopilot }, asks: { ...DEFAULT_ASKS, ...stored.asks }, did: { ...DEFAULT_DID, ...stored.did }, outreach: { ...DEFAULT_OUTREACH, ...stored.outreach }, newsletter: newsletterSettings(stored.newsletter), synconfig: { ...DEFAULT_SYNCONFIG, ...stored.synconfig }, skills: { defaults: { ...(stored.skills?.defaults ?? {}) }, rotate: { ...(stored.skills?.rotate ?? {}) }, cursor: { ...(stored.skills?.cursor ?? {}) }, }, plugins: Array.isArray(stored.plugins) ? stored.plugins.filter((entry) => typeof entry === "string") : [], }; } /** * The recap as the daemon sends it: the stored switch, and an address even * when none was set — the profile email, else the myna cloud login's — so an * install that never ran `myna recap on` still gets its nightly summary. */ export function effectiveRecap(settings: Settings = loadSettings()): RecapSettings & { toSource: ReturnType["source"] } { let cloud: string | undefined; try { cloud = cloudSession()?.email; } catch { cloud = undefined; } const address = recapAddress(settings.recap, { profile: settings.profile.email, cloud }); return { ...settings.recap, to: address.to, toSource: address.source }; } /** The live-links report as the daemon sends it: its own address, else the recap's. */ export function effectiveLinks(settings: Settings = loadSettings()): LinksSettings & { toSource: "links.to" | "recap" | "none" } { if (settings.links.to.trim()) return { ...settings.links, to: settings.links.to.trim(), toSource: "links.to" }; const recap = effectiveRecap(settings); return { ...settings.links, to: recap.to, toSource: recap.to ? "recap" : "none" }; } export function saveSettings(settings: Settings): void { writeJson(SETTINGS_FILE, settings); }