@yiyi_zhang/laoshi 0.1.1 → 0.2.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (176) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/adapters/cli/adapter.ts +53 -0
  3. package/adapters/cli/cli-runtime.ts +402 -0
  4. package/adapters/cli/drivers.ts +146 -0
  5. package/adapters/cli/install.mjs +28 -0
  6. package/adapters/cli/skill/setup.md +8 -0
  7. package/adapters/dsh/plugin/index.mjs +1 -1
  8. package/adapters/dsh/plugin/package.json +1 -1
  9. package/adapters/mogao/adapter.ts +47 -0
  10. package/adapters/mogao/install.mjs +31 -0
  11. package/adapters/mogao/make-expert.mjs +64 -0
  12. package/adapters/mogao/mogao-runtime.ts +506 -0
  13. package/adapters/mogao/skill/setup.md +21 -0
  14. package/adapters/paseo/adapter.ts +1 -1
  15. package/adapters/paseo/install.mjs +17 -5
  16. package/adapters/paseo/migrate.ts +267 -0
  17. package/adapters/paseo/plugin/OVERVIEW.md +9 -0
  18. package/adapters/paseo/plugin/client/config.tsx +216 -0
  19. package/adapters/paseo/plugin/client/data.ts +85 -0
  20. package/adapters/paseo/plugin/client/detail.tsx +342 -0
  21. package/adapters/paseo/plugin/client/format.ts +173 -0
  22. package/adapters/paseo/plugin/client/inbox.tsx +190 -0
  23. package/adapters/paseo/plugin/client/live.ts +161 -0
  24. package/adapters/paseo/plugin/client/markdown.tsx +220 -0
  25. package/adapters/paseo/plugin/client/models.tsx +117 -0
  26. package/adapters/paseo/plugin/client/nav.ts +22 -0
  27. package/adapters/paseo/plugin/client/overview.tsx +103 -0
  28. package/adapters/paseo/plugin/client/panel.tsx +56 -0
  29. package/adapters/paseo/plugin/client/review.tsx +80 -0
  30. package/adapters/paseo/plugin/client/row.tsx +63 -0
  31. package/adapters/paseo/plugin/client/settings.tsx +92 -0
  32. package/adapters/paseo/plugin/client/sidebar.tsx +27 -0
  33. package/adapters/paseo/plugin/client/stats.tsx +138 -0
  34. package/adapters/paseo/plugin/client/ui.tsx +278 -0
  35. package/adapters/paseo/plugin/client/web.ts +34 -0
  36. package/adapters/paseo/plugin/index.client.tsx +66 -0
  37. package/adapters/paseo/plugin/index.server.ts +61 -0
  38. package/adapters/paseo/plugin/package.json +22 -0
  39. package/adapters/paseo/plugin/paseo-plugin.json +6 -0
  40. package/adapters/paseo/plugin/server/handlers.ts +69 -0
  41. package/adapters/paseo/plugin/server/req.ts +105 -0
  42. package/adapters/paseo/plugin/shared/contracts.ts +286 -0
  43. package/adapters/paseo/plugin/shared/rk-colors.ts +35 -0
  44. package/adapters/paseo/plugin/tsconfig.json +16 -0
  45. package/adapters/paseo/plugin-cmd.mjs +233 -0
  46. package/bin/install.mjs +12 -5
  47. package/bin/req.mjs +18 -2
  48. package/contracts/README.md +1 -1
  49. package/contracts/agent-runtime.md +5 -2
  50. package/contracts/cli-json.md +4 -3
  51. package/contracts/notifier-event.md +2 -2
  52. package/contracts/state.md +2 -0
  53. package/contracts/usage-record.md +3 -3
  54. package/docs/design/adapter-guide.md +2 -1
  55. package/docs/design/cli-adapter.md +75 -0
  56. package/docs/design/compat-migration.md +2 -0
  57. package/docs/design/mogao-expert.md +103 -0
  58. package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +132 -0
  59. package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +32 -3
  60. package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +4 -2
  61. package/docs/guide//351/241/271/347/233/256/345/256/232/345/210/266/344/270/216/350/277/220/350/241/214/350/247/204/345/210/231.md +1 -1
  62. package/engine/src/api.ts +9 -5
  63. package/engine/src/code-review.ts +2 -2
  64. package/engine/src/control.ts +6 -6
  65. package/engine/src/danger-guard.ts +7 -0
  66. package/engine/src/doctor.ts +4 -3
  67. package/engine/src/features.ts +2 -2
  68. package/engine/src/identity.ts +16 -1
  69. package/engine/src/integration-cmd.ts +2 -2
  70. package/engine/src/launch.ts +44 -6
  71. package/engine/src/locations.ts +15 -1
  72. package/engine/src/main.ts +6 -1
  73. package/engine/src/messages.ts +1 -1
  74. package/engine/src/permission-cmd.ts +56 -0
  75. package/engine/src/platform.ts +7 -0
  76. package/engine/src/preflight.ts +2 -2
  77. package/engine/src/runtime-loader.ts +16 -0
  78. package/engine/src/runtime.ts +5 -0
  79. package/engine/src/skills-render.ts +10 -6
  80. package/engine/src/state.ts +25 -1
  81. package/engine/src/words.ts +1 -1
  82. package/package.json +2 -1
  83. package/site-dist/404.html +2 -2
  84. package/site-dist/assets/{app.Df99UgrJ.js → app.D2ywvSfZ.js} +1 -1
  85. package/site-dist/assets/changelog.md.EDul9PkX.js +1 -0
  86. package/site-dist/assets/changelog.md.EDul9PkX.lean.js +1 -0
  87. package/site-dist/assets/chunks/@localSearchIndexroot.Dr_jsw66.js +1 -0
  88. package/site-dist/assets/chunks/{VPLocalSearchBox.IEhP6Gw5.js → VPLocalSearchBox.ClWffKqN.js} +1 -1
  89. package/site-dist/assets/chunks/{theme.DHubfO7g.js → theme.tbt16E5a.js} +2 -2
  90. package/site-dist/assets/guide_cli.md.BrXllHw9.js +2 -0
  91. package/site-dist/assets/guide_cli.md.BrXllHw9.lean.js +2 -0
  92. package/site-dist/assets/{guide_getting-started.md.BZTWiHhH.js → guide_getting-started.md.qAp5hWCl.js} +1 -1
  93. package/site-dist/assets/{guide_getting-started.md.BZTWiHhH.lean.js → guide_getting-started.md.qAp5hWCl.lean.js} +1 -1
  94. package/site-dist/assets/guide_install.md.By4WxsJG.js +24 -0
  95. package/site-dist/assets/guide_install.md.By4WxsJG.lean.js +24 -0
  96. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +1 -0
  97. package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +1 -0
  98. package/site-dist/assets/guide_mogao.md.S0eln1Pr.js +10 -0
  99. package/site-dist/assets/guide_mogao.md.S0eln1Pr.lean.js +10 -0
  100. package/site-dist/assets/{guide_project.md.BIcaDhdS.js → guide_project.md.B2cmf8YF.js} +1 -1
  101. package/site-dist/assets/{guide_project.md.BIcaDhdS.lean.js → guide_project.md.B2cmf8YF.lean.js} +1 -1
  102. package/site-dist/assets/reference_contracts_agent-runtime.md.DPE2FJFc.js +1 -0
  103. package/site-dist/assets/{reference_contracts_agent-runtime.md.Bu8q-uGl.lean.js → reference_contracts_agent-runtime.md.DPE2FJFc.lean.js} +1 -1
  104. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +1 -0
  105. package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +1 -0
  106. package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.js → reference_contracts_index.md.B5P4FjRk.js} +1 -1
  107. package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.lean.js → reference_contracts_index.md.B5P4FjRk.lean.js} +1 -1
  108. package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.js → reference_contracts_notifier-event.md.BeR8iODP.js} +1 -1
  109. package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.lean.js → reference_contracts_notifier-event.md.BeR8iODP.lean.js} +1 -1
  110. package/site-dist/assets/reference_contracts_state.md.DLygjkfs.js +1 -0
  111. package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.js +10 -0
  112. package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.lean.js +10 -0
  113. package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.js → reference_design_adapter-guide.md.B_P-spS5.js} +2 -2
  114. package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.lean.js → reference_design_adapter-guide.md.B_P-spS5.lean.js} +2 -2
  115. package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.js +13 -0
  116. package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.lean.js +13 -0
  117. package/site-dist/changelog.html +5 -5
  118. package/site-dist/guide/cli.html +31 -0
  119. package/site-dist/guide/dsh.html +5 -5
  120. package/site-dist/guide/getting-started.html +5 -5
  121. package/site-dist/guide/how-it-works.html +4 -4
  122. package/site-dist/guide/index.html +4 -4
  123. package/site-dist/guide/install.html +13 -8
  124. package/site-dist/guide/intranet.html +5 -5
  125. package/site-dist/guide/maintainer.html +5 -5
  126. package/site-dist/guide/mogao.html +39 -0
  127. package/site-dist/guide/phases.html +4 -4
  128. package/site-dist/guide/project.html +6 -6
  129. package/site-dist/guide/user.html +4 -4
  130. package/site-dist/hashmap.json +1 -1
  131. package/site-dist/index.html +4 -4
  132. package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
  133. package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
  134. package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
  135. package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
  136. package/site-dist/reference/adr/0005-skill-names.html +4 -4
  137. package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
  138. package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
  139. package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
  140. package/site-dist/reference/adr/index.html +4 -4
  141. package/site-dist/reference/commands.html +4 -4
  142. package/site-dist/reference/config.html +4 -4
  143. package/site-dist/reference/contracts/agent-runtime.html +5 -5
  144. package/site-dist/reference/contracts/cli-json.html +5 -5
  145. package/site-dist/reference/contracts/feature-files.html +4 -4
  146. package/site-dist/reference/contracts/index.html +5 -5
  147. package/site-dist/reference/contracts/notifier-event.html +6 -6
  148. package/site-dist/reference/contracts/result-file.html +4 -4
  149. package/site-dist/reference/contracts/spec.html +4 -4
  150. package/site-dist/reference/contracts/state.html +5 -5
  151. package/site-dist/reference/contracts/usage-record.html +6 -6
  152. package/site-dist/reference/contracts/verify.html +4 -4
  153. package/site-dist/reference/design/adapter-guide.html +6 -6
  154. package/site-dist/reference/design/architecture.html +4 -4
  155. package/site-dist/reference/design/builtin-capabilities.html +4 -4
  156. package/site-dist/reference/design/cli-adapter.html +42 -0
  157. package/site-dist/reference/design/platform-vocabulary.html +4 -4
  158. package/site-dist/reference/scope.html +4 -4
  159. package/skills/laoshi/SKILL.md +3 -0
  160. package/skills/laoshi-doctor/SKILL.md +2 -0
  161. package/skills/laoshi-retro/SKILL.md +2 -0
  162. package/skills/laoshi-setup/SKILL.md +3 -0
  163. package/site-dist/assets/changelog.md.Df8vFhjK.js +0 -1
  164. package/site-dist/assets/changelog.md.Df8vFhjK.lean.js +0 -1
  165. package/site-dist/assets/chunks/@localSearchIndexroot.n-0kN-N0.js +0 -1
  166. package/site-dist/assets/guide_install.md.D7NiiOPu.js +0 -19
  167. package/site-dist/assets/guide_install.md.D7NiiOPu.lean.js +0 -19
  168. package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.js +0 -1
  169. package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.lean.js +0 -1
  170. package/site-dist/assets/reference_contracts_agent-runtime.md.Bu8q-uGl.js +0 -1
  171. package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.js +0 -1
  172. package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.lean.js +0 -1
  173. package/site-dist/assets/reference_contracts_state.md.DVHC4opX.js +0 -1
  174. package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.js +0 -10
  175. package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.lean.js +0 -10
  176. /package/site-dist/assets/{reference_contracts_state.md.DVHC4opX.lean.js → reference_contracts_state.md.DLygjkfs.lean.js} +0 -0
