@uncarved/jade 0.2.0 → 0.3.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 +277 -0
- package/assets/logo.svg +1 -0
- package/bin/jade.js +15 -0
- package/dist/api.d.ts +5 -250
- package/dist/api.js +5 -7
- package/dist/api.js.map +1 -1
- package/dist/fetch.d.ts +8 -0
- package/dist/fetch.js +19 -17
- package/dist/fetch.js.map +1 -1
- package/dist/host.d.ts +12 -1
- package/dist/host.js +49 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/main.js +28 -5
- package/dist/main.js.map +1 -1
- package/dist/remote.js +4 -0
- package/dist/remote.js.map +1 -1
- package/dist/session.d.ts +2 -0
- package/dist/session.js +133 -13
- package/dist/session.js.map +1 -1
- package/dist/source.d.ts +2 -10
- package/dist/source.js.map +1 -1
- package/dist/update.d.ts +8 -20
- package/dist/update.js +12 -1
- package/dist/update.js.map +1 -1
- package/package.json +6 -4
- package/plugins/approval/index.ts +246 -84
- package/plugins/approval/plugin.json +5 -1
- package/plugins/approval/policy.ts +27 -6
- package/plugins/approval/review.ts +1 -1
- package/plugins/ask/index.ts +2 -2
- package/plugins/budget/index.ts +1 -1
- package/plugins/checks/checks.ts +3 -2
- package/plugins/checks/index.ts +2 -5
- package/plugins/commands/index.ts +2 -44
- package/plugins/compact/compact.ts +15 -4
- package/plugins/compact/index.ts +13 -16
- package/plugins/continue/index.ts +1 -1
- package/plugins/cost/index.ts +143 -0
- package/plugins/cost/plugin.json +13 -0
- package/plugins/custom-commands/index.ts +85 -0
- package/plugins/custom-commands/plugin.json +8 -0
- package/plugins/editor/index.ts +88 -0
- package/plugins/editor/plugin.json +17 -0
- package/plugins/fs/fs.ts +110 -17
- package/plugins/fs/grep.ts +41 -11
- package/plugins/fs/index.ts +9 -7
- package/plugins/fs/renderers.ts +1 -1
- package/plugins/hooks/index.ts +152 -0
- package/plugins/hooks/plugin.json +14 -0
- package/plugins/keys/index.ts +2 -18
- package/plugins/mcp/index.ts +40 -12
- package/plugins/mcp/install.ts +139 -0
- package/plugins/mcp/mcp.ts +2 -1
- package/plugins/mcp/plugin.json +1 -1
- package/plugins/mcp/project.ts +37 -1
- package/plugins/memory/index.ts +4 -9
- package/plugins/memory/plugin.json +1 -1
- package/plugins/mentions/index.ts +33 -13
- package/plugins/models/configure.ts +258 -150
- package/plugins/models/context.ts +2 -2
- package/plugins/models/index.ts +50 -42
- package/plugins/models/plugin.json +1 -1
- package/plugins/models/provider.ts +22 -4
- package/plugins/models/saved.ts +8 -4
- package/plugins/modes/index.ts +2 -17
- package/plugins/plugins/index.ts +2 -2
- package/plugins/print/index.ts +60 -12
- package/plugins/print/plugin.json +1 -0
- package/plugins/prompts/index.ts +50 -14
- package/plugins/{memory → prompts}/notes.ts +21 -9
- package/plugins/prompts/plugin.json +8 -2
- package/plugins/prompts/prompts.ts +14 -8
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +16 -4
- package/plugins/renderers/index.ts +2 -43
- package/plugins/repeats/index.ts +1 -1
- package/plugins/schedule/index.ts +2 -2
- package/plugins/scratch/index.ts +2 -3
- package/plugins/screenshot/index.ts +26 -13
- package/plugins/screenshot/plugin.json +1 -1
- package/plugins/sessions/index.ts +2 -17
- package/plugins/shell/index.ts +56 -6
- package/plugins/shell/plugin.json +3 -1
- package/plugins/shell/renderers.ts +1 -1
- package/plugins/shell/service.ts +2 -13
- package/plugins/shell/shell.ts +31 -16
- package/plugins/skills/index.ts +172 -37
- package/plugins/skills/install.ts +212 -0
- package/plugins/skills/plugin.json +3 -2
- package/plugins/skills/project.ts +38 -1
- package/plugins/skills/skills.ts +28 -9
- package/plugins/steer/index.ts +142 -0
- package/plugins/steer/plugin.json +8 -0
- package/plugins/suggest/index.ts +16 -11
- package/plugins/suggest/plugin.json +1 -1
- package/plugins/task/index.ts +8 -16
- package/plugins/task/plugin.json +9 -2
- package/plugins/task/subagent.ts +119 -15
- package/plugins/todo/index.ts +4 -4
- package/plugins/tui/editor.ts +10 -2
- package/plugins/tui/frontend.ts +130 -25
- package/plugins/tui/index.ts +3 -8
- package/plugins/tui/markdown.ts +51 -6
- package/plugins/tui/mascot.ts +505 -0
- package/plugins/tui/mentions.ts +48 -8
- package/plugins/tui/plugin.json +2 -2
- package/plugins/tui/screen.ts +6 -0
- package/plugins/tui/transcript.ts +22 -3
- package/plugins/tui/tui.ts +323 -95
- package/plugins/tui/vendor.ts +16 -0
- package/plugins/undo/checkpoint.ts +26 -2
- package/plugins/undo/index.ts +86 -24
- package/plugins/undo/plugin.json +8 -2
- package/plugins/undo/snapshot.ts +129 -0
- package/plugins/update/index.ts +11 -15
- package/plugins/update/plugin.json +2 -1
- package/plugins/web/index.ts +2 -5
- package/plugins/web/renderers.ts +1 -1
- package/plugins/web/web.ts +6 -5
- package/plugins-dist/approval/index.js +232 -50
- package/plugins-dist/approval/plugin.json +5 -1
- package/plugins-dist/approval/policy.js +27 -5
- package/plugins-dist/ask/index.js +1 -1
- package/plugins-dist/budget/index.js +1 -1
- package/plugins-dist/checks/checks.js +2 -1
- package/plugins-dist/checks/index.js +1 -1
- package/plugins-dist/commands/index.js +1 -1
- package/plugins-dist/compact/compact.js +13 -2
- package/plugins-dist/compact/index.js +12 -8
- package/plugins-dist/continue/index.js +1 -1
- package/plugins-dist/cost/index.js +135 -0
- package/plugins-dist/cost/plugin.json +16 -0
- package/plugins-dist/custom-commands/index.js +86 -0
- package/plugins-dist/custom-commands/plugin.json +12 -0
- package/plugins-dist/editor/index.js +89 -0
- package/plugins-dist/editor/plugin.json +21 -0
- package/plugins-dist/fs/fs.js +106 -17
- package/plugins-dist/fs/grep.js +40 -12
- package/plugins-dist/fs/index.js +8 -5
- package/plugins-dist/hooks/index.js +145 -0
- package/plugins-dist/hooks/plugin.json +19 -0
- package/plugins-dist/keys/index.js +1 -1
- package/plugins-dist/mcp/index.js +41 -9
- package/plugins-dist/mcp/install.js +160 -0
- package/plugins-dist/mcp/mcp.js +2 -1
- package/plugins-dist/mcp/plugin.json +2 -1
- package/plugins-dist/mcp/project.js +42 -1
- package/plugins-dist/memory/index.js +3 -5
- package/plugins-dist/memory/plugin.json +1 -1
- package/plugins-dist/mentions/index.js +29 -11
- package/plugins-dist/models/configure.js +252 -151
- package/plugins-dist/models/context.js +2 -2
- package/plugins-dist/models/index.js +53 -16
- package/plugins-dist/models/plugin.json +1 -1
- package/plugins-dist/models/provider.js +4 -2
- package/plugins-dist/models/saved.js +9 -4
- package/plugins-dist/modes/index.js +1 -1
- package/plugins-dist/plugins/index.js +1 -1
- package/plugins-dist/print/index.js +62 -9
- package/plugins-dist/print/plugin.json +3 -0
- package/plugins-dist/prompts/index.js +49 -2
- package/plugins-dist/{memory → prompts}/notes.js +10 -7
- package/plugins-dist/prompts/plugin.json +8 -2
- package/plugins-dist/prompts/prompts.js +13 -8
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +15 -3
- package/plugins-dist/renderers/index.js +1 -1
- package/plugins-dist/repeats/index.js +1 -1
- package/plugins-dist/schedule/index.js +1 -1
- package/plugins-dist/scratch/index.js +1 -1
- package/plugins-dist/screenshot/index.js +25 -11
- package/plugins-dist/screenshot/plugin.json +1 -1
- package/plugins-dist/sessions/index.js +1 -1
- package/plugins-dist/shell/index.js +55 -3
- package/plugins-dist/shell/plugin.json +3 -1
- package/plugins-dist/shell/shell.js +26 -8
- package/plugins-dist/skills/index.js +184 -35
- package/plugins-dist/skills/install.js +178 -0
- package/plugins-dist/skills/plugin.json +6 -2
- package/plugins-dist/skills/project.js +43 -1
- package/plugins-dist/skills/skills.js +27 -10
- package/plugins-dist/steer/index.js +135 -0
- package/plugins-dist/steer/plugin.json +12 -0
- package/plugins-dist/suggest/index.js +15 -9
- package/plugins-dist/suggest/plugin.json +1 -1
- package/plugins-dist/task/index.js +7 -4
- package/plugins-dist/task/plugin.json +10 -2
- package/plugins-dist/task/subagent.js +106 -15
- package/plugins-dist/todo/index.js +3 -3
- package/plugins-dist/tui/editor.js +7 -2
- package/plugins-dist/tui/frontend.js +135 -18
- package/plugins-dist/tui/index.js +2 -1
- package/plugins-dist/tui/markdown.js +48 -6
- package/plugins-dist/tui/mascot.js +439 -0
- package/plugins-dist/tui/mentions.js +44 -6
- package/plugins-dist/tui/plugin.json +3 -2
- package/plugins-dist/tui/screen.js +2 -0
- package/plugins-dist/tui/transcript.js +19 -2
- package/plugins-dist/tui/tui.js +303 -83
- package/plugins-dist/tui/vendor.js +13822 -0
- package/plugins-dist/undo/checkpoint.js +28 -1
- package/plugins-dist/undo/index.js +92 -22
- package/plugins-dist/undo/plugin.json +10 -3
- package/plugins-dist/undo/snapshot.js +111 -0
- package/plugins-dist/update/index.js +9 -10
- package/plugins-dist/update/plugin.json +4 -1
- package/plugins-dist/web/index.js +1 -1
- package/plugins-dist/web/web.js +6 -5
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +8 -0
- package/src/api.ts +7 -262
- package/src/fetch.ts +18 -16
- package/src/host.ts +49 -1
- package/src/index.ts +1 -1
- package/src/main.ts +25 -6
- package/src/remote.ts +2 -0
- package/src/session.ts +134 -15
- package/src/source.ts +2 -11
- package/src/update.ts +16 -10
- package/plugins/undo/notes.ts +0 -43
- package/plugins-dist/undo/notes.js +0 -36
package/plugins/models/index.ts
CHANGED
|
@@ -6,38 +6,13 @@
|
|
|
6
6
|
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import type { ModelRequest, ModelResponse, Provider } from "uncarved";
|
|
9
|
-
import { definePlugin, type UI } from "
|
|
10
|
-
import type { Commands } from "
|
|
9
|
+
import { definePlugin, type UI } from "@uncarved/jade-api";
|
|
10
|
+
import type { Commands, Models } from "@uncarved/jade-api/services";
|
|
11
11
|
import { contextWindow } from "./context.ts";
|
|
12
|
-
import { envWithFile, hasProvider } from "./config.ts";
|
|
12
|
+
import { envWithFile, hasProvider, parseTokens } from "./config.ts";
|
|
13
13
|
import { configurator } from "./configure.ts";
|
|
14
|
-
import { isBuiltinKind, listModels, MODEL_KEY, providerFromEnv, providerInfo, providerKind, RateGate, rpmFromEnv, visionFromEnv, withRetry } from "./provider.ts";
|
|
15
|
-
import { readSavedServices, type Env } from "./saved.ts";
|
|
16
|
-
|
|
17
|
-
/** models@1 */
|
|
18
|
-
export interface Models {
|
|
19
|
-
/** 当前配置的服务和模型;没有配置时 undefined。via 是给人看的服务说明,例如 "the Anthropic API" */
|
|
20
|
-
current(): {
|
|
21
|
-
kind: string;
|
|
22
|
-
model: string;
|
|
23
|
-
via: string;
|
|
24
|
-
/** 上下文窗口(token) */
|
|
25
|
-
contextWindow: number;
|
|
26
|
-
/** 模型能不能看图片(JADE_VISION;不设时按服务推断) */
|
|
27
|
-
vision: boolean;
|
|
28
|
-
} | undefined;
|
|
29
|
-
/**
|
|
30
|
-
* 完成一次请求,带重试和限速。默认用当前配置的模型(限速和会话共用);
|
|
31
|
-
* model 是 /model 保存过的模型名($JADE_HOME/models.json),用它和它自己的设置,找不到时报错
|
|
32
|
-
*/
|
|
33
|
-
complete(request: ModelRequest, options: { signal: AbortSignal; onDelta?: (delta: import("uncarved").Delta) => void; model?: string }): Promise<ModelResponse>;
|
|
34
|
-
/** 服务提供的模型列表;不支持或出错时为空 */
|
|
35
|
-
list(): Promise<string[]>;
|
|
36
|
-
/** /model 保存过的模型名(complete 的 model 能用的那些),最近用过的在前 */
|
|
37
|
-
saved?(): Promise<string[]>;
|
|
38
|
-
/** 配置换了(/model)时调用,返回取消订阅。前端用它更新状态栏 */
|
|
39
|
-
subscribe?(fn: () => void): () => void;
|
|
40
|
-
}
|
|
14
|
+
import { isBuiltinKind, listModels, MODEL_KEY, providerFromEnv, providerInfo, providerKind, RateGate, rpmFromEnv, visionFromEnv, withRetry, type RetriedResponse } from "./provider.ts";
|
|
15
|
+
import { MODEL_SETTINGS, readSavedServices, type Env } from "./saved.ts";
|
|
41
16
|
|
|
42
17
|
export default definePlugin({
|
|
43
18
|
async process(ctx) {
|
|
@@ -93,24 +68,32 @@ export default definePlugin({
|
|
|
93
68
|
|
|
94
69
|
/** 保存过的模型的 provider,按配置缓存:models.json 里的密钥或设置改了就另建一份 */
|
|
95
70
|
const savedProviders = new Map<string, Promise<Provider>>();
|
|
71
|
+
const cachedBuild = (snapshot: Env): Promise<Provider> => {
|
|
72
|
+
const key = JSON.stringify(snapshot);
|
|
73
|
+
const cached = savedProviders.get(key);
|
|
74
|
+
if (cached) return cached;
|
|
75
|
+
const p = build(snapshot);
|
|
76
|
+
savedProviders.set(key, p);
|
|
77
|
+
// 创建失败时下次重试
|
|
78
|
+
p.catch(() => savedProviders.delete(key));
|
|
79
|
+
return p;
|
|
80
|
+
};
|
|
96
81
|
const saved = async (name: string): Promise<Provider> => {
|
|
97
82
|
for (const s of await readSavedServices(modelsFile)) {
|
|
98
83
|
const m = s.models.find((x) => x.name === name);
|
|
99
84
|
const kind = providerKind(s.env);
|
|
100
85
|
if (!m || !isBuiltinKind(kind)) continue;
|
|
101
|
-
|
|
102
|
-
const key = JSON.stringify(snapshot);
|
|
103
|
-
const cached = savedProviders.get(key);
|
|
104
|
-
if (cached) return cached;
|
|
105
|
-
const p = build(snapshot);
|
|
106
|
-
savedProviders.set(key, p);
|
|
107
|
-
// 创建失败时下次重试
|
|
108
|
-
p.catch(() => savedProviders.delete(key));
|
|
109
|
-
return p;
|
|
86
|
+
return cachedBuild({ ...s.env, ...m.settings, JADE_PROVIDER: kind, [MODEL_KEY[kind]]: m.name });
|
|
110
87
|
}
|
|
88
|
+
if (!hasProvider(env)) throw notConfigured();
|
|
111
89
|
// 只写在 .env 里、没保存过的当前模型
|
|
112
|
-
if (
|
|
113
|
-
|
|
90
|
+
if (providerInfo(env).model === name) return provider();
|
|
91
|
+
// 当前服务上的另一个模型(没保存过):用这个服务的地址和密钥,不带当前模型自己的设置,用服务的默认值
|
|
92
|
+
const kind = providerKind(env);
|
|
93
|
+
if (!isBuiltinKind(kind)) throw new Error(`model ${JSON.stringify(name)} is not one of the models saved by /model (${modelsFile})`);
|
|
94
|
+
const snapshot: Env = { ...env, JADE_PROVIDER: kind, [MODEL_KEY[kind]]: name };
|
|
95
|
+
for (const k of MODEL_SETTINGS) delete snapshot[k];
|
|
96
|
+
return cachedBuild(snapshot);
|
|
114
97
|
};
|
|
115
98
|
|
|
116
99
|
const current: Provider["complete"] = (request, options) => provider().then((p) => p.complete(request, options));
|
|
@@ -130,7 +113,20 @@ export default definePlugin({
|
|
|
130
113
|
// 写错的 JADE_VISION 在创建 provider 时报错,这里当作不能看
|
|
131
114
|
vision = false;
|
|
132
115
|
}
|
|
133
|
-
|
|
116
|
+
let maxTokens: number | undefined;
|
|
117
|
+
try {
|
|
118
|
+
maxTokens = env.JADE_MAX_TOKENS ? parseTokens("JADE_MAX_TOKENS", env.JADE_MAX_TOKENS) : undefined;
|
|
119
|
+
} catch {
|
|
120
|
+
// 写错的在创建 provider 时报错
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
kind: info.kind,
|
|
124
|
+
model: info.model,
|
|
125
|
+
via: via(info.kind, info.baseURL),
|
|
126
|
+
contextWindow: contextWindow(info.model, env),
|
|
127
|
+
vision,
|
|
128
|
+
...(maxTokens === undefined ? {} : { maxTokens }),
|
|
129
|
+
};
|
|
134
130
|
},
|
|
135
131
|
complete,
|
|
136
132
|
list: () => listModels(env),
|
|
@@ -180,6 +176,18 @@ export default definePlugin({
|
|
|
180
176
|
},
|
|
181
177
|
});
|
|
182
178
|
},
|
|
179
|
+
|
|
180
|
+
session(ctx) {
|
|
181
|
+
// 重试过的请求:把每次失败写进会话日志,事后能查到为什么慢、为什么重新输出(插件事件,不进上下文)
|
|
182
|
+
ctx.kernel.hook({
|
|
183
|
+
kind: "observe",
|
|
184
|
+
point: "model.after",
|
|
185
|
+
fn: async (res, hook) => {
|
|
186
|
+
const retries = (res as RetriedResponse).retries;
|
|
187
|
+
if (retries?.length) await hook.emit("retried", { retries });
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
},
|
|
183
191
|
});
|
|
184
192
|
|
|
185
193
|
function via(kind: string, baseURL: string | undefined): string {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Provider:按环境变量选择,外面包一层重试(4.7:重试是包装 Provider 的事)。
|
|
2
2
|
|
|
3
|
-
import { ProviderError, type Provider } from "uncarved";
|
|
3
|
+
import { ProviderError, type ModelResponse, type Provider } from "uncarved";
|
|
4
4
|
import { parseTokens } from "./config.ts";
|
|
5
5
|
|
|
6
6
|
/** 默认的重试等待:一次比一次久,最长 3 分钟 */
|
|
@@ -33,6 +33,22 @@ export const isRateLimit = (err: ProviderError) => err.status === 429 || /\b429\
|
|
|
33
33
|
*/
|
|
34
34
|
export const isConcurrencyLimit = (err: ProviderError) => /concurren/i.test(err.message);
|
|
35
35
|
|
|
36
|
+
/** 重试过的请求里每次失败的记录 */
|
|
37
|
+
export interface RetryRecord {
|
|
38
|
+
attempt: number;
|
|
39
|
+
delayMs: number;
|
|
40
|
+
error: string;
|
|
41
|
+
status?: number;
|
|
42
|
+
/** 失败前已经输出了一部分(界面上标了作废) */
|
|
43
|
+
discarded?: true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* withRetry 的回复:重试过时带上失败的记录。核心写日志时只取回复的 content、stopReason、usage,
|
|
48
|
+
* 这一项进不了上下文;jade/models 在 model.after 里把它写成插件事件
|
|
49
|
+
*/
|
|
50
|
+
export type RetriedResponse = ModelResponse & { retries?: RetryRecord[] };
|
|
51
|
+
|
|
36
52
|
export function withRetry(inner: Provider, opts: RetryOptions = {}): Provider {
|
|
37
53
|
const delays = opts.delaysMs ?? RETRY_DELAYS_MS;
|
|
38
54
|
const retries = opts.retries ?? delays.length;
|
|
@@ -40,7 +56,8 @@ export function withRetry(inner: Provider, opts: RetryOptions = {}): Provider {
|
|
|
40
56
|
const random = opts.random ?? Math.random;
|
|
41
57
|
return {
|
|
42
58
|
id: `retry(${inner.id})`,
|
|
43
|
-
async complete(request, options) {
|
|
59
|
+
async complete(request, options): Promise<RetriedResponse> {
|
|
60
|
+
const failures: RetryRecord[] = [];
|
|
44
61
|
for (let attempt = 1; ; attempt++) {
|
|
45
62
|
let streamed = false;
|
|
46
63
|
await opts.gate?.acquire(options.signal);
|
|
@@ -54,7 +71,7 @@ export function withRetry(inner: Provider, opts: RetryOptions = {}): Provider {
|
|
|
54
71
|
},
|
|
55
72
|
});
|
|
56
73
|
// 实际回复的是被包装者(4.7 第 3 款)
|
|
57
|
-
return { ...res, provider: res.provider ?? inner.id };
|
|
74
|
+
return { ...res, provider: res.provider ?? inner.id, ...(failures.length > 0 ? { retries: failures } : {}) };
|
|
58
75
|
} catch (err) {
|
|
59
76
|
if (!(err instanceof ProviderError) || !err.retryable || attempt > retries || options.signal.aborted) throw err;
|
|
60
77
|
// 在计划的时间上随机缩短最多 20%,并行的子 Agent 同时遇到 429 时不会同时重试。
|
|
@@ -66,6 +83,7 @@ export function withRetry(inner: Provider, opts: RetryOptions = {}): Provider {
|
|
|
66
83
|
if (isRateLimit(err)) opts.gate?.limited(delayMs, { learn: !isConcurrencyLimit(err) });
|
|
67
84
|
// 失败的这次已经推送过增量的,先让订阅者作废它们(4.7)
|
|
68
85
|
if (streamed) options.onDelta?.({ kind: "reset" });
|
|
86
|
+
failures.push({ attempt, delayMs, error: err.message, ...(err.status !== undefined ? { status: err.status } : {}), ...(streamed ? { discarded: true as const } : {}) });
|
|
69
87
|
opts.onRetry?.({ attempt, retries, delayMs, error: err });
|
|
70
88
|
await sleep(delayMs, options.signal);
|
|
71
89
|
}
|
|
@@ -351,7 +369,7 @@ export async function listModels(env: Env = process.env, fetchImpl: typeof fetch
|
|
|
351
369
|
}
|
|
352
370
|
}
|
|
353
371
|
|
|
354
|
-
function jsonObject(name: string, text: string): Record<string, unknown> {
|
|
372
|
+
export function jsonObject(name: string, text: string): Record<string, unknown> {
|
|
355
373
|
let value: unknown;
|
|
356
374
|
try {
|
|
357
375
|
value = JSON.parse(text);
|
package/plugins/models/saved.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// 保存过的模型:$JADE_HOME/models.json。同一个服务(类型、地址、密钥都相同)只存一份,下面是在它上面用过的模型,
|
|
2
|
-
//
|
|
2
|
+
// 每个模型带自己的设置(输出上限、思考力度、上下文窗口、openai-compat 的额外请求参数等)。.env 里始终是当前用的那一个,这里记着用过的全部,
|
|
3
3
|
// /model 可以切回去。
|
|
4
4
|
|
|
5
5
|
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
@@ -8,7 +8,7 @@ import path from "node:path";
|
|
|
8
8
|
export type Env = Record<string, string | undefined>;
|
|
9
9
|
|
|
10
10
|
/** 每个模型自己的设置:切换模型时一起换掉 */
|
|
11
|
-
export const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION"];
|
|
11
|
+
export const MODEL_SETTINGS = ["JADE_MAX_TOKENS", "JADE_EFFORT", "JADE_CONTEXT_WINDOW", "JADE_RPM", "JADE_VISION", "OPENAI_COMPAT_EXTRA_BODY"];
|
|
12
12
|
|
|
13
13
|
export interface SavedModel {
|
|
14
14
|
name: string;
|
|
@@ -34,11 +34,15 @@ export async function readSavedServices(file: string): Promise<SavedService[]> {
|
|
|
34
34
|
return data.services.flatMap((raw: unknown) => {
|
|
35
35
|
const s = raw as { env?: unknown; models?: unknown } | null;
|
|
36
36
|
if (!s || !Array.isArray(s.models)) return [];
|
|
37
|
+
// 以前额外请求参数存在服务上:分给它下面没有自己那份的模型
|
|
38
|
+
const { OPENAI_COMPAT_EXTRA_BODY: extraBody, ...env } = strings(s.env);
|
|
37
39
|
const models = s.models.flatMap((m: unknown) => {
|
|
38
40
|
const name = (m as { name?: unknown } | null)?.name;
|
|
39
|
-
|
|
41
|
+
const settings = strings((m as { settings?: unknown }).settings);
|
|
42
|
+
if (extraBody && settings.OPENAI_COMPAT_EXTRA_BODY === undefined) settings.OPENAI_COMPAT_EXTRA_BODY = extraBody;
|
|
43
|
+
return typeof name === "string" && name ? [{ name, settings }] : [];
|
|
40
44
|
});
|
|
41
|
-
return models.length ? [{ env
|
|
45
|
+
return models.length ? [{ env, models }] : [];
|
|
42
46
|
});
|
|
43
47
|
} catch {
|
|
44
48
|
return [];
|
package/plugins/modes/index.ts
CHANGED
|
@@ -10,23 +10,8 @@
|
|
|
10
10
|
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import type { Tool } from "uncarved";
|
|
13
|
-
import { definePlugin, type UI } from "
|
|
14
|
-
import type { Approval } from "
|
|
15
|
-
import type { Commands } from "../commands/index.ts";
|
|
16
|
-
import type { Keys } from "../keys/index.ts";
|
|
17
|
-
import type { Prompts } from "../prompts/index.ts";
|
|
18
|
-
|
|
19
|
-
/** modes@1 */
|
|
20
|
-
export interface Modes {
|
|
21
|
-
current(): string;
|
|
22
|
-
list(): { name: string; description: string }[];
|
|
23
|
-
/** 换模式,从下一个工具调用起生效 */
|
|
24
|
-
set(mode: string): void;
|
|
25
|
-
/** 换到轮换顺序里的下一个 */
|
|
26
|
-
cycle(): string;
|
|
27
|
-
/** 模式变化时调用,返回取消订阅的函数;调用方关闭时自动取消 */
|
|
28
|
-
subscribe(fn: (mode: string) => void): () => void;
|
|
29
|
-
}
|
|
13
|
+
import { definePlugin, type UI } from "@uncarved/jade-api";
|
|
14
|
+
import type { Approval, Commands, Keys, Modes, Prompts } from "@uncarved/jade-api/services";
|
|
30
15
|
|
|
31
16
|
export const DESCRIPTIONS: Record<string, string> = {
|
|
32
17
|
ask: "ask before edits and commands",
|
package/plugins/plugins/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// jade/plugins:/plugins 命令。列出这次启动里每个插件的状态和原因(failed、skipped、conflicted……),
|
|
2
2
|
// 以及每个服务由谁提供。数据来自核心自己的 jade@1 服务,和救援 CLI `jade plugins list` 是同一份状态。
|
|
3
3
|
|
|
4
|
-
import { definePlugin, type Jade } from "
|
|
5
|
-
import type { Commands } from "
|
|
4
|
+
import { definePlugin, type Jade } from "@uncarved/jade-api";
|
|
5
|
+
import type { Commands } from "@uncarved/jade-api/services";
|
|
6
6
|
|
|
7
7
|
export default definePlugin({
|
|
8
8
|
process(ctx) {
|
package/plugins/print/index.ts
CHANGED
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
// jade/print:jade -p "<prompt>" 跑一轮就退出。模型的回复写到 stdout,工具调用和提示写到 stderr。
|
|
2
2
|
// 不能向用户提问:ui@1 的 select 总是返回 undefined,要审批的调用由审批插件拒绝。
|
|
3
3
|
|
|
4
|
-
import type { Block, LogEvent, RuntimeNotice } from "uncarved";
|
|
5
|
-
import { definePlugin, type Frontend, type UI } from "
|
|
4
|
+
import type { Block, LogEvent, RuntimeNotice, Usage } from "uncarved";
|
|
5
|
+
import { definePlugin, type Frontend, type UI } from "@uncarved/jade-api";
|
|
6
|
+
import type { SessionIndex } from "@uncarved/jade-api/services";
|
|
6
7
|
|
|
7
|
-
const USAGE = `usage: jade -p <prompt> [--resume <session id>]
|
|
8
|
+
const USAGE = `usage: jade -p <prompt> [--resume <session id> | --continue] [--json]
|
|
8
9
|
echo <prompt> | jade -p
|
|
10
|
+
cat <file> | jade -p - <prompt>
|
|
11
|
+
|
|
12
|
+
With "-", what comes in on stdin is added after the prompt (without a prompt, stdin is the prompt).
|
|
9
13
|
|
|
10
14
|
Runs one prompt and exits. The reply goes to stdout; tool calls and notices go to stderr.
|
|
11
|
-
|
|
15
|
+
-c, --continue continues the most recent session in this directory.
|
|
16
|
+
--json prints one JSON object on stdout instead of the reply as it is written:
|
|
17
|
+
{"session", "result" (the final reply), "reason" (why the turn ended), "error"?, "usage"}
|
|
18
|
+
Exit code: 0 when the turn ends normally, 1 on an error, 130 when interrupted.
|
|
19
|
+
jade's own commands (plugins, update, --safe): jade help`;
|
|
12
20
|
|
|
13
21
|
const ui: UI = {
|
|
14
22
|
interactive: false,
|
|
@@ -19,6 +27,9 @@ const ui: UI = {
|
|
|
19
27
|
input: async () => undefined,
|
|
20
28
|
};
|
|
21
29
|
|
|
30
|
+
/** --continue 用:process() 里记下的工作目录和会话索引(jade/sessions 的 sessions@1,用到的时候取) */
|
|
31
|
+
let here: { cwd: string; index(): SessionIndex | undefined } | undefined;
|
|
32
|
+
|
|
22
33
|
const frontend: Frontend = {
|
|
23
34
|
async run({ argv, sessions }) {
|
|
24
35
|
const args = parse(argv);
|
|
@@ -30,16 +41,37 @@ const frontend: Frontend = {
|
|
|
30
41
|
process.stdout.write(`${USAGE}\n`);
|
|
31
42
|
return 0;
|
|
32
43
|
}
|
|
33
|
-
|
|
44
|
+
// 有 prompt 参数时只在写了 "-" 时读 stdin:脚本启动 jade -p 时 stdin 常是没人关的管道,默认去读会一直等下去
|
|
45
|
+
const piped = args.stdin || (args.prompt === undefined && !process.stdin.isTTY) ? (await readStdin()).trim() : "";
|
|
46
|
+
const prompt = [args.prompt, piped].filter(Boolean).join("\n\n");
|
|
34
47
|
if (!prompt) {
|
|
35
48
|
process.stderr.write(`no prompt given\n\n${USAGE}\n`);
|
|
36
49
|
return 2;
|
|
37
50
|
}
|
|
38
51
|
|
|
39
|
-
|
|
52
|
+
if (args.cont) {
|
|
53
|
+
const latest = (await here?.index()?.list(here.cwd))?.[0]?.id;
|
|
54
|
+
if (!latest) {
|
|
55
|
+
process.stderr.write("jade: there is no earlier session in this directory to continue\n");
|
|
56
|
+
return 2;
|
|
57
|
+
}
|
|
58
|
+
args.resume = latest;
|
|
59
|
+
}
|
|
60
|
+
let session: Awaited<ReturnType<typeof sessions.open>>;
|
|
61
|
+
try {
|
|
62
|
+
session = await sessions.open(args.resume ? { resume: args.resume } : {});
|
|
63
|
+
} catch (e) {
|
|
64
|
+
// 例如 --resume 的会话不存在:只说原因,不带插件名的包装
|
|
65
|
+
process.stderr.write(`jade: ${args.resume ? `could not resume ${args.resume}` : "could not start a session"}: ${errorText(e)}\n`);
|
|
66
|
+
return args.resume ? 2 : 1;
|
|
67
|
+
}
|
|
40
68
|
let ended: { reason: string; error?: string } | undefined;
|
|
41
69
|
let midLine = false;
|
|
70
|
+
/** --json:回复不边写边打印,最后一次回复的正文和用量合计在结束时一起输出 */
|
|
71
|
+
let result = "";
|
|
72
|
+
const used: Required<Usage> = { inputTokens: 0, outputTokens: 0, cacheReadTokens: 0, cacheWriteTokens: 0 };
|
|
42
73
|
const out = (text: string) => {
|
|
74
|
+
if (args.json) return;
|
|
43
75
|
process.stdout.write(text);
|
|
44
76
|
midLine = !text.endsWith("\n");
|
|
45
77
|
};
|
|
@@ -53,7 +85,10 @@ const frontend: Frontend = {
|
|
|
53
85
|
if (n.type !== "event") return;
|
|
54
86
|
const e = n.event as LogEvent;
|
|
55
87
|
if (e.type === "model.responded") {
|
|
56
|
-
const content =
|
|
88
|
+
const { content, usage } = e.data as { content: Block[]; usage?: Usage };
|
|
89
|
+
const text = content.flatMap((b) => (b.kind === "text" ? [b.text] : [])).join("\n");
|
|
90
|
+
if (text) result = text;
|
|
91
|
+
for (const k of Object.keys(used) as (keyof Usage)[]) used[k] += usage?.[k] ?? 0;
|
|
57
92
|
if (!streamed) for (const b of content) if (b.kind === "text") out(b.text);
|
|
58
93
|
streamed = false;
|
|
59
94
|
if (midLine) out("\n");
|
|
@@ -86,11 +121,13 @@ const frontend: Frontend = {
|
|
|
86
121
|
if (midLine) out("\n");
|
|
87
122
|
process.stderr.write(`session ${session.id}\n`);
|
|
88
123
|
const end = ended as { reason: string; error?: string } | undefined;
|
|
124
|
+
if (args.json) {
|
|
125
|
+
const error = failure !== undefined ? errorText(failure) : end?.error;
|
|
126
|
+
process.stdout.write(`${JSON.stringify({ session: session.id, result, reason: end?.reason ?? "error", ...(error ? { error } : {}), usage: used })}\n`);
|
|
127
|
+
}
|
|
89
128
|
if (end?.reason === "aborted") return 130;
|
|
90
129
|
if (failure !== undefined || end?.reason === "error") {
|
|
91
|
-
|
|
92
|
-
const cause = failure instanceof Error && failure.cause instanceof Error ? failure.cause : failure;
|
|
93
|
-
process.stderr.write(`error: ${cause instanceof Error ? cause.message : (end?.error ?? String(cause ?? "the turn failed"))}\n`);
|
|
130
|
+
process.stderr.write(`error: ${failure !== undefined ? errorText(failure) : (end?.error ?? "the turn failed")}\n`);
|
|
94
131
|
return 1;
|
|
95
132
|
}
|
|
96
133
|
return 0;
|
|
@@ -99,18 +136,22 @@ const frontend: Frontend = {
|
|
|
99
136
|
|
|
100
137
|
export default definePlugin({
|
|
101
138
|
process(ctx) {
|
|
139
|
+
here = { cwd: ctx.cwd, index: () => ctx.service<SessionIndex>("sessions@1") };
|
|
102
140
|
ctx.provide("ui@1", ui);
|
|
103
141
|
ctx.provide("frontend@1", frontend);
|
|
104
142
|
},
|
|
105
143
|
});
|
|
106
144
|
|
|
107
|
-
function parse(argv: readonly string[]): { prompt?: string; resume?: string; help?: boolean } | string {
|
|
108
|
-
const out: { prompt?: string; resume?: string; help?: boolean } = {};
|
|
145
|
+
function parse(argv: readonly string[]): { prompt?: string; resume?: string; cont?: boolean; json?: boolean; help?: boolean; stdin?: boolean } | string {
|
|
146
|
+
const out: { prompt?: string; resume?: string; cont?: boolean; json?: boolean; help?: boolean; stdin?: boolean } = {};
|
|
109
147
|
const words: string[] = [];
|
|
110
148
|
for (let i = 0; i < argv.length; i++) {
|
|
111
149
|
const a = argv[i]!;
|
|
112
150
|
if (a === "-p" || a === "--print") continue;
|
|
113
151
|
if (a === "-h" || a === "--help") out.help = true;
|
|
152
|
+
else if (a === "-") out.stdin = true;
|
|
153
|
+
else if (a === "-c" || a === "--continue") out.cont = true;
|
|
154
|
+
else if (a === "--json") out.json = true;
|
|
114
155
|
else if (a === "--resume") {
|
|
115
156
|
const id = argv[++i];
|
|
116
157
|
if (!id) return "--resume needs a session id";
|
|
@@ -118,6 +159,7 @@ function parse(argv: readonly string[]): { prompt?: string; resume?: string; hel
|
|
|
118
159
|
} else if (a.startsWith("-")) return `unknown option ${a}`;
|
|
119
160
|
else words.push(a);
|
|
120
161
|
}
|
|
162
|
+
if (out.cont && out.resume) return "--continue and --resume both pick the session; use one of them";
|
|
121
163
|
if (words.length > 0) out.prompt = words.join(" ");
|
|
122
164
|
return out;
|
|
123
165
|
}
|
|
@@ -136,6 +178,12 @@ function summary(input: unknown): string {
|
|
|
136
178
|
return line.length > 120 ? `${line.slice(0, 120)}…` : line;
|
|
137
179
|
}
|
|
138
180
|
|
|
181
|
+
/** 经过膜的错误包成了 PluginError,带着插件名;用户要看的是原因 */
|
|
182
|
+
function errorText(e: unknown): string {
|
|
183
|
+
const cause = e instanceof Error && e.cause instanceof Error ? e.cause : e;
|
|
184
|
+
return cause instanceof Error ? cause.message : String(cause);
|
|
185
|
+
}
|
|
186
|
+
|
|
139
187
|
function firstLine(content: Block[]): string {
|
|
140
188
|
const text = content.find((b) => b.kind === "text");
|
|
141
189
|
return text && "text" in text ? text.text.split("\n")[0]! : "(no message)";
|
package/plugins/prompts/index.ts
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
// jade/prompts:在 context.build 里生成系统提示词。其他插件经 prompts@1 往里加段落。
|
|
2
|
+
// 也负责内核不写的、给模型看的说明:内容为空的错误工具结果在投影里补一句原因(results.ts);
|
|
3
|
+
// 其他插件经 prompts@1 的 note 给模型留一句说明(notes.ts)。
|
|
2
4
|
|
|
5
|
+
import os from "node:os";
|
|
3
6
|
import path from "node:path";
|
|
4
|
-
import type { ContentSource, SystemSegment } from "uncarved";
|
|
5
|
-
import { definePlugin, type UI } from "
|
|
6
|
-
import type { Models } from "
|
|
7
|
+
import type { ContentSource, LogEvent, SystemSegment } from "uncarved";
|
|
8
|
+
import { definePlugin, type UI } from "@uncarved/jade-api";
|
|
9
|
+
import type { Models, PromptInstructions, Prompts } from "@uncarved/jade-api/services";
|
|
10
|
+
import { Notes } from "./notes.ts";
|
|
7
11
|
import { allInstructions, environment, mainPrompt, realPath } from "./prompts.ts";
|
|
8
|
-
|
|
9
|
-
/** prompts@1 */
|
|
10
|
-
export interface Prompts {
|
|
11
|
-
/**
|
|
12
|
-
* 往系统提示词里加一段,排在主体、环境信息和指令文件之后,返回撤销函数;调用方的作用域关闭时自动撤销。
|
|
13
|
-
* stable(默认 true)的段落排在 volatile 的前面:会变的段落放在后面,前面的才能命中提示缓存。
|
|
14
|
-
* 项目层插件加的段落标为不可信;untrusted 为 true 时也标为不可信(内容来自外部,例如 MCP 服务的说明、仓库里的 skill)
|
|
15
|
-
*/
|
|
16
|
-
add(section: { text: string; stable?: boolean; untrusted?: boolean }): () => void;
|
|
17
|
-
}
|
|
12
|
+
import { explainEmptyResults, whyEmpty, type Reasons, type Why } from "./results.ts";
|
|
18
13
|
|
|
19
14
|
interface Section {
|
|
20
15
|
plugin: string;
|
|
@@ -27,6 +22,10 @@ const ID = "jade/prompts";
|
|
|
27
22
|
|
|
28
23
|
/** 其他插件加的段落。模块每个进程只加载一次,进程级和会话级共用 */
|
|
29
24
|
const sections: Section[] = [];
|
|
25
|
+
/** 打开着的会话 → 它读到的指令文件(prompts@1.instructions) */
|
|
26
|
+
const loaded = new Map<string, PromptInstructions[]>();
|
|
27
|
+
/** 其他插件留给模型的说明 */
|
|
28
|
+
const notes = new Notes();
|
|
30
29
|
|
|
31
30
|
function segment(text: string, trust: SystemSegment["trust"] = "trusted", stability: SystemSegment["stability"] = "stable", by = ID, source?: ContentSource): SystemSegment {
|
|
32
31
|
return { text, stability, origin: { by: "plugin", id: by, ...(source ? { source } : {}) }, trust };
|
|
@@ -53,16 +52,53 @@ export default definePlugin({
|
|
|
53
52
|
caller.onDispose(remove);
|
|
54
53
|
return remove;
|
|
55
54
|
},
|
|
55
|
+
note(session, text) {
|
|
56
|
+
if (typeof session !== "string" || !session) throw new Error("prompts.note: session must be a session id");
|
|
57
|
+
if (typeof text !== "string" || !text) throw new Error("prompts.note: text must be a non-empty string");
|
|
58
|
+
notes.add(session, { plugin: caller.plugin, text, trusted: caller.layer !== "project" });
|
|
59
|
+
},
|
|
60
|
+
instructions: (session) => (loaded.get(session) ?? []).map((i) => ({ ...i, source: { ...i.source } })),
|
|
56
61
|
}));
|
|
57
62
|
},
|
|
58
63
|
|
|
59
64
|
async session(ctx) {
|
|
60
65
|
const models = ctx.service<Models>("models@1");
|
|
61
|
-
const [env, instructions] = await Promise.all([environment(ctx.cwd), allInstructions(ctx.home, ctx.cwd)]);
|
|
66
|
+
const [env, instructions] = await Promise.all([environment(ctx.cwd), allInstructions(ctx.home, ctx.cwd, ctx.config.claudeInstructions === false ? null : os.homedir())]);
|
|
67
|
+
loaded.set(ctx.session.id, instructions.map(({ text, trust, source }) => ({ text, trust, source })));
|
|
68
|
+
await ctx.effect(() => () => void loaded.delete(ctx.session.id));
|
|
62
69
|
const fixed = [segment(env), ...instructions.map((i) => segment(i.text, i.trust, "stable", ID, i.source))];
|
|
63
70
|
// 告诉用户读了哪些指令文件,否则看不出它们生效了
|
|
64
71
|
if (instructions.length > 0) ctx.service<UI>("ui@1")?.notify(`loaded instructions: ${instructions.map((i) => display(realPath(ctx.cwd), i.file)).join(", ")}`);
|
|
65
72
|
|
|
73
|
+
// 内容为空的错误工具结果补上说明(results.ts)。原因记在 derived 里;同一批里可能有几个,
|
|
74
|
+
// observe 并发执行、拿到的 derived 快照可能是旧的,所以在这里累积,每次记完整的一份。
|
|
75
|
+
// 运行时不等 observe:紧接着的模型调用投影时记录可能还没落盘,所以投影也看这份累积的。
|
|
76
|
+
// observe 在事件写入时就(以微任务)开始执行,早于之后的投影;下一轮之前记录一定已落盘,恢复会话时从 derived 读,
|
|
77
|
+
// 所以投影只取决于日志,每次相同
|
|
78
|
+
const reasonsKey = `${ID}/empty-results`;
|
|
79
|
+
let reasons: Record<string, Why> | undefined;
|
|
80
|
+
ctx.kernel.hook({
|
|
81
|
+
kind: "observe",
|
|
82
|
+
point: "event",
|
|
83
|
+
fn: async (e: LogEvent, hook) => {
|
|
84
|
+
const found = whyEmpty(e);
|
|
85
|
+
if (!found) return;
|
|
86
|
+
reasons ??= { ...((hook.derived[reasonsKey] as Reasons | undefined) ?? {}) };
|
|
87
|
+
reasons[found.toolUseId] = found.why;
|
|
88
|
+
await hook.record(reasonsKey, { ...reasons });
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
ctx.kernel.hook({
|
|
92
|
+
kind: "transform",
|
|
93
|
+
point: "context.project",
|
|
94
|
+
// 出错时跳过(不补说明),不让这一轮失败
|
|
95
|
+
optional: true,
|
|
96
|
+
fn: (messages, hook) => explainEmptyResults(messages, { ...(hook.derived[reasonsKey] as Reasons | undefined), ...reasons }, ID),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
ctx.kernel.hook(notes.hook(ctx.session.id, `${ID}/notes`));
|
|
100
|
+
await ctx.effect(() => () => notes.drop(ctx.session.id));
|
|
101
|
+
|
|
66
102
|
ctx.kernel.hook({
|
|
67
103
|
kind: "transform",
|
|
68
104
|
point: "context.build",
|
|
@@ -1,23 +1,35 @@
|
|
|
1
|
-
// 给模型的说明([Note from jade]
|
|
2
|
-
//
|
|
1
|
+
// 给模型的说明([Note from jade],prompts@1 的 note):命令里做的事(例如用户删掉了一条记忆、撤销了模型改的文件)
|
|
2
|
+
// 要让模型知道,但命令拿不到会话日志,也不该替用户发一条消息。所以先记下来,下一次请求模型时在 context.project 里
|
|
3
3
|
// 附在最后一条消息后面,并用 ctx.record 写进日志(derived):之后的投影、恢复的会话里它都在同一个位置。
|
|
4
|
-
// 插件之间不共享代码,jade/undo 里也有一份。
|
|
5
4
|
|
|
6
5
|
import type { Block, LocalHookSpec, Message } from "uncarved";
|
|
7
6
|
|
|
7
|
+
export interface Note {
|
|
8
|
+
/** 留下这条说明的插件 */
|
|
9
|
+
plugin: string;
|
|
10
|
+
text: string;
|
|
11
|
+
/** 项目层插件留的说明不可信 */
|
|
12
|
+
trusted: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
/** derived 里:消息的下标 → 附在它后面的说明 */
|
|
9
|
-
type NotesState = Record<string,
|
|
16
|
+
type NotesState = Record<string, Note[]>;
|
|
10
17
|
|
|
11
18
|
export class Notes {
|
|
12
19
|
/** 会话 → 还没交给模型的说明 */
|
|
13
|
-
readonly #pending = new Map<string,
|
|
20
|
+
readonly #pending = new Map<string, Note[]>();
|
|
21
|
+
|
|
22
|
+
add(sessionId: string, note: Note): void {
|
|
23
|
+
this.#pending.set(sessionId, [...(this.#pending.get(sessionId) ?? []), note]);
|
|
24
|
+
}
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
/** 会话关闭:还没交给模型的说明不再留着 */
|
|
27
|
+
drop(sessionId: string): void {
|
|
28
|
+
this.#pending.delete(sessionId);
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
/** 会话里的 context.project hook;key 是 derived 里的键 */
|
|
20
|
-
hook(sessionId: string,
|
|
32
|
+
hook(sessionId: string, key: string): LocalHookSpec {
|
|
21
33
|
return {
|
|
22
34
|
kind: "transform",
|
|
23
35
|
point: "context.project",
|
|
@@ -34,7 +46,7 @@ export class Notes {
|
|
|
34
46
|
return messages.map((m, i): Message => {
|
|
35
47
|
const notes = state[i];
|
|
36
48
|
if (!notes?.length || m.role !== "user") return m;
|
|
37
|
-
const blocks: Block[] = notes.map((
|
|
49
|
+
const blocks: Block[] = notes.map((n) => ({ kind: "text", text: `[Note from jade] ${n.text}`, origin: { by: "plugin", id: n.plugin }, trust: n.trusted ? "trusted" : "untrusted" }));
|
|
38
50
|
return { ...m, content: [...m.content, ...blocks] };
|
|
39
51
|
});
|
|
40
52
|
},
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "jade/prompts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"api": "^1",
|
|
5
5
|
"entry": "./index.ts",
|
|
6
6
|
"provides": ["prompts@1"],
|
|
7
|
-
"optional": ["models@1", "ui@1"]
|
|
7
|
+
"optional": ["models@1", "ui@1"],
|
|
8
|
+
"config": {
|
|
9
|
+
"claudeInstructions": {
|
|
10
|
+
"default": true,
|
|
11
|
+
"description": "when $JADE_HOME has no AGENTS.md or CLAUDE.md, use ~/.claude/CLAUDE.md as the user instructions; false turns this off"
|
|
12
|
+
}
|
|
13
|
+
}
|
|
8
14
|
}
|