@yiyi_zhang/laoshi 0.1.1 → 0.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/adapters/cli/adapter.ts +53 -0
  3. package/adapters/cli/cli-runtime.ts +402 -0
  4. package/adapters/cli/drivers.ts +146 -0
  5. package/adapters/cli/install.mjs +28 -0
  6. package/adapters/cli/skill/setup.md +8 -0
  7. package/adapters/dsh/plugin/index.mjs +1 -1
  8. package/adapters/dsh/plugin/package.json +1 -1
  9. package/adapters/mogao/adapter.ts +47 -0
  10. package/adapters/mogao/install.mjs +31 -0
  11. package/adapters/mogao/make-expert.mjs +64 -0
  12. package/adapters/mogao/mogao-runtime.ts +506 -0
  13. package/adapters/mogao/skill/setup.md +21 -0
  14. package/adapters/paseo/adapter.ts +1 -1
  15. package/adapters/paseo/install.mjs +17 -5
  16. package/adapters/paseo/migrate.ts +267 -0
  17. package/adapters/paseo/plugin/OVERVIEW.md +9 -0
  18. package/adapters/paseo/plugin/client/config.tsx +216 -0
  19. package/adapters/paseo/plugin/client/data.ts +85 -0
  20. package/adapters/paseo/plugin/client/detail.tsx +342 -0
  21. package/adapters/paseo/plugin/client/format.ts +173 -0
  22. package/adapters/paseo/plugin/client/inbox.tsx +190 -0
  23. package/adapters/paseo/plugin/client/live.ts +161 -0
  24. package/adapters/paseo/plugin/client/markdown.tsx +220 -0
  25. package/adapters/paseo/plugin/client/models.tsx +117 -0
  26. package/adapters/paseo/plugin/client/nav.ts +22 -0
  27. package/adapters/paseo/plugin/client/overview.tsx +103 -0
  28. package/adapters/paseo/plugin/client/panel.tsx +56 -0
  29. package/adapters/paseo/plugin/client/review.tsx +80 -0
  30. package/adapters/paseo/plugin/client/row.tsx +63 -0
  31. package/adapters/paseo/plugin/client/settings.tsx +92 -0
  32. package/adapters/paseo/plugin/client/sidebar.tsx +27 -0
  33. package/adapters/paseo/plugin/client/stats.tsx +138 -0
  34. package/adapters/paseo/plugin/client/ui.tsx +278 -0
  35. package/adapters/paseo/plugin/client/web.ts +34 -0
  36. package/adapters/paseo/plugin/index.client.tsx +66 -0
  37. package/adapters/paseo/plugin/index.server.ts +61 -0
  38. package/adapters/paseo/plugin/package.json +22 -0
  39. package/adapters/paseo/plugin/paseo-plugin.json +6 -0
  40. package/adapters/paseo/plugin/server/handlers.ts +69 -0
  41. package/adapters/paseo/plugin/server/req.ts +105 -0
  42. package/adapters/paseo/plugin/shared/contracts.ts +286 -0
  43. package/adapters/paseo/plugin/shared/rk-colors.ts +35 -0
  44. package/adapters/paseo/plugin/tsconfig.json +16 -0
  45. package/adapters/paseo/plugin-cmd.mjs +233 -0
  46. package/bin/install.mjs +12 -5
  47. package/bin/req.mjs +18 -2
  48. package/contracts/README.md +1 -1
  49. package/contracts/agent-runtime.md +5 -2
  50. package/contracts/cli-json.md +4 -3
  51. package/contracts/notifier-event.md +2 -2
  52. package/contracts/state.md +2 -0
  53. package/contracts/usage-record.md +3 -3
  54. package/docs/design/adapter-guide.md +2 -1
  55. package/docs/design/cli-adapter.md +75 -0
  56. package/docs/design/compat-migration.md +2 -0
  57. package/docs/design/mogao-expert.md +103 -0
  58. package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +132 -0
  59. package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +32 -3
  60. package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +4 -2
  61. package/docs/guide//351/241/271/347/233/256/345/256/232/345/210/266/344/270/216/350/277/220/350/241/214/350/247/204/345/210/231.md +1 -1
  62. package/engine/src/api.ts +9 -5
  63. package/engine/src/code-review.ts +2 -2
  64. package/engine/src/control.ts +6 -6
  65. package/engine/src/danger-guard.ts +7 -0
  66. package/engine/src/doctor.ts +4 -3
  67. package/engine/src/features.ts +2 -2
  68. package/engine/src/identity.ts +16 -1
  69. package/engine/src/integration-cmd.ts +2 -2
  70. package/engine/src/launch.ts +44 -6
  71. package/engine/src/locations.ts +15 -1
  72. package/engine/src/main.ts +6 -1
  73. package/engine/src/messages.ts +1 -1
  74. package/engine/src/permission-cmd.ts +56 -0
  75. package/engine/src/platform.ts +7 -0
  76. package/engine/src/preflight.ts +2 -2
  77. package/engine/src/runtime-loader.ts +16 -0
  78. package/engine/src/runtime.ts +5 -0
  79. package/engine/src/skills-render.ts +10 -6
  80. package/engine/src/state.ts +25 -1
  81. package/engine/src/words.ts +1 -1
  82. package/package.json +2 -1
  83. package/site-dist/404.html +2 -2
  84. package/site-dist/assets/{app.Df99UgrJ.js → app.D2ywvSfZ.js} +1 -1
  85. package/site-dist/assets/changelog.md.EDul9PkX.js +1 -0
  86. package/site-dist/assets/changelog.md.EDul9PkX.lean.js +1 -0
  87. package/site-dist/assets/chunks/@localSearchIndexroot.Dr_jsw66.js +1 -0
  88. package/site-dist/assets/chunks/{VPLocalSearchBox.IEhP6Gw5.js → VPLocalSearchBox.ClWffKqN.js} +1 -1
  89. package/site-dist/assets/chunks/{theme.DHubfO7g.js → theme.tbt16E5a.js} +2 -2
  90. package/site-dist/assets/guide_cli.md.BrXllHw9.js +2 -0
  91. package/site-dist/assets/guide_cli.md.BrXllHw9.lean.js +2 -0
  92. package/site-dist/assets/{guide_getting-started.md.BZTWiHhH.js → guide_getting-started.md.qAp5hWCl.js} +1 -1
  93. package/site-dist/assets/{guide_getting-started.md.BZTWiHhH.lean.js → guide_getting-started.md.qAp5hWCl.lean.js} +1 -1
  94. package/site-dist/assets/guide_install.md.By4WxsJG.js +24 -0
  95. package/site-dist/assets/guide_install.md.By4WxsJG.lean.js +24 -0
  96. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +1 -0
  97. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +1 -0
  98. package/site-dist/assets/guide_mogao.md.S0eln1Pr.js +10 -0
  99. package/site-dist/assets/guide_mogao.md.S0eln1Pr.lean.js +10 -0
  100. package/site-dist/assets/{guide_project.md.BIcaDhdS.js → guide_project.md.B2cmf8YF.js} +1 -1
  101. package/site-dist/assets/{guide_project.md.BIcaDhdS.lean.js → guide_project.md.B2cmf8YF.lean.js} +1 -1
  102. package/site-dist/assets/reference_contracts_agent-runtime.md.DPE2FJFc.js +1 -0
  103. package/site-dist/assets/{reference_contracts_agent-runtime.md.Bu8q-uGl.lean.js → reference_contracts_agent-runtime.md.DPE2FJFc.lean.js} +1 -1
  104. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +1 -0
  105. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +1 -0
  106. package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.js → reference_contracts_index.md.B5P4FjRk.js} +1 -1
  107. package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.lean.js → reference_contracts_index.md.B5P4FjRk.lean.js} +1 -1
  108. package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.js → reference_contracts_notifier-event.md.BeR8iODP.js} +1 -1
  109. package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.lean.js → reference_contracts_notifier-event.md.BeR8iODP.lean.js} +1 -1
  110. package/site-dist/assets/reference_contracts_state.md.DLygjkfs.js +1 -0
  111. package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.js +10 -0
  112. package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.lean.js +10 -0
  113. package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.js → reference_design_adapter-guide.md.B_P-spS5.js} +2 -2
  114. package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.lean.js → reference_design_adapter-guide.md.B_P-spS5.lean.js} +2 -2
  115. package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.js +13 -0
  116. package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.lean.js +13 -0
  117. package/site-dist/changelog.html +5 -5
  118. package/site-dist/guide/cli.html +31 -0
  119. package/site-dist/guide/dsh.html +5 -5
  120. package/site-dist/guide/getting-started.html +5 -5
  121. package/site-dist/guide/how-it-works.html +4 -4
  122. package/site-dist/guide/index.html +4 -4
  123. package/site-dist/guide/install.html +13 -8
  124. package/site-dist/guide/intranet.html +5 -5
  125. package/site-dist/guide/maintainer.html +5 -5
  126. package/site-dist/guide/mogao.html +39 -0
  127. package/site-dist/guide/phases.html +4 -4
  128. package/site-dist/guide/project.html +6 -6
  129. package/site-dist/guide/user.html +4 -4
  130. package/site-dist/hashmap.json +1 -1
  131. package/site-dist/index.html +4 -4
  132. package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
  133. package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
  134. package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
  135. package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
  136. package/site-dist/reference/adr/0005-skill-names.html +4 -4
  137. package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
  138. package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
  139. package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
  140. package/site-dist/reference/adr/index.html +4 -4
  141. package/site-dist/reference/commands.html +4 -4
  142. package/site-dist/reference/config.html +4 -4
  143. package/site-dist/reference/contracts/agent-runtime.html +5 -5
  144. package/site-dist/reference/contracts/cli-json.html +5 -5
  145. package/site-dist/reference/contracts/feature-files.html +4 -4
  146. package/site-dist/reference/contracts/index.html +5 -5
  147. package/site-dist/reference/contracts/notifier-event.html +6 -6
  148. package/site-dist/reference/contracts/result-file.html +4 -4
  149. package/site-dist/reference/contracts/spec.html +4 -4
  150. package/site-dist/reference/contracts/state.html +5 -5
  151. package/site-dist/reference/contracts/usage-record.html +6 -6
  152. package/site-dist/reference/contracts/verify.html +4 -4
  153. package/site-dist/reference/design/adapter-guide.html +6 -6
  154. package/site-dist/reference/design/architecture.html +4 -4
  155. package/site-dist/reference/design/builtin-capabilities.html +4 -4
  156. package/site-dist/reference/design/cli-adapter.html +42 -0
  157. package/site-dist/reference/design/platform-vocabulary.html +4 -4
  158. package/site-dist/reference/scope.html +4 -4
  159. package/skills/laoshi/SKILL.md +3 -0
  160. package/skills/laoshi-doctor/SKILL.md +2 -0
  161. package/skills/laoshi-retro/SKILL.md +2 -0
  162. package/skills/laoshi-setup/SKILL.md +3 -0
  163. package/site-dist/assets/changelog.md.Df8vFhjK.js +0 -1
  164. package/site-dist/assets/changelog.md.Df8vFhjK.lean.js +0 -1
  165. package/site-dist/assets/chunks/@localSearchIndexroot.n-0kN-N0.js +0 -1
  166. package/site-dist/assets/guide_install.md.D7NiiOPu.js +0 -19
  167. package/site-dist/assets/guide_install.md.D7NiiOPu.lean.js +0 -19
  168. package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.js +0 -1
  169. package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.lean.js +0 -1
  170. package/site-dist/assets/reference_contracts_agent-runtime.md.Bu8q-uGl.js +0 -1
  171. package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.js +0 -1
  172. package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.lean.js +0 -1
  173. package/site-dist/assets/reference_contracts_state.md.DVHC4opX.js +0 -1
  174. package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.js +0 -10
  175. package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.lean.js +0 -10
  176. /package/site-dist/assets/{reference_contracts_state.md.DVHC4opX.lean.js → reference_contracts_state.md.DLygjkfs.lean.js} +0 -0
