@acryldev/plugin-context 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 +21 -0
- package/README.md +12 -2
- package/docs/README.md +160 -0
- package/docs/delivery/local-live.md +113 -0
- package/docs/delivery/marketplace.md +16 -0
- package/docs/docs.json +2836 -0
- package/docs/extending/agent-preset.md +37 -0
- package/docs/extending/chat-command.md +28 -0
- package/docs/extending/client-slot.md +135 -0
- package/docs/extending/config-schema.md +7 -0
- package/docs/extending/cordis-core.md +63 -0
- package/docs/extending/desktop-app.md +53 -0
- package/docs/extending/desktop-main.md +25 -0
- package/docs/extending/event-hook.md +14 -0
- package/docs/extending/host-route.md +33 -0
- package/docs/extending/llm-adapter.md +38 -0
- package/docs/extending/packaging.md +53 -0
- package/docs/extending/prompt-contribution.md +9 -0
- package/docs/extending/service.md +13 -0
- package/docs/extending/skill-provider.md +9 -0
- package/docs/extending/state-and-persistence.md +71 -0
- package/docs/extending/three-role-capability.md +33 -0
- package/docs/extending/tool-plugin.md +24 -0
- package/docs/extending/tui-command.md +8 -0
- package/docs/extending/tui-components.md +61 -0
- package/docs/extending/ui-branding.md +43 -0
- package/docs/extending/ui-components.md +56 -0
- package/docs/extending/ui-customization.md +41 -0
- package/docs/extending/ui-library.md +66 -0
- package/docs/extending/ui-theme.md +55 -0
- package/docs/extending/workspace-tab.md +50 -0
- package/docs/maps/events.md +108 -0
- package/docs/maps/mount-points.md +154 -0
- package/docs/maps/slot-contracts.md +3376 -0
- package/docs/maps/taxonomy.md +306 -0
- package/docs/maps/theme-tokens.md +115 -0
- package/docs/maps/ui-components.md +26 -0
- package/docs/reference/cookbook/adding-a-package.md +174 -0
- package/docs/reference/cookbook/adding-a-remote-api.md +199 -0
- package/docs/reference/cookbook/adding-a-settings-card.md +74 -0
- package/docs/reference/cookbook/adding-a-tool.md +103 -0
- package/docs/reference/cookbook/adding-an-llm-adapter.md +45 -0
- package/docs/reference/cookbook/extension-cookbook.md +134 -0
- package/docs/reference/cordis-api/context.md +366 -0
- package/docs/reference/cordis-api/events.md +209 -0
- package/docs/reference/cordis-api/fiber.md +377 -0
- package/docs/reference/cordis-api/inherited.md +40 -0
- package/docs/reference/cordis-api/registry.md +154 -0
- package/docs/reference/cordis-api/service.md +104 -0
- package/docs/reference/cordis-guides/cordis-usage-cheatsheet.md +167 -0
- package/docs/reference/cordis-guides/cordis_system_guide_for_coding_agents.md +4666 -0
- package/docs/reference/cordis-guides/development-canvas-plugin.md +109 -0
- package/docs/reference/cordis-guides/hello-world-plugin-guide.md +517 -0
- package/docs/reference/harness/agent-lifecycle.md +93 -0
- package/docs/reference/harness/architecture.md +168 -0
- package/docs/reference/harness/capability-seams.md +675 -0
- package/docs/reference/harness/config-catalog.md +4523 -0
- package/docs/reference/harness/cordis-primer.md +47 -0
- package/docs/reference/harness/defensive-patterns.md +35 -0
- package/docs/reference/harness/event-producer-consumer.md +111 -0
- package/docs/reference/harness/glossary.md +47 -0
- package/docs/reference/harness/tool-catalog.md +2721 -0
- package/docs/reference/harness/tool-execution-pipeline.md +67 -0
- package/docs/reference/subsystems/README.md +75 -0
- package/docs/reference/subsystems/agent-team.md +233 -0
- package/docs/reference/subsystems/approval.md +172 -0
- package/docs/reference/subsystems/attachment.md +363 -0
- package/docs/reference/subsystems/boot.md +324 -0
- package/docs/reference/subsystems/browser-use.md +69 -0
- package/docs/reference/subsystems/client-modules.md +186 -0
- package/docs/reference/subsystems/client-resources.md +94 -0
- package/docs/reference/subsystems/commands.md +225 -0
- package/docs/reference/subsystems/compaction.md +286 -0
- package/docs/reference/subsystems/computer-use.md +58 -0
- package/docs/reference/subsystems/conversation.md +287 -0
- package/docs/reference/subsystems/core.md +1107 -0
- package/docs/reference/subsystems/credentials.md +497 -0
- package/docs/reference/subsystems/deliverables.md +180 -0
- package/docs/reference/subsystems/extensions.md +386 -0
- package/docs/reference/subsystems/feedback.md +402 -0
- package/docs/reference/subsystems/filesystem.md +532 -0
- package/docs/reference/subsystems/goal.md +315 -0
- package/docs/reference/subsystems/invariants.md +90 -0
- package/docs/reference/subsystems/jobs.md +501 -0
- package/docs/reference/subsystems/llm-streaming.md +1131 -0
- package/docs/reference/subsystems/lsp.md +204 -0
- package/docs/reference/subsystems/mcp.md +141 -0
- package/docs/reference/subsystems/office-to-pdf.md +89 -0
- package/docs/reference/subsystems/otel.md +46 -0
- package/docs/reference/subsystems/permission-presets.md +169 -0
- package/docs/reference/subsystems/persistence.md +418 -0
- package/docs/reference/subsystems/plan.md +89 -0
- package/docs/reference/subsystems/product-telemetry.md +81 -0
- package/docs/reference/subsystems/ptc-runtime.md +234 -0
- package/docs/reference/subsystems/sandbox.md +223 -0
- package/docs/reference/subsystems/schedule.md +545 -0
- package/docs/reference/subsystems/scope.md +61 -0
- package/docs/reference/subsystems/session-projection.md +358 -0
- package/docs/reference/subsystems/session-query.md +511 -0
- package/docs/reference/subsystems/session-reference.md +226 -0
- package/docs/reference/subsystems/session-telemetry.md +214 -0
- package/docs/reference/subsystems/session-title.md +206 -0
- package/docs/reference/subsystems/session.md +1300 -0
- package/docs/reference/subsystems/settings.md +157 -0
- package/docs/reference/subsystems/shell.md +316 -0
- package/docs/reference/subsystems/sidebar-right.md +160 -0
- package/docs/reference/subsystems/skills.md +354 -0
- package/docs/reference/subsystems/slots.md +201 -0
- package/docs/reference/subsystems/spill.md +126 -0
- package/docs/reference/subsystems/ssh.md +137 -0
- package/docs/reference/subsystems/storage.md +262 -0
- package/docs/reference/subsystems/subagent.md +762 -0
- package/docs/reference/subsystems/subprocess.md +323 -0
- package/docs/reference/subsystems/system-prompt.md +226 -0
- package/docs/reference/subsystems/terminal.md +186 -0
- package/docs/reference/subsystems/todo.md +34 -0
- package/docs/reference/subsystems/token-meter.md +108 -0
- package/docs/reference/subsystems/tools.md +749 -0
- package/docs/reference/subsystems/typert.md +489 -0
- package/docs/reference/subsystems/user-questions.md +309 -0
- package/docs/reference/subsystems/voice-input.md +166 -0
- package/docs/reference/subsystems/web-client.md +102 -0
- package/docs/reference/subsystems/web-server.md +228 -0
- package/docs/reference/subsystems/web.md +208 -0
- package/docs/reference/subsystems/webhook.md +72 -0
- package/docs/reference/subsystems/workflow.md +280 -0
- package/docs/reference/subsystems/workspace.md +661 -0
- package/docs/start-here/blueprints.md +33 -0
- package/docs/start-here/this-runtime.md +84 -0
- package/docs/start-here/troubleshooting.md +29 -0
- package/docs/start-here/trust-and-safety.md +39 -0
- package/docs/start-here/verify-before-done.md +46 -0
- package/example-plugins/README.md +45 -0
- package/example-plugins/packages/agent-preset-reviewer/agent.cordis.yml +18 -0
- package/example-plugins/packages/agent-preset-reviewer/preset.yml +3 -0
- package/example-plugins/packages/capability-swap-consumer/cordis.patch.yml +3 -0
- package/example-plugins/packages/capability-swap-consumer/index.js +14 -0
- package/example-plugins/packages/capability-swap-consumer/package.json +25 -0
- package/example-plugins/packages/capability-swap-provider-loud/cordis.patch.yml +3 -0
- package/example-plugins/packages/capability-swap-provider-loud/index.js +20 -0
- package/example-plugins/packages/capability-swap-provider-loud/package.json +25 -0
- package/example-plugins/packages/capability-swap-provider-quiet/cordis.patch.yml +3 -0
- package/example-plugins/packages/capability-swap-provider-quiet/index.js +20 -0
- package/example-plugins/packages/capability-swap-provider-quiet/package.json +25 -0
- package/example-plugins/packages/chat-command-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/chat-command-basic/index.js +26 -0
- package/example-plugins/packages/chat-command-basic/package.json +25 -0
- package/example-plugins/packages/client-chat-message-action/client.js +46 -0
- package/example-plugins/packages/client-chat-message-action/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-chat-message-action/index.js +9 -0
- package/example-plugins/packages/client-chat-message-action/package.json +31 -0
- package/example-plugins/packages/client-slot-header-action/client.js +57 -0
- package/example-plugins/packages/client-slot-header-action/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-slot-header-action/index.js +13 -0
- package/example-plugins/packages/client-slot-header-action/package.json +31 -0
- package/example-plugins/packages/client-slot-sidebar-tab/client.js +57 -0
- package/example-plugins/packages/client-slot-sidebar-tab/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-slot-sidebar-tab/index.js +9 -0
- package/example-plugins/packages/client-slot-sidebar-tab/package.json +32 -0
- package/example-plugins/packages/client-theme-override/client.js +52 -0
- package/example-plugins/packages/client-theme-override/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-theme-override/index.js +9 -0
- package/example-plugins/packages/client-theme-override/package.json +30 -0
- package/example-plugins/packages/client-tool-view/client.js +47 -0
- package/example-plugins/packages/client-tool-view/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-tool-view/index.js +24 -0
- package/example-plugins/packages/client-tool-view/package.json +34 -0
- package/example-plugins/packages/client-ui-components/client.js +77 -0
- package/example-plugins/packages/client-ui-components/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-ui-components/index.js +9 -0
- package/example-plugins/packages/client-ui-components/package.json +31 -0
- package/example-plugins/packages/client-ui-library/client.js +715 -0
- package/example-plugins/packages/client-ui-library/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-ui-library/index.js +9 -0
- package/example-plugins/packages/client-ui-library/package.json +37 -0
- package/example-plugins/packages/client-workspace-tab/client.js +72 -0
- package/example-plugins/packages/client-workspace-tab/cordis.patch.yml +3 -0
- package/example-plugins/packages/client-workspace-tab/index.js +9 -0
- package/example-plugins/packages/client-workspace-tab/package.json +30 -0
- package/example-plugins/packages/config-schema-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/config-schema-basic/index.js +19 -0
- package/example-plugins/packages/config-schema-basic/package.json +25 -0
- package/example-plugins/packages/desktop-main-profile-info/cordis.patch.yml +3 -0
- package/example-plugins/packages/desktop-main-profile-info/index.js +22 -0
- package/example-plugins/packages/desktop-main-profile-info/package.json +25 -0
- package/example-plugins/packages/event-hook-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/event-hook-basic/index.js +17 -0
- package/example-plugins/packages/event-hook-basic/package.json +22 -0
- package/example-plugins/packages/generated-capability-template/cordis.patch.yml +3 -0
- package/example-plugins/packages/generated-capability-template/index.js +16 -0
- package/example-plugins/packages/generated-capability-template/package.json +42 -0
- package/example-plugins/packages/host-route-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/host-route-basic/index.js +20 -0
- package/example-plugins/packages/host-route-basic/package.json +29 -0
- package/example-plugins/packages/lifecycle-function-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/lifecycle-function-basic/index.js +12 -0
- package/example-plugins/packages/lifecycle-function-basic/package.json +15 -0
- package/example-plugins/packages/lifecycle-function-hot-shim/cordis.patch.yml +3 -0
- package/example-plugins/packages/lifecycle-function-hot-shim/impl.js +5 -0
- package/example-plugins/packages/lifecycle-function-hot-shim/index.js +18 -0
- package/example-plugins/packages/lifecycle-function-hot-shim/package.json +23 -0
- package/example-plugins/packages/lifecycle-hooks-observer/cordis.patch.yml +3 -0
- package/example-plugins/packages/lifecycle-hooks-observer/index.js +23 -0
- package/example-plugins/packages/lifecycle-hooks-observer/package.json +22 -0
- package/example-plugins/packages/llm-adapter-echo/cordis.patch.yml +3 -0
- package/example-plugins/packages/llm-adapter-echo/index.js +42 -0
- package/example-plugins/packages/llm-adapter-echo/package.json +25 -0
- package/example-plugins/packages/prompt-assemble-hook/cordis.patch.yml +3 -0
- package/example-plugins/packages/prompt-assemble-hook/index.js +22 -0
- package/example-plugins/packages/prompt-assemble-hook/package.json +22 -0
- package/example-plugins/packages/prompt-contribution-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/prompt-contribution-basic/index.js +18 -0
- package/example-plugins/packages/prompt-contribution-basic/package.json +22 -0
- package/example-plugins/packages/service-consumer-greeter/cordis.patch.yml +3 -0
- package/example-plugins/packages/service-consumer-greeter/index.js +14 -0
- package/example-plugins/packages/service-consumer-greeter/package.json +22 -0
- package/example-plugins/packages/service-provider-greeter/cordis.patch.yml +3 -0
- package/example-plugins/packages/service-provider-greeter/index.js +22 -0
- package/example-plugins/packages/service-provider-greeter/package.json +25 -0
- package/example-plugins/packages/settings-section-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/settings-section-basic/index.js +34 -0
- package/example-plugins/packages/settings-section-basic/package.json +26 -0
- package/example-plugins/packages/skill-provider-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/skill-provider-basic/index.js +31 -0
- package/example-plugins/packages/skill-provider-basic/package.json +22 -0
- package/example-plugins/packages/state-host-store/client.js +57 -0
- package/example-plugins/packages/state-host-store/cordis.patch.yml +3 -0
- package/example-plugins/packages/state-host-store/index.js +90 -0
- package/example-plugins/packages/state-host-store/package.json +31 -0
- package/example-plugins/packages/state-workspace-file/cordis.patch.yml +3 -0
- package/example-plugins/packages/state-workspace-file/index.js +52 -0
- package/example-plugins/packages/state-workspace-file/package.json +25 -0
- package/example-plugins/packages/tool-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/tool-basic/index.js +25 -0
- package/example-plugins/packages/tool-basic/package.json +25 -0
- package/example-plugins/packages/tool-policy-hook/cordis.patch.yml +3 -0
- package/example-plugins/packages/tool-policy-hook/index.js +28 -0
- package/example-plugins/packages/tool-policy-hook/package.json +25 -0
- package/example-plugins/packages/tui-command-basic/cordis.patch.yml +3 -0
- package/example-plugins/packages/tui-command-basic/index.js +24 -0
- package/example-plugins/packages/tui-command-basic/package.json +22 -0
- package/example-plugins/packages/tui-overlay-themed/cordis.patch.yml +3 -0
- package/example-plugins/packages/tui-overlay-themed/index.js +65 -0
- package/example-plugins/packages/tui-overlay-themed/package.json +25 -0
- package/example-plugins/packages/tui-ui-library/cordis.patch.yml +3 -0
- package/example-plugins/packages/tui-ui-library/index.js +73 -0
- package/example-plugins/packages/tui-ui-library/package.json +29 -0
- package/example-plugins/packages/web-page-branding/cordis.patch.yml +3 -0
- package/example-plugins/packages/web-page-branding/index.js +31 -0
- package/example-plugins/packages/web-page-branding/package.json +22 -0
- package/example-plugins/scenarios.json +11 -0
- package/index.js +384 -0
- package/lib/blend-apply.js +107 -0
- package/lib/blend-capture.js +249 -0
- package/lib/blend-ledger.js +76 -0
- package/lib/contract.js +5 -0
- package/lib/install.js +516 -0
- package/lib/lookup.js +67 -0
- package/lib/manifest.js +56 -0
- package/lib/pack-root.js +22 -0
- package/lib/provenance.js +110 -0
- package/lib/publish.js +64 -0
- package/lib/reconcile.js +83 -0
- package/lib/router.js +55 -0
- package/lib/scopes.js +82 -0
- package/lib/skills.js +54 -0
- package/lib/stage.js +157 -0
- package/lib/verify.js +77 -0
- package/package.json +58 -3
- package/scripts/lib/indexes.mjs +45 -0
- package/scripts/lib/manifest.mjs +127 -0
- package/scripts/lib/maps.mjs +482 -0
- package/skills/acryl-add-provider-or-capability/SKILL.md +12 -0
- package/skills/acryl-add-ui/SKILL.md +18 -0
- package/skills/acryl-build-plugin/SKILL.md +21 -0
- package/skills/acryl-change-plugin/SKILL.md +16 -0
- package/skills/acryl-desktop-shell/SKILL.md +12 -0
- package/skills/acryl-diagnose-plugin/SKILL.md +10 -0
- package/skills/acryl-fix-plugin/SKILL.md +12 -0
- package/skills/acryl-improve-ui/SKILL.md +10 -0
- package/skills/acryl-remove-plugin/SKILL.md +11 -0
- package/skills/acryl-restyle-ui/SKILL.md +14 -0
- package/skills/acryl-share-plugin/SKILL.md +23 -0
- package/skills/acryl-tui-ui/SKILL.md +12 -0
package/lib/pack-root.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { existsSync } from 'node:fs'
|
|
2
|
+
import { dirname } from 'node:path'
|
|
3
|
+
import { fileURLToPath } from 'node:url'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Root directory of this pack on disk, as a path the agent's file and search
|
|
7
|
+
* tools can actually read. Inside a packaged Desktop app this module is
|
|
8
|
+
* resolved through the virtual `app.asar/...` path, which Electron's own fs
|
|
9
|
+
* can read but child-process tools (search, shell) cannot; the same files also
|
|
10
|
+
* exist under `app.asar.unpacked` (node_modules is asarUnpack'd), so prefer
|
|
11
|
+
* that real path when it exists (spec 037 research Q3).
|
|
12
|
+
* @param {string} [moduleUrl] this package's own module URL (injectable for tests)
|
|
13
|
+
*/
|
|
14
|
+
export function resolvePackRoot(moduleUrl = import.meta.url) {
|
|
15
|
+
const virtualRoot = dirname(dirname(fileURLToPath(moduleUrl)))
|
|
16
|
+
const marker = `app.asar${virtualRoot.includes('\\') ? '\\' : '/'}`
|
|
17
|
+
if (virtualRoot.includes(marker)) {
|
|
18
|
+
const unpacked = virtualRoot.replace('app.asar', 'app.asar.unpacked')
|
|
19
|
+
if (existsSync(unpacked)) return unpacked
|
|
20
|
+
}
|
|
21
|
+
return virtualRoot
|
|
22
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join, sep } from 'node:path'
|
|
3
|
+
import { canonical, stagedInfo } from './reconcile.js'
|
|
4
|
+
import { isProjectPluginPath } from './scopes.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Where an installed plugin came from. Derived from what the profile already records (its package.json dependency spec, the staged install's
|
|
8
|
+
* `acryl-source.json`, the pnpm lockfile); nothing new is written, so it cannot drift from the truth.
|
|
9
|
+
*
|
|
10
|
+
* local built here from a source folder (`file:` install). Editable: has a `source`, a `scope` (project / global / external) and, when staged,
|
|
11
|
+
* the `contentHash` it was installed from. Reproducing it elsewhere needs its source folder.
|
|
12
|
+
* registry installed from npm through the market (a version or range spec). Managed: do not edit; has the resolved `version` and the lockfile
|
|
13
|
+
* `integrity` digest. Reproducing it elsewhere needs only name and version.
|
|
14
|
+
* pulled pulled through the plugin hub (`/plugin pull github:...`, `npm:...`) and installed from the plugin store's tarball (a `file:` spec to
|
|
15
|
+
* `<store>/<name>/<version>.tgz`). Managed like registry: has the `version`, the `from` source it was pulled from and the tarball's sha512
|
|
16
|
+
* `integrity`, read from the store's index. Reproducing it elsewhere is pulling `from` again and checking `integrity`.
|
|
17
|
+
* git installed from a git URL.
|
|
18
|
+
* linked a workspace or link dependency (development checkout).
|
|
19
|
+
* unknown anything else; reported, never guessed at.
|
|
20
|
+
*/
|
|
21
|
+
export const ORIGINS = Object.freeze(['local', 'pulled', 'registry', 'git', 'linked', 'unknown'])
|
|
22
|
+
|
|
23
|
+
/** The pnpm (lockfile v9) view of the root importer's dependencies and package integrity digests. */
|
|
24
|
+
export function readLockfile(profileDir, fs = { existsSync, readFileSync }) {
|
|
25
|
+
const resolved = new Map()
|
|
26
|
+
const integrity = new Map()
|
|
27
|
+
try {
|
|
28
|
+
const file = join(profileDir, 'pnpm-lock.yaml')
|
|
29
|
+
if (!fs.existsSync(file)) return { resolved, integrity }
|
|
30
|
+
const lines = fs.readFileSync(file, 'utf8').split('\n')
|
|
31
|
+
let section = ''
|
|
32
|
+
let current = ''
|
|
33
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
34
|
+
const line = lines[i]
|
|
35
|
+
if (/^[a-z]/u.test(line)) { section = line.replace(/:.*$/u, ''); current = ''; continue }
|
|
36
|
+
if (section === 'importers') {
|
|
37
|
+
const dep = /^ {6}(\S+):$/u.exec(line)
|
|
38
|
+
if (dep) { current = dep[1].replace(/^'|'$/gu, ''); continue }
|
|
39
|
+
const version = /^ {8}version: (.+)$/u.exec(line)
|
|
40
|
+
if (version && current) resolved.set(current, version[1].trim().replace(/^'|'$/gu, ''))
|
|
41
|
+
} else if (section === 'packages') {
|
|
42
|
+
const pkg = /^ {2}'?([^'\s][^']*?)'?:$/u.exec(line)
|
|
43
|
+
if (pkg) { current = pkg[1]; continue }
|
|
44
|
+
const digest = /^ {4}resolution: \{integrity: (\S+?)[,}]/u.exec(line)
|
|
45
|
+
if (digest && current) integrity.set(current, digest[1])
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
} catch { /* an unreadable lockfile only means no digests */ }
|
|
49
|
+
return { resolved, integrity }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The plugin store's record for a `file:` install of one of its tarballs (`<store>/<name>/<version>.tgz`, the layout of plugin-hub's store), or
|
|
54
|
+
* undefined when the path is not a stored tarball of that plugin.
|
|
55
|
+
*/
|
|
56
|
+
export function storeRecordOf(name, installedPath, fs = { existsSync, readFileSync }) {
|
|
57
|
+
const normalized = installedPath.split(sep).join('/')
|
|
58
|
+
const match = new RegExp(`^(.*)/${name.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&')}/([^/]+)\\.tgz$`, 'u').exec(normalized)
|
|
59
|
+
if (match === null) return undefined
|
|
60
|
+
const [, root, version] = match
|
|
61
|
+
try {
|
|
62
|
+
const record = JSON.parse(fs.readFileSync(join(root, 'index.json'), 'utf8'))?.plugins?.[name]?.[version]
|
|
63
|
+
return typeof record?.from === 'string' && typeof record?.integrity === 'string' ? { version, from: record.from, integrity: record.integrity } : undefined
|
|
64
|
+
} catch {
|
|
65
|
+
return undefined
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Origin of one dependency spec. */
|
|
70
|
+
export function originOf(spec) {
|
|
71
|
+
if (typeof spec !== 'string') return 'unknown'
|
|
72
|
+
if (spec.startsWith('file:')) return 'local'
|
|
73
|
+
if (/^(git\+|git:|github:|gitlab:|bitbucket:|https?:.*\.git|[\w.-]+\/[\w.-]+$)/u.test(spec)) return 'git'
|
|
74
|
+
if (spec.startsWith('workspace:') || spec.startsWith('link:')) return 'linked'
|
|
75
|
+
if (/^(npm:|[\^~<>=*]|\d|latest$|next$|[a-z][\w.-]*$)/u.test(spec)) return 'registry'
|
|
76
|
+
return 'unknown'
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Every user-installed plugin of a profile with its provenance.
|
|
81
|
+
* @param {string} profileDir
|
|
82
|
+
* @param {{ globalDir?: string }} [options] the global extensions directory, to tell the global scope from the project scope
|
|
83
|
+
* @returns {Array<{ name: string, origin: string, spec: string, version?: string, integrity?: string, source?: string, installedDir?: string, scope?: string, contentHash?: string }>}
|
|
84
|
+
*/
|
|
85
|
+
export function listInstalledPlugins(profileDir, options = {}, fs = { existsSync, readFileSync }) {
|
|
86
|
+
const manifest = join(profileDir, 'package.json')
|
|
87
|
+
if (!fs.existsSync(manifest)) return []
|
|
88
|
+
const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'))
|
|
89
|
+
const lock = readLockfile(profileDir, fs)
|
|
90
|
+
const globalRoot = options.globalDir ? canonical(options.globalDir) : undefined
|
|
91
|
+
return Object.entries(pkg.dependencies ?? {}).map(([name, spec]) => {
|
|
92
|
+
const origin = originOf(spec)
|
|
93
|
+
if (origin === 'local') {
|
|
94
|
+
const installedDir = spec.slice('file:'.length)
|
|
95
|
+
const stored = storeRecordOf(name, installedDir, fs)
|
|
96
|
+
if (stored !== undefined) return { name, origin: 'pulled', spec, version: stored.version, from: stored.from, integrity: stored.integrity }
|
|
97
|
+
const staged = stagedInfo(installedDir, fs)
|
|
98
|
+
const source = staged?.source ?? installedDir
|
|
99
|
+
const real = canonical(source)
|
|
100
|
+
const scope = globalRoot !== undefined && real.replaceAll('\\', '/').startsWith(`${globalRoot.replaceAll('\\', '/')}/`) ? 'global' : isProjectPluginPath(real) ? 'project' : 'external'
|
|
101
|
+
return { name, origin, spec, source, installedDir, scope, ...(staged?.version ? { contentHash: staged.version } : {}) }
|
|
102
|
+
}
|
|
103
|
+
if (origin === 'registry') {
|
|
104
|
+
const version = lock.resolved.get(name)
|
|
105
|
+
const digest = version === undefined ? undefined : lock.integrity.get(`${name}@${version}`)
|
|
106
|
+
return { name, origin, spec, ...(version ? { version } : {}), ...(digest ? { integrity: digest } : {}) }
|
|
107
|
+
}
|
|
108
|
+
return { name, origin, spec }
|
|
109
|
+
})
|
|
110
|
+
}
|
package/lib/publish.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process'
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs'
|
|
3
|
+
import { isAbsolute, join } from 'node:path'
|
|
4
|
+
import { checkContractShape, syncServiceContract } from './contract.js'
|
|
5
|
+
import { lintPackageDir } from './install.js'
|
|
6
|
+
|
|
7
|
+
const ARTIFACT_KINDS = ['plugins', 'extensions', 'adapters', 'skills', 'workflows', 'blueprints', 'stemcells']
|
|
8
|
+
|
|
9
|
+
/** Marketplace catalog requirements: exact keyword, GitHub repository, license, valid `acryl` manifest. */
|
|
10
|
+
export function checkCatalogMetadata(dir, fs = { existsSync, readFileSync }) {
|
|
11
|
+
const errors = []
|
|
12
|
+
let pkg
|
|
13
|
+
try { pkg = JSON.parse(fs.readFileSync(join(dir, 'package.json'), 'utf8')) } catch { return { errors: ['package.json is missing or invalid'] } }
|
|
14
|
+
if (pkg.private === true) errors.push('"private": true blocks publishing; remove it')
|
|
15
|
+
if (typeof pkg.version !== 'string' || pkg.version === '') errors.push('package.json needs a "version"')
|
|
16
|
+
if (typeof pkg.license !== 'string' || pkg.license === '') errors.push('package.json needs a "license"')
|
|
17
|
+
if (!Array.isArray(pkg.keywords) || !pkg.keywords.includes('acryl-package')) errors.push('"keywords" must include exactly "acryl-package" or the marketplace catalog will not list the package')
|
|
18
|
+
const repo = typeof pkg.repository === 'string' ? pkg.repository : pkg.repository?.url
|
|
19
|
+
if (typeof repo !== 'string' || !/github\.com/u.test(repo)) errors.push('"repository" must point at a GitHub repository')
|
|
20
|
+
const manifest = pkg.acryl
|
|
21
|
+
if (manifest !== undefined) {
|
|
22
|
+
if (manifest.schemaVersion !== 1) errors.push('"acryl.schemaVersion" must be 1')
|
|
23
|
+
const artifacts = manifest.artifacts
|
|
24
|
+
if (typeof artifacts !== 'object' || artifacts === null) errors.push('"acryl.artifacts" must be an object')
|
|
25
|
+
else for (const [kind, paths] of Object.entries(artifacts)) {
|
|
26
|
+
if (!ARTIFACT_KINDS.includes(kind)) errors.push(`unknown artifact kind "${kind}"`)
|
|
27
|
+
else if (!Array.isArray(paths) || paths.some(p => typeof p !== 'string' || p.includes('..') || isAbsolute(p))) errors.push(`"acryl.artifacts.${kind}" must be relative paths without ".."`)
|
|
28
|
+
}
|
|
29
|
+
errors.push(...checkContractShape(manifest))
|
|
30
|
+
}
|
|
31
|
+
return { name: pkg.name, version: pkg.version, errors }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function npmPackDryRun(dir) {
|
|
35
|
+
return new Promise(resolve => {
|
|
36
|
+
execFile('npm', ['pack', '--dry-run', '--json', '--ignore-scripts'], { cwd: dir, timeout: 60_000 }, (error, stdout, stderr) => {
|
|
37
|
+
if (error) return resolve({ ok: false, output: `${stdout}${stderr}`.trim().slice(-600) || String(error.message) })
|
|
38
|
+
try { const [info] = JSON.parse(stdout); resolve({ ok: true, files: info.files?.length ?? 0, size: info.size }) } catch { resolve({ ok: false, output: 'npm pack produced unreadable output' }) }
|
|
39
|
+
})
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Prepare a local plugin for the marketplace WITHOUT publishing: install checks, catalog metadata, the service contract written into
|
|
45
|
+
* package.json from the code (`acryl.requires` / `acryl.provides`, see contract.js) and an `npm pack --dry-run` (needs no credentials, uploads
|
|
46
|
+
* nothing). Publishing is a human step.
|
|
47
|
+
*/
|
|
48
|
+
export async function preparePublish(input, deps = {}) {
|
|
49
|
+
const dir = input.path
|
|
50
|
+
if (typeof dir !== 'string' || !isAbsolute(dir)) return { ok: false, errors: ['path must be the ABSOLUTE package directory'] }
|
|
51
|
+
const lint = lintPackageDir(dir)
|
|
52
|
+
const catalog = checkCatalogMetadata(dir)
|
|
53
|
+
const errors = [...(lint.errors ?? []), ...catalog.errors]
|
|
54
|
+
if (errors.length > 0) return { ok: false, errors, readyForHumanPublish: false }
|
|
55
|
+
const contract = await (deps.syncContract ?? syncServiceContract)(dir)
|
|
56
|
+
if (!contract.ok) return { ok: false, errors: contract.errors, readyForHumanPublish: false }
|
|
57
|
+
const pack = await (deps.pack ?? npmPackDryRun)(dir)
|
|
58
|
+
if (!pack.ok) return { ok: false, errors: [`npm pack --dry-run failed: ${pack.output}`], readyForHumanPublish: false }
|
|
59
|
+
return {
|
|
60
|
+
ok: true, package: catalog.name, version: catalog.version, files: pack.files, readyForHumanPublish: true,
|
|
61
|
+
contract: contract.contract, contractWritten: contract.written,
|
|
62
|
+
next: `Tell the user the package is ready. Publishing is theirs to do (you cannot and must not publish): from ${dir} run \`npm publish --access public\` with their own npm login, then the marketplace lists it after its next catalog refresh.`,
|
|
63
|
+
}
|
|
64
|
+
}
|
package/lib/reconcile.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, realpathSync } from 'node:fs'
|
|
2
|
+
import { basename, dirname, isAbsolute, join } from 'node:path'
|
|
3
|
+
import { currentSourcePath, homePluginsDir } from '@acryldev/plugin-hub-core'
|
|
4
|
+
import { readManifest } from './manifest.js'
|
|
5
|
+
import { SOURCE_FILE } from './stage.js'
|
|
6
|
+
import { projectPluginsDir } from './scopes.js'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The source folder is authoritative; the profile's install list is derived state (pi.dev: "the extension filesystem is authoritative, the
|
|
10
|
+
* runtime registry is ephemeral and reconstructible"). This module answers two questions from the filesystem alone:
|
|
11
|
+
*
|
|
12
|
+
* - WHERE do source plugins live? Two scopes, like pi's `.pi/extensions/` and `~/.pi/agent/extensions/`:
|
|
13
|
+
* project `<workspace>/.acryl-plugins/<name>/` only for that project (and can be committed to its git repository)
|
|
14
|
+
* global `<ACRYL home>/plugins/<name>/` every project and every surface that runs against this ACRYL home
|
|
15
|
+
* Discovery is one level deep (a folder with a package.json is an extension; nothing below it is), paths are compared by real path so a
|
|
16
|
+
* symlink or `../` spelling never loads twice, and on a name clash the project copy wins and the global one is reported as shadowed.
|
|
17
|
+
* - WHAT is the state of an install? in-sync, changed (the source differs from what is installed), or stale (the source is gone).
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** The global plugins directory for an ACRYL home: `<ACRYL home>/plugins` (the DSH home is `<ACRYL home>/.dsh`), moved once from `extensions/`. */
|
|
21
|
+
export function globalPluginsDir(dshHome) {
|
|
22
|
+
if (typeof dshHome !== 'string' || !isAbsolute(dshHome)) return undefined
|
|
23
|
+
return homePluginsDir(basename(dshHome) === '.dsh' ? dirname(dshHome) : dshHome)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Real path, or the path itself when it does not exist (a stale source still needs a stable identity). */
|
|
27
|
+
export function canonical(path, fs = { realpathSync }) {
|
|
28
|
+
try { return fs.realpathSync(path) } catch { return path }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extension folders under the project and global roots.
|
|
33
|
+
* @param {{ workspaceDir?: string, globalDir?: string }} roots
|
|
34
|
+
* @returns {Array<{ name: string, dir: string, scope: 'project' | 'global', shadowed: boolean, permissions?: string[] }>}
|
|
35
|
+
*/
|
|
36
|
+
export function discoverPlugins({ workspaceDir, globalDir }, fs = { existsSync, readdirSync, readFileSync, realpathSync }) {
|
|
37
|
+
const found = []
|
|
38
|
+
const seenDirs = new Set()
|
|
39
|
+
const claimedNames = new Set()
|
|
40
|
+
const roots = [
|
|
41
|
+
['project', workspaceDir && isAbsolute(workspaceDir) ? projectPluginsDir(workspaceDir) : undefined],
|
|
42
|
+
['global', globalDir && isAbsolute(globalDir) ? globalDir : undefined],
|
|
43
|
+
]
|
|
44
|
+
for (const [scope, root] of roots) {
|
|
45
|
+
if (!root || !fs.existsSync(root)) continue
|
|
46
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true }).sort((a, b) => (a.name < b.name ? -1 : 1))) {
|
|
47
|
+
if (!entry.isDirectory() || entry.name.startsWith('.')) continue
|
|
48
|
+
const manifest = join(root, entry.name, 'package.json')
|
|
49
|
+
if (!fs.existsSync(manifest)) continue
|
|
50
|
+
const dir = canonical(join(root, entry.name), fs)
|
|
51
|
+
if (seenDirs.has(dir)) continue
|
|
52
|
+
seenDirs.add(dir)
|
|
53
|
+
let name = entry.name
|
|
54
|
+
let permissions
|
|
55
|
+
try {
|
|
56
|
+
const pkg = JSON.parse(fs.readFileSync(manifest, 'utf8'))
|
|
57
|
+
if (typeof pkg.name === 'string' && pkg.name !== '') name = pkg.name
|
|
58
|
+
permissions = readManifest(pkg).permissions
|
|
59
|
+
} catch { /* lint reports it on install */ }
|
|
60
|
+
found.push({ name, dir, scope, shadowed: claimedNames.has(name), permissions })
|
|
61
|
+
claimedNames.add(name)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return found
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** What a staged install recorded about itself: its source folder and the content hash it was built from. */
|
|
68
|
+
export function stagedInfo(installedDir, fs = { existsSync, readFileSync }) {
|
|
69
|
+
try {
|
|
70
|
+
const file = join(installedDir, SOURCE_FILE)
|
|
71
|
+
if (!fs.existsSync(file)) return undefined
|
|
72
|
+
const { source, version } = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
73
|
+
// A source recorded before the folders were renamed is found where it was moved.
|
|
74
|
+
return typeof source === 'string' ? { source: currentSourcePath(source), version: typeof version === 'string' ? version : undefined } : undefined
|
|
75
|
+
} catch { return undefined }
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `in-sync`, `changed`, or `stale` for one installed local plugin, given the source hash function. */
|
|
79
|
+
export function installState(plugin, hashSource, fs = { existsSync }) {
|
|
80
|
+
if (!fs.existsSync(join(plugin.installedFrom, 'package.json'))) return 'stale'
|
|
81
|
+
const recorded = plugin.installedDir ? stagedInfo(plugin.installedDir)?.version : undefined
|
|
82
|
+
return recorded !== undefined && recorded === hashSource(plugin.installedFrom) ? 'in-sync' : 'changed'
|
|
83
|
+
}
|
package/lib/router.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
import { appPluginsDir, projectPluginsLabel } from './scopes.js'
|
|
3
|
+
|
|
4
|
+
/** The router must stay small: it is in every prompt (spec 037 NFR-002). */
|
|
5
|
+
export const ROUTER_TOKEN_BUDGET = 650
|
|
6
|
+
export const ROUTER_SECTION_NAME = 'acryl:plugin-router'
|
|
7
|
+
/** The XML-style tag wrapping the router text, in pi.dev's per-section tag style. */
|
|
8
|
+
export const ROUTER_TAG = 'acryl_plugin_docs'
|
|
9
|
+
/** After the tool sections, before the local-path suffix (harness SECTION_ORDERS: 5000..10000). */
|
|
10
|
+
export const ROUTER_SECTION_ORDER = 9500
|
|
11
|
+
export const INSTALL_TOOL_NAME = 'acryl_install_plugin'
|
|
12
|
+
export const LIST_TOOL_NAME = 'acryl_list_plugins'
|
|
13
|
+
export const REMOVE_TOOL_NAME = 'acryl_remove_plugin'
|
|
14
|
+
export const VERIFY_TOOL_NAME = 'acryl_verify_plugin'
|
|
15
|
+
export const LOOKUP_TOOL_NAME = 'acryl_plugin_lookup'
|
|
16
|
+
export const PUBLISH_TOOL_NAME = 'acryl_prepare_publish'
|
|
17
|
+
|
|
18
|
+
export const estimateTokens = text => Math.ceil(text.length / 4)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The docs router for the system prompt, built the way pi.dev builds its `docs` section (packages/coding-agent/src/core/system-prompt.ts):
|
|
22
|
+
* one tagged section that does not contain the architecture but routes the model to it. Paths are resolved at runtime from the installed
|
|
23
|
+
* package; the topic map is inline ("when asked about X (doc)"); the protocol is "read the docs and the nearest example, read .md files
|
|
24
|
+
* completely, follow cross-references before implementing". The topic map is generated from the manifest (`topic` labels), so it cannot
|
|
25
|
+
* drift from the docs. The tag lets the model tell this block from its neighbours, as pi's per-section tags do.
|
|
26
|
+
* @param {string} root pack root on disk
|
|
27
|
+
* @param {{ navigation: Array<{ items: Array<{ id?: string, topic?: string, title: string, path: string, applies: string }> }> }} manifest
|
|
28
|
+
*/
|
|
29
|
+
export function buildRouterText(root, manifest) {
|
|
30
|
+
const pathOf = new Map()
|
|
31
|
+
for (const group of manifest.navigation) for (const item of group.items) if (item.id) pathOf.set(item.id, item.path)
|
|
32
|
+
const topics = []
|
|
33
|
+
if (Array.isArray(manifest.routes)) {
|
|
34
|
+
// Curated routes (pi.dev lists about a dozen "when asked about X (docs)" entries): several docs per route, most important first.
|
|
35
|
+
for (const route of manifest.routes) topics.push(`${route.when} (${route.docs.map(id => pathOf.get(id)).filter(Boolean).join(', ')})`)
|
|
36
|
+
} else {
|
|
37
|
+
for (const group of manifest.navigation) {
|
|
38
|
+
for (const item of group.items) {
|
|
39
|
+
if (item.applies === 'not-for-authors' || item.id?.startsWith('reference.') || item.id?.startsWith('maps.')) continue
|
|
40
|
+
topics.push(`${item.topic ?? (item.title.length > 48 ? `${item.title.slice(0, 45)}...` : item.title)} (${item.path})`)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [
|
|
45
|
+
`<${ROUTER_TAG}>`,
|
|
46
|
+
`ACRYL plugin docs: ${root}. Read only when the user asks to build, change, fix or remove something in ${appPluginsDir() === undefined ? 'ACRYL' : 'this app'} itself (extension, plugin, tool, panel, button, theme, skill, command, provider); or call ${LOOKUP_TOOL_NAME}(topic).`,
|
|
47
|
+
'- Paths below are under docs/; indexes: docs/README.md, example-plugins/README.md (verified plugins); start with start-here/this-runtime.md',
|
|
48
|
+
`- When asked about: ${topics.join(', ')}`,
|
|
49
|
+
"- Read .md files completely and the nearest example, follow links before implementing; never guess a plugin's shape from memory",
|
|
50
|
+
appPluginsDir() === undefined
|
|
51
|
+
? `- Write in ${projectPluginsLabel()} (this project) or <ACRYL home>/plugins/<name>/ (all projects); check with ${VERIFY_TOOL_NAME}; deliver with ${INSTALL_TOOL_NAME} (ABSOLUTE path; again = update). Removing and publish prep have their own tools; publishing is the user's decision. Do not claim it works without the tool result; UI needs a page reload (/reload)`
|
|
52
|
+
: `- This is an app: write every plugin in ${appPluginsDir()}/<name>/ (it loads at every start and is committed with the app); check with ${VERIFY_TOOL_NAME}; deliver with ${INSTALL_TOOL_NAME} (ABSOLUTE path; again = update). Removing and publish prep have their own tools.`,
|
|
53
|
+
`</${ROUTER_TAG}>`,
|
|
54
|
+
].join('\n')
|
|
55
|
+
}
|
package/lib/scopes.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where an ACRYL instance keeps what it authors inside a project (spec 036, "Many instances").
|
|
3
|
+
*
|
|
4
|
+
* An unscoped ACRYL (the default or development app) keeps the classic shared locations: `<workspace>/.acryl-plugins/` and `<workspace>/.acryl/blend/`, which
|
|
5
|
+
* belong to the project and can be committed. An app with a project scope must never leak into, or load from, another app that opens the same folder, so
|
|
6
|
+
* everything it authors lives under `<workspace>/.acryl/instances/<scope>/`. The instance-wide (global) scope is already private: it lives in the app's own home.
|
|
7
|
+
*
|
|
8
|
+
* The scope comes from the runtime's `appInstance` service, configured once when the pack is applied (`useAppInstance`); this module never reads the
|
|
9
|
+
* environment. Invalid scope values are ignored, never used to build a path.
|
|
10
|
+
*/
|
|
11
|
+
import { existsSync } from 'node:fs'
|
|
12
|
+
import { isAbsolute, join } from 'node:path'
|
|
13
|
+
import { HOME_PLUGINS_FOLDER, homePluginsDir, moveFolder, PROJECT_PLUGINS_FOLDER, projectPluginsDir as sharedProjectPluginsDir } from '@acryldev/plugin-hub-core'
|
|
14
|
+
|
|
15
|
+
const SCOPE = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u
|
|
16
|
+
const SCOPE_MAX = 64
|
|
17
|
+
|
|
18
|
+
let active = { projectScope: undefined, appHome: undefined }
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Configure the scopes from the app instance this pack runs in (the `appInstance` service: `{ home, projectScope?, definitionFile? }`). Returns the disposer
|
|
22
|
+
* that restores the previous configuration, so it belongs in an effect.
|
|
23
|
+
*/
|
|
24
|
+
export function useAppInstance(instance, exists = existsSync) {
|
|
25
|
+
const previous = active
|
|
26
|
+
const scope = instance?.projectScope
|
|
27
|
+
active = {
|
|
28
|
+
projectScope: typeof scope === 'string' && scope.length <= SCOPE_MAX && SCOPE.test(scope) ? scope : undefined,
|
|
29
|
+
appHome: typeof instance?.definitionFile === 'string' && typeof instance.home === 'string' && isAbsolute(instance.home) && exists(instance.definitionFile) ? instance.home : undefined,
|
|
30
|
+
}
|
|
31
|
+
return () => { active = previous }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The project scope this app writes under, or undefined for the classic shared locations. */
|
|
35
|
+
export function currentInstance() {
|
|
36
|
+
return active.projectScope
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function instanceRoot(workspaceDir, instance) {
|
|
40
|
+
return join(workspaceDir, '.acryl', 'instances', instance)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** A project's source plugins folder, moved once from its name before the rename (`@acryldev/plugin-hub-core` folders). */
|
|
44
|
+
export function projectPluginsDir(workspaceDir, instance = currentInstance()) {
|
|
45
|
+
if (instance === undefined) return sharedProjectPluginsDir(workspaceDir)
|
|
46
|
+
const dir = join(instanceRoot(workspaceDir, instance), HOME_PLUGINS_FOLDER)
|
|
47
|
+
moveFolder(join(instanceRoot(workspaceDir, instance), 'extensions'), dir)
|
|
48
|
+
return dir
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Captured Blend folder (manifest, lock, vendored sources, ledger). Inside an app it is the app folder itself: an app IS its Blend (one shape for
|
|
53
|
+
* creating, capturing and restoring), whatever project the session has open.
|
|
54
|
+
*/
|
|
55
|
+
export function blendDir(workspaceDir, instance = currentInstance()) {
|
|
56
|
+
if (active.appHome !== undefined) return active.appHome
|
|
57
|
+
return instance === undefined ? join(workspaceDir, '.acryl', 'blend') : join(instanceRoot(workspaceDir, instance), 'blend')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The app folder when this process runs an app from `acryl new`, else undefined. */
|
|
61
|
+
export function appHomeDir() {
|
|
62
|
+
return active.appHome
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Does this real path sit in some project plugins folder (classic or instance-namespaced, under its current or its old name)? */
|
|
66
|
+
export function isProjectPluginPath(path) {
|
|
67
|
+
const slashed = path.replaceAll('\\', '/')
|
|
68
|
+
return slashed.includes(`/${PROJECT_PLUGINS_FOLDER}/`) || slashed.includes('/.acryl-extensions/') || /\/\.acryl\/instances\/[^/]+\/(?:plugins|extensions)\//u.test(slashed)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** How the router names the project location the agent writes to. */
|
|
72
|
+
export function projectPluginsLabel(instance = currentInstance()) {
|
|
73
|
+
return instance === undefined ? `<workspace>/${PROJECT_PLUGINS_FOLDER}/<name>/` : `<workspace>/.acryl/instances/${instance}/${HOME_PLUGINS_FOLDER}/<name>/`
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* An app created by `acryl new` is its own ACRYL home (it has `blend.yaml`). Its plugins belong in `<app>/plugins/`, the home's plugin scope, so they
|
|
78
|
+
* load at every start and are committed with the app. Returns that folder, or undefined outside an app.
|
|
79
|
+
*/
|
|
80
|
+
export function appPluginsDir() {
|
|
81
|
+
return active.appHome === undefined ? undefined : homePluginsDir(active.appHome)
|
|
82
|
+
}
|
package/lib/skills.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { existsSync, readdirSync, readFileSync } from 'node:fs'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
const BUNDLED_RANK = 600
|
|
5
|
+
|
|
6
|
+
/** Minimal frontmatter reader: `---\nname: x\ndescription: y\n---\nbody`. */
|
|
7
|
+
export function parseSkill(text) {
|
|
8
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/u.exec(text)
|
|
9
|
+
if (!match) return undefined
|
|
10
|
+
const meta = {}
|
|
11
|
+
for (const line of match[1].split(/\r?\n/u)) {
|
|
12
|
+
const kv = /^([a-z-]+):\s*(.*)$/u.exec(line)
|
|
13
|
+
if (kv) meta[kv[1]] = kv[2].trim()
|
|
14
|
+
}
|
|
15
|
+
if (!meta.name || !meta.description) return undefined
|
|
16
|
+
return { name: meta.name, description: meta.description, body: match[2] }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A SkillProvider over `<root>/skills/<name>/SKILL.md`, the same seam pi.dev's skills use:
|
|
21
|
+
* only name and description sit in context; the body loads on demand. `{{pack}}` in a body
|
|
22
|
+
* is replaced by the pack root so its doc links are real paths. Rank is the bundled rank, so
|
|
23
|
+
* a project or user skill of the same name overrides it.
|
|
24
|
+
*/
|
|
25
|
+
export function createSkillProvider(root, fs = { existsSync, readdirSync, readFileSync }) {
|
|
26
|
+
const dir = join(root, 'skills')
|
|
27
|
+
const read = () => {
|
|
28
|
+
if (!fs.existsSync(dir)) return []
|
|
29
|
+
return fs.readdirSync(dir)
|
|
30
|
+
.map(entry => ({ entry, parsed: parseSkill(safeRead(fs, join(dir, entry, 'SKILL.md'))) }))
|
|
31
|
+
.filter(item => item.parsed !== undefined)
|
|
32
|
+
}
|
|
33
|
+
const candidateOf = ({ parsed }) => ({
|
|
34
|
+
name: parsed.name,
|
|
35
|
+
description: parsed.description,
|
|
36
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
37
|
+
provider: 'acryl-plugin-skills',
|
|
38
|
+
source: 'bundled',
|
|
39
|
+
rank: BUNDLED_RANK,
|
|
40
|
+
})
|
|
41
|
+
return {
|
|
42
|
+
name: 'acryl-plugin-skills',
|
|
43
|
+
list: () => Promise.resolve(read().map(candidateOf)),
|
|
44
|
+
get: candidate => {
|
|
45
|
+
const found = read().find(item => item.parsed.name === candidate.name)
|
|
46
|
+
if (!found) return Promise.resolve(undefined)
|
|
47
|
+
return Promise.resolve({ ...candidateOf(found), content: found.parsed.body.replaceAll('{{pack}}', root) })
|
|
48
|
+
},
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function safeRead(fs, path) {
|
|
53
|
+
try { return fs.readFileSync(path, 'utf8') } catch { return '' }
|
|
54
|
+
}
|
package/lib/stage.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
2
|
+
import { basename, join } from 'node:path'
|
|
3
|
+
import { digestFolder, FOLDER_DIGEST_SKIPPED } from '@acryldev/blends-core'
|
|
4
|
+
import { currentSourcePath } from '@acryldev/plugin-hub-core'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Automatic host-code hot reload (pi.dev clears its module cache on reload; Node cannot). Node caches an ES module by URL and caches the
|
|
8
|
+
* package's resolution, so a re-installed plugin keeps running its OLD host code. The installer therefore installs a STAGED copy of the plugin:
|
|
9
|
+
*
|
|
10
|
+
* <stage>/ the author's package, unchanged (client.js, cordis.patch.yml, package.json without "files", ...)
|
|
11
|
+
* <stage>/<entry> a generated wrapper (stable URL, cached) that, on EVERY activation, imports the newest versioned copy
|
|
12
|
+
* <stage>/acryl-v-<hash>/ a complete copy of the author's package, named by a hash of its contents
|
|
13
|
+
*
|
|
14
|
+
* Every version is a new directory, so the entry and everything it imports (helpers, sub-modules) have fresh URLs and are evaluated anew.
|
|
15
|
+
* Metadata the loader reads at import time (`name`, `inject`, `Config`) comes from the first load; the wrapper warns when a later version
|
|
16
|
+
* changes `inject`, which needs an app restart. Class-form `apply` (a Service subclass) cannot be wrapped and keeps its first version.
|
|
17
|
+
* The author's source folder is never modified; `acryl-source.json` records where it is so `/reload` re-installs from it.
|
|
18
|
+
*/
|
|
19
|
+
export const VERSION_DIR_PREFIX = 'acryl-v-'
|
|
20
|
+
export const SOURCE_FILE = 'acryl-source.json'
|
|
21
|
+
/** A short content hash of the package's files (names and bytes), so an unchanged package keeps its version directory. The same formula as a
|
|
22
|
+
* lock's `local` digest: `digestFolder` from blends-core, which skips `node_modules`, `.git`, `acryl-source.json` and the `acryl-v-*` copies. */
|
|
23
|
+
export function hashPackage(dir, length = 10) {
|
|
24
|
+
return digestFolder(dir, length)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** The entry file the loader imports, relative to the package root, or undefined when there is no JavaScript ES-module entry to wrap. */
|
|
28
|
+
export function entryOf(pkg) {
|
|
29
|
+
const exported = conditionalTarget(pkg.exports?.['.'])
|
|
30
|
+
const candidate = exported ?? (typeof pkg.main === 'string' ? pkg.main : './index.js')
|
|
31
|
+
return /\.(m?js)$/u.test(candidate) && pkg.type === 'module' || candidate.endsWith('.mjs') ? candidate.replace(/^\.\//u, '') : undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The file an `exports` target names for an ES-module import under Node: a string, or the first of `import`, `node`, `default` in a conditions object. */
|
|
35
|
+
function conditionalTarget(target) {
|
|
36
|
+
if (typeof target === 'string') return target
|
|
37
|
+
if (typeof target !== 'object' || target === null || Array.isArray(target)) return undefined
|
|
38
|
+
for (const condition of ['import', 'node', 'default']) {
|
|
39
|
+
const found = conditionalTarget(target[condition])
|
|
40
|
+
if (found !== undefined) return found
|
|
41
|
+
}
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function shimSource(pkgName, entryRel) {
|
|
46
|
+
// The versioned copies sit at the package root; the entry may be deeper (`lib/index.js`), so the wrapper walks up to the root.
|
|
47
|
+
const toRoot = entryRel.split('/').slice(1).map(() => '..').join('/') || '.'
|
|
48
|
+
return `// Generated by ACRYL (acryl_install_plugin) for automatic host-code hot reload. Do not edit: change the source folder and install again.
|
|
49
|
+
// Every activation imports the newest versioned copy of the plugin (acryl-v-*), so edits to host code and to the files it imports take
|
|
50
|
+
// effect without restarting the app. See docs/delivery/local-live.md in the extension pack.
|
|
51
|
+
import { readdirSync } from 'node:fs'
|
|
52
|
+
import { dirname, join } from 'node:path'
|
|
53
|
+
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
54
|
+
|
|
55
|
+
const here = join(dirname(fileURLToPath(import.meta.url)), ${JSON.stringify(toRoot)})
|
|
56
|
+
const latest = () => {
|
|
57
|
+
const dirs = readdirSync(here).filter(name => name.startsWith(${JSON.stringify(VERSION_DIR_PREFIX)})).sort()
|
|
58
|
+
const target = pathToFileURL(join(here, dirs[dirs.length - 1], ${JSON.stringify(entryRel)})).href
|
|
59
|
+
if (process.env.ACRYL_STAGE_DEBUG) console.error('[acryl-stage] importing', target, 'of', JSON.stringify(dirs))
|
|
60
|
+
return target
|
|
61
|
+
}
|
|
62
|
+
const first = await import(latest())
|
|
63
|
+
const isClass = value => typeof value === 'function' && /^class[\\s{]/u.test(Function.prototype.toString.call(value))
|
|
64
|
+
const initialInject = JSON.stringify(first.inject ?? null)
|
|
65
|
+
|
|
66
|
+
export const name = first.name
|
|
67
|
+
export const inject = first.inject
|
|
68
|
+
export const Config = first.Config
|
|
69
|
+
export const apply = isClass(first.apply) || typeof first.apply !== 'function'
|
|
70
|
+
? first.apply
|
|
71
|
+
: async function apply(ctx, config) {
|
|
72
|
+
const current = await import(latest())
|
|
73
|
+
if (JSON.stringify(current.inject ?? null) !== initialInject) {
|
|
74
|
+
ctx.logger?.warn?.(${JSON.stringify(`[${pkgName}] "inject" changed since this app started: restart to apply it (the rest of the update is live).`)})
|
|
75
|
+
}
|
|
76
|
+
return current.apply(ctx, config)
|
|
77
|
+
}
|
|
78
|
+
`
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Stage `sourceDir` for a hot-reloadable install.
|
|
83
|
+
* @param {string} sourceDir the author's package directory (never modified)
|
|
84
|
+
* @param {string} stageRoot directory that receives `<safe name>/`
|
|
85
|
+
* @returns {{ ok: true, dir: string, version: string, name: string } | { ok: false, reason: string }}
|
|
86
|
+
*/
|
|
87
|
+
export function stagePackage(sourceDir, stageRoot) {
|
|
88
|
+
let pkg
|
|
89
|
+
try { pkg = JSON.parse(readFileSync(join(sourceDir, 'package.json'), 'utf8')) } catch { return { ok: false, reason: 'package.json is unreadable' } }
|
|
90
|
+
const entryRel = entryOf(pkg)
|
|
91
|
+
if (entryRel === undefined) return { ok: false, reason: 'the host entry is not a JavaScript ES module ("type": "module" and a .js/.mjs entry)' }
|
|
92
|
+
if (!existsSync(join(sourceDir, entryRel))) return { ok: false, reason: `the host entry ${entryRel} does not exist` }
|
|
93
|
+
const version = hashPackage(sourceDir)
|
|
94
|
+
const safeName = String(pkg.name).replace(/[^A-Za-z0-9._-]+/gu, '_')
|
|
95
|
+
let stamp = String(Date.now()).padStart(15, '0')
|
|
96
|
+
// A UNIQUE path per install: pnpm treats an unchanged `file:` specifier as up to date and skips the copy even when the contents changed
|
|
97
|
+
// (measured), so the dependency specifier itself must change on every install. Two installs in the same millisecond (a test, a fast machine) must not
|
|
98
|
+
// share a path: step the stamp until the folder is free, which keeps the newest-first ordering the prune relies on.
|
|
99
|
+
let dir = join(stageRoot, `${safeName}@${stamp}`)
|
|
100
|
+
while (existsSync(dir)) {
|
|
101
|
+
stamp = String(Number(stamp) + 1).padStart(15, '0')
|
|
102
|
+
dir = join(stageRoot, `${safeName}@${stamp}`)
|
|
103
|
+
}
|
|
104
|
+
mkdirSync(dir, { recursive: true })
|
|
105
|
+
const copy = target => cpSync(sourceDir, target, { recursive: true, filter: source => !FOLDER_DIGEST_SKIPPED.has(basename(source)) && !basename(source).startsWith(VERSION_DIR_PREFIX) })
|
|
106
|
+
copy(dir)
|
|
107
|
+
// The timestamp prefix makes "newest" well defined even when the package manager leaves an older version directory behind.
|
|
108
|
+
const versionDir = `${VERSION_DIR_PREFIX}${stamp}-${version}`
|
|
109
|
+
copy(join(dir, versionDir))
|
|
110
|
+
writeFileSync(join(dir, entryRel), shimSource(pkg.name, entryRel))
|
|
111
|
+
// `files` would drop the versioned directory from the install; the staged package ships everything it contains.
|
|
112
|
+
const { files: _files, ...staged } = pkg
|
|
113
|
+
writeFileSync(join(dir, 'package.json'), `${JSON.stringify(staged, null, 2)}\n`)
|
|
114
|
+
writeFileSync(join(dir, SOURCE_FILE), `${JSON.stringify({ source: sourceDir, version })}\n`)
|
|
115
|
+
return { ok: true, dir, version, versionDir, name: pkg.name }
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Where a staged install came from, or undefined for a plain install. */
|
|
119
|
+
export function stagedSource(installedDir, fs = { existsSync, readFileSync }) {
|
|
120
|
+
try {
|
|
121
|
+
const file = join(installedDir, SOURCE_FILE)
|
|
122
|
+
if (!fs.existsSync(file)) return undefined
|
|
123
|
+
const { source } = JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
124
|
+
// A source recorded before the folders were renamed is found where it was moved.
|
|
125
|
+
return typeof source === 'string' ? currentSourcePath(source) : undefined
|
|
126
|
+
} catch { return undefined }
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Delete every versioned copy except the newest inside an INSTALLED staged package (best effort). Modules already evaluated stay in memory;
|
|
132
|
+
* this only keeps the profile from accumulating one full copy of the plugin per update.
|
|
133
|
+
*/
|
|
134
|
+
export function pruneOldVersions(installedDir, keep, fs = { existsSync, readdirSync, rmSync }) {
|
|
135
|
+
try {
|
|
136
|
+
if (!fs.existsSync(installedDir)) return 0
|
|
137
|
+
let removed = 0
|
|
138
|
+
for (const name of fs.readdirSync(installedDir)) {
|
|
139
|
+
if (name.startsWith(VERSION_DIR_PREFIX) && name !== keep) { fs.rmSync(join(installedDir, name), { recursive: true, force: true }); removed += 1 }
|
|
140
|
+
}
|
|
141
|
+
return removed
|
|
142
|
+
} catch { return 0 }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Remove earlier staging copies of `packageName` (best effort), keeping only `keepDir`. */
|
|
146
|
+
export function pruneOldStages(stageRoot, packageName, keepDir, fs = { existsSync, readdirSync, rmSync }) {
|
|
147
|
+
try {
|
|
148
|
+
if (!fs.existsSync(stageRoot)) return 0
|
|
149
|
+
const prefix = `${String(packageName).replace(/[^A-Za-z0-9._-]+/gu, '_')}@`
|
|
150
|
+
let removed = 0
|
|
151
|
+
for (const name of fs.readdirSync(stageRoot)) {
|
|
152
|
+
const path = join(stageRoot, name)
|
|
153
|
+
if (name.startsWith(prefix) && path !== keepDir) { fs.rmSync(path, { recursive: true, force: true }); removed += 1 }
|
|
154
|
+
}
|
|
155
|
+
return removed
|
|
156
|
+
} catch { return 0 }
|
|
157
|
+
}
|