@lumenflow/agent 1.3.2 → 1.3.4

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,55 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * IncidentLog schema for structured issue tracking
4
+ * Stored as NDJSON in .beacon/incidents/<category>.ndjson
5
+ */
6
+ export declare const IncidentLogSchema: z.ZodObject<{
7
+ timestamp: z.ZodString;
8
+ session_id: z.ZodString;
9
+ wu_id: z.ZodString;
10
+ lane: z.ZodString;
11
+ category: z.ZodEnum<{
12
+ workflow: "workflow";
13
+ tooling: "tooling";
14
+ confusion: "confusion";
15
+ violation: "violation";
16
+ error: "error";
17
+ }>;
18
+ severity: z.ZodEnum<{
19
+ blocker: "blocker";
20
+ major: "major";
21
+ minor: "minor";
22
+ info: "info";
23
+ }>;
24
+ title: z.ZodString;
25
+ description: z.ZodString;
26
+ resolution: z.ZodOptional<z.ZodString>;
27
+ tags: z.ZodDefault<z.ZodArray<z.ZodString>>;
28
+ context: z.ZodDefault<z.ZodOptional<z.ZodObject<{
29
+ git_branch: z.ZodOptional<z.ZodString>;
30
+ current_step: z.ZodOptional<z.ZodString>;
31
+ related_files: z.ZodOptional<z.ZodArray<z.ZodString>>;
32
+ }, z.core.$strip>>>;
33
+ }, z.core.$strip>;
34
+ /**
35
+ * @typedef {z.infer<typeof IncidentLogSchema>} IncidentLog
36
+ */
37
+ /**
38
+ * Inferred type from IncidentLogSchema
39
+ */
40
+ export type IncidentLog = z.infer<typeof IncidentLogSchema>;
41
+ /**
42
+ * Append an incident to the appropriate NDJSON log file
43
+ * @param incident - Incident data (will be validated)
44
+ * @param incidentsDir - Optional directory override (for testing)
45
+ * @throws {z.ZodError} if incident data is invalid
46
+ */
47
+ export declare function appendIncident(incident: unknown, incidentsDir?: string): void;
48
+ /**
49
+ * Read and parse incidents from NDJSON files
50
+ * @param categories - Categories to read (default: all)
51
+ * @param since - Filter incidents after this date
52
+ * @param incidentsDir - Optional directory override (for testing)
53
+ * @returns Parsed and validated incidents
54
+ */
55
+ export declare function readIncidents(categories?: readonly string[] | null, since?: Date | null, incidentsDir?: string): IncidentLog[];
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Session data structure
3
+ */
4
+ interface SessionData {
5
+ session_id: string;
6
+ wu_id: string;
7
+ lane: string;
8
+ started: string;
9
+ completed?: string;
10
+ agent_type: string;
11
+ context_tier: number;
12
+ incidents_logged: number;
13
+ incidents_major: number;
14
+ }
15
+ /**
16
+ * Start a new agent session
17
+ * @param wuId - WU ID (e.g., "WU-1234")
18
+ * @param tier - Context tier from bootloader
19
+ * @param agentType - Agent type (default: "claude-code")
20
+ * @returns session_id
21
+ * @throws {Error} if session already active or WU format invalid
22
+ */
23
+ export declare function startSession(wuId: string, tier: 1 | 2 | 3, agentType?: string): Promise<string>;
24
+ /**
25
+ * Get the current active session
26
+ * @returns Session state or null if no active session
27
+ */
28
+ export declare function getCurrentSession(): Promise<SessionData | null>;
29
+ /**
30
+ * Incident data input type
31
+ */
32
+ interface IncidentDataInput {
33
+ category: string;
34
+ severity: string;
35
+ title: string;
36
+ description: string;
37
+ context?: Record<string, unknown>;
38
+ [key: string]: unknown;
39
+ }
40
+ /**
41
+ * Log an incident and update session counters
42
+ * @param incidentData - Incident data (category, severity, title, description, etc.)
43
+ * @throws {Error} if no active session
44
+ */
45
+ export declare function logIncident(incidentData: IncidentDataInput): Promise<void>;
46
+ /**
47
+ * Session summary returned after ending a session
48
+ */
49
+ interface SessionSummary {
50
+ wu_id: string;
51
+ lane: string;
52
+ session_id: string;
53
+ started: string;
54
+ completed: string;
55
+ agent_type: string;
56
+ context_tier: number;
57
+ incidents_logged: number;
58
+ incidents_major: number;
59
+ }
60
+ /**
61
+ * End the current session and return summary
62
+ * @returns Session summary for appending to WU YAML
63
+ * @throws {Error} if no active session
64
+ */
65
+ export declare function endSession(): Promise<SessionSummary>;
66
+ export {};
@@ -0,0 +1,31 @@
1
+ type RunFn = (cmd: string) => string;
2
+ type ExistsFn = (path: string) => boolean;
3
+ /**
4
+ * Verification result type
5
+ */
6
+ export interface VerificationResult {
7
+ complete: boolean;
8
+ failures: string[];
9
+ }
10
+ /**
11
+ * Verification overrides for testing
12
+ */
13
+ interface VerificationOverrides {
14
+ run?: RunFn;
15
+ exists?: ExistsFn;
16
+ }
17
+ /**
18
+ * Verify that a WU has been completed and merged to main.
19
+ *
20
+ * Checks:
21
+ * 1. Working tree is clean
22
+ * 2. Completion stamp exists
23
+ * 3. Main history contains a commit updating the WU YAML
24
+ *
25
+ * @param wuId - Work Unit identifier (e.g., "WU-510")
26
+ * @param overrides - Test overrides
27
+ * @returns Verification result
28
+ */
29
+ export declare function verifyWUComplete(wuId: string, overrides?: VerificationOverrides): VerificationResult;
30
+ export declare function debugSummary(result: VerificationResult | null | undefined): string;
31
+ export {};
@@ -0,0 +1,106 @@
1
+ /**
2
+ * Session data stored in current.json
3
+ */
4
+ interface SessionFileData {
5
+ session_id: string;
6
+ wu_id: string;
7
+ started: string;
8
+ completed?: string;
9
+ agent_type: string;
10
+ context_tier: number;
11
+ incidents_logged: number;
12
+ incidents_major: number;
13
+ auto_started?: boolean;
14
+ }
15
+ /**
16
+ * Options for starting a session for a WU
17
+ */
18
+ interface StartSessionOptions {
19
+ wuId: string;
20
+ tier?: 1 | 2 | 3;
21
+ agentType?: string;
22
+ sessionDir?: string;
23
+ baseDir?: string;
24
+ }
25
+ /**
26
+ * Result of starting a session
27
+ */
28
+ interface StartSessionResult {
29
+ sessionId: string;
30
+ alreadyActive?: boolean;
31
+ memoryNodeId?: string | null;
32
+ }
33
+ /**
34
+ * Start a session for a WU (called by wu:claim)
35
+ *
36
+ * Unlike startSession in agent-session.mjs, this function:
37
+ * - Does NOT throw if a session already exists (returns existing session)
38
+ * - Uses default tier 2 if not specified
39
+ * - Supports custom session directory for testing
40
+ * - Creates memory layer session node for context restoration (WU-1466)
41
+ *
42
+ * @param options - Session options
43
+ * @returns Session result
44
+ */
45
+ export declare function startSessionForWU(options: StartSessionOptions): Promise<StartSessionResult>;
46
+ /**
47
+ * Options for ending a session
48
+ */
49
+ interface EndSessionOptions {
50
+ sessionDir?: string;
51
+ }
52
+ /**
53
+ * Session summary
54
+ */
55
+ interface SessionSummary {
56
+ wu_id: string;
57
+ session_id: string;
58
+ started: string;
59
+ completed: string;
60
+ agent_type: string;
61
+ context_tier: number;
62
+ incidents_logged: number;
63
+ incidents_major: number;
64
+ }
65
+ /**
66
+ * Result of ending a session
67
+ */
68
+ interface EndSessionResult {
69
+ ended: boolean;
70
+ summary?: SessionSummary;
71
+ reason?: string;
72
+ }
73
+ /**
74
+ * End the current session (called by wu:done)
75
+ *
76
+ * Unlike endSession in agent-session.mjs, this function:
77
+ * - Does NOT throw if no active session (returns { ended: false })
78
+ * - Returns structured result with summary
79
+ * - Supports custom session directory for testing
80
+ *
81
+ * @param options - Session options
82
+ * @returns Session end result
83
+ */
84
+ export declare function endSessionForWU(options?: EndSessionOptions): EndSessionResult;
85
+ /**
86
+ * Options for getting current session
87
+ */
88
+ interface GetSessionOptions {
89
+ sessionDir?: string;
90
+ }
91
+ /**
92
+ * Get the current active session
93
+ *
94
+ * @param options - Session options
95
+ * @returns Session object or null if no active session
96
+ */
97
+ export declare function getCurrentSessionForWU(options?: GetSessionOptions): SessionFileData | null;
98
+ /**
99
+ * Check if there's an active session for a specific WU
100
+ *
101
+ * @param wuId - WU ID to check
102
+ * @param options - Session options
103
+ * @returns True if session exists and matches WU ID
104
+ */
105
+ export declare function hasActiveSessionForWU(wuId: string, options?: GetSessionOptions): boolean;
106
+ export {};
@@ -0,0 +1,137 @@
1
+ /**
2
+ * Feedback Promote Core Logic (WU-1599)
3
+ *
4
+ * Generates draft WU specs from feedback patterns and promotes them to actual WUs.
5
+ * Tracks incident-to-WU mappings in feedback-index.ndjson.
6
+ *
7
+ * @see {@link tools/__tests__/feedback-promote.test.mjs} - Tests
8
+ * @see {@link tools/feedback-promote.mjs} - CLI entry point
9
+ */
10
+ /**
11
+ * Directory for draft WU specs
12
+ */
13
+ export declare const DRAFT_DIRECTORY = ".beacon/feedback-drafts";
14
+ /**
15
+ * Path to feedback index (incident-to-WU mappings)
16
+ */
17
+ export declare const FEEDBACK_INDEX_PATH = ".beacon/feedback-index.ndjson";
18
+ /**
19
+ * Feedback index entry status
20
+ */
21
+ export declare const FEEDBACK_STATUS: {
22
+ PENDING_RESOLUTION: string;
23
+ RESOLVED: string;
24
+ WONT_FIX: string;
25
+ };
26
+ /**
27
+ * Pattern example structure
28
+ */
29
+ interface PatternExample {
30
+ id: string;
31
+ [key: string]: unknown;
32
+ }
33
+ /**
34
+ * Pattern structure from feedback:review
35
+ */
36
+ interface Pattern {
37
+ title: string;
38
+ category?: string;
39
+ frequency?: number;
40
+ score?: number;
41
+ firstSeen?: string;
42
+ lastSeen?: string;
43
+ examples?: PatternExample[];
44
+ }
45
+ /**
46
+ * Draft WU spec structure
47
+ */
48
+ interface DraftSpec {
49
+ title: string;
50
+ lane: string;
51
+ description: string;
52
+ acceptance: string[];
53
+ source_incidents: string[];
54
+ pattern_metadata: {
55
+ frequency: number | undefined;
56
+ category: string | undefined;
57
+ score: number | undefined;
58
+ firstSeen: string | undefined;
59
+ lastSeen: string | undefined;
60
+ };
61
+ filePath?: string;
62
+ }
63
+ /**
64
+ * Options for generating a draft
65
+ */
66
+ interface GenerateDraftOptions {
67
+ writeFile?: boolean;
68
+ }
69
+ /**
70
+ * Generate draft WU spec from a pattern
71
+ *
72
+ * @param baseDir - Base directory
73
+ * @param pattern - Pattern from feedback:review
74
+ * @param options - Options
75
+ * @returns Draft WU spec
76
+ */
77
+ export declare function generateDraft(baseDir: string, pattern: Pattern, options?: GenerateDraftOptions): Promise<DraftSpec>;
78
+ /**
79
+ * Load all draft files from .beacon/feedback-drafts/
80
+ *
81
+ * @param baseDir - Base directory
82
+ * @returns Array of draft objects with filePath
83
+ */
84
+ export declare function loadDrafts(baseDir: string): Promise<DraftSpec[]>;
85
+ /**
86
+ * Options for promoting a draft
87
+ */
88
+ interface PromoteDraftOptions {
89
+ dryRun?: boolean;
90
+ wuIdOverride?: string;
91
+ removeDraft?: boolean;
92
+ }
93
+ /**
94
+ * Result of promoting a draft
95
+ */
96
+ interface PromoteDraftResult {
97
+ success: boolean;
98
+ wuId: string;
99
+ command: string;
100
+ draft?: DraftSpec;
101
+ error?: string;
102
+ draftRemoved?: boolean;
103
+ }
104
+ /**
105
+ * Promote a draft to a WU via wu:create
106
+ *
107
+ * @param baseDir - Base directory
108
+ * @param draft - Draft object
109
+ * @param options - Options
110
+ * @returns Result with success, wuId, command
111
+ */
112
+ export declare function promoteDraft(baseDir: string, draft: DraftSpec, options?: PromoteDraftOptions): Promise<PromoteDraftResult>;
113
+ /**
114
+ * Feedback index entry
115
+ */
116
+ interface FeedbackIndexEntry {
117
+ incident_id: string;
118
+ wu_id: string;
119
+ status: string;
120
+ timestamp: string;
121
+ }
122
+ /**
123
+ * Update feedback index with incident-to-WU mappings
124
+ *
125
+ * @param baseDir - Base directory
126
+ * @param wuId - WU ID
127
+ * @param incidentIds - Array of incident IDs
128
+ */
129
+ export declare function updateFeedbackIndex(baseDir: string, wuId: string, incidentIds: string[]): Promise<void>;
130
+ /**
131
+ * Load feedback index entries
132
+ *
133
+ * @param baseDir - Base directory
134
+ * @returns Array of index entries
135
+ */
136
+ export declare function loadFeedbackIndex(baseDir: string): Promise<FeedbackIndexEntry[]>;
137
+ export {};
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Feedback Review Core Logic (WU-1598)
3
+ *
4
+ * Aggregates .beacon/incidents/*.ndjson and .beacon/memory/memory.jsonl,
5
+ * clusters by title similarity, scores patterns (frequency x severity x recency),
6
+ * and outputs prioritised patterns for human review.
7
+ *
8
+ * @see {@link tools/__tests__/feedback-review.test.mjs} - Tests
9
+ * @see {@link tools/feedback-review.mjs} - CLI entry point
10
+ */
11
+ import { INCIDENT_SEVERITY } from '@lumenflow/core/lib/wu-constants.js';
12
+ /**
13
+ * Severity weights for scoring
14
+ *
15
+ * Higher severity = higher weight in scoring formula
16
+ */
17
+ export declare const SEVERITY_WEIGHTS: {
18
+ [INCIDENT_SEVERITY.BLOCKER]: number;
19
+ [INCIDENT_SEVERITY.MAJOR]: number;
20
+ [INCIDENT_SEVERITY.MINOR]: number;
21
+ [INCIDENT_SEVERITY.INFO]: number;
22
+ };
23
+ /**
24
+ * Node with ID and optional title/content
25
+ */
26
+ interface NodeWithTitle {
27
+ id: string;
28
+ title?: string;
29
+ content?: string;
30
+ category?: string;
31
+ severity?: string;
32
+ created_at?: string;
33
+ source?: string;
34
+ metadata?: Record<string, unknown>;
35
+ type?: string;
36
+ tags?: string[];
37
+ }
38
+ /**
39
+ * Cluster of nodes grouped by title similarity
40
+ */
41
+ interface Cluster {
42
+ title: string;
43
+ nodes: NodeWithTitle[];
44
+ category: string;
45
+ }
46
+ /**
47
+ * Cluster nodes by title similarity
48
+ *
49
+ * Uses simple greedy clustering with Jaccard similarity.
50
+ *
51
+ * @param nodes - Nodes to cluster
52
+ * @param threshold - Similarity threshold
53
+ * @returns Array of cluster objects
54
+ */
55
+ export declare function clusterByTitle(nodes: NodeWithTitle[], threshold?: number): Cluster[];
56
+ /**
57
+ * Score a pattern cluster
58
+ *
59
+ * Formula: frequency x average_severity x recency_factor
60
+ *
61
+ * @param cluster - Cluster with nodes
62
+ * @returns Score value
63
+ */
64
+ export declare function scorePattern(cluster: Cluster): number;
65
+ /**
66
+ * Options for reviewing feedback
67
+ */
68
+ interface ReviewOptions {
69
+ since?: string;
70
+ minFrequency?: number;
71
+ category?: string;
72
+ json?: boolean;
73
+ }
74
+ /**
75
+ * Pattern example for output
76
+ */
77
+ interface PatternExample {
78
+ id: string;
79
+ severity: string | undefined;
80
+ source: string | undefined;
81
+ }
82
+ /**
83
+ * Pattern in review result
84
+ */
85
+ interface ReviewPattern {
86
+ title: string;
87
+ frequency: number;
88
+ category: string;
89
+ score: number;
90
+ firstSeen: string | undefined;
91
+ lastSeen: string | undefined;
92
+ examples: PatternExample[];
93
+ }
94
+ /**
95
+ * Review result
96
+ */
97
+ interface ReviewResult {
98
+ success: boolean;
99
+ patterns: ReviewPattern[];
100
+ summary: {
101
+ totalNodes: number;
102
+ totalClusters: number;
103
+ topCategory: string | null;
104
+ };
105
+ }
106
+ /**
107
+ * Review feedback from incidents and memory nodes
108
+ *
109
+ * Main entry point for feedback review logic.
110
+ *
111
+ * @param baseDir - Base directory containing .beacon
112
+ * @param options - Review options
113
+ * @returns Review result
114
+ */
115
+ export declare function reviewFeedback(baseDir: string, options?: ReviewOptions): Promise<ReviewResult>;
116
+ export {};
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @lumenflow/agent - Agent session management
3
+ * @module @lumenflow/agent
4
+ */
5
+ export * from './agent-incidents.js';
6
+ export * from './agent-session.js';
7
+ export * from './agent-verification.js';
8
+ export * from './auto-session-integration.js';
9
+ export * from './feedback-promote-core.js';
10
+ export * from './feedback-review-core.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lumenflow/agent",
3
- "version": "1.3.2",
3
+ "version": "1.3.4",
4
4
  "description": "Agent session management for LumenFlow workflow framework",
5
5
  "keywords": [
6
6
  "lumenflow",
@@ -40,8 +40,8 @@
40
40
  "dependencies": {
41
41
  "simple-git": "^3.30.0",
42
42
  "zod": "^4.3.5",
43
- "@lumenflow/core": "1.3.2",
44
- "@lumenflow/memory": "1.3.2"
43
+ "@lumenflow/memory": "1.3.4",
44
+ "@lumenflow/core": "1.3.4"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@vitest/coverage-v8": "^4.0.17",