diff --git a/packages/kimi-desktop/kimi-desktop.test.mjs b/packages/kimi-desktop/kimi-desktop.test.mjs
index 838395c..defc8e0 100644
--- a/packages/kimi-desktop/kimi-desktop.test.mjs
+++ b/packages/kimi-desktop/kimi-desktop.test.mjs
@@ -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: '\nsynthetic shared instruction\n'});
+ content: '\nsynthetic shared instruction\n'});
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);
diff --git a/packages/kimi-desktop/library.mjs b/packages/kimi-desktop/library.mjs
index afd0387..5778661 100644
--- a/packages/kimi-desktop/library.mjs
+++ b/packages/kimi-desktop/library.mjs
@@ -1,8 +1,12 @@
import fs from 'node:fs';
import path from 'node:path';
-const BEGIN = '';
-const END = '';
+// 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 = '';
+const END = '';
+const TAGS = [[BEGIN, END], ['', '']];
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++;
diff --git a/packages/kimi-desktop/no-magpie.test.mjs b/packages/kimi-desktop/no-magpie.test.mjs
new file mode 100644
index 0000000..63f930d
--- /dev/null
+++ b/packages/kimi-desktop/no-magpie.test.mjs
@@ -0,0 +1,38 @@
+// magpie-community/plugins#356: the user's shared instructions went to the
+// model wrapped in , 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: '\nold rule\n'},
+ {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: '\nuse tabs\n'}]);
+ expect(out.messages.map(m => m.content)).toEqual(['Kimi native system prompt',
+ '\nuse tabs\n', '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]]);
+}));
diff --git a/packages/kimi-desktop/package.json b/packages/kimi-desktop/package.json
index 4437508..c4a3858 100644
--- a/packages/kimi-desktop/package.json
+++ b/packages/kimi-desktop/package.json
@@ -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",