adhdev 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.js CHANGED
@@ -968,7 +968,8 @@ function createDefaultGitCommandServices() {
968
968
  stashPush: async ({ workspace, message, includeUntracked = false }) => gitStashPush(workspace, message, includeUntracked),
969
969
  stashPop: async ({ workspace, stashRef }) => gitStashPop(workspace, stashRef),
970
970
  checkoutFiles: async ({ workspace, paths }) => gitCheckoutFiles(workspace, paths),
971
- getRemoteUrl: async ({ workspace, remote = "origin" }) => gitGetRemoteUrl(workspace, remote)
971
+ getRemoteUrl: async ({ workspace, remote = "origin" }) => gitGetRemoteUrl(workspace, remote),
972
+ push: async ({ workspace, remote = "origin", branch, setUpstream = false }) => gitPush(workspace, remote, branch, setUpstream)
972
973
  };
973
974
  }
974
975
  function validateWorkspace2(args) {
@@ -1135,6 +1136,20 @@ async function handleGitCommand(command, args, services = defaultGitCommandServi
1135
1136
  if ("success" in remoteResult) return remoteResult;
1136
1137
  return { success: true, remoteUrl: remoteResult.remoteUrl, remote: remoteResult.remote };
1137
1138
  }
1139
+ case "git_push": {
1140
+ if (!services.push) return serviceNotImplemented(command);
1141
+ const remote = typeof args?.remote === "string" && args.remote.trim() ? args.remote.trim() : "origin";
1142
+ const branch = typeof args?.branch === "string" && args.branch.trim() ? args.branch.trim() : void 0;
1143
+ const setUpstream = Boolean(args?.setUpstream);
1144
+ if (!/^[a-zA-Z0-9_.\-]+$/.test(remote)) {
1145
+ return failure("invalid_args", "remote must contain only alphanumeric characters, dots, hyphens, and underscores");
1146
+ }
1147
+ if (branch !== void 0 && !/^[a-zA-Z0-9/_.\-]+$/.test(branch)) {
1148
+ return failure("invalid_args", "branch must contain only alphanumeric characters, slashes, dots, hyphens, and underscores");
1149
+ }
1150
+ const pushResult = await runService(() => services.push({ workspace, remote, branch, setUpstream }));
1151
+ return "success" in pushResult ? pushResult : { success: true, push: pushResult };
1152
+ }
1138
1153
  default:
1139
1154
  return failure("invalid_args", `Unknown Git command: ${command}`);
1140
1155
  }
@@ -1237,6 +1252,49 @@ async function gitGetRemoteUrl(workspace, remote) {
1237
1252
  }
1238
1253
  return { remoteUrl, remote };
1239
1254
  }
1255
+ async function gitPush(workspace, remote, branch, setUpstream) {
1256
+ const lastCheckedAt = Date.now();
1257
+ const repo = await resolveGitRepository(workspace);
1258
+ const repoRoot = repo.repoRoot;
1259
+ let resolvedBranch = branch;
1260
+ if (!resolvedBranch) {
1261
+ const branchResult = await runGit(repo, ["symbolic-ref", "--short", "HEAD"], { cwd: repoRoot });
1262
+ resolvedBranch = branchResult.stdout.trim();
1263
+ if (!resolvedBranch) {
1264
+ throw new GitCommandError("git_command_failed", "Cannot push: not on a branch (detached HEAD)");
1265
+ }
1266
+ }
1267
+ const pushArgs = ["push"];
1268
+ if (setUpstream) pushArgs.push("--set-upstream");
1269
+ pushArgs.push(remote, resolvedBranch);
1270
+ let output = "";
1271
+ let newBranch = false;
1272
+ try {
1273
+ const result = await runGit(repo, pushArgs, { cwd: repoRoot });
1274
+ output = (result.stdout + result.stderr).trim();
1275
+ newBranch = /\[new branch\]/i.test(output);
1276
+ } catch (err) {
1277
+ const errOutput = (err?.stdout ?? "") + (err?.stderr ?? "");
1278
+ if (!setUpstream && /no upstream branch|set-upstream/i.test(errOutput)) {
1279
+ const retryArgs = ["push", "--set-upstream", remote, resolvedBranch];
1280
+ const retryResult = await runGit(repo, retryArgs, { cwd: repoRoot });
1281
+ output = (retryResult.stdout + retryResult.stderr).trim();
1282
+ newBranch = /\[new branch\]/i.test(output);
1283
+ } else {
1284
+ throw new GitCommandError("git_command_failed", errOutput || err?.message || "git push failed");
1285
+ }
1286
+ }
1287
+ return {
1288
+ workspace: repo.workspace,
1289
+ repoRoot,
1290
+ isGitRepo: true,
1291
+ remote,
1292
+ branch: resolvedBranch,
1293
+ output,
1294
+ newBranch,
1295
+ lastCheckedAt
1296
+ };
1297
+ }
1240
1298
  function formatOptionalGitLogRangeArg(flag, value) {
1241
1299
  return value ? [`${flag}=${value}`] : [];
1242
1300
  }
