fix(node): align Kimi hooks with official contracts

This commit is contained in:
ZacharyZhang-NY committed 2026-07-20 04:07:19 -04:00
1 parent 4998d79c0b
commit 2eddd5cf88
17 files changed
+1831 -860

No files matched your search

+18 -1
View File
@@ -198,8 +198,21 @@ test('high-drift providers retain their verified hook contracts', async () => {
assert.deepEqual(providers.get('kimi').events, {
before_tool: 'PreToolUse',
after_tool: 'PostToolUse',
after_tool_failure: 'PostToolUseFailure',
});
assert.deepEqual(providers.get('kimi').event_fields, {
name: 'tool_name',
input: 'tool_input',
session: 'session_id',
call_id: 'tool_call_id',
output: 'tool_output',
error: 'error',
});
assert.equal(providers.get('kimi').config_format, 'toml');
assert.equal(
providers.get('kimi').source_url,
'https://www.kimi.com/code/docs/en/kimi-code-cli/customization/hooks.html',
);
assert.deepEqual(providers.get('kimi').config_paths, [
'$KIMI_CODE_HOME/config.toml',
'~/.kimi-code/config.toml',
@@ -208,17 +221,21 @@ test('high-drift providers retain their verified hook contracts', async () => {
{
id: 'pythoncli',
release_channel: 'legacy',
activation: 'kimi-cli',
activation: 'An existing ~/.kimi home activates the legacy kimi-cli contract',
config_format: 'toml',
config_paths: ['~/.kimi/config.toml'],
events: {
before_tool: 'PreToolUse',
after_tool: 'PostToolUse',
after_tool_failure: 'PostToolUseFailure',
},
event_fields: {
name: 'tool_name',
input: 'tool_input',
session: 'session_id',
call_id: 'tool_call_id',
output: 'tool_output',
error: 'error',
},
blocking: {
mechanism: 'exit_code_2',
+13
View File
@@ -156,6 +156,9 @@ test('every provider exposes a complete, machine-readable hook contract', async
assert.ok(Array.isArray(provider.config_paths));
assert.equal(typeof provider.events.before_tool, 'string');
assert.equal(typeof provider.events.after_tool, 'string');
if (provider.events.after_tool_failure !== undefined) {
assert.equal(typeof provider.events.after_tool_failure, 'string');
}
assert.ok([
'any_nonzero_exit',
'exception',
@@ -182,6 +185,11 @@ test('every provider exposes a complete, machine-readable hook contract', async
assert.equal(typeof provider.event_fields.name, 'string');
assert.equal(typeof provider.event_fields.input, 'string');
assert.equal(typeof provider.event_fields.session, 'string');
for (const field of ['call_id', 'output', 'error']) {
if (provider.event_fields[field] !== undefined) {
assert.equal(typeof provider.event_fields[field], 'string');
}
}
}
for (const variant of provider.contract_variants ?? []) {
@@ -192,6 +200,9 @@ test('every provider exposes a complete, machine-readable hook contract', async
assert.ok(Array.isArray(variant.config_paths) && variant.config_paths.length > 0);
assert.equal(typeof variant.events.before_tool, 'string');
assert.equal(typeof variant.events.after_tool, 'string');
if (variant.events.after_tool_failure !== undefined) {
assert.equal(typeof variant.events.after_tool_failure, 'string');
}
assert.equal(typeof variant.blocking.mechanism, 'string');
assert.equal(typeof variant.blocking.failure_mode, 'string');
assert.match(variant.source_url, /^https:\/\//);
@@ -223,6 +234,8 @@ test('schema freezes the provider contract and supported enums', async () => {
providerSchema.properties.blocking.properties.timeout_failure_mode.enum,
['fail_closed', 'fail_open'],
);
assert.equal(providerSchema.properties.events.properties.after_tool_failure.type, 'string');
assert.equal(providerSchema.properties.event_fields.properties.error.type, 'string');
assert.deepEqual(providerSchema.properties.delivery_state.enum, ['available', 'partial', 'planned']);
assert.equal(providerSchema.properties.contract_variants.items.$ref, '#/$defs/contractVariant');
assert.deepEqual(schema.$defs.contractVariant.properties.release_channel.enum, [