glop.dev 0.10.0 → 0.11.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.
Files changed (2) hide show
  1. package/dist/index.js +175 -298
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // src/index.ts
4
- import { Command as Command8 } from "commander";
4
+ import { Command as Command7 } from "commander";
5
5
 
6
- // src/commands/auth.ts
6
+ // src/commands/login.ts
7
7
  import { Command } from "commander";
8
8
 
9
9
  // src/lib/config.ts
@@ -151,21 +151,13 @@ function saveRepoConfig(config) {
151
151
  }
152
152
  function loadConfig() {
153
153
  const global = loadGlobalConfig();
154
- if (!global || Object.keys(global.workspaces).length === 0) return null;
155
- const repoConfig = loadRepoConfig();
156
- const workspaceId = repoConfig?.workspace_id || global.default_workspace || Object.keys(global.workspaces)[0];
157
- if (!workspaceId) return null;
158
- const ws = global.workspaces[workspaceId];
159
- if (!ws) return null;
154
+ if (!global || !global.api_key) return null;
160
155
  return {
161
156
  server_url: global.server_url,
162
- api_key: ws.api_key,
163
- developer_id: ws.developer_id,
157
+ api_key: global.api_key,
158
+ developer_id: global.developer_id,
164
159
  developer_name: global.developer_name,
165
- machine_id: global.machine_id,
166
- workspace_id: workspaceId,
167
- workspace_name: ws.workspace_name,
168
- workspace_slug: ws.workspace_slug
160
+ machine_id: global.machine_id
169
161
  };
170
162
  }
