kimun-notes 0.7.0

A terminal-based notes application
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# Kimün CLI Phase 2: Multi-Workspace Usage Guide

Kimün CLI Phase 2 introduces comprehensive multi-workspace management, rich JSON output, and enhanced automation capabilities. This guide covers all CLI features, configuration, and best practices.

## Table of Contents

- [Installation & Setup]#installation--setup
- [Multi-Workspace Management]#multi-workspace-management
- [Search Operations]#search-operations
- [Notes Listing]#notes-listing
- [JSON Output Format]#json-output-format
- [Configuration]#configuration
- [Migration from Phase 1]#migration-from-phase-1
- [Automation & Scripting]#automation--scripting
- [Troubleshooting]#troubleshooting
- [Performance Considerations]#performance-considerations

## Installation & Setup

### Installation

```sh
cargo install kimun-notes
```

### Initial Setup

Kimün supports two setup approaches:

#### CLI-First Setup (Recommended)

```sh
# Initialize your first workspace directly via CLI
kimun workspace init --name default /path/to/your/notes

# Or create multiple workspaces from the start
kimun workspace init --name work /path/to/work/notes
kimun workspace init --name personal ~/personal-notes
```

#### TUI Setup

```sh
# Launch the TUI for interactive setup
kimun
```

The TUI provides a Settings screen for workspace configuration and will automatically migrate to the multi-workspace format.

## Multi-Workspace Management

### Core Concepts

- **Workspace**: An isolated notes environment with its own directory and search index
- **Current Workspace**: The active workspace for search and notes operations
- **Workspace Configuration**: Stored in `~/.config/kimun/kimun_config.toml` (Linux/macOS) or `%USERPROFILE%\kimun\kimun_config.toml` (Windows)

### Workspace Commands

#### Initialize Workspaces

```sh
# Create a new workspace
kimun workspace init --name <name> <path>

# Examples
kimun workspace init --name work ~/work-notes
kimun workspace init --name personal ~/Documents/notes
kimun workspace init --name research /mnt/external/research

# First workspace defaults to "default" name if omitted
kimun workspace init /path/to/notes
```

#### List Workspaces

```sh
kimun workspace list
```

Output shows all configured workspaces with current workspace marked:
```
* work       (/Users/user/work-notes)
  personal   (/Users/user/Documents/notes)
  research   (/mnt/external/research)
```

#### Switch Workspaces

```sh
# Switch to a different workspace
kimun workspace use <workspace-name>

# Examples
kimun workspace use personal
kimun workspace use work
```

#### Manage Workspaces

```sh
# Rename a workspace
kimun workspace rename old-name new-name

# Remove a workspace (removes from config, preserves files)
kimun workspace remove workspace-name

# Rebuild search index for a workspace
kimun workspace reindex                        # Current workspace
kimun workspace reindex --name specific-name   # Specific workspace
```

### Workspace Isolation

Each workspace maintains:
- **Separate search index** (`kimun.sqlite` in workspace directory)
- **Isolated note content** (no cross-workspace search)
- **Independent configuration** (last paths, workspace-specific settings)
- **Isolated file operations** (CLI commands only affect current workspace)

## Search Operations

### Basic Search

```sh
# Search in current workspace
kimun search "search term"

# Case-insensitive, diacritics ignored
kimun search "kimün"          # Matches "Kimün", "KIMÜN", "kimun"

# Wildcard support
kimun search "meet*"          # Matches "meeting", "meetings", "meetup"
kimun search "*report*"       # Matches "report", "reports", "quarterly-report"
```

### Advanced Search Operators

#### Filename Filtering (`@` or `at:`)

```sh
kimun search "@tasks"         # Only notes with "tasks" in filename
kimun search "at:project"     # Same as above
kimun search "@2024"          # Files with "2024" in name
```

#### Section/Title Filtering (`>` or `in:`)

