@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.
- package/CHANGELOG.md +32 -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 +47 -0
- package/adapters/mogao/install.mjs +31 -0
- package/adapters/mogao/make-expert.mjs +64 -0
- package/adapters/mogao/mogao-runtime.ts +506 -0
- package/adapters/mogao/skill/setup.md +21 -0
- 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 +12 -5
- package/bin/req.mjs +18 -2
- package/contracts/README.md +1 -1
- package/contracts/agent-runtime.md +5 -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 +103 -0
- 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 +9 -5
- package/engine/src/code-review.ts +2 -2
- package/engine/src/control.ts +6 -6
- package/engine/src/danger-guard.ts +7 -0
- package/engine/src/doctor.ts +4 -3
- package/engine/src/features.ts +2 -2
- package/engine/src/identity.ts +16 -1
- package/engine/src/integration-cmd.ts +2 -2
- package/engine/src/launch.ts +44 -6
- package/engine/src/locations.ts +15 -1
- package/engine/src/main.ts +6 -1
- package/engine/src/messages.ts +1 -1
- package/engine/src/permission-cmd.ts +56 -0
- package/engine/src/platform.ts +7 -0
- package/engine/src/preflight.ts +2 -2
- package/engine/src/runtime-loader.ts +16 -0
- package/engine/src/runtime.ts +5 -0
- package/engine/src/skills-render.ts +10 -6
- package/engine/src/state.ts +25 -1
- package/engine/src/words.ts +1 -1
- package/package.json +2 -1
- package/site-dist/404.html +2 -2
- package/site-dist/assets/{app.Df99UgrJ.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.IEhP6Gw5.js → VPLocalSearchBox.ClWffKqN.js} +1 -1
- package/site-dist/assets/chunks/{theme.DHubfO7g.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.BZTWiHhH.js → guide_getting-started.md.qAp5hWCl.js} +1 -1
- package/site-dist/assets/{guide_getting-started.md.BZTWiHhH.lean.js → guide_getting-started.md.qAp5hWCl.lean.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.Bu8q-uGl.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/skills/laoshi/SKILL.md +3 -0
- package/skills/laoshi-doctor/SKILL.md +2 -0
- package/skills/laoshi-retro/SKILL.md +2 -0
- package/skills/laoshi-setup/SKILL.md +3 -0
- package/site-dist/assets/changelog.md.Df8vFhjK.js +0 -1
- package/site-dist/assets/changelog.md.Df8vFhjK.lean.js +0 -1
- package/site-dist/assets/chunks/@localSearchIndexroot.n-0kN-N0.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.Bu8q-uGl.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/{reference_contracts_state.md.DVHC4opX.lean.js → reference_contracts_state.md.DLygjkfs.lean.js} +0 -0
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
// `laoshi plugin`: laoshi's plugin for Paseo (ported from paseo-req-kit's `req plugin`).
|
|
2
|
+
//
|
|
3
|
+
// laoshi plugin install [--yes] copy the plugin to <install root>/paseo-plugin and install it in Paseo
|
|
4
|
+
// laoshi plugin status whether it is installed and running
|
|
5
|
+
// laoshi plugin remove remove it from Paseo
|
|
6
|
+
//
|
|
7
|
+
// The plugin ships inside this package (adapters/paseo/plugin/). It is installed from a fixed copy
|
|
8
|
+
// under the install root, so `laoshi install` / `laoshi upgrade` only refresh that copy and reload
|
|
9
|
+
// the plugin (refreshPlugin, called from adapters/paseo/install.mjs); the plugin always matches the
|
|
10
|
+
// installed version. Turning on Paseo's plugin switch (pluginsEnabled) needs the person's consent:
|
|
11
|
+
// plugins run unsandboxed on this machine. req-kit's own plugin (id "req-kit") is a different one:
|
|
12
|
+
// it is not touched here, only pointed out.
|
|
13
|
+
import { spawnSync } from "node:child_process";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import os from "node:os";
|
|
16
|
+
import path from "node:path";
|
|
17
|
+
import readline from "node:readline";
|
|
18
|
+
import { fileURLToPath } from "node:url";
|
|
19
|
+
|
|
20
|
+
export const PLUGIN_ID = "laoshi";
|
|
21
|
+
const OLD_PLUGIN_ID = "req-kit";
|
|
22
|
+
const KIT_ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..");
|
|
23
|
+
|
|
24
|
+
/** The install root: LAOSHI_HOME, else the root this program is installed in, else ~/.laoshi. */
|
|
25
|
+
export function kitHome(env = process.env, kitRoot = KIT_ROOT) {
|
|
26
|
+
const override = env.LAOSHI_HOME?.trim();
|
|
27
|
+
if (override) return path.resolve(override);
|
|
28
|
+
const m = /^(.*)[\\/]npm[\\/](?:lib[\\/])?node_modules[\\/]/.exec(kitRoot);
|
|
29
|
+
if (m && fs.existsSync(path.join(m[1], "config.json"))) return m[1];
|
|
30
|
+
return path.join(os.homedir(), ".laoshi");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function stagedDir(home = kitHome()) {
|
|
34
|
+
return path.join(home, "paseo-plugin");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Copies this version's plugin to the fixed directory Paseo installs from. */
|
|
38
|
+
export function stagePlugin(kitRoot = KIT_ROOT, home = kitHome()) {
|
|
39
|
+
const from = path.join(kitRoot, "adapters", "paseo", "plugin");
|
|
40
|
+
if (!fs.existsSync(path.join(from, "paseo-plugin.json"))) throw new Error(`这个版本的 laoshi 没有附带 Paseo 插件(${from})`);
|
|
41
|
+
const to = stagedDir(home);
|
|
42
|
+
fs.rmSync(to, { recursive: true, force: true });
|
|
43
|
+
fs.cpSync(from, to, {
|
|
44
|
+
recursive: true,
|
|
45
|
+
filter: (src) => !path.relative(from, src).split(path.sep).includes("node_modules"),
|
|
46
|
+
});
|
|
47
|
+
return to;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The paseo command: LAOSHI_PASEO_BIN (tests; empty means none), else paseo on PATH. */
|
|
51
|
+
function paseoCommand(env = process.env) {
|
|
52
|
+
if (env.LAOSHI_PASEO_BIN !== undefined) return env.LAOSHI_PASEO_BIN || null;
|
|
53
|
+
const cmd = process.platform === "win32" ? "paseo.cmd" : "paseo";
|
|
54
|
+
return run(cmd, ["--version"], 30_000, env).status === 0 ? cmd : null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// A .cmd shim on Windows only runs through the shell; quote what the shell would split.
|
|
58
|
+
const WINDOWS = process.platform === "win32";
|
|
59
|
+
const quote = (a) => (WINDOWS && /[\s"&|<>^]/.test(a) ? `"${a.replace(/"/g, '""')}"` : a);
|
|
60
|
+
|
|
61
|
+
function run(cmd, args, timeout, env = process.env) {
|
|
62
|
+
return spawnSync(WINDOWS ? quote(cmd) : cmd, WINDOWS ? args.map(quote) : args, { encoding: "utf8", windowsHide: true, timeout, shell: WINDOWS, env });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function paseo(cmd, args, env = process.env) {
|
|
66
|
+
const r = run(cmd, args, 180_000, env);
|
|
67
|
+
let json = null;
|
|
68
|
+
try {
|
|
69
|
+
json = JSON.parse((r.stdout ?? "").trim());
|
|
70
|
+
} catch {
|
|
71
|
+
json = null;
|
|
72
|
+
}
|
|
73
|
+
return { ok: r.status === 0, json, text: `${r.stdout ?? ""}${r.stderr ?? ""}`.trim() };
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function pluginEntry(cmd, env = process.env) {
|
|
77
|
+
const r = paseo(cmd, ["plugin", "ls", "--json"], env);
|
|
78
|
+
if (!r.ok) return { error: r.text };
|
|
79
|
+
const list = Array.isArray(r.json) ? r.json : Array.isArray(r.json?.data) ? r.json.data : [];
|
|
80
|
+
return { entry: list.find((p) => p.id === PLUGIN_ID) ?? null, old: list.find((p) => p.id === OLD_PLUGIN_ID) ?? null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function pluginsEnabled(cmd, env = process.env) {
|
|
84
|
+
const r = paseo(cmd, ["daemon", "config", "get", "pluginsEnabled", "--json"], env);
|
|
85
|
+
const value = r.json?.value ?? r.json?.data?.value;
|
|
86
|
+
return value === true;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function ask(question) {
|
|
90
|
+
if (!process.stdin.isTTY) return Promise.resolve(false);
|
|
91
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
92
|
+
return new Promise((resolve) =>
|
|
93
|
+
rl.question(question, (answer) => {
|
|
94
|
+
rl.close();
|
|
95
|
+
resolve(/^(y|yes|是|好|可以)$/i.test(answer.trim()));
|
|
96
|
+
}),
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const say = (s) => console.log(s);
|
|
101
|
+
|
|
102
|
+
function manualSteps(dir) {
|
|
103
|
+
say("也可以在 Paseo 中手动安装:");
|
|
104
|
+
say(" 1. 设置 → Plugins → 打开 Enable plugins(插件是不受限制的代码,可以访问这台机器上的文件和进程)");
|
|
105
|
+
say(` 2. 在 Plugin source 中填:${dir}`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export async function installPlugin({ yes = false, env = process.env, kitRoot = KIT_ROOT } = {}) {
|
|
109
|
+
const dir = stagePlugin(kitRoot, kitHome(env));
|
|
110
|
+
say(`插件文件:${dir}`);
|
|
111
|
+
const cmd = paseoCommand(env);
|
|
112
|
+
if (!cmd) {
|
|
113
|
+
say("没有找到 paseo 命令(桌面版 Paseo 管理的 daemon 通常没有)。");
|
|
114
|
+
manualSteps(dir);
|
|
115
|
+
return 1;
|
|
116
|
+
}
|
|
117
|
+
if (!pluginsEnabled(cmd, env)) {
|
|
118
|
+
say("");
|
|
119
|
+
say("Paseo 的插件总开关(pluginsEnabled)是关着的。");
|
|
120
|
+
say("插件是受信任、不受沙箱限制的代码:它的后台部分可以访问这台机器上的文件、进程和网络。");
|
|
121
|
+
say("laoshi 插件只运行本机的 laoshi 命令,不连接任何外部服务。");
|
|
122
|
+
const agreed = yes || (await ask("打开 Paseo 的插件总开关并安装 laoshi 插件?[y/N] "));
|
|
123
|
+
if (!agreed) {
|
|
124
|
+
say("没有安装。之后可以运行 laoshi plugin install(或加 --yes)。");
|
|
125
|
+
manualSteps(dir);
|
|
126
|
+
return 1;
|
|
127
|
+
}
|
|
128
|
+
const set = paseo(cmd, ["daemon", "config", "set", "pluginsEnabled", "true", "--json"], env);
|
|
129
|
+
if (!set.ok) {
|
|
130
|
+
say(`没能打开插件总开关:${set.text}`);
|
|
131
|
+
manualSteps(dir);
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
say("✓ 已打开 Paseo 的插件总开关");
|
|
135
|
+
}
|
|
136
|
+
const found = pluginEntry(cmd, env);
|
|
137
|
+
if (found.error) {
|
|
138
|
+
say(`读取不了 Paseo 的插件列表:${found.error}`);
|
|
139
|
+
say("请确认 Paseo daemon 在运行(paseo daemon status)。");
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
const r = found.entry ? paseo(cmd, ["plugin", "reload", PLUGIN_ID, "--json"], env) : paseo(cmd, ["plugin", "install", dir, "--json"], env);
|
|
143
|
+
if (!r.ok) {
|
|
144
|
+
say(`${found.entry ? "重新加载" : "安装"}失败:${r.text}`);
|
|
145
|
+
say(`查看插件输出:paseo plugin logs ${PLUGIN_ID}`);
|
|
146
|
+
return 1;
|
|
147
|
+
}
|
|
148
|
+
const after = pluginEntry(cmd, env).entry;
|
|
149
|
+
if (after?.status === "running") {
|
|
150
|
+
say(`✓ laoshi 插件${found.entry ? "已更新" : "已安装"},正在运行。在 Paseo 侧边栏中点"需求(laoshi)"打开。`);
|
|
151
|
+
if (found.old) say("Paseo 里还装着 req-kit 的插件:迁移到 laoshi 后可以移除它(req plugin remove,或 设置 → Plugins)。");
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
say(`插件状态:${after?.status ?? "未知"}${after?.error ? `(${after.error})` : ""}。查看输出:paseo plugin logs ${PLUGIN_ID}`);
|
|
155
|
+
return 1;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function pluginStatus({ env = process.env } = {}) {
|
|
159
|
+
const dir = stagedDir(kitHome(env));
|
|
160
|
+
const staged = fs.existsSync(path.join(dir, "package.json")) ? JSON.parse(fs.readFileSync(path.join(dir, "package.json"), "utf8")).version : null;
|
|
161
|
+
say(staged ? `插件文件:${dir}(版本 ${staged})` : "还没有准备插件文件:运行 laoshi plugin install");
|
|
162
|
+
const cmd = paseoCommand(env);
|
|
163
|
+
if (!cmd) {
|
|
164
|
+
say("没有找到 paseo 命令,无法查看 Paseo 中的状态(在 Paseo 的 设置 → Plugins 中查看)。");
|
|
165
|
+
return staged ? 0 : 1;
|
|
166
|
+
}
|
|
167
|
+
const found = pluginEntry(cmd, env);
|
|
168
|
+
if (found.error) {
|
|
169
|
+
say(`读取不了 Paseo 的插件列表:${found.error}`);
|
|
170
|
+
return 1;
|
|
171
|
+
}
|
|
172
|
+
if (!found.entry) {
|
|
173
|
+
say("Paseo 中没有安装 laoshi 插件:运行 laoshi plugin install");
|
|
174
|
+
return 1;
|
|
175
|
+
}
|
|
176
|
+
say(`Paseo 中的 laoshi 插件:${found.entry.status}${found.entry.error ? `(${found.entry.error})` : ""}`);
|
|
177
|
+
if (!pluginsEnabled(cmd, env)) say("注意:Paseo 的插件总开关是关着的(设置 → Plugins → Enable plugins)。");
|
|
178
|
+
return found.entry.status === "running" ? 0 : 1;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export function removePlugin({ env = process.env } = {}) {
|
|
182
|
+
const cmd = paseoCommand(env);
|
|
183
|
+
if (cmd) {
|
|
184
|
+
const found = pluginEntry(cmd, env);
|
|
185
|
+
if (found.entry) {
|
|
186
|
+
const r = paseo(cmd, ["plugin", "remove", PLUGIN_ID, "--json"], env);
|
|
187
|
+
if (!r.ok) {
|
|
188
|
+
say(`移除失败:${r.text}`);
|
|
189
|
+
return 1;
|
|
190
|
+
}
|
|
191
|
+
say("✓ 已从 Paseo 移除 laoshi 插件(Paseo 的插件总开关保持原样)");
|
|
192
|
+
} else say("Paseo 中没有安装 laoshi 插件");
|
|
193
|
+
} else say("没有找到 paseo 命令:请在 Paseo 的 设置 → Plugins 中移除 laoshi。");
|
|
194
|
+
fs.rmSync(stagedDir(kitHome(env)), { recursive: true, force: true });
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* After laoshi is installed or upgraded (laoshi install): if the plugin was installed,
|
|
200
|
+
* refresh its files from that version and reload it. Quiet and best effort.
|
|
201
|
+
*/
|
|
202
|
+
export function refreshPlugin({ kitRoot = KIT_ROOT, env = process.env, log = () => {} } = {}) {
|
|
203
|
+
const home = kitHome(env);
|
|
204
|
+
if (!fs.existsSync(path.join(stagedDir(home), "paseo-plugin.json"))) return false;
|
|
205
|
+
try {
|
|
206
|
+
stagePlugin(kitRoot, home);
|
|
207
|
+
} catch (error) {
|
|
208
|
+
log(`没能更新 Paseo 插件的文件:${error.message}`);
|
|
209
|
+
return false;
|
|
210
|
+
}
|
|
211
|
+
const cmd = paseoCommand(env);
|
|
212
|
+
const r = cmd ? paseo(cmd, ["plugin", "reload", PLUGIN_ID, "--json"], env) : null;
|
|
213
|
+
log(r?.ok ? "Paseo 插件已更新到这个版本" : `Paseo 插件的文件已更新;在 Paseo 中重新加载它:paseo plugin reload ${PLUGIN_ID}(或 设置 → Plugins)`);
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
218
|
+
const [sub = "status", ...rest] = process.argv.slice(2);
|
|
219
|
+
let code;
|
|
220
|
+
try {
|
|
221
|
+
if (sub === "install") code = await installPlugin({ yes: rest.includes("--yes") || rest.includes("-y") });
|
|
222
|
+
else if (sub === "status") code = pluginStatus();
|
|
223
|
+
else if (sub === "remove" || sub === "uninstall") code = removePlugin();
|
|
224
|
+
else {
|
|
225
|
+
console.error(`没有 "${sub}" 这个子命令。可用:laoshi plugin install [--yes]、laoshi plugin status、laoshi plugin remove`);
|
|
226
|
+
code = 2;
|
|
227
|
+
}
|
|
228
|
+
} catch (error) {
|
|
229
|
+
console.error(error.message);
|
|
230
|
+
code = 1;
|
|
231
|
+
}
|
|
232
|
+
process.exit(code);
|
|
233
|
+
}
|
package/bin/install.mjs
CHANGED
|
@@ -55,7 +55,11 @@ dsh 的选项:--dsh-home <DSH_HOME> --profile <名称> --dsh-bin <dsh 的 bin.
|
|
|
55
55
|
process.exit(0);
|
|
56
56
|
}
|
|
57
57
|
const dry = args["dry-run"] || args.check;
|
|
58
|
-
|
|
58
|
+
// Without --home or LAOSHI_HOME: the install root this program was installed into with npm
|
|
59
|
+
// (<root>/npm/…/node_modules, as engine/src/locations.ts programHome finds it), else ~/.laoshi.
|
|
60
|
+
const programRoot = /^(.*)[\\/]npm[\\/](?:lib[\\/])?node_modules[\\/]/.exec(kit)?.[1] ?? null;
|
|
61
|
+
const programHome = programRoot && fs.existsSync(path.join(programRoot, "config.json")) ? programRoot : null;
|
|
62
|
+
const home = path.resolve(args.home ?? process.env.LAOSHI_HOME ?? programHome ?? path.join(os.homedir(), ".laoshi"));
|
|
59
63
|
const configPath = path.join(home, "config.json");
|
|
60
64
|
const recordPath = path.join(home, "install.json");
|
|
61
65
|
|
|
@@ -143,7 +147,7 @@ if (args.uninstall) {
|
|
|
143
147
|
}
|
|
144
148
|
report("ok", `已从 ${dir} 删除 laoshi 安装的 skill`);
|
|
145
149
|
}
|
|
146
|
-
mod.uninstall?.({ args, config: existing, report });
|
|
150
|
+
await mod.uninstall?.({ args, config: existing, report, home });
|
|
147
151
|
for (const f of ["laoshi", "laoshi.cmd", "req", "req.cmd"]) fs.rmSync(path.join(home, "bin", f), { force: true });
|
|
148
152
|
fs.rmSync(recordPath, { force: true });
|
|
149
153
|
report("ok", `保留了安装根 ${home}(配置、使用记录);不再需要时可以手工删除`);
|
|
@@ -171,7 +175,7 @@ const config = existing ?? { platform: mod.platformConfig(args) };
|
|
|
171
175
|
|
|
172
176
|
// ---------------------------------------------------------------------------------------------
|
|
173
177
|
section("skill");
|
|
174
|
-
const targets = [...mod.skillTargets(args, config), ...args.target.map((t) => ({ dir: path.resolve(t), label: `自定义目录 ${path.resolve(t)}` }))];
|
|
178
|
+
const targets = [...mod.skillTargets(args, config, process.env, home), ...args.target.map((t) => ({ dir: path.resolve(t), label: `自定义目录 ${path.resolve(t)}` }))];
|
|
175
179
|
const rendered = fs.mkdtempSync(path.join(os.tmpdir(), "laoshi-skills-"));
|
|
176
180
|
const renderConfig = path.join(rendered, "config.json");
|
|
177
181
|
fs.writeFileSync(renderConfig, JSON.stringify(config));
|
|
@@ -214,7 +218,7 @@ fs.rmSync(rendered, { recursive: true, force: true });
|
|
|
214
218
|
section(`平台:${platform}`);
|
|
215
219
|
let next = [];
|
|
216
220
|
try {
|
|
217
|
-
next = mod.setup({ kit, args, config, dry, report }) ?? [];
|
|
221
|
+
next = (await mod.setup({ kit, args, config, dry, report, home })) ?? [];
|
|
218
222
|
} catch (error) {
|
|
219
223
|
report("fail", error.message);
|
|
220
224
|
}
|
|
@@ -232,7 +236,10 @@ if (!dry) {
|
|
|
232
236
|
}
|
|
233
237
|
const onPath = (process.env.PATH ?? "").split(path.delimiter).some((p) => p && path.resolve(p) === bin);
|
|
234
238
|
report("ok", `laoshi、req 命令在 ${bin}${onPath ? "" : `(不在 PATH 中:用 npm 全局安装时可以忽略;否则把它加进 PATH${process.platform === "win32" ? `,例如在 cmd 中执行 setx PATH "%PATH%;${bin}"` : ""})`}`);
|
|
235
|
-
|
|
239
|
+
// Where the commands will look without --home: LAOSHI_HOME, else the root this program is installed
|
|
240
|
+
// in (its config.json is written above), else ~/.laoshi.
|
|
241
|
+
const foundAt = process.env.LAOSHI_HOME ?? (programRoot && path.resolve(programRoot) === home ? programRoot : path.join(os.homedir(), ".laoshi"));
|
|
242
|
+
if (path.resolve(foundAt) !== home) {
|
|
236
243
|
report("warn", `安装根不是默认位置,需要设置环境变量 LAOSHI_HOME=${home}(之后新开的终端和平台都要能读到它)`);
|
|
237
244
|
}
|
|
238
245
|
|
package/bin/req.mjs
CHANGED
|
@@ -35,6 +35,8 @@ const HELP = `laoshi ${version}(${kitRoot})
|
|
|
35
35
|
laoshi checklist <需求> 验收清单:按验收标准逐条勾选,提交后写成验收记录
|
|
36
36
|
laoshi ui-check <网址> [--prototype <原型文件>] [--width 1280,390]
|
|
37
37
|
不靠看图检查网页:显示不全、遮挡、超出屏幕、文字太淡、报错,和原型对文字
|
|
38
|
+
laoshi permission <需求> approve|deny [理由]
|
|
39
|
+
批准或拒绝步骤等待批准的操作,并接着运行(平台在对话里问人时用)
|
|
38
40
|
laoshi reply <需求> <回复> 把回答或方案意见转给需求的对话(需求插件的"等你处理"用它)
|
|
39
41
|
laoshi integration test [需求] 只显示对接外部系统时会执行的命令,不真正调用
|
|
40
42
|
laoshi start --from <系统>:<卡号> 从需求管理系统中的一张卡片开始需求(没有人开着对话也可以)
|
|
@@ -56,6 +58,10 @@ const HELP = `laoshi ${version}(${kitRoot})
|
|
|
56
58
|
laoshi index [--rebuild [目录…]] [--prune]
|
|
57
59
|
本机记录的需求(需求插件据此找到所有需求);索引里缺的需求用 --rebuild 补登
|
|
58
60
|
laoshi api <命令> … 给程序用的 JSON 输出(见 contracts/cli-json.md)
|
|
61
|
+
laoshi plugin install [--yes] | status | remove
|
|
62
|
+
Paseo 的需求插件(在 Paseo 里看需求、确认方案、停止和继续)
|
|
63
|
+
laoshi migrate [--apply | --rollback] [--from <目录>] [--to <目录>]
|
|
64
|
+
从 req-kit 1.x 迁移本机的配置、使用记录和需求状态(默认只预览)
|
|
59
65
|
|
|
60
66
|
本机维护:
|
|
61
67
|
npx -y [--registry=<npm 源>] @yiyi_zhang/laoshi@latest install --platform <平台>
|
|
@@ -185,6 +191,12 @@ switch (command) {
|
|
|
185
191
|
case "reply":
|
|
186
192
|
code = needTsx() ? node([tsxCli, path.join(kitRoot, "engine", "src", "reply.ts"), ...rest]) : 1;
|
|
187
193
|
break;
|
|
194
|
+
case "permission":
|
|
195
|
+
// Answers a step's pending approval, then continues the run (the step picks up the answer).
|
|
196
|
+
code = needTsx() ? node([tsxCli, path.join(kitRoot, "engine", "src", "permission-cmd.ts"), ...rest]) : 1;
|
|
197
|
+
if (code === 0) code = node([launcher, "--resume", ...feature(rest.slice(0, 1), true)]);
|
|
198
|
+
else if (code === 3) code = 0;
|
|
199
|
+
break;
|
|
188
200
|
case "sync":
|
|
189
201
|
code = needTsx() ? node([tsxCli, path.join(kitRoot, "engine", "src", "integration-cmd.ts"), "sync", ...rest]) : 1;
|
|
190
202
|
break;
|
|
@@ -209,9 +221,13 @@ switch (command) {
|
|
|
209
221
|
case "docs":
|
|
210
222
|
code = node([path.join(kitRoot, "bin", "req-docs.mjs"), ...rest]);
|
|
211
223
|
break;
|
|
224
|
+
case "migrate":
|
|
225
|
+
// From req-kit 1.x (~/.req-kit) to laoshi: preview by default, --apply, --rollback.
|
|
226
|
+
code = needTsx() ? node([tsxCli, path.join(kitRoot, "adapters", "paseo", "migrate.ts"), ...rest]) : 1;
|
|
227
|
+
break;
|
|
212
228
|
case "plugin":
|
|
213
|
-
|
|
214
|
-
code =
|
|
229
|
+
// laoshi's plugin for Paseo (adapters/paseo/plugin): install | status | remove.
|
|
230
|
+
code = node([path.join(kitRoot, "adapters", "paseo", "plugin-cmd.mjs"), ...rest]);
|
|
215
231
|
break;
|
|
216
232
|
case "notify-test":
|
|
217
233
|
code = needTsx() ? node([tsxCli, path.join(kitRoot, "engine", "src", "notify-test.ts"), ...rest]) : 1;
|
package/contracts/README.md
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
| `decisions.tsv`、`changes.md`、`acceptance.md` 与需求总览 | [feature-files.md](feature-files.md) | 见各文件说明 |
|
|
11
11
|
| `.requirement-pipeline/verify.md` | [verify.md](verify.md) | 自由格式,建议结构见文件 |
|
|
12
12
|
| 外部通知(企业 IM 等)收到的事件 | [notifier-event.md](notifier-event.md) | `schema: 1` |
|
|
13
|
-
| `req api`
|
|
13
|
+
| `req api` 的输出(平台插件等程序读取) | [cli-json.md](cli-json.md) | `schema: 1` |
|
|
14
14
|
| `~/.req-kit/index/`、`~/.req-kit/usage/runs.jsonl` | [usage-record.md](usage-record.md) | `schema: 1` |
|
|
15
15
|
| 引擎对 agent 平台的要求(`AgentRuntime`,`engine/src/runtime.ts`) | [agent-runtime.md](agent-runtime.md) | 以 `runtime.ts` 的类型为准 |
|
|
16
16
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AgentRuntime:引擎对 agent 平台的要求
|
|
2
2
|
|
|
3
|
-
引擎(`engine/src`)只通过 `AgentRuntime`(`engine/src/runtime.ts`)与 agent
|
|
3
|
+
引擎(`engine/src`)只通过 `AgentRuntime`(`engine/src/runtime.ts`)与 agent 平台打交道。现有的实现在各平台的适配器里:Paseo(`adapters/paseo/paseo-runtime.ts`)、DeepSeek Harness(`adapters/dsh/dsh-runtime.ts`)、摸高(`adapters/mogao/mogao-runtime.ts`);测试用 `REQ_PIPELINE_FAKE_RUNTIME` 指向的假实现(`engine/test/fake-runtime.ts`)。要让 laoshi 运行在别的 agent 平台上,就是为那个平台写一个适配器和它的 `AgentRuntime`(见 [adapter-guide](../docs/design/adapter-guide.md))。
|
|
4
4
|
|
|
5
5
|
本文说明:每个方法属于哪一级、没有它时现在的行为、以及适配器应该怎么做。`runtime.ts` 里的类型和注释是字段定义的准确来源,本文不重复。
|
|
6
6
|
|
|
@@ -48,6 +48,9 @@
|
|
|
48
48
|
| `createWorktree(request)`、`waitForWorkspaceSetup(id, timeoutMs)` | `--worktree`(`worktree.ts`)和联合需求(`joint.ts`) | ⚠ 创建失败是硬错误。没有平台工作区的适配器,可以在适配器内用 `git worktree` 实现并返回 `{ workspaceId, directory }`;`waitForWorkspaceSetup` 可恒返回 `{ status: "none" }` |
|
|
49
49
|
| `startSessionAgent(input)` | 从卡片接单(`card-cmd.ts`):为需求新开一个顶层会话 | 没有则不能用接单器 |
|
|
50
50
|
| `scheduleNewAgent(input)` | 需求总览的定时发送(`digest.ts --schedule`) | 返回 `null` 时该功能关闭 |
|
|
51
|
+
| `answerPermission(agentId, requestId, approve, reason)` | `laoshi permission <需求> approve\|deny`(`permission-cmd.ts`):平台的审批不能在它自己的界面里回答、由对话问人时,laoshi 转达人的决定;`requestId` 为 `null` 表示现在等待的那一个 | 没有时,审批按平台自己的方式处理(如 Paseo、dsh 的界面) |
|
|
52
|
+
|
|
53
|
+
适配器还可以声明 `runsInChat`(`PlatformAdapter`):平台只在对话的一个轮次内保留对话的机器时,引擎不能在后台运行,`launch.ts` 让它在对话的命令里运行,给对话的消息(`notifyAgent`)写进 `chat.log` 并显示在命令输出里。状态文件记下运行引擎的机器(`host`),另一台机器上记录的进程不算还在运行。
|
|
51
54
|
|
|
52
55
|
## 调度
|
|
53
56
|
|
|
@@ -77,7 +80,7 @@ req-kit 1.x 里带 Paseo 字样的地方,laoshi 中已改为中性的名称:
|
|
|
77
80
|
- 方法与字段:`listPaseoProfiles` → `listProfiles`(M2a),`capabilities().paseoTools` → `platformTools`(M2e)。`ServiceTarget`、`ManagedService` 本来就是中性的名字,只改了注释。
|
|
78
81
|
- 状态文件字段:`originAgentId`、`worktree.workspaceId`、`schedules[]` 在第 2 版中改名(M2d,见 `state.md`);对外契约不变。
|
|
79
82
|
- 面向使用者的文案和提示词:改用适配器的词汇表(M2e,`engine/src/words.ts`,见 [platform-vocabulary](../docs/design/platform-vocabulary.md));`engine/prompts/paseo-services.md` 改名为 `managed-services.md`。
|
|
80
|
-
- 会话识别:由适配器声明环境变量(`originEnv`,M2a)。
|
|
83
|
+
- 会话识别:由适配器声明环境变量(`originEnv`,M2a);使用者识别同样由适配器声明(`userEnv`,如摸高的 `AIMAX_USER_NAME`,ADR 0007)。
|
|
81
84
|
- 配置:`AgentProfile.paseoProfile` → `platformProfile`,`paseoServices` → `platformServices`,旧名继续读取(M2e);daemon 地址可写在 `platform.paseo` 中(M2c)。
|
|
82
85
|
|
|
83
86
|
`engine/test/platform.test.ts` 检查核心代码和提示词里不出现平台名(有意保留的旧字段名、对外契约字段,在那一行或上一行写明 `platform-name:` 和原因)。
|
package/contracts/cli-json.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 给程序用的 JSON 输出:`req api`
|
|
2
2
|
|
|
3
|
-
1.9.0
|
|
3
|
+
1.9.0 起。平台插件(如 Paseo 插件)和其他程序通过 `req api` 读取需求、执行管理操作,不直接读写状态文件。每个命令输出一行 JSON:
|
|
4
4
|
|
|
5
5
|
```json
|
|
6
6
|
{ "schema": 1, "kitVersion": "1.9.0", "data": … }
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
| 命令 | `data` |
|
|
22
22
|
| --- | --- |
|
|
23
|
-
| `req api version` | `{ kitVersion, kitRoot, apiSchema, paseo, featuresDir }`:`paseo` 是这个版本支持的 Paseo
|
|
23
|
+
| `req api version` | `{ kitVersion, kitRoot, apiSchema, paseo, featuresDir }`:`paseo` 是这个版本支持的 Paseo 范围(字段名沿用 1.x,只对 Paseo 有意义,其他平台为 null 或忽略) |
|
|
24
24
|
| `req api list [--repo <目录>]` | 这个仓库所有工作区中的需求,数组,每项见下面的"需求" |
|
|
25
25
|
| `req api list --all` | 本机记录过的所有需求([需求索引](usage-record.md)),同上;目录已不在的 `present: false`。1.14 起还包括:用 `--track` 登记、还在对齐中的需求(`stage` 为"对齐中",没有 `spec.md` 时 `title` 取自 `alignment.md`),以及索引里出现过的项目中没登记的需求 |
|
|
26
26
|
| `req api status <需求> [--repo <目录>]` | 一个需求的详情,见下面的"详情" |
|
|
@@ -45,8 +45,9 @@
|
|
|
45
45
|
| `key` | 需求在本机的标识(对话所在目录 + 功能目录) |
|
|
46
46
|
| `project` | 项目名:对话所在目录的目录名 |
|
|
47
47
|
| `codebase` | laoshi M2c 起。需求所属的代码库:`{ root, remote }`,`root` 是主检出目录(需求自己的 worktree 归属它的原仓库),`remote` 是 origin 的地址(去掉凭据),没有时为 null(ADR 0007) |
|
|
48
|
+
| `startedBy` | laoshi 起。发起人:状态文件的 `startedBy`;还没运行过、或状态文件是更早的版本时为 null |
|
|
48
49
|
| `repo` | 需求所在的目录(有自己的工作区时是那个工作区) |
|
|
49
|
-
| `sourceRepo` / `workspaceId` |
|
|
50
|
+
| `sourceRepo` / `workspaceId` | 有自己的工作区时:对话所在的目录、平台对这个工作区的引用(Paseo 上是工作区 ID);否则 null |
|
|
50
51
|
| `featureDir` / `name` / `title` | 功能目录、目录名、需求标题 |
|
|
51
52
|
| `type` / `profile` / `branch` | 需求类型(`defect`、`refactor`、`assessment` 或 null)、档位、分支 |
|
|
52
53
|
| `stage` | 与 `req list` 相同的阶段说明,如"开发中""等待确认方案""待验收" |
|
|
@@ -81,8 +81,8 @@ laoshi M2c 起(ADR 0007)另有两个字段:`codebase`(需求所属的代
|
|
|
81
81
|
| `completed` | 流水线结束,报告已生成 | `outcome`(`completed`、`completed_with_issues`、`not_completed`)、`summary`、`reportPath`。"只做研发"时另有 `mode`(`develop-only`)和 `handoffPath`,报告是研发报告,需要人工测试 |
|
|
82
82
|
| `approval` | 1.8.0 起。方案确认点(`designApproval`):方案已通过审核,等待需求方确认"做完后会看到什么",还没有开始写代码 | `previewPath`(要确认的内容)、`approveCommand`(确认后继续的命令)、`resumeCommand`(修改需求后继续的命令),都在发起的对话中执行 |
|
|
83
83
|
| `phase_done` | 1.7.0 起。分阶段执行时研发阶段已完成(代码已通过评审、提测说明已写好),流水线停在闸口等待测试验证。测试退回后再次修完也会发 | `handoffPath`(提测说明)、`mode`(`gated`)、`verifyCommand`(开始测试验证的命令,在发起的对话中执行)、`verifyAt`(预约的开始时间,ISO 格式,没有为 null)、`handbacks`(已退回的次数) |
|
|
84
|
-
| `alert` | 1.12 起。接单器(`req factory
|
|
85
|
-
| `digest` | `req digest --notify`(或由 `req digest --schedule`
|
|
84
|
+
| `alert` | 1.12 起。接单器(`req factory`)自检没有通过(平台连不上、agent 没有登录、额度用完、需求管理系统的命令不可用),暂停接新卡片;或者恢复正常。同样的问题只发一次。`feature.title` 为"接单器",`feature.dir`、`repo` 为空 | `source`(`factory`)、`machine`、`problems`(字符串数组,恢复时为空)、`recovered`。1.14 起,步骤 agent 运行或开始运行危险命令(`dangerGuard`)时也发:`details.kind` 为 `danger`,另有 `stepTitle`、`command`、`label`、`ran`;这时 `feature`、`repo` 是那个需求的 |
|
|
85
|
+
| `digest` | `req digest --notify`(或由 `req digest --schedule` 创建的平台定时任务)发送项目的需求总览,1.6.0 起。`feature.title` 为"<项目> 需求总览",`text` 是完整的多行总览 | `features`:每个需求的 `name`、`title`、`stage`、`branch`、`updatedAt`、`usage`;`recurringLessons`(1.8.0 起):在两个以上需求的 `lessons.tsv` 中出现的问题类别,每项 `category`、`features`、`rules` |
|
|
86
86
|
|
|
87
87
|
## 兼容性
|
|
88
88
|
|
package/contracts/state.md
CHANGED
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
| `specHash` | string | 启动时 spec.md 的 sha256 |
|
|
15
15
|
| `originSessionId` | string \| null | 发起流水线的对话(会话),通知发往这里。第 1 版叫 `originAgentId` |
|
|
16
16
|
| `pid` | number | 流水线进程 |
|
|
17
|
+
| `host` | string | 可选,laoshi 起。运行流水线进程的机器名:每个对话轮次换一台机器的平台(如摸高)上,用它判断 `pid` 是不是本机的进程 |
|
|
18
|
+
| `startedBy` | string | 可选,laoshi 起(ADR 0007)。发起人:第一次运行流水线时为谁运行(取法同使用记录的 `user`,见 [usage-record.md](usage-record.md)),之后的运行不改。更早的状态文件没有 |
|
|
17
19
|
| `startedAt` / `updatedAt` | ISO 时间 | |
|
|
18
20
|
| `results` | object | 已完成步骤的结果,键为步骤键(如 `code_review-r2`) |
|
|
19
21
|
| `history` | array | 每次步骤执行的记录:agent、起止时间、结果、错误;`usage`(可选,1.3.0 起)为 agent 报告的用量:`inputTokens`、`cachedInputTokens`、`outputTokens`、`totalCostUsd`,agent 没有报告时为 null 或缺少;`leftRunning`(可选,1.11 起)为 true 表示失败时 agent 可能还在运行,下一次运行这一步时先看它;`reattached`(可选,1.11 起)为接着等上一次 agent 的次数 |
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## 需求索引 `index/<key>.json`
|
|
6
6
|
|
|
7
|
-
每个在本机运行过的需求一个文件,记录它在哪里,供 `req api list --all`
|
|
7
|
+
每个在本机运行过的需求一个文件,记录它在哪里,供 `req api list --all` 和平台插件(如 Paseo 插件)找到本机所有的需求。需求的阶段、进度仍然现场从功能目录读取(ADR 0010)。
|
|
8
8
|
|
|
9
9
|
```json
|
|
10
10
|
{
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
| --- | --- |
|
|
34
34
|
| `schema` / `kind` | `1` / `"run"` |
|
|
35
35
|
| `machine` / `kitVersion` | 主机名、req-kit 版本 |
|
|
36
|
-
| `user` | laoshi M2c 起。这次运行是为谁:环境变量 `LAOSHI_USER
|
|
36
|
+
| `user` | laoshi M2c 起。这次运行是为谁:环境变量 `LAOSHI_USER`,其次平台提供的使用者(适配器声明的环境变量,如摸高的 `AIMAX_USER_NAME`),再次安装级配置的 `user`,最后系统用户名。更早的记录没有 |
|
|
37
37
|
| `requirement` | `{ key, project, name, title, type, profile }`;laoshi M2c 起另有 `codebase`(`{ root, remote }`,见 [cli-json.md](cli-json.md) 的同名字段);从卡片开始的需求(1.10 起)另有 `requester`(卡片的提出人)和 `source`(`{ system, id }`) |
|
|
38
|
-
| `steps[].cachedInputTokens` / `steps[].agent` | 1.13 起。输入中来自提示缓存的 tokens(agent 报告时);这一步用的 agent
|
|
38
|
+
| `steps[].cachedInputTokens` / `steps[].agent` | 1.13 起。输入中来自提示缓存的 tokens(agent 报告时);这一步用的 agent(平台档案名,如 Paseo 的 profile 名,或 "provider/model")。更早的记录没有 |
|
|
39
39
|
| `run` | `{ startedAt, endedAt, attempt, phase, phaseMode, status, outcome, stopReason, stopKind, recoveries }`;`status` 是运行结束时的状态,`outcome` 是完成时报告的结论;`stopKind`(1.12 起)是停下等人的原因代码(见 [state.md](state.md)),`recoveries`(1.12 起)是这次运行中自动处理的次数,按种类,如 `{ "retry": 2 }`。更早的记录没有这两项 |
|
|
40
40
|
| `agents` | `{ builder, reviewer }`:当时配置的 agent(如 `claude/opus(bypassPermissions)`) |
|
|
41
41
|
| `steps` | 这次运行中开始的步骤:`{ key, stepId, phase, attempt, round, startedAt, endedAt, minutes, outcome, inputTokens, outputTokens, costUsd }`;agent 没有报告的用量为 null |
|
|
@@ -73,7 +73,8 @@ req-kit 靠环境变量 `PASEO_AGENT_ID`、`PASEO_AGENT_CWD` 识别"当前对话
|
|
|
73
73
|
|
|
74
74
|
新适配器必须通过:
|
|
75
75
|
|
|
76
|
-
1.
|
|
76
|
+
1. **运行时一致性测试**(`engine/test/conformance.ts` 的 `runConformance`,M3 起):在适配器的测试目录里写一个 `conformance.test.ts`,给出"用假的平台后端建一个运行时"的方法(`setup`)和适配器的能力声明,就会跑同一组用例:`startAgent` → `wait` 为 idle 且文件写在 `cwd` 下;`followUp` 开始新回合;出错时为 error 且有原因;没等到时为 timeout、之后能等到结束;另一个进程的运行时用 `attachAgent` 接上;`interruptAgent` 改做新指令;声明了工具调用的看得到命令;可选方法不抛出、不支持的返回 `null`。假后端要认识三种提示词:`WRITE:<文件>:<内容>`、`SLEEP:<毫秒>`、`FAIL`。现在四个适配器都已接入(`adapters/*/test/conformance.test.ts`):Paseo(假的 SDK 客户端)、dsh(真实的 laoshi dsh 插件配假的 dsh 服务)、摸高(假的 `aimax`)、命令行(假的 `claude`、`codex`)。平台自己的假后端可以用 `engine/test/scripted-session.ts`:它按这三种提示词在工作目录里"做事",记下工具调用和回复,由假后端换成平台的格式(Paseo 的时间线、dsh 的会话记录等)。
|
|
77
|
+
编排测试(`engine/test` 中基于 `fake-runtime.ts` 的用例)测的是核心本身,适配器不需要再跑。
|
|
77
78
|
2. **探针测试**(真实平台上运行,需要一个临时目录和少量用量):
|
|
78
79
|
- 创建一个子 agent,要求它写一个文件,`wait` 到 idle,检查文件落在 `cwd` 下;
|
|
79
80
|
- `followUp` 一次;`notifyAgent` 一次且不打断;`interruptAgent` 一次;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# 命令行 agent 适配器(M3)
|
|
2
|
+
|
|
3
|
+
- 状态:第一版已实现([adapters/cli](../../adapters/cli/README.md)),用假的命令行测试;真实的 Claude Code、Codex 上的运行待验证。
|
|
4
|
+
- 目标:不依赖任何 agent 平台,在一台只装了编码 agent 命令行(Claude Code 的 `claude`、OpenAI Codex 的 `codex`)的机器上跑完整的流水线([抽取计划 M3](../extraction/plan.md))。这是第一个"非平台"的适配器,也是 [ADR 0002](../adr/0002-two-orchestration-modes.md) 里模式 A 的最小形态。
|
|
5
|
+
|
|
6
|
+
## 1. 形态
|
|
7
|
+
|
|
8
|
+
```text
|
|
9
|
+
使用者 ──► 交互式的 Claude Code / Codex(加载 /laoshi skill)
|
|
10
|
+
│ laoshi start <需求>(引擎在后台运行,和 Paseo 上一样)
|
|
11
|
+
▼
|
|
12
|
+
laoshi 引擎 ── 每一步 ──► claude -p … / codex exec …(一个子进程,带完整工具)
|
|
13
|
+
│ │ 标准输出是事件流(JSONL):会话 ID、工具调用、用量、结果
|
|
14
|
+
▼ ▼
|
|
15
|
+
结果文件、质量门、写回状态 → 下一步 …… → 需要人决定或做完:通知(日志、外部通知模块)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
和摸高适配器一样,"步骤 agent"是一次命令行运行,追问、续接用同一个会话;不同的是这里没有平台:没有对话可以发消息,没有审批界面,没有定时任务。
|
|
19
|
+
|
|
20
|
+
## 2. 映射
|
|
21
|
+
|
|
22
|
+
| laoshi 需要 | 命令行上怎么做 |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| `startAgent` | 按角色的 `provider`(`claude/<模型>`、`codex/<模型>`)选命令行,在步骤目录起一个子进程;提示词从标准输入传入(不受命令行参数长度限制) |
|
|
25
|
+
| `wait` | 等子进程结束,读它的事件流:正常结束 → `idle`(带最后一条回复和用量);出错 → `error`;超过单次运行上限 → 结束进程,`error` |
|
|
26
|
+
| `followUp` / `interruptAgent` | 用会话 ID 续接:`claude -p --resume <id>`、`codex exec resume <id>`;打断时先结束正在运行的进程 |
|
|
27
|
+
| `attachAgent` | 每个 agent 的记录在 `<安装根>/cli/agents/<id>/`(`agent.json`、提示词、每次运行的输出),另一个引擎进程也能接上 |
|
|
28
|
+
| 运行被意外打断(机器重启、进程被杀) | 进程不在了又没有结果:用会话续接,让它接着做(最多两次),不重做整步 |
|
|
29
|
+
| `recentActivity`、`runningTool`、`toolCalls` | 事件流里的工具调用(Claude 的 `tool_use` / `tool_result`,Codex 的 `command_execution`),写日志前脱敏;危险命令拦截照常工作 |
|
|
30
|
+
| 用量 | 事件流最后的用量(输入、缓存命中、输出 token,Claude 另有费用) |
|
|
31
|
+
| `providerStatus`、体检 | `<命令> --version` 能运行即为可用 |
|
|
32
|
+
| 审批 | 命令行的非交互模式不会停下来问人:由角色的 `modeId` 决定权限(见第 3 节),laoshi 的危险命令拦截兜底 |
|
|
33
|
+
| `notifyAgent`(进展发回对话) | 没有对话:通知写进流水线日志,并照常发给外部通知模块([notifier-event](../../contracts/notifier-event.md));使用者用 `laoshi status` 看进展。设置了 `LAOSHI_CLI_ORIGIN` 时,通知还写进 `<安装根>/cli/messages.log` |
|
|
34
|
+
| 定时(`scheduleMessage` 等) | none([内置调度](builtin-capabilities.md)已设计未实现,实现后由它提供) |
|
|
35
|
+
| 工作区、服务 | builtin(`git worktree`、`.laoshi/services.json`),和 dsh、摸高一样 |
|
|
36
|
+
| 发起的对话 | 没有:命令行不提供会话 ID;`LAOSHI_CLI_ORIGIN`(任意值)可以当作"对话",让通知写进 `messages.log` |
|
|
37
|
+
|
|
38
|
+
## 3. 权限
|
|
39
|
+
|
|
40
|
+
非交互模式下,命令行遇到没有许可的操作只会拒绝,不会等人。所以每个角色要在配置里写一个不会卡住的权限模式,和 Paseo 上的写法相同(`modeId`):
|
|
41
|
+
|
|
42
|
+
| 命令行 | `modeId` | 传给命令行 |
|
|
43
|
+
| --- | --- | --- |
|
|
44
|
+
| Claude Code | 默认 `bypassPermissions`;也可以写 `acceptEdits`、`default`、`plan` | `--permission-mode <modeId>` |
|
|
45
|
+
| Codex | 默认 `full-access` | `full-access` → `--dangerously-bypass-approvals-and-sandbox`;`auto` → `--full-auto`;`read-only` → `--sandbox read-only` |
|
|
46
|
+
|
|
47
|
+
用"不问人"的模式时,安全靠三层:步骤提示词的约束、laoshi 的危险命令拦截(读事件流里的工具调用,命中就打断这一步)、git 工作区(改动都在分支上,可以丢弃)。在共享或含机密的机器上,应该改用更严格的模式,并接受某些步骤因为权限不够而失败。
|
|
48
|
+
|
|
49
|
+
## 4. 配置
|
|
50
|
+
|
|
51
|
+
安装级配置:
|
|
52
|
+
|
|
53
|
+
```json
|
|
54
|
+
{
|
|
55
|
+
"platform": { "adapter": "cli", "cli": { "claude": "claude", "codex": "codex", "runTimeoutMinutes": 120 } },
|
|
56
|
+
"agents": {
|
|
57
|
+
"builder": { "provider": "claude/default", "modeId": "bypassPermissions" },
|
|
58
|
+
"reviewer": { "provider": "codex/default", "modeId": "full-access" }
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- 模型写 `default` 时不传模型参数,用命令行自己的默认模型。
|
|
64
|
+
- 只装了一种命令行时,两个角色都用它;评审的独立性靠"新会话、不带实现上下文"保证。
|
|
65
|
+
- `platform.cli.<命令行>` 写命令的路径(不在 `PATH` 中时);测试用环境变量 `LAOSHI_CLI_CLAUDE`、`LAOSHI_CLI_CODEX` 覆盖。
|
|
66
|
+
|
|
67
|
+
## 5. 安装
|
|
68
|
+
|
|
69
|
+
`laoshi install --platform cli`:写安装级配置;skill 装到 `~/.agents/skills`(Codex 等读取),有 `~/.claude` 时还有 `~/.claude/skills`,和 Paseo 相同。之后在交互式的 Claude Code 或 Codex 里用 `/laoshi`。入口 skill 里命令行特有的一节(`adapters/cli/skill/setup.md`)告诉对话:步骤不在子 agent 列表里、不会收到通知,用户问进展时运行状态命令。
|
|
70
|
+
|
|
71
|
+
## 6. 还没有做
|
|
72
|
+
|
|
73
|
+
- **真实命令行上的验证**:事件流的字段按两个命令行公开的 JSON 输出格式解析,测试用假的命令行(`adapters/cli/test/fake-agent.mjs`)。M3 的完成标准是"在只有编码 agent 命令行的机器上跑通一个 `evals/` 用例,夸大为零",要在有账号的机器上跑。
|
|
74
|
+
- **OpenCode、Pi**:先做 Claude Code 和 Codex;其他命令行按同样的方式加一个驱动。
|
|
75
|
+
- **定时**:等内置调度实现。
|
|
@@ -57,6 +57,8 @@ npx laoshi migrate --apply # 确认后执行
|
|
|
57
57
|
|
|
58
58
|
回滚:恢复 `.bak-v1` 状态文件和旧配置目录,重新安装 req-kit 1.x。`laoshi migrate` 的确认提示里要写明这一步。
|
|
59
59
|
|
|
60
|
+
实现(2026-11-09,`adapters/paseo/migrate.ts`)与上面的差别:旧配置目录不改不删(只复制),所以回滚不需要恢复它,只恢复状态文件、删除迁移写入的文件(依据新目录里的 `migrate.json`);skill 不由 migrate 安装,提示运行 `laoshi install --platform paseo`;有流水线正在运行时拒绝执行,而不只是提示。
|
|
61
|
+
|
|
60
62
|
## 6. 待定
|
|
61
63
|
|
|
62
64
|
- ~~skill 名~~:已决定,见 [ADR 0005](../adr/0005-skill-names.md)。仍待做的是转发薄 skill 的写法:只做命令转发和一句"这个命令已改名为 /laoshi",不复制手册内容,避免两份手册漂移。
|