AgentSkillsCN

fragno-fragment-creation

创建或修改 Fragno 片段(面向库作者的工作流程):搭建片段包框架,定义片段配置/Schema,添加依赖项与服务,声明路由,构建服务器实例化逻辑,并导出客户端构建器以及各框架对应的客户端入口点。当被要求构建新片段、添加路由/钩子,或为作者配置片段打包与代码分割时,可使用此方法。

SKILL.md
--- frontmatter
name: fragno-fragment-creation
description: >
  Create or modify Fragno fragments (library-author workflow): scaffold a fragment package, define
  fragment config/schema, add dependencies/services, declare routes, build server instantiation, and
  export client builders plus per-framework client entrypoints. Use when asked to build a new
  fragment, add routes/hooks, or set up fragment packaging/code-splitting for authors.

Fragno Fragment Creation

Overview

Create or extend a Fragno fragment package with typed routes and client hooks for multiple frameworks.

Workflow (Library Author)

Setup

  • Prefer creating a new package via the create CLI. For scripted/non-interactive usage:
sh
pnpm create fragno@latest --non-interactive --name my-fragment

This uses sensible defaults: tsdown build tool, database layer included, no agent docs, path set to ./<name>.

  • OR: Install @fragno-dev/core manually. See "assets" below.

Core building blocks

  1. Define fragment + config in a definition module

    • defineFragment<TConfig>("fragment-name").build()
    • Export config type and any shared schemas.
  2. Optional dependencies / services

    • Use withDependencies(({ config }) => ({ ... })) for server-only deps.
    • Dependencies are not bundled into the client.
  3. Define routes in dedicated route modules

    • defineRoutes(definition).create(({ defineRoute, config, deps, services }) => [ ... ])
    • defineRoute options: method, path, inputSchema, outputSchema, handler, errorCodes, queryParameters.
    • Handler input context: input.valid() and request data helpers.
    • Handler output helpers: json, jsonStream, empty, error.
  4. Server-side fragment instance (server entry module)

    • instantiate(definition).withConfig(config).withRoutes([ ... ]).withOptions(options).build()
  5. Client-side builder (client builder module)

    • createClientBuilder(definition, publicConfig, routes)
    • Export hooks/composables: createHook, createMutator.
  6. Framework client entrypoints (React/Vue/Svelte/Solid/Vanilla)

    • Create a file per framework: React, Vue, Svelte, Solid, Vanilla JS.
    • Each file wraps with the matching useFragno from @fragno-dev/core/<framework>.

Docs lookup

  • Search the docs index:
    • curl -s "https://fragno.dev/api/search?query=defineRoutes"
  • Fetch docs as Markdown:
    • curl -L "https://fragno.dev/docs/fragno/for-library-authors/getting-started" -H "accept: text/markdown"

References (library-author docs)

ReferenceWhat it isWhen to readFull docs
Config, Dependencies, and ServicesHow config, deps, and services are structured and composedWhen adding dependencies or exposing serviceshttps://fragno.dev/docs/fragno/for-library-authors/features/dependencies-and-services
Route DefinitionsRoute API, schemas, errors, query params, handlersWhen defining or updating routeshttps://fragno.dev/docs/fragno/for-library-authors/features/route-definition
Client-side State ManagementHooks, mutators, invalidation, custom stores, fetch configWhen building client APIs or custom statehttps://fragno.dev/docs/fragno/for-library-authors/features/client-state-management
Code SplittingUnplugin usage, bundling, exports, peer depsBefore publishing or changing build confighttps://fragno.dev/docs/fragno/for-library-authors/features/code-splitting
Database Integration OverviewWhen to add DB support and how the API is structuredWhen the fragment needs persistencehttps://fragno.dev/docs/fragno/for-library-authors/database-integration/overview
Defining SchemasSchema DSL, indexes, relations, evolution rulesWhen authoring or evolving a schemahttps://fragno.dev/docs/fragno/for-library-authors/database-integration/defining-schemas
QueryingTransaction builder patterns and query APIsWhen implementing DB reads/writeshttps://fragno.dev/docs/fragno/for-library-authors/database-integration/querying
Durable HooksOutbox-style side effects and dispatchersWhen you need reliable side effectshttps://fragno.dev/docs/fragno/for-library-authors/database-integration/durable-hooks
TransactionsHandler/service transaction boundaries and .check()When composing multi-step DB operationshttps://fragno.dev/docs/fragno/for-library-authors/database-integration/transactions
Database TestingDB test harness and adaptersWhen testing database-backed fragmentshttps://fragno.dev/docs/fragno/for-library-authors/database-integration/testing
TestingCore test utilities and callRoute behaviorWhen writing unit/integration testshttps://fragno.dev/docs/fragno/for-library-authors/testing

Assets (example code)

When creating a Fragment using the create command with database support, the following assets will automatically be created.

AssetWhat it isSource
database-index.tsComplete database-backed fragment: definition, services, routes, clientpackages/create/templates/optional/database/index.ts
database-schema.tsSchema definition with tables, columns, indexes, and relationspackages/create/templates/optional/database/schema.ts