@things-factory/figure-service 10.1.278 → 10.1.279

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/package.json +23 -8
  2. package/coverage/clover.xml +0 -6
  3. package/coverage/coverage-final.json +0 -1
  4. package/coverage/lcov-report/base.css +0 -224
  5. package/coverage/lcov-report/block-navigation.js +0 -87
  6. package/coverage/lcov-report/favicon.png +0 -0
  7. package/coverage/lcov-report/index.html +0 -101
  8. package/coverage/lcov-report/prettify.css +0 -1
  9. package/coverage/lcov-report/prettify.js +0 -2
  10. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  11. package/coverage/lcov-report/sorter.js +0 -210
  12. package/coverage/lcov.info +0 -0
  13. package/dist-server/index.js.map +0 -1
  14. package/dist-server/migrations/index.js.map +0 -1
  15. package/dist-server/routers/figure-mesh-router.js.map +0 -1
  16. package/dist-server/routers/figure-package-router.js.map +0 -1
  17. package/dist-server/routers/figure-thumbnail-router.js.map +0 -1
  18. package/dist-server/routes.js.map +0 -1
  19. package/dist-server/service/figure/event-subscriber.js.map +0 -1
  20. package/dist-server/service/figure/figure-ai-scenarios-run.js.map +0 -1
  21. package/dist-server/service/figure/figure-ai-scenarios.js.map +0 -1
  22. package/dist-server/service/figure/figure-categories.js.map +0 -1
  23. package/dist-server/service/figure/figure-context.js.map +0 -1
  24. package/dist-server/service/figure/figure-format.js.map +0 -1
  25. package/dist-server/service/figure/figure-glb.js.map +0 -1
  26. package/dist-server/service/figure/figure-history.js.map +0 -1
  27. package/dist-server/service/figure/figure-llm-provider.js.map +0 -1
  28. package/dist-server/service/figure/figure-mesh-store.js.map +0 -1
  29. package/dist-server/service/figure/figure-mutation.js.map +0 -1
  30. package/dist-server/service/figure/figure-namespace-entity.js.map +0 -1
  31. package/dist-server/service/figure/figure-namespace-resolver.js.map +0 -1
  32. package/dist-server/service/figure/figure-namespace.js.map +0 -1
  33. package/dist-server/service/figure/figure-package-export.js.map +0 -1
  34. package/dist-server/service/figure/figure-proposal-record.js.map +0 -1
  35. package/dist-server/service/figure/figure-proposal.js.map +0 -1
  36. package/dist-server/service/figure/figure-propose-steps.js.map +0 -1
  37. package/dist-server/service/figure/figure-propose-type.js.map +0 -1
  38. package/dist-server/service/figure/figure-public.js.map +0 -1
  39. package/dist-server/service/figure/figure-query.js.map +0 -1
  40. package/dist-server/service/figure/figure-rename.js.map +0 -1
  41. package/dist-server/service/figure/figure-replaced-draft.js.map +0 -1
  42. package/dist-server/service/figure/figure-revert.js.map +0 -1
  43. package/dist-server/service/figure/figure-subject.js.map +0 -1
  44. package/dist-server/service/figure/figure-thumbnail-reader.js.map +0 -1
  45. package/dist-server/service/figure/figure-thumbnail-store.js.map +0 -1
  46. package/dist-server/service/figure/figure-thumbnail-upgrade.js.map +0 -1
  47. package/dist-server/service/figure/figure-tools.js.map +0 -1
  48. package/dist-server/service/figure/figure-type.js.map +0 -1
  49. package/dist-server/service/figure/figure-write.js.map +0 -1
  50. package/dist-server/service/figure/figure.js.map +0 -1
  51. package/dist-server/service/figure/index.js.map +0 -1
  52. package/dist-server/service/figure-recipe/figure-recipe-resolver.js.map +0 -1
  53. package/dist-server/service/figure-recipe/figure-recipe-templates.js.map +0 -1
  54. package/dist-server/service/figure-recipe/figure-recipe-type.js.map +0 -1
  55. package/dist-server/service/figure-recipe/index.js.map +0 -1
  56. package/dist-server/service/index.js.map +0 -1
  57. package/dist-server/tsconfig.tsbuildinfo +0 -1
  58. package/logs/.08636eb59927f12972f6774f5947c8507b3564c2-audit.json +0 -15
  59. package/logs/application-2026-09-14-23.log +0 -0
  60. package/logs/figure-ai-scenarios/2026-11-03T09-31-35-151Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1167
  61. package/logs/figure-ai-scenarios/2026-11-03T09-39-05-265Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -904
  62. package/logs/figure-ai-scenarios/2026-11-03T09-41-49-107Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1629
  63. package/logs/figure-ai-scenarios/2026-11-03T09-58-26-681Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4412
  64. package/logs/figure-ai-scenarios/2026-11-03T10-16-46-212Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4513
  65. package/logs/figure-ai-scenarios/2026-11-03T10-21-07-872Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4202
  66. package/logs/figure-ai-scenarios/2026-11-03T10-25-21-721Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -1665
  67. package/logs/figure-ai-scenarios/2026-11-09T01-28-51-664Z-agent_hatiolab_ChatGPT-openai-gpt-5.4-mini.json +0 -4484
  68. package/scripts/build-templates.mts +0 -64
  69. package/scripts/figure-ai-scenarios-agent.cjs +0 -98
  70. package/scripts/rename-figures-to-full-names.mjs +0 -211
  71. package/scripts/templates.test.mts +0 -112
  72. package/server/index.ts +0 -46
  73. package/server/migrations/index.ts +0 -9
  74. package/server/routers/figure-mesh-router.ts +0 -63
  75. package/server/routers/figure-package-router.ts +0 -53
  76. package/server/routers/figure-thumbnail-router.ts +0 -159
  77. package/server/routes.ts +0 -30
  78. package/server/service/figure/catalog-db.test.ts +0 -162
  79. package/server/service/figure/event-subscriber.ts +0 -66
  80. package/server/service/figure/figure-ai-scenarios-run.ts +0 -127
  81. package/server/service/figure/figure-ai-scenarios.live.test.ts +0 -59
  82. package/server/service/figure/figure-ai-scenarios.test.ts +0 -109
  83. package/server/service/figure/figure-ai-scenarios.ts +0 -798
  84. package/server/service/figure/figure-blueprint-query.test.ts +0 -536
  85. package/server/service/figure/figure-catalog-seen-db.test.ts +0 -153
  86. package/server/service/figure/figure-categories.ts +0 -50
  87. package/server/service/figure/figure-category-db.test.ts +0 -127
  88. package/server/service/figure/figure-context.test.ts +0 -402
  89. package/server/service/figure/figure-context.ts +0 -510
  90. package/server/service/figure/figure-deprecation-db.test.ts +0 -218
  91. package/server/service/figure/figure-format.test.ts +0 -423
  92. package/server/service/figure/figure-format.ts +0 -783
  93. package/server/service/figure/figure-glb.test.ts +0 -112
  94. package/server/service/figure/figure-glb.ts +0 -251
  95. package/server/service/figure/figure-history.ts +0 -192
  96. package/server/service/figure/figure-inspect-db.test.ts +0 -131
  97. package/server/service/figure/figure-llm-provider.ts +0 -20
  98. package/server/service/figure/figure-llm-smoke.test.ts +0 -95
  99. package/server/service/figure/figure-mesh-db.test.ts +0 -246
  100. package/server/service/figure/figure-mesh-store.ts +0 -91
  101. package/server/service/figure/figure-mutation.ts +0 -656
  102. package/server/service/figure/figure-namespace-db.test.ts +0 -315
  103. package/server/service/figure/figure-namespace-entity.ts +0 -67
  104. package/server/service/figure/figure-namespace-resolver.ts +0 -54
  105. package/server/service/figure/figure-namespace.ts +0 -156
  106. package/server/service/figure/figure-package-export.ts +0 -136
  107. package/server/service/figure/figure-proposal-db.test.ts +0 -117
  108. package/server/service/figure/figure-proposal-record.ts +0 -38
  109. package/server/service/figure/figure-proposal.ts +0 -41
  110. package/server/service/figure/figure-propose-clips.test.ts +0 -69
  111. package/server/service/figure/figure-propose-steps.test.ts +0 -324
  112. package/server/service/figure/figure-propose-steps.ts +0 -354
  113. package/server/service/figure/figure-propose-type.ts +0 -46
  114. package/server/service/figure/figure-public-db.test.ts +0 -288
  115. package/server/service/figure/figure-public.ts +0 -60
  116. package/server/service/figure/figure-query.ts +0 -511
  117. package/server/service/figure/figure-release-check.test.ts +0 -63
  118. package/server/service/figure/figure-release-record-db.test.ts +0 -153
  119. package/server/service/figure/figure-release-size-db.test.ts +0 -156
  120. package/server/service/figure/figure-rename-db.test.ts +0 -237
  121. package/server/service/figure/figure-rename.test.ts +0 -117
  122. package/server/service/figure/figure-rename.ts +0 -143
  123. package/server/service/figure/figure-replaced-draft.ts +0 -99
  124. package/server/service/figure/figure-revert-db.test.ts +0 -163
  125. package/server/service/figure/figure-revert-race.pg.test.ts +0 -168
  126. package/server/service/figure/figure-revert.ts +0 -186
  127. package/server/service/figure/figure-subject.test.ts +0 -41
  128. package/server/service/figure/figure-subject.ts +0 -21
  129. package/server/service/figure/figure-thumbnail-db.test.ts +0 -279
  130. package/server/service/figure/figure-thumbnail-reader.ts +0 -20
  131. package/server/service/figure/figure-thumbnail-store.ts +0 -111
  132. package/server/service/figure/figure-thumbnail-upgrade.pg.test.ts +0 -93
  133. package/server/service/figure/figure-thumbnail-upgrade.ts +0 -70
  134. package/server/service/figure/figure-tool-doors.test.ts +0 -127
  135. package/server/service/figure/figure-tools-door-db.test.ts +0 -227
  136. package/server/service/figure/figure-tools.test.ts +0 -817
  137. package/server/service/figure/figure-tools.ts +0 -611
  138. package/server/service/figure/figure-type.ts +0 -241
  139. package/server/service/figure/figure-write.test.ts +0 -15
  140. package/server/service/figure/figure-write.ts +0 -131
  141. package/server/service/figure/figure.ts +0 -241
  142. package/server/service/figure/index.ts +0 -13
  143. package/server/service/figure-recipe/figure-recipe-resolver.ts +0 -38
  144. package/server/service/figure-recipe/figure-recipe-templates.test.ts +0 -47
  145. package/server/service/figure-recipe/figure-recipe-templates.ts +0 -70
  146. package/server/service/figure-recipe/figure-recipe-type.ts +0 -31
  147. package/server/service/figure-recipe/index.ts +0 -3
  148. package/server/service/index.ts +0 -34
  149. package/tsconfig.json +0 -14
