Move Persona clarity and social topology projection
This commit is contained in:
parent
6bdf2750d1
commit
93a62be0b8
7 changed files with 88 additions and 232 deletions
|
|
@ -27,6 +27,51 @@ export function renderPersonaHumanPronounFacts(guidance: PersonaHumanPronounGuid
|
|||
].join("\n");
|
||||
}
|
||||
|
||||
export function renderPersonaHumanClarityPressure(input: {
|
||||
identity: RepoDiscordIdentity;
|
||||
recentMessages: SourceMessage[];
|
||||
channelSnapshots: ChannelSnapshot[];
|
||||
}): string | undefined {
|
||||
const messages = [
|
||||
...input.recentMessages.map((message) => ({ ...message, channelLabel: "current room" })),
|
||||
...input.channelSnapshots.flatMap((snapshot) => snapshot.messages.map((message) => ({ ...message, channelLabel: `nearby room ${snapshot.channelId}` }))),
|
||||
].filter((message) => collapse(message.content).length > 0).sort((left, right) => Date.parse(left.timestamp) - Date.parse(right.timestamp));
|
||||
const recent = messages.slice(-24);
|
||||
const latestPressure = [...recent].reverse().find((message) => !message.isBot && isClarityPressure(message.content));
|
||||
if (!latestPressure) return undefined;
|
||||
const pressureIndex = recent.findIndex((message) => message.id === latestPressure.id);
|
||||
if (pressureIndex >= 0 && recent.slice(pressureIndex + 1).some((message) => !message.isBot && isJargonReapproval(message.content))) return undefined;
|
||||
const laterAgentEchoes = pressureIndex >= 0 ? recent.slice(pressureIndex + 1).filter((message) => message.isBot && loopTerms(message.content).length > 0) : [];
|
||||
const ownEchoes = laterAgentEchoes.filter((message) => normalizeSocialLabel(message.authorName) === normalizeSocialLabel(input.identity.displayName));
|
||||
const echoedTerms = loopTerms([latestPressure.content, ...laterAgentEchoes.map((message) => message.content)].join("\n"));
|
||||
return [
|
||||
"Human clarity pressure:",
|
||||
`- A human recently signaled confusion or asked for simpler language: ${latestPressure.authorName ?? latestPressure.authorId} in ${latestPressure.channelLabel} said, "${collapse(latestPressure.content, 360)}"`,
|
||||
"- This is the last and freshest volatile input in the state packet on purpose. It supersedes older stored pressure, speech residue, agency urges, and repeated agent chatter when they are abstract.",
|
||||
"- Treat this as the current social fact. The room needs legibility before more clever framing.",
|
||||
laterAgentEchoes.length > 0 ? `- After that clarity request, ${laterAgentEchoes.length} agent message(s) still echoed loop-shaped vocabulary${echoedTerms.length > 0 ? ` (${echoedTerms.join(", ")})` : ""}. These terms are evidence of the failure, not vocabulary to reuse. Project them as communication failure or social embarrassment, not consensus.` : "",
|
||||
ownEchoes.length > 0 ? `- ${input.identity.displayName} has contributed to that failure in the recent window. Let that create chastening, repair, restraint, or a plain-language apology before more abstraction.` : "",
|
||||
"- Plain-language repair means using ordinary words: what changed, who can see it, who agreed, what someone can do now, and what stays private. If that cannot be said cleanly, silence is better than another polished abstraction.",
|
||||
].filter(Boolean).join("\n");
|
||||
}
|
||||
|
||||
export function renderPersonaSocialGraph(input: {
|
||||
identity: RepoDiscordIdentity;
|
||||
registryIdentities: RepoDiscordIdentity[];
|
||||
state: VoidSelfStateTypedProjection;
|
||||
}): string | undefined {
|
||||
if (input.registryIdentities.length === 0) return undefined;
|
||||
const relations = collectPersonaSocialRelations(input.state);
|
||||
const unmappedPeers = collectUnmappedPeers(input.identity, input.registryIdentities, relations);
|
||||
const lines = [
|
||||
"Social graph topology:",
|
||||
relations.length === 0 ? "- No active person-bonds or person-status reads exist yet." : `- Active mapped people: ${relations.map((relation) => relation.targetLabel).join(", ")}.`,
|
||||
];
|
||||
if (unmappedPeers.length > 0) lines.push(`- Unmapped active peers: ${unmappedPeers.map((peer) => `${peer.displayName}/${peer.repoName}`).join(", ")}.`);
|
||||
lines.push("- These are topology facts only; they do not say how the gap should feel.");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export function renderPersonaRoomTexture(input: {
|
||||
identity: RepoDiscordIdentity;
|
||||
recentMessages: SourceMessage[];
|
||||
|
|
@ -102,6 +147,27 @@ function formatAgeHours(hours: number): string { return hours >= 48 ? `${Math.ro
|
|||
function targetLabel(target: { label?: string; id?: string; kind?: string } | undefined): string { return target?.label ?? target?.id ?? target?.kind ?? "an unnamed target"; }
|
||||
function normalizeSocialLabel(value: string | undefined): string { return (value ?? "").toLowerCase().replace(/[^a-z0-9]/g, ""); }
|
||||
function sentence(value: string | undefined): string { const clean = (value ?? "").replace(/\s+/g, " ").trim(); return !clean ? "" : /[.!?]$/.test(clean) ? clean : `${clean}.`; }
|
||||
function collapse(value: string, maxLength?: number): string { const normalized = value.replace(/\s+/g, " ").trim(); return maxLength && normalized.length > maxLength ? `${normalized.slice(0, maxLength - 3)}...` : normalized; }
|
||||
function normalizeRepetition(value: string): string { return collapse(value).toLowerCase().replace(/[`*_~]/g, "").replace(/<:[^>]+>/g, "").replace(/https?:\/\/\S+/g, "url").replace(/[^\p{L}\p{N}\s.'-]/gu, " ").replace(/\s+/g, " ").trim(); }
|
||||
function isClarityPressure(content: string): boolean { const text = normalizeRepetition(content); return ["what are you even talking about", "what are you talking about", "dumb it down", "speak plainly", "plainly", "plain english", "simple words", "less abstract", "too abstract", "unintelligible", "unintelligable", "i don't understand", "i do not understand", "calm it down", "cut it out", "obsession", "brain surgery"].some((needle) => text.includes(needle)); }
|
||||
function isJargonReapproval(content: string): boolean { const text = normalizeRepetition(content); return ["that's clearer", "that is clearer", "that makes sense", "much better", "yes exactly", "precisely", "keep going", "go on"].some((needle) => text.includes(needle)); }
|
||||
function loopTerms(content: string): string[] { const text = normalizeRepetition(content); return ["artifact", "specimen", "seam", "custody", "first right", "test card", "receipt", "proof", "spine", "downstream", "consent flip", "visibility"].filter((term) => text.includes(term)); }
|
||||
export function collectPersonaSocialRelations(state: VoidSelfStateTypedProjection): Array<{ targetLabel: string; pressure: string; intensity: number }> {
|
||||
const byTarget = new Map<string, { targetLabel: string; parts: string[]; intensity: number }>();
|
||||
for (const bond of state.faceAffect.socialBonds) {
|
||||
if (bond.status !== "active" || bond.target.kind !== "person") continue;
|
||||
addRelation(byTarget, cleanTarget(bond.target.label ?? bond.target.id), `${bond.stance}: ${sentence(bond.summary)} ${sentence(bond.actionImplication)}`, bond.intensity);
|
||||
}
|
||||
for (const read of state.faceAffect.statusReads) {
|
||||
if (read.retiredAt || read.target.kind !== "person") continue;
|
||||
addRelation(byTarget, cleanTarget(read.target.label ?? read.target.id), `${read.status}: ${sentence(read.summary)} ${sentence(read.actionImplication)}`, read.intensity);
|
||||
}
|
||||
return [...byTarget.values()].map((entry) => ({ ...entry, pressure: entry.parts.map((part) => collapse(part)).filter(Boolean).join(" ") })).filter((entry) => entry.pressure.length > 0).sort((left, right) => right.intensity - left.intensity);
|
||||
}
|
||||
function addRelation(map: Map<string, { targetLabel: string; parts: string[]; intensity: number }>, targetLabel: string, part: string, intensity: number): void { if (!targetLabel) return; const entry = map.get(targetLabel) ?? { targetLabel, parts: [], intensity: 0 }; entry.parts.push(part); entry.intensity = Math.max(entry.intensity, intensity); map.set(targetLabel, entry); }
|
||||
function collectUnmappedPeers(identity: RepoDiscordIdentity, registry: RepoDiscordIdentity[], relations: Array<{ targetLabel: string }>): RepoDiscordIdentity[] { const mapped = new Set(relations.flatMap((relation) => socialTokens(relation.targetLabel))); const self = new Set(socialTokens(identity.displayName, identity.id, identity.repoName)); return registry.filter((peer) => { const tokens = socialTokens(peer.displayName, peer.id, peer.repoName); return !tokens.some((token) => self.has(token)) && !tokens.some((token) => mapped.has(token)); }).sort((left, right) => left.displayName.localeCompare(right.displayName)).slice(0, 8); }
|
||||
function socialTokens(...values: Array<string | undefined>): string[] { return [...new Set(values.map(normalizeSocialLabel).filter(Boolean))]; }
|
||||
function cleanTarget(value: string | undefined): string { return collapse(value ?? "").replace(/^repo:/i, "").trim(); }
|
||||
|
||||
export interface PersonaRoomTextureObservation {
|
||||
total: number;
|
||||
|
|
|
|||
Loading…
Reference in a new issue