@adhdev/daemon-core 0.9.62 → 0.9.64

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/dist/index.mjs CHANGED
@@ -5462,7 +5462,8 @@ var GIT_COMMAND_NAMES = /* @__PURE__ */ new Set([
5462
5462
  "git_stash_push",
5463
5463
  "git_stash_pop",
5464
5464
  "git_checkout_files",
5465
- "git_remote_url"
5465
+ "git_remote_url",
5466
+ "git_push"
5466
5467
  ]);
5467
5468
  var SNAPSHOT_REASONS = /* @__PURE__ */ new Set([
5468
5469
  "session_baseline",
@@ -5508,7 +5509,8 @@ function createDefaultGitCommandServices() {
5508
5509
  stashPush: async ({ workspace, message, includeUntracked = false }) => gitStashPush(workspace, message, includeUntracked),
5509
5510
  stashPop: async ({ workspace, stashRef }) => gitStashPop(workspace, stashRef),
5510
5511
  checkoutFiles: async ({ workspace, paths }) => gitCheckoutFiles(workspace, paths),
5511
- getRemoteUrl: async ({ workspace, remote = "origin" }) => gitGetRemoteUrl(workspace, remote)
5512
+ getRemoteUrl: async ({ workspace, remote = "origin" }) => gitGetRemoteUrl(workspace, remote),
5513
+ push: async ({ workspace, remote = "origin", branch, setUpstream = false }) => gitPush(workspace, remote, branch, setUpstream)
5512
5514
  };
5513
5515
  }
5514
5516
  var defaultGitCommandServices = createDefaultGitCommandServices();
@@ -5676,6 +5678,20 @@ async function handleGitCommand(command, args, services = defaultGitCommandServi
5676
5678
  if ("success" in remoteResult) return remoteResult;
5677
5679
  return { success: true, remoteUrl: remoteResult.remoteUrl, remote: remoteResult.remote };
5678
5680
  }
5681
+ case "git_push": {
5682
+ if (!services.push) return serviceNotImplemented(command);
5683
+ const remote = typeof args?.remote === "string" && args.remote.trim() ? args.remote.trim() : "origin";
5684
+ const branch = typeof args?.branch === "string" && args.branch.trim() ? args.branch.trim() : void 0;
5685
+ const setUpstream = Boolean(args?.setUpstream);
5686
+ if (!/^[a-zA-Z0-9_.\-]+$/.test(remote)) {
5687
+ return failure("invalid_args", "remote must contain only alphanumeric characters, dots, hyphens, and underscores");
5688
+ }
5689
+ if (branch !== void 0 && !/^[a-zA-Z0-9/_.\-]+$/.test(branch)) {
5690
+ return failure("invalid_args", "branch must contain only alphanumeric characters, slashes, dots, hyphens, and underscores");
5691
+ }
5692
+ const pushResult = await runService(() => services.push({ workspace, remote, branch, setUpstream }));
5693
+ return "success" in pushResult ? pushResult : { success: true, push: pushResult };
5694
+ }
5679
5695
  default:
5680
5696
  return failure("invalid_args", `Unknown Git command: ${command}`);
5681
5697
  }
@@ -5778,6 +5794,49 @@ async function gitGetRemoteUrl(workspace, remote) {
5778
5794
  }
5779
5795
  return { remoteUrl, remote };
5780
5796
  }
