Files
plugins/packages/kimi-desktop/no-magpie.test.mjs
T
yetone a5c13b8c7a kimi-desktop 0.1.3: shared instructions go to the model as <shared-instructions>, not <magpie-kimi-shared-instructions> (#356)
The adapter puts the user's shared instructions in a system message of
their own, and its tag went upstream with every prompt naming the app.
This tag is the adapter's own (Kimi's client has no such message), so a
neutral one was picked: <shared-instructions>. A history holding the old
tag from turns before 0.1.3 has that message taken out as before, so no
prompt carries two copies or the old name.

Left as they are, and why: the menu alias magpie-local-<hash> and the
" · Magpie" display name live in Kimi's model menu; the adapter replaces
the alias with the real model id before a request leaves it, so neither
reaches the model.

Run:
- no-magpie.test.mjs: with shared instructions and an old tagged turn in
  history the prompt holds no "magpie", one <shared-instructions> message,
  and applying twice changes nothing (red on the old code); with no
  instructions the old turn is still taken out.
- bun test (package): 26 pass. scripts/check.mjs skips agent packages
  (exit 0).
Not tried live: no Kimi Work account here, and Kimi isn't installed on
this Mac or the Windows box.
2026-10-24 17:31:58 +08:00

39 lines
2.0 KiB
JavaScript

// magpie-community/plugins#356: the user's shared instructions went to the
// model wrapped in <magpie-kimi-shared-instructions>, so every prompt named
// the app. The tag is neutral now, and a history that still carries the old
// tag from earlier turns has it taken out, never sent twice.
import {test,expect} from 'bun:test';
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {applyInstructions} from './library.mjs';
function withRules(text, run) {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'kimi-desktop-rules-'));
try { const file = path.join(dir, 'instructions.md'); fs.writeFileSync(file, text); return run(file); }
finally { fs.rmSync(dir, {recursive: true, force: true}); }
}
const history = [
{role: 'system', content: 'Kimi native system prompt'},
{role: 'system', content: '<magpie-kimi-shared-instructions>\nold rule\n</magpie-kimi-shared-instructions>'},
{role: 'user', content: 'fix the build'},
{role: 'assistant', content: 'on it'},
];
test('the prompt with shared instructions names no magpie, old tag included', () => withRules('use tabs', file => {
const out = applyInstructions({model: 'k3-agent', messages: history}, file);
expect(JSON.stringify(out)).not.toMatch(/magpie/i);
const shared = out.messages.filter(m => m.role === 'system' && m.content.includes('use tabs'));
expect(shared).toEqual([{role: 'system', content: '<shared-instructions>\nuse tabs\n</shared-instructions>'}]);
expect(out.messages.map(m => m.content)).toEqual(['Kimi native system prompt',
'<shared-instructions>\nuse tabs\n</shared-instructions>', 'fix the build', 'on it']);
expect(applyInstructions(out, file)).toEqual(out);
}));
test('with no shared instructions an old tagged turn is still taken out', () => withRules('', file => {
const out = applyInstructions({model: 'k3-agent', messages: history}, file);
expect(JSON.stringify(out)).not.toMatch(/magpie/i);
expect(out.messages).toEqual([history[0], history[2], history[3]]);
}));