```sh
kimun search ">personal"      # Content under "Personal" headings
kimun search "in:work"        # Content under "Work" headings
kimun search ">project status" # "status" under "Project" sections
```

#### Path Filtering (`/` or `pt:`)

```sh
kimun search "/journal"       # Notes in journal directory
kimun search "pt:docs"        # Notes in docs path
kimun search "/2024/reports"  # Specific path structure
```

#### Exclusion Operators (`-` prefix)

```sh
# Content exclusion
kimun search "meeting -cancelled"      # Notes with "meeting" but not "cancelled"

# Filename exclusion
kimun search "@project @-draft"        # Project files excluding drafts
kimun search "at:2024 at:-temp"       # 2024 files excluding temporary ones

# Title exclusion
kimun search ">project >-draft"       # Project sections excluding draft titles
kimun search "in:work in:-archived"   # Work sections excluding archived

# Path exclusion
kimun search "/docs /-private"        # Docs path excluding private subdirs
kimun search "pt:notes pt:-old"       # Notes path excluding old directories

# Exclusion-only searches
kimun search "-cancelled"             # All notes except those with "cancelled"
kimun search ">-draft"               # All notes except those with "draft" in title
kimun search "@-temp"                # All notes except temporary files
```

#### Combining Operators

```sh
# Complex queries combining multiple operators
kimun search "@tasks >work report -cancelled"
# Files with "tasks" in name, under "Work" sections, containing "report", excluding "cancelled"

kimun search "/journal/2024 >daily -weekend"
# Notes in 2024 journal path, under "Daily" headings, excluding weekend entries

kimun search "@project @-draft >-archived status"
# Project files (not drafts), non-archived sections, containing "status"
```

### Output Formats

```sh
# Text output (default)
kimun search "query"

# JSON output for automation
kimun search "query" --format json
```

## Notes Listing

### Basic Listing

```sh
# List all notes in current workspace
kimun notes

# Filter by path prefix
kimun notes --path "journal/"
kimun notes --path "projects/2024/"
```

### Output Formats

```sh
# Text output (default) - shows titles, paths, and modification dates
kimun notes

# JSON output with comprehensive metadata
kimun notes --format json
kimun notes --path "journal/" --format json
```

## JSON Output Format

Both `search` and `notes` commands support rich JSON output for automation and integration.

### JSON Structure

```json
{
  "metadata": {
    "workspace": "work",
    "workspace_path": "/Users/user/work-notes",
    "total_results": 15,
    "query": "meeting",                    // null for notes listing
    "is_listing": false,                   // true for notes command
    "generated_at": "2024-03-15T10:30:00Z"
  },
  "notes": [
    {
      "path": "projects/status-meeting.md",
      "title": "Weekly Status Meeting",
      "content": "# Weekly Status Meeting\n\n...",
      "size": 1024,
      "modified": 1710504600,
      "created": 1710418200,
      "hash": "a1b2c3d4e5f67890",
      "journal_date": "2024-03-15",        // null if not a journal note
      "metadata": {
        "tags": ["meeting", "status", "weekly"],
        "links": ["project-roadmap", "team-updates"],
        "headers": [
          {"level": 1, "text": "Weekly Status Meeting"},
          {"level": 2, "text": "Agenda"},
          {"level": 2, "text": "Action Items"}
        ]
      }
    }
  ]
}
```

### Metadata Extraction

JSON output includes rich metadata extracted from note content:

- **Tags**: Extracted from hashtags (`#tag`) and YAML frontmatter
- **Links**: Wiki-style links (`[[link]]`) and Markdown links
- **Headers**: All Markdown headers with levels and text
- **Journal Detection**: Automatically detects and formats journal dates
- **Timestamps**: Both modification and creation times
- **Content Hash**: For change detection and caching

### Processing JSON Output

#### Using jq for Processing

