diff --git a/packages/app/__tests__/MemoryPage.test.tsx b/packages/app/__tests__/MemoryPage.test.tsx index 4330c15..2daa67a 100644 --- a/packages/app/__tests__/MemoryPage.test.tsx +++ b/packages/app/__tests__/MemoryPage.test.tsx @@ -20,6 +20,7 @@ const summary: HarnessSummary = { archive: [], conventions: null, }, + workflow: null, } interface Bridge { diff --git a/packages/app/__tests__/OverviewStats.test.tsx b/packages/app/__tests__/OverviewStats.test.tsx index 0881bef..93e9700 100644 --- a/packages/app/__tests__/OverviewStats.test.tsx +++ b/packages/app/__tests__/OverviewStats.test.tsx @@ -11,6 +11,7 @@ const summary: HarnessSummary = { installed: true, install: null, constitution: null, workflowDoc: null, checkpoints: [], todolist: null, memory: { scratchpad: null, observations: [], snapshots: [], archive: [], conventions: null }, + workflow: null, } const stats: ProjectStats = { diff --git a/packages/app/src/main/HarnessReader.ts b/packages/app/src/main/HarnessReader.ts index 30e4697..24c1264 100644 --- a/packages/app/src/main/HarnessReader.ts +++ b/packages/app/src/main/HarnessReader.ts @@ -6,6 +6,7 @@ import { extractUsageDelta } from './api/TokenUsageAccumulator' import type { HarnessSummary, HarnessInstall, HarnessCheckpoint, Todolist, TranscriptMessage, SessionListItem, MagiMemory, MagiMemoryEntry, ProjectStats, + WorkflowTemplateSelection, WorkflowTemplateFile, ActiveWorkflowTemplate, WorkflowStage, } from '../shared/harness' // ───────────────────────────────────────────────────────────────────────────── @@ -57,6 +58,75 @@ function readCheckpoints(workspace: string): HarnessCheckpoint[] { return out } +// ── Workflow template resolution (data-driven Workflow view) ────────────────── +// +// CCC-MAGI MAY write `.harness/state/workflow-template.json` (the active +// selection) and canonical templates under `.harness/workflows/templates/.json`. +// We resolve the effective template via this fallback chain — never throwing: +// +// 1. selection present + customized=true → use selection.stages inline +// 2. selection present + customized=false → load templates/.json +// 3. selection absent → default template_id 'full-stack' +// 4. template FILE missing / unknown id → load templates/full-stack.json +// 5. full-stack.json also missing → empty stages (renderer falls back) +// +// The returned object always has a usable shape; an empty `stages` array signals +// the renderer to keep its built-in hardcoded fallback (old behavior preserved). + +const DEFAULT_TEMPLATE_ID = 'full-stack' + +// Keep only stage entries that are objects; pass fields through defensively. We +// intentionally don't validate field types here — the shared types are all +// optional and the renderer tolerates partial stages. +function sanitizeStages(stages: unknown): WorkflowStage[] { + if (!Array.isArray(stages)) return [] + return stages.filter((s): s is WorkflowStage => !!s && typeof s === 'object') +} + +function loadTemplateFile(workspace: string, id: string): WorkflowTemplateFile | null { + // `id` originates from the (committed) selection file; guard the path anyway — + // a hand-edited id with slashes/.. must not escape the templates dir. + if (!id || /[\\/]/.test(id) || id.includes('..')) return null + return readJson( + workspace, join('.harness', 'workflows', 'templates', `${id}.json`)) +} + +// Resolve the active workflow template for the workspace. Returns null only when +// nothing is resolvable AND there's no default file — but always prefers an +// object with an (possibly empty) stages array so the renderer never crashes. +export function resolveWorkflowTemplate(workspace: string): ActiveWorkflowTemplate { + const sel = readJson( + workspace, join('.harness', 'state', 'workflow-template.json')) + + // Case 1: customized selection carries its own inline ordered stages. + if (sel && sel.customized === true && Array.isArray(sel.stages)) { + return { + template_id: typeof sel.template_id === 'string' ? sel.template_id : DEFAULT_TEMPLATE_ID, + title: typeof sel.template_id === 'string' ? sel.template_id : DEFAULT_TEMPLATE_ID, + summary: undefined, + customized: true, + customizations: Array.isArray(sel.customizations) ? sel.customizations : [], + stages: sanitizeStages(sel.stages), + } + } + + // Cases 2-4: resolve a canonical template file by id, falling back to full-stack. + const wantedId = sel && typeof sel.template_id === 'string' && sel.template_id + ? sel.template_id + : DEFAULT_TEMPLATE_ID + const file = loadTemplateFile(workspace, wantedId) + ?? (wantedId !== DEFAULT_TEMPLATE_ID ? loadTemplateFile(workspace, DEFAULT_TEMPLATE_ID) : null) + + return { + template_id: file?.id ?? wantedId, + title: file?.title ?? wantedId, + summary: typeof file?.summary === 'string' ? file.summary : undefined, + customized: sel?.customized === true, + customizations: sel && Array.isArray(sel.customizations) ? sel.customizations : [], + stages: sanitizeStages(file?.stages), + } +} + // ── Transcript (AI conversation history, Page 5) ────────────────────────────── // // Claude Code persists each session's JSONL transcript under @@ -362,6 +432,7 @@ export function harnessSummary(workspace: string): HarnessSummary { checkpoints: [], todolist: null, memory: EMPTY_MEMORY, + workflow: null, } } return { @@ -372,5 +443,6 @@ export function harnessSummary(workspace: string): HarnessSummary { checkpoints: readCheckpoints(workspace), todolist: readJson(workspace, join('.harness', 'state', 'todolist.json')), memory: readMagiMemory(workspace), + workflow: resolveWorkflowTemplate(workspace), } } diff --git a/packages/app/src/renderer/src/dashboard/WorkflowPage.tsx b/packages/app/src/renderer/src/dashboard/WorkflowPage.tsx index b300ee7..c0f9ac8 100644 --- a/packages/app/src/renderer/src/dashboard/WorkflowPage.tsx +++ b/packages/app/src/renderer/src/dashboard/WorkflowPage.tsx @@ -1,11 +1,14 @@ -import type { HarnessSummary, HarnessCheckpoint } from '../../../shared/harness' +import type { HarnessSummary, HarnessCheckpoint, WorkflowStage } from '../../../shared/harness' import type { LangCode } from '../i18n' import type { DashStrings } from './strings' import { fmt } from './strings' -import { TOTAL_STAGES } from './util' -// Page 3 — Workflow. (A) static教学: the 9 stages + 3 lanes. (B) live: a -// per-active-feature 9-stage progress bar from each checkpoint. +// Page 3 — Workflow. (A) static教学: the active template's stages + 3 lanes. +// (B) live: a per-active-feature progress bar from each checkpoint. +// +// The stage list is DATA-DRIVEN by the project's active workflow template +// (summary.workflow, written by CCC-MAGI). When no template is present we fall +// back to the legacy hardcoded 9 full-stack stage names (backward compatible). const STAGE_NAMES: Record = { en: ['Draft spec', 'Finalize', 'Schema', 'Plan', 'Implement', 'Tests', 'Smoke test', 'Commit', 'Watch'], @@ -18,6 +21,23 @@ const LANES: Record> = { ko: [['Full', 'new feature'], ['Stability-fix', 'bug fix'], ['Trivial', '< 20 LOC']], } +type StageRow = { n: number; title: string; slot?: string | null } + +// Resolve the stage list to render: the active template's stages, or the legacy +// 9 full-stack names if no template is present. +function activeStages(summary: HarnessSummary, lang: LangCode): StageRow[] { + const wf = summary.workflow + if (wf && Array.isArray(wf.stages) && wf.stages.length > 0) { + return wf.stages.map((st: WorkflowStage, i) => ({ + n: typeof st.n === 'number' ? st.n : i + 1, + title: st.title ?? st.id ?? `Stage ${i + 1}`, + slot: st.slot ?? null, + })) + } + const names = STAGE_NAMES[lang] ?? STAGE_NAMES.en + return names.map((nm, i) => ({ n: i + 1, title: nm, slot: null })) +} + type StageState = 'done' | 'current' | 'skipped' | 'todo' function stageState(cp: HarnessCheckpoint, n: number): StageState { @@ -37,8 +57,7 @@ function verdictClass(v?: string): string { } } -function FeatureProgress({ cp, s, lang }: { cp: HarnessCheckpoint; s: DashStrings; lang: LangCode }): JSX.Element { - const names = STAGE_NAMES[lang] ?? STAGE_NAMES.en +function FeatureProgress({ cp, stages, s }: { cp: HarnessCheckpoint; stages: StageRow[]; s: DashStrings }): JSX.Element { const sip = cp.stage_in_progress return (
@@ -48,10 +67,10 @@ function FeatureProgress({ cp, s, lang }: { cp: HarnessCheckpoint; s: DashString {fmt(s.stageOf, { n: cp.current_stage ?? 1 })}
- {Array.from({ length: TOTAL_STAGES }, (_, i) => i + 1).map(n => ( -
- {n} - {names[n - 1]} + {stages.map(st => ( +
+ {st.n} + {st.title}
))}
@@ -83,17 +102,23 @@ function FeatureProgress({ cp, s, lang }: { cp: HarnessCheckpoint; s: DashString } export function WorkflowPage({ summary, s, lang }: { summary: HarnessSummary; s: DashStrings; lang: LangCode }): JSX.Element { - const names = STAGE_NAMES[lang] ?? STAGE_NAMES.en const lanes = LANES[lang] ?? LANES.en const cps = summary.checkpoints ?? [] + const wf = summary.workflow + const stages = activeStages(summary, lang) + const heading = wf?.title ?? s.theNineStages return (
-

{s.theNineStages}

+

+ {heading} + {wf?.customized ? {s.tplCustomized} : null} +

- {names.map((nm, i) => ( -
- {i + 1}{nm} + {stages.map(st => ( +
+ {st.n}{st.title} + {st.slot ? · {st.slot} : null}
))}
@@ -115,7 +140,7 @@ export function WorkflowPage({ summary, s, lang }: { summary: HarnessSummary; s:

{s.liveProgress}

{cps.length === 0 ?
{s.noCheckpoints}
- : cps.map((cp, i) => )} + : cps.map((cp, i) => )}
) diff --git a/packages/app/src/renderer/src/dashboard/strings.ts b/packages/app/src/renderer/src/dashboard/strings.ts index 51f2877..5b6093c 100644 --- a/packages/app/src/renderer/src/dashboard/strings.ts +++ b/packages/app/src/renderer/src/dashboard/strings.ts @@ -36,6 +36,7 @@ export interface DashStrings { noConstitution: string // workflow theNineStages: string + tplCustomized: string theThreeLanes: string liveProgress: string lane: string @@ -140,6 +141,7 @@ const EN: DashStrings = { noInfo: 'No project info found.', noConstitution: 'No constitution.md found.', theNineStages: 'The 9 workflow stages', + tplCustomized: 'customized', theThreeLanes: 'Three lanes', liveProgress: 'Active features', lane: 'Lane', @@ -238,6 +240,7 @@ const ZH: DashStrings = { noInfo: '没有找到项目信息。', noConstitution: '没有找到 constitution.md。', theNineStages: '工作流 9 个阶段', + tplCustomized: '已定制', theThreeLanes: '三条通道', liveProgress: '进行中的功能', lane: '通道', diff --git a/packages/app/src/shared/harness.ts b/packages/app/src/shared/harness.ts index a4b9058..8aaa777 100644 --- a/packages/app/src/shared/harness.ts +++ b/packages/app/src/shared/harness.ts @@ -73,6 +73,64 @@ export interface HarnessCheckpoint { [key: string]: unknown } +// ── Workflow templates (data-driven workflow view) ─────────────────────────── +// CCC-MAGI MAY write a `.harness/state/workflow-template.json` selecting the +// active workflow template, plus canonical templates under +// `.harness/workflows/templates/.json`. When absent the project is on the +// `full-stack` template by default (backward compatible). Every field is +// optional / defensively typed — older installs won't have any of this. + +// A stage slot tags a stage's special role in the pipeline (verify / human / +// watch gates). `null`/absent = an ordinary stage. +export type WorkflowSlot = 'VERIFY-GATE' | 'HUMAN-REVIEW' | 'WATCH' | null + +// One ordered stage in a template's `stages[]`. `n` is the stage number that +// per-feature checkpoints (`current_stage`, `stages_completed`, …) index into. +export interface WorkflowStage { + n?: number + id?: string + title?: string + skill?: string | null // null = guidance / manual stage (no skill) + slot?: WorkflowSlot + lanes?: string[] | null // null = applies to all lanes + optional_if?: string | null + desc?: string + [key: string]: unknown +} + +// `.harness/state/workflow-template.json` — the active selection (committed). +export interface WorkflowTemplateSelection { + schema_version?: number | string + template_id?: string + recommended_id?: string + chosen_at?: string + customized?: boolean + customizations?: unknown[] + stages?: WorkflowStage[] | null // non-null only when customized=true + [key: string]: unknown +} + +// `.harness/workflows/templates/.json` — a canonical template definition. +export interface WorkflowTemplateFile { + schema_version?: number | string + id?: string + title?: string + summary?: string + stages?: WorkflowStage[] + [key: string]: unknown +} + +// The resolved active template surfaced to the renderer — the selection's +// metadata merged with whichever `stages[]` won the fallback chain. +export interface ActiveWorkflowTemplate { + template_id: string + title: string + summary?: string + customized: boolean + customizations: unknown[] + stages: WorkflowStage[] +} + // `.harness/state/todolist.json` export type TodoItemStatus = 'todo' | 'doing' | 'done' export type TodoFnStatus = 'planned' | 'in-progress' | 'done' | 'abandoned' @@ -187,4 +245,5 @@ export interface HarnessSummary { checkpoints: HarnessCheckpoint[] todolist: Todolist | null memory: MagiMemory + workflow: ActiveWorkflowTemplate | null // resolved active workflow template (null = not installed) }