@yiyi_zhang/laoshi 0.2.0 → 0.3.0
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 +21 -0
- package/README.md +3 -2
- package/adapters/dsh/adapter.ts +22 -1
- package/adapters/dsh/dsh-runtime.ts +14 -3
- package/adapters/dsh/install.mjs +16 -4
- package/adapters/dsh/plugin/index.mjs +197 -18
- package/adapters/dsh/plugin/package.json +1 -1
- package/adapters/mogao/adapter.ts +9 -1
- package/adapters/mogao/mogao-runtime.ts +30 -8
- package/adapters/paseo/install.mjs +13 -4
- package/adapters/paseo/plugin/client/data.ts +13 -2
- package/adapters/paseo/plugin/client/detail.tsx +244 -4
- package/adapters/paseo/plugin/client/format.ts +25 -117
- package/adapters/paseo/plugin/client/overview.tsx +3 -3
- package/adapters/paseo/plugin/index.server.ts +2 -1
- package/adapters/paseo/plugin/package.json +1 -1
- package/adapters/paseo/plugin/paseo-plugin.json +1 -1
- package/adapters/paseo/plugin/server/handlers.ts +22 -4
- package/adapters/paseo/plugin/server/req.ts +17 -4
- package/adapters/paseo/plugin/shared/contracts.ts +28 -2
- package/adapters/paseo/plugin/shared/view-model.ts +425 -0
- package/bin/req.mjs +10 -0
- package/contracts/cli-json.md +3 -1
- package/docs/design/dsh-adapter.md +9 -9
- package/docs/design/shared-ui.md +43 -0
- package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +13 -8
- package/docs/guide//347/234/237/345/256/236/347/216/257/345/242/203/350/265/260/346/237/245.md +78 -0
- package/engine/src/api.ts +11 -2
- package/engine/src/board.ts +435 -0
- package/engine/src/config.ts +23 -0
- package/engine/src/doctor.ts +25 -0
- package/engine/src/estimate.ts +11 -0
- package/engine/src/extensions.ts +271 -0
- package/engine/src/handover-cmd.ts +47 -0
- package/engine/src/handover.ts +89 -0
- package/engine/src/history.ts +102 -0
- package/engine/src/joint.ts +49 -4
- package/engine/src/launch.ts +2 -1
- package/engine/src/main.ts +1 -1
- package/engine/src/messages.ts +58 -0
- package/engine/src/pipeline.ts +109 -4
- package/engine/src/reply.ts +27 -6
- package/engine/src/semver.ts +21 -0
- package/package.json +5 -2
- package/site-dist/404.html +2 -2
- package/site-dist/assets/{app.BxNgGFu-.js → app.DZpVs0VH.js} +1 -1
- package/site-dist/assets/changelog.md.CdUYbro4.js +1 -0
- package/site-dist/assets/{changelog.md.D0PzSXw9.lean.js → changelog.md.CdUYbro4.lean.js} +1 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.CHr-ITwS.js +1 -0
- package/site-dist/assets/chunks/{VPLocalSearchBox.Dw_fzw9V.js → VPLocalSearchBox.BHkmziy1.js} +1 -1
- package/site-dist/assets/chunks/{theme.CwrnT4KI.js → theme.BsPChbDE.js} +2 -2
- package/site-dist/assets/guide_dsh.md.D0XhcUHz.js +7 -0
- package/site-dist/assets/guide_dsh.md.D0XhcUHz.lean.js +7 -0
- package/site-dist/assets/{guide_getting-started.md.CjzysdDe.js → guide_getting-started.md.BDd3nU5n.js} +1 -1
- package/site-dist/assets/{guide_install.md.By4WxsJG.js → guide_install.md.SsIHMfUu.js} +7 -5
- package/site-dist/assets/{guide_install.md.By4WxsJG.lean.js → guide_install.md.SsIHMfUu.lean.js} +7 -5
- package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.js +5 -0
- package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.lean.js +5 -0
- package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.lean.js +1 -0
- package/site-dist/changelog.html +5 -5
- package/site-dist/guide/cli.html +4 -4
- package/site-dist/guide/dsh.html +8 -6
- 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 +11 -9
- package/site-dist/guide/intranet.html +4 -4
- package/site-dist/guide/maintainer.html +4 -4
- package/site-dist/guide/mogao.html +4 -4
- package/site-dist/guide/phases.html +4 -4
- package/site-dist/guide/project.html +4 -4
- package/site-dist/guide/user.html +4 -4
- package/site-dist/guide/walkthrough.html +34 -0
- 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 +4 -4
- 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 +4 -4
- package/site-dist/reference/contracts/notifier-event.html +4 -4
- 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 +4 -4
- package/site-dist/reference/contracts/usage-record.html +4 -4
- package/site-dist/reference/contracts/verify.html +4 -4
- package/site-dist/reference/design/adapter-guide.html +4 -4
- 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 +4 -4
- package/site-dist/reference/design/platform-vocabulary.html +4 -4
- package/site-dist/reference/scope.html +4 -4
- package/skills/laoshi-setup/SKILL.md +1 -1
- package/ui/shared/view-model.ts +424 -0
- package/ui/web/board.ts +1126 -0
- package/site-dist/assets/changelog.md.D0PzSXw9.js +0 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.vA-yiw-8.js +0 -1
- package/site-dist/assets/guide_dsh.md.0X-eYB87.js +0 -5
- package/site-dist/assets/guide_dsh.md.0X-eYB87.lean.js +0 -5
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +0 -1
- /package/site-dist/assets/{guide_getting-started.md.CjzysdDe.lean.js → guide_getting-started.md.BDd3nU5n.lean.js} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Data hooks: every read is an RPC to the daemon side (laoshi api), cached by React Query.
|
|
2
2
|
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
3
|
import { useRpc, useSettings } from "@getpaseo/plugin/client";
|
|
4
|
-
import { configRpc, fileRpc, listRpc, modelsRpc, preferences, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, statusRpc, versionRpc, type Action, type AgentProfileData } from "../shared/contracts";
|
|
4
|
+
import { configRpc, fileRpc, historyRpc, listRpc, modelsRpc, preferences, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, statusRpc, versionRpc, type Action, type AgentProfileData } from "../shared/contracts";
|
|
5
5
|
|
|
6
6
|
export function usePreferences(): { readOnly: boolean; refreshMs: number } {
|
|
7
7
|
const settings = useSettings(preferences);
|
|
@@ -26,6 +26,17 @@ export function useRequirement(repo: string, featureDir: string) {
|
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export function useHistory(repo: string, featureDir: string) {
|
|
30
|
+
const history = useRpc(historyRpc);
|
|
31
|
+
const { refreshMs } = usePreferences();
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ["req", "history", repo, featureDir],
|
|
34
|
+
queryFn: () => history({ repo, featureDir }),
|
|
35
|
+
refetchInterval: refreshMs,
|
|
36
|
+
enabled: Boolean(repo && featureDir),
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
29
40
|
export function useDocument(repo: string, featureDir: string, file: string | null) {
|
|
30
41
|
const read = useRpc(fileRpc);
|
|
31
42
|
return useQuery({
|
|
@@ -49,7 +60,7 @@ export function useAction() {
|
|
|
49
60
|
const run = useRpc(runRpc);
|
|
50
61
|
const queries = useQueryClient();
|
|
51
62
|
return useMutation({
|
|
52
|
-
mutationFn: (input: { action: Action; repo: string; featureDir: string; verifyEnv?: "local" | "deployed"; text?: string }) => run(input),
|
|
63
|
+
mutationFn: (input: { action: Action; repo: string; featureDir: string; verifyEnv?: "local" | "deployed"; text?: string; to?: string; note?: string }) => run(input),
|
|
53
64
|
onSettled: () => queries.invalidateQueries({ queryKey: ["req"] }),
|
|
54
65
|
});
|
|
55
66
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// One requirement: where it stands, its steps, the quality gate, its documents, and the
|
|
2
2
|
// management actions (each one is `req <command>` on the daemon machine, after confirming).
|
|
3
3
|
import type { PluginHostProps, PluginScreenProps, PluginSurfaceProps } from "@getpaseo/plugin/client";
|
|
4
|
-
import { Modal, ScrollView, useToast } from "@getpaseo/plugin/client/react-native";
|
|
4
|
+
import { Modal, ScrollView, TextInput, useToast } from "@getpaseo/plugin/client/react-native";
|
|
5
5
|
import { ExternalLink } from "@getpaseo/plugin/client/ui";
|
|
6
6
|
import { useState } from "react";
|
|
7
7
|
import { Pressable, Text, View } from "react-native";
|
|
8
8
|
import type { Action, RequirementDetail, Step } from "../shared/contracts";
|
|
9
|
-
import { useAction, useDocument, usePreferences, useRequirement, useRequirements } from "./data";
|
|
9
|
+
import { useAction, useDocument, useHistory, usePreferences, useRequirement, useRequirements } from "./data";
|
|
10
10
|
import { ACTION_TEXT, actionsFor, ago, ATTENTION_LABELS, facts, FILE_LABELS, minutes, tokens, trackOf } from "./format";
|
|
11
11
|
import { Markdown, tsvToMarkdown } from "./markdown";
|
|
12
12
|
import { ChecklistButton, CodeReviewButton, ReviewButton } from "./review";
|
|
@@ -126,6 +126,234 @@ function ActionModal({
|
|
|
126
126
|
);
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
+
function ChangeModal({
|
|
130
|
+
theme,
|
|
131
|
+
layout,
|
|
132
|
+
detail,
|
|
133
|
+
open,
|
|
134
|
+
onClose,
|
|
135
|
+
}: {
|
|
136
|
+
theme: Theme;
|
|
137
|
+
layout: Layout;
|
|
138
|
+
detail: RequirementDetail;
|
|
139
|
+
open: boolean;
|
|
140
|
+
onClose(): void;
|
|
141
|
+
}) {
|
|
142
|
+
const s = useStyles(theme, layout.compact);
|
|
143
|
+
const run = useAction();
|
|
144
|
+
const toast = useToast();
|
|
145
|
+
const [text, setText] = useState("");
|
|
146
|
+
const submit = async () => {
|
|
147
|
+
const trimmed = text.trim();
|
|
148
|
+
if (!trimmed) {
|
|
149
|
+
toast.error("请先写下要修改的需求内容");
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const result = await run.mutateAsync({ action: "change", repo: detail.sourceRepo ?? detail.repo, featureDir: detail.featureDir, text: trimmed });
|
|
154
|
+
const first = result.message.split("\n").find((l) => l.trim()) ?? "";
|
|
155
|
+
if (result.ok) {
|
|
156
|
+
toast.show(first || "已发送改需求通知", { variant: "success", durationMs: 4000 });
|
|
157
|
+
setText("");
|
|
158
|
+
onClose();
|
|
159
|
+
} else {
|
|
160
|
+
toast.error(first || "发送失败");
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
toast.error((error as Error).message);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
return (
|
|
167
|
+
<Modal title={`发起改需求:${detail.title}`} open={open} onOpenChange={(next) => (next ? undefined : onClose())}>
|
|
168
|
+
<Modal.Content>
|
|
169
|
+
<Text style={s.text}>{ACTION_TEXT.change.confirm}</Text>
|
|
170
|
+
<TextInput
|
|
171
|
+
value={text}
|
|
172
|
+
onChangeText={setText}
|
|
173
|
+
multiline
|
|
174
|
+
placeholder="描述要调整的功能、字段或验收标准…"
|
|
175
|
+
placeholderTextColor={theme.colors.foregroundMuted}
|
|
176
|
+
style={{
|
|
177
|
+
minHeight: 88,
|
|
178
|
+
padding: 10,
|
|
179
|
+
borderRadius: 8,
|
|
180
|
+
borderWidth: 1,
|
|
181
|
+
borderColor: theme.colors.border,
|
|
182
|
+
backgroundColor: theme.colors.surface0,
|
|
183
|
+
color: theme.colors.foreground,
|
|
184
|
+
fontSize: 14,
|
|
185
|
+
textAlignVertical: "top",
|
|
186
|
+
}}
|
|
187
|
+
/>
|
|
188
|
+
<View style={s.row}>
|
|
189
|
+
<Button theme={theme} primary label={run.isPending ? "正在发送…" : "确认发起"} disabled={run.isPending || !text.trim()} onPress={() => void submit()} />
|
|
190
|
+
<Button theme={theme} label="取消" disabled={run.isPending} onPress={onClose} />
|
|
191
|
+
</View>
|
|
192
|
+
</Modal.Content>
|
|
193
|
+
</Modal>
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function HandoverModal({
|
|
198
|
+
theme,
|
|
199
|
+
layout,
|
|
200
|
+
detail,
|
|
201
|
+
open,
|
|
202
|
+
onClose,
|
|
203
|
+
}: {
|
|
204
|
+
theme: Theme;
|
|
205
|
+
layout: Layout;
|
|
206
|
+
detail: RequirementDetail;
|
|
207
|
+
open: boolean;
|
|
208
|
+
onClose(): void;
|
|
209
|
+
}) {
|
|
210
|
+
const s = useStyles(theme, layout.compact);
|
|
211
|
+
const run = useAction();
|
|
212
|
+
const toast = useToast();
|
|
213
|
+
const [to, setTo] = useState("");
|
|
214
|
+
const [note, setNote] = useState("");
|
|
215
|
+
const inputStyle = {
|
|
216
|
+
padding: 10,
|
|
217
|
+
borderRadius: 8,
|
|
218
|
+
borderWidth: 1,
|
|
219
|
+
borderColor: theme.colors.border,
|
|
220
|
+
backgroundColor: theme.colors.surface0,
|
|
221
|
+
color: theme.colors.foreground,
|
|
222
|
+
fontSize: 14,
|
|
223
|
+
};
|
|
224
|
+
const submit = async () => {
|
|
225
|
+
const trimmed = to.trim();
|
|
226
|
+
if (!trimmed) {
|
|
227
|
+
toast.error("请填写接手人");
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
try {
|
|
231
|
+
const result = await run.mutateAsync({
|
|
232
|
+
action: "handover",
|
|
233
|
+
repo: detail.sourceRepo ?? detail.repo,
|
|
234
|
+
featureDir: detail.featureDir,
|
|
235
|
+
to: trimmed,
|
|
236
|
+
note: note.trim() || undefined,
|
|
237
|
+
});
|
|
238
|
+
const first = result.message.split("\n").find((l) => l.trim()) ?? "";
|
|
239
|
+
if (result.ok) {
|
|
240
|
+
toast.show(first || "已转交", { variant: "success", durationMs: 4000 });
|
|
241
|
+
setTo("");
|
|
242
|
+
setNote("");
|
|
243
|
+
onClose();
|
|
244
|
+
} else {
|
|
245
|
+
toast.error(first || "转交失败");
|
|
246
|
+
}
|
|
247
|
+
} catch (error) {
|
|
248
|
+
toast.error((error as Error).message);
|
|
249
|
+
}
|
|
250
|
+
};
|
|
251
|
+
return (
|
|
252
|
+
<Modal title={`转交需求:${detail.title}`} open={open} onOpenChange={(next) => (next ? undefined : onClose())}>
|
|
253
|
+
<Modal.Content>
|
|
254
|
+
<Text style={s.text}>{ACTION_TEXT.handover.confirm}</Text>
|
|
255
|
+
<TextInput value={to} onChangeText={setTo} placeholder="接手人姓名或账号" placeholderTextColor={theme.colors.foregroundMuted} style={inputStyle} />
|
|
256
|
+
<TextInput value={note} onChangeText={setNote} placeholder="交接说明(可选,例如:请跟进验收阶段)" placeholderTextColor={theme.colors.foregroundMuted} style={inputStyle} />
|
|
257
|
+
<View style={s.row}>
|
|
258
|
+
<Button theme={theme} primary label={run.isPending ? "正在转交…" : "确认转交"} disabled={run.isPending || !to.trim()} onPress={() => void submit()} />
|
|
259
|
+
<Button theme={theme} label="取消" disabled={run.isPending} onPress={onClose} />
|
|
260
|
+
</View>
|
|
261
|
+
</Modal.Content>
|
|
262
|
+
</Modal>
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function HistorySection({ theme, layout, detail }: { theme: Theme; layout: Layout; detail: RequirementDetail }) {
|
|
267
|
+
const s = useStyles(theme, layout.compact);
|
|
268
|
+
const c = rk(theme);
|
|
269
|
+
const history = useHistory(detail.repo, detail.featureDir);
|
|
270
|
+
const [openChange, setOpenChange] = useState<number | null>(null);
|
|
271
|
+
const [openCommit, setOpenCommit] = useState<string | null>(null);
|
|
272
|
+
const h = history.data;
|
|
273
|
+
const ownerName = h?.owner.owner ?? detail.owner ?? detail.startedBy ?? "未指定";
|
|
274
|
+
return (
|
|
275
|
+
<View style={s.card}>
|
|
276
|
+
<Text style={s.heading}>变更历史与负责人</Text>
|
|
277
|
+
<Text style={s.text}>
|
|
278
|
+
当前负责人:{ownerName} · 需求说明版本:{h?.specVersion ? `v${h.specVersion}` : "未标注"}
|
|
279
|
+
</Text>
|
|
280
|
+
{h && h.owner.history.length > 0 ? (
|
|
281
|
+
<Text style={s.muted}>
|
|
282
|
+
最近转交:{h.owner.history.at(-1)!.from ?? "未指定"} → {h.owner.history.at(-1)!.to}
|
|
283
|
+
{h.owner.history.at(-1)!.note ? `(${h.owner.history.at(-1)!.note})` : ""}
|
|
284
|
+
</Text>
|
|
285
|
+
) : null}
|
|
286
|
+
<Status theme={theme} loading={history.isPending} error={history.error} />
|
|
287
|
+
{h && h.changes.length > 0 ? (
|
|
288
|
+
<View style={{ gap: 6, marginTop: 4 }}>
|
|
289
|
+
<Text style={s.muted}>变更记录({h.changes.length} 项)</Text>
|
|
290
|
+
{h.changes.map((ch, idx) => (
|
|
291
|
+
<View key={`${ch.title}-${idx}`} style={{ borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border, padding: 8, gap: 4 }}>
|
|
292
|
+
<Pressable accessibilityRole="button" onPress={() => setOpenChange(openChange === idx ? null : idx)}>
|
|
293
|
+
<View style={s.row}>
|
|
294
|
+
<Text style={[s.text, { flex: 1, fontWeight: "600" }]}>{ch.title}</Text>
|
|
295
|
+
<Text style={s.muted}>{openChange === idx ? "收起" : "展开"}</Text>
|
|
296
|
+
</View>
|
|
297
|
+
</Pressable>
|
|
298
|
+
{openChange === idx && ch.body ? <Text style={s.mono}>{ch.body}</Text> : null}
|
|
299
|
+
</View>
|
|
300
|
+
))}
|
|
301
|
+
</View>
|
|
302
|
+
) : null}
|
|
303
|
+
{h && h.commits.length > 0 ? (
|
|
304
|
+
<View style={{ gap: 6, marginTop: 4 }}>
|
|
305
|
+
<Text style={s.muted}>需求说明修改历史({h.commits.length} 次提交)</Text>
|
|
306
|
+
{h.commits.map((cm) => {
|
|
307
|
+
const opened = openCommit === cm.commit;
|
|
308
|
+
const day = cm.date ? cm.date.slice(0, 16).replace("T", " ") : "";
|
|
309
|
+
return (
|
|
310
|
+
<View key={cm.commit} style={{ borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border, padding: 8, gap: 4 }}>
|
|
311
|
+
<Pressable accessibilityRole="button" onPress={() => setOpenCommit(opened ? null : cm.commit)}>
|
|
312
|
+
<View style={s.row}>
|
|
313
|
+
<Text style={[s.text, { flex: 1 }]}>
|
|
314
|
+
{day ? `${day} · ` : ""}
|
|
315
|
+
{cm.author ? `${cm.author} · ` : ""}
|
|
316
|
+
{cm.subject || cm.commit.slice(0, 7)}
|
|
317
|
+
</Text>
|
|
318
|
+
<Text style={s.muted}>{opened ? "收起差异" : "查看差异"}</Text>
|
|
319
|
+
</View>
|
|
320
|
+
</Pressable>
|
|
321
|
+
{opened && cm.diff ? (
|
|
322
|
+
<View style={{ borderRadius: 6, backgroundColor: theme.colors.surface0, padding: 6, gap: 1 }}>
|
|
323
|
+
{cm.diff.split(/\r?\n/).map((line, li) => {
|
|
324
|
+
const isAdd = line.startsWith("+") && !line.startsWith("+++");
|
|
325
|
+
const isDel = line.startsWith("-") && !line.startsWith("---");
|
|
326
|
+
const isHunk = line.startsWith("@@");
|
|
327
|
+
return (
|
|
328
|
+
<Text
|
|
329
|
+
key={li}
|
|
330
|
+
style={[
|
|
331
|
+
s.mono,
|
|
332
|
+
isAdd
|
|
333
|
+
? { color: theme.colors.statusSuccess, backgroundColor: c.successTint }
|
|
334
|
+
: isDel
|
|
335
|
+
? { color: theme.colors.statusDanger, backgroundColor: c.failedTint }
|
|
336
|
+
: isHunk
|
|
337
|
+
? { color: c.data }
|
|
338
|
+
: undefined,
|
|
339
|
+
]}
|
|
340
|
+
>
|
|
341
|
+
{line || " "}
|
|
342
|
+
</Text>
|
|
343
|
+
);
|
|
344
|
+
})}
|
|
345
|
+
{cm.truncated ? <Text style={s.muted}>差异内容较长,已截断至 20000 字符。</Text> : null}
|
|
346
|
+
</View>
|
|
347
|
+
) : null}
|
|
348
|
+
</View>
|
|
349
|
+
);
|
|
350
|
+
})}
|
|
351
|
+
</View>
|
|
352
|
+
) : null}
|
|
353
|
+
</View>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
129
357
|
function GateSummary({ theme, layout, detail }: { theme: Theme; layout: Layout; detail: RequirementDetail }) {
|
|
130
358
|
const s = useStyles(theme, layout.compact);
|
|
131
359
|
const runs = [...(detail.gate?.runs ?? []), ...detail.joint.flatMap((j) => j.gate?.runs ?? [])];
|
|
@@ -163,6 +391,8 @@ export function RequirementView({
|
|
|
163
391
|
const { readOnly } = usePreferences();
|
|
164
392
|
const [doc, setDoc] = useState<string | null>(null);
|
|
165
393
|
const [action, setAction] = useState<Action | null>(null);
|
|
394
|
+
const [changeOpen, setChangeOpen] = useState(false);
|
|
395
|
+
const [handoverOpen, setHandoverOpen] = useState(false);
|
|
166
396
|
const [allSteps, setAllSteps] = useState(false);
|
|
167
397
|
const d = query.data;
|
|
168
398
|
if (!d) return <Status theme={theme} loading={query.isPending} error={query.error} />;
|
|
@@ -205,7 +435,10 @@ export function RequirementView({
|
|
|
205
435
|
) : null}
|
|
206
436
|
</View>
|
|
207
437
|
<StepTrack theme={theme} steps={trackOf(d, hr)} />
|
|
208
|
-
<Text style={s.muted}>
|
|
438
|
+
<Text style={s.muted}>
|
|
439
|
+
{facts(d)}
|
|
440
|
+
{d.owner ? ` · 负责人:${d.owner}` : ""}
|
|
441
|
+
</Text>
|
|
209
442
|
<Text style={[s.text, { color: d.attention ? c.brandText : theme.colors.foreground }]}>{d.stage}</Text>
|
|
210
443
|
{d.estimate && d.attention !== "approval" ? (
|
|
211
444
|
<Text style={s.muted}>
|
|
@@ -220,14 +453,18 @@ export function RequirementView({
|
|
|
220
453
|
{d.attention === "business" ? <Text style={s.muted}>需求方的决定请在发起需求的对话中回答,回答后再继续。</Text> : null}
|
|
221
454
|
</View>
|
|
222
455
|
|
|
223
|
-
{actions.length > 0 || d.hasPrototype || canAccept || canReviewCode ? (
|
|
456
|
+
{actions.length > 0 || d.hasPrototype || canAccept || canReviewCode || !readOnly ? (
|
|
224
457
|
<View style={s.row}>
|
|
225
458
|
{canReviewCode ? <CodeReviewButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} label={reviewLabel} primary={primary === "code"} /> : null}
|
|
226
459
|
{canAccept ? <ChecklistButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} primary={primary === "check"} /> : null}
|
|
460
|
+
{canAccept && !readOnly ? <Button theme={theme} label={ACTION_TEXT.try.label} onPress={() => setAction("try")} /> : null}
|
|
461
|
+
{canAccept && !readOnly ? <Button theme={theme} label={ACTION_TEXT["try-stop"].label} onPress={() => setAction("try-stop")} /> : null}
|
|
227
462
|
{d.hasPrototype ? <ReviewButton theme={theme} repo={d.sourceRepo ?? d.repo} featureDir={d.featureDir} title={d.title} waiting={primary === "review"} /> : null}
|
|
228
463
|
{actions.map((a) => (
|
|
229
464
|
<Button key={a} theme={theme} primary={primary === a} label={ACTION_TEXT[a].label} onPress={() => setAction(a)} />
|
|
230
465
|
))}
|
|
466
|
+
{!readOnly ? <Button theme={theme} label={ACTION_TEXT.change.label} onPress={() => setChangeOpen(true)} /> : null}
|
|
467
|
+
{!readOnly ? <Button theme={theme} label={ACTION_TEXT.handover.label} onPress={() => setHandoverOpen(true)} /> : null}
|
|
231
468
|
</View>
|
|
232
469
|
) : null}
|
|
233
470
|
|
|
@@ -300,6 +537,7 @@ export function RequirementView({
|
|
|
300
537
|
) : null}
|
|
301
538
|
|
|
302
539
|
<GateSummary theme={theme} layout={layout} detail={d} />
|
|
540
|
+
<HistorySection theme={theme} layout={layout} detail={d} />
|
|
303
541
|
|
|
304
542
|
{d.steps.length > 0 ? (
|
|
305
543
|
<View style={s.card}>
|
|
@@ -315,6 +553,8 @@ export function RequirementView({
|
|
|
315
553
|
|
|
316
554
|
<DocumentModal theme={theme} layout={layout} repo={d.repo} featureDir={d.featureDir} file={doc} onClose={() => setDoc(null)} />
|
|
317
555
|
<ActionModal theme={theme} layout={layout} detail={d} action={action} onClose={() => setAction(null)} />
|
|
556
|
+
<ChangeModal theme={theme} layout={layout} detail={d} open={changeOpen} onClose={() => setChangeOpen(false)} />
|
|
557
|
+
<HandoverModal theme={theme} layout={layout} detail={d} open={handoverOpen} onClose={() => setHandoverOpen(false)} />
|
|
318
558
|
</View>
|
|
319
559
|
);
|
|
320
560
|
}
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
// Plain-language labels, shared by every screen.
|
|
2
|
-
import type {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
// Plain-language labels, shared by every screen (re-exporting ui/shared/view-model).
|
|
2
|
+
import type { Requirement } from "../shared/contracts";
|
|
3
|
+
export {
|
|
4
|
+
ago,
|
|
5
|
+
ATTENTION_LABELS,
|
|
6
|
+
type Group,
|
|
7
|
+
GROUP_EYEBROWS,
|
|
8
|
+
GROUP_LABELS,
|
|
9
|
+
groupOf,
|
|
10
|
+
iconOf,
|
|
11
|
+
minutes,
|
|
12
|
+
PROFILE_LABELS,
|
|
13
|
+
tokens,
|
|
14
|
+
TRACK,
|
|
15
|
+
trackOf,
|
|
16
|
+
TYPE_LABELS,
|
|
17
|
+
} from "../shared/view-model";
|
|
16
18
|
|
|
17
19
|
export const FILE_LABELS: Record<string, string> = {
|
|
18
20
|
"spec.md": "需求说明",
|
|
@@ -37,51 +39,9 @@ export const FILE_LABELS: Record<string, string> = {
|
|
|
37
39
|
"lessons.tsv": "可以变成规则的问题",
|
|
38
40
|
};
|
|
39
41
|
|
|
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
42
|
/** One line under a requirement's title: project, type, stage. */
|
|
83
43
|
export function facts(r: Requirement): string {
|
|
84
|
-
return [r.project, r.type ?
|
|
44
|
+
return [r.project, r.type ? ({ defect: "缺陷", refactor: "重构", assessment: "评估" }[r.type] ?? r.type) : null, r.profile ? ({ quick: "快速档", standard: "标准档" }[r.profile] ?? r.profile) : null]
|
|
85
45
|
.filter(Boolean)
|
|
86
46
|
.join(" · ");
|
|
87
47
|
}
|
|
@@ -98,9 +58,9 @@ export function actionsFor(
|
|
|
98
58
|
? ["resume"]
|
|
99
59
|
: r.attention === "not_started"
|
|
100
60
|
? ["start"]
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
61
|
+
: r.status === "phase_done"
|
|
62
|
+
? ["verify"]
|
|
63
|
+
: [];
|
|
104
64
|
// A running pipeline sends what failed by itself at its next step change.
|
|
105
65
|
if (!r.running && r.status && (r.external ?? []).some((e) => e.pending > 0 || !e.id)) base.push("sync");
|
|
106
66
|
return base;
|
|
@@ -114,60 +74,8 @@ export const ACTION_TEXT = {
|
|
|
114
74
|
verify: { label: "开始测试验证", confirm: "开始测试验证?选择在哪里验证。" },
|
|
115
75
|
sync: { label: "同步到外部系统", confirm: "把这个需求同步到对接的外部系统:补发没有成功的调用、补建卡片、更新状态。" },
|
|
116
76
|
reply: { label: "发送回复", confirm: "把回复转给这个需求的对话,由它更新需求说明并继续开发。" },
|
|
77
|
+
try: { label: "一键试用", confirm: "启动这个需求的服务,生成访问地址和测试数据供试用?" },
|
|
78
|
+
"try-stop": { label: "停止试用", confirm: "停止试用时启动的服务?" },
|
|
79
|
+
change: { label: "改需求", confirm: "把需求变更转给这个需求的对话:它会先停下流水线,和你确认变化并更新需求说明后继续。" },
|
|
80
|
+
handover: { label: "转交", confirm: "把当前需求的负责权转交给另一位同事。" },
|
|
117
81
|
} 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
|
-
}
|
|
@@ -5,15 +5,15 @@ import { useMemo, useState } from "react";
|
|
|
5
5
|
import { Text, View } from "react-native";
|
|
6
6
|
import type { Requirement } from "../shared/contracts";
|
|
7
7
|
import { useRequirements } from "./data";
|
|
8
|
-
import { type Group, GROUP_LABELS, groupOf } from "./format";
|
|
8
|
+
import { type Group, GROUP_EYEBROWS, GROUP_LABELS, groupOf } from "./format";
|
|
9
9
|
import { Inbox } from "./inbox";
|
|
10
10
|
import { RequirementRow } from "./row";
|
|
11
11
|
import { BrandHeader, Button, Chip, Eyebrow, Status, useStyles } from "./ui";
|
|
12
12
|
|
|
13
13
|
export const ORDER: Group[] = ["attention", "running", "verify", "done", "other"];
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
const EYEBROW: Record<Group, string> =
|
|
15
|
+
/** Unified Chinese group headings (shared with dsh/Web board via ui/shared/view-model). */
|
|
16
|
+
const EYEBROW: Record<Group, string> = GROUP_EYEBROWS;
|
|
17
17
|
|
|
18
18
|
/** Opens a requirement's detail screen. */
|
|
19
19
|
export type OpenRequirement = (item: Pick<Requirement, "repo" | "featureDir" | "title">) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PluginServerContext } from "@getpaseo/plugin/server";
|
|
2
|
-
import { configRpc, fileRpc, listRpc, modelsRpc, preferences, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, statusRpc, versionRpc } from "./shared/contracts";
|
|
2
|
+
import { configRpc, fileRpc, historyRpc, listRpc, modelsRpc, preferences, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, statusRpc, versionRpc } from "./shared/contracts";
|
|
3
3
|
import { createHandlers } from "./server/handlers";
|
|
4
4
|
import { kitHomeOf, reqApi } from "./server/req";
|
|
5
5
|
|
|
@@ -32,6 +32,7 @@ export default function contribute(server: PluginServerContext) {
|
|
|
32
32
|
server.handle(versionRpc, () => handlers.version());
|
|
33
33
|
server.handle(listRpc, () => handlers.list());
|
|
34
34
|
server.handle(statusRpc, (input) => handlers.status(input));
|
|
35
|
+
server.handle(historyRpc, (input) => handlers.history(input));
|
|
35
36
|
server.handle(fileRpc, (input) => handlers.file(input));
|
|
36
37
|
server.handle(statsRpc, (input) => handlers.stats(input));
|
|
37
38
|
server.handle(runRpc, (input) => handlers.run(input));
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
// The daemon side: each RPC is one `laoshi api` call. Management actions are refused here too
|
|
2
2
|
// when the plugin is set to read-only, not only hidden in the app.
|
|
3
3
|
import type { RpcInput } from "@getpaseo/plugin";
|
|
4
|
-
import type { configRpc, ConfigViewData, fileRpc, KitInfo, ModelsData, Requirement, RequirementDetail, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, StatsSummary, statusRpc } from "../shared/contracts";
|
|
4
|
+
import type { configRpc, ConfigViewData, fileRpc, historyRpc, KitInfo, ModelsData, Requirement, RequirementDetail, RequirementHistory, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, StatsSummary, statusRpc } from "../shared/contracts";
|
|
5
5
|
import { coalesce, type ReqRunner } from "./req";
|
|
6
6
|
|
|
7
7
|
export interface Handlers {
|
|
8
8
|
version(): Promise<KitInfo>;
|
|
9
9
|
list(): Promise<Requirement[]>;
|
|
10
10
|
status(input: RpcInput<typeof statusRpc>): Promise<RequirementDetail>;
|
|
11
|
+
history(input: RpcInput<typeof historyRpc>): Promise<RequirementHistory>;
|
|
11
12
|
file(input: RpcInput<typeof fileRpc>): Promise<{ file: string; size: number; truncated: boolean; content: string }>;
|
|
12
13
|
stats(input: RpcInput<typeof statsRpc>): Promise<StatsSummary>;
|
|
13
14
|
run(input: RpcInput<typeof runRpc>): Promise<{ ok: boolean; message: string }>;
|
|
@@ -30,6 +31,9 @@ export function createHandlers(input: { req: ReqRunner; kitHome: () => string; r
|
|
|
30
31
|
async status({ repo, featureDir }) {
|
|
31
32
|
return (await req(["status", featureDir, "--repo", repo])) as RequirementDetail;
|
|
32
33
|
},
|
|
34
|
+
async history({ repo, featureDir }) {
|
|
35
|
+
return (await req(["history", featureDir, "--repo", repo])) as RequirementHistory;
|
|
36
|
+
},
|
|
33
37
|
async file({ repo, featureDir, file }) {
|
|
34
38
|
return (await req(["file", featureDir, file, "--repo", repo])) as { file: string; size: number; truncated: boolean; content: string };
|
|
35
39
|
},
|
|
@@ -39,11 +43,25 @@ export function createHandlers(input: { req: ReqRunner; kitHome: () => string; r
|
|
|
39
43
|
else if (since) args.push("--since", since);
|
|
40
44
|
return (await req(args)) as StatsSummary;
|
|
41
45
|
},
|
|
42
|
-
async run({ action, repo, featureDir, verifyEnv, text }) {
|
|
46
|
+
async run({ action, repo, featureDir, verifyEnv, text, to, note }) {
|
|
43
47
|
if (await input.readOnly()) return { ok: false, message: "插件设置为只读:不能在这里操作需求。可以在插件设置中关闭只读,或在终端用 req 命令。" };
|
|
44
48
|
if (action === "reply" && !text?.trim()) return { ok: false, message: "回复是空的" };
|
|
45
|
-
|
|
46
|
-
|
|
49
|
+
if (action === "change" && !text?.trim()) return { ok: false, message: "改动内容是空的" };
|
|
50
|
+
if (action === "handover" && !to?.trim()) return { ok: false, message: "接手人不能为空" };
|
|
51
|
+
const cmd = action === "try-stop" ? "try" : action === "change" ? "reply" : action;
|
|
52
|
+
const extra =
|
|
53
|
+
action === "verify" && verifyEnv
|
|
54
|
+
? ["--verify-env", verifyEnv]
|
|
55
|
+
: action === "reply"
|
|
56
|
+
? [text!.trim()]
|
|
57
|
+
: action === "change"
|
|
58
|
+
? ["--change", text!.trim()]
|
|
59
|
+
: action === "handover"
|
|
60
|
+
? [to!.trim(), ...(note?.trim() ? ["--note", note.trim()] : [])]
|
|
61
|
+
: action === "try-stop"
|
|
62
|
+
? ["--stop"]
|
|
63
|
+
: [];
|
|
64
|
+
const result = (await req(["run", cmd, featureDir, "--repo", repo, ...extra], { timeoutMs: 200_000 })) as { ok: boolean; message: string };
|
|
47
65
|
return { ok: result.ok, message: result.message };
|
|
48
66
|
},
|
|
49
67
|
async reviewUrl({ repo, featureDir, page }) {
|
|
@@ -15,16 +15,29 @@ export class ReqError extends Error {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
function defaultHere(): string | undefined {
|
|
19
|
+
// Paseo bundles server code to CJS and runs it via eval(), where import.meta.url is undefined.
|
|
20
|
+
try {
|
|
21
|
+
if (typeof import.meta !== "undefined" && import.meta.url) return path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
} catch {
|
|
23
|
+
// No module URL in bundled runtime; fall back to LAOSHI_HOME or ~/.laoshi.
|
|
24
|
+
}
|
|
25
|
+
return undefined;
|
|
26
|
+
}
|
|
27
|
+
|
|
18
28
|
/**
|
|
19
29
|
* laoshi's install root: the plugin setting, else LAOSHI_HOME, else the root the plugin is
|
|
20
30
|
* installed in (`laoshi plugin install` copies it to <install root>/paseo-plugin), else ~/.laoshi.
|
|
21
31
|
*/
|
|
22
|
-
export function kitHomeOf(configured: string, here: string =
|
|
23
|
-
|
|
32
|
+
export function kitHomeOf(configured: string, here: string | undefined = defaultHere()): string {
|
|
33
|
+
const manual = (configured ?? "").trim();
|
|
34
|
+
if (manual) return path.resolve(manual.replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
24
35
|
const env = process.env.LAOSHI_HOME?.trim();
|
|
25
36
|
if (env) return path.resolve(env);
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
if (here) {
|
|
38
|
+
const root = path.resolve(here, "..", "..");
|
|
39
|
+
if (path.basename(path.resolve(here, "..")) === "paseo-plugin" && fs.existsSync(path.join(root, "install.json"))) return root;
|
|
40
|
+
}
|
|
28
41
|
return path.join(os.homedir(), ".laoshi");
|
|
29
42
|
}
|
|
30
43
|
|