@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,506 @@
|
|
|
1
|
+
// The engine's runtime for 摸高 (docs/design/mogao-expert.md, form B1). Each step agent is a run of the
|
|
2
|
+
// platform's command line, `aimax run` (a new agent with tools, synchronous, JSON output), continued
|
|
3
|
+
// with `-s <sessionId>`; approvals are the platform's HITL (`paused`, then `aimax resume`). Tool
|
|
4
|
+
// calls and usage come from the platform's progress callback (`--callback-url`), received here.
|
|
5
|
+
//
|
|
6
|
+
// The platform keeps a container for one chat turn only, so the engine runs in the chat's command
|
|
7
|
+
// and every agent's state is kept on disk (<install root>/mogao/agents/<id>/): a later turn's engine
|
|
8
|
+
// picks an agent up again, and continues its session when the turn ended in the middle of a run.
|
|
9
|
+
//
|
|
10
|
+
// Worktrees and services are laoshi's builtin ones; there is no scheduling and no way to send the
|
|
11
|
+
// chat a message, so notifications go to the chat's command output (LAOSHI_CHAT_OUT, see launch.ts).
|
|
12
|
+
import { type ChildProcess, spawn } from "node:child_process";
|
|
13
|
+
import crypto from "node:crypto";
|
|
14
|
+
import fs from "node:fs";
|
|
15
|
+
import http from "node:http";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
import type { ToolCall } from "../../engine/src/danger-guard.js";
|
|
19
|
+
import { homeOf } from "../../engine/src/locations.js";
|
|
20
|
+
import { isAlive as engineProcessAlive } from "../../engine/src/state.js";
|
|
21
|
+
import type { AgentRuntime, RuntimeFactory, StepAgent, WaitOutcome } from "../../engine/src/runtime.js";
|
|
22
|
+
import type { RunningTool } from "../../engine/src/scan-guard.js";
|
|
23
|
+
import type { AgentUsage } from "../../engine/src/usage.js";
|
|
24
|
+
|
|
25
|
+
/** Settings from the install-level config's platform.mogao. */
|
|
26
|
+
export interface MogaoSettings {
|
|
27
|
+
/** The platform's command line; LAOSHI_AIMAX overrides it (tests). */
|
|
28
|
+
command: string;
|
|
29
|
+
/** The platform's data directory (`-d`), where its sessions live. */
|
|
30
|
+
dataDir: string;
|
|
31
|
+
/** Hard limit of one `aimax run`, in minutes (the engine keeps its own step limits). */
|
|
32
|
+
runTimeoutMinutes: number;
|
|
33
|
+
/** `--plugins-config` for step agents (the platform's plugins, e.g. its knowledge base), or null. */
|
|
34
|
+
pluginsConfig: string | null;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function mogaoSettings(config: unknown, env: NodeJS.ProcessEnv = process.env): MogaoSettings {
|
|
38
|
+
const raw = ((config as { platform?: { mogao?: Record<string, unknown> } } | null)?.platform?.mogao ?? {}) as Record<string, unknown>;
|
|
39
|
+
const text = (v: unknown) => (typeof v === "string" && v.trim() ? v.trim() : null);
|
|
40
|
+
const minutes = typeof raw.runTimeoutMinutes === "number" && raw.runTimeoutMinutes > 0 ? raw.runTimeoutMinutes : 240;
|
|
41
|
+
return {
|
|
42
|
+
command: text(env.LAOSHI_AIMAX) ?? text(raw.command) ?? "aimax",
|
|
43
|
+
dataDir: text(raw.dataDir) ?? "/data",
|
|
44
|
+
runTimeoutMinutes: minutes,
|
|
45
|
+
pluginsConfig: text(raw.pluginsConfig),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The platform's result of a run (`--output json`), as far as the engine reads it. */
|
|
50
|
+
export interface RunResult {
|
|
51
|
+
sessionId?: string;
|
|
52
|
+
text?: string;
|
|
53
|
+
usage?: { input?: number; output?: number; total?: number } | null;
|
|
54
|
+
paused?: { requestId: string; kind?: string; title?: string } | null;
|
|
55
|
+
error?: string | null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function toAgentUsage(u: RunResult["usage"]): AgentUsage | null {
|
|
59
|
+
if (!u) return null;
|
|
60
|
+
return { inputTokens: u.input ?? 0, cachedInputTokens: 0, outputTokens: u.output ?? 0 };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** Takes the JSON object out of a run's standard output (the last line that parses). */
|
|
64
|
+
export function parseRunOutput(stdout: string): RunResult | null {
|
|
65
|
+
const trimmed = stdout.trim();
|
|
66
|
+
if (!trimmed) return null;
|
|
67
|
+
try {
|
|
68
|
+
return JSON.parse(trimmed) as RunResult;
|
|
69
|
+
} catch {
|
|
70
|
+
for (const line of trimmed.split("\n").reverse()) {
|
|
71
|
+
try {
|
|
72
|
+
const value = JSON.parse(line.trim()) as unknown;
|
|
73
|
+
if (value && typeof value === "object") return value as RunResult;
|
|
74
|
+
} catch {
|
|
75
|
+
// Not this line.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** Platform credentials and tokens are never written to laoshi's files. */
|
|
83
|
+
export function redact(text: string): string {
|
|
84
|
+
return text
|
|
85
|
+
.replace(/(authorization["']?\s*[:=]\s*["']?(?:bearer\s+)?)[^\s"',}]+/gi, "$1***")
|
|
86
|
+
.replace(/\b(bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi, "$1***")
|
|
87
|
+
.replace(/((?:token|secret|password|api[_-]?key|credential)[A-Za-z_]*["']?\s*[:=]\s*["']?)[^\s"',}]{4,}/gi, "$1***")
|
|
88
|
+
.replace(/(AIMAX_[A-Z_]*(?:TOKEN|KEY|SECRET)[A-Z_]*=)\S+/g, "$1***");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** What laoshi keeps about one step agent between engine processes. */
|
|
92
|
+
interface AgentRecord {
|
|
93
|
+
id: string;
|
|
94
|
+
cwd: string;
|
|
95
|
+
title: string;
|
|
96
|
+
sessionId: string | null;
|
|
97
|
+
/** Number of runs so far (run-<n>.out is the latest's output). */
|
|
98
|
+
runs: number;
|
|
99
|
+
/** The latest run's process, and the machine (container) it ran in. */
|
|
100
|
+
pid: number | null;
|
|
101
|
+
host: string | null;
|
|
102
|
+
/** The HITL request a decision was sent for (decision.json), so it is answered once. */
|
|
103
|
+
answered: string | null;
|
|
104
|
+
/** When the latest run started: its callback events are the ones after this. */
|
|
105
|
+
runStartedAt?: string | null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** A decision on a pending approval, written by `laoshi permission` (answerPermission). */
|
|
109
|
+
interface Decision {
|
|
110
|
+
requestId: string;
|
|
111
|
+
approve: boolean;
|
|
112
|
+
reason: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const CONTINUE_MESSAGE = "上一次运行被中断了(对话轮次结束)。请接着完成原来的任务:先看一下已经做了什么,不要重复已经完成的部分。";
|
|
116
|
+
|
|
117
|
+
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
|
|
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
|
+
|
|
122
|
+
const isAlive = (pid: number) => engineProcessAlive(pid);
|
|
123
|
+
|
|
124
|
+
/** The callback receiver: one local HTTP server for all step agents of this engine process. */
|
|
125
|
+
class CallbackServer {
|
|
126
|
+
private server: http.Server | null = null;
|
|
127
|
+
private port = 0;
|
|
128
|
+
constructor(private readonly onEvent: (agentId: string, event: Record<string, unknown>) => void) {}
|
|
129
|
+
|
|
130
|
+
async url(agentId: string): Promise<string> {
|
|
131
|
+
if (!this.server) {
|
|
132
|
+
this.server = http.createServer((req, res) => {
|
|
133
|
+
const agentId = decodeURIComponent((req.url ?? "").replace(/^\/cb\//, "").split("?")[0]);
|
|
134
|
+
let body = "";
|
|
135
|
+
req.setEncoding("utf8");
|
|
136
|
+
req.on("data", (chunk) => {
|
|
137
|
+
if (body.length < 4_000_000) body += chunk;
|
|
138
|
+
});
|
|
139
|
+
req.on("end", () => {
|
|
140
|
+
res.writeHead(204).end();
|
|
141
|
+
try {
|
|
142
|
+
const event = JSON.parse(body) as Record<string, unknown>;
|
|
143
|
+
if (agentId) this.onEvent(agentId, event);
|
|
144
|
+
} catch {
|
|
145
|
+
// Not an event.
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
await new Promise<void>((resolve) => this.server!.listen(0, "127.0.0.1", resolve));
|
|
150
|
+
this.port = (this.server.address() as { port: number }).port;
|
|
151
|
+
this.server.unref();
|
|
152
|
+
}
|
|
153
|
+
return `http://127.0.0.1:${this.port}/cb/${encodeURIComponent(agentId)}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
close(): Promise<void> {
|
|
157
|
+
return new Promise((resolve) => (this.server ? this.server.close(() => resolve()) : resolve()));
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** An event's type and payload, whatever envelope the platform wraps them in. */
|
|
162
|
+
export function eventParts(event: Record<string, unknown>): { type: string; data: Record<string, unknown> } {
|
|
163
|
+
const type = String(event.type ?? event.event ?? "");
|
|
164
|
+
const data = (event.data ?? event.payload ?? event) as Record<string, unknown>;
|
|
165
|
+
return { type, data: data && typeof data === "object" ? data : {} };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export interface MogaoRuntimeOptions {
|
|
169
|
+
settings: MogaoSettings;
|
|
170
|
+
/** Where agents' records live: <install root>/mogao/agents. */
|
|
171
|
+
agentsDir: string;
|
|
172
|
+
log: (message: string) => void;
|
|
173
|
+
/** Where notifications for the chat go (the chat's command output); null: the log only. */
|
|
174
|
+
chatOut: string | null;
|
|
175
|
+
env?: NodeJS.ProcessEnv;
|
|
176
|
+
pollMs?: number;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function createMogaoRuntime(options: MogaoRuntimeOptions): AgentRuntime {
|
|
180
|
+
const { settings, agentsDir, log } = options;
|
|
181
|
+
const env = options.env ?? process.env;
|
|
182
|
+
const pollMs = options.pollMs ?? 500;
|
|
183
|
+
const children = new Map<string, ChildProcess>();
|
|
184
|
+
const dir = (id: string) => path.join(agentsDir, id);
|
|
185
|
+
const recordFile = (id: string) => path.join(dir(id), "agent.json");
|
|
186
|
+
const read = (id: string): AgentRecord | null => {
|
|
187
|
+
try {
|
|
188
|
+
return JSON.parse(fs.readFileSync(recordFile(id), "utf8")) as AgentRecord;
|
|
189
|
+
} catch {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const write = (record: AgentRecord) => {
|
|
194
|
+
fs.mkdirSync(dir(record.id), { recursive: true });
|
|
195
|
+
fs.writeFileSync(recordFile(record.id), `${JSON.stringify(record, null, 2)}\n`);
|
|
196
|
+
};
|
|
197
|
+
const eventsFile = (id: string) => path.join(dir(id), "events.jsonl");
|
|
198
|
+
|
|
199
|
+
const callbacks = new CallbackServer((agentId, event) => {
|
|
200
|
+
if (!fs.existsSync(dir(agentId))) return;
|
|
201
|
+
const { type, data } = eventParts(event);
|
|
202
|
+
if (type === "start" && typeof data.sessionId === "string") {
|
|
203
|
+
const record = read(agentId);
|
|
204
|
+
if (record && !record.sessionId) write({ ...record, sessionId: data.sessionId });
|
|
205
|
+
}
|
|
206
|
+
// Tool output can hold anything the agent printed: keep a redacted, shortened copy.
|
|
207
|
+
const keep: Record<string, unknown> = { at: new Date().toISOString(), type };
|
|
208
|
+
if (type === "tool_start") {
|
|
209
|
+
const input = (data.input ?? {}) as Record<string, unknown>;
|
|
210
|
+
Object.assign(keep, { callId: data.toolCallId, name: data.name, command: typeof input.command === "string" ? redact(input.command) : null, riskLevel: input.riskLevel ?? null });
|
|
211
|
+
} else if (type === "tool_end") {
|
|
212
|
+
const details = (data.details ?? {}) as Record<string, unknown>;
|
|
213
|
+
Object.assign(keep, { callId: data.toolCallId, exitCode: details.exitCode ?? null, output: typeof data.output === "string" ? redact(data.output).slice(-2000) : null });
|
|
214
|
+
} else if (type === "usage") {
|
|
215
|
+
Object.assign(keep, { input: data.input ?? null, output: data.output ?? null, total: data.total ?? null });
|
|
216
|
+
} else if (type === "done") {
|
|
217
|
+
const result = (data.result ?? {}) as Record<string, unknown>;
|
|
218
|
+
Object.assign(keep, { usage: result.usage ?? null, text: typeof result.text === "string" ? redact(result.text).slice(0, 4000) : null });
|
|
219
|
+
} else if (type !== "start" && type !== "title_updated") {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
fs.appendFileSync(eventsFile(agentId), `${JSON.stringify(keep)}\n`);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
const events = (id: string): Array<Record<string, unknown>> => {
|
|
226
|
+
try {
|
|
227
|
+
return fs
|
|
228
|
+
.readFileSync(eventsFile(id), "utf8")
|
|
229
|
+
.split("\n")
|
|
230
|
+
.filter(Boolean)
|
|
231
|
+
.map((l) => JSON.parse(l) as Record<string, unknown>);
|
|
232
|
+
} catch {
|
|
233
|
+
return [];
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
const toolCalls = async (id: string): Promise<ToolCall[] | null> => {
|
|
238
|
+
if (!read(id)) return null;
|
|
239
|
+
const calls = new Map<string, ToolCall>();
|
|
240
|
+
for (const e of events(id)) {
|
|
241
|
+
const callId = String(e.callId ?? "");
|
|
242
|
+
if (!callId) continue;
|
|
243
|
+
if (e.type === "tool_start") calls.set(callId, { callId, kind: e.name === "exec" ? "shell" : String(e.name ?? "tool"), text: String(e.command ?? ""), status: "running", startedAt: String(e.at) });
|
|
244
|
+
else if (e.type === "tool_end" && calls.has(callId)) calls.get(callId)!.status = "completed";
|
|
245
|
+
}
|
|
246
|
+
return [...calls.values()];
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
/** Starts one `aimax` process for an agent: a new run, its continuation, or an approval's answer. */
|
|
250
|
+
async function launch(record: AgentRecord, args: string[]): Promise<void> {
|
|
251
|
+
const n = record.runs + 1;
|
|
252
|
+
const out = fs.openSync(path.join(dir(record.id), `run-${n}.out`), "w");
|
|
253
|
+
const err = fs.openSync(path.join(dir(record.id), `run-${n}.err`), "w");
|
|
254
|
+
const callback = await callbacks.url(record.id);
|
|
255
|
+
const child = spawn(settings.command, [...args, "--output", "json", "--callback-url", callback], { cwd: record.cwd, env, stdio: ["ignore", out, err], windowsHide: true });
|
|
256
|
+
fs.closeSync(out);
|
|
257
|
+
fs.closeSync(err);
|
|
258
|
+
children.set(record.id, child);
|
|
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);
|
|
264
|
+
child.on("error", (e) => {
|
|
265
|
+
fs.appendFileSync(path.join(dir(record.id), `run-${n}.err`), `\n${e.message}\n`);
|
|
266
|
+
forget();
|
|
267
|
+
});
|
|
268
|
+
write({ ...record, runs: n, pid: child.pid ?? null, host: os.hostname(), runStartedAt: new Date().toISOString() });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
const runArgs = (record: AgentRecord, message: string) => [
|
|
272
|
+
"run",
|
|
273
|
+
...(record.sessionId ? ["-s", record.sessionId] : ["--project-dir", record.cwd]),
|
|
274
|
+
"-d",
|
|
275
|
+
settings.dataDir,
|
|
276
|
+
"--message",
|
|
277
|
+
message,
|
|
278
|
+
"--timeout",
|
|
279
|
+
String(settings.runTimeoutMinutes * 60_000),
|
|
280
|
+
...(settings.pluginsConfig ? ["--plugins-config", settings.pluginsConfig] : []),
|
|
281
|
+
];
|
|
282
|
+
|
|
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
|
+
*/
|
|
290
|
+
function finished(record: AgentRecord): { result: RunResult | null; stderr: string } | null {
|
|
291
|
+
const read = (suffix: string) => {
|
|
292
|
+
try {
|
|
293
|
+
return fs.readFileSync(path.join(dir(record.id), `run-${record.runs}.${suffix}`), "utf8");
|
|
294
|
+
} catch {
|
|
295
|
+
return "";
|
|
296
|
+
}
|
|
297
|
+
};
|
|
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 };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
const stepAgent = (id: string): StepAgent => ({
|
|
338
|
+
id,
|
|
339
|
+
async wait(timeoutMs: number): Promise<WaitOutcome> {
|
|
340
|
+
const deadline = Date.now() + timeoutMs;
|
|
341
|
+
const base = { error: null, lastMessage: null, pendingPermissions: [] };
|
|
342
|
+
for (;;) {
|
|
343
|
+
let record = read(id);
|
|
344
|
+
if (!record) return { ...base, status: "error", error: `找不到 laoshi 记录的 agent ${id}` };
|
|
345
|
+
const done = finished(record);
|
|
346
|
+
if (done) {
|
|
347
|
+
const { result, stderr } = done;
|
|
348
|
+
if (result?.sessionId && result.sessionId !== record.sessionId) {
|
|
349
|
+
record = { ...record, sessionId: result.sessionId };
|
|
350
|
+
write(record);
|
|
351
|
+
}
|
|
352
|
+
const usage = toAgentUsage(result?.usage);
|
|
353
|
+
if (result?.paused?.requestId) {
|
|
354
|
+
const decision = readDecision(id);
|
|
355
|
+
if (decision && decision.requestId === result.paused.requestId && record.answered !== decision.requestId && record.sessionId) {
|
|
356
|
+
await launch({ ...record, answered: decision.requestId }, [
|
|
357
|
+
"resume",
|
|
358
|
+
"-d",
|
|
359
|
+
settings.dataDir,
|
|
360
|
+
"-s",
|
|
361
|
+
record.sessionId,
|
|
362
|
+
"--request-id",
|
|
363
|
+
decision.requestId,
|
|
364
|
+
"--input-json",
|
|
365
|
+
JSON.stringify({ action: decision.approve ? "approve" : "deny", reason: decision.reason }),
|
|
366
|
+
]);
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
return { ...base, usage, status: "permission", pendingPermissions: [{ id: result.paused.requestId, title: result.paused.title ?? "需要批准的操作" }] };
|
|
370
|
+
}
|
|
371
|
+
if (result && !result.error) return { ...base, usage, status: "idle", lastMessage: result.text ?? null };
|
|
372
|
+
if (result?.error) return { ...base, usage, status: "error", error: /timed out/i.test(result.error) ? `超过 ${settings.runTimeoutMinutes} 分钟(单次运行的上限),运行已停止` : result.error };
|
|
373
|
+
// No result: the run was cut off (the chat's turn ended with the container). Continue its session.
|
|
374
|
+
if (record.sessionId && record.host !== os.hostname()) {
|
|
375
|
+
log(`agent ${id} 的上一次运行被中断(没有结果),接着它的会话 ${record.sessionId} 继续`);
|
|
376
|
+
await launch(record, runArgs(record, CONTINUE_MESSAGE));
|
|
377
|
+
continue;
|
|
378
|
+
}
|
|
379
|
+
return { ...base, status: "error", error: `运行没有输出结果${stderr.trim() ? `:${redact(stderr.trim()).split("\n").slice(-3).join(" ")}` : ""}` };
|
|
380
|
+
}
|
|
381
|
+
if (Date.now() >= deadline) return { ...base, status: "timeout", usage: latestUsage(id) };
|
|
382
|
+
await sleep(Math.min(pollMs, Math.max(0, deadline - Date.now())));
|
|
383
|
+
}
|
|
384
|
+
},
|
|
385
|
+
async followUp(text: string): Promise<void> {
|
|
386
|
+
const record = read(id);
|
|
387
|
+
if (!record?.sessionId) throw new Error(`agent ${id} 还没有会话,不能追问`);
|
|
388
|
+
await launch(record, runArgs(record, text));
|
|
389
|
+
},
|
|
390
|
+
async archive(): Promise<void> {
|
|
391
|
+
// Sessions stay with the platform (aimax sessions, export-html); nothing to archive.
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
const readDecision = (id: string): Decision | null => {
|
|
396
|
+
try {
|
|
397
|
+
return JSON.parse(fs.readFileSync(path.join(dir(id), "decision.json"), "utf8")) as Decision;
|
|
398
|
+
} catch {
|
|
399
|
+
return null;
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
const latestUsage = (id: string): AgentUsage | null => {
|
|
404
|
+
const last = events(id).filter((e) => e.type === "usage").at(-1);
|
|
405
|
+
return last ? toAgentUsage({ input: Number(last.input ?? 0), output: Number(last.output ?? 0) }) : null;
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
const chat = (text: string) => {
|
|
409
|
+
log(`给对话的消息:${text.split("\n")[0]}`);
|
|
410
|
+
if (options.chatOut) fs.appendFileSync(options.chatOut, `${text}\n\n`);
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
return {
|
|
414
|
+
async verifyOrigin() {
|
|
415
|
+
// The chat runs the engine in its own command, in the repository: nothing to check across.
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
async startAgent(input) {
|
|
419
|
+
const record: AgentRecord = { id: `mogao-${crypto.randomBytes(6).toString("hex")}`, cwd: input.cwd, title: input.title, sessionId: null, runs: 0, pid: null, host: null, answered: null };
|
|
420
|
+
write(record);
|
|
421
|
+
const promptFile = path.join(dir(record.id), "prompt.md");
|
|
422
|
+
fs.writeFileSync(promptFile, input.prompt);
|
|
423
|
+
// One command-line argument holds at most 128 KB on Linux: a longer prompt is read from its file.
|
|
424
|
+
const message = Buffer.byteLength(input.prompt) <= 100_000 ? input.prompt : `请先完整阅读文件 ${promptFile},然后严格按照其中的要求完成任务。`;
|
|
425
|
+
await launch(record, runArgs(record, message));
|
|
426
|
+
return stepAgent(record.id);
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
attachAgent: (agentId) => stepAgent(agentId),
|
|
430
|
+
|
|
431
|
+
async startSessionAgent() {
|
|
432
|
+
throw new Error("摸高上不能为需求新开对话");
|
|
433
|
+
},
|
|
434
|
+
|
|
435
|
+
async notifyAgent(_agentId, text) {
|
|
436
|
+
chat(text);
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
async interruptAgent(agentId, text) {
|
|
440
|
+
const child = children.get(agentId);
|
|
441
|
+
const record = read(agentId);
|
|
442
|
+
if (child) {
|
|
443
|
+
child.kill("SIGTERM");
|
|
444
|
+
await new Promise((r) => child.once("exit", r));
|
|
445
|
+
} else if (record?.pid && record.host === os.hostname() && isAlive(record.pid)) {
|
|
446
|
+
process.kill(record.pid, "SIGTERM");
|
|
447
|
+
for (let i = 0; i < 50 && isAlive(record.pid); i++) await sleep(100);
|
|
448
|
+
}
|
|
449
|
+
const now = read(agentId);
|
|
450
|
+
if (now?.sessionId) await launch(now, runArgs(now, text));
|
|
451
|
+
},
|
|
452
|
+
|
|
453
|
+
agentDirectory: async () => null,
|
|
454
|
+
listProfiles: async () => null,
|
|
455
|
+
listServices: async () => null,
|
|
456
|
+
startServices: async () => {
|
|
457
|
+
throw new Error("摸高不管理服务");
|
|
458
|
+
},
|
|
459
|
+
stopServices: async () => undefined,
|
|
460
|
+
createWorktree: async () => {
|
|
461
|
+
throw new Error("摸高不提供工作区");
|
|
462
|
+
},
|
|
463
|
+
waitForWorkspaceSetup: async () => ({ status: "none", error: null }),
|
|
464
|
+
providerQuota: async () => null,
|
|
465
|
+
|
|
466
|
+
async recentActivity(agentId, limit) {
|
|
467
|
+
const calls = await toolCalls(agentId);
|
|
468
|
+
return calls ? calls.slice(-limit).map((c) => ({ at: c.startedAt, text: c.kind === "shell" ? `运行命令:${c.text}` : `${c.kind}:${c.text}` })) : null;
|
|
469
|
+
},
|
|
470
|
+
|
|
471
|
+
async runningTool(agentId): Promise<RunningTool | null> {
|
|
472
|
+
const running = (await toolCalls(agentId))?.filter((c) => c.status === "running").at(-1);
|
|
473
|
+
return running ? { kind: running.kind, text: running.text, startedAt: running.startedAt, callId: running.callId } : null;
|
|
474
|
+
},
|
|
475
|
+
|
|
476
|
+
toolCalls,
|
|
477
|
+
capabilities: async () => null,
|
|
478
|
+
providerStatus: async () => null,
|
|
479
|
+
scheduleMessage: async () => null,
|
|
480
|
+
scheduleNewAgent: async () => null,
|
|
481
|
+
cancelSchedule: async () => undefined,
|
|
482
|
+
|
|
483
|
+
async answerPermission(agentId, requestId, approve, reason) {
|
|
484
|
+
const record = read(agentId);
|
|
485
|
+
if (!record) throw new Error(`找不到 laoshi 记录的 agent ${agentId}`);
|
|
486
|
+
const pending = finished(record)?.result?.paused?.requestId ?? null;
|
|
487
|
+
const id = requestId ?? pending;
|
|
488
|
+
if (!id) throw new Error(`agent ${agentId}(${record.title})现在没有等待批准的操作`);
|
|
489
|
+
const decision: Decision = { requestId: id, approve, reason };
|
|
490
|
+
fs.writeFileSync(path.join(dir(agentId), "decision.json"), `${JSON.stringify(decision, null, 2)}\n`);
|
|
491
|
+
},
|
|
492
|
+
|
|
493
|
+
async close() {
|
|
494
|
+
for (const child of children.values()) child.kill("SIGTERM");
|
|
495
|
+
await callbacks.close();
|
|
496
|
+
},
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
export const createRuntime: RuntimeFactory = async ({ config, log }) =>
|
|
501
|
+
createMogaoRuntime({
|
|
502
|
+
settings: mogaoSettings(config),
|
|
503
|
+
agentsDir: path.join(homeOf().dir, "mogao", "agents"),
|
|
504
|
+
log,
|
|
505
|
+
chatOut: process.env.LAOSHI_CHAT_OUT?.trim() || null,
|
|
506
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!-- laoshi: the 摸高 sections of the entry skills (the expert). Each turn of a 摸高 chat gets a new machine; only /data/workspace lasts, so laoshi lives there and is installed on first use. -->
|
|
2
|
+
<!-- fragment: firstUse -->
|
|
3
|
+
## 摸高上第一次使用
|
|
4
|
+
|
|
5
|
+
laoshi 装在工作区(`/data/workspace/.laoshi`),每个对话轮次的机器都是新的,但工作区里的东西会保留,所以**一个工作区只需要安装一次**。执行本 skill 里的任何命令之前,先执行下面这条(工作区里已经是这个版本时立即结束;专家换了新版本时会自动换上):
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
[ "$(node -p "require('{{REQ_KIT_ROOT}}/package.json').version" 2>/dev/null)" = "{{REQ_KIT_VERSION}}" ] || { npm install --prefix /data/workspace/.laoshi/npm --no-audit --no-fund @yiyi_zhang/laoshi@{{REQ_KIT_VERSION}} && node "{{REQ_KIT_ROOT}}/bin/req.mjs" install --platform mogao --home /data/workspace/.laoshi; }
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
第一次大约需要一分钟(从内网 npm 镜像安装)。失败时把输出告诉用户,请开发同事看一下,不要自己改安装目录。
|
|
12
|
+
|
|
13
|
+
本 skill 里写成 `req …` 或 `laoshi …` 的命令,在摸高上写成 `node "{{REQ_KIT_ROOT}}/bin/req.mjs" …`。
|
|
14
|
+
<!-- fragment: launchNote -->
|
|
15
|
+
|
|
16
|
+
**在摸高上不一样的地方:**
|
|
17
|
+
- "启动""继续""确认方案后继续""开始测试验证"这几条命令**不会一两秒就返回**:流水线就在这条命令里运行,进展会陆续出现在命令输出里,直到需要人决定(方案确认、业务问题、等待批准)或做完,命令才结束。这期间**不要结束这一轮对话**:命令转到后台后,持续查看它的输出,把进展用一句话转告用户,等命令结束再回复。对话结束时机器会被收回,流水线随之中断;下一轮用"继续"命令接着做,已经做完的步骤不会重做。
|
|
18
|
+
- 输出提示某个步骤**在等待批准**时:把要批准的操作原样告诉用户,问批准还是拒绝,然后结束这一轮。用户回答后执行 `node "{{REQ_KIT_ROOT}}/bin/req.mjs" permission <功能目录> approve`(拒绝用 `deny`,可以在后面写上理由),它会转达决定并接着运行,同样要等它结束。
|
|
19
|
+
- 没有定时任务:预约启动、定时提醒、自动继续都用不了。需要以后再做的事,告诉用户到时在对话里说"继续"。
|
|
20
|
+
<!-- fragment: toolsNote -->
|
|
21
|
+
- **摸高的沙箱自带的工具很少**(例如没有 mvn、gradle),机器每个对话轮次都是新的,只有工作区保留。项目要用、沙箱里没有的工具,装到 `/data/workspace/.laoshi/tools/<工具>`(例如解压 Maven 到 `/data/workspace/.laoshi/tools/maven`,本地仓库设为 `/data/workspace/.laoshi/tools/m2`),命令里写工具的完整路径(例如 `/data/workspace/.laoshi/tools/maven/bin/mvn -Dmaven.repo.local=/data/workspace/.laoshi/tools/m2 test`);`verify.md` 和 `.laoshi/services.json` 里的命令也这样写,因为每次执行时 `PATH` 都会重置。
|
|
@@ -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
|
+
}
|