```sh
# Extract note titles and paths
kimun notes --format json | jq '.notes[] | {title, path}'

# Find notes with specific tags
kimun search "project" --format json | jq '.notes[] | select(.metadata.tags[] | contains("urgent"))'

# Get notes modified in the last week
kimun notes --format json | jq --argjson week_ago $(date -d "1 week ago" +%s) '.notes[] | select(.modified > $week_ago)'

# Count notes by tag
kimun notes --format json | jq '[.notes[].metadata.tags[]] | group_by(.) | map({tag: .[0], count: length})'

# Extract all wiki links
kimun notes --format json | jq '.notes[].metadata.links[]' | sort | uniq

# Find journal entries from specific date range
kimun notes --format json | jq '.notes[] | select(.journal_date and (.journal_date | strptime("%Y-%m-%d") | mktime) > (now - 604800))'
```

#### Integration Examples

```sh
# Export to CSV
kimun notes --format json | jq -r '.notes[] | [.title, .path, .modified] | @csv' > notes.csv

# Create backlink index
kimun notes --format json | jq '.notes[] | {path: .path, links: .metadata.links}' > backlinks.json

# Monitor for changes
current_hash=$(kimun notes --format json | jq '.notes[] | .hash' | sort | md5sum)
```

## Configuration

### Config File Location

- **Linux/macOS**: `~/.config/kimun/kimun_config.toml`
- **Windows**: `%USERPROFILE%\kimun\kimun_config.toml`

### Custom Config Path

```sh
# Use custom config for all commands
kimun --config /path/to/custom-config.toml search "query"
kimun --config /path/to/custom-config.toml workspace list
kimun --config /path/to/custom-config.toml notes --format json
```

### Phase 2 Config Structure

```toml
config_version = 2

[workspace_config.global]
current_workspace = "work"
theme = "dark"

[workspace_config.workspaces.work]
path = "/Users/user/work-notes"
last_paths = ["/journal", "/projects"]
created = "2024-01-15T10:30:00Z"

[workspace_config.workspaces.personal]
path = "/Users/user/personal-notes"
last_paths = ["/thoughts", "/learning"]
created = "2024-01-20T15:45:00Z"
```

## Migration from Phase 1

### Automatic Migration

Kimün automatically detects and migrates Phase 1 configurations:

**Phase 1 Config (Single Workspace)**:
```toml
workspace_dir = "/Users/user/notes"
theme = "dark"
last_paths = ["/journal", "/projects"]
```

**Migrated to Phase 2**:
```toml
config_version = 2

[workspace_config.global]
current_workspace = "default"
theme = "dark"

[workspace_config.workspaces.default]
path = "/Users/user/notes"
last_paths = ["/journal", "/projects"]
created = "2024-03-15T10:30:00Z"
```

### Migration Process

1. **Detection**: Kimün detects `workspace_dir` field without `workspace_config`
2. **Validation**: Ensures workspace directory still exists
3. **Conversion**: Creates new multi-workspace structure with "default" workspace
4. **Preservation**: Maintains all existing settings (theme, last_paths, etc.)
5. **Update**: Sets `config_version = 2` marker

### Migration Verification

```sh
# Check migration status
kimun workspace list

# Should show your previous workspace as "default"
# * default    (/path/to/your/old/workspace)
```

### Post-Migration Workflow

After migration, you can:

```sh
# Continue using as before (now uses "default" workspace)
kimun search "query"
kimun notes

# Add additional workspaces
kimun workspace init --name work /path/to/work/notes
kimun workspace init --name research /path/to/research

# Rename the migrated workspace
kimun workspace rename default personal
```

## Automation & Scripting

### Bash Completion

Add to your `.bashrc` or `.zshrc`:

```sh
# Generate completion script (if available)
eval "$(kimun completion bash)"  # or zsh
```

### Common Automation Patterns

#### Daily Journal Creation

