glimmervoid 0.48.4-next.354 → 0.48.4-next.356

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 (93) hide show
  1. package/dist/bin/glimmervoid.js +13 -7
  2. package/dist/chunks/{agent-api-cli-BkmHQXK6.js → agent-api-cli-NPWGP-aG.js} +1 -1
  3. package/dist/chunks/{agent-api-cli-dXQTG2GO.js → agent-api-cli-wDSMdFsQ.js} +1 -1
  4. package/dist/chunks/{agent-api-core-D_f8pw2Q.js → agent-api-core-p7mq8Qw9.js} +10 -0
  5. package/dist/chunks/commit-sessions-DSp1CbMW.js +316 -0
  6. package/dist/chunks/{main-MOKPGavF.js → main-TpY_0KBx.js} +31 -278
  7. package/dist/chunks/{node-pty-preflight-DbfWP9Rc.js → node-pty-preflight-CQNBCDVM.js} +2 -28
  8. package/dist/chunks/{pair-cli-CkRuFX6c.js → pair-cli-pkc8mHbi.js} +2 -1
  9. package/dist/chunks/{remote-config-BTgp5KoH.js → pairings-store-CaQ2CQTr.js} +1 -89
  10. package/dist/chunks/remote-config-Dcejfz01.js +90 -0
  11. package/dist/chunks/{settings-cli-nrO-53SB.js → settings-cli-BRC0xzME.js} +1 -1
  12. package/dist/chunks/{ssh-sign-cli-BYQ8vj-c.js → ssh-sign-cli-KwmWJqa-.js} +1 -1
  13. package/dist/chunks/text-core-rXHoQWP9.js +28 -0
  14. package/dist/chunks/why-cli-cYNMNYwv.js +110 -0
  15. package/dist/client/assets/{benchmark-panel-BE4qC6f7.js → benchmark-panel-CskPxpnB.js} +1 -1
  16. package/dist/client/assets/benchmark-panel-CskPxpnB.js.br +0 -0
  17. package/dist/client/assets/{boards-view-D57L6U0h.js → boards-view-D6TgkWz8.js} +1 -1
  18. package/dist/client/assets/boards-view-D6TgkWz8.js.br +0 -0
  19. package/dist/client/assets/{community-panel-CskJ8AP8.js → community-panel-Dp6JbZlI.js} +1 -1
  20. package/dist/client/assets/community-panel-Dp6JbZlI.js.br +0 -0
  21. package/dist/client/assets/{dialogs-DfVIXl6X.js → dialogs-BMnB2T0I.js} +1 -1
  22. package/dist/client/assets/dialogs-BMnB2T0I.js.br +0 -0
  23. package/dist/client/assets/{doc-editor-ui-BFtUHES4.js → doc-editor-ui-BuluZVBd.js} +1 -1
  24. package/dist/client/assets/doc-editor-ui-BuluZVBd.js.br +0 -0
  25. package/dist/client/assets/{feature-hint-DyAk6e1q.js → feature-hint-BkQRQM38.js} +1 -1
  26. package/dist/client/assets/feature-hint-BkQRQM38.js.br +0 -0
  27. package/dist/client/assets/{first-run-checklist-CkkQMeVP.js → first-run-checklist-D18Zr_JZ.js} +1 -1
  28. package/dist/client/assets/first-run-checklist-D18Zr_JZ.js.br +0 -0
  29. package/dist/client/assets/{hooks-panel-D7VDfDhJ.js → hooks-panel-DsMDneXH.js} +1 -1
  30. package/dist/client/assets/hooks-panel-DsMDneXH.js.br +0 -0
  31. package/dist/client/assets/{index-DlcYI9Mg.js → index-q3RXVB7y.js} +5 -5
  32. package/dist/client/assets/index-q3RXVB7y.js.br +0 -0
  33. package/dist/client/assets/{issues-panel-4iTdSU0H.js → issues-panel-BFAadZEP.js} +1 -1
  34. package/dist/client/assets/issues-panel-BFAadZEP.js.br +0 -0
  35. package/dist/client/assets/{my-prs-panel-DWcYzbAJ.js → my-prs-panel-BjjtKga5.js} +1 -1
  36. package/dist/client/assets/my-prs-panel-BjjtKga5.js.br +0 -0
  37. package/dist/client/assets/{nyan-cat-DDspnz8S.js → nyan-cat-BAl07LPJ.js} +1 -1
  38. package/dist/client/assets/nyan-cat-BAl07LPJ.js.br +0 -0
  39. package/dist/client/assets/{phone-shell-DD2tkq1J.js → phone-shell-T2MjGOlk.js} +1 -1
  40. package/dist/client/assets/phone-shell-T2MjGOlk.js.br +0 -0
  41. package/dist/client/assets/{plan-face-CuHG-XHp.js → plan-face-p1ie7IrL.js} +1 -1
  42. package/dist/client/assets/plan-face-p1ie7IrL.js.br +0 -0
  43. package/dist/client/assets/{pr-queue-columns-Wpvt5lpP.js → pr-queue-columns-0noTXDSd.js} +1 -1
  44. package/dist/client/assets/pr-queue-columns-0noTXDSd.js.br +0 -0
  45. package/dist/client/assets/{radar-panel-D0xCJ-qW.js → radar-panel-B2JwPDON.js} +1 -1
  46. package/dist/client/assets/radar-panel-B2JwPDON.js.br +0 -0
  47. package/dist/client/assets/{repo-roots-adder-C70cwNtz.js → repo-roots-adder-BlaDr83Y.js} +1 -1
  48. package/dist/client/assets/repo-roots-adder-BlaDr83Y.js.br +0 -0
  49. package/dist/client/assets/{resume-dialog-CbOszZOP.js → resume-dialog-Ct2esNb1.js} +1 -1
  50. package/dist/client/assets/resume-dialog-Ct2esNb1.js.br +0 -0
  51. package/dist/client/assets/{review-queue-panel-B2CbcndW.js → review-queue-panel-BoS4YYxX.js} +1 -1
  52. package/dist/client/assets/review-queue-panel-BoS4YYxX.js.br +0 -0
  53. package/dist/client/assets/{settings-panel-B3IBo-4e.js → settings-panel-B95l_9Ya.js} +2 -2
  54. package/dist/client/assets/settings-panel-B95l_9Ya.js.br +0 -0
  55. package/dist/client/assets/{shown-lightbox-od2gVvDh.js → shown-lightbox-BCIOojpW.js} +1 -1
  56. package/dist/client/assets/shown-lightbox-BCIOojpW.js.br +0 -0
  57. package/dist/client/assets/{team-review-panel-BZkszJji.js → team-review-panel-DpS6sWEv.js} +1 -1
  58. package/dist/client/assets/team-review-panel-DpS6sWEv.js.br +0 -0
  59. package/dist/client/assets/{trace-panel-BM-GUU8G.js → trace-panel-BMZqavqS.js} +1 -1
  60. package/dist/client/assets/trace-panel-BMZqavqS.js.br +0 -0
  61. package/dist/client/assets/{usage-panel-Plw6c3LF.js → usage-panel-QpAQFZru.js} +1 -1
  62. package/dist/client/assets/usage-panel-QpAQFZru.js.br +0 -0
  63. package/dist/client/assets/{your-day-tip-D0Kgb05j.js → your-day-tip-B_fMD82l.js} +1 -1
  64. package/dist/client/assets/your-day-tip-B_fMD82l.js.br +0 -0
  65. package/dist/client/index.html +1 -1
  66. package/dist/client/index.html.br +0 -0
  67. package/dist/server/index.js +2 -2
  68. package/package.json +1 -1
  69. package/dist/client/assets/benchmark-panel-BE4qC6f7.js.br +0 -0
  70. package/dist/client/assets/boards-view-D57L6U0h.js.br +0 -0
  71. package/dist/client/assets/community-panel-CskJ8AP8.js.br +0 -0
  72. package/dist/client/assets/dialogs-DfVIXl6X.js.br +0 -0
  73. package/dist/client/assets/doc-editor-ui-BFtUHES4.js.br +0 -0
  74. package/dist/client/assets/feature-hint-DyAk6e1q.js.br +0 -0
  75. package/dist/client/assets/first-run-checklist-CkkQMeVP.js.br +0 -0
  76. package/dist/client/assets/hooks-panel-D7VDfDhJ.js.br +0 -0
  77. package/dist/client/assets/index-DlcYI9Mg.js.br +0 -0
  78. package/dist/client/assets/issues-panel-4iTdSU0H.js.br +0 -0
  79. package/dist/client/assets/my-prs-panel-DWcYzbAJ.js.br +0 -0
  80. package/dist/client/assets/nyan-cat-DDspnz8S.js.br +0 -0
  81. package/dist/client/assets/phone-shell-DD2tkq1J.js.br +0 -0
  82. package/dist/client/assets/plan-face-CuHG-XHp.js.br +0 -0
  83. package/dist/client/assets/pr-queue-columns-Wpvt5lpP.js.br +0 -0
  84. package/dist/client/assets/radar-panel-D0xCJ-qW.js.br +0 -0
  85. package/dist/client/assets/repo-roots-adder-C70cwNtz.js.br +0 -0
  86. package/dist/client/assets/resume-dialog-CbOszZOP.js.br +0 -0
  87. package/dist/client/assets/review-queue-panel-B2CbcndW.js.br +0 -0
  88. package/dist/client/assets/settings-panel-B3IBo-4e.js.br +0 -0
  89. package/dist/client/assets/shown-lightbox-od2gVvDh.js.br +0 -0
  90. package/dist/client/assets/team-review-panel-BZkszJji.js.br +0 -0
  91. package/dist/client/assets/trace-panel-BM-GUU8G.js.br +0 -0
  92. package/dist/client/assets/usage-panel-Plw6c3LF.js.br +0 -0
  93. package/dist/client/assets/your-day-tip-D0Kgb05j.js.br +0 -0
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
- import { r as firstLine, s as nodePtyRebuildHint, t as probeNodePty } from "../chunks/node-pty-preflight-DbfWP9Rc.js";
2
+ import { i as nodePtyRebuildHint, t as probeNodePty } from "../chunks/node-pty-preflight-CQNBCDVM.js";
3
+ import { t as firstLine } from "../chunks/text-core-rXHoQWP9.js";
3
4
  import { i as errorText } from "../chunks/text-DoirglWV.js";
