@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,69 @@
|
|
|
1
|
+
// The daemon side: each RPC is one `laoshi api` call. Management actions are refused here too
|
|
2
|
+
// when the plugin is set to read-only, not only hidden in the app.
|
|
3
|
+
import type { RpcInput } from "@getpaseo/plugin";
|
|
4
|
+
import type { configRpc, ConfigViewData, fileRpc, KitInfo, ModelsData, Requirement, RequirementDetail, reviewUrlRpc, runRpc, setAgentsRpc, statsRpc, StatsSummary, statusRpc } from "../shared/contracts";
|
|
5
|
+
import { coalesce, type ReqRunner } from "./req";
|
|
6
|
+
|
|
7
|
+
export interface Handlers {
|
|
8
|
+
version(): Promise<KitInfo>;
|
|
9
|
+
list(): Promise<Requirement[]>;
|
|
10
|
+
status(input: RpcInput<typeof statusRpc>): Promise<RequirementDetail>;
|
|
11
|
+
file(input: RpcInput<typeof fileRpc>): Promise<{ file: string; size: number; truncated: boolean; content: string }>;
|
|
12
|
+
stats(input: RpcInput<typeof statsRpc>): Promise<StatsSummary>;
|
|
13
|
+
run(input: RpcInput<typeof runRpc>): Promise<{ ok: boolean; message: string }>;
|
|
14
|
+
models(): Promise<ModelsData>;
|
|
15
|
+
config(input: RpcInput<typeof configRpc>): Promise<ConfigViewData>;
|
|
16
|
+
setAgents(input: RpcInput<typeof setAgentsRpc>): Promise<{ ok: boolean; message: string }>;
|
|
17
|
+
reviewUrl(input: RpcInput<typeof reviewUrlRpc>): Promise<{ url: string; readOnly: boolean }>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function createHandlers(input: { req: ReqRunner; kitHome: () => string; readOnly: () => Promise<boolean> }): Handlers {
|
|
21
|
+
const { req } = input;
|
|
22
|
+
// Every open screen polls the list; one `laoshi api list` serves them all for a moment.
|
|
23
|
+
const list = coalesce(2_000, () => req(["list", "--all"]) as Promise<Requirement[]>);
|
|
24
|
+
return {
|
|
25
|
+
async version() {
|
|
26
|
+
const info = (await req(["version"])) as Omit<KitInfo, "kitHome">;
|
|
27
|
+
return { ...info, kitHome: input.kitHome() };
|
|
28
|
+
},
|
|
29
|
+
list,
|
|
30
|
+
async status({ repo, featureDir }) {
|
|
31
|
+
return (await req(["status", featureDir, "--repo", repo])) as RequirementDetail;
|
|
32
|
+
},
|
|
33
|
+
async file({ repo, featureDir, file }) {
|
|
34
|
+
return (await req(["file", featureDir, file, "--repo", repo])) as { file: string; size: number; truncated: boolean; content: string };
|
|
35
|
+
},
|
|
36
|
+
async stats({ since, month }) {
|
|
37
|
+
const args = ["stats"];
|
|
38
|
+
if (month) args.push("--month", month);
|
|
39
|
+
else if (since) args.push("--since", since);
|
|
40
|
+
return (await req(args)) as StatsSummary;
|
|
41
|
+
},
|
|
42
|
+
async run({ action, repo, featureDir, verifyEnv, text }) {
|
|
43
|
+
if (await input.readOnly()) return { ok: false, message: "插件设置为只读:不能在这里操作需求。可以在插件设置中关闭只读,或在终端用 req 命令。" };
|
|
44
|
+
if (action === "reply" && !text?.trim()) return { ok: false, message: "回复是空的" };
|
|
45
|
+
const extra = action === "verify" && verifyEnv ? ["--verify-env", verifyEnv] : action === "reply" ? [text!.trim()] : [];
|
|
46
|
+
const result = (await req(["run", action, featureDir, "--repo", repo, ...extra], { timeoutMs: 200_000 })) as { ok: boolean; message: string };
|
|
47
|
+
return { ok: result.ok, message: result.message };
|
|
48
|
+
},
|
|
49
|
+
async reviewUrl({ repo, featureDir, page }) {
|
|
50
|
+
// Read-only plugin: the page opens without the buttons that send or confirm.
|
|
51
|
+
const ro = await input.readOnly();
|
|
52
|
+
return (await req(["review-url", featureDir, "--repo", repo, ...(page === "check" || page === "code" ? ["--page", page] : []), ...(ro ? ["--read-only"] : [])], { timeoutMs: 30_000 })) as { url: string; readOnly: boolean };
|
|
53
|
+
},
|
|
54
|
+
async config({ repo }) {
|
|
55
|
+
return (await req(repo ? ["config", "--repo", repo] : ["config", "--machine"])) as ConfigViewData;
|
|
56
|
+
},
|
|
57
|
+
async models() {
|
|
58
|
+
return (await req(["models"], { timeoutMs: 120_000 })) as ModelsData;
|
|
59
|
+
},
|
|
60
|
+
async setAgents(agents) {
|
|
61
|
+
if (await input.readOnly()) return { ok: false, message: "插件设置为只读:不能在这里修改。可以关闭只读,或在终端运行 laoshi configure。" };
|
|
62
|
+
try {
|
|
63
|
+
return (await req(["set-agents", "--json", JSON.stringify(agents)])) as { ok: boolean; message: string };
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return { ok: false, message: (error as Error).message };
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Runs `laoshi api …` with the laoshi this machine has installed, and parses its one line of JSON
|
|
2
|
+
// (contracts/cli-json.md). The plugin never reads or writes laoshi's files itself.
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
export class ReqError extends Error {
|
|
10
|
+
constructor(
|
|
11
|
+
readonly code: string,
|
|
12
|
+
message: string,
|
|
13
|
+
) {
|
|
14
|
+
super(message);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* laoshi's install root: the plugin setting, else LAOSHI_HOME, else the root the plugin is
|
|
20
|
+
* installed in (`laoshi plugin install` copies it to <install root>/paseo-plugin), else ~/.laoshi.
|
|
21
|
+
*/
|
|
22
|
+
export function kitHomeOf(configured: string, here: string = path.dirname(fileURLToPath(import.meta.url))): string {
|
|
23
|
+
if (configured.trim()) return path.resolve(configured.trim().replace(/^~(?=$|[\\/])/, os.homedir()));
|
|
24
|
+
const env = process.env.LAOSHI_HOME?.trim();
|
|
25
|
+
if (env) return path.resolve(env);
|
|
26
|
+
const root = path.resolve(here, "..", "..");
|
|
27
|
+
if (path.basename(path.resolve(here, "..")) === "paseo-plugin" && fs.existsSync(path.join(root, "install.json"))) return root;
|
|
28
|
+
return path.join(os.homedir(), ".laoshi");
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The installed laoshi's req.mjs, from <install root>/install.json (written by laoshi install). */
|
|
32
|
+
export function activeReq(kitHome: string): string {
|
|
33
|
+
const file = path.join(kitHome, "install.json");
|
|
34
|
+
let installed: { root?: string } | null = null;
|
|
35
|
+
try {
|
|
36
|
+
installed = JSON.parse(fs.readFileSync(file, "utf8")) as { root?: string };
|
|
37
|
+
} catch {
|
|
38
|
+
throw new ReqError("no_kit", `这台机器上没有找到 laoshi(${file})。请先安装 laoshi:laoshi install --platform paseo。`);
|
|
39
|
+
}
|
|
40
|
+
const req = installed?.root ? path.join(installed.root, "bin", "req.mjs") : "";
|
|
41
|
+
if (!req || !fs.existsSync(req)) throw new ReqError("no_kit", `laoshi 的程序不在了(${installed?.root ?? "未知"})。请重新安装:laoshi install --platform paseo。`);
|
|
42
|
+
return req;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** A node to run laoshi with: this process's when it is node, else the one on PATH. */
|
|
46
|
+
function nodeBinary(): string {
|
|
47
|
+
const base = path.basename(process.execPath).toLowerCase();
|
|
48
|
+
return base === "node" || base === "node.exe" ? process.execPath : "node";
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ReqRunner {
|
|
52
|
+
(args: string[], options?: { timeoutMs?: number }): Promise<unknown>;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Runs `laoshi api <args>` and returns its data, or throws ReqError with laoshi's message. */
|
|
56
|
+
export function reqApi(kitHome: () => string): ReqRunner {
|
|
57
|
+
return (args, options = {}) =>
|
|
58
|
+
new Promise((resolve, reject) => {
|
|
59
|
+
let req: string;
|
|
60
|
+
const home = kitHome();
|
|
61
|
+
try {
|
|
62
|
+
req = activeReq(home);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const env: NodeJS.ProcessEnv = { ...process.env, LAOSHI_HOME: home };
|
|
68
|
+
// Not a chat: the run keeps reporting to the chat that started it.
|
|
69
|
+
delete env.PASEO_AGENT_ID;
|
|
70
|
+
delete env.PASEO_AGENT_CWD;
|
|
71
|
+
execFile(
|
|
72
|
+
nodeBinary(),
|
|
73
|
+
[req, "api", ...args],
|
|
74
|
+
{ env, timeout: options.timeoutMs ?? 60_000, maxBuffer: 16 * 1024 * 1024, windowsHide: true },
|
|
75
|
+
(error, stdout, stderr) => {
|
|
76
|
+
const line = stdout.trim().split("\n").pop() ?? "";
|
|
77
|
+
let parsed: { schema?: number; data?: unknown; error?: { code: string; message: string } } | null = null;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(line);
|
|
80
|
+
} catch {
|
|
81
|
+
parsed = null;
|
|
82
|
+
}
|
|
83
|
+
if (parsed?.error) return reject(new ReqError(parsed.error.code, parsed.error.message));
|
|
84
|
+
if (parsed && "data" in parsed) return resolve(parsed.data);
|
|
85
|
+
const why = (stderr || error?.message || "没有输出").trim().split("\n").slice(-3).join(" ");
|
|
86
|
+
reject(new ReqError("failed", `laoshi api ${args[0] ?? ""} 失败:${why}`));
|
|
87
|
+
},
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The same call made twice within `ms` shares one run (several open screens, one daemon). */
|
|
93
|
+
export function coalesce<T>(ms: number, run: () => Promise<T>): () => Promise<T> {
|
|
94
|
+
let last: { at: number; value: Promise<T> } | null = null;
|
|
95
|
+
return () => {
|
|
96
|
+
const now = Date.now();
|
|
97
|
+
if (last && now - last.at < ms) return last.value;
|
|
98
|
+
const value = run();
|
|
99
|
+
last = { at: now, value };
|
|
100
|
+
value.catch(() => {
|
|
101
|
+
if (last?.value === value) last = null;
|
|
102
|
+
});
|
|
103
|
+
return value;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
// What the plugin's app side asks its daemon side. The daemon side answers by running
|
|
2
|
+
// `laoshi api …` (contracts/cli-json.md); these types mirror that format.
|
|
3
|
+
import { defineRpc, defineSettings } from "@getpaseo/plugin";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
export type Attention = "approval" | "business" | "permission" | "interrupted" | "not_completed" | "not_started" | null;
|
|
7
|
+
|
|
8
|
+
export interface Usage {
|
|
9
|
+
steps: number;
|
|
10
|
+
agentMinutes: number;
|
|
11
|
+
inputTokens: number | null;
|
|
12
|
+
outputTokens: number | null;
|
|
13
|
+
costUsd: number | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Requirement {
|
|
17
|
+
key: string;
|
|
18
|
+
project: string;
|
|
19
|
+
repo: string;
|
|
20
|
+
sourceRepo: string | null;
|
|
21
|
+
workspaceId: string | null;
|
|
22
|
+
featureDir: string;
|
|
23
|
+
name: string;
|
|
24
|
+
title: string;
|
|
25
|
+
type: string | null;
|
|
26
|
+
profile: string | null;
|
|
27
|
+
branch: string | null;
|
|
28
|
+
stage: string;
|
|
29
|
+
status: string | null;
|
|
30
|
+
running: boolean;
|
|
31
|
+
phase: string | null;
|
|
32
|
+
attention: Attention;
|
|
33
|
+
current: Array<{ key: string; title: string; agentId: string }>;
|
|
34
|
+
updatedAt: string;
|
|
35
|
+
usage: Usage | null;
|
|
36
|
+
present: boolean;
|
|
37
|
+
/** req-kit 1.13+: it has an interface prototype, which the review page shows. */
|
|
38
|
+
hasPrototype?: boolean;
|
|
39
|
+
/** req-kit 1.12+: what a requirement that needs a person is waiting for; absent before. */
|
|
40
|
+
waiting?: {
|
|
41
|
+
since: string;
|
|
42
|
+
questions: string[];
|
|
43
|
+
reason: string | null;
|
|
44
|
+
card: { system: string; id: string; url: string | null; requester: string | null } | null;
|
|
45
|
+
canReply: boolean;
|
|
46
|
+
/** req-kit 1.13+, attention "permission": the step agent waiting for an approval. */
|
|
47
|
+
agentId?: string;
|
|
48
|
+
/** req-kit 1.14+, attention "not_started": development can be started from here. */
|
|
49
|
+
canStart?: boolean;
|
|
50
|
+
} | null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface Step {
|
|
54
|
+
key: string;
|
|
55
|
+
stepId: string;
|
|
56
|
+
title: string;
|
|
57
|
+
phase: string | null;
|
|
58
|
+
attempt: number;
|
|
59
|
+
round: number | null;
|
|
60
|
+
agentId: string;
|
|
61
|
+
startedAt: string;
|
|
62
|
+
endedAt: string | null;
|
|
63
|
+
minutes: number;
|
|
64
|
+
outcome: "running" | "completed" | "failed";
|
|
65
|
+
result: string | null;
|
|
66
|
+
error: string | null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface GateRun {
|
|
70
|
+
key: string;
|
|
71
|
+
attempt: number;
|
|
72
|
+
at: string;
|
|
73
|
+
checks: Array<{ name: string; result: string; failedBefore: boolean }>;
|
|
74
|
+
newFailures: string[];
|
|
75
|
+
fixRounds: number;
|
|
76
|
+
passed: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface RequirementDetail extends Requirement {
|
|
80
|
+
files: string[];
|
|
81
|
+
/** req-kit 1.14+: the person's code review on the code review page; null before one. */
|
|
82
|
+
humanReview?: { status: "approved" | "changes_requested"; reviewer: string; at: string; reviewers: string[]; items: number; stale: boolean; consumedAttempt: number | null } | null;
|
|
83
|
+
/** req-kit 1.13+: what to expect, from this machine's completed requirements of the same profile; null without enough history. */
|
|
84
|
+
estimate?: {
|
|
85
|
+
basis: number;
|
|
86
|
+
profile: string;
|
|
87
|
+
typicalAgentMinutes: number;
|
|
88
|
+
typicalTokens: number | null;
|
|
89
|
+
usedAgentMinutes: number;
|
|
90
|
+
usedTokens: number | null;
|
|
91
|
+
leftMinutes: number;
|
|
92
|
+
over: boolean;
|
|
93
|
+
} | null;
|
|
94
|
+
run: {
|
|
95
|
+
attempt: number;
|
|
96
|
+
startedAt: string;
|
|
97
|
+
updatedAt: string;
|
|
98
|
+
phaseMode: string | null;
|
|
99
|
+
stopReason: string | null;
|
|
100
|
+
outcome: string | null;
|
|
101
|
+
queuedSince: string | null;
|
|
102
|
+
verifyAt: string | null;
|
|
103
|
+
approval: { attempt: number; status: string; at: string } | null;
|
|
104
|
+
originAgentId: string | null;
|
|
105
|
+
} | null;
|
|
106
|
+
steps: Step[];
|
|
107
|
+
gate: { runs: GateRun[] } | null;
|
|
108
|
+
joint: Array<{ name: string; repo: string; branch: string; workspaceId: string; gate: { runs: GateRun[] } | null }>;
|
|
109
|
+
/** Cards in external systems (req-kit 1.9.0+; absent before). */
|
|
110
|
+
external?: Array<{ name: string; id: string | null; url: string | null; status: string | null; syncedAt: string | null; pending: number; lastError: string | null }>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface StatsSummary {
|
|
114
|
+
period: { label: string };
|
|
115
|
+
machines: string[];
|
|
116
|
+
active: number;
|
|
117
|
+
completed: { total: number; byOutcome: Record<string, number> };
|
|
118
|
+
byType: Record<string, number>;
|
|
119
|
+
cycleHours: { median: number | null; average: number | null };
|
|
120
|
+
steps: Array<{ stepId: string; title: string; count: number; averageMinutes: number; totalMinutes: number }>;
|
|
121
|
+
rework: { averageReviewRounds: number | null; withDefectRounds: number | null; gateRuns: number; gateFailed: number };
|
|
122
|
+
waits: Array<{ kind: string; label: string; requirements: number; averageMinutes: number }>;
|
|
123
|
+
usage: { agentMinutes: number; inputTokens: number | null; outputTokens: number | null; costUsd: number | null };
|
|
124
|
+
/** req-kit 1.13+: where the tokens went. */
|
|
125
|
+
tokens?: {
|
|
126
|
+
total: number | null;
|
|
127
|
+
cachedShare: number | null;
|
|
128
|
+
byStep: Array<{ stepId: string; title: string; steps: number; tokens: number; share: number }>;
|
|
129
|
+
byAgent: Array<{ agent: string; steps: number; tokens: number; share: number }>;
|
|
130
|
+
rework: { tokens: number; share: number } | null;
|
|
131
|
+
perRequirement: { median: number | null; byProfile: Array<{ profile: string; requirements: number; median: number | null }> };
|
|
132
|
+
};
|
|
133
|
+
/** req-kit 1.14+: people's code reviews, acceptance, merges and problems after them. */
|
|
134
|
+
oversight?: {
|
|
135
|
+
reviews: { total: number; requirements: number; sentBack: number; passedFirstTime: number; items: number };
|
|
136
|
+
acceptance: { total: number; requirements: number; failed: number; passedFirstTime: number };
|
|
137
|
+
merged: { requirements: number; medianHoursAfterCompletion: number | null };
|
|
138
|
+
issues: { total: number; requirements: number };
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface KitInfo {
|
|
143
|
+
kitVersion: string;
|
|
144
|
+
kitRoot: string;
|
|
145
|
+
apiSchema: number;
|
|
146
|
+
paseo: string | null;
|
|
147
|
+
/** Where the daemon side found laoshi (the install root it read install.json from). */
|
|
148
|
+
kitHome: string;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Where a requirement is: as `laoshi api` names it. */
|
|
152
|
+
const target = z.object({ repo: z.string().min(1), featureDir: z.string().min(1) });
|
|
153
|
+
|
|
154
|
+
export const versionRpc = defineRpc({
|
|
155
|
+
name: "req.version",
|
|
156
|
+
input: z.object({}),
|
|
157
|
+
output: z.custom<KitInfo>(),
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
export const listRpc = defineRpc({
|
|
161
|
+
name: "req.list",
|
|
162
|
+
input: z.object({}),
|
|
163
|
+
output: z.custom<Requirement[]>(),
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
export const statusRpc = defineRpc({
|
|
167
|
+
name: "req.status",
|
|
168
|
+
input: target,
|
|
169
|
+
output: z.custom<RequirementDetail>(),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/** Documents the plugin shows; laoshi api only allows its own list (READABLE_FILES). */
|
|
173
|
+
export const fileRpc = defineRpc({
|
|
174
|
+
name: "req.file",
|
|
175
|
+
input: target.extend({ file: z.string().min(1) }),
|
|
176
|
+
output: z.custom<{ file: string; size: number; truncated: boolean; content: string }>(),
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
export const statsRpc = defineRpc({
|
|
180
|
+
name: "req.stats",
|
|
181
|
+
input: z.object({ since: z.string().optional(), month: z.string().optional() }),
|
|
182
|
+
output: z.custom<StatsSummary>(),
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
export const ACTIONS = ["approve", "stop", "resume", "verify", "sync", "reply", "start"] as const;
|
|
186
|
+
export type Action = (typeof ACTIONS)[number];
|
|
187
|
+
|
|
188
|
+
export const runRpc = defineRpc({
|
|
189
|
+
name: "req.run",
|
|
190
|
+
input: target.extend({
|
|
191
|
+
action: z.enum(ACTIONS),
|
|
192
|
+
/** For verify: local | deployed. */
|
|
193
|
+
verifyEnv: z.enum(["local", "deployed"]).optional(),
|
|
194
|
+
/** For reply (1.12): the answer, passed to the requirement's chat. */
|
|
195
|
+
text: z.string().max(8000).optional(),
|
|
196
|
+
}),
|
|
197
|
+
output: z.object({ ok: z.boolean(), message: z.string() }),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
/** laoshi api review-url (1.13): the address of the requirement's prototype review page. */
|
|
201
|
+
export const reviewUrlRpc = defineRpc({
|
|
202
|
+
name: "req.review-url",
|
|
203
|
+
/** page (1.14): "check" for the acceptance checklist, "code" for the code review page; the prototype review page otherwise. */
|
|
204
|
+
input: target.extend({ page: z.enum(["prototype", "check", "code"]).optional() }),
|
|
205
|
+
output: z.object({ url: z.string(), readOnly: z.boolean() }),
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
/** laoshi api config (1.12): every setting, its value in words and which file set it. */
|
|
209
|
+
export type ConfigLayer = "machine" | "team" | "project";
|
|
210
|
+
|
|
211
|
+
export interface ConfigItemData {
|
|
212
|
+
key: string;
|
|
213
|
+
label: string;
|
|
214
|
+
description: string;
|
|
215
|
+
display: string;
|
|
216
|
+
value: unknown;
|
|
217
|
+
setBy: ConfigLayer[];
|
|
218
|
+
scope: "any" | "machine" | "machine_team";
|
|
219
|
+
changed: boolean;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export interface ConfigViewData {
|
|
223
|
+
sources: Array<{ layer: ConfigLayer; path: string }>;
|
|
224
|
+
ignored: string[];
|
|
225
|
+
error: string | null;
|
|
226
|
+
repo: string | null;
|
|
227
|
+
groups: Array<{ id: string; title: string; description: string; items: ConfigItemData[] }>;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The configuration in a project (repo), or this machine's without a project. */
|
|
231
|
+
export const configRpc = defineRpc({
|
|
232
|
+
name: "req.config",
|
|
233
|
+
input: z.object({ repo: z.string().optional() }),
|
|
234
|
+
output: z.custom<ConfigViewData>(),
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
/** Agent settings, as laoshi writes them (1.12). */
|
|
238
|
+
export interface AgentProfileData {
|
|
239
|
+
provider?: string;
|
|
240
|
+
paseoProfile?: string;
|
|
241
|
+
modeId?: string;
|
|
242
|
+
[key: string]: unknown;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
export interface AgentChoiceData {
|
|
246
|
+
id: string;
|
|
247
|
+
label: string;
|
|
248
|
+
provider: string;
|
|
249
|
+
profile: AgentProfileData;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export interface ModelsData {
|
|
253
|
+
current: { builder?: AgentProfileData; reviewer?: AgentProfileData; fallback?: AgentProfileData | null } | null;
|
|
254
|
+
choices: AgentChoiceData[];
|
|
255
|
+
recommended: { builder?: AgentProfileData; reviewer?: AgentProfileData; fallback?: AgentProfileData | null } | null;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** What Paseo offers for builder, reviewer and the fallback model, and what is set now. */
|
|
259
|
+
export const modelsRpc = defineRpc({
|
|
260
|
+
name: "req.models",
|
|
261
|
+
input: z.object({}),
|
|
262
|
+
output: z.custom<ModelsData>(),
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
const profile = z.record(z.string(), z.unknown());
|
|
266
|
+
|
|
267
|
+
/** Writes the agents to this machine's laoshi config (refused when the plugin is read-only). */
|
|
268
|
+
export const setAgentsRpc = defineRpc({
|
|
269
|
+
name: "req.set-agents",
|
|
270
|
+
input: z.object({ builder: profile, reviewer: profile, fallback: profile.nullable() }),
|
|
271
|
+
output: z.object({ ok: z.boolean(), message: z.string() }),
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
export const preferences = defineSettings({
|
|
275
|
+
id: "preferences",
|
|
276
|
+
scope: "host",
|
|
277
|
+
version: 1,
|
|
278
|
+
schema: z.object({
|
|
279
|
+
/** Show requirements and documents only; hide stop, resume, approve and verify. */
|
|
280
|
+
readOnly: z.boolean().default(false),
|
|
281
|
+
/** How often an open screen refreshes, in seconds. */
|
|
282
|
+
refreshSeconds: z.number().int().min(3).max(300).default(10),
|
|
283
|
+
/** laoshi's install root, when the plugin cannot find it by itself (LAOSHI_HOME). */
|
|
284
|
+
kitHome: z.string().default(""),
|
|
285
|
+
}),
|
|
286
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// laoshi accent colors for the Paseo plugin, copied from req-kit's design tokens.
|
|
2
|
+
export const RK_COLORS = {
|
|
3
|
+
"dark": {
|
|
4
|
+
"brand500": "#a8e01f",
|
|
5
|
+
"brand400": "#bdeb4a",
|
|
6
|
+
"brandEdge": "#a8e01f",
|
|
7
|
+
"brandText": "#c2ee55",
|
|
8
|
+
"brandTint": "#a8e01f24",
|
|
9
|
+
"onBrand": "#0f1a02",
|
|
10
|
+
"ai": "#a5b4fc",
|
|
11
|
+
"aiTint": "#818cf81f",
|
|
12
|
+
"data": "#22d3ee",
|
|
13
|
+
"dataTint": "#22d3ee1f",
|
|
14
|
+
"successTint": "#34d3991f",
|
|
15
|
+
"warningTint": "#fbbf241f",
|
|
16
|
+
"failedTint": "#fb71851f"
|
|
17
|
+
},
|
|
18
|
+
"light": {
|
|
19
|
+
"brand500": "#a8e01f",
|
|
20
|
+
"brand400": "#b3e536",
|
|
21
|
+
"brandEdge": "#65a30d",
|
|
22
|
+
"brandText": "#466f0f",
|
|
23
|
+
"brandTint": "#a8e01f2e",
|
|
24
|
+
"onBrand": "#0f1a02",
|
|
25
|
+
"ai": "#4f46e5",
|
|
26
|
+
"aiTint": "#4f46e514",
|
|
27
|
+
"data": "#0e7490",
|
|
28
|
+
"dataTint": "#0e749014",
|
|
29
|
+
"successTint": "#04785714",
|
|
30
|
+
"warningTint": "#92400e14",
|
|
31
|
+
"failedTint": "#be123c14"
|
|
32
|
+
}
|
|
33
|
+
} as const;
|
|
34
|
+
|
|
35
|
+
export type RkColors = (typeof RK_COLORS)["dark"];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2023"],
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"allowSyntheticDefaultImports": true,
|
|
12
|
+
"noEmit": true,
|
|
13
|
+
"types": ["node"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["index.client.tsx", "index.server.ts", "client/**/*", "server/**/*", "shared/**/*"]
|
|
16
|
+
}
|