@yiyi_zhang/laoshi 0.2.0-beta.1 → 0.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/adapters/cli/adapter.ts +53 -0
- package/adapters/cli/cli-runtime.ts +402 -0
- package/adapters/cli/drivers.ts +146 -0
- package/adapters/cli/install.mjs +28 -0
- package/adapters/cli/skill/setup.md +8 -0
- package/adapters/dsh/plugin/index.mjs +1 -1
- package/adapters/dsh/plugin/package.json +1 -1
- package/adapters/mogao/adapter.ts +1 -0
- package/adapters/mogao/install.mjs +1 -1
- package/adapters/mogao/make-expert.mjs +1 -0
- package/adapters/mogao/mogao-runtime.ts +57 -8
- package/adapters/paseo/adapter.ts +1 -1
- package/adapters/paseo/install.mjs +17 -5
- package/adapters/paseo/migrate.ts +267 -0
- package/adapters/paseo/plugin/OVERVIEW.md +9 -0
- package/adapters/paseo/plugin/client/config.tsx +216 -0
- package/adapters/paseo/plugin/client/data.ts +85 -0
- package/adapters/paseo/plugin/client/detail.tsx +342 -0
- package/adapters/paseo/plugin/client/format.ts +173 -0
- package/adapters/paseo/plugin/client/inbox.tsx +190 -0
- package/adapters/paseo/plugin/client/live.ts +161 -0
- package/adapters/paseo/plugin/client/markdown.tsx +220 -0
- package/adapters/paseo/plugin/client/models.tsx +117 -0
- package/adapters/paseo/plugin/client/nav.ts +22 -0
- package/adapters/paseo/plugin/client/overview.tsx +103 -0
- package/adapters/paseo/plugin/client/panel.tsx +56 -0
- package/adapters/paseo/plugin/client/review.tsx +80 -0
- package/adapters/paseo/plugin/client/row.tsx +63 -0
- package/adapters/paseo/plugin/client/settings.tsx +92 -0
- package/adapters/paseo/plugin/client/sidebar.tsx +27 -0
- package/adapters/paseo/plugin/client/stats.tsx +138 -0
- package/adapters/paseo/plugin/client/ui.tsx +278 -0
- package/adapters/paseo/plugin/client/web.ts +34 -0
- package/adapters/paseo/plugin/index.client.tsx +66 -0
- package/adapters/paseo/plugin/index.server.ts +61 -0
- package/adapters/paseo/plugin/package.json +22 -0
- package/adapters/paseo/plugin/paseo-plugin.json +6 -0
- package/adapters/paseo/plugin/server/handlers.ts +69 -0
- package/adapters/paseo/plugin/server/req.ts +105 -0
- package/adapters/paseo/plugin/shared/contracts.ts +286 -0
- package/adapters/paseo/plugin/shared/rk-colors.ts +35 -0
- package/adapters/paseo/plugin/tsconfig.json +16 -0
- package/adapters/paseo/plugin-cmd.mjs +233 -0
- package/bin/install.mjs +8 -7
- package/bin/req.mjs +10 -2
- package/contracts/README.md +1 -1
- package/contracts/agent-runtime.md +2 -2
- package/contracts/cli-json.md +4 -3
- package/contracts/notifier-event.md +2 -2
- package/contracts/state.md +2 -0
- package/contracts/usage-record.md +3 -3
- package/docs/design/adapter-guide.md +2 -1
- package/docs/design/cli-adapter.md +75 -0
- package/docs/design/compat-migration.md +2 -0
- package/docs/design/mogao-expert.md +3 -1
- package/docs/guide//345/234/250/346/221/270/351/253/230/344/270/212/344/275/277/347/224/250.md +132 -0
- package/docs/guide//345/256/211/350/243/205/344/270/216/345/215/207/347/272/247.md +32 -3
- package/docs/guide//347/273/264/346/212/244/350/200/205/346/214/207/345/215/227.md +4 -2
- package/docs/guide//351/241/271/347/233/256/345/256/232/345/210/266/344/270/216/350/277/220/350/241/214/350/247/204/345/210/231.md +1 -1
- package/engine/src/api.ts +4 -0
- package/engine/src/doctor.ts +3 -2
- package/engine/src/identity.ts +16 -1
- package/engine/src/main.ts +3 -1
- package/engine/src/messages.ts +1 -1
- package/engine/src/platform.ts +2 -0
- package/engine/src/runtime-loader.ts +14 -0
- package/engine/src/state.ts +2 -0
- package/engine/src/words.ts +1 -1
- package/package.json +2 -1
- package/site-dist/404.html +2 -2
- package/site-dist/assets/{app.DMAHANCl.js → app.D2ywvSfZ.js} +1 -1
- package/site-dist/assets/changelog.md.EDul9PkX.js +1 -0
- package/site-dist/assets/changelog.md.EDul9PkX.lean.js +1 -0
- package/site-dist/assets/chunks/@localSearchIndexroot.Dr_jsw66.js +1 -0
- package/site-dist/assets/chunks/{VPLocalSearchBox.COsLwqWS.js → VPLocalSearchBox.ClWffKqN.js} +1 -1
- package/site-dist/assets/chunks/{theme.CeR3HD86.js → theme.tbt16E5a.js} +2 -2
- package/site-dist/assets/guide_cli.md.BrXllHw9.js +2 -0
- package/site-dist/assets/guide_cli.md.BrXllHw9.lean.js +2 -0
- package/site-dist/assets/{guide_getting-started.md.Bytaz3L8.js → guide_getting-started.md.qAp5hWCl.js} +1 -1
- package/site-dist/assets/guide_install.md.By4WxsJG.js +24 -0
- package/site-dist/assets/guide_install.md.By4WxsJG.lean.js +24 -0
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.js +1 -0
- package/site-dist/assets/guide_maintainer.md.Da1ffqxm.lean.js +1 -0
- package/site-dist/assets/guide_mogao.md.S0eln1Pr.js +10 -0
- package/site-dist/assets/guide_mogao.md.S0eln1Pr.lean.js +10 -0
- package/site-dist/assets/{guide_project.md.BIcaDhdS.js → guide_project.md.B2cmf8YF.js} +1 -1
- package/site-dist/assets/{guide_project.md.BIcaDhdS.lean.js → guide_project.md.B2cmf8YF.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_agent-runtime.md.DPE2FJFc.js +1 -0
- package/site-dist/assets/{reference_contracts_agent-runtime.md.TK7Lhwdf.lean.js → reference_contracts_agent-runtime.md.DPE2FJFc.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.js +1 -0
- package/site-dist/assets/reference_contracts_cli-json.md.D6vfWOD9.lean.js +1 -0
- package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.js → reference_contracts_index.md.B5P4FjRk.js} +1 -1
- package/site-dist/assets/{reference_contracts_index.md.dqNwNs6U.lean.js → reference_contracts_index.md.B5P4FjRk.lean.js} +1 -1
- package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.js → reference_contracts_notifier-event.md.BeR8iODP.js} +1 -1
- package/site-dist/assets/{reference_contracts_notifier-event.md.D6we9wWS.lean.js → reference_contracts_notifier-event.md.BeR8iODP.lean.js} +1 -1
- package/site-dist/assets/reference_contracts_state.md.DLygjkfs.js +1 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.js +10 -0
- package/site-dist/assets/reference_contracts_usage-record.md.CgfMoYp0.lean.js +10 -0
- package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.js → reference_design_adapter-guide.md.B_P-spS5.js} +2 -2
- package/site-dist/assets/{reference_design_adapter-guide.md.BSziZJSM.lean.js → reference_design_adapter-guide.md.B_P-spS5.lean.js} +2 -2
- package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.js +13 -0
- package/site-dist/assets/reference_design_cli-adapter.md.pJy3x6Un.lean.js +13 -0
- package/site-dist/changelog.html +5 -5
- package/site-dist/guide/cli.html +31 -0
- package/site-dist/guide/dsh.html +5 -5
- package/site-dist/guide/getting-started.html +5 -5
- package/site-dist/guide/how-it-works.html +4 -4
- package/site-dist/guide/index.html +4 -4
- package/site-dist/guide/install.html +13 -8
- package/site-dist/guide/intranet.html +5 -5
- package/site-dist/guide/maintainer.html +5 -5
- package/site-dist/guide/mogao.html +39 -0
- package/site-dist/guide/phases.html +4 -4
- package/site-dist/guide/project.html +6 -6
- package/site-dist/guide/user.html +4 -4
- package/site-dist/hashmap.json +1 -1
- package/site-dist/index.html +4 -4
- package/site-dist/reference/adr/0001-new-repo-core-and-adapters.html +4 -4
- package/site-dist/reference/adr/0002-two-orchestration-modes.html +4 -4
- package/site-dist/reference/adr/0003-generate-once-then-lock.html +4 -4
- package/site-dist/reference/adr/0004-external-contracts-stay-stable.html +4 -4
- package/site-dist/reference/adr/0005-skill-names.html +4 -4
- package/site-dist/reference/adr/0006-deterministic-engine-platform-capabilities.html +4 -4
- package/site-dist/reference/adr/0007-one-install-many-repos.html +4 -4
- package/site-dist/reference/adr/0008-capability-sources-and-platform-plugin.html +4 -4
- package/site-dist/reference/adr/index.html +4 -4
- package/site-dist/reference/commands.html +4 -4
- package/site-dist/reference/config.html +4 -4
- package/site-dist/reference/contracts/agent-runtime.html +5 -5
- package/site-dist/reference/contracts/cli-json.html +5 -5
- package/site-dist/reference/contracts/feature-files.html +4 -4
- package/site-dist/reference/contracts/index.html +5 -5
- package/site-dist/reference/contracts/notifier-event.html +6 -6
- package/site-dist/reference/contracts/result-file.html +4 -4
- package/site-dist/reference/contracts/spec.html +4 -4
- package/site-dist/reference/contracts/state.html +5 -5
- package/site-dist/reference/contracts/usage-record.html +6 -6
- package/site-dist/reference/contracts/verify.html +4 -4
- package/site-dist/reference/design/adapter-guide.html +6 -6
- package/site-dist/reference/design/architecture.html +4 -4
- package/site-dist/reference/design/builtin-capabilities.html +4 -4
- package/site-dist/reference/design/cli-adapter.html +42 -0
- package/site-dist/reference/design/platform-vocabulary.html +4 -4
- package/site-dist/reference/scope.html +4 -4
- package/site-dist/assets/changelog.md.Q8QGpuBY.js +0 -1
- package/site-dist/assets/changelog.md.Q8QGpuBY.lean.js +0 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.CQdjFK3w.js +0 -1
- package/site-dist/assets/guide_install.md.D7NiiOPu.js +0 -19
- package/site-dist/assets/guide_install.md.D7NiiOPu.lean.js +0 -19
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.js +0 -1
- package/site-dist/assets/guide_maintainer.md.C-Vt-DdK.lean.js +0 -1
- package/site-dist/assets/reference_contracts_agent-runtime.md.TK7Lhwdf.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.js +0 -1
- package/site-dist/assets/reference_contracts_cli-json.md.Bonk0m6-.lean.js +0 -1
- package/site-dist/assets/reference_contracts_state.md.DVHC4opX.js +0 -1
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.js +0 -10
- package/site-dist/assets/reference_contracts_usage-record.md.CQI2chqh.lean.js +0 -10
- /package/site-dist/assets/{guide_getting-started.md.Bytaz3L8.lean.js → guide_getting-started.md.qAp5hWCl.lean.js} +0 -0
- /package/site-dist/assets/{reference_contracts_state.md.DVHC4opX.lean.js → reference_contracts_state.md.DLygjkfs.lean.js} +0 -0
|
@@ -14,7 +14,7 @@ import { channelPaths, dshHome } from "./channel.mjs";
|
|
|
14
14
|
export const name = "laoshi-dsh";
|
|
15
15
|
export const inject = ["agents", "subagents", "schedule", "approval", "sessionController", "llm"];
|
|
16
16
|
|
|
17
|
-
const VERSION = "0.2.0-beta.
|
|
17
|
+
const VERSION = "0.2.0-beta.2";
|
|
18
18
|
const SHELL_TOOLS = new Set(["bash", "pwsh"]);
|
|
19
19
|
const SEARCH_TOOLS = new Set(["grep", "glob"]);
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "laoshi-dsh-plugin",
|
|
3
|
-
"version": "0.2.0-beta.
|
|
3
|
+
"version": "0.2.0-beta.2",
|
|
4
4
|
"private": true,
|
|
5
5
|
"description": "laoshi's plugin for the DeepSeek Harness host: creates step agents under the chat, schedules messages, answers approvals by policy, and serves the laoshi engine over a local socket (ADR 0008).",
|
|
6
6
|
"type": "module",
|
|
@@ -21,6 +21,7 @@ export const mogaoAdapter: PlatformAdapter = {
|
|
|
21
21
|
toolCalls: "platform",
|
|
22
22
|
},
|
|
23
23
|
originEnv: { id: "AIMAX_SESSION_ID" },
|
|
24
|
+
userEnv: "AIMAX_USER_NAME",
|
|
24
25
|
runsInChat: true,
|
|
25
26
|
skillSetup: path.join(path.dirname(fileURLToPath(import.meta.url)), "skill", "setup.md"),
|
|
26
27
|
words: {
|
|
@@ -24,7 +24,7 @@ export function skillTargets(args, config, env = process.env, home) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
export function setup({ report }) {
|
|
27
|
-
report("info", "步骤 agent 用摸高的 aimax
|
|
27
|
+
report("info", "步骤 agent 用摸高的 aimax 命令运行;在摸高上安装根放在工作区 /data/workspace/.laoshi,程序装在它的 npm 目录里,命令据此找到安装根(专家第一次使用时就这样安装)");
|
|
28
28
|
return ["把上面专家的 skill 目录提交为摸高的专家(或在对话里加载它)", "体检:laoshi doctor --no-project"];
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -43,6 +43,7 @@ fs.writeFileSync(
|
|
|
43
43
|
"- 入口:`/laoshi`(需求开发)、`/laoshi-setup`(项目接入,每个项目一次)、`/laoshi-doctor`(体检)、`/laoshi-retro`(复盘)",
|
|
44
44
|
`- 第一次使用时,入口 skill 会从内网 npm 镜像把 \`${pkg.name}@${pkg.version}\` 装到 \`${WORKSPACE_HOME}\`(约一分钟),之后每个对话直接使用`,
|
|
45
45
|
"- 每一步是摸高的一个独立 agent(`aimax run`);需要批准的操作走摸高的人工审批;进度和用量来自摸高的回调",
|
|
46
|
+
"- 使用说明(第一次使用、项目接入、运行期间不要结束对话、等待批准怎么回答、常见问题):https://yiyisf.github.io/laoshi/guide/mogao",
|
|
46
47
|
"",
|
|
47
48
|
"## 包含的 skill",
|
|
48
49
|
"",
|
|
@@ -101,6 +101,8 @@ interface AgentRecord {
|
|
|
101
101
|
host: string | null;
|
|
102
102
|
/** The HITL request a decision was sent for (decision.json), so it is answered once. */
|
|
103
103
|
answered: string | null;
|
|
104
|
+
/** When the latest run started: its callback events are the ones after this. */
|
|
105
|
+
runStartedAt?: string | null;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/** A decision on a pending approval, written by `laoshi permission` (answerPermission). */
|
|
@@ -114,6 +116,9 @@ const CONTINUE_MESSAGE = "上一次运行被中断了(对话轮次结束)。
|
|
|
114
116
|
|
|
115
117
|
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
116
118
|
|
|
119
|
+
/** How long a run may stay after printing its result before it counts as lingering. */
|
|
120
|
+
const LINGER_GRACE_MS = 2_000;
|
|
121
|
+
|
|
117
122
|
const isAlive = (pid: number) => engineProcessAlive(pid);
|
|
118
123
|
|
|
119
124
|
/** The callback receiver: one local HTTP server for all step agents of this engine process. */
|
|
@@ -210,7 +215,7 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
|
|
|
210
215
|
Object.assign(keep, { input: data.input ?? null, output: data.output ?? null, total: data.total ?? null });
|
|
211
216
|
} else if (type === "done") {
|
|
212
217
|
const result = (data.result ?? {}) as Record<string, unknown>;
|
|
213
|
-
Object.assign(keep, { usage: result.usage ?? null });
|
|
218
|
+
Object.assign(keep, { usage: result.usage ?? null, text: typeof result.text === "string" ? redact(result.text).slice(0, 4000) : null });
|
|
214
219
|
} else if (type !== "start" && type !== "title_updated") {
|
|
215
220
|
return;
|
|
216
221
|
}
|
|
@@ -251,12 +256,16 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
|
|
|
251
256
|
fs.closeSync(out);
|
|
252
257
|
fs.closeSync(err);
|
|
253
258
|
children.set(record.id, child);
|
|
254
|
-
|
|
259
|
+
// A lingering run stopped after its result can exit after the next run started: forget only itself.
|
|
260
|
+
const forget = () => {
|
|
261
|
+
if (children.get(record.id) === child) children.delete(record.id);
|
|
262
|
+
};
|
|
263
|
+
child.on("exit", forget);
|
|
255
264
|
child.on("error", (e) => {
|
|
256
265
|
fs.appendFileSync(path.join(dir(record.id), `run-${n}.err`), `\n${e.message}\n`);
|
|
257
|
-
|
|
266
|
+
forget();
|
|
258
267
|
});
|
|
259
|
-
write({ ...record, runs: n, pid: child.pid ?? null, host: os.hostname() });
|
|
268
|
+
write({ ...record, runs: n, pid: child.pid ?? null, host: os.hostname(), runStartedAt: new Date().toISOString() });
|
|
260
269
|
}
|
|
261
270
|
|
|
262
271
|
const runArgs = (record: AgentRecord, message: string) => [
|
|
@@ -271,10 +280,14 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
|
|
|
271
280
|
...(settings.pluginsConfig ? ["--plugins-config", settings.pluginsConfig] : []),
|
|
272
281
|
];
|
|
273
282
|
|
|
274
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* The latest run's result; null while it runs (here, or in another live process of this machine).
|
|
285
|
+
* A run whose agent is done but whose `aimax run` process has not exited (seen in the sandbox:
|
|
286
|
+
* the engine then waited until the platform ended its command) counts as finished once its
|
|
287
|
+
* result is complete in its output or the platform's callback reported "done"; the lingering
|
|
288
|
+
* process is stopped.
|
|
289
|
+
*/
|
|
275
290
|
function finished(record: AgentRecord): { result: RunResult | null; stderr: string } | null {
|
|
276
|
-
if (children.has(record.id)) return null;
|
|
277
|
-
if (record.pid && record.host === os.hostname() && isAlive(record.pid)) return null;
|
|
278
291
|
const read = (suffix: string) => {
|
|
279
292
|
try {
|
|
280
293
|
return fs.readFileSync(path.join(dir(record.id), `run-${record.runs}.${suffix}`), "utf8");
|
|
@@ -282,7 +295,43 @@ export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
|
|
|
282
295
|
return "";
|
|
283
296
|
}
|
|
284
297
|
};
|
|
285
|
-
|
|
298
|
+
// Only the latest run's own process counts (an earlier run's may still be exiting).
|
|
299
|
+
const tracked = children.get(record.id);
|
|
300
|
+
const child = tracked && tracked.pid === record.pid && record.host === os.hostname() ? tracked : undefined;
|
|
301
|
+
const alive = !!child || (!!record.pid && record.host === os.hostname() && isAlive(record.pid));
|
|
302
|
+
const result = parseRunOutput(read("out"));
|
|
303
|
+
if (!alive) return { result, stderr: read("err") };
|
|
304
|
+
const complete = result && (result.paused || result.error || typeof result.text === "string");
|
|
305
|
+
const done = complete ? null : doneEvent(record);
|
|
306
|
+
if (!complete && !done) return null;
|
|
307
|
+
// A process that has just printed its result usually exits a moment later: give it that moment.
|
|
308
|
+
const since = (() => {
|
|
309
|
+
try {
|
|
310
|
+
return Date.now() - fs.statSync(path.join(dir(record.id), `run-${record.runs}.out`)).mtimeMs;
|
|
311
|
+
} catch {
|
|
312
|
+
return Infinity;
|
|
313
|
+
}
|
|
314
|
+
})();
|
|
315
|
+
if (complete && since < LINGER_GRACE_MS) return null;
|
|
316
|
+
log(`agent ${record.id} 已经做完,但 aimax run 进程还没有退出:按已完成处理,并结束这个进程`);
|
|
317
|
+
if (child) child.kill("SIGTERM");
|
|
318
|
+
else if (record.pid) {
|
|
319
|
+
try {
|
|
320
|
+
process.kill(record.pid, "SIGTERM");
|
|
321
|
+
} catch {
|
|
322
|
+
// Gone meanwhile.
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
return { result: complete ? result : { sessionId: record.sessionId ?? undefined, text: done!.text ?? "", usage: done!.usage ?? null }, stderr: read("err") };
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/** The platform's "done" callback for the latest run, if it came. */
|
|
329
|
+
function doneEvent(record: AgentRecord): { text: string | null; usage: RunResult["usage"] } | null {
|
|
330
|
+
if (!record.runStartedAt) return null;
|
|
331
|
+
const e = events(record.id).filter((x) => x.type === "done" && String(x.at) >= record.runStartedAt!).at(-1);
|
|
332
|
+
if (!e) return null;
|
|
333
|
+
const usage = (e.usage ?? null) as RunResult["usage"];
|
|
334
|
+
return { text: typeof e.text === "string" ? e.text : null, usage };
|
|
286
335
|
}
|
|
287
336
|
|
|
288
337
|
const stepAgent = (id: string): StepAgent => ({
|
|
@@ -68,7 +68,7 @@ export const paseoAdapter: PlatformAdapter = {
|
|
|
68
68
|
requirementPage: "Paseo 侧边栏的\"需求\"",
|
|
69
69
|
browser: "Paseo 内置的浏览器(`browser_*` 工具)",
|
|
70
70
|
browserWatch: "需求方可以在 Paseo 桌面端实时看到你在浏览器中的操作。",
|
|
71
|
-
requirementView: "Paseo 的
|
|
71
|
+
requirementView: "Paseo 的 laoshi 插件",
|
|
72
72
|
connectFix: "确认 Paseo 桌面端或 daemon 在运行;设置了密码时,确认环境变量(默认 `PASEO_DAEMON_PASSWORD`)已设置。",
|
|
73
73
|
},
|
|
74
74
|
skillSetup: fileURLToPath(new URL("./skill/setup.md", import.meta.url)),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
// laoshi installer, Paseo part (bin/install.mjs): Paseo's agents read skills from the user-level
|
|
2
|
-
// skills directories, as req-kit installed them. The Paseo plugin (requirement views in Paseo
|
|
3
|
-
//
|
|
2
|
+
// skills directories, as req-kit installed them. The Paseo plugin (requirement views in Paseo,
|
|
3
|
+
// adapters/paseo/plugin) is installed with `laoshi plugin install` and refreshed here on upgrades.
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
7
8
|
|
|
8
9
|
export const id = "paseo";
|
|
9
10
|
export const options = {};
|
|
@@ -22,9 +23,20 @@ export function skillTargets() {
|
|
|
22
23
|
return roots;
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
export function setup({ report }) {
|
|
26
|
-
|
|
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
|
+
const staged = fs.existsSync(path.join(stagedDir(home), "paseo-plugin.json"));
|
|
29
|
+
if (staged && !dry) {
|
|
30
|
+
// Installed before: refresh its files from this version and reload it in Paseo.
|
|
31
|
+
refreshPlugin({ kitRoot: kit, env: { ...process.env, LAOSHI_HOME: home }, log: (m) => report("ok", m) });
|
|
32
|
+
} else if (!staged) {
|
|
33
|
+
report("info", "Paseo 的需求插件(在 Paseo 里看需求、确认方案、停止和继续):laoshi plugin install");
|
|
34
|
+
}
|
|
27
35
|
return ["在终端运行 laoshi configure,选择 builder 和 reviewer 用的 agent"];
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
export function uninstall() {
|
|
38
|
+
export async function uninstall({ home } = {}) {
|
|
39
|
+
if (!home) return;
|
|
40
|
+
const { removePlugin, stagedDir } = await import(new URL("./plugin-cmd.mjs", import.meta.url).href);
|
|
41
|
+
if (fs.existsSync(stagedDir(home))) removePlugin({ env: { ...process.env, LAOSHI_HOME: home } });
|
|
42
|
+
}
|
|
@@ -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` 安装和更新。
|