@acryldev/plugin-hub 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +14 -2
- package/cordis.patch.yml +3 -0
- package/index.js +232 -0
- package/manager.js +90 -0
- package/package.json +44 -3
- package/release-spec.js +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 WebBoxes s.r.o.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @acryldev/plugin-hub
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Save, share and pull plugins from inside an app (spec 044, `specs/044-extension-persistence-and-registries/lifecycle.md`). Part of every Blend's
|
|
4
|
+
base kit; the operations themselves are `@acryldev/plugin-hub-core`'s.
|
|
5
|
+
|
|
6
|
+
- **`pluginHub` service**: `saved()`, `save(folder)`, `bump(folder, 'patch'|'minor'|'major')`, `pull(source)`, `share(folder, options)`,
|
|
7
|
+
`publishNpm(folder, options)`, `installed()`. The store is the app instance's (`<instance home>/plugins/store`).
|
|
8
|
+
- **`/plugin`** in the chat: `list | saved | save <name> | share <name> [public] [owner/repo] | share <name> npm [public] [registry URL] | pull <source> |
|
|
9
|
+
version patch <name>`. npm uses the user's own npm login and `.npmrc` (scoped registries too); a private plugin needs a scope (`@owner/name`).
|
|
10
|
+
- **`acryl_plugins`** for the agent (`to: "npm"` or `"npm:<registry URL>"` publishes to npm): saving and versioning run directly; sharing and pulling from anywhere but the store ask the user in the
|
|
11
|
+
app first (DSH's approval), and nothing proceeds without "allow once".
|
|
12
|
+
- **`@acryldev/plugin-hub/manager`**: DSH's plugin manager with the hub in front of it. It takes the place of DSH's `plugin-manager` row, so DSH's
|
|
13
|
+
own "Add plugin" box installs a GitHub address as its latest release, fetched and checked by the hub; everything else is DSH's.
|
|
14
|
+
|
|
15
|
+
Requires `appInstance`. Optional: `pluginManager` (the installer), `commands`, `tools`, `approval`.
|
package/cordis.patch.yml
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @acryldev/plugin-hub: saving, sharing and pulling plugins inside an app (spec 044, `specs/044-extension-persistence-and-registries/lifecycle.md`,
|
|
3
|
+
* layer 2 over `@acryldev/plugin-hub-core`).
|
|
4
|
+
*
|
|
5
|
+
* Provides `pluginHub`, the one service every face drives (the `/plugin` chat command here, `acryl plugin` on the CLI, the agent tools and the
|
|
6
|
+
* Plugins page later), so a result is the same whichever face asked:
|
|
7
|
+
*
|
|
8
|
+
* saved() every version in this app instance's plugin store
|
|
9
|
+
* save(folder) pack a plugin you edit and keep that version
|
|
10
|
+
* pull(source, { install }) fetch, check the sha512, check the services the plugin needs against this app, keep it, install it
|
|
11
|
+
* bump(folder, 'patch'|...) give a fix its new version
|
|
12
|
+
* installed() the profile's plugins as DSH's plugin manager lists them, with their versions
|
|
13
|
+
*
|
|
14
|
+
* The operations are `@acryldev/plugin-hub-core`'s `createPluginHub`; this plugin supplies the app's side of them.
|
|
15
|
+
*
|
|
16
|
+
* Installing is DSH's `pluginManager.installBundle` on the stored tarball (D1): the same installer stock DSH uses, with its compatibility check
|
|
17
|
+
* and its approval of install scripts. This plugin never runs a package manager itself.
|
|
18
|
+
*
|
|
19
|
+
* Requires: `appInstance` (the home the store lives under). Optional: `pluginManager` (without it a pull only stores and says so) and
|
|
20
|
+
* `commands` (the chat command).
|
|
21
|
+
*/
|
|
22
|
+
import { join } from 'node:path'
|
|
23
|
+
import { defineTool } from '@deepseek-ai/dsh-tools'
|
|
24
|
+
import { createPluginHub, findSourceFolder, firstRegistryPort, homePluginsDir, projectPluginsDir, firstReleasePort, gitCli, githubCli, githubReleasesOverHttps, githubReleasesViaGh, npmCli, npmRegistryViaCli, httpsDownload, npmRegistryOverHttps, PluginStore, storeRootOf } from '@acryldev/plugin-hub-core'
|
|
25
|
+
|
|
26
|
+
export const name = 'acryl-plugin-hub'
|
|
27
|
+
export const inject = ['appInstance']
|
|
28
|
+
|
|
29
|
+
/** Where this app instance keeps its plugin store (`storeRootOf`: per instance, never machine-wide). */
|
|
30
|
+
export function storeRoot(instance) {
|
|
31
|
+
return storeRootOf(instance.home)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Where plugins you edit live: the session's project folder, then the app instance's own (`@acryldev/plugin-hub-core` folders, moved there once from the old names). */
|
|
35
|
+
export function sourceRoots({ workspaceDir, home }) {
|
|
36
|
+
return [workspaceDir === undefined ? undefined : projectPluginsDir(workspaceDir), home === undefined ? undefined : homePluginsDir(home)]
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const USAGE = 'Usage: /plugin list | saved | save <name or folder> | share <name or folder> [public] [owner/repo] | share <name> npm [public] [registry URL] | pull <source> | update <name> | version patch|minor|major <name or folder>. A source is store:<name>[@version], github:<owner>/<repo>[@version], npm:<name>[@version], a .tgz file or https URL.'
|
|
40
|
+
|
|
41
|
+
function describePull(result) {
|
|
42
|
+
const id = `${result.name} ${result.version}`
|
|
43
|
+
switch (result.status) {
|
|
44
|
+
case 'installed': return { kind: 'success', text: `Installed ${id} (${result.integrity.slice(0, 19)}...), kept in the plugin store.${result.contractChecked ? '' : ' It declares no service contract, so a missing service would only show as PENDING.'}` }
|
|
45
|
+
case 'restart-required': return { kind: 'success', text: `Installed ${id}; restart the app to load this version.` }
|
|
46
|
+
case 'stored': return { kind: 'success', text: `Kept ${id} in the plugin store${result.reason === undefined ? '' : `, not installed: ${result.reason}`}.` }
|
|
47
|
+
case 'missing-services': return { kind: 'error', text: `Not installed: ${id} needs ${result.missing.join(', ')}, which this app does not provide. It is kept in the plugin store (store:${result.name}@${result.version}), so it can be installed offline in an app that has those services.` }
|
|
48
|
+
default: return { kind: 'error', text: `Not installed: ${id} (${result.outcome?.error?.code ?? result.status}). ${result.outcome?.packageResult?.output?.split('\n').slice(-3).join(' ') ?? ''}`.trim() }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function describeUpdate(result) {
|
|
53
|
+
switch (result.status) {
|
|
54
|
+
case 'updated': return { kind: 'success', text: `Updated ${result.name} ${result.from} -> ${result.to} from ${result.source}.` }
|
|
55
|
+
case 'restart-required': return { kind: 'success', text: `Installed ${result.name} ${result.to} (was ${result.from}); restart the app to load it.` }
|
|
56
|
+
case 'up-to-date': return { kind: 'success', text: `${result.name} ${result.version} is the newest release of ${result.source}.` }
|
|
57
|
+
case 'not-updatable': return { kind: 'error', text: `Not updated: ${result.reason}.` }
|
|
58
|
+
default: return describePull(result.pull)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** The `/plugin` command's behaviour, apart from Cordis. */
|
|
63
|
+
export async function runPluginCommand(rawInput, hub, where) {
|
|
64
|
+
const [verb = '', ...rest] = String(rawInput ?? '').trim().split(/\s+/u).filter(Boolean)
|
|
65
|
+
try {
|
|
66
|
+
if (verb === 'saved') {
|
|
67
|
+
const saved = hub.saved()
|
|
68
|
+
return { kind: 'success', text: saved.length === 0 ? 'The plugin store is empty. Save a plugin with /plugin save <name>.' : saved.map(entry => `${entry.name} ${entry.version} from ${entry.from}`).join('\n') }
|
|
69
|
+
}
|
|
70
|
+
if (verb === 'list') {
|
|
71
|
+
const installed = await hub.installed()
|
|
72
|
+
const saved = hub.saved()
|
|
73
|
+
const lines = installed === undefined ? ['Installed: not available here (DSH\'s plugin manager is not loaded).'] : ['Installed:', ...installed.map(entry => ` ${entry.name} ${entry.version ?? '(no version)'}${entry.enabled ? '' : ' (off)'}`)]
|
|
74
|
+
lines.push(`Saved on this machine: ${saved.length === 0 ? 'none' : ''}`, ...saved.map(entry => ` ${entry.name} ${entry.version}`))
|
|
75
|
+
return { kind: 'success', text: lines.join('\n') }
|
|
76
|
+
}
|
|
77
|
+
if (verb === 'save' || verb === 'version') {
|
|
78
|
+
const bump = verb === 'version' ? rest.shift() : undefined
|
|
79
|
+
if (verb === 'version' && !['patch', 'minor', 'major'].includes(bump)) return { kind: 'error', text: USAGE }
|
|
80
|
+
const target = rest.join(' ')
|
|
81
|
+
if (target === '') return { kind: 'error', text: USAGE }
|
|
82
|
+
const folder = findSourceFolder(target, sourceRoots(where))
|
|
83
|
+
if (folder === undefined) return { kind: 'error', text: `No plugin folder named ${JSON.stringify(target)} in this project's .acryl-plugins/ or the app's plugins/; give its absolute folder.` }
|
|
84
|
+
if (verb === 'version') {
|
|
85
|
+
const bumped = hub.bump(folder, bump)
|
|
86
|
+
return { kind: 'success', text: `${bumped.name}: ${bumped.from} -> ${bumped.to}. Install it again to run it, and save or share it to keep the new version.` }
|
|
87
|
+
}
|
|
88
|
+
const saved = hub.save(folder)
|
|
89
|
+
return { kind: 'success', text: saved.added ? `Saved ${saved.name} ${saved.version} (${saved.files.length} files) to the plugin store.` : `${saved.name} ${saved.version} is already saved with exactly these files.` }
|
|
90
|
+
}
|
|
91
|
+
if (verb === 'share' && rest.includes('npm')) {
|
|
92
|
+
// `/plugin share <name> npm [public] [registry URL]`: publish to an npm registry instead of GitHub.
|
|
93
|
+
const isPublic = rest.includes('public')
|
|
94
|
+
const words = rest.filter(word => word !== 'public' && word !== 'npm')
|
|
95
|
+
const target = words[0]
|
|
96
|
+
if (target === undefined || words.length > 2 || (words[1] !== undefined && !/^https?:\/\/\S+$/u.test(words[1]))) return { kind: 'error', text: USAGE }
|
|
97
|
+
const folder = findSourceFolder(target, sourceRoots(where))
|
|
98
|
+
if (folder === undefined) return { kind: 'error', text: `No plugin folder named ${JSON.stringify(target)} in this project's .acryl-plugins/ or the app's plugins/; give its absolute folder.` }
|
|
99
|
+
const result = await hub.publishNpm(folder, { ...(words[1] ? { registry: words[1] } : {}), ...(isPublic ? { visibility: 'public' } : {}) })
|
|
100
|
+
if (result.status === 'refused') return { kind: 'error', text: `Not published: ${result.reason}${(result.secrets ?? []).map(found => `\n- ${found.path}${found.line > 0 ? `:${found.line}` : ''} (${found.kind})`).join('')}` }
|
|
101
|
+
return { kind: 'success', text: `Published ${result.name} ${result.version} to ${result.registry} (${result.access}), ${result.files.length} files.` }
|
|
102
|
+
}
|
|
103
|
+
if (verb === 'share') {
|
|
104
|
+
// `/plugin share <name> [public] [owner[/repo]]`: typed by the user, so it is the user's confirmation (spec 044 guards).
|
|
105
|
+
const isPublic = rest.includes('public')
|
|
106
|
+
const words = rest.filter(word => word !== 'public')
|
|
107
|
+
const target = words[0]
|
|
108
|
+
if (target === undefined || words.length > 2) return { kind: 'error', text: USAGE }
|
|
109
|
+
const folder = findSourceFolder(target, sourceRoots(where))
|
|
110
|
+
if (folder === undefined) return { kind: 'error', text: `No plugin folder named ${JSON.stringify(target)} in this project's .acryl-plugins/ or the app's plugins/; give its absolute folder.` }
|
|
111
|
+
const [owner, repo] = (words[1] ?? '').split('/')
|
|
112
|
+
const result = await hub.share(folder, { ...(owner ? { owner } : {}), ...(repo ? { repo } : {}), ...(isPublic ? { visibility: 'public' } : {}) })
|
|
113
|
+
if (result.status === 'refused') return { kind: 'error', text: `Not shared: ${result.reason}${(result.secrets ?? []).map(found => `\n- ${found.path}${found.line > 0 ? `:${found.line}` : ''} (${found.kind})`).join('')}` }
|
|
114
|
+
return { kind: 'success', text: `Shared ${result.name} ${result.version} to ${result.visibility} ${result.url}${result.created ? ' (new repository)' : ''}: release ${result.tag}, ${result.files.length} files.${result.visibility === 'public' ? ' Catalogs list it by its labels on their next refresh.' : ' Only its collaborators can pull it; type /plugin share ' + target + ' public to list it.'}` }
|
|
115
|
+
}
|
|
116
|
+
if (verb === 'update') {
|
|
117
|
+
if (rest.length !== 1) return { kind: 'error', text: USAGE }
|
|
118
|
+
return describeUpdate(await hub.update(rest[0]))
|
|
119
|
+
}
|
|
120
|
+
if (verb === 'pull') {
|
|
121
|
+
if (rest.length !== 1) return { kind: 'error', text: USAGE }
|
|
122
|
+
return describePull(await hub.pull(rest[0]))
|
|
123
|
+
}
|
|
124
|
+
} catch (cause) {
|
|
125
|
+
return { kind: 'error', text: String(cause?.message ?? cause) }
|
|
126
|
+
}
|
|
127
|
+
return { kind: 'error', text: USAGE }
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The agent's tool, one for every operation so it costs one definition in the prompt (spec 044 D4). Saving, versioning and pulling from the store stay on this machine and run directly. Sharing sends the user's
|
|
132
|
+
* work, and a pull from anywhere else installs code that runs with the user's permissions, so both ask the user through DSH's approval service
|
|
133
|
+
* first; only an explicit "allow once" proceeds, and with nobody to ask (a headless run, the "never" policy) they are refused.
|
|
134
|
+
*/
|
|
135
|
+
export function pluginTools(hub, { approval, where }) {
|
|
136
|
+
const ask = async (exec, reason) => {
|
|
137
|
+
const service = approval()
|
|
138
|
+
if (service === undefined || exec?.agent === undefined) return 'unavailable'
|
|
139
|
+
return service.request({ agent: exec.agent, toolName: 'acryl_plugins', ...(exec.callId === undefined ? {} : { callId: exec.callId }), reason, ...(exec.signal === undefined ? {} : { signal: exec.signal }) })
|
|
140
|
+
}
|
|
141
|
+
const folderOf = (exec, target) => {
|
|
142
|
+
const folder = findSourceFolder(String(target ?? ''), sourceRoots(where(exec)))
|
|
143
|
+
if (folder === undefined) throw new Error(`no plugin folder ${JSON.stringify(target)} in the project's .acryl-plugins/ or the app's plugins/; pass the ABSOLUTE folder`)
|
|
144
|
+
return folder
|
|
145
|
+
}
|
|
146
|
+
const refusedBy = outcome => `the user did not allow it (${outcome}); tell them they can type the /plugin command themselves`
|
|
147
|
+
return [defineTool({
|
|
148
|
+
name: 'acryl_plugins',
|
|
149
|
+
description: 'Save, version, share or pull plugins. share and non-store pulls ask the user first; if refused, give them the /plugin command.',
|
|
150
|
+
parameters: {
|
|
151
|
+
action: { type: 'string', required: true, enum: ['saved', 'save', 'version', 'pull', 'update', 'share'] },
|
|
152
|
+
plugin: { type: 'string', description: 'Folder or name (save, version, share, update).' },
|
|
153
|
+
bump: { type: 'string', enum: ['patch', 'minor', 'major'] },
|
|
154
|
+
source: { type: 'string', description: 'store:, github:o/r[@v], npm:, .tgz (pull).' },
|
|
155
|
+
public: { type: 'boolean' },
|
|
156
|
+
to: { type: 'string', description: 'owner[/repo] or npm[:URL] (share).' },
|
|
157
|
+
},
|
|
158
|
+
output: { schema: { type: 'string' }, render: (_args, value) => [{ type: 'text', text: value }] },
|
|
159
|
+
async execute(args, exec) {
|
|
160
|
+
switch (args.action) {
|
|
161
|
+
case 'saved': return JSON.stringify(hub.saved().map(entry => ({ name: entry.name, version: entry.version, integrity: entry.integrity, from: entry.from })))
|
|
162
|
+
case 'save': return JSON.stringify(hub.save(folderOf(exec, args.plugin)))
|
|
163
|
+
case 'version':
|
|
164
|
+
if (!['patch', 'minor', 'major'].includes(args.bump)) throw new Error('version needs bump: patch, minor or major')
|
|
165
|
+
return JSON.stringify(hub.bump(folderOf(exec, args.plugin), args.bump))
|
|
166
|
+
case 'pull': {
|
|
167
|
+
const source = String(args.source ?? '')
|
|
168
|
+
if (!source.startsWith('store:')) {
|
|
169
|
+
const outcome = await ask(exec, `Install the plugin ${source}: its code runs with your permissions.`)
|
|
170
|
+
if (outcome !== 'allowed-once') throw new Error(refusedBy(outcome))
|
|
171
|
+
}
|
|
172
|
+
return JSON.stringify(await hub.pull(source))
|
|
173
|
+
}
|
|
174
|
+
case 'update': {
|
|
175
|
+
const outcome = await ask(exec, `Update the plugin ${args.plugin} to its newest release: the new code runs with your permissions.`)
|
|
176
|
+
if (outcome !== 'allowed-once') throw new Error(refusedBy(outcome))
|
|
177
|
+
return JSON.stringify(await hub.update(String(args.plugin ?? '')))
|
|
178
|
+
}
|
|
179
|
+
case 'share': {
|
|
180
|
+
const folder = folderOf(exec, args.plugin)
|
|
181
|
+
// `to` names where the plugin goes: a GitHub owner[/repo] (default its own repository), or `npm` / `npm:<registry URL>`.
|
|
182
|
+
const npm = /^npm(?::(.+))?$/u.exec(String(args.to ?? ''))
|
|
183
|
+
const outcome = await ask(exec, `Share the plugin in ${folder} to ${npm !== null ? `npm${npm[1] === undefined ? '' : ` (${npm[1]})`}` : args.to ?? 'its GitHub repository'} (${args.public === true ? 'public: anyone can find and install it' : 'private'}).`)
|
|
184
|
+
if (outcome !== 'allowed-once') throw new Error(refusedBy(outcome))
|
|
185
|
+
if (npm !== null) {
|
|
186
|
+
const published = await hub.publishNpm(folder, { ...(npm[1] === undefined ? {} : { registry: npm[1] }), ...(args.public === true ? { visibility: 'public' } : {}) })
|
|
187
|
+
if (published.status === 'refused') throw new Error(JSON.stringify(published))
|
|
188
|
+
return JSON.stringify(published)
|
|
189
|
+
}
|
|
190
|
+
const [owner, repo] = String(args.to ?? '').split('/')
|
|
191
|
+
const result = await hub.share(folder, { ...(owner ? { owner } : {}), ...(repo ? { repo } : {}), ...(args.public === true ? { visibility: 'public' } : {}) })
|
|
192
|
+
if (result.status === 'refused') throw new Error(JSON.stringify(result))
|
|
193
|
+
return JSON.stringify(result)
|
|
194
|
+
}
|
|
195
|
+
default: throw new Error(`unknown action ${JSON.stringify(args.action)}`)
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
})]
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export function apply(ctx) {
|
|
202
|
+
const hub = createPluginHub({
|
|
203
|
+
store: new PluginStore(storeRoot(ctx.appInstance)),
|
|
204
|
+
// Public repositories anonymously; a private one through the user's own gh login.
|
|
205
|
+
releases: firstReleasePort(githubReleasesOverHttps(), githubReleasesViaGh()),
|
|
206
|
+
// The public registry anonymously; a private registry or scope through the user's own npm configuration.
|
|
207
|
+
registry: firstRegistryPort(npmRegistryOverHttps(), npmRegistryViaCli()),
|
|
208
|
+
npm: npmCli(),
|
|
209
|
+
download: httpsDownload(),
|
|
210
|
+
share: { host: githubCli(), git: gitCli() },
|
|
211
|
+
has: service => ctx.get(service) !== undefined,
|
|
212
|
+
installer: () => ctx.get('pluginManager'),
|
|
213
|
+
})
|
|
214
|
+
ctx.provide('pluginHub', hub)
|
|
215
|
+
|
|
216
|
+
// Human-typed: a pull installs code that runs with the user's permissions, so the user's own command is the confirmation (D4); the agent
|
|
217
|
+
// gets its own tools, which propose instead.
|
|
218
|
+
ctx.inject(['commands'], scoped => {
|
|
219
|
+
scoped.effect(() => scoped.commands.register({
|
|
220
|
+
name: 'plugin',
|
|
221
|
+
description: 'List, save, share, pull or version plugins (store:, github:owner/repo, npm:, a .tgz)',
|
|
222
|
+
input: { hint: 'list | saved | save <name> | share <name> [public] | pull <source> | update <name> | version patch <name>' },
|
|
223
|
+
async handler(invocation) {
|
|
224
|
+
return runPluginCommand(invocation?.rawInput, hub, { workspaceDir: invocation?.agent?.session?.header?.cwd, home: ctx.appInstance.home })
|
|
225
|
+
},
|
|
226
|
+
}), '@acryldev/plugin-hub: /plugin command')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
ctx.inject(['tools'], scoped => {
|
|
230
|
+
for (const tool of pluginTools(hub, { approval: () => ctx.get('approval'), where: exec => ({ workspaceDir: exec?.agent?.session?.header?.cwd, home: ctx.appInstance.home }) })) scoped.tools.register(tool)
|
|
231
|
+
})
|
|
232
|
+
}
|
package/manager.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DSH's plugin manager with ACRYL's pull in front of it (spec 044, `specs/044-extension-persistence-and-registries/lifecycle.md`, D7 option B).
|
|
3
|
+
*
|
|
4
|
+
* DSH's Plugins page calls `pluginManager.inspect(spec)` and `.installBundle(spec)` with whatever the person typed, and pnpm would clone a git
|
|
5
|
+
* address and install whatever its branch holds. Inside ACRYL a git address instead means that repository's latest release: it is fetched into
|
|
6
|
+
* the plugin store, its sha512 kept and the services it needs checked, and DSH's own installer then installs that tarball. A repository with no
|
|
7
|
+
* release, a branch or commit, or a git host other than GitHub is refused on the page with the reason. Names, folders and tarballs go to DSH's
|
|
8
|
+
* manager unchanged, so everything else (compatibility checks, script approval, live reload, listing, enabling) stays DSH's.
|
|
9
|
+
*
|
|
10
|
+
* Enabling and disabling have one store (spec 001 T089): a row ACRYL's plugin lifecycle admits is listed to DSH's page as one it can switch,
|
|
11
|
+
* and the page's switch goes through that lifecycle (applied live, kept in ACRYL's override file), never into the profile's patch file, where
|
|
12
|
+
* a second, contradicting disable used to be written. Rows ACRYL does not admit (DSH's own) stay DSH's, written as DSH writes them.
|
|
13
|
+
*
|
|
14
|
+
* The profile swaps DSH's `plugin-manager` row for this one rather than adding a second provider (Cordis refuses two). The class extends
|
|
15
|
+
* DSH's: its `@Remote` markers are written onto the prototype of the instance being constructed, so the page reaches these overrides.
|
|
16
|
+
*/
|
|
17
|
+
import { PluginManager } from '@deepseek-ai/dsh-plugin-manager'
|
|
18
|
+
import { createPluginHub, firstReleasePort, githubReleasesOverHttps, githubReleasesViaGh, PluginStore, storeRootOf } from '@acryldev/plugin-hub-core'
|
|
19
|
+
import { releaseSpec } from './release-spec.js'
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The hub a manager pulls through: the app instance's store, GitHub releases, and the contract checked against this app. A module function, not a
|
|
23
|
+
* `#private` method: Cordis calls a service through a proxy, and a private member is not reachable through it ("Receiver must be an instance").
|
|
24
|
+
*/
|
|
25
|
+
function hubOf(ctx) {
|
|
26
|
+
return createPluginHub({
|
|
27
|
+
store: new PluginStore(storeRootOf(ctx.appInstance.home)),
|
|
28
|
+
releases: firstReleasePort(githubReleasesOverHttps(), githubReleasesViaGh()),
|
|
29
|
+
has: service => ctx.get(service) !== undefined,
|
|
30
|
+
installer: () => undefined,
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The row ACRYL's lifecycle admits to user control for this Loader entry, or undefined (no lifecycle here, or DSH's own row). */
|
|
35
|
+
function admitted(ctx, entryId) {
|
|
36
|
+
const lifecycle = ctx.get('acrPluginLifecycle')
|
|
37
|
+
const entry = lifecycle?.snapshot().entries.find(candidate => candidate.entryId === entryId)
|
|
38
|
+
return entry?.mutable === true ? lifecycle : undefined
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default class AcrylPluginManager extends PluginManager {
|
|
42
|
+
static inject = [...PluginManager.inject, 'appInstance']
|
|
43
|
+
|
|
44
|
+
async inspect(spec, options, signal) {
|
|
45
|
+
const resolved = await releaseSpec(spec, hubOf(this.ctx))
|
|
46
|
+
// `unknown` is the problem DSH's page shows with its reason ("The plugin could not be looked up: <reason>"); the others show a fixed text.
|
|
47
|
+
if (resolved.refused !== undefined) return { status: 'refused', problem: 'unknown', reason: resolved.refused }
|
|
48
|
+
const inspection = await super.inspect(resolved.spec, options, signal)
|
|
49
|
+
if (resolved.pulled === undefined || inspection.status !== 'accepted') return inspection
|
|
50
|
+
return { ...inspection, name: resolved.pulled.name, version: resolved.pulled.version }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async installBundle(spec, options) {
|
|
54
|
+
const resolved = await releaseSpec(spec, hubOf(this.ctx))
|
|
55
|
+
if (resolved.refused !== undefined) {
|
|
56
|
+
return { changed: false, application: 'failed', stage: 'install', target: String(spec), error: { code: 'invalid-spec', diagnostic: resolved.refused } }
|
|
57
|
+
}
|
|
58
|
+
return super.installBundle(resolved.spec, options)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async listPlugins() {
|
|
62
|
+
const rows = await super.listPlugins()
|
|
63
|
+
const lifecycle = this.ctx.get('acrPluginLifecycle')
|
|
64
|
+
if (lifecycle === undefined) return rows
|
|
65
|
+
const mutable = new Set(lifecycle.snapshot().entries.filter(entry => entry.mutable).map(entry => entry.entryId))
|
|
66
|
+
return rows.map(row => {
|
|
67
|
+
if (!mutable.has(row.entryId) || row.readOnlyReason === 'management-required') return row
|
|
68
|
+
const { readOnlyReason: _unaddressable, ...rest } = row
|
|
69
|
+
return { ...rest, patchId: row.patchId ?? row.entryId.replace(/^include:/u, '') }
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
async setPluginEnabled(id, enabled) {
|
|
74
|
+
const lifecycle = admitted(this.ctx, id)
|
|
75
|
+
if (lifecycle === undefined) return super.setPluginEnabled(id, enabled)
|
|
76
|
+
const result = { stage: 'enable', target: id, enabled, changed: false, application: 'applied' }
|
|
77
|
+
try {
|
|
78
|
+
await lifecycle.setEnabled(id, enabled)
|
|
79
|
+
result.changed = true
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// Already in the asked state is not a failure: the page shows the row as it is.
|
|
82
|
+
if (error?.code !== 'already-enabled' && error?.code !== 'already-disabled') {
|
|
83
|
+
result.application = 'failed'
|
|
84
|
+
result.error = { code: 'operation-error', diagnostic: error instanceof Error ? error.message : String(error) }
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
this.ctx.emit('plugin-manager/changed', { reason: 'plugin' })
|
|
88
|
+
return result
|
|
89
|
+
}
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acryldev/plugin-hub",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Save, share and pull plugins in an app: the pluginHub service (the local store, pulls checked by sha512 and by the services the app provides, installed through DSH's own plugin manager) and the /plugin chat command",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/acryldev/acryl.git",
|
|
9
|
+
"directory": "plugins/plugin-hub"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "./index.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": "./index.js",
|
|
15
|
+
"./manager": "./manager.js",
|
|
16
|
+
"./package.json": "./package.json"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js",
|
|
20
|
+
"manager.js",
|
|
21
|
+
"release-spec.js",
|
|
22
|
+
"cordis.patch.yml",
|
|
23
|
+
"README.md",
|
|
24
|
+
"LICENSE"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": "^22.19.0 || >=24.0.0"
|
|
28
|
+
},
|
|
29
|
+
"dsh": {
|
|
30
|
+
"bundle": {
|
|
31
|
+
"patch": "./cordis.patch.yml"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@deepseek-ai/dsh-plugin-manager": "0.2.0-rc.2",
|
|
36
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
37
|
+
"@acryldev/plugin-hub-core": "0.2.2"
|
|
38
|
+
},
|
|
39
|
+
"homepage": "https://github.com/acryldev/acryl/tree/main/plugins/plugin-hub#readme",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/acryldev/acryl/issues"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"test": "node --test tests/*.test.mjs",
|
|
45
|
+
"check": "pnpm run test"
|
|
46
|
+
}
|
|
6
47
|
}
|
package/release-spec.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// Which spec DSH's installer gets inside ACRYL (spec 044 D7 option B): a git address becomes that GitHub repository's latest release, pulled into
|
|
2
|
+
// the plugin store and checked first; anything else is handed on unchanged. Kept apart from manager.js so it is testable without DSH.
|
|
3
|
+
const SCP = /^git@([^:]+):([^/]+)\/([^/#]+?)(?:\.git)?(#.*)?$/u
|
|
4
|
+
const SHORTHAND = /^(github|gitlab|bitbucket|gist):([^/]+)\/([^/#]+?)(?:\.git)?(#.*)?$/iu
|
|
5
|
+
const URL_FORM = /^(?:git\+)?(?:https?|git|ssh):\/\/(?:[^@/]+@)?([^/:]+)(?::\d+)?\/([^/]+)\/([^/#]+?)(?:\.git)?\/?(#.*)?$/iu
|
|
6
|
+
const SHORTHAND_HOSTS = { github: 'github.com', gitlab: 'gitlab.com', bitbucket: 'bitbucket.org', gist: 'gist.github.com' }
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The repository a git address names, the way pnpm reads DSH's box: `github:o/r`, `git@host:o/r.git`, `git+https://host/o/r.git`,
|
|
10
|
+
* `https://host/o/r` (a repository address, not a .tgz). Undefined for a name, a folder or a tarball.
|
|
11
|
+
*/
|
|
12
|
+
export function gitAddress(spec) {
|
|
13
|
+
const raw = String(spec ?? '').trim()
|
|
14
|
+
if (/\.(?:tgz|tar\.gz)(?:#.*)?$/iu.test(raw)) return undefined
|
|
15
|
+
const short = SHORTHAND.exec(raw)
|
|
16
|
+
if (short !== null) return { host: SHORTHAND_HOSTS[short[1].toLowerCase()], owner: short[2], repo: short[3], ...(short[4] ? { ref: short[4].slice(1) } : {}) }
|
|
17
|
+
const scp = SCP.exec(raw)
|
|
18
|
+
if (scp !== null) return { host: scp[1].toLowerCase(), owner: scp[2], repo: scp[3], ...(scp[4] ? { ref: scp[4].slice(1) } : {}) }
|
|
19
|
+
const url = URL_FORM.exec(raw)
|
|
20
|
+
if (url !== null) return { host: url[1].toLowerCase(), owner: url[2], repo: url[3], ...(url[4] ? { ref: url[4].slice(1) } : {}) }
|
|
21
|
+
return undefined
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* What DSH's installer should get for a spec: the spec itself, or for a git address the stored release tarball; or why it is refused.
|
|
26
|
+
* @returns `{ spec }` to hand on, or `{ refused: reason }`.
|
|
27
|
+
*/
|
|
28
|
+
export async function releaseSpec(spec, hub) {
|
|
29
|
+
const address = gitAddress(spec)
|
|
30
|
+
if (address === undefined) return { spec }
|
|
31
|
+
if (address.host !== 'github.com') return { refused: `ACRYL installs released versions, and finds them on GitHub; ${address.host} is not supported yet. Pull its .tgz file or URL instead.` }
|
|
32
|
+
if (address.ref !== undefined) return { refused: `#${address.ref} is a branch or commit, not a release. Leave it out for the latest release, or use github:${address.owner}/${address.repo}@<version> with /plugin pull.` }
|
|
33
|
+
let pulled
|
|
34
|
+
try { pulled = await hub.pull(`github:${address.owner}/${address.repo}`, { install: false }) } catch (cause) {
|
|
35
|
+
return { refused: String(cause?.message ?? cause) }
|
|
36
|
+
}
|
|
37
|
+
if (pulled.status === 'missing-services') return { refused: `${pulled.name} ${pulled.version} needs ${pulled.missing.join(', ')}, which this app does not provide.` }
|
|
38
|
+
return { spec: pulled.path, pulled }
|
|
39
|
+
}
|