@yiyi_zhang/laoshi 0.2.0-beta.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.
- package/CHANGELOG.md +20 -0
- package/adapters/cli/adapter.ts +53 -0
- package/adapters/cli/cli-runtime.ts +402 -0
- package/adapters/cli/drivers.ts +146 -0
- package/adapters/cli/install.mjs +28 -0
- package/adapters/cli/skill/setup.md +8 -0
- package/adapters/dsh/plugin/index.mjs +1 -1
- package/adapters/dsh/plugin/package.json +1 -1
- package/adapters/mogao/adapter.ts +1 -0
- package/adapters/mogao/install.mjs +1 -1
- package/adapters/mogao/make-expert.mjs +1 -0
- package/adapters/mogao/mogao-runtime.ts +57 -8
- package/adapters/paseo/adapter.ts +1 -1
- package/adapters/paseo/install.mjs +17 -5
- package/adapters/paseo/migrate.ts +267 -0
- package/adapters/paseo/plugin/OVERVIEW.md +9 -0
- package/adapters/paseo/plugin/client/config.tsx +216 -0
- package/adapters/paseo/plugin/client/data.ts +85 -0
- package/adapters/paseo/plugin/client/detail.tsx +342 -0
- package/adapters/paseo/plugin/client/format.ts +173 -0
- package/adapters/paseo/plugin/client/inbox.tsx +190 -0
- package/adapters/paseo/plugin/client/live.ts +161 -0
- package/adapters/paseo/plugin/client/markdown.tsx +220 -0
- package/adapters/paseo/plugin/client/models.tsx +117 -0
- package/adapters/paseo/plugin/client/nav.ts +22 -0
- package/adapters/paseo/plugin/client/overview.tsx +103 -0
- package/adapters/paseo/plugin/client/panel.tsx +56 -0
- package/adapters/paseo/plugin/client/review.tsx +80 -0
- package/adapters/paseo/plugin/client/row.tsx +63 -0
- package/adapters/paseo/plugin/client/settings.tsx +92 -0
- package/adapters/paseo/plugin/client/sidebar.tsx +27 -0
- package/adapters/paseo/plugin/client/stats.tsx +138 -0
- package/adapters/paseo/plugin/client/ui.tsx +278 -0
- package/adapters/paseo/plugin/client/web.ts +34 -0
- package/adapters/paseo/plugin/index.client.tsx +66 -0
- package/adapters/paseo/plugin/index.server.ts +61 -0
- package/adapters/paseo/plugin/package.json +22 -0
- package/adapters/paseo/plugin/paseo-plugin.json +6 -0
- package/adapters/paseo/plugin/server/handlers.ts +69 -0
- package/adapters/paseo/plugin/server/req.ts +105 -0
- package/adapters/paseo/plugin/shared/contracts.ts +286 -0
- package/adapters/paseo/plugin/shared/rk-colors.ts +35 -0
- package/adapters/paseo/plugin/tsconfig.json +16 -0
- package/adapters/paseo/plugin-cmd.mjs +233 -0
- package/bin/install.mjs +8 -7
- package/bin/req.mjs +10 -2
- package/contracts/README.md +1 -1
- package/contracts/agent-runtime.md +2 -2
- package/contracts/cli-json.md +4 -3
- package/contracts/notifier-event.md +2 -2
- package/contracts/state.md +2 -0
- package/contracts/usage-record.md +3 -3
- package/docs/design/adapter-guide.md +2 -1
- package/docs/design/cli-adapter.md +75 -0
- package/docs/design/compat-migration.md +2 -0
- package/docs/design/mogao-expert.md +3 -1
- package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +132 -0
- package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +32 -3
- package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +4 -2
- 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
- package/engine/src/api.ts +4 -0
- package/engine/src/doctor.ts +3 -2
- package/engine/src/identity.ts +16 -1
- package/engine/src/main.ts +3 -1
- package/engine/src/messages.ts +1 -1
- package/engine/src/platform.ts +2 -0
- package/engine/src/runtime-loader.ts +14 -0
- package/engine/src/state.ts +2 -0
- package/engine/src/words.ts +1 -1
- package/package.json +2 -1
- package/site-dist/404.html +2 -2
- package/site-dist/assets/{app.DMAHANCl.js → app.D2ywvSfZ.js} +1 -1
- package/site-dist/assets/changelog.md.EDul9PkX.js +1 -0
- package/site-dist/assets/changelog.md.EDul9PkX.lean.js +1 -0
- package/site-dist/assets/chunks/@localSearchIndexroot.Dr_jsw66.js +1 -0
- package/site-dist/assets/chunks/{VPLocalSearchBox.COsLwqWS.js → VPLocalSearchBox.ClWffKqN.js} +1 -1
- package/site-dist/assets/chunks/{theme.CeR3HD86.js → theme.tbt16E5a.js} +2 -2
- package/site-dist/assets/guide_cli.md.BrXllHw9.js +2 -0
- package/site-dist/assets/guide_cli.md.BrXllHw9.lean.js +2 -0
- package/site-dist/assets/{guide_getting-started.md.Bytaz3L8.js → guide_getting-started.md.qAp5hWCl.js} +1 -1
- package/site-dist/assets/guide_install.md.By4WxsJG.js +24 -0
- package/site-dist/assets/guide_install.md.By4WxsJG.lean.js +24 -0
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +1 -0
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +1 -0
- package/site-dist/assets/guide_mogao.md.S0eln1Pr.js +10 -0
- package/site-dist/assets/guide_mogao.md.S0eln1Pr.lean.js +10 -0
- package/site-dist/assets/{guide_project.md.BIcaDhdS.js → guide_project.md.B2cmf8YF.js} +1 -1
- package/site-dist/assets/{guide_project.md.BIcaDhdS.lean.js → guide_project.md.B2cmf8YF.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_agent-runtime.md.DPE2FJFc.js +1 -0
- package/site-dist/assets/{reference_contracts_agent-runtime.md.TK7Lhwdf.lean.js → reference_contracts_agent-runtime.md.DPE2FJFc.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +1 -0
- package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.js → reference_contracts_index.md.B5P4FjRk.js} +1 -1
- package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.lean.js → reference_contracts_index.md.B5P4FjRk.lean.js} +1 -1
- package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.js → reference_contracts_notifier-event.md.BeR8iODP.js} +1 -1
- package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.lean.js → reference_contracts_notifier-event.md.BeR8iODP.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_state.md.DLygjkfs.js +1 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.js +10 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.lean.js +10 -0
- package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.js → reference_design_adapter-guide.md.B_P-spS5.js} +2 -2
- package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.lean.js → reference_design_adapter-guide.md.B_P-spS5.lean.js} +2 -2
- package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.js +13 -0
- package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.lean.js +13 -0
- package/site-dist/changelog.html +5 -5
- package/site-dist/guide/cli.html +31 -0
- package/site-dist/guide/dsh.html +5 -5
- package/site-dist/guide/getting-started.html +5 -5
- package/site-dist/guide/how-it-works.html +4 -4
- package/site-dist/guide/index.html +4 -4
- package/site-dist/guide/install.html +13 -8
- package/site-dist/guide/intranet.html +5 -5
- package/site-dist/guide/maintainer.html +5 -5
- package/site-dist/guide/mogao.html +39 -0
- package/site-dist/guide/phases.html +4 -4
- package/site-dist/guide/project.html +6 -6
- package/site-dist/guide/user.html +4 -4
- package/site-dist/hashmap.json +1 -1
- package/site-dist/index.html +4 -4
- package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
- package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
- package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
- package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
- package/site-dist/reference/adr/0005-skill-names.html +4 -4
- package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
- package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
- package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
- package/site-dist/reference/adr/index.html +4 -4
- package/site-dist/reference/commands.html +4 -4
- package/site-dist/reference/config.html +4 -4
- package/site-dist/reference/contracts/agent-runtime.html +5 -5
- package/site-dist/reference/contracts/cli-json.html +5 -5
- package/site-dist/reference/contracts/feature-files.html +4 -4
- package/site-dist/reference/contracts/index.html +5 -5
- package/site-dist/reference/contracts/notifier-event.html +6 -6
- package/site-dist/reference/contracts/result-file.html +4 -4
- package/site-dist/reference/contracts/spec.html +4 -4
- package/site-dist/reference/contracts/state.html +5 -5
- package/site-dist/reference/contracts/usage-record.html +6 -6
- package/site-dist/reference/contracts/verify.html +4 -4
- package/site-dist/reference/design/adapter-guide.html +6 -6
- package/site-dist/reference/design/architecture.html +4 -4
- package/site-dist/reference/design/builtin-capabilities.html +4 -4
- package/site-dist/reference/design/cli-adapter.html +42 -0
- package/site-dist/reference/design/platform-vocabulary.html +4 -4
- package/site-dist/reference/scope.html +4 -4
- package/site-dist/assets/changelog.md.Q8QGpuBY.js +0 -1
- package/site-dist/assets/changelog.md.Q8QGpuBY.lean.js +0 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.CQdjFK3w.js +0 -1
- package/site-dist/assets/guide_install.md.D7NiiOPu.js +0 -19
- package/site-dist/assets/guide_install.md.D7NiiOPu.lean.js +0 -19
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.js +0 -1
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.lean.js +0 -1
- package/site-dist/assets/reference_contracts_agent-runtime.md.TK7Lhwdf.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.lean.js +0 -1
- package/site-dist/assets/reference_contracts_state.md.DVHC4opX.js +0 -1
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.js +0 -10
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.lean.js +0 -10
- /package/site-dist/assets/{guide_getting-started.md.Bytaz3L8.lean.js → guide_getting-started.md.qAp5hWCl.lean.js} +0 -0
- /package/site-dist/assets/{reference_contracts_state.md.DVHC4opX.lean.js → reference_contracts_state.md.DLygjkfs.lean.js} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// "等你处理" (1.12): everything that is waiting for a person, at the top, each with what to do and
|
|
2
|
+
// how long it has waited. Answers and plan confirmations can be given right here: an answer is
|
|
3
|
+
// passed to the requirement's chat (laoshi reply), the same as typing it there.
|
|
4
|
+
import type { PluginHostProps } from "@getpaseo/plugin/client";
|
|
5
|
+
import { TextInput, useToast } from "@getpaseo/plugin/client/react-native";
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { Text, View } from "react-native";
|
|
8
|
+
import type { Attention, Requirement } from "../shared/contracts";
|
|
9
|
+
import { useAction, usePreferences } from "./data";
|
|
10
|
+
import { facts } from "./format";
|
|
11
|
+
import { ReviewButton } from "./review";
|
|
12
|
+
import { AttentionIcon, Badge, Button, Eyebrow, useStyles } from "./ui";
|
|
13
|
+
|
|
14
|
+
type Theme = PluginHostProps["theme"];
|
|
15
|
+
type Layout = PluginHostProps["layout"];
|
|
16
|
+
|
|
17
|
+
const KIND: Record<Exclude<Attention, null>, { label: string; tone: "needs" | "danger" | "muted"; icon: string; todo: string }> = {
|
|
18
|
+
approval: { icon: "PenTool", label: "确认方案", tone: "needs", todo: "方案已通过审核。看一下“做完后会看到什么”,没问题就确认,开始写代码;要改就写下来。" },
|
|
19
|
+
business: { icon: "MessagesSquare", label: "回答问题", tone: "needs", todo: "方案审核有问题只有你能决定,回答后开发会接着进行。" },
|
|
20
|
+
permission: { icon: "ShieldCheck", label: "批准权限", tone: "needs", todo: "有一个步骤在等你允许它做一项操作,批准前会一直停在这里。打开这个 agent,在它的对话里选择允许或拒绝;拿不准时请开发同事看一下。" },
|
|
21
|
+
interrupted: { icon: "OctagonAlert", label: "已中断", tone: "danger", todo: "开发中断了,自动处理没能解决。看一下原因,能继续就继续。" },
|
|
22
|
+
not_completed: { icon: "CircleDashed", label: "没有完成", tone: "muted", todo: "流水线结束了,但有部分没有做完。完成报告里写了原因和建议。" },
|
|
23
|
+
not_started: { icon: "Play", label: "还没开始开发", tone: "needs", todo: "需求说明已经确认,但开发没有开始。确认无误就点“开始开发”,进展会发回谈需求的那个对话。" },
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/** Plain waiting time: "等了 3 小时". */
|
|
27
|
+
export function waited(since: string, now = Date.now()): string {
|
|
28
|
+
const m = (now - Date.parse(since)) / 60_000;
|
|
29
|
+
if (!Number.isFinite(m) || m < 1) return "刚刚";
|
|
30
|
+
if (m < 60) return `等了 ${Math.round(m)} 分钟`;
|
|
31
|
+
if (m < 48 * 60) return `等了 ${Math.round(m / 60)} 小时`;
|
|
32
|
+
return `等了 ${Math.round(m / 60 / 24)} 天`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Longest-waiting first: the oldest decision is the one holding things up most. */
|
|
36
|
+
export function inboxItems(items: Requirement[]): Requirement[] {
|
|
37
|
+
return items
|
|
38
|
+
.filter((r) => r.attention)
|
|
39
|
+
.sort((a, b) => (a.waiting?.since ?? a.updatedAt).localeCompare(b.waiting?.since ?? b.updatedAt));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function InboxCard({ theme, layout, item, open, readOnly, openAgent }: { theme: Theme; layout: Layout; item: Requirement; open(): void; readOnly: boolean; openAgent?: (agentId: string) => void }) {
|
|
43
|
+
const s = useStyles(theme, layout.compact);
|
|
44
|
+
const run = useAction();
|
|
45
|
+
const toast = useToast();
|
|
46
|
+
const [writing, setWriting] = useState(item.attention === "business");
|
|
47
|
+
const [text, setText] = useState("");
|
|
48
|
+
const kind = KIND[item.attention!];
|
|
49
|
+
const w = item.waiting;
|
|
50
|
+
const repo = item.sourceRepo ?? item.repo;
|
|
51
|
+
|
|
52
|
+
const act = async (action: "approve" | "resume" | "reply" | "start") => {
|
|
53
|
+
try {
|
|
54
|
+
const result = await run.mutateAsync({ action, repo, featureDir: item.featureDir, ...(action === "reply" ? { text } : {}) });
|
|
55
|
+
const first = result.message.split("\n").find((l) => l.trim()) ?? "";
|
|
56
|
+
if (result.ok) {
|
|
57
|
+
toast.show(first || "已完成", { variant: "success", durationMs: 4000 });
|
|
58
|
+
setText("");
|
|
59
|
+
} else toast.error(first || "没有完成");
|
|
60
|
+
} catch (error) {
|
|
61
|
+
toast.error((error as Error).message);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<View style={[s.card, { gap: 10 }]}>
|
|
67
|
+
<View style={{ flexDirection: "row", alignItems: "flex-start", gap: 12 }}>
|
|
68
|
+
<AttentionIcon theme={theme} icon={kind.icon} tone={kind.tone} />
|
|
69
|
+
<View style={{ flex: 1, minWidth: 0, gap: 2 }}>
|
|
70
|
+
<View style={[s.row, { justifyContent: "space-between" }]}>
|
|
71
|
+
<Text style={[s.text, { fontWeight: "600", fontSize: 15, flexShrink: 1 }]}>{item.title}</Text>
|
|
72
|
+
<Text style={s.mono}>{waited(w?.since ?? item.updatedAt)}</Text>
|
|
73
|
+
</View>
|
|
74
|
+
<View style={s.row}>
|
|
75
|
+
<Badge theme={theme} tone={kind.tone}>
|
|
76
|
+
{kind.label}
|
|
77
|
+
</Badge>
|
|
78
|
+
</View>
|
|
79
|
+
</View>
|
|
80
|
+
</View>
|
|
81
|
+
<Text style={s.muted}>
|
|
82
|
+
{facts(item)}
|
|
83
|
+
{w?.card ? ` · 卡片 ${w.card.system} ${w.card.id}${w.card.requester ? `(${w.card.requester})` : ""}` : ""}
|
|
84
|
+
</Text>
|
|
85
|
+
<Text style={s.text}>{kind.todo}</Text>
|
|
86
|
+
|
|
87
|
+
{(item.attention === "business" || item.attention === "permission") && w && w.questions.length > 0 ? (
|
|
88
|
+
<View style={{ gap: 4 }}>
|
|
89
|
+
{item.attention === "permission" ? <Text style={s.muted}>{w.reason}。要批准的操作:</Text> : null}
|
|
90
|
+
{w.questions.map((q, i) => (
|
|
91
|
+
<Text key={i} style={s.text}>
|
|
92
|
+
{i + 1}. {q}
|
|
93
|
+
</Text>
|
|
94
|
+
))}
|
|
95
|
+
</View>
|
|
96
|
+
) : null}
|
|
97
|
+
{item.attention === "interrupted" && w?.reason ? (
|
|
98
|
+
<Text style={s.danger} numberOfLines={4}>
|
|
99
|
+
{w.reason}
|
|
100
|
+
</Text>
|
|
101
|
+
) : null}
|
|
102
|
+
{item.attention === "not_started" && w?.reason ? <Text style={s.text}>{w.reason}</Text> : null}
|
|
103
|
+
|
|
104
|
+
{readOnly ? (
|
|
105
|
+
<View style={s.row}>
|
|
106
|
+
<Button theme={theme} label="查看详情" onPress={open} />
|
|
107
|
+
<Text style={s.muted}>插件设置为只读,请在对话中处理</Text>
|
|
108
|
+
</View>
|
|
109
|
+
) : (
|
|
110
|
+
<>
|
|
111
|
+
{item.attention === "approval" && item.hasPrototype ? <Text style={s.text}>这个方案有界面原型:在原型上点选要改的地方,比写文字说得清楚。</Text> : null}
|
|
112
|
+
{writing && w?.canReply ? (
|
|
113
|
+
<View style={{ gap: 8 }}>
|
|
114
|
+
<TextInput
|
|
115
|
+
value={text}
|
|
116
|
+
onChangeText={setText}
|
|
117
|
+
multiline
|
|
118
|
+
placeholder={item.attention === "approval" ? "写下要改的地方,例如:按钮放在右上角" : w.questions.length > 1 ? "按编号回答,例如:1. 只有新订单显示 2. 不需要" : "写下你的回答"}
|
|
119
|
+
placeholderTextColor={theme.colors.foregroundMuted}
|
|
120
|
+
style={{
|
|
121
|
+
minHeight: 72,
|
|
122
|
+
padding: 10,
|
|
123
|
+
borderRadius: 8,
|
|
124
|
+
borderWidth: 1,
|
|
125
|
+
borderColor: theme.colors.border,
|
|
126
|
+
backgroundColor: theme.colors.surface0,
|
|
127
|
+
color: theme.colors.foreground,
|
|
128
|
+
fontSize: 14,
|
|
129
|
+
textAlignVertical: "top",
|
|
130
|
+
}}
|
|
131
|
+
/>
|
|
132
|
+
{w.card ? <Text style={s.muted}>也可以在卡片的“需求方回复”区回答,效果一样。</Text> : null}
|
|
133
|
+
</View>
|
|
134
|
+
) : null}
|
|
135
|
+
<View style={s.row}>
|
|
136
|
+
{item.attention === "approval" ? (
|
|
137
|
+
<>
|
|
138
|
+
{item.hasPrototype ? <ReviewButton theme={theme} repo={repo} featureDir={item.featureDir} title={item.title} waiting /> : null}
|
|
139
|
+
<Button theme={theme} primary={!item.hasPrototype} label={run.isPending ? "正在执行…" : "确认方案"} disabled={run.isPending} onPress={() => void act("approve")} />
|
|
140
|
+
{w?.canReply ? (
|
|
141
|
+
writing ? (
|
|
142
|
+
<Button theme={theme} label="发送修改意见" disabled={run.isPending || !text.trim()} onPress={() => void act("reply")} />
|
|
143
|
+
) : (
|
|
144
|
+
<Button theme={theme} label="提修改意见" onPress={() => setWriting(true)} />
|
|
145
|
+
)
|
|
146
|
+
) : null}
|
|
147
|
+
</>
|
|
148
|
+
) : null}
|
|
149
|
+
{item.attention === "business" && w?.canReply ? (
|
|
150
|
+
<Button theme={theme} primary label={run.isPending ? "正在发送…" : "发送回答"} disabled={run.isPending || !text.trim()} onPress={() => void act("reply")} />
|
|
151
|
+
) : null}
|
|
152
|
+
{item.attention === "permission" && w?.agentId && openAgent ? <Button theme={theme} primary label="打开这个 agent" onPress={() => openAgent(w.agentId!)} /> : null}
|
|
153
|
+
{item.attention === "interrupted" ? (
|
|
154
|
+
<Button theme={theme} primary label={run.isPending ? "正在执行…" : "继续"} disabled={run.isPending} onPress={() => void act("resume")} />
|
|
155
|
+
) : null}
|
|
156
|
+
{item.attention === "not_started" && w?.canStart ? (
|
|
157
|
+
<Button theme={theme} primary label={run.isPending ? "正在开始…" : "开始开发"} disabled={run.isPending} onPress={() => void act("start")} />
|
|
158
|
+
) : null}
|
|
159
|
+
<Button theme={theme} label={item.attention === "approval" ? "看方案和确认预览" : item.attention === "not_completed" ? "看完成报告" : "查看详情"} onPress={open} />
|
|
160
|
+
</View>
|
|
161
|
+
</>
|
|
162
|
+
)}
|
|
163
|
+
</View>
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export function Inbox({ theme, layout, items, open, openAgent }: { theme: Theme; layout: Layout; items: Requirement[]; open(item: Requirement): void; openAgent?: (agentId: string) => void }) {
|
|
168
|
+
const s = useStyles(theme, layout.compact);
|
|
169
|
+
const { readOnly } = usePreferences();
|
|
170
|
+
const waiting = inboxItems(items);
|
|
171
|
+
return (
|
|
172
|
+
<View style={{ gap: 10 }}>
|
|
173
|
+
<View>
|
|
174
|
+
<Eyebrow theme={theme} accent right={<Text style={s.muted}>{waiting.length > 0 ? "等你处理 · 等得最久的在前" : "等你处理"}</Text>}>
|
|
175
|
+
NEEDS YOU · {waiting.length}
|
|
176
|
+
</Eyebrow>
|
|
177
|
+
</View>
|
|
178
|
+
{waiting.length === 0 ? (
|
|
179
|
+
<View style={[s.card, { flexDirection: "row", alignItems: "center", gap: 8 }]}>
|
|
180
|
+
<Badge theme={theme} tone="success" icon="CircleCheck">
|
|
181
|
+
没有
|
|
182
|
+
</Badge>
|
|
183
|
+
<Text style={s.muted}>现在没有需要你处理的事。需要你确认或回答时,会出现在这里。</Text>
|
|
184
|
+
</View>
|
|
185
|
+
) : (
|
|
186
|
+
waiting.map((item) => <InboxCard key={item.key} theme={theme} layout={layout} item={item} open={() => open(item)} readOnly={readOnly} openAgent={openAgent} />)
|
|
187
|
+
)}
|
|
188
|
+
</View>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Buttons that follow Paseo's agents and workspaces (registered outside React):
|
|
2
|
+
// - a pill on every step agent of a requirement: which requirement, opens it;
|
|
3
|
+
// - a header button on every workspace that has requirements: how many need a person.
|
|
4
|
+
import type { PluginButtonRegistration, PluginClientContext } from "@getpaseo/plugin/client";
|
|
5
|
+
import { listRpc, type Requirement } from "../shared/contracts";
|
|
6
|
+
import { inWorkspace } from "./panel";
|
|
7
|
+
|
|
8
|
+
/** The step agents' labels (laoshi's runtime sets them when it starts a step). */
|
|
9
|
+
const PIPELINE_LABEL = "requirement-pipeline";
|
|
10
|
+
|
|
11
|
+
interface AgentLike {
|
|
12
|
+
id: string;
|
|
13
|
+
workspaceId?: string | null;
|
|
14
|
+
labels?: Record<string, string> | null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
interface WorkspaceLike {
|
|
18
|
+
id: string;
|
|
19
|
+
workspaceDirectory?: string;
|
|
20
|
+
projectRootPath?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function contributeLive(client: PluginClientContext): () => void {
|
|
24
|
+
const lifetime = new AbortController();
|
|
25
|
+
const pills = new Map<string, PluginButtonRegistration>();
|
|
26
|
+
const headers = new Map<string, PluginButtonRegistration>();
|
|
27
|
+
const workspaces = new Map<string, WorkspaceLike>();
|
|
28
|
+
let requirements: Requirement[] = [];
|
|
29
|
+
|
|
30
|
+
// ----- pills on step agents
|
|
31
|
+
const registerAgent = (agent: AgentLike) => {
|
|
32
|
+
pills.get(agent.id)?.remove();
|
|
33
|
+
pills.delete(agent.id);
|
|
34
|
+
const name = agent.labels?.[PIPELINE_LABEL];
|
|
35
|
+
if (lifetime.signal.aborted || !name || !agent.workspaceId) return;
|
|
36
|
+
pills.set(
|
|
37
|
+
agent.id,
|
|
38
|
+
client.addComposerPill({
|
|
39
|
+
id: "requirement",
|
|
40
|
+
workspaceId: agent.workspaceId,
|
|
41
|
+
agentId: agent.id,
|
|
42
|
+
button: {
|
|
43
|
+
title: `打开需求 ${name}`,
|
|
44
|
+
icon: "ClipboardList",
|
|
45
|
+
label: "需求",
|
|
46
|
+
behavior: { kind: "action", onPress: () => client.openScreen({ screenId: "requirement", params: { name } }) },
|
|
47
|
+
},
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
void client.paseo.agents
|
|
52
|
+
.list({ subscribe: {}, signal: lifetime.signal })
|
|
53
|
+
.then(({ subscription }) => {
|
|
54
|
+
subscription.subscribe({
|
|
55
|
+
snapshot: ({ entries }) => {
|
|
56
|
+
for (const pill of pills.values()) pill.remove();
|
|
57
|
+
pills.clear();
|
|
58
|
+
for (const { agent } of entries) registerAgent(agent as AgentLike);
|
|
59
|
+
},
|
|
60
|
+
update: (message) => {
|
|
61
|
+
if (message.type !== "agent_update") return;
|
|
62
|
+
const update = message.payload;
|
|
63
|
+
if (update.kind === "remove") {
|
|
64
|
+
pills.get(update.agentId)?.remove();
|
|
65
|
+
pills.delete(update.agentId);
|
|
66
|
+
} else registerAgent(update.agent as AgentLike);
|
|
67
|
+
},
|
|
68
|
+
});
|
|
69
|
+
return undefined;
|
|
70
|
+
})
|
|
71
|
+
.catch((error: Error) => {
|
|
72
|
+
if (!lifetime.signal.aborted) console.error("[laoshi] 读取 agent 列表失败", error);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// ----- header buttons on workspaces with requirements
|
|
76
|
+
const refreshHeaders = () => {
|
|
77
|
+
for (const [id, ws] of workspaces) {
|
|
78
|
+
const mine = inWorkspace(requirements, ws.workspaceDirectory ?? ws.projectRootPath, id);
|
|
79
|
+
const existing = headers.get(id);
|
|
80
|
+
if (mine.length === 0) {
|
|
81
|
+
existing?.remove();
|
|
82
|
+
headers.delete(id);
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const waiting = mine.filter((r) => r.attention).length;
|
|
86
|
+
const label = waiting > 0 ? `需求 · 待处理 ${waiting}` : `需求 ${mine.length}`;
|
|
87
|
+
if (existing) existing.update({ label });
|
|
88
|
+
else
|
|
89
|
+
headers.set(
|
|
90
|
+
id,
|
|
91
|
+
client.addHeaderButton({
|
|
92
|
+
id: "requirements",
|
|
93
|
+
workspaceId: id,
|
|
94
|
+
button: {
|
|
95
|
+
title: "这个工作区的需求",
|
|
96
|
+
icon: "ClipboardList",
|
|
97
|
+
label,
|
|
98
|
+
behavior: { kind: "action", onPress: () => client.openPanel("requirements", { workspaceId: id }) },
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
for (const [id, button] of headers) {
|
|
104
|
+
if (!workspaces.has(id)) {
|
|
105
|
+
button.remove();
|
|
106
|
+
headers.delete(id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
const poll = async () => {
|
|
111
|
+
try {
|
|
112
|
+
requirements = await client.rpc(listRpc, {});
|
|
113
|
+
refreshHeaders();
|
|
114
|
+
} catch {
|
|
115
|
+
// laoshi missing or too old: the overview explains; no header buttons meanwhile.
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
let releaseWorkspaces: (() => void) | null = null;
|
|
119
|
+
void client.paseo.workspaces
|
|
120
|
+
.list({ subscribe: {} })
|
|
121
|
+
.then(({ subscription }) => {
|
|
122
|
+
// The workspace list takes no abort signal: release it here or at cleanup.
|
|
123
|
+
releaseWorkspaces = () => void subscription.release().catch(() => undefined);
|
|
124
|
+
if (lifetime.signal.aborted) {
|
|
125
|
+
releaseWorkspaces();
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
subscription.subscribe({
|
|
129
|
+
snapshot: ({ entries }) => {
|
|
130
|
+
workspaces.clear();
|
|
131
|
+
for (const ws of entries) workspaces.set(ws.id, ws as WorkspaceLike);
|
|
132
|
+
refreshHeaders();
|
|
133
|
+
},
|
|
134
|
+
update: (message) => {
|
|
135
|
+
if (message.type !== "workspace_update") return;
|
|
136
|
+
const update = message.payload as { kind: string; workspace?: WorkspaceLike; workspaceId?: string; id?: string };
|
|
137
|
+
if (update.kind === "upsert" && update.workspace) workspaces.set(update.workspace.id, update.workspace);
|
|
138
|
+
else {
|
|
139
|
+
const id = update.workspaceId ?? update.id;
|
|
140
|
+
if (id) workspaces.delete(id);
|
|
141
|
+
}
|
|
142
|
+
refreshHeaders();
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
return undefined;
|
|
146
|
+
})
|
|
147
|
+
.catch((error: Error) => {
|
|
148
|
+
if (!lifetime.signal.aborted) console.error("[laoshi] 读取工作区列表失败", error);
|
|
149
|
+
});
|
|
150
|
+
void poll();
|
|
151
|
+
const timer = setInterval(() => void poll(), 30_000);
|
|
152
|
+
|
|
153
|
+
return () => {
|
|
154
|
+
lifetime.abort();
|
|
155
|
+
releaseWorkspaces?.();
|
|
156
|
+
clearInterval(timer);
|
|
157
|
+
for (const b of [...pills.values(), ...headers.values()]) b.remove();
|
|
158
|
+
pills.clear();
|
|
159
|
+
headers.clear();
|
|
160
|
+
};
|
|
161
|
+
}
|