@@ -0,0 +1,267 @@
1
+ // `laoshi migrate` (M7, docs/design/compat-migration.md §5): moves a req-kit 1.x machine setup to
2
+ // laoshi. By default it only shows what it would do; --apply does it, --rollback undoes it.
3
+ //
4
+ // - The install-level config: ~/.req-kit/config.json → ~/.laoshi/config.json, with req-kit's
5
+ // setting names turned into laoshi's (the Paseo daemon address under platform.paseo, the old
6
+ // profile and services keys renamed). Everything else in the old directory (usage records, the
7
+ // requirement index, local prompts, notifiers) is copied.
8
+ // - Requirements: state files still in the 1.x format are moved to the current format, keeping
9
+ // the old file as state.json.bak-v1 (as the engine does when it reads one).
10
+ // - Nothing in the old directory is changed or removed: req-kit 1.x keeps working from it, so a
11
+ // rollback only has to restore the state files and remove what was written.
12
+ // - Projects' .requirement-pipeline.json and req-kit's /req* skills are left as they are: laoshi
13
+ // reads the old project file, and the skills go with req-kit.
14
+ //
15
+ // laoshi migrate [--from <req-kit 目录>] [--to <laoshi 目录>] [--apply | --rollback]
16
+ import fs from "node:fs";
17
+ import os from "node:os";
18
+ import path from "node:path";
19
+ import { pathToFileURL } from "node:url";
20
+ import { parseArgs } from "node:util";
21
+ import { LEGACY_PROJECT_CONFIG_FILE, normalizeLegacyKeys, PROJECT_CONFIG_FILE } from "../../engine/src/config.js";
22
+ import { isAlive, migrateState, STATE_VERSION } from "../../engine/src/state.js";
23
+
24
+ export interface MigrationPlan {
25
+ from: string;
26
+ to: string;
27
+ /** Reasons it cannot be applied now. */
28
+ blockers: string[];
29
+ /** The new install-level config, or null when there is none to write. */
30
+ config: Record<string, unknown> | null;
31
+ /** Files copied from the old directory (relative paths). */
32
+ copies: string[];
33
+ /** State files to move to the current format. */
34
+ states: string[];
35
+ /** Things people should know or do themselves. */
36
+ notes: string[];
37
+ }
38
+
39
+ /** What --apply wrote, so --rollback can undo exactly that. */
40
+ export interface MigrationRecord {
41
+ schema: 1;
42
+ at: string;
43
+ from: string;
44
+ to: string;
45
+ /** Files created in the new directory (absolute). */
46
+ created: string[];
47
+ /** State files moved to the current format; each has its state.json.bak-v<n>. */
48
+ states: Array<{ file: string; from: number }>;
49
+ }
50
+
51
+ export const RECORD_FILE = "migrate.json";
52
+
53
+ const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === "object" && v !== null && !Array.isArray(v);
54
+
55
+ /** req-kit 1.x's install-level config in laoshi's terms. */
56
+ export function migrateConfig(old: Record<string, unknown>): Record<string, unknown> {
57
+ const config = normalizeLegacyKeys(structuredClone(old));
58
+ const platform: Record<string, unknown> = isRecord(config.platform) ? { ...config.platform } : { adapter: "paseo" };
59
+ if (typeof platform.adapter !== "string") platform.adapter = "paseo";
60
+ // 1.x kept the daemon's address at the top level; laoshi keeps it with the Paseo adapter's settings.
61
+ const daemon: Record<string, unknown> = {};
62
+ for (const key of ["daemonUrl", "daemonPasswordEnv"]) {
63
+ if (config[key] !== undefined) {
64
+ daemon[key] = config[key];
65
+ delete config[key];
66
+ }
67
+ }
68
+ if (Object.keys(daemon).length) platform.paseo = { ...daemon, ...(isRecord(platform.paseo) ? platform.paseo : {}) };
69
+ return { ...config, platform };
70
+ }
71
+
72
+ function filesUnder(dir: string, base = dir): string[] {
73
+ if (!fs.existsSync(dir)) return [];
74
+ return fs.readdirSync(dir, { withFileTypes: true }).flatMap((e) => {
75
+ const full = path.join(dir, e.name);
76
+ if (e.isDirectory()) return filesUnder(full, base);
77
+ return e.isFile() ? [path.relative(base, full)] : [];
78
+ });
79
+ }
80
+
81
+ /** The requirements req-kit recorded: their repositories and feature directories. */
82
+ function indexed(from: string): Array<{ repo: string; featureDir: string }> {
83
+ const dir = path.join(from, "index");
84
+ if (!fs.existsSync(dir)) return [];
85
+ const out: Array<{ repo: string; featureDir: string }> = [];
86
+ for (const name of fs.readdirSync(dir).filter((n) => n.endsWith(".json"))) {
87
+ try {
88
+ const e = JSON.parse(fs.readFileSync(path.join(dir, name), "utf8")) as { repo?: unknown; featureDir?: unknown };
89
+ if (typeof e.repo === "string" && typeof e.featureDir === "string") out.push({ repo: e.repo, featureDir: e.featureDir });
90
+ } catch {
91
+ // A broken entry is skipped.
92
+ }
93
+ }
94
+ return out;
95
+ }
96
+
97
+ export function defaultDirs(env: NodeJS.ProcessEnv = process.env, home = os.homedir()): { from: string; to: string } {
98
+ const legacy = env.REQ_KIT_HOME?.trim();
99
+ const current = env.LAOSHI_HOME?.trim();
100
+ return { from: path.resolve(legacy || path.join(home, ".req-kit")), to: path.resolve(current || path.join(home, ".laoshi")) };
101
+ }
102
+
103
+ export function planMigration(from: string, to: string, env: NodeJS.ProcessEnv = process.env): MigrationPlan {
104
+ const plan: MigrationPlan = { from, to, blockers: [], config: null, copies: [], states: [], notes: [] };
105
+ const oldConfig = path.join(from, "config.json");
106
+ if (path.resolve(from) === path.resolve(to)) {
107
+ plan.blockers.push(`新旧目录相同(${from}):用 --to 指定 laoshi 的目录`);
108
+ return plan;
109
+ }
110
+ if (!fs.existsSync(oldConfig)) {
111
+ plan.blockers.push(`${from} 下没有 req-kit 的配置(config.json),没有可迁移的内容`);
112
+ return plan;
113
+ }
114
+ if (fs.existsSync(path.join(to, RECORD_FILE))) plan.blockers.push(`${to} 已经迁移过(有 ${RECORD_FILE});要重来,先 laoshi migrate --rollback`);
115
+ else if (fs.existsSync(path.join(to, "config.json"))) plan.blockers.push(`${to} 已经有 laoshi 的配置:用 --to 换一个目录,或先把它移走`);
116
+ try {
117
+ const raw = JSON.parse(fs.readFileSync(oldConfig, "utf8")) as unknown;
118
+ if (!isRecord(raw)) throw new Error("顶层不是对象");
119
+ plan.config = migrateConfig(raw);
120
+ } catch (error) {
121
+ plan.blockers.push(`${oldConfig} 读不出来:${(error as Error).message}`);
122
+ }
123
+ plan.copies = filesUnder(from).filter((f) => f !== "config.json" && !fs.existsSync(path.join(to, f)));
124
+
125
+ const projects = new Set<string>();
126
+ for (const { repo, featureDir } of indexed(from)) {
127
+ const file = path.join(repo, featureDir, ".pipeline", "state.json");
128
+ if (fs.existsSync(path.join(repo, LEGACY_PROJECT_CONFIG_FILE)) && !fs.existsSync(path.join(repo, PROJECT_CONFIG_FILE))) projects.add(repo);
129
+ if (!fs.existsSync(file)) continue;
130
+ let raw: Record<string, unknown>;
131
+ try {
132
+ raw = JSON.parse(fs.readFileSync(file, "utf8")) as Record<string, unknown>;
133
+ } catch {
134
+ plan.notes.push(`${file} 读不出来,跳过`);
135
+ continue;
136
+ }
137
+ if (raw.status === "running" && typeof raw.pid === "number" && isAlive(raw.pid)) {
138
+ plan.blockers.push(`需求 ${path.join(repo, featureDir)} 的流水线正在运行(进程 ${raw.pid}):先等它停下,或用 laoshi stop 停止`);
139
+ continue;
140
+ }
141
+ const version = typeof raw.version === "number" ? raw.version : 1;
142
+ if (version < STATE_VERSION) plan.states.push(file);
143
+ }
144
+
145
+ plan.notes.push("skill:运行 laoshi install --platform paseo 安装 /laoshi、/laoshi-setup 等;req-kit 的 /req* 先保留,以后由 paseo-req-kit 2.0 换成转到 /laoshi 的说明");
146
+ for (const repo of projects) plan.notes.push(`项目 ${repo} 用的是旧的 ${LEGACY_PROJECT_CONFIG_FILE}:laoshi 照常读取;要改名为 ${PROJECT_CONFIG_FILE},请在仓库里改名后提交`);
147
+ if (env.REQ_KIT_HOME?.trim()) plan.notes.push("环境变量 REQ_KIT_HOME 还在:laoshi 也认它,会继续用旧目录;迁移后请改为设置 LAOSHI_HOME(或去掉 REQ_KIT_HOME)");
148
+ return plan;
149
+ }
150
+
151
+ export function applyMigration(plan: MigrationPlan): MigrationRecord {
152
+ if (plan.blockers.length) throw new Error(plan.blockers.join("\n"));
153
+ const record: MigrationRecord = { schema: 1, at: new Date().toISOString(), from: plan.from, to: plan.to, created: [], states: [] };
154
+ const write = (file: string, content: string | Buffer) => {
155
+ fs.mkdirSync(path.dirname(file), { recursive: true });
156
+ fs.writeFileSync(file, content);
157
+ record.created.push(file);
158
+ };
159
+ fs.mkdirSync(plan.to, { recursive: true });
160
+ try {
161
+ if (plan.config) write(path.join(plan.to, "config.json"), `${JSON.stringify(plan.config, null, 2)}\n`);
162
+ for (const rel of plan.copies) write(path.join(plan.to, rel), fs.readFileSync(path.join(plan.from, rel)));
163
+ for (const file of plan.states) {
164
+ const text = fs.readFileSync(file, "utf8");
165
+ const { state, from } = migrateState(JSON.parse(text) as Record<string, unknown>, file);
166
+ const backup = `${file}.bak-v${from}`;
167
+ if (!fs.existsSync(backup)) fs.writeFileSync(backup, text);
168
+ fs.writeFileSync(file, `${JSON.stringify(state, null, 2)}\n`);
169
+ record.states.push({ file, from });
170
+ }
171
+ } finally {
172
+ // Written even when a step failed, so --rollback can undo what was done.
173
+ fs.writeFileSync(path.join(plan.to, RECORD_FILE), `${JSON.stringify(record, null, 2)}\n`);
174
+ }
175
+ return record;
176
+ }
177
+
178
+ /** Undoes --apply: the state files as they were, and the new directory's migrated files gone. */
179
+ export function rollbackMigration(to: string): { restored: string[]; removed: string[]; kept: string[] } {
180
+ const recordFile = path.join(to, RECORD_FILE);
181
+ if (!fs.existsSync(recordFile)) throw new Error(`${to} 下没有迁移记录(${RECORD_FILE}),没有可回滚的内容`);
182
+ const record = JSON.parse(fs.readFileSync(recordFile, "utf8")) as MigrationRecord;
183
+ const restored: string[] = [];
184
+ const kept: string[] = [];
185
+ for (const { file, from } of record.states) {
186
+ const backup = `${file}.bak-v${from}`;
187
+ if (!fs.existsSync(backup)) {
188
+ kept.push(`${file}(没有 ${path.basename(backup)})`);
189
+ continue;
190
+ }
191
+ fs.copyFileSync(backup, file);
192
+ restored.push(file);
193
+ }
194
+ const removed: string[] = [];
195
+ for (const file of record.created) {
196
+ if (fs.existsSync(file)) {
197
+ fs.rmSync(file);
198
+ removed.push(file);
199
+ }
200
+ }
201
+ fs.rmSync(recordFile);
202
+ // Directories the migration made and left empty.
203
+ const dirs = [...new Set(record.created.map((f) => path.dirname(f)))].sort((a, b) => b.length - a.length);
204
+ for (const dir of [...dirs, to]) {
205
+ try {
206
+ if (fs.readdirSync(dir).length === 0) fs.rmdirSync(dir);
207
+ } catch {
208
+ // Gone already or not empty: leave it.
209
+ }
210
+ }
211
+ return { restored, removed, kept };
212
+ }
213
+
214
+ function show(plan: MigrationPlan, applied: boolean): void {
215
+ const verb = applied ? "已" : "将";
216
+ console.log(`从 req-kit 迁移到 laoshi${applied ? "" : "(预览:不改任何东西)"}\n旧目录:${plan.from}\n新目录:${plan.to}\n`);
217
+ if (plan.config) {
218
+ console.log(`- 安装级配置:${verb}写入 ${path.join(plan.to, "config.json")}(平台 ${String((plan.config.platform as { adapter?: string }).adapter)}${(plan.config.platform as { paseo?: unknown }).paseo ? ",daemon 地址移到 platform.paseo" : ""})`);
219
+ console.log(`- 其他文件(使用记录、需求索引、本机提示词、通知模块):${verb}复制 ${plan.copies.length} 个`);
220
+ console.log(`- 需求状态:${plan.states.length ? `${verb}把 ${plan.states.length} 个旧格式的状态文件改为第 ${STATE_VERSION} 版(原文件保留为 state.json.bak-v1)` : "没有要改的"}`);
221
+ console.log("- 旧目录不改、不删:req-kit 1.x 仍然可以用");
222
+ for (const n of plan.notes) console.log(`· ${n}`);
223
+ }
224
+ if (plan.blockers.length) {
225
+ console.log("\n现在不能迁移:");
226
+ for (const b of plan.blockers) console.log(`✗ ${b}`);
227
+ } else if (!applied) {
228
+ console.log("\n确认后执行:laoshi migrate --apply");
229
+ console.log("回滚:laoshi migrate --rollback(恢复状态文件、删除新目录里迁移写入的文件;之后接着用 req-kit 1.x)");
230
+ }
231
+ }
232
+
233
+ async function main(): Promise<number> {
234
+ const { values } = parseArgs({
235
+ options: { from: { type: "string" }, to: { type: "string" }, apply: { type: "boolean", default: false }, rollback: { type: "boolean", default: false } },
236
+ allowPositionals: false,
237
+ });
238
+ const dirs = defaultDirs();
239
+ const from = values.from ? path.resolve(values.from) : dirs.from;
240
+ const to = values.to ? path.resolve(values.to) : dirs.to;
241
+ if (values.rollback) {
242
+ const r = rollbackMigration(to);
243
+ console.log(`已回滚:恢复了 ${r.restored.length} 个状态文件,删除了 ${r.removed.length} 个迁移写入的文件。`);
244
+ for (const k of r.kept) console.log(`· 没有恢复:${k}`);
245
+ console.log(`req-kit 1.x 继续使用 ${from}。`);
246
+ return 0;
247
+ }
248
+ const plan = planMigration(from, to);
249
+ if (!values.apply || plan.blockers.length) {
250
+ show(plan, false);
251
+ return plan.blockers.length ? 1 : 0;
252
+ }
253
+ applyMigration(plan);
254
+ show(plan, true);
255
+ console.log(`\n迁移记录:${path.join(to, RECORD_FILE)}。接下来:laoshi install --platform paseo,然后 laoshi doctor。`);
256
+ return 0;
257
+ }
258
+
259
+ if (process.argv[1] && import.meta.url === pathToFileURL(path.resolve(process.argv[1])).href) {
260
+ main().then(
261
+ (code) => process.exit(code),
262
+ (error) => {
263
+ console.error((error as Error).message);
264
+ process.exit(1);
265
+ },
266
+ );
267
+ }
@@ -0,0 +1,9 @@
1
+ laoshi 的需求在 Paseo 里的样子:本机所有项目的需求一页看完,哪些在等你确认、哪些卡住了、哪些在运行;点开一个需求,看它走到哪一步、每一步用了多久、质量门的结果,读需求说明、方案、确认预览、提测说明和完成报告。
2
+
3
+ 需要人处理的时候,可以直接在这里确认方案、停止、继续或开始测试验证。这些操作和在终端运行 `laoshi approve`、`laoshi stop`、`laoshi resume`、`laoshi verify` 完全一样,流水线本身不受插件影响;不想让人在网页上操作时,在插件设置中打开"只读"。
4
+
5
+ 在插件设置的"模型"一页,可以从 Paseo 中已登录的 agent 里选择 builder、reviewer 和备用模型,保存到 laoshi 的安装级配置,和在终端运行 `laoshi configure` 一样。
6
+
7
+ 还有:侧边栏的"需求"(带待处理数)、每个工作区头部的"需求"按钮和面板、步骤 agent 输入框旁的"需求"按钮,以及使用统计(交付周期、返工、等待、用量)。
8
+
9
+ 需要这台 daemon 上安装 laoshi,插件通过本机的 `laoshi api` 读取需求;它不连接任何外部服务。用 `laoshi plugin install` 安装和更新。
@@ -0,0 +1,216 @@
1
+ // "laoshi 配置" (1.12): every setting that applies, in plain words, with where each one comes
2
+ // from (default, this machine, the team, the project) and how to change it. Read-only: changes
3
+ // go through the files, laoshi configure, /laoshi-setup, or the model settings page.
4
+ import type { PluginHostProps, PluginScreenProps } from "@getpaseo/plugin/client";
5
+ import { ScrollView, TextInput } from "@getpaseo/plugin/client/react-native";
6
+ import { useMemo, useState } from "react";
7
+ import { Pressable, Text, View } from "react-native";
8
+ import type { ConfigItemData, ConfigLayer, ConfigViewData } from "../shared/contracts";
9
+ import { useConfigView, useRequirements } from "./data";
10
+ import { Badge, Chip, Status, useStyles } from "./ui";
11
+
12
+ type Theme = PluginHostProps["theme"];
13
+ type Layout = PluginHostProps["layout"];
14
+
15
+ const LAYER: Record<ConfigLayer, { label: string; tone: "accent" | "success" | "warning"; hint: string }> = {
16
+ machine: { label: "本机", tone: "accent", hint: "这台机器自己的设置" },
17
+ team: { label: "团队", tone: "warning", hint: "团队共用的配置,覆盖本机的同名设置" },
18
+ project: { label: "项目", tone: "success", hint: "项目仓库中的设置,覆盖本机和团队的" },
19
+ };
20
+
21
+ const SCOPE_NOTE: Record<ConfigItemData["scope"], string | null> = {
22
+ any: null,
23
+ machine: "只能在本机配置中设置",
24
+ machine_team: "只能在本机或团队配置中设置(会运行命令或发消息)",
25
+ };
26
+
27
+ /** Where an item's value comes from: the last file that set it to something other than the default. */
28
+ function originOf(item: ConfigItemData): ConfigLayer | null {
29
+ return item.changed ? (item.setBy.at(-1) ?? null) : null;
30
+ }
31
+
32
+ function ItemRow({ theme, layout, item }: { theme: Theme; layout: Layout; item: ConfigItemData }) {
33
+ const s = useStyles(theme, layout.compact);
34
+ const [open, setOpen] = useState(false);
35
+ const origin = originOf(item);
36
+ const scope = SCOPE_NOTE[item.scope];
37
+ return (
38
+ <Pressable
39
+ accessibilityRole="button"
40
+ accessibilityLabel={`${item.label}:${item.display}`}
41
+ accessibilityState={{ selected: open }}
42
+ onPress={() => setOpen((v) => !v)}
43
+ style={{ paddingVertical: 10, gap: 4 }}
44
+ >
45
+ <View style={[s.row, { justifyContent: "space-between", flexWrap: "nowrap" }]}>
46
+ <Text style={[s.text, { fontWeight: "600", flexShrink: 1 }]}>{item.label}</Text>
47
+ {origin ? (
48
+ <Badge theme={theme} tone={LAYER[origin].tone}>
49
+ {LAYER[origin].label}
50
+ </Badge>
51
+ ) : (
52
+ <Badge theme={theme} tone="muted">
53
+ 默认
54
+ </Badge>
55
+ )}
56
+ </View>
57
+ <Text style={s.text}>{item.display}</Text>
58
+ {item.description ? <Text style={s.muted}>{item.description}</Text> : null}
59
+ {open ? (
60
+ <View style={{ gap: 6, marginTop: 4 }}>
61
+ <Text style={s.muted}>
62
+ 配置项 <Text style={{ fontFamily: "monospace", color: theme.colors.foreground }}>{item.key}</Text>
63
+ {item.setBy.length > 0 ? ` · 写在${item.setBy.map((l) => LAYER[l].label).join("、")}配置中` : " · 没有在任何配置文件中写,用的是默认值"}
64
+ {scope ? ` · ${scope}` : ""}
65
+ </Text>
66
+ <View style={{ backgroundColor: theme.colors.surface0, borderRadius: 8, borderWidth: 1, borderColor: theme.colors.border, padding: 10 }}>
67
+ <Text selectable style={{ fontFamily: "monospace", fontSize: 12, color: theme.colors.foreground }}>
68
+ {JSON.stringify(item.value, null, 2) ?? "null"}
69
+ </Text>
70
+ </View>
71
+ </View>
72
+ ) : null}
73
+ </Pressable>
74
+ );
75
+ }
76
+
77
+ function Sources({ theme, layout, view }: { theme: Theme; layout: Layout; view: ConfigViewData }) {
78
+ const s = useStyles(theme, layout.compact);
79
+ return (
80
+ <View style={[s.card, { gap: 8 }]}>
81
+ <Text style={s.heading}>配置从哪里来</Text>
82
+ <Text style={s.muted}>按下面的顺序叠加,后面的覆盖前面的;没有写的用 laoshi 的默认值。</Text>
83
+ {view.sources.length === 0 ? <Text style={s.text}>还没有本机配置文件。在终端运行 laoshi install 生成。</Text> : null}
84
+ {view.sources.map((src, i) => (
85
+ <View key={src.path} style={[s.row, { flexWrap: "nowrap", alignItems: "flex-start" }]}>
86
+ <Text style={[s.muted, { width: 18 }]}>{i + 1}.</Text>
87
+ <Badge theme={theme} tone={LAYER[src.layer].tone}>
88
+ {LAYER[src.layer].label}
89
+ </Badge>
90
+ <View style={{ flexShrink: 1, gap: 2 }}>
91
+ <Text selectable style={[s.text, { fontFamily: "monospace", fontSize: 12 }]}>
92
+ {src.path}
93
+ </Text>
94
+ <Text style={s.muted}>{LAYER[src.layer].hint}</Text>
95
+ </View>
96
+ </View>
97
+ ))}
98
+ {view.ignored.length > 0 ? <Text style={{ color: theme.colors.statusWarning, fontSize: 13 }}>没有生效:{view.ignored.join("、")}(这些设置不能写在团队或项目配置中)</Text> : null}
99
+ </View>
100
+ );
101
+ }
102
+
103
+ export function ConfigScreen({ theme, layout }: PluginScreenProps) {
104
+ const s = useStyles(theme, layout.compact);
105
+ const requirements = useRequirements();
106
+ // A project is any checkout requirements were started from.
107
+ const projects = useMemo(() => {
108
+ const map = new Map<string, string>();
109
+ for (const r of requirements.data ?? []) if (r.present) map.set(r.sourceRepo ?? r.repo, r.project);
110
+ return [...map.entries()].sort((a, b) => a[1].localeCompare(b[1]));
111
+ }, [requirements.data]);
112
+ const [repo, setRepo] = useState<string | null>(null);
113
+ const [query, setQuery] = useState("");
114
+ const [changedOnly, setChangedOnly] = useState(false);
115
+ const config = useConfigView(repo);
116
+ const view = config.data;
117
+
118
+ const groups = useMemo(() => {
119
+ if (!view) return [];
120
+ const q = query.trim().toLowerCase();
121
+ return view.groups
122
+ .map((g) => ({
123
+ ...g,
124
+ items: g.items.filter(
125
+ (i) => (!changedOnly || i.changed) && (!q || `${i.label} ${i.key} ${i.display} ${i.description}`.toLowerCase().includes(q)),
126
+ ),
127
+ }))
128
+ .filter((g) => g.items.length > 0);
129
+ }, [view, query, changedOnly]);
130
+ const changedCount = view ? view.groups.reduce((n, g) => n + g.items.filter((i) => i.changed).length, 0) : 0;
131
+
132
+ return (
133
+ <View style={s.screen}>
134
+ <ScrollView contentContainerStyle={s.body}>
135
+ <View style={{ gap: 4 }}>
136
+ <Text style={s.title}>laoshi 配置</Text>
137
+ <Text style={s.muted}>这台机器上生效的全部设置,用大白话写出每一项是什么、现在是什么、来自哪个文件。这一页只看不改,修改方法在最下面。</Text>
138
+ </View>
139
+
140
+ <View style={{ gap: 6 }}>
141
+ <Text style={s.heading}>看哪里的配置</Text>
142
+ <View style={s.row}>
143
+ <Chip theme={theme} label="本机(不含项目)" active={repo === null} onPress={() => setRepo(null)} />
144
+ {projects.map(([dir, name]) => (
145
+ <Chip key={dir} theme={theme} label={name} active={repo === dir} onPress={() => setRepo(dir)} />
146
+ ))}
147
+ </View>
148
+ {projects.length === 0 ? <Text style={s.muted}>开始过需求的项目会出现在这里,可以看到项目配置叠加后的结果。</Text> : null}
149
+ </View>
150
+
151
+ <Status theme={theme} loading={config.isPending} error={config.error} />
152
+ {view ? (
153
+ <>
154
+ {view.error ? (
155
+ <View style={[s.card, { borderColor: theme.colors.statusDanger }]}>
156
+ <Text style={[s.text, { color: theme.colors.statusDanger, fontWeight: "600" }]}>配置有错误,流水线现在无法启动</Text>
157
+ <Text style={s.text}>{view.error}</Text>
158
+ <Text style={s.muted}>下面显示的是各文件中写的值。修好后在终端运行 laoshi doctor 检查。</Text>
159
+ </View>
160
+ ) : null}
161
+ <Sources theme={theme} layout={layout} view={view} />
162
+
163
+ <View style={{ gap: 8 }}>
164
+ <TextInput
165
+ value={query}
166
+ onChangeText={setQuery}
167
+ placeholder="搜索设置,例如:超时、备用模型、推送"
168
+ placeholderTextColor={theme.colors.foregroundMuted}
169
+ style={{
170
+ paddingHorizontal: 12,
171
+ paddingVertical: 8,
172
+ borderRadius: 8,
173
+ borderWidth: 1,
174
+ borderColor: theme.colors.border,
175
+ backgroundColor: theme.colors.surface1,
176
+ color: theme.colors.foreground,
177
+ fontSize: 14,
178
+ }}
179
+ />
180
+ <View style={s.row}>
181
+ <Chip theme={theme} label="全部" active={!changedOnly} onPress={() => setChangedOnly(false)} />
182
+ <Chip theme={theme} label={`只看改过的(${changedCount})`} active={changedOnly} onPress={() => setChangedOnly(true)} />
183
+ </View>
184
+ </View>
185
+
186
+ {groups.length === 0 ? <Text style={s.muted}>{changedOnly && !query ? "所有设置都是默认值。" : "没有符合的设置。"}</Text> : null}
187
+ {groups.map((g) => (
188
+ <View key={g.id} style={{ gap: 6 }}>
189
+ <View style={{ gap: 2 }}>
190
+ <Text style={[s.text, { fontSize: 15, fontWeight: "600" }]}>{g.title}</Text>
191
+ <Text style={s.muted}>{g.description}</Text>
192
+ </View>
193
+ <View style={[s.card, { paddingVertical: 2 }]}>
194
+ {g.items.map((item, i) => (
195
+ <View key={item.key}>
196
+ {i > 0 ? <View style={s.divider} /> : null}
197
+ <ItemRow theme={theme} layout={layout} item={item} />
198
+ </View>
199
+ ))}
200
+ </View>
201
+ </View>
202
+ ))}
203
+
204
+ <View style={[s.card, { gap: 6 }]}>
205
+ <Text style={s.heading}>怎么修改</Text>
206
+ <Text style={s.text}>· 模型(builder、reviewer、备用模型):设置 → 插件 → laoshi → 模型,或在终端运行 laoshi configure。</Text>
207
+ <Text style={s.text}>· 项目的检查命令、服务启动方式、接哪些卡片:在项目的对话中运行 /laoshi-setup。</Text>
208
+ <Text style={s.text}>· 其他设置:编辑上面"配置从哪里来"中的文件,写法见 laoshi 文档的《项目定制与运行规则》。改完运行 laoshi doctor 检查。</Text>
209
+ <Text style={s.muted}>密码、令牌等看起来像密钥的值和个人账号不会在这里显示。</Text>
210
+ </View>
211
+ </>
212
+ ) : null}
213
+ </ScrollView>
214
+ </View>
215
+ );
216
+ }
@@ -0,0 +1,85 @@
1
+ // Data hooks: every read is an RPC to the daemon side (laoshi api), cached by React Query.
2
+ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
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";
5
+
6
+ export function usePreferences(): { readOnly: boolean; refreshMs: number } {
7
+ const settings = useSettings(preferences);
8
+ if (settings.status !== "ready") return { readOnly: true, refreshMs: 10_000 };
9
+ return { readOnly: settings.values.readOnly, refreshMs: settings.values.refreshSeconds * 1000 };
10
+ }
11
+
12
+ export function useRequirements() {
13
+ const list = useRpc(listRpc);
14
+ const { refreshMs } = usePreferences();
15
+ return useQuery({ queryKey: ["req", "list"], queryFn: () => list({}), refetchInterval: refreshMs });
16
+ }
17
+
18
+ export function useRequirement(repo: string, featureDir: string) {
19
+ const status = useRpc(statusRpc);
20
+ const { refreshMs } = usePreferences();
21
+ return useQuery({
22
+ queryKey: ["req", "status", repo, featureDir],
23
+ queryFn: () => status({ repo, featureDir }),
24
+ refetchInterval: refreshMs,
25
+ enabled: Boolean(repo && featureDir),
26
+ });
27
+ }
28
+
29
+ export function useDocument(repo: string, featureDir: string, file: string | null) {
30
+ const read = useRpc(fileRpc);
31
+ return useQuery({
32
+ queryKey: ["req", "file", repo, featureDir, file],
33
+ queryFn: () => read({ repo, featureDir, file: file ?? "" }),
34
+ enabled: Boolean(file),
35
+ });
36
+ }
37
+
38
+ export function useStats(period: { since?: string; month?: string }) {
39
+ const stats = useRpc(statsRpc);
40
+ return useQuery({ queryKey: ["req", "stats", period.since ?? "", period.month ?? ""], queryFn: () => stats(period) });
41
+ }
42
+
43
+ export function useKitInfo() {
44
+ const version = useRpc(versionRpc);
45
+ return useQuery({ queryKey: ["req", "version"], queryFn: () => version({}), retry: false });
46
+ }
47
+
48
+ export function useAction() {
49
+ const run = useRpc(runRpc);
50
+ const queries = useQueryClient();
51
+ return useMutation({
52
+ mutationFn: (input: { action: Action; repo: string; featureDir: string; verifyEnv?: "local" | "deployed"; text?: string }) => run(input),
53
+ onSettled: () => queries.invalidateQueries({ queryKey: ["req"] }),
54
+ });
55
+ }
56
+
57
+ export function useModels() {
58
+ const models = useRpc(modelsRpc);
59
+ return useQuery({ queryKey: ["req", "models"], queryFn: () => models({}), retry: false });
60
+ }
61
+
62
+ export function useSetAgents() {
63
+ const set = useRpc(setAgentsRpc);
64
+ const queries = useQueryClient();
65
+ return useMutation({
66
+ mutationFn: (input: { builder: AgentProfileData; reviewer: AgentProfileData; fallback: AgentProfileData | null }) => set(input),
67
+ onSettled: () => queries.invalidateQueries({ queryKey: ["req", "models"] }),
68
+ });
69
+ }
70
+
71
+ export function useConfigView(repo: string | null) {
72
+ const config = useRpc(configRpc);
73
+ return useQuery({ queryKey: ["req", "config", repo ?? ""], queryFn: () => config(repo ? { repo } : {}), retry: false });
74
+ }
75
+
76
+ /** The prototype review page's address (1.13); it stays valid while its server runs. */
77
+ export function useReviewUrl(repo: string, featureDir: string, enabled: boolean, page: "prototype" | "check" | "code" = "prototype") {
78
+ const reviewUrl = useRpc(reviewUrlRpc);
79
+ return useQuery({
80
+ queryKey: ["req", "review-url", repo, featureDir, page],
81
+ queryFn: () => reviewUrl({ repo, featureDir, ...(page !== "prototype" ? { page } : {}) }),
82
+ enabled: enabled && Boolean(repo && featureDir),
83
+ retry: false,
84
+ });
85
+ }