@trans-ai/trans-code 0.10.0 → 0.10.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trans-ai/trans-code",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
4
4
  "description": "AI-powered multi-model coding CLI",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -48,3 +48,12 @@ describe('permission mode', () => {
48
48
  expect(PERMISSION_MODES).toEqual(['ask', 'auto', 'readonly']);
49
49
  });
50
50
  });
51
+
52
+ describe('nextPermissionMode', () => {
53
+ test('shift+tab 循环:ask → auto → readonly → ask', async () => {
54
+ const { nextPermissionMode } = await import('./permission.js');
55
+ expect(nextPermissionMode('ask')).toBe('auto');
56
+ expect(nextPermissionMode('auto')).toBe('readonly');
57
+ expect(nextPermissionMode('readonly')).toBe('ask');
58
+ });
59
+ });
@@ -21,6 +21,12 @@ export function getPermissionMode(): PermissionMode {
21
21
  return currentMode;
22
22
  }
23
23
 
24
+ /** Shift+Tab cycling order: ask → auto → readonly → ask. */
25
+ export function nextPermissionMode(current: PermissionMode): PermissionMode {
26
+ const index = PERMISSION_MODES.indexOf(current);
27
+ return PERMISSION_MODES[(index + 1) % PERMISSION_MODES.length]!;
28
+ }
29
+
24
30
  export function setPermissionMode(mode: PermissionMode): void {
25
31
  if (!PERMISSION_MODES.includes(mode)) {
26
32
  throw new Error(`Unknown permission mode: ${mode}. Valid: ${PERMISSION_MODES.join(', ')}`);
@@ -173,3 +173,37 @@ describe('omitted-only user memory', () => {
173
173
  expect(prompt).toContain('(omitted: huge)');
174
174
  });
175
175
  });
176
+
177
+ describe('web tool guidance', () => {
178
+ test('webSearch 已配置 → How to work 含 web_search 优先于记忆的引导', async () => {
179
+ const configDir = await fs.mkdtemp(path.join(tmpdir(), 'transcode-prompt-web-'));
180
+ process.env.TRANSCODE_CONFIG_PATH = path.join(configDir, 'config.json');
181
+ try {
182
+ writeFileSync(
183
+ path.join(configDir, 'config.json'),
184
+ JSON.stringify({ webSearch: { provider: 'tavily', apiKey: 'tvly-x' } }),
185
+ );
186
+ const prompt = buildSystemPrompt({ cwd: '/tmp', projectFiles: [] });
187
+ expect(prompt).toContain('web_search');
188
+ expect(prompt).toContain('web_fetch');
189
+ expect(prompt.toLowerCase()).toContain('outside this workspace');
190
+ } finally {
191
+ delete process.env.TRANSCODE_CONFIG_PATH;
192
+ await fs.rm(configDir, { recursive: true, force: true });
193
+ }
194
+ });
195
+
196
+ test('未配置 → 不提 web_search(与工具隐藏一致),仍提 web_fetch', () => {
197
+ const configDir = mkdtempSync(path.join(tmpdir(), 'transcode-prompt-noweb-'));
198
+ process.env.TRANSCODE_CONFIG_PATH = path.join(configDir, 'empty.json');
199
+ try {
200
+ writeFileSync(path.join(configDir, 'empty.json'), '{}');
201
+ const prompt = buildSystemPrompt({ cwd: '/tmp', projectFiles: [] });
202
+ expect(prompt).not.toContain('web_search');
203
+ expect(prompt).toContain('web_fetch');
204
+ } finally {
205
+ delete process.env.TRANSCODE_CONFIG_PATH;
206
+ rmSync(configDir, { recursive: true, force: true });
207
+ }
208
+ });
209
+ });
@@ -2,6 +2,8 @@ import { promises as fs } from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { getRouting } from '../provider/provider.js';
4
4
  import { loadUserMemory, renderMemoryIndex, type UserMemory } from './memory.js';
