@tdsoft-tech/aikit 0.1.16 → 0.1.17

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.
@@ -0,0 +1,70 @@
1
+ #!/bin/sh
2
+ #
3
+ # bd (beads) pre-commit hook
4
+ #
5
+ # This hook ensures that any pending bd issue changes are flushed to
6
+ # .beads/issues.jsonl before the commit is created, preventing a
7
+ # race condition where daemon auto-flush fires after the commit.
8
+ #
9
+
10
+ # Check if bd is available
11
+ if ! command -v bd >/dev/null 2>&1; then
12
+ echo "Warning: bd command not found, skipping pre-commit flush" >&2
13
+ exit 0
14
+ fi
15
+
16
+ # Check if we're in a bd workspace
17
+ # For worktrees, .beads is in the main repository root, not the worktree
18
+ BEADS_DIR=""
19
+ if git rev-parse --git-dir >/dev/null 2>&1; then
20
+ # Check if we're in a worktree
21
+ if [ "$(git rev-parse --git-dir)" != "$(git rev-parse --git-common-dir)" ]; then
22
+ # Worktree: .beads is in main repo root
23
+ MAIN_REPO_ROOT="$(git rev-parse --git-common-dir)"
24
+ MAIN_REPO_ROOT="$(dirname "$MAIN_REPO_ROOT")"
25
+ if [ -d "$MAIN_REPO_ROOT/.beads" ]; then
26
+ BEADS_DIR="$MAIN_REPO_ROOT/.beads"
27
+ fi
28
+ else
29
+ # Regular repo: check current directory
30
+ if [ -d .beads ]; then
31
+ BEADS_DIR=".beads"
32
+ fi
33
+ fi
34
+ fi
35
+
36
+ if [ -z "$BEADS_DIR" ]; then
37
+ # Not a bd workspace, nothing to do
38
+ exit 0
39
+ fi
40
+
41
+ # Check if bd is actually initialized (has beads.db or config.yaml)
42
+ # This prevents errors if .beads/ exists but bd was never initialized
43
+ if [ ! -f "$BEADS_DIR/beads.db" ] && [ ! -f "$BEADS_DIR/config.yaml" ]; then
44
+ # .beads/ exists but bd is not initialized, skip bd operations
45
+ exit 0
46
+ fi
47
+
48
+ # Flush pending changes to JSONL
49
+ # Use --flush-only to skip git operations (we're already in a git hook)
50
+ # Suppress output unless there's an error
51
+ if ! bd sync --flush-only >/dev/null 2>&1; then
52
+ echo "Error: Failed to flush bd changes to JSONL" >&2
53
+ echo "Run 'bd sync --flush-only' manually to diagnose" >&2
54
+ exit 1
55
+ fi
56
+
57
+ # If the JSONL file was modified, stage it
58
+ # For worktrees, JSONL is in the main repo's working tree, not the worktree,
59
+ # so we can't use git add. Skip this step for worktrees.
60
+ if [ -f "$BEADS_DIR/issues.jsonl" ]; then
61
+ if [ "$(git rev-parse --git-dir)" = "$(git rev-parse --git-common-dir)" ]; then
62
+ # Regular repo: file is in the working tree, safe to add
63
+ git add "$BEADS_DIR/issues.jsonl" 2>/dev/null || true
64
+ fi
65
+ # For worktrees: .beads is in the main repo's working tree, not this worktree
66
+ # Git rejects adding files outside the worktree, so we skip it.
67
+ # The main repo will see the changes on the next pull/sync.
68
+ fi
69
+
70
+ exit 0
package/dist/cli.js CHANGED
@@ -1227,6 +1227,64 @@ bd init
1227
1227
  return false;
1228
1228
  }
1229
1229
  }
1230
+ /**
1231
+ * Setup git hooks for Beads integration
1232
+ */
1233
+ async setupGitHooks() {
1234
+ try {
1235
+ const gitHooksDir = join9(this.projectPath, ".git", "hooks");
1236
+ const preCommitHook = join9(gitHooksDir, "pre-commit");
1237
+ const hookContent = `#!/bin/sh
1238
+ #
1239
+ # bd (beads) pre-commit hook
1240
+ #
1241
+ # This hook ensures that any pending bd issue changes are flushed to
1242
+ # .beads/issues.jsonl before the commit is created, preventing a
1243
+ # race condition where daemon auto-flush fires after the commit.
1244
+ #
1245
+
1246
+ # Check if bd is available
1247
+ if ! command -v bd >/dev/null 2>&1; then
1248
+ echo "Warning: bd command not found, skipping pre-commit flush" >&2
1249
+ exit 0
1250
+ fi
1251
+
1252
+ # Check if we're in a bd workspace
1253
+ BEADS_DIR=""
1254
+ if [ -d ".beads" ]; then
1255
+ BEADS_DIR=".beads"
1256
+ fi
1257
+
1258
+ if [ -z "$BEADS_DIR" ]; then
1259
+ # Not a bd workspace, nothing to do
1260
+ exit 0
1261
+ fi
1262
+
1263
+ # Check if bd is actually initialized (has beads.db or config.yaml)
1264
+ # This prevents errors if .beads/ exists but bd was never initialized
1265
+ if [ ! -f "$BEADS_DIR/beads.db" ] && [ ! -f "$BEADS_DIR/config.yaml" ]; then
1266
+ # .beads/ exists but bd is not initialized, skip bd operations
1267
+ exit 0
1268
+ fi
1269
+
1270
+ # Flush pending changes to JSONL
1271
+ # Use --flush-only to skip git operations (we're already in a git hook)
1272
+ # Suppress output unless there's an error
1273
+ if ! bd sync --flush-only >/dev/null 2>&1; then
1274
+ echo "Error: Failed to flush bd changes to JSONL" >&2
1275
+ echo "Run 'bd sync --flush-only' manually to diagnose" >&2
1276
+ exit 1
1277
+ fi
1278
+
1279
+ exit 0
1280
+ `;
1281
+ await writeFile5(preCommitHook, hookContent, { mode: 493 });
1282
+ return true;
1283
+ } catch (error) {
1284
+ logger.error("Failed to setup git hooks:", error);
1285
+ return false;
1286
+ }
1287
+ }
1230
1288
  /**
1231
1289
  * Get current status
1232
1290
  */
@@ -5367,6 +5425,9 @@ function registerInitCommand(program2) {
5367
5425
  } else {
5368
5426
  logger.info("Beads already initialized");
5369
5427
  }
5428
+ logger.info("Setting up git hooks...");
5429
+ await beads.setupGitHooks();
5430
+ logger.success("\u2713 Git hooks configured");
5370
5431
  const opencodePath = paths.opencodeConfig();
5371
5432
  await installToOpenCode(opencodePath);
5372
5433
  console.log(chalk2.bold("\n\u2728 AIKit is ready!\n"));