berget 2.2.11 → 2.2.12

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/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "berget",
3
- "version": "2.2.11",
3
+ "version": "2.2.12",
4
4
  "main": "dist/index.js",
5
5
  "bin": {
6
6
  "berget": "dist/index.js"
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const vitest_1 = require("vitest");
4
4
  const errors_1 = require("../errors");
5
- const setup_1 = require("../setup");
5
+ const init_1 = require("../init");
6
6
  const fake_api_key_service_1 = require("./fake-api-key-service");
7
7
  const fake_auth_service_1 = require("./fake-auth-service");
8
8
  const fake_command_runner_1 = require("./fake-command-runner");
@@ -35,7 +35,7 @@ function makeJwt(payload) {
35
35
  const body = base64urlEncode(JSON.stringify(payload));
36
36
  return `${header}.${body}.signature`;
37
37
  }
38
- (0, vitest_1.describe)('runSetup', () => {
38
+ (0, vitest_1.describe)('runInit', () => {
39
39
  (0, vitest_1.describe)('happy path', () => {
40
40
  (0, vitest_1.it)('sets up opencode project without existing config', async () => {
41
41
  const deps = makeDeps({
@@ -46,12 +46,12 @@ function makeJwt(payload) {
46
46
  (0, fake_prompter_1.multiselect)([]), // No agents selected
47
47
  ]),
48
48
  });
49
- await (0, setup_1.runSetup)(deps);
49
+ await (0, init_1.runInit)(deps);
50
50
  const files = deps.files;
51
51
  const written = files.getWrittenFiles();
52
52
  (0, vitest_1.expect)(written.has('/home/user/project/opencode.json')).toBe(true);
53
53
  const config = JSON.parse(written.get('/home/user/project/opencode.json'));
54
- (0, vitest_1.expect)(config.plugin).toContain('@bergetai/opencode-auth');
54
+ (0, vitest_1.expect)(config.plugin).toContain('@bergetai/opencode-auth@1.0.21');
55
55
  });
56
56
  (0, vitest_1.it)('sets up opencode globally without existing config', async () => {
57
57
  const deps = makeDeps({
@@ -62,7 +62,7 @@ function makeJwt(payload) {
62
62
  (0, fake_prompter_1.multiselect)([]), // No agents selected
63
63
  ]),
64
64
  });
65
- await (0, setup_1.runSetup)(deps);
65
+ await (0, init_1.runInit)(deps);
66
66
  const files = deps.files;
67
67
  const written = files.getWrittenFiles();
68
68
  (0, vitest_1.expect)(written.has('/home/user/.config/opencode/opencode.json')).toBe(true);
@@ -80,7 +80,7 @@ function makeJwt(payload) {
80
80
  (0, fake_prompter_1.confirm)(true, 'Create'),
81
81
  ]),
82
82
  });
83
- await (0, setup_1.runSetup)(deps);
83
+ await (0, init_1.runInit)(deps);
84
84
  const commands = deps.commands;
85
85
  (0, vitest_1.expect)(commands.calls.length).toBeGreaterThan(0);
86
86
  const installCall = commands.calls.find((c) => c.command === 'pi');
@@ -97,7 +97,7 @@ function makeJwt(payload) {
97
97
  (0, fake_prompter_1.confirm)(false, 'Set up an agent for Pi?'),
98
98
  ]),
99
99
  });
100
- await (0, setup_1.runSetup)(deps);
100
+ await (0, init_1.runInit)(deps);
101
101
  const files = deps.files;
102
102
  const written = files.getWrittenFiles();
103
103
  // Should not create any agent files
@@ -113,7 +113,7 @@ function makeJwt(payload) {
113
113
  prompter: new fake_prompter_1.FakePrompter([(0, fake_prompter_1.select)('opencode'), (0, fake_prompter_1.select)('project')]),
114
114
  });
115
115
  // Simulate opencode not being installed