171
163
  function getDefaultServerUrl() {
@@ -223,10 +215,7 @@ function waitForCallback(port) {
223
215
  resolve({
224
216
  api_key: apiKey,
225
217
  developer_id: developerId,
226
- developer_name: developerName,
227
- workspace_id: url.searchParams.get("workspace_id") || void 0,
228
- workspace_name: url.searchParams.get("workspace_name") || void 0,
229
- workspace_slug: url.searchParams.get("workspace_slug") || void 0
218
+ developer_name: developerName
230
219
  });
231
220
  return;
232
221
  }
@@ -254,8 +243,53 @@ h1{margin:0 0 1rem;font-size:1.25rem}</style></head>
254
243
  </html>`;
255
244
  }
256
245
 
257
- // src/commands/auth.ts
258
- var authCommand = new Command("auth").description("Authenticate with a glop server").option("-s, --server <url>", "Server URL").action(async (opts) => {
246
+ // src/commands/login.ts
247
+ import { execSync as execSync2 } from "child_process";
248
+ import fs2 from "fs";
249
+ import path2 from "path";
250
+ import os2 from "os";
251
+ function installGlobalHooks() {
252
+ const claudeDir = path2.join(os2.homedir(), ".claude");
253
+ const settingsFile = path2.join(claudeDir, "settings.json");
254
+ if (!fs2.existsSync(claudeDir)) {
255
+ fs2.mkdirSync(claudeDir, { recursive: true });
256
+ }
257
+ let settings = {};
258
+ if (fs2.existsSync(settingsFile)) {
259
+ try {
260
+ settings = JSON.parse(fs2.readFileSync(settingsFile, "utf-8"));
261
+ } catch {
262
+ }
263
+ }
264
+ const hookHandler = {
265
+ type: "command",
266
+ command: "glop __hook"
267
+ };
268
+ const hookGroup = {
269
+ hooks: [hookHandler]
270
+ };
271
+ const hooks = settings.hooks || {};
272
+ const hookEvents = [
273
+ "PostToolUse",
274
+ "PermissionRequest",
275
+ "Stop",
276
+ "UserPromptSubmit",
277
+ "SessionStart",
278
+ "SessionEnd"
279
+ ];
280
+ for (const event of hookEvents) {
281
+ const existing = (hooks[event] || []).filter((group) => {
282
+ const groupHooks = group?.hooks || [];
283
+ return !groupHooks.some(
284
+ (h) => h?.command?.includes("glop __hook")
285
+ );
286
+ });
287
+ hooks[event] = [...existing, hookGroup];
288
+ }
289
+ settings.hooks = hooks;
290
+ fs2.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
291
+ }
292
+ var loginCommand = new Command("login").description("Authenticate with a glop server").option("-s, --server <url>", "Server URL").action(async (opts) => {
259
293
  const serverUrl = (opts.server || getDefaultServerUrl()).replace(/\/+$/, "");
260
294
  const port = await findOpenPort();
261
295
  const machineId = getMachineId();
@@ -269,109 +303,67 @@ var authCommand = new Command("auth").description("Authenticate with a glop serv
269
303
  console.log("Waiting for authorization...");
270
304
  openBrowser(authUrl);
271
305
  const result = await waitForCallback(port);
272
- const existing = loadGlobalConfig();
273
- const globalConfig = existing || {
306
+ const globalConfig = {
274
307
  server_url: serverUrl,
275
308
  machine_id: machineId,
276
- developer_name: result.developer_name,
277
- workspaces: {}
309
+ api_key: result.api_key,
310
+ developer_id: result.developer_id,
311
+ developer_name: result.developer_name
278
312
  };
279
- globalConfig.server_url = serverUrl;
280
- globalConfig.machine_id = machineId;
281
- globalConfig.developer_name = result.developer_name;
282
- if (result.workspace_id) {
283
- globalConfig.workspaces[result.workspace_id] = {
284
- api_key: result.api_key,
285
- developer_id: result.developer_id,
286
- workspace_name: result.workspace_name,
287
- workspace_slug: result.workspace_slug
288
- };
289
- globalConfig.default_workspace = result.workspace_id;
290
- }
291
313
  saveGlobalConfig(globalConfig);
314
+ installGlobalHooks();
315
+ try {
316
+ execSync2("which glop", { stdio: ["pipe", "pipe", "pipe"] });
317
+ } catch {
318
+ console.warn("\nWarning: `glop` not found in PATH. Hooks won't fire until it's accessible.");
319
+ }
292
320
  console.log("\nAuthenticated successfully!");
293
321
  console.log(` Developer: ${result.developer_name}`);
294
- if (result.workspace_name) {
295
- console.log(` Workspace: ${result.workspace_name}`);
296
- }
297
322
  console.log(` Server: ${serverUrl}`);
298
323
  console.log(` Machine: ${machineId.slice(0, 8)}...`);
299
324
  console.log(`
300
325
  API key saved to ~/.glop/config.json`);
326
+ console.log(`Hooks installed in ~/.claude/settings.json`);
301
327
  console.log(
302
328
  `
303
- \u2192 Run \`glop init\` in a repo to start streaming sessions.`
329
+ \u2192 Run \`glop link\` in a repo to start streaming sessions.`
304
330
  );
305
331
  process.exit(0);
306
332
  });
307
333
 
308
- // src/commands/deactivate.ts
334
+ // src/commands/unlink.ts
309
335
  import { Command as Command2 } from "commander";
