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.
This commit is contained in:
@@ -174,7 +174,7 @@ test('thinking controls and complete tool histories survive the desktop bridge w
|
||||
const expected = structuredClone(original);
|
||||
expected.model = 'original-provider/test-model';
|
||||
if (shared) expected.messages.splice(2, 0, {role: 'system',
|
||||
content: '<magpie-kimi-shared-instructions>\nsynthetic shared instruction\n</magpie-kimi-shared-instructions>'});
|
||||
content: '<shared-instructions>\nsynthetic shared instruction\n</shared-instructions>'});
|
||||
const response = await fetch(f.controller.bridgeURL + '/chat/completions', {method: 'POST',
|
||||
headers: {Authorization: 'Bearer synthetic-kimi-key'}, body: JSON.stringify(original)});
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const BEGIN = '<magpie-kimi-shared-instructions>';
|
||||
const END = '</magpie-kimi-shared-instructions>';
|
||||
// The tag goes upstream with the prompt, so it names neither the app nor
|
||||
// the vendor (magpie-community/plugins#356). Turns written before 0.1.3 hold
|
||||
// the old tag; both are taken out, so a history never carries two copies.
|
||||
const BEGIN = '<shared-instructions>';
|
||||
const END = '</shared-instructions>';
|
||||
const TAGS = [[BEGIN, END], ['<magpie-kimi-shared-instructions>', '</magpie-kimi-shared-instructions>']];
|
||||
const LIMIT = 1024 * 1024;
|
||||
|
||||
function linkDirectory(link, target) {
|
||||
@@ -41,8 +45,8 @@ export function applyInstructions(payload, file) {
|
||||
// Remove only our separate system message; leave Kimi's and the user's own
|
||||
// instructions, tool messages, image parts and conversation history intact.
|
||||
const messages = payload.messages.filter(message => !(message?.role === 'system'
|
||||
&& typeof message.content === 'string' && message.content.startsWith(BEGIN + '\n')
|
||||
&& message.content.endsWith('\n' + END)));
|
||||
&& typeof message.content === 'string' && TAGS.some(([begin, end]) =>
|
||||
message.content.startsWith(begin + '\n') && message.content.endsWith('\n' + end))));
|
||||
if (text) {
|
||||
let at = 0;
|
||||
while (['system', 'developer'].includes(messages[at]?.role)) at++;
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// 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]]);
|
||||
}));
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/agent-kimi-desktop",
|
||||
"version": "0.1.2",
|
||||
"version": "0.1.3",
|
||||
"description": "Kimi desktop Work as a Magpie agent, using the models configured in Magpie",
|
||||
"type": "module",
|
||||
"main": "./index.mjs",
|
||||
|
||||
Reference in New Issue
Block a user