116
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.PrerequisiteError);
116
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.PrerequisiteError);
117
117
  });
118
118
  });
119
119
  (0, vitest_1.describe)('cancellation', () => {
@@ -121,7 +121,7 @@ function makeJwt(payload) {
121
121
  const deps = makeDeps({
122
122
  prompter: new fake_prompter_1.FakePrompter([(0, fake_prompter_1.select)(fake_prompter_1.CANCEL)]),
123
123
  });
124
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
124
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
125
125
  });
126
126
  (0, vitest_1.it)('throws CancelledError when user cancels at write confirmation', async () => {
127
127
  const deps = makeDeps({
@@ -131,7 +131,7 @@ function makeJwt(payload) {
131
131
  (0, fake_prompter_1.confirm)(false, 'Create'),
132
132
  ]),
133
133
  });
134
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
134
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
135
135
  });
136
136
  (0, vitest_1.it)('throws CancelledError when user cancels at agent write confirmation (opencode)', async () => {
137
137
  const deps = makeDeps({
@@ -143,7 +143,7 @@ function makeJwt(payload) {
143
143
  (0, fake_prompter_1.confirm)(false, 'agent'),
144
144
  ]),
145
145
  });
146
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
146
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
147
147
  });
148
148
  (0, vitest_1.it)('throws CancelledError when user cancels at agent write confirmation (pi)', async () => {
149
149
  const deps = makeDeps({
@@ -156,7 +156,7 @@ function makeJwt(payload) {
156
156
  (0, fake_prompter_1.confirm)(false, /Create|Overwrite/),
157
157
  ]),
158
158
  });
159
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
159
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.CancelledError);
160
160
  });
161
161
  });
162
162
  (0, vitest_1.describe)('file operations', () => {
@@ -174,12 +174,12 @@ function makeJwt(payload) {
174
174
  customField: 'should-preserve',
175
175
  plugin: ['other-plugin'],
176
176
  }));
177
- await (0, setup_1.runSetup)(deps);
177
+ await (0, init_1.runInit)(deps);
178
178
  const written = files.getWrittenFiles();
179
179
  const config = JSON.parse(written.get('/home/user/project/opencode.json'));
180
180
  (0, vitest_1.expect)(config.customField).toBe('should-preserve');
181
181
  (0, vitest_1.expect)(config.plugin).toContain('other-plugin');
182
- (0, vitest_1.expect)(config.plugin).toContain('@bergetai/opencode-auth');
182
+ (0, vitest_1.expect)(config.plugin).toContain('@bergetai/opencode-auth@1.0.21');
183
183
  });
