@uncarved/jade 0.3.1 → 0.4.1
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 +490 -29
- package/dist/session.js.map +1 -1
- package/package.json +4 -4
- package/plugins/approval/index.ts +36 -14
- package/plugins/approval/policy.ts +15 -10
- 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 +42 -9
- 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 +47 -12
- package/plugins/models/index.ts +27 -1
- package/plugins/models/provider.ts +24 -0
- package/plugins/models/saved.ts +1 -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 +8 -8
- package/plugins/schedule/index.ts +5 -1
- package/plugins/screenshot/browser.ts +10 -0
- package/plugins/sessions/index.ts +48 -2
- package/plugins/shell/index.ts +27 -28
- package/plugins/shell/plugin.json +1 -1
- package/plugins/shell/renderers.ts +9 -7
- package/plugins/shell/shell.ts +3 -1
- 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 +80 -50
- package/plugins/task/plugin.json +6 -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 +9 -2
- package/plugins/tui/frontend.ts +139 -89
- package/plugins/tui/index.ts +2 -3
- 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 +337 -101
- package/plugins/tui/vendor.ts +1 -1
- package/plugins/undo/checkpoint.ts +8 -4
- package/plugins/undo/index.ts +170 -31
- package/plugins/undo/plugin.json +1 -0
- package/plugins/undo/snapshot.ts +87 -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 -418
- package/plugins-dist/approval/policy.js +391 -508
- 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 -253
- 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 +421 -474
- package/plugins-dist/models/context.js +14 -22
- package/plugins-dist/models/index.js +182 -189
- package/plugins-dist/models/provider.js +263 -307
- package/plugins-dist/models/saved.js +60 -72
- 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 +86 -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 +131 -174
- package/plugins-dist/schedule/cron.js +49 -56
- package/plugins-dist/schedule/index.js +230 -247
- package/plugins-dist/schedule/store.js +93 -109
- package/plugins-dist/scratch/index.js +12 -18
- package/plugins-dist/screenshot/browser.js +136 -154
- package/plugins-dist/screenshot/index.js +37 -46
- package/plugins-dist/screenshot/sys.js +53 -65
- package/plugins-dist/screenshot/tool.js +98 -126
- package/plugins-dist/sessions/index.js +149 -117
- package/plugins-dist/shell/index.js +117 -135
- package/plugins-dist/shell/plugin.json +1 -1
- package/plugins-dist/shell/renderers.js +28 -33
- package/plugins-dist/shell/service.js +17 -23
- package/plugins-dist/shell/shell.js +307 -362
- 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 -117
- package/plugins-dist/task/plugin.json +5 -2
- 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 +36 -42
- package/plugins-dist/tui/editor.js +145 -160
- package/plugins-dist/tui/frontend.js +639 -678
- 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 -355
- 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 -1656
- package/plugins-dist/tui/vendor.js +1088 -1388
- package/plugins-dist/undo/checkpoint.js +97 -118
- package/plugins-dist/undo/index.js +281 -192
- package/plugins-dist/undo/plugin.json +3 -0
- package/plugins-dist/undo/snapshot.js +134 -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 +496 -36
|
Binary file
|
|
@@ -140,6 +140,10 @@ class Context:
|
|
|
140
140
|
|
|
141
141
|
require = service
|
|
142
142
|
|
|
143
|
+
def report(self, message: str) -> None:
|
|
144
|
+
"""告诉用户一个问题(警告,不是错误),消息前面加上插件 id"""
|
|
145
|
+
self._conn.request("report", {"scope": self.scope, "message": message})
|
|
146
|
+
|
|
143
147
|
def provide(self, name: str, impl: Any = None, *, factory: Callable[[Caller], Any] | None = None, methods: list[str] | None = None) -> None:
|
|
144
148
|
"""
|
|
145
149
|
提供一个声明在 provides 里的服务,只能在 process 里调用。
|
|
@@ -159,12 +163,15 @@ class Context:
|
|
|
159
163
|
self._conn.services[name] = impl
|
|
160
164
|
self._conn.request("provide", {"scope": self.scope, "service": name, "methods": methods, "perCaller": factory is not None})
|
|
161
165
|
|
|
162
|
-
def tool(self, name: str, description: str, input_schema: dict, *, effect: str, execute: Callable[[Any, dict], Any], concurrency: str = "exclusive", idempotent: bool = False) -> None:
|
|
166
|
+
def tool(self, name: str, description: str, input_schema: dict, *, effect: str, execute: Callable[[Any, dict], Any], concurrency: str = "exclusive", idempotent: bool = False, meta: dict | None = None) -> None:
|
|
163
167
|
"""
|
|
164
168
|
注册一个工具,只能在 session 里调用。effect:"read"、"write" 或 "external"。
|
|
165
|
-
execute(input, ctx) 返回文字,或 {"content": 文字或 block 列表, "isError": bool}
|
|
169
|
+
execute(input, ctx) 返回文字,或 {"content": 文字或 block 列表, "isError": bool}。
|
|
170
|
+
meta:别的插件据此认出工具做什么,{"writes": "path"} 表示写输入里 path 字段给的文件,{"shell": "command"} 表示执行 command 字段里的命令
|
|
166
171
|
"""
|
|
167
172
|
tool = {"name": name, "description": description, "inputSchema": input_schema, "effect": effect, "concurrency": concurrency, "idempotent": idempotent}
|
|
173
|
+
if meta is not None:
|
|
174
|
+
tool["meta"] = meta
|
|
168
175
|
self._conn.request("kernel/tool", {"scope": self.scope, "tool": tool, "execute": self._conn.handle(execute, self.scope)})
|
|
169
176
|
|
|
170
177
|
def hook(self, kind: str, point: str, fn: Callable[[dict], Any], *, reads: list[str], writes: list[str] | None = None, timeout_ms: int = 30_000, order: int | None = None) -> None:
|
package/src/api.ts
CHANGED
|
@@ -5,7 +5,7 @@ import type { PluginLayer } from "@uncarved/jade-api";
|
|
|
5
5
|
export * from "@uncarved/jade-api";
|
|
6
6
|
|
|
7
7
|
/** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明。和 @uncarved/jade-api 的版本一致 */
|
|
8
|
-
export const API_VERSION = "1.
|
|
8
|
+
export const API_VERSION = "1.4.0";
|
|
9
9
|
|
|
10
10
|
/** 来源层级,后面的层级更高(3.3) */
|
|
11
11
|
export const LAYERS: readonly PluginLayer[] = ["bundled", "user", "project"];
|
package/src/host.ts
CHANGED
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
type ProcessContext,
|
|
20
20
|
type Secrets,
|
|
21
21
|
type Sources,
|
|
22
|
+
type Trust,
|
|
22
23
|
} from "./api.ts";
|
|
23
24
|
import { pluginConfig, readConfigFile, type ConfigFile } from "./config.ts";
|
|
24
25
|
import { fetchSource } from "./fetch.ts";
|
|
@@ -28,9 +29,9 @@ import { ambient, invoke, Scope, serviceHandle, type Owner } from "./membrane.ts
|
|
|
28
29
|
import { startRemote } from "./remote.ts";
|
|
29
30
|
import { resolve, type Plan, type PlanState } from "./resolve.ts";
|
|
30
31
|
import { scopedSecrets, SecretsStore } from "./secrets.ts";
|
|
31
|
-
import { Sessions } from "./session.ts";
|
|
32
|
+
import { CORE_PLUGIN_ID, Sessions } from "./session.ts";
|
|
32
33
|
import { parseSource } from "./source.ts";
|
|
33
|
-
import { countFault, readFaults, readPluginsConfig, writeFaults, type Faults } from "./state.ts";
|
|
34
|
+
import { countFault, FileTrustStore, readFaults, readPluginsConfig, writeFaults, type Faults } from "./state.ts";
|
|
34
35
|
import { updater } from "./update.ts";
|
|
35
36
|
|
|
36
37
|
/** untrusted:项目层插件没有得到用户确认,没有执行它的任何代码 */
|
|
@@ -72,7 +73,9 @@ export const CLI_SERVICE = "cli@1";
|
|
|
72
73
|
export const SOURCES_SERVICE = "sources@1";
|
|
73
74
|
/** jade 本身的版本和升级(3.4),名字要和 api.ts 的 Updater 一致 */
|
|
74
75
|
export const UPDATE_SERVICE = "update@1";
|
|
75
|
-
|
|
76
|
+
/** 用户确认过的东西(3.4),名字要和 api.ts 的 Trust 一致 */
|
|
77
|
+
export const TRUST_SERVICE = "trust@1";
|
|
78
|
+
const CORE_SERVICES = [JADE_SERVICE, CLI_SERVICE, SOURCES_SERVICE, UPDATE_SERVICE, TRUST_SERVICE];
|
|
76
79
|
|
|
77
80
|
/** main.ts 在启动宿主之前自己处理的第一个参数:插件注册了也轮不到,所以不让注册 */
|
|
78
81
|
const CORE_WORDS: ReadonlySet<string> = new Set(["plugins", "update", "upgrade", "help", "list", "ls", "add", "install", "remove", "rm", "uninstall", "enable", "disable"]);
|
|
@@ -142,6 +145,28 @@ export class PluginHost {
|
|
|
142
145
|
// 核心自己装插件、升级自己用的代码,插件经服务用同一份,不 import 核心的模块(3.5)
|
|
143
146
|
this.#services.set(SOURCES_SERVICE, { impl: { parse: parseSource, fetch: fetchSource, hash: treeHash } satisfies Sources, provider: this.#core });
|
|
144
147
|
this.#services.set(UPDATE_SERVICE, { impl: updater(opts.home), provider: this.#core });
|
|
148
|
+
// 插件要用户确认的东西(检查命令、项目里的 MCP 服务)记在同一处,每个调用方一份:记录的键带着插件 id,查不到别的插件的。
|
|
149
|
+
// 和项目层插件的确认(state/trust.json)分开放:那份由内核的确认流程写
|
|
150
|
+
const confirmed = new FileTrustStore(path.join(opts.home, "state", "confirmed.json"));
|
|
151
|
+
/** 写入排队:FileTrustStore 每次读出整份再写回,并发的两次写会丢一条 */
|
|
152
|
+
let writing: Promise<unknown> = Promise.resolve();
|
|
153
|
+
this.#services.set(TRUST_SERVICE, {
|
|
154
|
+
impl: (caller: Caller): Trust => {
|
|
155
|
+
const key = (hash: string) => `${caller.plugin}\0${String(hash)}`;
|
|
156
|
+
return {
|
|
157
|
+
has: async (hash) => {
|
|
158
|
+
await writing;
|
|
159
|
+
return confirmed.has(key(hash));
|
|
160
|
+
},
|
|
161
|
+
add: (hash, where) => {
|
|
162
|
+
const run = writing.then(() => confirmed.add({ hash: key(hash), path: String(where), at: new Date().toISOString() }));
|
|
163
|
+
writing = run.catch(() => {});
|
|
164
|
+
return run;
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
provider: this.#core,
|
|
169
|
+
});
|
|
145
170
|
// jade <子命令> 的注册表:每个调用方一个实例,调用方关闭(停用、被隔离)时撤销它注册的
|
|
146
171
|
this.#services.set(CLI_SERVICE, {
|
|
147
172
|
impl: (caller: Caller): Cli => ({
|
|
@@ -150,8 +175,12 @@ export class PluginHost {
|
|
|
150
175
|
if (typeof name !== "string" || !CLI_NAME.test(name)) throw new Error(`invalid jade subcommand name ${JSON.stringify(name)}`);
|
|
151
176
|
if (CORE_WORDS.has(name)) throw new Error(`"jade ${name}" belongs to jade itself`);
|
|
152
177
|
if (typeof command.run !== "function") throw new Error(`jade ${name} has no run function`);
|
|
178
|
+
// 重名时先注册的留下,后来的跳过并报告:抛错会让调用方整个激活失败
|
|
153
179
|
const taken = this.#cli.get(name);
|
|
154
|
-
if (taken)
|
|
180
|
+
if (taken) {
|
|
181
|
+
this.#report(`"jade ${name}" from ${caller.plugin} was skipped: ${taken.plugin} already registered it`);
|
|
182
|
+
return () => {};
|
|
183
|
+
}
|
|
155
184
|
const entry = { command, plugin: caller.plugin };
|
|
156
185
|
this.#cli.set(name, entry);
|
|
157
186
|
const revoke = () => {
|
|
@@ -257,6 +286,8 @@ export class PluginHost {
|
|
|
257
286
|
home: this.#opts.home,
|
|
258
287
|
cwd: this.#cwd,
|
|
259
288
|
config: (source) => this.#configOf(source),
|
|
289
|
+
// 只读用户的:项目层的配置不能放宽子会话的上限
|
|
290
|
+
coreConfig: () => this.#config.user[CORE_PLUGIN_ID] ?? {},
|
|
260
291
|
core: this.#core,
|
|
261
292
|
active: () => this.#active,
|
|
262
293
|
service: (name, caller) => this.#handle(name, caller),
|
|
@@ -384,6 +415,10 @@ export class PluginHost {
|
|
|
384
415
|
});
|
|
385
416
|
this.#services.set(name, { impl, provider: owner });
|
|
386
417
|
},
|
|
418
|
+
report: (message: string): void => {
|
|
419
|
+
if (owner.scope.closed) throw new StaleContext(id);
|
|
420
|
+
this.#report(`${id}: ${String(message)}`);
|
|
421
|
+
},
|
|
387
422
|
effect: async (start): Promise<void> => {
|
|
388
423
|
if (owner.scope.closed) throw new StaleContext(id);
|
|
389
424
|
// 插件调用自己的代码,不过膜:膜会把返回的清理函数也包起来,作用域关闭时它就被当成过期调用拒绝了。
|
package/src/remote.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { spawn } from "node:child_process";
|
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import type { HookContext, RemoteHookSpec, ToolResult } from "uncarved";
|
|
13
|
-
import { API_VERSION, type Caller, type PluginModule, type PluginSource, type ProcessContext, type ScopeContext, type SessionContext } from "./api.ts";
|
|
13
|
+
import { API_VERSION, type Caller, type PluginModule, type PluginSource, type ProcessContext, type ScopeContext, type SessionContext, type ToolMeta } from "./api.ts";
|
|
14
14
|
import { ambient, type Owner } from "./membrane.ts";
|
|
15
15
|
import { Rpc } from "./rpc.ts";
|
|
16
16
|
|
|
@@ -191,6 +191,7 @@ export async function startRemote(source: PluginSource, owner: Owner, opts: Remo
|
|
|
191
191
|
effect: t.effect,
|
|
192
192
|
concurrency: t.concurrency === "safe" ? "safe" : "exclusive",
|
|
193
193
|
idempotent: t.idempotent === true,
|
|
194
|
+
...(t.meta !== undefined && t.meta !== null ? { meta: t.meta as ToolMeta } : {}),
|
|
194
195
|
execute: async (input, tctx) => {
|
|
195
196
|
const r = await rpc.request("call", { scope, target: { $fn: fn }, args: [input, { sessionId: tctx.sessionId, toolUseId: tctx.toolUseId }] }, tctx.signal);
|
|
196
197
|
return (typeof r === "string" ? { content: r } : r) as ToolResult;
|
|
@@ -217,6 +218,10 @@ export async function startRemote(source: PluginSource, owner: Owner, opts: Remo
|
|
|
217
218
|
(ctx as SessionContext).kernel.hook(spec);
|
|
218
219
|
return null;
|
|
219
220
|
}
|
|
221
|
+
case "report": {
|
|
222
|
+
ctx.report(String(p.message));
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
220
225
|
case "secrets/get": {
|
|
221
226
|
if (typeof p.key !== "string") throw new Error("secrets/get: key must be a string");
|
|
222
227
|
return (await ctx.secrets.get(p.key)) ?? null;
|