```sh
#!/bin/bash
# daily-journal.sh
date_today=$(date +%Y-%m-%d)
journal_path="journal/${date_today}.md"

kimun workspace use personal
if ! kimun notes --path "journal/" --format json | jq -e ".notes[] | select(.path | contains(\"$date_today\"))" > /dev/null; then
    mkdir -p ~/personal-notes/journal
    echo "# Daily Journal - $date_today" > ~/personal-notes/journal/${date_today}.md
    echo "" >> ~/personal-notes/journal/${date_today}.md
    echo "## Tasks" >> ~/personal-notes/journal/${date_today}.md
    echo "## Notes" >> ~/personal-notes/journal/${date_today}.md
fi
```

#### Project Status Reports

```sh
#!/bin/bash
# project-report.sh
kimun workspace use work
kimun search "@project status" --format json | \
  jq '.notes[] | select(.metadata.tags[] | contains("active"))' | \
  jq -r '"\(.title): \(.path)"'
```

#### Content Analytics

```sh
#!/bin/bash
# content-analytics.sh

echo "=== Content Statistics ==="
for workspace in $(kimun workspace list | grep -v "^*" | awk '{print $1}' | grep -v "Configured"); do
    echo "Workspace: $workspace"
    kimun workspace use $workspace

    total=$(kimun notes --format json | jq '.metadata.total_results')
    echo "  Total notes: $total"

    tags=$(kimun notes --format json | jq '.notes[].metadata.tags[]' | sort | uniq -c | sort -nr | head -5)
    echo "  Top tags:"
    echo "$tags" | while read count tag; do
        echo "    $tag: $count"
    done
    echo
done
```

#### Backup and Sync

```sh
#!/bin/bash
# backup-workspaces.sh

backup_dir="$HOME/kimun-backups/$(date +%Y-%m-%d)"
mkdir -p "$backup_dir"

kimun workspace list | grep -E "^\s*\*?\s*\w+" | while read line; do
    workspace=$(echo "$line" | sed 's/^\s*\*\?\s*//' | awk '{print $1}')
    path=$(echo "$line" | grep -o '([^)]*)' | tr -d '()')

    echo "Backing up workspace: $workspace"
    rsync -av "$path/" "$backup_dir/$workspace/"
done

# Export configuration
cp ~/.config/kimun/kimun_config.toml "$backup_dir/"
```

### Integration with External Tools

#### With fzf for Interactive Selection

```sh
# Interactive note selection
note=$(kimun notes --format json | jq -r '.notes[] | "\(.title)|\(.path)"' | fzf --delimiter='|' --with-nth=1 | cut -d'|' -f2)
if [ -n "$note" ]; then
    editor "$note"  # Open in your preferred editor
fi
```

#### With Obsidian or Other Tools

```sh
# Export to Obsidian format
kimun notes --format json | jq '.notes[]' | while read -r note; do
    path=$(echo "$note" | jq -r '.path')
    title=$(echo "$note" | jq -r '.title')
    tags=$(echo "$note" | jq -r '.metadata.tags[]' | tr '\n' ' ')

    # Add Obsidian frontmatter
    obsidian_path="$OBSIDIAN_VAULT/$(basename "$path")"
    echo "---" > "$obsidian_path"
    echo "title: $title" >> "$obsidian_path"
    echo "tags: [$tags]" >> "$obsidian_path"
    echo "kimun_path: $path" >> "$obsidian_path"
    echo "---" >> "$obsidian_path"
    echo "" >> "$obsidian_path"
    cat "$(dirname "$(kimun notes --format json | jq -r '.metadata.workspace_path')")/$path" >> "$obsidian_path"
done
```

## Troubleshooting

### Common Issues

#### "No workspace configured" Error

```sh
# Problem: CLI shows "No workspace configured"
# Solution: Initialize a workspace
kimun workspace init --name default /path/to/notes

# Or use TUI for interactive setup
kimun
```

#### Workspace Directory Not Found

