Skip to content

Commit c0b23bc

Browse files
David Engelhartclaude
andcommitted
lumopolis: a line no model described says what the code shows, never a bare "Not described yet"
One pass describes four lines per building, so most lines keep the code's labels. Their cards now say, under How it travels, who reaches whom and through what ("From the code: Renderer reaches Main this way: it uses 2 message channels and reads 1 setting."), with the identifiers listed above as before, and under Why that nothing in the code records why yet. The HTML card and the agent's text card share the sentence (cardFacts.edgeFromCode). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 13f58c4 commit c0b23bc

6 files changed

Lines changed: 83 additions & 15 deletions

File tree

‎src/main/world/cardText.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// cards.ts), gathered by the same helpers (shared/world/cardFacts.ts, edgeText.ts), with each claim
33
// followed by its state in brackets and the evidence behind it on the next line.
44
import { NOT_IN_DESIGN } from '../../shared/world/reconcile'
5-
import { BUILD_STATUS_TEXT, allBuildings, allEdges, evidenceText, nodeName, notInDesign, runsIn } from '../../shared/world/cardFacts'
5+
import { BUILD_STATUS_TEXT, NO_WHY_YET, allBuildings, allEdges, edgeFromCode, evidenceText, nodeName, notInDesign, runsIn } from '../../shared/world/cardFacts'
66
import { edgeItems, edgeSummary } from '../../shared/world/edgeText'
77
import type { Claim, WorldDoc, WorldEdge } from '../../shared/world/types'
88

99
const section = (title: string, lines: string[]): string[] => ['', `${title}:`, ...lines]
1010

