@braingrid/cli 0.0.9 → 0.1.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/CHANGELOG.md +53 -0
- package/README.md +27 -19
- package/dist/build-config.d.ts +4 -8
- package/dist/build-config.d.ts.map +1 -1
- package/dist/build-config.js +21 -8
- package/dist/build-config.js.map +1 -1
- package/dist/cli.js +318 -276
- package/dist/cli.js.map +1 -1
- package/dist/handlers/agent.handlers.d.ts +12 -0
- package/dist/handlers/agent.handlers.d.ts.map +1 -0
- package/dist/handlers/agent.handlers.js +130 -0
- package/dist/handlers/agent.handlers.js.map +1 -0
- package/dist/handlers/auth.handlers.d.ts +7 -1
- package/dist/handlers/auth.handlers.d.ts.map +1 -1
- package/dist/handlers/auth.handlers.js +80 -21
- package/dist/handlers/auth.handlers.js.map +1 -1
- package/dist/handlers/index.d.ts +1 -0
- package/dist/handlers/index.d.ts.map +1 -1
- package/dist/handlers/index.js +1 -0
- package/dist/handlers/index.js.map +1 -1
- package/dist/handlers/init.handlers.js +4 -4
- package/dist/handlers/init.handlers.js.map +1 -1
- package/dist/handlers/project.handlers.d.ts +2 -3
- package/dist/handlers/project.handlers.d.ts.map +1 -1
- package/dist/handlers/project.handlers.js +81 -71
- package/dist/handlers/project.handlers.js.map +1 -1
- package/dist/handlers/requirement.handlers.d.ts.map +1 -1
- package/dist/handlers/requirement.handlers.js +21 -20
- package/dist/handlers/requirement.handlers.js.map +1 -1
- package/dist/handlers/status.handlers.d.ts.map +1 -1
- package/dist/handlers/status.handlers.js +5 -2
- package/dist/handlers/status.handlers.js.map +1 -1
- package/dist/handlers/task.handlers.d.ts.map +1 -1
- package/dist/handlers/task.handlers.js +45 -26
- package/dist/handlers/task.handlers.js.map +1 -1
- package/dist/rpc/registry.d.ts +97 -0
- package/dist/rpc/registry.d.ts.map +1 -0
- package/dist/rpc/registry.js +119 -0
- package/dist/rpc/registry.js.map +1 -0
- package/dist/rpc/server.d.ts +78 -0
- package/dist/rpc/server.d.ts.map +1 -0
- package/dist/rpc/server.js +437 -0
- package/dist/rpc/server.js.map +1 -0
- package/dist/rpc/transport.d.ts +84 -0
- package/dist/rpc/transport.d.ts.map +1 -0
- package/dist/rpc/transport.js +296 -0
- package/dist/rpc/transport.js.map +1 -0
- package/dist/services/__mocks__/utils.d.ts +16 -0
- package/dist/services/__mocks__/utils.d.ts.map +1 -0
- package/dist/services/__mocks__/utils.js +21 -0
- package/dist/services/__mocks__/utils.js.map +1 -0
- package/dist/services/agent-service.d.ts +29 -0
- package/dist/services/agent-service.d.ts.map +1 -0
- package/dist/services/agent-service.js +273 -0
- package/dist/services/agent-service.js.map +1 -0
- package/dist/services/auth.d.ts +18 -0
- package/dist/services/auth.d.ts.map +1 -1
- package/dist/services/auth.js +92 -42
- package/dist/services/auth.js.map +1 -1
- package/dist/services/credential-store.d.ts.map +1 -1
- package/dist/services/credential-store.js +1 -0
- package/dist/services/credential-store.js.map +1 -1
- package/dist/services/internal/github-service.d.ts +67 -0
- package/dist/services/internal/github-service.d.ts.map +1 -0
- package/dist/services/internal/github-service.js +81 -0
- package/dist/services/internal/github-service.js.map +1 -0
- package/dist/services/internal/repository-service.d.ts +79 -0
- package/dist/services/internal/repository-service.d.ts.map +1 -0
- package/dist/services/internal/repository-service.js +88 -0
- package/dist/services/internal/repository-service.js.map +1 -0
- package/dist/services/oauth2-auth.d.ts +16 -0
- package/dist/services/oauth2-auth.d.ts.map +1 -1
- package/dist/services/oauth2-auth.js +74 -0
- package/dist/services/oauth2-auth.js.map +1 -1
- package/dist/types/github.d.ts +105 -0
- package/dist/types/github.d.ts.map +1 -0
- package/dist/types/github.js +6 -0
- package/dist/types/github.js.map +1 -0
- package/dist/utils/cli-tools.d.ts.map +1 -1
- package/dist/utils/cli-tools.js +0 -1
- package/dist/utils/cli-tools.js.map +1 -1
- package/dist/utils/git.d.ts +5 -0
- package/dist/utils/git.d.ts.map +1 -1
- package/dist/utils/git.js +13 -0
- package/dist/utils/git.js.map +1 -1
- package/dist/utils/id-normalization.d.ts +26 -0
- package/dist/utils/id-normalization.d.ts.map +1 -0
- package/dist/utils/id-normalization.js +45 -0
- package/dist/utils/id-normalization.js.map +1 -0
- package/dist/utils/local-store.d.ts +7 -7
- package/dist/utils/local-store.d.ts.map +1 -1
- package/dist/utils/local-store.js +29 -17
- package/dist/utils/local-store.js.map +1 -1
- package/dist/utils/projects.d.ts +23 -0
- package/dist/utils/projects.d.ts.map +1 -0
- package/dist/utils/projects.js +36 -0
- package/dist/utils/projects.js.map +1 -0
- package/dist/utils/requirements.d.ts +15 -0
- package/dist/utils/requirements.d.ts.map +1 -1
- package/dist/utils/requirements.js +32 -7
- package/dist/utils/requirements.js.map +1 -1
- package/dist/utils/tasks.d.ts +12 -0
- package/dist/utils/tasks.d.ts.map +1 -1
- package/dist/utils/tasks.js +31 -6
- package/dist/utils/tasks.js.map +1 -1
- package/dist/utils/workspace-manager.d.ts +65 -0
- package/dist/utils/workspace-manager.d.ts.map +1 -0
- package/dist/utils/workspace-manager.js +98 -0
- package/dist/utils/workspace-manager.js.map +1 -0
- package/package.json +14 -29
- package/dist/.build-info.json +0 -9
- package/dist/services/context-manager.d.ts +0 -170
- package/dist/services/context-manager.d.ts.map +0 -1
- package/dist/services/context-manager.js +0 -261
- package/dist/services/context-manager.js.map +0 -1
- package/dist/test/setup.d.ts +0 -2
- package/dist/test/setup.d.ts.map +0 -1
- package/dist/test/setup.js +0 -40
- package/dist/test/setup.js.map +0 -1
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { RequirementService } from './requirement-service.js';
|
|
2
|
-
import { Requirement } from '../types/requirement.js';
|
|
3
|
-
/**
|
|
4
|
-
* Represents the active requirement context in the current session
|
|
5
|
-
*/
|
|
6
|
-
export interface RequirementContext {
|
|
7
|
-
/**
|
|
8
|
-
* The full requirement ID (e.g., "req_abc123")
|
|
9
|
-
*/
|
|
10
|
-
requirementId: string;
|
|
11
|
-
/**
|
|
12
|
-
* The formatted requirement ID for display (e.g., "REQ-123")
|
|
13
|
-
*/
|
|
14
|
-
formattedId: string;
|
|
15
|
-
/**
|
|
16
|
-
* The requirement name/title
|
|
17
|
-
*/
|
|
18
|
-
name: string;
|
|
19
|
-
/**
|
|
20
|
-
* Timestamp of last validation
|
|
21
|
-
*/
|
|
22
|
-
lastValidated: Date;
|
|
23
|
-
/**
|
|
24
|
-
* The full requirement object (optional, for caching)
|
|
25
|
-
*/
|
|
26
|
-
requirement?: Requirement;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Event types for context changes
|
|
30
|
-
*/
|
|
31
|
-
export type ContextEventType = 'set' | 'cleared' | 'invalidated' | 'validated';
|
|
32
|
-
/**
|
|
33
|
-
* Context change event data
|
|
34
|
-
*/
|
|
35
|
-
export interface ContextChangeEvent {
|
|
36
|
-
type: ContextEventType;
|
|
37
|
-
context: RequirementContext | null;
|
|
38
|
-
previousContext: RequirementContext | null;
|
|
39
|
-
reason?: string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Callback function for context change events
|
|
43
|
-
*/
|
|
44
|
-
export type ContextChangeCallback = (event: ContextChangeEvent) => void;
|
|
45
|
-
/**
|
|
46
|
-
* Options for context validation
|
|
47
|
-
*/
|
|
48
|
-
export interface ValidationOptions {
|
|
49
|
-
/**
|
|
50
|
-
* Whether to emit events for validation results
|
|
51
|
-
*/
|
|
52
|
-
emitEvents?: boolean;
|
|
53
|
-
/**
|
|
54
|
-
* Whether to clear context on validation failure
|
|
55
|
-
*/
|
|
56
|
-
clearOnFailure?: boolean;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Manages the active requirement context for the current session
|
|
60
|
-
* Context is session-scoped and resets when the CLI restarts
|
|
61
|
-
*/
|
|
62
|
-
export declare class ContextManager {
|
|
63
|
-
private activeContext;
|
|
64
|
-
private changeCallbacks;
|
|
65
|
-
/**
|
|
66
|
-
* Creates a new ContextManager instance
|
|
67
|
-
*/
|
|
68
|
-
constructor();
|
|
69
|
-
/**
|
|
70
|
-
* Sets the active requirement context
|
|
71
|
-
*
|
|
72
|
-
* @param requirementId - The requirement ID to set as context
|
|
73
|
-
* @param requirement - Optional requirement object to cache
|
|
74
|
-
* @returns The new context or null if setting failed
|
|
75
|
-
*/
|
|
76
|
-
setContext(requirementId: string, requirement?: Requirement): Promise<RequirementContext | null>;
|
|
77
|
-
/**
|
|
78
|
-
* Gets the current active context
|
|
79
|
-
*
|
|
80
|
-
* @returns The active context or null if none set
|
|
81
|
-
*/
|
|
82
|
-
getContext(): RequirementContext | null;
|
|
83
|
-
/**
|
|
84
|
-
* Clears the active context
|
|
85
|
-
*
|
|
86
|
-
* @param reason - Optional reason for clearing context
|
|
87
|
-
*/
|
|
88
|
-
clearContext(reason?: string): void;
|
|
89
|
-
/**
|
|
90
|
-
* Validates the current context is still valid
|
|
91
|
-
*
|
|
92
|
-
* @param requirementService - The requirement service to use for validation
|
|
93
|
-
* @param options - Validation options
|
|
94
|
-
* @returns true if context is valid, false otherwise
|
|
95
|
-
*/
|
|
96
|
-
validateContext(requirementService: RequirementService, options?: ValidationOptions): Promise<boolean>;
|
|
97
|
-
/**
|
|
98
|
-
* Validates and refreshes the current context
|
|
99
|
-
* Fetches fresh requirement data and updates the context
|
|
100
|
-
*
|
|
101
|
-
* @param requirementService - The requirement service to use
|
|
102
|
-
* @returns The refreshed context or null if validation failed
|
|
103
|
-
*/
|
|
104
|
-
validateAndRefreshContext(requirementService: RequirementService): Promise<RequirementContext | null>;
|
|
105
|
-
/**
|
|
106
|
-
* Formats the command prompt based on current context
|
|
107
|
-
*
|
|
108
|
-
* @returns Formatted prompt string
|
|
109
|
-
*/
|
|
110
|
-
formatPrompt(): string;
|
|
111
|
-
/**
|
|
112
|
-
* Registers a callback for context change events
|
|
113
|
-
*
|
|
114
|
-
* @param callback - The callback to register
|
|
115
|
-
* @returns Function to unregister the callback
|
|
116
|
-
*/
|
|
117
|
-
onContextChange(callback: ContextChangeCallback): () => void;
|
|
118
|
-
/**
|
|
119
|
-
* Checks if there is an active context
|
|
120
|
-
*
|
|
121
|
-
* @returns true if context is set, false otherwise
|
|
122
|
-
*/
|
|
123
|
-
hasContext(): boolean;
|
|
124
|
-
/**
|
|
125
|
-
* Gets the active requirement ID if context is set
|
|
126
|
-
*
|
|
127
|
-
* @returns The requirement ID or null
|
|
128
|
-
*/
|
|
129
|
-
getActiveRequirementId(): string | null;
|
|
130
|
-
/**
|
|
131
|
-
* Gets the formatted requirement ID if context is set
|
|
132
|
-
*
|
|
133
|
-
* @returns The formatted ID (e.g., "REQ-123") or null
|
|
134
|
-
*/
|
|
135
|
-
getFormattedId(): string | null;
|
|
136
|
-
/**
|
|
137
|
-
* Invalidates the current context with a reason
|
|
138
|
-
*
|
|
139
|
-
* @param reason - The reason for invalidation
|
|
140
|
-
*/
|
|
141
|
-
private invalidateContext;
|
|
142
|
-
/**
|
|
143
|
-
* Emits a context change event to all registered callbacks
|
|
144
|
-
*
|
|
145
|
-
* @param event - The event to emit
|
|
146
|
-
*/
|
|
147
|
-
private emitChange;
|
|
148
|
-
/**
|
|
149
|
-
* Formats a requirement ID for display
|
|
150
|
-
* Converts "req_abc123" to "REQ-123" format
|
|
151
|
-
*
|
|
152
|
-
* @param requirementId - The requirement ID to format
|
|
153
|
-
* @returns Formatted ID
|
|
154
|
-
*/
|
|
155
|
-
private formatRequirementId;
|
|
156
|
-
/**
|
|
157
|
-
* Gets a summary of the current context state
|
|
158
|
-
*
|
|
159
|
-
* @returns Context summary object
|
|
160
|
-
*/
|
|
161
|
-
getContextSummary(): {
|
|
162
|
-
hasContext: boolean;
|
|
163
|
-
requirementId: string | null;
|
|
164
|
-
formattedId: string | null;
|
|
165
|
-
name: string | null;
|
|
166
|
-
lastValidated: Date | null;
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
export declare const contextManager: ContextManager;
|
|
170
|
-
//# sourceMappingURL=context-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-manager.d.ts","sourceRoot":"","sources":["../../src/services/context-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,aAAa,EAAE,IAAI,CAAC;IAEpB;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,GAAG,SAAS,GAAG,aAAa,GAAG,WAAW,CAAC;AAE/E;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAClC,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,kBAAkB,GAAG,IAAI,CAAC;IACnC,eAAe,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;AAExE;;GAEG;AACH,MAAM,WAAW,iBAAiB;IACjC;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CACzB;AAED;;;GAGG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,eAAe,CAAyC;IAEhE;;OAEG;;IAMH;;;;;;OAMG;IACG,UAAU,CACf,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,WAAW,GACvB,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IA2BrC;;;;OAIG;IACH,UAAU,IAAI,kBAAkB,GAAG,IAAI;IAIvC;;;;OAIG;IACH,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI;IAanC;;;;;;OAMG;IACG,eAAe,CACpB,kBAAkB,EAAE,kBAAkB,EACtC,OAAO,GAAE,iBAAsB,GAC7B,OAAO,CAAC,OAAO,CAAC;IA0CnB;;;;;;OAMG;IACG,yBAAyB,CAC9B,kBAAkB,EAAE,kBAAkB,GACpC,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC;IAmCrC;;;;OAIG;IACH,YAAY,IAAI,MAAM;IAOtB;;;;;OAKG;IACH,eAAe,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM,IAAI;IAS5D;;;;OAIG;IACH,UAAU,IAAI,OAAO;IAIrB;;;;OAIG;IACH,sBAAsB,IAAI,MAAM,GAAG,IAAI;IAIvC;;;;OAIG;IACH,cAAc,IAAI,MAAM,GAAG,IAAI;IAI/B;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAazB;;;;OAIG;IACH,OAAO,CAAC,UAAU;IAWlB;;;;;;OAMG;IACH,OAAO,CAAC,mBAAmB;IAY3B;;;;OAIG;IACH,iBAAiB,IAAI;QACpB,UAAU,EAAE,OAAO,CAAC;QACpB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;QAC3B,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;QACpB,aAAa,EAAE,IAAI,GAAG,IAAI,CAAC;KAC3B;CASD;AAGD,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages the active requirement context for the current session
|
|
3
|
-
* Context is session-scoped and resets when the CLI restarts
|
|
4
|
-
*/
|
|
5
|
-
export class ContextManager {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new ContextManager instance
|
|
8
|
-
*/
|
|
9
|
-
constructor() {
|
|
10
|
-
this.activeContext = null;
|
|
11
|
-
this.changeCallbacks = new Set();
|
|
12
|
-
// Session-scoped: context starts null
|
|
13
|
-
this.activeContext = null;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* Sets the active requirement context
|
|
17
|
-
*
|
|
18
|
-
* @param requirementId - The requirement ID to set as context
|
|
19
|
-
* @param requirement - Optional requirement object to cache
|
|
20
|
-
* @returns The new context or null if setting failed
|
|
21
|
-
*/
|
|
22
|
-
async setContext(requirementId, requirement) {
|
|
23
|
-
const previousContext = this.activeContext;
|
|
24
|
-
// Format the requirement ID for display
|
|
25
|
-
const formattedId = this.formatRequirementId(requirementId);
|
|
26
|
-
// Create new context
|
|
27
|
-
const newContext = {
|
|
28
|
-
requirementId,
|
|
29
|
-
formattedId,
|
|
30
|
-
name: requirement?.name || 'Unknown',
|
|
31
|
-
lastValidated: new Date(),
|
|
32
|
-
requirement,
|
|
33
|
-
};
|
|
34
|
-
this.activeContext = newContext;
|
|
35
|
-
// Emit change event
|
|
36
|
-
this.emitChange({
|
|
37
|
-
type: 'set',
|
|
38
|
-
context: newContext,
|
|
39
|
-
previousContext,
|
|
40
|
-
});
|
|
41
|
-
return newContext;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Gets the current active context
|
|
45
|
-
*
|
|
46
|
-
* @returns The active context or null if none set
|
|
47
|
-
*/
|
|
48
|
-
getContext() {
|
|
49
|
-
return this.activeContext;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Clears the active context
|
|
53
|
-
*
|
|
54
|
-
* @param reason - Optional reason for clearing context
|
|
55
|
-
*/
|
|
56
|
-
clearContext(reason) {
|
|
57
|
-
const previousContext = this.activeContext;
|
|
58
|
-
this.activeContext = null;
|
|
59
|
-
// Emit change event
|
|
60
|
-
this.emitChange({
|
|
61
|
-
type: 'cleared',
|
|
62
|
-
context: null,
|
|
63
|
-
previousContext,
|
|
64
|
-
reason,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Validates the current context is still valid
|
|
69
|
-
*
|
|
70
|
-
* @param requirementService - The requirement service to use for validation
|
|
71
|
-
* @param options - Validation options
|
|
72
|
-
* @returns true if context is valid, false otherwise
|
|
73
|
-
*/
|
|
74
|
-
async validateContext(requirementService, options = {}) {
|
|
75
|
-
const { emitEvents = true, clearOnFailure = true } = options;
|
|
76
|
-
if (!this.activeContext) {
|
|
77
|
-
return true; // No context is valid
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
// Try to fetch the requirement to validate it still exists
|
|
81
|
-
const requirement = await requirementService.getRequirement(this.activeContext.requirementId);
|
|
82
|
-
if (!requirement) {
|
|
83
|
-
// Requirement no longer exists or is inaccessible
|
|
84
|
-
if (clearOnFailure) {
|
|
85
|
-
this.invalidateContext('Requirement no longer exists or is inaccessible');
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
// Update cached requirement data
|
|
90
|
-
this.activeContext.requirement = requirement;
|
|
91
|
-
this.activeContext.name = requirement.name;
|
|
92
|
-
this.activeContext.lastValidated = new Date();
|
|
93
|
-
if (emitEvents) {
|
|
94
|
-
this.emitChange({
|
|
95
|
-
type: 'validated',
|
|
96
|
-
context: this.activeContext,
|
|
97
|
-
previousContext: this.activeContext,
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
// Handle any errors during validation
|
|
104
|
-
if (clearOnFailure) {
|
|
105
|
-
this.invalidateContext(`Validation failed: ${error}`);
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Validates and refreshes the current context
|
|
112
|
-
* Fetches fresh requirement data and updates the context
|
|
113
|
-
*
|
|
114
|
-
* @param requirementService - The requirement service to use
|
|
115
|
-
* @returns The refreshed context or null if validation failed
|
|
116
|
-
*/
|
|
117
|
-
async validateAndRefreshContext(requirementService) {
|
|
118
|
-
if (!this.activeContext) {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
// Fetch fresh requirement data
|
|
123
|
-
const requirement = await requirementService.getRequirement(this.activeContext.requirementId);
|
|
124
|
-
if (!requirement) {
|
|
125
|
-
// Requirement no longer exists
|
|
126
|
-
this.invalidateContext('Requirement no longer exists or is inaccessible');
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
// Update context with fresh data
|
|
130
|
-
this.activeContext.requirement = requirement;
|
|
131
|
-
this.activeContext.name = requirement.name;
|
|
132
|
-
this.activeContext.lastValidated = new Date();
|
|
133
|
-
// Emit validation event
|
|
134
|
-
this.emitChange({
|
|
135
|
-
type: 'validated',
|
|
136
|
-
context: this.activeContext,
|
|
137
|
-
previousContext: this.activeContext,
|
|
138
|
-
});
|
|
139
|
-
return this.activeContext;
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
// Clear context on error
|
|
143
|
-
this.invalidateContext(`Failed to refresh context: ${error}`);
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Formats the command prompt based on current context
|
|
149
|
-
*
|
|
150
|
-
* @returns Formatted prompt string
|
|
151
|
-
*/
|
|
152
|
-
formatPrompt() {
|
|
153
|
-
if (this.activeContext) {
|
|
154
|
-
return `braingrid[${this.activeContext.formattedId}]>`;
|
|
155
|
-
}
|
|
156
|
-
return 'braingrid>';
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Registers a callback for context change events
|
|
160
|
-
*
|
|
161
|
-
* @param callback - The callback to register
|
|
162
|
-
* @returns Function to unregister the callback
|
|
163
|
-
*/
|
|
164
|
-
onContextChange(callback) {
|
|
165
|
-
this.changeCallbacks.add(callback);
|
|
166
|
-
// Return unsubscribe function
|
|
167
|
-
return () => {
|
|
168
|
-
this.changeCallbacks.delete(callback);
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Checks if there is an active context
|
|
173
|
-
*
|
|
174
|
-
* @returns true if context is set, false otherwise
|
|
175
|
-
*/
|
|
176
|
-
hasContext() {
|
|
177
|
-
return this.activeContext !== null;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Gets the active requirement ID if context is set
|
|
181
|
-
*
|
|
182
|
-
* @returns The requirement ID or null
|
|
183
|
-
*/
|
|
184
|
-
getActiveRequirementId() {
|
|
185
|
-
return this.activeContext?.requirementId || null;
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Gets the formatted requirement ID if context is set
|
|
189
|
-
*
|
|
190
|
-
* @returns The formatted ID (e.g., "REQ-123") or null
|
|
191
|
-
*/
|
|
192
|
-
getFormattedId() {
|
|
193
|
-
return this.activeContext?.formattedId || null;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
* Invalidates the current context with a reason
|
|
197
|
-
*
|
|
198
|
-
* @param reason - The reason for invalidation
|
|
199
|
-
*/
|
|
200
|
-
invalidateContext(reason) {
|
|
201
|
-
const previousContext = this.activeContext;
|
|
202
|
-
this.activeContext = null;
|
|
203
|
-
// Emit invalidation event
|
|
204
|
-
this.emitChange({
|
|
205
|
-
type: 'invalidated',
|
|
206
|
-
context: null,
|
|
207
|
-
previousContext,
|
|
208
|
-
reason,
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
/**
|
|
212
|
-
* Emits a context change event to all registered callbacks
|
|
213
|
-
*
|
|
214
|
-
* @param event - The event to emit
|
|
215
|
-
*/
|
|
216
|
-
emitChange(event) {
|
|
217
|
-
this.changeCallbacks.forEach(callback => {
|
|
218
|
-
try {
|
|
219
|
-
callback(event);
|
|
220
|
-
}
|
|
221
|
-
catch (error) {
|
|
222
|
-
// Prevent callback errors from affecting other callbacks
|
|
223
|
-
console.error('Error in context change callback:', error);
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* Formats a requirement ID for display
|
|
229
|
-
* Converts "req_abc123" to "REQ-123" format
|
|
230
|
-
*
|
|
231
|
-
* @param requirementId - The requirement ID to format
|
|
232
|
-
* @returns Formatted ID
|
|
233
|
-
*/
|
|
234
|
-
formatRequirementId(requirementId) {
|
|
235
|
-
// Extract numeric ID from requirement ID
|
|
236
|
-
// Assuming format like "req_abc123" where 123 is the numeric part
|
|
237
|
-
const match = requirementId.match(/(\d+)$/);
|
|
238
|
-
if (match) {
|
|
239
|
-
return `REQ-${match[1]}`;
|
|
240
|
-
}
|
|
241
|
-
// Fallback: just use the ID as-is with REQ- prefix
|
|
242
|
-
return `REQ-${requirementId}`;
|
|
243
|
-
}
|
|
244
|
-
/**
|
|
245
|
-
* Gets a summary of the current context state
|
|
246
|
-
*
|
|
247
|
-
* @returns Context summary object
|
|
248
|
-
*/
|
|
249
|
-
getContextSummary() {
|
|
250
|
-
return {
|
|
251
|
-
hasContext: this.hasContext(),
|
|
252
|
-
requirementId: this.activeContext?.requirementId || null,
|
|
253
|
-
formattedId: this.activeContext?.formattedId || null,
|
|
254
|
-
name: this.activeContext?.name || null,
|
|
255
|
-
lastValidated: this.activeContext?.lastValidated || null,
|
|
256
|
-
};
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// Export singleton instance for session-scoped usage
|
|
260
|
-
export const contextManager = new ContextManager();
|
|
261
|
-
//# sourceMappingURL=context-manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-manager.js","sourceRoot":"","sources":["../../src/services/context-manager.ts"],"names":[],"mappings":"AAoEA;;;GAGG;AACH,MAAM,OAAO,cAAc;IAI1B;;OAEG;IACH;QANQ,kBAAa,GAA8B,IAAI,CAAC;QAChD,oBAAe,GAA+B,IAAI,GAAG,EAAE,CAAC;QAM/D,sCAAsC;QACtC,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC;IAC3B,CAAC;IAED;;;;;;OAMG;IAC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AAI,IAAI;YACtC,aAAa,EAAE,IAAI,CAAC,aAAa,EAAE,aAAa,IAAI,IAAI;SACxD,CAAC;IACH,CAAC;CACD;AAED,qDAAqD;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
package/dist/test/setup.d.ts
DELETED
package/dist/test/setup.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":""}
|
package/dist/test/setup.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { vi, expect } from 'vitest';
|
|
2
|
-
// Mock console methods to reduce noise in tests
|
|
3
|
-
global.console = {
|
|
4
|
-
...console,
|
|
5
|
-
log: vi.fn(),
|
|
6
|
-
error: vi.fn(),
|
|
7
|
-
warn: vi.fn(),
|
|
8
|
-
info: vi.fn(),
|
|
9
|
-
debug: vi.fn(),
|
|
10
|
-
};
|
|
11
|
-
// Mock process.stdin for Ink components
|
|
12
|
-
Object.defineProperty(process.stdin, 'setRawMode', {
|
|
13
|
-
value: vi.fn(),
|
|
14
|
-
writable: true,
|
|
15
|
-
});
|
|
16
|
-
// Mock keytar for auth tests
|
|
17
|
-
vi.mock('keytar', () => ({
|
|
18
|
-
getPassword: vi.fn(),
|
|
19
|
-
setPassword: vi.fn(),
|
|
20
|
-
deletePassword: vi.fn(),
|
|
21
|
-
}));
|
|
22
|
-
// Add custom matchers if needed
|
|
23
|
-
expect.extend({
|
|
24
|
-
toBeWithinRange(received, floor, ceiling) {
|
|
25
|
-
const pass = received >= floor && received <= ceiling;
|
|
26
|
-
if (pass) {
|
|
27
|
-
return {
|
|
28
|
-
message: () => `expected ${received} not to be within range ${floor} - ${ceiling}`,
|
|
29
|
-
pass: true,
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
return {
|
|
34
|
-
message: () => `expected ${received} to be within range ${floor} - ${ceiling}`,
|
|
35
|
-
pass: false,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
//# sourceMappingURL=setup.js.map
|
package/dist/test/setup.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEpC,gDAAgD;AAChD,MAAM,CAAC,OAAO,GAAG;IAChB,GAAG,OAAO;IACV,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;IACZ,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;IACb,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;IACb,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;CACd,CAAC;AAEF,wCAAwC;AACxC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,EAAE;IAClD,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,QAAQ,EAAE,IAAI;CACd,CAAC,CAAC;AAEH,6BAA6B;AAC7B,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,CAAC;IACxB,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE;IACpB,WAAW,EAAE,EAAE,CAAC,EAAE,EAAE;IACpB,cAAc,EAAE,EAAE,CAAC,EAAE,EAAE;CACvB,CAAC,CAAC,CAAC;AAEJ,gCAAgC;AAChC,MAAM,CAAC,MAAM,CAAC;IACb,eAAe,CAAC,QAAgB,EAAE,KAAa,EAAE,OAAe;QAC/D,MAAM,IAAI,GAAG,QAAQ,IAAI,KAAK,IAAI,QAAQ,IAAI,OAAO,CAAC;QACtD,IAAI,IAAI,EAAE,CAAC;YACV,OAAO;gBACN,OAAO,EAAE,GAAG,EAAE,CAAC,YAAY,QAAQ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