temps-add-plugin
Skill949 starsChanged 23 days agoApache-2.0View on GitHub
Add a TempsPlugin so a crate's services, routes and OpenAPI schema are wired into the server - the trait in temps-core, register_services with require_service vs get_service, the two-phase initialisation, configure_routes/configure_public_routes/openapi_schema, and where the plugin list lives in the console startup. Use when creating a new feature crate, or when a crate needs to provide or consume a shared service.
In this repository23 other files it gives its agents.
- AGENTS.mdAGENTS.md
- web/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- web/CLAUDE.mdCLAUDE.md
- start-temps-clusterSkill
- start-tempsSkill
- temps-add-handlerSkill
- temps-add-migration-and-entitySkill
- temps-design-systemSkill
- temps-split-moduleSkill
- add-custom-domainSkill
- add-error-trackingSkill
- add-node-sdkSkill
- add-react-analyticsSkill
- add-session-recordingSkill
- deploy-to-tempsSkill
- estimate-temps-savingsSkill
- temps-best-practicesSkill
- temps-cliSkill
- temps-mcp-setupSkill
- temps-platform-setupSkill
- temps-pluginSkill
- tempsSkill
The file
We split this skill into the rules it gives an agent
10 rules. About 0 are common, 0 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 12
Every feature crate plugs into the server through TempsPlugin.
- Very specific: line 30
Add it to members in the root Cargo.toml.
- Very specific: line 35
Add a description to [package].
- Very specific: line 84
get_service: only for genuinely optional collaborators, where None has a defined meaning. - Very specific: line 100
verify_required_services: every type listed by a plugin's required_services() must now be registered. - Very specific: line 105
Phase 2,
initialize_plugin_services(&PluginContext): every service is registered, so a plugin can look up others and load configuration … - Very specific: line 145
Add its name() at the same position in FULL_ORDER in that file's tests.
- Very specific: line 146
Add the crate to crates/temps-cli/Cargo.toml (temps-flags = { path = "../temps-flags" }) and the use to …
- Very specific: line 169
Start the server once (start-temps skill) and check the startup log shows the plugin registered and initialised without errors.
- Very specific: line 183
If the plugin adds or changes endpoints, regenerate both OpenAPI clients as described in the temps-add-handler skill.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
<!--
SPDX-FileCopyrightText: 2024-2026 Temps Contributors
SPDX-License-Identifier: MIT OR Apache-2.0
-->Add a plugin
Every feature crate plugs into the server through TempsPlugin. The plugin
builds the crate's services from shared ones, publishes its own services for
other plugins, and returns its router and OpenAPI document.
- Trait and runtime:
crates/temps-core/src/plugin.rs(TempsPlugin,ServiceRegistrationContext,PluginContext,PluginRoutes,RequiredService,PluginManager). - Smallest complete example:
crates/temps-flags/src/plugin.rs(one service, one router, one OpenAPI doc, no background work). - Example with declared requirements:
crates/temps-error-tracking/src/plugin.rs. - Example with deferred initialisation:
crates/temps-blob/src/plugin.rs. - Where plugins are registered:
register_builtin_pluginsincrates/temps-cli/src/commands/serve/console/startup/plugins.rs.
1. The crate
A new crate under crates/:
- Add it to
membersin the rootCargo.toml. - End its
Cargo.tomlwith[lints]/workspace = true. - Typical layout, as in temps-flags:
lib.rs,error.rs,services/,handlers/{mod,handler,types,audit}.rs,plugin.rs. Re-export the plugin fromlib.rs(pub use plugin::FlagsPlugin;). - Add a
descriptionto[package].
2. Implement TempsPlugin
Shape of crates/temps-flags/src/plugin.rs:
pub struct FlagsPlugin;
impl TempsPlugin for FlagsPlugin {
fn name(&self) -> &'static str {
"flags"
}
fn register_services<'a>(
&'a self,
context: &'a ServiceRegistrationContext,
) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'a>> {
Box::pin(async move {
let db = context.require_service::<DatabaseConnection>();
context.register_service(Arc::new(FlagService::new(db)));
Ok(())
})
}
fn configure_routes(&self, context: &PluginContext) -> Option<PluginRoutes> {
let flag_service = context.require_service::<FlagService>();
let audit_service = context.require_service::<dyn AuditLogger>();
let project_access_checker = context.get_service::<dyn temps_core::ProjectAccessChecker>();
let app_state = Arc::new(FlagsAppState { flag_service, audit_service, project_access_checker });
Some(PluginRoutes::new(configure_routes().with_state(app_state)))
}
fn openapi_schema(&self) -> Option<OpenApi> {
Some(<FlagsApiDoc as OpenApiTrait>::openapi())
}
}Also provide new() and Default.
Services: require_service vs get_service
- Services are keyed by type and returned as
Arc<T>:require_service::<DatabaseConnection>()yieldsArc<DatabaseConnection>. Trait objects usedyn:require_service::<dyn AuditLogger>(). require_servicefor anything the plugin cannot work without. It fails fast at startup with the missing type's name. Never wrap a required dependency inOption.get_serviceonly for genuinely optional collaborators, whereNonehas a defined meaning. The canonical case isdyn temps_core::ProjectAccessChecker, which isNoneunless another plugin provides team-based access, and which the guard macros treat as a no-op.- Give each component its own
Arcclone. Do not add accessors such asservice.db()to hand dependencies around. - Publish with
context.register_service(Arc::new(MyService::new(..))). If other plugins should depend on an abstraction, register anArc<dyn Trait>.
Two-phase initialisation
PluginManager::initialize_plugins runs:
- Phase 1,
register_services, for every plugin in registration order.require_servicehere only sees services registered by plugins earlier in the list, so register providers before consumers. verify_required_services: every type listed by a plugin'srequired_services()must now be registered; all gaps are reported in one error. Declare cross-plugin requirements there, ascrates/temps-error-tracking/src/plugin.rsdoes withRequiredService::of::<temps_otel::OtelService>().- Phase 2,
initialize_plugin_services(&PluginContext): every service is registered, so a plugin can look up others and load configuration from the database. Do not block startup on slow work (pulling an image, starting a container); spawn it, ascrates/temps-blob/src/plugin.rsdoes.
Routes, middleware and OpenAPI are collected after both phases.
Routes and OpenAPI
configure_routesreturns authenticated routes (the auth middleware puts anAuthContextin the request; handlers takeRequireAuth). ReturnNoneif the crate has no endpoints.configure_public_routesis for endpoints without a user session (tracking pixels, inbound webhooks, token-authenticated delivery). Each one still authenticates its caller somehow; say how in the handler doc.- Paths have no
/apiprefix;build_applicationadds it. Use{param}. - Two plugins must not register the same method and path. Replacing an existing
route is done with
PluginRoutes::with_override, not a second.route(). openapi_schemareturns the crate's#[derive(OpenApi)]doc. A route missing from it is missing from both generated clients.configure_middlewareexists for the rare plugin that adds middleware.
Handlers themselves follow the temps-add-handler skill.
3. Wire it into the server
In register_builtin_plugins
(crates/temps-cli/src/commands/serve/console/startup/plugins.rs), add one row to
the table at the point the plugin's dependencies are met:
// Feature flags (depends on database only).
|| Box::new(FlagsPlugin::new()),- That function is the startup order, read top to bottom. Insert the row after every plugin whose services it requires in phase 1, with a comment that names those dependencies.
- A plugin that takes startup inputs or depends on the serve profile is an explicit statement between the tables, not a row.
- Add its
name()at the same position inFULL_ORDERin that file's tests. - Add the crate to
crates/temps-cli/Cargo.toml(temps-flags = { path = "../temps-flags" }) and theusetocrates/temps-cli/src/commands/serve/console.rs. - This is the console process. The proxy, agent and stateless processes wire their services separately; if the feature must run there too, wire it there explicitly.
- Background loops are bounded: O(changes) per tick, bounded channels, bounded
memory (
AGENTS.md→ Scalability & Efficiency). - An optional dependency (Docker, an external provider) never makes the plugin
disappear: register it, report "not configured" through a status endpoint, and
let the UI onboard (
AGENTS.md→ Feature Discoverability).
4. Tests
- Plugin-level: assert the OpenAPI document contains the routes you expect.
openapi_schema_exposes_deployment_token_routesincrates/temps-deployments/src/plugin.rsis the pattern. - Registration behaviour:
crates/temps-core/src/plugin.rstests build aPluginManager,register_plugina provider and a consumer, and callinitialize_plugins()(satisfied_requirements_pass,missing_requirement_fails_before_phase_two). Copy that shape when the plugin declaresrequired_services(). - Services and handlers are tested in their own modules (see
temps-add-handler). - Start the server once (
start-tempsskill) and check the startup log shows the plugin registered and initialised without errors.
Verification
cargo check --lib -p <new-crate>
cargo check --lib -p temps-cli
cargo test --lib -p <new-crate>
cargo clippy -p <new-crate> -p temps-cli --all-targets -- -D warnings
python3 scripts/rule_drift.py
python3 scripts/source_attribution.py checkIf the plugin adds or changes endpoints, regenerate both OpenAPI clients as
described in the temps-add-handler skill.
New files get the SPDX header (python3 scripts/source_attribution.py annotate
<file>). Commit with git commit -s -m "feat(<crate>): <capability>".
Checklist
- Crate in workspace
members,[lints] workspace = true,descriptionset require_servicefor required deps,get_serviceonly for optional ones- Cross-plugin needs declared in
required_services() - Slow initialisation spawned, not awaited, in phase 2
- Routes in
configure_routes(orconfigure_public_routeswith its own auth) openapi_schemareturns the crate'sApiDoc- Registered in
start_console_apiafter its providers - OpenAPI test, service tests and handler tests pass
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