@@ -0,0 +1,342 @@
1
+ // One requirement: where it stands, its steps, the quality gate, its documents, and the
2
+ // management actions (each one is `req <command>` on the daemon machine, after confirming).
3
+ import type { PluginHostProps, PluginScreenProps, PluginSurfaceProps } from "@getpaseo/plugin/client";
4
+ import { Modal, ScrollView, useToast } from "@getpaseo/plugin/client/react-native";
5
+ import { ExternalLink } from "@getpaseo/plugin/client/ui";
6
+ import { useState } from "react";
7
+ import { Pressable, Text, View } from "react-native";
8
+ import type { Action, RequirementDetail, Step } from "../shared/contracts";
9
+ import { useAction, useDocument, usePreferences, useRequirement, useRequirements } from "./data";
10
+ import { ACTION_TEXT, actionsFor, ago, ATTENTION_LABELS, facts, FILE_LABELS, minutes, tokens, trackOf } from "./format";
11
+ import { Markdown, tsvToMarkdown } from "./markdown";
12
+ import { ChecklistButton, CodeReviewButton, ReviewButton } from "./review";
13
+ import { Badge, Button, Chip, Eyebrow, rk, Status, StepTrack, useStyles } from "./ui";
14
+
15
+ type Theme = PluginHostProps["theme"];
16
+ type Layout = PluginHostProps["layout"];
17
+ type Navigation = PluginSurfaceProps["navigation"];
18
+
19
+ const OUTCOME_LABELS: Record<Step["outcome"], string> = { running: "运行中", completed: "完成", failed: "失败" };
20
+
21
+ function StepRow({ theme, layout, step, navigation }: { theme: Theme; layout: Layout; step: Step; navigation: Navigation }) {
22
+ const s = useStyles(theme, layout.compact);
23
+ const tone = step.outcome === "failed" ? "danger" : step.outcome === "running" ? "running" : "muted";
24
+ const body = (
25
+ <View style={{ gap: 2, paddingVertical: 6 }}>
26
+ <View style={s.row}>
27
+ <Text style={[s.text, { flexShrink: 1 }]}>{step.title}</Text>
28
+ <Badge theme={theme} tone={tone}>
29
+ {step.outcome === "completed" && step.result ? step.result : OUTCOME_LABELS[step.outcome]}
30
+ </Badge>
31
+ </View>
32
+ <Text style={s.muted}>
33
+ 第 {step.attempt} 次尝试 · {minutes(step.minutes)} · {ago(step.startedAt)}开始
34
+ </Text>
35
+ {step.error ? <Text style={s.danger}>{step.error}</Text> : null}
36
+ </View>
37
+ );
38
+ // A step agent opens in Paseo, where its whole conversation is.
39
+ if (!navigation || !step.agentId) return body;
40
+ return (
41
+ <Pressable accessibilityRole="button" accessibilityLabel={`打开 ${step.title} 的 agent`} onPress={() => navigation.openAgent({ agentId: step.agentId })}>
42
+ {body}
43
+ </Pressable>
44
+ );
45
+ }
46
+
47
+ function DocumentModal({
48
+ theme,
49
+ layout,
50
+ repo,
51
+ featureDir,
52
+ file,
53
+ onClose,
54
+ }: {
55
+ theme: Theme;
56
+ layout: Layout;
57
+ repo: string;
58
+ featureDir: string;
59
+ file: string | null;
60
+ onClose(): void;
61
+ }) {
62
+ const s = useStyles(theme, layout.compact);
63
+ const doc = useDocument(repo, featureDir, file);
64
+ return (
65
+ <Modal title={file ? `${FILE_LABELS[file] ?? file}(${file})` : ""} open={file !== null} onOpenChange={(open) => (open ? undefined : onClose())}>
66
+ <Modal.Content>
67
+ <Status theme={theme} loading={doc.isPending} error={doc.error} />
68
+ {doc.data ? (
69
+ <>
70
+ <Markdown theme={theme} source={doc.data.file.endsWith(".tsv") ? tsvToMarkdown(doc.data.content) : doc.data.content} />
71
+ {doc.data.truncated ? <Text style={s.muted}>文件较大,只显示了开头的 512 KB。</Text> : null}
72
+ </>
73
+ ) : null}
74
+ </Modal.Content>
75
+ </Modal>
76
+ );
77
+ }
78
+
79
+ function ActionModal({
80
+ theme,
81
+ layout,
82
+ detail,
83
+ action,
84
+ onClose,
85
+ }: {
86
+ theme: Theme;
87
+ layout: Layout;
88
+ detail: RequirementDetail;
89
+ action: Action | null;
90
+ onClose(): void;
91
+ }) {
92
+ const s = useStyles(theme, layout.compact);
93
+ const run = useAction();
94
+ const toast = useToast();
95
+ const go = async (verifyEnv?: "local" | "deployed") => {
96
+ if (!action) return;
97
+ try {
98
+ const result = await run.mutateAsync({ action, repo: detail.sourceRepo ?? detail.repo, featureDir: detail.featureDir, verifyEnv });
99
+ const first = result.message.split("\n").find((l) => l.trim()) ?? "";
100
+ if (result.ok) toast.show(first || "已完成", { variant: "success", durationMs: 4000 });
101
+ else toast.error(first || "没有完成");
102
+ onClose();
103
+ } catch (error) {
104
+ toast.error((error as Error).message);
105
+ }
106
+ };
107
+ const text = action ? ACTION_TEXT[action] : null;
108
+ return (
109
+ <Modal title={text ? `${text.label}:${detail.title}` : ""} open={action !== null} onOpenChange={(open) => (open ? undefined : onClose())}>
110
+ <Modal.Content>
111
+ <Text style={s.text}>{text?.confirm}</Text>
112
+ {action === "approve" && detail.files.includes("preview.md") ? <Text style={s.muted}>确认预览在本页的"文档"中:确认预览(preview.md)。</Text> : null}
113
+ <View style={s.row}>
114
+ {action === "verify" ? (
115
+ <>
116
+ <Button theme={theme} primary label="在本地验证" disabled={run.isPending} onPress={() => void go("local")} />
117
+ <Button theme={theme} label="在已部署的测试环境验证" disabled={run.isPending} onPress={() => void go("deployed")} />
118
+ </>
119
+ ) : (
120
+ <Button theme={theme} primary label={run.isPending ? "正在执行…" : (text?.label ?? "")} disabled={run.isPending} onPress={() => void go()} />
121
+ )}
122
+ <Button theme={theme} label="取消" disabled={run.isPending} onPress={onClose} />
123
+ </View>
124
+ </Modal.Content>
125
+ </Modal>
126
+ );
127
+ }
128
+
129
+ function GateSummary({ theme, layout, detail }: { theme: Theme; layout: Layout; detail: RequirementDetail }) {
130
+ const s = useStyles(theme, layout.compact);
131
+ const runs = [...(detail.gate?.runs ?? []), ...detail.joint.flatMap((j) => j.gate?.runs ?? [])];
132
+ if (runs.length === 0) return null;
133
+ const last = runs.at(-1)!;
134
+ const failed = runs.filter((r) => !r.passed).length;
135
+ return (
136
+ <View style={s.card}>
137
+ <Text style={s.heading}>质量门</Text>
138
+ <Text style={s.text}>
139
+ 运行 {runs.length} 次{failed > 0 ? `,其中 ${failed} 次发现改动带来的新失败` : ",都没有新失败"}
140
+ </Text>
141
+ <Text style={s.muted}>
142
+ 最近一次({last.key}):{last.passed ? "通过" : `新失败:${last.newFailures.join("、")}`}
143
+ </Text>
144
+ </View>
145
+ );
146
+ }
147
+
148
+ export function RequirementView({
149
+ theme,
150
+ layout,
151
+ navigation,
152
+ repo,
153
+ featureDir,
154
+ }: {
155
+ theme: Theme;
156
+ layout: Layout;
157
+ navigation: Navigation;
158
+ repo: string;
159
+ featureDir: string;
160
+ }) {
161
+ const s = useStyles(theme, layout.compact);
162
+ const query = useRequirement(repo, featureDir);
163
+ const { readOnly } = usePreferences();
164
+ const [doc, setDoc] = useState<string | null>(null);
165
+ const [action, setAction] = useState<Action | null>(null);
166
+ const [allSteps, setAllSteps] = useState(false);
167
+ const d = query.data;
168
+ if (!d) return <Status theme={theme} loading={query.isPending} error={query.error} />;
169
+ const steps = allSteps ? d.steps : d.steps.slice(-12);
170
+ const actions = readOnly ? [] : actionsFor(d);
171
+ // 1.14: finished (it has a report) and not running: the requester can try it and accept it.
172
+ const canAccept = d.files.includes("report.md") && !d.running;
173
+ // 1.14: code written and reviewed by the AI: a person can review it too.
174
+ const canReviewCode = (d.files.includes("code-review.md") || d.files.includes("implementation.md")) && !d.running;
175
+ const hr = d.humanReview ?? null;
176
+ const reviewLabel = !hr ? "代码审查" : hr.status === "approved" ? (hr.stale ? "代码审查(有新改动,需重新评审)" : "代码审查(已通过)") : "代码审查(已退回修改)";
177
+ // 1.15: one lime button, the decision this requirement waits for now.
178
+ const waitingAcceptance = d.stage.startsWith("待验收") || d.stage === "验收未通过";
179
+ const codeNeedsReview = canReviewCode && (!hr || hr.stale) && (d.status === "completed" || d.status === "phase_done");
180
+ const primary: "review" | "code" | "check" | Action | null =
181
+ d.attention === "approval" && d.hasPrototype
182
+ ? "review"
183
+ : codeNeedsReview
184
+ ? "code"
185
+ : canAccept && waitingAcceptance
186
+ ? "check"
187
+ : (actions.find((a) => a !== "stop" && !(a === "approve" && d.hasPrototype)) ?? null);
188
+ const c = rk(theme);
189
+ return (
190
+ <View style={{ gap: 16 }}>
191
+ <View style={[s.card, { gap: 12 }]}>
192
+ <Eyebrow theme={theme} accent right={<Text style={s.mono} numberOfLines={1}>{d.branch ?? d.name}</Text>}>
193
+ REQUIREMENT
194
+ </Eyebrow>
195
+ <View style={s.row}>
196
+ <Text style={s.title}>{d.title}</Text>
197
+ {d.attention ? (
198
+ <Badge theme={theme} tone={d.attention === "interrupted" ? "danger" : d.attention === "not_completed" ? "warning" : "needs"}>
199
+ {ATTENTION_LABELS[d.attention]}
200
+ </Badge>
201
+ ) : d.running ? (
202
+ <Badge theme={theme} tone="running" icon="LoaderCircle">
203
+ 进行中
204
+ </Badge>
205
+ ) : null}
206
+ </View>
207
+ <StepTrack theme={theme} steps={trackOf(d, hr)} />
208
+ <Text style={s.muted}>{facts(d)}</Text>
209
+ <Text style={[s.text, { color: d.attention ? c.brandText : theme.colors.foreground }]}>{d.stage}</Text>
210
+ {d.estimate && d.attention !== "approval" ? (
211
+ <Text style={s.muted}>
212
+ {d.estimate.over
213
+ ? `已超过同档位需求通常的用时(已用 ${minutes(d.estimate.usedAgentMinutes)},通常 ${minutes(d.estimate.typicalAgentMinutes)})`
214
+ : `预计还要约 ${minutes(Math.max(5, d.estimate.leftMinutes))}`}
215
+ {d.estimate.usedTokens !== null ? ` · 已用 ${tokens(d.estimate.usedTokens)} tokens${d.estimate.typicalTokens !== null ? `(通常 ${tokens(d.estimate.typicalTokens)})` : ""}` : ""}
216
+ {` · 按本机最近 ${d.estimate.basis} 个同档位需求,不含等人的时间`}
217
+ </Text>
218
+ ) : null}
219
+ {d.run?.stopReason && !d.running ? <Text style={s.danger}>{d.run.stopReason}</Text> : null}
220
+ {d.attention === "business" ? <Text style={s.muted}>需求方的决定请在发起需求的对话中回答,回答后再继续。</Text> : null}
221
+ </View>
222
+
223
+ {actions.length > 0 || d.hasPrototype || canAccept || canReviewCode ? (
224
+ <View style={s.row}>
225
+ {canReviewCode ? <CodeReviewButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} label={reviewLabel} primary={primary === "code"} /> : null}
226
+ {canAccept ? <ChecklistButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} primary={primary === "check"} /> : null}
227
+ {d.hasPrototype ? <ReviewButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} waiting={primary === "review"} /> : null}
228
+ {actions.map((a) => (
229
+ <Button key={a} theme={theme} primary={primary === a} label={ACTION_TEXT[a].label} onPress={() => setAction(a)} />
230
+ ))}
231
+ </View>
232
+ ) : null}
233
+
234
+ {d.files.length > 0 ? (
235
+ <View style={{ gap: 6 }}>
236
+ <Text style={s.heading}>文档</Text>
237
+ <View style={s.row}>
238
+ {d.files.map((f) => (
239
+ <Chip key={f} theme={theme} label={FILE_LABELS[f] ?? f} active={false} onPress={() => setDoc(f)} />
240
+ ))}
241
+ </View>
242
+ </View>
243
+ ) : null}
244
+
245
+ <View style={s.card}>
246
+ <Text style={s.heading}>位置</Text>
247
+ <Text selectable style={s.text}>
248
+ {d.repo}/{d.featureDir}
249
+ </Text>
250
+ {d.branch ? <Text style={s.muted}>分支 {d.branch}</Text> : null}
251
+ {d.workspaceId && navigation ? (
252
+ <Pressable accessibilityRole="button" onPress={() => navigation.openWorkspace({ workspaceId: d.workspaceId! })}>
253
+ <Text style={{ color: rk(theme).brandText, fontSize: 13, fontWeight: "600" }}>打开这个需求的工作区</Text>
254
+ </Pressable>
255
+ ) : null}
256
+ {d.joint.map((j) => (
257
+ <Text key={j.name} style={s.muted}>
258
+ 联合开发「{j.name}」:{j.repo}(分支 {j.branch})
259
+ </Text>
260
+ ))}
261
+ </View>
262
+
263
+ {(d.external ?? []).length > 0 ? (
264
+ <View style={s.card}>
265
+ <Text style={s.heading}>外部系统</Text>
266
+ {(d.external ?? []).map((e) => (
267
+ <View key={e.name} style={{ gap: 2 }}>
268
+ <View style={s.row}>
269
+ <Text style={s.text}>
270
+ {e.name}:{e.id ?? "还没有建卡"}
271
+ </Text>
272
+ {e.status ? (
273
+ <Badge theme={theme} tone="muted">
274
+ {e.status}
275
+ </Badge>
276
+ ) : null}
277
+ </View>
278
+ {e.url ? <ExternalLink href={e.url}>打开卡片</ExternalLink> : null}
279
+ {e.pending > 0 ? (
280
+ <Text style={s.danger}>
281
+ 有 {e.pending} 次调用没有成功:{e.lastError}
282
+ </Text>
283
+ ) : null}
284
+ </View>
285
+ ))}
286
+ </View>
287
+ ) : null}
288
+
289
+ {d.usage ? (
290
+ <View style={s.card}>
291
+ <Text style={s.heading}>用时与用量</Text>
292
+ <Text style={s.text}>
293
+ {d.usage.steps} 个步骤,agent 合计 {minutes(d.usage.agentMinutes)}
294
+ </Text>
295
+ <Text style={s.muted}>
296
+ 输入 {tokens(d.usage.inputTokens)} tokens,输出 {tokens(d.usage.outputTokens)} tokens
297
+ {d.usage.costUsd !== null ? `,约 $${d.usage.costUsd.toFixed(2)}` : ""}
298
+ </Text>
299
+ </View>
300
+ ) : null}
301
+
302
+ <GateSummary theme={theme} layout={layout} detail={d} />
303
+
304
+ {d.steps.length > 0 ? (
305
+ <View style={s.card}>
306
+ <View style={s.row}>
307
+ <Text style={s.heading}>步骤({d.steps.length})</Text>
308
+ {d.steps.length > 12 ? <Button theme={theme} label={allSteps ? "只看最近的" : "显示全部"} onPress={() => setAllSteps((v) => !v)} /> : null}
309
+ </View>
310
+ {steps.map((step) => (
311
+ <StepRow key={`${step.key}-${step.attempt}-${step.startedAt}`} theme={theme} layout={layout} step={step} navigation={navigation} />
312
+ ))}
313
+ </View>
314
+ ) : null}
315
+
316
+ <DocumentModal theme={theme} layout={layout} repo={d.repo} featureDir={d.featureDir} file={doc} onClose={() => setDoc(null)} />
317
+ <ActionModal theme={theme} layout={layout} detail={d} action={action} onClose={() => setAction(null)} />
318
+ </View>
319
+ );
320
+ }
321
+
322
+ export function RequirementScreen({ theme, layout, navigation, params }: PluginScreenProps) {
323
+ const s = useStyles(theme, layout.compact);
324
+ // Opened from a step agent's pill: only the requirement's name is known; find it in the list.
325
+ const list = useRequirements();
326
+ const byName = !params.repo && params.name ? (list.data ?? []).find((r) => r.name === params.name) : null;
327
+ const repo = params.repo ?? byName?.repo;
328
+ const featureDir = params.featureDir ?? byName?.featureDir;
329
+ return (
330
+ <View style={s.screen}>
331
+ <ScrollView contentContainerStyle={s.body}>
332
+ {repo && featureDir ? (
333
+ <RequirementView theme={theme} layout={layout} navigation={navigation} repo={repo} featureDir={featureDir} />
334
+ ) : params.name ? (
335
+ <Status theme={theme} loading={list.isPending} error={list.error} empty={list.data ? `本机记录中没有需求 ${params.name}。` : null} />
336
+ ) : (
337
+ <Text style={s.muted}>没有指定需求。</Text>
338
+ )}
339
+ </ScrollView>
340
+ </View>
341
+ );
342
+ }
@@ -0,0 +1,173 @@
1
+ // Plain-language labels, shared by every screen.
2
+ import type { Attention, Requirement } from "../shared/contracts";
3
+
4
+ export const ATTENTION_LABELS: Record<Exclude<Attention, null>, string> = {
5
+ approval: "等待确认方案",
6
+ business: "等待需求方决定",
7
+ permission: "等待批准权限",
8
+ interrupted: "已中断,可以继续",
9
+ not_completed: "结束但未完成",
10
+ not_started: "已确认,未开始开发",
11
+ };
12
+
13
+ export const TYPE_LABELS: Record<string, string> = { defect: "缺陷", refactor: "重构", assessment: "评估" };
14
+
15
+ export const PROFILE_LABELS: Record<string, string> = { quick: "快速档", standard: "标准档" };
16
+
17
+ export const FILE_LABELS: Record<string, string> = {
18
+ "spec.md": "需求说明",
19
+ "alignment.md": "访谈记录",
20
+ "spec-review.md": "需求说明审阅",
21
+ "changes.md": "需求变更",
22
+ "decisions.tsv": "决策记录",
23
+ "design.md": "方案",
24
+ "design-review.md": "方案审核",
25
+ "preview.md": "确认预览",
26
+ "contract.md": "接口约定",
27
+ "diagnosis.md": "复现与定位",
28
+ "assessment.md": "评估",
29
+ "implementation.md": "实现记录",
30
+ "progress.md": "进展",
31
+ "code-review.md": "代码评审",
32
+ "handoff.md": "提测说明",
33
+ "service-start.md": "服务启动",
34
+ "verification.md": "功能验证",
35
+ "report.md": "完成报告",
36
+ "acceptance.md": "验收记录",
37
+ "lessons.tsv": "可以变成规则的问题",
38
+ };
39
+
40
+ export type Group = "attention" | "running" | "verify" | "done" | "other";
41
+
42
+ export const GROUP_LABELS: Record<Group, string> = {
43
+ attention: "需要你处理",
44
+ running: "进行中",
45
+ verify: "研发完成,待测试验证",
46
+ done: "最近完成",
47
+ other: "其他",
48
+ };
49
+
50
+ const RECENT_MS = 14 * 24 * 3600_000;
51
+
52
+ export function groupOf(r: Requirement, now = Date.now()): Group {
53
+ if (r.attention) return "attention";
54
+ if (r.running) return "running";
55
+ if (r.status === "phase_done") return "verify";
56
+ if (r.status === "completed" && now - Date.parse(r.updatedAt) < RECENT_MS) return "done";
57
+ return "other";
58
+ }
59
+
60
+ export function minutes(m: number): string {
61
+ if (m < 1) return "不到 1 分钟";
62
+ if (m < 60) return `${Math.round(m)} 分钟`;
63
+ const h = Math.floor(m / 60);
64
+ const rest = Math.round(m % 60);
65
+ return rest === 0 ? `${h} 小时` : `${h} 小时 ${rest} 分`;
66
+ }
67
+
68
+ export function ago(iso: string, now = Date.now()): string {
69
+ const m = (now - Date.parse(iso)) / 60_000;
70
+ if (!Number.isFinite(m)) return "";
71
+ if (m < 1) return "刚刚";
72
+ if (m < 60) return `${Math.round(m)} 分钟前`;
73
+ if (m < 24 * 60) return `${Math.round(m / 60)} 小时前`;
74
+ return `${Math.round(m / 60 / 24)} 天前`;
75
+ }
76
+
77
+ export function tokens(n: number | null): string {
78
+ if (n === null) return "未报告";
79
+ return n >= 10_000 ? `${Math.round(n / 1_000) / 10} 万` : String(n);
80
+ }
81
+
82
+ /** One line under a requirement's title: project, type, stage. */
83
+ export function facts(r: Requirement): string {
84
+ return [r.project, r.type ? TYPE_LABELS[r.type] ?? r.type : null, r.profile ? PROFILE_LABELS[r.profile] ?? r.profile : null]
85
+ .filter(Boolean)
86
+ .join(" · ");
87
+ }
88
+
89
+ /** What a person can do from here, by the requirement's state. */
90
+ export function actionsFor(
91
+ r: Pick<Requirement, "attention" | "running" | "status"> & { external?: Array<{ pending: number; id: string | null }> },
92
+ ): Array<"approve" | "stop" | "resume" | "verify" | "sync" | "start"> {
93
+ const base: Array<"approve" | "stop" | "resume" | "verify" | "sync" | "start"> = r.running
94
+ ? ["stop"]
95
+ : r.attention === "approval"
96
+ ? ["approve"]
97
+ : r.attention === "interrupted" || r.attention === "business"
98
+ ? ["resume"]
99
+ : r.attention === "not_started"
100
+ ? ["start"]
101
+ : r.status === "phase_done"
102
+ ? ["verify"]
103
+ : [];
104
+ // A running pipeline sends what failed by itself at its next step change.
105
+ if (!r.running && r.status && (r.external ?? []).some((e) => e.pending > 0 || !e.id)) base.push("sync");
106
+ return base;
107
+ }
108
+
109
+ export const ACTION_TEXT = {
110
+ approve: { label: "确认方案", confirm: "确认 preview.md 中的方案,开始写代码?请先看过确认预览和原型。" },
111
+ stop: { label: "停止", confirm: "停止这个需求的流水线?正在运行的步骤会被中断,之后可以继续。" },
112
+ start: { label: "开始开发", confirm: "按已确认的需求说明开始开发?在项目主目录中的需求会新建自己的工作区;进展发回谈需求的那个对话。" },
113
+ resume: { label: "继续", confirm: "从中断处继续?需求说明改过的话,只处理变化的部分。" },
114
+ verify: { label: "开始测试验证", confirm: "开始测试验证?选择在哪里验证。" },
115
+ sync: { label: "同步到外部系统", confirm: "把这个需求同步到对接的外部系统:补发没有成功的调用、补建卡片、更新状态。" },
116
+ reply: { label: "发送回复", confirm: "把回复转给这个需求的对话,由它更新需求说明并继续开发。" },
117
+ } as const;
118
+
119
+ /** The six stops of the step track, and who does each (design/components/StepTrack.md). */
120
+ export const TRACK = [
121
+ { label: "对齐", who: "你" },
122
+ { label: "方案", who: "AI · 你确认" },
123
+ { label: "实现", who: "AI" },
124
+ { label: "评审", who: "AI · 开发同事" },
125
+ { label: "验证", who: "AI" },
126
+ { label: "验收", who: "需求方" },
127
+ ] as const;
128
+
129
+ const STEP_STOP: Array<[RegExp, number]> = [
130
+ [/^(design|design_review|design_revise|design_proposal|assessment|diagnosis|reproduce)/, 1],
131
+ [/^(implement|acceptance_tests)/, 2],
132
+ [/^(code_review|review_fix)/, 3],
133
+ [/^(verify|defect_fix|reverify|service|handoff|report)/, 4],
134
+ ];
135
+
136
+ /**
137
+ * Where the requirement is on the track, and whether that stop waits for a person.
138
+ * `humanReview` (detail only) tells whether the code review is done.
139
+ */
140
+ export function trackOf(
141
+ r: Pick<Requirement, "stage" | "status" | "attention" | "running" | "current">,
142
+ humanReview?: { status: string; stale: boolean } | null,
143
+ ): Array<{ label: string; who: string; state: "done" | "now" | "needs" | "todo" }> {
144
+ let at = 0;
145
+ let needs = false;
146
+ const running = r.current[0]?.key;
147
+ if (r.stage.startsWith("对齐")) at = 0;
148
+ else if (r.attention === "approval" || r.attention === "business" || r.attention === "not_started") [at, needs] = [1, true];
149
+ else if (running) at = STEP_STOP.find(([re]) => re.test(running))?.[1] ?? 2;
150
+ else if (r.status === "phase_done") [at, needs] = [4, true];
151
+ else if (r.status === "completed" || /待验收|已验收|验收/.test(r.stage)) {
152
+ const reviewed = humanReview && humanReview.status === "approved" && !humanReview.stale;
153
+ if (/已验收|验收通过/.test(r.stage)) at = TRACK.length;
154
+ else if (humanReview !== undefined && !reviewed) [at, needs] = [3, true];
155
+ else [at, needs] = [5, true];
156
+ } else if (r.status) at = 2;
157
+ return TRACK.map((t, i) => ({ ...t, state: i < at ? "done" : i === at ? (needs ? "needs" : "now") : "todo" }));
158
+ }
159
+
160
+ /** The icon of a requirement in a list, by what it needs (Lucide names). */
161
+ export function iconOf(r: Pick<Requirement, "attention" | "running" | "status" | "stage">): { name: string; tone: "needs" | "running" | "success" | "warning" | "danger" | "muted" } {
162
+ if (r.attention === "interrupted") return { name: "OctagonAlert", tone: "danger" };
163
+ if (r.attention === "permission") return { name: "ShieldCheck", tone: "needs" };
164
+ if (r.attention === "approval") return { name: "PenTool", tone: "needs" };
165
+ if (r.attention === "business") return { name: "MessagesSquare", tone: "needs" };
166
+ if (r.attention === "not_started") return { name: "Play", tone: "needs" };
167
+ if (r.attention === "not_completed") return { name: "CircleDashed", tone: "warning" };
168
+ if (r.running) return { name: "LoaderCircle", tone: "running" };
169
+ if (r.stage.startsWith("对齐")) return { name: "MessagesSquare", tone: "muted" };
170
+ if (r.status === "phase_done" || /待验收/.test(r.stage)) return { name: "ClipboardCheck", tone: "warning" };
171
+ if (r.status === "completed") return { name: "CircleCheck", tone: "success" };
172
+ return { name: "Circle", tone: "muted" };
173
+ }