@lumenflow/agent 1.0.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/LICENSE +190 -0
- package/README.md +192 -0
- package/dist/agent-incidents.d.ts +55 -0
- package/dist/agent-incidents.js +91 -0
- package/dist/agent-session.d.ts +66 -0
- package/dist/agent-session.js +155 -0
- package/dist/agent-verification.d.ts +31 -0
- package/dist/agent-verification.js +118 -0
- package/dist/auto-session-integration.d.ts +106 -0
- package/dist/auto-session-integration.js +173 -0
- package/dist/feedback-promote-core.d.ts +137 -0
- package/dist/feedback-promote-core.js +337 -0
- package/dist/feedback-review-core.d.ts +116 -0
- package/dist/feedback-review-core.js +358 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 HellmAI
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# @lumenflow/agent
|
|
2
|
+
|
|
3
|
+
Agent session management and verification for LumenFlow workflow framework.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @lumenflow/agent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Overview
|
|
12
|
+
|
|
13
|
+
This package provides agent session management for AI agents working within the LumenFlow framework. It enables:
|
|
14
|
+
|
|
15
|
+
- **Session management**: Track agent sessions with WU context
|
|
16
|
+
- **Incident logging**: Record incidents with severity levels
|
|
17
|
+
- **WU verification**: Verify WU completion status
|
|
18
|
+
- **Feedback promotion**: Promote agent feedback to project guidelines
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
### Session Management
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { startSession, getCurrentSession, endSession, logIncident } from '@lumenflow/agent';
|
|
26
|
+
|
|
27
|
+
// Start a session (auto-detects lane from git branch)
|
|
28
|
+
const sessionId = await startSession('WU-123', 2, 'claude-code');
|
|
29
|
+
|
|
30
|
+
// Get current session
|
|
31
|
+
const session = await getCurrentSession();
|
|
32
|
+
console.log(session?.wu_id, session?.lane);
|
|
33
|
+
|
|
34
|
+
// Log an incident during the session
|
|
35
|
+
await logIncident({
|
|
36
|
+
category: 'validation',
|
|
37
|
+
severity: 'minor',
|
|
38
|
+
title: 'Schema validation warning',
|
|
39
|
+
description: 'Optional field missing from response',
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// End session and get summary
|
|
43
|
+
const summary = await endSession();
|
|
44
|
+
console.log(`Completed ${summary.wu_id} with ${summary.incidents_logged} incidents`);
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### WU Verification
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { verifyWUComplete, debugSummary } from '@lumenflow/agent';
|
|
51
|
+
|
|
52
|
+
// Verify a WU has been properly completed
|
|
53
|
+
const result = verifyWUComplete('WU-123');
|
|
54
|
+
|
|
55
|
+
if (result.complete) {
|
|
56
|
+
console.log('WU-123 is complete');
|
|
57
|
+
} else {
|
|
58
|
+
console.log(debugSummary(result));
|
|
59
|
+
// Verification failed:
|
|
60
|
+
// - Missing stamp .beacon/stamps/WU-123.done
|
|
61
|
+
// - No commit on main touching WU YAML
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Incident Tracking
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { appendIncident, readIncidents } from '@lumenflow/agent/incidents';
|
|
69
|
+
|
|
70
|
+
// Append an incident to the log
|
|
71
|
+
appendIncident({
|
|
72
|
+
timestamp: new Date().toISOString(),
|
|
73
|
+
session_id: 'uuid-here',
|
|
74
|
+
wu_id: 'WU-123',
|
|
75
|
+
lane: 'Operations',
|
|
76
|
+
category: 'gate_failure',
|
|
77
|
+
severity: 'major',
|
|
78
|
+
title: 'Typecheck failed',
|
|
79
|
+
description: 'Missing type export in index.ts',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// Read all incidents
|
|
83
|
+
const incidents = readIncidents();
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Feedback Promotion
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import { promoteFeedback } from '@lumenflow/agent/feedback-promote';
|
|
90
|
+
import { reviewFeedback } from '@lumenflow/agent/feedback-review';
|
|
91
|
+
|
|
92
|
+
// Review pending feedback items
|
|
93
|
+
const pending = await reviewFeedback();
|
|
94
|
+
for (const item of pending) {
|
|
95
|
+
console.log(`${item.id}: ${item.title}`);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Promote feedback to project guidelines
|
|
99
|
+
await promoteFeedback('feedback-001', {
|
|
100
|
+
target: 'CLAUDE.md',
|
|
101
|
+
section: 'Constraints',
|
|
102
|
+
});
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Subpath Exports
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Main entry (all exports)
|
|
109
|
+
import { startSession, verifyWUComplete } from '@lumenflow/agent';
|
|
110
|
+
|
|
111
|
+
// Specific modules
|
|
112
|
+
import { startSession, getCurrentSession, endSession, logIncident } from '@lumenflow/agent/session';
|
|
113
|
+
import { appendIncident, readIncidents } from '@lumenflow/agent/incidents';
|
|
114
|
+
import { verifyWUComplete, debugSummary } from '@lumenflow/agent/verification';
|
|
115
|
+
import { initAutoSession, getAutoSession } from '@lumenflow/agent/auto-session';
|
|
116
|
+
import { promoteFeedback } from '@lumenflow/agent/feedback-promote';
|
|
117
|
+
import { reviewFeedback } from '@lumenflow/agent/feedback-review';
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## API Reference
|
|
121
|
+
|
|
122
|
+
### Session Management
|
|
123
|
+
|
|
124
|
+
| Function | Description |
|
|
125
|
+
| -------------------------------------- | -------------------------------------- |
|
|
126
|
+
| `startSession(wuId, tier, agentType?)` | Start a new agent session |
|
|
127
|
+
| `getCurrentSession()` | Get the current active session |
|
|
128
|
+
| `endSession()` | End session and return summary |
|
|
129
|
+
| `logIncident(data)` | Log an incident to the current session |
|
|
130
|
+
|
|
131
|
+
### Verification
|
|
132
|
+
|
|
133
|
+
| Function | Description |
|
|
134
|
+
| ------------------------ | ------------------------------------------------ |
|
|
135
|
+
| `verifyWUComplete(wuId)` | Verify WU completion (stamp, commit, clean tree) |
|
|
136
|
+
| `debugSummary(result)` | Format verification result for display |
|
|
137
|
+
|
|
138
|
+
### Incidents
|
|
139
|
+
|
|
140
|
+
| Function | Description |
|
|
141
|
+
| -------------------------- | ----------------------------- |
|
|
142
|
+
| `appendIncident(incident)` | Append incident to NDJSON log |
|
|
143
|
+
| `readIncidents()` | Read all incidents from log |
|
|
144
|
+
|
|
145
|
+
### Types
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
interface SessionData {
|
|
149
|
+
session_id: string;
|
|
150
|
+
wu_id: string;
|
|
151
|
+
lane: string;
|
|
152
|
+
started: string;
|
|
153
|
+
completed?: string;
|
|
154
|
+
agent_type: string;
|
|
155
|
+
context_tier: number;
|
|
156
|
+
incidents_logged: number;
|
|
157
|
+
incidents_major: number;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface VerificationResult {
|
|
161
|
+
complete: boolean;
|
|
162
|
+
failures: string[];
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
interface IncidentData {
|
|
166
|
+
timestamp: string;
|
|
167
|
+
session_id: string;
|
|
168
|
+
wu_id: string;
|
|
169
|
+
lane: string;
|
|
170
|
+
category: string;
|
|
171
|
+
severity: 'minor' | 'major' | 'blocker';
|
|
172
|
+
title: string;
|
|
173
|
+
description: string;
|
|
174
|
+
context?: Record<string, unknown>;
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Features
|
|
179
|
+
|
|
180
|
+
- **Session isolation**: One session per agent, prevents conflicts
|
|
181
|
+
- **Auto lane detection**: Parses lane from git branch name
|
|
182
|
+
- **Incident severity**: Track minor/major/blocker incidents
|
|
183
|
+
- **Completion verification**: Multi-check WU completion validation
|
|
184
|
+
- **Modern**: Node 22+, ESM-only, TypeScript
|
|
185
|
+
|
|
186
|
+
## Documentation
|
|
187
|
+
|
|
188
|
+
For complete documentation, see the [LumenFlow documentation](https://github.com/hellmai/os).
|
|
189
|
+
|
|
190
|
+
## License
|
|
191
|
+
|
|
192
|
+
Apache-2.0
|
|
@@ -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,91 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync } from 'fs';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { VALIDATION_LIMITS } from '@lumenflow/core/lib/wu-validation-constants.js';
|
|
5
|
+
import { BEACON_PATHS, FILE_EXTENSIONS, STRING_LITERALS, } from '@lumenflow/core/lib/wu-constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* Incident severity values as a const tuple for z.enum
|
|
8
|
+
*/
|
|
9
|
+
const SEVERITY_VALUES = ['blocker', 'major', 'minor', 'info'];
|
|
10
|
+
/**
|
|
11
|
+
* Incident categories values as a const tuple for z.enum
|
|
12
|
+
*/
|
|
13
|
+
const CATEGORY_VALUES = ['workflow', 'tooling', 'confusion', 'violation', 'error'];
|
|
14
|
+
/**
|
|
15
|
+
* IncidentLog schema for structured issue tracking
|
|
16
|
+
* Stored as NDJSON in .beacon/incidents/<category>.ndjson
|
|
17
|
+
*/
|
|
18
|
+
export const IncidentLogSchema = z.object({
|
|
19
|
+
timestamp: z.string().datetime(), // ISO 8601 with timezone
|
|
20
|
+
session_id: z.string().uuid(),
|
|
21
|
+
wu_id: z.string().regex(/^WU-\d+$/, 'Must match WU-XXX format'),
|
|
22
|
+
lane: z.string().min(1),
|
|
23
|
+
category: z.enum(CATEGORY_VALUES),
|
|
24
|
+
severity: z.enum(SEVERITY_VALUES),
|
|
25
|
+
title: z.string().min(VALIDATION_LIMITS.TITLE_MIN).max(VALIDATION_LIMITS.TITLE_MAX),
|
|
26
|
+
description: z
|
|
27
|
+
.string()
|
|
28
|
+
.min(VALIDATION_LIMITS.DESCRIPTION_MIN)
|
|
29
|
+
.max(VALIDATION_LIMITS.DESCRIPTION_MAX),
|
|
30
|
+
resolution: z.string().optional(),
|
|
31
|
+
tags: z.array(z.string()).default([]),
|
|
32
|
+
context: z
|
|
33
|
+
.object({
|
|
34
|
+
git_branch: z.string().optional(),
|
|
35
|
+
current_step: z.string().optional(),
|
|
36
|
+
related_files: z.array(z.string()).optional(),
|
|
37
|
+
})
|
|
38
|
+
.optional()
|
|
39
|
+
.default(() => ({})),
|
|
40
|
+
});
|
|
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 function appendIncident(incident, incidentsDir = BEACON_PATHS.INCIDENTS) {
|
|
48
|
+
// Validate against schema
|
|
49
|
+
const validated = IncidentLogSchema.parse(incident);
|
|
50
|
+
// Ensure incidents directory exists
|
|
51
|
+
if (!existsSync(incidentsDir)) {
|
|
52
|
+
mkdirSync(incidentsDir, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
// Append to category-specific file
|
|
55
|
+
const logFile = join(incidentsDir, `${validated.category}${FILE_EXTENSIONS.NDJSON}`);
|
|
56
|
+
appendFileSync(logFile, `${JSON.stringify(validated)}\n`, { encoding: 'utf-8' });
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Read and parse incidents from NDJSON files
|
|
60
|
+
* @param categories - Categories to read (default: all)
|
|
61
|
+
* @param since - Filter incidents after this date
|
|
62
|
+
* @param incidentsDir - Optional directory override (for testing)
|
|
63
|
+
* @returns Parsed and validated incidents
|
|
64
|
+
*/
|
|
65
|
+
export function readIncidents(categories = null, since = null, incidentsDir = BEACON_PATHS.INCIDENTS) {
|
|
66
|
+
if (!existsSync(incidentsDir))
|
|
67
|
+
return [];
|
|
68
|
+
const categoriesToRead = categories ?? CATEGORY_VALUES;
|
|
69
|
+
const incidents = [];
|
|
70
|
+
for (const category of categoriesToRead) {
|
|
71
|
+
const logFile = join(incidentsDir, `${category}${FILE_EXTENSIONS.NDJSON}`);
|
|
72
|
+
if (!existsSync(logFile))
|
|
73
|
+
continue;
|
|
74
|
+
const lines = readFileSync(logFile, { encoding: 'utf-8' })
|
|
75
|
+
.split(STRING_LITERALS.NEWLINE)
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
for (const line of lines) {
|
|
78
|
+
try {
|
|
79
|
+
const incident = IncidentLogSchema.parse(JSON.parse(line));
|
|
80
|
+
if (since && new Date(incident.timestamp) < since)
|
|
81
|
+
continue;
|
|
82
|
+
incidents.push(incident);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
86
|
+
console.warn(`Skipping malformed incident in ${logFile}: ${errorMessage}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return incidents.sort((a, b) => new Date(b.timestamp).getTime() - new Date(a.timestamp).getTime());
|
|
91
|
+
}
|
|
@@ -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 {};
|