4
5
  import { a as packageRoot } from "../chunks/runtime-paths-D_ZjJLE0.js";
5
6
  import { n as glimmervoidHomeDir, t as decideConfigPath } from "../chunks/config-path-core-DUWk0Lui.js";
6
7
  import { t as AGENT_API_VERBS } from "../chunks/session-CmkfJxzB.js";
7
8
  import { a as execSync } from "../chunks/child-process-safe-BCOoKfxG.js";
8
- import { J as isOwnedCommandName, Y as parseCommand, q as OWNED_COMMAND_SPECS, r as agentCommandHelpLines } from "../chunks/agent-api-core-D_f8pw2Q.js";
9
+ import { J as isOwnedCommandName, Y as parseCommand, q as OWNED_COMMAND_SPECS, r as agentCommandHelpLines } from "../chunks/agent-api-core-p7mq8Qw9.js";
9
10
  import { t as renderTable } from "../chunks/ascii-figure-core-pDAwtlKO.js";
10
11
  import { i as parseCommandLine, r as gitDoctorRows, t as probeGitVersion } from "../chunks/git-version-xS1GFU8P.js";
11
12
  import { i as pnpmGlobalBinDir, n as npmGlobalBinDir, r as onPath, t as formatPathNotice } from "../chunks/path-doctor-C23VAqeu.js";
