@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,145 +1,131 @@
|
|
|
1
|
-
// jade/ask:ask_user 工具。模型拿不准、而答案会改变它要做的事时,先问用户再动手。
|
|
2
|
-
//
|
|
3
|
-
// 每个问题给几个选项让用户选,也可以自己输入回答。对话框经 ui@1,不再由宿主私下传入。
|
|
4
|
-
// 前端不能提问(-p、非终端)时不提供这个工具,提示词里也就不会提到它(jade/prompts 按工具是否存在取舍)。
|
|
5
|
-
// 从旧 jade 的 tools/ask.ts 和 main.ts 的 askUser 移植。
|
|
6
1
|
import { definePlugin } from "@uncarved/jade-api";
|
|
7
2
|
const MAX_QUESTIONS = 4;
|
|
8
|
-
/** 选项的值是序号,"其他" 的值不会和它重复 */
|
|
9
3
|
const OTHER = "other";
|
|
10
4
|
export const DISMISSED = "The user dismissed the questions without answering. Do not ask again: proceed with your best judgment and state your assumptions, or end your turn.";
|
|
11
|
-
/** 回到上一个问题 */
|
|
12
5
|
const BACK = "back";
|
|
13
|
-
/**
|
|
14
|
-
* 用 ui@1 逐个问题让用户选一项,或者选"其他"自己输入。第二个问题起可以回到上一个问题改答案(已经答过的选项标着);
|
|
15
|
-
* 自己输入时取消回到这个问题的选项。选项对话框取消就算没有回答。signal 中止时抛出
|
|
16
|
-
*/
|
|
17
6
|
export function askVia(ui) {
|
|
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
|
-
};
|
|
7
|
+
return async (questions, signal) => {
|
|
8
|
+
if (!ui.interactive)
|
|
9
|
+
return;
|
|
10
|
+
const answers = [];
|
|
11
|
+
let i = 0;
|
|
12
|
+
while (i < questions.length) {
|
|
13
|
+
const q = questions[i];
|
|
14
|
+
const previous = answers[i];
|
|
15
|
+
const typed = previous !== undefined && !q.options.some((o) => o.label === previous) ? previous : undefined;
|
|
16
|
+
const hint = (description, chosen) => {
|
|
17
|
+
const text = [description, chosen ? "your answer" : undefined].filter(Boolean).join(" · ");
|
|
18
|
+
return text ? { hint: text } : {};
|
|
19
|
+
};
|
|
20
|
+
const title = questions.length > 1 ? `${q.question} (${i + 1}/${questions.length})` : q.question;
|
|
21
|
+
const choice = await ui.select({
|
|
22
|
+
title,
|
|
23
|
+
options: [
|
|
24
|
+
...q.options.map((o, k) => ({ label: o.label, value: String(k), ...hint(o.description, o.label === previous) })),
|
|
25
|
+
{ label: "Other (type your answer)", value: OTHER, ...typed ? { hint: `your answer: ${typed}` } : {} },
|
|
26
|
+
...i > 0 ? [{ label: "← Previous question", value: BACK }] : []
|
|
27
|
+
]
|
|
28
|
+
}, signal);
|
|
29
|
+
signal.throwIfAborted();
|
|
30
|
+
if (choice === undefined)
|
|
31
|
+
return;
|
|
32
|
+
if (choice === BACK) {
|
|
33
|
+
i--;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
const answer = choice === OTHER ? (await ui.input({ title: q.question, ...typed ? { initial: typed } : {} }, signal))?.trim() : q.options[Number(choice)]?.label;
|
|
37
|
+
signal.throwIfAborted();
|
|
38
|
+
if (!answer)
|
|
39
|
+
continue;
|
|
40
|
+
answers[i] = answer;
|
|
41
|
+
i++;
|
|
42
|
+
}
|
|
43
|
+
return answers;
|
|
44
|
+
};
|
|
57
45
|
}
|
|
58
46
|
export function askUserTool(ask) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
47
|
+
return {
|
|
48
|
+
name: "ask_user",
|
|
49
|
+
description: "Ask the user one to four questions and wait for the answers. Use it before starting work when the request is ambiguous in a way that changes what you would do " + "(scope, approach, a trade-off or preference only the user can decide). Do not ask about things you can find out from the code, docs or tools, " + "or that have a sensible default (pick it and say so). Each question offers 2-4 options; the user can also type their own answer. " + "Put your recommended option first.",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {
|
|
53
|
+
questions: {
|
|
54
|
+
type: "array",
|
|
55
|
+
items: {
|
|
66
56
|
type: "object",
|
|
67
57
|
properties: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
description: { type: "string", description: "What choosing it means, trade-offs" },
|
|
84
|
-
},
|
|
85
|
-
required: ["label"],
|
|
86
|
-
additionalProperties: false,
|
|
87
|
-
},
|
|
88
|
-
},
|
|
89
|
-
},
|
|
90
|
-
required: ["question", "options"],
|
|
91
|
-
additionalProperties: false,
|
|
92
|
-
},
|
|
93
|
-
},
|
|
58
|
+
question: { type: "string", description: "The complete question, ending with a question mark" },
|
|
59
|
+
label: { type: "string", description: "Optional short tag; not shown" },
|
|
60
|
+
header: { type: "string", description: "Optional short tag; not shown" },
|
|
61
|
+
options: {
|
|
62
|
+
type: "array",
|
|
63
|
+
items: {
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
label: { type: "string", description: "1-5 words" },
|
|
67
|
+
description: { type: "string", description: "What choosing it means, trade-offs" }
|
|
68
|
+
},
|
|
69
|
+
required: ["label"],
|
|
70
|
+
additionalProperties: false
|
|
71
|
+
}
|
|
72
|
+
}
|
|
94
73
|
},
|
|
95
|
-
required: ["
|
|
96
|
-
additionalProperties: false
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
74
|
+
required: ["question", "options"],
|
|
75
|
+
additionalProperties: false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
required: ["questions"],
|
|
80
|
+
additionalProperties: false
|
|
81
|
+
},
|
|
82
|
+
effect: "read",
|
|
83
|
+
concurrency: "exclusive",
|
|
84
|
+
idempotent: false,
|
|
85
|
+
async execute(input, ctx) {
|
|
86
|
+
const questions = input.questions;
|
|
87
|
+
if (!Array.isArray(questions) || questions.length === 0 || questions.length > MAX_QUESTIONS)
|
|
88
|
+
return { content: `questions must have 1-${MAX_QUESTIONS} items`, isError: true };
|
|
89
|
+
const bad = questions.find((q) => !Array.isArray(q?.options) || q.options.length < 2 || q.options.length > 4);
|
|
90
|
+
if (bad)
|
|
91
|
+
return { content: `each question needs 2-4 options ("${bad.question}" has ${Array.isArray(bad.options) ? bad.options.length : 0})`, isError: true };
|
|
92
|
+
const answers = await ask(questions, ctx.signal);
|
|
93
|
+
if (answers === undefined)
|
|
94
|
+
return { content: DISMISSED };
|
|
95
|
+
return { content: questions.map((q, i) => `Q: ${q.question}
|
|
96
|
+
A: ${answers[i] ?? "(no answer)"}`).join(`
|
|
97
|
+
|
|
98
|
+
`) };
|
|
99
|
+
}
|
|
100
|
+
};
|
|
115
101
|
}
|
|
116
|
-
const clip = (s, n) =>
|
|
117
|
-
const args = (input) =>
|
|
102
|
+
const clip = (s, n) => s.length > n ? s.slice(0, n) + "…" : s;
|
|
103
|
+
const args = (input) => input !== null && typeof input === "object" ? input : {};
|
|
118
104
|
export const askRenderer = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
105
|
+
tool: "ask_user",
|
|
106
|
+
summary: (input) => {
|
|
107
|
+
const q = args(input).questions;
|
|
108
|
+
return Array.isArray(q) && q.length === 1 ? clip(String(q[0]?.question ?? ""), 120) : `${Array.isArray(q) ? q.length : 0} questions`;
|
|
109
|
+
},
|
|
110
|
+
result: ({ text, isError }) => {
|
|
111
|
+
if (isError)
|
|
112
|
+
return;
|
|
113
|
+
if (text === DISMISSED)
|
|
114
|
+
return { line: "dismissed" };
|
|
115
|
+
const pairs = [...text.matchAll(/^Q: (.*)\nA: (.*)$/gm)].map((m) => ({ q: m[1], a: m[2] }));
|
|
116
|
+
if (!pairs.length)
|
|
117
|
+
return;
|
|
118
|
+
return { line: clip(pairs.map((p) => p.a).join(" · "), 200), ...pairs.length > 1 ? { details: pairs.map((p) => `${p.q} → ${p.a}`).join(`
|
|
119
|
+
`) } : {} };
|
|
120
|
+
}
|
|
135
121
|
};
|
|
136
122
|
export default definePlugin({
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
123
|
+
process(ctx) {
|
|
124
|
+
ctx.service("renderers@1")?.tool(askRenderer);
|
|
125
|
+
},
|
|
126
|
+
session(ctx) {
|
|
127
|
+
const ui = ctx.require("ui@1");
|
|
128
|
+
if (ui.interactive)
|
|
129
|
+
ctx.kernel.tool(askUserTool(askVia(ui)));
|
|
130
|
+
}
|
|
145
131
|
});
|
|
@@ -1,37 +1,33 @@
|
|
|
1
|
-
// jade/budget:一轮里模型回复的次数达到上限就停下(turn.continue 关卡拒绝,这一轮以 stopped 结束)。
|
|
2
|
-
// 从旧 jade 的 plugins/budget.ts 移植;上限来自配置 maxSteps。
|
|
3
1
|
import { definePlugin } from "@uncarved/jade-api";
|
|
4
2
|
const DEFAULT_STEPS = 100;
|
|
5
|
-
/** 本轮(最近一条用户输入之后)模型已经回复了几次 */
|
|
6
3
|
export function stepsThisTurn(s) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
let steps = 0;
|
|
5
|
+
for (let i = s.messages.length - 1;i >= 0; i--) {
|
|
6
|
+
const m = s.messages[i];
|
|
7
|
+
if (m.role === "assistant")
|
|
8
|
+
steps++;
|
|
9
|
+
else if (m.content.some((b) => b.kind !== "tool_result"))
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
return steps;
|
|
16
13
|
}
|
|
17
14
|
export default definePlugin({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
},
|
|
15
|
+
session(ctx) {
|
|
16
|
+
const raw = ctx.config.maxSteps;
|
|
17
|
+
let max = DEFAULT_STEPS;
|
|
18
|
+
if (typeof raw === "number" && Number.isInteger(raw) && raw > 0)
|
|
19
|
+
max = raw;
|
|
20
|
+
else if (raw !== undefined)
|
|
21
|
+
ctx.service("ui@1")?.notify(`jade/budget: maxSteps must be a positive integer, got ${JSON.stringify(raw)}; using ${DEFAULT_STEPS}`, "warning");
|
|
22
|
+
ctx.kernel.hook({
|
|
23
|
+
kind: "gate",
|
|
24
|
+
point: "turn.continue",
|
|
25
|
+
fn: async (s, hook) => {
|
|
26
|
+
if (stepsThisTurn(s) < max)
|
|
27
|
+
return { decision: "abstain" };
|
|
28
|
+
await hook.emit("notice", { text: `stopped after ${max} model responses in this turn (config maxSteps); send a message to continue`, level: "warning" });
|
|
29
|
+
return { decision: "deny" };
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
37
33
|
});
|