feat: Initial clean release of CHM
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled

这个提交包含在:
chen
2026-11-04 11:29:39 +08:00
当前提交 301194963b
共有 8663 个文件被更改,包括 1962691 次插入 和 0 次删除

查看文件

@@ -0,0 +1,73 @@
import extractReasoning from './extractReasoning';
describe('extractReasoning', () => {
test.each([
[
'Gemma channel markers',
'<|channel>thought\nI should greet them.<channel|>Hello there!',
'Hello there!',
'thought\nI should greet them.',
],
[
'think tags',
'<think>Let me work this out.</think>The answer is 42.',
'The answer is 42.',
'Let me work this out.',
],
[
'thinking tags',
'<thinking>Considering options.</thinking>Done.',
'Done.',
'Considering options.',
],
[
'no markers',
'Just a plain reply.',
'Just a plain reply.',
'',
],
[
'empty content',
'',
'',
'',
],
[
'leading whitespace before the marker',
'\n <think>Deliberating.</think>The answer.',
'The answer.',
'Deliberating.',
],
[
'a marker-like tag that is part of the reply',
'The `<think>` tag marks internal reasoning, like <think>this</think>.',
'The `<think>` tag marks internal reasoning, like <think>this</think>.',
'',
],
[
'a reply whose code block shows the tag',
'<think>They want an example.</think>Here:\n\n```\n<think>hello</think>\n```',
'Here:\n\n```\n<think>hello</think>\n```',
'They want an example.',
],
])('should split %s', (_name, content, expectedText, expectedReasoning) => {
const result = extractReasoning(content);
expect(result.text).toBe(expectedText);
expect(result.reasoning).toBe(expectedReasoning);
});
it('should treat an unterminated marker as reasoning rather than leaking it as the reply', () => {
const result = extractReasoning('<|channel>thought\nI was cut off mid-sent');
expect(result.text).toBe('');
expect(result.reasoning).toBe('thought\nI was cut off mid-sent');
});
it('should preserve a reply that opens with a fenced block showing the tag', () => {
const content = '```\n<think>hello</think>\n```\n\nThat tag marks internal reasoning.';
const result = extractReasoning(content);
expect(result.text).toBe(content.trim());
expect(result.reasoning).toBe('');
});
});

查看文件

@@ -0,0 +1,37 @@
// Some models emit reasoning inline instead of in a separate field. Gemma's
// pair is asymmetric, so generic special-token filters miss it.
const markerPairs = [
{ open: '<|channel>', close: '<channel|>' },
{ open: '<think>', close: '</think>' },
{ open: '<thinking>', close: '</thinking>' },
];
interface ExtractedReasoning {
text: string;
reasoning: string;
}
// Only a leading marker counts: anything later is the model talking *about*
// these tags, and stripping it would corrupt the answer.
const extractReasoning = (content: string): ExtractedReasoning => {
if (!content) return { text: '', reasoning: '' };
const trimmed = content.trimStart();
const pair = markerPairs.find(candidate => trimmed.startsWith(candidate.open));
if (!pair) return { text: content.trim(), reasoning: '' };
const bodyStart = pair.open.length;
const closeIndex = trimmed.indexOf(pair.close, bodyStart);
// Cut off mid-thought: keep it as reasoning rather than leak it as the reply.
if (closeIndex === -1) {
return { text: '', reasoning: trimmed.slice(bodyStart).trim() };
}
return {
text: trimmed.slice(closeIndex + pair.close.length).trim(),
reasoning: trimmed.slice(bodyStart, closeIndex).trim(),
};
};
export default extractReasoning;

查看文件

@@ -0,0 +1,24 @@
import { pregQuote } from '../../../string-utils';
const fencedBlockRegex = (tag: string) =>
new RegExp(`\`\`\`${pregQuote(tag)}\\s*\\n([\\s\\S]*?)\\n?\`\`\``, 'gi');
// Cursor=0 fallback (no selection) makes the first match win naturally.
const findFencedBlock = (body: string, tag: string, cursorPos: number) => {
const re = fencedBlockRegex(tag);
let best: RegExpExecArray | null = null;
let bestDistance = Infinity;
let match: RegExpExecArray | null;
while ((match = re.exec(body)) !== null) {
const distance = Math.abs(match.index - cursorPos);
if (distance < bestDistance) {
bestDistance = distance;
best = match;
}
// Defensive against zero-width matches looping forever.
if (match.index === re.lastIndex) re.lastIndex++;
}
return best;
};
export default findFencedBlock;