swarm-mail 0.5.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +84 -0
- package/bin/daemon-cli.ts +4 -4
- package/dist/adapter.d.ts.map +1 -1
- package/dist/beads/adapter.d.ts +38 -0
- package/dist/beads/adapter.d.ts.map +1 -0
- package/dist/beads/blocked-cache.d.ts +21 -0
- package/dist/beads/blocked-cache.d.ts.map +1 -0
- package/dist/beads/comments.d.ts +21 -0
- package/dist/beads/comments.d.ts.map +1 -0
- package/dist/beads/dependencies.d.ts +58 -0
- package/dist/beads/dependencies.d.ts.map +1 -0
- package/dist/beads/events.d.ts +163 -0
- package/dist/beads/events.d.ts.map +1 -0
- package/dist/beads/flush-manager.d.ts +71 -0
- package/dist/beads/flush-manager.d.ts.map +1 -0
- package/dist/beads/index.d.ts +25 -0
- package/dist/beads/index.d.ts.map +1 -0
- package/dist/beads/jsonl.d.ts +103 -0
- package/dist/beads/jsonl.d.ts.map +1 -0
- package/dist/beads/labels.d.ts +21 -0
- package/dist/beads/labels.d.ts.map +1 -0
- package/dist/beads/merge.d.ts +99 -0
- package/dist/beads/merge.d.ts.map +1 -0
- package/dist/beads/migrations.d.ts +41 -0
- package/dist/beads/migrations.d.ts.map +1 -0
- package/dist/beads/operations.d.ts +56 -0
- package/dist/beads/operations.d.ts.map +1 -0
- package/dist/beads/projections.d.ts +103 -0
- package/dist/beads/projections.d.ts.map +1 -0
- package/dist/beads/queries.d.ts +77 -0
- package/dist/beads/queries.d.ts.map +1 -0
- package/dist/beads/store.d.ts +98 -0
- package/dist/beads/store.d.ts.map +1 -0
- package/dist/beads/validation.d.ts +75 -0
- package/dist/beads/validation.d.ts.map +1 -0
- package/dist/daemon.d.ts +8 -9
- package/dist/daemon.d.ts.map +1 -1
- package/dist/hive/adapter.d.ts.map +1 -1
- package/dist/hive/index.d.ts +1 -0
- package/dist/hive/index.d.ts.map +1 -1
- package/dist/hive/jsonl.d.ts +2 -0
- package/dist/hive/jsonl.d.ts.map +1 -1
- package/dist/hive/queries.d.ts +23 -0
- package/dist/hive/queries.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1530 -866
- package/dist/memory/adapter.d.ts +2 -0
- package/dist/memory/adapter.d.ts.map +1 -1
- package/dist/memory/index.d.ts +1 -0
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/migrations.d.ts.map +1 -1
- package/dist/memory/store.d.ts +2 -0
- package/dist/memory/store.d.ts.map +1 -1
- package/dist/memory/sync.d.ts +93 -0
- package/dist/memory/sync.d.ts.map +1 -0
- package/dist/pglite.d.ts +9 -7
- package/dist/pglite.d.ts.map +1 -1
- package/dist/test-server.d.ts +64 -0
- package/dist/test-server.d.ts.map +1 -0
- package/dist/types/adapter.d.ts +38 -1
- package/dist/types/adapter.d.ts.map +1 -1
- package/dist/types/beads-adapter.d.ts +397 -0
- package/dist/types/beads-adapter.d.ts.map +1 -0
- package/dist/types/database.d.ts +67 -0
- package/dist/types/database.d.ts.map +1 -1
- package/package.json +6 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonl.d.ts","sourceRoot":"","sources":["../../src/beads/jsonl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAa9D;;;;GAIG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,GAAG,QAAQ,GAAG,WAAW,CAAC;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;IAC1D,UAAU,EAAE,MAAM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;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC,CAa/C;AAMD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,OAAO,GAAE,aAAkB,GAC1B,OAAO,CAAC,YAAY,CAAC,CAqBvB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Label Operations
|
|
3
|
+
*
|
|
4
|
+
* Simple label management for categorizing beads.
|
|
5
|
+
* Labels are string tags that can be queried for grouping and filtering.
|
|
6
|
+
*
|
|
7
|
+
* Reference: steveyegge/beads/internal/storage/sqlite/labels.go
|
|
8
|
+
*
|
|
9
|
+
* @module beads/labels
|
|
10
|
+
*/
|
|
11
|
+
import type { DatabaseAdapter } from "../types/database.js";
|
|
12
|
+
import type { Bead } from "../types/beads-adapter.js";
|
|
13
|
+
/**
|
|
14
|
+
* Get all beads with a specific label
|
|
15
|
+
*/
|
|
16
|
+
export declare function getBeadsByLabel(db: DatabaseAdapter, projectKey: string, label: string): Promise<Bead[]>;
|
|
17
|
+
/**
|
|
18
|
+
* Get all unique labels for a project
|
|
19
|
+
*/
|
|
20
|
+
export declare function getAllLabels(db: DatabaseAdapter, projectKey: string): Promise<string[]>;
|
|
21
|
+
//# sourceMappingURL=labels.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"labels.d.ts","sourceRoot":"","sources":["../../src/beads/labels.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEtD;;GAEG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,IAAI,EAAE,CAAC,CASjB;AAED;;GAEG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 3-Way Merge Driver for Beads JSONL
|
|
3
|
+
*
|
|
4
|
+
* Ported from steveyegge/beads internal/merge/merge.go (MIT License)
|
|
5
|
+
* Original by @neongreen: https://github.com/neongreen/mono/tree/main/beads-merge
|
|
6
|
+
*
|
|
7
|
+
* Features:
|
|
8
|
+
* - 3-way merge of JSONL bead files
|
|
9
|
+
* - Tombstone semantics (soft-delete wins over live, expired allows resurrection)
|
|
10
|
+
* - Field-level merge with updated_at tiebreaker
|
|
11
|
+
* - Deterministic conflict resolution (no manual intervention needed)
|
|
12
|
+
*
|
|
13
|
+
* ## Tombstone Rules
|
|
14
|
+
* - Tombstone always wins over live issue (unless expired)
|
|
15
|
+
* - Expired tombstones allow resurrection (live issue wins)
|
|
16
|
+
* - Two tombstones: later deleted_at wins
|
|
17
|
+
*
|
|
18
|
+
* ## Field Merge Rules
|
|
19
|
+
* - title/description: latest updated_at wins
|
|
20
|
+
* - status: closed wins over open, tombstone wins over all
|
|
21
|
+
* - priority: higher priority wins (lower number = more urgent)
|
|
22
|
+
* - notes: concatenate on conflict
|
|
23
|
+
* - dependencies: union (deduplicated)
|
|
24
|
+
*
|
|
25
|
+
* @module beads/merge
|
|
26
|
+
*/
|
|
27
|
+
import type { BeadExport } from "./jsonl.js";
|
|
28
|
+
/** Default TTL for tombstones (30 days) */
|
|
29
|
+
export declare const DEFAULT_TOMBSTONE_TTL_MS: number;
|
|
30
|
+
/** Minimum TTL for tombstones (7 days) - safety limit */
|
|
31
|
+
export declare const MIN_TOMBSTONE_TTL_MS: number;
|
|
32
|
+
/** Clock skew grace period (1 hour) - added to TTL for distributed systems */
|
|
33
|
+
export declare const CLOCK_SKEW_GRACE_MS: number;
|
|
34
|
+
/** Tombstone status constant */
|
|
35
|
+
export declare const STATUS_TOMBSTONE = "tombstone";
|
|
36
|
+
/**
|
|
37
|
+
* Issue key for matching across base/left/right
|
|
38
|
+
*
|
|
39
|
+
* Uses ID + created_at + created_by for uniqueness (handles ID collisions)
|
|
40
|
+
*/
|
|
41
|
+
export interface IssueKey {
|
|
42
|
+
id: string;
|
|
43
|
+
createdAt: string;
|
|
44
|
+
createdBy?: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Merge result
|
|
48
|
+
*/
|
|
49
|
+
export interface MergeResult {
|
|
50
|
+
/** Successfully merged beads */
|
|
51
|
+
merged: BeadExport[];
|
|
52
|
+
/** Conflict markers (for manual resolution if needed) */
|
|
53
|
+
conflicts: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Merge options
|
|
57
|
+
*/
|
|
58
|
+
export interface MergeOptions {
|
|
59
|
+
/** Custom tombstone TTL in milliseconds (default: 30 days) */
|
|
60
|
+
tombstoneTtlMs?: number;
|
|
61
|
+
/** Enable debug logging */
|
|
62
|
+
debug?: boolean;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if a bead is a tombstone (soft-deleted)
|
|
66
|
+
*/
|
|
67
|
+
export declare function isTombstone(bead: BeadExport): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Check if a tombstone has expired (resurrection allowed)
|
|
70
|
+
*
|
|
71
|
+
* @param bead - The bead to check
|
|
72
|
+
* @param ttlMs - TTL in milliseconds (default: 30 days)
|
|
73
|
+
* @returns true if tombstone is expired, false otherwise
|
|
74
|
+
*/
|
|
75
|
+
export declare function isExpiredTombstone(bead: BeadExport, ttlMs?: number): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Perform 3-way merge of JSONL bead arrays
|
|
78
|
+
*
|
|
79
|
+
* @param base - Common ancestor (e.g., git merge-base)
|
|
80
|
+
* @param left - Local changes (e.g., HEAD)
|
|
81
|
+
* @param right - Remote changes (e.g., MERGE_HEAD)
|
|
82
|
+
* @param options - Merge options
|
|
83
|
+
* @returns Merged beads and any conflicts
|
|
84
|
+
*/
|
|
85
|
+
export declare function merge3Way(base: BeadExport[], left: BeadExport[], right: BeadExport[], options?: MergeOptions): MergeResult;
|
|
86
|
+
/**
|
|
87
|
+
* Merge JSONL strings (convenience wrapper)
|
|
88
|
+
*
|
|
89
|
+
* @param baseJsonl - Base JSONL string
|
|
90
|
+
* @param leftJsonl - Left JSONL string
|
|
91
|
+
* @param rightJsonl - Right JSONL string
|
|
92
|
+
* @param options - Merge options
|
|
93
|
+
* @returns Merged JSONL string
|
|
94
|
+
*/
|
|
95
|
+
export declare function mergeJsonl(baseJsonl: string, leftJsonl: string, rightJsonl: string, options?: MergeOptions): {
|
|
96
|
+
jsonl: string;
|
|
97
|
+
conflicts: string[];
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=merge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge.d.ts","sourceRoot":"","sources":["../../src/beads/merge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAM7C,2CAA2C;AAC3C,eAAO,MAAM,wBAAwB,QAA2B,CAAC;AAEjE,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,QAA0B,CAAC;AAE5D,8EAA8E;AAC9E,eAAO,MAAM,mBAAmB,QAAiB,CAAC;AAElD,gCAAgC;AAChC,eAAO,MAAM,gBAAgB,cAAc,CAAC;AAM5C;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,gCAAgC;IAChC,MAAM,EAAE,UAAU,EAAE,CAAC;IACrB,yDAAyD;IACzD,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,8DAA8D;IAC9D,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,2BAA2B;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AA0BD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAErD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,UAAU,EAChB,KAAK,GAAE,MAAiC,GACvC,OAAO,CAyBT;AAwUD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,UAAU,EAAE,EAClB,IAAI,EAAE,UAAU,EAAE,EAClB,KAAK,EAAE,UAAU,EAAE,EACnB,OAAO,GAAE,YAAiB,GACzB,WAAW,CA0Jb;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,YAAiB,GACzB;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,EAAE,CAAA;CAAE,CAoBxC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Schema Migration (v6)
|
|
3
|
+
*
|
|
4
|
+
* Adds beads-specific tables to the shared PGLite database.
|
|
5
|
+
* This migration extends the existing swarm-mail schema.
|
|
6
|
+
*
|
|
7
|
+
* ## Migration Strategy
|
|
8
|
+
* - Migration v6 adds beads tables to existing swarm-mail schema (v1-v5)
|
|
9
|
+
* - Shares same PGLite database instance and migration system
|
|
10
|
+
* - Uses same schema_version table for tracking
|
|
11
|
+
*
|
|
12
|
+
* ## Tables Created
|
|
13
|
+
* - beads: Core bead records (parallel to steveyegge/beads issues table)
|
|
14
|
+
* - bead_dependencies: Dependency relationships between beads
|
|
15
|
+
* - bead_labels: String tags for categorization
|
|
16
|
+
* - bead_comments: Comments/notes on beads
|
|
17
|
+
* - blocked_beads_cache: Materialized view for fast blocked queries
|
|
18
|
+
* - dirty_beads: Tracks beads that need JSONL export
|
|
19
|
+
*
|
|
20
|
+
* ## Design Notes
|
|
21
|
+
* - Uses BIGINT for timestamps (Unix ms, like swarm-mail events)
|
|
22
|
+
* - Uses TEXT for IDs (like steveyegge/beads)
|
|
23
|
+
* - CASCADE deletes for referential integrity
|
|
24
|
+
* - Indexes for common query patterns
|
|
25
|
+
* - CHECK constraints for data integrity
|
|
26
|
+
*
|
|
27
|
+
* @module beads/migrations
|
|
28
|
+
*/
|
|
29
|
+
import type { Migration } from "../streams/migrations.js";
|
|
30
|
+
/**
|
|
31
|
+
* Migration v6: Add beads tables
|
|
32
|
+
*
|
|
33
|
+
* This migration is designed to be appended to the existing migrations array
|
|
34
|
+
* in src/streams/migrations.ts.
|
|
35
|
+
*/
|
|
36
|
+
export declare const beadsMigration: Migration;
|
|
37
|
+
/**
|
|
38
|
+
* Export as array for convenience
|
|
39
|
+
*/
|
|
40
|
+
export declare const beadsMigrations: Migration[];
|
|
41
|
+
//# sourceMappingURL=migrations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../../src/beads/migrations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,SAoH5B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,SAAS,EAAqB,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bead Operations - High-level CRUD operations using BeadsAdapter
|
|
3
|
+
*
|
|
4
|
+
* Convenience functions that wrap BeadsAdapter with validation.
|
|
5
|
+
* Plugin tools should use these operations instead of calling adapter directly.
|
|
6
|
+
*
|
|
7
|
+
* ## Layering
|
|
8
|
+
* - BeadsAdapter: Low-level event sourcing operations
|
|
9
|
+
* - operations.ts: High-level validated CRUD (THIS FILE)
|
|
10
|
+
* - Plugin tools: Type-safe Zod-validated wrappers
|
|
11
|
+
*/
|
|
12
|
+
import type { BeadsAdapter, Bead, QueryBeadsOptions } from "../types/beads-adapter.js";
|
|
13
|
+
import { type CreateBeadOptions, type UpdateBeadOptions } from "./validation.js";
|
|
14
|
+
/**
|
|
15
|
+
* Create a new bead with validation
|
|
16
|
+
*
|
|
17
|
+
* @throws {Error} If validation fails
|
|
18
|
+
*/
|
|
19
|
+
export declare function createBead(adapter: BeadsAdapter, projectKey: string, options: CreateBeadOptions): Promise<Bead>;
|
|
20
|
+
/**
|
|
21
|
+
* Get a bead by ID
|
|
22
|
+
*
|
|
23
|
+
* @returns Bead or null if not found
|
|
24
|
+
*/
|
|
25
|
+
export declare function getBead(adapter: BeadsAdapter, projectKey: string, beadId: string): Promise<Bead | null>;
|
|
26
|
+
/**
|
|
27
|
+
* Update a bead with validation
|
|
28
|
+
*
|
|
29
|
+
* @throws {Error} If validation fails or bead not found
|
|
30
|
+
*/
|
|
31
|
+
export declare function updateBead(adapter: BeadsAdapter, projectKey: string, beadId: string, updates: UpdateBeadOptions): Promise<Bead>;
|
|
32
|
+
/**
|
|
33
|
+
* Close a bead
|
|
34
|
+
*
|
|
35
|
+
* @throws {Error} If bead not found
|
|
36
|
+
*/
|
|
37
|
+
export declare function closeBead(adapter: BeadsAdapter, projectKey: string, beadId: string, reason: string, closedBy?: string): Promise<Bead>;
|
|
38
|
+
/**
|
|
39
|
+
* Reopen a closed bead
|
|
40
|
+
*
|
|
41
|
+
* @throws {Error} If bead not found or invalid transition
|
|
42
|
+
*/
|
|
43
|
+
export declare function reopenBead(adapter: BeadsAdapter, projectKey: string, beadId: string, reopenedBy?: string): Promise<Bead>;
|
|
44
|
+
/**
|
|
45
|
+
* Delete a bead (soft delete - creates tombstone)
|
|
46
|
+
*
|
|
47
|
+
* @throws {Error} If bead not found
|
|
48
|
+
*/
|
|
49
|
+
export declare function deleteBead(adapter: BeadsAdapter, projectKey: string, beadId: string, reason: string, deletedBy?: string): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Search beads by title
|
|
52
|
+
*
|
|
53
|
+
* Simple text search across bead titles with optional filters.
|
|
54
|
+
*/
|
|
55
|
+
export declare function searchBeads(adapter: BeadsAdapter, projectKey: string, query: string, filter?: QueryBeadsOptions): Promise<Bead[]>;
|
|
56
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../../src/beads/operations.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,IAAI,EACJ,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACvB,MAAM,iBAAiB,CAAC;AAEzB;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAiBf;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAEtB;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CASf;AAED;;;;GAIG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,IAAI,CAAC,CAIf;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,EAAE,CAAC,CAejB"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Projections Layer - Update and query materialized views
|
|
3
|
+
*
|
|
4
|
+
* Projections are the read-side of CQRS. They update denormalized
|
|
5
|
+
* materialized views when events are appended, and provide query methods.
|
|
6
|
+
*
|
|
7
|
+
* ## Architecture
|
|
8
|
+
* - Event store is source of truth (write side)
|
|
9
|
+
* - Projections are cached views (read side)
|
|
10
|
+
* - Events trigger projection updates
|
|
11
|
+
* - Queries read from projections (fast)
|
|
12
|
+
*
|
|
13
|
+
* ## Key projections:
|
|
14
|
+
* - beads table: Main bead records
|
|
15
|
+
* - bead_dependencies: Dependency relationships
|
|
16
|
+
* - bead_labels: String tags
|
|
17
|
+
* - bead_comments: Comments/notes
|
|
18
|
+
* - blocked_beads_cache: Cached blocker lookups
|
|
19
|
+
* - dirty_beads: Tracks changes for export
|
|
20
|
+
*
|
|
21
|
+
* @module beads/projections
|
|
22
|
+
*/
|
|
23
|
+
import type { DatabaseAdapter } from "../types/database.js";
|
|
24
|
+
import type { Bead, BeadComment, BeadDependency, QueryBeadsOptions } from "../types/beads-adapter.js";
|
|
25
|
+
type BeadEvent = {
|
|
26
|
+
type: string;
|
|
27
|
+
project_key: string;
|
|
28
|
+
bead_id: string;
|
|
29
|
+
timestamp: number;
|
|
30
|
+
[key: string]: unknown;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Update projections based on an event
|
|
34
|
+
*
|
|
35
|
+
* This is called by the event store after appending an event.
|
|
36
|
+
* Routes to specific handlers based on event type.
|
|
37
|
+
*/
|
|
38
|
+
export declare function updateProjections(db: DatabaseAdapter, event: BeadEvent): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Get a bead by ID
|
|
41
|
+
*/
|
|
42
|
+
export declare function getBead(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<Bead | null>;
|
|
43
|
+
/**
|
|
44
|
+
* Query beads with filters
|
|
45
|
+
*/
|
|
46
|
+
export declare function queryBeads(db: DatabaseAdapter, projectKey: string, options?: QueryBeadsOptions): Promise<Bead[]>;
|
|
47
|
+
/**
|
|
48
|
+
* Get dependencies for a bead
|
|
49
|
+
*/
|
|
50
|
+
export declare function getDependencies(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<BeadDependency[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Get beads that depend on this bead
|
|
53
|
+
*/
|
|
54
|
+
export declare function getDependents(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<BeadDependency[]>;
|
|
55
|
+
/**
|
|
56
|
+
* Check if bead is blocked
|
|
57
|
+
*/
|
|
58
|
+
export declare function isBlocked(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Get blockers for a bead
|
|
61
|
+
*/
|
|
62
|
+
export declare function getBlockers(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<string[]>;
|
|
63
|
+
/**
|
|
64
|
+
* Get labels for a bead
|
|
65
|
+
*/
|
|
66
|
+
export declare function getLabels(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<string[]>;
|
|
67
|
+
/**
|
|
68
|
+
* Get comments for a bead
|
|
69
|
+
*/
|
|
70
|
+
export declare function getComments(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<BeadComment[]>;
|
|
71
|
+
/**
|
|
72
|
+
* Get next ready bead (unblocked, highest priority)
|
|
73
|
+
*/
|
|
74
|
+
export declare function getNextReadyBead(db: DatabaseAdapter, projectKey: string): Promise<Bead | null>;
|
|
75
|
+
/**
|
|
76
|
+
* Get all in-progress beads
|
|
77
|
+
*/
|
|
78
|
+
export declare function getInProgressBeads(db: DatabaseAdapter, projectKey: string): Promise<Bead[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Get all blocked beads with their blockers
|
|
81
|
+
*/
|
|
82
|
+
export declare function getBlockedBeads(db: DatabaseAdapter, projectKey: string): Promise<Array<{
|
|
83
|
+
bead: Bead;
|
|
84
|
+
blockers: string[];
|
|
85
|
+
}>>;
|
|
86
|
+
/**
|
|
87
|
+
* Mark bead as dirty for JSONL export
|
|
88
|
+
*/
|
|
89
|
+
export declare function markBeadDirty(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<void>;
|
|
90
|
+
/**
|
|
91
|
+
* Get all dirty beads
|
|
92
|
+
*/
|
|
93
|
+
export declare function getDirtyBeads(db: DatabaseAdapter, projectKey: string): Promise<string[]>;
|
|
94
|
+
/**
|
|
95
|
+
* Clear dirty flag after export
|
|
96
|
+
*/
|
|
97
|
+
export declare function clearDirtyBead(db: DatabaseAdapter, projectKey: string, beadId: string): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Clear all dirty flags
|
|
100
|
+
*/
|
|
101
|
+
export declare function clearAllDirtyBeads(db: DatabaseAdapter, projectKey: string): Promise<void>;
|
|
102
|
+
export {};
|
|
103
|
+
//# sourceMappingURL=projections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"projections.d.ts","sourceRoot":"","sources":["../../src/beads/projections.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAC5D,OAAO,KAAK,EACV,IAAI,EACJ,WAAW,EACX,cAAc,EAId,iBAAiB,EAClB,MAAM,2BAA2B,CAAC;AAInC,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,CAAC;AAMF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,EAAE,EAAE,eAAe,EACnB,KAAK,EAAE,SAAS,GACf,OAAO,CAAC,IAAI,CAAC,CA6Df;AAkND;;GAEG;AACH,wBAAsB,OAAO,CAC3B,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,CAMtB;AAED;;GAEG;AACH,wBAAsB,UAAU,CAC9B,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,IAAI,EAAE,CAAC,CA6CjB;AAED;;GAEG;AACH,wBAAsB,eAAe,CACnC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,cAAc,EAAE,CAAC,CAM3B;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC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MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAOf;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,EAAE,CAAC,CASnB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,CAKf;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,EAAE,EAAE,eAAe,EACnB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,IAAI,CAAC,CAOf"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Query Functions
|
|
3
|
+
*
|
|
4
|
+
* High-level query functions for common bead operations:
|
|
5
|
+
* - Ready work (unblocked beads with sort policies)
|
|
6
|
+
* - Blocked issues with blockers
|
|
7
|
+
* - Epics eligible for closure
|
|
8
|
+
* - Stale issues
|
|
9
|
+
* - Statistics
|
|
10
|
+
*
|
|
11
|
+
* Based on steveyegge/beads query patterns.
|
|
12
|
+
*
|
|
13
|
+
* @module beads/queries
|
|
14
|
+
*/
|
|
15
|
+
import type { Bead, BeadStatus, BeadsAdapter } from "../types/beads-adapter.js";
|
|
16
|
+
/**
|
|
17
|
+
* Sort policy for ready work queries
|
|
18
|
+
*
|
|
19
|
+
* - hybrid (default): Recent issues (<48h) by priority, older by age
|
|
20
|
+
* - priority: Always priority first, then creation date
|
|
21
|
+
* - oldest: Creation date ascending (backlog clearing)
|
|
22
|
+
*/
|
|
23
|
+
export type SortPolicy = "hybrid" | "priority" | "oldest";
|
|
24
|
+
export interface ReadyWorkOptions {
|
|
25
|
+
limit?: number;
|
|
26
|
+
assignee?: string;
|
|
27
|
+
unassigned?: boolean;
|
|
28
|
+
labels?: string[];
|
|
29
|
+
sortPolicy?: SortPolicy;
|
|
30
|
+
}
|
|
31
|
+
export interface BlockedBead {
|
|
32
|
+
bead: Bead;
|
|
33
|
+
blockers: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface EpicStatus {
|
|
36
|
+
epic_id: string;
|
|
37
|
+
title: string;
|
|
38
|
+
total_children: number;
|
|
39
|
+
closed_children: number;
|
|
40
|
+
}
|
|
41
|
+
export interface StaleOptions {
|
|
42
|
+
status?: BeadStatus;
|
|
43
|
+
limit?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface Statistics {
|
|
46
|
+
total_beads: number;
|
|
47
|
+
open: number;
|
|
48
|
+
in_progress: number;
|
|
49
|
+
closed: number;
|
|
50
|
+
blocked: number;
|
|
51
|
+
ready: number;
|
|
52
|
+
by_type: Record<string, number>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get ready work (unblocked, prioritized)
|
|
56
|
+
*
|
|
57
|
+
* By default returns both 'open' and 'in_progress' beads so epics/tasks
|
|
58
|
+
* ready to close are visible (matching steveyegge/beads behavior).
|
|
59
|
+
*/
|
|
60
|
+
export declare function getReadyWork(adapter: BeadsAdapter, projectKey: string, options?: ReadyWorkOptions): Promise<Bead[]>;
|
|
61
|
+
/**
|
|
62
|
+
* Get all blocked beads with their blockers
|
|
63
|
+
*/
|
|
64
|
+
export declare function getBlockedIssues(adapter: BeadsAdapter, projectKey: string): Promise<BlockedBead[]>;
|
|
65
|
+
/**
|
|
66
|
+
* Get epics eligible for closure (all children closed)
|
|
67
|
+
*/
|
|
68
|
+
export declare function getEpicsEligibleForClosure(adapter: BeadsAdapter, projectKey: string): Promise<EpicStatus[]>;
|
|
69
|
+
/**
|
|
70
|
+
* Get stale issues (not updated in N days)
|
|
71
|
+
*/
|
|
72
|
+
export declare function getStaleIssues(adapter: BeadsAdapter, projectKey: string, days: number, options?: StaleOptions): Promise<Bead[]>;
|
|
73
|
+
/**
|
|
74
|
+
* Get aggregate statistics
|
|
75
|
+
*/
|
|
76
|
+
export declare function getStatistics(adapter: BeadsAdapter, projectKey: string): Promise<Statistics>;
|
|
77
|
+
//# sourceMappingURL=queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.d.ts","sourceRoot":"","sources":["../../src/beads/queries.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,IAAI,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEhF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,UAAU,GAAG,QAAQ,CAAC;AAE1D,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,IAAI,CAAC;IACX,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED;;;;;GAKG;AACH,wBAAsB,YAAY,CAChC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,IAAI,EAAE,CAAC,CA2DjB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,WAAW,EAAE,CAAC,CAmBxB;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,EAAE,CAAC,CA4BvB;AAED;;GAEG;AACH,wBAAsB,cAAc,CAClC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,IAAI,EAAE,CAAC,CAmCjB;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,YAAY,EACrB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC,CA4ErB"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Beads Event Store - Append-only event log for bead operations
|
|
3
|
+
*
|
|
4
|
+
* Integrates bead events (from opencode-swarm-plugin) into the shared
|
|
5
|
+
* swarm-mail event store. Follows same pattern as streams/store.ts but
|
|
6
|
+
* for bead-specific events.
|
|
7
|
+
*
|
|
8
|
+
* ## Architecture
|
|
9
|
+
* - Bead events stored in shared `events` table (same as agent/message events)
|
|
10
|
+
* - Events trigger updateProjections() to update materialized views
|
|
11
|
+
* - Events are NOT replayed for state (hybrid model - projections are source of truth)
|
|
12
|
+
* - Event log provides audit trail and debugging for swarm coordination
|
|
13
|
+
*
|
|
14
|
+
* ## Event Flow
|
|
15
|
+
* 1. appendBeadEvent() -> INSERT INTO events
|
|
16
|
+
* 2. updateProjections() -> UPDATE materialized views (beads, dependencies, labels, etc.)
|
|
17
|
+
* 3. Query operations read from projections (fast)
|
|
18
|
+
*
|
|
19
|
+
* @module beads/store
|
|
20
|
+
*/
|
|
21
|
+
import type { DatabaseAdapter } from "../types/database.js";
|
|
22
|
+
import type { BeadEvent } from "./events.js";
|
|
23
|
+
/**
|
|
24
|
+
* Options for reading bead events
|
|
25
|
+
*/
|
|
26
|
+
export interface ReadBeadEventsOptions {
|
|
27
|
+
/** Filter by project key */
|
|
28
|
+
projectKey?: string;
|
|
29
|
+
/** Filter by bead ID */
|
|
30
|
+
beadId?: string;
|
|
31
|
+
/** Filter by event types */
|
|
32
|
+
types?: BeadEvent["type"][];
|
|
33
|
+
/** Events after this timestamp */
|
|
34
|
+
since?: number;
|
|
35
|
+
/** Events before this timestamp */
|
|
36
|
+
until?: number;
|
|
37
|
+
/** Events after this sequence number */
|
|
38
|
+
afterSequence?: number;
|
|
39
|
+
/** Maximum number of events to return */
|
|
40
|
+
limit?: number;
|
|
41
|
+
/** Skip this many events (pagination) */
|
|
42
|
+
offset?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Append a bead event to the shared event store
|
|
46
|
+
*
|
|
47
|
+
* Events are stored in the same `events` table as agent/message events.
|
|
48
|
+
* Triggers updateProjections() to update materialized views.
|
|
49
|
+
*
|
|
50
|
+
* @param event - Bead event to append
|
|
51
|
+
* @param projectPath - Optional project path for database location
|
|
52
|
+
* @param dbOverride - Optional database adapter for dependency injection
|
|
53
|
+
* @returns Event with id and sequence number
|
|
54
|
+
*/
|
|
55
|
+
export declare function appendBeadEvent(event: BeadEvent, projectPath?: string, dbOverride?: DatabaseAdapter): Promise<BeadEvent & {
|
|
56
|
+
id: number;
|
|
57
|
+
sequence: number;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Read bead events with optional filters
|
|
61
|
+
*
|
|
62
|
+
* Queries the shared events table for bead events (type starts with "bead_").
|
|
63
|
+
*
|
|
64
|
+
* @param options - Filter options
|
|
65
|
+
* @param projectPath - Optional project path for database location
|
|
66
|
+
* @param dbOverride - Optional database adapter for dependency injection
|
|
67
|
+
* @returns Array of bead events with id and sequence
|
|
68
|
+
*/
|
|
69
|
+
export declare function readBeadEvents(options?: ReadBeadEventsOptions, projectPath?: string, dbOverride?: DatabaseAdapter): Promise<Array<BeadEvent & {
|
|
70
|
+
id: number;
|
|
71
|
+
sequence: number;
|
|
72
|
+
}>>;
|
|
73
|
+
/**
|
|
74
|
+
* Replay bead events to rebuild materialized views
|
|
75
|
+
*
|
|
76
|
+
* Useful for:
|
|
77
|
+
* - Recovering from projection corruption
|
|
78
|
+
* - Migrating to new schema
|
|
79
|
+
* - Debugging state issues
|
|
80
|
+
*
|
|
81
|
+
* Note: Unlike swarm-mail agent events, bead projections are NOT rebuilt
|
|
82
|
+
* from events in normal operation (hybrid CRUD + audit trail model).
|
|
83
|
+
* This function is for recovery/debugging only.
|
|
84
|
+
*
|
|
85
|
+
* @param options - Replay options
|
|
86
|
+
* @param projectPath - Optional project path for database location
|
|
87
|
+
* @param dbOverride - Optional database adapter for dependency injection
|
|
88
|
+
* @returns Stats about replay operation
|
|
89
|
+
*/
|
|
90
|
+
export declare function replayBeadEvents(options?: {
|
|
91
|
+
projectKey?: string;
|
|
92
|
+
fromSequence?: number;
|
|
93
|
+
clearViews?: boolean;
|
|
94
|
+
}, projectPath?: string, dbOverride?: DatabaseAdapter): Promise<{
|
|
95
|
+
eventsReplayed: number;
|
|
96
|
+
duration: number;
|
|
97
|
+
}>;
|
|
98
|
+
//# sourceMappingURL=store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/beads/store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AA+B7C;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,4B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AAM,CAAA;CAAE,CAAC,CAyEvD"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bead Validation - Port of steveyegge/beads internal/validation/bead.go
|
|
3
|
+
*
|
|
4
|
+
* Implements validation rules from steveyegge/beads internal/types/types.go Validate() method.
|
|
5
|
+
*
|
|
6
|
+
* ## Business Rules
|
|
7
|
+
* - Title required, max 500 chars
|
|
8
|
+
* - Priority 0-4 (0=critical, 4=low)
|
|
9
|
+
* - Valid status: open, in_progress, blocked, closed, tombstone
|
|
10
|
+
* - Valid type: bug, feature, task, epic, chore, message
|
|
11
|
+
* - closed_at only when status=closed
|
|
12
|
+
* - deleted_at required when status=tombstone
|
|
13
|
+
* - Status transitions enforce state machine
|
|
14
|
+
*
|
|
15
|
+
* ## Status Transition Rules
|
|
16
|
+
* - open -> in_progress, blocked, closed
|
|
17
|
+
* - in_progress -> open, blocked, closed
|
|
18
|
+
* - blocked -> open, in_progress, closed
|
|
19
|
+
* - closed -> open (reopen only)
|
|
20
|
+
* - tombstone -> (no transitions, permanent)
|
|
21
|
+
*
|
|
22
|
+
* Direct transitions to tombstone are prohibited - use delete operation instead.
|
|
23
|
+
*/
|
|
24
|
+
import type { BeadStatus, BeadType } from "../types/beads-adapter.js";
|
|
25
|
+
export interface ValidationResult {
|
|
26
|
+
valid: boolean;
|
|
27
|
+
errors: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface CreateBeadOptions {
|
|
30
|
+
title: string;
|
|
31
|
+
type: BeadType;
|
|
32
|
+
priority?: number;
|
|
33
|
+
description?: string;
|
|
34
|
+
parent_id?: string;
|
|
35
|
+
assignee?: string;
|
|
36
|
+
created_by?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface UpdateBeadOptions {
|
|
39
|
+
title?: string;
|
|
40
|
+
description?: string;
|
|
41
|
+
priority?: number;
|
|
42
|
+
assignee?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Validate bead creation options
|
|
46
|
+
*
|
|
47
|
+
* @param options - Bead creation options
|
|
48
|
+
* @returns Validation result with errors if invalid
|
|
49
|
+
*/
|
|
50
|
+
export declare function validateCreateBead(options: CreateBeadOptions): ValidationResult;
|
|
51
|
+
/**
|
|
52
|
+
* Validate bead update options
|
|
53
|
+
*
|
|
54
|
+
* @param options - Bead update options
|
|
55
|
+
* @returns Validation result with errors if invalid
|
|
56
|
+
*/
|
|
57
|
+
export declare function validateUpdateBead(options: UpdateBeadOptions): ValidationResult;
|
|
58
|
+
/**
|
|
59
|
+
* Validate status transition
|
|
60
|
+
*
|
|
61
|
+
* Enforces state machine rules:
|
|
62
|
+
* - open -> in_progress, blocked, closed
|
|
63
|
+
* - in_progress -> open, blocked, closed
|
|
64
|
+
* - blocked -> open, in_progress, closed
|
|
65
|
+
* - closed -> open (reopen only)
|
|
66
|
+
* - tombstone -> (no transitions, permanent)
|
|
67
|
+
*
|
|
68
|
+
* Direct transitions to tombstone are prohibited - use delete operation.
|
|
69
|
+
*
|
|
70
|
+
* @param currentStatus - Current bead status
|
|
71
|
+
* @param newStatus - Target status
|
|
72
|
+
* @returns Validation result with errors if invalid
|
|
73
|
+
*/
|
|
74
|
+
export declare function validateStatusTransition(currentStatus: BeadStatus, newStatus: BeadStatus): ValidationResult;
|
|
75
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/beads/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAEtE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GACzB,gBAAgB,CAmClB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GACzB,gBAAgB,CAyBlB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACtC,aAAa,EAAE,UAAU,EACzB,SAAS,EAAE,UAAU,GACpB,gBAAgB,CA+ClB"}
|
package/dist/daemon.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Daemon Lifecycle Management for
|
|
2
|
+
* Daemon Lifecycle Management for PGLiteSocketServer
|
|
3
3
|
*
|
|
4
|
-
* Provides start/stop/health functionality for
|
|
5
|
-
* Uses
|
|
4
|
+
* Provides start/stop/health functionality for in-process PGLiteSocketServer.
|
|
5
|
+
* Uses module-level state to track active server instance.
|
|
6
6
|
*
|
|
7
7
|
* ## Usage
|
|
8
8
|
* ```typescript
|
|
@@ -90,9 +90,9 @@ export declare function isDaemonRunning(projectPath?: string): Promise<boolean>;
|
|
|
90
90
|
*/
|
|
91
91
|
export declare function healthCheck(options: Pick<DaemonOptions, "port" | "host" | "path">): Promise<boolean>;
|
|
92
92
|
/**
|
|
93
|
-
* Start
|
|
93
|
+
* Start PGLiteSocketServer daemon in-process
|
|
94
94
|
*
|
|
95
|
-
*
|
|
95
|
+
* Creates PGlite instance and starts PGLiteSocketServer.
|
|
96
96
|
* Writes PID file and waits for server to be ready via health check.
|
|
97
97
|
*
|
|
98
98
|
* If daemon is already running, returns existing daemon info.
|
|
@@ -120,15 +120,14 @@ export declare function healthCheck(options: Pick<DaemonOptions, "port" | "host"
|
|
|
120
120
|
*/
|
|
121
121
|
export declare function startDaemon(options?: DaemonOptions): Promise<DaemonInfo>;
|
|
122
122
|
/**
|
|
123
|
-
* Stop
|
|
123
|
+
* Stop PGLiteSocketServer daemon
|
|
124
124
|
*
|
|
125
|
-
*
|
|
126
|
-
* Cleans up PID file
|
|
125
|
+
* Performs graceful shutdown: CHECKPOINT → server.stop() → db.close()
|
|
126
|
+
* Cleans up PID file and module-level state.
|
|
127
127
|
*
|
|
128
128
|
* If daemon is not running, this is a no-op (not an error).
|
|
129
129
|
*
|
|
130
130
|
* @param projectPath - Optional project root path
|
|
131
|
-
* @throws Error if daemon doesn't stop within timeout
|
|
132
131
|
*
|
|
133
132
|
* @example
|
|
134
133
|
* ```typescript
|