@uncarved/jade 0.1.3 → 0.2.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 +161 -150
- package/bin/jade.js +14 -25
- package/dist/api.d.ts +266 -0
- package/dist/api.js +38 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +13 -32
- package/dist/config.js +39 -121
- package/dist/config.js.map +1 -1
- package/dist/fetch.d.ts +20 -0
- package/dist/fetch.js +190 -0
- package/dist/fetch.js.map +1 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +42 -0
- package/dist/hash.js.map +1 -0
- package/dist/host.d.ts +71 -0
- package/dist/host.js +400 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +11 -30
- package/dist/index.js +11 -30
- package/dist/index.js.map +1 -1
- package/dist/install.d.ts +78 -0
- package/dist/install.js +292 -0
- package/dist/install.js.map +1 -0
- package/dist/main.d.ts +1 -2
- package/dist/main.js +160 -1362
- package/dist/main.js.map +1 -1
- package/dist/manifest.d.ts +23 -0
- package/dist/manifest.js +159 -0
- package/dist/manifest.js.map +1 -0
- package/dist/membrane.d.ts +33 -0
- package/dist/membrane.js +140 -0
- package/dist/membrane.js.map +1 -0
- package/dist/remote.d.ts +10 -0
- package/dist/remote.js +292 -0
- package/dist/remote.js.map +1 -0
- package/dist/rescue.d.ts +10 -0
- package/dist/rescue.js +216 -0
- package/dist/rescue.js.map +1 -0
- package/dist/resolve.d.ts +34 -0
- package/dist/resolve.js +178 -0
- package/dist/resolve.js.map +1 -0
- package/dist/rpc.d.ts +26 -0
- package/dist/rpc.js +144 -0
- package/dist/rpc.js.map +1 -0
- package/dist/secrets.d.ts +12 -0
- package/dist/secrets.js +125 -0
- package/dist/secrets.js.map +1 -0
- package/dist/session.d.ts +45 -0
- package/dist/session.js +401 -0
- package/dist/session.js.map +1 -0
- package/dist/source.d.ts +12 -0
- package/dist/source.js +72 -0
- package/dist/source.js.map +1 -0
- package/dist/state.d.ts +37 -0
- package/dist/state.js +93 -0
- package/dist/state.js.map +1 -0
- package/dist/update.d.ts +2 -0
- package/dist/update.js +6 -3
- package/dist/update.js.map +1 -1
- package/package.json +10 -8
- package/plugins/approval/index.ts +311 -0
- package/plugins/approval/plugin.json +22 -0
- package/{src/plugins → plugins/approval}/policy.ts +45 -104
- package/{src/plugins → plugins/approval}/review.ts +62 -16
- package/plugins/ask/index.ts +159 -0
- package/plugins/ask/plugin.json +8 -0
- package/plugins/budget/index.ts +38 -0
- package/plugins/budget/plugin.json +13 -0
- package/{src/plugins → plugins/checks}/checks.ts +48 -38
- package/plugins/checks/index.ts +158 -0
- package/plugins/checks/plugin.json +14 -0
- package/plugins/checks/project.ts +81 -0
- package/plugins/commands/index.ts +76 -0
- package/plugins/commands/plugin.json +7 -0
- package/{src/plugins → plugins/compact}/compact.ts +80 -39
- package/plugins/compact/index.ts +115 -0
- package/plugins/compact/plugin.json +17 -0
- package/plugins/compact/style.ts +17 -0
- package/plugins/continue/index.ts +58 -0
- package/plugins/continue/plugin.json +13 -0
- package/{src/ui → plugins/fs}/diff.ts +2 -2
- package/{src/tools → plugins/fs}/fs.ts +89 -46
- package/{src/tools → plugins/fs}/grep.ts +36 -8
- package/plugins/fs/index.ts +37 -0
- package/plugins/fs/plugin.json +7 -0
- package/{src/ui → plugins/fs}/renderers.ts +25 -70
- package/plugins/fs/style.ts +18 -0
- package/plugins/fs/sys.ts +81 -0
- package/plugins/keys/index.ts +53 -0
- package/plugins/keys/plugin.json +7 -0
- package/plugins/mcp/index.ts +192 -0
- package/{src → plugins/mcp}/mcp.ts +32 -32
- package/plugins/mcp/plugin.json +7 -0
- package/plugins/mcp/project.ts +93 -0
- package/plugins/memory/index.ts +105 -0
- package/{src → plugins/memory}/memory.ts +20 -2
- package/plugins/memory/notes.ts +43 -0
- package/plugins/memory/plugin.json +7 -0
- package/plugins/memory/style.ts +17 -0
- package/plugins/mentions/attach.ts +127 -0
- package/plugins/mentions/index.ts +99 -0
- package/plugins/mentions/plugin.json +7 -0
- package/plugins/mentions/style.ts +17 -0
- package/plugins/models/config.ts +53 -0
- package/plugins/models/configure.ts +455 -0
- package/plugins/models/context.ts +32 -0
- package/plugins/models/index.ts +213 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +16 -119
- package/plugins/models/saved.ts +94 -0
- package/plugins/modes/index.ts +222 -0
- package/plugins/modes/plugin.json +9 -0
- package/plugins/plugins/index.ts +38 -0
- package/plugins/plugins/plugin.json +7 -0
- package/plugins/print/index.ts +160 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +111 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +258 -0
- package/plugins/prompts/results.ts +63 -0
- package/plugins/prompts/sys.ts +84 -0
- package/plugins/renderers/index.ts +78 -0
- package/plugins/renderers/plugin.json +7 -0
- package/plugins/repeats/index.ts +165 -0
- package/plugins/repeats/plugin.json +6 -0
- package/plugins/schedule/cron.ts +74 -0
- package/plugins/schedule/index.ts +292 -0
- package/plugins/schedule/plugin.json +13 -0
- package/plugins/schedule/store.ts +149 -0
- package/plugins/scratch/index.ts +31 -0
- package/plugins/scratch/plugin.json +7 -0
- package/plugins/screenshot/index.ts +40 -0
- package/plugins/screenshot/plugin.json +7 -0
- package/plugins/screenshot/sys.ts +84 -0
- package/{src/tools/screenshot.ts → plugins/screenshot/tool.ts} +6 -6
- package/plugins/sessions/index.ts +148 -0
- package/plugins/sessions/plugin.json +8 -0
- package/plugins/shell/index.ts +33 -0
- package/plugins/shell/plugin.json +17 -0
- package/plugins/shell/renderers.ts +45 -0
- package/plugins/shell/service.ts +44 -0
- package/{src/tools → plugins/shell}/shell.ts +31 -20
- package/{src → plugins/shell}/sys.ts +2 -43
- package/plugins/skills/index.ts +96 -0
- package/plugins/skills/plugin.json +7 -0
- package/plugins/skills/project.ts +49 -0
- package/{src → plugins/skills}/skills.ts +4 -11
- package/plugins/suggest/index.ts +286 -0
- package/plugins/suggest/plugin.json +18 -0
- package/plugins/task/index.ts +168 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +343 -0
- package/plugins/todo/index.ts +93 -0
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +3 -0
- package/plugins/tui/frontend.ts +619 -0
- package/plugins/tui/index.ts +37 -0
- package/plugins/tui/mentions.ts +153 -0
- package/plugins/tui/plugin.json +10 -0
- package/{src/ui → plugins/tui}/render.ts +8 -2
- package/{src/ui → plugins/tui}/screen.ts +8 -3
- package/{src/ui → plugins/tui}/transcript.ts +79 -100
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +360 -392
- package/plugins/tui/vendor.ts +16 -0
- package/{src/tools → plugins/undo}/checkpoint.ts +45 -60
- package/plugins/undo/index.ts +143 -0
- package/plugins/undo/notes.ts +43 -0
- package/plugins/undo/plugin.json +7 -0
- package/plugins/undo/style.ts +17 -0
- package/plugins/update/index.ts +40 -0
- package/plugins/update/plugin.json +13 -0
- package/plugins/web/env.ts +78 -0
- package/plugins/web/index.ts +133 -0
- package/plugins/web/plugin.json +15 -0
- package/plugins/web/renderers.ts +11 -0
- package/{src/tools → plugins/web}/web.ts +64 -31
- package/plugins-dist/approval/index.js +287 -0
- package/plugins-dist/approval/plugin.json +28 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +41 -85
- package/{dist/plugins → plugins-dist/approval}/review.js +56 -10
- package/{dist/plugins → plugins-dist/approval}/schema.js +0 -1
- package/plugins-dist/ask/index.js +145 -0
- package/plugins-dist/ask/plugin.json +12 -0
- package/plugins-dist/budget/index.js +37 -0
- package/plugins-dist/budget/plugin.json +15 -0
- package/{dist/plugins → plugins-dist/checks}/checks.js +46 -35
- package/plugins-dist/checks/index.js +150 -0
- package/plugins-dist/checks/plugin.json +21 -0
- package/plugins-dist/checks/project.js +76 -0
- package/plugins-dist/commands/index.js +33 -0
- package/plugins-dist/commands/plugin.json +9 -0
- package/{dist/plugins → plugins-dist/compact}/compact.js +58 -34
- package/plugins-dist/compact/index.js +100 -0
- package/plugins-dist/compact/plugin.json +25 -0
- package/plugins-dist/compact/style.js +14 -0
- package/plugins-dist/continue/index.js +57 -0
- package/plugins-dist/continue/plugin.json +15 -0
- package/{dist/ui → plugins-dist/fs}/diff.js +2 -3
- package/{dist/tools → plugins-dist/fs}/fs.js +82 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +36 -11
- package/plugins-dist/fs/index.js +39 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/{dist/ui → plugins-dist/fs}/renderers.js +24 -61
- package/plugins-dist/fs/style.js +15 -0
- package/plugins-dist/fs/sys.js +54 -0
- package/plugins-dist/keys/index.js +36 -0
- package/plugins-dist/keys/plugin.json +9 -0
- package/plugins-dist/mcp/index.js +187 -0
- package/{dist → plugins-dist/mcp}/mcp.js +34 -30
- package/plugins-dist/mcp/plugin.json +12 -0
- package/plugins-dist/mcp/project.js +90 -0
- package/plugins-dist/memory/index.js +94 -0
- package/{dist → plugins-dist/memory}/memory.js +21 -3
- package/plugins-dist/memory/notes.js +36 -0
- package/plugins-dist/memory/plugin.json +11 -0
- package/plugins-dist/memory/style.js +14 -0
- package/plugins-dist/mentions/attach.js +120 -0
- package/plugins-dist/mentions/index.js +87 -0
- package/plugins-dist/mentions/plugin.json +9 -0
- package/plugins-dist/mentions/style.js +14 -0
- package/plugins-dist/models/config.js +53 -0
- package/plugins-dist/models/configure.js +415 -0
- package/plugins-dist/models/context.js +27 -0
- package/plugins-dist/models/index.js +181 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +18 -81
- package/plugins-dist/models/saved.js +80 -0
- package/plugins-dist/modes/index.js +190 -0
- package/plugins-dist/modes/plugin.json +18 -0
- package/plugins-dist/plugins/index.js +37 -0
- package/plugins-dist/plugins/plugin.json +10 -0
- package/plugins-dist/print/index.js +172 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +85 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +231 -0
- package/plugins-dist/prompts/results.js +60 -0
- package/plugins-dist/prompts/sys.js +58 -0
- package/plugins-dist/renderers/index.js +36 -0
- package/plugins-dist/renderers/plugin.json +9 -0
- package/plugins-dist/repeats/index.js +165 -0
- package/plugins-dist/repeats/plugin.json +6 -0
- package/plugins-dist/schedule/cron.js +67 -0
- package/plugins-dist/schedule/index.js +281 -0
- package/plugins-dist/schedule/plugin.json +16 -0
- package/plugins-dist/schedule/store.js +125 -0
- package/plugins-dist/scratch/index.js +26 -0
- package/plugins-dist/scratch/plugin.json +10 -0
- package/plugins-dist/screenshot/index.js +35 -0
- package/plugins-dist/screenshot/plugin.json +11 -0
- package/plugins-dist/screenshot/sys.js +76 -0
- package/{dist/tools/screenshot.js → plugins-dist/screenshot/tool.js} +5 -4
- package/plugins-dist/sessions/index.js +136 -0
- package/plugins-dist/sessions/plugin.json +12 -0
- package/plugins-dist/shell/index.js +33 -0
- package/plugins-dist/shell/plugin.json +19 -0
- package/plugins-dist/shell/renderers.js +40 -0
- package/plugins-dist/shell/service.js +29 -0
- package/{dist/tools → plugins-dist/shell}/shell.js +31 -22
- package/{dist → plugins-dist/shell}/sys.js +2 -43
- package/plugins-dist/skills/index.js +90 -0
- package/plugins-dist/skills/plugin.json +12 -0
- package/plugins-dist/skills/project.js +47 -0
- package/{dist → plugins-dist/skills}/skills.js +3 -7
- package/plugins-dist/suggest/index.js +282 -0
- package/plugins-dist/suggest/plugin.json +23 -0
- package/plugins-dist/task/index.js +152 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +284 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +31 -9
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +3 -1
- package/plugins-dist/tui/frontend.js +609 -0
- package/{dist → plugins-dist/tui}/history.js +0 -1
- package/plugins-dist/tui/index.js +21 -0
- package/{dist/ui → plugins-dist/tui}/markdown.js +0 -1
- package/plugins-dist/tui/mentions.js +153 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/{dist/ui → plugins-dist/tui}/render.js +7 -3
- package/{dist/ui → plugins-dist/tui}/screen.js +6 -2
- package/{dist/ui → plugins-dist/tui}/transcript.js +79 -99
- package/{dist/ui → plugins-dist/tui}/tui.js +185 -54
- package/plugins-dist/tui/vendor.js +13822 -0
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +48 -55
- package/plugins-dist/undo/index.js +143 -0
- package/plugins-dist/undo/notes.js +36 -0
- package/plugins-dist/undo/plugin.json +9 -0
- package/plugins-dist/undo/style.js +14 -0
- package/plugins-dist/update/index.js +34 -0
- package/plugins-dist/update/plugin.json +15 -0
- package/plugins-dist/web/env.js +80 -0
- package/plugins-dist/web/index.js +124 -0
- package/plugins-dist/web/plugin.json +21 -0
- package/plugins-dist/web/renderers.js +7 -0
- package/{dist/tools → plugins-dist/web}/web.js +56 -29
- package/sdk/python/__pycache__/jade_plugin.cpython-312.pyc +0 -0
- package/sdk/python/jade_plugin.py +380 -0
- package/src/api.ts +298 -0
- package/src/config.ts +32 -134
- package/src/fetch.ts +216 -0
- package/src/hash.ts +39 -0
- package/src/host.ts +429 -0
- package/src/index.ts +23 -30
- package/src/install.ts +355 -0
- package/src/main.ts +156 -1387
- package/src/manifest.ts +160 -0
- package/src/membrane.ts +142 -0
- package/src/remote.ts +288 -0
- package/src/rescue.ts +217 -0
- package/src/resolve.ts +199 -0
- package/src/rpc.ts +144 -0
- package/src/secrets.ts +122 -0
- package/src/session.ts +458 -0
- package/src/source.ts +83 -0
- package/src/state.ts +120 -0
- package/src/update.ts +265 -262
- package/LICENSE +0 -21
- package/dist/commands.d.ts +0 -50
- package/dist/commands.js +0 -126
- package/dist/commands.js.map +0 -1
- package/dist/context.d.ts +0 -17
- package/dist/context.js +0 -53
- package/dist/context.js.map +0 -1
- package/dist/distro.d.ts +0 -141
- package/dist/distro.js +0 -462
- package/dist/distro.js.map +0 -1
- package/dist/history.d.ts +0 -10
- package/dist/history.js.map +0 -1
- package/dist/mcp.d.ts +0 -114
- package/dist/mcp.js.map +0 -1
- package/dist/memory.d.ts +0 -19
- package/dist/memory.js.map +0 -1
- package/dist/mentions.d.ts +0 -35
- package/dist/mentions.js +0 -130
- package/dist/mentions.js.map +0 -1
- package/dist/plugin-cli.d.ts +0 -16
- package/dist/plugin-cli.js +0 -294
- package/dist/plugin-cli.js.map +0 -1
- package/dist/plugins/budget.d.ts +0 -9
- package/dist/plugins/budget.js +0 -30
- package/dist/plugins/budget.js.map +0 -1
- package/dist/plugins/builtins.d.ts +0 -10
- package/dist/plugins/builtins.js +0 -25
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -71
- package/dist/plugins/checks.js.map +0 -1
- package/dist/plugins/compact.d.ts +0 -26
- package/dist/plugins/compact.js.map +0 -1
- package/dist/plugins/core.d.ts +0 -47
- package/dist/plugins/core.js +0 -229
- package/dist/plugins/core.js.map +0 -1
- package/dist/plugins/host.d.ts +0 -52
- package/dist/plugins/host.js +0 -115
- package/dist/plugins/host.js.map +0 -1
- package/dist/plugins/install.d.ts +0 -68
- package/dist/plugins/install.js +0 -377
- package/dist/plugins/install.js.map +0 -1
- package/dist/plugins/loader.d.ts +0 -410
- package/dist/plugins/loader.js +0 -407
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -98
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -43
- package/dist/plugins/prompts.js +0 -284
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -16
- package/dist/plugins/repeats.js +0 -151
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -18
- package/dist/plugins/review.js.map +0 -1
- package/dist/plugins/schema.d.ts +0 -2
- package/dist/plugins/schema.js.map +0 -1
- package/dist/plugins/sessions.d.ts +0 -7
- package/dist/plugins/sessions.js +0 -110
- package/dist/plugins/sessions.js.map +0 -1
- package/dist/provider.d.ts +0 -165
- package/dist/provider.js.map +0 -1
- package/dist/session-lifecycle.d.ts +0 -61
- package/dist/session-lifecycle.js +0 -167
- package/dist/session-lifecycle.js.map +0 -1
- package/dist/session-scope.d.ts +0 -53
- package/dist/session-scope.js +0 -116
- package/dist/session-scope.js.map +0 -1
- package/dist/sessions.d.ts +0 -28
- package/dist/sessions.js +0 -73
- package/dist/sessions.js.map +0 -1
- package/dist/skills.d.ts +0 -37
- package/dist/skills.js.map +0 -1
- package/dist/sys.d.ts +0 -51
- package/dist/sys.js.map +0 -1
- package/dist/tools/ask.d.ts +0 -11
- package/dist/tools/ask.js +0 -62
- package/dist/tools/ask.js.map +0 -1
- package/dist/tools/checkpoint.d.ts +0 -43
- package/dist/tools/checkpoint.js.map +0 -1
- package/dist/tools/fs.d.ts +0 -39
- package/dist/tools/fs.js.map +0 -1
- package/dist/tools/grep.d.ts +0 -6
- package/dist/tools/grep.js.map +0 -1
- package/dist/tools/screenshot.d.ts +0 -15
- package/dist/tools/screenshot.js.map +0 -1
- package/dist/tools/shell.d.ts +0 -55
- package/dist/tools/shell.js.map +0 -1
- package/dist/tools/task.d.ts +0 -39
- package/dist/tools/task.js +0 -117
- package/dist/tools/task.js.map +0 -1
- package/dist/tools/todo.d.ts +0 -10
- package/dist/tools/todo.js.map +0 -1
- package/dist/tools/web.d.ts +0 -53
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -447
- package/dist/ui/configure.js.map +0 -1
- package/dist/ui/diff.d.ts +0 -20
- package/dist/ui/diff.js.map +0 -1
- package/dist/ui/editor.d.ts +0 -41
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -22
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -14
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/renderers.d.ts +0 -8
- package/dist/ui/renderers.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -118
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -46
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -47
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -144
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -577
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -278
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -34
- package/src/plugins/core.ts +0 -257
- package/src/plugins/host.ts +0 -146
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -742
- package/src/plugins/prompts.ts +0 -327
- package/src/plugins/repeats.ts +0 -157
- package/src/plugins/sessions.ts +0 -109
- package/src/session-lifecycle.ts +0 -194
- package/src/session-scope.ts +0 -135
- package/src/sessions.ts +0 -78
- package/src/tools/ask.ts +0 -72
- package/src/tools/task.ts +0 -149
- package/src/tools/todo.ts +0 -67
- package/src/ui/configure.ts +0 -471
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
- /package/{src/ui → plugins/tui}/markdown.ts +0 -0
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import type { LocalHookSpec, LogEvent, RemoteHookSpec, RuntimeNotice, State, Tool, UserInput } from "uncarved";
|
|
2
|
+
export type { LocalHookSpec, LogEvent, RemoteHookSpec, RuntimeNotice, State, Tool, UserInput } from "uncarved";
|
|
3
|
+
/** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明 */
|
|
4
|
+
export declare const API_VERSION = "1.0.0";
|
|
5
|
+
/** 来源层级,后面的层级更高(3.3) */
|
|
6
|
+
export declare const LAYERS: readonly ["bundled", "user", "project"];
|
|
7
|
+
export type PluginLayer = (typeof LAYERS)[number];
|
|
8
|
+
/** plugin.json:不执行插件代码就能读到的一切(原则 4) */
|
|
9
|
+
export interface Manifest {
|
|
10
|
+
id: string;
|
|
11
|
+
version: string;
|
|
12
|
+
/** 兼容的插件 API 版本,只接受 ^ 范围,如 "^1" */
|
|
13
|
+
api: string;
|
|
14
|
+
/** 进程内插件的入口模块,相对插件目录 */
|
|
15
|
+
entry?: string;
|
|
16
|
+
/** 进程外插件的启动方式(第 6 节),和 entry 二选一 */
|
|
17
|
+
runtime?: {
|
|
18
|
+
command: string;
|
|
19
|
+
args?: string[];
|
|
20
|
+
};
|
|
21
|
+
/** 提供的服务,形如 "commands@1" */
|
|
22
|
+
provides?: string[];
|
|
23
|
+
/** 必需的服务:缺任何一项就不激活 */
|
|
24
|
+
requires?: string[];
|
|
25
|
+
/** 可选的服务:缺了照样激活,ctx.service 返回 undefined */
|
|
26
|
+
optional?: string[];
|
|
27
|
+
/** 代替的插件 id(3.3) */
|
|
28
|
+
replaces?: string[];
|
|
29
|
+
/** 这是一个前端(3.4):default 为默认前端,flag 为选中它的命令行开关 */
|
|
30
|
+
frontend?: {
|
|
31
|
+
name: string;
|
|
32
|
+
default?: boolean;
|
|
33
|
+
flag?: string;
|
|
34
|
+
};
|
|
35
|
+
/** 配置项(第 8 节):键 → 默认值、说明;project 为 true 的键项目层的 .jade/config.json 也能设 */
|
|
36
|
+
config?: Record<string, ConfigKey>;
|
|
37
|
+
}
|
|
38
|
+
export interface ConfigKey {
|
|
39
|
+
default?: unknown;
|
|
40
|
+
description?: string;
|
|
41
|
+
/** 项目层可以设置这个键。项目层插件自己的键不用标 */
|
|
42
|
+
project?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/** 发现的一个插件 */
|
|
45
|
+
export interface PluginSource {
|
|
46
|
+
manifest: Manifest;
|
|
47
|
+
/** 插件目录的绝对路径 */
|
|
48
|
+
dir: string;
|
|
49
|
+
layer: PluginLayer;
|
|
50
|
+
}
|
|
51
|
+
/** 清理函数,作用域关闭时逆序执行 */
|
|
52
|
+
export type Disposer = () => void | Promise<void>;
|
|
53
|
+
/** 一个插件的密钥(第 8 节):按插件 id 隔离,插件只能读写自己的那一份 */
|
|
54
|
+
export interface Secrets {
|
|
55
|
+
/** 读一个密钥;没有时 undefined */
|
|
56
|
+
get(key: string): Promise<string | undefined>;
|
|
57
|
+
/** 写一个密钥;value 为 undefined 时删除它 */
|
|
58
|
+
set(key: string, value: string | undefined): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
/** 进程级和会话级 ctx 共有的部分 */
|
|
61
|
+
export interface ScopeContext {
|
|
62
|
+
/** 本插件的 id */
|
|
63
|
+
readonly plugin: string;
|
|
64
|
+
/** 作用域关闭时中止 */
|
|
65
|
+
readonly signal: AbortSignal;
|
|
66
|
+
/** 工作目录 */
|
|
67
|
+
readonly cwd: string;
|
|
68
|
+
/** $JADE_HOME */
|
|
69
|
+
readonly home: string;
|
|
70
|
+
/** 本插件的配置:清单里的默认值 < 用户 config.json < 项目 .jade/config.json,按键合并(第 8 节) */
|
|
71
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
72
|
+
/** 本插件的密钥:按插件 id 分隔存储,和作用域同生共死(第 8 节) */
|
|
73
|
+
readonly secrets: Secrets;
|
|
74
|
+
/** 取一个声明在 requires 里的服务,没有声明或没有提供者时抛错 */
|
|
75
|
+
require<T extends object>(service: string): T;
|
|
76
|
+
/** 取一个声明在 requires 或 optional 里的服务,没有提供者时返回 undefined */
|
|
77
|
+
service<T extends object>(service: string): T | undefined;
|
|
78
|
+
/** 启动一项后台资源,返回的清理函数在作用域关闭时执行 */
|
|
79
|
+
effect(start: () => Disposer | void | Promise<Disposer | void>): Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
/** 服务的调用方,交给按调用方创建的服务实例(ProcessContext.provide) */
|
|
82
|
+
export interface Caller {
|
|
83
|
+
/** 调用方插件的 id;核心自己调用时为 "jade" */
|
|
84
|
+
readonly plugin: string;
|
|
85
|
+
/** 调用方插件的层级;核心自己调用时为 "core"。项目层插件给的东西(例如提示词)应当当作不可信 */
|
|
86
|
+
readonly layer: PluginLayer | "core";
|
|
87
|
+
/** 调用方的作用域关闭时中止 */
|
|
88
|
+
readonly signal: AbortSignal;
|
|
89
|
+
/** 调用方的作用域关闭时执行,以提供者的身份执行。注册表用它撤销调用方注册的东西 */
|
|
90
|
+
onDispose(d: Disposer): void;
|
|
91
|
+
}
|
|
92
|
+
export interface ProcessContext extends ScopeContext {
|
|
93
|
+
/**
|
|
94
|
+
* 提供一个声明在 provides 里的服务。
|
|
95
|
+
* 传对象:所有调用方共用;传函数:每个调用方作用域调用一次,得到这个调用方专用的实例。
|
|
96
|
+
* 注册表应当用函数形式,在 caller.onDispose 里撤销调用方注册的东西,这样调用方关闭、
|
|
97
|
+
* 激活失败或被隔离时,它的注册自动撤销(4.1)
|
|
98
|
+
*/
|
|
99
|
+
provide(service: string, impl: object | ((caller: Caller) => object)): void;
|
|
100
|
+
}
|
|
101
|
+
/** 插件在会话里能做的事(4.3) */
|
|
102
|
+
export interface SessionControl {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
/** 本轮完全结束(turn.ended 已落盘、没有在途工具)后执行一次;会话空闲时尽快执行 */
|
|
105
|
+
afterTurn(fn: () => void | Promise<void>): void;
|
|
106
|
+
/**
|
|
107
|
+
* 发起一轮。正在跑时排到当前这一轮之后,这一轮跑完时 resolve。
|
|
108
|
+
* 不要在 hook 或工具里 await 它:它要等当前这一轮结束,而当前这一轮在等你。项目层插件不能用(第 7 节)
|
|
109
|
+
*/
|
|
110
|
+
send(input: UserInput): Promise<void>;
|
|
111
|
+
/** 中止正在跑的这一轮(例如用户在别处喊停);空闲时什么都不做。项目层插件不能用 */
|
|
112
|
+
abort(reason?: string): void;
|
|
113
|
+
}
|
|
114
|
+
export interface SessionContext extends ScopeContext {
|
|
115
|
+
readonly session: SessionControl;
|
|
116
|
+
/**
|
|
117
|
+
* 状态栏上这个插件的一段(一行);undefined 去掉。前端没有状态栏时是 undefined。
|
|
118
|
+
* 状态栏同时显示几个插件的段落时按调用先后排列(4.3)
|
|
119
|
+
*/
|
|
120
|
+
readonly status?: (text: string | undefined) => void;
|
|
121
|
+
/** 输入框里的草稿:读、追加、整段替换、灰色提示;只有终端界面有 */
|
|
122
|
+
readonly input?: Draft;
|
|
123
|
+
/** 交给内核的部分,只能在 session() 执行期间注册:会话的内核插件清单在创建时确定 */
|
|
124
|
+
readonly kernel: {
|
|
125
|
+
tool(tool: Tool): void;
|
|
126
|
+
/** 进程内的 hook,或进程外插件的 RemoteHookSpec(字段裁剪、超时由内核保证) */
|
|
127
|
+
hook(hook: LocalHookSpec | RemoteHookSpec): void;
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** 输入框(4.3):只在前端有输入框时给插件 */
|
|
131
|
+
export interface Draft {
|
|
132
|
+
/** 现在输入框里的文字 */
|
|
133
|
+
text(): string;
|
|
134
|
+
/** 在光标处插入一段文字 */
|
|
135
|
+
insert(text: string): void;
|
|
136
|
+
/** 换掉整段文字,光标移到末尾 */
|
|
137
|
+
set(text: string): void;
|
|
138
|
+
/** 输入框空着时显示的灰色提示,Tab 或 → 接受;undefined 去掉 */
|
|
139
|
+
hint(text: string | undefined): void;
|
|
140
|
+
}
|
|
141
|
+
/** 前端拿到的会话 */
|
|
142
|
+
export interface Session {
|
|
143
|
+
readonly id: string;
|
|
144
|
+
readonly state: State;
|
|
145
|
+
/** 发一条输入;正在跑时排队。这一轮跑完时 resolve(之后的 afterTurn 不等) */
|
|
146
|
+
send(input: UserInput): Promise<void>;
|
|
147
|
+
/** 排队的输入和 afterTurn 全部处理完时 resolve */
|
|
148
|
+
idle(): Promise<void>;
|
|
149
|
+
/** 继续日志里没做完的工作(崩溃、重启后) */
|
|
150
|
+
recover(): Promise<void>;
|
|
151
|
+
abort(reason?: unknown): void;
|
|
152
|
+
subscribe(fn: (n: RuntimeNotice) => void): () => void;
|
|
153
|
+
/** 日志里的全部事件(恢复会话时前端用它重新显示对话) */
|
|
154
|
+
history(): Promise<LogEvent[]>;
|
|
155
|
+
}
|
|
156
|
+
export interface OpenOptions {
|
|
157
|
+
/** 恢复这个会话;不写就新建 */
|
|
158
|
+
resume?: string;
|
|
159
|
+
}
|
|
160
|
+
/** 会话管理器:新建、恢复、切换(4.2) */
|
|
161
|
+
export interface SessionManager {
|
|
162
|
+
readonly current: Session | undefined;
|
|
163
|
+
/** 新建或恢复一个会话,成功后它成为当前会话,旧会话离开(仍可恢复)。失败时旧会话不受影响 */
|
|
164
|
+
open(opts?: OpenOptions): Promise<Session>;
|
|
165
|
+
/** 当前会话离开(仍可恢复) */
|
|
166
|
+
close(): Promise<void>;
|
|
167
|
+
}
|
|
168
|
+
/** frontend@1:核心启动后把控制权交给它,返回进程的退出码 */
|
|
169
|
+
export interface Frontend {
|
|
170
|
+
run(opts: {
|
|
171
|
+
argv: readonly string[];
|
|
172
|
+
sessions: SessionManager;
|
|
173
|
+
signal: AbortSignal;
|
|
174
|
+
}): Promise<number | void>;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* jade@1:核心自己的诊断信息,由核心提供(不是插件,见 3.4)。只读;`/plugins` 用它,
|
|
178
|
+
* 和救援 CLI `jade plugins list` 看的是同一份状态
|
|
179
|
+
*/
|
|
180
|
+
export interface Jade {
|
|
181
|
+
/** 这次启动里每个插件的状态和原因,包括读不出清单的目录 */
|
|
182
|
+
plugins(): PluginStatus[];
|
|
183
|
+
/** 服务名 → 提供者 id(含核心自己的 jade@1) */
|
|
184
|
+
services(): {
|
|
185
|
+
service: string;
|
|
186
|
+
provider: string;
|
|
187
|
+
}[];
|
|
188
|
+
}
|
|
189
|
+
/** 一个插件在这次启动里的状态(和 PluginState 一致,这里不 import 宿主) */
|
|
190
|
+
export interface PluginStatus {
|
|
191
|
+
id?: string;
|
|
192
|
+
version?: string;
|
|
193
|
+
layer: PluginLayer;
|
|
194
|
+
dir: string;
|
|
195
|
+
state: "active" | "disabled" | "duplicate" | "incompatible" | "replaced" | "conflict" | "skipped" | "broken" | "failed" | "untrusted" | "quarantined";
|
|
196
|
+
reason?: string;
|
|
197
|
+
}
|
|
198
|
+
/** ui@1:前端提供的和用户打交道的方式。每个前端都提供它,形状由 jade 定义 */
|
|
199
|
+
export interface UI {
|
|
200
|
+
/** 能不能向用户提问。不能时 select 总是返回 undefined */
|
|
201
|
+
readonly interactive: boolean;
|
|
202
|
+
/** 告诉用户一件事 */
|
|
203
|
+
notify(message: string, level?: "info" | "warning" | "error"): void;
|
|
204
|
+
/** 请用户从选项里选一个,返回选中项的 value;不能提问、用户取消或 signal 中止时返回 undefined */
|
|
205
|
+
select<T extends string>(request: SelectRequest<T>, signal?: AbortSignal): Promise<T | undefined>;
|
|
206
|
+
/** 请用户输入一行;不能提问、用户取消或 signal 中止时返回 undefined */
|
|
207
|
+
input(request: InputRequest, signal?: AbortSignal): Promise<string | undefined>;
|
|
208
|
+
/**
|
|
209
|
+
* 某个插件在一个会话里的界面(4.3):状态栏上它的一段、输入框。
|
|
210
|
+
* 核心为每个加入会话的插件调用一次;不能显示时返回 undefined。插件的作用域关闭时核心调用 dispose
|
|
211
|
+
*/
|
|
212
|
+
session?(request: SessionRequest): SessionUI | undefined;
|
|
213
|
+
}
|
|
214
|
+
/** UI.session 的参数:会话 id 和调用它的插件 */
|
|
215
|
+
export interface SessionRequest {
|
|
216
|
+
session: string;
|
|
217
|
+
plugin: string;
|
|
218
|
+
}
|
|
219
|
+
/** 一个插件在一个会话里的界面;每个插件一份,所以状态栏的段落不用 key */
|
|
220
|
+
export interface SessionUI {
|
|
221
|
+
/** 状态栏上这个插件的一段(一行);undefined 去掉 */
|
|
222
|
+
status(text: string | undefined): void;
|
|
223
|
+
/** 输入框;没有输入框的前端(例如 -p)没有 */
|
|
224
|
+
readonly draft?: Draft;
|
|
225
|
+
/** 去掉这个插件在这个会话里留下的一切(状态栏的段落、输入框的提示) */
|
|
226
|
+
dispose(): void;
|
|
227
|
+
}
|
|
228
|
+
export interface InputRequest {
|
|
229
|
+
title: string;
|
|
230
|
+
initial?: string;
|
|
231
|
+
placeholder?: string;
|
|
232
|
+
/** 输入的内容不显示(密钥) */
|
|
233
|
+
mask?: boolean;
|
|
234
|
+
}
|
|
235
|
+
export interface SelectRequest<T extends string> {
|
|
236
|
+
title: string;
|
|
237
|
+
/** 选项上方的详细内容,例如要执行的命令、要改的文件 */
|
|
238
|
+
detail?: string;
|
|
239
|
+
options: {
|
|
240
|
+
label: string;
|
|
241
|
+
value: T; /** 选项后面的灰色说明 */
|
|
242
|
+
hint?: string;
|
|
243
|
+
}[];
|
|
244
|
+
}
|
|
245
|
+
export interface PluginModule {
|
|
246
|
+
/** 进程级:提供服务、向其他插件的注册服务注册东西。只做注册,不在这里直接启动后台资源 */
|
|
247
|
+
process?(ctx: ProcessContext): void | Promise<void>;
|
|
248
|
+
/** 会话级:每个会话调用一次,注册工具和内核 hook。会话关闭(换会话、退出)时作用域关闭 */
|
|
249
|
+
session?(ctx: SessionContext): void | Promise<void>;
|
|
250
|
+
}
|
|
251
|
+
export declare function definePlugin<T extends PluginModule>(module: T): T;
|
|
252
|
+
/** 插件代码抛出的错误,标明归属 */
|
|
253
|
+
export declare class PluginError extends Error {
|
|
254
|
+
readonly plugin: string;
|
|
255
|
+
constructor(plugin: string, where: string, cause: unknown);
|
|
256
|
+
}
|
|
257
|
+
/** 作用域已关闭之后还在用它的 ctx 或从它拿到的东西(4.1) */
|
|
258
|
+
export declare class StaleContext extends Error {
|
|
259
|
+
readonly plugin: string;
|
|
260
|
+
constructor(plugin: string);
|
|
261
|
+
}
|
|
262
|
+
/** 服务的提供者已被隔离或已关闭(3.3) */
|
|
263
|
+
export declare class ServiceUnavailable extends Error {
|
|
264
|
+
readonly service: string;
|
|
265
|
+
constructor(service: string, provider: string);
|
|
266
|
+
}
|
package/dist/api.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// jade 插件 API:插件能看到的全部类型。设计见 docs/design/jade.md。
|
|
2
|
+
// 插件只从这里 import 类型和 definePlugin,运行时用到的一切都从 ctx 拿(3.5)。
|
|
3
|
+
/** 插件 API 的版本,插件在 plugin.json 的 api 字段里用 ^ 范围声明 */
|
|
4
|
+
export const API_VERSION = "1.0.0";
|
|
5
|
+
/** 来源层级,后面的层级更高(3.3) */
|
|
6
|
+
export const LAYERS = ["bundled", "user", "project"];
|
|
7
|
+
export function definePlugin(module) {
|
|
8
|
+
return module;
|
|
9
|
+
}
|
|
10
|
+
// ---------- 错误 ----------
|
|
11
|
+
/** 插件代码抛出的错误,标明归属 */
|
|
12
|
+
export class PluginError extends Error {
|
|
13
|
+
plugin;
|
|
14
|
+
constructor(plugin, where, cause) {
|
|
15
|
+
super(`plugin ${plugin} (${where}): ${cause instanceof Error ? cause.message : String(cause)}`, { cause });
|
|
16
|
+
this.name = "PluginError";
|
|
17
|
+
this.plugin = plugin;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/** 作用域已关闭之后还在用它的 ctx 或从它拿到的东西(4.1) */
|
|
21
|
+
export class StaleContext extends Error {
|
|
22
|
+
plugin;
|
|
23
|
+
constructor(plugin) {
|
|
24
|
+
super(`plugin ${plugin}: this context belongs to a closed scope; do not keep ctx or services across a session switch`);
|
|
25
|
+
this.name = "StaleContext";
|
|
26
|
+
this.plugin = plugin;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/** 服务的提供者已被隔离或已关闭(3.3) */
|
|
30
|
+
export class ServiceUnavailable extends Error {
|
|
31
|
+
service;
|
|
32
|
+
constructor(service, provider) {
|
|
33
|
+
super(`service ${service}: provider ${provider} is no longer active`);
|
|
34
|
+
this.name = "ServiceUnavailable";
|
|
35
|
+
this.service = service;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=api.js.map
|
package/dist/api.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,wDAAwD;AAKxD,mDAAmD;AACnD,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC;AAEnC,wBAAwB;AACxB,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,CAAU,CAAC;AA6P9D,MAAM,UAAU,YAAY,CAAyB,MAAS;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,2BAA2B;AAE3B,qBAAqB;AACrB,MAAM,OAAO,WAAY,SAAQ,KAAK;IAC3B,MAAM,CAAS;IACxB,YAAY,MAAc,EAAE,KAAa,EAAE,KAAc;QACvD,KAAK,CAAC,UAAU,MAAM,KAAK,KAAK,MAAM,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3G,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,sCAAsC;AACtC,MAAM,OAAO,YAAa,SAAQ,KAAK;IAC5B,MAAM,CAAS;IACxB,YAAY,MAAc;QACxB,KAAK,CAAC,UAAU,MAAM,+FAA+F,CAAC,CAAC;QACvH,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,0BAA0B;AAC1B,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAClC,OAAO,CAAS;IACzB,YAAY,OAAe,EAAE,QAAgB;QAC3C,KAAK,CAAC,WAAW,OAAO,cAAc,QAAQ,sBAAsB,CAAC,CAAC;QACtE,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;QACjC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
|
package/dist/config.d.ts
CHANGED
|
@@ -1,34 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
/**
|
|
4
|
-
export declare function
|
|
1
|
+
import type { PluginSource } from "./api.ts";
|
|
2
|
+
export type ConfigFile = Record<string, Record<string, unknown>>;
|
|
3
|
+
/** 文件不存在时为空;格式不对时为空并给出原因 */
|
|
4
|
+
export declare function readConfigFile(file: string): Promise<{
|
|
5
|
+
config: ConfigFile;
|
|
6
|
+
error?: string;
|
|
7
|
+
}>;
|
|
5
8
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
9
|
+
* 一个插件的配置。项目层的文件只能设置项目层插件的键,和清单里标了 project 的键:
|
|
10
|
+
* 克隆的仓库不能改你的审批模式、模型配置(第 7 节)。被忽略的键在 ignored 里
|
|
8
11
|
*/
|
|
9
|
-
export declare function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* 改写配置文件里的变量:已有的行原地替换,没有的追加在末尾,值为 undefined 的删除;注释和其他行保持不变。
|
|
14
|
-
* 同时更新 env,让改动在本次运行中生效
|
|
15
|
-
*/
|
|
16
|
-
export declare function updateEnvFile(file: string, updates: Record<string, string | undefined>, env?: Record<string, string | undefined>): Promise<void>;
|
|
17
|
-
/**
|
|
18
|
-
* 保存过的服务和模型:$JADE_HOME/models.json。同一个服务(类型、地址、密钥都相同)只存一份,下面是在它上面用过的模型,
|
|
19
|
-
* 每个模型带自己的设置(输出上限、思考力度、上下文窗口)。.env 里始终是当前用的那一个;这里记着用过的全部,/model 可以切回去
|
|
20
|
-
*/
|
|
21
|
-
export interface SavedService {
|
|
22
|
-
/** 服务的变量:JADE_PROVIDER、地址、密钥等 */
|
|
23
|
-
env: Record<string, string>;
|
|
24
|
-
/** 最近用过的在前 */
|
|
25
|
-
models: SavedModel[];
|
|
26
|
-
}
|
|
27
|
-
export interface SavedModel {
|
|
28
|
-
name: string;
|
|
29
|
-
/** 这个模型自己的设置变量 */
|
|
30
|
-
settings: Record<string, string>;
|
|
31
|
-
}
|
|
32
|
-
/** 读不了或格式不对时返回空数组 */
|
|
33
|
-
export declare function readSavedServices(file: string): Promise<SavedService[]>;
|
|
34
|
-
export declare function writeSavedServices(file: string, services: SavedService[]): Promise<void>;
|
|
12
|
+
export declare function pluginConfig(source: PluginSource, user: ConfigFile, project: ConfigFile): {
|
|
13
|
+
config: Record<string, unknown>;
|
|
14
|
+
ignored: string[];
|
|
15
|
+
};
|
package/dist/config.js
CHANGED
|
@@ -1,130 +1,48 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/** 解析 KEY=VALUE 格式:忽略空行和 # 注释,允许 export 前缀,去掉成对的引号(双引号里的 \n 换成换行) */
|
|
8
|
-
export function parseEnv(text) {
|
|
9
|
-
const out = {};
|
|
10
|
-
for (const raw of text.split(/\r?\n/)) {
|
|
11
|
-
const m = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*?)\s*$/.exec(raw);
|
|
12
|
-
if (!m)
|
|
13
|
-
continue;
|
|
14
|
-
let value = m[2];
|
|
15
|
-
const quote = value[0];
|
|
16
|
-
if ((quote === '"' || quote === "'") && value.length >= 2 && value.endsWith(quote)) {
|
|
17
|
-
value = value.slice(1, -1);
|
|
18
|
-
if (quote === '"')
|
|
19
|
-
value = value.replaceAll("\\n", "\n");
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
// 未加引号的值里,空白之后的 # 是注释
|
|
23
|
-
value = value.replace(/\s+#.*$/, "");
|
|
24
|
-
}
|
|
25
|
-
out[m[1]] = value;
|
|
26
|
-
}
|
|
27
|
-
return out;
|
|
28
|
-
}
|
|
29
|
-
/** 把配置文件里的变量填进 env 中还没有的键;文件不存在时什么也不做。返回是否读到了文件 */
|
|
30
|
-
export async function loadEnvFile(file, env = process.env) {
|
|
31
|
-
let text;
|
|
1
|
+
// 插件的配置(第 8 节):清单里的默认值 < 用户 config.json < 项目 .jade/config.json,按插件、按键合并。
|
|
2
|
+
// 两个文件的形状相同:{ "<插件 id>": { "<键>": 值 } }。不执行插件代码。
|
|
3
|
+
import { readFile } from "node:fs/promises";
|
|
4
|
+
/** 文件不存在时为空;格式不对时为空并给出原因 */
|
|
5
|
+
export async function readConfigFile(file) {
|
|
6
|
+
let raw;
|
|
32
7
|
try {
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
catch {
|
|
36
|
-
|
|
8
|
+
raw = JSON.parse(await readFile(file, "utf8"));
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
if (e.code === "ENOENT")
|
|
12
|
+
return { config: {} };
|
|
13
|
+
return { config: {}, error: `${file}: ${e instanceof Error ? e.message : String(e)}; ignored` };
|
|
14
|
+
}
|
|
15
|
+
const isObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
16
|
+
if (!isObject(raw))
|
|
17
|
+
return { config: {}, error: `${file}: expected an object of plugin ids; ignored` };
|
|
18
|
+
const config = {};
|
|
19
|
+
const bad = [];
|
|
20
|
+
for (const [id, section] of Object.entries(raw)) {
|
|
21
|
+
if (isObject(section))
|
|
22
|
+
config[id] = section;
|
|
23
|
+
else
|
|
24
|
+
bad.push(id);
|
|
37
25
|
}
|
|
38
|
-
|
|
39
|
-
if (env[k] === undefined)
|
|
40
|
-
env[k] = v;
|
|
41
|
-
return true;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* token 数:整数,或者带 K(千)、M(百万)的写法,例如 32000、512K、1M、1.5M,不区分大小写,可以用 _ 分隔数字。
|
|
45
|
-
* 不是正整数时抛出,错误信息里带变量名 name
|
|
46
|
-
*/
|
|
47
|
-
export function parseTokens(name, text) {
|
|
48
|
-
const m = /^\s*(\d+(?:\.\d+)?)\s*([km])?\s*$/i.exec(text.replaceAll("_", ""));
|
|
49
|
-
const unit = m?.[2] ? (m[2].toLowerCase() === "k" ? 1_000 : 1_000_000) : 1;
|
|
50
|
-
const n = m ? (unit === 1 ? Number(m[1]) : Math.round(Number(m[1]) * unit)) : NaN;
|
|
51
|
-
if (!Number.isInteger(n) || n <= 0)
|
|
52
|
-
throw new Error(`${name} must be a number of tokens such as 32000, 512K or 1M, got ${JSON.stringify(text)}`);
|
|
53
|
-
return n;
|
|
54
|
-
}
|
|
55
|
-
/** 至少配置了一种模型 */
|
|
56
|
-
export function hasProvider(env = process.env) {
|
|
57
|
-
return Boolean(env.JADE_PROVIDER || env.OPENAI_API_KEY || env.OPENAI_COMPAT_BASE_URL || env.ANTHROPIC_API_KEY);
|
|
26
|
+
return bad.length > 0 ? { config, error: `${file}: the sections for ${bad.join(", ")} are not objects; ignored` } : { config };
|
|
58
27
|
}
|
|
59
28
|
/**
|
|
60
|
-
*
|
|
61
|
-
*
|
|
29
|
+
* 一个插件的配置。项目层的文件只能设置项目层插件的键,和清单里标了 project 的键:
|
|
30
|
+
* 克隆的仓库不能改你的审批模式、模型配置(第 7 节)。被忽略的键在 ignored 里
|
|
62
31
|
*/
|
|
63
|
-
export
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
for (const raw of lines) {
|
|
75
|
-
const key = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(raw)?.[1];
|
|
76
|
-
if (!key || !(key in updates)) {
|
|
77
|
-
out.push(raw);
|
|
78
|
-
continue;
|
|
79
|
-
}
|
|
80
|
-
// 同一个键出现多次时只保留第一处
|
|
81
|
-
const value = updates[key];
|
|
82
|
-
if (value !== undefined && !written.has(key))
|
|
83
|
-
out.push(format(key, value));
|
|
84
|
-
written.add(key);
|
|
85
|
-
}
|
|
86
|
-
for (const [key, value] of Object.entries(updates)) {
|
|
87
|
-
if (value !== undefined && !written.has(key))
|
|
88
|
-
out.push(format(key, value));
|
|
89
|
-
}
|
|
90
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
91
|
-
await writeFile(file, out.join("\n") + "\n");
|
|
92
|
-
for (const [key, value] of Object.entries(updates)) {
|
|
93
|
-
if (value === undefined)
|
|
94
|
-
delete env[key];
|
|
32
|
+
export function pluginConfig(source, user, project) {
|
|
33
|
+
const { id, config: keys = {} } = source.manifest;
|
|
34
|
+
const config = {};
|
|
35
|
+
for (const [k, v] of Object.entries(keys))
|
|
36
|
+
if (v.default !== undefined)
|
|
37
|
+
config[k] = structuredClone(v.default);
|
|
38
|
+
Object.assign(config, user[id]);
|
|
39
|
+
const ignored = [];
|
|
40
|
+
for (const [k, v] of Object.entries(project[id] ?? {})) {
|
|
41
|
+
if (source.layer === "project" || keys[k]?.project)
|
|
42
|
+
config[k] = v;
|
|
95
43
|
else
|
|
96
|
-
|
|
44
|
+
ignored.push(k);
|
|
97
45
|
}
|
|
98
|
-
}
|
|
99
|
-
const strings = (v) => typeof v === "object" && v !== null ? Object.fromEntries(Object.entries(v).filter(([, x]) => typeof x === "string")) : {};
|
|
100
|
-
/** 读不了或格式不对时返回空数组 */
|
|
101
|
-
export async function readSavedServices(file) {
|
|
102
|
-
try {
|
|
103
|
-
const data = JSON.parse(await readFile(file, "utf8"));
|
|
104
|
-
if (!Array.isArray(data.services))
|
|
105
|
-
return [];
|
|
106
|
-
return data.services.flatMap((raw) => {
|
|
107
|
-
const s = raw;
|
|
108
|
-
if (!s || !Array.isArray(s.models))
|
|
109
|
-
return [];
|
|
110
|
-
const models = s.models.flatMap((m) => {
|
|
111
|
-
const name = m?.name;
|
|
112
|
-
return typeof name === "string" && name ? [{ name, settings: strings(m.settings) }] : [];
|
|
113
|
-
});
|
|
114
|
-
return models.length ? [{ env: strings(s.env), models }] : [];
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export async function writeSavedServices(file, services) {
|
|
122
|
-
await mkdir(path.dirname(file), { recursive: true });
|
|
123
|
-
// 里面有 API 密钥
|
|
124
|
-
await writeFile(file, JSON.stringify({ services }, null, 2) + "\n", { mode: 0o600 });
|
|
125
|
-
}
|
|
126
|
-
/** 含空白、# 或引号的值加双引号,parseEnv 能原样读回 */
|
|
127
|
-
function format(key, value) {
|
|
128
|
-
return /[\s#"']/.test(value) ? `${key}="${value.replaceAll("\n", "\\n")}"` : `${key}=${value}`;
|
|
46
|
+
return { config: Object.freeze(config), ignored };
|
|
129
47
|
}
|
|
130
48
|
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"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"}
|
package/dist/fetch.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Manifest } from "./api.ts";
|
|
2
|
+
import type { PluginSourceSpec } from "./source.ts";
|
|
3
|
+
export interface Fetched {
|
|
4
|
+
/** 插件目录(staging 里的某个子目录) */
|
|
5
|
+
dir: string;
|
|
6
|
+
/** git 安装的提交 */
|
|
7
|
+
commit?: string;
|
|
8
|
+
manifest: Manifest;
|
|
9
|
+
/** 插件源码的哈希,安装/更新时记进安装记录 */
|
|
10
|
+
hash: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function fetchPlugin(source: PluginSourceSpec, staging: string, subdir?: string, log?: (text: string) => void): Promise<Fetched>;
|
|
13
|
+
/** 读一个插件目录的 plugin.json;不是插件时给出能看懂的错误 */
|
|
14
|
+
export declare function readPluginManifest(dir: string): Promise<Manifest>;
|
|
15
|
+
/** 把 --path 限制在来源目录里,不能跑到外面去 */
|
|
16
|
+
export declare function inSubdir(root: string, subdir: string): string;
|
|
17
|
+
/** npm 的 node 脚本;没有 npm 时返回 undefined */
|
|
18
|
+
export declare function npmCommand(): string[] | undefined;
|
|
19
|
+
/** 在 PATH 里找一个可执行文件;Windows 上按 PATHEXT 补扩展名 */
|
|
20
|
+
export declare function which(bin: string): string | undefined;
|