From b387fec8974fe2c86c0642bbe288ad979ed67ce1 Mon Sep 17 00:00:00 2001 From: reoring Date: Wed, 18 Nov 2026 19:14:30 +0900 Subject: [PATCH 1/5] Announce a recreated workspace once instead of switching silently (APT-1264) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Read replacedDevWorkspaceId on conversation turns and plan generations (optional; older Platforms omit it). - Show 「作業環境を作り直しました。会話と計画は引き継いでいます」 once, on the record that replaced the retired workspace, as information only; derived from the draft so reloads keep exactly one notice. --- web/src/api/build.test.ts | 13 +++++- web/src/api/contracts/platform/build.ts | 6 +++ web/src/features/build/copy.test.tsx | 29 ++++++++++++ web/src/model/build/copy.en.ts | 1 + web/src/model/build/copy.ts | 2 + web/src/model/build/messages.test.ts | 62 ++++++++++++++++++++++++- web/src/model/build/messages.ts | 22 +++++++++ web/src/model/contracts/build.ts | 5 +- 8 files changed, 136 insertions(+), 4 deletions(-) diff --git a/web/src/api/build.test.ts b/web/src/api/build.test.ts index 262f769..50ce5d7 100644 --- a/web/src/api/build.test.ts +++ b/web/src/api/build.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, expect, mock, test } from 'bun:test' import { QueryClient, QueryObserver, skipToken } from '@tanstack/react-query' import * as api from './build' import { BUILD_POLL_MS, buildDraftOptions, buildKeys, draftsOptions } from './queries/build' -import { draftOf, runOf } from './testing/build-domain' +import { draftOf, generationOf, runOf, turnOf } from './testing/build-domain' import { POLL_INTERVAL_MS, readRetryDelay, retryReadQuery } from './queries/shared' import { isPublishPreparationPending } from './publish-retry' @@ -44,6 +44,17 @@ afterEach(() => { else Reflect.deleteProperty(globalThis, 'sessionStorage') }) +test('turn and plan generation readers keep the workspace they replaced, and read answers without it (APT-1264)', () => { + expect(turnOf({ ...turn, replacedDevWorkspaceId: 'workspace-0' }).replacedDevWorkspaceId).toBe('workspace-0') + expect(generationOf({ ...generation, replacedDevWorkspaceId: 'workspace-0' }).replacedDevWorkspaceId).toBe('workspace-0') + // An older Platform never sends the field: the same answers read unchanged. + expect(turnOf(turn).replacedDevWorkspaceId).toBeUndefined() + expect(generationOf(generation).replacedDevWorkspaceId).toBeUndefined() + const read = draftOf({ ...draft, conversationTurns: [{ ...turn, replacedDevWorkspaceId: 'workspace-0' }, { ...turn, id: 'turn-2' }], creationPlanGenerations: [{ ...generation, replacedDevWorkspaceId: 'workspace-0' }] }) + expect(read.conversationTurns.map((item) => item.replacedDevWorkspaceId)).toEqual(['workspace-0', undefined]) + expect(read.creationPlanGenerations[0]?.replacedDevWorkspaceId).toBe('workspace-0') +}) + test('all build API adapters use contract routes, payloads and idempotency keys per mutation attempt', async () => { await api.createDraft('project-1', { intent: '見積を作る', title: '見積' }) await api.updateDraft('project-1', 'draft-1', { specMarkdown: '---\nspec: {}\n---\n', intent: '新しい内容', title: '新しい名前' }) diff --git a/web/src/api/contracts/platform/build.ts b/web/src/api/contracts/platform/build.ts index bd2ac5b..02a8b67 100644 --- a/web/src/api/contracts/platform/build.ts +++ b/web/src/api/contracts/platform/build.ts @@ -67,17 +67,23 @@ export function openCanonical(canonical: { options: readonly K const DRAFT_OMITS = 'platform-api internal/api/dto_application_draft.go' +// The retired workspace a turn or plan generation replaced (APT-1264): present only on the record that switched to a new +// workspace. Restated here until the published api-schema carries it; an older Platform never sends it. +const replacedDevWorkspaceId = z.string().optional() + export const turnReader: z.ZodType = ApplicationDraftConversationTurn.extend({ // A turn without `kind` predates the field and is a conversation turn (canonical default). kind: openCanonical(ApplicationDraftConversationTurnKind).default({ kind: 'known', value: 'conversation' }), status: openCanonical(ApplicationDraftConversationTurnStatus), excelProgress: excelProgressReader.optional(), uiDesign: uiDesignReader.optional(), + replacedDevWorkspaceId, }) export const generationReader: z.ZodType = ApplicationDraftCreationPlanGeneration.extend({ status: openCanonical(ApplicationDraftCreationPlanGenerationStatus), stage: openCanonical(ApplicationDraftCreationPlanGeneration.shape.stage.unwrap()).optional(), + replacedDevWorkspaceId, }) const stepReader: z.ZodType = ApplicationDraftCreationExecutionStep.extend({ diff --git a/web/src/features/build/copy.test.tsx b/web/src/features/build/copy.test.tsx index c51e8d9..353b355 100644 --- a/web/src/features/build/copy.test.tsx +++ b/web/src/features/build/copy.test.tsx @@ -7,6 +7,7 @@ import { isPlatformNotFound } from '../../api/platform-error' import { draftOf, runOf, taskOf } from '../../api/testing/build-domain' import { buildCopy } from '../../model/build/copy' import { buildFailureReference, classifyBuildFailure, destinationFailure } from '../../model/build/failure' +import { messagesFromDraft } from '../../model/build/messages' import { deriveStage, draftPublished } from '../../model/build/stage' import type { BuildProposal, BuildSpec } from '../../model/build/types' import type { BuildDraft } from '../../model/contracts/build' @@ -126,6 +127,34 @@ test.each(['ja', 'en'] as const)('a moved destination is approved again with the expect(render('blocked')).toContain(`>${text.conversation.retry}`) }) +test.each(['ja', 'en'] as const)('a recreated workspace is announced once, on the turn that replaced it, as information only (%s)', (language) => { + setLanguage(language) + const at = (minute: number, second = 0) => `2026-11-18T00:0${minute}:${String(second).padStart(2, '0')}Z` + const turn = (id: string, minute: number, fields: Record = {}) => ({ + id, kind: 'conversation', status: 'succeeded', startedAt: at(minute), finishedAt: at(minute, 10), devWorkspaceId: 'ws-new', userMessage: `request ${id}`, assistantMessage: `answer ${id}`, ...fields, + }) + const draft = draftOf({ + id: 'draft-1', projectId: 'project-1', title: 'Contacts', intent: 'Keep contacts', phase: 'specifying', specMarkdown: '', architectureMarkdown: '', ownerUserId: 'user-1', createdAt: at(0), updatedAt: at(4), + conversationTurns: [turn('turn-1', 1, { devWorkspaceId: 'ws-old' }), turn('turn-2', 2, { replacedDevWorkspaceId: 'ws-old' }), turn('turn-3', 3)], + creationPlanGenerations: [{ id: 'gen-1', status: 'succeeded', startedAt: at(4), finishedAt: at(4, 30), devWorkspaceId: 'ws-new' }], + }) + const markup = renderToStaticMarkup( {}} onRetry={() => {}} onUseName={() => {}} + />) + const notice = buildCopy.workspaceRecreated + expect(notice).toBe(language === 'ja' ? '作業環境を作り直しました。会話と計画は引き継いでいます' : 'Your workspace was recreated. The conversation and plan are kept.') + expect(markup.split(notice)).toHaveLength(2) + // Below the request that switched workspaces and above its answer; the later turn carries none. + expect(markup.indexOf('request turn-2')).toBeLessThan(markup.indexOf(notice)) + expect(markup.indexOf(notice)).toBeLessThan(markup.indexOf('answer turn-2')) + // A calm status, not an alert: no retry, no support reference. + expect(markup).toContain('role="status"') + expect(markup).not.toContain('role="alert"') + expect(markup).not.toContain(`>${text.conversation.retry}`) + expect(markup).not.toContain(buildCopy.failure.copyReference) +}) + // The rendered state needs the router (LinkButton); app-build-ai.mock.spec.ts covers it. Here: the // classifier that routes a 404 away from 「しばらくしてから再読み込み」, and the wording. test('a 404 draft is an answer, not a transient failure, and the copy names the signed-in account', () => { diff --git a/web/src/model/build/copy.en.ts b/web/src/model/build/copy.en.ts index 7206b45..4050793 100644 --- a/web/src/model/build/copy.en.ts +++ b/web/src/model/build/copy.en.ts @@ -3,6 +3,7 @@ import type { textJa } from './copy' export const textEn: typeof textJa = { intent: { reply: '### Follow-up', publish: 'Publish: yes', omitted: (count) => `(${count} earlier follow-up${count === 1 ? '' : 's'} omitted)` }, unreadablePlan: { title: 'The saved plan could not be read', detail: 'This console cannot show the contents of the plan saved on the platform.' }, + workspaceRecreated: 'Your workspace was recreated. The conversation and plan are kept.', questions: { firstTurn: 'Ask me one question at a time about the decisions needed to build this app.', kickoffReply: 'Propose an app from this', diff --git a/web/src/model/build/copy.ts b/web/src/model/build/copy.ts index daa12c8..1aba573 100644 --- a/web/src/model/build/copy.ts +++ b/web/src/model/build/copy.ts @@ -4,6 +4,8 @@ import { textEn } from './copy.en' export const textJa = { intent: { reply: '### 追記', publish: '公開: する', omitted: (count: number) => `(以前の追記 ${count} 件を省略)` }, unreadablePlan: { title: '保存された計画を読めませんでした', detail: '基盤に保存された計画の内容を、このコンソールでは確認できません。' }, + /** A turn or plan generation moved to a new workspace because the old one was retired (APT-1264): information only. */ + workspaceRecreated: '作業環境を作り直しました。会話と計画は引き継いでいます', questions: { firstTurn: 'このアプリを作るために決めるべきことを、一つずつ質問してください。', kickoffReply: 'この内容で提案して', diff --git a/web/src/model/build/messages.test.ts b/web/src/model/build/messages.test.ts index 80926d7..fd6b79e 100644 --- a/web/src/model/build/messages.test.ts +++ b/web/src/model/build/messages.test.ts @@ -10,7 +10,10 @@ const messagesFromDraft = readFirst(draftOf, model.messagesFromDraft) const planProposal = readFirst(draftOf, model.planProposal) const prepareAnswers = readEachFirst(turnOf, questions.prepareAnswers) const { replyOptions } = questions -import { buildCopy } from './copy' +import { buildCopy, textJa } from './copy' +import { textEn } from './copy.en' +import { preserveLanguage } from '../../../test/language' +import { setLanguage } from '../../shell/language' import { buildFailureReference, classifyBuildFailure } from './failure' import { serializeSpec } from './spec' import type { BuildMessage } from './types' @@ -123,6 +126,63 @@ describe('conversation history', () => { }) }) +describe('recreated workspace notice (APT-1264)', () => { + const recreated = { role: 'notice', tone: 'info', title: textJa.workspaceRecreated, at: '2026-10-08T00:02:00Z' } satisfies BuildMessage + const earlier = { ...turn, devWorkspaceId: 'ws-old' } + const switched = { ...turn, id: 'turn-2', startedAt: '2026-10-08T00:02:00Z', finishedAt: '2026-10-08T00:02:10Z', userMessage: '入れる', replacedDevWorkspaceId: 'ws-old' } + const later = { ...turn, id: 'turn-3', startedAt: '2026-10-08T00:03:00Z', finishedAt: '2026-10-08T00:03:10Z', userMessage: 'ありがとう' } + const generation = { id: 'gen-1', status: 'succeeded', startedAt: '2026-10-08T00:04:00Z', finishedAt: '2026-10-08T00:04:30Z', devWorkspaceId: 'ws-1' } + + test('appears once, on the turn that replaced the workspace: below its request, above its answer', () => { + const messages = messagesFromDraft({ ...draft, conversationTurns: [later, switched, earlier], creationPlanGenerations: [generation] }, []) + expect(messages.map((message) => message.role === 'notice' ? message.title : message.role)).toEqual(['user', 'assistant', 'user', textJa.workspaceRecreated, 'assistant', 'user', 'assistant']) + expect(messages.filter((message) => message.role === 'notice')).toEqual([recreated]) + }) + test('is information only: no retry and no reference', () => { + const [notice] = messagesFromDraft({ ...draft, conversationTurns: [switched] }, []).filter((message) => message.role === 'notice') + expect(notice).toEqual(recreated) + expect(notice).not.toHaveProperty('retry') + expect(notice).not.toHaveProperty('reference') + }) + test('stays one notice on every read and reload, also while the replacing turn runs', () => { + const read = { ...draft, conversationTurns: [earlier, switched, later] } + const first = messagesFromDraft(read, []) + // A reload hands the earlier transcript back as local messages: the derived notice is not added twice. + expect(messagesFromDraft(read, first).filter((message) => message.role === 'notice')).toEqual([recreated]) + const running = messagesFromDraft({ ...draft, conversationTurns: [earlier, { ...switched, status: 'running', finishedAt: undefined }] }, []) + expect(running.slice(-2)).toEqual([{ role: 'user', text: switched.userMessage, at: switched.startedAt }, recreated]) + }) + test('appears on a plan generation that replaced the workspace, at its start', () => { + const replacing = { ...generation, replacedDevWorkspaceId: 'ws-old' } + const messages = messagesFromDraft({ ...draft, conversationTurns: [earlier], creationPlanGenerations: [replacing] }, []) + expect(messages.filter((message) => message.role === 'notice')).toEqual([{ ...recreated, at: replacing.startedAt }]) + expect(messages.at(-1)).toEqual({ ...recreated, at: replacing.startedAt }) + }) + test('a retired workspace named by more than one record is announced at the first; another retirement is announced again', () => { + const replacing = { ...generation, replacedDevWorkspaceId: 'ws-old' } + expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [switched], creationPlanGenerations: [replacing] }))).toEqual([recreated]) + const again = { ...later, replacedDevWorkspaceId: 'ws-1' } + expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [again, switched] })).map((notice) => notice.at)).toEqual([switched.startedAt, again.startedAt]) + }) + test('nothing is shown without the field (an older Platform) or for an empty one', () => { + expect(messagesFromDraft({ ...draft, conversationTurns: [earlier, later], creationPlanGenerations: [generation] }, []).some((message) => message.role === 'notice')).toBe(false) + expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [{ ...switched, replacedDevWorkspaceId: '' }] }))).toEqual([]) + }) + test('the copy is calm and exact in Japanese and English, switched at use time', () => { + expect(textJa.workspaceRecreated).toBe('作業環境を作り直しました。会話と計画は引き継いでいます') + expect(textEn.workspaceRecreated).toBe('Your workspace was recreated. The conversation and plan are kept.') + const restore = preserveLanguage() + try { + setLanguage('en') + expect(messagesFromDraft({ ...draft, conversationTurns: [switched] }, []).find((message) => message.role === 'notice')).toEqual({ ...recreated, title: textEn.workspaceRecreated }) + setLanguage('ja') + expect(buildCopy.workspaceRecreated).toBe(textJa.workspaceRecreated) + } finally { + restore() + } + }) +}) + describe('plan proposal', () => { const specMarkdown = serializeSpec({ name: '在庫管理', oneLine: '在庫を数えて一覧にする', users: ['自分だけ'], screens: ['在庫一覧', '入出庫の記録'], records: [{ name: '在庫', fields: ['品目', '数量', '保管場所'] }], rules: ['数量は 0 以上'] }, '') const tasks = Array.from({ length: 8 }, (_, index) => ({ title: `作業 ${index + 1}`, description: '一覧を作る。並べ替えもできる。', acceptanceCriteria: ['できる'] })) diff --git a/web/src/model/build/messages.ts b/web/src/model/build/messages.ts index b037967..bfbf54a 100644 --- a/web/src/model/build/messages.ts +++ b/web/src/model/build/messages.ts @@ -157,6 +157,26 @@ function proposalMessage(draft: BuildDraft, lastPlannedIntent?: string, destinat return { role: 'assistant', text: proposal.lead ?? proposal.name, proposal, at, turnId: `proposal:${generation?.id ?? draft.id}` } } +/** + * The notice that the workspace was recreated (APT-1264), on the turn or plan generation Platform marked as the switch + * from a retired workspace (`replacedDevWorkspaceId`). Information only: no retry, no reference. It is derived from + * those records, so every read and reload shows it once, at the switch, and never beside later messages; a retired + * workspace named by more than one record is announced at the first. + */ +export function workspaceRecreatedNotices(draft: BuildDraft): BuildMessage[] { + const switches = [...draft.conversationTurns, ...draft.creationPlanGenerations] + .filter((record) => record.replacedDevWorkspaceId) + .sort((a, b) => Date.parse(a.startedAt) - Date.parse(b.startedAt)) + const announced = new Set() + const notices: BuildMessage[] = [] + for (const { replacedDevWorkspaceId: replaced, startedAt } of switches) { + if (!replaced || announced.has(replaced)) continue + announced.add(replaced) + notices.push({ role: 'notice', tone: 'info', title: buildCopy.workspaceRecreated, at: startedAt }) + } + return notices +} + export function messagesFromDraft(draft: BuildDraft, extra: BuildMessage[], options: { lastPlannedIntent?: string; preparationDone?: boolean; destination?: ShownDestination } = {}): BuildMessage[] { const messages: BuildMessage[] = [] if (draft.creationPlanUnreadable) messages.push({ @@ -178,6 +198,8 @@ export function messagesFromDraft(draft: BuildDraft, extra: BuildMessage[], opti // A reply in a state this console does not know reads as that, never as an answer or a failure. if (turn.status.kind === 'unknown' || isOneOf(turn.status, 'succeeded', 'failed')) messages.push(assistantMessage(turn, draft.id)) } + // At the switch's start: after the request that caused it (a stable sort keeps it below that request), before its answer. + messages.push(...workspaceRecreatedNotices(draft)) const proposal = proposalMessage(draft, options.lastPlannedIntent, options.destination) if (proposal) messages.push(proposal) for (const message of extra) { diff --git a/web/src/model/contracts/build.ts b/web/src/model/contracts/build.ts index 327ad1f..2961a18 100644 --- a/web/src/model/contracts/build.ts +++ b/web/src/model/contracts/build.ts @@ -52,8 +52,9 @@ export type WorkspacePhase = DevWorkspacePhase export type ConditionStatus = CanonicalCondition['status'] export type PreviewDatabaseEngine = DevWorkspacePreviewDatabaseEngine -export type BuildTurn = Omit & { kind: OpenValue; status: OpenValue; excelProgress?: ExcelProgress; uiDesign?: UiDesign } -export type BuildGeneration = Omit & { status: OpenValue; stage?: OpenValue } +/** `replacedDevWorkspaceId`: the retired workspace this turn or plan generation replaced (APT-1264), on that record only. */ +export type BuildTurn = Omit & { kind: OpenValue; status: OpenValue; excelProgress?: ExcelProgress; uiDesign?: UiDesign; replacedDevWorkspaceId?: string } +export type BuildGeneration = Omit & { status: OpenValue; stage?: OpenValue; replacedDevWorkspaceId?: string } export type BuildExecutionStep = Omit & { status: OpenValue; phase?: OpenValue } export type BuildExecution = Omit & { status: OpenValue From 67718171345ec12fdba439ef86eb0478b3d50919 Mon Sep 17 00:00:00 2001 From: reoring Date: Wed, 18 Nov 2026 20:01:16 +0900 Subject: [PATCH 2/5] Announce a recreated workspace on every screen that reads the turn (APT-1264 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - One pure selector (recreatingRecords): earliest record per replacedDevWorkspaceId, derived from the draft. - Improve conversation, Excel → app analysis and preview chat, and console-v1 plan requests (by platformGenerationId) show the notice. - The notice is display-only (kind workspace-recreated); build-page decisions read the last actionable message. - The notice sits right after its request and before the answer, also at equal times or without finishedAt. --- .../features/build/build-page-wire.test.tsx | 25 +++++++++ web/src/features/build/build-page.tsx | 4 +- web/src/features/build/console-build-page.tsx | 12 ++-- .../features/build/console-conversation.tsx | 11 ++-- web/src/features/build/console-view.test.ts | 23 +++++++- web/src/features/build/console-view.ts | 19 +++++++ web/src/features/build/conversation-pane.tsx | 8 +++ .../excel2app/excel2app-page-wire.test.tsx | 46 ++++++++++++++++ web/src/features/excel2app/page.tsx | 3 + .../excel2app/ui-preview-step.test.tsx | 15 +++++ .../features/excel2app/ui-preview-step.tsx | 3 + .../excel2app/use-excel2app-draft.test.ts | 26 ++++++++- .../features/excel2app/use-excel2app-draft.ts | 26 ++++++--- web/src/features/improve/conversation.tsx | 7 ++- web/src/features/improve/copy.test.tsx | 16 ++++++ web/src/model/build/messages.test.ts | 45 ++++++++++++--- web/src/model/build/messages.ts | 55 ++++++++++++++----- web/src/model/build/types.ts | 4 +- 18 files changed, 305 insertions(+), 43 deletions(-) diff --git a/web/src/features/build/build-page-wire.test.tsx b/web/src/features/build/build-page-wire.test.tsx index 8e4f4f1..3ab9790 100644 --- a/web/src/features/build/build-page-wire.test.tsx +++ b/web/src/features/build/build-page-wire.test.tsx @@ -987,6 +987,31 @@ describe('a plan Platform\'s validation rejects is an answer about the plan (APT expect(proposalButtons()).toEqual([buildCopy.primary.prepare]) }) + test('at the generation limit, a recreated-workspace notice sorted after the limit notice (device clock behind the server) brings back no new plan (APT-1264)', async () => { + const { draftId, key } = await rejected(fieldErrorAnswer) + refusals.push({ method: 'POST', path: generations(draftId), status: 412, body: { error: { code: 'failed_precondition', message: 'application draft has reached 20 plan generation attempts' } } }) + await click(action(buildCopy.failure.plan.incomplete.title, makeAgain)) + await settle(10) + expect(notices(buildCopy.failure.limit.title, '#build-conversation')).toHaveLength(1) + expect(proposalButtons()).toEqual([]) + // Platform marks the plan's generation as the switch from a retired workspace. Its start (server time) reads later + // than the limit notice's (this device's time), so the display-only notice is the conversation's last message. + const ahead = new Date(Date.now() + 60 * 60_000).toISOString() + rewrites.push({ + method: 'GET', path: new RegExp(`${draftPath(draftId)}$`), once: false, + body: (wire) => rewriteDraftWire(wire, draftId, (draft) => ({ ...draft, creationPlanGenerations: (draft.creationPlanGenerations as Json[]).map((generation) => ({ ...generation, startedAt: ahead, replacedDevWorkspaceId: 'ws-retired' })) })), + }) + await tick(key) + await settle(10) + expect(notices(buildCopy.workspaceRecreated, '#build-conversation')).toHaveLength(1) + expect(conversation().lastIndexOf(buildCopy.workspaceRecreated)).toBeGreaterThan(conversation().lastIndexOf(buildCopy.failure.limit.title)) + // The limit is still what the page decides on: 「計画を作り直す」 is not offered again, and nothing is generated. + expect(labels(buildCopy.failure.limit.title)).toEqual([]) + expect(labels(buildCopy.workspaceRecreated)).toEqual([]) + expect(proposalButtons()).toEqual([]) + expect(count('POST', generations(draftId))).toBe(1) + }) + // A failed request is not an answer about the plan: preparing asks no AI, so a 500 and a gateway 503 alike are the // platform failure with its reference, and the same approval may be tried again. test.each([500, 503])('a failed validation request (%i) is the platform failure with its reference, never a plan rejection', async (status) => { diff --git a/web/src/features/build/build-page.tsx b/web/src/features/build/build-page.tsx index 05f4c3d..044fe00 100644 --- a/web/src/features/build/build-page.tsx +++ b/web/src/features/build/build-page.tsx @@ -24,6 +24,7 @@ import { useEffect, useState, type ReactNode } from 'react' import { buildKeys, useBuildDraft } from '../../api/queries/build' import { useGroups } from '../../api/queries/console' import { buildCopy } from '../../model/build/copy' +import { lastActionable } from '../../model/build/messages' import { isBuildPending } from '../../model/build/progress' import { paths } from '../../routes/paths' import { setArtifactCollapsed, shellStore } from '../../shell/store' @@ -80,7 +81,8 @@ function Session({ draft, groupId, stale }: { draft: BuildDraft; groupId: string const primary = { ...build.result.primary, enabled: build.result.primary.enabled && !build.busy && !sharing && !updatingPlan && (build.result.primary.action !== 'publish' || !appReadOnly) } // 決める: the prepare action is attached to the AI's proposal, labelled by what pressing it will do. After the // destination moved, the notice right below the proposal carries the same action (once, beside its explanation). - const lastMessage = build.messages.at(-1) + // A recreated-workspace notice is display only: what follows is decided on the newest message before it. + const lastMessage = lastActionable(build.messages) const reapproveNotice = lastMessage?.role === 'notice' && lastMessage.retry === 'prepare' && lastMessage.title === buildCopy.failure.destination.changed.title // A plan Platform's validation rejected is never approved again. Its actions (「もう一度確かめる」 when the cause may lie // outside the plan, 「計画を作り直す」) are on the notice that explains the rejection, or on the proposal when that notice diff --git a/web/src/features/build/console-build-page.tsx b/web/src/features/build/console-build-page.tsx index cd33478..ef171bb 100644 --- a/web/src/features/build/console-build-page.tsx +++ b/web/src/features/build/console-build-page.tsx @@ -8,7 +8,7 @@ // platform-v1 page (`build-page.tsx`) shares presentational parts only. import { useSelector } from '@tanstack/react-store' import { Loader2, PanelRightOpen } from 'lucide-react' -import { Fragment, useEffect, useState, type ReactNode } from 'react' +import { Fragment, useEffect, useMemo, useState, type ReactNode } from 'react' import { useBuildDraft } from '../../api/queries/build' import { copy } from '../../copy' import { buildCopy } from '../../model/build/copy' @@ -23,7 +23,7 @@ import { ActionError, Button, cn, Loading, Notice, ResourceBoundary, focusHeadin import { ConsoleConversation, FailureNotice } from './console-conversation' import { useConsoleDraftStages, type ConsoleStages } from './console-draft-stages' import { ConsoleSpecPane } from './console-spec-pane' -import type { ConsoleBuildView } from './console-view' +import { recreatedPlanTurnIds, type ConsoleBuildView } from './console-view' import { text } from './copy' import { SessionHeader } from './session-header' import { UnconfirmedNotice } from './unconfirmed-notice' @@ -57,10 +57,12 @@ function ConsoleWithDraft({ view, actions, stale, draftId }: { view: ConsoleBuil function ConsoleDraftView({ view, actions, stale, draft, me, groups }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draft: BuildDraft; me: Me; groups: Group[] }) { const [openArtifact, setOpenArtifact] = useState(0) const stages = useConsoleDraftStages({ view, actions, draft, me, groups, onOpenArtifact: () => setOpenArtifact((count) => count + 1) }) - return + // A plan request whose Platform generation switched from a retired workspace says so (APT-1264). + const recreatedPlanTurns = useMemo(() => recreatedPlanTurnIds(view.turns, draft.creationPlanGenerations), [view.turns, draft.creationPlanGenerations]) + return } -function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact = 0 }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; stages?: ConsoleStages; draftError?: unknown; openArtifact?: number }) { +function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact = 0, recreatedPlanTurns }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; stages?: ConsoleStages; draftError?: unknown; openArtifact?: number; recreatedPlanTurns?: ReadonlySet }) { const { session } = view const name = parseSpec(session.specification.markdown).spec.name || text.session.newApp useDocumentTitle(text.page.title(name)) @@ -103,7 +105,7 @@ function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact
- +
{stages?.artifact ?? } diff --git a/web/src/features/build/console-conversation.tsx b/web/src/features/build/console-conversation.tsx index bdecd55..e033881 100644 --- a/web/src/features/build/console-conversation.tsx +++ b/web/src/features/build/console-conversation.tsx @@ -15,14 +15,14 @@ import { locale } from '../../shell/language' import { Button, cn, Notice } from '../../ui' import { Composer } from './composer' import type { ConsoleBuildView, ConsoleProgress } from './console-view' -import { AiTurn, UserMessage } from './conversation-pane' +import { AiTurn, UserMessage, WorkspaceRecreatedNotice } from './conversation-pane' import { text } from './copy' import type { ConsoleBuildActions } from './use-console-build-session' /** Pixels from the bottom that still count as "reading the newest message". */ const STICK = 96 -export function ConsoleConversation({ view, actions, restore, end, closedReason }: { +export function ConsoleConversation({ view, actions, restore, end, closedReason, recreatedPlanTurns }: { view: ConsoleBuildView actions: ConsoleBuildActions restore?: { text: string; nonce: number } @@ -30,6 +30,8 @@ export function ConsoleConversation({ view, actions, restore, end, closedReason end?: ReactNode /** Why the composer is closed for good (building started). */ closedReason?: string + /** Plan requests whose Platform generation switched from a retired workspace (console-view.ts#recreatedPlanTurnIds). */ + recreatedPlanTurns?: ReadonlySet }) { const scroller = useRef(null) const content = useRef(null) @@ -66,7 +68,7 @@ export function ConsoleConversation({ view, actions, restore, end, closedReason
{view.turns.map((turn) => turn.kind === 'conversation' ? { following.current = true; actions.send(text.console.candidateMessage(label), 'change') }} /> - : )} + : )} {end}
@@ -157,11 +159,12 @@ function ReplyBody({ reply, turn, view, actions, actionable, confirming, onChoos
} -function PlanTurnItem({ turn, view }: { turn: PlanTurn; view: ConsoleBuildView }) { +function PlanTurnItem({ turn, view, recreated }: { turn: PlanTurn; view: ConsoleBuildView; recreated: boolean }) { const phase = planPhase(turn) const active = view.activeTurn?.id === turn.id return
+ {recreated ? : null} {phase.kind === 'failed' ? : {phase.kind === 'working' ? active ? : null : phase.kind === 'handed_off' ? <> diff --git a/web/src/features/build/console-view.test.ts b/web/src/features/build/console-view.test.ts index 974f0ae..22f4bab 100644 --- a/web/src/features/build/console-view.test.ts +++ b/web/src/features/build/console-view.test.ts @@ -3,9 +3,10 @@ import { describe, expect, test } from 'bun:test' import { readFileSync } from 'node:fs' import { buildSessionReader, buildTurnReader } from '../../api/contracts/console/build-sessions' +import { generationOf } from '../../api/testing/build-domain' import { buildCopy } from '../../model/build/copy' import type { BuildSession, BuildTurn } from '../../model/contracts/console' -import { deriveConsoleBuildView, SLOW_OBSERVATION_MS, type ConsoleViewInput } from './console-view' +import { deriveConsoleBuildView, recreatedPlanTurnIds, SLOW_OBSERVATION_MS, type ConsoleViewInput } from './console-view' type Fixture = { name: string; raw: string } const fixtures = JSON.parse(readFileSync(new URL('../../../../cmd/server/internal/api/testdata/build-conversation.json', import.meta.url), 'utf8')) as Fixture[] @@ -74,3 +75,23 @@ describe('what may be sent', () => { expect(deriveConsoleBuildView(input({ intent: { ...intent, status: 'pending' }, sending: true })).write).toEqual({ family: 'publish', status: 'sending' }) }) }) + +describe('a plan request whose Platform generation replaced a retired workspace (APT-1264)', () => { + const generation = (id: string, minute: number, replaced?: string) => generationOf({ id, status: 'succeeded', startedAt: `2026-11-12T00:0${minute}:00Z`, devWorkspaceId: 'ws-new', ...(replaced ? { replacedDevWorkspaceId: replaced } : {}) }) + const plan = (id: string, generationId?: string) => turn('plan-turn', { id, platformGenerationId: generationId }) + test('matches the request_plan turn by its platformGenerationId, never a conversation turn', () => { + const turns = [turn('turn-explicit-keep'), plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012', 'gen-2')] + expect([...recreatedPlanTurnIds(turns, [generation('gen-1', 1), generation('gen-2', 2, 'ws-old')])]).toEqual(['89c00000-0000-4000-8000-000000000012']) + }) + test('nothing without the field, without a generation id, or for a generation this draft does not hold', () => { + const turns = [plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012')] + expect([...recreatedPlanTurnIds(turns, [generation('gen-1', 1)])]).toEqual([]) + expect([...recreatedPlanTurnIds(turns, [generation('gen-9', 1, 'ws-old')])]).toEqual([]) + }) + test('one per retired workspace, at the first generation that named it; the same on every read', () => { + const turns = [plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012', 'gen-2'), plan('89c00000-0000-4000-8000-000000000013', 'gen-3')] + const generations = [generation('gen-3', 3, 'ws-2'), generation('gen-2', 2, 'ws-old'), generation('gen-1', 1, 'ws-old')] + expect([...recreatedPlanTurnIds(turns, generations)]).toEqual(['89c00000-0000-4000-8000-000000000011', '89c00000-0000-4000-8000-000000000013']) + expect(recreatedPlanTurnIds(turns, generations)).toEqual(recreatedPlanTurnIds(turns, generations)) + }) +}) diff --git a/web/src/features/build/console-view.ts b/web/src/features/build/console-view.ts index 58b562e..9cd5e4d 100644 --- a/web/src/features/build/console-view.ts +++ b/web/src/features/build/console-view.ts @@ -6,6 +6,8 @@ // stage and observation time (design §13), never a fabricated activity log. import type { OpenValue } from '../../api/boundary' import { isObserving, mergeTurn } from '../../api/queries/build-sessions' +import { recreatingRecords } from '../../model/build/messages' +import type { BuildGeneration } from '../../model/contracts/build' import type { BuildPublishResult, BuildSession, BuildTurn } from '../../model/contracts/console' import type { ConsoleWriteFamily, ConsoleWriteIntent } from './console-session-state' @@ -144,3 +146,20 @@ export function deriveConsoleBuildView(input: ConsoleViewInput): ConsoleBuildVie ...(publish ? { publish } : {}), } } + +/** + * The plan requests whose Platform plan generation switched from a retired workspace (APT-1264), by turn id. Matched + * on the typed `platformGenerationId` only: a conversation turn is never guessed at. One per retired workspace, at the + * first generation that named it; derived from the draft, so every read shows the same ones. + */ +export function recreatedPlanTurnIds(turns: readonly BuildTurn[], generations: readonly BuildGeneration[]): Set { + const recreating = new Set([...recreatingRecords(generations)].map((generation) => generation.id)) + const announced = new Set() + const ids = new Set() + for (const turn of turns) { + if (turn.kind !== 'request_plan' || !turn.platformGenerationId || !recreating.has(turn.platformGenerationId) || announced.has(turn.platformGenerationId)) continue + announced.add(turn.platformGenerationId) + ids.add(turn.id) + } + return ids +} diff --git a/web/src/features/build/conversation-pane.tsx b/web/src/features/build/conversation-pane.tsx index d5bdad1..5e74fe9 100644 --- a/web/src/features/build/conversation-pane.tsx +++ b/web/src/features/build/conversation-pane.tsx @@ -148,6 +148,14 @@ export function UserMessage({ text }: { text: string }) { } +/** + * The workspace was recreated (APT-1264), where a conversation keeps its own records (improve, Excel → app, console-v1 + * plan requests): information only, the same as the build conversation's derived notice (messages.ts#workspaceRecreatedNotice). + */ +export function WorkspaceRecreatedNotice({ className }: { className?: string }) { + return +} + /** A failure's support reference, with its copy button. */ export function FailureReference({ reference }: { reference: NonNullable }) { const value = buildFailureReference(reference) diff --git a/web/src/features/excel2app/excel2app-page-wire.test.tsx b/web/src/features/excel2app/excel2app-page-wire.test.tsx index ca88bc9..d6c74bf 100644 --- a/web/src/features/excel2app/excel2app-page-wire.test.tsx +++ b/web/src/features/excel2app/excel2app-page-wire.test.tsx @@ -375,3 +375,49 @@ describe('X5: a 2xx Excel write whose answer cannot be read', () => { expect(stepTitle()).toBe(text.preview.title) }) }) + +describe('APT-1264: a turn that replaced a retired workspace', () => { + /** Platform marks the draft's turns of `kind` as the switch from a retired workspace (every read of the draft). */ + function replaced(kind: 'excel-analysis' | 'ui-design') { + rewrites.push({ + method: 'GET', path: /\/application-drafts\/[^/]+$/, once: false, + body: (wire) => Array.isArray(wire.conversationTurns) + ? { ...wire, conversationTurns: (wire.conversationTurns as Json[]).map((turn) => turn.kind === kind ? { ...turn, replacedDevWorkspaceId: 'ws-retired' } : turn) } + : wire, + }) + } + const recreated = () => [...container.querySelectorAll('[role="status"]')].filter((item) => item.querySelector('p')?.textContent === buildCopy.workspaceRecreated) + async function reopen(draftId: string) { + await act(async () => { root?.unmount() }) + container.remove() + await renderExcel(draftId) + } + + test('the analysis step says so once, also after the same draft is opened again', async () => { + const draftId = await storedDraft() + // Started but not advanced: the analysis runs, so the page opens on its step. + await call('POST', `${draftPath(draftId)}/conversation-turns`, { kind: 'excel-analysis', message: '' }) + replaced('excel-analysis') + await renderExcel(draftId) + await until(() => Boolean(byTestId('excel2app-workspace-recreated'))) + expect(recreated()).toHaveLength(1) + expect(buttonsIn(byTestId('excel2app-workspace-recreated')!)).toEqual([]) + await reopen(draftId) + await until(() => Boolean(byTestId('excel2app-workspace-recreated'))) + expect(recreated()).toHaveLength(1) + }) + + test('the preview chat says so once, at the design turn, also after the same draft is opened again', async () => { + const draftId = await storedDraft({ analysed: true, designed: true }) + replaced('ui-design') + await renderExcel(draftId) + await until(() => Boolean(byTestId('excel2app-chat-input'))) + expect(recreated()).toHaveLength(1) + expect(container.querySelectorAll('[data-testid="excel2app-chat-message"][data-role="notice"]')).toHaveLength(1) + // The analysis turn did not switch: its step has nothing to say. + expect(byTestId('excel2app-workspace-recreated')).toBeNull() + await reopen(draftId) + await until(() => Boolean(byTestId('excel2app-chat-input'))) + expect(recreated()).toHaveLength(1) + }) +}) diff --git a/web/src/features/excel2app/page.tsx b/web/src/features/excel2app/page.tsx index 5cf3f79..ac8cf20 100644 --- a/web/src/features/excel2app/page.tsx +++ b/web/src/features/excel2app/page.tsx @@ -20,6 +20,7 @@ import { Button, Card, CardBody, cn, CopyButton, EmptyState, Field, focusHeading import { ResourceBoundary, type ResourceQuery } from '../../ui/resource-boundary' import { text as buildText } from '../build/copy' import { resolveBuildGroup } from '../build/entry' +import { WorkspaceRecreatedNotice } from '../build/conversation-pane' import { UnconfirmedNotice } from '../build/unconfirmed-notice' import { filesFromDrop, filesFromList, type CollectedWorkbook } from './collect' import { text } from './copy' @@ -274,6 +275,8 @@ function Excel2AppFlow({ draftId, onCreatedDraft }: { draftId?: string; onCreate {flow.unconfirmed ?
void flow.confirm()} />
: null} {step === 0 && !readOnly ? void collected(files)} onSample={(grids) => void collected(grids, true)} onRemove={(file) => void remove(file)} onRetry={(file) => void flow.retryFile(file.key)} onStart={() => { setStep(ANALYSIS_STEP); void flow.startAnalysis() }} /> : null} + {/* The analysis switched from a retired workspace (APT-1264): told once on its step, above what it read. */} + {step === ANALYSIS_STEP && draft && flow.analysis.recreated ?
: null} {step === ANALYSIS_STEP && draft ? ( reading ? ( diff --git a/web/src/features/excel2app/ui-preview-step.test.tsx b/web/src/features/excel2app/ui-preview-step.test.tsx index 5ecd860..35d5993 100644 --- a/web/src/features/excel2app/ui-preview-step.test.tsx +++ b/web/src/features/excel2app/ui-preview-step.test.tsx @@ -109,6 +109,21 @@ test('a failed turn renders as a notice with retry on the last message only', () expect(render({ messages: [failed], onRetry: () => {}, busy: true })).not.toContain('excel2app-chat-retry') }) +test.each(['ja', 'en'] as const)('a recreated workspace is one calm notice between the instruction and its reply, never a bubble or a retry (APT-1264, %s)', (language) => { + setLanguage(language) + const messages: UiPreviewChatMessage[] = [ + { role: 'user', text: '一覧をカード表示に' }, + { role: 'notice', text: buildCopy.workspaceRecreated }, + { role: 'assistant', text: '一覧をカード表示にしました。' }, + ] + const html = render({ messages, onRetry: () => {} }) + expect(html.split(buildCopy.workspaceRecreated)).toHaveLength(2) + expect(html.split('data-role="notice"')).toHaveLength(2) + expect(html.indexOf('data-role="user"')).toBeLessThan(html.indexOf(buildCopy.workspaceRecreated)) + expect(html.indexOf(buildCopy.workspaceRecreated)).toBeLessThan(html.indexOf('data-role="assistant"')) + expect(html).not.toContain('excel2app-chat-retry') +}) + test.each(['ja', 'en'] as const)('quota failure in UI chat explains the account problem and retains manual retry in %s', (language) => { setLanguage(language) for (const error of [ diff --git a/web/src/features/excel2app/ui-preview-step.tsx b/web/src/features/excel2app/ui-preview-step.tsx index 8cacbc0..4f0e3d2 100644 --- a/web/src/features/excel2app/ui-preview-step.tsx +++ b/web/src/features/excel2app/ui-preview-step.tsx @@ -233,6 +233,9 @@ function ChatPanel({ messages, busy, readOnly, activity, ready, onSend, onUndo, {/* biome-ignore lint/a11y/noNoninteractiveTabindex: a scrollable region must be reachable by keyboard. */}
    {messages.map((message, index) => { + // The workspace was recreated (APT-1264): information between an instruction and its reply, not a chat bubble. + // biome-ignore lint/suspicious/noArrayIndexKey: the conversation only grows; an index is its identity. + if (message.role === 'notice') return
  1. const state = message.failed ? 'failed' : message.pending ? 'pending' : undefined const quota = message.failed && isAIQuotaExhausted(message.text) const failure = message.failed ? message.failure ?? classifyBuildFailure(message.text, undefined, 'turn') : undefined diff --git a/web/src/features/excel2app/use-excel2app-draft.test.ts b/web/src/features/excel2app/use-excel2app-draft.test.ts index 99b6fb8..88c87c6 100644 --- a/web/src/features/excel2app/use-excel2app-draft.test.ts +++ b/web/src/features/excel2app/use-excel2app-draft.test.ts @@ -2,13 +2,15 @@ import { describe, expect, test } from 'bun:test' import type { ApplicationDraft, ApplicationDraftConversationTurn } from '@appthrust/api-schema/platform-api' import { completeUiDesign, excelAnalysisOf, uiDesignOf, type CompleteUiDesign } from '../../model/contracts/excel' import { draftOf, readEachFirst, readFirst, turnOf } from '../../api/testing/build-domain' +import { buildCopy } from '../../model/build/copy' +import { recreatingRecords } from '../../model/build/messages' import { serializeSpec } from '../../model/build/spec' import { textJa } from './copy' import { fromDraftWorkbook, planApp, toDraftWorkbook } from './model' import { designFromReadings } from './design' import { SAMPLE_SETS } from './samples' import { defaultUiDesign } from './ui-design' -import { analysisTitle as domainAnalysisTitle, classifyStoreError, currentTurns as domainCurrentTurns, designMessages as domainDesignMessages, designStack as domainDesignStack, fileStem, handOffPatch, isApplicationCreated, latestSaver, resumeStep as domainResumeStep, specParts, undoMessage, UI_DESIGN_INIT } from './use-excel2app-draft' +import { analysisTitle as domainAnalysisTitle, classifyStoreError, currentTurns as domainCurrentTurns, designMessages as domainDesignMessages, designStack as domainDesignStack, fileStem, handOffPatch, isApplicationCreated, latestSaver, resumeStep as domainResumeStep, specParts, undoMessage, UI_DESIGN_INIT, type UiPreviewChatMessage } from './use-excel2app-draft' const currentTurns = readFirst(draftOf, domainCurrentTurns) const resumeStep = readFirst(draftOf, domainResumeStep) @@ -153,6 +155,28 @@ describe('screen design turns', () => { { role: 'user', text: '密度をコンパクトに', pending: true }, ]) }) + test('a turn that replaced a retired workspace says so once, after its instruction and before its reply; reopening gives the same chat (APT-1264)', () => { + const replacingInit = { ...init, replacedDevWorkspaceId: 'ws-old' } + const replacingChange = { ...change, replacedDevWorkspaceId: 'ws-1' } + // A later turn naming the same retired workspace again adds nothing. + const again = { ...turn('t-again', '色を青に', 4, { assistantMessage: '## 要約\n色を青にしました。' }), replacedDevWorkspaceId: 'ws-old' } + const open = () => { + const turns = domainCurrentTurns(draftOf({ ...draft, conversationTurns: [replacingInit, replacingChange, again] })) + return domainDesignMessages(turns, recreatingRecords(turns)) + } + const notice: UiPreviewChatMessage = { role: 'notice', text: buildCopy.workspaceRecreated } + expect(open()).toEqual([ + notice, + { role: 'assistant', text: '6 画面を用意しました。' }, + { role: 'user', text: '一覧をカード表示に' }, + notice, + { role: 'assistant', text: '一覧をカード表示にしました。' }, + { role: 'user', text: '色を青に' }, + { role: 'assistant', text: '色を青にしました。' }, + ]) + expect(open()).toEqual(open()) + expect(designMessages([init, change]).some((message) => message.role === 'notice')).toBe(false) + }) test('the undo request carries the previous design as JSON within one turn message', () => { const message = undoMessage(design) expect(message.startsWith(textJa.preview.undoRequest)).toBe(true) diff --git a/web/src/features/excel2app/use-excel2app-draft.ts b/web/src/features/excel2app/use-excel2app-draft.ts index 0697188..4ea42c4 100644 --- a/web/src/features/excel2app/use-excel2app-draft.ts +++ b/web/src/features/excel2app/use-excel2app-draft.ts @@ -10,9 +10,10 @@ import { draftWorkbookGridOptions, draftWorkbooksOptions } from '../../api/queri import { isResponseContractError } from '../../api/boundary' import { platformErrorEnvelope } from '../../api/platform-error' import { useCreationTools } from '../../api/queries/catalog' +import { buildCopy } from '../../model/build/copy' import { classifyBuildFailure } from '../../model/build/failure' import type { BuildFailure } from '../../model/build/types' -import { parseAssistantMessage } from '../../model/build/messages' +import { parseAssistantMessage, recreatingRecords } from '../../model/build/messages' import { isBuildPending } from '../../model/build/progress' import { parseSpec, serializeSpec } from '../../model/build/spec' import { filesFromList, isWorkbookFile, workbookBudget, type CollectedWorkbook, type WorkbookFileState } from './collect' @@ -43,9 +44,12 @@ export interface CollectionResult { analysisRequested: boolean } -/** One bubble of the chat. Failed turns retain their cause for classification by the notice. */ +/** + * One bubble of the chat. Failed turns retain their cause for classification by the notice. `notice`: the workspace was + * recreated (APT-1264), shown between the turn's instruction and its reply; information only. + */ export interface UiPreviewChatMessage { - role: 'user' | 'assistant' + role: 'user' | 'assistant' | 'notice' text: string pending?: boolean failed?: boolean @@ -123,12 +127,16 @@ export function designStack(turns: BuildTurn[]): UiDesign[] { return stack } -/** The chat the ui-design turns make: the instruction, then the reply's summary (or its error). */ -export function designMessages(turns: BuildTurn[]): UiPreviewChatMessage[] { +/** + * The chat the ui-design turns make: the instruction, then the reply's summary (or its error). A turn in `recreating` + * (messages.ts#recreatingRecords) switched from a retired workspace: it says so once, after its instruction. + */ +export function designMessages(turns: BuildTurn[], recreating: ReadonlySet = new Set()): UiPreviewChatMessage[] { const messages: UiPreviewChatMessage[] = [] for (const turn of turns) { const pending = isBuildPending(turn) if (turn.userMessage !== UI_DESIGN_INIT) messages.push({ role: 'user', text: isUndoMessage(turn.userMessage) ? text.preview.undoMessage : turn.userMessage, ...(pending ? { pending: true } : {}) }) + if (recreating.has(turn)) messages.push({ role: 'notice', text: buildCopy.workspaceRecreated }) if (isOneOf(turn.status, 'failed')) messages.push({ role: 'assistant', text: turn.error || text.preview.turnFailed, failed: true }) else if (isOneOf(turn.status, 'succeeded') && turn.assistantMessage) { const parts = parseAssistantMessage(turn.assistantMessage) @@ -255,6 +263,8 @@ export function useExcel2AppDraft(projectId: string, draftId: string | undefined const turns = useMemo(() => (draft ? currentTurns(draft) : []), [draft]) const analysisTurn = turnsOf(turns, 'excel-analysis').at(-1) const designTurns = useMemo(() => turnsOf(turns, 'ui-design'), [turns]) + // Turns that switched from a retired workspace (APT-1264): derived from the draft, so reopening it shows the same ones. + const recreating = useMemo(() => recreatingRecords(turns), [turns]) const latestDesignTurn = designTurns.at(-1) // A turn in a state this console does not know may still run: nothing new is sent over it. const turnRunning = turns.some((turn) => jobState(turn) !== 'settled') @@ -662,14 +672,14 @@ export function useExcel2AppDraft(projectId: string, draftId: string | undefined const messages = useMemo(() => { if (usingOffline) return offlineDesign?.messages ?? [] - const list = designMessages(designTurns) + const list = designMessages(designTurns, recreating) if (sending && sending !== UI_DESIGN_INIT) list.push({ role: 'user', text: isUndoMessage(sending) ? text.preview.undoMessage : sending, pending: true }) if (sendProblem) { if (sendProblem.instruction !== UI_DESIGN_INIT) list.push({ role: 'user', text: isUndoMessage(sendProblem.instruction) ? text.preview.undoMessage : sendProblem.instruction }) list.push({ role: 'assistant', text: sendProblem.message, failed: true, failure: sendProblem.failure }) } return list - }, [usingOffline, offlineDesign, designTurns, sending, sendProblem]) + }, [usingOffline, offlineDesign, designTurns, recreating, sending, sendProblem]) const designBusy = usingOffline ? false : Boolean(sending) || isBuildPending(latestDesignTurn) const suggestions = usingOffline @@ -721,6 +731,8 @@ export function useExcel2AppDraft(projectId: string, draftId: string | undefined offline: usingOffline, analysis: { turn: analysisTurn, + /** An analysis turn of this membership switched from a retired workspace: the step says so once (APT-1264). */ + recreated: turnsOf(turns, 'excel-analysis').some((turn) => recreating.has(turn)), running: starting || isBuildPending(analysisTurn), problem: analysisProblem?.kind ?? (isOneOf(analysisTurn?.status, 'failed') && !draft?.excelAnalysis ? ('failed' as const) : undefined), failure: analysisProblem?.failure, diff --git a/web/src/features/improve/conversation.tsx b/web/src/features/improve/conversation.tsx index d8c512d..c8e7ad0 100644 --- a/web/src/features/improve/conversation.tsx +++ b/web/src/features/improve/conversation.tsx @@ -3,14 +3,14 @@ import { Check, Circle, ExternalLink, Loader2 } from 'lucide-react' import { forwardRef, useLayoutEffect, useRef, type ReactNode } from 'react' import { buildCopy } from '../../model/build/copy' import { buildFailureReference, classifyBuildFailure, classifyRunFailure, failureOffers, failureText } from '../../model/build/failure' -import { assistantMessage } from '../../model/build/messages' +import { assistantMessage, recreatingRecords } from '../../model/build/messages' import { activityLines, formatElapsed } from '../../model/build/progress' import type { BuildFailure } from '../../model/build/types' import { isProductLanguage } from '../../model/build/wording' import { improveTimeline, runVersion, sortedTurns, type ImproveState, type ImproveTask } from '../../model/improve' import { ActivityLog, Button, CopyButton, LinkButton, Notice } from '../../ui' import { Composer } from '../build/composer' -import { AiTurn, AssistantMessage, UserMessage } from '../build/conversation-pane' +import { AiTurn, AssistantMessage, UserMessage, WorkspaceRecreatedNotice } from '../build/conversation-pane' import { text as buildText } from '../build/copy' import { text } from './copy' import { useClock } from './use-clock' @@ -72,6 +72,8 @@ export const ImproveConversation = forwardRef isOneOf(turn.status, 'succeeded')) + // The turn that switched from a retired workspace tells it once, between its request and its answer (APT-1264). + const recreating = recreatingRecords(turns) const latestRun = draft.implementationRuns.at(-1) const answerable = state.phase === 'asking' || state.phase === 'proposed' const chips = answerable && !locked ? (lastAnswer?.suggestedReplies ?? []).map((reply) => ({ label: reply, value: reply })) : [] @@ -80,6 +82,7 @@ export const ImproveConversation = forwardRef + {recreating.has(turn) ? : null} {answer?.role === 'assistant' ? : null} {turn.id === state.proposalTurnId ? : null} {isOneOf(turn.status, 'failed') ? submit(turn.userMessage) : undefined} /> : null} diff --git a/web/src/features/improve/copy.test.tsx b/web/src/features/improve/copy.test.tsx index ec7edc2..cddffe4 100644 --- a/web/src/features/improve/copy.test.tsx +++ b/web/src/features/improve/copy.test.tsx @@ -96,6 +96,22 @@ test('improvement failures honor run and task reasons before diagnostic wording' expect(interrupted).toContain(buildCopy.failure.resumable.reason) }) +test.each(['ja', 'en'] as const)('a turn that replaced a retired workspace tells it once, between its request and its answer, as information (APT-1264, %s)', (language) => { + setLanguage(language) + const first = draft.conversationTurns![0]! + const replacing = { ...first, id: 't2', startedAt: '2026-10-26T00:01:00Z', finishedAt: '2026-10-26T00:01:10Z', userMessage: '並び順も変えたい', assistantMessage: '## 要約\n並び順を変えます。', replacedDevWorkspaceId: 'ws-old' } + const later = { ...first, id: 't3', startedAt: '2026-10-26T00:02:00Z', finishedAt: '2026-10-26T00:02:10Z', userMessage: '色も変えたい', assistantMessage: '## 要約\n色を変えます。' } + const html = render({ ...draft, conversationTurns: [first, replacing, later] }) + const notice = buildCopy.workspaceRecreated + expect(notice).toBe(language === 'ja' ? '作業環境を作り直しました。会話と計画は引き継いでいます' : 'Your workspace was recreated. The conversation and plan are kept.') + expect(html.split(notice)).toHaveLength(2) + expect(html.indexOf('並び順も変えたい')).toBeLessThan(html.indexOf(notice)) + expect(html.indexOf(notice)).toBeLessThan(html.indexOf('並び順を変えます。')) + expect(html.indexOf(notice)).toBeLessThan(html.indexOf('色も変えたい')) + // An older Platform sends no field: nothing is shown. + expect(render(draft)).not.toContain(notice) +}) + test.each(['ja', 'en'] as const)('a stopped run names no way on this page lacks: no skip, and a reply here is a new turn, not a change run, in %s', (language) => { setLanguage(language) const id = implementationTodoId(tasks[0]!.title, 0) diff --git a/web/src/model/build/messages.test.ts b/web/src/model/build/messages.test.ts index fd6b79e..fa6980f 100644 --- a/web/src/model/build/messages.test.ts +++ b/web/src/model/build/messages.test.ts @@ -127,19 +127,21 @@ describe('conversation history', () => { }) describe('recreated workspace notice (APT-1264)', () => { - const recreated = { role: 'notice', tone: 'info', title: textJa.workspaceRecreated, at: '2026-10-08T00:02:00Z' } satisfies BuildMessage + const recreated = { role: 'notice', kind: 'workspace-recreated', tone: 'info', title: textJa.workspaceRecreated, at: '2026-10-08T00:02:00Z' } satisfies BuildMessage const earlier = { ...turn, devWorkspaceId: 'ws-old' } const switched = { ...turn, id: 'turn-2', startedAt: '2026-10-08T00:02:00Z', finishedAt: '2026-10-08T00:02:10Z', userMessage: '入れる', replacedDevWorkspaceId: 'ws-old' } const later = { ...turn, id: 'turn-3', startedAt: '2026-10-08T00:03:00Z', finishedAt: '2026-10-08T00:03:10Z', userMessage: 'ありがとう' } const generation = { id: 'gen-1', status: 'succeeded', startedAt: '2026-10-08T00:04:00Z', finishedAt: '2026-10-08T00:04:30Z', devWorkspaceId: 'ws-1' } + const notices = (wire: unknown) => messagesFromDraft(wire, []).filter((message) => message.role === 'notice') + const shape = (messages: BuildMessage[]) => messages.map((message) => message.role === 'notice' ? message.title : message.role) test('appears once, on the turn that replaced the workspace: below its request, above its answer', () => { const messages = messagesFromDraft({ ...draft, conversationTurns: [later, switched, earlier], creationPlanGenerations: [generation] }, []) - expect(messages.map((message) => message.role === 'notice' ? message.title : message.role)).toEqual(['user', 'assistant', 'user', textJa.workspaceRecreated, 'assistant', 'user', 'assistant']) + expect(shape(messages)).toEqual(['user', 'assistant', 'user', textJa.workspaceRecreated, 'assistant', 'user', 'assistant']) expect(messages.filter((message) => message.role === 'notice')).toEqual([recreated]) }) test('is information only: no retry and no reference', () => { - const [notice] = messagesFromDraft({ ...draft, conversationTurns: [switched] }, []).filter((message) => message.role === 'notice') + const [notice] = notices({ ...draft, conversationTurns: [switched] }) expect(notice).toEqual(recreated) expect(notice).not.toHaveProperty('retry') expect(notice).not.toHaveProperty('reference') @@ -152,21 +154,50 @@ describe('recreated workspace notice (APT-1264)', () => { const running = messagesFromDraft({ ...draft, conversationTurns: [earlier, { ...switched, status: 'running', finishedAt: undefined }] }, []) expect(running.slice(-2)).toEqual([{ role: 'user', text: switched.userMessage, at: switched.startedAt }, recreated]) }) + test('sits right below the request, before an answer of the same time (no finishedAt, or finished at its start)', () => { + const user = { role: 'user', text: switched.userMessage, at: switched.startedAt } satisfies BuildMessage + const failed = messagesFromDraft({ ...draft, conversationTurns: [{ ...switched, status: 'failed', finishedAt: undefined, error: 'codex exited' }] }, []) + expect(failed.slice(0, 2)).toEqual([user, recreated]) + expect(failed[2]).toMatchObject({ role: 'notice', tone: 'error', at: switched.startedAt, retry: 'turn' }) + const unknown = messagesFromDraft({ ...draft, conversationTurns: [{ ...switched, status: 'future-state', finishedAt: undefined }] }, []) + expect(shape(unknown)).toEqual(['user', textJa.workspaceRecreated, buildCopy.unsupported.title]) + const instant = messagesFromDraft({ ...draft, conversationTurns: [{ ...switched, finishedAt: switched.startedAt }] }, []) + expect(shape(instant)).toEqual(['user', textJa.workspaceRecreated, 'assistant']) + }) test('appears on a plan generation that replaced the workspace, at its start', () => { const replacing = { ...generation, replacedDevWorkspaceId: 'ws-old' } const messages = messagesFromDraft({ ...draft, conversationTurns: [earlier], creationPlanGenerations: [replacing] }, []) expect(messages.filter((message) => message.role === 'notice')).toEqual([{ ...recreated, at: replacing.startedAt }]) expect(messages.at(-1)).toEqual({ ...recreated, at: replacing.startedAt }) }) + test('a switch an Excel → app turn made stays after the collapsed Excel line', () => { + const analysis = { ...turn, kind: 'excel-analysis' as const, id: 'turn-excel', userMessage: 'この Excel を読み取ってください', startedAt: '2026-10-08T00:00:10Z', finishedAt: '2026-10-08T00:00:40Z' } + const design = { ...turn, kind: 'ui-design' as const, id: 'turn-ui-1', userMessage: '__init__', startedAt: '2026-10-08T00:00:50Z', finishedAt: '2026-10-08T00:00:55Z', replacedDevWorkspaceId: 'ws-old' } + const messages = messagesFromDraft({ ...draft, conversationTurns: [switched, design, analysis] }, []) + // The design turn named ws-old first: the later conversation turn naming it again adds nothing. + expect(shape(messages)).toEqual(['assistant', textJa.workspaceRecreated, 'user', 'assistant']) + expect(messages[0]).toMatchObject({ turnId: `excel:${draft.id}` }) + expect(messages[1]).toEqual({ ...recreated, at: design.startedAt }) + }) test('a retired workspace named by more than one record is announced at the first; another retirement is announced again', () => { const replacing = { ...generation, replacedDevWorkspaceId: 'ws-old' } - expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [switched], creationPlanGenerations: [replacing] }))).toEqual([recreated]) + expect(notices({ ...draft, conversationTurns: [switched], creationPlanGenerations: [replacing] })).toEqual([recreated]) const again = { ...later, replacedDevWorkspaceId: 'ws-1' } - expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [again, switched] })).map((notice) => notice.at)).toEqual([switched.startedAt, again.startedAt]) + expect(notices({ ...draft, conversationTurns: [again, switched] }).map((notice) => notice.at)).toEqual([switched.startedAt, again.startedAt]) + const read = draftOf({ ...draft, conversationTurns: [again, switched], creationPlanGenerations: [replacing] }) + expect([...model.recreatingRecords([...read.conversationTurns, ...read.creationPlanGenerations])].map((record) => record.id)).toEqual(['turn-2', 'turn-3']) }) test('nothing is shown without the field (an older Platform) or for an empty one', () => { - expect(messagesFromDraft({ ...draft, conversationTurns: [earlier, later], creationPlanGenerations: [generation] }, []).some((message) => message.role === 'notice')).toBe(false) - expect(model.workspaceRecreatedNotices(draftOf({ ...draft, conversationTurns: [{ ...switched, replacedDevWorkspaceId: '' }] }))).toEqual([]) + expect(notices({ ...draft, conversationTurns: [earlier, later], creationPlanGenerations: [generation] })).toEqual([]) + expect(notices({ ...draft, conversationTurns: [{ ...switched, replacedDevWorkspaceId: '' }] })).toEqual([]) + }) + test('decisions read past it: the newest actionable message is the one before it', () => { + // A device clock behind the server's sorts the server-timed notice after the local generation-limit notice. + const limit = { role: 'notice', tone: 'warning', title: buildCopy.failure.limit.title, detail: buildCopy.failure.limitRejected, at: '2026-10-08T00:01:30Z' } satisfies BuildMessage + const messages = messagesFromDraft({ ...draft, conversationTurns: [earlier], creationPlanGenerations: [{ ...generation, replacedDevWorkspaceId: 'ws-old' }] }, [limit]) + expect(messages.at(-1)).toMatchObject({ kind: 'workspace-recreated' }) + expect(model.lastActionable(messages)).toEqual(limit) + expect(model.lastActionable([{ ...recreated }])).toBeUndefined() }) test('the copy is calm and exact in Japanese and English, switched at use time', () => { expect(textJa.workspaceRecreated).toBe('作業環境を作り直しました。会話と計画は引き継いでいます') diff --git a/web/src/model/build/messages.ts b/web/src/model/build/messages.ts index bfbf54a..38d426d 100644 --- a/web/src/model/build/messages.ts +++ b/web/src/model/build/messages.ts @@ -157,24 +157,41 @@ function proposalMessage(draft: BuildDraft, lastPlannedIntent?: string, destinat return { role: 'assistant', text: proposal.lead ?? proposal.name, proposal, at, turnId: `proposal:${generation?.id ?? draft.id}` } } +/** A record Platform may mark as the switch from a retired workspace (APT-1264): a conversation turn or a plan generation. */ +interface WorkspaceSwitch { startedAt: string; replacedDevWorkspaceId?: string } + /** - * The notice that the workspace was recreated (APT-1264), on the turn or plan generation Platform marked as the switch - * from a retired workspace (`replacedDevWorkspaceId`). Information only: no retry, no reference. It is derived from - * those records, so every read and reload shows it once, at the switch, and never beside later messages; a retired - * workspace named by more than one record is announced at the first. + * The records that announce a recreated workspace: of those a surface shows, the first (by start) to name each retired + * workspace in `replacedDevWorkspaceId`. Derived from the records alone, so every read and reload of the same draft + * announces the same ones, once each, and a later record that does not carry the field never repeats it. */ -export function workspaceRecreatedNotices(draft: BuildDraft): BuildMessage[] { - const switches = [...draft.conversationTurns, ...draft.creationPlanGenerations] - .filter((record) => record.replacedDevWorkspaceId) - .sort((a, b) => Date.parse(a.startedAt) - Date.parse(b.startedAt)) +export function recreatingRecords(records: readonly T[]): Set { const announced = new Set() - const notices: BuildMessage[] = [] - for (const { replacedDevWorkspaceId: replaced, startedAt } of switches) { + const recreating = new Set() + for (const record of [...records].sort((a, b) => Date.parse(a.startedAt) - Date.parse(b.startedAt))) { + const replaced = record.replacedDevWorkspaceId if (!replaced || announced.has(replaced)) continue announced.add(replaced) - notices.push({ role: 'notice', tone: 'info', title: buildCopy.workspaceRecreated, at: startedAt }) + recreating.add(record) + } + return recreating +} + +/** The notice that the workspace was recreated, at the switch's start. Information only: no retry, no reference. */ +export function workspaceRecreatedNotice(at: string): BuildMessage { + return { role: 'notice', kind: 'workspace-recreated', tone: 'info', title: buildCopy.workspaceRecreated, at } +} + +/** + * The newest message the page decides on (re-approval, a rejected plan, the generation limit). A recreated-workspace + * notice is display only: it is skipped, also when a device clock behind the server's sorts it after a local notice. + */ +export function lastActionable(messages: readonly BuildMessage[]): BuildMessage | undefined { + for (let index = messages.length - 1; index >= 0; index--) { + const message = messages[index]! + if (message.role !== 'notice' || message.kind !== 'workspace-recreated') return message } - return notices + return undefined } export function messagesFromDraft(draft: BuildDraft, extra: BuildMessage[], options: { lastPlannedIntent?: string; preparationDone?: boolean; destination?: ShownDestination } = {}): BuildMessage[] { @@ -184,6 +201,10 @@ export function messagesFromDraft(draft: BuildDraft, extra: BuildMessage[], opti ...(!draft.createdApplicationId && !draft.createdApplicationStackId && !draft.creationExecutions.length ? { retry: 'plan' as const } : {}), at: draft.updatedAt, }) const all = [...draft.conversationTurns].sort((a, b) => Date.parse(a.startedAt) - Date.parse(b.startedAt)) + // A switch from a retired workspace is told once, at the record that made it (stable sort: a notice pushed after a + // message of the same time stays below it). + const recreating = recreatingRecords([...all, ...draft.creationPlanGenerations]) + const recreated = (record: WorkspaceSwitch) => recreating.has(record) ? [workspaceRecreatedNotice(record.startedAt)] : [] // Excel → app's analysis and screen-design turns read as one line before the conversation, // linked back to Excel → app; 「この内容で提案して」 is offered right away, since the // specification is already written. @@ -192,14 +213,20 @@ export function messagesFromDraft(draft: BuildDraft, extra: BuildMessage[], opti const text = buildCopy.questions.excelReady messages.push({ role: 'assistant', text, summary: text, at: excel[0]!.startedAt, turnId: `excel:${draft.id}`, options: [buildCopy.questions.kickoffReply], link: { kind: 'excel2app', draftId: draft.id } }) } + // The collapsed line does not hide a switch Excel → app's turns made. + for (const turn of excel) messages.push(...recreated(turn)) const turns = conversationTurns(all) for (const turn of turns) { messages.push({ role: 'user', text: turn.userMessage, at: turn.startedAt }) + // Right below the request, before its answer, also when the answer carries the same time (no finishedAt). + messages.push(...recreated(turn)) // A reply in a state this console does not know reads as that, never as an answer or a failure. if (turn.status.kind === 'unknown' || isOneOf(turn.status, 'succeeded', 'failed')) messages.push(assistantMessage(turn, draft.id)) } - // At the switch's start: after the request that caused it (a stable sort keeps it below that request), before its answer. - messages.push(...workspaceRecreatedNotices(draft)) + // A turn of a kind this console does not know is not shown, but its switch is still told. + for (const turn of all) if (!excel.includes(turn) && !turns.includes(turn)) messages.push(...recreated(turn)) + // Before the plan's proposal, which sits where the generation finished. + for (const generation of draft.creationPlanGenerations) messages.push(...recreated(generation)) const proposal = proposalMessage(draft, options.lastPlannedIntent, options.destination) if (proposal) messages.push(proposal) for (const message of extra) { diff --git a/web/src/model/build/types.ts b/web/src/model/build/types.ts index c156fd2..ab63e7e 100644 --- a/web/src/model/build/types.ts +++ b/web/src/model/build/types.ts @@ -58,8 +58,10 @@ export type BuildMessage = * `retry: 'confirm'` re-reads the draft after a write whose answer could not be read; it never resends that write. * `retry: 'recheck'`: Platform's validation rejected the plan for a cause that may lie outside it; the notice offers * 「もう一度確かめる」 (the same plan validated once more) and 「計画を作り直す」. + * `kind: 'workspace-recreated'`: display only (messages.ts#workspaceRecreatedNotice); it never stands for the + * conversation's state, so decisions read past it (messages.ts#lastActionable). */ - | { role: 'notice'; tone: 'info' | 'warning' | 'error'; title: string; detail?: string; at: string; retry?: 'turn' | 'plan' | 'prepare' | 'implement' | 'publish' | 'confirm' | 'recheck'; reference?: BuildFailure['reference'] } + | { role: 'notice'; tone: 'info' | 'warning' | 'error'; title: string; detail?: string; at: string; retry?: 'turn' | 'plan' | 'prepare' | 'implement' | 'publish' | 'confirm' | 'recheck'; reference?: BuildFailure['reference']; kind?: 'workspace-recreated' } export interface ProgressCard { kind: 'workspace' | 'turn' | 'plan' | 'prepare' | 'implement' | 'publish' title: string From 5d80e03187c3d035a17ae5ba266e19e13880677b Mon Sep 17 00:00:00 2001 From: reoring Date: Wed, 18 Nov 2026 20:10:47 +0900 Subject: [PATCH 3/5] Show the recreated-workspace notice for failed and re-planned console plans and only on the shown analysis (APT-1264 review) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - console-v1 reads the draft once a plan request names a Platform generation (failed first plans included). - A plan turn naming a generation the last draft read lacks refetches the draft once per turn update. - Excel → app analysis shows the notice only when the analysis on screen itself replaced the workspace. --- .../build/console-build-page.test.tsx | 77 +++++++++++++++++++ web/src/features/build/console-build-page.tsx | 37 ++++++--- .../excel2app/excel2app-page-wire.test.tsx | 32 ++++++++ .../features/excel2app/use-excel2app-draft.ts | 7 +- 4 files changed, 141 insertions(+), 12 deletions(-) diff --git a/web/src/features/build/console-build-page.test.tsx b/web/src/features/build/console-build-page.test.tsx index 118d30d..1f6e440 100644 --- a/web/src/features/build/console-build-page.test.tsx +++ b/web/src/features/build/console-build-page.test.tsx @@ -892,3 +892,80 @@ describe('APT-1124: what the implementation run means on the console-v1 build pa expect(buttons(specPane(page), implementationCopy.skip)).toHaveLength(atTask ? 1 : 0) }) }) + +describe('APT-1264: a plan request whose Platform generation replaced a retired workspace', () => { + async function planOutcome(outcome: 'succeeded' | 'failed') { + const toggle = new URL('/api/v1/__mock/plan-generation', 'http://mock.test') + await platformRoutes(new Request(toggle, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ outcome, error: outcome === 'failed' ? 'codex exited' : '' }) }), toggle) + } + /** A request_plan sent by the server-side setup, observed to its end; its Platform generation id. */ + async function requestPlan(sessionId: string) { + const session = await api.get(sessionId) + await api.createTurn(sessionId, { kind: 'request_plan', specRevision: session.specification.revision }, { key: mintIdempotencyKey(), version: session.version }) + await finishActive(sessionId) + const turn = (await api.allTurns(sessionId)).at(-1) + if (turn?.kind !== 'request_plan' || !turn.platformGenerationId) throw new Error('the plan request named no Platform generation') + return turn.platformGenerationId + } + /** The page's reads of the draft carry `replacedDevWorkspaceId` on the generations `marked` picks. */ + function replaced(draftId: string, marked: (generationId: string) => boolean) { + mock.rewrites.push({ + method: 'GET', path: new RegExp(`/application-drafts/${draftId}$`), once: false, + body: (wire) => rewriteDraftWire(wire, draftId, (draft) => ({ + ...draft, + creationPlanGenerations: ((draft.creationPlanGenerations ?? []) as Record[]).map((generation) => marked(generation.id as string) ? { ...generation, replacedDevWorkspaceId: 'ws-retired' } : generation), + })), + }) + } + const planTurns = (page: Page) => [...page.container.querySelectorAll('[data-testid="console-plan-turn"]')] + const recreatedIn = (scope: Element) => [...scope.querySelectorAll('[role="status"]')].filter((item) => item.querySelector('p')?.textContent === buildCopy.workspaceRecreated) + + test('a first plan that failed after the switch: opened, and opened again, the failure and the notice once each; no plan is offered', async () => { + const { draftId, sessionId } = await startSession() + await planOutcome('failed') + const generation = await requestPlan(sessionId) + expect((await api.get(sessionId)).plan).toBeUndefined() + replaced(draftId, (id) => id === generation) + const opened = async () => { + const page = await open(draftId) + await settle(30) + const turns = planTurns(page) + expect(turns).toHaveLength(1) + expect(turns[0]!.querySelectorAll('[role="alert"]')).toHaveLength(1) + expect(recreatedIn(turns[0]!)).toHaveLength(1) + expect(recreatedIn(page.container)).toHaveLength(1) + // The stages still wait for a plan: nothing is offered to build from. + expect(buttons(page.container, buildCopy.primary.prepare)).toHaveLength(0) + expect(page.container.querySelector('[data-testid="build-proposal"]')).toBeNull() + } + await opened() + await opened() + }) + + test('a re-plan with the page open: only the re-planned request says so, with no re-read of the draft forced by the test', async () => { + const { draftId, sessionId } = await startSession() + const first = await requestPlan(sessionId) + // A spec change accepted after the plan makes it stale: the page offers the re-plan. + await say(sessionId, '承認を二段階にして') + const session = await api.get(sessionId) + await api.resolveTurn(sessionId, session.activeTurnId!, { decision: 'accept_spec' }, { key: mintIdempotencyKey(), version: session.version }) + replaced(draftId, (id) => id !== first) + mock.requests.length = 0 + const page = await open(draftId) + await settle(30) + expect(recreatedIn(page.container)).toHaveLength(0) + await act(async () => { button(page.container.querySelector('[data-testid="console-plan-stale"]')!, c.plan.replan).click() }) + await settle() + expect(posts(sessionId, '/turns')).toHaveLength(1) + await finishActive(sessionId) + // The session and its turns reach the page as a poll would; the draft is read again by the page itself. + await reread(page) + await settle(30) + expect((await getDraft('commerce', draftId)).creationPlanGenerations).toHaveLength(2) + const turns = planTurns(page) + expect(turns).toHaveLength(2) + expect(recreatedIn(turns[0]!)).toHaveLength(0) + expect(recreatedIn(turns[1]!)).toHaveLength(1) + expect(recreatedIn(page.container)).toHaveLength(1) + }) +}) diff --git a/web/src/features/build/console-build-page.tsx b/web/src/features/build/console-build-page.tsx index ef171bb..11b233d 100644 --- a/web/src/features/build/console-build-page.tsx +++ b/web/src/features/build/console-build-page.tsx @@ -9,7 +9,8 @@ import { useSelector } from '@tanstack/react-store' import { Loader2, PanelRightOpen } from 'lucide-react' import { Fragment, useEffect, useMemo, useState, type ReactNode } from 'react' -import { useBuildDraft } from '../../api/queries/build' +import { useQueryClient } from '@tanstack/react-query' +import { buildKeys, useBuildDraft } from '../../api/queries/build' import { copy } from '../../copy' import { buildCopy } from '../../model/build/copy' import { failureKind, failureNext, planPhase, type FailureKind } from '../../model/build/replies' @@ -42,23 +43,39 @@ const STAGE_BY_LIFECYCLE: Record = { initializing: 'ask', sp function ConsoleSession({ view, actions, stale }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode }) { const { session } = view // From the plan onward the Platform draft carries the plan, the creation and publishing (design §9). - const needsDraft = Boolean(session.draftId && (session.plan || (session.lifecycle.kind === 'known' && session.lifecycle.value === 'created'))) - return needsDraft ? : + const stages = Boolean(session.plan || (session.lifecycle.kind === 'known' && session.lifecycle.value === 'created')) + // A plan request names its Platform generation before any plan exists, also when that generation fails: the draft is + // read to tell whether it switched from a retired workspace (APT-1264). The stages still wait for the plan. + const generationNamed = view.turns.some((turn) => turn.kind === 'request_plan' && Boolean(turn.platformGenerationId)) + return session.draftId && (stages || generationNamed) + ? + : } -function ConsoleWithDraft({ view, actions, stale, draftId }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draftId: string }) { +function ConsoleWithDraft({ view, actions, stale, draftId, stages }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draftId: string; stages: boolean }) { const { me, groups } = useShell() + const client = useQueryClient() const query = useBuildDraft(me.projectId, draftId) - // Until the draft is read the conversation stays usable; a failed first read is one notice, retried by the query. - if (!query.data) return - return + const draft = query.data + // A plan request whose Platform generation switched from a retired workspace says so (APT-1264). + const recreatedPlanTurns = useMemo(() => draft ? recreatedPlanTurnIds(view.turns, draft.creationPlanGenerations) : undefined, [view.turns, draft]) + // A finished draft is not polled. A plan request naming a generation this read does not hold yet (a re-plan with the + // page open) reads the draft again, once per observation of that turn, until the read holds it. + const unseen = draft + ? view.turns.flatMap((turn) => turn.kind === 'request_plan' && turn.platformGenerationId && !draft.creationPlanGenerations.some((generation) => generation.id === turn.platformGenerationId) ? [`${turn.platformGenerationId}@${turn.updatedAt}`] : []).join(' ') + : '' + useEffect(() => { + if (unseen) void client.invalidateQueries({ queryKey: buildKeys.draft(me.projectId, draftId), exact: true }) + }, [unseen, client, me.projectId, draftId]) + // Until the draft is read the conversation stays usable; a failed first read for the stages is one notice, retried by the query. + if (!draft) return + if (!stages) return + return } -function ConsoleDraftView({ view, actions, stale, draft, me, groups }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draft: BuildDraft; me: Me; groups: Group[] }) { +function ConsoleDraftView({ view, actions, stale, draft, me, groups, recreatedPlanTurns }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draft: BuildDraft; me: Me; groups: Group[]; recreatedPlanTurns?: ReadonlySet }) { const [openArtifact, setOpenArtifact] = useState(0) const stages = useConsoleDraftStages({ view, actions, draft, me, groups, onOpenArtifact: () => setOpenArtifact((count) => count + 1) }) - // A plan request whose Platform generation switched from a retired workspace says so (APT-1264). - const recreatedPlanTurns = useMemo(() => recreatedPlanTurnIds(view.turns, draft.creationPlanGenerations), [view.turns, draft.creationPlanGenerations]) return } diff --git a/web/src/features/excel2app/excel2app-page-wire.test.tsx b/web/src/features/excel2app/excel2app-page-wire.test.tsx index d6c74bf..4f29380 100644 --- a/web/src/features/excel2app/excel2app-page-wire.test.tsx +++ b/web/src/features/excel2app/excel2app-page-wire.test.tsx @@ -407,6 +407,38 @@ describe('APT-1264: a turn that replaced a retired workspace', () => { expect(recreated()).toHaveLength(1) }) + test('an earlier analysis that replaced the workspace and failed says nothing on the analysis shown after it; the shown one that replaced does', async () => { + const draftId = await storedDraft() + const startAnalysis = async () => ((await call('POST', `${draftPath(draftId)}/conversation-turns`, { kind: 'excel-analysis', message: '' })).resource as Json).id as string + const first = await startAnalysis() + await call('POST', '/api/v1/__mock/advance') + // Started but not advanced: the second analysis (reusing what the first read) runs, so the page opens on its step. + const second = await startAnalysis() + /** The first analysis failed after replacing a retired workspace; `marked` carries the switch (only it). */ + const reads = (marked: string) => rewrites.push({ + method: 'GET', path: new RegExp(`${draftPath(draftId)}$`), once: false, + body: (wire) => ({ + ...Object.fromEntries(Object.entries(wire).filter(([key]) => key !== 'excelAnalysis')), + conversationTurns: (wire.conversationTurns as Json[]).map((turn) => ({ + ...turn, + ...(turn.id === first ? { status: 'failed', error: 'codex exited' } : {}), + ...(turn.id === marked ? { replacedDevWorkspaceId: 'ws-retired' } : {}), + })), + }), + }) + reads(first) + await renderExcel(draftId) + await until(() => stepTitle() === text.analysis.running) + await settle(10) + expect(byTestId('excel2app-workspace-recreated')).toBeNull() + expect(recreated()).toHaveLength(0) + rewrites = [] + reads(second) + await reopen(draftId) + await until(() => Boolean(byTestId('excel2app-workspace-recreated'))) + expect(recreated()).toHaveLength(1) + }) + test('the preview chat says so once, at the design turn, also after the same draft is opened again', async () => { const draftId = await storedDraft({ analysed: true, designed: true }) replaced('ui-design') diff --git a/web/src/features/excel2app/use-excel2app-draft.ts b/web/src/features/excel2app/use-excel2app-draft.ts index 4ea42c4..61ca3da 100644 --- a/web/src/features/excel2app/use-excel2app-draft.ts +++ b/web/src/features/excel2app/use-excel2app-draft.ts @@ -731,8 +731,11 @@ export function useExcel2AppDraft(projectId: string, draftId: string | undefined offline: usingOffline, analysis: { turn: analysisTurn, - /** An analysis turn of this membership switched from a retired workspace: the step says so once (APT-1264). */ - recreated: turnsOf(turns, 'excel-analysis').some((turn) => recreating.has(turn)), + /** + * The analysis turn this step shows switched from a retired workspace: the step says so once (APT-1264). An + * earlier analysis that switched and failed says nothing about the one shown now. + */ + recreated: Boolean(analysisTurn && recreating.has(analysisTurn)), running: starting || isBuildPending(analysisTurn), problem: analysisProblem?.kind ?? (isOneOf(analysisTurn?.status, 'failed') && !draft?.excelAnalysis ? ('failed' as const) : undefined), failure: analysisProblem?.failure, From 3cc77be1999fc6e6b4a2abe5115e68a1279015ac Mon Sep 17 00:00:00 2001 From: reoring Date: Wed, 18 Nov 2026 20:29:07 +0900 Subject: [PATCH 4/5] Leave console-v1 unchanged; track its recreated-workspace notice in APT-1282 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Restore console-build-page, console-conversation and console-view (and their tests) to main. - Showing the notice there needs an earlier draft read that let a stale plan be approved while a re-plan loads (review round 3); PO lead decision (a): ship build, improve and Excel → app first. --- .../build/console-build-page.test.tsx | 77 ------------------- web/src/features/build/console-build-page.tsx | 45 ++++------- .../features/build/console-conversation.tsx | 11 +-- web/src/features/build/console-view.test.ts | 23 +----- web/src/features/build/console-view.ts | 19 ----- 5 files changed, 18 insertions(+), 157 deletions(-) diff --git a/web/src/features/build/console-build-page.test.tsx b/web/src/features/build/console-build-page.test.tsx index 1f6e440..118d30d 100644 --- a/web/src/features/build/console-build-page.test.tsx +++ b/web/src/features/build/console-build-page.test.tsx @@ -892,80 +892,3 @@ describe('APT-1124: what the implementation run means on the console-v1 build pa expect(buttons(specPane(page), implementationCopy.skip)).toHaveLength(atTask ? 1 : 0) }) }) - -describe('APT-1264: a plan request whose Platform generation replaced a retired workspace', () => { - async function planOutcome(outcome: 'succeeded' | 'failed') { - const toggle = new URL('/api/v1/__mock/plan-generation', 'http://mock.test') - await platformRoutes(new Request(toggle, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ outcome, error: outcome === 'failed' ? 'codex exited' : '' }) }), toggle) - } - /** A request_plan sent by the server-side setup, observed to its end; its Platform generation id. */ - async function requestPlan(sessionId: string) { - const session = await api.get(sessionId) - await api.createTurn(sessionId, { kind: 'request_plan', specRevision: session.specification.revision }, { key: mintIdempotencyKey(), version: session.version }) - await finishActive(sessionId) - const turn = (await api.allTurns(sessionId)).at(-1) - if (turn?.kind !== 'request_plan' || !turn.platformGenerationId) throw new Error('the plan request named no Platform generation') - return turn.platformGenerationId - } - /** The page's reads of the draft carry `replacedDevWorkspaceId` on the generations `marked` picks. */ - function replaced(draftId: string, marked: (generationId: string) => boolean) { - mock.rewrites.push({ - method: 'GET', path: new RegExp(`/application-drafts/${draftId}$`), once: false, - body: (wire) => rewriteDraftWire(wire, draftId, (draft) => ({ - ...draft, - creationPlanGenerations: ((draft.creationPlanGenerations ?? []) as Record[]).map((generation) => marked(generation.id as string) ? { ...generation, replacedDevWorkspaceId: 'ws-retired' } : generation), - })), - }) - } - const planTurns = (page: Page) => [...page.container.querySelectorAll('[data-testid="console-plan-turn"]')] - const recreatedIn = (scope: Element) => [...scope.querySelectorAll('[role="status"]')].filter((item) => item.querySelector('p')?.textContent === buildCopy.workspaceRecreated) - - test('a first plan that failed after the switch: opened, and opened again, the failure and the notice once each; no plan is offered', async () => { - const { draftId, sessionId } = await startSession() - await planOutcome('failed') - const generation = await requestPlan(sessionId) - expect((await api.get(sessionId)).plan).toBeUndefined() - replaced(draftId, (id) => id === generation) - const opened = async () => { - const page = await open(draftId) - await settle(30) - const turns = planTurns(page) - expect(turns).toHaveLength(1) - expect(turns[0]!.querySelectorAll('[role="alert"]')).toHaveLength(1) - expect(recreatedIn(turns[0]!)).toHaveLength(1) - expect(recreatedIn(page.container)).toHaveLength(1) - // The stages still wait for a plan: nothing is offered to build from. - expect(buttons(page.container, buildCopy.primary.prepare)).toHaveLength(0) - expect(page.container.querySelector('[data-testid="build-proposal"]')).toBeNull() - } - await opened() - await opened() - }) - - test('a re-plan with the page open: only the re-planned request says so, with no re-read of the draft forced by the test', async () => { - const { draftId, sessionId } = await startSession() - const first = await requestPlan(sessionId) - // A spec change accepted after the plan makes it stale: the page offers the re-plan. - await say(sessionId, '承認を二段階にして') - const session = await api.get(sessionId) - await api.resolveTurn(sessionId, session.activeTurnId!, { decision: 'accept_spec' }, { key: mintIdempotencyKey(), version: session.version }) - replaced(draftId, (id) => id !== first) - mock.requests.length = 0 - const page = await open(draftId) - await settle(30) - expect(recreatedIn(page.container)).toHaveLength(0) - await act(async () => { button(page.container.querySelector('[data-testid="console-plan-stale"]')!, c.plan.replan).click() }) - await settle() - expect(posts(sessionId, '/turns')).toHaveLength(1) - await finishActive(sessionId) - // The session and its turns reach the page as a poll would; the draft is read again by the page itself. - await reread(page) - await settle(30) - expect((await getDraft('commerce', draftId)).creationPlanGenerations).toHaveLength(2) - const turns = planTurns(page) - expect(turns).toHaveLength(2) - expect(recreatedIn(turns[0]!)).toHaveLength(0) - expect(recreatedIn(turns[1]!)).toHaveLength(1) - expect(recreatedIn(page.container)).toHaveLength(1) - }) -}) diff --git a/web/src/features/build/console-build-page.tsx b/web/src/features/build/console-build-page.tsx index 11b233d..cd33478 100644 --- a/web/src/features/build/console-build-page.tsx +++ b/web/src/features/build/console-build-page.tsx @@ -8,9 +8,8 @@ // platform-v1 page (`build-page.tsx`) shares presentational parts only. import { useSelector } from '@tanstack/react-store' import { Loader2, PanelRightOpen } from 'lucide-react' -import { Fragment, useEffect, useMemo, useState, type ReactNode } from 'react' -import { useQueryClient } from '@tanstack/react-query' -import { buildKeys, useBuildDraft } from '../../api/queries/build' +import { Fragment, useEffect, useState, type ReactNode } from 'react' +import { useBuildDraft } from '../../api/queries/build' import { copy } from '../../copy' import { buildCopy } from '../../model/build/copy' import { failureKind, failureNext, planPhase, type FailureKind } from '../../model/build/replies' @@ -24,7 +23,7 @@ import { ActionError, Button, cn, Loading, Notice, ResourceBoundary, focusHeadin import { ConsoleConversation, FailureNotice } from './console-conversation' import { useConsoleDraftStages, type ConsoleStages } from './console-draft-stages' import { ConsoleSpecPane } from './console-spec-pane' -import { recreatedPlanTurnIds, type ConsoleBuildView } from './console-view' +import type { ConsoleBuildView } from './console-view' import { text } from './copy' import { SessionHeader } from './session-header' import { UnconfirmedNotice } from './unconfirmed-notice' @@ -43,43 +42,25 @@ const STAGE_BY_LIFECYCLE: Record = { initializing: 'ask', sp function ConsoleSession({ view, actions, stale }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode }) { const { session } = view // From the plan onward the Platform draft carries the plan, the creation and publishing (design §9). - const stages = Boolean(session.plan || (session.lifecycle.kind === 'known' && session.lifecycle.value === 'created')) - // A plan request names its Platform generation before any plan exists, also when that generation fails: the draft is - // read to tell whether it switched from a retired workspace (APT-1264). The stages still wait for the plan. - const generationNamed = view.turns.some((turn) => turn.kind === 'request_plan' && Boolean(turn.platformGenerationId)) - return session.draftId && (stages || generationNamed) - ? - : + const needsDraft = Boolean(session.draftId && (session.plan || (session.lifecycle.kind === 'known' && session.lifecycle.value === 'created'))) + return needsDraft ? : } -function ConsoleWithDraft({ view, actions, stale, draftId, stages }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draftId: string; stages: boolean }) { +function ConsoleWithDraft({ view, actions, stale, draftId }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draftId: string }) { const { me, groups } = useShell() - const client = useQueryClient() const query = useBuildDraft(me.projectId, draftId) - const draft = query.data - // A plan request whose Platform generation switched from a retired workspace says so (APT-1264). - const recreatedPlanTurns = useMemo(() => draft ? recreatedPlanTurnIds(view.turns, draft.creationPlanGenerations) : undefined, [view.turns, draft]) - // A finished draft is not polled. A plan request naming a generation this read does not hold yet (a re-plan with the - // page open) reads the draft again, once per observation of that turn, until the read holds it. - const unseen = draft - ? view.turns.flatMap((turn) => turn.kind === 'request_plan' && turn.platformGenerationId && !draft.creationPlanGenerations.some((generation) => generation.id === turn.platformGenerationId) ? [`${turn.platformGenerationId}@${turn.updatedAt}`] : []).join(' ') - : '' - useEffect(() => { - if (unseen) void client.invalidateQueries({ queryKey: buildKeys.draft(me.projectId, draftId), exact: true }) - }, [unseen, client, me.projectId, draftId]) - // Until the draft is read the conversation stays usable; a failed first read for the stages is one notice, retried by the query. - if (!draft) return - if (!stages) return - return + // Until the draft is read the conversation stays usable; a failed first read is one notice, retried by the query. + if (!query.data) return + return } -function ConsoleDraftView({ view, actions, stale, draft, me, groups, recreatedPlanTurns }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draft: BuildDraft; me: Me; groups: Group[]; recreatedPlanTurns?: ReadonlySet }) { +function ConsoleDraftView({ view, actions, stale, draft, me, groups }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; draft: BuildDraft; me: Me; groups: Group[] }) { const [openArtifact, setOpenArtifact] = useState(0) const stages = useConsoleDraftStages({ view, actions, draft, me, groups, onOpenArtifact: () => setOpenArtifact((count) => count + 1) }) - return + return } -function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact = 0, recreatedPlanTurns }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; stages?: ConsoleStages; draftError?: unknown; openArtifact?: number; recreatedPlanTurns?: ReadonlySet }) { +function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact = 0 }: { view: ConsoleBuildView; actions: ConsoleBuildActions; stale: ReactNode; stages?: ConsoleStages; draftError?: unknown; openArtifact?: number }) { const { session } = view const name = parseSpec(session.specification.markdown).spec.name || text.session.newApp useDocumentTitle(text.page.title(name)) @@ -122,7 +103,7 @@ function ConsoleLayout({ view, actions, stale, stages, draftError, openArtifact
- +
{stages?.artifact ?? } diff --git a/web/src/features/build/console-conversation.tsx b/web/src/features/build/console-conversation.tsx index e033881..bdecd55 100644 --- a/web/src/features/build/console-conversation.tsx +++ b/web/src/features/build/console-conversation.tsx @@ -15,14 +15,14 @@ import { locale } from '../../shell/language' import { Button, cn, Notice } from '../../ui' import { Composer } from './composer' import type { ConsoleBuildView, ConsoleProgress } from './console-view' -import { AiTurn, UserMessage, WorkspaceRecreatedNotice } from './conversation-pane' +import { AiTurn, UserMessage } from './conversation-pane' import { text } from './copy' import type { ConsoleBuildActions } from './use-console-build-session' /** Pixels from the bottom that still count as "reading the newest message". */ const STICK = 96 -export function ConsoleConversation({ view, actions, restore, end, closedReason, recreatedPlanTurns }: { +export function ConsoleConversation({ view, actions, restore, end, closedReason }: { view: ConsoleBuildView actions: ConsoleBuildActions restore?: { text: string; nonce: number } @@ -30,8 +30,6 @@ export function ConsoleConversation({ view, actions, restore, end, closedReason, end?: ReactNode /** Why the composer is closed for good (building started). */ closedReason?: string - /** Plan requests whose Platform generation switched from a retired workspace (console-view.ts#recreatedPlanTurnIds). */ - recreatedPlanTurns?: ReadonlySet }) { const scroller = useRef(null) const content = useRef(null) @@ -68,7 +66,7 @@ export function ConsoleConversation({ view, actions, restore, end, closedReason,
{view.turns.map((turn) => turn.kind === 'conversation' ? { following.current = true; actions.send(text.console.candidateMessage(label), 'change') }} /> - : )} + : )} {end}
@@ -159,12 +157,11 @@ function ReplyBody({ reply, turn, view, actions, actionable, confirming, onChoos
} -function PlanTurnItem({ turn, view, recreated }: { turn: PlanTurn; view: ConsoleBuildView; recreated: boolean }) { +function PlanTurnItem({ turn, view }: { turn: PlanTurn; view: ConsoleBuildView }) { const phase = planPhase(turn) const active = view.activeTurn?.id === turn.id return
- {recreated ? : null} {phase.kind === 'failed' ? : {phase.kind === 'working' ? active ? : null : phase.kind === 'handed_off' ? <> diff --git a/web/src/features/build/console-view.test.ts b/web/src/features/build/console-view.test.ts index 22f4bab..974f0ae 100644 --- a/web/src/features/build/console-view.test.ts +++ b/web/src/features/build/console-view.test.ts @@ -3,10 +3,9 @@ import { describe, expect, test } from 'bun:test' import { readFileSync } from 'node:fs' import { buildSessionReader, buildTurnReader } from '../../api/contracts/console/build-sessions' -import { generationOf } from '../../api/testing/build-domain' import { buildCopy } from '../../model/build/copy' import type { BuildSession, BuildTurn } from '../../model/contracts/console' -import { deriveConsoleBuildView, recreatedPlanTurnIds, SLOW_OBSERVATION_MS, type ConsoleViewInput } from './console-view' +import { deriveConsoleBuildView, SLOW_OBSERVATION_MS, type ConsoleViewInput } from './console-view' type Fixture = { name: string; raw: string } const fixtures = JSON.parse(readFileSync(new URL('../../../../cmd/server/internal/api/testdata/build-conversation.json', import.meta.url), 'utf8')) as Fixture[] @@ -75,23 +74,3 @@ describe('what may be sent', () => { expect(deriveConsoleBuildView(input({ intent: { ...intent, status: 'pending' }, sending: true })).write).toEqual({ family: 'publish', status: 'sending' }) }) }) - -describe('a plan request whose Platform generation replaced a retired workspace (APT-1264)', () => { - const generation = (id: string, minute: number, replaced?: string) => generationOf({ id, status: 'succeeded', startedAt: `2026-11-12T00:0${minute}:00Z`, devWorkspaceId: 'ws-new', ...(replaced ? { replacedDevWorkspaceId: replaced } : {}) }) - const plan = (id: string, generationId?: string) => turn('plan-turn', { id, platformGenerationId: generationId }) - test('matches the request_plan turn by its platformGenerationId, never a conversation turn', () => { - const turns = [turn('turn-explicit-keep'), plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012', 'gen-2')] - expect([...recreatedPlanTurnIds(turns, [generation('gen-1', 1), generation('gen-2', 2, 'ws-old')])]).toEqual(['89c00000-0000-4000-8000-000000000012']) - }) - test('nothing without the field, without a generation id, or for a generation this draft does not hold', () => { - const turns = [plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012')] - expect([...recreatedPlanTurnIds(turns, [generation('gen-1', 1)])]).toEqual([]) - expect([...recreatedPlanTurnIds(turns, [generation('gen-9', 1, 'ws-old')])]).toEqual([]) - }) - test('one per retired workspace, at the first generation that named it; the same on every read', () => { - const turns = [plan('89c00000-0000-4000-8000-000000000011', 'gen-1'), plan('89c00000-0000-4000-8000-000000000012', 'gen-2'), plan('89c00000-0000-4000-8000-000000000013', 'gen-3')] - const generations = [generation('gen-3', 3, 'ws-2'), generation('gen-2', 2, 'ws-old'), generation('gen-1', 1, 'ws-old')] - expect([...recreatedPlanTurnIds(turns, generations)]).toEqual(['89c00000-0000-4000-8000-000000000011', '89c00000-0000-4000-8000-000000000013']) - expect(recreatedPlanTurnIds(turns, generations)).toEqual(recreatedPlanTurnIds(turns, generations)) - }) -}) diff --git a/web/src/features/build/console-view.ts b/web/src/features/build/console-view.ts index 9cd5e4d..58b562e 100644 --- a/web/src/features/build/console-view.ts +++ b/web/src/features/build/console-view.ts @@ -6,8 +6,6 @@ // stage and observation time (design §13), never a fabricated activity log. import type { OpenValue } from '../../api/boundary' import { isObserving, mergeTurn } from '../../api/queries/build-sessions' -import { recreatingRecords } from '../../model/build/messages' -import type { BuildGeneration } from '../../model/contracts/build' import type { BuildPublishResult, BuildSession, BuildTurn } from '../../model/contracts/console' import type { ConsoleWriteFamily, ConsoleWriteIntent } from './console-session-state' @@ -146,20 +144,3 @@ export function deriveConsoleBuildView(input: ConsoleViewInput): ConsoleBuildVie ...(publish ? { publish } : {}), } } - -/** - * The plan requests whose Platform plan generation switched from a retired workspace (APT-1264), by turn id. Matched - * on the typed `platformGenerationId` only: a conversation turn is never guessed at. One per retired workspace, at the - * first generation that named it; derived from the draft, so every read shows the same ones. - */ -export function recreatedPlanTurnIds(turns: readonly BuildTurn[], generations: readonly BuildGeneration[]): Set { - const recreating = new Set([...recreatingRecords(generations)].map((generation) => generation.id)) - const announced = new Set() - const ids = new Set() - for (const turn of turns) { - if (turn.kind !== 'request_plan' || !turn.platformGenerationId || !recreating.has(turn.platformGenerationId) || announced.has(turn.platformGenerationId)) continue - announced.add(turn.platformGenerationId) - ids.add(turn.id) - } - return ids -} From c2923c875c1e830ca133d97f4dcd03c5a1d2e109 Mon Sep 17 00:00:00 2001 From: reoring Date: Wed, 18 Nov 2026 20:31:11 +0900 Subject: [PATCH 5/5] Tidy the recreated-workspace notice after narrowing (APT-1264 review nits) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - The shared notice's comment names only improve and Excel → app; the build notice factory is module-private. --- web/src/features/build/conversation-pane.tsx | 4 ++-- web/src/model/build/messages.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/src/features/build/conversation-pane.tsx b/web/src/features/build/conversation-pane.tsx index 5e74fe9..a8c2053 100644 --- a/web/src/features/build/conversation-pane.tsx +++ b/web/src/features/build/conversation-pane.tsx @@ -149,8 +149,8 @@ export function UserMessage({ text }: { text: string }) { } /** - * The workspace was recreated (APT-1264), where a conversation keeps its own records (improve, Excel → app, console-v1 - * plan requests): information only, the same as the build conversation's derived notice (messages.ts#workspaceRecreatedNotice). + * The workspace was recreated (APT-1264), where a conversation keeps its own records (improve, Excel → app): + * information only, the same as the build conversation's derived notice (messages.ts#workspaceRecreatedNotice). */ export function WorkspaceRecreatedNotice({ className }: { className?: string }) { return diff --git a/web/src/model/build/messages.ts b/web/src/model/build/messages.ts index 38d426d..10da955 100644 --- a/web/src/model/build/messages.ts +++ b/web/src/model/build/messages.ts @@ -178,7 +178,7 @@ export function recreatingRecords(records: readonly T } /** The notice that the workspace was recreated, at the switch's start. Information only: no retry, no reference. */ -export function workspaceRecreatedNotice(at: string): BuildMessage { +function workspaceRecreatedNotice(at: string): BuildMessage { return { role: 'notice', kind: 'workspace-recreated', tone: 'info', title: buildCopy.workspaceRecreated, at } }