@markmdev/pebble 0.1.3 → 0.1.5

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/cli/index.js CHANGED
@@ -1,4 +1,10 @@
1
1
  #!/usr/bin/env node
2
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
3
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
4
+ }) : x)(function(x) {
5
+ if (typeof require !== "undefined") return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
2
8
 
3
9
  // src/cli/index.ts
4
10
  import { Command } from "commander";
@@ -1410,15 +1416,20 @@ async function findAvailablePort(startPort, maxAttempts = 10) {
1410
1416
  }
1411
1417
  throw new Error(`No available port found (tried ${startPort}-${startPort + maxAttempts - 1})`);
1412
1418
  }
1413
- function readEventsFromFiles(filePaths) {
1414
- const allEvents = [];
1419
+ function mergeEventsFromFiles(filePaths) {
1420
+ const merged = /* @__PURE__ */ new Map();
1415
1421
  for (const filePath of filePaths) {
1416
1422
  const events = readEventsFromFile(filePath);
1417
1423
  for (const event of events) {
1418
- allEvents.push({ ...event, _source: filePath });
1424
+ const key = `${event.issueId}-${event.timestamp}-${event.type}`;
1425
+ if (!merged.has(key)) {
1426
+ merged.set(key, event);
1427
+ }
1419
1428
  }
1420
1429
  }
1421
- return allEvents;
1430
+ return Array.from(merged.values()).sort(
1431
+ (a, b) => new Date(a.timestamp).getTime() - new Date(b.timestamp).getTime()
1432
+ );
1422
1433
  }
1423
1434
  function mergeIssuesFromFiles(filePaths) {
1424
1435
  const merged = /* @__PURE__ */ new Map();
@@ -1541,6 +1552,57 @@ function uiCommand(program2) {
1541
1552
  res.status(500).json({ error: error.message });
1542
1553
  }
1543
1554
  });
1555
+ app.get("/api/worktrees", (_req, res) => {
1556
+ try {
1557
+ const { execSync } = __require("child_process");
1558
+ let worktreeOutput;
1559
+ try {
1560
+ worktreeOutput = execSync("git worktree list --porcelain", {
1561
+ encoding: "utf-8",
1562
+ cwd: process.cwd()
1563
+ });
1564
+ } catch {
1565
+ res.json({ worktrees: [] });
1566
+ return;
1567
+ }
1568
+ const worktrees = [];
1569
+ const blocks = worktreeOutput.trim().split("\n\n");
1570
+ for (const block of blocks) {
1571
+ const lines = block.split("\n");
1572
+ let worktreePath = "";
1573
+ let branch = null;
1574
+ for (const line of lines) {
1575
+ if (line.startsWith("worktree ")) {
1576
+ worktreePath = line.slice("worktree ".length);
1577
+ } else if (line.startsWith("branch ")) {
1578
+ branch = line.slice("branch ".length).replace("refs/heads/", "");
1579
+ }
1580
+ }
1581
+ if (worktreePath) {
1582
+ const issuesFile = path2.join(worktreePath, ".pebble", "issues.jsonl");
1583
+ const hasIssues = fs2.existsSync(issuesFile);
1584
+ const isActive = issueFiles.includes(issuesFile);
1585
+ let issueCount = 0;
1586
+ if (hasIssues) {
1587
+ const events = readEventsFromFile(issuesFile);
1588
+ const state = computeState(events);
1589
+ issueCount = state.size;
1590
+ }
1591
+ worktrees.push({
1592
+ path: worktreePath,
1593
+ branch,
1594
+ issuesFile: hasIssues ? issuesFile : null,
1595
+ hasIssues,
1596
+ isActive,
1597
+ issueCount
1598
+ });
1599
+ }
1600
+ }
1601
+ res.json({ worktrees });
1602
+ } catch (error) {
1603
+ res.status(500).json({ error: error.message });
1604
+ }
1605
+ });
1544
1606
  app.get("/api/issues", (_req, res) => {
1545
1607
  try {
1546
1608
  const issues = mergeIssuesFromFiles(issueFiles);
@@ -1551,7 +1613,7 @@ function uiCommand(program2) {
1551
1613
  });
1552
1614
  app.get("/api/events", (_req, res) => {
1553
1615
  try {
1554
- const events = readEventsFromFiles(issueFiles);
1616
+ const events = mergeEventsFromFiles(issueFiles);
1555
1617
  res.json(events);
1556
1618
  } catch (error) {
1557
1619
  res.status(500).json({ error: error.message });