Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit d3acb9de0cc988b196d69ada309f60d9b1de9656
parent 2605f7f648f7c52764cb24f3ff0d0a5d36bccd8c
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 15 Oct 2026 08:29:38 -0400

common: review fixes โ€” X weighs a scheme-less domain it would link (`Kick.com`, `x.co`, `a.pages.dev/โ€ฆ`: a label.tld from SOCIAL_TLDS, not glued to a word, an @ or a dot) as 23, and the social task refuses one (`hasLink`); a social post loses quotation marks only when they wrap it whole, so a verbatim quote that opens or ends a post is kept

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mcommon/lib/report/draft/tasks/social.test.ts | 25++++++++++++++++++++++++-
Mcommon/lib/report/draft/tasks/social.ts | 18+++++++++++++-----
Mcommon/lib/report/social.d.mts | 2++
Mcommon/lib/report/social.mjs | 25+++++++++++++++++++++++--
4 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/common/lib/report/draft/tasks/social.test.ts b/common/lib/report/draft/tasks/social.test.ts @@ -14,7 +14,7 @@ import path from "node:path"; import { jsonReply, startFakeOllama, type FakeOllama } from "../../../../testing/llm/fakeOllama.mjs"; import { PROJECT_URL } from "../../../project"; import { createIteration, projectOf, updateIteration, writeIterationFile } from "../../iterations"; -import { blueskyLength, graphemes, SOCIAL_LIMITS, socialLinkOf, validateSocialPost, withLink, xLength } from "../../social.mjs"; +import { blueskyLength, graphemes, hasLink, SOCIAL_LIMITS, socialLinkOf, validateSocialPost, withLink, xLength } from "../../social.mjs"; import { groundingInputOf } from "../grounding"; import type { DraftFile } from "./media"; import { postBudget, postProblems, social, socialSystem } from "./social"; @@ -43,6 +43,14 @@ test("X weighs a URL as 23 whatever its length, an emoji as 2, a CJK character a assert.equal(xLength("๐Ÿ™‚"), 2); assert.equal(xLength("๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"), 2, "a family is one emoji"); assert.equal(xLength("ๆ—ฅๆœฌ"), 4); + // A bare domain is a link to X too (review fix): "Kick.com" is 23, not 8. + assert.equal(xLength("Kai streamed on Kick.com"), 16 + 23); + assert.equal(xLength("jeralyzer.pages.dev/pages/a"), 23); + assert.ok(hasLink("on Kick.com") && hasLink("x.co") && !hasLink("e.g. this, i.e. that, No. 5, 3.5 million, a@b.com")); + // 270 characters and two bare domains are 318 as X counts them, not 280. + const two = `${"a".repeat(270)} x.co x.co`; + assert.equal(xLength(two), 318); + assert.deepEqual(validateSocialPost("x", { post: two }), ["publish.x.post is 318 characters as X counts them (at most 280)"]); // Three long links and the text between them: 205 + 3 ร— (1 + 23) + 3 = 280, at the limit. const link = (i: number) => `https://archive.example/moment/${"x".repeat(60)}/${i}`; const text = `${"a".repeat(205)} ${link(1)} ${link(2)} ${link(3)} bb`; @@ -91,6 +99,7 @@ test("the checks: third person, grounded, quotes only verbatim, no link, hashtag assert.match(hard('The baker says "I will sell the bakery" now.'), /is not what a cited clip says, word for word/); assert.match(hard("Synth Kitchen's baker on the bakery: https://synth.example"), /no links, timestamps, hashtags or @mentions/); assert.match(hard("Synth Kitchen's baker on the bakery #bread"), /no links, timestamps, hashtags or @mentions/); + assert.match(hard("Synth Kitchen's baker streams on Kick.com"), /no links, timestamps, hashtags or @mentions/); assert.match(hard("Synth Kitchen's baker on the bakery @synthkitchen"), /no links, timestamps, hashtags or @mentions/); assert.match(hard("Synth Kitchen's baker on the bakery ๐Ÿž"), /no emoji/); // 255 characters fit beside the link; 256 do not. @@ -188,6 +197,20 @@ test("the link appended by code: a public article's page on the homepage, else t assert.ok((await vid.manifestNow()).publish.x.post.endsWith("\n\nhttps://video.example/watch/1")); }); +test("a post wrapped whole in quotation marks loses them; a quote that opens or ends a post is kept verbatim", async () => { + const p = await project(); + ol.push( + jsonReply({ post: '"Synth Kitchen\'s baker says she paid for the new mixer herself."', thread: ['Synth Kitchen\'s baker says, "I paid for the new mixer myself"'] }), + jsonReply({ post: '"I would never sell the bakery to a chain," says the baker of Synth Kitchen.', thread: [] }), + ); + const res = await social(p.input, p.deps); + assert.equal(res.status, "done", res.summary); + const m = await p.manifestNow(); + assert.equal(m.publish.x.post, "Synth Kitchen's baker says she paid for the new mixer herself."); + assert.deepEqual(m.publish.x.thread, ['Synth Kitchen\'s baker says, "I paid for the new mixer myself"']); + assert.equal(m.publish.bluesky.post, '"I would never sell the bakery to a chain," says the baker of Synth Kitchen.'); +}); + test("a post over its count with its link is trimmed at a sentence; a failing thread post dropped; five thread posts refused, then cut to four", async () => { const p = await project({ publicArticle: true }); const long = "Synth Kitchen's baker says she would not sell the bakery to a chain.".padEnd(240, " ") + " She says she paid for the new mixer herself."; diff --git a/common/lib/report/draft/tasks/social.ts b/common/lib/report/draft/tasks/social.ts @@ -27,7 +27,7 @@ import { PROJECT_URL } from "../../../project"; import { readArticleState } from "../../registry"; import { ARTICLES_REPORTS_BASE } from "../../routes"; -import { SOCIAL_LIMITS, SOCIAL_NAMES, socialLength, socialLinkOf, withLink, type SocialPlatform, type SocialPost } from "../../social.mjs"; +import { SOCIAL_LIMITS, SOCIAL_NAMES, hasLink, socialLength, socialLinkOf, withLink, type SocialPlatform, type SocialPost } from "../../social.mjs"; import { reportPagePath } from "../../views"; import { sentencesOf, type GroundingInput } from "../grounding"; import { checkLine } from "./clipEvidence"; @@ -42,8 +42,10 @@ export type SocialValue = { post: string; thread: string[] }; type SocialUnit = MediaUnit & { platform: SocialPlatform; link: string | null; g: GroundingInput; evidence: string }; const oneLine = (s: unknown) => String(s ?? "").replace(/\s+/g, " ").trim(); -// What the model may not write: a link, a timestamp, a hashtag, an @mention. -const NOT_WRITTEN = /https?:\/\/|www\.|\b\d{1,2}:\d{2}\b|(^|\s)#\w|(^|\s)@\w/; +// What the model may not write: a link (a scheme, www. or a bare domain X +// would link: social.mjs hasLink), a timestamp, a hashtag, an @mention. +const NOT_WRITTEN = /\b\d{1,2}:\d{2}\b|(^|\s)#\w|(^|\s)@\w/; +const notWritten = (text: string) => hasLink(text) || NOT_WRITTEN.test(text); const EMOJI = /\p{Extended_Pictographic}/u; /** Room the link takes under the first post (its blank line included). */ @@ -63,7 +65,7 @@ export function postProblems(text: string, u: Pick<SocialUnit, "platform" | "lin const limit = SOCIAL_LIMITS[u.platform]; const n = socialLength(u.platform, first ? withLink(text, u.link) : text); if (n > limit) hard.push(`${where} is ${n} ${u.platform === "bluesky" ? "graphemes" : "characters as X counts them"}${first && u.link ? " with its link" : ""} (at most ${limit})`); - if (NOT_WRITTEN.test(text)) hard.push(`${where}: no links, timestamps, hashtags or @mentions โ€” the link is added after it`); + if (notWritten(text)) hard.push(`${where}: no links, timestamps, hashtags or @mentions โ€” the link is added after it`); if (EMOJI.test(text)) hard.push(`${where}: no emoji`); const r = text ? checkLine(text, u.g, { quotes: true }) : { hard: [], soft: [] }; return { hard: [...hard, ...r.hard.map((h) => `${where}: ${h}`)], soft: r.soft.map((s) => `${where}: ${s}`) }; @@ -145,7 +147,13 @@ export const SOCIAL_SPEC: MediaTaskSpec<SocialUnit, SocialValue, SocialInput> = user: (u) => `${u.evidence}\n\nWrite the ${SOCIAL_NAMES[u.platform]} post and its thread.`, parse(answer) { const a = answer as { post?: unknown; thread?: unknown } | null; - const clean = (s: unknown) => oneLine(s).replace(/^["โ€œ]+|["โ€]+$/g, ""); + // A post the model wrapped whole in quotation marks loses them; a quote + // inside the post (or one that opens or ends it) is the speaker's, kept. + const clean = (s: unknown) => { + const t = oneLine(s); + const m = /^["โ€œ]([^"โ€œโ€]*)["โ€]$/.exec(t); + return m ? m[1]!.trim() : t; + }; return { post: clean(a?.post), thread: (Array.isArray(a?.thread) ? a.thread : []).map(clean).filter(Boolean), diff --git a/common/lib/report/social.d.mts b/common/lib/report/social.d.mts @@ -9,6 +9,8 @@ export const SOCIAL_PLATFORMS: readonly SocialPlatform[]; export const SOCIAL_LIMITS: Readonly<{ x: number; bluesky: number; thread: number; urlWeight: number }>; export const SOCIAL_NAMES: Readonly<Record<SocialPlatform, string>>; export const SOCIAL_URL_RE: RegExp; +export const SOCIAL_TLDS: readonly string[]; +export function hasLink(text: unknown): boolean; export function graphemes(text: unknown): string[]; export function xLength(text: unknown): number; diff --git a/common/lib/report/social.mjs b/common/lib/report/social.mjs @@ -26,8 +26,29 @@ export const SOCIAL_LIMITS = Object.freeze({ x: 280, bluesky: 300, thread: 4, ur /** What the page calls each platform. */ export const SOCIAL_NAMES = Object.freeze({ x: "X", bluesky: "Bluesky" }); -/** A URL as X sees one in a post (scheme, or a www. host). */ -export const SOCIAL_URL_RE = /\bhttps?:\/\/[^\s<>"]+|\bwww\.[^\s<>"]+\.[a-z]{2,}[^\s<>"]*/giu; +// The top-level domains a scheme-less `label.tld` is taken as a link for +// (X auto-links `Kick.com`, `x.com`, `jeralyzer.pages.dev` and weighs each as a +// URL). Conservative: the common generic TLDs and the country codes a link in +// a post is likely to carry โ€” counting a domain X would not link as 23 only +// makes a post shorter than it could be, never too long. +export const SOCIAL_TLDS = Object.freeze([ + "com", "net", "org", "edu", "gov", "info", "biz", "io", "co", "dev", "app", "ai", "gg", "tv", "fm", "me", "ly", "so", "to", + "xyz", "live", "news", "page", "site", "online", "blog", "link", "social", "video", "media", "art", "store", "shop", + "us", "uk", "ca", "au", "de", "fr", "es", "it", "nl", "be", "ch", "at", "se", "no", "dk", "fi", "ie", "pl", "pt", "ru", + "br", "mx", "ar", "in", "jp", "kr", "cn", "nz", "za", "eu", "is", "sh", "ws", "cc", "la", "im", "ms", "gl", "vc", "lol", +]); +const TLD = SOCIAL_TLDS.join("|"); +// A scheme-less domain: labels and a known TLD, not glued to a word, an @ (a +// handle or an address) or a dot before it, a path after it if any. +const BARE_DOMAIN = `(?<![\\w@.-])(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+(?:${TLD})(?![\\w-])(?:\\/[^\\s<>"]*)?`; + +/** A URL as X sees one in a post: a scheme, a `www.` host, or a bare `label.tld` (SOCIAL_TLDS). */ +export const SOCIAL_URL_RE = new RegExp(`\\bhttps?:\\/\\/[^\\s<>"]+|\\bwww\\.[^\\s<>"]+\\.[a-z]{2,}[^\\s<>"]*|${BARE_DOMAIN}`, "giu"); + +/** Whether a text holds anything X would turn into a link (a URL, a www. host, a bare domain). */ +export function hasLink(text) { + return new RegExp(SOCIAL_URL_RE.source, "iu").test(String(text ?? "")); +} const X_LIGHT = [ [0, 4351],