184
184
  (0, vitest_1.it)('preserves jsonc comments when updating', async () => {
185
185
  const deps = makeDeps({
@@ -197,7 +197,7 @@ function makeJwt(payload) {
197
197
  /* block comment explaining plugin */
198
198
  "plugin": ["other-plugin"]
199
199
  }`);
200
- await (0, setup_1.runSetup)(deps);
200
+ await (0, init_1.runInit)(deps);
201
201
  const written = files.getWrittenFiles();
202
202
  const content = written.get('/home/user/project/opencode.jsonc');
203
203
  (0, vitest_1.expect)(content).toContain('// This is my custom config');
@@ -213,14 +213,14 @@ function makeJwt(payload) {
213
213
  // Already has the exact same plugin version
214
214
  files.seed('/home/user/project/opencode.json', JSON.stringify({
215
215
  $schema: 'https://opencode.ai/config.json',
216
- plugin: ['@bergetai/opencode-auth'],
216
+ plugin: ['@bergetai/opencode-auth@1.0.21'],
217
217
  }, null, 2) + '\n');
218
- await (0, setup_1.runSetup)(deps);
218
+ await (0, init_1.runInit)(deps);
219
219
  // Check that no write happened — content should be unchanged
220
220
  const written = files.getWrittenFiles();
221
221
  const content = written.get('/home/user/project/opencode.json');
222
222
  const config = JSON.parse(content);
223
- (0, vitest_1.expect)(config.plugin).toEqual(['@bergetai/opencode-auth']);
223
+ (0, vitest_1.expect)(config.plugin).toEqual(['@bergetai/opencode-auth@1.0.21']);
224
224
  (0, vitest_1.expect)(content).toContain('$schema');
225
225
  });
226
226
  (0, vitest_1.it)('preserves existing Pi settings when setting defaultProvider', async () => {
@@ -239,7 +239,7 @@ function makeJwt(payload) {
239
239
  anotherSetting: true,
240
240
  existingKey: 'should-preserve',
241
241
  }));
242
- await (0, setup_1.runSetup)(deps);
242
+ await (0, init_1.runInit)(deps);
243
243
  const written = files.getWrittenFiles();
244
244
  const settings = JSON.parse(written.get('/home/user/project/.pi/settings.json'));
245
245
  (0, vitest_1.expect)(settings.existingKey).toBe('should-preserve');
@@ -255,7 +255,7 @@ function makeJwt(payload) {
255
255
  (0, fake_prompter_1.multiselect)([]),
256
256
  ]),
257
257
  });
258
- await (0, setup_1.runSetup)(deps);
258
+ await (0, init_1.runInit)(deps);
259
259
  const files = deps.files;
260
260
  const written = files.getWrittenFiles();
261
261
  (0, vitest_1.expect)(written.has('/home/user/.config/opencode/opencode.json')).toBe(true);
@@ -273,7 +273,7 @@ function makeJwt(payload) {
273
273
  (0, fake_prompter_1.confirm)(true, 'Create'),
274
274
  ]),
275
275
  });
276
- await (0, setup_1.runSetup)(deps);
276
+ await (0, init_1.runInit)(deps);
277
277
  const commands = deps.commands;
278
278
  const installCall = commands.calls.find((c) => c.command === 'pi');
279
279
  (0, vitest_1.expect)(installCall?.args).toContain('npm:@bergetai/pi-provider');
@@ -288,7 +288,7 @@ function makeJwt(payload) {
288
288
  .handle('pi install', new Error('npm error')),
289
289
  prompter: new fake_prompter_1.FakePrompter([(0, fake_prompter_1.select)('pi'), (0, fake_prompter_1.select)('project')]),
290
290
  });
291
- await (0, vitest_1.expect)((0, setup_1.runSetup)(deps)).rejects.toBeInstanceOf(errors_1.CommandFailedError);
291
+ await (0, vitest_1.expect)((0, init_1.runInit)(deps)).rejects.toBeInstanceOf(errors_1.CommandFailedError);
292
292
  });
293
293
  });
294
294
  (0, vitest_1.describe)('auth integration', () => {
@@ -305,7 +305,7 @@ function makeJwt(payload) {
305
305
  (0, fake_prompter_1.multiselect)([]),
306
306
  ]),
307
307
  });
308
- await (0, setup_1.runSetup)(deps);
308
+ await (0, init_1.runInit)(deps);
309
309
  const prompter = deps.prompter;
310
310
  const notes = prompter.calls.filter((c) => c.method === 'note');
311
311
  const lastNote = notes.at(-1);
@@ -325,7 +325,7 @@ function makeJwt(payload) {
325
325
  (0, fake_prompter_1.confirm)(true, 'Create'),
326
326
  ]),
327
327
  });
328
- await (0, setup_1.runSetup)(deps);
328
+ await (0, init_1.runInit)(deps);
329
329
  const prompter = deps.prompter;
330
330
  const notes = prompter.calls.filter((c) => c.method === 'note');
331
331
  const lastNote = notes.at(-1);
@@ -346,7 +346,7 @@ function makeJwt(payload) {
346
346
  (0, fake_prompter_1.confirm)(true, 'Create'),
347
347
  ]),
348
348
  });
349
- await (0, setup_1.runSetup)(deps);
349
+ await (0, init_1.runInit)(deps);
350
350
  const written = files.getWrittenFiles();
351
351
  (0, vitest_1.expect)(written.has('/home/user/.pi/agent/auth.json')).toBe(true);
352
352
  const parsed = JSON.parse(written.get('/home/user/.pi/agent/auth.json'));
@@ -370,7 +370,7 @@ function makeJwt(payload) {
370
370
  (0, fake_prompter_1.multiselect)([]),
371
371
  ]),
372
372
  });
373
- await (0, setup_1.runSetup)(deps);
373
+ await (0, init_1.runInit)(deps);
374
374
  const written = files.getWrittenFiles();
375
375
  const parsed = JSON.parse(written.get('/home/user/.local/share/opencode/auth.json'));
376
376
  (0, vitest_1.expect)(parsed.berget.type).toBe('oauth');
@@ -387,7 +387,7 @@ function makeJwt(payload) {
387
387
  (0, fake_prompter_1.confirm)(true, 'agent'),
388
388
  ]),
389
389
  });
390
- await (0, setup_1.runSetup)(deps);
390
+ await (0, init_1.runInit)(deps);
391
391
  const files = deps.files;
392
392
  const written = files.getWrittenFiles();
393
393
  (0, vitest_1.expect)(written.has('/home/user/project/.opencode/agents/backend.md')).toBe(true);
@@ -402,7 +402,7 @@ function makeJwt(payload) {
402
402
  (0, fake_prompter_1.multiselect)([]),
403
403
  ]),
404
404
  });
405
- await (0, setup_1.runSetup)(deps);
405
+ await (0, init_1.runInit)(deps);
406
406
  const files = deps.files;
407
407
  const written = files.getWrittenFiles();
408
408
  for (const path of written.keys()) {
@@ -419,7 +419,7 @@ function makeJwt(payload) {
419
419
  (0, fake_prompter_1.confirm)(true, 'agent'),
420
420
  ]),
421
421
  });
422
- await (0, setup_1.runSetup)(deps);
422
+ await (0, init_1.runInit)(deps);
423
423
  const files = deps.files;
424
424
  const written = files.getWrittenFiles();
425
425
  (0, vitest_1.expect)(written.has('/home/user/.config/opencode/agents/fullstack.md')).toBe(true);
@@ -435,7 +435,7 @@ function makeJwt(payload) {
435
435
  (0, fake_prompter_1.confirm)(true, 'Create'),
436
436
  ]),
437
437
  });
438
- await (0, setup_1.runSetup)(deps);
438
+ await (0, init_1.runInit)(deps);
439
439
  const files = deps.files;
440
440
  const written = files.getWrittenFiles();
441
441
  (0, vitest_1.expect)(written.has('/home/user/project/.pi/SYSTEM.md')).toBe(true);
@@ -451,7 +451,7 @@ function makeJwt(payload) {
451
451
  (0, fake_prompter_1.confirm)(true, 'Create'),
452
452
  ]),
453
453
  });
454
- await (0, setup_1.runSetup)(deps);
454
+ await (0, init_1.runInit)(deps);
455
455
  const files = deps.files;
456
456
  const written = files.getWrittenFiles();
457
457
  (0, vitest_1.expect)(written.has('/home/user/.pi/agent/SYSTEM.md')).toBe(true);
@@ -467,7 +467,7 @@ function makeJwt(payload) {
467
467
  ]),
468
468
  });
469
469
  // First run writes the files
470
- await (0, setup_1.runSetup)(deps);
470
+ await (0, init_1.runInit)(deps);
471
471
  const files = deps.files;
472
472
  const firstBackend = files
473
473
  .getWrittenFiles()
@@ -485,7 +485,7 @@ function makeJwt(payload) {
485
485
  (0, fake_prompter_1.confirm)(true, 'Write'),
486
486
  ]),
487
487
  });
488
- await (0, setup_1.runSetup)(deps2);
488
+ await (0, init_1.runInit)(deps2);
489
489
  // Content should be unchanged
490
490
  (0, vitest_1.expect)(files.getWrittenFiles().get('/home/user/project/.opencode/agents/backend.md')).toBe(firstBackend);
491
491
  (0, vitest_1.expect)(files.getWrittenFiles().get('/home/user/project/.opencode/agents/frontend.md')).toBe(firstFrontend);
@@ -504,7 +504,7 @@ function makeJwt(payload) {
504
504
  (0, fake_prompter_1.confirm)(true, 'SYSTEM.md already exists'),
505
505
  ]),
506
506
  });
507
- await (0, setup_1.runSetup)(deps);
507
+ await (0, init_1.runInit)(deps);
508
508
  const written = files.getWrittenFiles();
509
509
  const content = written.get('/home/user/project/.pi/SYSTEM.md');
510
510
  (0, vitest_1.expect)(content).not.toBe('old agent content');
@@ -38,7 +38,7 @@ async function configureAuth(deps, tool) {
38
38
  const loginResult = await authService.loginInteractive();
39
39
  if (!loginResult.success) {
40
40
  s.stop('Login failed.');
41
- prompter.note(`${loginResult.error || 'Login timed out or was cancelled.'}\n\nPlease run \`berget auth login\` manually, then run \`berget code setup\` again.`, 'Authentication Failed');
41
+ prompter.note(`${loginResult.error || 'Login timed out or was cancelled.'}\n\nPlease run \`berget auth login\` manually, then run \`berget code init\` again.`, 'Authentication Failed');
42
42
  return { authenticated: false };
43
43
  }
44
44
  s.stop('Successfully logged in to Berget.');
@@ -88,7 +88,7 @@ async function configureAuth(deps, tool) {
88
88
  s.start('Creating API key...');
89
89
  try {
90
90
  const { key } = await apiKeyService.create({
91
- description: 'Created by berget code setup',
91
+ description: 'Created by berget code init',
92
92
  name: `${tool === 'opencode' ? 'OpenCode' : 'Pi'} (created by berget CLI)`,
93
93
  });
94
94
  await syncApiKeyToTool(files, homeDir, tool, key);
@@ -111,7 +111,7 @@ async function configureAuth(deps, tool) {
111
111
  s.start('Creating API key...');
112
112
  try {
113
113
  const { key } = await apiKeyService.create({
114
- description: 'Created by berget code setup',
114
+ description: 'Created by berget code init',
115
115
  name: `${tool === 'opencode' ? 'OpenCode' : 'Pi'} (created by berget CLI)`,
116
116
  });
117
117
  await syncApiKeyToTool(files, homeDir, tool, key);
@@ -22,8 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.runSetupCommand = exports.runSetup = void 0;
29
+ exports.runInitCommand = exports.runInit = void 0;
30
+ const chalk_1 = __importDefault(require("chalk"));
27
31
  const jsonc_parser_1 = require("jsonc-parser");
28
32
  const os = __importStar(require("node:os"));
29
33
  const index_js_1 = require("../../agents/index.js");
@@ -34,13 +38,14 @@ const fs_file_store_js_1 = require("./adapters/fs-file-store.js");
34
38
  const spawn_command_runner_js_1 = require("./adapters/spawn-command-runner.js");
35
39
  const auth_sync_js_1 = require("./auth-sync.js");
36
40
  const errors_1 = require("./errors");
37
- const OPENCODE_PLUGIN = '@bergetai/opencode-auth';
41
+ const OPENCODE_PLUGIN = '@bergetai/opencode-auth@1.0.21';
38
42
  const PI_PROVIDER = 'npm:@bergetai/pi-provider';
39
43
  const OPENCODE_PLUGIN_NAME = '@bergetai/opencode-auth';
40
44
  const PI_PROVIDER_NAME = '@bergetai/pi-provider';
41
- async function runSetup(deps) {
45
+ async function runInit(deps) {
42
46
  const { apiKeyService, authService, commands, cwd, files, homeDir, prompter } = deps;
43
- prompter.intro('\uD83D\uDD27 Berget Code Setup');
47
+ prompter.intro(`${chalk_1.default.bgGreen.black(' berget code ')}`);
48
+ prompter.note(`Ask questions and report bugs on our GitHub repository:\n\n${chalk_1.default.cyan.underline('https://github.com/berget-ai/cli')}`, 'Need help?');
44
49
  const ocState = await getOpencodeState(files, homeDir, cwd);
45
50
  const piState = await getPiState(files, homeDir, cwd);
46
51
  const tool = await prompter.select({
@@ -106,13 +111,13 @@ async function runSetup(deps) {
106
111
  prompter.note(`Next steps:\n\n1. Restart Pi or run /reload\n2. Type: /login\n3. Choose your auth method:\n • "Use a subscription" → Berget AI\n • (or set BERGET_API_KEY env var)\n4. Select model: /model\n\nFor more information, see official docs:\n\nhttps://github.com/berget-ai/pi-provider`, 'Successfully configured Berget AI for Pi');
107
112
  }
108
113
  }
109
- prompter.outro('Setup complete!');
114
+ prompter.outro('Initialization complete!');
110
115
  }
111
- exports.runSetup = runSetup;
116
+ exports.runInit = runInit;
112
117
  // ─── OpenCode ────────────────────────────────────────────────────────────────
113
- async function runSetupCommand() {
118
+ async function runInitCommand() {
114
119
  try {
115
- await runSetup({
120
+ await runInit({
116
121
  apiKeyService: api_key_service_js_1.ApiKeyService.getInstance(),
117
122
  authService: auth_service_js_1.AuthService.getInstance(),
118
123
  commands: new spawn_command_runner_js_1.SpawnCommandRunner(),
@@ -138,25 +143,8 @@ async function runSetupCommand() {
138
143
  throw error;
139
144
  }
140
145
  }
141
- exports.runSetupCommand = runSetupCommand;
142
- // ─── Pi ────────────────────────────────────────────────────────────────────────
143
- function generateDiff(oldText, newText, filePath) {
144
- const oldLines = oldText.split('\n');
145
- const newLines = newText.split('\n');
146
- let result = `--- ${filePath}\n+++ ${filePath}\n`;
147
- const maxLength = Math.max(oldLines.length, newLines.length);
148
- for (let index = 0; index < maxLength; index++) {
149
- const oldLine = oldLines[index];
150
- const newLine = newLines[index];
151
- if (oldLine !== newLine) {
152
- if (oldLine !== undefined)
153
- result += `- ${oldLine}\n`;
154
- if (newLine !== undefined)
155
- result += `+ ${newLine}\n`;
156
- }
157
- }
158
- return result.trimEnd();
159
- }
146
+ exports.runInitCommand = runInitCommand;
147
+ // ─── OpenCode Config Helpers ──────────────────────────────────────────────────
160
148
  function generateModifiedContent(existingContent, configPath) {
161
149
  if (configPath.endsWith('.jsonc')) {
162
150
  const content = existingContent || '{}';
@@ -318,10 +306,10 @@ async function setupOpenCode(deps) {
318
306
  return;
319
307
  }
320
308
  if (existingContent) {
321
- prompter.note(generateDiff(existingContent, newContent, configPath), 'Changes to be written');
309
+ prompter.note(`OpenCode config will be updated at:\n ${configPath}`, 'Config update');
322
310
  }
323
311
  else {
324
- prompter.note(`New config at ${configPath}:\n\n${newContent}`, 'Config preview');
312
+ prompter.note(`OpenCode config will be created at:\n ${configPath}`, 'Config update');
325
313
  }
326
314
  const shouldWrite = await prompter.confirm({
327
315
  initialValue: true,