Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
Merge remote-tracking branch 'origin/main' into next/issue-1289
[._.]/ Adam Eivy5e45aa6e14e9
diff --cc .changelog/NEXT.mdindex 9621fb2e9b,bc970998bc..10810ac823--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@@ -2,7 -2,7 +2,9 @@@## Added- - **[issue-1289] Ticking clock — model the countdown your reader is anticipating.** A story's "what is this building toward?" — an incoming storm, a deadline, a prophecy's hour — is now a first-class part of the series arc instead of something only implied. On the Arc Canvas you can turn on a **ticking clock**, name it, pick its kind (deadline / event / countdown / prophecy / bomb / custom), set where it's planted and where it's due, and spell out the stakes if it runs out; it shows on the arc card and the Story Builder reader-map view with its plant→due span and reminder beats. The countdown is fed into arc generation so the AI reinforces it, and a new **Ticking-clock hygiene** editorial check flags a clock that's unnamed, has no stakes, has no plant/due span, is due before it's planted, or has no reminder beats to keep the reader from forgetting it through the long middle. (#1289)++- **[issue-1289] Ticking clock — model the countdown your reader is anticipating.** A story's "what is this building toward?" — an incoming storm, a deadline, a prophecy's hour — is now a first-class part of the series arc instead of something only implied. On the Arc Canvas you can turn on a **ticking clock**, name it, pick its kind (deadline / event / countdown / prophecy / bomb / custom), set where it's planted and where it's due, spell out the stakes if it runs out, and add **reminder beats** that keep it ticking in the reader's mind; it shows on the arc card and the Story Builder reader-map view with its plant→due span. The countdown is fed into arc generation so the AI reinforces it, and a new **Ticking-clock hygiene** editorial check flags a clock that's unnamed, has no stakes, has no plant/due span, is due before it's planted, or has no reminder beats to keep the reader from forgetting it through the long middle. (#1289)+++ - **[issue-1288] Object↔character attachments — model who cares about each object, and why.** An object's significance used to be a single free-text field with no link to the cast. Each universe object now also carries **structured attachments**: pick a character, then capture the **emotion** they feel toward the object (grief, pride, guilt, longing…), **why it matters** to that specific character, **how they came to have it** (the backstory link), and a **role** archetype (talisman / macguffin / memento / tool / symbol / custom). The object card in the universe canon editor gets a collapsible **Attachments** section to add, edit, and remove these. Three new editorial checks read the web: **Unattached significant object** (an object with written significance that nobody is on record caring about), **Unmotivated object interaction** (an LLM scan for moments where a character treats an object as significant with no established reason), and **Attachment backstory consistency** (an LLM check that flags an attachment whose origin story contradicts the character's established background). The legacy prose `significance` field is untouched; attachments are purely additive and version-gated for cross-machine sync so an older peer can't silently strip them. (#1288)- **Structured character relationships + opposing-force tagging.** A character's relationships used to be a single free-text field — readable, but invisible to tooling. Each universe character now also carries **structured relationship links**: pick a target character from the cast, tag the dynamic (ally / antagonist / rival / mentor / love-interest / family / custom), and add a short description. A link can optionally carry an **opposing force** — a binary tension the reader watches to see reverse (hunter/prey, winner/loser, predator/prey, smart/dumb, or a custom axis), with each side's role and a note ("reader is waiting to see if these flip"). The Cast editor surfaces opposition pairs prominently (they're a story spine, not every story has them). Three new editorial checks validate the web: **Relationship reciprocity** (A links B but B doesn't link back), **Relationship dangling target** (a link points at a deleted character), and an advisory **Opposition role-reversal payoff** (surfaces every tagged opposing-force pair so you can confirm the roles ever reverse — or deliberately don't). The legacy prose `relationships` field is untouched; `relationshipLinks` is purely additive and version-gated for cross-machine sync so an older peer can't silently strip it. (`server/lib/storyBible.js`, `server/lib/validation.js`, `server/lib/editorial/checkRegistry.js`, `server/lib/schemaVersions.js`, `client/src/components/universe/CharacterDetailEditor.jsx`) (#1287)diff --cc server/lib/editorial/checkRegistry.jsindex 9f3514eb7e,cea1c6d859..38303f7fa7--- a/server/lib/editorial/checkRegistry.js+++ b/server/lib/editorial/checkRegistry.js@@@ -251,99 -370,147 +370,240 @@@ export const EDITORIAL_CHECKS =return findings;},},+ {+ id: 'arc.ticking-clock-hygiene',+ label: 'Ticking-clock hygiene',+ description:+ 'Advisory — checks the series ticking clock/countdown is fully specified: named, with stakes, a plant→due span, and reminder beats so the reader does not forget it through the long middle.',+ scope: 'series',+ kind: 'deterministic',+ category: 'arc',+ severityDefault: 'low',+ defaultEnabled: true,+ configSchema: z.object({+ // How many reminder beats an enabled clock should carry. 0 disables the+ // reminder-count check while keeping the named/stakes/span checks.+ minReminders: z.number().int().min(0).max(20).default(1),+ }),+ configFields: [+ {+ key: 'minReminders',+ label: 'Minimum reminder beats',+ type: 'number',+ min: 0,+ max: 20,+ step: 1,+ help: 'How many reminder beats an enabled ticking clock should have so the reader does not forget it through the long middle.',+ },+ ],+ // Only audit a clock the author turned on — a disabled/absent clock means+ // "this story has no countdown", which is a valid choice, not a problem.+ gate: (ctx) => ctx.series?.arc?.tickingClock?.enabled === true,+ run: (ctx) => {+ const clock = ctx.series?.arc?.tickingClock;+ if (!clock || clock.enabled !== true) return [];+ const minReminders = ctx.config?.minReminders ?? 1;+ const label = clock.label || 'the ticking clock';+ const location = `Series arc: ${clock.label || 'ticking clock'}`;+ const findings = [];+ const flag = (problem, suggestion) => findings.push({+ severity: ctx.severityDefault,+ category: 'arc',+ location,+ problem,+ suggestion,+ anchorQuote: clock.label || '',+ issueNumber: null,+ });+ if (!clock.label) {+ flag(+ 'The ticking clock is enabled but unnamed — the reader needs a concrete thing to count down to.',+ 'Give the countdown a specific label (e.g. "The storm makes landfall").',+ );+ }+ if (!clock.stakes) {+ flag(+ `The ticking clock "${label}" has no stakes — it is unclear what the reader fears if it runs out.`,+ 'State what happens when the clock hits zero so the countdown carries dread.',+ );+ }+ if (clock.plantedAtArcPosition == null) {+ flag(+ `The ticking clock "${label}" has no plant position — the reader never learns the countdown has started.`,+ 'Set where the reader first learns of the countdown (plantedAtArcPosition).',+ );+ }+ if (clock.dueAtArcPosition == null) {+ flag(+ `The ticking clock "${label}" has no due position — there is no moment it lands.`,+ 'Set where the countdown pays off (dueAtArcPosition).',+ );+ }+ // Plant and due share the arc-position coordinate space, so they're+ // directly comparable; a due at/before the plant leaves no span for+ // tension to build. (Reminders use issue numbers, a different axis, so+ // they're intentionally NOT compared against the plant/due span here.)+ if (+ clock.plantedAtArcPosition != null+ && clock.dueAtArcPosition != null+ && clock.dueAtArcPosition <= clock.plantedAtArcPosition+ ) {+ flag(+ `The ticking clock "${label}" is due (arc position ${clock.dueAtArcPosition}) at or before it is planted (${clock.plantedAtArcPosition}) — there is no span for tension to build.`,+ 'Set the due position after the plant position.',+ );+ }+ const reminders = Array.isArray(clock.reminders) ? clock.reminders : [];+ if (reminders.length < minReminders) {+ flag(+ `The ticking clock "${label}" has ${reminders.length} reminder beat(s) (expected at least ${minReminders}) — without periodic reminders the reader forgets it through the long middle.`,+ 'Add reminder beats between the plant and due to keep the countdown alive in the reader’s mind.',+ );+ }+ return findings;+ },+ },+ {+ id: 'objects.unattached-significant',+ label: 'Unattached significant object',+ description:+ 'Flags objects with written significance but no character attachment — the object clearly matters to the story, yet nobody in the cast is on record caring about it.',+ scope: 'series',+ kind: 'deterministic',+ category: 'continuity',+ severityDefault: 'low',+ defaultEnabled: true,+ configSchema: z.object({}),+ run: (ctx) => {+ const { objects, nameById } = attachmentCanon(ctx);+ const findings = [];+ for (const o of objects) {+ // Only a LIVE attachment (one whose characterId still resolves to a+ // cast member) counts as "someone cares" — an object whose sole+ // attachment dangles at a deleted character is effectively unattached+ // (the UI shows it as "(missing)"), so it should still be flagged.+ const attachments = Array.isArray(o.attachments) ? o.attachments : [];+ const hasLiveAttachment = attachments.some((a) => a?.characterId && nameById.has(a.characterId));+ const significance = (o.significance || '').trim();+ if (hasLiveAttachment || !significance) continue;+ const name = o.name || o.id;+ findings.push({+ severity: ctx.severityDefault,+ category: 'continuity',+ location: `Object: ${name}`,+ problem: `"${name}" has written significance but no character is attached to it — what does this object mean to anyone in the cast?`,+ suggestion: 'Add an attachment linking this object to the character whose backstory or emotional stake it carries (or clear its significance if it is purely set dressing).',+ anchorQuote: name,+ issueNumber: null,+ });+ }+ return findings;+ },+ },+ {+ id: 'objects.unmotivated-interaction',+ label: 'Unmotivated object interaction',+ description:+ 'LLM scan — flags moments where a character interacts meaningfully with an object the prose (and the canon attachments) have given them no reason to care about.',+ scope: 'issue',+ kind: 'llm',+ category: 'continuity',+ severityDefault: 'low',+ defaultEnabled: true,+ needsManuscript: true,+ configSchema: z.object({+ // Cap findings per run so a long manuscript can't flood the review.+ maxFindings: z.number().int().min(1).max(50).default(12),+ // Bound the prompt so a long series can't overflow a small/local provider's+ // context window. Single-call safeguard — mirrors the info-dumping check.+ maxManuscriptChars: z.number().int().min(2000).max(200_000).default(48_000),+ }),+ configFields: [+ {+ key: 'maxFindings',+ label: 'Max findings per run',+ type: 'number',+ min: 1,+ max: 50,+ step: 1,+ help: 'Cap findings so a long manuscript can not flood the review.',+ },+ {+ key: 'maxManuscriptChars',+ label: 'Max manuscript characters analyzed',+ type: 'number',+ min: 2000,+ max: 200_000,+ step: 1000,+ help: 'Bounds the prompt so a long series can not overflow a small provider context window.',+ },+ ],+ gate: (ctx) => (ctx.manuscript || '').trim().length > 0,+ run: async (ctx) => {+ const manuscript = capManuscript(ctx.manuscript, ctx.config?.maxManuscriptChars ?? 48_000);+ const { content } = await ctx.callStagedLLM(+ OBJECT_MOTIVATION_STAGE,+ { manuscript, objects: describeObjectAttachments(ctx) },+ { returnsJson: true, source: OBJECT_MOTIVATION_STAGE },+ );+ return mapLlmFindings(content?.findings, {+ severityDefault: ctx.severityDefault,+ category: 'continuity',+ max: ctx.config?.maxFindings ?? 12,+ withIssueNumber: true,+ });+ },+ },+ {+ id: 'objects.backstory-consistency',+ label: 'Attachment backstory consistency',+ description:+ "LLM check — flags object attachments whose origin story contradicts the attached character's established background.",+ scope: 'noun',+ kind: 'llm',+ category: 'continuity',+ severityDefault: 'medium',+ defaultEnabled: true,+ // Canon-only (no manuscript): compares each attachment's `origin` against the+ // attached character's `background`, both of which live on the canon.+ configSchema: z.object({+ maxFindings: z.number().int().min(1).max(50).default(12),+ }),+ configFields: [+ {+ key: 'maxFindings',+ label: 'Max findings per run',+ type: 'number',+ min: 1,+ max: 50,+ step: 1,+ help: 'Cap findings so a large cast can not flood the review.',+ },+ ],+ // Skip the LLM call entirely when no attachment has both an origin AND an+ // attached character with a background to contradict.+ gate: (ctx) => attachmentBackstoryRows(ctx).length > 0,+ run: async (ctx) => {+ const rows = attachmentBackstoryRows(ctx);+ if (!rows.length) return [];+ const attachments = rows.map((r, i) =>+ `${i + 1}. Object "${r.object}" — ${r.character}'s attachment${r.emotion ? ` (${r.emotion})` : ''}\n`+ + ` Origin (how ${r.character} came to have it): ${r.origin}\n`+ + ` ${r.character}'s established background: ${r.background}`,+ ).join('\n\n');+ const { content } = await ctx.callStagedLLM(+ OBJECT_BACKSTORY_STAGE,+ { attachments },+ { returnsJson: true, source: OBJECT_BACKSTORY_STAGE },+ );+ return mapLlmFindings(content?.findings, {+ severityDefault: ctx.severityDefault,+ category: 'continuity',+ max: ctx.config?.maxFindings ?? 12,+ withIssueNumber: false,+ });+ },+ },{id: 'prose.info-dumping',label: 'Info-dumping / "as you know, Bob" exposition',diff --cc server/lib/editorial/checkRegistry.test.jsindex 014158bc26,6e6049bc01..33420c2eaf--- a/server/lib/editorial/checkRegistry.test.js+++ b/server/lib/editorial/checkRegistry.test.js@@@ -321,64 -321,154 +321,216 @@@ describe('relationships.opposition-reve});});+describe('arc.ticking-clock-hygiene — deterministic advisory', () => {+ const CLOCK = 'arc.ticking-clock-hygiene';+ const run = (tickingClock, config = { minReminders: 1 }) =>+ getCheck(CLOCK).run({ series: { arc: { tickingClock } }, config, severityDefault: 'low' });+ const check = getCheck(CLOCK);+ const gate = (tickingClock) => check.gate({ series: { arc: { tickingClock } } });++ it('gate fires only for an enabled clock', () => {+ expect(gate(undefined)).toBe(false);+ expect(gate({ enabled: false, label: 'x' })).toBe(false);+ expect(gate({ enabled: true })).toBe(true);+ });++ it('returns nothing for a fully-specified clock', () => {+ const findings = run({+ enabled: true,+ label: 'The storm makes landfall',+ kind: 'event',+ plantedAtArcPosition: 1,+ dueAtArcPosition: 8,+ stakes: 'The town floods.',+ reminders: [{ id: 'rm-1', atIssue: 4, note: 'barometer drops' }],+ });+ expect(findings).toEqual([]);+ });++ it('flags an enabled clock missing name, stakes, plant, due, and reminders', () => {+ const findings = run({ enabled: true });+ const problems = findings.map((f) => f.problem).join(' | ');+ expect(problems).toMatch(/unnamed/i);+ expect(problems).toMatch(/no stakes/i);+ expect(problems).toMatch(/no plant position/i);+ expect(problems).toMatch(/no due position/i);+ expect(problems).toMatch(/reminder beat/i);+ for (const f of findings) {+ expect(f.category).toBe('arc');+ expect(f.severity).toBe('low');+ }+ });++ it('flags a due position at or before the plant position', () => {+ const findings = run({+ enabled: true, label: 'x', stakes: 's',+ plantedAtArcPosition: 5, dueAtArcPosition: 5,+ reminders: [{ id: 'rm-1', note: 'tick' }],+ });+ expect(findings.some((f) => /at or before it is planted/i.test(f.problem))).toBe(true);+ });++ it('respects minReminders: 0 (skips the reminder-count finding)', () => {+ const findings = run(+ { enabled: true, label: 'x', stakes: 's', plantedAtArcPosition: 1, dueAtArcPosition: 4 },+ { minReminders: 0 },+ );+ expect(findings.some((f) => /reminder beat/i.test(f.problem))).toBe(false);+ });++ it('is enabled by default', () => {+ expect(getCheck(CLOCK).defaultEnabled).toBe(true);+ });+});+++ describe('objects.unattached-significant — deterministic check (#1288)', () => {+ const run = (objects, characters = []) =>+ getCheck('objects.unattached-significant').run({ canon: { objects, characters }, config: {}, severityDefault: 'low' });++ it('flags an object with significance but no attachments', () => {+ const findings = run([+ { id: 'o1', name: 'Pocket Watch', significance: 'her father gave it to her' },+ ]);+ expect(findings).toHaveLength(1);+ expect(findings[0].category).toBe('continuity');+ expect(findings[0].location).toContain('Pocket Watch');+ expect(findings[0].problem).toMatch(/mean to anyone/i);+ });++ it('does not flag an object whose attachment resolves to a live character', () => {+ const findings = run(+ [{ id: 'o1', name: 'Pocket Watch', significance: 'matters', attachments: [{ characterId: 'c1' }] }],+ [{ id: 'c1', name: 'Mara' }],+ );+ expect(findings).toEqual([]);+ });++ it('flags an object whose only attachment dangles at a deleted character', () => {+ // The character was deleted, leaving a "(missing)" attachment — the object+ // is effectively unattached, so it must still surface.+ const findings = run(+ [{ id: 'o1', name: 'Pocket Watch', significance: 'matters', attachments: [{ characterId: 'gone' }] }],+ [{ id: 'c1', name: 'Mara' }],+ );+ expect(findings).toHaveLength(1);+ expect(findings[0].location).toContain('Pocket Watch');+ });++ it('does not flag an object with no significance (pure set dressing)', () => {+ const findings = run([{ id: 'o1', name: 'A Chair' }]);+ expect(findings).toEqual([]);+ });++ it('tolerates empty / id-less canon', () => {+ expect(run([])).toEqual([]);+ expect(run([{ significance: 'orphan, no id' }])).toEqual([]);+ });+ });++ describe('objects.unmotivated-interaction — LLM check (#1288)', () => {+ const baseCtx = (overrides = {}) => ({+ manuscript: 'She clutched the watch as if it meant everything.',+ canon: {+ objects: [{ id: 'o1', name: 'Watch', significance: 'heirloom', attachments: [{ characterId: 'c1', emotion: 'grief' }] }],+ characters: [{ id: 'c1', name: 'Mara' }],+ },+ config: { maxManuscriptChars: 48_000, maxFindings: 12 },+ severityDefault: 'low',+ callStagedLLM: async () => ({ content: { findings: [] } }),+ ...overrides,+ });++ it('passes the manuscript AND an objects-attachment summary to the model', async () => {+ let vars = null;+ await getCheck('objects.unmotivated-interaction').run(baseCtx({+ callStagedLLM: async (_stage, v) => { vars = v; return { content: { findings: [] } }; },+ }));+ expect(vars.manuscript).toContain('clutched the watch');+ expect(vars.objects).toContain('Watch');+ expect(vars.objects).toContain('Mara'); // resolved character name, not the id+ });++ it('caps the manuscript so a long corpus cannot overflow context', async () => {+ let sent = null;+ await getCheck('objects.unmotivated-interaction').run(baseCtx({+ manuscript: 'x'.repeat(100_000),+ config: { maxManuscriptChars: 10_000, maxFindings: 12 },+ callStagedLLM: async (_stage, v) => { sent = v.manuscript; return { content: { findings: [] } }; },+ }));+ expect(sent.length).toBeLessThan(11_000);+ expect(sent).toContain('truncated');+ });++ it('shapes findings into the continuity category and respects maxFindings', async () => {+ const many = Array.from({ length: 30 }, (_, i) => ({ severity: 'low', problem: `p${i}`, anchorQuote: `a${i}` }));+ const findings = await getCheck('objects.unmotivated-interaction').run(baseCtx({+ config: { maxManuscriptChars: 48_000, maxFindings: 4 },+ callStagedLLM: async () => ({ content: { findings: many } }),+ }));+ expect(findings).toHaveLength(4);+ expect(findings.every((f) => f.category === 'continuity')).toBe(true);+ });++ it('gates off when the manuscript is empty', () => {+ expect(getCheck('objects.unmotivated-interaction').gate(baseCtx({ manuscript: ' ' }))).toBe(false);+ });+ });++ describe('objects.backstory-consistency — LLM check (#1288)', () => {+ const canonWithRow = () => ({+ objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'c1', emotion: 'grief', origin: 'gift from her father in 1990' }] }],+ characters: [{ id: 'c1', name: 'Mara', background: 'orphaned at birth, never knew her parents' }],+ });++ it('gates on whether any attachment has both an origin and a character with a background', () => {+ const check = getCheck('objects.backstory-consistency');+ expect(check.gate({ canon: canonWithRow() })).toBe(true);+ // origin present but no background → nothing to contradict+ expect(check.gate({ canon: {+ objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'c1', origin: 'x' }] }],+ characters: [{ id: 'c1', name: 'Mara' }],+ } })).toBe(false);+ // origin missing → skip+ expect(check.gate({ canon: {+ objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'c1' }] }],+ characters: [{ id: 'c1', name: 'Mara', background: 'x' }],+ } })).toBe(false);+ // dangling characterId → not this check's job+ expect(check.gate({ canon: {+ objects: [{ id: 'o1', name: 'Watch', attachments: [{ characterId: 'ghost', origin: 'x' }] }],+ characters: [{ id: 'c1', name: 'Mara', background: 'x' }],+ } })).toBe(false);+ });++ it('feeds origin + background rows to the model and shapes findings', async () => {+ let vars = null;+ const findings = await getCheck('objects.backstory-consistency').run({+ canon: canonWithRow(),+ config: { maxFindings: 12 },+ severityDefault: 'medium',+ callStagedLLM: async (_stage, v) => {+ vars = v;+ return { content: { findings: [{ severity: 'high', problem: 'orphan cannot receive a gift from her father', suggestion: 'fix', location: 'Object "Watch" — Mara\'s attachment' }] } };+ },+ });+ expect(vars.attachments).toContain('Watch');+ expect(vars.attachments).toContain('Mara');+ expect(vars.attachments).toContain('orphaned at birth'); // the background side+ expect(vars.attachments).toContain('gift from her father'); // the origin side+ expect(findings).toHaveLength(1);+ expect(findings[0].category).toBe('continuity');+ expect(findings[0].issueNumber).toBeNull();+ });++ it('returns no findings (and never calls the model) when no row qualifies', async () => {+ let called = false;+ const findings = await getCheck('objects.backstory-consistency').run({+ canon: { objects: [{ id: 'o1', name: 'Watch' }], characters: [] },+ config: {},+ severityDefault: 'medium',+ callStagedLLM: async () => { called = true; return { content: { findings: [] } }; },+ });+ expect(findings).toEqual([]);+ expect(called).toBe(false);+ });+ });diff --cc server/lib/schemaVersions.test.jsindex 0675be0109,33a5d0a618..680300bc76--- a/server/lib/schemaVersions.test.js+++ b/server/lib/schemaVersions.test.js@@@ -39,9 -40,9 +40,9 @@@ describe('buildPortosMeta', () =>it('returns { portosVersion, schemaVersions } with the live registry', async () => {const meta = await buildPortosMeta();expect(meta.portosVersion).toMatch(/^\d+\.\d+\.\d+/);- expect(meta.schemaVersions.universes).toBe(6);+ expect(meta.schemaVersions.universes).toBe(7);expect(meta.schemaVersions.pipelineIssues).toBe(2);- expect(meta.schemaVersions.pipelineSeries).toBe(2);+ expect(meta.schemaVersions.pipelineSeries).toBe(3);});it('overrides merge into schemaVersions', async () => {