@@ -1314,7 +1372,8 @@ var init_git_commands = __esm({
1314
1372
  "git_stash_push",
1315
1373
  "git_stash_pop",
1316
1374
  "git_checkout_files",
1317
- "git_remote_url"
1375
+ "git_remote_url",
1376
+ "git_push"
1318
1377
  ]);
1319
1378
  SNAPSHOT_REASONS = /* @__PURE__ */ new Set([
1320
1379
  "session_baseline",
@@ -8830,9 +8889,34 @@ function findLastMessageIndexBySignature(messages, signature) {
8830
8889
  }
8831
8890
  return -1;
8832
8891
  }
8892
+ function isReadChatConversationAnchorMessage(message) {
8893
+ if (!message) return false;
8894
+ const role = String(message.role || "").trim().toLowerCase();
8895
+ if (role !== "user" && role !== "assistant") return false;
8896
+ const kind = String(message.kind || "standard").trim().toLowerCase();
8897
+ return !kind || kind === "standard";
8898
+ }
8899
+ function buildVisibleReadChatTailMessages(messages, tailLimit) {
8900
+ const totalMessages = messages.length;
8901
+ if (tailLimit <= 0 || totalMessages <= tailLimit) return messages;
8902
+ const tailMessages = messages.slice(-tailLimit);
8903
+ if (tailMessages.some(isReadChatConversationAnchorMessage)) return tailMessages;
8904
+ const hiddenMessages = messages.slice(0, totalMessages - tailLimit);
8905
+ const anchors = [];
8906
+ const seenRoles = /* @__PURE__ */ new Set();
8907
+ for (let index = hiddenMessages.length - 1; index >= 0 && anchors.length < 2; index -= 1) {
8908
+ const message = hiddenMessages[index];
8909
+ if (!isReadChatConversationAnchorMessage(message)) continue;
8910
+ const role = String(message.role || "").trim().toLowerCase();
8911
+ if (seenRoles.has(role)) continue;
8912
+ seenRoles.add(role);
8913
+ anchors.unshift(message);
8914
+ }
8915
+ return anchors.length > 0 ? [...anchors, ...tailMessages] : tailMessages;
8916
+ }
8833
8917
  function buildBoundedTailSync(messages, cursor) {
8834
8918
  const totalMessages = messages.length;
8835
- const tailMessages = cursor.tailLimit > 0 && totalMessages > cursor.tailLimit ? messages.slice(-cursor.tailLimit) : messages;
8919
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
8836
8920
  return {
8837
8921
  syncMode: "full",
8838
8922
  replaceFrom: 0,
@@ -8954,8 +9038,8 @@ function buildReadChatCommandResult(payload, args) {
8954
9038
  const messages = collapseReplayDuplicatesFromReadChat(normalizeReadChatMessages(validatedPayload));
8955
9039
  const cursor = normalizeReadChatCursor(args);
8956
9040
  if (!cursor.knownMessageCount && !cursor.lastMessageSignature && cursor.tailLimit > 0 && messages.length > cursor.tailLimit) {
8957
- const tailMessages = messages.slice(-cursor.tailLimit);
8958
- const lastMessageSignature = getChatMessageSignature(tailMessages[tailMessages.length - 1]);
9041
+ const tailMessages = buildVisibleReadChatTailMessages(messages, cursor.tailLimit);
9042
+ const lastMessageSignature = getChatMessageSignature(messages[messages.length - 1]);
8959
9043
  return {
8960
9044
  success: true,
8961
9045
  ...validatedPayload,
@@ -59187,7 +59271,7 @@ var init_adhdev_daemon = __esm({
59187
59271
  init_version();
59188
59272
  init_src();
59189
59273
  init_runtime_defaults();
59190
- pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.62" });
59274
+ pkgVersion = resolvePackageVersion({ injectedVersion: "0.9.64" });
59191
59275
  AdhdevDaemon = class _AdhdevDaemon {
59192
59276
  localHttpServer = null;
59193
59277
  localWss = null;