5797
+ async function gitPush(workspace, remote, branch, setUpstream) {
5798
+ const lastCheckedAt = Date.now();
5799
+ const repo = await resolveGitRepository(workspace);
5800
+ const repoRoot = repo.repoRoot;
5801
+ let resolvedBranch = branch;
5802
+ if (!resolvedBranch) {
5803
+ const branchResult = await runGit(repo, ["symbolic-ref", "--short", "HEAD"], { cwd: repoRoot });
5804
+ resolvedBranch = branchResult.stdout.trim();
5805
+ if (!resolvedBranch) {
5806
+ throw new GitCommandError("git_command_failed", "Cannot push: not on a branch (detached HEAD)");
5807
+ }
5808
+ }
5809
+ const pushArgs = ["push"];
5810
+ if (setUpstream) pushArgs.push("--set-upstream");
5811
+ pushArgs.push(remote, resolvedBranch);
5812
+ let output = "";
5813
+ let newBranch = false;
5814
+ try {
5815
+ const result = await runGit(repo, pushArgs, { cwd: repoRoot });
5816
+ output = (result.stdout + result.stderr).trim();
5817
+ newBranch = /\[new branch\]/i.test(output);
5818
+ } catch (err) {
5819
+ const errOutput = (err?.stdout ?? "") + (err?.stderr ?? "");
5820
+ if (!setUpstream && /no upstream branch|set-upstream/i.test(errOutput)) {
5821
+ const retryArgs = ["push", "--set-upstream", remote, resolvedBranch];
5822
+ const retryResult = await runGit(repo, retryArgs, { cwd: repoRoot });
5823
+ output = (retryResult.stdout + retryResult.stderr).trim();
5824
+ newBranch = /\[new branch\]/i.test(output);
5825
+ } else {
5826
+ throw new GitCommandError("git_command_failed", errOutput || err?.message || "git push failed");
5827
+ }
5828
+ }
5829
+ return {
5830
+ workspace: repo.workspace,
5831
+ repoRoot,
5832
+ isGitRepo: true,
5833
+ remote,
5834
+ branch: resolvedBranch,
5835
+ output,
5836
+ newBranch,
5837
+ lastCheckedAt
5838
+ };
5839
+ }
5781
5840
  function formatOptionalGitLogRangeArg(flag, value) {
5782
5841
  return value ? [`${flag}=${value}`] : [];
5783
5842
  }
@@ -12103,9 +12162,34 @@ function findLastMessageIndexBySignature(messages, signature) {
12103
12162
  }
12104
12163
  return -1;
12105
12164
  }
12165
+ function isReadChatConversationAnchorMessage(message) {
12166
+ if (!message) return false;
12167
+ const role = String(message.role || "").trim().toLowerCase();
12168
+ if (role !== "user" && role !== "assistant") return false;
12169
+ const kind = String(message.kind || "standard").trim().toLowerCase();
12170
+ return !kind || kind === "standard";
12171
+ }
12172
+ function buildVisibleReadChatTailMessages(messages, tailLimit) {
12173
+ const totalMessages = messages.length;
12174
+ if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
12175
+ const tailMessages = messages.slice(-tailLimit);
12176
+ if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
12177
+ const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
12178
+ const anchors = [];
12179
+ const seenRoles = /* @__PURE__ */ new Set();
12180
+ for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
12181
+ const message = hiddenMessages[index];
12182
+ if (!isReadChatConversationAnchorMessage(message)) continue;
12183
+ const role = String(message.role || "").trim().toLowerCase();
12184
+ if (seenRoles.has(role)) continue;
12185
+ seenRoles.add(role);
12186
+ anchors.unshift(message);
12187
+ }
12188
+ return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
12189
+ }
12106
12190
  function buildBoundedTailSync(messages, cursor) {
12107
12191
  const totalMessages = messages.length;
12108
- const tailMessages = cursor.tailLimit > 0 && totalMessages > cursor.tailLimit ? messages.slice(-cursor.tailLimit) : messages;
12192
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
12109
12193
  return {
12110
12194
  syncMode: "full",
12111
12195
  replaceFrom: 0,
@@ -12227,8 +12311,8 @@ function buildReadChatCommandResult(payload, args) {
12227
12311
  const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
12228
12312
  const cursor = normalizeReadChatCursor(args);
12229
12313
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
12230
- const tailMessages = messages.slice(-cursor.tailLimit);
12231
- const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
12314
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
12315
+ const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
12232
12316
  return {
12233
12317
  success: true,
12234
12318
  ...validatedPayload,