@uncarved/jade 0.1.2 → 0.2.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/bin/jade.js +5 -4
- 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 -28
- package/dist/index.js +11 -28
- 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 +156 -1223
- 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 +55 -0
- package/dist/update.js +258 -0
- package/dist/update.js.map +1 -0
- package/package.json +12 -9
- package/plugins/approval/index.ts +297 -0
- package/plugins/approval/plugin.json +18 -0
- package/{src/plugins → plugins/approval}/policy.ts +21 -84
- package/plugins/approval/review.ts +192 -0
- 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 +68 -39
- 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 +112 -38
- 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 +3 -4
- package/{src/tools → plugins/fs}/fs.ts +64 -46
- package/{src/tools → plugins/fs}/grep.ts +4 -3
- package/plugins/fs/index.ts +34 -0
- package/plugins/fs/plugin.json +7 -0
- package/plugins/fs/renderers.ts +138 -0
- 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 +79 -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 +198 -0
- package/plugins/models/plugin.json +8 -0
- package/{src → plugins/models}/provider.ts +23 -27
- 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 +142 -0
- package/plugins/print/plugin.json +8 -0
- package/plugins/prompts/index.ts +83 -0
- package/plugins/prompts/plugin.json +8 -0
- package/plugins/prompts/prompts.ts +253 -0
- package/plugins/prompts/sys.ts +72 -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 +36 -21
- package/{src → plugins/shell}/sys.ts +19 -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 +167 -0
- package/plugins/task/plugin.json +15 -0
- package/plugins/task/style.ts +17 -0
- package/plugins/task/subagent.ts +257 -0
- package/{src/tools/todo.ts → plugins/todo/index.ts} +33 -7
- package/plugins/todo/plugin.json +7 -0
- package/{src/ui → plugins/tui}/editor.ts +53 -1
- package/plugins/tui/frontend.ts +596 -0
- package/plugins/tui/index.ts +37 -0
- package/{src/ui → plugins/tui}/markdown.ts +258 -219
- package/plugins/tui/mentions.ts +113 -0
- package/plugins/tui/plugin.json +10 -0
- package/plugins/tui/render.ts +67 -0
- package/plugins/tui/screen.ts +268 -0
- package/{src/ui → plugins/tui}/transcript.ts +179 -111
- package/{src/ui/tui.tsx → plugins/tui/tui.ts} +684 -418
- package/{src/tools → plugins/undo}/checkpoint.ts +21 -60
- package/plugins/undo/index.ts +139 -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/plugins/web/web.ts +713 -0
- package/plugins-dist/approval/index.js +271 -0
- package/plugins-dist/approval/plugin.json +24 -0
- package/{dist/plugins → plugins-dist/approval}/policy.js +15 -65
- package/plugins-dist/approval/review.js +176 -0
- 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 +65 -34
- 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 +95 -33
- 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 +3 -5
- package/{dist/tools → plugins-dist/fs}/fs.js +62 -46
- package/{dist/tools → plugins-dist/fs}/grep.js +4 -4
- package/plugins-dist/fs/index.js +36 -0
- package/plugins-dist/fs/plugin.json +10 -0
- package/plugins-dist/fs/renderers.js +132 -0
- 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 +69 -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 +167 -0
- package/plugins-dist/models/plugin.json +14 -0
- package/{dist → plugins-dist/models}/provider.js +22 -19
- 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 +153 -0
- package/plugins-dist/print/plugin.json +14 -0
- package/plugins-dist/prompts/index.js +57 -0
- package/plugins-dist/prompts/plugin.json +13 -0
- package/plugins-dist/prompts/prompts.js +227 -0
- package/plugins-dist/prompts/sys.js +46 -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 +36 -23
- package/{dist → plugins-dist/shell}/sys.js +20 -44
- 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 +151 -0
- package/plugins-dist/task/plugin.json +23 -0
- package/plugins-dist/task/style.js +14 -0
- package/plugins-dist/task/subagent.js +208 -0
- package/{dist/tools/todo.js → plugins-dist/todo/index.js} +29 -7
- package/plugins-dist/todo/plugin.json +9 -0
- package/{dist/ui → plugins-dist/tui}/editor.js +53 -2
- package/plugins-dist/tui/frontend.js +586 -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 +57 -20
- package/plugins-dist/tui/mentions.js +115 -0
- package/plugins-dist/tui/plugin.json +25 -0
- package/plugins-dist/tui/render.js +61 -0
- package/plugins-dist/tui/screen.js +201 -0
- package/{dist/ui → plugins-dist/tui}/transcript.js +179 -111
- package/{dist/ui → plugins-dist/tui}/tui.js +484 -101
- package/{dist/tools → plugins-dist/undo}/checkpoint.js +21 -55
- package/plugins-dist/undo/index.js +140 -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/plugins-dist/web/web.js +660 -0
- 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 -28
- package/src/install.ts +355 -0
- package/src/main.ts +152 -1263
- 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 -0
- package/LICENSE +0 -21
- package/README.md +0 -198
- package/dist/commands.d.ts +0 -30
- package/dist/commands.js +0 -106
- 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 -104
- package/dist/distro.js +0 -312
- 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 -251
- 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 -22
- package/dist/plugins/builtins.js.map +0 -1
- package/dist/plugins/checks.d.ts +0 -70
- 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 -42
- package/dist/plugins/core.js +0 -190
- package/dist/plugins/core.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 -182
- package/dist/plugins/loader.js +0 -253
- package/dist/plugins/loader.js.map +0 -1
- package/dist/plugins/policy.d.ts +0 -96
- package/dist/plugins/policy.js.map +0 -1
- package/dist/plugins/prompts.d.ts +0 -38
- package/dist/plugins/prompts.js +0 -196
- package/dist/plugins/prompts.js.map +0 -1
- package/dist/plugins/repeats.d.ts +0 -9
- package/dist/plugins/repeats.js +0 -90
- package/dist/plugins/repeats.js.map +0 -1
- package/dist/plugins/review.d.ts +0 -16
- package/dist/plugins/review.js +0 -92
- 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/provider.d.ts +0 -111
- package/dist/provider.js.map +0 -1
- package/dist/sessions.d.ts +0 -22
- package/dist/sessions.js +0 -53
- 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 -48
- package/dist/sys.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 -35
- 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 -35
- package/dist/tools/task.js +0 -89
- 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 -23
- package/dist/tools/web.js +0 -426
- package/dist/tools/web.js.map +0 -1
- package/dist/ui/configure.d.ts +0 -20
- package/dist/ui/configure.js +0 -378
- 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 -33
- package/dist/ui/editor.js.map +0 -1
- package/dist/ui/markdown.d.ts +0 -17
- package/dist/ui/markdown.js.map +0 -1
- package/dist/ui/render.d.ts +0 -15
- package/dist/ui/render.js +0 -94
- package/dist/ui/render.js.map +0 -1
- package/dist/ui/screen.d.ts +0 -98
- package/dist/ui/screen.js +0 -108
- package/dist/ui/screen.js.map +0 -1
- package/dist/ui/transcript.d.ts +0 -33
- package/dist/ui/transcript.js.map +0 -1
- package/dist/ui/tui.d.ts +0 -45
- package/dist/ui/tui.js.map +0 -1
- package/src/commands.ts +0 -120
- package/src/context.ts +0 -64
- package/src/distro.ts +0 -400
- package/src/mentions.ts +0 -135
- package/src/plugin-cli.ts +0 -239
- package/src/plugins/budget.ts +0 -37
- package/src/plugins/builtins.ts +0 -31
- package/src/plugins/core.ts +0 -217
- package/src/plugins/install.ts +0 -429
- package/src/plugins/loader.ts +0 -386
- package/src/plugins/prompts.ts +0 -234
- package/src/plugins/repeats.ts +0 -96
- package/src/plugins/review.ts +0 -109
- package/src/sessions.ts +0 -61
- package/src/tools/task.ts +0 -109
- package/src/tools/web.ts +0 -451
- package/src/ui/configure.ts +0 -408
- package/src/ui/render.ts +0 -83
- package/src/ui/screen.ts +0 -169
- /package/{src/plugins → plugins/approval}/schema.ts +0 -0
- /package/{src → plugins/tui}/history.ts +0 -0
package/src/install.ts
ADDED
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
// 安装、更新、删除用户层或项目层插件(5.4、第 11 节)。
|
|
2
|
+
//
|
|
3
|
+
// 来源可以是本地目录、npm 包或 git 仓库(见 source.ts)。安装先下载到插件目录里的
|
|
4
|
+
// .staging-* 临时目录,检查 plugin.json、装好依赖之后再原子替换正式目录;失败不会留下装了一半的插件。
|
|
5
|
+
// 安装记录写在插件目录的 .installed.json 里(按插件 id),jade plugins update 按记录重新下载。
|
|
6
|
+
//
|
|
7
|
+
// 安装不执行插件的代码;npm 的依赖安装用 --ignore-scripts。
|
|
8
|
+
|
|
9
|
+
import { randomBytes } from "node:crypto";
|
|
10
|
+
import { lstat, mkdir, readFile, rename, rm, rmdir, symlink, unlink, writeFile } from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { hashDir, type TrustStore } from "uncarved";
|
|
13
|
+
import { fetchPlugin, inSubdir, readPluginManifest } from "./fetch.ts";
|
|
14
|
+
import { treeHash } from "./hash.ts";
|
|
15
|
+
import { isPluginId } from "./manifest.ts";
|
|
16
|
+
import { parseSource, type PluginSourceSpec, type SourceKind } from "./source.ts";
|
|
17
|
+
import { forgetFaults, readPluginsConfig, writePluginsConfig } from "./state.ts";
|
|
18
|
+
|
|
19
|
+
/** 用户层/项目层插件的目录名:id 里的 / 换成 __ */
|
|
20
|
+
export const installDir = (root: string, id: string) => path.join(root, id.replaceAll("/", "__"));
|
|
21
|
+
|
|
22
|
+
/** 安装记录:更新时据此重新下载,也用来判断装好的插件有没有被手改过 */
|
|
23
|
+
export interface InstallRecord {
|
|
24
|
+
id: string;
|
|
25
|
+
/** 插件目录名(id 去掉 / 替换后的最后一段) */
|
|
26
|
+
dir: string;
|
|
27
|
+
/** 用户写的来源;本地路径是绝对路径 */
|
|
28
|
+
source: string;
|
|
29
|
+
/** 解析后的来源(git 地址、npm 写法或绝对路径);更新时直接用它,不再按当前目录重新解析 source */
|
|
30
|
+
location?: string;
|
|
31
|
+
kind: SourceKind | "link";
|
|
32
|
+
/** git 的分支、tag 或提交 */
|
|
33
|
+
ref?: string;
|
|
34
|
+
/** 只安装来源里的这个子目录 */
|
|
35
|
+
subdir?: string;
|
|
36
|
+
/** git:安装的提交 */
|
|
37
|
+
commit?: string;
|
|
38
|
+
version?: string;
|
|
39
|
+
/** 安装时插件源码的哈希(不含 node_modules、.git 和包管理器的 lock 文件) */
|
|
40
|
+
hash?: string;
|
|
41
|
+
installedAt: string;
|
|
42
|
+
updatedAt?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface AddOptions {
|
|
46
|
+
/** $JADE_HOME/plugins 或 <仓库>/.jade/plugins */
|
|
47
|
+
root: string;
|
|
48
|
+
/** 解析相对路径用 */
|
|
49
|
+
cwd: string;
|
|
50
|
+
subdir?: string;
|
|
51
|
+
/** 本地目录:建链接而不是复制 */
|
|
52
|
+
link?: boolean;
|
|
53
|
+
/** 已经有同 id 的插件时替换它 */
|
|
54
|
+
force?: boolean;
|
|
55
|
+
/** 装进项目层:装好后把内容哈希写进信任存储 */
|
|
56
|
+
project?: boolean;
|
|
57
|
+
trust?: TrustStore;
|
|
58
|
+
/** 进度(下载、安装依赖) */
|
|
59
|
+
log?: (text: string) => void;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface Added {
|
|
63
|
+
id: string;
|
|
64
|
+
version: string;
|
|
65
|
+
dir: string;
|
|
66
|
+
record: InstallRecord;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export interface UpdateOptions {
|
|
70
|
+
root: string;
|
|
71
|
+
cwd: string;
|
|
72
|
+
/** 覆盖装好后被手动改过的插件 */
|
|
73
|
+
force?: boolean;
|
|
74
|
+
project?: boolean;
|
|
75
|
+
trust?: TrustStore;
|
|
76
|
+
log?: (text: string) => void;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type UpdateStatus = "updated" | "current" | "linked" | "unmanaged" | "modified" | "failed";
|
|
80
|
+
|
|
81
|
+
export interface UpdateResult {
|
|
82
|
+
id: string;
|
|
83
|
+
dir: string;
|
|
84
|
+
status: UpdateStatus;
|
|
85
|
+
from?: string;
|
|
86
|
+
to?: string;
|
|
87
|
+
error?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** 从本地目录、npm 包或 git 仓库安装一个插件 */
|
|
91
|
+
export async function addPlugin(spec: string, opts: AddOptions): Promise<Added> {
|
|
92
|
+
const source = await parseSource(spec, opts.cwd);
|
|
93
|
+
const root = path.resolve(opts.root);
|
|
94
|
+
await mkdir(root, { recursive: true });
|
|
95
|
+
// 先确认安装记录可读,别等插件已经装好才因为一个坏文件报错
|
|
96
|
+
await readRecords(root);
|
|
97
|
+
// 本地来源如果包含插件目录,staging 会被复制进去(甚至递归复制自己)
|
|
98
|
+
if (source.kind === "local") {
|
|
99
|
+
const from = opts.subdir ? inSubdir(source.location, opts.subdir) : path.resolve(source.location);
|
|
100
|
+
const rel = path.relative(from, root);
|
|
101
|
+
const inside = rel === "" || (rel !== ".." && !rel.startsWith(`..${path.sep}`) && !path.isAbsolute(rel));
|
|
102
|
+
if (inside) throw new Error(`${source.location} contains the plugins directory; add the plugin's own directory, or use --path`);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (opts.link) {
|
|
106
|
+
if (source.kind !== "local") throw new Error("--link only works with a local directory");
|
|
107
|
+
return addLinked(source.location, opts, root);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const staging = path.join(root, `.staging-${randomBytes(4).toString("hex")}`);
|
|
111
|
+
try {
|
|
112
|
+
const fetched = await fetchPlugin(source, staging, opts.subdir, opts.log);
|
|
113
|
+
const id = fetched.manifest.id;
|
|
114
|
+
const target = installDir(root, id);
|
|
115
|
+
await replaceDir(root, target, fetched.dir, { force: !!opts.force, label: id });
|
|
116
|
+
const record: InstallRecord = {
|
|
117
|
+
id,
|
|
118
|
+
dir: path.basename(target),
|
|
119
|
+
source: source.kind === "local" ? source.location : source.spec,
|
|
120
|
+
location: source.location,
|
|
121
|
+
kind: source.kind,
|
|
122
|
+
...(source.ref ? { ref: source.ref } : {}),
|
|
123
|
+
...(opts.subdir ? { subdir: opts.subdir } : {}),
|
|
124
|
+
...(fetched.commit ? { commit: fetched.commit } : {}),
|
|
125
|
+
version: fetched.manifest.version,
|
|
126
|
+
hash: fetched.hash,
|
|
127
|
+
installedAt: now(),
|
|
128
|
+
};
|
|
129
|
+
await saveRecord(root, id, record);
|
|
130
|
+
if (opts.project && opts.trust) await trustPlugin(opts.trust, target, opts.log);
|
|
131
|
+
return { id, version: fetched.manifest.version, dir: target, record };
|
|
132
|
+
} finally {
|
|
133
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** --link:本地目录只建一个链接,更新时不用重新下载 */
|
|
138
|
+
async function addLinked(srcDir: string, opts: AddOptions, root: string): Promise<Added> {
|
|
139
|
+
const dir = opts.subdir ? inSubdir(srcDir, opts.subdir) : srcDir;
|
|
140
|
+
const manifest = await readPluginManifest(dir);
|
|
141
|
+
const target = installDir(root, manifest.id);
|
|
142
|
+
const existing = await lstat(target).catch(() => undefined);
|
|
143
|
+
if (existing) {
|
|
144
|
+
if (!opts.force) {
|
|
145
|
+
throw new Error(`plugin ${manifest.id} is already installed in ${target}; run "jade plugins update ${manifest.id}", "jade plugins remove ${manifest.id}", or add --force`);
|
|
146
|
+
}
|
|
147
|
+
await removeDir(target);
|
|
148
|
+
}
|
|
149
|
+
await symlink(dir, target, process.platform === "win32" ? "junction" : "dir");
|
|
150
|
+
const record: InstallRecord = {
|
|
151
|
+
id: manifest.id,
|
|
152
|
+
dir: path.basename(target),
|
|
153
|
+
source: dir,
|
|
154
|
+
kind: "link",
|
|
155
|
+
version: manifest.version,
|
|
156
|
+
installedAt: now(),
|
|
157
|
+
};
|
|
158
|
+
await saveRecord(root, manifest.id, record);
|
|
159
|
+
if (opts.project && opts.trust) await trustPlugin(opts.trust, target, opts.log);
|
|
160
|
+
return { id: manifest.id, version: manifest.version, dir: target, record };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** 按安装记录重新下载;没给名字时更新这个插件目录里所有用 jade plugins add 装的插件 */
|
|
164
|
+
export async function updatePlugins(names: readonly string[], opts: UpdateOptions): Promise<UpdateResult[]> {
|
|
165
|
+
const root = path.resolve(opts.root);
|
|
166
|
+
const records = await readRecords(root);
|
|
167
|
+
const seen = new Set<string>();
|
|
168
|
+
const plan: { record?: InstallRecord; result?: UpdateResult }[] = [];
|
|
169
|
+
|
|
170
|
+
if (names.length === 0) {
|
|
171
|
+
for (const id of Object.keys(records).sort()) plan.push({ record: records[id]! });
|
|
172
|
+
} else {
|
|
173
|
+
for (const name of names) {
|
|
174
|
+
const key = records[name] ? name : Object.keys(records).find((k) => records[k]!.id === name || records[k]!.dir === name);
|
|
175
|
+
if (key) {
|
|
176
|
+
if (!seen.has(key)) {
|
|
177
|
+
seen.add(key);
|
|
178
|
+
plan.push({ record: records[key]! });
|
|
179
|
+
}
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// 没有安装记录:目录存在就说明是手动放进去的,没目录就是没装
|
|
183
|
+
const dir = installDir(root, name);
|
|
184
|
+
const exists = await lstat(dir).catch(() => undefined);
|
|
185
|
+
plan.push({
|
|
186
|
+
result: exists
|
|
187
|
+
? { id: name, dir, status: "unmanaged", error: 'not installed with "jade plugins add"; update it by hand' }
|
|
188
|
+
: { id: name, dir, status: "failed", error: "not installed" },
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const out: UpdateResult[] = [];
|
|
194
|
+
for (const item of plan) out.push(item.result ?? (await updateOne(root, item.record!, opts)));
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async function updateOne(root: string, rec: InstallRecord, opts: UpdateOptions): Promise<UpdateResult> {
|
|
199
|
+
const dir = path.join(root, rec.dir || path.basename(installDir(root, rec.id)));
|
|
200
|
+
if (rec.kind === "link") return { id: rec.id, dir, status: "linked" };
|
|
201
|
+
|
|
202
|
+
const exists = await lstat(dir).catch(() => undefined);
|
|
203
|
+
const staging = path.join(root, `.staging-${randomBytes(4).toString("hex")}`);
|
|
204
|
+
try {
|
|
205
|
+
let modified = false;
|
|
206
|
+
if (exists && rec.hash) modified = (await treeHash(dir)) !== rec.hash;
|
|
207
|
+
|
|
208
|
+
opts.log?.(`${rec.id}: fetching ${rec.source}`);
|
|
209
|
+
const kind = rec.kind as SourceKind;
|
|
210
|
+
// 老记录没有 location,只能按当前目录重新解析;解析出的种类和安装时不同就不更新
|
|
211
|
+
const source: PluginSourceSpec = rec.location
|
|
212
|
+
? { kind, location: rec.location, ...(rec.ref ? { ref: rec.ref } : {}), spec: rec.source }
|
|
213
|
+
: await parseSource(rec.source, opts.cwd);
|
|
214
|
+
if (source.kind !== kind) {
|
|
215
|
+
throw new Error(`${rec.source} was installed as a ${kind} source but now reads as ${source.kind}; remove it and add it again`);
|
|
216
|
+
}
|
|
217
|
+
const fetched = await fetchPlugin(source, staging, rec.subdir, opts.log);
|
|
218
|
+
if (fetched.manifest.id !== rec.id) {
|
|
219
|
+
throw new Error(`plugin id changed from ${rec.id} to ${fetched.manifest.id}; remove it and add it again`);
|
|
220
|
+
}
|
|
221
|
+
const same = rec.kind === "git" ? rec.commit === fetched.commit : rec.kind === "npm" ? rec.version !== undefined && rec.version === fetched.manifest.version : rec.hash === fetched.hash;
|
|
222
|
+
const to = fetched.commit?.slice(0, 7) ?? fetched.manifest.version;
|
|
223
|
+
if (exists && same && !modified) return { id: rec.id, dir, status: "current", to };
|
|
224
|
+
if (exists && modified && !opts.force) {
|
|
225
|
+
return { id: rec.id, dir, status: "modified", error: `changed locally; run "jade plugins update --force ${rec.id}" to replace it` };
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const from = rec.commit?.slice(0, 7) ?? rec.version;
|
|
229
|
+
await replaceDir(root, dir, fetched.dir, { force: true, label: rec.id });
|
|
230
|
+
const next: InstallRecord = { ...rec, version: fetched.manifest.version, hash: fetched.hash, updatedAt: now() };
|
|
231
|
+
if (fetched.commit) next.commit = fetched.commit;
|
|
232
|
+
else delete next.commit;
|
|
233
|
+
await saveRecord(root, rec.id, next);
|
|
234
|
+
if (opts.project && opts.trust) await trustPlugin(opts.trust, dir, opts.log);
|
|
235
|
+
return { id: rec.id, dir, status: "updated", from, to };
|
|
236
|
+
} catch (e) {
|
|
237
|
+
return { id: rec.id, dir, status: "failed", error: e instanceof Error ? e.message : String(e) };
|
|
238
|
+
} finally {
|
|
239
|
+
await rm(staging, { recursive: true, force: true }).catch(() => {});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** 删掉一个插件目录和它的安装记录;链接只删链接本身,不碰它指向的目录 */
|
|
244
|
+
export async function removePlugin(id: string, opts: { root: string }): Promise<string> {
|
|
245
|
+
if (!isPluginId(id)) throw new Error(`refusing to remove ${JSON.stringify(id)}: not a plugin id`);
|
|
246
|
+
const root = path.resolve(opts.root);
|
|
247
|
+
const dir = path.resolve(installDir(root, id));
|
|
248
|
+
const rel = path.relative(root, dir);
|
|
249
|
+
if (rel === "" || rel.startsWith("..") || path.isAbsolute(rel)) throw new Error(`refusing to remove ${dir}: it is not inside ${root}`);
|
|
250
|
+
if (!(await lstat(dir).catch(() => undefined))) throw new Error(`${id} is not installed in ${root}`);
|
|
251
|
+
// 先读出记录再删目录;记录文件坏了就什么都别动
|
|
252
|
+
const records = await readRecords(root);
|
|
253
|
+
await removeDir(dir);
|
|
254
|
+
|
|
255
|
+
const keys = Object.keys(records).filter((k) => k === id || records[k]!.id === id || records[k]!.dir === path.basename(dir));
|
|
256
|
+
for (const key of keys) delete records[key];
|
|
257
|
+
if (keys.length > 0) await writeRecords(root, records);
|
|
258
|
+
return dir;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** 安装记录:<plugins 目录>/.installed.json 的 { plugins: { <id>: InstallRecord } } */
|
|
262
|
+
export async function readRecords(root: string): Promise<Record<string, InstallRecord>> {
|
|
263
|
+
const file = recordsPath(root);
|
|
264
|
+
let raw: unknown;
|
|
265
|
+
try {
|
|
266
|
+
raw = JSON.parse(await readFile(file, "utf8"));
|
|
267
|
+
} catch (e) {
|
|
268
|
+
if ((e as NodeJS.ErrnoException).code === "ENOENT") return {};
|
|
269
|
+
throw new Error(`${file}: ${e instanceof Error ? e.message : String(e)}`);
|
|
270
|
+
}
|
|
271
|
+
const plugins = (raw as { plugins?: unknown } | undefined)?.plugins;
|
|
272
|
+
if (typeof plugins !== "object" || plugins === null || Array.isArray(plugins)) return {};
|
|
273
|
+
const out: Record<string, InstallRecord> = {};
|
|
274
|
+
for (const [id, value] of Object.entries(plugins)) {
|
|
275
|
+
const rec = value as Partial<InstallRecord> | null;
|
|
276
|
+
if (typeof rec?.id !== "string" || typeof rec.source !== "string" || typeof rec.kind !== "string") continue;
|
|
277
|
+
out[id] = { ...rec } as InstallRecord;
|
|
278
|
+
}
|
|
279
|
+
return out;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
async function saveRecord(root: string, id: string, record: InstallRecord): Promise<void> {
|
|
283
|
+
const records = await readRecords(root);
|
|
284
|
+
records[id] = record;
|
|
285
|
+
await writeRecords(root, records);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async function writeRecords(root: string, records: Record<string, InstallRecord>): Promise<void> {
|
|
289
|
+
await mkdir(root, { recursive: true });
|
|
290
|
+
const sorted = Object.fromEntries(Object.entries(records).sort(([a], [b]) => a.localeCompare(b)));
|
|
291
|
+
const file = recordsPath(root);
|
|
292
|
+
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
293
|
+
await writeFile(tmp, `${JSON.stringify({ plugins: sorted }, null, 2)}\n`);
|
|
294
|
+
await rename(tmp, file);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const recordsPath = (root: string) => path.join(root, ".installed.json");
|
|
298
|
+
|
|
299
|
+
/** 原子替换:先把旧目录改名,再把新目录放进来;失败时把旧目录放回去 */
|
|
300
|
+
async function replaceDir(root: string, target: string, incoming: string, opts: { force: boolean; label: string }): Promise<void> {
|
|
301
|
+
const existing = await lstat(target).catch(() => undefined);
|
|
302
|
+
if (existing && !opts.force) {
|
|
303
|
+
throw new Error(`plugin ${opts.label} is already installed in ${target}; run "jade plugins update ${opts.label}", "jade plugins remove ${opts.label}", or add --force`);
|
|
304
|
+
}
|
|
305
|
+
if (!existing) {
|
|
306
|
+
await rename(incoming, target);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const old = path.join(root, `.old-${randomBytes(4).toString("hex")}`);
|
|
310
|
+
await rename(target, old);
|
|
311
|
+
try {
|
|
312
|
+
await rename(incoming, target);
|
|
313
|
+
} catch (e) {
|
|
314
|
+
await rename(old, target).catch(() => {});
|
|
315
|
+
throw e;
|
|
316
|
+
}
|
|
317
|
+
await removeDir(old);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** 链接(包括 Windows 的 junction)只删链接本身 */
|
|
321
|
+
async function removeDir(p: string): Promise<void> {
|
|
322
|
+
const info = await lstat(p);
|
|
323
|
+
if (info.isSymbolicLink()) {
|
|
324
|
+
await unlink(p).catch(async () => {
|
|
325
|
+
await rmdir(p);
|
|
326
|
+
});
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
await rm(p, { recursive: true, force: true });
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** 项目层插件装好后记下内容哈希,下次启动不用再问;记不下时只提示,安装本身算成功 */
|
|
333
|
+
async function trustPlugin(trust: TrustStore, dir: string, log?: (text: string) => void): Promise<void> {
|
|
334
|
+
try {
|
|
335
|
+
const root = path.resolve(dir);
|
|
336
|
+
const { hash } = await hashDir(root);
|
|
337
|
+
if (!(await trust.has(hash))) await trust.add({ hash, path: root, at: now() });
|
|
338
|
+
} catch (e) {
|
|
339
|
+
log?.(`installed, but could not record trust: ${e instanceof Error ? e.message : String(e)}; jade will ask on the next launch`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/** 安装、删除之后清掉这个 id 的停用记录和连续崩溃记录;返回它原来是不是被用户停用了 */
|
|
344
|
+
export async function forgetPluginState(home: string, id: string): Promise<boolean> {
|
|
345
|
+
const config = await readPluginsConfig(home);
|
|
346
|
+
const wasDisabled = config.disabled.includes(id);
|
|
347
|
+
if (wasDisabled) {
|
|
348
|
+
config.disabled = config.disabled.filter((d) => d !== id);
|
|
349
|
+
await writePluginsConfig(home, config);
|
|
350
|
+
}
|
|
351
|
+
await forgetFaults(home, id);
|
|
352
|
+
return wasDisabled;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const now = () => new Date().toISOString();
|