Files
deepseek-harness/packages/experimental/claude-code-mods/src/values.ts
T
Tianyi Cui 35873604ad feat(experimental): add Claude Code mods bridge
Add @deepseek-ai/dsh-experimental-claude-code-mods, an alpha bridge that
loads Claude Code mods (plugin directories whose hooks/hooks.json names a
hooks module), runs register(on, options) unchanged, and raises the mod
events from harness extension points: session.start on agent/created,
prompt.submit and turn.start on agent/pre-step, tool.call around
tools/execute, turn.complete on turn/end, session.end on agent/disposed,
and command.run from registered commands. The $ mods API is served over
composed services (commands, tools, user-questions, fs, subprocess,
storage domain, projections); unserved members fail by name.

Includes a middleware chain with Claude Code's failure rules and budget
clock, a claude-code/testing-style test kit, fixtures from the mods
tutorial, full-loop and Loader composition tests, the attribution-only
claude-code-mods message source with its persistence record, and the
regenerated catalogs.
2026-10-02 11:10:41 +08:00

47 lines
1.5 KiB
TypeScript

/**
* Small value helpers shared by the engine and the host: reading a mod's
* untyped call input, wording a thrown value, and JSON encoding as typed by
* what it does.
* @module
*/
/**
* The message of a thrown value: an Error's `message`, anything else as text.
* @param error - the thrown value.
* @returns the message text.
*/
export function messageOf(error: unknown): string {
return error instanceof Error ? error.message : String(error)
}
/**
* A mod's call input as a field record; anything that is not an object reads as empty.
* @param input - the value a mod passed.
* @returns the fields, or an empty record.
*/
export function record(input: unknown): Record<string, unknown> {
return typeof input === 'object' && input !== null ? input as Record<string, unknown> : {}
}
/**
* Require one string field of a mod's call input.
* @param value - the field value.
* @param what - the field, named in the error.
* @returns the string.
* @throws TypeError when the value is not a string.
*/
export function requireString(value: unknown, what: string): string {
if (typeof value !== 'string') throw new TypeError(`${what} must be a string`)
return value
}
/**
* `JSON.stringify` as typed by what it does: undefined for a value JSON cannot carry.
* @param value - the value to encode.
* @returns the JSON text, or undefined.
*/
export function stringify(value: unknown): string | undefined {
const encoded: string | undefined = JSON.stringify(value)
return encoded
}