```sh
# Problem: "workspace directory no longer exists"
# Check current workspaces
kimun workspace list

# Remove invalid workspace
kimun workspace remove invalid-workspace

# Re-add with correct path
kimun workspace init --name corrected /correct/path
```

#### Search Returns No Results

```sh
# Check current workspace
kimun workspace list

# Verify workspace has notes
ls -la $(kimun notes --format json | jq -r '.metadata.workspace_path')

# Rebuild search index
kimun workspace reindex
```

#### JSON Parsing Issues

```sh
# Validate JSON output
kimun notes --format json | jq '.'

# Check for binary files or encoding issues
kimun notes --format json | jq '.notes[] | select(.size > 100000)'
```

### Performance Issues

#### Large Workspace Optimization

```sh
# For workspaces with many files (>10,000 notes)

# 1. Use path filters for better performance
kimun notes --path "recent/" --format json

# 2. Regular reindexing
kimun workspace reindex

# 3. Consider splitting large workspaces
kimun workspace init --name archive /path/to/archived/notes
```

#### Memory Usage

```sh
# Monitor memory usage during large operations
time kimun notes --format json > /dev/null

# Use streaming for large JSON outputs
kimun notes --format json | jq -c '.notes[]' | while read note; do
    # Process one note at a time
    echo "$note" | jq '.title'
done
```

### Configuration Issues

#### Config File Corruption

```sh
# Backup current config
cp ~/.config/kimun/kimun_config.toml ~/.config/kimun/kimun_config.toml.backup

# Reset to defaults (will prompt for workspace setup)
rm ~/.config/kimun/kimun_config.toml
kimun workspace init --name default /path/to/notes
```

#### Permission Issues

```sh
# Check config directory permissions
ls -la ~/.config/kimun/

# Fix permissions
chmod 755 ~/.config/kimun/
chmod 644 ~/.config/kimun/kimun_config.toml
```

### Debug Mode

```sh
# Enable verbose logging (if available)
RUST_LOG=debug kimun search "query"

# Or check for debug flags
kimun --help
```

## Performance Considerations

### Indexing Performance

- **Initial Indexing**: First-time indexing scales with content size
- **Incremental Updates**: Subsequent operations are fast due to incremental indexing
- **Index Size**: SQLite index is typically 5-10% of total content size
- **Memory Usage**: Scales with concurrent operations and result set size

### Best Practices

#### Workspace Organization

```sh
# Good: Moderate-sized workspaces (1,000-10,000 notes)
kimun workspace init --name current-work ~/work/2024
kimun workspace init --name archive ~/work/archive

# Avoid: Single massive workspace with 50,000+ notes
# Instead: Split by time, project, or category
```

#### Query Optimization

```sh
# Efficient: Specific path filters
kimun search "meeting" --path "journal/2024/"

# Less efficient: Broad searches on large workspaces
kimun search "*"

# Efficient: Combined filters
kimun search "@status >weekly"

# Less efficient: Multiple separate queries
kimun search "@status" && kimun search ">weekly"
```

#### JSON Output Optimization

```sh
# For large result sets, use streaming processing
kimun notes --format json | jq -c '.notes[]' | head -100

# Filter early in the pipeline
kimun notes --path "recent/" --format json | jq '.notes[] | select(.modified > 1640995200)'

# Use path filters to limit scope
kimun search "query" --path "specific/directory/"
```

### Resource Monitoring

```sh
# Monitor disk usage
du -sh ~/.config/kimun/
find ~/notes -name "kimun.sqlite" -exec du -sh {} \;

# Check index status
sqlite3 ~/notes/kimun.sqlite "SELECT COUNT(*) as note_count FROM notes;"
sqlite3 ~/notes/kimun.sqlite "SELECT COUNT(*) as search_entries FROM search_index;"
```

---

This guide covers all CLI Phase 2 features and capabilities. For additional help or feature requests, please refer to the main project documentation or submit issues through the project repository.