@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,131 +1,114 @@
|
|
|
1
|
-
// 仓库目录、确认记录、显示用的小工具、斜杠命令参数的切分、token 估算。插件之间不共享代码(只能共享类型),jade/skills、jade/checks 各有一份。
|
|
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 projectDirs(root, cwd) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
23
|
+
const rel = path.relative(root, cwd);
|
|
24
|
+
const inside = rel === "" || !(rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel));
|
|
25
|
+
if (!inside)
|
|
26
|
+
return [cwd];
|
|
27
|
+
const dirs = [root];
|
|
28
|
+
if (rel)
|
|
29
|
+
for (const seg of rel.split(path.sep))
|
|
30
|
+
dirs.push(path.join(dirs.at(-1), seg));
|
|
31
|
+
return dirs;
|
|
36
32
|
}
|
|
37
|
-
/** 工作目录里的显示成相对路径,外面的显示绝对路径 */
|
|
38
33
|
export function display(cwd, full) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* 用户确认过的东西(项目层的 MCP 服务),每行一条 { hash, path, at }。
|
|
45
|
-
* 和旧 jade 的 $JADE_HOME/trust.jsonl 同一个文件、同一种格式,旧 jade 里确认过的不用再确认
|
|
46
|
-
*/
|
|
47
|
-
export class TrustFile {
|
|
48
|
-
file;
|
|
49
|
-
#known = new Set();
|
|
50
|
-
constructor(file) {
|
|
51
|
-
this.file = file;
|
|
52
|
-
}
|
|
53
|
-
async has(hash) {
|
|
54
|
-
if (this.#known.has(hash))
|
|
55
|
-
return true;
|
|
56
|
-
let text = "";
|
|
57
|
-
try {
|
|
58
|
-
text = await readFile(this.file, "utf8");
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
for (const line of text.split("\n")) {
|
|
64
|
-
try {
|
|
65
|
-
if (JSON.parse(line).hash === hash) {
|
|
66
|
-
this.#known.add(hash);
|
|
67
|
-
return true;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
catch {
|
|
71
|
-
// 写到一半的行
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
async add(hash, where) {
|
|
77
|
-
await mkdir(path.dirname(this.file), { recursive: true });
|
|
78
|
-
await appendFile(this.file, `${JSON.stringify({ hash, path: where, at: new Date().toISOString() })}\n`);
|
|
79
|
-
this.#known.add(hash);
|
|
80
|
-
}
|
|
34
|
+
const rel = path.relative(cwd, full);
|
|
35
|
+
const shown = rel && rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel) ? rel : full;
|
|
36
|
+
return shown.split(path.sep).join("/");
|
|
81
37
|
}
|
|
82
|
-
export const clip = (s, n) =>
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const
|
|
86
|
-
export const
|
|
87
|
-
export const
|
|
88
|
-
export const
|
|
89
|
-
export const
|
|
90
|
-
|
|
91
|
-
/** 斜杠命令的参数按空白切开;"…" 或 '…' 里的空白不切(不处理反斜杠,Windows 路径照写) */
|
|
38
|
+
export const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
|
|
39
|
+
const styled = (style) => (text) => ({ text, style });
|
|
40
|
+
export const dim = styled("dim");
|
|
41
|
+
export const bold = styled("bold");
|
|
42
|
+
export const ok = styled("ok");
|
|
43
|
+
export const warn = styled("warn");
|
|
44
|
+
export const error = styled("error");
|
|
45
|
+
export const lines = (rows) => rows.flatMap((r, i) => i ? [`
|
|
46
|
+
`, r] : [r]);
|
|
92
47
|
export function splitArgs(text) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
else if (/\s/.test(ch)) {
|
|
109
|
-
if (started)
|
|
110
|
-
out.push(cur);
|
|
111
|
-
cur = "";
|
|
112
|
-
started = false;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
cur += ch;
|
|
116
|
-
started = true;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (quote)
|
|
120
|
-
throw new Error(`unclosed ${quote}`);
|
|
121
|
-
if (started)
|
|
48
|
+
const out = [];
|
|
49
|
+
let cur = "";
|
|
50
|
+
let started = false;
|
|
51
|
+
let quote;
|
|
52
|
+
for (const ch of text) {
|
|
53
|
+
if (quote) {
|
|
54
|
+
if (ch === quote)
|
|
55
|
+
quote = undefined;
|
|
56
|
+
else
|
|
57
|
+
cur += ch;
|
|
58
|
+
} else if (ch === '"' || ch === "'") {
|
|
59
|
+
quote = ch;
|
|
60
|
+
started = true;
|
|
61
|
+
} else if (/\s/.test(ch)) {
|
|
62
|
+
if (started)
|
|
122
63
|
out.push(cur);
|
|
123
|
-
|
|
64
|
+
cur = "";
|
|
65
|
+
started = false;
|
|
66
|
+
} else {
|
|
67
|
+
cur += ch;
|
|
68
|
+
started = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (quote)
|
|
72
|
+
throw new Error(`unclosed ${quote}`);
|
|
73
|
+
if (started)
|
|
74
|
+
out.push(cur);
|
|
75
|
+
return out;
|
|
124
76
|
}
|
|
125
|
-
/** 中日韩文字和全角符号:大约一个字一个 token(和 jade/compact 的估算一致) */
|
|
126
77
|
const WIDE = /[ -鿿가-豈--]/g;
|
|
127
|
-
/** 粗略估算一段文字发给模型时占多少 token:英文和代码约 4 个字符 1 个,中日韩文字每字约 1 个 */
|
|
128
78
|
export function estimateTokens(text) {
|
|
129
|
-
|
|
130
|
-
|
|
79
|
+
const wide = text.match(WIDE)?.length ?? 0;
|
|
80
|
+
return Math.ceil((text.length - wide) / 4 + wide);
|
|
81
|
+
}
|
|
82
|
+
export function withLegacyTrust(trust, home) {
|
|
83
|
+
let legacy;
|
|
84
|
+
const read = async () => {
|
|
85
|
+
const hashes = new Map;
|
|
86
|
+
let text = "";
|
|
87
|
+
try {
|
|
88
|
+
text = await readFile(path.join(home, "trust.jsonl"), "utf8");
|
|
89
|
+
} catch {
|
|
90
|
+
return hashes;
|
|
91
|
+
}
|
|
92
|
+
for (const line of text.split(`
|
|
93
|
+
`)) {
|
|
94
|
+
try {
|
|
95
|
+
const r = JSON.parse(line);
|
|
96
|
+
if (typeof r.hash === "string")
|
|
97
|
+
hashes.set(r.hash, typeof r.path === "string" ? r.path : "");
|
|
98
|
+
} catch {}
|
|
99
|
+
}
|
|
100
|
+
return hashes;
|
|
101
|
+
};
|
|
102
|
+
return {
|
|
103
|
+
has: async (hash) => {
|
|
104
|
+
if (await trust.has(hash))
|
|
105
|
+
return true;
|
|
106
|
+
const where = (await (legacy ??= read())).get(hash);
|
|
107
|
+
if (where === undefined)
|
|
108
|
+
return false;
|
|
109
|
+
await trust.add(hash, where).catch(() => {});
|
|
110
|
+
return true;
|
|
111
|
+
},
|
|
112
|
+
add: (hash, where) => trust.add(hash, where)
|
|
113
|
+
};
|
|
131
114
|
}
|
|
@@ -1,92 +1,87 @@
|
|
|
1
|
-
// jade/memory:跨会话的记忆(见 memory.ts)。memory 工具给模型增删,/memory 给用户查看和管理,
|
|
2
|
-
// 会话开始时经 prompts@1 把记忆放进系统提示词(会话中途的改动下一个会话才进提示词,这样提示缓存不失效;
|
|
3
|
-
// 用户在 /memory 里改了,下一次请求时附一条说明告诉模型)。
|
|
4
1
|
import { definePlugin } from "@uncarved/jade-api";
|
|
5
2
|
import { Memory, MEMORY_SCOPES, memoryTool, projectRoot } from "./memory.js";
|
|
6
|
-
import { clip, dim,
|
|
7
|
-
const args = (input) =>
|
|
3
|
+
import { clip, dim, error, ok as success } from "./style.js";
|
|
4
|
+
const args = (input) => input ?? {};
|
|
8
5
|
export default definePlugin({
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
ctx.service("prompts@1")?.add({ text });
|
|
91
|
-
},
|
|
6
|
+
process(ctx) {
|
|
7
|
+
const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
|
|
8
|
+
ctx.service("renderers@1")?.tool({
|
|
9
|
+
tool: "memory",
|
|
10
|
+
summary: (input) => {
|
|
11
|
+
const i = args(input);
|
|
12
|
+
return `${i.action} ${i.scope}: ${clip(String(i.text ?? ""), 120)}`;
|
|
13
|
+
},
|
|
14
|
+
preview: (input) => {
|
|
15
|
+
const i = args(input);
|
|
16
|
+
return [i.action === "remove" ? error("- ") : success("+ "), String(i.text ?? "")];
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
ctx.service("commands@1")?.register({
|
|
20
|
+
name: "memory",
|
|
21
|
+
args: "[text]",
|
|
22
|
+
description: "see and remove what jade remembers across sessions, or remember text",
|
|
23
|
+
instant: true,
|
|
24
|
+
async run(input, { ui, sessions, signal }) {
|
|
25
|
+
const note = (text) => {
|
|
26
|
+
const id = sessions.current?.id;
|
|
27
|
+
if (id)
|
|
28
|
+
ctx.service("prompts@1")?.note(id, text);
|
|
29
|
+
};
|
|
30
|
+
let text = input.trim();
|
|
31
|
+
if (!text) {
|
|
32
|
+
const entries = (await Promise.all(MEMORY_SCOPES.map(async (scope) => (await memory.list(scope)).map((t) => ({ scope, text: t }))))).flat();
|
|
33
|
+
if (!ui.interactive)
|
|
34
|
+
return entries.length ? entries.map((e) => `${e.scope}: ${e.text}`).join(`
|
|
35
|
+
`) : "jade does not remember anything yet";
|
|
36
|
+
const choice = await ui.select({
|
|
37
|
+
title: entries.length ? "Memory: choose an entry to remove it, or add one" : "jade does not remember anything yet",
|
|
38
|
+
detail: dim(`user (all projects): ${memory.files.user}
|
|
39
|
+
project: ${memory.files.project}`),
|
|
40
|
+
options: [{ label: "Add a memory…", value: "add" }, ...entries.map((e, i) => ({ label: e.text, value: String(i), hint: e.scope }))]
|
|
41
|
+
}, signal);
|
|
42
|
+
if (!choice)
|
|
43
|
+
return;
|
|
44
|
+
if (choice !== "add") {
|
|
45
|
+
const entry = entries[Number(choice)];
|
|
46
|
+
const ok = await ui.select({
|
|
47
|
+
title: `Remove this ${entry.scope} memory?`,
|
|
48
|
+
detail: entry.text,
|
|
49
|
+
options: [
|
|
50
|
+
{ label: "No", value: "no" },
|
|
51
|
+
{ label: "Yes, remove it", value: "yes" }
|
|
52
|
+
]
|
|
53
|
+
}, signal);
|
|
54
|
+
if (ok !== "yes")
|
|
55
|
+
return;
|
|
56
|
+
await memory.remove(entry.scope, entry.text);
|
|
57
|
+
note(`The user removed this ${entry.scope} memory, so stop following it: ${entry.text}`);
|
|
58
|
+
return success(`Removed from ${entry.scope} memory: ${entry.text}`);
|
|
59
|
+
}
|
|
60
|
+
text = await ui.input({ title: "What should jade remember?", placeholder: "e.g. Reply in Chinese; run tests with bun test" }, signal) ?? "";
|
|
61
|
+
if (!text.trim())
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const scope = ui.interactive ? await ui.select({
|
|
65
|
+
title: "Remember it for",
|
|
66
|
+
options: [
|
|
67
|
+
{ label: "All projects", value: "user", hint: "user memory" },
|
|
68
|
+
{ label: "This project only", value: "project", hint: "project memory" }
|
|
69
|
+
]
|
|
70
|
+
}, signal) : "user";
|
|
71
|
+
if (!scope)
|
|
72
|
+
return;
|
|
73
|
+
const added = await memory.add(scope, text);
|
|
74
|
+
if (added)
|
|
75
|
+
note(`The user saved a ${scope} memory; follow it from now on: ${text.replace(/\s+/g, " ").trim()}`);
|
|
76
|
+
return added ? success(`Saved to ${scope} memory.`) : dim(`The ${scope} memory already has this.`);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
async session(ctx) {
|
|
81
|
+
const memory = new Memory(ctx.home, projectRoot(ctx.cwd));
|
|
82
|
+
ctx.kernel.tool(memoryTool(memory));
|
|
83
|
+
const text = await memory.prompt();
|
|
84
|
+
if (text)
|
|
85
|
+
ctx.service("prompts@1")?.add({ text });
|
|
86
|
+
}
|
|
92
87
|
});
|