my-durable 0.0.81 → 0.0.83

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.
@@ -77,13 +77,21 @@ const CHILD_ENV_ALLOWLIST = ["PATH", "HOME", "USER", "SHELL", "TMPDIR", "LANG",
77
77
  // execFile `env` REPLACES the whole environment, and on win32 git/gh resolve
78
78
  // home (USERPROFILE chain), config (APPDATA), temp (TEMP/TMP) and TLS
79
79
  // (SystemRoot) from these — without them commit identity and gh auth break.
80
+ // git-for-windows resolves a commit identity from getpwuid(), which its compat
81
+ // layer fills from USERNAME/USERDOMAIN and gethostname()→COMPUTERNAME. Leaving
82
+ // those out made every device-side git call see "Author identity unknown" while
83
+ // the same repo committed fine in a terminal (live report) — the identity was
84
+ // there, the environment was not. They are not secrets; they are the account.
80
85
  const WIN32_CHILD_ENV_ALLOWLIST = [
81
86
  ...CHILD_ENV_ALLOWLIST,
87
+ "USERNAME", "USERDOMAIN", "LOGNAME", "COMPUTERNAME", "WINDIR",
82
88
  "SYSTEMROOT", "SYSTEMDRIVE", "COMSPEC", "PATHEXT",
83
89
  "TEMP", "TMP", "USERPROFILE", "HOMEDRIVE", "HOMEPATH",
84
90
  "APPDATA", "LOCALAPPDATA", "PROGRAMFILES", "PROGRAMDATA",
85
91
  ];
86
- const childEnv = (): NodeJS.ProcessEnv => {
92
+ export const childEnvKeys = (): string[] =>
93
+ process.platform === "win32" ? WIN32_CHILD_ENV_ALLOWLIST : CHILD_ENV_ALLOWLIST;
94
+ export const childEnv = (): NodeJS.ProcessEnv => {
87
95
  const allow = process.platform === "win32" ? WIN32_CHILD_ENV_ALLOWLIST : CHILD_ENV_ALLOWLIST;
88
96
  return Object.fromEntries(allow.flatMap((k) => (process.env[k] ? [[k, process.env[k]]] : [])));
89
97
  }
@@ -117,6 +125,70 @@ export function setGitExecForTests(fn?: typeof execFile) {
117
125
  execFileImpl = fn ?? execFile;
118
126
  }
119
127
 
128
+ /** Forges the panel can speak to. Only GitHub has a CLI we drive; the rest
129
+ * are link-first (the operator opens the MR/PR page), because `gh` is
130
+ * GitHub-only and a GitLab origin silently produced empty PR lists. */
131
+ export type Forge = "github" | "gitlab" | "bitbucket" | "other";
132
+
133
+ export interface ParsedRemote {
134
+ host: string;
135
+ /** Everything after the host, without a trailing .git or leading slash. */
136
+ path: string;
137
+ forge: Forge;
138
+ webUrl: string;
139
+ }
140
+
141
+ /** Parse ANY git origin spelling into host + path + browser URL.
142
+ * Handles `git@host:ns/repo.git`, `ssh://git@host:2222/ns/repo.git`,
143
+ * `https://user:token@host/ns/sub/repo.git`, and path-only remotes (which
144
+ * have no browser). GitLab namespaces nest arbitrarily — never slice to two. */
145
+ export function parseRemote(url?: string): ParsedRemote | undefined {
146
+ const raw = (url ?? "").trim();
147
+ if (!raw) return undefined;
148
+ let host = "";
149
+ let path = "";
150
+ const scp = raw.match(/^(?:[A-Za-z0-9._~-]+@)?([^/:]+):(?!\/\/)(.+)$/); // git@host:ns/repo
151
+ if (scp && !/^[A-Za-z]:[\\/]/.test(raw)) {
152
+ host = scp[1]!;
153
+ path = scp[2]!;
154
+ } else if (/^[A-Za-z][A-Za-z0-9+.-]*:\/\//.test(raw)) {
155
+ try {
156
+ const u = new URL(raw);
157
+ host = u.hostname;
158
+ path = u.pathname.replace(/^\/+/, "");
159
+ } catch {
160
+ return undefined;
161
+ }
162
+ } else {
163
+ return undefined; // a filesystem remote (/srv/git/x.git, ..\repo) has no browser
164
+ }
165
+ path = path.replace(/\/+$/, "").replace(/\.git$/, "");
166
+ if (!host || !path) return undefined;
167
+ const h = host.toLowerCase();
168
+ const forge: Forge = h === "github.com" || h.endsWith(".github.com") || /(^|\.)github\./.test(h)
169
+ ? "github"
170
+ : /gitlab/.test(h) || /(^|\.)gitlab\./.test(h)
171
+ ? "gitlab"
172
+ : /bitbucket/.test(h)
173
+ ? "bitbucket"
174
+ : "other";
175
+ const scheme = /^http:\/\//.test(raw) ? "http" : "https";
176
+ return { host, path, forge, webUrl: `${scheme}://${host}/${path}` };
177
+ }
178
+
179
+ /** The browser URL that starts a new merge/pull request for `branch` into
180
+ * `base` on this forge — the only cross-forge action that needs no CLI. */
181
+ export function newChangeUrl(remote: ParsedRemote | undefined, branch: string, base?: string): string | undefined {
182
+ if (!remote || !branch) return undefined;
183
+ const br = encodeURIComponent(branch);
184
+ const bs = base ? encodeURIComponent(base) : undefined;
185
+ if (remote.forge === "github") return `${remote.webUrl}/compare/${bs ?? "main"}...${br}?expand=1`;
186
+ if (remote.forge === "gitlab")
187
+ return `${remote.webUrl}/-/merge_requests/new?merge_request%5Bsource_branch%5D=${br}${bs ? `&merge_request%5Btarget_branch%5D=${bs}` : ""}`;
188
+ if (remote.forge === "bitbucket") return `${remote.webUrl}/pull-requests/new?source=${br}${bs ? `&dest=${bs}` : ""}`;
189
+ return undefined; // unknown forge: the UI offers the plain repo link instead
190
+ }
191
+
120
192
  /** The ONE stderr that legitimately means "no repo here" — anything else
121
193
  * (git missing, permission, timeout) is a failure we must not flatten into
122
194
  * repo:false. Reported live: a Windows daemon without git on PATH showed
@@ -176,8 +248,14 @@ export interface GitStatus {
176
248
  merge?: boolean;
177
249
  /** Unmerged paths (UU/AA/DD/AU/UA/DU/UD). */
178
250
  conflicts?: number;
179
- /** Commit identity from config — warn before committing without one. */
251
+ /** The identity a commit would be authored with, as GIT resolves it. */
180
252
  identity?: { name?: string; email?: string };
253
+ /** False ⇔ git itself would refuse to commit (no identity resolvable at all). */
254
+ identityComplete?: boolean;
255
+ /** Which forge the origin belongs to — the UI must not assume GitHub. */
256
+ forge?: Forge;
257
+ /** Browser URL of the repo on that forge ("" when origin is unparseable). */
258
+ webUrl?: string;
181
259
  /** `origin` URL, parsed by the UI into an open-in-remote link. */
182
260
  remoteUrl?: string;
183
261
  /** Local branches for pickers — nobody should TYPE a name that exists. */
@@ -374,7 +452,7 @@ async function statusOnce(path: string, key: string): Promise<GitStatus> {
374
452
  out.root = root;
375
453
  // Everything after toplevel runs in PARALLEL — status is the long pole
376
454
  // (20s+ on big Windows checkouts) and must not wait for four fast calls.
377
- const [branchP, headP, statusP, gitDirP, wlP, branchesP, numWorkP, numIdxP, mergeP, nameP, emailP, remoteP] = await Promise.allSettled([
455
+ const [branchP, headP, statusP, gitDirP, wlP, branchesP, numWorkP, numIdxP, mergeP, identP, remoteP] = await Promise.allSettled([
378
456
  g(["branch", "--show-current"]),
379
457
  g(["log", "-1", "--pretty=%h%x09%s"]),
380
458
  g(["--no-optional-locks", "status", "--porcelain=v1", "-z", "-b"], GIT_SLOW_TIMEOUT),
@@ -385,8 +463,13 @@ async function statusOnce(path: string, key: string): Promise<GitStatus> {
385
463
  g(["--no-optional-locks", "diff", "--numstat", "-z", "--cached", "--no-renames"]),
386
464
  // MERGE_HEAD exists ⇔ a merge is waiting to be resolved.
387
465
  g(["rev-parse", "-q", "--verify", "MERGE_HEAD"]),
388
- g(["config", "user.name"]),
389
- g(["config", "user.email"]),
466
+ // ONE authoritative probe: `git var GIT_AUTHOR_IDENT` is git's own
467
+ // resolution — every config level, GIT_AUTHOR_*/EMAIL env, and the
468
+ // getpwuid()/hostname fallback a plain commit would use. The old pair of
469
+ // `git config user.name/user.email` reads only saw config FILES, so a
470
+ // machine whose identity git derives (Windows account) was told to "set
471
+ // user.name" although `git commit` there works.
472
+ g(["var", "GIT_AUTHOR_IDENT"]),
390
473
  g(["remote", "get-url", "origin"]),
391
474
  ]);
392
475
  const branch = branchP.status === "fulfilled" ? branchP.value : "";
@@ -435,11 +518,23 @@ async function statusOnce(path: string, key: string): Promise<GitStatus> {
435
518
  }
436
519
  out.merge = mergeP.status === "fulfilled";
437
520
  out.conflicts = body.filter((r) => /^(UU|AA|DD|AU|UA|DU|UD)/.test(r)).length;
521
+ // "Name <email> 1730000000 +0700" — the timestamp/tz tail is not identity.
522
+ const identLine = identP.status === "fulfilled" ? identP.value.trim() : "";
523
+ const identMatch = identLine.match(/^(.*?)\s*<([^>]*)>/);
438
524
  out.identity = {
439
- name: nameP.status === "fulfilled" ? nameP.value.trim() || undefined : undefined,
440
- email: emailP.status === "fulfilled" ? emailP.value.trim() || undefined : undefined,
525
+ name: identMatch?.[1]?.trim() || undefined,
526
+ email: identMatch?.[2]?.trim() || undefined,
441
527
  };
528
+ // A commit would be REFUSED (not merely unconfigured) when git cannot
529
+ // resolve an identity at all. That is the only case worth warning about.
530
+ out.identityComplete = Boolean(identMatch?.[1]?.trim() && identMatch?.[2]?.trim());
531
+ if (!out.identityComplete) delete out.identity;
442
532
  if (remoteP.status === "fulfilled") out.remoteUrl = remoteP.value.trim() || undefined;
533
+ const parsed = parseRemote(out.remoteUrl);
534
+ if (parsed) {
535
+ out.forge = parsed.forge;
536
+ out.webUrl = parsed.webUrl;
537
+ }
443
538
  // ±n per file: worktree-vs-index numstat for unstaged paths, cached for staged.
444
539
  const numstat = (raw: string) => {
445
540
  const m = new Map<string, { a: number; d: number }>();
@@ -821,7 +821,13 @@ export class Store {
821
821
  process.platform === "win32" ? p.replace(/\//g, "\\").replace(/\\+$/, "").toLowerCase() : p;
822
822
  const sep = process.platform === "win32" ? "\\" : "/";
823
823
  const n = norm(root);
824
- return (await store.startDirRoots()).some((r) => {
824
+ // SAME set as containedPath()/browse(): start dirs UNION the folders
825
+ // that already host a session. Guarding walk-up with start dirs alone
826
+ // left the git surface refusing a folder the device itself advertises
827
+ // in info.gitDirs — the panel then got {repo:true} with no branch, no
828
+ // files, no identity, and reported the folder as empty while the agent
829
+ // was committing in it (live: a D:\ session on a narrowed start-dir list).
830
+ return (await store.servedRoots()).some((r) => {
825
831
  const b = norm(r);
826
832
  return !!b && (n === b || n.startsWith(b + sep));
827
833
  });