5
+ import { loadConfig } from '../config.js';
6
+ import { normalizeWebSearchConfig } from '../provider/web-search.js';
5
7
 
6
8
  const CONTEXT_FILES = ['TRANS.md', 'AGENTS.md', 'CLAUDE.md', 'TRANSCODE.md', '.transcode/AGENTS.md'];
7
9
  const MAX_CONTEXT_CHARS = 40_000;
@@ -36,6 +38,26 @@ async function readOptional(file: string): Promise<string | null> {
36
38
  }
37
39
  }
38
40
 
41
+ /**
42
+ * Web tool guidance, gated like the tools themselves: web_search is only
43
+ * advertised when configured (the tool is hidden from the table otherwise);
44
+ * web_fetch is always available.
45
+ */
46
+ function webToolLines(): string[] {
47
+ const searchConfigured = normalizeWebSearchConfig(loadConfig().webSearch) !== null;
48
+ return [
49
+ ...(searchConfigured
50
+ ? [
51
+ '- Questions about anything outside this workspace — unfamiliar terms, latest ' +
52
+ 'releases, current documentation — search the web with web_search BEFORE answering ' +
53
+ 'from memory; read a promising result with web_fetch.',
54
+ ]
55
+ : []),
56
+ '- Use web_fetch to read a specific URL (docs, API responses, raw files) when the user ' +
57
+ 'points at one.',
58
+ ];
59
+ }
60
+
39
61
  /** Advertises configured role routing so the model knows it can delegate. */
40
62
  function roleRoutingLines(): string[] {
41
63
  const entries = Object.entries(getRouting()).filter(([role]) => role !== 'default');
@@ -116,6 +138,7 @@ export function buildSystemPrompt(
116
138
  'then state a short plan and write the result. Exploration is not the deliverable.',
117
139
  '- Multi-step tasks (3+ steps): create the list with todo_write first, keep exactly one ' +
118
140
  'step in_progress, and mark steps completed as you finish them.',
141
+ ...webToolLines(),
119
142
  ...roleRoutingLines(),
120
143
  '- Reporting counts (tests, checks, matches): grep -c counts matching LINES, including ' +
121
144
  'definitions like `def check(` — read the actual item list instead of trusting a raw count.',
@@ -27,7 +27,7 @@ import {
27
27
  } from '../provider/web-search.js';
28
28
  import { runAgentLoop, type PermissionRequest } from '../agent/loop.js';
29
29
  import { createToolSession } from '../agent/tools/index.js';
30
- import { getPermissionMode } from '../agent/permission.js';
30
+ import { getPermissionMode, nextPermissionMode, setPermissionMode } from '../agent/permission.js';
31
31
  import {
32
32
  buildSessionRecord,
33
33
  generateTitle,
@@ -1203,6 +1203,16 @@ export default function REPL({ ctx, updateNotice }: REPLProps) {
1203
1203
  return;
1204
1204
  }
1205
1205
 
1206
+ // Shift+Tab cycles permission modes (ask → auto → readonly). Runs FIRST:
1207
+ // ink reports shift+tab as a bare {tab} key (raw input '[Z'), so every
1208
+ // later tab branch (popup completion, slash completion) would misfire.
1209
+ if (key.tab && (ch === '[Z' || key.shift) && phase === 'idle') {
1210
+ const next = nextPermissionMode(getPermissionMode());
1211
+ setPermissionMode(next);
1212
+ addHistory({ input: '', output: `权限模式 → ${next}` });
1213
+ return;
1214
+ }
1215
+
1206
1216
  // @-mention popup navigation and completion (takes precedence over
1207
1217
  // history navigation, tab completion and submission).
1208
1218
  if (phase === 'idle' && mentionActive && mentionCandidates.length > 0) {
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  // Auto-generated from package.json by scripts/sync-version.ts (npm version hook)
2
- export const VERSION = '0.10.0';
2
+ export const VERSION = '0.10.1';