@diologue/local-agent 0.8.0 → 0.9.0

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/cli.mjs CHANGED
@@ -782,6 +782,14 @@ var getRemoteUrl = async (cwd) => {
782
782
  throw err;
783
783
  }
784
784
  };
785
+ var parseGithubRemote = (url) => {
786
+ const m = /github\.com[:/]+([^/]+)\/(.+?)(?:\.git)?\/?$/.exec(url.trim());
787
+ if (!m) return null;
788
+ const owner = m[1];
789
+ const repo = m[2];
790
+ if (!owner || !repo) return null;
791
+ return { owner, repo };
792
+ };
785
793
  var getDefaultBranch = async (cwd) => {
786
794
  try {
787
795
  const ref = (await runGit(cwd, ["rev-parse", "--abbrev-ref", "origin/HEAD"])).trim();
@@ -1115,6 +1123,10 @@ var createPrSchema = z.object({
1115
1123
  /** When set, the PR is created from this session's worktree branch. */
1116
1124
  sessionId: z.string().min(1).optional()
1117
1125
  });
1126
+ var pushSchema = z.object({
1127
+ title: z.string().min(1).max(200),
1128
+ sessionId: z.string().min(1).optional()
1129
+ });
1118
1130
  var buildRepoStatus = async (resolvedPath) => {
1119
1131
  const [branch, head, dirty] = await Promise.all([
1120
1132
  getBranch(resolvedPath),
@@ -1254,6 +1266,69 @@ var createRepoRouter = (state, worktrees) => {
1254
1266
  throw err;
1255
1267
  }
1256
1268
  });
1269
+ router.post("/push", async (req, res) => {
1270
+ const repo = requireSelectedRepo(state, res);
1271
+ if (!repo) return;
1272
+ const parsed = pushSchema.safeParse(req.body);
1273
+ if (!parsed.success) {
1274
+ res.status(400).json({ error: "invalid_body", issues: parsed.error.issues });
1275
+ return;
1276
+ }
1277
+ const worktree = parsed.data.sessionId ? worktrees.get(parsed.data.sessionId) : null;
1278
+ const cwd = worktree ? worktree.path : repo.path;
1279
+ try {
1280
+ const remoteUrl = await getRemoteUrl(cwd);
1281
+ if (!remoteUrl) {
1282
+ res.status(400).json({
1283
+ error: "no_remote",
1284
+ message: "This repo has no `origin` remote."
1285
+ });
1286
+ return;
1287
+ }
1288
+ const gh = parseGithubRemote(remoteUrl);
1289
+ if (!gh) {
1290
+ res.status(400).json({
1291
+ error: "not_github",
1292
+ message: "The `origin` remote isn't a GitHub repository."
1293
+ });
1294
+ return;
1295
+ }
1296
+ if (!await isDirty(cwd)) {
1297
+ res.status(409).json({
1298
+ error: "nothing_to_commit",
1299
+ message: "There are no changes in the working tree to open a PR for."
1300
+ });
1301
+ return;
1302
+ }
1303
+ let head;
1304
+ let base;
1305
+ if (worktree) {
1306
+ head = worktree.branch;
1307
+ base = worktree.base;
1308
+ } else {
1309
+ const current = await getBranch(cwd) ?? "";
1310
+ const onAgentBranch = current.startsWith("diologue/");
1311
+ base = onAgentBranch ? await getDefaultBranch(cwd) : current || "main";
1312
+ head = onAgentBranch ? current : branchNameForTitle(parsed.data.title);
1313
+ if (!onAgentBranch) await createBranch(cwd, head);
1314
+ }
1315
+ await commitAll(cwd, parsed.data.title);
1316
+ await pushBranch(cwd, head);
1317
+ const payload = {
1318
+ owner: gh.owner,
1319
+ repo: gh.repo,
1320
+ head,
1321
+ base
1322
+ };
1323
+ res.json(payload);
1324
+ } catch (err) {
1325
+ if (err instanceof GitCommandError) {
1326
+ sendGitError(res, err);
1327
+ return;
1328
+ }
1329
+ throw err;
1330
+ }
1331
+ });
1257
1332
  router.get("/status", async (_req, res) => {
1258
1333
  const repo = state.getSelectedRepo();
1259
1334
  if (!repo) {