dirban 0.1.6 → 0.1.8

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 (3) hide show
  1. package/README.md +1 -1
  2. package/dist/dirban.js +399 -221
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  > **Zero-database, folder-based Kanban board for builders, knowledge workers, and AI agents.**
4
4
 
5
- [![CI](https://github.com/SYip/dirban/actions/workflows/publish.yml/badge.svg)](https://github.com/SYip/dirban/actions)
5
+ [![CI](https://github.com/SYip/dirban/actions/workflows/ci.yml/badge.svg)](https://github.com/SYip/dirban/actions/workflows/ci.yml)
6
6
  [![npm version](https://img.shields.io/npm/v/dirban.svg?color=cb3837)](https://www.npmjs.com/package/dirban)
7
7
  [![Visual Studio Marketplace](https://img.shields.io/visual-studio-marketplace/v/syip.dirban-vscode?color=blue&label=VS%20Code)](https://marketplace.visualstudio.com/items?itemName=syip.dirban-vscode)
8
8
  [![Open VSX](https://img.shields.io/open-vsx/v/syip/dirban-vscode?color=purple&label=Open%20VSX)](https://open-vsx.org/extension/syip/dirban-vscode)
package/dist/dirban.js CHANGED
@@ -7198,7 +7198,7 @@ import * as process8 from "process";
7198
7198
  // package.json
7199
7199
  var package_default = {
7200
7200
  name: "dirban",
7201
- version: "0.1.6",
7201
+ version: "0.1.8",
7202
7202
  description: "Zero-Database, Agent-Native Kanban Engine & TUI Backed by the File System and Google Open Knowledge Format (OKF)",
7203
7203
  type: "module",
7204
7204
  main: "./dist/dirban.js",
@@ -7742,6 +7742,7 @@ var DEFAULT_CONFIG = Object.freeze({
7742
7742
  defaultPriority: DEFAULT_PRIORITY,
7743
7743
  branchStrategy: DEFAULT_BRANCH_STRATEGY,
7744
7744
  autoMerge: true,
7745
+ mergeStrategy: "merge",
7745
7746
  worktreesDir: DEFAULT_WORKTREES_DIR,
7746
7747
  branchPrefix: DEFAULT_BRANCH_PREFIX,
7747
7748
  focusColumn: undefined
@@ -7769,6 +7770,8 @@ var parseRawConfigObject = (raw, isVsCodeSettings = false) => {
7769
7770
  const branchStrategy = branchStrategyRaw === "checkout" || branchStrategyRaw === "worktree" || branchStrategyRaw === "none" ? branchStrategyRaw : undefined;
7770
7771
  const autoMergeRaw = getVal("autoMerge");
7771
7772
  const autoMerge = typeof autoMergeRaw === "boolean" ? autoMergeRaw : undefined;
7773
+ const mergeStrategyRaw = getVal("mergeStrategy");
7774
+ const mergeStrategy = mergeStrategyRaw === "merge" || mergeStrategyRaw === "squash" || mergeStrategyRaw === "rebase" ? mergeStrategyRaw : undefined;
7772
7775
  const worktreesDirRaw = getVal("worktreesDir");
7773
7776
  const worktreesDir = typeof worktreesDirRaw === "string" && worktreesDirRaw.trim() !== "" ? worktreesDirRaw.trim() : undefined;
7774
7777
  const branchPrefixRaw = getVal("branchPrefix");
@@ -7782,6 +7785,7 @@ var parseRawConfigObject = (raw, isVsCodeSettings = false) => {
7782
7785
  defaultPriority,
7783
7786
  branchStrategy,
7784
7787
  autoMerge,
7788
+ mergeStrategy,
7785
7789
  worktreesDir,
7786
7790
  branchPrefix,
7787
7791
  focusColumn
@@ -7825,6 +7829,7 @@ var loadConfig = (workspaceRoot = process.cwd()) => {
7825
7829
  defaultPriority: parsed.defaultPriority ?? DEFAULT_CONFIG.defaultPriority,
7826
7830
  branchStrategy: parsed.branchStrategy ?? DEFAULT_CONFIG.branchStrategy,
7827
7831
  autoMerge: parsed.autoMerge ?? DEFAULT_CONFIG.autoMerge,
7832
+ mergeStrategy: parsed.mergeStrategy ?? DEFAULT_CONFIG.mergeStrategy,
7828
7833
  worktreesDir: parsed.worktreesDir ?? DEFAULT_CONFIG.worktreesDir,
7829
7834
  branchPrefix: parsed.branchPrefix ?? DEFAULT_CONFIG.branchPrefix,
7830
7835
  focusColumn: parsed.focusColumn ?? DEFAULT_CONFIG.focusColumn
@@ -8111,7 +8116,7 @@ var import_picocolors2 = __toESM(require_picocolors2(), 1);
8111
8116
  import * as process3 from "node:process";
8112
8117
 
8113
8118
  // src/board/discovery.ts
8114
- import * as fs5 from "node:fs";
8119
+ import * as fs6 from "node:fs";
8115
8120
  import * as path7 from "node:path";
8116
8121
 
8117
8122
  // src/config/config.ts
@@ -8138,6 +8143,7 @@ var DEFAULT_CONFIG2 = Object.freeze({
8138
8143
  defaultPriority: DEFAULT_PRIORITY2,
8139
8144
  branchStrategy: DEFAULT_BRANCH_STRATEGY2,
8140
8145
  autoMerge: true,
8146
+ mergeStrategy: "merge",
8141
8147
  worktreesDir: DEFAULT_WORKTREES_DIR2,
8142
8148
  branchPrefix: DEFAULT_BRANCH_PREFIX2,
8143
8149
  focusColumn: undefined
@@ -8423,12 +8429,24 @@ var parseTaskDocument = (rawContent, filename) => {
8423
8429
 
8424
8430
  // src/vcs/git/commit.ts
8425
8431
  import { spawnSync } from "node:child_process";
8426
- var commitSingleGitFile = (context, filePath, message, cwd = process.cwd()) => {
8432
+ import * as fs3 from "node:fs";
8433
+ var isTrackedInGit = (filePath, cwd) => {
8434
+ const res = spawnSync("git", ["ls-files", "--error-unmatch", "--", filePath], {
8435
+ cwd,
8436
+ stdio: "ignore"
8437
+ });
8438
+ return res.status === 0;
8439
+ };
8440
+ var commitSingleGitFile = (context, filePaths, message, cwd = process.cwd()) => {
8427
8441
  if (!context.isAvailable || context.repoRoot == null) {
8428
8442
  return $ok(undefined);
8429
8443
  }
8444
+ const stageablePaths = filePaths.filter((p) => fs3.existsSync(p) || isTrackedInGit(p, cwd));
8445
+ if (stageablePaths.length === 0) {
8446
+ return $ok(undefined);
8447
+ }
8430
8448
  try {
8431
- const addRes = spawnSync("git", ["add", filePath], {
8449
+ const addRes = spawnSync("git", ["add", "--", ...stageablePaths], {
8432
8450
  cwd,
8433
8451
  encoding: "utf-8",
8434
8452
  stdio: ["pipe", "pipe", "pipe"]
@@ -8436,10 +8454,10 @@ var commitSingleGitFile = (context, filePath, message, cwd = process.cwd()) => {
8436
8454
  if (addRes.status !== 0) {
8437
8455
  return $err({
8438
8456
  kind: "COMMAND_ERROR",
8439
- message: `Failed to stage file '${filePath}': ${addRes.stderr.trim()}`
8457
+ message: `Failed to stage file(s) '${stageablePaths.join(", ")}': ${addRes.stderr.trim()}`
8440
8458
  });
8441
8459
  }
8442
- const commitRes = spawnSync("git", ["commit", "-m", message, "--", filePath], {
8460
+ const commitRes = spawnSync("git", ["commit", "-m", message, "--", ...stageablePaths], {
8443
8461
  cwd,
8444
8462
  encoding: "utf-8",
8445
8463
  stdio: ["pipe", "pipe", "pipe"]
@@ -8447,7 +8465,7 @@ var commitSingleGitFile = (context, filePath, message, cwd = process.cwd()) => {
8447
8465
  if (commitRes.status !== 0) {
8448
8466
  return $err({
8449
8467
  kind: "COMMAND_ERROR",
8450
- message: `Failed to commit file '${filePath}': ${commitRes.stderr.trim()}`
8468
+ message: `Failed to commit file(s) '${stageablePaths.join(", ")}': ${commitRes.stderr.trim()}`
8451
8469
  });
8452
8470
  }
8453
8471
  return $ok(undefined);
@@ -8460,19 +8478,185 @@ var commitSingleGitFile = (context, filePath, message, cwd = process.cwd()) => {
8460
8478
  }
8461
8479
  };
8462
8480
  // src/vcs/git/git.ts
8463
- import { spawnSync as spawnSync3 } from "node:child_process";
8464
- import * as fs3 from "node:fs";
8481
+ import { spawnSync as spawnSync4 } from "node:child_process";
8482
+ import * as fs4 from "node:fs";
8465
8483
  import * as path4 from "node:path";
8466
8484
 
8467
- // src/vcs/git/status.ts
8485
+ // src/vcs/git/merge.ts
8468
8486
  import { spawnSync as spawnSync2 } from "node:child_process";
8487
+ var integrateSquash = (repoRoot, taskBranch, baseBranch, commitMessage) => {
8488
+ const squashRes = spawnSync2("git", ["merge", "--squash", taskBranch], {
8489
+ cwd: repoRoot,
8490
+ encoding: "utf-8",
8491
+ stdio: ["pipe", "pipe", "pipe"]
8492
+ });
8493
+ if (squashRes.status !== 0) {
8494
+ spawnSync2("git", ["reset", "--merge"], { cwd: repoRoot, stdio: "ignore" });
8495
+ return $err({
8496
+ kind: "MERGE_ERROR",
8497
+ message: `Failed to squash merge ${taskBranch} into ${baseBranch}: ${squashRes.stderr.trim()}`
8498
+ });
8499
+ }
8500
+ const msg = commitMessage ?? `chore(task): squash ${taskBranch}`;
8501
+ const commitRes = spawnSync2("git", ["commit", "-m", msg], {
8502
+ cwd: repoRoot,
8503
+ encoding: "utf-8",
8504
+ stdio: ["pipe", "pipe", "pipe"]
8505
+ });
8506
+ if (commitRes.status !== 0) {
8507
+ return $err({
8508
+ kind: "MERGE_ERROR",
8509
+ message: `Failed to commit squashed ${taskBranch}: ${commitRes.stderr.trim()}`
8510
+ });
8511
+ }
8512
+ spawnSync2("git", ["branch", "-D", taskBranch], { cwd: repoRoot, stdio: "ignore" });
8513
+ return $ok(undefined);
8514
+ };
8515
+ var integrateRebase = (repoRoot, taskBranch, baseBranch) => {
8516
+ const rebaseRes = spawnSync2("git", ["rebase", baseBranch, taskBranch], {
8517
+ cwd: repoRoot,
8518
+ encoding: "utf-8",
8519
+ stdio: ["pipe", "pipe", "pipe"]
8520
+ });
8521
+ if (rebaseRes.status !== 0) {
8522
+ spawnSync2("git", ["rebase", "--abort"], { cwd: repoRoot, stdio: "ignore" });
8523
+ return $err({
8524
+ kind: "MERGE_ERROR",
8525
+ message: `Failed to rebase ${taskBranch} onto ${baseBranch}: ${rebaseRes.stderr.trim()}`
8526
+ });
8527
+ }
8528
+ const checkoutRes = spawnSync2("git", ["checkout", baseBranch], {
8529
+ cwd: repoRoot,
8530
+ encoding: "utf-8",
8531
+ stdio: ["pipe", "pipe", "pipe"]
8532
+ });
8533
+ if (checkoutRes.status !== 0) {
8534
+ return $err({
8535
+ kind: "COMMAND_ERROR",
8536
+ message: `Failed to checkout ${baseBranch}: ${checkoutRes.stderr.trim()}`
8537
+ });
8538
+ }
8539
+ const ffRes = spawnSync2("git", ["merge", "--ff-only", taskBranch], {
8540
+ cwd: repoRoot,
8541
+ encoding: "utf-8",
8542
+ stdio: ["pipe", "pipe", "pipe"]
8543
+ });
8544
+ if (ffRes.status !== 0) {
8545
+ return $err({
8546
+ kind: "MERGE_ERROR",
8547
+ message: `Failed to fast-forward ${baseBranch} to ${taskBranch}: ${ffRes.stderr.trim()}`
8548
+ });
8549
+ }
8550
+ spawnSync2("git", ["branch", "-d", taskBranch], { cwd: repoRoot, stdio: "ignore" });
8551
+ return $ok(undefined);
8552
+ };
8553
+ var integrateMerge = (repoRoot, taskBranch, baseBranch) => {
8554
+ const mergeResult = spawnSync2("git", ["merge", "--no-ff", "-m", `Merge branch '${taskBranch}' into ${baseBranch}`, taskBranch], { cwd: repoRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
8555
+ if (mergeResult.status !== 0) {
8556
+ spawnSync2("git", ["merge", "--abort"], { cwd: repoRoot, stdio: "ignore" });
8557
+ return $err({
8558
+ kind: "MERGE_ERROR",
8559
+ message: `Failed to merge ${taskBranch} into ${baseBranch}: ${mergeResult.stderr.trim()}`
8560
+ });
8561
+ }
8562
+ return $ok(undefined);
8563
+ };
8564
+ var integrateBranch = (repoRoot, taskBranch, baseBranch, strategy, commitMessage) => {
8565
+ const strategies = {
8566
+ squash: () => integrateSquash(repoRoot, taskBranch, baseBranch, commitMessage),
8567
+ rebase: () => integrateRebase(repoRoot, taskBranch, baseBranch),
8568
+ merge: () => integrateMerge(repoRoot, taskBranch, baseBranch)
8569
+ };
8570
+ return strategies[strategy]();
8571
+ };
8572
+ var mergeWorktreeAndCleanup = (repoRoot, cwd, options, strategy) => {
8573
+ const headRes = spawnSync2("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
8574
+ cwd: repoRoot,
8575
+ encoding: "utf-8",
8576
+ stdio: ["pipe", "pipe", "pipe"]
8577
+ });
8578
+ const currentBranch = headRes.stdout?.trim();
8579
+ if (currentBranch !== options.baseBranch) {
8580
+ const checkoutBase = spawnSync2("git", ["checkout", options.baseBranch], {
8581
+ cwd: repoRoot,
8582
+ encoding: "utf-8",
8583
+ stdio: ["pipe", "pipe", "pipe"]
8584
+ });
8585
+ if (checkoutBase.status !== 0) {
8586
+ return $err({
8587
+ kind: "COMMAND_ERROR",
8588
+ message: `Failed to checkout ${options.baseBranch} in ${repoRoot}: ${checkoutBase.stderr.trim()}`
8589
+ });
8590
+ }
8591
+ }
8592
+ if (strategy === "rebase") {
8593
+ const rebaseRes = spawnSync2("git", ["rebase", options.baseBranch], {
8594
+ cwd,
8595
+ encoding: "utf-8",
8596
+ stdio: ["pipe", "pipe", "pipe"]
8597
+ });
8598
+ if (rebaseRes.status !== 0) {
8599
+ spawnSync2("git", ["rebase", "--abort"], { cwd, stdio: "ignore" });
8600
+ return $err({
8601
+ kind: "MERGE_ERROR",
8602
+ message: `Failed to rebase ${options.taskBranch} onto ${options.baseBranch}: ${rebaseRes.stderr.trim()}`
8603
+ });
8604
+ }
8605
+ const ffRes = spawnSync2("git", ["merge", "--ff-only", options.taskBranch], {
8606
+ cwd: repoRoot,
8607
+ encoding: "utf-8",
8608
+ stdio: ["pipe", "pipe", "pipe"]
8609
+ });
8610
+ if (ffRes.status !== 0) {
8611
+ return $err({
8612
+ kind: "MERGE_ERROR",
8613
+ message: `Failed to fast-forward ${options.baseBranch} to ${options.taskBranch}: ${ffRes.stderr.trim()}`
8614
+ });
8615
+ }
8616
+ } else {
8617
+ const integrateRes = integrateBranch(repoRoot, options.taskBranch, options.baseBranch, strategy, options.commitMessage);
8618
+ if (integrateRes.isErr())
8619
+ return $err(integrateRes.error);
8620
+ }
8621
+ const removeResult = spawnSync2("git", ["worktree", "remove", cwd], {
8622
+ cwd: repoRoot,
8623
+ encoding: "utf-8",
8624
+ stdio: ["pipe", "pipe", "pipe"]
8625
+ });
8626
+ const branchDeleteFlag = strategy === "squash" ? "-D" : "-d";
8627
+ spawnSync2("git", ["branch", branchDeleteFlag, options.taskBranch], {
8628
+ cwd: repoRoot,
8629
+ stdio: "ignore"
8630
+ });
8631
+ return $ok({ worktreeRemoved: removeResult.status === 0 });
8632
+ };
8633
+ var mergeInPlaceBranch = (repoRoot, options, strategy) => {
8634
+ const checkoutBase = spawnSync2("git", ["checkout", options.baseBranch], {
8635
+ cwd: repoRoot,
8636
+ encoding: "utf-8",
8637
+ stdio: ["pipe", "pipe", "pipe"]
8638
+ });
8639
+ if (checkoutBase.status !== 0) {
8640
+ return $err({
8641
+ kind: "COMMAND_ERROR",
8642
+ message: `Failed to checkout ${options.baseBranch}: ${checkoutBase.stderr.trim()}`
8643
+ });
8644
+ }
8645
+ const integrateRes = integrateBranch(repoRoot, options.taskBranch, options.baseBranch, strategy, options.commitMessage);
8646
+ if (integrateRes.isErr())
8647
+ return $err(integrateRes.error);
8648
+ return $ok({ worktreeRemoved: false });
8649
+ };
8650
+
8651
+ // src/vcs/git/status.ts
8652
+ import { spawnSync as spawnSync3 } from "node:child_process";
8469
8653
  var checkGitWorkingTreeClean = (context, options) => {
8470
8654
  const cwd = options?.cwd ?? process.cwd();
8471
8655
  if (!context.isAvailable || context.repoRoot == null) {
8472
8656
  return $ok(undefined);
8473
8657
  }
8474
8658
  try {
8475
- const statusRes = spawnSync2("git", ["status", "--porcelain=v1", "-uall"], {
8659
+ const statusRes = spawnSync3("git", ["status", "--porcelain=v1", "-uall"], {
8476
8660
  cwd,
8477
8661
  encoding: "utf-8",
8478
8662
  stdio: ["pipe", "pipe", "pipe"]
@@ -8540,7 +8724,7 @@ class GitVcsProvider {
8540
8724
  name = "git";
8541
8725
  getContext(cwd = process.cwd()) {
8542
8726
  try {
8543
- const isInsideWorktreeResult = spawnSync3("git", ["rev-parse", "--is-inside-work-tree"], {
8727
+ const isInsideWorktreeResult = spawnSync4("git", ["rev-parse", "--is-inside-work-tree"], {
8544
8728
  cwd,
8545
8729
  encoding: "utf-8",
8546
8730
  stdio: ["pipe", "pipe", "pipe"]
@@ -8549,19 +8733,19 @@ class GitVcsProvider {
8549
8733
  if (!isGitRepo) {
8550
8734
  return { isAvailable: false };
8551
8735
  }
8552
- const branchResult = spawnSync3("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
8736
+ const branchResult = spawnSync4("git", ["rev-parse", "--abbrev-ref", "HEAD"], {
8553
8737
  cwd,
8554
8738
  encoding: "utf-8",
8555
8739
  stdio: ["pipe", "pipe", "pipe"]
8556
8740
  });
8557
8741
  const branchName = branchResult.status === 0 ? branchResult.stdout.trim() : undefined;
8558
- const rootResult = spawnSync3("git", ["rev-parse", "--show-toplevel"], {
8742
+ const rootResult = spawnSync4("git", ["rev-parse", "--show-toplevel"], {
8559
8743
  cwd,
8560
8744
  encoding: "utf-8",
8561
8745
  stdio: ["pipe", "pipe", "pipe"]
8562
8746
  });
8563
8747
  const repoRoot = rootResult.status === 0 ? rootResult.stdout.trim() : undefined;
8564
- const gitDirResult = spawnSync3("git", ["rev-parse", "--git-dir"], {
8748
+ const gitDirResult = spawnSync4("git", ["rev-parse", "--git-dir"], {
8565
8749
  cwd,
8566
8750
  encoding: "utf-8",
8567
8751
  stdio: ["pipe", "pipe", "pipe"]
@@ -8621,7 +8805,7 @@ class GitVcsProvider {
8621
8805
  const trimmedTarget = taskIdOrTarget?.trim().toLowerCase();
8622
8806
  const isTargetingMain = trimmedTarget == null || trimmedTarget === "" || trimmedTarget === "main" || trimmedTarget === "root";
8623
8807
  if (isTargetingMain) {
8624
- const commonDirResult = spawnSync3("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
8808
+ const commonDirResult = spawnSync4("git", ["rev-parse", "--path-format=absolute", "--git-common-dir"], { cwd, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
8625
8809
  if (commonDirResult.status === 0 && commonDirResult.stdout.trim() !== "") {
8626
8810
  const commonDir = commonDirResult.stdout.trim();
8627
8811
  const mainRoot = path4.resolve(commonDir, "..");
@@ -8629,7 +8813,7 @@ class GitVcsProvider {
8629
8813
  }
8630
8814
  return $ok(ctx.repoRoot);
8631
8815
  }
8632
- const worktreeListResult = spawnSync3("git", ["worktree", "list", "--porcelain"], {
8816
+ const worktreeListResult = spawnSync4("git", ["worktree", "list", "--porcelain"], {
8633
8817
  cwd: ctx.repoRoot,
8634
8818
  encoding: "utf-8",
8635
8819
  stdio: ["pipe", "pipe", "pipe"]
@@ -8658,7 +8842,7 @@ class GitVcsProvider {
8658
8842
  message: "Git repository not detected"
8659
8843
  });
8660
8844
  }
8661
- const worktreeListResult = spawnSync3("git", ["worktree", "list", "--porcelain"], {
8845
+ const worktreeListResult = spawnSync4("git", ["worktree", "list", "--porcelain"], {
8662
8846
  cwd: ctx.repoRoot,
8663
8847
  encoding: "utf-8",
8664
8848
  stdio: ["pipe", "pipe", "pipe"]
@@ -8686,7 +8870,7 @@ class GitVcsProvider {
8686
8870
  });
8687
8871
  }
8688
8872
  const args = force ? ["worktree", "remove", "--force", targetPath] : ["worktree", "remove", targetPath];
8689
- const removeResult = spawnSync3("git", args, {
8873
+ const removeResult = spawnSync4("git", args, {
8690
8874
  cwd: ctx.repoRoot,
8691
8875
  encoding: "utf-8",
8692
8876
  stdio: ["pipe", "pipe", "pipe"]
@@ -8710,14 +8894,14 @@ class GitVcsProvider {
8710
8894
  if (ctx.currentBranch === branchName) {
8711
8895
  return $ok({ alreadyOnBranch: true });
8712
8896
  }
8713
- const branchCheck = spawnSync3("git", ["rev-parse", "--verify", `refs/heads/${branchName}`], {
8897
+ const branchCheck = spawnSync4("git", ["rev-parse", "--verify", `refs/heads/${branchName}`], {
8714
8898
  cwd: ctx.repoRoot,
8715
8899
  encoding: "utf-8",
8716
8900
  stdio: ["pipe", "pipe", "pipe"]
8717
8901
  });
8718
8902
  const branchExists = branchCheck.status === 0;
8719
8903
  const checkoutArgs = branchExists ? ["checkout", branchName] : ["checkout", "-b", branchName];
8720
- const checkoutResult = spawnSync3("git", checkoutArgs, {
8904
+ const checkoutResult = spawnSync4("git", checkoutArgs, {
8721
8905
  cwd: ctx.repoRoot,
8722
8906
  encoding: "utf-8",
8723
8907
  stdio: ["pipe", "pipe", "pipe"]
@@ -8738,21 +8922,21 @@ class GitVcsProvider {
8738
8922
  message: "Git repository not detected"
8739
8923
  });
8740
8924
  }
8741
- if (fs3.existsSync(targetPath)) {
8925
+ if (fs4.existsSync(targetPath)) {
8742
8926
  return $err({
8743
8927
  kind: "WORKTREE_ERROR",
8744
8928
  message: `Worktree path already exists: ${targetPath}`
8745
8929
  });
8746
8930
  }
8747
- fs3.mkdirSync(path4.dirname(targetPath), { recursive: true });
8748
- const branchCheck = spawnSync3("git", ["rev-parse", "--verify", `refs/heads/${branchName}`], {
8931
+ fs4.mkdirSync(path4.dirname(targetPath), { recursive: true });
8932
+ const branchCheck = spawnSync4("git", ["rev-parse", "--verify", `refs/heads/${branchName}`], {
8749
8933
  cwd: ctx.repoRoot,
8750
8934
  encoding: "utf-8",
8751
8935
  stdio: ["pipe", "pipe", "pipe"]
8752
8936
  });
8753
8937
  const branchExists = branchCheck.status === 0;
8754
8938
  const worktreeArgs = branchExists ? ["worktree", "add", targetPath, branchName] : ["worktree", "add", "-b", branchName, targetPath];
8755
- const worktreeResult = spawnSync3("git", worktreeArgs, {
8939
+ const worktreeResult = spawnSync4("git", worktreeArgs, {
8756
8940
  cwd: ctx.repoRoot,
8757
8941
  encoding: "utf-8",
8758
8942
  stdio: ["pipe", "pipe", "pipe"]
@@ -8770,10 +8954,10 @@ class GitVcsProvider {
8770
8954
  const ctx = this.getContext(cwd);
8771
8955
  return checkGitWorkingTreeClean(ctx, options);
8772
8956
  }
8773
- commitFile(filePath, message, cwd) {
8957
+ commitFile(filePaths, message, cwd) {
8774
8958
  const workingDir = cwd ?? process.cwd();
8775
8959
  const ctx = this.getContext(workingDir);
8776
- return commitSingleGitFile(ctx, filePath, message, workingDir);
8960
+ return commitSingleGitFile(ctx, filePaths, message, workingDir);
8777
8961
  }
8778
8962
  autoMergeAndCleanup(options) {
8779
8963
  const cwd = options.cwd ?? process.cwd();
@@ -8786,64 +8970,23 @@ class GitVcsProvider {
8786
8970
  }
8787
8971
  const repoRoot = ctx.repoRoot;
8788
8972
  const commitMsg = options.commitMessage ?? `docs: complete task and move to done`;
8789
- const addResult = spawnSync3("git", ["add", "-A"], {
8973
+ const addResult = spawnSync4("git", ["add", "-A"], {
8790
8974
  cwd,
8791
8975
  encoding: "utf-8",
8792
8976
  stdio: ["pipe", "pipe", "pipe"]
8793
8977
  });
8794
8978
  if (addResult.status === 0) {
8795
- spawnSync3("git", ["commit", "-m", commitMsg], {
8979
+ spawnSync4("git", ["commit", "-m", commitMsg], {
8796
8980
  cwd,
8797
8981
  encoding: "utf-8",
8798
8982
  stdio: ["pipe", "pipe", "pipe"]
8799
8983
  });
8800
8984
  }
8985
+ const strategy = options.mergeStrategy ?? "merge";
8801
8986
  if (options.isWorktree) {
8802
- const mergeResult = spawnSync3("git", [
8803
- "merge",
8804
- "--no-ff",
8805
- "-m",
8806
- `Merge branch '${options.taskBranch}' into ${options.baseBranch}`,
8807
- options.taskBranch
8808
- ], { cwd: repoRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
8809
- if (mergeResult.status !== 0) {
8810
- return $err({
8811
- kind: "MERGE_ERROR",
8812
- message: `Failed to merge ${options.taskBranch} into ${options.baseBranch}: ${mergeResult.stderr.trim()}`
8813
- });
8814
- }
8815
- const removeResult = spawnSync3("git", ["worktree", "remove", cwd], {
8816
- cwd: repoRoot,
8817
- encoding: "utf-8",
8818
- stdio: ["pipe", "pipe", "pipe"]
8819
- });
8820
- return $ok({ worktreeRemoved: removeResult.status === 0 });
8987
+ return mergeWorktreeAndCleanup(repoRoot, cwd, options, strategy);
8821
8988
  }
8822
- const checkoutBase = spawnSync3("git", ["checkout", options.baseBranch], {
8823
- cwd: repoRoot,
8824
- encoding: "utf-8",
8825
- stdio: ["pipe", "pipe", "pipe"]
8826
- });
8827
- if (checkoutBase.status !== 0) {
8828
- return $err({
8829
- kind: "COMMAND_ERROR",
8830
- message: `Failed to checkout ${options.baseBranch}: ${checkoutBase.stderr.trim()}`
8831
- });
8832
- }
8833
- const mergeResult = spawnSync3("git", [
8834
- "merge",
8835
- "--no-ff",
8836
- "-m",
8837
- `Merge branch '${options.taskBranch}' into ${options.baseBranch}`,
8838
- options.taskBranch
8839
- ], { cwd: repoRoot, encoding: "utf-8", stdio: ["pipe", "pipe", "pipe"] });
8840
- if (mergeResult.status !== 0) {
8841
- return $err({
8842
- kind: "MERGE_ERROR",
8843
- message: `Failed to merge ${options.taskBranch} into ${options.baseBranch}: ${mergeResult.stderr.trim()}`
8844
- });
8845
- }
8846
- return $ok({ worktreeRemoved: false });
8989
+ return mergeInPlaceBranch(repoRoot, options, strategy);
8847
8990
  }
8848
8991
  }
8849
8992
  // src/vcs/noop.ts
@@ -8902,7 +9045,7 @@ class NoopVcsProvider {
8902
9045
  checkWorkingTreeClean(_options) {
8903
9046
  return $ok(undefined);
8904
9047
  }
8905
- commitFile(_filePath, _message, _cwd) {
9048
+ commitFile(_filePaths, _message, _cwd) {
8906
9049
  return $ok(undefined);
8907
9050
  }
8908
9051
  autoMergeAndCleanup(_options) {
@@ -8924,7 +9067,7 @@ var getVcsProvider = (cwd = process.cwd()) => {
8924
9067
  };
8925
9068
 
8926
9069
  // src/board/overlay.ts
8927
- import * as fs4 from "node:fs";
9070
+ import * as fs5 from "node:fs";
8928
9071
  import * as path6 from "node:path";
8929
9072
  var buildWorktreeTaskMap = (vcs, workspaceRoot) => {
8930
9073
  const vcsCtx = vcs.getContext(workspaceRoot);
@@ -8956,11 +9099,11 @@ var overlayWorktreeTask = (task, worktreeMap, tasksDir) => {
8956
9099
  return task;
8957
9100
  }
8958
9101
  const worktreeTaskFile = path6.join(worktreePath, tasksDir, task.column, task.filename);
8959
- if (!fs4.existsSync(worktreeTaskFile)) {
9102
+ if (!fs5.existsSync(worktreeTaskFile)) {
8960
9103
  return task;
8961
9104
  }
8962
9105
  try {
8963
- const content = fs4.readFileSync(worktreeTaskFile, "utf-8");
9106
+ const content = fs5.readFileSync(worktreeTaskFile, "utf-8");
8964
9107
  const parseRes = parseTaskDocument(content, task.filename);
8965
9108
  if (parseRes.isErr()) {
8966
9109
  return task;
@@ -9061,7 +9204,7 @@ var filterTasks = (tasks, filter) => {
9061
9204
  var discoverBoard = (config, workspaceRoot = process.cwd(), options) => {
9062
9205
  const rootDir = path7.isAbsolute(config.tasksDir) ? config.tasksDir : path7.join(workspaceRoot, config.tasksDir);
9063
9206
  try {
9064
- const dirInfo = fs5.statSync(rootDir);
9207
+ const dirInfo = fs6.statSync(rootDir);
9065
9208
  if (!dirInfo.isDirectory()) {
9066
9209
  return $err({
9067
9210
  kind: "DIRECTORY_NOT_FOUND",
@@ -9085,7 +9228,7 @@ var discoverBoard = (config, workspaceRoot = process.cwd(), options) => {
9085
9228
  }
9086
9229
  const discoveredDirNames = [];
9087
9230
  try {
9088
- for (const entry of fs5.readdirSync(rootDir, { withFileTypes: true })) {
9231
+ for (const entry of fs6.readdirSync(rootDir, { withFileTypes: true })) {
9089
9232
  if (entry.isDirectory() && !entry.name.startsWith(".")) {
9090
9233
  discoveredDirNames.push(entry.name);
9091
9234
  }
@@ -9120,10 +9263,10 @@ var discoverBoard = (config, workspaceRoot = process.cwd(), options) => {
9120
9263
  const colPath = path7.join(rootDir, colName);
9121
9264
  const taskList = [];
9122
9265
  try {
9123
- for (const entry of fs5.readdirSync(colPath, { withFileTypes: true })) {
9266
+ for (const entry of fs6.readdirSync(colPath, { withFileTypes: true })) {
9124
9267
  if (entry.isFile() && entry.name.endsWith(".md")) {
9125
9268
  const filePath = path7.join(colPath, entry.name);
9126
- const content = fs5.readFileSync(filePath, "utf-8");
9269
+ const content = fs6.readFileSync(filePath, "utf-8");
9127
9270
  const parseResult = parseTaskDocument(content, entry.name);
9128
9271
  if (parseResult.isOk()) {
9129
9272
  let doc = parseResult.value;
@@ -9236,10 +9379,10 @@ var findTaskByIdOrName = (board, idOrPath) => {
9236
9379
  };
9237
9380
 
9238
9381
  // src/tasks/mutation/check.ts
9239
- import * as fs7 from "node:fs";
9382
+ import * as fs8 from "node:fs";
9240
9383
 
9241
9384
  // src/tasks/mutation/move.ts
9242
- import * as fs6 from "node:fs";
9385
+ import * as fs7 from "node:fs";
9243
9386
  import * as path8 from "node:path";
9244
9387
  var getIsoDate = () => {
9245
9388
  if (typeof Temporal !== "undefined" && Temporal?.Now != null) {
@@ -9269,7 +9412,7 @@ var moveTask = (board, taskIdOrPath, targetColumnName) => {
9269
9412
  }
9270
9413
  const newFilePath = path8.join(targetCol.path, task.filename);
9271
9414
  try {
9272
- fs6.renameSync(task.filePath, newFilePath);
9415
+ fs7.renameSync(task.filePath, newFilePath);
9273
9416
  const updatedDoc = Object.freeze({
9274
9417
  ...task.document,
9275
9418
  frontmatter: Object.freeze({
@@ -9327,7 +9470,7 @@ var checkTaskItem = (board, taskIdOrPath, targetIndex, forcedState) => {
9327
9470
  });
9328
9471
  let fileContent;
9329
9472
  try {
9330
- fileContent = fs7.readFileSync(task.filePath, "utf-8");
9473
+ fileContent = fs8.readFileSync(task.filePath, "utf-8");
9331
9474
  } catch (readErr) {
9332
9475
  return $err({
9333
9476
  kind: "FS_ERROR",
@@ -9357,7 +9500,7 @@ var checkTaskItem = (board, taskIdOrPath, targetIndex, forcedState) => {
9357
9500
  rawBody: updatedLines.join(eol)
9358
9501
  });
9359
9502
  try {
9360
- fs7.writeFileSync(task.filePath, updatedLines.join(eol), "utf-8");
9503
+ fs8.writeFileSync(task.filePath, updatedLines.join(eol), "utf-8");
9361
9504
  return $ok(Object.freeze({
9362
9505
  ...task,
9363
9506
  document: updatedDoc
@@ -9726,7 +9869,7 @@ var viewCommand = {
9726
9869
 
9727
9870
  // src/tasks/lifecycle/current.cli.ts
9728
9871
  var import_picocolors4 = __toESM(require_picocolors2(), 1);
9729
- import * as fs8 from "node:fs";
9872
+ import * as fs9 from "node:fs";
9730
9873
  import * as process5 from "node:process";
9731
9874
 
9732
9875
  // src/tasks/lifecycle/current.ts
@@ -9817,7 +9960,7 @@ var handleCurrent = (ctx) => {
9817
9960
  const { task, multipleInDoing, doingCount } = currentRes.value;
9818
9961
  if (ctx.flags.raw) {
9819
9962
  try {
9820
- const rawContent = fs8.readFileSync(task.filePath, "utf-8");
9963
+ const rawContent = fs9.readFileSync(task.filePath, "utf-8");
9821
9964
  process5.stdout.write(rawContent);
9822
9965
  return 0;
9823
9966
  } catch (readErr) {
@@ -9990,7 +10133,8 @@ class GitBranchStrategy {
9990
10133
  baseBranch,
9991
10134
  isWorktree: false,
9992
10135
  cwd: ctx.cwd,
9993
- commitMessage
10136
+ commitMessage,
10137
+ mergeStrategy: options?.mergeStrategy ?? ctx.config.mergeStrategy
9994
10138
  });
9995
10139
  if (mergeResult.isErr()) {
9996
10140
  return $err({
@@ -10053,6 +10197,18 @@ class GitWorktreeStrategy {
10053
10197
  gitSkipped: false
10054
10198
  });
10055
10199
  }
10200
+ validateDone(task, ctx, options) {
10201
+ const willMerge = options?.noMerge !== undefined ? !options.noMerge : ctx.config.autoMerge !== false;
10202
+ if (ctx.vcsCtx.isWorktree && willMerge) {
10203
+ const displayId = task.document.id ?? task.filename;
10204
+ const mainRepo = ctx.vcsCtx.repoRoot ?? "the main repository";
10205
+ return $err({
10206
+ kind: "GIT_ERROR",
10207
+ message: `Cannot run 'dirban done' with auto-merge from inside a linked worktree. Run 'dirban done ${displayId}' from ${mainRepo} instead, or pass --no-merge.`
10208
+ });
10209
+ }
10210
+ return $ok(undefined);
10211
+ }
10056
10212
  onDone(task, ctx, options) {
10057
10213
  const effectiveId = getEffectiveTaskId(task);
10058
10214
  const detectedId = ctx.vcs.extractTaskId(ctx.vcsCtx.currentBranch, ctx.cwd);
@@ -10087,7 +10243,8 @@ class GitWorktreeStrategy {
10087
10243
  baseBranch,
10088
10244
  isWorktree: ctx.vcsCtx.isWorktree ?? false,
10089
10245
  cwd: ctx.cwd,
10090
- commitMessage
10246
+ commitMessage,
10247
+ mergeStrategy: options?.mergeStrategy ?? ctx.config.mergeStrategy
10091
10248
  });
10092
10249
  if (mergeResult.isErr()) {
10093
10250
  return $err({
@@ -10162,12 +10319,12 @@ var detectWorkspaceDoneStrategy = (task, options, vcsCtx, vcs, config, cwd) => {
10162
10319
  return new GitBranchStrategy;
10163
10320
  };
10164
10321
  // src/tasks/mutation/archive.ts
10165
- import * as fs9 from "node:fs";
10322
+ import * as fs10 from "node:fs";
10166
10323
  import * as path9 from "node:path";
10167
10324
  var archiveTasks = (board, config, taskIdOrAll, workspaceRoot = process.cwd()) => {
10168
10325
  const archiveBaseDir = path9.isAbsolute(config.archiveDir) ? config.archiveDir : path9.join(workspaceRoot, config.archiveDir);
10169
10326
  try {
10170
- fs9.mkdirSync(archiveBaseDir, { recursive: true });
10327
+ fs10.mkdirSync(archiveBaseDir, { recursive: true });
10171
10328
  } catch (mkdirErr) {
10172
10329
  return $err({
10173
10330
  kind: "FS_ERROR",
@@ -10196,7 +10353,7 @@ var archiveTasks = (board, config, taskIdOrAll, workspaceRoot = process.cwd()) =
10196
10353
  for (const task of tasksToArchive) {
10197
10354
  const destPath = path9.join(archiveBaseDir, task.filename);
10198
10355
  try {
10199
- fs9.renameSync(task.filePath, destPath);
10356
+ fs10.renameSync(task.filePath, destPath);
10200
10357
  archived.push({
10201
10358
  ...task,
10202
10359
  filePath: destPath,
@@ -10219,100 +10376,97 @@ var archiveTasks = (board, config, taskIdOrAll, workspaceRoot = process.cwd()) =
10219
10376
  var countUncheckedCriteria = (task) => {
10220
10377
  return task.document.acceptanceCriteria.filter((item) => !item.checked).length;
10221
10378
  };
10222
- var doneTask = (board, config, taskId, options) => {
10223
- const cwd = options?.cwd ?? process.cwd();
10224
- const vcs = options?.vcsProvider ?? getVcsProvider(cwd);
10225
- const focusColName = resolveFocusColumn(config);
10226
- let taskToDone;
10227
- if (taskId != null && taskId.trim() !== "") {
10228
- const trimmedId = taskId.trim();
10229
- const found = findTaskByIdOrName(board, trimmedId) ?? findTaskExact(board, trimmedId);
10230
- if (found == null) {
10231
- return $err({
10232
- kind: "TASK_NOT_FOUND",
10233
- id: trimmedId,
10234
- message: `Task not found: ${trimmedId}`
10235
- });
10236
- }
10237
- taskToDone = found;
10238
- if (focusColName != null && taskToDone.column !== focusColName) {
10239
- const displayId = taskToDone.document.id ?? taskToDone.filename;
10240
- const isCompleted = taskToDone.column === ARCHIVE_COLUMN2 || taskToDone.column === "archive" || taskToDone.column === DEFAULT_COLUMNS2[DEFAULT_COLUMNS2.length - 1];
10241
- if (isCompleted) {
10242
- return $err({
10243
- kind: "ALREADY_COMPLETED",
10244
- message: `Task ${displayId} is already completed in '${taskToDone.column}'.`
10245
- });
10246
- }
10247
- if (taskToDone.column === BACKLOG_COLUMN2 || taskToDone.column === "backlog") {
10248
- return $err({
10249
- kind: "INVALID_COLUMN_TRANSITION",
10250
- message: `Cannot mark task ${displayId} as done: task is in '${taskToDone.column}'. Run 'dirban ready ${displayId}' first.`,
10251
- currentColumn: taskToDone.column,
10252
- expectedColumn: focusColName,
10253
- id: trimmedId,
10254
- suggestion: `dirban ready ${displayId}`
10255
- });
10256
- }
10257
- const preFocusCol = resolvePreviousColumn(config, focusColName) ?? DEFAULT_COLUMNS2[0];
10258
- if (taskToDone.column === preFocusCol) {
10259
- return $err({
10260
- kind: "INVALID_COLUMN_TRANSITION",
10261
- message: `Cannot mark task ${displayId} as done: task is in '${taskToDone.column}'. Run 'dirban start ${displayId}' first.`,
10262
- currentColumn: taskToDone.column,
10263
- expectedColumn: focusColName,
10264
- id: trimmedId,
10265
- suggestion: `dirban start ${displayId}`
10266
- });
10267
- }
10268
- return $err({
10269
- kind: "INVALID_COLUMN_TRANSITION",
10270
- message: `Cannot mark task ${displayId} as done: task is in '${taskToDone.column}' (expected '${focusColName}').`,
10271
- currentColumn: taskToDone.column,
10272
- expectedColumn: focusColName,
10273
- id: trimmedId
10274
- });
10275
- }
10276
- } else {
10379
+ var resolveDoneTarget = (board, config, taskId, focusColName, cwd, vcs) => {
10380
+ if (taskId == null || taskId.trim() === "") {
10277
10381
  const currentResult = resolveCurrentTask(board, config, undefined, cwd, vcs);
10278
10382
  if (currentResult.isErr()) {
10279
- return $err({
10280
- kind: "NO_ACTIVE_TASK",
10281
- message: currentResult.error.message
10282
- });
10383
+ return $err({ kind: "NO_ACTIVE_TASK", message: currentResult.error.message });
10283
10384
  }
10284
- taskToDone = currentResult.value.task;
10385
+ return $ok(currentResult.value.task);
10285
10386
  }
10286
- const uncheckedCount = countUncheckedCriteria(taskToDone);
10287
- let updatedTask = taskToDone;
10387
+ const trimmedId = taskId.trim();
10388
+ const found = findTaskByIdOrName(board, trimmedId) ?? findTaskExact(board, trimmedId);
10389
+ if (found == null) {
10390
+ return $err({ kind: "TASK_NOT_FOUND", id: trimmedId, message: `Task not found: ${trimmedId}` });
10391
+ }
10392
+ if (focusColName == null || found.column === focusColName) {
10393
+ return $ok(found);
10394
+ }
10395
+ const displayId = found.document.id ?? found.filename;
10396
+ const isCompleted = found.column === ARCHIVE_COLUMN2 || found.column === "archive" || found.column === DEFAULT_COLUMNS2[DEFAULT_COLUMNS2.length - 1];
10397
+ if (isCompleted) {
10398
+ return $err({
10399
+ kind: "ALREADY_COMPLETED",
10400
+ message: `Task ${displayId} is already completed in '${found.column}'.`
10401
+ });
10402
+ }
10403
+ if (found.column === BACKLOG_COLUMN2 || found.column === "backlog") {
10404
+ return $err({
10405
+ kind: "INVALID_COLUMN_TRANSITION",
10406
+ message: `Cannot mark task ${displayId} as done: task is in '${found.column}'. Run 'dirban ready ${displayId}' first.`,
10407
+ currentColumn: found.column,
10408
+ expectedColumn: focusColName,
10409
+ id: trimmedId,
10410
+ suggestion: `dirban ready ${displayId}`
10411
+ });
10412
+ }
10413
+ const preFocusCol = resolvePreviousColumn(config, focusColName) ?? DEFAULT_COLUMNS2[0];
10414
+ if (found.column === preFocusCol) {
10415
+ return $err({
10416
+ kind: "INVALID_COLUMN_TRANSITION",
10417
+ message: `Cannot mark task ${displayId} as done: task is in '${found.column}'. Run 'dirban start ${displayId}' first.`,
10418
+ currentColumn: found.column,
10419
+ expectedColumn: focusColName,
10420
+ id: trimmedId,
10421
+ suggestion: `dirban start ${displayId}`
10422
+ });
10423
+ }
10424
+ return $err({
10425
+ kind: "INVALID_COLUMN_TRANSITION",
10426
+ message: `Cannot mark task ${displayId} as done: task is in '${found.column}' (expected '${focusColName}').`,
10427
+ currentColumn: found.column,
10428
+ expectedColumn: focusColName,
10429
+ id: trimmedId
10430
+ });
10431
+ };
10432
+ var transitionCompletedTaskFile = (board, config, taskToDone, focusColName, cwd) => {
10288
10433
  if (focusColName == null) {
10289
10434
  const archiveResult = archiveTasks(board, config, taskToDone.document.id ?? taskToDone.filename, cwd);
10290
10435
  if (archiveResult.isErr()) {
10291
- return $err({
10292
- kind: "MOVE_ERROR",
10293
- message: archiveResult.error.message
10294
- });
10295
- }
10296
- const archivedTask = archiveResult.value.archivedTasks[0];
10297
- if (archivedTask != null) {
10298
- updatedTask = archivedTask;
10299
- }
10300
- } else {
10301
- const targetColName = resolveNextColumn(config, focusColName);
10302
- if (taskToDone.column !== targetColName) {
10303
- const moveResult = moveTask(board, taskToDone.document.id ?? taskToDone.filename, targetColName);
10304
- if (moveResult.isErr()) {
10305
- return $err({
10306
- kind: "MOVE_ERROR",
10307
- message: moveResult.error.message
10308
- });
10309
- }
10310
- updatedTask = moveResult.value;
10436
+ return $err({ kind: "MOVE_ERROR", message: archiveResult.error.message });
10311
10437
  }
10438
+ return $ok(archiveResult.value.archivedTasks[0] ?? taskToDone);
10439
+ }
10440
+ const targetColName = resolveNextColumn(config, focusColName);
10441
+ if (taskToDone.column === targetColName) {
10442
+ return $ok(taskToDone);
10443
+ }
10444
+ const moveResult = moveTask(board, taskToDone.document.id ?? taskToDone.filename, targetColName);
10445
+ if (moveResult.isErr()) {
10446
+ return $err({ kind: "MOVE_ERROR", message: moveResult.error.message });
10312
10447
  }
10448
+ return $ok(moveResult.value);
10449
+ };
10450
+ var doneTask = (board, config, taskId, options) => {
10451
+ const cwd = options?.cwd ?? process.cwd();
10452
+ const vcs = options?.vcsProvider ?? getVcsProvider(cwd);
10453
+ const focusColName = resolveFocusColumn(config);
10454
+ const targetRes = resolveDoneTarget(board, config, taskId, focusColName, cwd, vcs);
10455
+ if (targetRes.isErr())
10456
+ return $err(targetRes.error);
10457
+ const taskToDone = targetRes.value;
10458
+ const uncheckedCount = countUncheckedCriteria(taskToDone);
10313
10459
  const vcsCtx = vcs.getContext(cwd);
10314
- const strategy = options?.workspaceStrategy ?? detectWorkspaceDoneStrategy(updatedTask, options, vcsCtx, vcs, config, cwd);
10460
+ const strategy = options?.workspaceStrategy ?? detectWorkspaceDoneStrategy(taskToDone, options, vcsCtx, vcs, config, cwd);
10315
10461
  const workspaceCtx = { vcs, vcsCtx, config, cwd };
10462
+ const validateRes = strategy.validateDone?.(taskToDone, workspaceCtx, options);
10463
+ if (validateRes?.isErr()) {
10464
+ return $err({ kind: "GIT_ERROR", message: validateRes.error.message });
10465
+ }
10466
+ const transitionRes = transitionCompletedTaskFile(board, config, taskToDone, focusColName, cwd);
10467
+ if (transitionRes.isErr())
10468
+ return $err(transitionRes.error);
10469
+ const updatedTask = transitionRes.value;
10316
10470
  const doneResult = strategy.onDone(updatedTask, workspaceCtx, options);
10317
10471
  if (doneResult.isErr()) {
10318
10472
  return $err(doneResult.error);
@@ -10334,17 +10488,29 @@ var parseDone = (ctx) => {
10334
10488
  if (ctx.flags.merge && ctx.flags["no-merge"]) {
10335
10489
  return $err({ message: "Cannot specify both --merge and --no-merge." });
10336
10490
  }
10491
+ if (ctx.flags.squash && ctx.flags.rebase) {
10492
+ return $err({ message: "Cannot specify both --squash and --rebase." });
10493
+ }
10337
10494
  const taskId = ctx.positionals[1];
10338
10495
  const strategyParam = ctx.flags.strategy;
10339
10496
  const isNoneStrategy = strategyParam === "none" || ctx.flags.current || ctx.flags["no-branch"];
10340
10497
  const strategy = isNoneStrategy ? "none" : strategyParam === "worktree" || strategyParam === "checkout" || strategyParam === "directory-only" ? strategyParam : ctx.flags.worktree ? "worktree" : ctx.flags.checkout ? "checkout" : undefined;
10341
10498
  const noGit = ctx.flags["no-git"];
10342
10499
  const noMerge = ctx.flags.merge === true ? false : ctx.flags["no-merge"];
10500
+ let mergeStrategy;
10501
+ if (ctx.flags.squash === true) {
10502
+ mergeStrategy = "squash";
10503
+ } else if (ctx.flags.rebase === true) {
10504
+ mergeStrategy = "rebase";
10505
+ } else if (ctx.flags.merge === true) {
10506
+ mergeStrategy = "merge";
10507
+ }
10343
10508
  return $ok({
10344
10509
  taskId,
10345
10510
  strategy,
10346
10511
  noGit,
10347
- noMerge
10512
+ noMerge,
10513
+ mergeStrategy
10348
10514
  });
10349
10515
  };
10350
10516
  var printDoneError = (err) => {
@@ -10379,7 +10545,8 @@ var handleDone = (ctx) => {
10379
10545
  cwd: ctx.cwd,
10380
10546
  strategy: params.strategy,
10381
10547
  noGit: params.noGit,
10382
- noMerge: params.noMerge
10548
+ noMerge: params.noMerge,
10549
+ mergeStrategy: params.mergeStrategy
10383
10550
  });
10384
10551
  if (doneRes.isErr()) {
10385
10552
  printDoneError(doneRes.error);
@@ -10416,6 +10583,14 @@ var doneCommand = {
10416
10583
  flag: "--merge",
10417
10584
  description: "Force merge into base branch even if autoMerge is disabled in config"
10418
10585
  },
10586
+ {
10587
+ flag: "--squash",
10588
+ description: "Squash task branch commits into a single commit on base branch"
10589
+ },
10590
+ {
10591
+ flag: "--rebase",
10592
+ description: "Rebase task branch onto base branch and fast-forward"
10593
+ },
10419
10594
  {
10420
10595
  flag: "--no-merge",
10421
10596
  description: "Preserve active branch/worktree without merging into base branch"
@@ -10779,11 +10954,11 @@ var readyCommand = {
10779
10954
  var import_picocolors9 = __toESM(require_picocolors2(), 1);
10780
10955
 
10781
10956
  // src/tasks/lifecycle/resume.ts
10782
- import * as fs11 from "node:fs";
10957
+ import * as fs12 from "node:fs";
10783
10958
  import * as path11 from "node:path";
10784
10959
 
10785
10960
  // src/tasks/planning/block.ts
10786
- import * as fs10 from "node:fs";
10961
+ import * as fs11 from "node:fs";
10787
10962
  import * as path10 from "node:path";
10788
10963
  var FRONTMATTER_DELIMITER2 = "---";
10789
10964
  var COMMA_SPLIT_REGEX = /\s*,\s*/;
@@ -10825,7 +11000,7 @@ var parseBlockerReasons = (rawReasons, board) => {
10825
11000
  var writeTaskRelationships = (task, updatedRelationships) => {
10826
11001
  let rawContent;
10827
11002
  try {
10828
- rawContent = fs10.readFileSync(task.filePath, "utf-8");
11003
+ rawContent = fs11.readFileSync(task.filePath, "utf-8");
10829
11004
  } catch (readErr) {
10830
11005
  return $err({
10831
11006
  kind: "FS_ERROR",
@@ -10878,7 +11053,7 @@ ${yamlStr}
10878
11053
  ---${eol}${eol}${rawContent.trim()}${eol}`;
10879
11054
  }
10880
11055
  try {
10881
- fs10.writeFileSync(task.filePath, updatedContent, "utf-8");
11056
+ fs11.writeFileSync(task.filePath, updatedContent, "utf-8");
10882
11057
  } catch (fsErr) {
10883
11058
  return $err({
10884
11059
  kind: "FS_ERROR",
@@ -10929,13 +11104,14 @@ var validateWorktreeClean = (vcs, vcsCtx, worktreePath, effectiveId, cwd, option
10929
11104
  var syncBlockedTaskToRoot = (taskFile, rootOldPath, repoRoot, tasksDir, taskFilename, effectiveId, blockers, vcs) => {
10930
11105
  const rootTarget = path10.join(repoRoot, tasksDir, BACKLOG_COLUMN2, taskFilename);
10931
11106
  try {
10932
- fs10.mkdirSync(path10.dirname(rootTarget), { recursive: true });
10933
- fs10.copyFileSync(taskFile, rootTarget);
10934
- if (rootOldPath !== rootTarget && fs10.existsSync(rootOldPath)) {
10935
- fs10.unlinkSync(rootOldPath);
11107
+ fs11.mkdirSync(path10.dirname(rootTarget), { recursive: true });
11108
+ fs11.copyFileSync(taskFile, rootTarget);
11109
+ if (rootOldPath !== rootTarget && fs11.existsSync(rootOldPath)) {
11110
+ fs11.unlinkSync(rootOldPath);
10936
11111
  }
10937
11112
  const commitMsg = `chore(task): block ${effectiveId} (${blockers.join(", ")})`;
10938
- vcs.commitFile(rootTarget, commitMsg, repoRoot);
11113
+ const filesToCommit = rootOldPath !== rootTarget ? [rootOldPath, rootTarget] : [rootTarget];
11114
+ vcs.commitFile(filesToCommit, commitMsg, repoRoot);
10939
11115
  } catch {}
10940
11116
  };
10941
11117
  var blockTask = (board, taskIdOrPath, reasons, options) => {
@@ -10982,7 +11158,7 @@ var blockTask = (board, taskIdOrPath, reasons, options) => {
10982
11158
  if (worktreePath != null) {
10983
11159
  const relTaskPath = path10.relative(vcsCtx.repoRoot ?? cwd, task.filePath);
10984
11160
  const worktreeTaskFile = path10.join(worktreePath, relTaskPath);
10985
- if (fs10.existsSync(worktreeTaskFile)) {
11161
+ if (fs11.existsSync(worktreeTaskFile)) {
10986
11162
  primaryTask = { ...task, filePath: worktreeTaskFile };
10987
11163
  }
10988
11164
  }
@@ -10998,8 +11174,8 @@ var blockTask = (board, taskIdOrPath, reasons, options) => {
10998
11174
  const targetPath = path10.join(parentDir, backlogColName, finalTask.filename);
10999
11175
  if (targetPath !== finalTask.filePath) {
11000
11176
  try {
11001
- fs10.mkdirSync(path10.dirname(targetPath), { recursive: true });
11002
- fs10.renameSync(finalTask.filePath, targetPath);
11177
+ fs11.mkdirSync(path10.dirname(targetPath), { recursive: true });
11178
+ fs11.renameSync(finalTask.filePath, targetPath);
11003
11179
  demoted = true;
11004
11180
  finalTask = {
11005
11181
  ...finalTask,
@@ -11136,11 +11312,11 @@ var syncResumedFileToWorktree = (activeWorktreePath, tasksDir, focusColName, fil
11136
11312
  const worktreeTarget = path11.join(activeWorktreePath, tasksDir, focusColName, filename);
11137
11313
  const worktreeOld = path11.join(activeWorktreePath, tasksDir, "backlog", filename);
11138
11314
  try {
11139
- fs11.mkdirSync(path11.dirname(worktreeTarget), { recursive: true });
11140
- if (fs11.existsSync(worktreeOld) && worktreeOld !== worktreeTarget) {
11141
- fs11.unlinkSync(worktreeOld);
11315
+ fs12.mkdirSync(path11.dirname(worktreeTarget), { recursive: true });
11316
+ if (fs12.existsSync(worktreeOld) && worktreeOld !== worktreeTarget) {
11317
+ fs12.unlinkSync(worktreeOld);
11142
11318
  }
11143
- fs11.copyFileSync(sourceFilePath, worktreeTarget);
11319
+ fs12.copyFileSync(sourceFilePath, worktreeTarget);
11144
11320
  } catch {}
11145
11321
  };
11146
11322
  var resumeTask = (board, config, taskId, options) => {
@@ -11194,13 +11370,13 @@ var resumeTask = (board, config, taskId, options) => {
11194
11370
  const { worktreePath: activeWorktreePath, branchName } = resolveWorktreeOrBranch(strategy.name, effectiveId, vcs, vcsCtx, config, cwd);
11195
11371
  const tasksDir = config.tasksDir ?? "docs/tasks";
11196
11372
  const repoRoot = vcsCtx.repoRoot;
11197
- const tasksRoot = repoRoot != null && fs11.existsSync(repoRoot) ? path11.join(repoRoot, tasksDir) : path11.dirname(path11.dirname(workingTask.filePath));
11373
+ const tasksRoot = repoRoot != null && fs12.existsSync(repoRoot) ? path11.join(repoRoot, tasksDir) : path11.dirname(path11.dirname(workingTask.filePath));
11198
11374
  const targetColDir = path11.join(tasksRoot, focusColName);
11199
11375
  const targetFilePath = path11.join(targetColDir, workingTask.filename);
11200
11376
  try {
11201
- fs11.mkdirSync(targetColDir, { recursive: true });
11202
- if (workingTask.filePath !== targetFilePath && fs11.existsSync(workingTask.filePath)) {
11203
- fs11.renameSync(workingTask.filePath, targetFilePath);
11377
+ fs12.mkdirSync(targetColDir, { recursive: true });
11378
+ if (workingTask.filePath !== targetFilePath && fs12.existsSync(workingTask.filePath)) {
11379
+ fs12.renameSync(workingTask.filePath, targetFilePath);
11204
11380
  }
11205
11381
  } catch (fsErr) {
11206
11382
  return $err({
@@ -11217,7 +11393,8 @@ var resumeTask = (board, config, taskId, options) => {
11217
11393
  if (!isVcsOperationSkipped(vcsCtx, strategy.name, options?.noGit)) {
11218
11394
  const taskTitle = task.document.frontmatter.title ?? effectiveId;
11219
11395
  const commitMsg = `chore(task): resume ${effectiveId} ${taskTitle}`.trim();
11220
- vcs.commitFile(targetFilePath, commitMsg, cwd);
11396
+ const filesToCommit = task.filePath !== targetFilePath ? [task.filePath, targetFilePath] : [targetFilePath];
11397
+ vcs.commitFile(filesToCommit, commitMsg, cwd);
11221
11398
  }
11222
11399
  return $ok({
11223
11400
  task: updatedTask,
@@ -11284,13 +11461,14 @@ var resumeCommand = {
11284
11461
  var import_picocolors10 = __toESM(require_picocolors2(), 1);
11285
11462
 
11286
11463
  // src/tasks/lifecycle/start.ts
11287
- var commitStartMoveToTarget = (vcs, vcsCtx, filePath, displayId, title, cwd, strategyName, noGit) => {
11464
+ var commitStartMoveToTarget = (vcs, vcsCtx, oldFilePath, newFilePath, displayId, title, cwd, strategyName, noGit) => {
11288
11465
  if (isVcsOperationSkipped(vcsCtx, strategyName, noGit)) {
11289
11466
  return $ok(undefined);
11290
11467
  }
11291
11468
  const taskTitle = title ?? displayId;
11292
11469
  const commitMsg = `chore(task): start ${displayId} ${taskTitle}`.trim();
11293
- const commitRes = vcs.commitFile(filePath, commitMsg, cwd);
11470
+ const filesToCommit = oldFilePath !== newFilePath ? [oldFilePath, newFilePath] : [newFilePath];
11471
+ const commitRes = vcs.commitFile(filesToCommit, commitMsg, cwd);
11294
11472
  if (commitRes.isErr()) {
11295
11473
  return $err({
11296
11474
  kind: "GIT_CONFLICT",
@@ -11364,7 +11542,7 @@ var startTask = (board, config, taskId, options) => {
11364
11542
  }
11365
11543
  updatedTask = moveResult.value;
11366
11544
  }
11367
- const commitRes = commitStartMoveToTarget(vcs, vcsCtx, updatedTask.filePath, displayId, task.document.frontmatter.title ?? task.document.id, cwd, strategy.name, options?.noGit);
11545
+ const commitRes = commitStartMoveToTarget(vcs, vcsCtx, task.filePath, updatedTask.filePath, displayId, task.document.frontmatter.title ?? task.document.id, cwd, strategy.name, options?.noGit);
11368
11546
  if (commitRes.isErr()) {
11369
11547
  return $err(commitRes.error);
11370
11548
  }
@@ -11763,7 +11941,7 @@ var checkCommand = {
11763
11941
  var import_picocolors14 = __toESM(require_picocolors2(), 1);
11764
11942
 
11765
11943
  // src/tasks/mutation/create.ts
11766
- import * as fs12 from "node:fs";
11944
+ import * as fs13 from "node:fs";
11767
11945
  import * as path12 from "node:path";
11768
11946
  var SLUGIFY = (text) => {
11769
11947
  return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
@@ -11821,7 +11999,7 @@ var createTask = (board, options, referenceDate = new Date) => {
11821
11999
  const slug = SLUGIFY(trimmedTitle);
11822
12000
  const filename = slug !== "" ? `${nextId}-${slug}.md` : `${nextId}.md`;
11823
12001
  const filePath = path12.join(targetCol.path, filename);
11824
- if (fs12.existsSync(filePath)) {
12002
+ if (fs13.existsSync(filePath)) {
11825
12003
  return $err({
11826
12004
  kind: "FS_ERROR",
11827
12005
  message: `File already exists: ${filePath}`
@@ -11867,7 +12045,7 @@ var createTask = (board, options, referenceDate = new Date) => {
11867
12045
  ${bodyLines.join(`
11868
12046
  `)}`;
11869
12047
  try {
11870
- fs12.writeFileSync(filePath, fullContent, "utf-8");
12048
+ fs13.writeFileSync(filePath, fullContent, "utf-8");
11871
12049
  } catch (e) {
11872
12050
  return $err({
11873
12051
  kind: "FS_ERROR",
@@ -12020,7 +12198,7 @@ var nextIdCommand = {
12020
12198
  var import_picocolors17 = __toESM(require_picocolors2(), 1);
12021
12199
 
12022
12200
  // src/tasks/mutation/set.ts
12023
- import * as fs13 from "node:fs";
12201
+ import * as fs14 from "node:fs";
12024
12202
  var detectEol3 = (content) => content.includes(`\r
12025
12203
  `) ? `\r
12026
12204
  ` : `
@@ -12057,7 +12235,7 @@ var setTaskMetadata = (board, taskIdOrPath, options) => {
12057
12235
  });
12058
12236
  let rawContent;
12059
12237
  try {
12060
- rawContent = fs13.readFileSync(task.filePath, "utf-8");
12238
+ rawContent = fs14.readFileSync(task.filePath, "utf-8");
12061
12239
  } catch (readErr) {
12062
12240
  return $err({
12063
12241
  kind: "FS_ERROR",
@@ -12110,7 +12288,7 @@ ${yamlStr}
12110
12288
  frontmatter: updatedFm
12111
12289
  });
12112
12290
  try {
12113
- fs13.writeFileSync(task.filePath, updatedContent, "utf-8");
12291
+ fs14.writeFileSync(task.filePath, updatedContent, "utf-8");
12114
12292
  return $ok(Object.freeze({
12115
12293
  ...task,
12116
12294
  document: updatedDoc
@@ -12623,7 +12801,7 @@ var helpCommand = {
12623
12801
  var import_picocolors22 = __toESM(require_picocolors2(), 1);
12624
12802
 
12625
12803
  // src/tasks/project/init.ts
12626
- import * as fs14 from "node:fs";
12804
+ import * as fs15 from "node:fs";
12627
12805
  import * as path13 from "node:path";
12628
12806
  var initializeBoard = (config = DEFAULT_CONFIG2, workspaceRoot = process.cwd(), options = {}) => {
12629
12807
  const rootDir = path13.isAbsolute(config.tasksDir) ? config.tasksDir : path13.join(workspaceRoot, config.tasksDir);
@@ -12645,16 +12823,16 @@ var initializeBoard = (config = DEFAULT_CONFIG2, workspaceRoot = process.cwd(),
12645
12823
  ];
12646
12824
  for (const dirPath of directoriesToEnsure) {
12647
12825
  try {
12648
- if (fs14.existsSync(dirPath)) {
12826
+ if (fs15.existsSync(dirPath)) {
12649
12827
  alreadyExisted.push(dirPath);
12650
12828
  } else {
12651
- fs14.mkdirSync(dirPath, { recursive: true });
12829
+ fs15.mkdirSync(dirPath, { recursive: true });
12652
12830
  created.push(dirPath);
12653
12831
  }
12654
12832
  if (directoriesForGitkeep.includes(dirPath)) {
12655
12833
  const gitkeepPath = path13.join(dirPath, GITKEEP_FILE_NAME);
12656
- if (!fs14.existsSync(gitkeepPath)) {
12657
- fs14.writeFileSync(gitkeepPath, "", "utf-8");
12834
+ if (!fs15.existsSync(gitkeepPath)) {
12835
+ fs15.writeFileSync(gitkeepPath, "", "utf-8");
12658
12836
  }
12659
12837
  }
12660
12838
  } catch (e) {
@@ -12670,14 +12848,14 @@ var initializeBoard = (config = DEFAULT_CONFIG2, workspaceRoot = process.cwd(),
12670
12848
  let configFileCreated;
12671
12849
  let configFileUpdated;
12672
12850
  const target = options.configTarget ?? "auto";
12673
- const useVsCode = target === "vscode" || target === "auto" && fs14.existsSync(vscodeDir) && !fs14.existsSync(dirbanConfigPath);
12851
+ const useVsCode = target === "vscode" || target === "auto" && fs15.existsSync(vscodeDir) && !fs15.existsSync(dirbanConfigPath);
12674
12852
  try {
12675
12853
  if (useVsCode) {
12676
- fs14.mkdirSync(vscodeDir, { recursive: true });
12854
+ fs15.mkdirSync(vscodeDir, { recursive: true });
12677
12855
  let currentSettings = {};
12678
- if (fs14.existsSync(vscodeSettingsPath)) {
12856
+ if (fs15.existsSync(vscodeSettingsPath)) {
12679
12857
  try {
12680
- const content = fs14.readFileSync(vscodeSettingsPath, "utf-8");
12858
+ const content = fs15.readFileSync(vscodeSettingsPath, "utf-8");
12681
12859
  currentSettings = JSON.parse(content);
12682
12860
  } catch {
12683
12861
  currentSettings = {};
@@ -12697,23 +12875,23 @@ var initializeBoard = (config = DEFAULT_CONFIG2, workspaceRoot = process.cwd(),
12697
12875
  modified = true;
12698
12876
  }
12699
12877
  if (modified) {
12700
- fs14.writeFileSync(vscodeSettingsPath, `${JSON.stringify(currentSettings, null, 2)}
12878
+ fs15.writeFileSync(vscodeSettingsPath, `${JSON.stringify(currentSettings, null, 2)}
12701
12879
  `, "utf-8");
12702
- if (fs14.existsSync(vscodeSettingsPath)) {
12880
+ if (fs15.existsSync(vscodeSettingsPath)) {
12703
12881
  configFileUpdated = path13.relative(workspaceRoot, vscodeSettingsPath);
12704
12882
  } else {
12705
12883
  configFileCreated = path13.relative(workspaceRoot, vscodeSettingsPath);
12706
12884
  }
12707
12885
  }
12708
12886
  } else {
12709
- if (!fs14.existsSync(dirbanConfigPath)) {
12887
+ if (!fs15.existsSync(dirbanConfigPath)) {
12710
12888
  const configContent = {
12711
12889
  tasksDir: config.tasksDir,
12712
12890
  priorities: [...config.priorities],
12713
12891
  defaultPriority: config.defaultPriority,
12714
12892
  archiveDir: config.archiveDir
12715
12893
  };
12716
- fs14.writeFileSync(dirbanConfigPath, `${JSON.stringify(configContent, null, 2)}
12894
+ fs15.writeFileSync(dirbanConfigPath, `${JSON.stringify(configContent, null, 2)}
12717
12895
  `, "utf-8");
12718
12896
  configFileCreated = CONFIG_FILE_NAME2;
12719
12897
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dirban",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "Zero-Database, Agent-Native Kanban Engine & TUI Backed by the File System and Google Open Knowledge Format (OKF)",
5
5
  "type": "module",
6
6
  "main": "./dist/dirban.js",