@eloxiv/cli 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/dist/AgentSkills.d.ts +51 -0
- package/dist/AgentSkills.d.ts.map +1 -0
- package/dist/AgentSkills.js +264 -0
- package/dist/AgentSkills.js.map +1 -0
- package/dist/AgentWeb.d.ts +83 -0
- package/dist/AgentWeb.d.ts.map +1 -0
- package/dist/AgentWeb.js +436 -0
- package/dist/AgentWeb.js.map +1 -0
- package/dist/App.d.ts +213 -0
- package/dist/App.d.ts.map +1 -0
- package/dist/App.js +357 -0
- package/dist/App.js.map +1 -0
- package/dist/Blueprint.d.ts +47 -0
- package/dist/Blueprint.d.ts.map +1 -0
- package/dist/Blueprint.js +241 -0
- package/dist/Blueprint.js.map +1 -0
- package/dist/Brand.d.ts +42 -0
- package/dist/Brand.d.ts.map +1 -0
- package/dist/Brand.js +370 -0
- package/dist/Brand.js.map +1 -0
- package/dist/Changelog.d.ts +22 -0
- package/dist/Changelog.d.ts.map +1 -0
- package/dist/Changelog.js +117 -0
- package/dist/Changelog.js.map +1 -0
- package/dist/Cli.d.ts +17 -0
- package/dist/Cli.d.ts.map +1 -0
- package/dist/Cli.js +810 -0
- package/dist/Cli.js.map +1 -0
- package/dist/DbAdmin.d.ts +18 -0
- package/dist/DbAdmin.d.ts.map +1 -0
- package/dist/DbAdmin.js +91 -0
- package/dist/DbAdmin.js.map +1 -0
- package/dist/Dependencies.d.ts +53 -0
- package/dist/Dependencies.d.ts.map +1 -0
- package/dist/Dependencies.js +132 -0
- package/dist/Dependencies.js.map +1 -0
- package/dist/Deploy.d.ts +39 -0
- package/dist/Deploy.d.ts.map +1 -0
- package/dist/Deploy.js +458 -0
- package/dist/Deploy.js.map +1 -0
- package/dist/Docs.d.ts +71 -0
- package/dist/Docs.d.ts.map +1 -0
- package/dist/Docs.js +240 -0
- package/dist/Docs.js.map +1 -0
- package/dist/Doctor.d.ts +56 -0
- package/dist/Doctor.d.ts.map +1 -0
- package/dist/Doctor.js +368 -0
- package/dist/Doctor.js.map +1 -0
- package/dist/Dossier.d.ts +23 -0
- package/dist/Dossier.d.ts.map +1 -0
- package/dist/Dossier.js +92 -0
- package/dist/Dossier.js.map +1 -0
- package/dist/Emit.d.ts +26 -0
- package/dist/Emit.d.ts.map +1 -0
- package/dist/Emit.js +51 -0
- package/dist/Emit.js.map +1 -0
- package/dist/Errors.d.ts +26 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +17 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Evals.d.ts +52 -0
- package/dist/Evals.d.ts.map +1 -0
- package/dist/Evals.js +126 -0
- package/dist/Evals.js.map +1 -0
- package/dist/Files.d.ts +47 -0
- package/dist/Files.d.ts.map +1 -0
- package/dist/Files.js +145 -0
- package/dist/Files.js.map +1 -0
- package/dist/Generate.d.ts +80 -0
- package/dist/Generate.d.ts.map +1 -0
- package/dist/Generate.js +310 -0
- package/dist/Generate.js.map +1 -0
- package/dist/Guards.d.ts +45 -0
- package/dist/Guards.d.ts.map +1 -0
- package/dist/Guards.js +530 -0
- package/dist/Guards.js.map +1 -0
- package/dist/Inspect.d.ts +125 -0
- package/dist/Inspect.d.ts.map +1 -0
- package/dist/Inspect.js +270 -0
- package/dist/Inspect.js.map +1 -0
- package/dist/Keychain.d.ts +57 -0
- package/dist/Keychain.d.ts.map +1 -0
- package/dist/Keychain.js +73 -0
- package/dist/Keychain.js.map +1 -0
- package/dist/Lock.d.ts +13 -0
- package/dist/Lock.d.ts.map +1 -0
- package/dist/Lock.js +145 -0
- package/dist/Lock.js.map +1 -0
- package/dist/Mcp.d.ts +91 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +128 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/Merge.d.ts +18 -0
- package/dist/Merge.d.ts.map +1 -0
- package/dist/Merge.js +43 -0
- package/dist/Merge.js.map +1 -0
- package/dist/Migrate.d.ts +78 -0
- package/dist/Migrate.d.ts.map +1 -0
- package/dist/Migrate.js +288 -0
- package/dist/Migrate.js.map +1 -0
- package/dist/Plugins.d.ts +36 -0
- package/dist/Plugins.d.ts.map +1 -0
- package/dist/Plugins.js +304 -0
- package/dist/Plugins.js.map +1 -0
- package/dist/Postgres.d.ts +73 -0
- package/dist/Postgres.d.ts.map +1 -0
- package/dist/Postgres.js +294 -0
- package/dist/Postgres.js.map +1 -0
- package/dist/Publish.d.ts +23 -0
- package/dist/Publish.d.ts.map +1 -0
- package/dist/Publish.js +59 -0
- package/dist/Publish.js.map +1 -0
- package/dist/Registry.d.ts +539 -0
- package/dist/Registry.d.ts.map +1 -0
- package/dist/Registry.js +340 -0
- package/dist/Registry.js.map +1 -0
- package/dist/Remote.d.ts +90 -0
- package/dist/Remote.d.ts.map +1 -0
- package/dist/Remote.js +1006 -0
- package/dist/Remote.js.map +1 -0
- package/dist/Run.d.ts +120 -0
- package/dist/Run.d.ts.map +1 -0
- package/dist/Run.js +477 -0
- package/dist/Run.js.map +1 -0
- package/dist/SyncGen.d.ts +118 -0
- package/dist/SyncGen.d.ts.map +1 -0
- package/dist/SyncGen.js +392 -0
- package/dist/SyncGen.js.map +1 -0
- package/dist/Update.d.ts +301 -0
- package/dist/Update.d.ts.map +1 -0
- package/dist/Update.js +627 -0
- package/dist/Update.js.map +1 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.d.ts.map +1 -0
- package/dist/bin.js +42 -0
- package/dist/bin.js.map +1 -0
- package/dist/docs/backlog.md +56 -0
- package/dist/docs/ci.md +277 -0
- package/dist/docs/cli.md +696 -0
- package/dist/docs/connectors/google.md +115 -0
- package/dist/docs/connectors/http-openapi.md +7 -0
- package/dist/docs/connectors/mcp.md +8 -0
- package/dist/docs/connectors/microsoft-graph.md +75 -0
- package/dist/docs/connectors/openai.md +25 -0
- package/dist/docs/connectors/slack.md +162 -0
- package/dist/docs/connectors/workos.md +39 -0
- package/dist/docs/contracts/README.md +173 -0
- package/dist/docs/contracts/action-consent.md +92 -0
- package/dist/docs/contracts/action-registry.md +85 -0
- package/dist/docs/contracts/actor.md +100 -0
- package/dist/docs/contracts/agent-resources.md +90 -0
- package/dist/docs/contracts/agent-runtime.md +257 -0
- package/dist/docs/contracts/approvals.md +126 -0
- package/dist/docs/contracts/audit.md +75 -0
- package/dist/docs/contracts/auth-provider.md +74 -0
- package/dist/docs/contracts/calendar-provider.md +46 -0
- package/dist/docs/contracts/client-sdk.md +245 -0
- package/dist/docs/contracts/collab-document.md +151 -0
- package/dist/docs/contracts/command.md +44 -0
- package/dist/docs/contracts/connections.md +235 -0
- package/dist/docs/contracts/context-accounting.md +50 -0
- package/dist/docs/contracts/daemon.md +243 -0
- package/dist/docs/contracts/db-tx.md +53 -0
- package/dist/docs/contracts/delegation.md +68 -0
- package/dist/docs/contracts/device-control.md +103 -0
- package/dist/docs/contracts/directory-provider.md +36 -0
- package/dist/docs/contracts/directory.md +161 -0
- package/dist/docs/contracts/document-source.md +33 -0
- package/dist/docs/contracts/files.md +115 -0
- package/dist/docs/contracts/flags.md +83 -0
- package/dist/docs/contracts/host.md +68 -0
- package/dist/docs/contracts/http-api.md +43 -0
- package/dist/docs/contracts/ingestion.md +130 -0
- package/dist/docs/contracts/ingress.md +141 -0
- package/dist/docs/contracts/invocation.md +260 -0
- package/dist/docs/contracts/local-client.md +110 -0
- package/dist/docs/contracts/locale.md +56 -0
- package/dist/docs/contracts/machine-identity.md +117 -0
- package/dist/docs/contracts/mail-provider.md +49 -0
- package/dist/docs/contracts/memory.md +53 -0
- package/dist/docs/contracts/messaging.md +40 -0
- package/dist/docs/contracts/metering.md +139 -0
- package/dist/docs/contracts/model-provider.md +84 -0
- package/dist/docs/contracts/module-manifest.md +213 -0
- package/dist/docs/contracts/notification-channel.md +90 -0
- package/dist/docs/contracts/notifications.md +123 -0
- package/dist/docs/contracts/outbox.md +80 -0
- package/dist/docs/contracts/privacy.md +110 -0
- package/dist/docs/contracts/progress.md +52 -0
- package/dist/docs/contracts/query-surface.md +108 -0
- package/dist/docs/contracts/readiness.md +63 -0
- package/dist/docs/contracts/release.md +142 -0
- package/dist/docs/contracts/result-rendering.md +61 -0
- package/dist/docs/contracts/sandbox.md +186 -0
- package/dist/docs/contracts/scheduler.md +148 -0
- package/dist/docs/contracts/screen-context.md +81 -0
- package/dist/docs/contracts/search.md +120 -0
- package/dist/docs/contracts/secrets.md +74 -0
- package/dist/docs/contracts/settings.md +109 -0
- package/dist/docs/contracts/sharing.md +77 -0
- package/dist/docs/contracts/slot.md +48 -0
- package/dist/docs/contracts/space.md +67 -0
- package/dist/docs/contracts/storage-adapter.md +45 -0
- package/dist/docs/contracts/storage-backend.md +56 -0
- package/dist/docs/contracts/sync.md +213 -0
- package/dist/docs/contracts/telemetry.md +80 -0
- package/dist/docs/contracts/theme-tokens.md +50 -0
- package/dist/docs/contracts/tool-source.md +58 -0
- package/dist/docs/contracts/versioning.md +99 -0
- package/dist/docs/contracts/view.md +65 -0
- package/dist/docs/contracts/work-items.md +99 -0
- package/dist/docs/contracts/workflow.md +82 -0
- package/dist/docs/decisions.md +163 -0
- package/dist/docs/example-app.md +192 -0
- package/dist/docs/getting-started.md +927 -0
- package/dist/docs/goal.md +54 -0
- package/dist/docs/parity.md +29 -0
- package/dist/docs/performance.md +129 -0
- package/dist/docs/registry/README.md +74 -0
- package/dist/docs/registry/app.md +38 -0
- package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
- package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
- package/dist/docs/registry/calendar.md +35 -0
- package/dist/docs/registry/chat-ui-foldkit.md +30 -0
- package/dist/docs/registry/desktop-rune.md +50 -0
- package/dist/docs/registry/desktop.md +32 -0
- package/dist/docs/registry/eloxiv-action.md +25 -0
- package/dist/docs/registry/eloxiv-connector.md +25 -0
- package/dist/docs/registry/eloxiv-module.md +25 -0
- package/dist/docs/registry/eloxiv-policy.md +25 -0
- package/dist/docs/registry/eloxiv-view.md +25 -0
- package/dist/docs/registry/hello-ui-foldkit.md +29 -0
- package/dist/docs/registry/hello.md +39 -0
- package/dist/docs/registry/home-ui-foldkit.md +27 -0
- package/dist/docs/registry/home.md +29 -0
- package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail-ui-foldkit.md +27 -0
- package/dist/docs/registry/mail.md +34 -0
- package/dist/docs/registry/meeting-prep.md +26 -0
- package/dist/docs/registry/members-ui-foldkit.md +28 -0
- package/dist/docs/registry/mobile.md +37 -0
- package/dist/docs/registry/notes-ui-foldkit.md +27 -0
- package/dist/docs/registry/notes.md +26 -0
- package/dist/docs/registry/people-ui-foldkit.md +28 -0
- package/dist/docs/registry/people.md +38 -0
- package/dist/docs/registry/shell-foldkit.md +35 -0
- package/dist/docs/registry/theme.md +25 -0
- package/dist/docs/registry/ui-conformance.md +30 -0
- package/dist/docs/release.md +100 -0
- package/dist/docs/scaffold.md +826 -0
- package/dist/docs/security/threat-model.md +299 -0
- package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/package.json +48 -3
- package/src/AgentSkills.ts +329 -0
- package/src/AgentWeb.ts +507 -0
- package/src/App.ts +435 -0
- package/src/Blueprint.ts +276 -0
- package/src/Brand.ts +415 -0
- package/src/Changelog.ts +136 -0
- package/src/Cli.ts +1458 -0
- package/src/DbAdmin.ts +115 -0
- package/src/Dependencies.ts +170 -0
- package/src/Deploy.ts +563 -0
- package/src/Docs.ts +309 -0
- package/src/Doctor.ts +424 -0
- package/src/Dossier.ts +148 -0
- package/src/Emit.ts +68 -0
- package/src/Errors.ts +18 -0
- package/src/Evals.ts +153 -0
- package/src/Files.ts +152 -0
- package/src/Generate.ts +402 -0
- package/src/Guards.ts +541 -0
- package/src/Inspect.ts +358 -0
- package/src/Keychain.ts +107 -0
- package/src/Lock.ts +174 -0
- package/src/Mcp.ts +159 -0
- package/src/Merge.ts +70 -0
- package/src/Migrate.ts +331 -0
- package/src/Plugins.ts +347 -0
- package/src/Postgres.ts +353 -0
- package/src/Publish.ts +64 -0
- package/src/Registry.ts +405 -0
- package/src/Remote.ts +1158 -0
- package/src/Run.ts +541 -0
- package/src/SyncGen.ts +570 -0
- package/src/Update.ts +873 -0
- package/src/bin.ts +46 -0
- package/src/index.ts +7 -0
package/src/Plugins.ts
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `eloxiv plugin import <dir>`: bring a coding-agent plugin (the standard layout Claude Code plugins use) into the
|
|
3
|
+
* app (docs/cli.md, "plugin"):
|
|
4
|
+
*
|
|
5
|
+
* - `.claude-plugin/plugin.json`: the manifest (`name` in kebab case; `version`, `description`), validated first;
|
|
6
|
+
* - `skills/<skill>/SKILL.md` (YAML frontmatter with `name` and `description`): each becomes the app skill
|
|
7
|
+
* `<plugin>-<skill>` in `skills/`, for development only (`audience: "development"`: coding agents read it, the
|
|
8
|
+
* app's own agent never does), **inert**: its Markdown and text references are copied, nothing else (no script, no
|
|
9
|
+
* binary, nothing that runs), with its provenance (`plugin.json`: the plugin, its version and each file's hash);
|
|
10
|
+
* - `.mcp.json` (`mcpServers`): each remote server over HTTP (an `https` URL, or `http` on this machine) is listed in
|
|
11
|
+
* the hosts' project configuration as `eloxiv mcp install` lists the kernel's, named `<plugin>-<server>`; a server
|
|
12
|
+
* that runs a local command, uses another transport, or carries headers (a credential) is not imported.
|
|
13
|
+
*
|
|
14
|
+
* A skill directory already there that the same plugin did not import is left as it is (reported), so local work is
|
|
15
|
+
* never overwritten; importing again refreshes what the plugin imported. `--dry-run` reports without writing.
|
|
16
|
+
*/
|
|
17
|
+
import { createHash } from "node:crypto"
|
|
18
|
+
import { lstatSync, realpathSync } from "node:fs"
|
|
19
|
+
import { Argument, Command, Flag } from "effect/cli"
|
|
20
|
+
import { Console, Effect, FileSystem, Option, Path } from "effect"
|
|
21
|
+
import { stripFrontmatter } from "./AgentSkills.ts"
|
|
22
|
+
import { CliError } from "./Errors.ts"
|
|
23
|
+
import { writeAppFile } from "./Files.ts"
|
|
24
|
+
import { MCP_HOST_NAMES, MCP_HOSTS, type McpHost } from "./Mcp.ts"
|
|
25
|
+
|
|
26
|
+
const KEBAB = /^[a-z][a-z0-9]*(-[a-z0-9]+)*$/u
|
|
27
|
+
/** What a skill brings besides its document: references a coding agent reads, nothing that runs. */
|
|
28
|
+
const INERT = /\.(md|txt)$/iu
|
|
29
|
+
|
|
30
|
+
export interface PluginReport {
|
|
31
|
+
readonly plugin: string
|
|
32
|
+
readonly version: string
|
|
33
|
+
readonly skills: ReadonlyArray<string>
|
|
34
|
+
readonly servers: ReadonlyArray<string>
|
|
35
|
+
/** What was not imported, and why. */
|
|
36
|
+
readonly skipped: ReadonlyArray<{ readonly what: string; readonly why: string }>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The YAML frontmatter's `key: value` lines (strings, quoted or not): all a skill's header needs. */
|
|
40
|
+
export const frontmatterOf = (document: string): Readonly<Record<string, string>> => {
|
|
41
|
+
const match = /^---\r?\n([\s\S]*?)\r?\n---/u.exec(document)
|
|
42
|
+
if (match === null) return {}
|
|
43
|
+
const fields: Record<string, string> = {}
|
|
44
|
+
for (const line of match[1]!.split(/\r?\n/u)) {
|
|
45
|
+
const field = /^([A-Za-z][\w-]*):\s*(.*)$/u.exec(line)
|
|
46
|
+
if (field === null) continue
|
|
47
|
+
let value = field[2]!.trim()
|
|
48
|
+
if (/^".*"$/u.test(value)) {
|
|
49
|
+
try {
|
|
50
|
+
value = JSON.parse(value) as string
|
|
51
|
+
} catch {
|
|
52
|
+
value = value.slice(1, -1)
|
|
53
|
+
}
|
|
54
|
+
} else if (/^'.*'$/u.test(value)) value = value.slice(1, -1).replaceAll("''", "'")
|
|
55
|
+
fields[field[1]!] = value
|
|
56
|
+
}
|
|
57
|
+
return fields
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const sha = (content: string) => createHash("sha256").update(content).digest("hex")
|
|
61
|
+
const camel = (name: string) => name.replace(/-([a-z0-9])/gu, (_, c: string) => c.toUpperCase())
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The imported skill's definition. Nothing from the plugin goes into it as code or in a comment: its name is checked
|
|
65
|
+
* kebab case, its description is a JSON string literal; where it came from (plugin, version) is in plugin.json, data.
|
|
66
|
+
*/
|
|
67
|
+
const skillSource = (name: string, description: string) =>
|
|
68
|
+
`/**
|
|
69
|
+
* Imported from an agent plugin by \`eloxiv plugin import\` (where from: plugin.json beside it): a skill for the coding
|
|
70
|
+
* agents that build the app (audience development: the app's own agent is never given it). Inert: a document.
|
|
71
|
+
*/
|
|
72
|
+
import { defineAppSkill } from "@eloxiv/kernel"
|
|
73
|
+
|
|
74
|
+
export const ${camel(name)}Skill = defineAppSkill({
|
|
75
|
+
name: ${JSON.stringify(name)},
|
|
76
|
+
description: ${JSON.stringify(description)},
|
|
77
|
+
directory: import.meta.url,
|
|
78
|
+
content: { path: "SKILL.md" },
|
|
79
|
+
audience: "development",
|
|
80
|
+
})
|
|
81
|
+
`
|
|
82
|
+
|
|
83
|
+
const readJson = (file: string, what: string) =>
|
|
84
|
+
Effect.gen(function* () {
|
|
85
|
+
const fs = yield* FileSystem.FileSystem
|
|
86
|
+
const text = yield* fs
|
|
87
|
+
.readFileString(file)
|
|
88
|
+
.pipe(Effect.mapError(() => new CliError({ message: `Cannot read ${what}` })))
|
|
89
|
+
try {
|
|
90
|
+
const parsed = JSON.parse(text) as unknown
|
|
91
|
+
if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
|
|
92
|
+
return parsed as Record<string, unknown>
|
|
93
|
+
} catch {
|
|
94
|
+
// Refused below.
|
|
95
|
+
}
|
|
96
|
+
return yield* new CliError({ message: `${what} is not a JSON object` })
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
/** Semantic versions (`1.2.0`, `1.2.0-beta.1+build.5`): nothing else is recorded as a plugin's version. */
|
|
100
|
+
const SEMVER =
|
|
101
|
+
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/u
|
|
102
|
+
|
|
103
|
+
/** Query parameters that carry a credential by their name. */
|
|
104
|
+
const CREDENTIAL_PARAM =
|
|
105
|
+
/^(api[-_]?key|key|token|access[-_]?token|auth|authorization|secret|client[-_]?secret|password|passwd|pwd|sig|signature|credential|credentials|session)$/iu
|
|
106
|
+
|
|
107
|
+
/** Whether a URL carries a credential: a user or password, or a query parameter named for one. */
|
|
108
|
+
export const carriesCredential = (url: string) => {
|
|
109
|
+
try {
|
|
110
|
+
const parsed = new URL(url)
|
|
111
|
+
if (parsed.username !== "" || parsed.password !== "") return true
|
|
112
|
+
return [...parsed.searchParams.keys()].some((k) => CREDENTIAL_PARAM.test(k) || /(token|secret|key)$/iu.test(k))
|
|
113
|
+
} catch {
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const isRemote = (url: string) => {
|
|
119
|
+
try {
|
|
120
|
+
const parsed = new URL(url)
|
|
121
|
+
return (
|
|
122
|
+
parsed.protocol === "https:" ||
|
|
123
|
+
(parsed.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(parsed.hostname))
|
|
124
|
+
)
|
|
125
|
+
} catch {
|
|
126
|
+
return false
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export const importPlugin = (
|
|
131
|
+
dir: string,
|
|
132
|
+
source: string,
|
|
133
|
+
options: { readonly hosts: ReadonlyArray<McpHost>; readonly dryRun: boolean; readonly replace?: boolean },
|
|
134
|
+
) =>
|
|
135
|
+
Effect.gen(function* () {
|
|
136
|
+
const fs = yield* FileSystem.FileSystem
|
|
137
|
+
const path = yield* Path.Path
|
|
138
|
+
const manifestFile = path.join(source, ".claude-plugin", "plugin.json")
|
|
139
|
+
if (!(yield* fs.exists(manifestFile))) {
|
|
140
|
+
return yield* new CliError({ message: `${source} is not an agent plugin: it has no .claude-plugin/plugin.json` })
|
|
141
|
+
}
|
|
142
|
+
const manifest = yield* readJson(manifestFile, ".claude-plugin/plugin.json")
|
|
143
|
+
const plugin = manifest["name"]
|
|
144
|
+
if (typeof plugin !== "string" || !KEBAB.test(plugin)) {
|
|
145
|
+
return yield* new CliError({ message: `The plugin's name must be kebab case (got ${JSON.stringify(plugin)})` })
|
|
146
|
+
}
|
|
147
|
+
const declaredVersion = manifest["version"] ?? "0.0.0"
|
|
148
|
+
if (typeof declaredVersion !== "string" || !SEMVER.test(declaredVersion)) {
|
|
149
|
+
return yield* new CliError({
|
|
150
|
+
message: `The plugin's version must be a semantic version such as 1.2.0 (got ${JSON.stringify(declaredVersion)})`,
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
const version: string = declaredVersion
|
|
154
|
+
// Every file read must be a regular file inside the plugin's directory once symbolic links are resolved.
|
|
155
|
+
const pluginRoot = realpathSync(source)
|
|
156
|
+
const inside = (file: string) => {
|
|
157
|
+
const stat = lstatSync(file, { throwIfNoEntry: false })
|
|
158
|
+
if (stat === undefined || stat.isSymbolicLink() || !stat.isFile()) return false
|
|
159
|
+
const real = realpathSync(file)
|
|
160
|
+
const relative = path.relative(pluginRoot, real)
|
|
161
|
+
return relative !== "" && !relative.startsWith("..") && !path.isAbsolute(relative)
|
|
162
|
+
}
|
|
163
|
+
const skills: Array<string> = []
|
|
164
|
+
const servers: Array<string> = []
|
|
165
|
+
const skipped: Array<{ what: string; why: string }> = []
|
|
166
|
+
|
|
167
|
+
// Skills: each a namespaced app skill for development, its documents only.
|
|
168
|
+
const skillsRoot = path.join(source, "skills")
|
|
169
|
+
const skillDirs = (yield* fs.exists(skillsRoot)) ? (yield* fs.readDirectory(skillsRoot)).sort() : []
|
|
170
|
+
for (const skillDir of skillDirs) {
|
|
171
|
+
const documentFile = path.join(skillsRoot, skillDir, "SKILL.md")
|
|
172
|
+
if (!(yield* fs.exists(documentFile))) continue
|
|
173
|
+
if (lstatSync(path.join(skillsRoot, skillDir)).isSymbolicLink() || !inside(documentFile)) {
|
|
174
|
+
skipped.push({ what: `skills/${skillDir}`, why: "a symbolic link, or a file outside the plugin" })
|
|
175
|
+
continue
|
|
176
|
+
}
|
|
177
|
+
const document = yield* fs.readFileString(documentFile)
|
|
178
|
+
const header = frontmatterOf(document)
|
|
179
|
+
const local: string = header["name"] ?? skillDir
|
|
180
|
+
const name: string = `${plugin}-${local}`
|
|
181
|
+
if (!KEBAB.test(local) || !KEBAB.test(name)) {
|
|
182
|
+
skipped.push({ what: `skill ${local}`, why: "its name is not kebab case" })
|
|
183
|
+
continue
|
|
184
|
+
}
|
|
185
|
+
const description = (header["description"] ?? "").trim()
|
|
186
|
+
if (description === "") {
|
|
187
|
+
skipped.push({ what: `skill ${local}`, why: "its SKILL.md has no description" })
|
|
188
|
+
continue
|
|
189
|
+
}
|
|
190
|
+
const target: string = `skills/${name}`
|
|
191
|
+
const provenanceFile = path.join(dir, target, "plugin.json")
|
|
192
|
+
if (yield* fs.exists(path.join(dir, target))) {
|
|
193
|
+
const previous: Record<string, unknown> = (yield* fs.exists(provenanceFile))
|
|
194
|
+
? yield* readJson(provenanceFile, `${target}/plugin.json`).pipe(Effect.orElseSucceed(() => ({})))
|
|
195
|
+
: {}
|
|
196
|
+
if ((previous as { plugin?: unknown }).plugin !== plugin) {
|
|
197
|
+
skipped.push({
|
|
198
|
+
what: `skill ${local}`,
|
|
199
|
+
why: `${target} is already there and was not imported from ${plugin}`,
|
|
200
|
+
})
|
|
201
|
+
continue
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
const files: Record<string, string> = {}
|
|
205
|
+
const body = stripFrontmatter(document)
|
|
206
|
+
files["SKILL.md"] = body
|
|
207
|
+
for (const entry of (yield* fs.readDirectory(path.join(skillsRoot, skillDir), { recursive: true })).sort()) {
|
|
208
|
+
const relative = entry.split("\\").join("/")
|
|
209
|
+
if (relative === "SKILL.md") continue
|
|
210
|
+
const full = path.join(skillsRoot, skillDir, entry)
|
|
211
|
+
const kind = lstatSync(full)
|
|
212
|
+
if (kind.isDirectory()) continue
|
|
213
|
+
if (!inside(full)) {
|
|
214
|
+
skipped.push({ what: `skills/${skillDir}/${relative}`, why: "a symbolic link, or a file outside the plugin" })
|
|
215
|
+
continue
|
|
216
|
+
}
|
|
217
|
+
if (!INERT.test(relative) || relative.split("/").some((part) => part.startsWith("."))) {
|
|
218
|
+
skipped.push({
|
|
219
|
+
what: `skills/${skillDir}/${relative}`,
|
|
220
|
+
why: "not a document (only Markdown and text are imported)",
|
|
221
|
+
})
|
|
222
|
+
continue
|
|
223
|
+
}
|
|
224
|
+
files[relative] = yield* fs.readFileString(full)
|
|
225
|
+
}
|
|
226
|
+
if (!options.dryRun) {
|
|
227
|
+
for (const [relative, content] of Object.entries(files))
|
|
228
|
+
yield* writeAppFile(dir, `${target}/${relative}`, content)
|
|
229
|
+
yield* writeAppFile(dir, `${target}/skill.ts`, skillSource(name, description))
|
|
230
|
+
const hashes = Object.fromEntries(Object.entries(files).map(([relative, content]) => [relative, sha(content)]))
|
|
231
|
+
yield* writeAppFile(
|
|
232
|
+
dir,
|
|
233
|
+
`${target}/plugin.json`,
|
|
234
|
+
`${JSON.stringify({ plugin, version, skill: local, files: hashes }, null, 2)}\n`,
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
skills.push(name)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// MCP servers: remote ones over HTTP, without credentials, into the hosts' project configuration.
|
|
241
|
+
const mcpFile = path.join(source, ".mcp.json")
|
|
242
|
+
if ((yield* fs.exists(mcpFile)) && !inside(mcpFile)) {
|
|
243
|
+
return yield* new CliError({ message: ".mcp.json is a symbolic link or outside the plugin" })
|
|
244
|
+
}
|
|
245
|
+
const declared = (yield* fs.exists(mcpFile))
|
|
246
|
+
? (((yield* readJson(mcpFile, ".mcp.json"))["mcpServers"] ?? {}) as Record<string, any>)
|
|
247
|
+
: {}
|
|
248
|
+
const accepted: Array<{ readonly name: string; readonly url: string }> = []
|
|
249
|
+
for (const [server, config] of Object.entries(declared).sort(([a], [b]) => a.localeCompare(b))) {
|
|
250
|
+
const name = `${plugin}-${server}`
|
|
251
|
+
const why =
|
|
252
|
+
typeof config !== "object" || config === null
|
|
253
|
+
? "not a server configuration"
|
|
254
|
+
: "command" in config
|
|
255
|
+
? "it runs a local command"
|
|
256
|
+
: config.type !== undefined && config.type !== "http"
|
|
257
|
+
? `its transport is ${String(config.type)}, not http`
|
|
258
|
+
: typeof config.url !== "string" || !isRemote(config.url)
|
|
259
|
+
? "its URL is not https (or http on this machine)"
|
|
260
|
+
: carriesCredential(config.url)
|
|
261
|
+
? "its URL carries a credential (a user and password, or a key or token in its query)"
|
|
262
|
+
: "headers" in config || "env" in config
|
|
263
|
+
? "it carries headers or environment (a credential is never written)"
|
|
264
|
+
: !/^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/u.test(name)
|
|
265
|
+
? "its name is not a server name"
|
|
266
|
+
: undefined
|
|
267
|
+
if (why !== undefined) {
|
|
268
|
+
skipped.push({ what: `MCP server ${server}`, why })
|
|
269
|
+
continue
|
|
270
|
+
}
|
|
271
|
+
accepted.push({ name, url: config.url as string })
|
|
272
|
+
servers.push(name)
|
|
273
|
+
}
|
|
274
|
+
if (!options.dryRun && accepted.length > 0) {
|
|
275
|
+
for (const host of options.hosts) {
|
|
276
|
+
const spec = MCP_HOSTS[host]
|
|
277
|
+
const file = path.join(dir, spec.file)
|
|
278
|
+
const config = (yield* fs.exists(file)) ? yield* readJson(file, spec.file) : {}
|
|
279
|
+
const listed = { ...((config[spec.key] ?? {}) as Record<string, unknown>) }
|
|
280
|
+
for (const server of accepted) {
|
|
281
|
+
const entry = spec.entry(server.url)
|
|
282
|
+
const existing = listed[server.name]
|
|
283
|
+
if (existing !== undefined && JSON.stringify(existing) !== JSON.stringify(entry) && !options.replace) {
|
|
284
|
+
// A server of that name the person already trusts, pointing elsewhere: kept, unless asked to replace it.
|
|
285
|
+
skipped.push({
|
|
286
|
+
what: `MCP server ${server.name} in ${spec.file}`,
|
|
287
|
+
why: "already listed with another endpoint; kept (import with --replace to replace it)",
|
|
288
|
+
})
|
|
289
|
+
continue
|
|
290
|
+
}
|
|
291
|
+
listed[server.name] = entry
|
|
292
|
+
}
|
|
293
|
+
yield* writeAppFile(dir, spec.file, `${JSON.stringify({ ...config, [spec.key]: listed }, null, 2)}\n`)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return { plugin, version, skills, servers, skipped } satisfies PluginReport
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
export const formatPlugin = (report: PluginReport, dryRun: boolean) =>
|
|
300
|
+
[
|
|
301
|
+
`${dryRun ? "would import" : "imported"} ${report.plugin} ${report.version}`,
|
|
302
|
+
...report.skills.map((s) => ` skill skills/${s} (development)`),
|
|
303
|
+
...report.servers.map((s) => ` MCP server ${s}`),
|
|
304
|
+
...report.skipped.map((s) => ` skipped ${s.what}: ${s.why}`),
|
|
305
|
+
].join("\n")
|
|
306
|
+
|
|
307
|
+
export const pluginCommand = Command.make("plugin").pipe(
|
|
308
|
+
Command.withDescription("Coding-agent plugins (the Claude Code layout): their skills and remote MCP servers"),
|
|
309
|
+
Command.withSubcommands([
|
|
310
|
+
Command.make(
|
|
311
|
+
"import",
|
|
312
|
+
{
|
|
313
|
+
source: Argument.String("dir").pipe(Argument.withDescription("The plugin's directory")),
|
|
314
|
+
host: Flag.String("host").pipe(
|
|
315
|
+
Flag.withDescription(`Hosts its MCP servers are listed for (default: ${MCP_HOST_NAMES.join(", ")})`),
|
|
316
|
+
Flag.optional,
|
|
317
|
+
),
|
|
318
|
+
cwd: Flag.String("cwd").pipe(Flag.withDescription("The app's directory (default: here)"), Flag.optional),
|
|
319
|
+
dryRun: Flag.Boolean("dry-run").pipe(Flag.withDescription("Report, write nothing"), Flag.withDefault(false)),
|
|
320
|
+
replace: Flag.Boolean("replace").pipe(
|
|
321
|
+
Flag.withDescription("Replace an MCP server of the same name already listed with another endpoint"),
|
|
322
|
+
Flag.withDefault(false),
|
|
323
|
+
),
|
|
324
|
+
json: Flag.Boolean("json").pipe(Flag.withDescription("Print the report as JSON"), Flag.withDefault(false)),
|
|
325
|
+
},
|
|
326
|
+
Effect.fn(function* ({ source, host, cwd, dryRun, replace, json }) {
|
|
327
|
+
const path = yield* Path.Path
|
|
328
|
+
const dir = path.resolve(Option.getOrElse(cwd, () => process.cwd()))
|
|
329
|
+
const hosts = Option.isNone(host)
|
|
330
|
+
? MCP_HOST_NAMES
|
|
331
|
+
: (host.value.split(",").map((h) => h.trim()) as Array<McpHost>)
|
|
332
|
+
const unknown = hosts.filter((h) => !MCP_HOST_NAMES.includes(h))
|
|
333
|
+
if (unknown.length > 0) {
|
|
334
|
+
return yield* new CliError({
|
|
335
|
+
message: `Unknown host ${unknown.join(", ")} (hosts: ${MCP_HOST_NAMES.join(", ")})`,
|
|
336
|
+
})
|
|
337
|
+
}
|
|
338
|
+
const report = yield* importPlugin(dir, path.resolve(source), { hosts, dryRun, replace })
|
|
339
|
+
yield* Console.log(json ? JSON.stringify(report, null, 2) : formatPlugin(report, dryRun))
|
|
340
|
+
}),
|
|
341
|
+
).pipe(
|
|
342
|
+
Command.withDescription(
|
|
343
|
+
"Import a plugin's skills as inert development skills, and its remote MCP servers into the hosts' configuration",
|
|
344
|
+
),
|
|
345
|
+
),
|
|
346
|
+
]),
|
|
347
|
+
)
|