glop.dev 0.10.0 → 0.12.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 +206 -302
  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,53 @@ 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
+ if (repoRoot) {
438
+ const repoBinding = loadRepoConfig();
439
+ if (repoBinding) {
440
+ let workspaceLabel = repoBinding.workspace_id;
441
+ try {
442
+ const wsRes = await fetch(`${config.server_url}/api/v1/cli/workspaces`, {
443
+ headers: {
444
+ Authorization: `Bearer ${config.api_key}`,
445
+ "X-Machine-Id": config.machine_id
446
+ },
447
+ signal: AbortSignal.timeout(5e3)
448
+ });
449
+ if (wsRes.ok) {
450
+ const data = await wsRes.json();
451
+ const ws = data.workspaces.find((w) => w.id === repoBinding.workspace_id);
452
+ if (ws) {
453
+ workspaceLabel = ws.name;
454
+ }
455
+ }
456
+ } catch {
457
+ }
458
+ check("pass", "Repo bound to workspace", workspaceLabel);
459
+ } else {
460
+ check("warn", "Repo bound to workspace", "run `glop link` to bind this repo");
461
+ }
448
462
  }
449
463
  try {
450
- const which = execSync2("which glop", {
464
+ const which = execSync3("which glop", {
451
465
  encoding: "utf-8",
452
466
  stdio: ["pipe", "pipe", "pipe"]
453
467
  }).trim();
@@ -456,7 +470,7 @@ var doctorCommand = new Command3("doctor").description("Check that glop is set u
456
470
  fail("CLI in PATH", "hooks won't fire \u2014 ensure `glop` is in your PATH");
457
471
  }
458
472
  try {
459
- const ghWhich = execSync2("which gh", {
473
+ const ghWhich = execSync3("which gh", {
460
474
  encoding: "utf-8",
461
475
  stdio: ["pipe", "pipe", "pipe"]
462
476
  }).trim();
@@ -477,8 +491,16 @@ import { Command as Command4 } from "commander";
477
491
  import { openSync, readSync, closeSync, readFileSync } from "fs";
478
492
  import { spawn } from "child_process";
479
493
  import { fileURLToPath } from "url";
480
- import path4 from "path";
494
+ import path5 from "path";
481
495
  var PR_URL_RE = /(https:\/\/github\.com\/[^\s]+\/pull\/\d+)/;
496
+ function extractBashOutput(response) {
497
+ if (!response || typeof response !== "object") return "";
498
+ const r = response;
499
+ const parts = [];
500
+ if (typeof r.stdout === "string") parts.push(r.stdout);
501
+ if (typeof r.stderr === "string") parts.push(r.stderr);
502
+ return parts.join("\n");
503
+ }
482
504
  function extractSlugFromTranscript(transcriptPath) {
483
505
  try {
484
506
  const fd = openSync(transcriptPath, "r");
@@ -498,6 +520,8 @@ function extractSlugFromTranscript(transcriptPath) {
498
520
  var hookCommand = new Command4("__hook").description("internal").action(async () => {
499
521
  const config = loadConfig();
500
522
  if (!config) return;
523
+ const repoConfig = loadRepoConfig();
524
+ if (!repoConfig) return;
501
525
  let input = "";
502
526
  for await (const chunk of process.stdin) {
503
527
  input += chunk;
@@ -511,11 +535,13 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
511
535
  payload.repo_key = getRepoKey() || payload.cwd || "unknown";
512
536
  payload.branch = getBranch();
513
537
  payload.machine_id = config.machine_id;
538
+ payload.workspace_id = repoConfig.workspace_id;
514
539
  payload.git_user_name = getGitUserName();
515
540
  payload.git_user_email = getGitUserEmail();
516
- if (payload.hook_event_name === "PostToolUse" && payload.tool_name === "Bash" && typeof payload.tool_response === "string" && /\bgit\s+commit\b/.test(
541
+ const toolOutput = payload.hook_event_name === "PostToolUse" && payload.tool_name === "Bash" ? extractBashOutput(payload.tool_response) : "";
542
+ if (toolOutput && /\bgit\s+commit\b/.test(
517
543
  typeof payload.tool_input?.command === "string" ? payload.tool_input.command : ""
518
- ) && /\[\w[^\]]*\s+[a-f0-9]{7,}\]/.test(payload.tool_response)) {
544
+ ) && /\[\w[^\]]*\s+[a-f0-9]{7,}\]/.test(toolOutput)) {
519
545
  const diffStats = getCommitDiffStats();
520
546
  if (diffStats) {
521
547
  payload.commit_diff_stats = diffStats;
@@ -527,10 +553,10 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
527
553
  if (slug) payload.slug = slug;
528
554
  }
529
555
  let prUrl = null;
530
- if (payload.hook_event_name === "PostToolUse" && payload.tool_name === "Bash" && typeof payload.tool_response === "string" && /\bgh\s+pr\s+create\b/.test(
556
+ if (toolOutput && /\bgh\s+pr\s+create\b/.test(
531
557
  typeof payload.tool_input?.command === "string" ? payload.tool_input.command : ""
532
558
  )) {
533
- const prMatch = payload.tool_response.match(PR_URL_RE);
559
+ const prMatch = toolOutput.match(PR_URL_RE);
534
560
  if (prMatch) prUrl = prMatch[1];
535
561
  }
536
562
  try {
@@ -552,15 +578,15 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
552
578
  console.log(`glop: Add "Glop-Run: ${runUrl}" as a git trailer in all commit messages and PR descriptions.`);
553
579
  }
554
580
  } else if (res.status === 401) {
555
- console.log("glop: API key expired or invalid \u2014 run `glop auth` to re-authenticate");
581
+ console.log("glop: API key expired or invalid \u2014 run `glop login` to re-authenticate");
556
582
  } else {
557
583
  console.log(`glop: server returned HTTP ${res.status}`);
558
584
  }
559
585
  }
560
586
  if (prUrl && resBody?.run_id) {
561
587
  try {
562
- const workerPath = path4.join(
563
- path4.dirname(fileURLToPath(import.meta.url)),
588
+ const workerPath = path5.join(
589
+ path5.dirname(fileURLToPath(import.meta.url)),
564
590
  "lib",
565
591
  "pr-comment-worker.js"
566
592
  );
@@ -580,109 +606,8 @@ var hookCommand = new Command4("__hook").description("internal").action(async ()
580
606
  }
581
607
  });
582
608
 
583
- // src/commands/init.ts
609
+ // src/commands/link.ts
584
610
  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
611
 
687
612
  // src/lib/select.ts
688
613
  function interactiveSelect(items, initialIndex = 0) {
@@ -745,13 +670,26 @@ function interactiveSelect(items, initialIndex = 0) {
745
670
  });
746
671
  }
747
672
 
748
- // src/commands/workspace.ts
749
- var workspaceCommand = new Command7("workspace").description("View or switch workspaces").action(async () => {
673
+ // src/commands/link.ts
674
+ var linkCommand = new Command5("link").description("Bind this repo to a glop workspace").action(async () => {
750
675
  const config = loadConfig();
751
676
  if (!config) {
752
- console.error("Not authenticated. Run `glop auth` first.");
677
+ console.error("Not authenticated. Run `glop login` first.");
678
+ process.exit(1);
679
+ }
680
+ const repoRoot = getRepoRoot();
681
+ if (!repoRoot) {
682
+ console.error("Not in a git repository. Run this from a git repo.");
753
683
  process.exit(1);
754
684
  }
685
+ const existingRepo = loadRepoConfig();
686
+ if (existingRepo) {
687
+ console.log(`This repo is already bound to workspace ${existingRepo.workspace_id}.`);
688
+ if (!process.stdin.isTTY) {
689
+ process.exit(0);
690
+ }
691
+ console.log("Re-running to switch workspace...\n");
692
+ }
755
693
  let data;
756
694
  try {
757
695
  const res = await fetch(`${config.server_url}/api/v1/cli/workspaces`, {
@@ -762,11 +700,11 @@ var workspaceCommand = new Command7("workspace").description("View or switch wor
762
700
  signal: AbortSignal.timeout(1e4)
763
701
  });
764
702
  if (res.status === 401) {
765
- console.error("API key is invalid. Run `glop auth` to re-authenticate.");
703
+ console.error("API key is invalid or expired. Run `glop login` again.");
766
704
  process.exit(1);
767
705
  }
768
706
  if (!res.ok) {
769
- console.error(`Failed to fetch workspaces (HTTP ${res.status}).`);
707
+ console.error(`Server error: HTTP ${res.status}. Try again later.`);
770
708
  process.exit(1);
771
709
  }
772
710
  data = await res.json();
@@ -779,89 +717,56 @@ var workspaceCommand = new Command7("workspace").description("View or switch wor
779
717
  process.exit(1);
780
718
  }
781
719
  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);
720
+ console.error("No workspaces found. Create one at " + config.server_url);
721
+ process.exit(1);
791
722
  }
723
+ let selectedWorkspace;
792
724
  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);
725
+ selectedWorkspace = data.workspaces[0];
726
+ } else {
727
+ if (!process.stdin.isTTY) {
728
+ console.error("Multiple workspaces available. Run interactively to choose.");
729
+ process.exit(1);
824
730
  }
825
- console.log(`
826
- Switched to ${selectedWorkspace.name}!`);
827
- process.exit(0);
731
+ const currentId = existingRepo?.workspace_id || data.current_workspace_id;
732
+ const items = data.workspaces.map((w) => {
733
+ const marker = w.id === currentId ? "\u25CF" : "\u25CB";
734
+ return `${marker} ${w.name}`;
735
+ });
736
+ const currentIndex = data.workspaces.findIndex((w) => w.id === currentId);
737
+ console.log(" Select a workspace:\n");
738
+ console.log(" \x1B[2m\u2191/\u2193 navigate \xB7 Enter select \xB7 Esc cancel\x1B[0m\n");
739
+ const selected = await interactiveSelect(items, Math.max(currentIndex, 0));
740
+ if (selected === null) {
741
+ console.log("\n Cancelled.");
742
+ process.exit(0);
743
+ }
744
+ selectedWorkspace = data.workspaces[selected];
828
745
  }
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;
746
+ saveRepoConfig({ workspace_id: selectedWorkspace.id });
747
+ console.log(`\u2713 Bound to workspace "${selectedWorkspace.name}" \u2014 sessions will appear at ${config.server_url}/live`);
748
+ });
749
+
750
+ // src/commands/update.ts
751
+ import { Command as Command6 } from "commander";
752
+ import { execSync as execSync4 } from "child_process";
753
+ var updateCommand = new Command6("update").description("Update glop to the latest version").action(() => {
754
+ console.log("Updating glop\u2026");
755
+ try {
756
+ execSync4("npm install -g glop.dev@latest", { stdio: "inherit" });
757
+ const version = execSync4("glop --version", { encoding: "utf-8" }).trim();
758
+ console.log(`
759
+ glop has been updated successfully to v${version}.`);
760
+ } catch {
761
+ process.exitCode = 1;
853
762
  }
854
- saveGlobalConfig(globalConfig);
855
- console.log(`
856
- Switched to ${result.workspace_name || selectedWorkspace.name}!`);
857
- process.exit(0);
858
763
  });
859
764
 
860
765
  // src/lib/update-check.ts
861
766
  import fs5 from "fs";
862
767
  import path6 from "path";
863
- import os2 from "os";
864
- var CONFIG_DIR2 = path6.join(os2.homedir(), ".glop");
768
+ import os4 from "os";
769
+ var CONFIG_DIR2 = path6.join(os4.homedir(), ".glop");
865
770
  var CACHE_FILE = path6.join(CONFIG_DIR2, "update-check.json");
866
771
  var CHECK_INTERVAL_MS = 24 * 60 * 60 * 1e3;
867
772
  function ensureConfigDir2() {
@@ -923,7 +828,7 @@ async function checkForUpdate(currentVersion) {
923
828
  // package.json
924
829
  var package_default = {
925
830
  name: "glop.dev",
926
- version: "0.10.0",
831
+ version: "0.12.0",
927
832
  type: "module",
928
833
  bin: {
929
834
  glop: "./dist/index.js"
@@ -951,14 +856,13 @@ var package_default = {
951
856
  };
952
857
 
953
858
  // 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);
859
+ var program = new Command7().name("glop").description("Passive control plane for local Claude-driven development").version(package_default.version);
860
+ program.addCommand(loginCommand);
861
+ program.addCommand(unlinkCommand);
957
862
  program.addCommand(doctorCommand);
958
863
  program.addCommand(hookCommand, { hidden: true });
959
- program.addCommand(initCommand);
864
+ program.addCommand(linkCommand);
960
865
  program.addCommand(updateCommand);
961
- program.addCommand(workspaceCommand);
962
866
  program.hook("postAction", async (_thisCommand, actionCommand) => {
963
867
  if (actionCommand.name() === "__hook") return;
964
868
  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.12.0",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "glop": "./dist/index.js"