@yiyi_zhang/laoshi 0.2.0-beta.3 → 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.
Files changed (139) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/README.md +3 -2
  3. package/adapters/dsh/adapter.ts +22 -1
  4. package/adapters/dsh/dsh-runtime.ts +14 -3
  5. package/adapters/dsh/install.mjs +16 -4
  6. package/adapters/dsh/plugin/index.mjs +197 -18
  7. package/adapters/dsh/plugin/package.json +1 -1
  8. package/adapters/mogao/adapter.ts +10 -1
  9. package/adapters/mogao/mogao-runtime.ts +58 -23
  10. package/adapters/mogao/skill/setup.md +6 -0
  11. package/adapters/paseo/install.mjs +13 -4
  12. package/adapters/paseo/plugin/client/data.ts +13 -2
  13. package/adapters/paseo/plugin/client/detail.tsx +244 -4
  14. package/adapters/paseo/plugin/client/format.ts +25 -117
  15. package/adapters/paseo/plugin/client/overview.tsx +3 -3
  16. package/adapters/paseo/plugin/index.server.ts +2 -1
  17. package/adapters/paseo/plugin/package.json +1 -1
  18. package/adapters/paseo/plugin/paseo-plugin.json +1 -1
  19. package/adapters/paseo/plugin/server/handlers.ts +22 -4
  20. package/adapters/paseo/plugin/server/req.ts +17 -4
  21. package/adapters/paseo/plugin/shared/contracts.ts +28 -2
  22. package/adapters/paseo/plugin/shared/view-model.ts +425 -0
  23. package/bin/ensure-version.mjs +60 -0
  24. package/bin/req-doctor.mjs +5 -0
  25. package/bin/req.mjs +18 -0
  26. package/bin/start-pipeline.mjs +5 -0
  27. package/contracts/cli-json.md +3 -1
  28. package/docs/design/builtin-capabilities.md +2 -2
  29. package/docs/design/cli-adapter.md +1 -1
  30. package/docs/design/dsh-adapter.md +11 -11
  31. package/docs/design/shared-ui.md +43 -0
  32. package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +2 -1
  33. package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +13 -8
  34. package/docs/guide//347/234/237/345/256/236/347/216/257/345/242/203/350/265/260/346/237/245.md +78 -0
  35. package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +36 -6
  36. package/engine/prompts/00-shared-context.md +7 -0
  37. package/engine/prompts/03-design.md +2 -0
  38. package/engine/prompts/04-design-review.md +5 -1
  39. package/engine/skill-fragments/defaults.md +5 -0
  40. package/engine/src/api.ts +11 -2
  41. package/engine/src/board.ts +435 -0
  42. package/engine/src/config.ts +23 -0
  43. package/engine/src/diagnose.ts +238 -0
  44. package/engine/src/doctor.ts +25 -0
  45. package/engine/src/estimate.ts +11 -0
  46. package/engine/src/extensions.ts +271 -0
  47. package/engine/src/handover-cmd.ts +47 -0
  48. package/engine/src/handover.ts +89 -0
  49. package/engine/src/history.ts +102 -0
  50. package/engine/src/joint.ts +49 -4
  51. package/engine/src/launch.ts +20 -5
  52. package/engine/src/main.ts +1 -1
  53. package/engine/src/messages.ts +58 -0
  54. package/engine/src/pipeline.ts +121 -5
  55. package/engine/src/platform.ts +6 -0
  56. package/engine/src/reply.ts +27 -6
  57. package/engine/src/semver.ts +21 -0
  58. package/engine/src/skills-render.ts +10 -1
  59. package/package.json +5 -2
  60. package/site-dist/404.html +2 -2
  61. package/site-dist/assets/{app.CXydUhZx.js → app.DZpVs0VH.js} +1 -1
  62. package/site-dist/assets/changelog.md.CdUYbro4.js +1 -0
  63. package/site-dist/assets/{changelog.md.BU-CvyJ1.lean.js → changelog.md.CdUYbro4.lean.js} +1 -1
  64. package/site-dist/assets/chunks/@localSearchIndexroot.CHr-ITwS.js +1 -0
  65. package/site-dist/assets/chunks/{VPLocalSearchBox.CIjDV0ax.js → VPLocalSearchBox.BHkmziy1.js} +1 -1
  66. package/site-dist/assets/chunks/{theme.CWtC1Kby.js → theme.BsPChbDE.js} +2 -2
  67. package/site-dist/assets/guide_dsh.md.D0XhcUHz.js +7 -0
  68. package/site-dist/assets/guide_dsh.md.D0XhcUHz.lean.js +7 -0
  69. package/site-dist/assets/{guide_getting-started.md.BxOxfic_.js → guide_getting-started.md.BDd3nU5n.js} +1 -1
  70. package/site-dist/assets/{guide_install.md.By4WxsJG.js → guide_install.md.SsIHMfUu.js} +7 -5
  71. package/site-dist/assets/{guide_install.md.By4WxsJG.lean.js → guide_install.md.SsIHMfUu.lean.js} +7 -5
  72. package/site-dist/assets/guide_maintainer.md.CvqvRle1.js +1 -0
  73. package/site-dist/assets/guide_maintainer.md.CvqvRle1.lean.js +1 -0
  74. package/site-dist/assets/{guide_mogao.md.S0eln1Pr.js → guide_mogao.md.TCu3lgE9.js} +2 -2
  75. package/site-dist/assets/{guide_mogao.md.S0eln1Pr.lean.js → guide_mogao.md.TCu3lgE9.lean.js} +2 -2
  76. package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.js +5 -0
  77. package/site-dist/assets/guide_walkthrough.md.nj_PWP9Y.lean.js +5 -0
  78. package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.js +1 -0
  79. package/site-dist/assets/reference_contracts_cli-json.md.3iU9h4rw.lean.js +1 -0
  80. package/site-dist/assets/{reference_design_builtin-capabilities.md.CZYtjo_v.js → reference_design_builtin-capabilities.md.k5NXkESv.js} +2 -2
  81. package/site-dist/assets/{reference_design_builtin-capabilities.md.CZYtjo_v.lean.js → reference_design_builtin-capabilities.md.k5NXkESv.lean.js} +2 -2
  82. package/site-dist/assets/{reference_design_cli-adapter.md.pJy3x6Un.js → reference_design_cli-adapter.md.C1lcDATP.js} +1 -1
  83. package/site-dist/assets/{reference_design_cli-adapter.md.pJy3x6Un.lean.js → reference_design_cli-adapter.md.C1lcDATP.lean.js} +1 -1
  84. package/site-dist/changelog.html +5 -5
  85. package/site-dist/guide/cli.html +4 -4
  86. package/site-dist/guide/dsh.html +8 -6
  87. package/site-dist/guide/getting-started.html +5 -5
  88. package/site-dist/guide/how-it-works.html +4 -4
  89. package/site-dist/guide/index.html +4 -4
  90. package/site-dist/guide/install.html +11 -9
  91. package/site-dist/guide/intranet.html +4 -4
  92. package/site-dist/guide/maintainer.html +5 -5
  93. package/site-dist/guide/mogao.html +7 -7
  94. package/site-dist/guide/phases.html +4 -4
  95. package/site-dist/guide/project.html +4 -4
  96. package/site-dist/guide/user.html +4 -4
  97. package/site-dist/guide/walkthrough.html +34 -0
  98. package/site-dist/hashmap.json +1 -1
  99. package/site-dist/index.html +4 -4
  100. package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
  101. package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
  102. package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
  103. package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
  104. package/site-dist/reference/adr/0005-skill-names.html +4 -4
  105. package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
  106. package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
  107. package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
  108. package/site-dist/reference/adr/index.html +4 -4
  109. package/site-dist/reference/commands.html +4 -4
  110. package/site-dist/reference/config.html +4 -4
  111. package/site-dist/reference/contracts/agent-runtime.html +4 -4
  112. package/site-dist/reference/contracts/cli-json.html +5 -5
  113. package/site-dist/reference/contracts/feature-files.html +4 -4
  114. package/site-dist/reference/contracts/index.html +4 -4
  115. package/site-dist/reference/contracts/notifier-event.html +4 -4
  116. package/site-dist/reference/contracts/result-file.html +4 -4
  117. package/site-dist/reference/contracts/spec.html +4 -4
  118. package/site-dist/reference/contracts/state.html +4 -4
  119. package/site-dist/reference/contracts/usage-record.html +4 -4
  120. package/site-dist/reference/contracts/verify.html +4 -4
  121. package/site-dist/reference/design/adapter-guide.html +4 -4
  122. package/site-dist/reference/design/architecture.html +4 -4
  123. package/site-dist/reference/design/builtin-capabilities.html +6 -6
  124. package/site-dist/reference/design/cli-adapter.html +5 -5
  125. package/site-dist/reference/design/platform-vocabulary.html +4 -4
  126. package/site-dist/reference/scope.html +4 -4
  127. package/skills/laoshi/SKILL.md +1 -3
  128. package/skills/laoshi-setup/SKILL.md +1 -1
  129. package/ui/shared/view-model.ts +424 -0
  130. package/ui/web/board.ts +1126 -0
  131. package/site-dist/assets/changelog.md.BU-CvyJ1.js +0 -1
  132. package/site-dist/assets/chunks/@localSearchIndexroot.CfgJeQRO.js +0 -1
  133. package/site-dist/assets/guide_dsh.md.0X-eYB87.js +0 -5
  134. package/site-dist/assets/guide_dsh.md.0X-eYB87.lean.js +0 -5
  135. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +0 -1
  136. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +0 -1
  137. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +0 -1
  138. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +0 -1
  139. /package/site-dist/assets/{guide_getting-started.md.BxOxfic_.lean.js → guide_getting-started.md.BDd3nU5n.lean.js} +0 -0
