@uncarved/jade 0.3.0 → 0.4.0
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/README.md +1 -0
- package/dist/api.d.ts +1 -1
- package/dist/api.js +1 -1
- package/dist/host.d.ts +2 -0
- package/dist/host.js +39 -5
- package/dist/host.js.map +1 -1
- package/dist/remote.js +5 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +7 -0
- package/dist/session.js +482 -27
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +49 -24
- package/plugins/approval/policy.ts +48 -25
- package/plugins/approval/review.ts +9 -5
- package/plugins/checks/checks.ts +10 -7
- package/plugins/checks/index.ts +13 -13
- package/plugins/checks/plugin.json +1 -1
- package/plugins/checks/project.ts +37 -38
- package/plugins/commands/index.ts +27 -3
- package/plugins/compact/compact.ts +13 -5
- package/plugins/compact/index.ts +20 -3
- package/plugins/compact/style.ts +13 -14
- package/plugins/completions/index.ts +35 -0
- package/plugins/completions/plugin.json +7 -0
- package/plugins/copy/index.ts +46 -0
- package/plugins/copy/plugin.json +7 -0
- package/plugins/editor/index.ts +10 -4
- package/plugins/fs/diff.ts +7 -6
- package/plugins/fs/fs.ts +8 -4
- package/plugins/fs/grep.ts +55 -12
- package/plugins/fs/index.ts +2 -7
- package/plugins/fs/plugin.json +1 -1
- package/plugins/fs/renderers.ts +16 -15
- package/plugins/fs/style.ts +16 -15
- package/plugins/hooks/index.ts +3 -2
- package/plugins/keys/index.ts +5 -1
- package/plugins/mcp/index.ts +197 -78
- package/plugins/mcp/install.ts +5 -3
- package/plugins/mcp/mcp.ts +163 -11
- package/plugins/mcp/plugin.json +2 -1
- package/plugins/mcp/project.ts +47 -50
- package/plugins/memory/index.ts +4 -4
- package/plugins/memory/style.ts +13 -14
- package/plugins/mentions/candidates.ts +67 -0
- package/plugins/mentions/index.ts +12 -5
- package/plugins/mentions/plugin.json +1 -1
- package/plugins/mentions/style.ts +13 -14
- package/plugins/models/configure.ts +10 -9
- package/plugins/models/index.ts +31 -4
- package/plugins/models/provider.ts +12 -1
- package/plugins/modes/index.ts +13 -2
- package/plugins/print/index.ts +7 -4
- package/plugins/prompts/index.ts +0 -0
- package/plugins/renderers/index.ts +10 -5
- package/plugins/repeats/index.ts +39 -9
- package/plugins/schedule/index.ts +2 -0
- package/plugins/screenshot/browser.ts +231 -0
- package/plugins/screenshot/index.ts +3 -2
- package/plugins/screenshot/tool.ts +27 -51
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +75 -22
- package/plugins/shell/plugin.json +1 -2
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +93 -34
- package/plugins/skills/index.ts +28 -19
- package/plugins/skills/project.ts +12 -7
- package/plugins/steer/index.ts +5 -4
- package/plugins/task/index.ts +81 -81
- package/plugins/task/plugin.json +5 -2
- package/plugins/task/style.ts +13 -14
- package/plugins/task/subagent.ts +67 -184
- package/plugins/todo/index.ts +39 -9
- package/plugins/tools/index.ts +57 -0
- package/plugins/tools/plugin.json +7 -0
- package/plugins/tui/frontend.ts +161 -87
- package/plugins/tui/index.ts +2 -3
- package/plugins/tui/mascot.ts +8 -7
- package/plugins/tui/mentions.ts +11 -80
- package/plugins/tui/plugin.json +1 -1
- package/plugins/tui/screen.ts +55 -5
- package/plugins/tui/transcript.ts +17 -7
- package/plugins/tui/tui.ts +356 -104
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +5 -3
- package/plugins/undo/index.ts +43 -14
- package/plugins/undo/style.ts +13 -14
- package/plugins/web/index.ts +7 -18
- package/plugins/web/plugin.json +1 -1
- package/plugins-dist/approval/index.js +363 -414
- package/plugins-dist/approval/policy.js +395 -497
- package/plugins-dist/approval/review.js +132 -158
- package/plugins-dist/approval/schema.js +50 -55
- package/plugins-dist/ask/index.js +115 -129
- package/plugins-dist/budget/index.js +27 -31
- package/plugins-dist/checks/checks.js +293 -329
- package/plugins-dist/checks/index.js +119 -139
- package/plugins-dist/checks/plugin.json +2 -1
- package/plugins-dist/checks/project.js +57 -65
- package/plugins-dist/commands/index.js +47 -29
- package/plugins-dist/compact/compact.js +233 -249
- package/plugins-dist/compact/index.js +98 -95
- package/plugins-dist/compact/style.js +9 -14
- package/plugins-dist/completions/index.js +30 -0
- package/plugins-dist/completions/plugin.json +9 -0
- package/plugins-dist/continue/index.js +40 -52
- package/plugins-dist/copy/index.js +40 -0
- package/plugins-dist/copy/plugin.json +9 -0
- package/plugins-dist/cost/index.js +98 -115
- package/plugins-dist/custom-commands/index.js +55 -72
- package/plugins-dist/editor/index.js +64 -72
- package/plugins-dist/fs/diff.js +111 -124
- package/plugins-dist/fs/fs.js +426 -469
- package/plugins-dist/fs/grep.js +262 -244
- package/plugins-dist/fs/index.js +20 -34
- package/plugins-dist/fs/plugin.json +1 -2
- package/plugins-dist/fs/renderers.js +100 -112
- package/plugins-dist/fs/style.js +11 -15
- package/plugins-dist/fs/sys.js +31 -43
- package/plugins-dist/hooks/index.js +107 -127
- package/plugins-dist/keys/index.js +27 -31
- package/plugins-dist/mcp/index.js +271 -199
- package/plugins-dist/mcp/install.js +123 -137
- package/plugins-dist/mcp/mcp.js +638 -577
- package/plugins-dist/mcp/plugin.json +3 -1
- package/plugins-dist/mcp/project.js +98 -115
- package/plugins-dist/memory/index.js +83 -88
- package/plugins-dist/memory/memory.js +111 -128
- package/plugins-dist/memory/style.js +9 -14
- package/plugins-dist/mentions/attach.js +91 -99
- package/plugins-dist/mentions/candidates.js +49 -0
- package/plugins-dist/mentions/index.js +71 -81
- package/plugins-dist/mentions/plugin.json +2 -1
- package/plugins-dist/mentions/style.js +9 -14
- package/plugins-dist/models/config.js +29 -43
- package/plugins-dist/models/configure.js +392 -473
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -188
- package/plugins-dist/models/provider.js +243 -295
- package/plugins-dist/models/saved.js +59 -71
- package/plugins-dist/modes/index.js +138 -165
- package/plugins-dist/plugins/index.js +34 -34
- package/plugins-dist/print/index.js +192 -175
- package/plugins-dist/prompts/index.js +81 -89
- package/plugins-dist/prompts/notes.js +31 -37
- package/plugins-dist/prompts/prompts.js +155 -193
- package/plugins-dist/prompts/results.js +40 -53
- package/plugins-dist/prompts/sys.js +39 -50
- package/plugins-dist/renderers/index.js +32 -32
- package/plugins-dist/repeats/index.js +134 -151
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +229 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +169 -0
- package/plugins-dist/screenshot/index.js +37 -45
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +101 -151
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +117 -74
- package/plugins-dist/shell/plugin.json +1 -2
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +317 -320
- package/plugins-dist/shell/sys.js +64 -79
- package/plugins-dist/skills/index.js +193 -211
- package/plugins-dist/skills/install.js +122 -149
- package/plugins-dist/skills/project.js +65 -73
- package/plugins-dist/skills/skills.js +135 -171
- package/plugins-dist/steer/index.js +108 -125
- package/plugins-dist/suggest/index.js +235 -259
- package/plugins-dist/task/index.js +130 -148
- package/plugins-dist/task/plugin.json +5 -4
- package/plugins-dist/task/style.js +9 -14
- package/plugins-dist/task/subagent.js +156 -279
- package/plugins-dist/todo/index.js +79 -63
- package/plugins-dist/tools/index.js +43 -0
- package/plugins-dist/tools/plugin.json +9 -0
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +641 -655
- package/plugins-dist/tui/history.js +34 -37
- package/plugins-dist/tui/index.js +16 -18
- package/plugins-dist/tui/markdown.js +203 -247
- package/plugins-dist/tui/mascot.js +266 -353
- package/plugins-dist/tui/mentions.js +67 -144
- package/plugins-dist/tui/plugin.json +1 -2
- package/plugins-dist/tui/render.js +35 -45
- package/plugins-dist/tui/screen.js +197 -180
- package/plugins-dist/tui/transcript.js +436 -468
- package/plugins-dist/tui/tui.js +1554 -1645
- package/plugins-dist/tui/vendor.js +1388 -1088
- package/plugins-dist/undo/checkpoint.js +95 -118
- package/plugins-dist/undo/index.js +185 -192
- package/plugins-dist/undo/snapshot.js +83 -99
- package/plugins-dist/undo/style.js +9 -14
- package/plugins-dist/update/index.js +26 -28
- package/plugins-dist/web/env.js +55 -68
- package/plugins-dist/web/index.js +80 -110
- package/plugins-dist/web/plugin.json +1 -2
- package/plugins-dist/web/renderers.js +4 -5
- package/plugins-dist/web/web.js +514 -593
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +9 -2
- package/src/api.ts +1 -1
- package/src/host.ts +39 -4
- package/src/remote.ts +6 -1
- package/src/session.ts +489 -34
|
@@ -1,150 +1,130 @@
|
|
|
1
|
-
// jade/checks:模型改了文件之后,下一次请求模型之前对改过的文件跑项目的检查(类型检查、lint),
|
|
2
|
-
// 把发现的问题附在这批修改的最后一个结果后面(见 checks.ts);/checks 查看、开关;对话里显示检查的结果。
|
|
3
|
-
//
|
|
4
|
-
// 检查在本轮之内、下一次请求模型之前(context.project)运行,不放到 session.afterTurn:模型要在同一轮里看到
|
|
5
|
-
// 自己刚引入的错误并改掉;轮次结束后才检查就得再发起一轮(session.send),等于替用户多说一句话。
|
|
6
|
-
//
|
|
7
|
-
// 检查会执行仓库里的代码(node_modules 里的 tsc、.jade/checks.json 里的命令),每条命令第一次运行前请用户确认,
|
|
8
|
-
// 记在 $JADE_HOME/trust.jsonl(和旧 jade 同一个文件、同一种记录,旧 jade 里确认过的不用再确认)。
|
|
9
|
-
// yolo 模式不问;不能提问时不运行没确认过的命令。
|
|
10
1
|
import { createHash } from "node:crypto";
|
|
11
2
|
import path from "node:path";
|
|
12
3
|
import { definePlugin } from "@uncarved/jade-api";
|
|
13
4
|
import { changedFiles, checks } from "./checks.js";
|
|
14
|
-
import { bold, dim, display, realPath, repoRoot,
|
|
15
|
-
|
|
16
|
-
const checkHash = (c) => createHash("sha256").update(`jade-check\0${c.cwd}\0${c.command}`).digest("hex");
|
|
17
|
-
/** 展开后最多显示的行数 */
|
|
5
|
+
import { bold, dim, display, lines as joinLines, realPath, repoRoot, warn, withLegacyTrust } from "./project.js";
|
|
6
|
+
const checkHash = (c) => createHash("sha256").update(`jade-check\x00${c.cwd}\x00${c.command}`).digest("hex");
|
|
18
7
|
const MAX_DETAIL_LINES = 40;
|
|
19
|
-
|
|
20
|
-
const bySession = new Map();
|
|
21
|
-
/** process() 里准备好、session() 里调用:用进程级的确认记录和"一次只问一个问题" */
|
|
8
|
+
const bySession = new Map;
|
|
22
9
|
let sessionSetup;
|
|
23
10
|
export const checksRenderers = [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
.filter(Boolean)
|
|
40
|
-
.join(", ")}`);
|
|
41
|
-
return withDetails(yellow(`⚠ checks: ${what.join("; ")}`));
|
|
42
|
-
},
|
|
43
|
-
},
|
|
11
|
+
{
|
|
12
|
+
event: "checked",
|
|
13
|
+
render: (data) => {
|
|
14
|
+
const d = data;
|
|
15
|
+
const bad = d.summary.filter((s) => s.problems > 0 || s.others || s.failed);
|
|
16
|
+
const lines = d.report ? d.report.split(`
|
|
17
|
+
`).slice(1) : [];
|
|
18
|
+
const details = lines.length ? joinLines([...lines.slice(0, MAX_DETAIL_LINES), ...lines.length > MAX_DETAIL_LINES ? [dim(`… ${lines.length - MAX_DETAIL_LINES} more lines`)] : []]) : undefined;
|
|
19
|
+
const withDetails = (line) => details ? { line, details } : { line };
|
|
20
|
+
if (bad.length === 0)
|
|
21
|
+
return withDetails(dim(`✓ checks passed: ${d.summary.map((s) => s.name).join(", ")}`));
|
|
22
|
+
const what = bad.map((s) => s.failed ? `${s.name} ${s.failed}` : `${s.name}: ${[s.problems > 0 ? `${s.problems} problem${s.problems > 1 ? "s" : ""} in changed files` : "", s.others ? `${s.others} new elsewhere` : ""].filter(Boolean).join(", ")}`);
|
|
23
|
+
return withDetails(warn(`⚠ checks: ${what.join("; ")}`));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
44
26
|
];
|
|
45
27
|
export default definePlugin({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
28
|
+
process(ctx) {
|
|
29
|
+
const off = ctx.config.enabled === false || process.env.JADE_CHECKS === "off";
|
|
30
|
+
const trust = withLegacyTrust(ctx.require("trust@1"), ctx.home);
|
|
31
|
+
const renderers = ctx.service("renderers@1");
|
|
32
|
+
if (renderers)
|
|
33
|
+
for (const r of checksRenderers)
|
|
34
|
+
renderers.event(r);
|
|
35
|
+
ctx.service("commands@1")?.register({
|
|
36
|
+
name: "checks",
|
|
37
|
+
args: "[on|off]",
|
|
38
|
+
description: "checks jade runs after the agent edits files (type checker, linter)",
|
|
39
|
+
instant: true,
|
|
40
|
+
async run(args, c) {
|
|
41
|
+
const session = c.sessions.current;
|
|
42
|
+
const checks = session && bySession.get(session.id);
|
|
43
|
+
if (!checks) {
|
|
44
|
+
if (off)
|
|
45
|
+
return dim(`Edit-time checks are turned off${process.env.JADE_CHECKS === "off" ? " by JADE_CHECKS=off" : ` ({"jade/checks": {"enabled": false}} in ${path.join(ctx.home, "config.json")})`}.`);
|
|
46
|
+
return dim(unavailable ?? "Edit-time checks are not available in this session.");
|
|
47
|
+
}
|
|
48
|
+
const arg = args.trim();
|
|
49
|
+
if (arg === "on" || arg === "off") {
|
|
50
|
+
checks.enabled = arg === "on";
|
|
51
|
+
if (arg === "on")
|
|
52
|
+
checks.reset();
|
|
53
|
+
return `checks: ${arg}`;
|
|
54
|
+
}
|
|
55
|
+
if (arg)
|
|
56
|
+
return warn("usage: /checks [on|off]");
|
|
57
|
+
const files = changedFiles(session.state.messages, realPath(ctx.cwd), (t) => session.tool(t)?.meta?.writes);
|
|
58
|
+
const found = await checks.resolve(files);
|
|
59
|
+
const lines = [`Edit-time checks are ${checks.enabled ? "on" : "off"} in this session.`];
|
|
60
|
+
if (found.length > 0) {
|
|
61
|
+
lines.push("For the files changed in this session:");
|
|
62
|
+
for (const check of found) {
|
|
63
|
+
const pending = await trust.has(checkHash(check)) ? "" : ", not confirmed yet";
|
|
64
|
+
lines.push([" ", bold(check.name), " ", dim(`in ${display(ctx.cwd, check.cwd) || "."}${pending}`), `
|
|
65
|
+
`, dim(check.command)]);
|
|
66
|
+
}
|
|
67
|
+
} else
|
|
68
|
+
lines.push(dim(files.length ? "No checks apply to the files changed in this session." : "No files changed in this session yet."));
|
|
69
|
+
lines.push(dim(`Detected per file: TypeScript (nearest tsconfig.json + the project's typescript), Python (ruff), Go (go vet).
|
|
70
|
+
` + `Add your own in .jade/checks.json or ${path.join(ctx.home, "checks.json")}; JADE_CHECKS=off turns them off.`));
|
|
71
|
+
return joinLines(lines);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
let unavailable;
|
|
75
|
+
let asking = Promise.resolve();
|
|
76
|
+
sessionSetup = async (s) => {
|
|
77
|
+
if (off)
|
|
78
|
+
return;
|
|
79
|
+
const shell = s.require("shell@1");
|
|
80
|
+
if (!shell.executable) {
|
|
81
|
+
unavailable = `edit-time checks are off: ${shell.unavailable ?? "no shell was found"}`;
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const ui = s.service("ui@1");
|
|
85
|
+
const approve = async (check, signal) => {
|
|
86
|
+
const hash = checkHash(check);
|
|
87
|
+
if (await trust.has(hash))
|
|
88
|
+
return true;
|
|
89
|
+
if (s.service("approval@1")?.mode() === "yolo")
|
|
90
|
+
return true;
|
|
91
|
+
if (!ui?.interactive)
|
|
92
|
+
return false;
|
|
93
|
+
const turn = asking.then(async () => {
|
|
94
|
+
if (await trust.has(hash))
|
|
95
|
+
return true;
|
|
96
|
+
signal.throwIfAborted();
|
|
97
|
+
const answer = await ui.select({
|
|
98
|
+
title: `Run ${check.name} after the agent edits files, and show it the problems found?`,
|
|
99
|
+
detail: `${check.command}
|
|
100
|
+
in ${display(s.cwd, check.cwd) || "."}${check.source === "config" ? " (from checks.json)" : " (detected)"}`,
|
|
101
|
+
options: [
|
|
102
|
+
{ label: "Yes, in this project from now on", value: "yes" },
|
|
103
|
+
{ label: "No, not in this session", value: "no" }
|
|
104
|
+
]
|
|
105
|
+
}, signal);
|
|
106
|
+
if (answer === "yes") {
|
|
107
|
+
await trust.add(hash, check.cwd);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
ui.notify(`${check.name} will not run in this session; /checks on to ask again`);
|
|
111
|
+
return false;
|
|
91
112
|
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return true;
|
|
110
|
-
if (s.service("approval@1")?.mode() === "yolo")
|
|
111
|
-
return true;
|
|
112
|
-
if (!ui?.interactive)
|
|
113
|
-
return false;
|
|
114
|
-
const turn = asking.then(async () => {
|
|
115
|
-
if (await trust.has(hash))
|
|
116
|
-
return true;
|
|
117
|
-
signal.throwIfAborted();
|
|
118
|
-
const answer = await ui.select({
|
|
119
|
-
title: `Run ${check.name} after the agent edits files, and show it the problems found?`,
|
|
120
|
-
detail: `${check.command}\nin ${display(s.cwd, check.cwd) || "."}${check.source === "config" ? " (from checks.json)" : " (detected)"}`,
|
|
121
|
-
options: [
|
|
122
|
-
{ label: "Yes, in this project from now on", value: "yes" },
|
|
123
|
-
{ label: "No, not in this session", value: "no" },
|
|
124
|
-
],
|
|
125
|
-
}, signal);
|
|
126
|
-
if (answer === "yes") {
|
|
127
|
-
await trust.add(hash, check.cwd);
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
ui.notify(`${check.name} will not run in this session; /checks on to ask again`);
|
|
131
|
-
return false;
|
|
132
|
-
});
|
|
133
|
-
asking = turn.catch(() => { });
|
|
134
|
-
return turn;
|
|
135
|
-
};
|
|
136
|
-
const cwd = realPath(s.cwd);
|
|
137
|
-
const c = checks({ cwd, root: realPath(repoRoot(cwd)), home: s.home, run: shell.run, which: (bin) => shell.which(bin) ?? null, approve });
|
|
138
|
-
const id = s.session.id;
|
|
139
|
-
bySession.set(id, c);
|
|
140
|
-
await s.effect(() => () => {
|
|
141
|
-
if (bySession.get(id) === c)
|
|
142
|
-
bySession.delete(id);
|
|
143
|
-
});
|
|
144
|
-
s.kernel.hook(c.hook);
|
|
145
|
-
};
|
|
146
|
-
},
|
|
147
|
-
async session(ctx) {
|
|
148
|
-
await sessionSetup?.(ctx);
|
|
149
|
-
},
|
|
113
|
+
asking = turn.catch(() => {});
|
|
114
|
+
return turn;
|
|
115
|
+
};
|
|
116
|
+
const cwd = realPath(s.cwd);
|
|
117
|
+
const c = checks({ cwd, root: realPath(repoRoot(cwd)), home: s.home, run: shell.run, which: (bin) => shell.which(bin) ?? null, approve, writes: (t) => s.session.tool(t)?.meta?.writes });
|
|
118
|
+
const id = s.session.id;
|
|
119
|
+
bySession.set(id, c);
|
|
120
|
+
await s.effect(() => () => {
|
|
121
|
+
if (bySession.get(id) === c)
|
|
122
|
+
bySession.delete(id);
|
|
123
|
+
});
|
|
124
|
+
s.kernel.hook(c.hook);
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
async session(ctx) {
|
|
128
|
+
await sessionSetup?.(ctx);
|
|
129
|
+
}
|
|
150
130
|
});
|
|
@@ -1,76 +1,68 @@
|
|
|
1
|
-
// 仓库目录、确认记录、显示用的小工具。插件之间不共享代码(只能共享类型),jade/mcp、jade/skills 各有一份。
|
|
2
1
|
import { existsSync, realpathSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
4
3
|
import path from "node:path";
|
|
5
4
|
export function realPath(p) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
5
|
+
try {
|
|
6
|
+
return realpathSync.native(p);
|
|
7
|
+
} catch {
|
|
8
|
+
return path.resolve(p);
|
|
9
|
+
}
|
|
12
10
|
}
|
|
13
|
-
/** git 仓库的根目录(往上找 .git,目录或文件都算);不在仓库里时是 cwd 本身 */
|
|
14
11
|
export function repoRoot(cwd) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
let d = path.resolve(cwd);
|
|
13
|
+
for (;; ) {
|
|
14
|
+
if (existsSync(path.join(d, ".git")))
|
|
15
|
+
return d;
|
|
16
|
+
const parent = path.dirname(d);
|
|
17
|
+
if (parent === d)
|
|
18
|
+
return path.resolve(cwd);
|
|
19
|
+
d = parent;
|
|
20
|
+
}
|
|
24
21
|
}
|
|
25
|
-
/** 工作目录里的显示成相对路径,外面的显示绝对路径 */
|
|
26
22
|
export function display(cwd, full) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
const rel = path.relative(cwd, full);
|
|
24
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
25
|
+
return shown.split(path.sep).join("/");
|
|
30
26
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return false;
|
|
50
|
-
}
|
|
51
|
-
for (const line of text.split("\n")) {
|
|
52
|
-
try {
|
|
53
|
-
if (JSON.parse(line).hash === hash) {
|
|
54
|
-
this.#known.add(hash);
|
|
55
|
-
return true;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
// 写到一半的行
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return false;
|
|
27
|
+
export const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
|
|
28
|
+
const styled = (style) => (text) => ({ text, style });
|
|
29
|
+
export const dim = styled("dim");
|
|
30
|
+
export const bold = styled("bold");
|
|
31
|
+
export const ok = styled("ok");
|
|
32
|
+
export const warn = styled("warn");
|
|
33
|
+
export const error = styled("error");
|
|
34
|
+
export const lines = (rows) => rows.flatMap((r, i) => i ? [`
|
|
35
|
+
`, r] : [r]);
|
|
36
|
+
export function withLegacyTrust(trust, home) {
|
|
37
|
+
let legacy;
|
|
38
|
+
const read = async () => {
|
|
39
|
+
const hashes = new Map;
|
|
40
|
+
let text = "";
|
|
41
|
+
try {
|
|
42
|
+
text = await readFile(path.join(home, "trust.jsonl"), "utf8");
|
|
43
|
+
} catch {
|
|
44
|
+
return hashes;
|
|
63
45
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
for (const line of text.split(`
|
|
47
|
+
`)) {
|
|
48
|
+
try {
|
|
49
|
+
const r = JSON.parse(line);
|
|
50
|
+
if (typeof r.hash === "string")
|
|
51
|
+
hashes.set(r.hash, typeof r.path === "string" ? r.path : "");
|
|
52
|
+
} catch {}
|
|
68
53
|
}
|
|
54
|
+
return hashes;
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
has: async (hash) => {
|
|
58
|
+
if (await trust.has(hash))
|
|
59
|
+
return true;
|
|
60
|
+
const where = (await (legacy ??= read())).get(hash);
|
|
61
|
+
if (where === undefined)
|
|
62
|
+
return false;
|
|
63
|
+
await trust.add(hash, where).catch(() => {});
|
|
64
|
+
return true;
|
|
65
|
+
},
|
|
66
|
+
add: (hash, where) => trust.add(hash, where)
|
|
67
|
+
};
|
|
69
68
|
}
|
|
70
|
-
export const clip = (s, n) => (s.length > n ? s.slice(0, n) + "…" : s);
|
|
71
|
-
// 设了 NO_COLOR(非空)或标准输出不是终端时不输出颜色,见 https://no-color.org
|
|
72
|
-
const colors = Boolean(process.stdout.isTTY) && !process.env.NO_COLOR;
|
|
73
|
-
const paint = (open, close) => (s) => colors ? `\x1b[${open}m${s.replaceAll(`\x1b[${close}m`, `\x1b[${close}m\x1b[${open}m`)}\x1b[${close}m` : s;
|
|
74
|
-
export const dim = paint("2", "22");
|
|
75
|
-
export const yellow = paint("33", "39");
|
|
76
|
-
export const bold = paint("1", "22");
|
|
@@ -1,33 +1,51 @@
|
|
|
1
|
-
// jade/commands:斜杠命令的注册表。只登记,不执行:前端解析输入、带着自己的上下文调用 run。
|
|
2
|
-
// 每个调用方一个实例,调用方关闭(停用、被隔离、换会话时的会话作用域)时它注册的命令自动撤销。
|
|
3
1
|
import { definePlugin } from "@uncarved/jade-api";
|
|
4
2
|
const NAME = /^[a-z0-9][a-z0-9_-]*$/i;
|
|
5
|
-
const registry = new Map
|
|
3
|
+
const registry = new Map;
|
|
4
|
+
const prefixes = new Map;
|
|
6
5
|
export default definePlugin({
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
6
|
+
process(ctx) {
|
|
7
|
+
ctx.provide("commands@1", (caller) => ({
|
|
8
|
+
register(command) {
|
|
9
|
+
if (typeof command?.name !== "string" || !NAME.test(command.name))
|
|
10
|
+
throw new Error(`invalid command name ${JSON.stringify(command?.name)}`);
|
|
11
|
+
if (typeof command.run !== "function")
|
|
12
|
+
throw new Error(`command /${command.name} has no run function`);
|
|
13
|
+
const key = command.name.toLowerCase();
|
|
14
|
+
const taken = registry.get(key);
|
|
15
|
+
if (taken) {
|
|
16
|
+
ctx.report(`/${command.name} from ${caller.plugin} was skipped: ${taken.plugin} already registered it`);
|
|
17
|
+
return () => {};
|
|
18
|
+
}
|
|
19
|
+
if (command.prefix !== undefined && (typeof command.prefix !== "string" || [...command.prefix].length !== 1 || /[\p{L}\p{N}\s/]/u.test(command.prefix))) {
|
|
20
|
+
throw new Error(`command /${command.name}: prefix must be one character that is not a letter, digit, space or "/"`);
|
|
21
|
+
}
|
|
22
|
+
let entry = { command, plugin: caller.plugin };
|
|
23
|
+
let prefix = command.prefix;
|
|
24
|
+
const owner = prefix === undefined ? undefined : prefixes.get(prefix);
|
|
25
|
+
if (prefix !== undefined && owner !== undefined) {
|
|
26
|
+
ctx.report(`the ${prefix} shortcut for /${command.name} from ${caller.plugin} was skipped: /${owner} already uses it`);
|
|
27
|
+
const { prefix: _, prefixHint: __, ...rest } = command;
|
|
28
|
+
entry = { command: rest, plugin: caller.plugin };
|
|
29
|
+
prefix = undefined;
|
|
30
|
+
}
|
|
31
|
+
registry.set(key, entry);
|
|
32
|
+
if (prefix !== undefined)
|
|
33
|
+
prefixes.set(prefix, key);
|
|
34
|
+
const revoke = () => {
|
|
35
|
+
if (registry.get(key) === entry)
|
|
36
|
+
registry.delete(key);
|
|
37
|
+
if (prefix !== undefined && prefixes.get(prefix) === key)
|
|
38
|
+
prefixes.delete(prefix);
|
|
39
|
+
};
|
|
40
|
+
caller.onDispose(revoke);
|
|
41
|
+
return revoke;
|
|
42
|
+
},
|
|
43
|
+
get: (name) => registry.get(name.toLowerCase()),
|
|
44
|
+
byPrefix: (prefix) => {
|
|
45
|
+
const name = prefixes.get(prefix);
|
|
46
|
+
return name === undefined ? undefined : registry.get(name);
|
|
47
|
+
},
|
|
48
|
+
list: () => [...registry.values()].map(({ command: c, plugin }) => ({ name: c.name, ...c.args ? { args: c.args } : {}, ...c.description ? { description: c.description } : {}, ...c.instant ? { instant: true } : {}, ...c.prefix ? { prefix: c.prefix } : {}, ...c.prefixHint ? { prefixHint: c.prefixHint } : {}, plugin })).sort((a, b) => a.name.localeCompare(b.name))
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
33
51
|
});
|