opencode-self-improvement 0.13.0 → 0.13.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/repokey.ts +25 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-self-improvement",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "description": "Durable memory for opencode: remember facts, decisions, and commands across sessions, plus a one-command per-repo setup (/repo-init).",
5
5
  "main": "index.ts",
6
6
  "exports": {
package/src/repokey.ts CHANGED
@@ -7,13 +7,16 @@
7
7
  // Two keys, both cheap, with opposite failure modes:
8
8
  // key — sha1 of the normalized origin URL: survives re-clone, moves, and
9
9
  // export/import to another machine. Absent when the repo has no
10
- // origin (fresh or remote-less), where the path is used as the key.
11
- // path — resolved git toplevel: the secondary match, so rows stamped
12
- // before an origin was added keep recognizing their repo.
10
+ // origin (fresh or remote-less): sha1 of the NORMALIZED resolved
11
+ // path instead, so repo= is always a bare token — a raw path with
12
+ // a space gets logfmt-quoted, which breaks naive field extraction
13
+ // and can't be hash-compared (#92). path stays the human-readable
14
+ // secondary, so rows stamped before the hash keep matching.
13
15
  // Rows carry no stamp when their writer had no scope (viewer process,
14
16
  // tests) and legacy rows predate the field: both read as GLOBAL — visible
15
17
  // everywhere — which keeps every upgrade non-breaking.
16
18
  import { createHash } from "node:crypto";
19
+ import { realpathSync } from "node:fs";
17
20
 
18
21
  export interface RepoScope {
19
22
  key: string;
@@ -56,14 +59,31 @@ function git(args: string[], cwd: string): string | null {
56
59
  }
57
60
  }
58
61
 
62
+ // Normalize a directory for hashing: symlinks, junctions, and Windows 8.3
63
+ // aliases collapse to the real path (realpath), separators unify to "/",
64
+ // a trailing separator disappears, and case folds ONLY on the
65
+ // case-insensitive filesystems (win32/darwin) where two spellings are the
66
+ // same directory — Linux folds nothing, there "Foo" and "foo" are two dirs.
67
+ export function normalizeDirPath(p: string): string {
68
+ let r = p;
69
+ try {
70
+ r = realpathSync(r);
71
+ } catch {
72
+ // deleted/unreadable mid-resolve: hash the given spelling rather than throw
73
+ }
74
+ r = r.replace(/\\/g, "/").replace(/\/+$/, "");
75
+ if (process.platform === "win32" || process.platform === "darwin") r = r.toLowerCase();
76
+ return r || "/";
77
+ }
78
+
59
79
  // Resolve the current repo from any start dir (never throws; a non-git dir
60
- // simply scopes by its own path).
80
+ // simply scopes by the hash of its own normalized path).
61
81
  export function resolveRepo(startDir: string): RepoScope {
62
82
  const path = git(["git", "rev-parse", "--show-toplevel"], startDir) ?? startDir;
63
83
  const remote = git(["git", "remote", "get-url", "origin"], path);
64
84
  const key = remote
65
85
  ? createHash("sha1").update(normalizeRemote(remote)).digest("hex").slice(0, 12)
66
- : path;
86
+ : createHash("sha1").update(normalizeDirPath(path)).digest("hex").slice(0, 12);
67
87
  return { key, path };
68
88
  }
69
89