@@ -123,6 +123,23 @@ const LINGER_GRACE_MS = 2_000;
123
123
 
124
124
  const isAlive = (pid: number) => engineProcessAlive(pid);
125
125
 
126
+ /**
127
+ * Stops a run with everything it started. Each `aimax run` leads its own process group (spawned
128
+ * detached), so the commands its agent left running (a dev server, a build daemon) stop with it.
129
+ */
130
+ function stopRun(pid: number | null | undefined): void {
131
+ if (!pid) return;
132
+ try {
133
+ process.kill(process.platform === "win32" ? pid : -pid, "SIGTERM");
134
+ } catch {
135
+ try {
136
+ process.kill(pid, "SIGTERM");
137
+ } catch {
138
+ // Gone already.
139
+ }
140
+ }
141
+ }
142
+
126
143
  /** The callback receiver: one local HTTP server for all step agents of this engine process. */
127
144
  class CallbackServer {
128
145
  private server: http.Server | null = null;
@@ -190,13 +207,19 @@ export interface MogaoRuntimeOptions {
190
207
  chatOut: string | null;
191
208
  env?: NodeJS.ProcessEnv;
192
209
  pollMs?: number;
210
+ /** Maximum UTF-8 bytes passed inline to `--message`; longer messages are written to a file. */
211
+ maxInlineBytes?: number;
193
212
  }
194
213
 
195
214
  export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
196
215
  const { settings, agentsDir, log } = options;
197
216
  const env = options.env ?? process.env;
198
217
  const pollMs = options.pollMs ?? 500;
218
+ const envMax = Number(env.LAOSHI_MOGAO_MAX_INLINE_BYTES);
219
+ const maxInlineBytes = options.maxInlineBytes ?? (Number.isFinite(envMax) && envMax > 0 ? envMax : 100_000);
199
220
  const children = new Map<string, ChildProcess>();
221
+ /** Latest run number started by this runtime process, per agent (used to distinguish crashed own runs from cut-off earlier turns). */
222
+ const launchedRuns = new Map<string, number>();
200
223
  const dir = (id: string) => path.join(agentsDir, id);
201
224
  const recordFile = (id: string) => path.join(dir(id), "agent.json");
202
225
  const read = (id: string): AgentRecord | null => {
@@ -277,7 +300,7 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
277
300
  const out = fs.openSync(path.join(dir(record.id), `run-${n}.out`), "w");
278
301
  const err = fs.openSync(path.join(dir(record.id), `run-${n}.err`), "w");
279
302
  const callback = await callbacks.url(record.id);
280
- const child = spawn(settings.command, [...args, "--output", "json", "--callback-url", callback], { cwd: record.cwd, env, stdio: ["ignore", out, err], windowsHide: true });
303
+ const child = spawn(settings.command, [...args, "--output", "json", "--callback-url", callback], { cwd: record.cwd, env, stdio: ["ignore", out, err], windowsHide: true, detached: process.platform !== "win32" });
281
304
  fs.closeSync(out);
282
305
  fs.closeSync(err);
283
306
  children.set(record.id, child);
@@ -290,9 +313,24 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
290
313
  fs.appendFileSync(path.join(dir(record.id), `run-${n}.err`), `\n${e.message}\n`);
291
314
  forget();
292
315
  });
