DeepSeek Harness first plugin
In Harness, a plugin is a TypeScript module that exports an apply function.
The framework calls apply when loading a plugin and passes in a ctx (context object).
We register capabilities through ctx, such as event listeners, tools, and LLM adapters.
ctx(Context) is the context object the framework passes to each plugin.
ctx It is both the entry point for registering capabilities and a record of all resources the plugin registers.
Creating a local project
We need to install from source first:
git clone https://github.com/deepseek-ai/deepseek-harness.git
cd deepseek-harness
pnpm install
pnpm run build
When installing, use the repository's package.json declared Node.js and pnpm versions; an already-checked-out old repository may differ from the latest docs. Continue this chapter after the build completes; there is no need to first start a web service without plugins.
Next create a scratch-plugin project to hold our plugin.
Run this in the repository root:
mkdir -p scratch-plugin/src
Minimal plugin: hello-plugin
Create my-plugin.ts under scratch-plugin/src.
Keep the terminal at the repository root and create the file with an editor; the launch command in the next chapter is also run from the repository root.
Below is a complete, working plugin configuration with nothing missing.
Example
// File path: scratch-plugin/src/my-plugin.ts
import
type
{
Context
}
from
'@deepseek-ai/cordis'
// name is the plugin name, used to identify this plugin in logs and configuration
export
const
name
=
'hello-plugin'
// apply is the plugin's entry point: the framework calls it when loading the plugin
export
function
apply
(
ctx
:
Context
)
{
// Required dependencies are ready before apply runs (see chapter 13)
console.
log
(
'[hello-plugin] plugin loaded!'
)
}
This code does only one thing: print a log line when loaded. It registers no capabilities, yet it is already a valid plugin.
Three forms of a plugin
Besides the function form seen above, plugins also support an object form and a class form.
| Form | Syntax | Applicable scenarios |
|---|---|---|
| Function form | Export a standalone apply function | Most plugins; the simplest and most direct |
| Object form | export default an object with name / inject / apply | When you need to declare metadata at the same time |
| Class form | export default a Service subclass | When the plugin needs to provide services to other plugins |
Function form
Exporting name and apply separately is the default style in official examples.
Example
// File path: scratch-plugin/src/my-plugin.ts (function form)
import
type
{
Context
}
from
'@deepseek-ai/cordis'
export
const
name
=
'my-plugin'
export
function
apply
(
ctx
:
Context
)
{
// Register capabilities here
}
Object form
Put name, inject, and apply into a single object export.
Do not add an extra export default.The Loader prioritizes the module's default export; if a plugin in function or object form adds one more line
export default apply, the inject declared on the namespace is discarded entirely, and the plugin starts with empty dependencies (the root cause of official incident postmortem 0001).
Example
// Object form: a single default-exported object
import
type
{
Context
}
from
'@deepseek-ai/cordis'
export
default
{
name
:
'my-plugin'
,
inject
:
[
'tools'
]
,
apply
(
ctx
:
Context
)
{
// ...
}
,
}
Class form
The class form extends the Service base class, suitable for plugins that provide services to others.
Example
// Class form: a Service subclass that can provide services externally
import
{
Service
,
type Context
}
from
'@deepseek-ai/cordis'
export
default
class
MyService
extends
Service
{
static
inject
=
[
'tools'
]
constructor
(
ctx
:
Context
)
{
// The first parameter is ctx, the second is the service name
super
(
ctx
,
'myService'
)
// Put synchronous initialization in the constructor
}
}
How to choose
In most cases, the function form is sufficient.
Use the class form when a plugin needs to provide services to other plugins.
Tip: the core of the class form is super(ctx, 'service name').
For the complete mechanism of services and dependencies, see:DeepSeek Harness Services and Dependencies。