capable-kit 0.0.1-alpha.8 → 0.1.0-alpha.11
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/CHANGELOG.md +385 -0
- package/LICENSE +21 -0
- package/README.md +12 -0
- package/dist/ai-sdk.d.mts +3 -3
- package/dist/ai-sdk.mjs +9 -7
- package/dist/ai-sdk.mjs.map +1 -1
- package/dist/app.d.mts +2 -2
- package/dist/app.mjs +2 -2
- package/dist/bin.mjs +19 -15
- package/dist/bin.mjs.map +1 -1
- package/dist/cli.d.mts +9 -1
- package/dist/cli.mjs +1 -1
- package/dist/core.d.mts +3 -3
- package/dist/core.mjs +2 -2
- package/dist/eve.d.mts +92 -9
- package/dist/eve.mjs +606 -26
- package/dist/eve.mjs.map +1 -1
- package/dist/http.d.mts +1 -1
- package/dist/http.mjs +1 -1
- package/dist/{index-_qKFfWV4.d.mts → index-BIO_hbXJ.d.mts} +69 -26
- package/dist/{index-hdH_K5Zc.d.mts → index-C0tU5Y2n.d.mts} +4 -4
- package/dist/{index-Dl4NK9G0.d.mts → index-CwvjDizW.d.mts} +5 -3
- package/dist/{index-F4ba_olD.d.mts → index-F_eaksy8.d.mts} +58 -17
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +3 -3
- package/dist/mcp.d.mts +19 -4
- package/dist/mcp.mjs +2 -2
- package/dist/{mount-CEFAplR5.mjs → mount-pvIaehZC.mjs} +159 -107
- package/dist/mount-pvIaehZC.mjs.map +1 -0
- package/dist/react-query.d.mts +2 -2
- package/dist/react-query.mjs +1 -1
- package/dist/react-query.mjs.map +1 -1
- package/dist/runtime-support.d.mts +1 -1
- package/dist/runtime-support.mjs +3 -3
- package/dist/server.d.mts +1 -1
- package/dist/server.mjs +1 -1
- package/dist/{src-rkr5j_NH.mjs → src-Bk3lEhI7.mjs} +63 -25
- package/dist/src-Bk3lEhI7.mjs.map +1 -0
- package/dist/src-C2OEkZ3c.mjs +760 -0
- package/dist/src-C2OEkZ3c.mjs.map +1 -0
- package/dist/{src-BWxDO2Ua.mjs → src-DFrxQ_S6.mjs} +9 -7
- package/dist/src-DFrxQ_S6.mjs.map +1 -0
- package/dist/{src-D_0PIhqq.mjs → src-DklM1g7V.mjs} +69 -40
- package/dist/src-DklM1g7V.mjs.map +1 -0
- package/dist/{src-D-cm2gQ6.mjs → src-TCQGaWar.mjs} +119 -45
- package/dist/src-TCQGaWar.mjs.map +1 -0
- package/dist/{subscription-B-auXJbm.d.mts → subscription-fVgS4T8P.d.mts} +2 -2
- package/dist/swr.d.mts +2 -2
- package/dist/swr.mjs +1 -1
- package/dist/swr.mjs.map +1 -1
- package/docs/CONTEXT.md +44 -22
- package/docs/README.md +3 -0
- package/docs/internal/README.md +3 -0
- package/docs/internal/adr/0001-capability-is-the-semantic-boundary.md +1 -1
- package/docs/internal/adr/0003-capability-reference-customization.md +68 -0
- package/docs/internal/architecture.md +31 -17
- package/docs/internal/capability-first-model.md +126 -17
- package/docs/internal/eve-recovery-validation.md +87 -0
- package/docs/internal/feedback/v-ray/README.md +258 -0
- package/docs/internal/feedback/v-ray/inference.mjs +43 -0
- package/docs/internal/feedback/v-ray/reproduce.mjs +36 -0
- package/docs/internal/implementation-friction.md +445 -1
- package/docs/internal/releases.md +79 -0
- package/docs/site/capable-orpc-and-trpc.mdx +2 -2
- package/docs/site/concepts/apps.mdx +7 -1
- package/docs/site/concepts/architecture.mdx +9 -1
- package/docs/site/concepts/capabilities.mdx +41 -4
- package/docs/site/concepts/errors.mdx +26 -4
- package/docs/site/concepts/presentations.mdx +20 -0
- package/docs/site/hosting/standalone-server.mdx +2 -0
- package/docs/site/patterns/composition.mdx +152 -8
- package/docs/site/patterns/remote-apps.mdx +29 -3
- package/docs/site/patterns/subscriptions.mdx +79 -32
- package/docs/site/quickstart.mdx +3 -2
- package/docs/site/reference/packages-and-entry-points.mdx +52 -4
- package/docs/site/reference/the-cap-cli.mdx +2 -2
- package/docs/site/surfaces/cli.mdx +44 -0
- package/docs/site/surfaces/eve.mdx +67 -18
- package/docs/site/surfaces/mcp.mdx +84 -2
- package/docs/site/surfaces/typescript.mdx +3 -3
- package/package-docs.mjs +3 -0
- package/package.json +17 -12
- package/src/bin.ts +0 -0
- package/src/index.test.ts +2 -1
- package/src/index.ts +8 -1
- package/src/package.test.ts +15 -0
- package/dist/mount-CEFAplR5.mjs.map +0 -1
- package/dist/src-BWxDO2Ua.mjs.map +0 -1
- package/dist/src-D-cm2gQ6.mjs.map +0 -1
- package/dist/src-D_0PIhqq.mjs.map +0 -1
- package/dist/src-betOfnDL.mjs +0 -481
- package/dist/src-betOfnDL.mjs.map +0 -1
- package/dist/src-rkr5j_NH.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-C2OEkZ3c.mjs","names":["samePath"],"sources":["../../app/src/manifest.ts","../../app/src/runtime.ts","../../app/src/customization.ts","../../app/src/composition.ts"],"sourcesContent":["import {\n isCapability,\n isCapabilityGroup,\n schemaToJsonSchema,\n type AnySchema,\n type CapabilityExecution,\n type AppDefinition,\n type LocatedCapability,\n} from \"@capable/core\";\n\nexport type JsonSchema = Readonly<Record<string, unknown>>;\n\nexport type ManifestError = {\n readonly message?: string;\n readonly data?: JsonSchema;\n readonly status?: number;\n readonly meta?: Readonly<Record<string, unknown>>;\n};\n\nexport type ManifestCapability = {\n readonly type: \"capability\";\n readonly customization?: {\n /** Use the Capability's placed path for surface navigation. */\n readonly navigation?: \"destination\";\n readonly title?: string;\n readonly description?: string;\n readonly meta?: Readonly<Record<string, unknown>>;\n };\n readonly id: string;\n readonly path: readonly string[];\n readonly title?: string;\n readonly description?: string;\n readonly deprecated: boolean;\n readonly effect?: \"read\" | \"write\" | \"destructive\";\n readonly execution: CapabilityExecution;\n readonly input?: JsonSchema;\n readonly output?: JsonSchema;\n readonly errors: Readonly<Record<string, ManifestError>>;\n readonly meta: Readonly<Record<string, unknown>>;\n};\n\nexport type ManifestGroup = {\n readonly type: \"group\";\n readonly key: string;\n readonly title?: string;\n readonly description?: string;\n readonly meta: Readonly<Record<string, unknown>>;\n readonly children: readonly ManifestNode[];\n};\n\nexport type ManifestNode = ManifestGroup | ManifestCapability;\n\nexport type ApplicationManifest = {\n readonly protocol: \"capable.capabilities.v4\";\n readonly name: string;\n readonly version: string;\n readonly description?: string;\n readonly capabilities: readonly ManifestNode[];\n};\n\nexport function createAppManifest(\n definition: AppDefinition<any>,\n): ApplicationManifest {\n const byCapability = new Map(\n definition.locatedCapabilities.map((entry) => [entry.capability, entry]),\n );\n return Object.freeze({\n protocol: \"capable.capabilities.v4\",\n name: definition.name,\n version: definition.version,\n ...(definition.description ? { description: definition.description } : {}),\n capabilities: manifestNodes(definition.capabilities, byCapability),\n });\n}\n\nexport function validateManifest(\n manifest: ApplicationManifest,\n label: string,\n): void {\n if (!manifest || typeof manifest !== \"object\") {\n throw new Error(`${label} manifest must be an object`);\n }\n if (manifest.protocol !== \"capable.capabilities.v4\") {\n throw new Error(`${label} uses unsupported protocol \"${manifest.protocol}\"`);\n }\n const capabilities = flattenManifestCapabilities(manifest.capabilities);\n const ids = new Map<string, ManifestCapability>();\n const paths = new Set<string>();\n for (const capability of capabilities) {\n if (![\"unary\", \"live\", \"events\"].includes(capability.execution)) {\n throw new Error(`${label} contains unsupported execution kind for Capability \"${capability.id}\"`);\n }\n if (capability.execution !== \"unary\" && capability.effect !== \"read\") {\n throw new Error(`${label} subscribable Capability \"${capability.id}\" must have effect \"read\"`);\n }\n const path = capability.path.join(\".\");\n const previous = ids.get(capability.id);\n if (previous && !sameCapabilityContract(previous, capability)) {\n throw new Error(\n `${label} contains conflicting definitions for Capability id \"${capability.id}\"`,\n );\n }\n if (paths.has(path)) {\n throw new Error(`${label} contains duplicate Capability path \"${path}\"`);\n }\n ids.set(capability.id, capability);\n paths.add(path);\n }\n validateManifestPaths(manifest.capabilities, [], label);\n}\n\nexport type ApplicationManifestSource<TOwner extends object = object> = {\n readonly manifest: ApplicationManifest;\n /** Identity used only to avoid repeating one source in the composed label. */\n readonly application: object;\n /** Terminal execution owner for every Capability ID in this source view. */\n readonly owners: ReadonlyMap<string, TOwner>;\n};\n\nexport function composeApplicationManifests(\n sources: readonly ApplicationManifestSource[],\n): ApplicationManifest {\n const conflicts = collectManifestConflicts(sources);\n if (conflicts.length) {\n throw new Error(\n `Cannot compose Apps:\\n${conflicts.map((item) => `- ${item}`).join(\"\\n\")}`,\n );\n }\n const manifests = sources.map(({ manifest }) => manifest);\n const applications = sources.filter((source, index) =>\n sources.findIndex(({ application }) => application === source.application) === index\n ).map(({ manifest }) => manifest);\n return Object.freeze({\n protocol: \"capable.capabilities.v4\",\n name: applications.map(({ name }) => name).join(\" + \"),\n version: applications.map(({ version }) => version).join(\" + \"),\n capabilities: mergeManifestNodes(\n manifests.flatMap(({ capabilities }) => capabilities),\n ),\n });\n}\n\nexport function selectManifest(\n source: ApplicationManifest,\n selection: {\n readonly include?: unknown;\n readonly exclude?: unknown;\n },\n): ApplicationManifest {\n validateSelectionTree(selection.include, source.capabilities, \"include\", []);\n validateSelectionTree(selection.exclude, source.capabilities, \"exclude\", []);\n return Object.freeze({\n ...source,\n capabilities: filterManifestNodes(source.capabilities, selection),\n });\n}\n\nfunction validateSelectionTree(\n tree: unknown,\n nodes: readonly ManifestNode[],\n label: \"include\" | \"exclude\",\n parent: readonly string[],\n): void {\n if (tree === undefined || tree === true) return;\n if (!tree || typeof tree !== \"object\" || Array.isArray(tree)) {\n throw new Error(\n `Application selection ${label} at \"${parent.join(\".\") || \"<root>\"}\" must be an object or true`,\n );\n }\n for (const [key, child] of Object.entries(tree)) {\n const path = [...parent, key];\n const node = nodes.find((candidate) =>\n candidate.type === \"group\"\n ? candidate.key === key\n : candidate.path.at(-1) === key\n );\n if (!node) {\n throw new Error(\n `Application selection ${label} references unknown path \"${path.join(\".\")}\"`,\n );\n }\n if (child === true) continue;\n if (node.type === \"capability\") {\n throw new Error(\n `Application selection ${label} at \"${path.join(\".\")}\" must be true`,\n );\n }\n validateSelectionTree(child, node.children, label, path);\n }\n}\n\nexport function flattenManifestCapabilities(\n nodes: readonly ManifestNode[],\n): readonly ManifestCapability[] {\n return nodes.flatMap((node) =>\n node.type === \"capability\"\n ? [node]\n : flattenManifestCapabilities(node.children)\n );\n}\n\nexport function findManifestCapability(\n nodes: readonly ManifestNode[],\n path: readonly string[],\n): ManifestCapability | undefined {\n const node = findManifestNode(nodes, path);\n return node?.type === \"capability\" ? node : undefined;\n}\n\nexport function findManifestNode(\n nodes: readonly ManifestNode[],\n path: readonly string[],\n): ManifestNode | undefined {\n let current = nodes;\n for (let index = 0; index < path.length; index++) {\n const key = path[index]!;\n const node = current.find((candidate) =>\n candidate.type === \"group\"\n ? candidate.key === key\n : candidate.path.at(-1) === key\n );\n if (!node) return undefined;\n if (node.type === \"capability\") {\n return index === path.length - 1 ? node : undefined;\n }\n if (index === path.length - 1) return node;\n current = node.children;\n }\n return undefined;\n}\n\nfunction manifestNodes(\n tree: Readonly<Record<string, unknown>>,\n located: ReadonlyMap<unknown, LocatedCapability>,\n): readonly ManifestNode[] {\n const nodes: ManifestNode[] = [];\n for (const [key, value] of Object.entries(tree)) {\n if (isCapability(value)) {\n const entry = located.get(value);\n if (entry) nodes.push(manifestCapability(entry));\n continue;\n }\n const decorated = isCapabilityGroup(value);\n const childTree = decorated\n ? value.capabilities\n : value as Readonly<Record<string, unknown>>;\n const children = manifestNodes(childTree, located);\n nodes.push(Object.freeze({\n type: \"group\",\n key,\n ...(decorated && value.title ? { title: value.title } : {}),\n ...(decorated && value.description\n ? { description: value.description }\n : {}),\n meta: decorated ? value.meta : {},\n children,\n } satisfies ManifestGroup));\n }\n return nodes;\n}\n\nfunction manifestCapability(entry: LocatedCapability): ManifestCapability {\n const capability = entry.capability;\n return Object.freeze({\n type: \"capability\",\n id: capability.id,\n path: entry.path,\n ...(capability.title ? { title: capability.title } : {}),\n ...(capability.description ? { description: capability.description } : {}),\n deprecated: capability.deprecated,\n ...(capability.effect ? { effect: capability.effect } : {}),\n execution: capability.execution,\n ...(capability.input\n ? { input: manifestJsonSchema(capability.input, \"input\") }\n : {}),\n ...(capability.output\n ? { output: manifestJsonSchema(capability.output, \"output\") }\n : {}),\n errors: Object.fromEntries(\n Object.entries(entry.errors).map(([code, definition]) => [\n code,\n {\n ...(definition.message ? { message: definition.message } : {}),\n ...(typeof definition.status === \"number\"\n ? { status: definition.status }\n : {}),\n ...(definition.data\n ? { data: manifestJsonSchema(definition.data, \"output\") }\n : {}),\n ...(definition.meta ? { meta: definition.meta } : {}),\n } satisfies ManifestError,\n ]),\n ),\n meta: capability.meta,\n });\n}\n\nfunction manifestJsonSchema(\n schema: AnySchema,\n direction: \"input\" | \"output\",\n): JsonSchema {\n return schemaToJsonSchema(schema, direction, {\n allowUnrepresentable: true,\n });\n}\n\nfunction validateManifestPaths(\n nodes: readonly ManifestNode[],\n parent: readonly string[],\n label: string,\n): void {\n for (const node of nodes) {\n if (node.type === \"group\") {\n validateManifestPaths(node.children, [...parent, node.key], label);\n continue;\n }\n if (!samePath(node.path, [...parent, node.path.at(-1)!])) {\n throw new Error(\n `${label} Capability \"${node.id}\" declares path \"${node.path.join(\".\")}\" that does not match its manifest placement`,\n );\n }\n }\n}\n\nfunction collectManifestConflicts(\n sources: readonly ApplicationManifestSource[],\n): readonly string[] {\n const conflicts: string[] = [];\n for (const { manifest } of sources) {\n try {\n validateManifest(manifest, manifest.name);\n } catch (error) {\n conflicts.push(error instanceof Error ? error.message : String(error));\n }\n }\n const capabilities = sources.flatMap(({ manifest, owners }, source) =>\n flattenManifestCapabilities(manifest.capabilities).map((capability) => ({\n capability,\n source,\n owner: requiredOwner(owners, capability.id, manifest.name),\n label: manifest.name,\n }))\n );\n for (let leftIndex = 0; leftIndex < capabilities.length; leftIndex++) {\n for (\n let rightIndex = leftIndex + 1;\n rightIndex < capabilities.length;\n rightIndex++\n ) {\n const left = capabilities[leftIndex]!;\n const right = capabilities[rightIndex]!;\n if (left.source === right.source) continue;\n const sameId = left.capability.id === right.capability.id;\n const sameCapabilityPath = samePath(\n left.capability.path,\n right.capability.path,\n );\n if (sameCapabilityPath) {\n conflicts.push(\n sameId\n ? `Capability \"${left.capability.id}\" is placed twice at \"${left.capability.path.join(\".\")}\" by \"${left.label}\" and \"${right.label}\"`\n : `Path \"${left.capability.path.join(\".\")}\" contains both \"${left.capability.id}\" from \"${left.label}\" and \"${right.capability.id}\" from \"${right.label}\"`,\n );\n continue;\n }\n if (sameId) {\n if (left.owner !== right.owner) {\n conflicts.push(\n `Capability id \"${left.capability.id}\" is owned by different Apps at \"${left.capability.path.join(\".\")}\" in \"${left.label}\" and \"${right.capability.path.join(\".\")}\"`,\n );\n }\n }\n if (\n isPathPrefix(left.capability.path, right.capability.path) ||\n isPathPrefix(right.capability.path, left.capability.path)\n ) {\n const leaf = left.capability.path.length < right.capability.path.length\n ? left\n : right;\n const subtree = leaf === left ? right : left;\n conflicts.push(\n `Leaf \"${leaf.capability.path.join(\".\")}\" from \"${leaf.label}\" collides with subtree Capability \"${subtree.capability.path.join(\".\")}\" from \"${subtree.label}\"`,\n );\n }\n }\n }\n return [...new Set(conflicts)];\n}\n\nfunction requiredOwner(\n owners: ReadonlyMap<string, object>,\n capabilityId: string,\n application: string,\n): object {\n const owner = owners.get(capabilityId);\n if (!owner) {\n throw new Error(\n `Missing execution owner for Capability \"${capabilityId}\" in \"${application}\"`,\n );\n }\n return owner;\n}\n\nfunction sameCapabilityContract(\n left: ManifestCapability,\n right: ManifestCapability,\n): boolean {\n const { path: _leftPath, customization: _leftCustomization, ...leftContract } = left;\n const { path: _rightPath, customization: _rightCustomization, ...rightContract } = right;\n return JSON.stringify(leftContract) === JSON.stringify(rightContract);\n}\n\nfunction mergeManifestNodes(\n nodes: readonly ManifestNode[],\n): readonly ManifestNode[] {\n const merged = new Map<string, ManifestNode>();\n for (const node of nodes) {\n const key = node.type === \"group\" ? node.key : node.path.at(-1)!;\n const previous = merged.get(key);\n if (!previous) {\n merged.set(key, node);\n continue;\n }\n if (previous.type !== \"group\" || node.type !== \"group\") {\n throw new Error(`Manifest node collision at \"${key}\"`);\n }\n merged.set(key, Object.freeze({\n type: \"group\",\n key,\n ...mergeGroupField(\"title\", previous.title, node.title, key),\n ...mergeGroupField(\n \"description\",\n previous.description,\n node.description,\n key,\n ),\n meta: mergeGroupMeta(previous.meta, node.meta, key),\n children: mergeManifestNodes([...previous.children, ...node.children]),\n }));\n }\n return [...merged.values()];\n}\n\nfunction mergeGroupField(\n field: \"title\" | \"description\",\n left: string | undefined,\n right: string | undefined,\n path: string,\n): Record<string, string> {\n if (left && right && left !== right) {\n throw new Error(`Group \"${path}\" has conflicting ${field}`);\n }\n const value = left ?? right;\n return value ? { [field]: value } : {};\n}\n\nfunction mergeGroupMeta(\n left: Readonly<Record<string, unknown>>,\n right: Readonly<Record<string, unknown>>,\n path: string,\n): Readonly<Record<string, unknown>> {\n const merged: Record<string, unknown> = { ...left };\n for (const [key, value] of Object.entries(right)) {\n if (\n key in merged &&\n JSON.stringify(merged[key]) !== JSON.stringify(value)\n ) {\n throw new Error(\n `Group \"${path}\" has conflicting metadata for \"${key}\"`,\n );\n }\n merged[key] = value;\n }\n return Object.freeze(merged);\n}\n\nfunction filterManifestNodes(\n nodes: readonly ManifestNode[],\n selection: {\n readonly include?: unknown;\n readonly exclude?: unknown;\n },\n): readonly ManifestNode[] {\n const filtered: ManifestNode[] = [];\n for (const node of nodes) {\n if (node.type === \"capability\") {\n const included = selection.include\n ? matchesManifestSelection(selection.include, node.path)\n : true;\n if (\n included && !matchesManifestSelection(selection.exclude, node.path)\n ) {\n filtered.push(node);\n }\n continue;\n }\n const children = filterManifestNodes(node.children, selection);\n if (children.length) filtered.push(Object.freeze({ ...node, children }));\n }\n return filtered;\n}\n\nfunction matchesManifestSelection(\n tree: unknown,\n path: readonly string[],\n): boolean {\n let current = tree;\n for (const segment of path) {\n if (current === true) return true;\n if (!current || typeof current !== \"object\" || Array.isArray(current)) {\n return false;\n }\n current = (current as Record<string, unknown>)[segment];\n }\n return current === true || (\n Boolean(current) && typeof current === \"object\" && !Array.isArray(current)\n );\n}\n\nfunction samePath(\n left: readonly string[],\n right: readonly string[],\n): boolean {\n return left.length === right.length &&\n left.every((segment, index) => segment === right[index]);\n}\n\nfunction isPathPrefix(\n prefix: readonly string[],\n path: readonly string[],\n): boolean {\n return prefix.length < path.length &&\n prefix.every((segment, index) => segment === path[index]);\n}\n","import {\n CapableError,\n executeLocatedCapability,\n markPublicError,\n normalizePresentation,\n subscribeLocatedCapability,\n unmarkPublicError,\n type AnyCapability,\n type AnyObjectSchema,\n type AppDefinition,\n type AppContext,\n type InferSchemaInput,\n type LocatedCapability,\n type MaybePromise,\n type PresentationPart,\n type CapabilityDefinition,\n type CapabilityGroupDefinition,\n type CapabilityOutput,\n type CapabilityTree,\n type SubscribableCapability,\n} from \"@capable/core\";\nimport {\n createAppManifest,\n findManifestCapability,\n validateManifest,\n type ApplicationManifest,\n type ManifestCapability,\n} from \"./manifest.ts\";\n\nexport type CapabilityCall = {\n readonly id: string;\n readonly input?: unknown;\n readonly signal?: AbortSignal;\n readonly presentation?: boolean;\n};\n\nexport type CapabilityResult = {\n readonly output: unknown;\n readonly presentation?: readonly PresentationPart[];\n};\n\nexport interface ApplicationTransport {\n manifest(\n options?: { readonly signal?: AbortSignal },\n ): Promise<ApplicationManifest>;\n call(call: CapabilityCall): Promise<CapabilityResult>;\n subscribe(\n call: CapabilityCall,\n ): Promise<AsyncIterableIterator<CapabilityResult>>;\n}\n\nexport type CreateRemoteAppOptions = {\n readonly manifest?: ApplicationManifest;\n};\n\nexport type ResolvedCapability = {\n readonly capability: ManifestCapability;\n readonly transport: ApplicationTransport;\n};\n\n/** The in-process runtime can bind one path without resolving sibling Apps. */\nexport interface ApplicationRuntime extends ApplicationTransport {\n resolve(path: readonly string[]): Promise<ResolvedCapability | undefined>;\n}\n\nfunction mapAsyncIterator<TInput, TOutput>(\n source: AsyncIterableIterator<TInput>,\n transform: (value: TInput) => TOutput | Promise<TOutput>,\n transformError: (error: unknown) => unknown = (error) => error,\n): AsyncIterableIterator<TOutput> {\n let failed = false;\n return {\n [Symbol.asyncIterator]() {\n return this;\n },\n async next() {\n try {\n const result = await source.next();\n return result.done\n ? { done: true, value: undefined }\n : { done: false, value: await transform(result.value) };\n } catch (error) {\n failed = true;\n await source.return?.().catch(() => undefined);\n throw transformError(error);\n }\n },\n async return() {\n if (failed) return { done: true, value: undefined };\n try {\n await source.return?.();\n return { done: true, value: undefined };\n } catch (error) {\n throw transformError(error);\n }\n },\n };\n}\n\nexport const APP_RUNTIME_SYMBOL: unique symbol = Symbol.for(\n \"capable.app.runtime\",\n) as never;\nexport const APP_CAPABILITIES_SYMBOL: unique symbol = Symbol.for(\n \"capable.app.capabilities\",\n) as never;\nconst APP_CALL_SYMBOL = Symbol.for(\"capable.app.call\");\n\nexport type CapabilityBinding = {\n readonly runtime: ApplicationRuntime;\n readonly path: readonly string[];\n};\n\n/** @internal Shared by composition and subscriptions; ordinary functions are not references. */\nexport function getCapabilityBinding(\n value: unknown,\n): CapabilityBinding | undefined {\n return typeof value === \"function\"\n ? (value as unknown as Record<symbol, CapabilityBinding>)[APP_CALL_SYMBOL]\n : undefined;\n}\n\nexport type AppCapabilityReference<\n TCapability extends AnyCapability = AnyCapability,\n> = {\n readonly \"~capable/capability\": TCapability;\n};\n\ntype AppCapabilityInput<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, infer TInput, any, any, any>\n ? TInput extends AnyObjectSchema\n ? InferSchemaInput<TInput>\n : Record<never, never>\n : never;\n\ntype AppCapabilityOutput<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, any, infer TOutput, any, any>\n ? TOutput\n : never;\n\ntype AppCapabilityOptions = { readonly signal?: AbortSignal };\n\ntype AppCapabilityArgs<TCapability extends AnyCapability> =\n TCapability extends CapabilityDefinition<any, infer TInput, any, any, any>\n ? TInput extends undefined\n ? [\n input?: Record<never, never>,\n options?: AppCapabilityOptions,\n ]\n : Record<never, never> extends AppCapabilityInput<TCapability>\n ? [\n input?: AppCapabilityInput<TCapability>,\n options?: AppCapabilityOptions,\n ]\n : [\n input: AppCapabilityInput<TCapability>,\n options?: AppCapabilityOptions,\n ]\n : never;\n\nexport type AppCapabilityCall<TCapability extends AnyCapability> = ((\n ...args: AppCapabilityArgs<TCapability>\n) => Promise<AppCapabilityOutput<TCapability>>) &\n AppCapabilityReference<TCapability>;\n\nexport type AppCapabilityIsSubscribable<TCall> =\n TCall extends AppCapabilityReference<infer TCapability>\n ? TCapability[\"execution\"] extends \"live\" | \"events\" ? true : false\n : false;\n\nexport type AppCapabilityIsLive<TCall> =\n TCall extends AppCapabilityReference<infer TCapability>\n ? TCapability[\"execution\"] extends \"live\" ? true : false\n : false;\n\nexport type CallableTree<TTree> =\n TTree extends AnyCapability\n ? TTree[\"execution\"] extends \"events\"\n ? AppCapabilityReference<TTree>\n : AppCapabilityCall<TTree>\n : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any>\n ? CallableTree<TCapabilities>\n : TTree extends CapabilityTree\n ? { readonly [TKey in keyof TTree]: CallableTree<TTree[TKey]> }\n : never;\n\nexport type App<\n TCapabilities extends CapabilityTree = CapabilityTree,\n> = CallableTree<TCapabilities> & {\n readonly [APP_RUNTIME_SYMBOL]: ApplicationTransport;\n readonly [APP_CAPABILITIES_SYMBOL]?: TCapabilities;\n};\n\nexport type AnyApp = {\n readonly [APP_RUNTIME_SYMBOL]: ApplicationTransport;\n readonly [APP_CAPABILITIES_SYMBOL]?: CapabilityTree;\n};\n\ntype DefinitionCapabilities<TDefinition extends AppDefinition<any, any>> =\n TDefinition extends AppDefinition<infer TCapabilities>\n ? TCapabilities\n : never;\n\nexport type AppCapabilities<\n TApplication extends AnyApp,\n> = TApplication extends {\n readonly [APP_CAPABILITIES_SYMBOL]?: infer TCapabilities extends CapabilityTree;\n}\n ? TCapabilities\n : never;\n\nexport function getAppRuntime(\n app: AnyApp,\n): ApplicationTransport {\n return app[APP_RUNTIME_SYMBOL];\n}\n\n/** @internal Composition uses path bindings without exposing them to transports. */\nexport function getInternalAppRuntime(\n app: AnyApp,\n): ApplicationRuntime {\n const runtime = app[APP_RUNTIME_SYMBOL];\n if (!(\"resolve\" in runtime) || typeof runtime.resolve !== \"function\") {\n throw new TypeError(\"Capable App is missing its internal path resolver\");\n }\n return runtime as ApplicationRuntime;\n}\n\nexport function isApp(value: unknown): value is AnyApp {\n return Boolean(\n value &&\n (typeof value === \"object\" || typeof value === \"function\") &&\n (value as Partial<AnyApp>)[APP_RUNTIME_SYMBOL],\n );\n}\n\nexport function appFromRuntime<\n TCapabilities extends CapabilityTree,\n>(\n runtime: ApplicationRuntime,\n): App<TCapabilities> {\n const read = (path: readonly string[], root: boolean, key: PropertyKey) => {\n if (root && key === APP_RUNTIME_SYMBOL) return runtime;\n if (!root && key === APP_CALL_SYMBOL) return { runtime, path };\n if (key === \"then\") return undefined;\n if (typeof key !== \"string\") return undefined;\n return proxy([...path, key], false);\n };\n\n const proxy = (path: readonly string[], root: boolean): unknown => {\n if (root) {\n return new Proxy({}, {\n get(_target, key) {\n return read(path, true, key);\n },\n });\n }\n return new Proxy(() => undefined, {\n get(_target, key) {\n return read(path, false, key);\n },\n async apply(_target, _this, args: [unknown?, { signal?: AbortSignal }?]) {\n const signal = args[1]?.signal;\n const binding = await runtime.resolve(path);\n if (!binding) {\n throw new Error(`No Capability exists at \"${path.join(\".\")}\"`);\n }\n if (binding.capability.execution === \"events\") {\n throw wrongExecutionMode(binding.capability.id, \"subscribe\");\n }\n const result = await binding.transport.call({\n id: binding.capability.id,\n input: args[0] ?? {},\n ...(signal ? { signal } : {}),\n });\n return result.output;\n },\n });\n };\n\n return proxy([], true) as App<TCapabilities>;\n}\n\nexport function subscribe<\n const TCapability extends SubscribableCapability,\n>(\n capabilityCall: AppCapabilityReference<TCapability>,\n ...args: AppCapabilityArgs<TCapability>\n): AsyncIterableIterator<CapabilityOutput<TCapability>> {\n const binding = getCapabilityBinding(capabilityCall);\n if (!binding) {\n throw new Error(\"subscribe() requires a Capability call from a Capable App\");\n }\n\n return (async function* () {\n const signal = args[1]?.signal;\n const resolved = await binding.runtime.resolve(binding.path);\n if (!resolved) {\n throw new Error(`No Capability exists at \"${binding.path.join(\".\")}\"`);\n }\n if (resolved.capability.execution === \"unary\") {\n throw wrongExecutionMode(resolved.capability.id, \"call\");\n }\n const stream = await resolved.transport.subscribe({\n id: resolved.capability.id,\n input: args[0] ?? {},\n ...(signal ? { signal } : {}),\n });\n yield* mapAsyncIterator(\n stream,\n (result) => result.output as CapabilityOutput<TCapability>,\n );\n })();\n}\n\nexport type AppContextProvider<TContext> = (call: {\n readonly id: string;\n readonly signal?: AbortSignal;\n}) => MaybePromise<TContext>;\n\ntype CreateAppOptions<TContext> = {\n readonly context: AppContextProvider<TContext>;\n};\n\ntype CreateAppArgs<TContext> = [TContext] extends [undefined]\n ? [options?: Partial<CreateAppOptions<TContext>>]\n : [options: CreateAppOptions<TContext>];\n\nconst localManifestCache = new WeakMap<object, ApplicationManifest>();\nconst localCapabilityCache = new WeakMap<\n object,\n ReadonlyMap<string, LocatedCapability>\n>();\n\nexport function createApp<\n const TDefinition extends AppDefinition<any, any>,\n>(\n definition: TDefinition,\n ...[options]: CreateAppArgs<AppContext<TDefinition>>\n): App<DefinitionCapabilities<TDefinition>> {\n let manifest = localManifestCache.get(definition);\n if (!manifest) {\n manifest = createAppManifest(definition);\n localManifestCache.set(definition, manifest);\n }\n let byId = localCapabilityCache.get(definition);\n if (!byId) {\n byId = new Map(\n definition.locatedCapabilities.map((entry) => [entry.capability.id, entry]),\n );\n localCapabilityCache.set(definition, byId);\n }\n const runtime: ApplicationRuntime = Object.freeze({\n async manifest() {\n return manifest;\n },\n async resolve(path: readonly string[]) {\n const capability = findManifestCapability(manifest.capabilities, path);\n return capability ? { capability, transport: runtime } : undefined;\n },\n async call({ id, input = {}, signal, presentation: wantsPresentation }: CapabilityCall) {\n const located = byId.get(id);\n if (!located) {\n throw markPublicError(new TransportError(\"NOT_FOUND\", { status: 404 }));\n }\n if (located.capability.execution === \"events\") {\n throw wrongExecutionMode(id, \"subscribe\");\n }\n\n const context = await resolveContext(options?.context, id, signal);\n\n const output = await executeLocatedCapability(located, input, {\n context,\n ...(signal ? { signal } : {}),\n });\n\n const presentation = await materializePresentation(\n located.capability,\n output,\n context,\n wantsPresentation,\n );\n\n return {\n output,\n ...(presentation ? { presentation } : {}),\n };\n },\n async subscribe({\n id,\n input = {},\n signal,\n presentation: wantsPresentation,\n }: CapabilityCall) {\n const located = byId.get(id);\n if (!located) {\n throw markPublicError(new TransportError(\"NOT_FOUND\", { status: 404 }));\n }\n if (!located.capability.subscribe) {\n throw wrongExecutionMode(id, \"call\");\n }\n\n const context = await resolveContext(options?.context, id, signal);\n\n const stream = await subscribeLocatedCapability(located, input, {\n context,\n ...(signal ? { signal } : {}),\n });\n return mapAsyncIterator(\n stream,\n async (output) => {\n const presentation = await materializePresentation(\n located.capability,\n output,\n context,\n wantsPresentation,\n );\n return {\n output,\n ...(presentation ? { presentation } : {}),\n };\n },\n );\n },\n });\n return appFromRuntime(runtime);\n}\n\nexport function createRemoteApp<\n TDefinition extends AppDefinition<any, any> = AppDefinition<CapabilityTree>,\n>(\n transport: ApplicationTransport,\n options?: CreateRemoteAppOptions,\n): App<DefinitionCapabilities<TDefinition>> {\n const staticManifest = options?.manifest;\n if (staticManifest !== undefined) {\n validateManifest(staticManifest, \"Remote App\");\n }\n const manifest = staticManifest !== undefined\n ? () => Promise.resolve(staticManifest)\n : cacheAsync(async () => {\n const manifest = await transport.manifest();\n validateManifest(manifest, \"Remote App\");\n return manifest;\n });\n const runtime: ApplicationRuntime = Object.freeze({\n manifest,\n async resolve(path: readonly string[]) {\n const capability = findManifestCapability(\n (await manifest()).capabilities,\n path,\n );\n return capability ? { capability, transport } : undefined;\n },\n async call(call: CapabilityCall) {\n await manifest();\n return transport.call(call);\n },\n async subscribe(call: CapabilityCall) {\n await manifest();\n return transport.subscribe(call);\n },\n });\n return appFromRuntime(runtime);\n}\n\nexport function cacheAsync<T>(\n load: () => Promise<T>,\n): () => Promise<T> {\n let cached: Promise<T> | undefined;\n return () => {\n if (cached) return cached;\n const attempt = Promise.resolve().then(load);\n cached = attempt;\n void attempt.catch(() => {\n if (cached === attempt) cached = undefined;\n });\n return attempt;\n };\n}\n\nexport class TransportError extends Error {\n readonly code: string;\n readonly status: number | undefined;\n readonly data: unknown;\n\n constructor(\n code: string,\n options: {\n readonly message?: string;\n readonly status?: number;\n readonly data?: unknown;\n readonly cause?: unknown;\n } = {},\n ) {\n super(options.message ?? code, { cause: options.cause });\n this.name = \"TransportError\";\n this.code = code;\n this.status = options.status;\n this.data = options.data;\n }\n}\n\nasync function resolveContext(\n provider: AppContextProvider<any> | undefined,\n id: string,\n signal: AbortSignal | undefined,\n): Promise<unknown> {\n if (!provider) return undefined;\n try {\n return await provider({\n id,\n ...(signal ? { signal } : {}),\n });\n } catch (error) {\n if (error instanceof CapableError || error instanceof TransportError) {\n markPublicError(error);\n }\n throw error;\n }\n}\n\nasync function materializePresentation(\n capability: AnyCapability,\n output: unknown,\n context: unknown,\n requested: boolean | undefined,\n): Promise<readonly PresentationPart[] | undefined> {\n if (!requested || !capability.toPresentation) return undefined;\n try {\n const presentation = normalizePresentation(\n await capability.toPresentation(output, { context }),\n );\n return presentation.length > 0 ? presentation : undefined;\n } catch (error) {\n unmarkPublicError(error);\n throw error;\n }\n}\n\nfunction wrongExecutionMode(\n id: string,\n supported: \"call\" | \"subscribe\",\n): TransportError {\n return markPublicError(new TransportError(\"METHOD_NOT_ALLOWED\", {\n status: 405,\n message: `Capability \"${id}\" only supports ${supported}`,\n }));\n}\n","import type { AnyCapability } from \"@capable/core\";\nimport {\n getCapabilityBinding,\n type AppCapabilityReference,\n} from \"./runtime.ts\";\nimport type { ManifestCapability } from \"./manifest.ts\";\n\n// Global augmentation survives declaration bundling into capable-kit. Module\n// augmentations of private workspace paths do not survive that boundary.\ndeclare global {\n interface CapableCustomizationMeta {}\n}\n\nexport type CapabilityCustomization = {\n readonly title?: string;\n readonly description?: string;\n readonly meta?: keyof CapableCustomizationMeta extends never\n ? never\n : Partial<CapableCustomizationMeta>;\n};\n\nconst CUSTOMIZED_SYMBOL: unique symbol = Symbol.for(\"capable.customized\");\n\nexport type CustomizedCapability<TCapability extends AnyCapability = any> = {\n readonly [CUSTOMIZED_SYMBOL]: true;\n readonly reference: AppCapabilityReference<TCapability>;\n readonly customization: CapabilityCustomization;\n};\n\n/** Customize a bound local or remote reference without changing its execution. */\nexport function customize<TCapability extends AnyCapability>(\n reference:\n | AppCapabilityReference<TCapability>\n | CustomizedCapability<TCapability>,\n options: CapabilityCustomization,\n): CustomizedCapability<TCapability> {\n const previous = isCustomizedCapability(reference) ? reference : undefined;\n const original = (previous ? previous.reference : reference) as\n AppCapabilityReference<TCapability>;\n if (!getCapabilityBinding(original)) {\n throw new TypeError(\"customize() requires a Capability reference from a Capable App\");\n }\n if (!isRecord(options)) throw new TypeError(\"customize() options must be an object\");\n for (const key of Object.keys(options)) {\n if (key !== \"title\" && key !== \"description\" && key !== \"meta\") {\n throw new TypeError(`customize() does not support \"${key}\"`);\n }\n }\n for (const key of [\"title\", \"description\"] as const) {\n if (options[key] !== undefined && typeof options[key] !== \"string\") {\n throw new TypeError(`customize() ${key} must be a string`);\n }\n }\n if (options.meta !== undefined && !isRecord(options.meta)) {\n throw new TypeError(\"customize() meta must be an object\");\n }\n return Object.freeze({\n [CUSTOMIZED_SYMBOL]: true as const,\n reference: original,\n customization: mergeCustomization(previous?.customization, options) as CapabilityCustomization,\n });\n}\n\nexport function isCustomizedCapability(value: unknown): value is CustomizedCapability {\n return isRecord(value) && value[CUSTOMIZED_SYMBOL] === true;\n}\n\ntype ManifestCustomization = NonNullable<ManifestCapability[\"customization\"]>;\n\n/** Outer customizations replace supplied namespaces; no generic deep merge. */\nexport function mergeCustomization(\n source: ManifestCustomization | undefined,\n override: ManifestCustomization,\n): ManifestCustomization {\n return snapshot({\n ...source,\n ...override,\n ...(source?.meta || override.meta\n ? { meta: { ...source?.meta, ...override.meta } }\n : {}),\n }) as ManifestCustomization;\n}\n\n/** Surface-facing fields only. Policies and executors retain the source contract. */\nexport function getCapabilityDisplay(capability: ManifestCapability): {\n readonly title?: string;\n readonly description?: string;\n readonly meta: Readonly<Record<string, unknown>>;\n} {\n const { customization } = capability;\n return {\n ...(capability.title !== undefined ? { title: capability.title } : {}),\n ...(capability.description !== undefined ? { description: capability.description } : {}),\n ...(customization?.title !== undefined ? { title: customization.title } : {}),\n ...(customization?.description !== undefined ? { description: customization.description } : {}),\n meta: { ...capability.meta, ...customization?.meta },\n };\n}\n\n/** Navigation overrides come from the destination only for relocated leaves. */\nexport function getCapabilityNavigationMeta<\n TSurface extends keyof CapableCustomizationMeta,\n>(\n capability: ManifestCapability,\n surface: TSurface,\n): CapableCustomizationMeta[TSurface] | undefined {\n const value = capability.customization?.navigation === \"destination\"\n ? capability.customization.meta?.[surface as string]\n : capability.meta[surface as string];\n return value as CapableCustomizationMeta[TSurface] | undefined;\n}\n\n// Copy and freeze only portable JSON values: callers cannot mutate cached help,\n// and re-exporting a composed manifest cannot silently discard executable values.\nfunction snapshot(value: unknown, ancestors = new Set<unknown>()): unknown {\n if (value === null || typeof value === \"string\" || typeof value === \"boolean\") return value;\n if (typeof value === \"number\" && Number.isFinite(value)) return value;\n if (Array.isArray(value) || isRecord(value)) {\n if (ancestors.has(value)) throw new TypeError(\"customize() metadata must not contain cycles\");\n ancestors.add(value);\n const copy = Array.isArray(value)\n ? value.map((child) => snapshot(child, ancestors))\n : Object.fromEntries(Object.entries(value).filter(([, child]) => child !== undefined)\n .sort(([left], [right]) => left.localeCompare(right))\n .map(([key, child]) => [key, snapshot(child, ancestors)]));\n ancestors.delete(value);\n return Object.freeze(copy);\n }\n throw new TypeError(\"customize() metadata must contain only JSON values\");\n}\n\nfunction isRecord(value: unknown): value is Record<PropertyKey, unknown> {\n return value !== null && typeof value === \"object\" &&\n (Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null);\n}\n","import {\n markPublicError,\n type AnyCapability,\n type CapabilityGroupDefinition,\n type CapabilityTree,\n} from \"@capable/core\";\nimport {\n appFromRuntime,\n cacheAsync,\n getInternalAppRuntime,\n getCapabilityBinding,\n type AppCapabilityReference,\n isApp,\n TransportError,\n type AnyApp,\n type App,\n type AppCapabilities,\n type ApplicationRuntime,\n type ApplicationTransport,\n type CapabilityCall,\n} from \"./runtime.ts\";\nimport {\n flattenManifestCapabilities,\n composeApplicationManifests,\n findManifestCapability,\n findManifestNode,\n selectManifest,\n type ApplicationManifest,\n type ManifestNode,\n type ManifestCapability,\n type ManifestGroup,\n} from \"./manifest.ts\";\n\nimport {\n isCustomizedCapability,\n mergeCustomization,\n type CapabilityCustomization,\n type CustomizedCapability,\n} from \"./customization.ts\";\n\ntype UnionToIntersection<TValue> =\n (TValue extends unknown ? (value: TValue) => void : never) extends\n (value: infer TIntersection) => void ? TIntersection : never;\n\ntype AppComposition = AnyApp | {\n readonly [key: string]: AppComposition | AppCapabilityReference | CustomizedCapability;\n};\n\ntype ComposedNode<TNode> = TNode extends AnyApp\n ? AppCapabilities<TNode>\n : TNode extends CustomizedCapability<infer TCapability>\n ? TCapability\n : TNode extends AppCapabilityReference<infer TCapability>\n ? TCapability\n : TNode extends Readonly<Record<string, unknown>>\n ? { readonly [TKey in keyof TNode]: ComposedNode<TNode[TKey]> }\n : never;\n\ntype ComposedCapabilities<\n TNodes extends readonly AppComposition[],\n> = UnionToIntersection<ComposedNode<TNodes[number]>> extends\n infer TCapabilities extends CapabilityTree ? TCapabilities : never;\n\n/** Compose executable Apps, subtrees, and Capability references into one tree. */\nexport function composeApps<\n const TNodes extends readonly [\n AppComposition,\n ...AppComposition[],\n ],\n>(\n ...nodes: TNodes\n): App<ComposedCapabilities<TNodes>> {\n const placements = nodes.flatMap((node) => collectPlacements(node, []));\n const uniquePlacements = placements.filter((placement, index) =>\n placements.findIndex((candidate) =>\n candidate.runtime === placement.runtime &&\n samePath(candidate.path, placement.path) &&\n samePath(candidate.sourcePath, placement.sourcePath) &&\n JSON.stringify(candidate.customization) === JSON.stringify(placement.customization)\n ) === index\n );\n return appFromRuntime(\n createCompositionRuntime(uniquePlacements),\n ) as App<ComposedCapabilities<TNodes>>;\n}\n\ntype AppPlacement = {\n readonly path: readonly string[];\n readonly runtime: ApplicationRuntime;\n readonly sourcePath: readonly string[];\n readonly customization?: CapabilityCustomization;\n};\n\nfunction collectPlacements(\n node: AppComposition | AppCapabilityReference | CustomizedCapability,\n path: readonly string[],\n): readonly AppPlacement[] {\n const customized = isCustomizedCapability(node) ? node : undefined;\n const binding = getCapabilityBinding(customized ? customized.reference : node);\n if (binding) {\n return [{\n path: Object.freeze(path),\n runtime: binding.runtime,\n sourcePath: Object.freeze(binding.path),\n ...(customized ? { customization: customized.customization } : {}),\n }];\n }\n if (isApp(node)) {\n return [{\n path: Object.freeze(path),\n runtime: getInternalAppRuntime(node),\n sourcePath: Object.freeze([]),\n }];\n }\n if (!node || typeof node !== \"object\" || Array.isArray(node)) {\n throw new TypeError(\n \"composeApps() entries must be Apps, executable subtree references, Capability references, or named object trees\",\n );\n }\n const entries = Object.entries(node);\n if (entries.length === 0) {\n throw new Error(\n `composeApps() contains an empty object at \"${path.join(\".\") || \"<root>\"}\"`,\n );\n }\n return entries.flatMap(([key, child]) => {\n if (!key) throw new Error(\"composeApps() keys must not be empty\");\n if (key === \"then\") {\n throw new Error('composeApps() uses reserved key \"then\"');\n }\n return collectPlacements(child, [...path, key]);\n });\n}\n\nfunction createCompositionRuntime(\n placements: readonly AppPlacement[],\n): ApplicationRuntime {\n return derivedRuntime(async () => {\n const sources = await Promise.all(placements.map(resolvePlacement));\n const manifest = composeApplicationManifests(sources);\n const dispatch = new Map<string, ApplicationTransport>();\n for (const { owners } of sources) {\n for (const [id, target] of owners) {\n dispatch.set(id, target);\n }\n }\n return { manifest, dispatch };\n }, async (path) => {\n const matches = (await Promise.all(\n placements\n .filter((placement) => isPathPrefixOrEqual(placement.path, path))\n .map(async (placement) => {\n const resolved = await placement.runtime.resolve(\n [\n ...placement.sourcePath,\n ...path.slice(placement.path.length),\n ],\n );\n if (!resolved) return undefined;\n const relocatedLeaf = samePath(placement.path, path);\n if (placement.customization && !relocatedLeaf) {\n throw new TypeError(\n \"customize() requires a Capability reference, not an App subtree\",\n );\n }\n return {\n transport: resolved.transport,\n capability: placeCapability(resolved.capability, {\n path,\n relocatedLeaf,\n ...(relocatedLeaf && placement.customization\n ? { customization: placement.customization }\n : {}),\n }),\n };\n }),\n )).filter((match) => match !== undefined).filter((match, index, all) =>\n all.findIndex((candidate) =>\n candidate.capability.id === match.capability.id &&\n candidate.transport === match.transport &&\n JSON.stringify(candidate.capability.customization) === JSON.stringify(match.capability.customization)\n ) === index\n );\n if (matches.length > 1) throw new Error(`Cannot resolve ambiguous App path \"${path.join(\".\")}\"`);\n return matches[0];\n });\n}\n\nasync function resolvePlacement(placement: AppPlacement): Promise<{\n readonly manifest: ApplicationManifest;\n readonly application: object;\n readonly owners: ReadonlyMap<string, ApplicationTransport>;\n}> {\n const source = await placement.runtime.manifest();\n const placed = placeSourceManifest(source, placement);\n const targets = new Map<string, ApplicationTransport>();\n for (const capability of placed.sourceCapabilities) {\n const resolved = await placement.runtime.resolve(capability.path);\n if (!resolved) throw missingReference(capability.path);\n const previous = targets.get(capability.id);\n if (previous && previous !== resolved.transport) {\n throw new Error(\n `Capability id \"${capability.id}\" has multiple execution owners in \"${source.name}\"`,\n );\n }\n targets.set(capability.id, resolved.transport);\n }\n return {\n manifest: placed.manifest,\n application: placement.runtime,\n owners: targets,\n };\n}\n\nfunction placeSourceManifest(\n source: ApplicationManifest,\n placement: AppPlacement,\n): {\n readonly manifest: ApplicationManifest;\n readonly sourceCapabilities: readonly ManifestCapability[];\n} {\n if (placement.sourcePath.length === 0) {\n return {\n manifest: placeManifest(placement.path, source),\n sourceCapabilities: flattenManifestCapabilities(source.capabilities),\n };\n }\n\n const node = findManifestNode(source.capabilities, placement.sourcePath);\n if (!node) throw missingReference(placement.sourcePath);\n if (node.type === \"capability\") {\n if (placement.path.length === 0) {\n throw new TypeError(\"Capability references require a named key in composeApps()\");\n }\n return {\n manifest: Object.freeze({\n ...source,\n capabilities: wrapGroups(\n Object.freeze([placeCapability(node, {\n path: placement.path,\n relocatedLeaf: true,\n ...(placement.customization\n ? { customization: placement.customization }\n : {}),\n })]),\n placement.path.slice(0, -1),\n ),\n }),\n sourceCapabilities: Object.freeze([node]),\n };\n }\n\n if (placement.customization) {\n throw new TypeError(\"customize() requires a Capability reference, not an App subtree\");\n }\n return {\n manifest: Object.freeze({\n ...source,\n capabilities: placeGroup(node, placement.sourcePath, placement.path),\n }),\n sourceCapabilities: flattenManifestCapabilities(node.children),\n };\n}\n\nfunction placeGroup(\n group: ManifestGroup,\n sourcePath: readonly string[],\n path: readonly string[],\n): readonly ManifestNode[] {\n if (path.length === 0) {\n return rebaseManifestPaths(group.children, sourcePath, []);\n }\n const placed = Object.freeze({\n ...group,\n key: path.at(-1)!,\n // The placed node is named by its destination key. Nested Groups retain\n // their authored presentation and navigation metadata.\n meta: Object.freeze({}),\n children: rebaseManifestPaths(group.children, sourcePath, path),\n });\n return wrapGroups(Object.freeze([placed]), path.slice(0, -1));\n}\n\nfunction placeCapability(\n capability: ManifestCapability,\n placement: {\n readonly path: readonly string[];\n readonly relocatedLeaf: boolean;\n readonly customization?: CapabilityCustomization;\n },\n): ManifestCapability {\n return Object.freeze({\n ...capability,\n path: placement.path,\n ...(placement.relocatedLeaf\n ? {\n customization: mergeCustomization(capability.customization, {\n ...placement.customization,\n navigation: \"destination\",\n }),\n }\n : {}),\n });\n}\n\nfunction missingReference(path: readonly string[]): Error {\n return new Error(`No executable App node exists at \"${path.join(\".\")}\"`);\n}\n\n/** One cached manifest/dispatch snapshot for both composition and selection. */\nfunction derivedRuntime(\n load: () => Promise<{\n readonly manifest: ApplicationManifest;\n readonly dispatch: ReadonlyMap<string, ApplicationTransport>;\n }>,\n resolve: ApplicationRuntime[\"resolve\"],\n): ApplicationRuntime {\n const snapshot = cacheAsync(load);\n const target = async (id: string) => {\n const runtime = (await snapshot()).dispatch.get(id);\n if (!runtime) {\n throw markPublicError(new TransportError(\"NOT_FOUND\", { status: 404 }));\n }\n return runtime;\n };\n return Object.freeze({\n manifest: async () => (await snapshot()).manifest,\n resolve,\n async call(call: CapabilityCall) {\n return (await target(call.id)).call(call);\n },\n async subscribe(call: CapabilityCall) {\n return (await target(call.id)).subscribe(call);\n },\n });\n}\n\ntype SelectionNode<TTree> =\n TTree extends AnyCapability\n ? true\n : TTree extends CapabilityGroupDefinition<infer TCapabilities, any, any>\n ? true | SelectionNode<TCapabilities>\n : TTree extends CapabilityTree\n ? true | {\n readonly [TKey in keyof TTree]?: SelectionNode<TTree[TKey]>;\n }\n : never;\n\nexport type ApplicationSelection<\n TCapabilities extends CapabilityTree = CapabilityTree,\n> = {\n readonly include?: Exclude<SelectionNode<TCapabilities>, true>;\n readonly exclude?: Exclude<SelectionNode<TCapabilities>, true>;\n};\n\nexport function selectApp<\n const TCapabilities extends CapabilityTree,\n>(\n application: App<TCapabilities>,\n selection: ApplicationSelection<TCapabilities>,\n): App<TCapabilities> {\n const runtime = getInternalAppRuntime(application);\n const manifest = cacheAsync(async () => selectManifest(await runtime.manifest(), selection));\n return appFromRuntime(derivedRuntime(async () => {\n const selected = await manifest();\n return {\n manifest: selected,\n dispatch: new Map(flattenManifestCapabilities(selected.capabilities)\n .map((capability) => [capability.id, runtime])),\n };\n }, async (path) => {\n if (!findManifestCapability((await manifest()).capabilities, path)) return undefined;\n return runtime.resolve(path);\n }));\n}\n\nfunction placeManifest(\n path: readonly string[],\n source: ApplicationManifest,\n): ApplicationManifest {\n if (path.length === 0) return source;\n return Object.freeze({\n ...source,\n capabilities: wrapGroups(\n rebaseManifestPaths(source.capabilities, [], path),\n path,\n source,\n ),\n });\n}\n\nfunction wrapGroups(\n nodes: readonly ManifestNode[],\n path: readonly string[],\n source?: ApplicationManifest,\n): readonly ManifestNode[] {\n let capabilities = nodes;\n for (let index = path.length - 1; index >= 0; index--) {\n const leaf = index === path.length - 1;\n capabilities = Object.freeze([Object.freeze({\n type: \"group\" as const,\n key: path[index]!,\n ...(leaf && source ? { title: source.name } : {}),\n ...(leaf && source?.description ? { description: source.description } : {}),\n meta: Object.freeze({}),\n children: capabilities,\n })]);\n }\n return capabilities;\n}\n\nfunction rebaseManifestPaths(\n nodes: readonly ManifestNode[],\n sourcePath: readonly string[],\n destinationPath: readonly string[],\n): readonly ManifestNode[] {\n return Object.freeze(nodes.map((node) =>\n node.type === \"capability\"\n ? Object.freeze({\n ...node,\n path: Object.freeze([\n ...destinationPath,\n ...node.path.slice(sourcePath.length),\n ]),\n })\n : Object.freeze({\n ...node,\n children: rebaseManifestPaths(\n node.children,\n sourcePath,\n destinationPath,\n ),\n })\n ));\n}\n\nfunction isPathPrefixOrEqual(\n prefix: readonly string[],\n path: readonly string[],\n): boolean {\n return prefix.length <= path.length &&\n prefix.every((segment, index) => segment === path[index]);\n}\n\nfunction samePath(left: readonly string[], right: readonly string[]): boolean {\n return left.length === right.length &&\n left.every((segment, index) => segment === right[index]);\n}\n"],"mappings":";;AA4DA,SAAgB,kBACd,YACqB;CACrB,MAAM,eAAe,IAAI,IACvB,WAAW,oBAAoB,KAAK,UAAU,CAAC,MAAM,YAAY,KAAK,CAAC,CACzE;CACA,OAAO,OAAO,OAAO;EACnB,UAAU;EACV,MAAM,WAAW;EACjB,SAAS,WAAW;EACpB,GAAI,WAAW,cAAc,EAAE,aAAa,WAAW,YAAY,IAAI,CAAC;EACxE,cAAc,cAAc,WAAW,cAAc,YAAY;CACnE,CAAC;AACH;AAEA,SAAgB,iBACd,UACA,OACM;CACN,IAAI,CAAC,YAAY,OAAO,aAAa,UACnC,MAAM,IAAI,MAAM,GAAG,MAAM,4BAA4B;CAEvD,IAAI,SAAS,aAAa,2BACxB,MAAM,IAAI,MAAM,GAAG,MAAM,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UAAU,KAAK,UAC3B,OAAO,OAAO,SAAS,UAAU,YAAY,KAAK,MAAM;AAC5D;AAEA,SAAS,SAAS,MAAyB,OAAmC;CAC5E,OAAO,KAAK,WAAW,MAAM,UAC3B,KAAK,OAAO,SAAS,UAAU,YAAY,MAAM,MAAM;AAC3D"}
|
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as createProtocolHandler, t as createHttpHandler } from "./src-
|
|
1
|
+
import { l as createApp, n as selectApp } from "./src-C2OEkZ3c.mjs";
|
|
2
|
+
import { r as createProtocolHandler, t as createHttpHandler } from "./src-Bk3lEhI7.mjs";
|
|
3
3
|
//#region packages/server/src/index.ts
|
|
4
4
|
function protocol(options = {}) {
|
|
5
5
|
return {
|
|
6
6
|
kind: "capable.server.mount",
|
|
7
|
-
compile(app, context) {
|
|
7
|
+
compile(app, context, onError) {
|
|
8
8
|
const protocol = createProtocolHandler((request) => {
|
|
9
9
|
const executable = createApp(app, context ? { context: () => context({ request }) } : void 0);
|
|
10
10
|
return options.selection ? selectApp(executable, options.selection) : executable;
|
|
11
11
|
}, {
|
|
12
12
|
...options.path ? { basePath: options.path } : {},
|
|
13
|
-
...options.codec ? { codec: options.codec } : {}
|
|
13
|
+
...options.codec ? { codec: options.codec } : {},
|
|
14
|
+
...onError ? { onError } : {}
|
|
14
15
|
});
|
|
15
16
|
const base = normalizePath(options.path ?? "/~capable");
|
|
16
17
|
return {
|
|
@@ -26,13 +27,14 @@ function protocol(options = {}) {
|
|
|
26
27
|
function http(options = {}) {
|
|
27
28
|
return {
|
|
28
29
|
kind: "capable.server.mount",
|
|
29
|
-
compile(app, context) {
|
|
30
|
+
compile(app, context, onError) {
|
|
30
31
|
const handler = createHttpHandler(app, {
|
|
31
32
|
...context ? { context } : {},
|
|
32
33
|
...options.path ? { basePath: options.path } : {},
|
|
33
34
|
...options.openapiPath !== void 0 ? { openapiPath: options.openapiPath } : {},
|
|
34
35
|
...options.requireExplicitRoutes !== void 0 ? { requireExplicitRoutes: options.requireExplicitRoutes } : {},
|
|
35
|
-
...options.selection ? { selection: options.selection } : {}
|
|
36
|
+
...options.selection ? { selection: options.selection } : {},
|
|
37
|
+
...onError ? { onError } : {}
|
|
36
38
|
});
|
|
37
39
|
const base = normalizePath(options.path ?? "/api");
|
|
38
40
|
const openapiPath = options.openapiPath === false ? void 0 : normalizePath(options.openapiPath ?? "/openapi.json");
|
|
@@ -82,4 +84,4 @@ function normalizePath(value) {
|
|
|
82
84
|
//#endregion
|
|
83
85
|
export { http as n, protocol as r, createServer as t };
|
|
84
86
|
|
|
85
|
-
//# sourceMappingURL=src-
|
|
87
|
+
//# sourceMappingURL=src-DFrxQ_S6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-DFrxQ_S6.mjs","names":[],"sources":["../../server/src/index.ts"],"sourcesContent":["import type {\n AppDefinition,\n MaybePromise,\n} from \"@capable/core\";\nimport {\n createHttpHandler,\n createProtocolHandler,\n type ContextProvider,\n type CapabilitySelection,\n type ProtocolCodec,\n} from \"@capable/fetch\";\nimport {\n createApp,\n selectApp,\n type ApplicationSelection,\n} from \"@capable/app\";\n\nexport type ServerMount<TContext> = {\n readonly kind: \"capable.server.mount\";\n compile(\n app: AppDefinition<any, TContext>,\n context: ContextProvider<TContext> | undefined,\n onError?: (error: unknown) => void,\n ): CompiledServerMount;\n};\n\nexport type CompiledServerMount = {\n readonly name: string;\n readonly fetch: (request: Request) => MaybePromise<Response | undefined>;\n};\n\nexport function protocol<TContext = any>(\n options: {\n readonly path?: string;\n readonly selection?: ApplicationSelection;\n readonly codec?: ProtocolCodec;\n } = {},\n): ServerMount<TContext> {\n return {\n kind: \"capable.server.mount\",\n compile(app, context, onError) {\n const protocol = createProtocolHandler(\n (request) => {\n const executable = createApp(\n app,\n context\n ? { context: () => context({ request }) }\n : undefined as never,\n );\n return options.selection\n ? selectApp(executable, options.selection)\n : executable;\n },\n {\n ...(options.path ? { basePath: options.path } : {}),\n ...(options.codec ? { codec: options.codec } : {}),\n ...(onError ? { onError } : {}),\n },\n );\n const base = normalizePath(options.path ?? \"/~capable\");\n return {\n name: \"protocol\",\n async fetch(request) {\n if (!new URL(request.url).pathname.startsWith(`${base}/`)) {\n return undefined;\n }\n return protocol.fetch(request);\n },\n };\n },\n };\n}\n\nexport function http<TContext = any>(\n options: {\n readonly path?: string;\n readonly openapiPath?: string | false;\n readonly requireExplicitRoutes?: boolean;\n readonly selection?: CapabilitySelection;\n } = {},\n): ServerMount<TContext> {\n return {\n kind: \"capable.server.mount\",\n compile(app, context, onError) {\n const handler = createHttpHandler(app, {\n ...(context ? { context } : {}),\n ...(options.path ? { basePath: options.path } : {}),\n ...(options.openapiPath !== undefined\n ? { openapiPath: options.openapiPath }\n : {}),\n ...(options.requireExplicitRoutes !== undefined\n ? { requireExplicitRoutes: options.requireExplicitRoutes }\n : {}),\n ...(options.selection ? { selection: options.selection } : {}),\n ...(onError ? { onError } : {}),\n });\n const base = normalizePath(options.path ?? \"/api\");\n const openapiPath = options.openapiPath === false\n ? undefined\n : normalizePath(options.openapiPath ?? \"/openapi.json\");\n return {\n name: \"http\",\n async fetch(request) {\n const pathname = new URL(request.url).pathname;\n if (\n !pathname.startsWith(`${base}/`) &&\n pathname !== base &&\n pathname !== openapiPath\n ) {\n return undefined;\n }\n return handler.fetch(request);\n },\n };\n },\n };\n}\n\nexport type CapableServer = {\n readonly fetch: (request: Request) => Promise<Response>;\n};\n\nexport type ServerMiddleware = (args: {\n readonly request: Request;\n readonly next: (request?: Request) => Promise<Response>;\n}) => MaybePromise<Response>;\n\ntype CreateServerOptions<TContext> = {\n readonly context?: ContextProvider<TContext>;\n readonly mounts?: readonly ServerMount<TContext>[];\n readonly middleware?: ServerMiddleware;\n readonly onError?: (error: unknown) => void;\n};\n\ntype CreateServerArgs<TContext> = [TContext] extends [undefined]\n ? [options?: CreateServerOptions<TContext>]\n : [options: CreateServerOptions<TContext> & {\n readonly context: ContextProvider<TContext>;\n }];\n\nexport function createServer<TContext>(\n app: AppDefinition<any, TContext>,\n ...[providedOptions]: CreateServerArgs<TContext>\n): CapableServer {\n const options = (providedOptions ?? {}) as CreateServerOptions<TContext>;\n const mounts = (options.mounts ?? [protocol(), http()])\n .map((mount) => mount.compile(app, options.context, options.onError));\n\n async function dispatch(request: Request): Promise<Response> {\n for (const mount of mounts) {\n const response = await mount.fetch(request);\n if (response) return response;\n }\n return new Response(\"Not Found\", { status: 404 });\n }\n\n return Object.freeze({\n async fetch(request: Request) {\n try {\n return options.middleware\n ? await options.middleware({\n request,\n next: (nextRequest = request) => dispatch(nextRequest),\n })\n : await dispatch(request);\n } catch (error) {\n options.onError?.(error);\n return Response.json({\n ok: false,\n error: {\n code: \"INTERNAL_SERVER_ERROR\",\n message: \"Internal Server Error\",\n status: 500,\n },\n }, { status: 500 });\n }\n },\n });\n}\n\nfunction normalizePath(value: string): string {\n return `/${value.split(\"/\").filter(Boolean).join(\"/\")}`;\n}\n"],"mappings":";;;AA+BA,SAAgB,SACd,UAII,CAAC,GACkB;CACvB,OAAO;EACL,MAAM;EACN,QAAQ,KAAK,SAAS,SAAS;GAC7B,MAAM,WAAW,uBACd,YAAY;IACX,MAAM,aAAa,UACjB,KACA,UACI,EAAE,eAAe,QAAQ,EAAE,QAAQ,CAAC,EAAE,IACtC,KAAA,CACN;IACA,OAAO,QAAQ,YACX,UAAU,YAAY,QAAQ,SAAS,IACvC;GACN,GACA;IACE,GAAI,QAAQ,OAAO,EAAE,UAAU,QAAQ,KAAK,IAAI,CAAC;IACjD,GAAI,QAAQ,QAAQ,EAAE,OAAO,QAAQ,MAAM,IAAI,CAAC;IAChD,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;GAC/B,CACF;GACA,MAAM,OAAO,cAAc,QAAQ,QAAQ,WAAW;GACtD,OAAO;IACL,MAAM;IACN,MAAM,MAAM,SAAS;KACnB,IAAI,CAAC,IAAI,IAAI,QAAQ,GAAG,CAAC,CAAC,SAAS,WAAW,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AAM,MAAM,MAAM,OAAO;GAC1C,IAAI,UAAU,OAAO;EACvB;EACA,OAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;CAClD;CAEA,OAAO,OAAO,OAAO,EACnB,MAAM,MAAM,SAAkB;EAC5B,IAAI;GACF,OAAO,QAAQ,aACX,MAAM,QAAQ,WAAW;IACzB;IACA,OAAO,cAAc,YAAY,SAAS,WAAW;GACvD,CAAC,IACC,MAAM,SAAS,OAAO;EAC5B,SAAS,OAAO;GACd,QAAQ,UAAU,KAAK;GACvB,OAAO,SAAS,KAAK;IACnB,IAAI;IACJ,OAAO;KACL,MAAM;KACN,SAAS;KACT,QAAQ;IACV;GACF,GAAG,EAAE,QAAQ,IAAI,CAAC;EACpB;CACF,EACF,CAAC;AACH;AAEA,SAAS,cAAc,OAAuB;CAC5C,OAAO,IAAI,MAAM,MAAM,GAAG,CAAC,CAAC,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACtD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { y as renderPresentationMarkdown } from "./src-
|
|
2
|
-
import { a as
|
|
1
|
+
import { x as CapableError, y as renderPresentationMarkdown } from "./src-TCQGaWar.mjs";
|
|
2
|
+
import { a as getCapabilityNavigationMeta, c as TransportError, d as getAppRuntime, i as getCapabilityDisplay } from "./src-C2OEkZ3c.mjs";
|
|
3
3
|
import { render } from "markdansi";
|
|
4
4
|
//#region packages/cli/src/commands.ts
|
|
5
5
|
function collectCommands(nodes, parent = []) {
|
|
@@ -15,12 +15,18 @@ function collectCommands(nodes, parent = []) {
|
|
|
15
15
|
groups.push(...children.groups);
|
|
16
16
|
continue;
|
|
17
17
|
}
|
|
18
|
-
const
|
|
18
|
+
const capability = {
|
|
19
|
+
...node,
|
|
20
|
+
...getCapabilityDisplay(node)
|
|
21
|
+
};
|
|
22
|
+
const rawMeta = capability.meta.cli;
|
|
19
23
|
if (rawMeta === false) continue;
|
|
20
24
|
const meta = rawMeta ?? {};
|
|
25
|
+
const navigationMeta = getCapabilityNavigationMeta(node, "cli");
|
|
26
|
+
const navigation = navigationMeta === false ? {} : navigationMeta ?? {};
|
|
21
27
|
commands.push({
|
|
22
|
-
command:
|
|
23
|
-
capability
|
|
28
|
+
command: navigation.command ?? [...parent, navigation.name ?? node.path.at(-1)],
|
|
29
|
+
capability,
|
|
24
30
|
meta
|
|
25
31
|
});
|
|
26
32
|
}
|
|
@@ -88,6 +94,7 @@ const GLOBAL_OPTIONS = [{
|
|
|
88
94
|
description: "Show help"
|
|
89
95
|
}];
|
|
90
96
|
function renderRootHelp(manifest, commands, groups, invocationName, style) {
|
|
97
|
+
const root = commands.find((command) => command.command.length === 0);
|
|
91
98
|
const sections = commandSections(commands, groups);
|
|
92
99
|
const nested = sections.some((section) => section.title !== void 0);
|
|
93
100
|
const column = Math.max(descriptionColumn(sections.flatMap((section) => section.rows), nested ? `${ROW_INDENT} ` : ROW_INDENT), descriptionColumn(GLOBAL_OPTIONS));
|
|
@@ -95,15 +102,19 @@ function renderRootHelp(manifest, commands, groups, invocationName, style) {
|
|
|
95
102
|
banner({
|
|
96
103
|
title: manifest.name,
|
|
97
104
|
...manifest.description ? { description: manifest.description } : {},
|
|
98
|
-
usage:
|
|
105
|
+
usage: [
|
|
106
|
+
invocationName,
|
|
107
|
+
root && commands.length === 1 ? signature(root) : "<command>",
|
|
108
|
+
"[options]"
|
|
109
|
+
].filter(Boolean).join(" "),
|
|
99
110
|
style
|
|
100
111
|
}),
|
|
101
112
|
renderSection("Commands", sections.map((section) => [section.title ? `${ROW_INDENT}${style.dim(section.title)}` : void 0, renderRows(section.rows, style, {
|
|
102
113
|
column,
|
|
103
114
|
...section.title ? { indent: `${ROW_INDENT} ` } : {}
|
|
104
115
|
})].filter(Boolean).join("\n")).join("\n\n"), style),
|
|
105
|
-
renderSection("Options", renderRows(GLOBAL_OPTIONS, style, { column }), style),
|
|
106
|
-
hint(`Run \`${invocationName} <command> --help\` for details on a command.`, style)
|
|
116
|
+
root ? renderCommandInputs(root, style, column) : renderSection("Options", renderRows(GLOBAL_OPTIONS, style, { column }), style),
|
|
117
|
+
commands.some((command) => command.command.length > 0) ? hint(`Run \`${invocationName} <command> --help\` for details on a command.`, style) : void 0
|
|
107
118
|
]);
|
|
108
119
|
}
|
|
109
120
|
function renderGroupHelp(group, commands, invocationName, style) {
|
|
@@ -126,6 +137,18 @@ function renderGroupHelp(group, commands, invocationName, style) {
|
|
|
126
137
|
]);
|
|
127
138
|
}
|
|
128
139
|
function renderCommandHelp(command, invocationName, style) {
|
|
140
|
+
return renderHelp([banner({
|
|
141
|
+
...command.capability.title ? { title: command.capability.title } : {},
|
|
142
|
+
...command.capability.description ? { description: command.capability.description } : {},
|
|
143
|
+
usage: [
|
|
144
|
+
invocationName,
|
|
145
|
+
signature(command),
|
|
146
|
+
"[options]"
|
|
147
|
+
].join(" "),
|
|
148
|
+
style
|
|
149
|
+
}), renderCommandInputs(command, style)]);
|
|
150
|
+
}
|
|
151
|
+
function renderCommandInputs(command, style, minColumn = 0) {
|
|
129
152
|
const properties = fields(command);
|
|
130
153
|
const required = requiredFields(command);
|
|
131
154
|
const positionals = command.meta.positional ?? [];
|
|
@@ -136,30 +159,20 @@ function renderCommandHelp(command, invocationName, style) {
|
|
|
136
159
|
const optionRows = [...Object.entries(properties).filter(([name]) => !positionals.includes(name)).map(([name, schema]) => ({
|
|
137
160
|
label: optionLabel(name, schema),
|
|
138
161
|
...description(schema, { required: required.has(name) })
|
|
139
|
-
})), ...command.capability.
|
|
162
|
+
})), ...command.capability.execution === "live" ? [{
|
|
140
163
|
label: "--watch",
|
|
141
164
|
description: "Stream updates until interrupted"
|
|
142
165
|
}] : []];
|
|
143
|
-
const column = descriptionColumn([
|
|
166
|
+
const column = Math.max(minColumn, descriptionColumn([
|
|
144
167
|
...argumentRows,
|
|
145
168
|
...optionRows,
|
|
146
169
|
...GLOBAL_OPTIONS
|
|
147
|
-
]);
|
|
148
|
-
return
|
|
149
|
-
banner({
|
|
150
|
-
...command.capability.title ? { title: command.capability.title } : {},
|
|
151
|
-
...command.capability.description ? { description: command.capability.description } : {},
|
|
152
|
-
usage: [
|
|
153
|
-
invocationName,
|
|
154
|
-
signature(command),
|
|
155
|
-
"[options]"
|
|
156
|
-
].join(" "),
|
|
157
|
-
style
|
|
158
|
-
}),
|
|
170
|
+
]));
|
|
171
|
+
return [
|
|
159
172
|
argumentRows.length ? renderSection("Arguments", renderRows(argumentRows, style, { column }), style) : void 0,
|
|
160
173
|
optionRows.length ? renderSection("Options", renderRows(optionRows, style, { column }), style) : void 0,
|
|
161
174
|
renderSection(optionRows.length ? "Global Options" : "Options", renderRows(GLOBAL_OPTIONS, style, { column }), style)
|
|
162
|
-
]);
|
|
175
|
+
].filter(Boolean).join("\n\n");
|
|
163
176
|
}
|
|
164
177
|
/** Root commands are grouped under their top-level group, Vercel style. */
|
|
165
178
|
function commandSections(commands, groups) {
|
|
@@ -245,7 +258,8 @@ function renderCliCapabilityResult(result, options) {
|
|
|
245
258
|
function renderCliMarkdown(markdown, options) {
|
|
246
259
|
return options.isTTY ? render(markdown, {
|
|
247
260
|
color: options.color,
|
|
248
|
-
width: options.columns
|
|
261
|
+
width: options.columns,
|
|
262
|
+
...options.markdown
|
|
249
263
|
}) : markdown;
|
|
250
264
|
}
|
|
251
265
|
//#endregion
|
|
@@ -259,6 +273,7 @@ function createCli(app, cliOptions = {}) {
|
|
|
259
273
|
...cliOptions.color !== void 0 ? { color: cliOptions.color } : {},
|
|
260
274
|
...cliOptions.isTTY !== void 0 ? { isTTY: cliOptions.isTTY } : {},
|
|
261
275
|
...cliOptions.columns !== void 0 ? { columns: cliOptions.columns } : {},
|
|
276
|
+
...cliOptions.markdown ? { markdown: cliOptions.markdown } : {},
|
|
262
277
|
...options.io ? { io: options.io } : {}
|
|
263
278
|
});
|
|
264
279
|
} });
|
|
@@ -291,7 +306,14 @@ async function runCli(options) {
|
|
|
291
306
|
"--help",
|
|
292
307
|
"-h"
|
|
293
308
|
].includes(argument));
|
|
294
|
-
|
|
309
|
+
const roots = catalog.commands.filter((command) => command.command.length === 0);
|
|
310
|
+
if (roots.length > 1) {
|
|
311
|
+
io.stderr("Multiple Capabilities map to the root CLI command");
|
|
312
|
+
return 2;
|
|
313
|
+
}
|
|
314
|
+
const root = roots[0];
|
|
315
|
+
const runsRoot = root && !wantsHelp && (json || watch || root.capability.execution === "events");
|
|
316
|
+
if (argv.length === 0 && !runsRoot) {
|
|
295
317
|
io.stdout(renderRootHelp(manifest, catalog.commands, catalog.groups, invocationName, style));
|
|
296
318
|
return 0;
|
|
297
319
|
}
|
|
@@ -318,9 +340,9 @@ async function runCli(options) {
|
|
|
318
340
|
return 2;
|
|
319
341
|
}
|
|
320
342
|
try {
|
|
321
|
-
if (watch &&
|
|
343
|
+
if (watch && command.capability.execution === "unary") throw new CliUsageError(`Option --watch is only available for subscribable Capabilities`);
|
|
322
344
|
const input = parseArguments(argv.slice(command.command.length), command, invocationName);
|
|
323
|
-
if (watch) return await runWatchedCommand({
|
|
345
|
+
if (watch || command.capability.execution === "events") return await runWatchedCommand({
|
|
324
346
|
runtime,
|
|
325
347
|
command,
|
|
326
348
|
input,
|
|
@@ -328,7 +350,8 @@ async function runCli(options) {
|
|
|
328
350
|
io,
|
|
329
351
|
color,
|
|
330
352
|
isTTY,
|
|
331
|
-
columns
|
|
353
|
+
columns,
|
|
354
|
+
...options.markdown ? { markdown: options.markdown } : {}
|
|
332
355
|
});
|
|
333
356
|
const result = await runtime.call({
|
|
334
357
|
id: command.capability.id,
|
|
@@ -338,7 +361,8 @@ async function runCli(options) {
|
|
|
338
361
|
io.stdout(json ? JSON.stringify(result.output, null, 2) : renderCliCapabilityResult(result, {
|
|
339
362
|
color,
|
|
340
363
|
isTTY,
|
|
341
|
-
columns
|
|
364
|
+
columns,
|
|
365
|
+
...options.markdown ? { markdown: options.markdown } : {}
|
|
342
366
|
}));
|
|
343
367
|
return 0;
|
|
344
368
|
} catch (error) {
|
|
@@ -346,7 +370,7 @@ async function runCli(options) {
|
|
|
346
370
|
io.stderr(error.message);
|
|
347
371
|
return 2;
|
|
348
372
|
}
|
|
349
|
-
if (error instanceof TransportError) {
|
|
373
|
+
if (error instanceof CapableError || error instanceof TransportError) {
|
|
350
374
|
io.stderr(renderRuntimeError(error));
|
|
351
375
|
return 1;
|
|
352
376
|
}
|
|
@@ -361,13 +385,14 @@ async function runWatchedCommand(options) {
|
|
|
361
385
|
const controller = new AbortController();
|
|
362
386
|
const abort = () => controller.abort();
|
|
363
387
|
process.once("SIGINT", abort);
|
|
364
|
-
|
|
365
|
-
id: options.command.capability.id,
|
|
366
|
-
input: options.input,
|
|
367
|
-
...!options.json ? { presentation: true } : {},
|
|
368
|
-
signal: controller.signal
|
|
369
|
-
});
|
|
388
|
+
let stream;
|
|
370
389
|
try {
|
|
390
|
+
stream = await options.runtime.subscribe({
|
|
391
|
+
id: options.command.capability.id,
|
|
392
|
+
input: options.input,
|
|
393
|
+
...!options.json ? { presentation: true } : {},
|
|
394
|
+
signal: controller.signal
|
|
395
|
+
});
|
|
371
396
|
let frame = 0;
|
|
372
397
|
let previousFrameLines = 0;
|
|
373
398
|
for await (const result of stream) {
|
|
@@ -376,6 +401,10 @@ async function runWatchedCommand(options) {
|
|
|
376
401
|
continue;
|
|
377
402
|
}
|
|
378
403
|
const presentation = renderCliCapabilityResult(result, options);
|
|
404
|
+
if (options.command.capability.execution === "events") {
|
|
405
|
+
options.io.stdout(withTrailingNewline(presentation));
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
379
408
|
options.io.stdout(formatWatchFrame(presentation, frame++, options.isTTY, previousFrameLines));
|
|
380
409
|
previousFrameLines = countFrameLines(presentation);
|
|
381
410
|
}
|
|
@@ -385,7 +414,7 @@ async function runWatchedCommand(options) {
|
|
|
385
414
|
throw error;
|
|
386
415
|
} finally {
|
|
387
416
|
process.off("SIGINT", abort);
|
|
388
|
-
await stream
|
|
417
|
+
await stream?.return?.();
|
|
389
418
|
}
|
|
390
419
|
}
|
|
391
420
|
function formatWatchFrame(value, index, isTTY, previousFrameLines) {
|
|
@@ -402,7 +431,7 @@ function isAbortError(error) {
|
|
|
402
431
|
function parseArguments(argv, command, invocationName) {
|
|
403
432
|
const capability = command.capability;
|
|
404
433
|
const positional = command.meta.positional ?? [];
|
|
405
|
-
const commandName =
|
|
434
|
+
const commandName = [invocationName, ...command.command].join(" ");
|
|
406
435
|
const schema = capability.input;
|
|
407
436
|
const properties = schema?.properties;
|
|
408
437
|
const input = {};
|
|
@@ -448,7 +477,7 @@ function coerce(value, schema, label, commandName) {
|
|
|
448
477
|
}
|
|
449
478
|
var CliUsageError = class extends Error {};
|
|
450
479
|
function renderRuntimeError(error) {
|
|
451
|
-
return error instanceof TransportError ? `${error.code}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
480
|
+
return error instanceof CapableError || error instanceof TransportError ? `${error.code}: ${error.message}` : error instanceof Error ? error.message : String(error);
|
|
452
481
|
}
|
|
453
482
|
function matchCommand(argv, commands) {
|
|
454
483
|
return commands.filter((candidate) => candidate.command.every((token, index) => argv[index] === token)).sort((left, right) => right.command.length - left.command.length)[0];
|
|
@@ -495,4 +524,4 @@ function kebabCase(value) {
|
|
|
495
524
|
//#endregion
|
|
496
525
|
export { createCliStyle as a, renderSection as c, ROW_INDENT as i, supportsColor as l, runCli as n, descriptionColumn as o, MARGIN as r, renderRows as s, createCli as t };
|
|
497
526
|
|
|
498
|
-
//# sourceMappingURL=src-
|
|
527
|
+
//# sourceMappingURL=src-DklM1g7V.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"src-DklM1g7V.mjs","names":["kebabCase","renderMarkdown"],"sources":["../../cli/src/commands.ts","../../cli/src/style.ts","../../cli/src/help.ts","../../cli/src/presentation.ts","../../cli/src/index.ts"],"sourcesContent":["import {\n getCapabilityDisplay,\n getCapabilityNavigationMeta,\n} from \"@capable/app\";\nimport type {\n ManifestGroup,\n ManifestNode,\n ManifestCapability,\n} from \"@capable/app\";\nimport type {\n CliGroupMeta,\n CliCapabilityMeta,\n} from \"./index.ts\";\n\nexport type CliCommand = {\n readonly command: readonly string[];\n readonly capability: ManifestCapability;\n readonly meta: Exclude<CliCapabilityMeta, false>;\n};\n\nexport type CliCommandGroup = {\n readonly command: readonly string[];\n readonly title?: string;\n readonly description?: string;\n};\n\nexport type CliCommandCatalog = {\n readonly commands: readonly CliCommand[];\n readonly groups: readonly CliCommandGroup[];\n};\n\nexport function collectCommands(\n nodes: readonly ManifestNode[],\n parent: readonly string[] = [],\n): CliCommandCatalog {\n const commands: CliCommand[] = [];\n const groups: CliCommandGroup[] = [];\n\n for (const node of nodes) {\n if (node.type === \"group\") {\n const meta = (node.meta.cli ?? {}) as CliGroupMeta;\n const command = [...parent, meta.name ?? node.key];\n groups.push(groupFrom(node, command));\n const children = collectCommands(node.children, command);\n commands.push(...children.commands);\n groups.push(...children.groups);\n continue;\n }\n\n const capability = { ...node, ...getCapabilityDisplay(node) };\n const rawMeta = capability.meta.cli as CliCapabilityMeta | undefined;\n if (rawMeta === false) continue;\n const meta = rawMeta ?? {};\n // Curated leaves get navigation from the destination tree, unless explicitly\n // overridden there. Keep source non-navigational metadata (e.g. positionals).\n const navigationMeta = getCapabilityNavigationMeta(node, \"cli\");\n const navigation = navigationMeta === false ? {} : navigationMeta ?? {};\n commands.push({\n command: navigation.command ?? [...parent, navigation.name ?? node.path.at(-1)!],\n capability,\n meta,\n });\n }\n\n return {\n commands: Object.freeze(commands),\n groups: Object.freeze(groups),\n };\n}\n\nfunction groupFrom(\n node: ManifestGroup,\n command: readonly string[],\n): CliCommandGroup {\n return Object.freeze({\n command: Object.freeze(command),\n ...(node.title ? { title: node.title } : {}),\n ...(node.description ? { description: node.description } : {}),\n });\n}\n","export type CliStyle = {\n readonly bold: (text: string) => string;\n readonly accent: (text: string) => string;\n readonly dim: (text: string) => string;\n};\n\nexport type CliRow = {\n readonly label: string;\n readonly description?: string;\n};\n\n/** Every help line hangs off this margin. */\nexport const MARGIN = \" \";\n\n/** Rows sit one step inside their section heading. */\nexport const ROW_INDENT = \" \";\n\n/** Widest label that still keeps descriptions in a single column. */\nconst MAX_LABEL_WIDTH = 30;\n\nconst LABEL_GAP = 2;\n\nexport function createCliStyle(color?: boolean): CliStyle {\n const enabled = color ?? supportsColor();\n return {\n bold: enabled\n ? (text: string) => `\\u001B[1m${text}\\u001B[22m`\n : identity,\n accent: enabled\n ? (text: string) => `\\u001B[36m${text}\\u001B[39m`\n : identity,\n dim: enabled\n ? (text: string) => `\\u001B[2m${text}\\u001B[22m`\n : identity,\n };\n}\n\nexport function supportsColor(\n env: Record<string, string | undefined> = process.env,\n isTTY: boolean = Boolean(process.stdout.isTTY),\n): boolean {\n if (\"NO_COLOR\" in env) return false;\n if (env.FORCE_COLOR !== undefined) return env.FORCE_COLOR !== \"0\";\n return isTTY && env.TERM !== \"dumb\";\n}\n\nexport function renderRows(\n rows: readonly CliRow[],\n style: CliStyle,\n options: {\n readonly indent?: string;\n /** Absolute column for descriptions, so sibling sections stay aligned. */\n readonly column?: number;\n } = {},\n): string {\n const indent = options.indent ?? ROW_INDENT;\n const width = Math.max(\n 0,\n (options.column ?? descriptionColumn(rows, indent)) - indent.length -\n LABEL_GAP,\n );\n return rows.map(({ label, description }) => {\n const line = `${indent}${style.accent(label)}`;\n if (!description) return line;\n return label.length > width\n ? `${line}\\n${indent}${\" \".repeat(width + LABEL_GAP)}${style.dim(description)}`\n : `${line}${\" \".repeat(width - label.length + LABEL_GAP)}${\n style.dim(description)\n }`;\n }).join(\"\\n\");\n}\n\n/** Shared description column so sibling sections stay visually aligned. */\nexport function descriptionColumn(\n rows: readonly CliRow[],\n indent: string = ROW_INDENT,\n): number {\n const labels = rows\n .filter(({ description }) => description !== undefined)\n .map(({ label }) => label.length)\n .filter((length) => length <= MAX_LABEL_WIDTH);\n return indent.length + LABEL_GAP + Math.max(0, ...labels);\n}\n\nexport function renderSection(\n title: string,\n body: string,\n style: CliStyle,\n): string {\n return `${MARGIN}${style.bold(title)}\\n\\n${body}`;\n}\n\nfunction identity(text: string): string {\n return text;\n}\n","import type {\n ApplicationManifest,\n JsonSchema,\n} from \"@capable/app\";\nimport type {\n CliCommand,\n CliCommandGroup,\n} from \"./commands.ts\";\nimport {\n descriptionColumn,\n MARGIN,\n renderRows,\n renderSection,\n ROW_INDENT,\n type CliRow,\n type CliStyle,\n} from \"./style.ts\";\n\nconst GLOBAL_OPTIONS: readonly CliRow[] = [\n { label: \"--json\", description: \"Print canonical JSON\" },\n { label: \"-h, --help\", description: \"Show help\" },\n];\n\nexport function renderRootHelp(\n manifest: Pick<ApplicationManifest, \"name\" | \"description\">,\n commands: readonly CliCommand[],\n groups: readonly CliCommandGroup[],\n invocationName: string,\n style: CliStyle,\n): string {\n const root = commands.find((command) => command.command.length === 0);\n const sections = commandSections(commands, groups);\n const nested = sections.some((section) => section.title !== undefined);\n const column = Math.max(\n descriptionColumn(\n sections.flatMap((section) => section.rows),\n nested ? `${ROW_INDENT}${MARGIN}` : ROW_INDENT,\n ),\n descriptionColumn(GLOBAL_OPTIONS),\n );\n return renderHelp([\n banner({\n title: manifest.name,\n ...(manifest.description ? { description: manifest.description } : {}),\n usage: [invocationName, root && commands.length === 1 ? signature(root) : \"<command>\", \"[options]\"].filter(Boolean).join(\" \"),\n style,\n }),\n renderSection(\n \"Commands\",\n sections\n .map((section) =>\n [\n section.title ? `${ROW_INDENT}${style.dim(section.title)}` : undefined,\n renderRows(section.rows, style, {\n column,\n ...(section.title ? { indent: `${ROW_INDENT}${MARGIN}` } : {}),\n }),\n ].filter(Boolean).join(\"\\n\")\n )\n .join(\"\\n\\n\"),\n style,\n ),\n root\n ? renderCommandInputs(root, style, column)\n : renderSection(\"Options\", renderRows(GLOBAL_OPTIONS, style, { column }), style),\n commands.some((command) => command.command.length > 0)\n ? hint(`Run \\`${invocationName} <command> --help\\` for details on a command.`, style)\n : undefined,\n ]);\n}\n\nexport function renderGroupHelp(\n group: CliCommandGroup,\n commands: readonly CliCommand[],\n invocationName: string,\n style: CliStyle,\n): string {\n const prefix = group.command.join(\" \");\n const rows = commands\n .filter((candidate) => startsWith(candidate.command, group.command))\n .map((candidate) => ({\n label: signature(candidate, candidate.command.slice(group.command.length)),\n ...describe(candidate),\n }));\n const column = descriptionColumn([...rows, ...GLOBAL_OPTIONS]);\n return renderHelp([\n banner({\n ...(group.title ? { title: group.title } : {}),\n ...(group.description ? { description: group.description } : {}),\n usage: `${invocationName} ${prefix} <command> [options]`,\n style,\n }),\n renderSection(\"Commands\", renderRows(rows, style, { column }), style),\n renderSection(\"Options\", renderRows(GLOBAL_OPTIONS, style, { column }), style),\n hint(\n `Run \\`${invocationName} ${prefix} <command> --help\\` for details on a command.`,\n style,\n ),\n ]);\n}\n\nexport function renderCommandHelp(\n command: CliCommand,\n invocationName: string,\n style: CliStyle,\n): string {\n return renderHelp([\n banner({\n ...(command.capability.title ? { title: command.capability.title } : {}),\n ...(command.capability.description\n ? { description: command.capability.description }\n : {}),\n usage: [invocationName, signature(command), \"[options]\"].join(\" \"),\n style,\n }),\n renderCommandInputs(command, style),\n ]);\n}\n\nfunction renderCommandInputs(command: CliCommand, style: CliStyle, minColumn = 0): string {\n const properties = fields(command);\n const required = requiredFields(command);\n const positionals = command.meta.positional ?? [];\n const argumentRows = positionals.map((name) => ({\n label: placeholder(name, required.has(name)),\n ...description(properties[name], { choices: true }),\n }));\n const optionRows = [\n ...Object.entries(properties)\n .filter(([name]) => !positionals.includes(name))\n .map(([name, schema]) => ({\n label: optionLabel(name, schema),\n ...description(schema, { required: required.has(name) }),\n })),\n ...(command.capability.execution === \"live\"\n ? [{ label: \"--watch\", description: \"Stream updates until interrupted\" }]\n : []),\n ];\n const column = Math.max(minColumn, descriptionColumn([\n ...argumentRows,\n ...optionRows,\n ...GLOBAL_OPTIONS,\n ]));\n\n return [\n argumentRows.length\n ? renderSection(\n \"Arguments\",\n renderRows(argumentRows, style, { column }),\n style,\n )\n : undefined,\n optionRows.length\n ? renderSection(\"Options\", renderRows(optionRows, style, { column }), style)\n : undefined,\n renderSection(\n optionRows.length ? \"Global Options\" : \"Options\",\n renderRows(GLOBAL_OPTIONS, style, { column }),\n style,\n ),\n ].filter(Boolean).join(\"\\n\\n\");\n}\n\n/** Root commands are grouped under their top-level group, Vercel style. */\nfunction commandSections(\n commands: readonly CliCommand[],\n groups: readonly CliCommandGroup[],\n): readonly { readonly title?: string; readonly rows: readonly CliRow[] }[] {\n const roots = groups.filter((group) => group.command.length === 1);\n const loose = commands.filter((command) =>\n !roots.some((group) => startsWith(command.command, group.command))\n );\n const sections = roots.map((group) => ({\n ...(roots.length > 1 || loose.length\n ? { title: group.title ?? group.command.join(\" \") }\n : {}),\n rows: commands\n .filter((command) => startsWith(command.command, group.command))\n .map(row),\n })).filter((section) => section.rows.length > 0);\n return [\n ...sections,\n ...(loose.length\n ? [{\n ...(sections.length ? { title: \"General\" } : {}),\n rows: loose.map(row),\n }]\n : []),\n ];\n}\n\nfunction row(command: CliCommand): CliRow {\n return { label: signature(command), ...describe(command) };\n}\n\nfunction describe(command: CliCommand): { description?: string } {\n const text = command.capability.title ?? command.capability.description;\n return text ? { description: text } : {};\n}\n\n/** `todo delete <todoId>` — command path plus its positional slots. */\nfunction signature(\n command: CliCommand,\n path: readonly string[] = command.command,\n): string {\n const required = requiredFields(command);\n return [\n ...path,\n ...(command.meta.positional ?? []).map((name) =>\n placeholder(name, required.has(name))\n ),\n ].join(\" \");\n}\n\nfunction placeholder(name: string, required: boolean): string {\n return required ? `<${name}>` : `[${name}]`;\n}\n\n/** Title, prose, then the invocation line. No heading needed above it. */\nfunction banner(options: {\n readonly title?: string;\n readonly description?: string;\n readonly usage: string;\n readonly style: CliStyle;\n}): string {\n const { style } = options;\n return [\n [\n options.title ? `${MARGIN}${style.bold(options.title)}` : undefined,\n options.description\n ? `${MARGIN}${style.dim(options.description)}`\n : undefined,\n ].filter(Boolean).join(\"\\n\"),\n `${MARGIN}${style.accent(options.usage)}`,\n ].filter(Boolean).join(\"\\n\\n\");\n}\n\nfunction hint(text: string, style: CliStyle): string {\n return `${MARGIN}${style.dim(text)}`;\n}\n\nfunction fields(command: CliCommand): Record<string, JsonSchema> {\n return (command.capability.input?.properties as\n | Record<string, JsonSchema>\n | undefined) ?? {};\n}\n\nfunction requiredFields(command: CliCommand): ReadonlySet<string> {\n return new Set(\n command.capability.input?.required as readonly string[] | undefined,\n );\n}\n\nfunction optionLabel(name: string, schema: JsonSchema): string {\n const flag = `--${kebabCase(name)}`;\n if (schema.type === \"boolean\") return flag;\n if (Array.isArray(schema.enum)) {\n return `${flag} <${schema.enum.map(String).join(\"|\")}>`;\n }\n if (schema.type === \"array\" || schema.type === \"object\") {\n return `${flag} <json>`;\n }\n return `${flag} <${String(schema.type ?? \"value\")}>`;\n}\n\n/**\n * Descriptions stay one short line: prose first, then only the facts a reader\n * cannot guess from the label (requiredness, defaults, choices).\n */\nfunction description(\n schema: JsonSchema | undefined,\n options: { readonly required?: boolean; readonly choices?: boolean } = {},\n): { description?: string } {\n const prose = typeof schema?.description === \"string\"\n ? schema.description\n : undefined;\n const notes = [\n options.choices && Array.isArray(schema?.enum)\n ? `one of ${schema.enum.map(String).join(\", \")}`\n : undefined,\n schema?.default !== undefined\n ? `default: ${String(schema.default)}`\n : undefined,\n options.required ? \"required\" : undefined,\n ].filter(Boolean);\n const text = [prose, notes.length ? `(${notes.join(\", \")})` : undefined]\n .filter(Boolean)\n .join(\" \");\n return text ? { description: text } : {};\n}\n\nfunction startsWith(\n value: readonly string[],\n prefix: readonly string[],\n): boolean {\n return prefix.every((part, index) => value[index] === part);\n}\n\nfunction kebabCase(value: string): string {\n return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);\n}\n\nfunction renderHelp(sections: readonly (string | undefined)[]): string {\n return `\\n${sections.filter(Boolean).join(\"\\n\\n\")}\\n`;\n}\n","import type { CapabilityResult } from \"@capable/app\";\nimport { renderPresentationMarkdown } from \"@capable/core\";\nimport { render as renderMarkdown, type RenderOptions } from \"markdansi\";\n\nexport type CliPresentationOptions = {\n readonly color: boolean;\n readonly isTTY: boolean;\n readonly columns: number;\n readonly markdown?: RenderOptions;\n};\n\nexport function renderCliCapabilityResult(\n result: CapabilityResult,\n options: CliPresentationOptions,\n): string {\n if (result.presentation !== undefined) {\n return renderCliMarkdown(\n renderPresentationMarkdown(result.presentation),\n options,\n );\n }\n return typeof result.output === \"string\"\n ? result.output\n : JSON.stringify(result.output, null, 2);\n}\n\nfunction renderCliMarkdown(\n markdown: string,\n options: CliPresentationOptions,\n): string {\n return options.isTTY\n ? renderMarkdown(markdown, {\n color: options.color,\n width: options.columns,\n ...options.markdown,\n })\n : markdown;\n}\n","import type { RenderOptions } from \"markdansi\";\nimport {\n CapableError,\n type GroupMetaRegistry,\n type CapabilityMetaRegistry,\n} from \"@capable/core\";\nimport {\n getAppRuntime,\n TransportError,\n type AnyApp,\n type JsonSchema,\n} from \"@capable/app\";\nimport {\n collectCommands,\n type CliCommand,\n type CliCommandGroup,\n} from \"./commands.ts\";\nimport {\n renderCommandHelp,\n renderGroupHelp,\n renderRootHelp,\n} from \"./help.ts\";\nimport {\n createCliStyle,\n supportsColor,\n} from \"./style.ts\";\nimport { renderCliCapabilityResult } from \"./presentation.ts\";\n\n/** Shared help layout, so every Capable surface prints the same shape. */\nexport {\n createCliStyle,\n descriptionColumn,\n MARGIN,\n renderRows,\n renderSection,\n ROW_INDENT,\n supportsColor,\n type CliRow,\n type CliStyle,\n} from \"./style.ts\";\n\nexport type CliCapabilityMeta =\n | false\n | {\n readonly name?: string;\n readonly command?: readonly string[];\n readonly positional?: readonly string[];\n };\n\ndeclare global {\n interface CapableCustomizationMeta {\n readonly cli?: CliCapabilityMeta;\n }\n}\n\nexport type CliGroupMeta = {\n readonly name?: string;\n};\n\ndeclare module \"@capable/core\" {\n interface CapabilityMetaRegistry {\n readonly cli?: CliCapabilityMeta;\n }\n\n interface GroupMetaRegistry {\n readonly cli?: CliGroupMeta;\n }\n}\n\nexport type CliIo = {\n readonly stdout: (text: string) => void;\n readonly stderr: (text: string) => void;\n};\n\nexport type CreateCliOptions = {\n readonly invocationName?: string;\n readonly color?: boolean;\n readonly isTTY?: boolean;\n readonly columns?: number;\n readonly markdown?: RenderOptions;\n};\n\nexport function createCli(\n app: AnyApp,\n cliOptions: CreateCliOptions = {},\n): {\n run(\n argv: readonly string[],\n options?: { readonly io?: Partial<CliIo> },\n ): Promise<number>;\n} {\n return Object.freeze({\n run(argv, options = {}) {\n return runCli({\n app,\n argv,\n ...(cliOptions.invocationName\n ? { invocationName: cliOptions.invocationName }\n : {}),\n ...(cliOptions.color !== undefined ? { color: cliOptions.color } : {}),\n ...(cliOptions.isTTY !== undefined ? { isTTY: cliOptions.isTTY } : {}),\n ...(cliOptions.columns !== undefined\n ? { columns: cliOptions.columns }\n : {}),\n ...(cliOptions.markdown ? { markdown: cliOptions.markdown } : {}),\n ...(options.io ? { io: options.io } : {}),\n });\n },\n });\n}\n\nexport async function runCli(options: {\n readonly app: AnyApp;\n readonly argv: readonly string[];\n readonly invocationName?: string;\n readonly color?: boolean;\n readonly isTTY?: boolean;\n readonly columns?: number;\n readonly markdown?: RenderOptions;\n readonly io?: Partial<CliIo>;\n}): Promise<number> {\n const io: CliIo = {\n stdout: options.io?.stdout ??\n ((text) => process.stdout.write(withTrailingNewline(text))),\n stderr: options.io?.stderr ??\n ((text) => process.stderr.write(withTrailingNewline(text))),\n };\n const invocationName = options.invocationName ?? \"cap\";\n const isTTY = options.isTTY ?? Boolean(process.stdout.isTTY);\n const color = options.color ?? supportsColor(process.env, isTTY);\n const columns = options.columns ?? process.stdout.columns ?? 80;\n const style = createCliStyle(color);\n const runtime = getAppRuntime(options.app);\n let manifest;\n try {\n manifest = await runtime.manifest();\n } catch (error) {\n io.stderr(renderRuntimeError(error));\n return 1;\n }\n const catalog = collectCommands(manifest.capabilities);\n const json = options.argv.includes(\"--json\");\n const watch = options.argv.includes(\"--watch\");\n const wantsHelp = options.argv.includes(\"--help\") ||\n options.argv.includes(\"-h\");\n const argv = options.argv.filter((argument) =>\n ![\"--json\", \"--watch\", \"--help\", \"-h\"].includes(argument)\n );\n\n const roots = catalog.commands.filter((command) => command.command.length === 0);\n if (roots.length > 1) {\n io.stderr(\"Multiple Capabilities map to the root CLI command\");\n return 2;\n }\n const root = roots[0];\n const runsRoot = root && !wantsHelp &&\n (json || watch || root.capability.execution === \"events\");\n if (argv.length === 0 && !runsRoot) {\n io.stdout(renderRootHelp(\n manifest,\n catalog.commands,\n catalog.groups,\n invocationName,\n style,\n ));\n return 0;\n }\n\n const command = matchCommand(argv, catalog.commands);\n const group = exactGroup(argv, catalog.groups);\n if (wantsHelp) {\n if (command) {\n io.stdout(renderCommandHelp(command, invocationName, style));\n return 0;\n }\n if (group) {\n io.stdout(renderGroupHelp(\n group,\n catalog.commands,\n invocationName,\n style,\n ));\n return 0;\n }\n io.stderr(unknownCommand(argv, catalog.commands, invocationName));\n return 2;\n }\n\n if (!command) {\n if (group) {\n io.stderr(\n `Missing command after ${group.command.join(\" \")}\\n` +\n `Run \\`${invocationName} ${group.command.join(\" \")} --help\\` to list available commands.`,\n );\n return 2;\n }\n io.stderr(unknownCommand(argv, catalog.commands, invocationName));\n return 2;\n }\n\n try {\n if (watch && command.capability.execution === \"unary\") {\n throw new CliUsageError(\n `Option --watch is only available for subscribable Capabilities`,\n );\n }\n const input = parseArguments(\n argv.slice(command.command.length),\n command,\n invocationName,\n );\n if (watch || command.capability.execution === \"events\") {\n return await runWatchedCommand({\n runtime,\n command,\n input,\n json,\n io,\n color,\n isTTY,\n columns,\n ...(options.markdown ? { markdown: options.markdown } : {}),\n });\n }\n const result = await runtime.call({\n id: command.capability.id,\n input,\n ...(!json ? { presentation: true } : {}),\n });\n io.stdout(\n json\n ? JSON.stringify(result.output, null, 2)\n : renderCliCapabilityResult(result, {\n color,\n isTTY,\n columns,\n ...(options.markdown ? { markdown: options.markdown } : {}),\n }),\n );\n return 0;\n } catch (error) {\n if (error instanceof CliUsageError) {\n io.stderr(error.message);\n return 2;\n }\n if (error instanceof CapableError || error instanceof TransportError) {\n io.stderr(renderRuntimeError(error));\n return 1;\n }\n io.stderr(error instanceof Error ? error.message : String(error));\n return 1;\n }\n}\n\nfunction withTrailingNewline(value: string): string {\n return value.endsWith(\"\\n\") ? value : `${value}\\n`;\n}\n\nasync function runWatchedCommand(options: {\n readonly runtime: ReturnType<typeof getAppRuntime>;\n readonly command: CliCommand;\n readonly input: Record<string, unknown>;\n readonly json: boolean;\n readonly io: CliIo;\n readonly color: boolean;\n readonly isTTY: boolean;\n readonly columns: number;\n readonly markdown?: RenderOptions;\n}): Promise<number> {\n const controller = new AbortController();\n const abort = () => controller.abort();\n process.once(\"SIGINT\", abort);\n let stream: Awaited<ReturnType<typeof options.runtime.subscribe>> | undefined;\n\n try {\n stream = await options.runtime.subscribe({\n id: options.command.capability.id,\n input: options.input,\n ...(!options.json ? { presentation: true } : {}),\n signal: controller.signal,\n });\n let frame = 0;\n let previousFrameLines = 0;\n for await (const result of stream) {\n if (options.json) {\n options.io.stdout(`${JSON.stringify(result.output)}\\n`);\n continue;\n }\n const presentation = renderCliCapabilityResult(result, options);\n if (options.command.capability.execution === \"events\") {\n options.io.stdout(withTrailingNewline(presentation));\n continue;\n }\n options.io.stdout(formatWatchFrame(\n presentation,\n frame++,\n options.isTTY,\n previousFrameLines,\n ));\n previousFrameLines = countFrameLines(presentation);\n }\n return 0;\n } catch (error) {\n if (controller.signal.aborted || isAbortError(error)) return 0;\n throw error;\n } finally {\n process.off(\"SIGINT\", abort);\n await stream?.return?.();\n }\n}\n\nfunction formatWatchFrame(\n value: string,\n index: number,\n isTTY: boolean,\n previousFrameLines: number,\n): string {\n const frame = value.endsWith(\"\\n\") ? value : `${value}\\n`;\n if (isTTY) {\n return index === 0\n ? frame\n : `\\u001B[${previousFrameLines}A\\r\\u001B[0J${frame}`;\n }\n return index === 0 ? frame : `\\n---\\n\\n${frame}`;\n}\n\nfunction countFrameLines(value: string): number {\n const frame = value.endsWith(\"\\n\") ? value : `${value}\\n`;\n return frame.split(\"\\n\").length - 1;\n}\n\nfunction isAbortError(error: unknown): boolean {\n return error instanceof DOMException && error.name === \"AbortError\";\n}\n\nfunction parseArguments(\n argv: readonly string[],\n command: CliCommand,\n invocationName: string,\n): Record<string, unknown> {\n const capability = command.capability;\n const positional = command.meta.positional ?? [];\n const commandName = [invocationName, ...command.command].join(\" \");\n const schema = capability.input;\n const properties = schema?.properties as\n | Record<string, JsonSchema>\n | undefined;\n const input: Record<string, unknown> = {};\n let position = 0;\n\n for (let index = 0; index < argv.length; index++) {\n const token = argv[index]!;\n if (token.startsWith(\"--\")) {\n const [rawName, inline] = token.slice(2).split(\"=\", 2);\n const name = camelCase(rawName!);\n const field = properties?.[name];\n if (!field || positional.includes(name)) {\n const suggestion = nearest(\n rawName!,\n Object.keys(properties ?? {})\n .filter((candidate) => !positional.includes(candidate))\n .map(kebabCase),\n );\n throw new CliUsageError([\n `Unknown option --${rawName}`,\n ...(suggestion ? [`Did you mean \\`--${suggestion}\\`?`] : []),\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n ].join(\"\\n\"));\n }\n const boolean = field.type === \"boolean\";\n const raw = inline ?? (boolean ? \"true\" : argv[++index]);\n if (raw === undefined) {\n throw new CliUsageError(\n `Option --${rawName} requires a value\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n input[name] = coerce(raw, field, `--${rawName}`, commandName);\n continue;\n }\n const name = positional[position++];\n if (!name) {\n throw new CliUsageError(\n `Unexpected argument \"${token}\"\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n const field = properties?.[name];\n if (!field) {\n throw new CliUsageError(\n `CLI positional field \"${name}\" is not present in the input schema`,\n );\n }\n input[name] = coerce(token, field, `<${name}>`, commandName);\n }\n\n const required = schema?.required as readonly string[] | undefined;\n for (const name of required ?? []) {\n if (!(name in input)) {\n const label = positional.includes(name)\n ? `positional argument <${name}>`\n : `required option --${kebabCase(name)}`;\n throw new CliUsageError(\n `Missing ${label}\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n }\n return input;\n}\n\nfunction coerce(\n value: string,\n schema: JsonSchema,\n label: string,\n commandName: string,\n): unknown {\n if (schema.type === \"boolean\") return value !== \"false\";\n if (schema.type === \"integer\" || schema.type === \"number\") {\n const number = Number(value);\n if (!Number.isFinite(number)) {\n throw new CliUsageError(\n `Expected a number for ${label}, received \"${value}\"\\n` +\n `Run \\`${commandName} --help\\` to inspect accepted input.`,\n );\n }\n return number;\n }\n return value;\n}\n\nclass CliUsageError extends Error {}\n\nfunction renderRuntimeError(error: unknown): string {\n return error instanceof CapableError || error instanceof TransportError\n ? `${error.code}: ${error.message}`\n : error instanceof Error\n ? error.message\n : String(error);\n}\n\nfunction matchCommand(\n argv: readonly string[],\n commands: readonly CliCommand[],\n): CliCommand | undefined {\n return commands\n .filter((candidate) =>\n candidate.command.every((token, index) => argv[index] === token)\n )\n .sort((left, right) => right.command.length - left.command.length)[0];\n}\n\nfunction exactGroup(\n argv: readonly string[],\n groups: readonly CliCommandGroup[],\n): CliCommandGroup | undefined {\n return groups.find((group) =>\n group.command.length === argv.length &&\n group.command.every((token, index) => argv[index] === token)\n );\n}\n\nfunction unknownCommand(\n argv: readonly string[],\n commands: readonly CliCommand[],\n invocationName: string,\n): string {\n const entered = argv.join(\" \");\n const suggestion = nearest(\n entered,\n commands.map((command) => command.command.join(\" \")),\n );\n return [\n `Unknown command: ${entered}`,\n ...(suggestion ? [`Did you mean \\`${suggestion}\\`?`] : []),\n `Run \\`${invocationName} --help\\` to list available commands.`,\n ].join(\"\\n\");\n}\n\nfunction nearest(\n value: string,\n candidates: readonly string[],\n): string | undefined {\n let match: { readonly candidate: string; readonly distance: number } | undefined;\n for (const candidate of new Set(candidates)) {\n const distance = editDistance(value, candidate);\n if (!match || distance < match.distance) {\n match = { candidate, distance };\n }\n }\n if (!match) return undefined;\n return match.distance <= Math.max(2, Math.floor(match.candidate.length / 3))\n ? match.candidate\n : undefined;\n}\n\nfunction editDistance(left: string, right: string): number {\n const previous = Array.from(\n { length: right.length + 1 },\n (_, index) => index,\n );\n for (let leftIndex = 1; leftIndex <= left.length; leftIndex++) {\n const current = [leftIndex];\n for (let rightIndex = 1; rightIndex <= right.length; rightIndex++) {\n current[rightIndex] = Math.min(\n current[rightIndex - 1]! + 1,\n previous[rightIndex]! + 1,\n previous[rightIndex - 1]! +\n (left[leftIndex - 1] === right[rightIndex - 1] ? 0 : 1),\n );\n }\n previous.splice(0, previous.length, ...current);\n }\n return previous[right.length]!;\n}\n\nfunction camelCase(value: string): string {\n return value.replace(/-([a-z])/g, (_, character: string) =>\n character.toUpperCase()\n );\n}\n\nfunction kebabCase(value: string): string {\n return value.replace(/[A-Z]/g, (character) => `-${character.toLowerCase()}`);\n}\n"],"mappings":";;;;AA+BA,SAAgB,gBACd,OACA,SAA4B,CAAC,GACV;CACnB,MAAM,WAAyB,CAAC;CAChC,MAAM,SAA4B,CAAC;CAEnC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,SAAS,SAAS;GACzB,MAAM,OAAQ,KAAK,KAAK,OAAO,CAAC;GAChC,MAAM,UAAU,CAAC,GAAG,QAAQ,KAAK,QAAQ,KAAK,GAAG;GACjD,OAAO,KAAK,UAAU,MAAM,OAAO,CAAC;GACpC,MAAM,WAAW,gBAAgB,KAAK,UAAU,OAAO;GACvD,SAAS,KAAK,GAAG,SAAS,QAAQ;GAClC,OAAO,KAAK,GAAG,SAAS,MAAM;GAC9B;EACF;EAEA,MAAM,aAAa;GAAE,GAAG;GAAM,GAAG,qBAAqB,IAAI;EAAE;EAC5D,MAAM,UAAU,WAAW,KAAK;EAChC,IAAI,YAAY,OAAO;EACvB,MAAM,OAAO,WAAW,CAAC;EAGzB,MAAM,iBAAiB,4BAA4B,MAAM,KAAK;EAC9D,MAAM,aAAa,mBAAmB,QAAQ,CAAC,IAAI,kBAAkB,CAAC;EACtE,SA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