@solaqua/gji 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 (122) hide show
  1. package/README.md +83 -426
  2. package/dist/back.d.ts +3 -0
  3. package/dist/back.js +19 -7
  4. package/dist/bootstrap-output.d.ts +3 -0
  5. package/dist/bootstrap-output.js +27 -0
  6. package/dist/bootstrap-preview.d.ts +10 -0
  7. package/dist/bootstrap-preview.js +21 -0
  8. package/dist/clean.js +27 -3
  9. package/dist/cli.d.ts +4 -0
  10. package/dist/cli.js +140 -22
  11. package/dist/clone-failure-store.d.ts +18 -0
  12. package/dist/clone-failure-store.js +230 -0
  13. package/dist/command-runner.d.ts +6 -0
  14. package/dist/command-runner.js +38 -0
  15. package/dist/completion.js +7 -2
  16. package/dist/config-command.d.ts +1 -0
  17. package/dist/config-command.js +7 -1
  18. package/dist/config.d.ts +26 -1
  19. package/dist/config.js +110 -6
  20. package/dist/context-card.d.ts +1 -0
  21. package/dist/context-card.js +25 -0
  22. package/dist/dependency-bootstrap-prompt.d.ts +24 -0
  23. package/dist/dependency-bootstrap-prompt.js +103 -0
  24. package/dist/dependency-bootstrap.d.ts +129 -0
  25. package/dist/dependency-bootstrap.js +566 -0
  26. package/dist/dir-clone.d.ts +33 -0
  27. package/dist/dir-clone.js +505 -0
  28. package/dist/doctor.js +21 -0
  29. package/dist/done.d.ts +10 -0
  30. package/dist/done.js +210 -0
  31. package/dist/file-sync.js +71 -22
  32. package/dist/format-bytes.d.ts +1 -0
  33. package/dist/format-bytes.js +14 -0
  34. package/dist/fs-utils.d.ts +4 -0
  35. package/dist/fs-utils.js +26 -0
  36. package/dist/git.d.ts +5 -0
  37. package/dist/git.js +50 -0
  38. package/dist/gji-bundle.mjs +6189 -1313
  39. package/dist/go-resolver.d.ts +35 -0
  40. package/dist/go-resolver.js +185 -0
  41. package/dist/go.d.ts +6 -2
  42. package/dist/go.js +270 -62
  43. package/dist/hooks.d.ts +2 -1
  44. package/dist/hooks.js +20 -8
  45. package/dist/hub.d.ts +31 -0
  46. package/dist/hub.js +287 -0
  47. package/dist/init.js +30 -22
  48. package/dist/install-prompt.d.ts +1 -0
  49. package/dist/install-prompt.js +3 -25
  50. package/dist/ls.js +9 -1
  51. package/dist/navigation-output.d.ts +11 -0
  52. package/dist/navigation-output.js +6 -0
  53. package/dist/new.d.ts +14 -2
  54. package/dist/new.js +422 -38
  55. package/dist/pr-open.js +2 -10
  56. package/dist/pr.d.ts +6 -2
  57. package/dist/pr.js +135 -30
  58. package/dist/pull-requests.d.ts +1 -0
  59. package/dist/pull-requests.js +32 -3
  60. package/dist/remove.js +22 -0
  61. package/dist/repo.d.ts +4 -0
  62. package/dist/repo.js +61 -6
  63. package/dist/run-hook.js +2 -0
  64. package/dist/safe-destination.d.ts +15 -0
  65. package/dist/safe-destination.js +166 -0
  66. package/dist/shell-completion.js +52 -13
  67. package/dist/slots.d.ts +8 -0
  68. package/dist/slots.js +61 -0
  69. package/dist/status.d.ts +2 -0
  70. package/dist/status.js +9 -1
  71. package/dist/sync-directories.d.ts +33 -0
  72. package/dist/sync-directories.js +97 -0
  73. package/dist/sync-plan.d.ts +16 -0
  74. package/dist/sync-plan.js +128 -0
  75. package/dist/sync.js +7 -13
  76. package/dist/task-command.d.ts +9 -0
  77. package/dist/task-command.js +29 -0
  78. package/dist/task.d.ts +9 -0
  79. package/dist/task.js +37 -0
  80. package/dist/terminal-text.d.ts +4 -0
  81. package/dist/terminal-text.js +72 -0
  82. package/dist/undo.d.ts +36 -0
  83. package/dist/undo.js +392 -0
  84. package/dist/warp.d.ts +3 -1
  85. package/dist/warp.js +32 -125
  86. package/dist/worktree-bootstrap.d.ts +35 -0
  87. package/dist/worktree-bootstrap.js +96 -0
  88. package/dist/worktree-info.d.ts +6 -1
  89. package/dist/worktree-info.js +14 -4
  90. package/dist/worktree-management.d.ts +1 -0
  91. package/dist/worktree-management.js +23 -4
  92. package/dist/worktree-picker.d.ts +24 -11
  93. package/dist/worktree-picker.js +176 -95
  94. package/dist/worktree-prompts.js +1 -1
  95. package/dist/worktree-source.d.ts +6 -0
  96. package/dist/worktree-source.js +1 -0
  97. package/dist/worktree-sources.d.ts +4 -0
  98. package/dist/worktree-sources.js +77 -0
  99. package/man/man1/gji-back.1 +1 -1
  100. package/man/man1/gji-clean.1 +1 -1
  101. package/man/man1/gji-completion.1 +1 -1
  102. package/man/man1/gji-config.1 +1 -1
  103. package/man/man1/gji-doctor.1 +1 -1
  104. package/man/man1/gji-done.1 +19 -0
  105. package/man/man1/gji-go.1 +12 -3
  106. package/man/man1/gji-history.1 +1 -1
  107. package/man/man1/gji-init.1 +1 -1
  108. package/man/man1/gji-ls.1 +1 -1
  109. package/man/man1/gji-new.1 +21 -3
  110. package/man/man1/gji-open.1 +1 -1
  111. package/man/man1/gji-pr.1 +7 -1
  112. package/man/man1/gji-remove.1 +3 -3
  113. package/man/man1/gji-root.1 +1 -1
  114. package/man/man1/gji-run-hook.1 +1 -1
  115. package/man/man1/gji-status.1 +1 -1
  116. package/man/man1/gji-sync-files.1 +1 -1
  117. package/man/man1/gji-sync.1 +1 -1
  118. package/man/man1/gji-task.1 +16 -0
  119. package/man/man1/gji-undo.1 +16 -0
  120. package/man/man1/gji-warp.1 +3 -6
  121. package/man/man1/gji.1 +17 -5
  122. package/package.json +3 -1
