waypoint-codex 0.1.5 → 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,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
import { existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
-
import {
|
|
4
|
+
import { execFileSync } from "node:child_process";
|
|
5
5
|
import os from "node:os";
|
|
6
6
|
import path from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
@@ -23,16 +23,96 @@ function ensureDir(dirPath) {
|
|
|
23
23
|
mkdirSync(dirPath, { recursive: true });
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function
|
|
26
|
+
function runCommand(command, cwd) {
|
|
27
27
|
try {
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
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}`;
|
|
35
114
|
}
|
|
115
|
+
return result.stdout || emptyMessage;
|
|
36
116
|
}
|
|
37
117
|
|
|
38
118
|
const SESSION_DIR_NAMES = ["sessions", "archived_sessions"];
|
|
@@ -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,21 +428,58 @@ function main() {
|
|
|
329
428
|
contextDir,
|
|
330
429
|
"UNCOMMITTED_CHANGES.md",
|
|
331
430
|
"Uncommitted Changes",
|
|
332
|
-
|
|
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
|
+
})()
|
|
333
455
|
);
|
|
334
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
|
+
};
|
|
335
465
|
const recentCommitsPath = writeContextFile(
|
|
336
466
|
contextDir,
|
|
337
467
|
"RECENT_COMMITS.md",
|
|
338
468
|
"Recent Commits",
|
|
339
|
-
|
|
469
|
+
[
|
|
470
|
+
authorFilter ? `Author filter: ${authorFilter.label}` : "Author filter: unavailable",
|
|
471
|
+
"",
|
|
472
|
+
"```",
|
|
473
|
+
renderCommandBlock(recentCommitsResult, "No recent commits found for the current author."),
|
|
474
|
+
"```",
|
|
475
|
+
].join("\n")
|
|
340
476
|
);
|
|
341
477
|
|
|
342
478
|
const nestedRepos = collectNestedGitRepos(projectRoot);
|
|
343
479
|
const nestedRepoSections = nestedRepos.map((repoPath) => {
|
|
344
480
|
const rel = path.relative(projectRoot, repoPath) || ".";
|
|
345
|
-
const branch = safeExec("git branch --show-current", repoPath) || "unknown";
|
|
346
|
-
const commits = safeExec("git log --format=%h %s (%cr) -10", repoPath) || "No recent commits found.";
|
|
481
|
+
const branch = safeExec(["git", "branch", "--show-current"], repoPath) || "unknown";
|
|
482
|
+
const commits = safeExec(["git", "log", "--format=%h %s (%cr)", "-10"], repoPath) || "No recent commits found.";
|
|
347
483
|
return `## ${rel}\n\nBranch: ${branch}\n\n\`\`\`\n${commits}\n\`\`\``;
|
|
348
484
|
});
|
|
349
485
|
const nestedReposPath = writeContextFile(
|
|
@@ -353,29 +489,71 @@ function main() {
|
|
|
353
489
|
nestedRepoSections.join("\n\n") || "No nested repositories found."
|
|
354
490
|
);
|
|
355
491
|
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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;
|
|
364
539
|
const prsPath = writeContextFile(
|
|
365
540
|
contextDir,
|
|
366
541
|
"PULL_REQUESTS.md",
|
|
367
542
|
"Pull Requests",
|
|
368
543
|
[
|
|
544
|
+
prContext.ok ? `GitHub viewer: ${prContext.viewer}` : `GitHub context: ${prContext.error}`,
|
|
545
|
+
prContext.ok ? `GitHub repo: ${prContext.repo}` : "",
|
|
546
|
+
"",
|
|
369
547
|
"## Open PRs",
|
|
370
548
|
"",
|
|
371
549
|
"```",
|
|
372
|
-
openPrs
|
|
550
|
+
renderPullRequestBlock(openPrs, "No open PRs found for the current GitHub user."),
|
|
373
551
|
"```",
|
|
374
552
|
"",
|
|
375
553
|
"## Recently Merged PRs",
|
|
376
554
|
"",
|
|
377
555
|
"```",
|
|
378
|
-
mergedPrs
|
|
556
|
+
renderPullRequestBlock(mergedPrs, "No recently merged PRs found for the current GitHub user."),
|
|
379
557
|
"```",
|
|
380
558
|
].join("\n")
|
|
381
559
|
);
|