316
+ launchedRuns.set(record.id, n);
293
317
  write({ ...record, runs: n, pid: child.pid ?? null, host: os.hostname(), runStartedAt: new Date().toISOString() });
294
318
  }
295
319
 
320
+ /**
321
+ * Passes short messages inline via `--message`; writes longer ones (start prompt, follow-up, or
322
+ * interrupt) to the agent's directory so we never hit OS ARG_MAX or CLI argument length limits.
323
+ */
324
+ function prepareMessage(record: AgentRecord, text: string, filename: string, alwaysWrite = false): string {
325
+ const file = path.join(dir(record.id), filename);
326
+ const over = Buffer.byteLength(text) > maxInlineBytes;
327
+ if (alwaysWrite || over) {
328
+ fs.mkdirSync(dir(record.id), { recursive: true });
329
+ fs.writeFileSync(file, text, "utf8");
330
+ }
331
+ return over ? `请先完整阅读文件 ${file},然后严格按照其中的要求完成任务。` : text;
332
+ }
333
+
296
334
  const runArgs = (record: AgentRecord, message: string) => [
297
335
  "run",
298
336
  ...(record.sessionId ? ["-s", record.sessionId] : ["--project-dir", record.cwd]),
@@ -338,15 +376,10 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
338
376
  }
