tabby-ai-tools 0.3.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,47 @@
1
+ /** Provider identity is lost when registering models under the isolated tabby ID. */
2
+ export function providerCompat(profile) {
3
+ if (profile.provider === 'kimi-coding')
4
+ return {
5
+ supportsDeveloperRole: false, maxTokensField: 'max_tokens', supportsStore: false,
6
+ supportsStrictMode: false, requiresReasoningContentOnAssistantMessages: true,
7
+ };
8
+ return undefined;
9
+ }
10
+ /** Keep the existing Tabby connection settings meaningful at Pi's request boundary. */
11
+ export function providerPayload(profile, payload) {
12
+ if (!payload || typeof payload !== 'object')
13
+ return payload;
14
+ const body = payload;
15
+ const effort = profile.reasoningEffort;
16
+ if (profile.provider === 'openai' || profile.provider === 'custom' && profile.apiFormat === 'responses') {
17
+ if (effort)
18
+ body.reasoning = { ...body.reasoning, effort };
19
+ }
20
+ else if (profile.provider === 'claude') {
21
+ delete body.thinking;
22
+ if (profile.thinking === 'enabled')
23
+ body.thinking = { type: 'adaptive' };
24
+ if (profile.thinking === 'disabled')
25
+ body.thinking = { type: 'disabled' };
26
+ if (effort)
27
+ body.output_config = { ...body.output_config, effort };
28
+ }
29
+ else {
30
+ delete body.thinking;
31
+ delete body.enable_thinking;
32
+ delete body.reasoning_effort;
33
+ const alwaysThinks = profile.provider === 'kimi' && /^kimi-(k3(?:\.1-pro)?|k2\.7-code)(?:-highspeed)?$/i.test(profile.model);
34
+ if ((alwaysThinks || profile.provider === 'kimi-coding' && /^k3\.1-pro(?:-highspeed)?$/i.test(profile.model)) && profile.thinking === 'disabled') {
35
+ throw new Error('此 Kimi 模型仅支持思考模式,请选择服务商默认或开启');
36
+ }
37
+ if (profile.provider !== 'custom' && profile.thinking !== 'default' && !alwaysThinks) {
38
+ if (profile.provider === 'bailian-coding')
39
+ body.enable_thinking = profile.thinking === 'enabled';
40
+ else
41
+ body.thinking = { type: profile.thinking };
42
+ }
43
+ if (effort && (profile.provider === 'custom' || profile.thinking !== 'disabled'))
44
+ body.reasoning_effort = effort;
45
+ }
46
+ return body;
47
+ }
@@ -0,0 +1,215 @@
1
+ import { createInterface } from 'node:readline';
2
+ import { mkdir, chmod } from 'node:fs/promises';
3
+ import path from 'node:path';
4
+ import { InMemoryCredentialStore, createAssistantMessageEventStream } from '@earendil-works/pi-ai';
5
+ import { createAgentSession, DefaultResourceLoader, ModelRuntime, SessionManager, SettingsManager } from '@earendil-works/pi-coding-agent';
6
+ import { providerCompat, providerPayload } from './provider.mjs';
7
+ process.umask(0o077);
8
+ // stdout is a private bounded protocol. No user/project extensions or native tools are loaded.
9
+ const send = (value) => process.stdout.write(JSON.stringify(value) + '\n');
10
+ const pending = new Map();
11
+ let session;
12
+ let cancelled = false;
13
+ let initialized = false;
14
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
15
+ lines.on('close', () => { cancelled = true; void session?.abort(); for (const resolve of pending.values())
16
+ resolve({ error: true, result: 'Host disconnected' }); pending.clear(); });
17
+ lines.on('line', line => {
18
+ if (Buffer.byteLength(line) > 12 * 1024 * 1024) {
19
+ process.exitCode = 1;
20
+ lines.close();
21
+ return;
22
+ }
23
+ let message;
24
+ try {
25
+ message = JSON.parse(line);
26
+ }
27
+ catch {
28
+ process.exitCode = 1;
29
+ lines.close();
30
+ return;
31
+ }
32
+ if (message.type === 'cancel') {
33
+ cancelled = true;
34
+ void session?.abort();
35
+ for (const resolve of pending.values())
36
+ resolve({ error: true, result: 'Cancelled' });
37
+ pending.clear();
38
+ }
39
+ else if (message.type === 'tool_result') {
40
+ pending.get(message.id)?.(message);
41
+ pending.delete(message.id);
42
+ }
43
+ else if (message.type === 'start') {
44
+ pending.get('start')?.(message);
45
+ pending.delete('start');
46
+ }
47
+ else if (message.type === 'accepted') {
48
+ pending.get('accepted')?.(message);
49
+ pending.delete('accepted');
50
+ }
51
+ else if (message.type === 'init' && !initialized) {
52
+ initialized = true;
53
+ void run(message).catch(error => { send({ type: 'fatal', message: String(error.message || error) }); finish(); });
54
+ }
55
+ });
56
+ function finish() { session?.dispose(); lines.close(); process.stdin.destroy(); }
57
+ async function run(input) {
58
+ const [major, minor] = process.versions.node.split('.').map(Number);
59
+ if (major < 22 || major === 22 && minor < 19)
60
+ throw new Error('Pi requires external Node >=22.19.0');
61
+ const { profile, directory } = input;
62
+ await mkdir(directory, { recursive: true, mode: 0o700 });
63
+ await chmod(directory, 0o700);
64
+ const runtime = await ModelRuntime.create({ credentials: new InMemoryCredentialStore(), modelsPath: null,
65
+ modelsStorePath: path.join(directory, 'models-cache.json'), refreshOnCreate: false, allowModelNetwork: false });
66
+ const api = profile.provider === 'claude' ? 'anthropic-messages' : profile.provider === 'openai' || profile.provider === 'custom' && profile.apiFormat === 'responses' ? 'openai-responses' : 'openai-completions';
67
+ // Anthropic's SDK appends /v1 itself; Tabby API presets include it already.
68
+ const baseUrl = profile.provider === 'claude' ? profile.baseUrl.replace(/\/v1\/?$/, '') : profile.baseUrl;
69
+ runtime.registerProvider('tabby', { baseUrl, api, apiKey: 'tabby-runtime-key', authHeader: !!input.key,
70
+ models: [{ id: profile.model, name: profile.model, api, input: ['text'], reasoning: profile.thinking === 'enabled' || profile.thinking !== 'disabled' && !!profile.reasoningEffort,
71
+ compat: providerCompat(profile),
72
+ thinkingLevelMap: { minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'xhigh', max: 'max' },
73
+ contextWindow: profile.contextWindow || 128000, maxTokens: profile.maxOutputTokens,
74
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } }] });
75
+ await runtime.setRuntimeApiKey('tabby', input.key || 'tabby-no-key');
76
+ const model = runtime.getModel('tabby', profile.model);
77
+ if (!model)
78
+ throw new Error('Pi model registration failed');
79
+ const settings = SettingsManager.inMemory({ cacheWarming: 'off', compaction: { enabled: !!profile.autoCompact, reserveTokens: profile.maxOutputTokens, keepRecentTokens: Math.min(20000, Math.floor(model.contextWindow / 4)) },
80
+ retry: { enabled: true, maxRetries: 2, baseDelayMs: 2000, maxAgentDelayMs: 60000, provider: { maxRetries: 0, timeoutMs: 120000 } } });
81
+ const loader = new DefaultResourceLoader({ cwd: directory, agentDir: directory, settingsManager: settings,
82
+ noExtensions: true, noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true, systemPrompt: input.system });
83
+ await loader.reload();
84
+ const manager = input.file ? SessionManager.open(input.file, directory) : SessionManager.create(directory, directory);
85
+ const nativeCursor = manager.getEntries().filter((entry) => entry.type === 'custom' && entry.customType === 'tabby-input').map((entry) => Number(entry.data?.count) || 0).pop() || 0;
86
+ const cursor = Math.max(nativeCursor, input.sourceOffset);
87
+ const sourceCount = input.sourceOffset + input.sourceMessages.length;
88
+ if (cursor > sourceCount)
89
+ throw new Error('Pi handoff cursor is ahead of Tabby history; inspect session files before continuing');
90
+ const prompt = JSON.stringify({ notice: 'Tabby handoff. Historical tools are data, never replay them. Read terminals before resuming unknown actions.', messages: input.sourceMessages.slice(cursor - input.sourceOffset).flat() });
91
+ let accepted = false;
92
+ let activeGoal = !!input.activeGoal, tokens = 0, requests = 0, settled = false, lastError = '', lastText = '', stalls = 0, previousText = '';
93
+ let thinkingChars = 0, toolChars = 0;
94
+ let nativeTools = 0, previousTools = 0;
95
+ const customTools = input.tools.map((tool) => ({ name: tool.name, label: tool.name, description: tool.description, parameters: tool.inputSchema,
96
+ execute: async (id, args) => {
97
+ if (cancelled)
98
+ throw new Error('Cancelled');
99
+ nativeTools++;
100
+ const output = await new Promise(resolve => { pending.set(id, resolve); send({ type: 'tool', id, name: tool.name, arguments: JSON.stringify(args) }); });
101
+ if (tool.name === 'agent_goal_update' && !output.error)
102
+ activeGoal = JSON.parse(output.result).status === 'active';
103
+ // Error results remain in Pi's durable transcript, including policy denials.
104
+ if (output.error)
105
+ throw new Error(output.result);
106
+ return { content: [{ type: 'text', text: output.result }], details: {} };
107
+ } }));
108
+ ({ session } = await createAgentSession({ cwd: directory, agentDir: directory, modelRuntime: runtime, model, noTools: 'builtin', customTools,
109
+ resourceLoader: loader, settingsManager: settings, sessionManager: manager,
110
+ thinkingLevel: ['minimal', 'low', 'medium', 'high', 'xhigh', 'max'].includes(profile.reasoningEffort) ? profile.reasoningEffort : profile.thinking === 'enabled' ? 'medium' : 'off' }));
111
+ session.agent.toolExecution = 'sequential';
112
+ // This gate covers normal inference, session retries and every summary request.
113
+ const stream = session.agent.streamFunction;
114
+ session.agent.streamFunction = (selected, context, options) => {
115
+ const output = createAssistantMessageEventStream();
116
+ void (async () => {
117
+ try {
118
+ if (cancelled)
119
+ throw new Error('Cancelled');
120
+ // The SDK has persisted the user message before opening its model stream.
121
+ // Reconcile this durable cursor after a process/host crash; never resend accepted input.
122
+ if (!accepted && manager.getEntries().some((entry) => entry.type === 'message' && entry.message.role === 'user' &&
123
+ (typeof entry.message.content === 'string' ? entry.message.content : entry.message.content.filter((part) => part.type === 'text').map((part) => part.text).join('')) === prompt)) {
124
+ accepted = true;
125
+ manager.appendCustomEntry('tabby-input', { count: sourceCount });
126
+ await new Promise(resolve => { pending.set('accepted', resolve); send({ type: 'accepted' }); });
127
+ if (cancelled)
128
+ throw new Error('Cancelled');
129
+ }
130
+ if (input.budget && tokens >= input.budget)
131
+ throw new Error('Goal token budget exhausted');
132
+ if (++requests > 100)
133
+ throw new Error('Pi request safety limit reached (100, including retries and summaries)');
134
+ const source = await stream(selected, context, { ...options, maxRetries: 0, maxTokens: profile.maxOutputTokens,
135
+ identity: { userAgent: { custom: 'tabby-ai-tools (Pi SDK)' }, attribution: null },
136
+ onPayload: payload => providerPayload(profile, payload),
137
+ ...(!input.key ? { headers: { ...options?.headers, Authorization: null } } : {}) });
138
+ for await (const event of source) {
139
+ if (event.type === 'done' || event.type === 'error') {
140
+ const message = event.type === 'done' ? event.message : event.error;
141
+ tokens += Math.max(0, message.usage?.totalTokens || 0);
142
+ send({ type: 'usage', tokens, inputTokens: (message.usage?.input || 0) + (message.usage?.cacheRead || 0) + (message.usage?.cacheWrite || 0) });
143
+ }
144
+ output.push(event);
145
+ }
146
+ output.end(await source.result());
147
+ }
148
+ catch (error) {
149
+ const message = { role: 'assistant', content: [], api: selected.api, provider: selected.provider, model: selected.id,
150
+ usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } },
151
+ stopReason: cancelled ? 'aborted' : 'error', errorMessage: String(error.message || error), timestamp: Date.now() };
152
+ output.push({ type: 'error', reason: message.stopReason, error: message });
153
+ }
154
+ })();
155
+ return output;
156
+ };
157
+ session.subscribe(event => {
158
+ if (event.type === 'message_update' && event.assistantMessageEvent.type === 'text_delta')
159
+ send({ type: 'text', delta: event.assistantMessageEvent.delta });
160
+ if (event.type === 'message_update' && ['thinking_delta', 'toolcall_delta'].includes(event.assistantMessageEvent.type)) {
161
+ const delta = event.assistantMessageEvent;
162
+ if (delta.type === 'thinking_delta')
163
+ thinkingChars += delta.delta.length;
164
+ else
165
+ toolChars += delta.delta.length;
166
+ send({ type: 'progress', progress: { phase: delta.type === 'thinking_delta' ? 'thinking' : 'tools', receivedChars: delta.type === 'thinking_delta' ? thinkingChars : toolChars } });
167
+ }
168
+ if (event.type === 'message_end' && event.message.role === 'assistant') {
169
+ const message = event.message;
170
+ lastError = message.stopReason === 'length' ? 'Pi response reached the output token limit; the reply is incomplete.'
171
+ : message.stopReason === 'error' ? message.errorMessage || 'Pi inference failed' : '';
172
+ lastText = message.content.filter(part => part.type === 'text').map(part => part.text).join('');
173
+ }
174
+ if (['auto_retry_start', 'auto_retry_end', 'compaction_start', 'compaction_end', 'summarization_retry_scheduled', 'agent_settled'].includes(event.type))
175
+ send({ type: 'lifecycle', event });
176
+ if (event.type === 'agent_settled')
177
+ settled = true;
178
+ });
179
+ await new Promise(resolve => { pending.set('start', resolve); send({ type: 'ready', file: manager.getSessionFile() }); });
180
+ if (cancelled)
181
+ throw new Error('Cancelled');
182
+ if (input.compact) {
183
+ try {
184
+ await session.compact('Preserve all user constraints, goal, active skills, pending workflow checkpoints, observed results, and unknown actions. Never infer completion from a sent command.');
185
+ lastText = 'Context compacted; original Pi session entries retained.';
186
+ }
187
+ catch (error) {
188
+ if (!/^(Already compacted|Nothing to compact \(session too small\))$/.test(error.message))
189
+ throw error;
190
+ lastText = 'History is already compact or too short to compact.';
191
+ }
192
+ }
193
+ else {
194
+ let nextPrompt = prompt;
195
+ do {
196
+ settled = false;
197
+ await session.prompt(nextPrompt);
198
+ await session.waitForIdle();
199
+ if (!settled && !cancelled)
200
+ throw new Error('Pi did not settle');
201
+ if (lastError)
202
+ throw new Error(lastError);
203
+ if (cancelled)
204
+ break;
205
+ stalls = nativeTools === previousTools && lastText === previousText ? stalls + 1 : 0;
206
+ previousTools = nativeTools;
207
+ previousText = lastText;
208
+ if (stalls >= 2 && activeGoal)
209
+ throw new Error('Goal stalled: repeated response without new evidence');
210
+ nextPrompt = 'The goal is active. Continue from observed results, never replay completed operations. Verify the original requirements and update agent_goal_update with evidence. Pause only on user request.';
211
+ } while (activeGoal);
212
+ }
213
+ send({ type: 'done', text: lastText, tokens, file: manager.getSessionFile(), cancelled });
214
+ finish();
215
+ }
Binary file
@@ -1,6 +1,6 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" width="1800" height="1220" viewBox="0 0 1800 1220" role="img" aria-labelledby="title desc">
2
- <title id="title">Tabby AI Tools 0.3.2 — multi-terminal work, schedules and language settings</title>
3
- <desc id="desc">Interface illustration, not a running screenshot. The assistant sidebar coordinates example staging database and application terminals. Scheduled tasks, provider connections, startup opening enabled by default and twelve interface languages are shown below.</desc>
1
+ <svg xmlns="http://www.w3.org/2000/svg" width="1800" height="1440" viewBox="0 0 1800 1440" role="img" aria-labelledby="title desc">
2
+ <title id="title">Tabby AI Tools v0.5.0 interface illustration — verified workflow recording, conversational aliases, local login and API connections</title>
3
+ <desc id="desc">Interface illustration, not a running screenshot. The assistant sidebar coordinates example staging database and application terminals. Connection and model controls share one compact row. Scheduled tasks, provider connections, startup opening enabled by default and twelve interface languages and the Claude Code local-login connection are shown below. Active goals continue automatically by default. Terminal output is read on demand without automatic forwarding; a completed explicit recording and a saved workflow alias are shown. Archive status distinguishes successful checkpoints from successful persistence. Pi runtime settings show an external Node executable, host-only tools and opt-in automatic context compaction. The provider list includes Kimi and Alibaba Cloud Coding Plan connections. Custom OpenAI-compatible settings show an example Base URL, model, protocol and authentication. Version 0.5.0 example with optional Pi SDK runtime, external Node 22.19+, manual context compaction and structured retry waiting.</desc>
4
4
  <defs>
