@trans-ai/trans-code 0.1.2 → 0.1.4

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.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "AI-powered multi-model coding CLI",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -26,7 +26,8 @@
26
26
  "test:acp": "bun scripts/acp-smoke.ts",
27
27
  "test:acp:openai": "bun scripts/acp-openai-smoke.ts",
28
28
  "test:acp:real": "bun scripts/acp-real-smoke.ts",
29
- "model:check": "bun scripts/model-check.ts"
29
+ "model:check": "bun scripts/model-check.ts",
30
+ "version": "bun scripts/sync-version.ts"
30
31
  },
31
32
  "dependencies": {
32
33
  "ink": "^5.1.0",
@@ -117,7 +117,11 @@ export class AcpSession {
117
117
  const signal = this.abortController.signal;
118
118
 
119
119
  try {
120
- const systemPrompt = buildSystemPrompt(await loadProjectContext(this.cwd));
120
+ const provider =
121
+ process.env.TRANSCODE_MOCK === '1' ? undefined : createModel(this.modelSpec);
122
+ const systemPrompt = buildSystemPrompt(await loadProjectContext(this.cwd), {
123
+ modelName: provider?.config.name,
124
+ });
121
125
  if (this.messages[0]?.getType() === 'system') {
122
126
  this.messages[0] = new SystemMessage(systemPrompt);
123
127
  } else {
@@ -126,8 +130,6 @@ export class AcpSession {
126
130
 
127
131
  this.messages.push(new HumanMessage(text));
128
132
 
129
- const provider =
130
- process.env.TRANSCODE_MOCK === '1' ? undefined : createModel(this.modelSpec);
131
133
  const result = await runAgentLoop({
132
134
  model: provider?.model,
133
135
  cwd: this.cwd,
@@ -53,10 +53,19 @@ export async function loadProjectContext(cwd: string): Promise<ProjectContext> {
53
53
  return { cwd, gitBranch: await gitBranch(cwd), projectFiles };
54
54
  }
55
55
 
56
- export function buildSystemPrompt(context: ProjectContext): string {
56
+ export function buildSystemPrompt(
57
+ context: ProjectContext,
58
+ options?: { modelName?: string },
59
+ ): string {
60
+ const poweredBy = options?.modelName ? `, powered by the ${options.modelName} model` : '';
57
61
  const sections: string[] = [
58
- 'You are transcode, a coding agent running as a local CLI agent in a terminal.',
62
+ `You are transcode${poweredBy}, a coding agent running as a local CLI agent in a terminal.`,
59
63
  'You work directly in the user-provided workspace and can read, search, edit and execute code.',
64
+ ...(options?.modelName
65
+ ? [
66
+ `When asked which model or company you are, answer that you are transcode running on ${options.modelName}. Never claim to be a different model or company.`,
67
+ ]
68
+ : []),
60
69
  '',
61
70
  '## Environment',
62
71
  `- Workspace: ${context.cwd}`,
@@ -161,8 +161,8 @@ const readFileTool: AgentTool = {
161
161
  isMutating: false,
162
162
  schema: z.object({
163
163
  path: z.string().describe('File path, relative to the workspace root'),
164
- offset: z.number().int().min(1).optional().describe('First line to read (1-based)'),
165
- limit: z.number().int().min(1).max(5000).optional().describe('Maximum number of lines'),
164
+ offset: z.number().int().min(1).nullable().optional().describe('First line to read (1-based)'),
165
+ limit: z.number().int().min(1).max(5000).nullable().optional().describe('Maximum number of lines'),
166
166
  }),
167
167
  title: (input) => `read: ${String(input.path ?? '')}`,
168
168
  async execute(input, ctx) {
@@ -232,7 +232,7 @@ const editFileTool: AgentTool = {
232
232
  path: z.string().describe('File path, relative to the workspace root'),
233
233
  old_string: z.string().describe('Exact text to replace'),
234
234
  new_string: z.string().describe('Replacement text'),
235
- replace_all: z.boolean().optional().describe('Replace every occurrence'),
235
+ replace_all: z.boolean().nullable().optional().describe('Replace every occurrence'),
236
236
  }),
237
237
  title: (input) => `patch: ${String(input.path ?? '')}`,
238
238
  async execute(input, ctx) {
@@ -274,7 +274,7 @@ const globTool: AgentTool = {
274
274
  isMutating: false,
275
275
  schema: z.object({
276
276
  pattern: z.string().describe('Glob pattern, matched against workspace-relative paths'),
277
- path: z.string().optional().describe('Directory to search in (default: workspace root)'),
277
+ path: z.string().nullable().optional().describe('Directory to search in (default: workspace root)'),
278
278
  }),
279
279
  title: (input) => `search: ${String(input.pattern ?? '')}`,
280
280
  async execute(input, ctx) {
@@ -309,9 +309,9 @@ const grepTool: AgentTool = {
309
309
  isMutating: false,
310
310
  schema: z.object({
311
311
  pattern: z.string().describe('JavaScript regular expression to search for'),
312
- path: z.string().optional().describe('Directory or file to search (default: workspace root)'),
313
- include: z.string().optional().describe('Glob that file paths must match'),
314
- ignore_case: z.boolean().optional().describe('Case-insensitive search'),
312
+ path: z.string().nullable().optional().describe('Directory or file to search (default: workspace root)'),
313
+ include: z.string().nullable().optional().describe('Glob that file paths must match'),
314
+ ignore_case: z.boolean().nullable().optional().describe('Case-insensitive search'),
315
315
  }),
316
316
  title: (input) => `search: ${String(input.pattern ?? '')}`,
317
317
  async execute(input, ctx) {
@@ -369,8 +369,8 @@ const bashTool: AgentTool = {
369
369
  isMutating: true,
370
370
  schema: z.object({
371
371
  command: z.string().describe('Shell command to run'),
372
- timeout_ms: z.number().int().min(1000).max(600_000).optional().describe('Timeout in ms'),
373
- description: z.string().optional().describe('Short description of what the command does'),
372
+ timeout_ms: z.number().int().min(1000).max(600_000).nullable().optional().describe('Timeout in ms'),
373
+ description: z.string().nullable().optional().describe('Short description of what the command does'),
374
374
  }),
375
375
  title: (input) => {
376
376
  const command = String(input.command ?? '');
package/src/config.ts ADDED
@@ -0,0 +1,24 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { homedir } from 'node:os';
3
+ import { join } from 'node:path';
4
+
5
+ export interface TranscodeConfig {
6
+ model?: string;
7
+ apiKeys?: Record<string, string>;
8
+ }
9
+
10
+ const CONFIG_PATH = join(homedir(), '.transcode.json');
11
+
12
+ export function loadConfig(): TranscodeConfig {
13
+ try {
14
+ const parsed = JSON.parse(readFileSync(CONFIG_PATH, 'utf8'));
15
+ if (parsed && typeof parsed === 'object') return parsed as TranscodeConfig;
16
+ } catch {
17
+ // missing or invalid — treat as empty
18
+ }
19
+ return {};
20
+ }
21
+
22
+ export function saveConfig(config: TranscodeConfig): void {
23
+ writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2) + '\n');
24
+ }
package/src/main.tsx CHANGED
@@ -1,11 +1,11 @@
1
1
  import { render, Box, Text } from 'ink';
2
2
  import { useState } from 'react';
3
- import { envModelLabel, getAvailableModels, type ModelId } from './provider/provider.js';
3
+ import { envModelLabel, getAvailableModels, preferredModelId, type ModelId } from './provider/provider.js';
4
4
  import { type CommandContext } from './commands.js';
5
5
  import REPL from './screens/REPL.js';
6
6
  import { createKeyedStdin } from './tui/keyed-stdin.js';
7
7
  import { VERSION } from './version.js';
8
- const DEFAULT_MODEL: ModelId = 'opus';
8
+ const DEFAULT_MODEL: ModelId = preferredModelId() ?? 'opus';
9
9
 
10
10
  function Banner({ modelId, cwd, envLabel }: { modelId: ModelId; cwd: string; envLabel?: string }) {
11
11
  const models = getAvailableModels();
@@ -50,7 +50,8 @@ function App() {
50
50
 
51
51
  return (
52
52
  <Box flexDirection="column">
53
- <Banner modelId={modelId} cwd={cwd} envLabel={envModelLabel()} />
53
+ {/* A saved model choice (from the models flow) wins over the env label */}
54
+ <Banner modelId={modelId} cwd={cwd} envLabel={preferredModelId() ? undefined : envModelLabel()} />
54
55
  <REPL ctx={ctx} />
55
56
  </Box>
56
57
  );
@@ -1,6 +1,7 @@
1
1
  import { ChatOpenAI } from '@langchain/openai';
2
2
  import { ChatAnthropic } from '@langchain/anthropic';
3
3
  import { BaseChatModel } from '@langchain/core/language_models/chat_models';
4
+ import { loadConfig, saveConfig } from '../config.js';
4
5
 
5
6
  export type ModelId = 'opus' | 'gpt' | 'deepseek' | 'glm' | 'minimax' | 'kimi';
6
7
 
@@ -148,6 +149,12 @@ function defaultModelSpec(): string {
148
149
  const explicit = process.env.TRANSCODE_MODEL?.trim();
149
150
  if (explicit) return explicit;
150
151
 
152
+ // A model saved from the REPL `models` flow (~/.transcode.json) applies
153
+ // everywhere — REPL, ACP (`transcode acp`), and model checks — so an
154
+ // integration host without an explicit model gets the user's choice.
155
+ const preferred = preferredModelId();
156
+ if (preferred) return preferred;
157
+
151
158
  if (anthropicAuthToken() || anthropicGatewayUrl()) {
152
159
  const fable = fableModelName();
153
160
  if (fable) return `anthropic:${fable}`;
@@ -294,7 +301,9 @@ export function envModelLabel(): string | undefined {
294
301
 
295
302
  export function createModel(spec?: string): TransProvider {
296
303
  const resolved = resolveModel(spec);
297
- const apiKey = apiKeyFor(resolved.envKey);
304
+ // Keys entered in the REPL (`models` flow) take precedence over the
305
+ // environment, so switching models in the session actually works.
306
+ const apiKey = registeredApiKey(resolved.id) ?? apiKeyFor(resolved.envKey);
298
307
 
299
308
  if (!apiKey) {
300
309
  throw new Error(
@@ -352,6 +361,8 @@ export function createProviderWithKey(id: ModelId, apiKey: string): TransProvide
352
361
  const config = MODEL_REGISTRY[id];
353
362
  if (!config) throw new Error(`Unknown model: ${id}`);
354
363
 
364
+ registerApiKey(id, apiKey);
365
+
355
366
  const model =
356
367
  config.provider === 'anthropic'
357
368
  ? new ChatAnthropic({
@@ -371,3 +382,35 @@ export function createProviderWithKey(id: ModelId, apiKey: string): TransProvide
371
382
  export function createProvider(id: ModelId): TransProvider {
372
383
  return createModel(id);
373
384
  }
385
+
386
+ // ---- REPL key/model persistence (~/.transcode.json) ----
387
+
388
+ const keyStore = new Map<string, string>(
389
+ Object.entries(loadConfig().apiKeys ?? {}),
390
+ );
391
+
392
+ /** Register an API key for a registry model and persist it to disk. */
393
+ export function registerApiKey(id: ModelId, apiKey: string): void {
394
+ keyStore.set(id, apiKey);
395
+ const cfg = loadConfig();
396
+ cfg.apiKeys = { ...(cfg.apiKeys ?? {}), [id]: apiKey };
397
+ saveConfig(cfg);
398
+ }
399
+
400
+ /** Key registered via the REPL, if any (env vars are the fallback). */
401
+ export function registeredApiKey(id: string): string | undefined {
402
+ return keyStore.get(id);
403
+ }
404
+
405
+ /** Model chosen in the REPL on a previous run, if any. */
406
+ export function preferredModelId(): ModelId | undefined {
407
+ const saved = loadConfig().model;
408
+ return saved && isKnownModelId(saved) ? saved : undefined;
409
+ }
410
+
411
+ /** Persist the REPL's model choice for the next run. */
412
+ export function setPreferredModel(id: ModelId): void {
413
+ const cfg = loadConfig();
414
+ cfg.model = id;
415
+ saveConfig(cfg);
416
+ }
@@ -1,7 +1,7 @@
1
1
  import { Box, Text, useInput, useApp } from 'ink';
2
2
  import { useState, useCallback, useRef } from 'react';
3
3
  import { findCommand, getCommands, type CommandContext } from '../commands.js';
4
- import { getAvailableModels, createProviderWithKey, createProvider, type ModelId } from '../provider/provider.js';
4
+ import { getAvailableModels, createProviderWithKey, createProvider, setPreferredModel, type ModelId } from '../provider/provider.js';
5
5
  import { runAgentLoop, type PermissionRequest } from '../agent/loop.js';
6
6
  import { buildSystemPrompt, loadProjectContext } from '../agent/system-prompt.js';
7
7
  import { HumanMessage, SystemMessage, type BaseMessage } from '@langchain/core/messages';
@@ -103,7 +103,16 @@ export default function REPL({ ctx }: REPLProps) {
103
103
  addHistory({ input: text, output: '' });
104
104
 
105
105
  try {
106
- const systemPrompt = buildSystemPrompt(await loadProjectContext(process.cwd()));
106
+ const provider =
107
+ process.env.TRANSCODE_MOCK === '1'
108
+ ? undefined
109
+ : createProvider(ctx.modelId);
110
+
111
+ const projectContext = await loadProjectContext(process.cwd());
112
+ const systemPrompt = buildSystemPrompt(
113
+ projectContext,
114
+ provider ? { modelName: provider.config.name } : undefined,
115
+ );
107
116
  if (messagesRef.current[0]?.getType() === 'system') {
108
117
  messagesRef.current[0] = new SystemMessage(systemPrompt);
109
118
  } else {
@@ -111,11 +120,6 @@ export default function REPL({ ctx }: REPLProps) {
111
120
  }
112
121
  messagesRef.current.push(new HumanMessage(text));
113
122
 
114
- const provider =
115
- process.env.TRANSCODE_MOCK === '1'
116
- ? undefined
117
- : createProvider(ctx.modelId);
118
-
119
123
  let lastWasTool = false;
120
124
  const result = await runAgentLoop({
121
125
  model: provider?.model,
@@ -174,6 +178,7 @@ export default function REPL({ ctx }: REPLProps) {
174
178
  try {
175
179
  createProviderWithKey(modelId, apiKey);
176
180
  ctx.setModelId(modelId);
181
+ setPreferredModel(modelId);
177
182
  const found = models.find(m => m.id === modelId);
178
183
  addHistory({ input: '••••••••', output: `Switched to ${found?.name ?? modelId}` });
179
184
  } catch {
package/src/version.ts CHANGED
@@ -1 +1,2 @@
1
- export const VERSION = '0.1.0';
1
+ // Auto-generated from package.json by scripts/sync-version.ts (npm version hook)
2
+ export const VERSION = '0.1.4';