339
377
  })();
340
378
  if (complete && since < LINGER_GRACE_MS) return null;
379
+ // "done" is posted a moment before the run prints its result: prefer the printed result while it may still come.
380
+ if (!complete && done && Date.now() - Date.parse(done.at) < LINGER_GRACE_MS) return null;
341
381
  log(`agent ${record.id} 已经做完,但 aimax run 进程还没有退出:按已完成处理,并结束这个进程`);
342
- if (child) child.kill("SIGTERM");
343
- else if (record.pid) {
344
- try {
345
- process.kill(record.pid, "SIGTERM");
346
- } catch {
347
- // Gone meanwhile.
348
- }
349
- }
382
+ stopRun(child?.pid ?? record.pid);
350
383
  return {
351
384
  result: complete ? result : { sessionId: record.sessionId ?? undefined, ...(done!.error ? { error: done!.error } : { text: done!.text ?? "" }), usage: done!.usage ?? null },
352
385
  stderr: read("err"),
@@ -357,13 +390,13 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
357
390
  * The platform's "done" (or "error") callback for the latest run, if it came: the last one after
358
391
  * the latest "start" (each run starts with one), and after the run was launched when that is known.
359
392
  */
360
- function doneEvent(record: AgentRecord): { text: string | null; usage: RunResult["usage"]; error: string | null } | null {
393
+ function doneEvent(record: AgentRecord): { at: string; text: string | null; usage: RunResult["usage"]; error: string | null } | null {
361
394
  const all = events(record.id);
362
395
  const lastStart = all.map((x) => x.type).lastIndexOf("start");
363
396
  const e = all.slice(lastStart + 1).filter((x) => (x.type === "done" || x.type === "error") && (!record.runStartedAt || String(x.at) >= record.runStartedAt)).at(-1);
364
397
  if (!e) return null;
365
398
  const usage = (e.usage ?? null) as RunResult["usage"];
366
- return { text: typeof e.text === "string" ? e.text : null, usage, error: e.type === "error" ? String(e.message ?? "运行出错") : null };
399
+ return { at: String(e.at), text: typeof e.text === "string" ? e.text : null, usage, error: e.type === "error" ? String(e.message ?? "运行出错") : null };
367
400
  }
368
401
 
369
402
  const stepAgent = (id: string): StepAgent => ({
@@ -402,8 +435,8 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
402
435
  }
403
436
  if (result && !result.error) return { ...base, usage, status: "idle", lastMessage: result.text ?? null };
404
437
  if (result?.error) return { ...base, usage, status: "error", error: /timed out/i.test(result.error) ? `超过 ${settings.runTimeoutMinutes} 分钟(单次运行的上限),运行已停止` : result.error };
405
- // No result: the run was cut off (the chat's turn ended with the container). Continue its session.
406
- if (record.sessionId && record.host !== os.hostname()) {
438
+ // No result: the previous turn's run was cut off (container recycled or command timed out). Continue its session.
439
+ if (record.sessionId && (record.host !== os.hostname() || launchedRuns.get(id) !== record.runs)) {
407
440
  log(`agent ${id} 的上一次运行被中断(没有结果),接着它的会话 ${record.sessionId} 继续`);
408
441
  await launch(record, runArgs(record, CONTINUE_MESSAGE));
409
442
  continue;
@@ -417,7 +450,8 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
417
450
  async followUp(text: string): Promise<void> {
418
451
  const record = read(id);
419
452
  if (!record?.sessionId) throw new Error(`agent ${id} 还没有会话,不能追问`);
420
- await launch(record, runArgs(record, text));
453
+ const message = prepareMessage(record, text, `followup-${record.runs + 1}.md`);
454
+ await launch(record, runArgs(record, message));
421
455
  },
422
456
  async archive(): Promise<void> {
423
457
  // Sessions stay with the platform (aimax sessions, export-html); nothing to archive.
@@ -450,10 +484,7 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
450
484
  async startAgent(input) {
451
485
  const record: AgentRecord = { id: `mogao-${crypto.randomBytes(6).toString("hex")}`, cwd: input.cwd, title: input.title, sessionId: null, runs: 0, pid: null, host: null, answered: null };
452
486
  write(record);
453
- const promptFile = path.join(dir(record.id), "prompt.md");
454
- fs.writeFileSync(promptFile, input.prompt);
455
- // One command-line argument holds at most 128 KB on Linux: a longer prompt is read from its file.
456
- const message = Buffer.byteLength(input.prompt) <= 100_000 ? input.prompt : `请先完整阅读文件 ${promptFile},然后严格按照其中的要求完成任务。`;
487
+ const message = prepareMessage(record, input.prompt, "prompt.md", true);
457
488
  await launch(record, runArgs(record, message));
458
489
  return stepAgent(record.id);
459
490
  },
@@ -472,14 +503,18 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
472
503
  const child = children.get(agentId);
473
504
  const record = read(agentId);
474
505
  if (child) {
475
- child.kill("SIGTERM");
476
- await new Promise((r) => child.once("exit", r));
506
+ const exited = new Promise((r) => child.once("exit", r));
507
+ stopRun(child.pid);
508
+ await exited;
477
509
  } else if (record?.pid && record.host === os.hostname() && isAlive(record.pid)) {
478
- process.kill(record.pid, "SIGTERM");
510
+ stopRun(record.pid);
479
511
  for (let i = 0; i < 50 && isAlive(record.pid); i++) await sleep(100);
480
512
  }
481
513
  const now = read(agentId);
482
- if (now?.sessionId) await launch(now, runArgs(now, text));
514
+ if (now?.sessionId) {
515
+ const message = prepareMessage(now, text, `interrupt-${now.runs + 1}.md`);
516
+ await launch(now, runArgs(now, message));
517
+ }
483
518
  },
484
519
 
485
520
  agentDirectory: async () => null,
@@ -523,7 +558,7 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
523
558
  },
524
559
 
525
560
  async close() {
526
- for (const child of children.values()) child.kill("SIGTERM");
561
+ for (const child of children.values()) stopRun(child.pid);
527
562
  await callbacks.close();
528
563
  },
529
564
  };
@@ -11,6 +11,12 @@ laoshi 装在工作区(`/data/workspace/.laoshi`),每个对话轮次的机
11
11
  第一次大约需要一分钟(从内网 npm 镜像安装)。失败时把输出告诉用户,请开发同事看一下,不要自己改安装目录。
12
12
 
13
13
  本 skill 里写成 `req …` 或 `laoshi …` 的命令,在摸高上写成 `node "{{REQ_KIT_ROOT}}/bin/req.mjs" …`。
14
+ <!-- fragment: launchResult -->
15
+ **在摸高上,启动、继续、确认方案后继续、开始测试验证这几条命令不会马上返回,流水线就在这条命令里运行,不在后台。** 摸高在这一轮对话结束时会收回机器,流水线也随之停止,不会自己继续,也不会有消息发进这个对话。所以:
16
+ - 命令输出"未启动":把原因告诉用户。spec 未确认 → 回到确认;同一目录已有流水线在运行 → 等它结束;其他原因(找不到程序、配置有误等)→ 请用户运行 `/laoshi-doctor` 或联系开发同事,并附上输出。
17
+ - 命令输出"已启动":**不要说"开发已在后台进行、有进展会通知你"之类的话,也不要结束这一轮对话。** 命令转到后台会话后,持续查看它的输出(每隔一两分钟看一次),把新的进展用一句话转告用户,直到命令结束;命令结束时,按输出最后的消息处理(方案确认、业务问题、等待批准、完成或中断)。
18
+ - 命令输出里出现"流水线仍在运行":说明还没做完,继续等它。
19
+ - 这一轮对话还是被结束了(例如超过了平台的时限):下一轮用户说"继续"时,用"继续"命令接着做,已经做完的步骤不会重做。
14
20
  <!-- fragment: launchNote -->
15
21
 
16
22
  **在摸高上不一样的地方:**
@@ -7,7 +7,9 @@ import path from "node:path";
7
7
  import { pathToFileURL } from "node:url";
8
8
 
9
9
  export const id = "paseo";
10
- export const options = {};
10
+ export const options = {
11
+ "with-plugin": { type: "boolean" },
12
+ };
11
13
 
12
14
  export function platformConfig() {
13
15
  return { adapter: "paseo" };
@@ -23,14 +25,21 @@ export function skillTargets() {
23
25
  return roots;
24
26
  }
25
27
 
26
- export async function setup({ kit, dry, report, home }) {
27
- const { refreshPlugin, stagedDir } = await import(pathToFileURL(path.join(kit, "adapters", "paseo", "plugin-cmd.mjs")).href);
28
+ export async function setup({ kit, args = {}, dry, report, home }) {
29
+ const { installPlugin, refreshPlugin, stagedDir } = await import(pathToFileURL(path.join(kit, "adapters", "paseo", "plugin-cmd.mjs")).href);
28
30
  const staged = fs.existsSync(path.join(stagedDir(home), "paseo-plugin.json"));
29
31
  if (staged && !dry) {
30
32
  // Installed before: refresh its files from this version and reload it in Paseo.
31
33
  refreshPlugin({ kitRoot: kit, env: { ...process.env, LAOSHI_HOME: home }, log: (m) => report("ok", m) });
34
+ } else if (!staged && args["with-plugin"]) {
35
+ if (dry) report("ok", "将安装 Paseo 需求插件(--with-plugin)");
36
+ else {
37
+ const code = await installPlugin({ yes: true, kitRoot: kit, env: { ...process.env, LAOSHI_HOME: home } });
38
+ if (code === 0) report("ok", "已安装 Paseo 需求插件");
39
+ else report("warn", "Paseo 插件文件已就绪,但尚未注册到 Paseo daemon", "启动 Paseo daemon 后再运行 laoshi plugin install");
40
+ }
32
41
  } else if (!staged) {
33
- report("info", "Paseo 的需求插件(在 Paseo 里看需求、确认方案、停止和继续):laoshi plugin install");
42
+ report("info", "Paseo 的需求插件(看需求、确认方案、一键试用、验收):运行 laoshi plugin install(或安装时加 --with-plugin 一步装好)");
34
43
  }
35
44
  return ["在终端运行 laoshi configure,选择 builder 和 reviewer 用的 agent"];
36
45
  }
@@ -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}>{facts(d)}</Text>
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
  }