11-
/** One line per claim, "text [state]", then its evidence. None reads as "Not described yet.". */
12-
function claimLines(list: Claim[]): string[] {
13-
if (list.length === 0) return ['Not described yet.']
11+
/** One line per claim, "text [state]", then its evidence. None reads as `empty`. */
12+
function claimLines(list: Claim[], empty = 'Not described yet.'): string[] {
13+
if (list.length === 0) return [empty]
1414
return list.flatMap((c) => {
1515
const ev = c.evidence.map(evidenceText).join('; ')
1616
return [`- ${c.text} [${c.state}]`, ...(ev ? [` evidence: ${ev}`] : [])]
@@ -65,9 +65,10 @@ function edgeText(doc: WorldDoc, id: string): string {
6565
`${nodeName(doc, e.from)} (${e.from}) -> ${nodeName(doc, e.to)} (${e.to})${e.twoWay ? ' (both ways)' : ''}`,
6666
...(items ? section('What it carries', items.map((i) => `- ${i}`)) : title !== e.label.trim() ? [e.label] : []),
6767
...section('What travels', [cargo ? cargo.label : e.cargo]),
68-
...section('How it travels', claimLines(e.how)),
68+
// A line no model described still says what the code shows.
69+
...section('How it travels', claimLines(e.how, edgeFromCode(doc, e))),
6970
...(e.tech.length ? section('Technology', techLine(doc, e.tech)) : []),
70-
...section('Why it is done this way', claimLines(e.why)),
71+
...section('Why it is done this way', claimLines(e.why, NO_WHY_YET)),
7172
...known(e.claims),
7273
...(e.rate ? section('How often', [e.rate]) : [])
7374
]

‎src/renderer/src/world/engine/cards.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Inspector cards as HTML strings. Every interpolated value is escaped (attributes too).
22
import type { Claim, Evidence, WorldDoc, WorldEdge } from '../../../../shared/world/types'
33
import { NOT_IN_DESIGN } from '../../../../shared/world/reconcile'
4-
import { BUILD_STATUS_TEXT as STATUS, allBuildings, allEdges, nodeName, notInDesign, runsIn as runsInOf } from '../../../../shared/world/cardFacts'
4+
import { BUILD_STATUS_TEXT as STATUS, NO_WHY_YET, allBuildings, allEdges, edgeFromCode, nodeName, notInDesign, runsIn as runsInOf } from '../../../../shared/world/cardFacts'
55
import { edgeItems, edgeSummary } from '../../../../shared/world/edgeText'
66
import { escapeHtml as esc } from './html'
77

@@ -108,9 +108,10 @@ export function edgeCard(doc: WorldDoc, id: string): string {
108108
return `<h3>${esc(title)}</h3><p class="muted">${nodeLink(doc, e.from)} → ${nodeLink(doc, e.to)}${e.twoWay ? ' (both ways)' : ''}</p>`
109109
+ carries
110110
+ section('What travels', `<p>${swatch(doc, e)}${esc(cargo ? cargo.label : e.cargo)}</p>`)
111-
+ section('How it travels', claims(e.how, e.id, 0))
111+
// A line no model described still says what the code shows.
112+
+ section('How it travels', claims(e.how, e.id, 0, `<p>${esc(edgeFromCode(doc, e))}</p>`))
112113
+ (e.tech.length ? section('Technology', `<div>${chips(doc, e.tech)}</div>`) : '')
113-
+ section('Why it\'s done this way', claims(e.why, e.id, e.how.length))
114+
+ section('Why it\'s done this way', claims(e.why, e.id, e.how.length, `<p class="muted">${NO_WHY_YET}</p>`))
114115
+ known(e)
115116
+ (e.rate ? section('How often', `<p>${esc(e.rate)}</p>`) : '')
116117
}

‎src/shared/world/cardFacts.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// plain-text card an agent reads (main cardText.ts) import these, so the two cannot say different things.
33
// Pure and ES2020.
44
import type { Building, Evidence, WorldDoc, WorldEdge } from './types'
5+
import { edgeActions, edgeItems } from './edgeText'
56

67
/** The status pill of a building, in words. */
78
export const BUILD_STATUS_TEXT: Record<Building['status'], string> = {
@@ -31,3 +32,21 @@ export const runsIn = (doc: WorldDoc, b: Building): string => {
3132
const proc = doc.processes[b.process]
3233
return proc ? proc.label : b.process
3334
}
35+
36+
/** What a line no model has described says under "How it travels": what the code alone shows, who reaches whom and
37+
* through what (the identifiers themselves are listed under "What it carries"). */
38+
export function edgeFromCode(doc: WorldDoc, e: WorldEdge): string {
39+
const from = nodeName(doc, e.from)
40+
const to = nodeName(doc, e.to)
41+
const items = edgeItems(e.label)
42+
if (items) {
43+
const acts = edgeActions(items)
44+
const said = acts.length === 1 ? acts[0] : `${acts.slice(0, -1).join(', ')} and ${acts[acts.length - 1]}`
45+
return `From the code: ${from} reaches ${to} this way: it ${said}.`
46+
}
47+
if (e.label.trim() === 'imports') return `From the code: ${from} imports code from ${to}.`
48+
return `From the code: ${from} reaches ${to}${e.tech.length ? ` through ${e.tech.join(', ')}` : ''}.`
49+
}
50+
51+
/** What a line no model has described says under "Why": the code records how, not why. */
52+
export const NO_WHY_YET = 'Nothing in the code records why yet.'

‎src/shared/world/edgeText.ts‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,25 @@ export function capText(text: string, max = MAX_EDGE_TEXT): string {
5353
export function edgeSummary(label: string): string {
5454
const items = edgeItems(label)
5555
if (!items) return capText(label)
56+
const [[p, n], ...rest] = countKinds(items)
57+
const others = rest.reduce((s, [, k]) => s + k, 0)
58+
const head = phrase(p, n)
59+
return capText(others > 0 ? `${head} +${others} more` : head)
60+
}
61+
62+
/** How many of a code-written label's identifiers each kind of crossing has, busiest first; a tie keeps the order the
63+
* label lists them in (the sort is stable). */
64+
function countKinds(items: string[]): [Phrase, number][] {
5665
const count = new Map<Phrase, number>()
5766
for (const i of items) {
5867
const p = phraseOf(i) as Phrase
5968
count.set(p, (count.get(p) ?? 0) + 1)
6069
}
61-
// Busiest first; a tie keeps the order the label lists them in (the sort is stable).
62-
const [[p, n], ...rest] = [...count].sort((a, b) => b[1] - a[1])
63-
const others = rest.reduce((s, [, k]) => s + k, 0)
64-
const head = `${p[0]} ${n} ${n === 1 ? p[1] : p[2]}`
65-
return capText(others > 0 ? `${head} +${others} more` : head)
70+
return [...count].sort((a, b) => b[1] - a[1])
6671
}
72+
73+
const phrase = (p: Phrase, n: number): string => `${p[0]} ${n} ${n === 1 ? p[1] : p[2]}`
74+
75+
/** What every kind of crossing among `items` (from edgeItems) does, busiest first and uncut: ["uses 3 message
76+
* channels", "reads 2 settings"]. */
77+
export const edgeActions = (items: string[]): string[] => countKinds(items).map(([p, n]) => phrase(p, n))

‎tests/electron/worldCardText.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,35 @@ describe('cardText', () => {
8686
expect(bare).not.toContain('Technology')
8787
})
8888

89+
it('a line no model described says, from the code, who reaches whom and through what, in the text and the HTML card alike (round 3 E)', () => {
90+
const doc = minimal()
91+
const e = doc.edges[0]
92+
Object.assign(e, { how: [], why: [], label: 'ipc world:get, env A, ipc world:ask', tech: ['ipc', 'env'] })
93+
const from = doc.buildings.find((b) => b.id === e.from)?.name as string
94+
const to = doc.buildings.find((b) => b.id === e.to)?.name as string
95+
const how = `From the code: ${from} reaches ${to} this way: it uses 2 message channels and reads 1 setting.`
96+
const why = 'Nothing in the code records why yet.'
97+
for (const card of [cardText(doc, e.id), edgeCard(doc, e.id)]) {
98+
expect(card).not.toContain('Not described yet')
99+
expect(card).toContain(how)
100+
expect(card).toContain(why)
101+
}
102+
e.label = 'port 5173'
103+
expect(cardText(doc, e.id)).toContain(`From the code: ${from} reaches ${to} this way: it connects on 1 port.`)
104+
e.label = 'env A, ipc b, port 1'
105+
expect(cardText(doc, e.id)).toContain('it reads 1 setting, uses 1 message channel and connects on 1 port.')
106+
// A line of imports alone, and one with a model's name but no description.
107+
Object.assign(e, { label: 'imports', tech: [] })
108+
expect(cardText(doc, e.id)).toContain(`From the code: ${from} imports code from ${to}.`)
109+
Object.assign(e, { label: 'Asks for the world', tech: ['ipc'] })
110+
expect(edgeCard(doc, e.id)).toContain(`From the code: ${from} reaches ${to} through ipc.`)
111+
Object.assign(e, { tech: [] })
112+
expect(cardText(doc, e.id)).toContain(`From the code: ${from} reaches ${to}.`)
113+
// A described line keeps its own words.
114+
e.how = [claim('Sends it over IPC', 'inferred')]
115+
expect(edgeCard(doc, e.id)).not.toContain('From the code')
116+
})
117+
89118
it('states outside parts, planned parts and nothing for an unknown id or a district', () => {
90119
const doc = rich()
91120
expect(cardText(doc, 'x1')).toContain('Outside the project')

‎tests/shared/worldEdgeText.test.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it } from 'vitest'
2-
import { capText, edgeItems, edgeSummary, MAX_EDGE_TEXT } from '../../src/shared/world/edgeText'
2+
import { capText, edgeActions, edgeItems, edgeSummary, MAX_EDGE_TEXT } from '../../src/shared/world/edgeText'
33

44
describe('edgeItems', () => {
55
it('lists the identifiers of a code-written label', () => {
@@ -67,3 +67,10 @@ describe('edgeSummary', () => {
6767
expect(s.length).toBeLessThanOrEqual(MAX_EDGE_TEXT)
6868
})
6969
})
70+
71+
describe('edgeActions (round 3 E)', () => {
72+
it('says what every kind of crossing does, busiest first, uncut', () => {
73+
expect(edgeActions(['ipc a', 'env A', 'ipc b', 'ipc c', 'env B', 'port 80'])).toEqual(['uses 3 message channels', 'reads 2 settings', 'connects on 1 port'])
74+
expect(edgeActions(['mcp memory_search'])).toEqual(['uses 1 tool'])
75+
})
76+
})

0 commit comments

Comments
 (0)