@stackmemoryai/stackmemory 0.1.0 → 0.2.1
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/dist/scripts/initialize.js +15 -15
- package/dist/scripts/initialize.js.map +1 -1
- package/dist/scripts/status.js +21 -11
- package/dist/scripts/status.js.map +1 -1
- package/dist/src/beads/beads-task-store.d.ts +117 -0
- package/dist/src/beads/beads-task-store.d.ts.map +1 -0
- package/dist/src/beads/beads-task-store.js +318 -0
- package/dist/src/beads/beads-task-store.js.map +1 -0
- package/dist/src/beads/task-aware-context.d.ts +103 -0
- package/dist/src/beads/task-aware-context.d.ts.map +1 -0
- package/dist/src/beads/task-aware-context.js +395 -0
- package/dist/src/beads/task-aware-context.js.map +1 -0
- package/dist/src/beads-task-store.d.ts +117 -0
- package/dist/src/beads-task-store.d.ts.map +1 -0
- package/dist/src/beads-task-store.js +318 -0
- package/dist/src/beads-task-store.js.map +1 -0
- package/dist/src/cli/cli.d.ts +7 -0
- package/dist/src/cli/cli.d.ts.map +1 -0
- package/dist/src/cli/cli.js +471 -0
- package/dist/src/cli/cli.js.map +1 -0
- package/dist/src/core/error-handler.d.ts +46 -0
- package/dist/src/core/error-handler.d.ts.map +1 -0
- package/dist/src/core/error-handler.js +212 -0
- package/dist/src/core/error-handler.js.map +1 -0
- package/dist/src/core/frame-manager.d.ts +106 -0
- package/dist/src/core/frame-manager.d.ts.map +1 -0
- package/dist/src/core/frame-manager.js +387 -0
- package/dist/src/core/frame-manager.js.map +1 -0
- package/dist/src/core/logger.d.ts +24 -0
- package/dist/src/core/logger.d.ts.map +1 -0
- package/dist/src/core/logger.js +121 -0
- package/dist/src/core/logger.js.map +1 -0
- package/dist/src/core/logger.test.d.ts +2 -0
- package/dist/src/core/logger.test.d.ts.map +1 -0
- package/dist/src/core/logger.test.js +31 -0
- package/dist/src/core/logger.test.js.map +1 -0
- package/dist/src/index.d.ts +4 -4
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +4 -4
- package/dist/src/index.js.map +1 -1
- package/dist/src/integrations/linear-auth.d.ts +99 -0
- package/dist/src/integrations/linear-auth.d.ts.map +1 -0
- package/dist/src/integrations/linear-auth.js +319 -0
- package/dist/src/integrations/linear-auth.js.map +1 -0
- package/dist/src/integrations/linear-auto-sync.d.ts +77 -0
- package/dist/src/integrations/linear-auto-sync.d.ts.map +1 -0
- package/dist/src/integrations/linear-auto-sync.js +268 -0
- package/dist/src/integrations/linear-auto-sync.js.map +1 -0
- package/dist/src/integrations/linear-client.d.ts +86 -0
- package/dist/src/integrations/linear-client.d.ts.map +1 -0
- package/dist/src/integrations/linear-client.js +275 -0
- package/dist/src/integrations/linear-client.js.map +1 -0
- package/dist/src/integrations/linear-config.d.ts +51 -0
- package/dist/src/integrations/linear-config.d.ts.map +1 -0
- package/dist/src/integrations/linear-config.js +103 -0
- package/dist/src/integrations/linear-config.js.map +1 -0
- package/dist/src/integrations/linear-sync.d.ts +95 -0
- package/dist/src/integrations/linear-sync.d.ts.map +1 -0
- package/dist/src/integrations/linear-sync.js +340 -0
- package/dist/src/integrations/linear-sync.js.map +1 -0
- package/dist/src/mcp/mcp-server.d.ts +38 -0
- package/dist/src/mcp/mcp-server.d.ts.map +1 -0
- package/dist/src/mcp/mcp-server.js +812 -0
- package/dist/src/mcp/mcp-server.js.map +1 -0
- package/dist/src/pebbles/pebbles-task-store.d.ts +117 -0
- package/dist/src/pebbles/pebbles-task-store.d.ts.map +1 -0
- package/dist/src/pebbles/pebbles-task-store.js +335 -0
- package/dist/src/pebbles/pebbles-task-store.js.map +1 -0
- package/dist/src/pebbles/task-aware-context.d.ts +103 -0
- package/dist/src/pebbles/task-aware-context.d.ts.map +1 -0
- package/dist/src/pebbles/task-aware-context.js +412 -0
- package/dist/src/pebbles/task-aware-context.js.map +1 -0
- package/dist/src/task-aware-context.d.ts +103 -0
- package/dist/src/task-aware-context.d.ts.map +1 -0
- package/dist/src/task-aware-context.js +395 -0
- package/dist/src/task-aware-context.js.map +1 -0
- package/package.json +41 -9
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Comprehensive error handling for StackMemory CLI
|
|
3
|
+
*/
|
|
4
|
+
import { logger } from './logger.js';
|
|
5
|
+
export var ErrorCode;
|
|
6
|
+
(function (ErrorCode) {
|
|
7
|
+
// Authentication errors
|
|
8
|
+
ErrorCode["AUTH_FAILED"] = "AUTH_FAILED";
|
|
9
|
+
ErrorCode["TOKEN_EXPIRED"] = "TOKEN_EXPIRED";
|
|
10
|
+
ErrorCode["INVALID_CREDENTIALS"] = "INVALID_CREDENTIALS";
|
|
11
|
+
// File system errors
|
|
12
|
+
ErrorCode["FILE_NOT_FOUND"] = "FILE_NOT_FOUND";
|
|
13
|
+
ErrorCode["PERMISSION_DENIED"] = "PERMISSION_DENIED";
|
|
14
|
+
ErrorCode["DISK_FULL"] = "DISK_FULL";
|
|
15
|
+
// Git operation errors
|
|
16
|
+
ErrorCode["NOT_GIT_REPO"] = "NOT_GIT_REPO";
|
|
17
|
+
ErrorCode["GIT_COMMAND_FAILED"] = "GIT_COMMAND_FAILED";
|
|
18
|
+
ErrorCode["INVALID_BRANCH"] = "INVALID_BRANCH";
|
|
19
|
+
// Database errors
|
|
20
|
+
ErrorCode["DB_CONNECTION_FAILED"] = "DB_CONNECTION_FAILED";
|
|
21
|
+
ErrorCode["DB_QUERY_FAILED"] = "DB_QUERY_FAILED";
|
|
22
|
+
ErrorCode["DB_CORRUPTION"] = "DB_CORRUPTION";
|
|
23
|
+
// Network errors
|
|
24
|
+
ErrorCode["NETWORK_ERROR"] = "NETWORK_ERROR";
|
|
25
|
+
ErrorCode["API_ERROR"] = "API_ERROR";
|
|
26
|
+
ErrorCode["TIMEOUT"] = "TIMEOUT";
|
|
27
|
+
// Validation errors
|
|
28
|
+
ErrorCode["INVALID_INPUT"] = "INVALID_INPUT";
|
|
29
|
+
ErrorCode["VALIDATION_FAILED"] = "VALIDATION_FAILED";
|
|
30
|
+
// General errors
|
|
31
|
+
ErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
32
|
+
ErrorCode["OPERATION_FAILED"] = "OPERATION_FAILED";
|
|
33
|
+
ErrorCode["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
|
|
34
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
35
|
+
export class StackMemoryError extends Error {
|
|
36
|
+
code;
|
|
37
|
+
context;
|
|
38
|
+
userMessage;
|
|
39
|
+
recoverable;
|
|
40
|
+
constructor(code, message, userMessage, context = {}, recoverable = false, cause) {
|
|
41
|
+
super(message);
|
|
42
|
+
this.name = 'StackMemoryError';
|
|
43
|
+
this.code = code;
|
|
44
|
+
this.context = context;
|
|
45
|
+
this.userMessage = userMessage || this.getDefaultUserMessage(code);
|
|
46
|
+
this.recoverable = recoverable;
|
|
47
|
+
if (cause && Error.captureStackTrace) {
|
|
48
|
+
Error.captureStackTrace(this, StackMemoryError);
|
|
49
|
+
}
|
|
50
|
+
// Log the error
|
|
51
|
+
logger.error(message, cause, {
|
|
52
|
+
code,
|
|
53
|
+
context,
|
|
54
|
+
recoverable,
|
|
55
|
+
userMessage: this.userMessage,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
getDefaultUserMessage(code) {
|
|
59
|
+
switch (code) {
|
|
60
|
+
case ErrorCode.AUTH_FAILED:
|
|
61
|
+
return 'Authentication failed. Please check your credentials and try again.';
|
|
62
|
+
case ErrorCode.NOT_GIT_REPO:
|
|
63
|
+
return 'This command requires a git repository. Please run it from within a git repository.';
|
|
64
|
+
case ErrorCode.PERMISSION_DENIED:
|
|
65
|
+
return 'Permission denied. Please check file permissions or run with appropriate privileges.';
|
|
66
|
+
case ErrorCode.NETWORK_ERROR:
|
|
67
|
+
return 'Network error. Please check your internet connection and try again.';
|
|
68
|
+
case ErrorCode.INVALID_INPUT:
|
|
69
|
+
return 'Invalid input provided. Please check your command and try again.';
|
|
70
|
+
case ErrorCode.DB_CONNECTION_FAILED:
|
|
71
|
+
return 'Database connection failed. Please try again or contact support if the issue persists.';
|
|
72
|
+
case ErrorCode.GIT_COMMAND_FAILED:
|
|
73
|
+
return 'Git operation failed. Please ensure your repository is in a valid state.';
|
|
74
|
+
default:
|
|
75
|
+
return 'An unexpected error occurred. Please try again or contact support.';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
static fromNodeError(nodeError, context = {}) {
|
|
79
|
+
const code = nodeError.code;
|
|
80
|
+
switch (code) {
|
|
81
|
+
case 'ENOENT':
|
|
82
|
+
return new StackMemoryError(ErrorCode.FILE_NOT_FOUND, `File or directory not found: ${nodeError.path}`, 'The requested file or directory was not found.', { ...context, path: nodeError.path }, false, nodeError);
|
|
83
|
+
case 'EACCES':
|
|
84
|
+
case 'EPERM':
|
|
85
|
+
return new StackMemoryError(ErrorCode.PERMISSION_DENIED, `Permission denied: ${nodeError.path}`, 'Permission denied. Please check file permissions.', { ...context, path: nodeError.path }, true, nodeError);
|
|
86
|
+
case 'ENOSPC':
|
|
87
|
+
return new StackMemoryError(ErrorCode.DISK_FULL, 'No space left on device', 'Insufficient disk space. Please free up space and try again.', context, true, nodeError);
|
|
88
|
+
case 'ETIMEDOUT':
|
|
89
|
+
return new StackMemoryError(ErrorCode.TIMEOUT, 'Operation timed out', 'The operation timed out. Please try again.', context, true, nodeError);
|
|
90
|
+
default:
|
|
91
|
+
return new StackMemoryError(ErrorCode.UNKNOWN_ERROR, nodeError.message, 'An unexpected system error occurred.', { ...context, nodeErrorCode: code }, false, nodeError);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
export class ErrorHandler {
|
|
96
|
+
static retryMap = new Map();
|
|
97
|
+
static MAX_RETRIES = 3;
|
|
98
|
+
static handle(error, operation) {
|
|
99
|
+
if (error instanceof StackMemoryError) {
|
|
100
|
+
// Already a well-formed StackMemory error
|
|
101
|
+
console.error(`❌ ${error.userMessage}`);
|
|
102
|
+
if (error.recoverable) {
|
|
103
|
+
console.error('💡 This error may be recoverable. Please try again.');
|
|
104
|
+
}
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
if (error instanceof Error) {
|
|
108
|
+
// Convert Node.js error to StackMemoryError
|
|
109
|
+
let stackMemoryError;
|
|
110
|
+
if ('code' in error && typeof error.code === 'string') {
|
|
111
|
+
stackMemoryError = StackMemoryError.fromNodeError(error, { operation });
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
stackMemoryError = new StackMemoryError(ErrorCode.OPERATION_FAILED, `Operation '${operation}' failed: ${error.message}`, `Operation failed: ${error.message}`, { operation }, false, error);
|
|
115
|
+
}
|
|
116
|
+
console.error(`❌ ${stackMemoryError.userMessage}`);
|
|
117
|
+
if (stackMemoryError.recoverable) {
|
|
118
|
+
console.error('💡 This error may be recoverable. Please try again.');
|
|
119
|
+
}
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
// Unknown error type
|
|
123
|
+
const unknownError = new StackMemoryError(ErrorCode.UNKNOWN_ERROR, `Unknown error in operation '${operation}': ${String(error)}`, 'An unexpected error occurred.', { operation, errorType: typeof error }, false);
|
|
124
|
+
console.error(`❌ ${unknownError.userMessage}`);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
static async safeExecute(operation, operationName, fallback) {
|
|
128
|
+
try {
|
|
129
|
+
return await operation();
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (fallback !== undefined) {
|
|
133
|
+
logger.warn(`Operation '${operationName}' failed, using fallback`, {
|
|
134
|
+
error: String(error),
|
|
135
|
+
});
|
|
136
|
+
return fallback;
|
|
137
|
+
}
|
|
138
|
+
ErrorHandler.handle(error, operationName);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
static async withRetry(operation, operationName, maxRetries = ErrorHandler.MAX_RETRIES) {
|
|
142
|
+
let lastError;
|
|
143
|
+
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
144
|
+
try {
|
|
145
|
+
const result = await operation();
|
|
146
|
+
// Clear retry count on success
|
|
147
|
+
ErrorHandler.retryMap.delete(operationName);
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
lastError = error;
|
|
152
|
+
if (error instanceof StackMemoryError && !error.recoverable) {
|
|
153
|
+
// Don't retry non-recoverable errors
|
|
154
|
+
ErrorHandler.handle(error, operationName);
|
|
155
|
+
}
|
|
156
|
+
if (attempt === maxRetries) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
const delay = Math.min(1000 * Math.pow(2, attempt - 1), 5000); // Exponential backoff
|
|
160
|
+
logger.warn(`Attempt ${attempt}/${maxRetries} failed for '${operationName}', retrying in ${delay}ms`, {
|
|
161
|
+
error: String(error),
|
|
162
|
+
});
|
|
163
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
ErrorHandler.handle(lastError, `${operationName} (after ${maxRetries} attempts)`);
|
|
167
|
+
}
|
|
168
|
+
static createCircuitBreaker(operation, operationName, threshold = 5) {
|
|
169
|
+
let failures = 0;
|
|
170
|
+
let lastFailure = 0;
|
|
171
|
+
const resetTimeout = 30000; // 30 seconds
|
|
172
|
+
return async () => {
|
|
173
|
+
const now = Date.now();
|
|
174
|
+
// Reset circuit breaker after timeout
|
|
175
|
+
if (now - lastFailure > resetTimeout) {
|
|
176
|
+
failures = 0;
|
|
177
|
+
}
|
|
178
|
+
// Circuit is open (too many failures)
|
|
179
|
+
if (failures >= threshold) {
|
|
180
|
+
throw new StackMemoryError(ErrorCode.OPERATION_FAILED, `Circuit breaker open for '${operationName}'`, `Operation temporarily unavailable. Please try again later.`, { operationName, failures, threshold }, true);
|
|
181
|
+
}
|
|
182
|
+
try {
|
|
183
|
+
const result = await operation();
|
|
184
|
+
failures = 0; // Reset on success
|
|
185
|
+
return result;
|
|
186
|
+
}
|
|
187
|
+
catch (error) {
|
|
188
|
+
failures++;
|
|
189
|
+
lastFailure = now;
|
|
190
|
+
throw error;
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
// Utility functions for common error scenarios
|
|
196
|
+
export const validateInput = (value, name, validator) => {
|
|
197
|
+
if (!validator(value)) {
|
|
198
|
+
throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid ${name}: ${String(value)}`, `Please provide a valid ${name}.`, { name, value }, true);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
export const validateEmail = (email) => {
|
|
202
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
203
|
+
if (!emailRegex.test(email) || email.length > 254) {
|
|
204
|
+
throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid email format: ${email}`, 'Please provide a valid email address.', { email }, true);
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
export const validatePath = (filePath) => {
|
|
208
|
+
if (!filePath || filePath.includes('..') || filePath.includes('\0')) {
|
|
209
|
+
throw new StackMemoryError(ErrorCode.INVALID_INPUT, `Invalid path: ${filePath}`, 'Invalid file path provided.', { path: filePath }, true);
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=error-handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-handler.js","sourceRoot":"","sources":["../../../src/core/error-handler.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,MAAM,CAAN,IAAY,SAkCX;AAlCD,WAAY,SAAS;IACnB,wBAAwB;IACxB,wCAA2B,CAAA;IAC3B,4CAA+B,CAAA;IAC/B,wDAA2C,CAAA;IAE3C,qBAAqB;IACrB,8CAAiC,CAAA;IACjC,oDAAuC,CAAA;IACvC,oCAAuB,CAAA;IAEvB,uBAAuB;IACvB,0CAA6B,CAAA;IAC7B,sDAAyC,CAAA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,CAAC,MAAM,aAAa,GAAG,CAAC,KAAa,EAA2B,EAAE;IACtE,MAAM,UAAU,GAAG,4BAA4B,CAAC;IAChD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAClD,MAAM,IAAI,gBAAgB,CACxB,SAAS,CAAC,aAAa,EACvB,yBAAyB,KAAK,EAAE,EAChC,uCAAuC,EACvC,EAAE,KAAK,EAAE,EACT,IAAI,CACL,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,QAAgB,EAA8B,EAAE;IAC3E,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,QAAQ,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,gBAAgB,CACxB,SAAS,CAAC,aAAa,EACvB,iBAAiB,QAAQ,EAAE,EAC3B,6BAA6B,EAC7B,EAAE,IAAI,EAAE,QAAQ,EAAE,EAClB,IAAI,CACL,CAAC;IACJ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StackMemory Frame Manager - Call Stack Implementation
|
|
3
|
+
* Manages nested frames representing the call stack of work
|
|
4
|
+
*/
|
|
5
|
+
import Database from 'better-sqlite3';
|
|
6
|
+
export type FrameType = 'task' | 'subtask' | 'tool_scope' | 'review' | 'write' | 'debug';
|
|
7
|
+
export type FrameState = 'active' | 'closed';
|
|
8
|
+
export interface Frame {
|
|
9
|
+
frame_id: string;
|
|
10
|
+
run_id: string;
|
|
11
|
+
project_id: string;
|
|
12
|
+
parent_frame_id?: string;
|
|
13
|
+
depth: number;
|
|
14
|
+
type: FrameType;
|
|
15
|
+
name: string;
|
|
16
|
+
state: FrameState;
|
|
17
|
+
inputs: Record<string, any>;
|
|
18
|
+
outputs: Record<string, any>;
|
|
19
|
+
digest_text?: string;
|
|
20
|
+
digest_json: Record<string, any>;
|
|
21
|
+
created_at: number;
|
|
22
|
+
closed_at?: number;
|
|
23
|
+
}
|
|
24
|
+
export interface FrameContext {
|
|
25
|
+
frameId: string;
|
|
26
|
+
header: {
|
|
27
|
+
goal: string;
|
|
28
|
+
constraints?: string[];
|
|
29
|
+
definitions?: Record<string, string>;
|
|
30
|
+
};
|
|
31
|
+
anchors: Anchor[];
|
|
32
|
+
recentEvents: Event[];
|
|
33
|
+
activeArtifacts: string[];
|
|
34
|
+
}
|
|
35
|
+
export interface Anchor {
|
|
36
|
+
anchor_id: string;
|
|
37
|
+
frame_id: string;
|
|
38
|
+
type: 'FACT' | 'DECISION' | 'CONSTRAINT' | 'INTERFACE_CONTRACT' | 'TODO' | 'RISK';
|
|
39
|
+
text: string;
|
|
40
|
+
priority: number;
|
|
41
|
+
metadata: Record<string, any>;
|
|
42
|
+
}
|
|
43
|
+
export interface Event {
|
|
44
|
+
event_id: string;
|
|
45
|
+
frame_id: string;
|
|
46
|
+
run_id: string;
|
|
47
|
+
seq: number;
|
|
48
|
+
event_type: 'user_message' | 'assistant_message' | 'tool_call' | 'tool_result' | 'decision' | 'constraint' | 'artifact' | 'observation';
|
|
49
|
+
payload: Record<string, any>;
|
|
50
|
+
ts: number;
|
|
51
|
+
}
|
|
52
|
+
export declare class FrameManager {
|
|
53
|
+
private db;
|
|
54
|
+
private currentRunId;
|
|
55
|
+
private projectId;
|
|
56
|
+
private activeStack;
|
|
57
|
+
constructor(db: Database.Database, projectId: string, runId?: string);
|
|
58
|
+
private initializeSchema;
|
|
59
|
+
private loadActiveStack;
|
|
60
|
+
private buildStackOrder;
|
|
61
|
+
/**
|
|
62
|
+
* Create a new frame and push to stack
|
|
63
|
+
*/
|
|
64
|
+
createFrame(options: {
|
|
65
|
+
type: FrameType;
|
|
66
|
+
name: string;
|
|
67
|
+
inputs?: Record<string, any>;
|
|
68
|
+
parentFrameId?: string;
|
|
69
|
+
}): string;
|
|
70
|
+
/**
|
|
71
|
+
* Close the current frame and generate digest
|
|
72
|
+
*/
|
|
73
|
+
closeFrame(frameId?: string, outputs?: Record<string, any>): void;
|
|
74
|
+
private closeChildFrames;
|
|
75
|
+
/**
|
|
76
|
+
* Generate digest for a frame
|
|
77
|
+
*/
|
|
78
|
+
private generateDigest;
|
|
79
|
+
private generateDigestText;
|
|
80
|
+
/**
|
|
81
|
+
* Add event to current frame
|
|
82
|
+
*/
|
|
83
|
+
addEvent(eventType: Event['event_type'], payload: Record<string, any>, frameId?: string): string;
|
|
84
|
+
/**
|
|
85
|
+
* Add anchor to frame
|
|
86
|
+
*/
|
|
87
|
+
addAnchor(type: Anchor['type'], text: string, priority?: number, metadata?: Record<string, any>, frameId?: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Get hot stack context for current active frames
|
|
90
|
+
*/
|
|
91
|
+
getHotStackContext(maxEvents?: number): FrameContext[];
|
|
92
|
+
/**
|
|
93
|
+
* Get active frame path (root to current)
|
|
94
|
+
*/
|
|
95
|
+
getActiveFramePath(): Frame[];
|
|
96
|
+
getCurrentFrameId(): string | undefined;
|
|
97
|
+
getStackDepth(): number;
|
|
98
|
+
private getFrameDepth;
|
|
99
|
+
getFrame(frameId: string): Frame | undefined;
|
|
100
|
+
getFrameEvents(frameId: string, limit?: number): Event[];
|
|
101
|
+
private getFrameAnchors;
|
|
102
|
+
private getNextEventSequence;
|
|
103
|
+
private extractConstraints;
|
|
104
|
+
private getActiveArtifacts;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=frame-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"frame-manager.d.ts","sourceRoot":"","sources":["../../../src/core/frame-manager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAMtC,MAAM,MAAM,SAAS,GACjB,MAAM,GACN,SAAS,GACT,YAAY,GACZ,QAAQ,GACR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