@@ -0,0 +1,96 @@
1
+ import { basename } from "node:path";
2
+ import { executeDependencyBootstrap, prepareDependencyBootstrap, } from "./dependency-bootstrap.js";
3
+ import { cloneDir } from "./dir-clone.js";
4
+ import { syncFiles } from "./file-sync.js";
5
+ import { extractHooks, runHook } from "./hooks.js";
6
+ import { maybeRunInstallPrompt, } from "./install-prompt.js";
7
+ import { assignWorktreeSlot } from "./slots.js";
8
+ import { executeSyncDirectoryPlan, } from "./sync-directories.js";
9
+ import { prepareSyncDirectoryPlan } from "./sync-plan.js";
10
+ export async function bootstrapWorktree(options) {
11
+ const dependencyMode = options.config.dependencyBootstrap ?? "off";
12
+ const dependencyPlan = await prepareDependencyBootstrap(dependencyMode, {
13
+ currentRoot: options.currentRoot,
14
+ detectionRoot: options.dependencyDetectionRoot,
15
+ repoRoot: options.repoRoot,
16
+ cargoBuildCommand: options.config.dependencyBuildCommand,
17
+ worktreePath: options.worktreePath,
18
+ });
19
+ const syncPlan = await prepareSyncDirectoryPlan(options.repoRoot, options.worktreePath, options.config.syncDirs ?? []);
20
+ const outcomes = await executeSyncDirectoryPlan(syncPlan, {
21
+ cloneDirectory: options.cloneDirectory ?? cloneDir,
22
+ repoRoot: options.repoRoot,
23
+ reporter: options.reporter,
24
+ });
25
+ const clonedDirs = outcomes.flatMap((outcome) => outcome.kind === "cloned" ? [outcome.directory] : []);
26
+ const skippedDirs = outcomes.flatMap((outcome) => outcome.kind === "skipped"
27
+ ? [{ dir: outcome.dir, reason: outcome.reason }]
28
+ : []);
29
+ const syncFileFailures = [];
30
+ for (const pattern of options.config.syncFiles ?? []) {
31
+ try {
32
+ await syncFiles(options.repoRoot, options.worktreePath, [pattern]);
33
+ }
34
+ catch (error) {
35
+ const message = `failed to sync file "${pattern}": ${toErrorMessage(error)}`;
36
+ if (!options.json)
37
+ options.reporter.write(`Warning: ${message}\n`);
38
+ syncFileFailures.push({
39
+ adapter: "syncFiles",
40
+ kind: "sync-file",
41
+ reason: "sync-file-failed",
42
+ state: "failed",
43
+ target: pattern,
44
+ message,
45
+ });
46
+ }
47
+ }
48
+ if (syncFileFailures.length > 0) {
49
+ for (const event of syncFileFailures)
50
+ options.reporter.dependency(event);
51
+ }
52
+ const dependencyBootstrap = syncFileFailures.length > 0
53
+ ? { mode: dependencyMode, ready: false, events: [] }
54
+ : await executeDependencyBootstrap(dependencyPlan, {
55
+ cloneDirectory: options.cloneDirectory,
56
+ repoRoot: options.repoRoot,
57
+ reporter: options.reporter,
58
+ stderr: options.commandStderr ?? options.reporter.write,
59
+ stdout: options.commandStdout,
60
+ seededDirectories: clonedDirs.map(({ dir }) => dir),
61
+ runCommand: options.runCommand,
62
+ });
63
+ if (!dependencyBootstrap.ready) {
64
+ return {
65
+ clonedDirs,
66
+ dependencyBootstrap,
67
+ ready: false,
68
+ syncFileFailures,
69
+ skippedDirs,
70
+ };
71
+ }
72
+ if (dependencyMode === "off" &&
73
+ ["default", "legacy"].includes(options.dependencyBootstrapPolicy?.source ?? "default")) {
74
+ await maybeRunInstallPrompt(options.worktreePath, options.repoRoot, options.config, options.reporter.write, options.installDependencies, options.nonInteractive);
75
+ }
76
+ const hooks = extractHooks(options.config);
77
+ const slot = await assignWorktreeSlot(options.repoRoot, options.worktreePath);
78
+ await runHook(hooks["after-create"], options.worktreePath, {
79
+ branch: options.branch,
80
+ path: options.worktreePath,
81
+ repo: basename(options.repoRoot),
82
+ slot,
83
+ }, options.reporter.write, options.json
84
+ ? () => undefined
85
+ : (options.commandStdout ?? ((chunk) => process.stdout.write(chunk))));
86
+ return {
87
+ clonedDirs,
88
+ dependencyBootstrap,
89
+ ready: true,
90
+ syncFileFailures: [],
91
+ skippedDirs,
92
+ };
93
+ }
94
+ function toErrorMessage(error) {
95
+ return error instanceof Error ? error.message : String(error);
96
+ }
@@ -2,14 +2,18 @@ import { type WorktreeHealth } from "./git.js";
2
2
  import type { WorktreeEntry } from "./repo.js";
