DeepSeek Harness Plugin Config: Config and Schemastery
The greet tool hardcodes the greeting in the code; changing it for different deployments requires modifying the code
This chapter lets a plugin accept configuration passed in from cordis.yml, achieving "separation of configuration and code"
Export the Config type and a same-named schema
Export a Config interface and a same-named Schemastery schema in the plugin
Write default values directly on the schema fields
Example
// File path: scratch-plugin/src/my-plugin.ts
import
type
{
Context
}
from
'@deepseek-ai/cordis'
import
Schema from
'@deepseek-ai/schemastery'
export
const
name
=
'my-plugin'
// Config interface: defines which configuration items the plugin accepts
export
interface
Config
{
greeting
:
string
// Greeting
maxRetries
:
number
// Maximum number of retries
verbose
?:
boolean
// Whether to output verbose logs (optional)
}
// Same-named Config schema: default values are written here
export
const
Config
:
Schema
<
Config
=Schema.
object
(
{
greeting
:
Schema.
string
(
)
.
default
(
'Hello'
)
,
maxRetries
:
Schema.
number
(
)
.
default
(
3
)
,
verbose
:
Schema.
boolean
(
)
.
default
(
false
)
,
}
)
// The second parameter of apply is the validated config
export
function
apply
(
ctx
:
Context
,
config
:
Config
)
{
// What's printed is the value passed by the user or the schema default
console.
log
(
config.
greeting
)
}
The interface provides TypeScript types; the schema provides runtime validation and default values
The two share the same name, which is a Cordis convention
Don't export a plain object as Config
It doesn't satisfy the Standard Schema interface required by Cordis
Pass configuration in cordis.yml
Add a config field to the newly inserted local plugin entry
Example
File path: scratch-plugin/cordis.yml
- insert
:
- id
:
hello
The plugin path must be absolute (see article 7)
name
:
'/absolute/path/to/deepseek-harness/scratch-plugin/src/my-plugin.ts'
config
:
greeting
:
'Hi there, runoob!'
maxRetries
:
5
When the plugin loads, Cordis validates the config via the exported schema and fills in defaults for fields not provided
The config above doesn't write verbose, so it takes the schema default false
Schema validation
When stricter validation is needed, use Schemastery to express constraints
Example
// File path: scratch-plugin/src/validated-plugin.ts
import
type
{
Context
}
from
'@deepseek-ai/cordis'
import
Schema from
'@deepseek-ai/schemastery'
export
const
name
=
'validated-plugin'
export
interface
Config
{
apiKey
:
string
// Required
timeout
:
number
// Timeout in milliseconds
mode
:
'fast'
|
'accurate'
// Can only take one of these two values
}
export
const
Config
=
Schema.
object
(
{
apiKey
:
Schema.
string
(
)
.
required
(
)
,
timeout
:
Schema.
number
(
)
.
default
(
30000
)
,
mode
:
Schema.
union
(
[
'fast'
,
'accurate'
]
)
.
default
(
'fast'
)
,
}
)
export
function
apply
(
ctx
:
Context
,
config
:
Config
)
{
// config is already validated and type-safe
}
Schema performs validation when the plugin loads
If the config is invalid, the plugin fails to load with a clear error message
Design principle: no hardcoded tunable parameters
The Harness convention is: any parameter that different deployments might need to give different values must be defined as a configuration field
Wrong and correct ways
// Wrong: hardcoding the timeout
const
TIMEOUT
=
30000
// Correct: define as a config field, with the default still provided by schema
export
interface
Config
{
timeoutMs
:
number
// Default 30000
}
One-sentence test: can you change this value in cordis.yml without modifying code?
If yes, it's a qualified tunable parameter; if not, you need to extract it into a config field
Hardcodingis writing a value that should be tunable directly into the code
It turns "changing config" into "changing code plus redeploying", a common source of production incidents
Config errors should be loud
Express complete constraints in the schema so invalid configs fail at plugin load time
References to services or registered resources require dependency injection; the services tutorial will introduce this convention
With HMR: config hot replacement
Config changes trigger plugin hot replacement (HMR)
After modifying a plugin's config in cordis.yml, the framework unloads the old instance and loads a new one
Since registrations are all effects and are cleaned up automatically, no registrations from the old instance remain after replacement
Summary and self-test
Export a Config interface and same-named schema, write defaults into the schema, validate config at load time; all tunable parameters go into config
1. Why write default values in the schema rather than in code?
2. What happens when the config is invalid?
3. What is the test for "no hardcoding"?