@tdsoft-tech/aikit 0.1.15 → 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
  */
@@ -2361,9 +2419,7 @@ var DEFAULT_COMMANDS = [
2361
2419
 
2362
2420
  ## Workflow
2363
2421
 
2364
- **Step 0: Use Provided Arguments**
2365
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the task description with this command. Use it directly - do NOT ask the user for a task description!
2366
- - The arguments contain the task description you should create
2422
+ Task description: $ARGUMENTS
2367
2423
 
2368
2424
  1. Create a new bead file with unique ID
2369
2425
  2. Add task description, status, and notes
@@ -2385,9 +2441,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2385
2441
 
2386
2442
  ## Workflow
2387
2443
 
2388
- **Step 0: Use Provided Arguments**
2389
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the feature or task to plan. Use it directly - do NOT ask the user what to plan!
2390
- - The arguments contain the feature/task description you should create a plan for
2444
+ Feature or task to plan: $ARGUMENTS
2391
2445
 
2392
2446
  1. UNDERSTAND: Clarify requirements through Socratic questioning
2393
2447
  2. RESEARCH: Check existing patterns and dependencies
@@ -2429,9 +2483,7 @@ Brief description of the goal.
2429
2483
 
2430
2484
  ## Workflow
2431
2485
 
2432
- **Step 0: Use Provided Arguments**
2433
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the task reference or description. Use it directly - do NOT ask the user which task to implement!
2434
- - The arguments contain the task reference (e.g., task-001) or task description to implement
2486
+ Task reference or description: $ARGUMENTS
2435
2487
 
2436
2488
  1. LOAD: Get task details from .beads/ or plan
2437
2489
  2. TEST: Write failing tests first (RED)
@@ -2530,9 +2582,7 @@ Before marking complete:
2530
2582
 
2531
2583
  ## Workflow
2532
2584
 
2533
- **Step 0: Use Provided Arguments**
2534
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the task description. Use it directly - do NOT ask the user what task to perform!
2535
- - The arguments contain the task description to execute
2585
+ Task description: $ARGUMENTS
2536
2586
 
2537
2587
  **Phase 1: Requirements Gathering**
2538
2588
  - Interactive selection of task type (Feature, Bug Fix, Refactoring, etc.)
@@ -2622,9 +2672,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2622
2672
 
2623
2673
  ## Workflow
2624
2674
 
2625
- **Step 0: Use Provided Arguments**
2626
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the issue description. Use it directly - do NOT ask user what to fix!
2627
- - The arguments contain the issue description you should fix
2675
+ Issue description: $ARGUMENTS
2628
2676
 
2629
2677
  1. Identify issue
2630
2678
  2. Make minimal change to fix
@@ -2641,10 +2689,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2641
2689
 
2642
2690
  ## Workflow
2643
2691
 
2644
- **Step 0: Use Provided Arguments**
2645
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided optional file argument. Use it if provided!
2646
- - If a file argument is provided, focus on fixing types in that specific file
2647
- - If no file argument is provided, fix all type errors in the project
2692
+ Optional file argument: $ARGUMENTS
2648
2693
 
2649
2694
  1. Run \`npm run typecheck\`
2650
2695
  2. Parse error output
@@ -2679,10 +2724,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2679
2724
 
2680
2725
  ## Workflow
2681
2726
 
2682
- **Step 0: Use Provided Arguments**
2683
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided a commit message. Use it if provided!
2684
- - If a commit message is provided, use that message directly
2685
- - If no message is provided, generate a conventional commit message based on changes
2727
+ Optional commit message: $ARGUMENTS
2686
2728
 
2687
2729
  1. Stage changes: \`git add -A\`
2688
2730
  2. Generate commit message following conventional commits:
@@ -2704,10 +2746,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
2704
2746
 
2705
2747
  ## Workflow
2706
2748
 
2707
- **Step 0: Use Provided Arguments**
2708
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided a PR title. Use it if provided!
2709
- - If a title is provided, use that as the PR title
2710
- - If no title is provided, generate a title based on changes
2749
+ Optional PR title: $ARGUMENTS
2711
2750
 
2712
2751
  1. Push current branch
2713
2752
  2. Generate PR description:
@@ -2728,9 +2767,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
2728
2767
 
2729
2768
  ## Workflow
2730
2769
 
2731
- **Step 0: Use Provided Arguments**
2732
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the research topic. Use it directly - do NOT ask user what to research!
2733
- - The arguments contain the topic you should research
2770
+ Research topic: $ARGUMENTS
2734
2771
 
2735
2772
  1. Search documentation and resources
2736
2773
  2. Find code examples and patterns
@@ -2770,10 +2807,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2770
2807
 
2771
2808
  ## Workflow
2772
2809
 
2773
- **Step 0: Use Provided Arguments**
2774
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided a path. Use it if provided!
2775
- - If a path is provided, review code in that specific directory
2776
- - If no path is provided, review the entire codebase
2810
+ Optional path: $ARGUMENTS
2777
2811
 
2778
2812
  1. Check code quality metrics
2779
2813
  2. Identify:
@@ -2795,9 +2829,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
2795
2829
 
2796
2830
  ## Workflow
2797
2831
 
2798
- **Step 0: Use Provided Arguments**
2799
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the feature to design. Use it directly - do NOT ask user what to design!
2800
- - The arguments contain the feature you should design
2832
+ Feature to design: $ARGUMENTS
2801
2833
 
2802
2834
  1. Requirements gathering (Socratic questioning)
2803
2835
  2. Research existing solutions
@@ -2821,9 +2853,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2821
2853
 
2822
2854
  ## Workflow
2823
2855
 
2824
- **Step 0: Use Provided Arguments**
2825
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided a problem. Use it directly - do NOT ask the user what to brainstorm about!
2826
- - The arguments contain the problem you should brainstorm ideas for
2856
+ Problem to brainstorm: $ARGUMENTS
2827
2857
 
2828
2858
  1. Define problem clearly
2829
2859
  2. Generate diverse ideas (no judgement)
@@ -2842,9 +2872,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2842
2872
 
2843
2873
  ## Workflow
2844
2874
 
2845
- **Step 0: Use Provided Arguments**
2846
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided the branch name. Use it directly - do NOT ask user what to name the branch!
2847
- - The arguments contain the branch name to create
2875
+ Branch name: $ARGUMENTS
2848
2876
 
2849
2877
  1. Ensure clean working directory
2850
2878
  2. Pull latest main/master
@@ -2865,10 +2893,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
2865
2893
 
2866
2894
  ## Workflow
2867
2895
 
2868
- **Step 0: Use Provided Arguments**
2869
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided a target branch. Use it if provided!
2870
- - If a target branch is provided, merge to that branch
2871
- - If no target is provided, default to merging to main/master
2896
+ Optional target branch: $ARGUMENTS
2872
2897
 
2873
2898
  1. Run quality gates first
2874
2899
  2. Commit any pending changes
@@ -3061,10 +3086,7 @@ The analysis will be saved automatically for later reference.`
3061
3086
 
3062
3087
  ## Workflow
3063
3088
 
3064
- **Step 0: Use Provided Arguments**
3065
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided optional file or pattern argument. Use it if provided!
3066
- - If a file/pattern argument is provided, focus refactoring on that specific target
3067
- - If no argument is provided, identify refactoring opportunities across the codebase
3089
+ Optional file or pattern: $ARGUMENTS
3068
3090
 
3069
3091
  1. Ensure tests are in place
3070
3092
  2. Identify refactoring opportunities
@@ -3082,10 +3104,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
3082
3104
 
3083
3105
  ## Workflow
3084
3106
 
3085
- **Step 0: Use Provided Arguments**
3086
- IMPORTANT: Look at the "Arguments Provided" section below. The user has provided optional pattern argument. Use it if provided!
3087
- - If a pattern argument is provided, run tests matching that pattern
3088
- - If no argument is provided, run the full test suite
3107
+ Optional pattern: $ARGUMENTS
3089
3108
 
3090
3109
  1. Run test command: \`npm run test\`
3091
3110
  2. Parse and display results
@@ -3103,10 +3122,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user has provided
3103
3122
 
3104
3123
  ## Workflow
3105
3124
 
3106
- **Step 0: Use Provided Arguments**
3107
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided --fix flag. Check for it!
3108
- - If --fix flag is provided, automatically fix issues
3109
- - If no --fix flag is provided, only report issues without fixing
3125
+ Optional flags: $ARGUMENTS
3110
3126
 
3111
3127
  1. Run linter: \`npm run lint\`
3112
3128
  2. Parse errors and warnings
@@ -3124,10 +3140,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
3124
3140
 
3125
3141
  ## Workflow
3126
3142
 
3127
- **Step 0: Use Provided Arguments**
3128
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided an environment. Use it if provided!
3129
- - If an environment is provided, deploy to that environment
3130
- - If no environment is provided, default to production or prompt user
3143
+ Optional environment: $ARGUMENTS
3131
3144
 
3132
3145
  1. Run quality gates (test, lint, build)
3133
3146
  2. Check for uncommitted changes
@@ -3145,10 +3158,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
3145
3158
 
3146
3159
  ## Workflow
3147
3160
 
3148
- **Step 0: Use Provided Arguments**
3149
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided a version. Use it if provided!
3150
- - If a version is provided, rollback to that specific version
3151
- - If no version is provided, list available versions and prompt user
3161
+ Optional version: $ARGUMENTS
3152
3162
 
3153
3163
  1. Identify current version
3154
3164
  2. List available versions
@@ -3166,11 +3176,7 @@ IMPORTANT: Look at the "Arguments Provided" section below. The user may have pro
3166
3176
 
3167
3177
  ## Workflow
3168
3178
 
3169
- **Step 0: Use Provided Arguments**
3170
- IMPORTANT: Look at the "Arguments Provided" section below. The user may have provided flags. Check for them!
3171
- - If --tail N is provided, show only the last N lines
3172
- - If --follow is provided, stream live log updates
3173
- - If no flags are provided, show standard log output
3179
+ Optional flags: $ARGUMENTS
3174
3180
 
3175
3181
  1. Determine log location
3176
3182
  2. Apply filters if specified
@@ -3277,6 +3283,11 @@ Describe what this command does.
3277
3283
  * Format command for agent consumption
3278
3284
  */
3279
3285
  formatForAgent(command, args) {
3286
+ let content = command.content;
3287
+ if (args && args.trim()) {
3288
+ const argParts = args.trim().split(/\s+/);
3289
+ content = content.replace(/\$ARGUMENTS/g, args.trim()).replace(/\$1/g, argParts[0] || "").replace(/\$2/g, argParts[1] || "").replace(/\$3/g, argParts[2] || "").replace(/\$4/g, argParts[3] || "").replace(/\$5/g, argParts[4] || "");
3290
+ }
3280
3291
  let output = `# Command: /${command.name}
3281
3292
 
3282
3293
  ## Usage
@@ -3289,14 +3300,11 @@ ${command.description}
3289
3300
  ${command.examples.map((e) => `- \`${e}\``).join("\n")}
3290
3301
 
3291
3302
  ## Workflow
3292
- ${command.content}
3303
+ ${content}
3293
3304
  `;
3294
3305
  if (args && args.trim()) {
3295
3306
  output += `
3296
- ## Arguments Provided
3297
- \`${args}\`
3298
-
3299
- **IMPORTANT**: The user provided these arguments with the command. Use them in the workflow as needed.
3307
+ User arguments are : ${args.trim()}
3300
3308
  `;
3301
3309
  }
3302
3310
  return output;
@@ -5417,6 +5425,9 @@ function registerInitCommand(program2) {
5417
5425
  } else {
5418
5426
  logger.info("Beads already initialized");
5419
5427
  }
5428
+ logger.info("Setting up git hooks...");
5429
+ await beads.setupGitHooks();
5430
+ logger.success("\u2713 Git hooks configured");
5420
5431
  const opencodePath = paths.opencodeConfig();
5421
5432
  await installToOpenCode(opencodePath);
5422
5433
  console.log(chalk2.bold("\n\u2728 AIKit is ready!\n"));