Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/app/__tests__/MemoryPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const summary: HarnessSummary = {
archive: [],
conventions: null,
},
workflow: null,
}

interface Bridge {
Expand Down
1 change: 1 addition & 0 deletions packages/app/__tests__/OverviewStats.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
72 changes: 72 additions & 0 deletions packages/app/src/main/HarnessReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

// ─────────────────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -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/<id>.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/<template_id>.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<WorkflowTemplateFile>(
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<WorkflowTemplateSelection>(
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
Expand Down Expand Up @@ -362,6 +432,7 @@ export function harnessSummary(workspace: string): HarnessSummary {
checkpoints: [],
todolist: null,
memory: EMPTY_MEMORY,
workflow: null,
}
}
return {
Expand All @@ -372,5 +443,6 @@ export function harnessSummary(workspace: string): HarnessSummary {
checkpoints: readCheckpoints(workspace),
todolist: readJson<Todolist>(workspace, join('.harness', 'state', 'todolist.json')),
memory: readMagiMemory(workspace),
workflow: resolveWorkflowTemplate(workspace),
}
}
57 changes: 41 additions & 16 deletions packages/app/src/renderer/src/dashboard/WorkflowPage.tsx
Original file line number Diff line number Diff line change
@@ -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<LangCode, string[]> = {
en: ['Draft spec', 'Finalize', 'Schema', 'Plan', 'Implement', 'Tests', 'Smoke test', 'Commit', 'Watch'],
Expand All @@ -18,6 +21,23 @@ const LANES: Record<LangCode, Array<[string, string]>> = {
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 {
Expand All @@ -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 (
<div className="dash-wf-feature">
Expand All @@ -48,10 +67,10 @@ function FeatureProgress({ cp, s, lang }: { cp: HarnessCheckpoint; s: DashString
<span className="dash-chip is-stage">{fmt(s.stageOf, { n: cp.current_stage ?? 1 })}</span>
</div>
<div className="dash-wf-bar">
{Array.from({ length: TOTAL_STAGES }, (_, i) => i + 1).map(n => (
<div key={n} className={`dash-wf-step is-${stageState(cp, n)}`} title={names[n - 1]}>
<span className="dash-wf-step-n">{n}</span>
<span className="dash-wf-step-label">{names[n - 1]}</span>
{stages.map(st => (
<div key={st.n} className={`dash-wf-step is-${stageState(cp, st.n)}`} title={st.slot ? `${st.title} · ${st.slot}` : st.title}>
<span className="dash-wf-step-n">{st.n}</span>
<span className="dash-wf-step-label">{st.title}</span>
</div>
))}
</div>
Expand Down Expand Up @@ -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 (
<div className="dash-page">
<section className="dash-section">
<h3 className="dash-h3">{s.theNineStages}</h3>
<h3 className="dash-h3">
{heading}
{wf?.customized ? <span className="dash-chip is-stage">{s.tplCustomized}</span> : null}
</h3>
<div className="dash-stage-flow">
{names.map((nm, i) => (
<div key={i} className="dash-stage-pill">
<span className="dash-stage-pill-n">{i + 1}</span>{nm}
{stages.map(st => (
<div key={st.n} className="dash-stage-pill" title={st.slot ?? undefined}>
<span className="dash-stage-pill-n">{st.n}</span>{st.title}
{st.slot ? <span className="dash-stage-slot"> · {st.slot}</span> : null}
</div>
))}
</div>
Expand All @@ -115,7 +140,7 @@ export function WorkflowPage({ summary, s, lang }: { summary: HarnessSummary; s:
<h3 className="dash-h3">{s.liveProgress}</h3>
{cps.length === 0
? <div className="dash-muted">{s.noCheckpoints}</div>
: cps.map((cp, i) => <FeatureProgress key={cp.feature ?? i} cp={cp} s={s} lang={lang} />)}
: cps.map((cp, i) => <FeatureProgress key={cp.feature ?? i} cp={cp} stages={stages} s={s} />)}
</section>
</div>
)
Expand Down
3 changes: 3 additions & 0 deletions packages/app/src/renderer/src/dashboard/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface DashStrings {
noConstitution: string
// workflow
theNineStages: string
tplCustomized: string
theThreeLanes: string
liveProgress: string
lane: string
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -238,6 +240,7 @@ const ZH: DashStrings = {
noInfo: '没有找到项目信息。',
noConstitution: '没有找到 constitution.md。',
theNineStages: '工作流 9 个阶段',
tplCustomized: '已定制',
theThreeLanes: '三条通道',
liveProgress: '进行中的功能',
lane: '通道',
Expand Down
59 changes: 59 additions & 0 deletions packages/app/src/shared/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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/<id>.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/<id>.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'
Expand Down Expand Up @@ -187,4 +245,5 @@ export interface HarnessSummary {
checkpoints: HarnessCheckpoint[]
todolist: Todolist | null
memory: MagiMemory
workflow: ActiveWorkflowTemplate | null // resolved active workflow template (null = not installed)
}
Loading