5
5
  <linearGradient id="background" x2="1" y2="1"><stop stop-color="#0c1622"/><stop offset="1" stop-color="#151729"/></linearGradient>
6
6
  <linearGradient id="outline"><stop stop-color="#375d5d"/><stop offset="1" stop-color="#3b3d5c"/></linearGradient>
@@ -10,14 +10,14 @@ text{font-family:"DejaVu Sans",sans-serif;fill:#e8eff9}
10
10
  .mono{font-family:"DejaVu Sans Mono",monospace}
11
11
  </style>
12
12
 
13
- <rect x="0" y="0" width="1800" height="1220" rx="24" fill="url(#background)"/>
13
+ <rect x="0" y="0" width="1800" height="1440" rx="24" fill="url(#background)"/>
14
14
  <rect x="48" y="38" width="42" height="38" rx="10" fill="#173a33" stroke="#306355"/>
15
15
  <text x="56" y="65" font-size="23" font-weight="700" style="fill:#8ae6c2" class="mono">&gt;_</text>
16
16
  <text x="106" y="66" font-size="21" font-weight="700" style="fill:#a7b8cb">TABBY AI TOOLS</text>
17
17
  <rect x="1534" y="44" width="218" height="28" rx="6" fill="#22313f"/>
18
- <text x="1544" y="64" font-size="16" font-weight="600" style="fill:#8ae6c2">v0.3.2 / 12 languages</text>
18
+ <text x="1544" y="64" font-size="16" font-weight="600" style="fill:#8ae6c2">v0.5.0 / Pi optional</text>
19
19
  <text x="48" y="134" font-size="54" font-weight="700" style="fill:#f1f6ff">Your terminals. Working together.</text>
20
- <text x="50" y="176" font-size="23" font-weight="400" style="fill:#a7b8cb">Codex + API connections / Automatic terminal takeover / Scheduled AI tasks</text>
20
+ <text x="50" y="176" font-size="23" font-weight="400" style="fill:#a7b8cb">Codex + Claude Code + APIs + optional Pi SDK / Terminal tools / Scheduled AI tasks</text>
21
21
  <rect x="48" y="210" width="1704" height="632" rx="14" fill="#0d1520" stroke="url(#outline)"/>
22
22
  <rect x="49" y="211" width="1702" height="42" rx="13" fill="#1c2635"/>
23
23
  <rect x="49" y="235" width="1702" height="18" rx="0" fill="#1c2635"/>
@@ -28,45 +28,47 @@ text{font-family:"DejaVu Sans",sans-serif;fill:#e8eff9}
28
28
  <text x="1647" y="239" font-size="15" font-weight="400" style="fill:#a7b8cb">+ Settings</text>
29
29
  <rect x="49" y="253" width="499" height="588" rx="0" fill="#172130"/>
30
30
  <path d="M548 253L548 842" stroke="#3b4b60"/>
31
- <text x="72" y="285" font-size="23" font-weight="700" style="fill:#eef4ff">Codex</text>
32
- <text x="166" y="284" font-size="16" font-weight="400" style="fill:#8ca0b8">workspace</text>
31
+ <text x="72" y="285" font-size="23" font-weight="700" style="fill:#eef4ff">Pi example</text>
32
+ <text x="248" y="284" font-size="16" font-weight="400" style="fill:#8ca0b8">workspace</text>
33
33
  <rect x="368" y="263" width="62" height="28" rx="6" fill="#1a4a3a"/>
34
34
  <text x="378" y="283" font-size="14" font-weight="600" style="fill:#8ae6c2">Linked</text>
35
35
  <rect x="438" y="263" width="64" height="28" rx="6" fill="#253348"/>
36
36
  <text x="448" y="283" font-size="14" font-weight="600" style="fill:#a7b8cb">Details</text>
37
37
  <text x="519" y="285" font-size="22" font-weight="400" style="fill:#8ca0b8">×</text>
38
- <rect x="72" y="302" width="452" height="33" rx="5" fill="#243247" stroke="#3a4c65"/>
39
- <text x="86" y="325" font-size="17" font-weight="400" style="fill:#e8eff9">Codex (local login)</text>
40
- <text x="500" y="325" font-size="20" font-weight="400" style="fill:#a7b8cb">⌄</text>
41
- <rect x="72" y="344" width="452" height="31" rx="5" fill="#202d40"/>
42
- <text x="84" y="366" font-size="16" font-weight="400" style="fill:#e8eff9">Codex default</text>
43
- <text x="302" y="366" font-size="15" font-weight="400" style="fill:#a7b8cb">reasoning: high</text>
38
+ <rect x="72" y="302" width="196" height="33" rx="5" fill="#243247" stroke="#3a4c65"/>
39
+ <text x="82" y="325" font-size="15" style="fill:#e8eff9">Pi SDK (example)</text>
40
+ <text x="246" y="325" font-size="20" style="fill:#a7b8cb">⌄</text>
41
+ <rect x="276" y="302" width="248" height="33" rx="5" fill="#202d40"/>
42
+ <text x="284" y="325" font-size="14" style="fill:#e8eff9">default</text>
43
+ <text x="390" y="325" font-size="14" style="fill:#a7b8cb">reasoning: high</text>
44
+ <g transform="translate(0 -40)">
44
45
  <rect x="72" y="384" width="88" height="28" rx="6" fill="#344132"/>
45
- <text x="82" y="404" font-size="15" font-weight="600" style="fill:#d4e9a1">Running</text>
46
- <text x="174" y="405" font-size="15" font-weight="400" style="fill:#a7b8cb">Context 18%</text>
47
- <text x="290" y="405" font-size="15" font-weight="400" style="fill:#8ae6c2">Control 2</text>
48
- <text x="387" y="405" font-size="15" font-weight="600" style="fill:#8ae6c2">Release</text>
49
- <text x="461" y="405" font-size="14" font-weight="400" style="fill:#a7b8cb">Fwd on</text>
46
+ <text x="82" y="404" font-size="15" font-weight="600" style="fill:#d4e9a1">Done</text>
47
+ <text x="174" y="405" font-size="15" font-weight="400" style="fill:#a7b8cb">Context —</text>
48
+ <text x="290" y="405" font-size="15" font-weight="400" style="fill:#8ae6c2">Control —</text>
49
+
50
+ <text x="461" y="405" font-size="14" font-weight="400" style="fill:#a7b8cb">Fwd off</text>
50
51
  <rect x="72" y="419" width="452" height="80" rx="8" fill="#21324b" stroke="#3b4f70"/>
51
52
  <text x="86" y="442" font-size="14" font-weight="600" style="fill:#b9d3f7">You</text>
52
- <text x="86" y="467" font-size="17" font-weight="400" style="fill:#e8eff9">Check staging-db first, then staging-app.</text>
53
- <text x="86" y="489" font-size="17" font-weight="400" style="fill:#e8eff9">Verify connectivity and the health check.</text>
53
+ <text x="86" y="467" font-size="17" font-weight="400" style="fill:#e8eff9">/remember Check staging services.</text>
54
+ <text x="86" y="489" font-size="17" font-weight="400" style="fill:#e8eff9">Verify database and application health.</text>
54
55
  <rect x="72" y="509" width="452" height="80" rx="8" fill="#1b2839" stroke="#344458"/>
55
56
  <text x="86" y="533" font-size="14" font-weight="600" style="fill:#8ae6c2">Assistant</text>
56
- <text x="86" y="557" font-size="17" font-weight="400" style="fill:#e8eff9">Database step verified. Application next.</text>
57
- <text x="86" y="578" font-size="17" font-weight="400" style="fill:#e8eff9">Verify server ID, IP and operation path.</text>
57
+ <text x="86" y="557" font-size="17" font-weight="400" style="fill:#e8eff9">Checks passed; recording archived.</text>
58
+ <text x="86" y="578" font-size="17" font-weight="400" style="fill:#e8eff9">Workflow alias saved: /pm1.</text>
58
59
  <text x="75" y="606" font-size="15" font-weight="600" style="fill:#a7b8cb">Workflows</text>
59
60
  <text x="205" y="606" font-size="15" font-weight="600" style="fill:#8ae6c2">Scheduled tasks</text>
60
61
  <rect x="72" y="619" width="452" height="92" rx="7" fill="#1a2938" stroke="#35534f"/>
61
62
  <text x="85" y="644" font-size="18" font-weight="600" style="fill:#e5f3eb">Daily service health</text>
62
63
  <text x="85" y="667" font-size="15" font-weight="400" style="fill:#a7b8cb">Enabled · Daily 09:00 (Asia/Shanghai)</text>
63
64
  <text x="85" y="692" font-size="15" font-weight="400" style="fill:#8ae6c2">Run now Pause Run history</text>
64
- <rect x="72" y="723" width="452" height="53" rx="7" fill="#101a27" stroke="#42546d"/>
65
- <text x="85" y="747" font-size="16" font-weight="400" style="fill:#8ca0b8">/task1 — run the saved workflow</text>
66
- <text x="85" y="768" font-size="12" font-weight="400" style="fill:#8ca0b8">Ctrl / Cmd + Enter to send</text>
67
- <text x="73" y="812" font-size="14" font-weight="400" style="fill:#a7b8cb">Files</text>
65
+ </g>
66
+ <rect x="72" y="683" width="452" height="93" rx="7" fill="#101a27" stroke="#42546d"/>
67
+ <text x="85" y="707" font-size="16" font-weight="400" style="fill:#8ca0b8">Workflow alias saved: /pm1</text>
68
+ <text x="85" y="728" font-size="12" font-weight="400" style="fill:#8ca0b8">/pm1 will verify the live targets again.</text>
69
+ <text x="73" y="812" font-size="14" font-weight="400" style="fill:#a7b8cb">Tools</text>
68
70
  <rect x="115" y="792" width="159" height="28" rx="6" fill="#253348"/>
69
- <text x="125" y="812" font-size="14" font-weight="600" style="fill:#a7b8cb">Workspace write</text>
71
+ <text x="125" y="812" font-size="14" font-weight="600" style="fill:#a7b8cb">Terminal tools</text>
70
72
  <text x="286" y="812" font-size="13" font-weight="400" style="fill:#a7b8cb">Approval</text>
71
73
  <rect x="352" y="792" width="97" height="28" rx="6" fill="#253348"/>
72
74
  <text x="362" y="812" font-size="13" font-weight="600" style="fill:#a7b8cb">On request</text>
@@ -105,12 +107,12 @@ text{font-family:"DejaVu Sans",sans-serif;fill:#e8eff9}
105
107
  <text x="1178" y="654" font-size="18" font-weight="400" style="fill:#8ca0b8" class="mono">}</text>
106
108
  <text x="1178" y="685" font-size="18" font-weight="400" style="fill:#c7b6f6" class="mono">deploy@staging-app:~$</text>
107
109
  <path d="M549 806H1751" stroke="#2b3a4d"/>
108
- <text x="574" y="830" font-size="16" font-weight="400" style="fill:#a7b8cb">2 SSH terminals · Input can be reclaimed from the sidebar at any time</text>
110
+ <text x="574" y="830" font-size="16" font-weight="400" style="fill:#a7b8cb">2 SSH terminals · Output read on demand · Automatic forwarding off</text>
109
111
  <rect x="48" y="878" width="1050" height="254" rx="12" fill="#172130" stroke="#35475c"/>
110
112
  <text x="72" y="915" font-size="24" font-weight="650" style="fill:#edf5ff">Settings / AI Tools</text>
111
113
  <text x="72" y="952" font-size="18" font-weight="400" style="fill:#a7b8cb">Default connection</text>
112
114
  <rect x="496" y="929" width="575" height="33" rx="6" fill="#233246" stroke="#3c5068"/>
113
- <text x="512" y="952" font-size="17" font-weight="400" style="fill:#e8eff9">Codex (local login)</text>
115
+ <text x="512" y="952" font-size="17" font-weight="400" style="fill:#e8eff9">Claude Code (local login)</text>
114
116
  <text x="1048" y="952" font-size="20" font-weight="400" style="fill:#a7b8cb">⌄</text>
115
117
  <text x="72" y="993" font-size="18" font-weight="400" style="fill:#e8eff9">Open AI Tools when Tabby starts</text>
116
118
  <text x="740" y="993" font-size="16" font-weight="500" style="fill:#8ae6c2">On by default</text>
@@ -122,19 +124,38 @@ text{font-family:"DejaVu Sans",sans-serif;fill:#e8eff9}
122
124
  <text x="892" y="1035" font-size="15" font-weight="400" style="fill:#8ca0b8">12 languages</text>
123
125
  <text x="1048" y="1035" font-size="20" font-weight="400" style="fill:#a7b8cb">⌄</text>
124
126
  <path d="M72 1061H1071" stroke="#2b3a4d"/>
125
- <text x="72" y="1086" font-size="18" font-weight="500" style="fill:#8ae6c2">Codex · OpenAI · DeepSeek · GLM · Claude</text>
126
- <text x="72" y="1115" font-size="14" style="fill:#a7b8cb">macOS discovery: ChatGPT.app/Contents/Resources/codex-cli/bin/codex</text>
127
+ <text x="72" y="1086" font-size="16" font-weight="500" style="fill:#8ae6c2">Codex · Claude Code · OpenAI · DeepSeek · GLM · Kimi API / Plan · Alibaba Plan · Claude API</text>
128
+ <text x="72" y="1115" font-size="14" style="fill:#a7b8cb">Goals continue automatically · Default tool-round limit: 0 (unlimited)</text>
127
129
  <rect x="1122" y="878" width="630" height="254" rx="12" fill="#172130" stroke="#35475c"/>
128
- <text x="1146" y="915" font-size="24" font-weight="650" style="fill:#edf5ff">One setup, many targets</text>
129
- <circle cx="1153" cy="948" r="4" fill="#8ae6c2"/>
130
- <text x="1168" y="953" font-size="18" font-weight="600" style="fill:#e1ecf8">Local login or API connections</text>
131
- <text x="1168" y="976" font-size="15" font-weight="400" style="fill:#a7b8cb">Keep account setup on your computer.</text>
132
- <circle cx="1153" cy="1007" r="4" fill="#8ae6c2"/>
133
- <text x="1168" y="1012" font-size="18" font-weight="600" style="fill:#e1ecf8">Ordered workflows with result checks</text>
134
- <text x="1168" y="1035" font-size="15" font-weight="400" style="fill:#a7b8cb">Save host / IP / path; verify each step before the next.</text>
135
- <circle cx="1153" cy="1066" r="4" fill="#8ae6c2"/>
136
- <text x="1168" y="1071" font-size="18" font-weight="600" style="fill:#e1ecf8">Scheduled tasks with run records</text>
137
- <text x="1168" y="1094" font-size="15" font-weight="400" style="fill:#a7b8cb">Execute only while Tabby is open.</text>
138
- <text x="49" y="1176" font-size="16" font-weight="400" style="fill:#8ca0b8">INTERFACE ILLUSTRATION · Example connections and task output; not a running screenshot.</text>
139
- <text x="49" y="1201" font-size="14" font-weight="400" style="fill:#8ca0b8">Appearance varies with your Tabby theme, window size and configured connections.</text>
130
+ <text x="1146" y="915" font-size="22" font-weight="650" style="fill:#edf5ff">Pi SDK / Example runtime settings</text>
131
+ <text x="1146" y="946" font-size="16" style="fill:#a7b8cb">Runtime: isolated Node 22.19+ process</text>
132
+ <rect x="1146" y="960" width="580" height="31" rx="5" fill="#233246"/>
133
+ <text x="1160" y="981" font-size="16">Node executable: /path/to/node</text>
134
+ <text x="1160" y="1015" font-size="16">API Agent</text>
135
+ <text x="1315" y="1015" font-size="16">Pi SDK</text>
136
+ <rect x="1475" y="997" width="251" height="28" rx="5" fill="#286a54"/>
137
+ <text x="1490" y="1016" font-size="16" style="fill:#e8fff5">Pi SDK selected</text>
138
+ <text x="1146" y="1052" font-size="15" style="fill:#a7b8cb">Automatic compaction (optional)</text>
139
+ <rect x="1146" y="1063" width="461" height="28" rx="5" fill="#233246"/>
140
+ <text x="1160" y="1083" font-size="14" style="fill:#a7b8cb">Off by default; /compact manually</text>
141
+ <rect x="1619" y="1063" width="107" height="28" rx="5" fill="#253348"/>
142
+ <text x="1648" y="1083" font-size="14">Saved</text>
143
+ <text x="1146" y="1116" font-size="15" style="fill:#8ae6c2">Host tools only · Existing approval and workflow policies</text>
144
+ <rect x="48" y="1152" width="1704" height="204" rx="12" fill="#172130" stroke="#35475c"/>
145
+ <text x="72" y="1189" font-size="22" font-weight="650" style="fill:#edf5ff">Custom (OpenAI compatible) / Example connection settings</text>
146
+ <text x="72" y="1223" font-size="16" style="fill:#a7b8cb">API protocol</text>
147
+ <rect x="260" y="1201" width="580" height="33" rx="5" fill="#233246"/>
148
+ <text x="276" y="1224" font-size="16">Chat Completions (default) / Responses</text>
149
+ <text x="890" y="1223" font-size="16" style="fill:#a7b8cb">Key source</text>
150
+ <rect x="1080" y="1201" width="646" height="33" rx="5" fill="#233246"/>
151
+ <text x="1096" y="1224" font-size="16">Direct key / Environment variable / No API key</text>
152
+ <text x="72" y="1271" font-size="16" style="fill:#a7b8cb">Base URL</text>
153
+ <rect x="260" y="1249" width="580" height="33" rx="5" fill="#233246"/>
154
+ <text x="276" y="1272" font-size="16">https://gateway.example/v1</text>
155
+ <text x="890" y="1271" font-size="16" style="fill:#a7b8cb">Model ID</text>
156
+ <rect x="1080" y="1249" width="646" height="33" rx="5" fill="#233246"/>
157
+ <text x="1096" y="1272" font-size="16">your-model-id / Discover or enter manually</text>
158
+ <text x="72" y="1326" font-size="16" style="fill:#8ae6c2">/compact retains original history · Summaries use quota · Structured retry countdown · Stop cancels backoff</text>
159
+ <text x="49" y="1393" font-size="16" font-weight="400" style="fill:#8ca0b8">INTERFACE ILLUSTRATION · Example connections and task output; not a running screenshot.</text>
160
+ <text x="49" y="1418" font-size="14" font-weight="400" style="fill:#8ca0b8">Appearance varies with your Tabby theme, window size and configured connections.</text>
140
161
  </svg>
@@ -0,0 +1,57 @@
1
+ # Claude Code local login
2
+
3
+ [README](../README.md) · [中文使用指南](guide.md)
4
+
5
+ Version 0.4.1 includes **Claude Code (local login)** alongside native Codex and the existing Claude API connection. It runs the user's installed, unmodified official CLI. Authentication, model access, subscription limits, and billing remain with Claude Code.
6
+
7
+ ## Setup
8
+
9
+ 1. Install the [official Claude Code CLI](https://code.claude.com/docs/en/setup) on the computer running Tabby.
10
+ 2. Run `claude auth login` in a local terminal and choose your Claude account to use an eligible subscription. Check `claude auth status` and confirm the intended authentication method. Existing API keys, API key helpers, or cloud-provider configuration may select separately billed usage; the plugin preserves the CLI's authentication options.
11
+ 3. In **Settings → AI Tools → Claude Code**, set the executable path if discovery cannot find it. Select **Claude Code (local login)** in the sidebar or make it the default connection. The default alias is `sonnet`; `opus`, `haiku`, and full model IDs can also be configured. These are candidate aliases, not an account entitlement list.
12
+ 4. Describe a task. Operations use the same Tabby tools, read-only restrictions, approvals, workflow checkpoints, and execution records as API connections. The host's operating system permissions still apply; this mode does not supply an OS sandbox.
13
+
14
+ The executable resolver checks PATH, the official `~/.local/bin` location, common Homebrew/npm directories, and the current executable's directory. Explicit paths, quoted paths, and `~/` paths are supported. A custom command name searches PATH only. Windows `.exe`, `.com`, `.cmd`, and `.bat` launchers are supported. Custom Node/npm prefixes outside these locations need an explicit path and a working Node environment.
15
+
16
+ Connecting checks `--help` and `auth status` without model inference. The CLI must support the integration flags, including `--system-prompt-snapshot`, `--append-system-prompt-file`, strict MCP configuration, and streaming partial messages. Update Claude Code if the connection reports a missing flag. No account credentials are read from files or saved by the plugin.
17
+
18
+ ## Design decision and official sources
19
+
20
+ The [official authentication rules](https://code.claude.com/docs/en/legal-and-compliance#authentication-and-credential-use) distinguish running unmodified Claude Code with the user's own subscription from a third-party application's reuse of subscription credentials. The integration uses the former: the CLI completes Anthropic's own login flow and makes all model requests. The plugin neither implements a Claude.ai OAuth flow nor forwards subscription tokens to the Messages API. Existing Claude API connections remain separate.
21
+
22
+ The adapter uses the documented [programmatic CLI](https://code.claude.com/docs/en/headless), [CLI flags](https://code.claude.com/docs/en/cli-reference), and [HTTP MCP configuration](https://code.claude.com/docs/en/mcp). A TypeScript Agent SDK dependency is not needed. The default Claude Code system prompt is retained, with the bundled Tabby skill and current task instructions appended.
23
+
24
+ ```mermaid
25
+ sequenceDiagram
26
+ participant User
27
+ participant Panel as Tabby sidebar
28
+ participant CLI as Official Claude Code CLI
29
+ participant MCP as Temporary loopback MCP bridge
30
+ participant Host as Tabby tool executor
31
+ User->>CLI: claude auth login (official flow)
32
+ User->>Panel: Task and selected local connection
33
+ Panel->>CLI: -p + stream-json + appended instructions
34
+ CLI-->>Panel: Streamed response and usage
35
+ CLI->>MCP: Authenticated tools/call
36
+ MCP->>Host: Existing tool validation and permissions
37
+ Host-->>Panel: Approval when required
38
+ Host-->>MCP: Recorded execution result
39
+ MCP-->>CLI: MCP tool result
40
+ CLI-->>Panel: Final result and native session ID
41
+ ```
42
+
43
+ ## Runtime boundaries
44
+
45
+ - Each invocation gets an HTTP MCP listener on `127.0.0.1` with a random port and a fresh 256-bit bearer secret. The listener checks the host and rejects browser origins. Calls are serialized before entering the existing executor; intent is saved before execution. The server and private temporary instruction/config files are removed when the invocation ends or stops.
46
+ - `--tools ""` disables built-in shell/file tools. `--strict-mcp-config` loads the Tabby bridge, and `--disable-slash-commands` disables CLI skills and commands for this invocation. `--settings '{"disableAllHooks":true}'` disables user/project/plugin hooks; administrator-managed hooks and enforced policy remain governed by Claude Code. Only user settings are loaded to retain the user's authentication helpers; project/local settings are excluded. These options apply to the launched session, without changing the user's settings files.
47
+ - MCP approval rules allow the bridge to reach the host executor. They do not waive the host's read-only checks, mutation approval, workflow sequencing, sudo authentication, or scheduled-task restrictions.
48
+ - The plugin stores portable conversation history and an opaque native session ID, not credentials. Successful continuations use `--resume` and send only new input. Model changes and provider switches import portable text and observed tool outcomes into a fresh session. On an interrupted or failed invocation, the next explicit request reconstructs from recorded history, with a warning to verify the terminal before acting. There is no automatic model retry or silent API fallback.
49
+ - Stop cancels pending host requests and terminates the owned CLI process tree before the turn finishes. Commands already submitted to a Tabby terminal may still run. Messages added while Claude Code is working are queued for a new invocation after the current one ends, rather than injected into an in-progress CLI request.
50
+ - Observed usage is counted once per native message and checked against the task budget before further operations. Token usage is not a subscription balance or price. Native context compaction belongs to Claude Code; imported plugin history has a 9 MiB input limit.
51
+ - Schedules can choose this connection. Existing scheduler isolation, logging, and unattended rules apply. An explicitly requested candidate-model test uses an isolated MCP confirmation tool and consumes model quota; normal connection/model-list checks do not.
52
+
53
+ ## Validation limits
54
+
55
+ Offline tests use a real child process and authenticated HTTP MCP, with simulated Claude events. They cover streaming, native resume, migration, approvals, read-only mode, durable intent, cancellation, malformed/truncated output, failed results, token accounting/budgets, connection selection, and the scheduler's model probe. They make no model requests.
56
+
57
+ A real subscription end-to-end run still requires an installed CLI, an eligible user's official login, and real Tabby desktop testing. Passing the offline tests does not establish actual subscription entitlement, model quality, or Windows/macOS execution results.
@@ -0,0 +1,39 @@
1
+ # Kimi API、Kimi Coding Plan 与阿里云百炼 Coding Plan
2
+
3
+ [返回使用指南](guide.md#api-密钥与切换模型)
4
+
5
+ v0.4.1 提供三个独立的供应商选项,均通过 Chat Completions 接入,无需安装模型厂商的 CLI。支持文本流式回复、思考接收进度、工具调用、目标续行及历史恢复。模型本身支持图片不代表插件已支持图片输入;当前输入仍为文本与终端内容。
6
+
7
+ ## 国内与国际端点
8
+
9
+ 在 **Settings → AI Tools → 添加 API 连接** 中选择供应商,然后选择 **服务区域 → 中国内地/国际**。区域切换自动填写 Base URL,并清除旧模型列表;模型 ID 和密钥草稿保留,请重新核对。手动修改 Base URL 后会显示“自定义地址”,不会自动覆盖代理配置。服务区域代表购买平台的接口,不是自动测速、故障转移或套餐互转。
10
+
11
+ | 供应商选项 | 中国内地 Base URL | 国际 Base URL | 默认环境变量 | 预填模型 ID |
12
+ | --- | --- | --- | --- | --- |
13
+ | Kimi API(开放平台,按量付费) | `https://api.moonshot.cn/v1` | `https://api.moonshot.ai/v1` | `MOONSHOT_API_KEY` | `kimi-k3.1-pro` |
14
+ | Kimi Coding Plan(Kimi Code 会员) | `https://api.kimi.com/coding/v1` | `https://api.kimi.ai/coding/v1` | `KIMI_API_KEY` | `kimi-for-coding` |
15
+ | 阿里云百炼 Coding Plan | `https://coding.dashscope.aliyuncs.com/v1` | `https://coding-intl.dashscope.aliyuncs.com/v1` | `BAILIAN_CODING_PLAN_API_KEY` | `qwen3.7-plus` |
16
+
17
+ 默认选择中国内地。请求路径由插件拼接为 `/chat/completions`,无需手动附加。选择端点时,请使用购买平台、套餐及区域对应的 Key;国内与国际的可用模型、权益和配额应分别以对应控制台为准。
18
+
19
+ Kimi 的开放平台 Key 和 Kimi Code 会员 Key 是两套配置,不能混用。Kimi Code Key 在 [Kimi Code 控制台](https://www.kimi.com/code/console) 创建。官方端点与区别见 [Kimi Code API 接入](https://www.kimi.com/code/docs/#api-接入)和[常见问题](https://www.kimi.com/help/kimi-code/faq)。
20
+
21
+ 阿里 Coding Plan 使用套餐页面创建的专用 Key(`sk-sp-`),不能使用普通百炼按量 API Key。两类地址与额度不互通,套餐额度耗尽不会自动回退至按量计费。国内说明见[百炼 Coding Plan](https://help.aliyun.com/zh/model-studio/coding-plan),国际接入见[Model Studio 第三方编程工具](https://www.alibabacloud.com/help/en/model-studio/more-tools)。Coding Plan 与 Token Plan 是不同产品,本选项预设的是 Coding Plan 地址。
22
+
23
+ ## 模型、思考与工具调用
24
+
25
+ 预填模型可手动修改,不代表账号已获得该模型权限。聚焦模型输入框或点击“获取模型”读取当前端点的 `/models`;服务端不提供模型列表时,保留手动输入。不要把 Kimi Code 的 `kimi-for-coding` 别名填入普通 Kimi API,也不要假定百炼支持所有 Kimi 直连模型。
26
+
27
+ 新选择这三个供应商时,输出上限预填 `32768`,为思考和正文保留空间;可以在高级设置按模型上限调整。现有连接不会因为升级自动改写。
28
+
29
+ - **Kimi API**:K3/K3.1 Pro 通过 `reasoning_effort` 调整 `low`/`high`/`max`;已知仅支持思考的 K3、K3.1 Pro 和 K2.7 Code 模型不发送不兼容的 `thinking` 字段。关闭这些模型的思考会在发请求前提示修改配置。K2.6 等可切换模型仍可显式启用或关闭 Thinking。
30
+ - **Kimi Coding Plan**:根据服务端元数据或已知模型提供推理等级;`kimi-for-coding`、K3 和 K3.1 Pro 支持 `low`/`high`/`max`,高速模型不一概复用这些选项。K3.1 Pro 不能关闭思考。模型别名实际指向的版本及会员档位可能变化,见[官方模型配置](https://www.kimi.com/code/docs/kimi-code/models.html)。
31
+ - **百炼 Coding Plan**:使用自己的 `enable_thinking` 布尔参数;即使模型名为 `kimi-k2.5` 或 GLM,也遵循百炼协议。默认不强加思考参数;手动推理强度只应填写该端点和模型明确支持的值。见[百炼思考模式配置](https://help.aliyun.com/zh/model-studio/coding-plan-faq)。
32
+
33
+ 三个连接都会处理分片 `tool_calls` 和流式 usage;历史中的 `reasoning_content` 在所属会话里保存并回传,跨供应商只交接通用文本,不泄露或重放内部推理。Kimi 请求带会话级 `prompt_cache_key`,同一会话工具续轮、后续消息和重启恢复保持一致,新会话独立。协议依据:[Kimi Chat Completions](https://platform.kimi.ai/docs/api/chat)、[思考与工具调用](https://platform.kimi.ai/docs/guide/use-thinking-models)。
34
+
35
+ ## 使用范围与验证边界
36
+
37
+ Kimi Code 会员和百炼 Coding Plan 用于个人交互式编程。无人值守定时任务、批量脚本或应用后端应使用适合该场景的普通按量 API。插件提示此限制,模型知识也会提示选用合适的连接;当前并未增加套餐用途的运行时强制拦截。请求使用真实的 `tabby-ai-tools` 客户端标识,不冒用官方客户端,也不伪装成其他工具。参见 [Kimi Code 社区倡议](https://www.kimi.com/code/docs/kimi-code/community-guidelines.html)和[百炼使用须知](https://help.aliyun.com/zh/model-studio/coding-plan)。
38
+
39
+ 本次使用本地 HTTP/SSE 夹具验证了协议、鉴权、区域切换、模型发现、流式回复、连续工具调用、思考参数、历史恢复和缓存标识;未调用收费模型,未用真实套餐账号核验厂商准入与额度扣减。点击设置中的“测试连接”会发送真实简短请求并消耗少量用量;HTTP 401 请核对 Key 与端点,403 请核对套餐、模型权限及工具准入,429 请检查额度与限流。错误不会自动改走其他计费端点。