waypoint-codex 0.1.6 → 0.1.7

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": "waypoint-codex",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Codex-native repository operating system: scaffolding, docs routing, repo-local skills, doctor, and sync.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -23,18 +23,98 @@ function ensureDir(dirPath) {
23
23
  mkdirSync(dirPath, { recursive: true });
24
24
  }
25
25
 
26
- function safeExec(command, cwd) {
26
+ function runCommand(command, cwd) {
27
27
  try {
28
- return execFileSync(command[0], command.slice(1), {
29
- cwd,
30
- stdio: ["ignore", "pipe", "ignore"],
31
- encoding: "utf8",
32
- }).trim();
33
- } catch {
34
- return "";
28
+ return {
29
+ ok: true,
30
+ stdout: execFileSync(command[0], command.slice(1), {
31
+ cwd,
32
+ stdio: ["ignore", "pipe", "pipe"],
33
+ encoding: "utf8",
34
+ }).trim(),
35
+ stderr: "",
36
+ };
37
+ } catch (error) {
38
+ return {
39
+ ok: false,
40
+ stdout: typeof error?.stdout === "string" ? error.stdout.trim() : "",
41
+ stderr:
42
+ typeof error?.stderr === "string" && error.stderr.trim().length > 0
43
+ ? error.stderr.trim()
44
+ : error instanceof Error
45
+ ? error.message
46
+ : "Unknown command failure",
47
+ };
35
48
  }
36
49
  }
37
50
 
51
+ function safeExec(command, cwd) {
52
+ const result = runCommand(command, cwd);
53
+ return result.ok ? result.stdout : "";
54
+ }
55
+
56
+ function escapeRegex(value) {
57
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
58
+ }
59
+
60
+ function currentAuthorFilter(projectRoot) {
61
+ const email = runCommand(["git", "config", "user.email"], projectRoot);
62
+ if (email.ok && email.stdout) {
63
+ return {
64
+ label: email.stdout,
65
+ pattern: escapeRegex(email.stdout),
66
+ };
67
+ }
68
+
69
+ const name = runCommand(["git", "config", "user.name"], projectRoot);
70
+ if (name.ok && name.stdout) {
71
+ return {
72
+ label: name.stdout,
73
+ pattern: `^${escapeRegex(name.stdout)}\\s<`,
74
+ };
75
+ }
76
+
77
+ return null;
78
+ }
79
+
80
+ function githubPullRequestContext(projectRoot) {
81
+ const repo = runCommand(["gh", "repo", "view", "--json", "nameWithOwner", "--jq", ".nameWithOwner"], projectRoot);
82
+ if (!repo.ok || !repo.stdout) {
83
+ return {
84
+ ok: false,
85
+ error: repo.stderr || "Could not resolve GitHub repository from this checkout.",
86
+ };
87
+ }
88
+
89
+ const viewer = runCommand(["gh", "api", "user", "--jq", ".login"], projectRoot);
90
+ if (!viewer.ok || !viewer.stdout) {
91
+ return {
92
+ ok: false,
93
+ error: viewer.stderr || "Could not resolve active GitHub user.",
94
+ };
95
+ }
96
+
97
+ return {
98
+ ok: true,
99
+ repo: repo.stdout,
100
+ viewer: viewer.stdout,
101
+ };
102
+ }
103
+
104
+ function renderCommandBlock(result, emptyMessage) {
105
+ if (!result.ok) {
106
+ return `Command failed: ${result.stderr}`;
107
+ }
108
+ return result.stdout || emptyMessage;
109
+ }
110
+
111
+ function renderPullRequestBlock(result, emptyMessage) {
112
+ if (!result.ok) {
113
+ return `Command failed: ${result.error || result.stderr}`;
114
+ }
115
+ return result.stdout || emptyMessage;
116
+ }
117
+
38
118
  const SESSION_DIR_NAMES = ["sessions", "archived_sessions"];
39
119
  const SECRET_PATTERNS = [
40
120
  /npm_[A-Za-z0-9]+/g,
@@ -242,6 +322,25 @@ function writeRecentThread(contextDir, projectRoot) {
242
322
  return filePath;
243
323
  }
244
324
 
325
+ if (!snapshot.selectedFromPreCompaction) {
326
+ writeFileSync(
327
+ filePath,
328
+ [
329
+ "# Recent Thread",
330
+ "",
331
+ `Generated by \`${path.relative(projectRoot, fileURLToPath(import.meta.url))}\` on ${generatedAt}.`,
332
+ "",
333
+ `- Source session: \`${path.relative(codexHome(), snapshot.path)}\``,
334
+ `- Session cwd: \`${snapshot.sessionCwd}\``,
335
+ `- Compactions in source session: ${snapshot.compactionCount}`,
336
+ "- No compaction was found in the latest matching local Codex session, so there is nothing to restore into startup context yet.",
337
+ "",
338
+ ].join("\n"),
339
+ "utf8"
340
+ );
341
+ return filePath;
342
+ }
343
+
245
344
  const selectedTurns = snapshot.turns.slice(-MAX_RECENT_TURNS);
246
345
  const relSessionPath = path.relative(codexHome(), snapshot.path);
247
346
  const lines = [
@@ -329,34 +428,49 @@ function main() {
329
428
  contextDir,
330
429
  "UNCOMMITTED_CHANGES.md",
331
430
  "Uncommitted Changes",
332
- [
333
- "## Status",
334
- "",
335
- "```",
336
- safeExec(["git", "status", "--short", "--branch"], projectRoot) || "No uncommitted changes.",
337
- "```",
338
- "",
339
- "## Diff Stat",
340
- "",
341
- "```",
342
- safeExec(["git", "diff", "--stat"], projectRoot) || "No unstaged tracked diff.",
343
- "```",
344
- "",
345
- "## Staged Diff Stat",
346
- "",
347
- "```",
348
- safeExec(["git", "diff", "--stat", "--cached"], projectRoot) || "No staged diff.",
349
- "```",
350
- ].join("\n")
431
+ (() => {
432
+ const status = runCommand(["git", "status", "--short", "--branch"], projectRoot);
433
+ const unstaged = runCommand(["git", "diff", "--stat"], projectRoot);
434
+ const staged = runCommand(["git", "diff", "--stat", "--cached"], projectRoot);
435
+ return [
436
+ "## Status",
437
+ "",
438
+ "```",
439
+ renderCommandBlock(status, "No uncommitted changes."),
440
+ "```",
441
+ "",
442
+ "## Diff Stat",
443
+ "",
444
+ "```",
445
+ renderCommandBlock(unstaged, "No unstaged tracked diff."),
446
+ "```",
447
+ "",
448
+ "## Staged Diff Stat",
449
+ "",
450
+ "```",
451
+ renderCommandBlock(staged, "No staged diff."),
452
+ "```",
453
+ ].join("\n");
454
+ })()
351
455
  );
352
456
 
457
+ const authorFilter = currentAuthorFilter(projectRoot);
458
+ const recentCommitsResult = authorFilter
459
+ ? runCommand(["git", "log", `--author=${authorFilter.pattern}`, "--format=%h%d %s (%cr)", "-20", "--all"], projectRoot)
460
+ : {
461
+ ok: false,
462
+ stdout: "",
463
+ stderr: "Could not determine current git author from local git config.",
464
+ };
353
465
  const recentCommitsPath = writeContextFile(
354
466
  contextDir,
355
467
  "RECENT_COMMITS.md",
356
468
  "Recent Commits",
357
469
  [
470
+ authorFilter ? `Author filter: ${authorFilter.label}` : "Author filter: unavailable",
471
+ "",
358
472
  "```",
359
- safeExec(["git", "log", "--format=%h%d %s (%cr)", "-20", "--all"], projectRoot) || "No recent commits found.",
473
+ renderCommandBlock(recentCommitsResult, "No recent commits found for the current author."),
360
474
  "```",
361
475
  ].join("\n")
362
476
  );
@@ -375,57 +489,71 @@ function main() {
375
489
  nestedRepoSections.join("\n\n") || "No nested repositories found."
376
490
  );
377
491
 
378
- const openPrs = safeExec(
379
- [
380
- "gh",
381
- "pr",
382
- "list",
383
- "--state",
384
- "open",
385
- "--author",
386
- "@me",
387
- "--limit",
388
- "5",
389
- "--json",
390
- "number,title,author,headRefName",
391
- "--template",
392
- "{{range .}}#{{.number}} {{.title}} ({{.author.login}}) [{{.headRefName}}]\n{{end}}",
393
- ],
394
- projectRoot
395
- );
396
- const mergedPrs = safeExec(
397
- [
398
- "gh",
399
- "pr",
400
- "list",
401
- "--state",
402
- "merged",
403
- "--author",
404
- "@me",
405
- "--limit",
406
- "5",
407
- "--json",
408
- "number,title,author,mergedAt",
409
- "--template",
410
- "{{range .}}#{{.number}} {{.title}} ({{.author.login}}) merged {{timeago .mergedAt}}\n{{end}}",
411
- ],
412
- projectRoot
413
- );
492
+ const prContext = githubPullRequestContext(projectRoot);
493
+ const openPrs =
494
+ prContext.ok
495
+ ? runCommand(
496
+ [
497
+ "gh",
498
+ "pr",
499
+ "list",
500
+ "--repo",
501
+ prContext.repo,
502
+ "--state",
503
+ "open",
504
+ "--author",
505
+ prContext.viewer,
506
+ "--limit",
507
+ "5",
508
+ "--json",
509
+ "number,title,author,headRefName",
510
+ "--template",
511
+ "{{range .}}#{{.number}} {{.title}} ({{.author.login}}) [{{.headRefName}}]\n{{end}}",
512
+ ],
513
+ projectRoot
514
+ )
515
+ : prContext;
516
+ const mergedPrs =
517
+ prContext.ok
518
+ ? runCommand(
519
+ [
520
+ "gh",
521
+ "pr",
522
+ "list",
523
+ "--repo",
524
+ prContext.repo,
525
+ "--state",
526
+ "merged",
527
+ "--author",
528
+ prContext.viewer,
529
+ "--limit",
530
+ "5",
531
+ "--json",
532
+ "number,title,author,mergedAt",
533
+ "--template",
534
+ "{{range .}}#{{.number}} {{.title}} ({{.author.login}}) merged {{timeago .mergedAt}}\n{{end}}",
535
+ ],
536
+ projectRoot
537
+ )
538
+ : prContext;
414
539
  const prsPath = writeContextFile(
415
540
  contextDir,
416
541
  "PULL_REQUESTS.md",
417
542
  "Pull Requests",
418
543
  [
544
+ prContext.ok ? `GitHub viewer: ${prContext.viewer}` : `GitHub context: ${prContext.error}`,
545
+ prContext.ok ? `GitHub repo: ${prContext.repo}` : "",
546
+ "",
419
547
  "## Open PRs",
420
548
  "",
421
549
  "```",
422
- openPrs || "No open PRs found.",
550
+ renderPullRequestBlock(openPrs, "No open PRs found for the current GitHub user."),
423
551
  "```",
424
552
  "",
425
553
  "## Recently Merged PRs",
426
554
  "",
427
555
  "```",
428
- mergedPrs || "No recently merged PRs found.",
556
+ renderPullRequestBlock(mergedPrs, "No recently merged PRs found for the current GitHub user."),
429
557
  "```",
430
558
  ].join("\n")
431
559
  );