@cueloop/daemon 0.1.0-alpha.65 → 0.1.0-alpha.66

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": "@cueloop/daemon",
3
- "version": "0.1.0-alpha.65",
3
+ "version": "0.1.0-alpha.66",
4
4
  "description": "The cueloop session daemon and its client: socket protocol, atomic store, resumable waits",
5
5
  "homepage": "https://github.com/mmurakaru/cueloop#readme",
6
6
  "bugs": {
@@ -35,7 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
- "@cueloop/schema": "0.1.0-alpha.65",
38
+ "@cueloop/schema": "0.1.0-alpha.66",
39
39
  "@pierre/diffs": "^1.3.6",
40
40
  "valibot": "^1.4.2"
41
41
  },
package/src/review.ts CHANGED
@@ -35,12 +35,33 @@ async function git(args: string[], cwd: string): Promise<string | null> {
35
35
  }
36
36
  }
37
37
 
38
- /** Workspace key resolution: repo root + branch from the cwd. */
38
+ /** The oldest root commit reachable from HEAD; the project key that survives moving or re-cloning the repo. */
39
+ function earliestRootCommit(revList: string | null): string | undefined {
40
+ if (!revList) return undefined;
41
+ const roots = revList.split("\n").filter((line) => line.length > 0);
42
+
43
+ // --date-order lists newest first, so the last root is the earliest
44
+ return roots.at(-1);
45
+ }
46
+
47
+ /** Workspace key resolution: repo root, branch, and the project identity (root commit + remote) from the cwd. */
39
48
  export async function resolveWorkspace(cwd = process.cwd()): Promise<WorkspaceKey> {
40
49
  const repoRoot = (await git(["rev-parse", "--show-toplevel"], cwd)) ?? cwd;
41
50
  const branch = (await git(["rev-parse", "--abbrev-ref", "HEAD"], cwd)) ?? "detached";
42
-
43
- return { repoRoot, branch };
51
+ // a shallow clone's oldest commit is the graft boundary, not the true root, so
52
+ // it would key a different project than a full clone - leave it unset instead
53
+ const shallow = (await git(["rev-parse", "--is-shallow-repository"], cwd)) === "true";
54
+ const rootCommit = shallow
55
+ ? undefined
56
+ : earliestRootCommit(await git(["rev-list", "--max-parents=0", "--date-order", "HEAD"], cwd));
57
+ const remote = await git(["remote", "get-url", "origin"], cwd);
58
+
59
+ const workspace: WorkspaceKey = { repoRoot, branch };
60
+ // a repo with no commits (or a shallow clone) has no reliable root, so the thread stays standalone
61
+ if (rootCommit) workspace.rootCommit = rootCommit;
62
+ if (remote) workspace.remote = remote;
63
+
64
+ return workspace;
44
65
  }
45
66
 
46
67
  function firstHeading(markdown: string): string | undefined {
@@ -221,7 +221,12 @@ describe("wire pins", () => {
221
221
  resolvedAt: "now",
222
222
  };
223
223
  const fullRevision: Required<Revision> = { revision: 1, content: "# P", submittedAt: "now" };
224
- const fullWorkspace: Required<WorkspaceKey> = { repoRoot: "/repo", branch: "main" };
224
+ const fullWorkspace: Required<WorkspaceKey> = {
225
+ repoRoot: "/repo",
226
+ branch: "main",
227
+ rootCommit: "11e7abbcf507a13ae5e4e7559c4b42dbb52237fe",
228
+ remote: "git@github.com:acme/repo.git",
229
+ };
225
230
  const fullIdentity: Required<Identity> = {
226
231
  id: "SHA256:abc",
227
232
  provider: "ssh",
package/src/validate.ts CHANGED
@@ -44,6 +44,8 @@ const NonEmpty = v.pipe(v.string(), v.minLength(1));
44
44
  export const WorkspaceSchema = v.object({
45
45
  repoRoot: NonEmpty,
46
46
  branch: NonEmpty,
47
+ rootCommit: v.optional(NonEmpty),
48
+ remote: v.optional(NonEmpty),
47
49
  } satisfies EntriesOf<WorkspaceKey>);
48
50
 
49
51
  export const ArtifactMetaSchema = v.object({