@@ -26,6 +27,7 @@ Commands:
26
27
  pair --list List paired devices
27
28
  pair --revoke <id> Revoke a paired device
28
29
  agent setup grok Install the Grok hook relay, which does nothing outside Glimmervoid
30
+ why <file>:<line> Name the session that made the commit owning a line (or pass a commit sha)
29
31
 
30
32
  Inside a Glimmervoid session:
31
33
  ${agentCommandHelpLines().join("\n")}
@@ -61,7 +63,7 @@ var OWNED_COMMAND_RUNNERS = {
61
63
  return await runDoctor() ? 0 : 1;
62
64
  },
63
65
  pair: async ({ values }) => {
64
- const { runPairCli } = await import("../chunks/pair-cli-CkRuFX6c.js");
66
+ const { runPairCli } = await import("../chunks/pair-cli-pkc8mHbi.js");
65
67
  return runPairCli({
66
68
  isListing: values.list === true,
67
69
  revokeDeviceId: typeof values.revoke === "string" ? values.revoke : null,
@@ -73,11 +75,15 @@ var OWNED_COMMAND_RUNNERS = {
73
75
  return runAgentSetupCli();
74
76
  },
75
77
  settings: async (parsed) => {
76
- const { runParsedSettingsCli } = await import("../chunks/settings-cli-nrO-53SB.js");
78
+ const { runParsedSettingsCli } = await import("../chunks/settings-cli-BRC0xzME.js");
77
79
  return runParsedSettingsCli(parsed);
78
80
  },
81
+ why: async ({ positionals }) => {
82
+ const { runWhyCli } = await import("../chunks/why-cli-cYNMNYwv.js");
83
+ return runWhyCli({ targetArgument: positionals[0] ?? "" });
84
+ },
79
85
  "ssh-sign": async ({ rawArgs }) => {
80
- const { runSshSignCli } = await import("../chunks/ssh-sign-cli-BYQ8vj-c.js");
86
+ const { runSshSignCli } = await import("../chunks/ssh-sign-cli-KwmWJqa-.js");
81
87
  return runSshSignCli(rawArgs);
82
88
  }
83
89
  };
@@ -99,7 +105,7 @@ async function runOwnedCommand(name, subcommandArgs) {
99
105
  return OWNED_COMMAND_RUNNERS[name](parsed);
100
106
  }
101
107
  var SUBCOMMAND_RUNNERS = new Map([...Object.keys(OWNED_COMMAND_SPECS).filter(isOwnedCommandName).map((name) => [name, (subcommandArgs) => runOwnedCommand(name, subcommandArgs)]), ...AGENT_API_VERBS.filter((verb) => !isOwnedCommandName(verb)).map((verb) => [verb, async (subcommandArgs, subcommandName) => {
102
- const { runAgentApiCli } = await import("../chunks/agent-api-cli-dXQTG2GO.js");
108
+ const { runAgentApiCli } = await import("../chunks/agent-api-cli-wDSMdFsQ.js");
103
109
  return runAgentApiCli([subcommandName, ...subcommandArgs]);
104
110
  }])]);
105
111
  var AGENT_INSTALL_COMMAND_BY_ID = {
@@ -113,7 +119,7 @@ function missingAgentText(agentId) {
113
119
  }
114
120
  async function printSessionLimits() {
115
121
  if (!process.env["GLIMMERVOID_AGENT_URL"]) return;
116
- const { sessionLimitsHelpLines } = await import("../chunks/agent-api-cli-dXQTG2GO.js");
122
+ const { sessionLimitsHelpLines } = await import("../chunks/agent-api-cli-wDSMdFsQ.js");
117
123
  const limitsLines = await sessionLimitsHelpLines();
118
124
  console.log(`\n${limitsLines.join("\n")}`);
119
125
  }
@@ -1,5 +1,5 @@
1
1
  import { X as WhiteboardAgentReply, l as AgentLimitsReply, r as AGENT_URL_ENV } from "./session-CmkfJxzB.js";
2
- import { Y as parseCommand, i as agentCommandSpec, m as isAgentApiVerb, t as AGENT_COMMAND_HELP } from "./agent-api-core-D_f8pw2Q.js";
2
+ import { Y as parseCommand, i as agentCommandSpec, m as isAgentApiVerb, t as AGENT_COMMAND_HELP } from "./agent-api-core-p7mq8Qw9.js";
3
3
  import { i as formatSessionLimits } from "./session-routes-CgqWd0bR.js";
4
4
  import { i as resolveHookTarget } from "./hook-relay-core-DA_bz2KA.js";
5
5
  import { t as parseJsonOrNull } from "./json-core-If8h-Qgy.js";
@@ -1 +1 @@
1
- export { t as askAgentApi, r as runAgentApiCli, i as sessionLimitsHelpLines } from "./agent-api-cli-BkmHQXK6.js";
1
+ export { t as askAgentApi, r as runAgentApiCli, i as sessionLimitsHelpLines } from "./agent-api-cli-NPWGP-aG.js";
@@ -268,6 +268,16 @@ change it in the dashboard settings or through its environment variable.`,
268
268
  }
269
269
  ]
270
270
  },
271
+ why: {
272
+ name: "why",
273
+ summary: "Name the session that made the commit owning a file line, or a commit, and what it was asked",
274
+ positionals: {
275
+ usage: "<file>:<line> | <sha>",
276
+ min: 1,
277
+ max: 1
278
+ },
279
+ options: [CONFIG_OPTION]
280
+ },
271
281
  "ssh-sign": {
272
282
  name: "ssh-sign",
273
283
  summary: "Sign a commit with the operator's forwarded ssh agent (git runs this)",
@@ -0,0 +1,316 @@
1
+ import { r as errorMessage } from "./text-DoirglWV.js";
2
+ import { r as execFileAsync } from "./child-process-safe-BCOoKfxG.js";
3
+ import { Pt as TraceRecord } from "./config-BWa_HecL.js";
4
+ import { m as createKeyedSerialQueue, n as appendJsonLines } from "./json-file-AKRVPqG1.js";
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { z } from "zod";
8
+ import crypto from "node:crypto";
9
+ //#region server/git/git-exec.ts
10
+ var DEFAULT_COMMAND_TIMEOUT_MS = 2e4;
11
+ function outputText(value) {
12
+ if (typeof value === "string") return value;
13
+ if (Buffer.isBuffer(value)) return value.toString("utf8");
14
+ return value == null ? "" : String(value);
15
+ }
16
+ function childEnv(env, replaceEnv) {
17
+ if (replaceEnv) return { env: replaceEnv };
18
+ if (env) return { env: {
19
+ ...process.env,
20
+ ...env
21
+ } };
22
+ return {};
23
+ }
24
+ async function runCommand(file, args, { cwd, timeoutMs = DEFAULT_COMMAND_TIMEOUT_MS, maxBuffer, env, replaceEnv, signal, input, trim = true, keepStdoutOnFailure = false, preferStderr = false, execFileFn = execFileAsync } = {}) {
25
+ const execOptions = {
26
+ encoding: "utf8",
27
+ timeout: timeoutMs,
28
+ ...cwd === void 0 ? {} : { cwd },
29
+ ...maxBuffer === void 0 ? {} : { maxBuffer },
30
+ ...signal ? { signal } : {},
31
+ ...input === void 0 ? {} : { input },
32
+ ...childEnv(env, replaceEnv)
33
+ };
34
+ try {
35
+ const { stdout, stderr } = await execFileFn(file, args, execOptions);
36
+ const out = outputText(stdout);
37
+ return {
38
+ ok: true,
39
+ out: trim ? out.trim() : out,
40
+ err: "",
41
+ stderr: outputText(stderr)
42
+ };
43
+ } catch (error) {
44
+ const failure = error ?? {};
45
+ const stdout = outputText(failure.stdout);
46
+ const stderr = outputText(failure.stderr);
47
+ const message = errorMessage(error);
48
+ return {
49
+ ok: false,
50
+ out: keepStdoutOnFailure ? trim ? stdout.trim() : stdout : "",
51
+ err: preferStderr ? stderr || message : message,
52
+ stderr,
53
+ error,
54
+ timedOut: failure.killed === true && Boolean(failure.signal)
55
+ };
56
+ }
57
+ }
58
+ function runGit(args, { gitPath = "git", env, replaceEnv, ...rest } = {}) {
59
+ const baseEnv = replaceEnv ?? (env ? {
60
+ ...process.env,
61
+ ...env
62
+ } : process.env);
63
+ return runCommand(gitPath, args, {
64
+ ...rest,
65
+ replaceEnv: {
66
+ ...baseEnv,
67
+ GIT_TERMINAL_PROMPT: "0"
68
+ }
69
+ });
70
+ }
71
+ function gitCommandFailure(args, command, timeoutMs = DEFAULT_COMMAND_TIMEOUT_MS) {
72
+ if (!command.timedOut) return command.error;
73
+ return new Error(`git ${args.join(" ")} timed out after ${timeoutMs}ms`, { cause: command.error });
74
+ }
75
+ function runGh(args, options = {}) {
76
+ return runCommand("gh", args, options);
77
+ }
78
+ //#endregion
79
+ //#region shared/contracts/commit-session.ts
80
+ var CommitSha = z.string().regex(/^[0-9a-f]{40}$/);
81
+ var CommitSessionRecord = z.object({
82
+ sha: CommitSha,
83
+ patchId: CommitSha.nullable(),
84
+ sessionId: z.string().min(1).max(64),
85
+ sessionName: z.string().max(200),
86
+ agent: z.string().max(64),
87
+ taskTitle: z.string().max(300).nullable(),
88
+ committedAt: z.number().int(),
89
+ recordedAt: z.number().int()
90
+ }).strict();
91
+ //#endregion
92
+ //#region server/core/commit-session-core.ts
93
+ var COMMIT_LOG_FORMAT = "%H %ct";
94
+ var REPO_KEY_HASH_LENGTH = 12;
95
+ var SHORT_SHA_LENGTH = 7;
96
+ var MAX_PROMPT_CHARS = 200;
97
+ var PROMPT_MARKER = "\"kind\":\"prompt\"";
98
+ function repoKeyOf(gitCommonDirectory) {
99
+ return `${path.basename(path.dirname(gitCommonDirectory)).replace(/[^A-Za-z0-9._-]/g, "_") || "repo"}-${crypto.createHash("sha1").update(gitCommonDirectory).digest("hex").slice(0, REPO_KEY_HASH_LENGTH)}`;
100
+ }
101
+ function parseCommitLog(logOutput) {
102
+ return logOutput.split("\n").flatMap((line) => {
103
+ const [sha, seconds] = line.trim().split(" ");
104
+ if (!sha || !/^[0-9a-f]{40}$/.test(sha) || !seconds) return [];
105
+ return [{
106
+ sha,
107
+ committedAt: Number(seconds) * 1e3
108
+ }];
109
+ });
110
+ }
111
+ function parsePatchIds(patchIdOutput) {
112
+ const patchIdBySha = /* @__PURE__ */ new Map();
113
+ for (const line of patchIdOutput.split("\n")) {
114
+ const [patchId, sha] = line.trim().split(" ");
115
+ if (patchId && sha) patchIdBySha.set(sha, patchId);
116
+ }
117
+ return patchIdBySha;
118
+ }
119
+ function parsedLineAround(text, offset, schema) {
120
+ const lineStart = text.lastIndexOf("\n", offset) + 1;
121
+ const lineEnd = text.indexOf("\n", offset);
122
+ try {
123
+ const parsed = schema.safeParse(JSON.parse(text.slice(lineStart, lineEnd === -1 ? void 0 : lineEnd)));
124
+ return parsed.success ? parsed.data : null;
125
+ } catch {
126
+ return null;
127
+ }
128
+ }
129
+ function findRecord(storeText, key) {
130
+ const marker = "sha" in key ? `"sha":"${key.sha}"` : `"patchId":"${key.patchId}"`;
131
+ for (let at = storeText.indexOf(marker); at !== -1; at = storeText.indexOf(marker, at + marker.length)) {
132
+ const record = parsedLineAround(storeText, at, CommitSessionRecord);
133
+ if (record && ("sha" in key ? record.sha === key.sha : record.patchId === key.patchId)) return record;
134
+ }
135
+ return null;
136
+ }
137
+ function parseWhyTarget(argument) {
138
+ if (/^[0-9a-f]{4,40}$/i.test(argument)) return { sha: argument.toLowerCase() };
139
+ const separatorAt = argument.lastIndexOf(":");
140
+ const lineText = argument.slice(separatorAt + 1);
141
+ if (separatorAt <= 0 || !/^[1-9][0-9]*$/.test(lineText)) return { error: `expected <file>:<line> or a commit sha, got ${argument}` };
142
+ return {
143
+ file: argument.slice(0, separatorAt),
144
+ line: Number(lineText)
145
+ };
146
+ }
147
+ function lastPromptBefore(traceText, committedAtMs) {
148
+ let latest = null;
149
+ for (let at = traceText.indexOf(PROMPT_MARKER); at !== -1; at = traceText.indexOf(PROMPT_MARKER, at + 15)) {
150
+ const record = parsedLineAround(traceText, at, TraceRecord);
151
+ if (record?.kind !== "prompt" || record.ts > committedAtMs || latest && latest.ts > record.ts) continue;
152
+ const firstPromptLine = record.text.trim().split("\n")[0] ?? "";
153
+ if (firstPromptLine) latest = {
154
+ text: firstPromptLine.slice(0, MAX_PROMPT_CHARS),
155
+ ts: record.ts
156
+ };
157
+ }
158
+ return latest;
159
+ }
160
+ function twoDigits(value) {
161
+ return String(value).padStart(2, "0");
162
+ }
163
+ function localDay(ms) {
164
+ const date = new Date(ms);
165
+ return `${date.getFullYear()}-${twoDigits(date.getMonth() + 1)}-${twoDigits(date.getDate())}`;
166
+ }
167
+ function localTime(ms) {
168
+ const date = new Date(ms);
169
+ return `${twoDigits(date.getHours())}:${twoDigits(date.getMinutes())}`;
170
+ }
171
+ function formatWhy(answer) {
172
+ const heading = `${answer.location} ${answer.sha.slice(0, SHORT_SHA_LENGTH)} ${localDay(answer.committedAt)} ${localTime(answer.committedAt)}`;
173
+ const { record } = answer;
174
+ if (!record) return `${heading}\nno Glimmervoid session made this commit`;
175
+ const lines = [heading, `session ${record.sessionName} (${record.agent}) ${record.sessionId.slice(0, 8)}`];
176
+ if (record.taskTitle) lines.push(`task ${record.taskTitle}`);
177
+ if (answer.prompt) lines.push(`asked ${JSON.stringify(answer.prompt.text)} (${localTime(answer.prompt.ts)})`);
178
+ return lines.join("\n");
179
+ }
180
+ function recordedShasOf(storeText, sessionId) {
181
+ const recordedShas = /* @__PURE__ */ new Set();
182
+ const sessionMarker = `"sessionId":${JSON.stringify(sessionId)}`;
183
+ for (let at = storeText.indexOf(sessionMarker); at !== -1; at = storeText.indexOf(sessionMarker, at + sessionMarker.length)) {
184
+ const record = parsedLineAround(storeText, at, CommitSessionRecord);
185
+ if (record?.sessionId === sessionId) recordedShas.add(record.sha);
186
+ }
187
+ return recordedShas;
188
+ }
189
+ //#endregion
190
+ //#region server/commit-sessions.ts
191
+ var COMMIT_SESSIONS_FOLDER_NAME = "commit-sessions";
192
+ var GIT_TIMEOUT_MS = 2e4;
193
+ var GIT_MAX_BUFFER = 67108864;
194
+ function storePathFor(storeRoot, gitCommonDirectory) {
195
+ return path.join(storeRoot, `${repoKeyOf(gitCommonDirectory)}.jsonl`);
196
+ }
197
+ async function gitCommonDirectoryOf(directory, runGitFn = runGit) {
198
+ const result = await runGitFn([
199
+ "rev-parse",
200
+ "--path-format=absolute",
201
+ "--git-common-dir"
202
+ ], {
203
+ cwd: directory,
204
+ timeoutMs: GIT_TIMEOUT_MS
205
+ });
206
+ if (!result.ok || !result.out) return null;
207
+ return fs.promises.realpath(result.out).catch(() => result.out);
208
+ }
209
+ async function patchIdsOfBatch(shas, gitOptions, runGitFn = runGit) {
210
+ const patches = await runGitFn([
211
+ "show",
212
+ "--no-color",
213
+ "--format=commit %H",
214
+ "-p",
215
+ ...shas
216
+ ], {
217
+ ...gitOptions,
218
+ trim: false
219
+ });
220
+ if (!patches.ok) return null;
221
+ const patchIds = await runGitFn(["patch-id", "--stable"], {
222
+ ...gitOptions,
223
+ input: patches.out
224
+ });
225
+ return patchIds.ok ? parsePatchIds(patchIds.out) : null;
226
+ }
227
+ async function readStoreText(storePath) {
228
+ return fs.promises.readFile(storePath, "utf8").catch(() => "");
229
+ }
230
+ function createCommitSessions({ storeRoot, runGitFn = runGit, logger, nowFn = Date.now }) {
231
+ const lastCapturedHeadBySessionId = /* @__PURE__ */ new Map();
232
+ const recordedShasBySessionId = /* @__PURE__ */ new Map();
233
+ const storePathByWorktreeDir = /* @__PURE__ */ new Map();
234
+ const captureQueue = createKeyedSerialQueue();
235
+ async function storePathOf(worktreeDir) {
236
+ const known = storePathByWorktreeDir.get(worktreeDir);
237
+ if (known) return known;
238
+ const gitCommonDirectory = await gitCommonDirectoryOf(worktreeDir, runGitFn);
239
+ if (!gitCommonDirectory) return null;
240
+ const storePath = storePathFor(storeRoot, gitCommonDirectory);
241
+ storePathByWorktreeDir.set(worktreeDir, storePath);
242
+ return storePath;
243
+ }
244
+ async function recordedShasFor(sessionId, storePath) {
245
+ const known = recordedShasBySessionId.get(sessionId);
246
+ if (known) return known;
247
+ const recordedShas = recordedShasOf(await readStoreText(storePath), sessionId);
248
+ recordedShasBySessionId.set(sessionId, recordedShas);
249
+ return recordedShas;
250
+ }
251
+ async function patchIdsOf(commits, gitOptions) {
252
+ const shas = commits.map((commit) => commit.sha);
253
+ const batchPatchIds = await patchIdsOfBatch(shas, gitOptions, runGitFn);
254
+ if (batchPatchIds || shas.length === 1) return batchPatchIds ?? /* @__PURE__ */ new Map();
255
+ const patchIdBySha = /* @__PURE__ */ new Map();
256
+ for (const sha of shas) {
257
+ const singlePatchId = (await patchIdsOfBatch([sha], gitOptions, runGitFn))?.get(sha);
258
+ if (singlePatchId) patchIdBySha.set(sha, singlePatchId);
259
+ }
260
+ return patchIdBySha;
261
+ }
262
+ async function capture(change) {
263
+ if (lastCapturedHeadBySessionId.get(change.sessionId) === change.headSha) return;
264
+ const storePath = await storePathOf(change.worktreeDir);
265
+ if (!storePath) return;
266
+ const gitOptions = {
267
+ cwd: change.worktreeDir,
268
+ timeoutMs: GIT_TIMEOUT_MS,
269
+ maxBuffer: GIT_MAX_BUFFER
270
+ };
271
+ const listed = await runGitFn([
272
+ "log",
273
+ "--no-merges",
274
+ `--format=${COMMIT_LOG_FORMAT}`,
275
+ `${change.baseRef}..${change.headSha}`
276
+ ], gitOptions);
277
+ if (!listed.ok) return;
278
+ const recordedShas = await recordedShasFor(change.sessionId, storePath);
279
+ const newCommits = parseCommitLog(listed.out).filter((commit) => !recordedShas.has(commit.sha));
280
+ if (newCommits.length === 0) {
281
+ lastCapturedHeadBySessionId.set(change.sessionId, change.headSha);
282
+ return;
283
+ }
284
+ const patchIdBySha = await patchIdsOf(newCommits, gitOptions);
285
+ const shasWithoutPatchId = newCommits.filter((commit) => !patchIdBySha.has(commit.sha)).map((commit) => commit.sha.slice(0, 12));
286
+ if (shasWithoutPatchId.length > 0) logger.warn(`[commit-sessions] no patch-id for ${shasWithoutPatchId.join(", ")} in ${change.sessionId}; a rebased copy will not trace back`);
287
+ const recordedAt = nowFn();
288
+ const records = newCommits.map((commit) => ({
289
+ sha: commit.sha,
290
+ patchId: patchIdBySha.get(commit.sha) ?? null,
291
+ sessionId: change.sessionId,
292
+ sessionName: change.sessionName.slice(0, 200),
293
+ agent: change.agent.slice(0, 64),
294
+ taskTitle: change.taskTitle?.slice(0, 300) ?? null,
295
+ committedAt: commit.committedAt,
296
+ recordedAt
297
+ }));
298
+ await appendJsonLines(storePath, records, {
299
+ mkdir: true,
300
+ mode: 384
301
+ });
302
+ lastCapturedHeadBySessionId.set(change.sessionId, change.headSha);
303
+ for (const record of records) recordedShas.add(record.sha);
304
+ }
305
+ function noteHeadChange(change) {
306
+ const { baseRef } = change;
307
+ if (!baseRef) return Promise.resolve();
308
+ return captureQueue.run(change.sessionId, () => capture({
309
+ ...change,
310
+ baseRef
311
+ })).catch((error) => logger.warn(`[commit-sessions] capture failed for ${change.sessionId}: ${errorMessage(error)}`));
312
+ }
313
+ return { noteHeadChange };
314
+ }
315
+ //#endregion
316
+ export { gitCommonDirectoryOf as a, findRecord as c, parseCommitLog as d, parseWhyTarget as f, runGit as g, runGh as h, createCommitSessions as i, formatWhy as l, runCommand as m, GIT_MAX_BUFFER as n, patchIdsOfBatch as o, gitCommandFailure as p, GIT_TIMEOUT_MS as r, storePathFor as s, COMMIT_SESSIONS_FOLDER_NAME as t, lastPromptBefore as u };