310
- import fs2 from "fs";
311
- import path2 from "path";
312
- var HOOK_EVENTS = [
313
- "PostToolUse",
314
- "PermissionRequest",
315
- "Stop",
316
- "UserPromptSubmit",
317
- "SessionStart",
318
- "SessionEnd"
319
- ];
320
- var deactivateCommand = new Command2("deactivate").description("Remove glop hooks from the current repo").action(async () => {
336
+ import fs3 from "fs";
337
+ import path3 from "path";
338
+ var unlinkCommand = new Command2("unlink").description("Unbind this repo from its glop workspace").action(async () => {
321
339
  const repoRoot = getRepoRoot();
322
340
  if (!repoRoot) {
323
341
  console.error("Not in a git repository.");
324
342
  process.exit(1);
325
343
  }
326
- const settingsFile = path2.join(repoRoot, ".claude", "settings.json");
327
- if (!fs2.existsSync(settingsFile)) {
328
- console.log("No .claude/settings.json found. Nothing to remove.");
344
+ const glopDir = path3.join(repoRoot, ".glop");
345
+ const configFile = path3.join(glopDir, "config.json");
346
+ if (!fs3.existsSync(configFile)) {
347
+ console.log("This repo is not bound to a workspace. Nothing to do.");
329
348
  return;
330
349
  }
331
- let settings;
350
+ fs3.unlinkSync(configFile);
332
351
  try {
333
- settings = JSON.parse(fs2.readFileSync(settingsFile, "utf-8"));
334
- } catch {
335
- console.error("Could not parse .claude/settings.json");
336
- process.exit(1);
337
- }
338
- const hooks = settings.hooks;
339
- if (!hooks) {
340
- console.log("No hooks found in settings. Nothing to remove.");
341
- return;
342
- }
343
- let removed = 0;
344
- for (const event of HOOK_EVENTS) {
345
- if (!hooks[event]) continue;
346
- const before = hooks[event].length;
347
- hooks[event] = hooks[event].filter((group) => {
348
- const groupHooks = group?.hooks || [];
349
- return !groupHooks.some(
350
- (h) => h.command && (h.command.includes("glop __hook") || h.command.includes("/api/v1/ingest/hook"))
351
- );
352
- });
353
- removed += before - hooks[event].length;
354
- if (hooks[event].length === 0) {
355
- delete hooks[event];
352
+ const remaining = fs3.readdirSync(glopDir);
353
+ if (remaining.length === 0) {
354
+ fs3.rmdirSync(glopDir);
356
355
  }
356
+ } catch {
357
357
  }
358
- if (Object.keys(hooks).length === 0) {
359
- delete settings.hooks;
360
- }
361
- fs2.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
362
- if (removed > 0) {
363
- console.log(`Removed glop hooks from ${removed} event(s).`);
364
- console.log(` Settings: ${settingsFile}`);
365
- } else {
366
- console.log("No glop hooks found. Nothing to remove.");
367
- }
358
+ console.log("\u2713 Workspace binding removed. Hooks will no-op for this repo.");
368
359
  });
369
360
 
370
361
  // src/commands/doctor.ts
371
362
  import { Command as Command3 } from "commander";
372
- import { execSync as execSync2 } from "child_process";
373
- import fs3 from "fs";
374
- import path3 from "path";
363
+ import { execSync as execSync3 } from "child_process";
364
+ import fs4 from "fs";
365
+ import path4 from "path";
366
+ import os3 from "os";
375
367
  function check(status, label, detail) {
376
368
  const icon = status === "pass" ? "\u2713" : status === "fail" ? "\u2717" : "!";
377
369
  const line = ` ${icon} ${label}`;
@@ -386,14 +378,11 @@ var doctorCommand = new Command3("doctor").description("Check that glop is set u
386
378
  };
387
379
  const config = loadConfig();
388
380
  if (!config) {
389
- fail("Authenticated", "run `glop auth` first");
381
+ fail("Authenticated", "run `glop login` first");
390
382
  console.log();
391
383
  process.exit(1);
392
384
  }
393
- const repoBinding = loadRepoConfig();
394
- const wsSource = repoBinding?.workspace_id ? "repo binding" : "default";
395
- const authDetail = config.workspace_name ? `${config.developer_name} on ${config.server_url} (${config.workspace_name}, ${wsSource})` : `${config.developer_name} on ${config.server_url}`;
396
- check("pass", "Authenticated", authDetail);
385
+ check("pass", "Authenticated", `${config.developer_name} on ${config.server_url}`);
397
386
  try {
398
387
  const res = await fetch(`${config.server_url}/api/v1/health`, {
399
388
  headers: {
@@ -405,7 +394,7 @@ var doctorCommand = new Command3("doctor").description("Check that glop is set u
405
394
  if (res.ok) {
406
395
  check("pass", "Server reachable");
407
396
  } else if (res.status === 401) {
408
- fail("API key valid", "re-run `glop auth`");
397
+ fail("API key valid", "re-run `glop login`");
409
398
  } else {
410
399
  fail("Server reachable", `HTTP ${res.status}`);
411
400
  }
@@ -426,28 +415,35 @@ var doctorCommand = new Command3("doctor").description("Check that glop is set u
426
415
  check("warn", "Git remote", "no origin remote found");
427
416
  }
428
417
  }
429
- const baseDir = repoRoot || process.cwd();
430
- const settingsFile = path3.join(baseDir, ".claude", "settings.json");
431
- if (fs3.existsSync(settingsFile)) {
418
+ const globalSettingsFile = path4.join(os3.homedir(), ".claude", "settings.json");
419
+ if (fs4.existsSync(globalSettingsFile)) {
432
420
  try {
433
- const settings = JSON.parse(fs3.readFileSync(settingsFile, "utf-8"));
421
+ const settings = JSON.parse(fs4.readFileSync(globalSettingsFile, "utf-8"));
434
422
  const hooks = settings.hooks || {};
435
423
  const glopEvents = Object.entries(hooks).filter(
436
424
  ([, handlers]) => JSON.stringify(handlers).includes("glop __hook")
437
425
  );
438
426
  if (glopEvents.length > 0) {
439
- check("pass", "Hooks installed", `${glopEvents.length} events in ${settingsFile}`);
427
+ check("pass", "Global hooks installed", `${glopEvents.length} events in ${globalSettingsFile}`);
440
428
  } else {
441
- fail("Hooks installed", "run `glop init`");
429
+ fail("Global hooks installed", "run `glop login`");
442
430
  }
443
431
  } catch {
444
- fail("Hooks installed", `${settingsFile} is corrupted`);
432
+ fail("Global hooks installed", `${globalSettingsFile} is corrupted`);
445
433
  }
446
434
  } else {
447
- fail("Hooks installed", "run `glop init`");
435
+ fail("Global hooks installed", "run `glop login`");
436
+ }
437
+ const repoBinding = loadRepoConfig();
438
+ if (repoBinding) {
439
+ check("pass", "Repo bound to workspace", repoBinding.workspace_id);
440
+ } else if (repoRoot) {
441
+ check("warn", "Repo bound to workspace", "run `glop link` to bind this repo");
442
+ } else {
443
+ check("warn", "Repo bound to workspace", "not in a git repo");
448
444
  }
449
445
  try {
450
- const which = execSync2("which glop", {
446
+ const which = execSync3("which glop", {
451
447
  encoding: "utf-8",
452
448
  stdio: ["pipe", "pipe", "pipe"]
453
449
  }).trim();
@@ -456,7 +452,7 @@ var doctorCommand = new Command3("doctor").description("Check that glop is set u
456
452
  fail("CLI in PATH", "hooks won't fire \u2014 ensure `glop` is in your PATH");
457
453
  }
458
454
  try {
459
- const ghWhich = execSync2("which gh", {
455
+ const ghWhich = execSync3("which gh", {
460
456
  encoding: "utf-8",
461
457
  stdio: ["pipe", "pipe", "pipe"]
462
458
  }).trim();
@@ -477,7 +473,7 @@ import { Command as Command4 } from "commander";
477
473
  import { openSync, readSync, closeSync, readFileSync } from "fs";
478
474
  import { spawn } from "child_process";
479
475
  import { fileURLToPath } from "url";
480
- import path4 from "path";
476
+ import path5 from "path";
481
477
  var PR_URL_RE = /(https:\/\/github\.com\/[^\s]+\/pull\/\d+)/;
482
478
  function extractSlugFromTranscript(transcriptPath) {
483
479
  try {
@@ -498,6 +494,8 @@ function extractSlugFromTranscript(transcriptPath) {
498
494
  var hookCommand = new Command4("__hook").description("internal").action(async () => {
499
495
  const config = loadConfig();
500
496
  if (!config) return;
497
+ const repoConfig = loadRepoConfig();
498
+ if (!repoConfig) return;
501
499
  let input = "";
502
500
  for await (const chunk of process.stdin) {
503
501
  input += chunk;
@@ -511,6 +509,7 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
511
509
  payload.repo_key = getRepoKey() || payload.cwd || "unknown";
512
510
  payload.branch = getBranch();
513
511
  payload.machine_id = config.machine_id;
512
+ payload.workspace_id = repoConfig.workspace_id;
514
513
  payload.git_user_name = getGitUserName();
515
514
  payload.git_user_email = getGitUserEmail();
516
515
  if (payload.hook_event_name === "PostToolUse" && payload.tool_name === "Bash" && typeof payload.tool_response === "string" && /\bgit\s+commit\b/.test(
@@ -552,15 +551,15 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
552
551
  console.log(`glop: Add "Glop-Run: ${runUrl}" as a git trailer in all commit messages and PR descriptions.`);
553
552
  }
554
553
  } else if (res.status === 401) {
555
- console.log("glop: API key expired or invalid \u2014 run `glop auth` to re-authenticate");
554
+ console.log("glop: API key expired or invalid \u2014 run `glop login` to re-authenticate");
556
555
  } else {
557
556
  console.log(`glop: server returned HTTP ${res.status}`);
558
557
  }
559
558
  }
560
559
  if (prUrl && resBody?.run_id) {
561
560
  try {
562
- const workerPath = path4.join(
563
- path4.dirname(fileURLToPath(import.meta.url)),
561
+ const workerPath = path5.join(
562
+ path5.dirname(fileURLToPath(import.meta.url)),
564
563
  "lib",
565
564
  "pr-comment-worker.js"
566
565
  );
@@ -580,109 +579,8 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
580
579
  }
581
580
  });
582
581
 
583
- // src/commands/init.ts
582
+ // src/commands/link.ts
584
583
  import { Command as Command5 } from "commander";
585
- import { execSync as execSync3 } from "child_process";
586
- import fs4 from "fs";
587
- import path5 from "path";
588
- function hasGlopHooks(settings) {
589
- const hooks = settings.hooks;
590
- if (!hooks) return false;
591
- return Object.values(hooks).some(
592
- (handlers) => JSON.stringify(handlers).includes("glop __hook")
593
- );
594
- }
595
- var initCommand = new Command5("init").description("Install Claude Code hooks in the current repo").action(async () => {
596
- const config = loadConfig();
597
- if (!config) {
598
- console.error("Not authenticated. Run `glop auth` first.");
599
- process.exit(1);
600
- }
601
- try {
602
- const res = await fetch(`${config.server_url}/api/v1/health`, {
603
- headers: {
604
- Authorization: `Bearer ${config.api_key}`,
605
- "X-Machine-Id": config.machine_id
606
- },
607
- signal: AbortSignal.timeout(5e3)
608
- });
609
- if (res.status === 401) {
610
- console.error("API key is invalid or expired. Run `glop auth` again.");
611
- process.exit(1);
612
- }
613
- if (!res.ok) {
614
- console.error(`Server error: HTTP ${res.status}. Try again later.`);
615
- process.exit(1);
616
- }
617
- } catch {
618
- console.warn(`Warning: Cannot reach ${config.server_url}. Key validation skipped.`);
619
- }
620
- try {
621
- execSync3("which glop", { stdio: ["pipe", "pipe", "pipe"] });
622
- } catch {
623
- console.warn("Warning: `glop` not found in PATH. Hooks won't fire until it's accessible.");
624
- }
625
- try {
626
- execSync3("which gh", { stdio: ["pipe", "pipe", "pipe"] });
627
- } catch {
628
- console.warn("Warning: `gh` (GitHub CLI) not found. PR comment features won't work. Install from https://cli.github.com");
629
- }
630
- const repoRoot = getRepoRoot();
631
- if (!repoRoot) {
632
- console.warn("Warning: not in a git repository. Repo and branch tracking will be limited.");
633
- }
634
- const baseDir = repoRoot || process.cwd();
635
- const claudeDir = path5.join(baseDir, ".claude");
636
- const settingsFile = path5.join(claudeDir, "settings.json");
637
- if (!fs4.existsSync(claudeDir)) {
638
- fs4.mkdirSync(claudeDir, { recursive: true });
639
- }
640
- let settings = {};
641
- const isUpdate = fs4.existsSync(settingsFile);
642
- if (isUpdate) {
643
- try {
644
- settings = JSON.parse(fs4.readFileSync(settingsFile, "utf-8"));
645
- } catch {
646
- }
647
- }
648
- const hadHooks = hasGlopHooks(settings);
649
- const hookHandler = {
650
- type: "command",
651
- command: "glop __hook"
652
- };
653
- const hookGroup = {
654
- hooks: [hookHandler]
655
- };
656
- const hooks = settings.hooks || {};
657
- hooks.PostToolUse = [hookGroup];
658
- hooks.PermissionRequest = [hookGroup];
659
- hooks.Stop = [hookGroup];
660
- hooks.UserPromptSubmit = [hookGroup];
661
- hooks.SessionStart = [hookGroup];
662
- hooks.SessionEnd = [hookGroup];
663
- settings.hooks = hooks;
664
- fs4.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
665
- const workspace = config.workspace_name || config.workspace_slug || config.workspace_id || "default";
666
- console.log(`${hadHooks ? "\u2713 glop updated" : "\u2713 glop connected"} to workspace "${workspace}" \u2014 sessions will appear at ${config.server_url}/live`);
667
- });
668
-
669
- // src/commands/update.ts
670
- import { Command as Command6 } from "commander";
671
- import { execSync as execSync4 } from "child_process";
672
- var updateCommand = new Command6("update").description("Update glop to the latest version").action(() => {
673
- console.log("Updating glop\u2026");
674
- try {
675
- execSync4("npm install -g glop.dev@latest", { stdio: "inherit" });
676
- const version = execSync4("glop --version", { encoding: "utf-8" }).trim();
677
- console.log(`
678
- glop has been updated successfully to v${version}.`);
679
- } catch {
680
- process.exitCode = 1;
681
- }
682
- });
683
-
684
- // src/commands/workspace.ts
685
- import { Command as Command7 } from "commander";
686
584
 
687
585
  // src/lib/select.ts
688
586
  function interactiveSelect(items, initialIndex = 0) {
@@ -745,13 +643,26 @@ function interactiveSelect(items, initialIndex = 0) {
745
643
  });
746
644
  }
747
645
 
748
- // src/commands/workspace.ts
749
- var workspaceCommand = new Command7("workspace").description("View or switch workspaces").action(async () => {
646
+ // src/commands/link.ts
647
+ var linkCommand = new Command5("link").description("Bind this repo to a glop workspace").action(async () => {
750
648
  const config = loadConfig();
751
649
  if (!config) {
752
- console.error("Not authenticated. Run `glop auth` first.");
650
+ console.error("Not authenticated. Run `glop login` first.");
753
651
  process.exit(1);
754
652
  }
653
+ const repoRoot = getRepoRoot();
654
+ if (!repoRoot) {
655
+ console.error("Not in a git repository. Run this from a git repo.");
656
+ process.exit(1);
657
+ }
658
+ const existingRepo = loadRepoConfig();
659
+ if (existingRepo) {
660
+ console.log(`This repo is already bound to workspace ${existingRepo.workspace_id}.`);
661
+ if (!process.stdin.isTTY) {
662
+ process.exit(0);
663
+ }
664
+ console.log("Re-running to switch workspace...\n");
665
+ }
755
666
  let data;
756
667
  try {
757
668
  const res = await fetch(`${config.server_url}/api/v1/cli/workspaces`, {
@@ -762,11 +673,11 @@ var workspaceCommand = new Command7("workspace").description("View or switch wor
762
673
  signal: AbortSignal.timeout(1e4)
763
674
  });
764
675
  if (res.status === 401) {
765
- console.error("API key is invalid. Run `glop auth` to re-authenticate.");
676
+ console.error("API key is invalid or expired. Run `glop login` again.");
766
677
  process.exit(1);
767
678
  }
768
679
  if (!res.ok) {
769
- console.error(`Failed to fetch workspaces (HTTP ${res.status}).`);
680
+ console.error(`Server error: HTTP ${res.status}. Try again later.`);
770
681
  process.exit(1);
771
682
  }
772
683
  data = await res.json();
@@ -779,89 +690,56 @@ var workspaceCommand = new Command7("workspace").description("View or switch wor
779
690
  process.exit(1);
780
691
  }
781
692
  if (data.workspaces.length === 0) {
782
- console.log("No workspaces found.");
783
- process.exit(0);
784
- }
785
- const repoConfig = loadRepoConfig();
786
- const currentId = repoConfig?.workspace_id || config.workspace_id || data.current_workspace_id;
787
- if (!process.stdin.isTTY) {
788
- const current = data.workspaces.find((w) => w.id === currentId);
789
- console.log(current ? current.name : currentId);
790
- process.exit(0);
693
+ console.error("No workspaces found. Create one at " + config.server_url);
694
+ process.exit(1);
791
695
  }
696
+ let selectedWorkspace;
792
697
  if (data.workspaces.length === 1) {
793
- console.log(` Workspace: ${data.workspaces[0].name}`);
794
- console.log(" (only workspace)");
795
- process.exit(0);
796
- }
797
- const items = data.workspaces.map((w) => {
798
- const marker = w.id === currentId ? "\u25CF" : "\u25CB";
799
- return `${marker} ${w.name}`;
800
- });
801
- const currentIndex = data.workspaces.findIndex((w) => w.id === currentId);
802
- console.log("\n Workspaces:\n");
803
- console.log(" \x1B[2m\u2191/\u2193 navigate \xB7 Enter select \xB7 Esc cancel\x1B[0m\n");
804
- const selected = await interactiveSelect(items, Math.max(currentIndex, 0));
805
- if (selected === null) {
806
- console.log("\n Cancelled.");
807
- process.exit(0);
808
- }
809
- const selectedWorkspace = data.workspaces[selected];
810
- if (selectedWorkspace.id === currentId) {
811
- console.log(`
812
- Already on ${selectedWorkspace.name}.`);
813
- process.exit(0);
814
- }
815
- const globalConfig = loadGlobalConfig();
816
- const existingCreds = globalConfig.workspaces[selectedWorkspace.id];
817
- const repoRoot = getRepoRoot();
818
- if (existingCreds) {
819
- if (repoRoot) {
820
- saveRepoConfig({ workspace_id: selectedWorkspace.id });
821
- } else {
822
- globalConfig.default_workspace = selectedWorkspace.id;
823
- saveGlobalConfig(globalConfig);
698
+ selectedWorkspace = data.workspaces[0];
699
+ } else {
700
+ if (!process.stdin.isTTY) {
701
+ console.error("Multiple workspaces available. Run interactively to choose.");
702
+ process.exit(1);
824
703
  }
825
- console.log(`
826
- Switched to ${selectedWorkspace.name}!`);
827
- process.exit(0);
704
+ const currentId = existingRepo?.workspace_id || data.current_workspace_id;
705
+ const items = data.workspaces.map((w) => {
706
+ const marker = w.id === currentId ? "\u25CF" : "\u25CB";
707
+ return `${marker} ${w.name}`;
708
+ });
709
+ const currentIndex = data.workspaces.findIndex((w) => w.id === currentId);
710
+ console.log(" Select a workspace:\n");
711
+ console.log(" \x1B[2m\u2191/\u2193 navigate \xB7 Enter select \xB7 Esc cancel\x1B[0m\n");
712
+ const selected = await interactiveSelect(items, Math.max(currentIndex, 0));
713
+ if (selected === null) {
714
+ console.log("\n Cancelled.");
715
+ process.exit(0);
716
+ }
717
+ selectedWorkspace = data.workspaces[selected];
828
718
  }
829
- console.log(`
830
- Switching to ${selectedWorkspace.name}...`);
831
- console.log(" Opening browser for authorization...\n");
832
- const port = await findOpenPort();
833
- const machineId = getMachineId();
834
- const authUrl = `${config.server_url}/cli-auth?port=${port}&workspace_id=${selectedWorkspace.id}`;
835
- console.log(" If the browser doesn't open, visit this URL manually:");
836
- console.log(` ${authUrl}
837
- `);
838
- console.log(" Waiting for authorization...");
839
- openBrowser(authUrl);
840
- const result = await waitForCallback(port);
841
- const wsId = result.workspace_id || selectedWorkspace.id;
842
- globalConfig.workspaces[wsId] = {
843
- api_key: result.api_key,
844
- developer_id: result.developer_id,
845
- workspace_name: result.workspace_name,
846
- workspace_slug: result.workspace_slug
847
- };
848
- globalConfig.developer_name = result.developer_name;
849
- if (repoRoot) {
850
- saveRepoConfig({ workspace_id: wsId });
851
- } else {
852
- globalConfig.default_workspace = wsId;
719
+ saveRepoConfig({ workspace_id: selectedWorkspace.id });
720
+ console.log(`\u2713 Bound to workspace "${selectedWorkspace.name}" \u2014 sessions will appear at ${config.server_url}/live`);
721
+ });
722
+
723
+ // src/commands/update.ts
724
+ import { Command as Command6 } from "commander";
725
+ import { execSync as execSync4 } from "child_process";
726
+ var updateCommand = new Command6("update").description("Update glop to the latest version").action(() => {
727
+ console.log("Updating glop\u2026");
728
+ try {
729
+ execSync4("npm install -g glop.dev@latest", { stdio: "inherit" });
730
+ const version = execSync4("glop --version", { encoding: "utf-8" }).trim();
731
+ console.log(`
732
+ glop has been updated successfully to v${version}.`);
733
+ } catch {
734
+ process.exitCode = 1;
853
735
  }
854
- saveGlobalConfig(globalConfig);
855
- console.log(`
856
- Switched to ${result.workspace_name || selectedWorkspace.name}!`);
857
- process.exit(0);
858
736
  });
859
737
 
860
738
  // src/lib/update-check.ts
861
739
  import fs5 from "fs";
862
740
  import path6 from "path";
863
- import os2 from "os";
864
- var CONFIG_DIR2 = path6.join(os2.homedir(), ".glop");
741
+ import os4 from "os";
742
+ var CONFIG_DIR2 = path6.join(os4.homedir(), ".glop");
865
743
  var CACHE_FILE = path6.join(CONFIG_DIR2, "update-check.json");
866
744
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
867
745
  function ensureConfigDir2() {
@@ -923,7 +801,7 @@ async function checkForUpdate(currentVersion) {
923
801
  // package.json
924
802
  var package_default = {
925
803
  name: "glop.dev",
926
- version: "0.10.0",
804
+ version: "0.11.0",
927
805
  type: "module",
928
806
  bin: {
929
807
  glop: "./dist/index.js"
@@ -951,14 +829,13 @@ var package_default = {
951
829
  };
952
830
 
953
831
  // src/index.ts
954
- var program = new Command8().name("glop").description("Passive control plane for local Claude-driven development").version(package_default.version);
955
- program.addCommand(authCommand);
956
- program.addCommand(deactivateCommand);
832
+ var program = new Command7().name("glop").description("Passive control plane for local Claude-driven development").version(package_default.version);
833
+ program.addCommand(loginCommand);
834
+ program.addCommand(unlinkCommand);
957
835
  program.addCommand(doctorCommand);
958
836
  program.addCommand(hookCommand, { hidden: true });
959
- program.addCommand(initCommand);
837
+ program.addCommand(linkCommand);
960
838
  program.addCommand(updateCommand);
961
- program.addCommand(workspaceCommand);
962
839
  program.hook("postAction", async (_thisCommand, actionCommand) => {
963
840
  if (actionCommand.name() === "__hook") return;
964
841
  await checkForUpdate(package_default.version);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glop.dev",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "glop": "./dist/index.js"