@@ -1,324 +0,0 @@
1
- /**
2
- * figure-propose-steps — an AI proposal for a figure is a list of the modeller's commands (ADR-0094).
3
- *
4
- * What is held here is our filter, not the model's skill: the model is not called. The steps are applied on a copy;
5
- * the step the kernel refuses, and the gate findings the steps bring in, go back to the model; after three attempts
6
- * the proposer says it could not make it, and nothing half made comes back.
7
- */
8
- import { FIGURE_PROPOSAL_GRAMMAR, addFigureBox, applyFigureAuthoring, applyFigureProposal, createFigureAsset, inspectFigureAsset } from '@hatiolab/figure-model'
9
- import { AIAnswerNotJSON, type AIClient } from '@things-factory/ai-client-base'
10
-
11
- import { ProposeFigureFailure, WORKED_EXAMPLE, judgeFigureAnswer, proposalFailureForPerson, proposeFigureSteps, rulesPromptFigure } from './figure-propose-steps'
12
-
13
- function stubClient(answers: unknown[]): AIClient & { calls: number; sent: any[][]; system?: string } {
14
- const client = {
15
- id: 'stub',
16
- calls: 0,
17
- sent: [] as any[][],
18
- system: undefined as string | undefined,
19
- async chat() {
20
- return ''
21
- },
22
- async generateJSON(messages: any[], options?: { systemPrompt?: string }) {
23
- client.sent.push(JSON.parse(JSON.stringify(messages)))
24
- client.system = options?.systemPrompt
25
- const answer = answers[client.calls]
26
- client.calls++
27
- if (answer instanceof Error) throw answer
28
- return answer
29
- }
30
- }
31
- return client as unknown as AIClient & { calls: number; sent: any[][]; system?: string }
32
- }
33
-
34
- const liftTable = [
35
- { kind: 'add-part', part: { id: 'base', kind: 'box', dimensions: { width: 1200, height: 80, depth: 800 } } },
36
- { kind: 'add-part', part: { id: 'column', kind: 'cylinder', dimensions: { radius: 90, length: 600 } } },
37
- { kind: 'add-part', part: { id: 'top', kind: 'box', dimensions: { width: 1200, height: 60, depth: 800 } } },
38
- { kind: 'attach', part: 'base', to: { plane: 'mounting-plane' } },
39
- { kind: 'attach', part: 'column', to: { part: 'base', face: 'top' } },
40
- { kind: 'attach', part: 'top', to: { part: 'column', face: 'top' } },
41
- { kind: 'set-material', target: 'top', material: { token: 'palette.accent' }, palette: { 'palette.accent': '#d08a2c' } }
42
- ]
43
- /* The table's top named as the face it is mounted on: a finding the draft has, its face 740 mm off the plane. */
44
- const offFace = [...liftTable, { kind: 'set-mounting-face', part: 'top', face: 'top' }]
45
- const wrongFace = liftTable.map((s, i) => (i === 4 ? { ...s, face: 'left' } : s))
46
-
47
- describe('the model is told the kernel\'s commands and the open draft', () => {
48
- it('teaches every word of the grammar, in its own shape', () => {
49
- const rules = rulesPromptFigure()
50
- for (const word of FIGURE_PROPOSAL_GRAMMAR) expect(rules).toContain(word.shape)
51
- /*
52
- Our own words teach no retired shape -- a `parts` array, an `anchor` on a part. The kernel's grammar is taught as it
53
- is, and a slot layout's `anchors` are its own (figure-model 0.4.3), so its words are taken out before looking.
54
- */
55
- const ours = FIGURE_PROPOSAL_GRAMMAR.reduce((text, word) => text.split(word.shape).join('').split(word.means).join(''), rules)
56
- expect(ours).not.toMatch(/"parts"\s*:\s*\[|anchor/i)
57
- })
58
-
59
- /*
60
- :3300, 2026-10-16, a real model asked for a conveyor with 12 rollers: one answer added and fastened every roller and
61
- frame rail by hand, sixty steps, and fastened a rail twice (ATTACH_REPLACED at steps[59]); another named a part it
62
- had not added. Both are rules of writing, so they are taught with the rules.
63
- */
64
- /*
65
- Three walks on :3300 (2026-10-16) stopped at three fastening rules in turn -- a part not added, flush on the mounting
66
- plane, a face that does not meet -- each refusal saying what to do, and none put right in three tries. A rule a line
67
- at a time did not end it; one whole answer the kernel takes shows the rules together. It is held to the kernel here,
68
- on the path an answer takes, so it cannot teach what the kernel refuses.
69
- */
70
- it('shows one whole answer, and that answer is one the kernel and the gate take', () => {
71
- expect(rulesPromptFigure()).toContain(JSON.stringify({ steps: WORKED_EXAMPLE }))
72
- const judged = judgeFigureAnswer(createFigureAsset('Roller conveyor'), { steps: WORKED_EXAMPLE }, false)
73
- expect(judged.reasons).toEqual([])
74
- expect(judged.source!.appearance.map(a => a.target)).toEqual(['frame', 'support', 'roller'])
75
- const kinds = WORKED_EXAMPLE.map(step => step.kind)
76
- expect(kinds).toContain('make-repeat')
77
- expect(WORKED_EXAMPLE.filter(step => step.kind === 'attach' && 'plane' in (step as any).to).every(step => !('facing' in step))).toBe(true)
78
- })
79
-
80
- it('teaches a row of the same part as one part repeated, and each part fastened once', () => {
81
- const rules = rulesPromptFigure()
82
- expect(rules).toMatch(/same part .*make-repeat/)
83
- expect(rules).toMatch(/Fasten each part once/)
84
- expect(rules).toMatch(/fasten only to the mounting plane or to a part an earlier step added/)
85
- })
86
-
87
- it('a measure asked to be the same as another is linked, not copied (:3300, 2026-09-26: 「몸통 지름과 같게」 came as a fixed 100)', () => {
88
- expect(rulesPromptFigure()).toMatch(/same as, matches or follows another part or the figure, write link-dimension/)
89
- })
90
-
91
- it('a revision carries the draft\'s source', async () => {
92
- const draft = applyFigureProposal(createFigureAsset('Lift table'), liftTable as any)
93
- const client = stubClient([{ steps: [{ kind: 'rename', name: 'Lift table 2' }] }])
94
- const made = await proposeFigureSteps({ client, prompt: '이름을 바꿔 줘', base: draft })
95
- expect(client.sent[0]![0]!.content).toContain('"version":"figure-asset-1"')
96
- expect(made.source.name).toBe('Lift table 2')
97
- expect(draft.name).toBe('Lift table')
98
- })
99
-
100
- it('a revision shows the draft\'s pipes as set-pipe takes them, and none for a draft without', async () => {
101
- const draft = applyFigureProposal(createFigureAsset('Elbow'), [
102
- { kind: 'add-part', part: { id: 'pipe', kind: 'pipe', dimensions: { radius: 40, wall: 4 }, path: [{ line: 500 }, { bend: { radius: 120, angle: 90, toward: 90 } }, { line: 400 }] } },
103
- { kind: 'add-part', part: { id: 'stand', kind: 'box', dimensions: { width: 100, height: 100, depth: 100 } } },
104
- { kind: 'attach', part: 'pipe', to: { plane: 'mounting-plane' } },
105
- { kind: 'attach', part: 'stand', to: { plane: 'mounting-plane' }, align: { x: { mm: 600 } } }
106
- ] as any)
107
- const told = async (base: typeof draft) => {
108
- const client = stubClient([{ steps: [{ kind: 'rename', name: 'Again' }] }])
109
- await proposeFigureSteps({ client, prompt: '이름', base })
110
- return client.sent[0]![0]!.content as string
111
- }
112
- const line = (await told(draft)).split('\n').find(l => l.startsWith('{"pipe":'))
113
- expect(JSON.parse(line!)).toEqual({ pipe: { kind: 'pipe', radius: 40, wall: 4, path: [{ line: 500 }, { bend: { radius: 120, angle: 90, turn: '+X' } }, { line: 400 }] } })
114
- expect(await told(applyFigureProposal(createFigureAsset('Box'), liftTable as any))).not.toContain('Its pipes and ducts')
115
- })
116
- })
117
-
118
- describe('the steps are held to the kernel and the gate', () => {
119
- it('a list the kernel takes comes back with the figure it makes, the gate clean, on the first attempt', async () => {
120
- const client = stubClient([{ steps: liftTable }])
121
- const made = await proposeFigureSteps({ client, prompt: '리프트 테이블', name: 'Lift table' })
122
- expect(made.attempts).toBe(1)
123
- expect(made.steps).toEqual(liftTable)
124
- expect(inspectFigureAsset(made.source).violations).toEqual([])
125
- expect(made.score?.grade).toMatch(/^[ABCD]$/)
126
- })
127
-
128
- /* ADR-0100 §16 (2026-11-03, 「파이프같은 경우가 많이 활용될 것 같으니까」): a pipe run and a tapered box made by a proposal. */
129
- it('a pipe run with a flange on its end, and a tapered cover, are made by the grammar\'s words; a bend too tight is said back', async () => {
130
- const run = [
131
- { kind: 'add-part', part: { id: 'pipe', kind: 'pipe', dimensions: { radius: 40, wall: 4 }, path: [{ line: 500 }, { bend: { radius: 120, angle: 90, toward: 90 } }, { line: 400 }] } },
132
- { kind: 'attach', part: 'pipe', to: { plane: 'mounting-plane' } },
133
- { kind: 'add-part', part: { id: 'flange', kind: 'cylinder', dimensions: { radius: 70, length: 20 } } },
134
- { kind: 'attach', part: 'flange', to: { part: 'pipe', face: 'right' } },
135
- { kind: 'add-part', part: { id: 'cover', kind: 'tapered-box', dimensions: { width: 300, depth: 200, height: 150, topWidth: 180, topDepth: 120, round: 20, topRound: 10 } } },
136
- { kind: 'attach', part: 'cover', to: { plane: 'mounting-plane' } }
137
- ]
138
- const tight = run.map((s, i) => (i === 0 ? { ...s, part: { ...(s as any).part, path: [{ line: 500 }, { bend: { radius: 30, angle: 90, toward: 90 } }] } } : s))
139
- const client = stubClient([{ steps: tight }, { steps: run }])
140
- const made = await proposeFigureSteps({ client, prompt: '엘보 배관과 플랜지, 덮개', name: 'Pipe run' })
141
- expect(made.attempts).toBe(2)
142
- expect(JSON.stringify(client.sent[1])).toContain('GEOMETRY_DOMAIN')
143
- expect(made.steps).toEqual(run)
144
- expect(inspectFigureAsset(made.source).violations).toEqual([])
145
- /* The words the model was told include the pipe's and the tapered box's. */
146
- expect(client.system).toContain("kind: 'pipe'")
147
- expect(client.system).toContain("kind: 'set-pipe'")
148
- expect(client.system).toContain("kind: 'tapered-box'")
149
- })
150
-
151
- it('a refused step goes back with its place and the kernel\'s code, and the next answer is taken', async () => {
152
- const client = stubClient([{ steps: wrongFace }, { steps: liftTable }])
153
- const made = await proposeFigureSteps({ client, prompt: '리프트 테이블', name: 'Lift table' })
154
- expect(made.attempts).toBe(2)
155
- const said = client.sent[1]!.at(-1)!.content as string
156
- expect(said).toMatch(/SCHEMA: steps\[4\]: attach: column: face is a word attach does not take/)
157
- })
158
-
159
- it('a revision is not blamed for what the draft already had', async () => {
160
- const draft = applyFigureProposal(createFigureAsset('Lift table'), offFace as any)
161
- expect(inspectFigureAsset(draft).violations.map(v => v.code)).toEqual(['PARTS_OFF_PLACEMENT_FACE'])
162
- const client = stubClient([{ steps: [{ kind: 'rename', name: 'Lift' }] }])
163
- const made = await proposeFigureSteps({ client, prompt: '이름', base: draft })
164
- expect(made.attempts).toBe(1)
165
- })
166
-
167
- it('three refusals said back, then it says it could not make it, with the last reasons -- nothing half made', async () => {
168
- const client = stubClient([{ steps: wrongFace }, new AIAnswerNotJSON('no balanced JSON found'), { nope: true }])
169
- const failure = await proposeFigureSteps({ client, prompt: '리프트 테이블', name: 'Lift table' }).catch(e => e)
170
- expect(failure).toBeInstanceOf(ProposeFigureFailure)
171
- expect(failure.message).toBe('The figure could not be made.')
172
- expect(failure.attempts).toBe(3)
173
- expect(failure.reasons).toEqual(['The answer must be { "steps": [ ... ] }.'])
174
- expect(client.calls).toBe(3)
175
- expect(client.sent[2]!.at(-1)!.content).toMatch(/not valid JSON: no balanced JSON found/)
176
- })
177
-
178
- /*
179
- Only an answer that is not JSON is asked again (figure audit 2026-10-16 N2). A request that failed -- a rejected key,
180
- a rate limit, a dropped connection -- was asked three times and said as "not valid JSON"; now it is said as it is,
181
- once, and the tool's caller hears the provider's own words.
182
- */
183
- /*
184
- :3300, 2026-10-16, a real model: three answers refused with "TARGET_ABSENT: steps[12]: attach: joints.frame: frame is
185
- not a placed part". The kernel says the same for a part never added and a part not placed yet, so the writer is told
186
- which parts there were at the refused step, and fastens to one of them.
187
- */
188
- it('a step that names a part not there is said back with the parts there were at that step', () => {
189
- const steps = [...liftTable.slice(0, 3), { kind: 'attach', part: 'column', to: { part: 'frame', face: 'top' } }]
190
- const { reasons } = judgeFigureAnswer(createFigureAsset('Lift table'), { steps }, false)
191
- expect(reasons).toHaveLength(1)
192
- expect(reasons[0]).toMatch(/^TARGET_ABSENT: steps\[3\]/)
193
- expect(reasons[0]).toContain('The parts at steps[3] are: base, column, top.')
194
- /* The kernel's sentence ends without a stop; the two sentences are not run together (:3300 "...here The parts"). */
195
- expect(reasons[0]).toMatch(/[.!?] The parts at steps\[3\]/)
196
- })
197
-
198
- it('a request that failed is not asked again, and is said as it failed', async () => {
199
- const refused = Object.assign(new Error('401 Unauthorized'), { status: 401 })
200
- const client = stubClient([refused, { steps: liftTable }])
201
- const failure = await proposeFigureSteps({ client, prompt: '리프트 테이블', name: 'Lift table' }).catch(e => e)
202
- expect(failure).toBe(refused)
203
- expect(client.calls).toBe(1)
204
- })
205
-
206
- it('an answer cut off at the output limit is asked again for fewer commands, not for the same', async () => {
207
- const client = stubClient([new AIAnswerNotJSON('no balanced JSON found', true), { steps: liftTable }])
208
- const made = await proposeFigureSteps({ client, prompt: '리프트 테이블', name: 'Lift table' })
209
- expect(made.attempts).toBe(2)
210
- const asked = client.sent[1]!.at(-1)!.content as string
211
- expect(asked).toMatch(/cut off at the output limit/)
212
- expect(asked).toMatch(/make-repeat/)
213
- expect(asked).not.toMatch(/not valid JSON/)
214
- })
215
- })
216
-
217
- /*
218
- "Make this one bigger": the part the person selected reaches the step writer, or it guesses which part was meant
219
- (ADR-0097 §5.6 item 5). Only a revision has a selection; a new figure has nothing to select.
220
- */
221
- describe('a pipe in a revision is told as set-pipe takes it', () => {
222
- it('its bends by the axis they turn to, so "down" is written as -Y', async () => {
223
- const base = applyFigureProposal(createFigureAsset('Elbow'), [
224
- { kind: 'add-part', part: { id: 'pipe', kind: 'pipe', dimensions: { radius: 40, wall: 4 }, path: [{ line: 500 }, { bend: { radius: 120, angle: 90, toward: 90 } }, { line: 400 }] } },
225
- { kind: 'attach', part: 'pipe', to: { plane: 'mounting-plane' } }
226
- ] as any)
227
- const client = stubClient([{ steps: [{ kind: 'set-pipe', part: 'pipe', append: [{ bend: { radius: 120, angle: 90, turn: '-Y' } }, { line: 300 }] }] }])
228
- const made = await proposeFigureSteps({ client, prompt: '끝에서 아래로 꺾어 300 더', base })
229
- const task = String(client.sent[0][0].content)
230
- expect(task).toContain('"turn":"+X"')
231
- expect(task).toContain('set-pipe takes them')
232
- expect(made.attempts).toBe(1)
233
- })
234
- })
235
-
236
- describe('what the person has in view goes with a revision', () => {
237
- it('the selected part and the values being tried are named in the task', async () => {
238
- const draft = applyFigureProposal(createFigureAsset('Lift table'), liftTable as any)
239
- const client = stubClient([{ steps: [{ kind: 'rename', name: 'Lift table 2' }] }])
240
- await proposeFigureSteps({ client, prompt: 'make this one taller', base: draft, focus: { selection: { part: 'column' }, trying: { controls: { height: 300 } } } })
241
- const task = client.sent[0]![0]!.content as string
242
- expect(task).toMatch(/selected the part "column"/)
243
- expect(task).toMatch(/"this part"/)
244
- expect(task).toContain('{"controls":{"height":300}}')
245
- })
246
-
247
- it('a new figure is not told about a selection', async () => {
248
- const client = stubClient([{ steps: liftTable }])
249
- await proposeFigureSteps({ client, prompt: 'lift table', name: 'Lift table', focus: { selection: { part: 'column' } } })
250
- expect(client.sent[0]![0]!.content).not.toMatch(/selected/)
251
- })
252
- })
253
-
254
- /* The pictures the person attached reach the step writer - every one, in their order (ADR-0061, 2026-10-16 decision 2). */
255
- describe('reference pictures go with the task', () => {
256
- it('every picture is sent after the task, in the order given', async () => {
257
- const front = { data: Buffer.from([1, 2, 3]), mediaType: 'image/png' as const }
258
- const side = { data: Buffer.from([4, 5]), mediaType: 'image/jpeg' as const }
259
- const client = stubClient([{ steps: liftTable }])
260
- await proposeFigureSteps({ client, prompt: 'lift table like these', name: 'Lift table', images: [front, side] })
261
- const content = client.sent[0]![0]!.content as any[]
262
- expect(content[0]).toMatchObject({ type: 'text', text: expect.stringMatching(/attached images for proportions/) })
263
- expect(content.slice(1).map(part => [part.type, part.source.mediaType, part.source.data])).toEqual([
264
- ['image', 'image/png', JSON.parse(JSON.stringify(front.data))],
265
- ['image', 'image/jpeg', JSON.parse(JSON.stringify(side.data))]
266
- ])
267
- })
268
-
269
- it('no picture: the task alone, and no word about one', async () => {
270
- const client = stubClient([{ steps: liftTable }])
271
- await proposeFigureSteps({ client, prompt: 'lift table', name: 'Lift table' })
272
- expect(client.sent[0]![0]!.content).not.toMatch(/image/)
273
- })
274
- })
275
-
276
- /*
277
- A revision is not blamed for a finding the draft already had -- but the same finding made worse is the answer's.
278
- Matching by code, part and axis alone excused a part pushed further out of the declared room; the room is computed
279
- now (ADR-0145), and a mounting face further off its plane is the same case.
280
- */
281
- describe('a finding the draft had is excused only while it is no worse', () => {
282
- const outside = (() => {
283
- let asset = addFigureBox(createFigureAsset('Mixer'), { id: 'body', size: { x: 300, y: 400, z: 300 }, position: { x: 0, y: 200, z: 0 } })
284
- asset = applyFigureAuthoring(asset, { kind: 'set-placement', placement: 'floor' })
285
- asset = addFigureBox(asset, { id: 'sign', size: { x: 100, y: 100, z: 40 }, position: { x: 300, y: 250, z: 0 } })
286
- return applyFigureAuthoring(asset, { kind: 'set-mounting-face', part: 'sign', face: 'bottom' })
287
- })()
288
-
289
- it('the draft has the finding to begin with', () => {
290
- expect(inspectFigureAsset(outside).violations.map(v => `${v.code} ${v.part} ${v.axis} ${v.mm}`)).toEqual(['PARTS_OFF_PLACEMENT_FACE sign y 200'])
291
- })
292
-
293
- it('left as it was, or made smaller, it is excused', () => {
294
- expect(judgeFigureAnswer(outside, { steps: [{ kind: 'rename', name: 'Mixer 2' }] }, true).reasons).toEqual([])
295
- expect(judgeFigureAnswer(outside, { steps: [{ kind: 'nudge-part', part: 'sign', by: { y: -20 } }] }, true).reasons).toEqual([])
296
- })
297
-
298
- it('pushed further out, it is sent back as the answer\'s', () => {
299
- const judged = judgeFigureAnswer(outside, { steps: [{ kind: 'nudge-part', part: 'sign', by: { y: 100 } }] }, true)
300
- expect(judged.source).toBeUndefined()
301
- expect(judged.reasons).toEqual([expect.stringMatching(/^PARTS_OFF_PLACEMENT_FACE \(sign\): .*worse than the 200 mm the figure already had/)])
302
- })
303
- })
304
-
305
- /*
306
- The failure's first line is the model's in the tool path, and a person's when the GraphQL door answers it: there it is
307
- said in the reader's language (ADR-0054); the reasons stay as the kernel and the gate said them.
308
- */
309
- describe('a failure told to a person', () => {
310
- const failure = new ProposeFigureFailure('The figure could not be made.', ['ATTACH_FACE: steps[4]: attach: faces along x'], 3)
311
-
312
- it('says the first line in the reader\'s language, the reasons as they were', () => {
313
- const said: any[] = []
314
- const text = proposalFailureForPerson(failure, (key, params) => (said.push([key, params]), '피규어를 만들지 못했습니다.'))
315
- expect(text).toBe('피규어를 만들지 못했습니다.\nATTACH_FACE: steps[4]: attach: faces along x')
316
- expect(said).toEqual([['error.figure-proposal-failed', { defaultValue: 'The figure could not be made.' }]])
317
- })
318
-
319
- it('every locale has the key', () => {
320
- for (const locale of ['en', 'ko', 'ja', 'zh', 'es', 'ms']) {
321
- expect(require(`../../../translations/${locale}.json`)['error.figure-proposal-failed']).toBeTruthy()
322
- }
323
- })
324
- })