@acryldev/manifest 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 acrylblends
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
- # Temporary Holding Version
1
+ # @acryldev/manifest
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The app as data: blend.yaml lists ordered plugin rows with config, parameters and on/off switches; validated, composed and locked.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ npm install @acryldev/manifest
9
+ ```
10
+
11
+ It is a Cordis plugin: its peer dependency is `@deepseek-ai/cordis`, and an app registers it as a row of its `blend.yaml`.
12
+
13
+ ## Source and license
14
+
15
+ Part of [ACRYL](https://github.com/acryldev/acryl): [`plugins/manifest`](https://github.com/acryldev/acryl/tree/main/plugins/manifest). MIT license.
package/app-plugins.ts ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * The app's own plugins: the folders of `plugins/` that are not library copies (`plugins/library.json` lists those). A feature is one of them, and
3
+ * `blend.yaml` mounts it with a row of its own (`- id: notes` / `name: notes`), with no import in `src/app.ts`: a row whose name the static registry
4
+ * does not have resolves to the folder of that name here. So `blend.yaml` plus `plugins/` is the whole composition, and a version, a shared app or a
5
+ * blueprint made from the folder starts the same plugins.
6
+ */
7
+ import { existsSync, readdirSync, readFileSync } from 'node:fs'
8
+ import { basename, join } from 'node:path'
9
+ import { pathToFileURL } from 'node:url'
10
+
11
+ /** The file a plugin folder starts from, in the order they are looked for. */
12
+ export const PLUGIN_ENTRIES = ['index.ts', 'index.js', 'index.mjs'] as const
13
+ /** A plugin's name: its folder's name and its Loader row id. */
14
+ const NAME = /^[a-z0-9][a-z0-9-]*$/
15
+
16
+ /** The library copies a plugins folder holds (`library.json`, written by `acrylblends add`); absent or unreadable means none. */
17
+ export function libraryCopies(dir: string): ReadonlySet<string> {
18
+ try {
19
+ const listed = (
20
+ JSON.parse(readFileSync(join(dir, 'library.json'), 'utf8')) as { plugins?: unknown }
21
+ ).plugins
22
+ return new Set(
23
+ Array.isArray(listed)
24
+ ? listed.filter((name): name is string => typeof name === 'string')
25
+ : [],
26
+ )
27
+ } catch {
28
+ return new Set()
29
+ }
30
+ }
31
+
32
+ /** The entry file of a plugin folder, or undefined when it has none. */
33
+ export function pluginEntry(dir: string): string | undefined {
34
+ return PLUGIN_ENTRIES.map((file) => join(dir, file)).find((path) => existsSync(path))
35
+ }
36
+
37
+ /** The names of the app's own plugins in `dir` (the app's `plugins/`): folders with an entry file that are not library copies, sorted. */
38
+ export function appPluginNames(dir: string): string[] {
39
+ if (!existsSync(dir)) return []
40
+ const library = libraryCopies(dir)
41
+ return readdirSync(dir, { withFileTypes: true })
42
+ .filter(
43
+ (entry) =>
44
+ entry.isDirectory() &&
45
+ NAME.test(entry.name) &&
46
+ !library.has(entry.name) &&
47
+ pluginEntry(join(dir, entry.name)) !== undefined,
48
+ )
49
+ .map((entry) => entry.name)
50
+ .sort()
51
+ }
52
+
53
+ /** A plugin module as a row mounts it. */
54
+ export interface AppPluginModule {
55
+ readonly name: string
56
+ readonly apply: (...args: never[]) => unknown
57
+ }
58
+
59
+ /**
60
+ * Import the app's own plugins `names` from `dir`, each checked to be a Cordis plugin whose `name` is its folder's.
61
+ * @throws an error that names the folder and the fix, for a folder that does not export a plugin.
62
+ */
63
+ export async function loadAppPlugins(
64
+ dir: string,
65
+ names: readonly string[],
66
+ ): Promise<Record<string, AppPluginModule>> {
67
+ const loaded: Record<string, AppPluginModule> = {}
68
+ for (const name of names) {
69
+ const entry = pluginEntry(join(dir, name))
70
+ if (entry === undefined) throw new Error(`plugins/${name} has no ${PLUGIN_ENTRIES.join(', ')}`)
71
+ const module = (await import(pathToFileURL(entry).href)) as Partial<AppPluginModule> & {
72
+ default?: Partial<AppPluginModule>
73
+ }
74
+ const plugin = typeof module.apply === 'function' ? module : module.default
75
+ if (plugin === undefined || typeof plugin.apply !== 'function')
76
+ throw new Error(
77
+ `plugins/${name}/${basename(entry)} must export a Cordis plugin: export const name = '${name}' and export function apply(ctx) { ... }`,
78
+ )
79
+ if (plugin.name !== undefined && plugin.name !== name)
80
+ throw new Error(
81
+ `plugins/${name} exports the plugin name "${String(plugin.name)}"; a plugin's name is its folder's, "${name}"`,
82
+ )
83
+ loaded[name] = { ...plugin, name } as AppPluginModule
84
+ }
85
+ return loaded
86
+ }