3
3
  export interface WorktreeInfo extends WorktreeEntry {
4
4
  lastCommitTimestamp: number | null;
5
+ slot: number | null;
5
6
  status: WorktreeHealth["status"] | "unknown";
7
+ task: string | null;
6
8
  upstream: UpstreamState;
7
9
  }
8
10
  export interface SerializedWorktreeInfo {
9
11
  branch: string | null;
10
12
  lastCommitTimestamp: number | null;
11
13
  path: string;
14
+ slot: number | null;
12
15
  status: WorktreeInfo["status"];
16
+ task: string | null;
13
17
  upstream: UpstreamState;
14
18
  }
15
19
  export type UpstreamState = {
@@ -26,7 +30,8 @@ export type UpstreamState = {
26
30
  kind: "unknown";
27
31
  };
28
32
  export declare function readWorktreeInfos(worktrees: WorktreeEntry[]): Promise<WorktreeInfo[]>;
33
+ export declare function readWorktreeInfo(worktree: WorktreeEntry): Promise<WorktreeInfo>;
29
34
  export declare function serializeWorktreeInfo(info: WorktreeInfo): SerializedWorktreeInfo;
30
35
  export declare function formatUpstreamState(upstream: UpstreamState): string;
31
36
  export declare function formatLastCommit(timestampSeconds: number | null): string;
32
- export declare function formatRelativeAge(timestampSeconds: number): string;
37
+ export declare function formatRelativeAge(timestampSeconds: number, nowSeconds?: number): string;
@@ -1,4 +1,6 @@
1
1
  import { readBranchLastCommitTimestamp, readWorktreeHealth, } from "./git.js";
2
+ import { getWorktreeSlot } from "./slots.js";
3
+ import { readTask } from "./task.js";
2
4
  const MAX_WORKTREE_INFO_READ_CONCURRENCY = 8;
3
5
  export async function readWorktreeInfos(worktrees) {
4
6
  return mapWithConcurrency(worktrees, MAX_WORKTREE_INFO_READ_CONCURRENCY, readWorktreeInfo);
@@ -18,19 +20,25 @@ async function mapWithConcurrency(items, limit, mapper) {
18
20
  await Promise.all(Array.from({ length: Math.min(limit, items.length) }, () => readNext()));
19
21
  return results;
20
22
  }
21
- async function readWorktreeInfo(worktree) {
22
- const [healthResult, lastCommitResult] = await Promise.allSettled([
23
+ export async function readWorktreeInfo(worktree) {
24
+ const [healthResult, lastCommitResult, slotResult, taskResult] = await Promise.allSettled([
23
25
  readWorktreeHealth(worktree.path),
24
26
  worktree.branch === null
25
27
  ? null
26
28
  : readBranchLastCommitTimestamp(worktree.path, worktree.branch),
29
+ getWorktreeSlot(worktree.path),
30
+ readTask(worktree.path),
27
31
  ]);
28
32
  const health = healthResult.status === "fulfilled" ? healthResult.value : null;
29
33
  const lastCommitTimestamp = lastCommitResult.status === "fulfilled" ? lastCommitResult.value : null;
34
+ const slot = slotResult.status === "fulfilled" ? slotResult.value : null;
35
+ const task = taskResult.status === "fulfilled" ? (taskResult.value?.task ?? null) : null;
30
36
  return {
31
37
  ...worktree,
32
38
  lastCommitTimestamp,
39
+ slot,
33
40
  status: health?.status ?? "unknown",
41
+ task,
34
42
  upstream: buildUpstreamState(worktree.branch, health),
35
43
  };
36
44
  }
@@ -58,7 +66,9 @@ export function serializeWorktreeInfo(info) {
58
66
  branch: info.branch,
59
67
  lastCommitTimestamp: info.lastCommitTimestamp,
60
68
  path: info.path,
69
+ slot: info.slot,
61
70
  status: info.status,
71
+ task: info.task,
62
72
  upstream: info.upstream,
63
73
  };
64
74
  }
@@ -94,8 +104,8 @@ export function formatLastCommit(timestampSeconds) {
94
104
  ? "n/a"
95
105
  : formatRelativeAge(timestampSeconds);
96
106
  }
97
- export function formatRelativeAge(timestampSeconds) {
98
- const ageSeconds = Math.max(0, Math.floor(Date.now() / 1000) - timestampSeconds);
107
+ export function formatRelativeAge(timestampSeconds, nowSeconds = Math.floor(Date.now() / 1000)) {
108
+ const ageSeconds = Math.max(0, nowSeconds - timestampSeconds);
99
109
  const units = [
100
110
  { label: "y", seconds: 365 * 24 * 60 * 60 },
101
111
  { label: "mo", seconds: 30 * 24 * 60 * 60 },
@@ -9,5 +9,6 @@ export declare function forceRemoveWorktree(repoRoot: string, worktreePath: stri
9
9
  export declare function deleteBranch(repoRoot: string, branch: string): Promise<void>;
10
10
  export declare function forceDeleteBranch(repoRoot: string, branch: string): Promise<void>;
11
11
  export declare function isWorktreeForceRemovalError(error: unknown): boolean;
12
+ export declare function isSubmoduleWorktreeRemovalError(error: unknown): boolean;
12
13
  export declare function isWorktreeDeletionError(error: unknown): boolean;
13
14
  export declare function isBranchUnmergedError(error: unknown): boolean;
@@ -21,12 +21,14 @@ export async function removeWorktree(repoRoot, worktreePath) {
21
21
  }
22
22
  export async function forceRemoveWorktree(repoRoot, worktreePath) {
23
23
  try {
24
- await execFileAsync("git", ["worktree", "remove", "--force", worktreePath], {
25
- cwd: repoRoot,
26
- env: GIT_ENV,
27
- });
24
+ await removeWorktreeWithForce(repoRoot, worktreePath);
28
25
  }
29
26
  catch (error) {
27
+ if (isSubmoduleWorktreeRemovalError(error)) {
28
+ await deinitializeSubmodules(worktreePath);
29
+ await removeWorktreeWithForce(repoRoot, worktreePath);
30
+ return;
31
+ }
30
32
  const worktreeIsStillRegistered = (await listWorktrees(repoRoot)).some((worktree) => worktree.path === worktreePath);
31
33
  if (worktreeIsStillRegistered) {
32
34
  throw error;
@@ -34,6 +36,18 @@ export async function forceRemoveWorktree(repoRoot, worktreePath) {
34
36
  await rm(worktreePath, { force: true, recursive: true });
35
37
  }
36
38
  }
39
+ async function removeWorktreeWithForce(repoRoot, worktreePath) {
40
+ await execFileAsync("git", ["worktree", "remove", "--force", worktreePath], {
41
+ cwd: repoRoot,
42
+ env: GIT_ENV,
43
+ });
44
+ }
45
+ async function deinitializeSubmodules(worktreePath) {
46
+ await execFileAsync("git", ["submodule", "deinit", "--force", "--all"], {
47
+ cwd: worktreePath,
48
+ env: GIT_ENV,
49
+ });
50
+ }
37
51
  export async function deleteBranch(repoRoot, branch) {
38
52
  await execFileAsync("git", ["branch", "-d", branch], {
39
53
  cwd: repoRoot,
@@ -51,8 +65,13 @@ export function isWorktreeForceRemovalError(error) {
51
65
  return false;
52
66
  }
53
67
  return (error.stderr.includes("contains modified or untracked files") ||
68
+ isSubmoduleWorktreeRemovalError(error) ||
54
69
  isWorktreeDeletionError(error));
55
70
  }
71
+ export function isSubmoduleWorktreeRemovalError(error) {
72
+ return (hasStderr(error) &&
73
+ error.stderr.includes("working trees containing submodules cannot be moved or removed"));
74
+ }
56
75
  export function isWorktreeDeletionError(error) {
57
76
  return hasStderr(error) && error.stderr.includes("failed to delete");
58
77
  }
@@ -1,25 +1,24 @@
1
1
  import type { Readable, Writable } from "node:stream";
2
2
  import { type PullRequestInfo } from "./pull-requests.js";
3
3
  import type { WorktreeEntry } from "./repo.js";
4
- export interface WorktreePromptSource {
5
- repoRoot?: string;
6
- repoName: string;
7
- worktree: WorktreeEntry;
8
- }
4
+ import type { WorktreeSource } from "./worktree-source.js";
5
+ export type WorktreePromptSource = WorktreeSource;
9
6
  export interface WorktreePromptEntry extends WorktreeEntry {
10
7
  group: "recent" | "other";
11
8
  label: string;
12
9
  metadata?: string | null;
13
- pullRequestNumbers?: number[];
14
- pullRequestUrls?: string[];
10
+ pullRequests?: PullRequestInfo[];
15
11
  repoName: string;
12
+ task?: string | null;
16
13
  }
17
14
  export type QueryWorktreePullRequests = (repoRoot: string, sourceBranch: string) => Promise<PullRequestInfo[]>;
18
15
  export type QueryRepositoryPullRequests = (repoRoot: string) => Promise<PullRequestInfo[]>;
19
16
  export interface BuildWorktreePromptEntriesDependencies {
17
+ metadata?: WorktreeMetadataMode;
20
18
  queryPullRequests?: QueryWorktreePullRequests;
21
19
  queryRepositoryPullRequests?: QueryRepositoryPullRequests;
22
20
  }
21
+ export type WorktreeMetadataMode = "full" | "fast";
23
22
  export interface WorktreePickerIO {
24
23
  input?: Readable & {
25
24
  isTTY?: boolean;
@@ -30,8 +29,22 @@ export interface WorktreePickerIO {
30
29
  rows?: number;
31
30
  };
32
31
  }
33
- export declare function buildWorktreePromptEntries(sources: WorktreePromptSource[], dependencies?: BuildWorktreePromptEntriesDependencies): Promise<WorktreePromptEntry[]>;
34
- export declare function resolveWorktreeQuery(sources: WorktreePromptSource[], query: string): WorktreePromptSource | null;
35
- export declare function promptForSingleWorktree(message: string, worktrees: WorktreePromptEntry[], io?: WorktreePickerIO): Promise<string | null>;
32
+ export interface WorktreePromptScope {
33
+ label: string;
34
+ toggle: () => Promise<WorktreePromptScopeResult>;
35
+ toggleLabel: string;
36
+ }
37
+ export interface WorktreePromptScopeResult {
38
+ entries: WorktreePromptEntry[];
39
+ label: string;
40
+ toggleLabel: string;
41
+ }
42
+ export declare function buildWorktreePromptEntries(sources: WorktreeSource[], dependencies?: BuildWorktreePromptEntriesDependencies): Promise<WorktreePromptEntry[]>;
43
+ export declare function resolveWorktreeQuery(sources: WorktreeSource[], query: string): WorktreeSource | null;
44
+ export declare function resolveWorktreeQueryMatches(sources: WorktreeSource[], query: string): WorktreeSource[];
45
+ export declare function resolveExactWorktreeQueryMatches(sources: WorktreeSource[], query: string): WorktreeSource[];
46
+ export declare function promptForSingleWorktree(message: string, worktrees: WorktreePromptEntry[], io?: WorktreePickerIO & {
47
+ scope?: WorktreePromptScope;
48
+ }): Promise<string | null>;
36
49
  export declare function promptForMultipleWorktrees(message: string, worktrees: WorktreePromptEntry[], io?: WorktreePickerIO): Promise<string[] | null>;
37
- export declare function formatWorktreeBranchLabel(branch: string | null, pullRequestNumbers?: number[]): string;
50
+ export declare function formatWorktreeBranchLabel(branch: string | null, pullRequests?: PullRequestInfo[]): string;