jiva-core 0.2.2 → 0.2.3

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,224 @@
1
+ /**
2
+ * Orchestration Logger - Tracks Manager/Worker coordination
3
+ *
4
+ * Writes detailed logs to understand how tasks flow through the dual-agent system.
5
+ * Logs are written to: ~/.jiva/logs/orchestration-{timestamp}.log
6
+ */
7
+ import * as fs from 'fs';
8
+ import * as path from 'path';
9
+ import * as os from 'os';
10
+ class OrchestrationLogger {
11
+ static instance;
12
+ logFilePath = null;
13
+ logStream = null;
14
+ sessionStart;
15
+ constructor() {
16
+ this.sessionStart = new Date();
17
+ this.initializeLogFile();
18
+ }
19
+ static getInstance() {
20
+ if (!OrchestrationLogger.instance) {
21
+ OrchestrationLogger.instance = new OrchestrationLogger();
22
+ }
23
+ return OrchestrationLogger.instance;
24
+ }
25
+ initializeLogFile() {
26
+ try {
27
+ // Create logs directory in ~/.jiva/logs/
28
+ const jivaDir = path.join(os.homedir(), '.jiva', 'logs');
29
+ fs.mkdirSync(jivaDir, { recursive: true });
30
+ // Create timestamped log file
31
+ const timestamp = this.sessionStart.toISOString().replace(/[:.]/g, '-');
32
+ this.logFilePath = path.join(jivaDir, `orchestration-${timestamp}.log`);
33
+ // Create write stream
34
+ this.logStream = fs.createWriteStream(this.logFilePath, { flags: 'a' });
35
+ // Write header
36
+ this.writeHeader();
37
+ }
38
+ catch (error) {
39
+ console.error('Failed to initialize orchestration log file:', error);
40
+ this.logFilePath = null;
41
+ this.logStream = null;
42
+ }
43
+ }
44
+ writeHeader() {
45
+ if (!this.logStream)
46
+ return;
47
+ const header = [
48
+ '='.repeat(80),
49
+ 'JIVA ORCHESTRATION LOG',
50
+ `Session started: ${this.sessionStart.toISOString()}`,
51
+ '='.repeat(80),
52
+ '',
53
+ ].join('\n');
54
+ this.logStream.write(header);
55
+ }
56
+ writeEvent(event) {
57
+ if (!this.logStream)
58
+ return;
59
+ const line = [
60
+ `[${event.timestamp}]`,
61
+ `[${event.phase}]`,
62
+ event.event,
63
+ Object.keys(event.details).length > 0 ? JSON.stringify(event.details, null, 2) : '',
64
+ ].filter(Boolean).join(' ');
65
+ this.logStream.write(line + '\n');
66
+ }
67
+ // DualAgent events
68
+ logUserMessage(message) {
69
+ this.writeEvent({
70
+ timestamp: new Date().toISOString(),
71
+ phase: 'DUAL_AGENT',
72
+ event: 'USER_MESSAGE',
73
+ details: { message },
74
+ });
75
+ }
76
+ logPhaseStart(phase) {
77
+ this.writeEvent({
78
+ timestamp: new Date().toISOString(),
79
+ phase: 'DUAL_AGENT',
80
+ event: `PHASE_START_${phase}`,
81
+ details: {},
82
+ });
83
+ }
84
+ logPhaseEnd(phase, durationMs) {
85
+ this.writeEvent({
86
+ timestamp: new Date().toISOString(),
87
+ phase: 'DUAL_AGENT',
88
+ event: `PHASE_END_${phase}`,
89
+ details: { durationMs },
90
+ });
91
+ }
92
+ logFinalResponse(response, totalIterations, toolsUsed) {
93
+ this.writeEvent({
94
+ timestamp: new Date().toISOString(),
95
+ phase: 'DUAL_AGENT',
96
+ event: 'FINAL_RESPONSE',
97
+ details: {
98
+ responseLength: response.length,
99
+ totalIterations,
100
+ toolsUsed,
101
+ uniqueTools: [...new Set(toolsUsed)],
102
+ },
103
+ });
104
+ }
105
+ // Manager events
106
+ logManagerCreatePlan(task, context) {
107
+ this.writeEvent({
108
+ timestamp: new Date().toISOString(),
109
+ phase: 'MANAGER',
110
+ event: 'CREATE_PLAN',
111
+ details: { task, context },
112
+ });
113
+ }
114
+ logManagerPlanCreated(subtasks, reasoning) {
115
+ this.writeEvent({
116
+ timestamp: new Date().toISOString(),
117
+ phase: 'MANAGER',
118
+ event: 'PLAN_CREATED',
119
+ details: {
120
+ subtaskCount: subtasks.length,
121
+ subtasks,
122
+ reasoning,
123
+ },
124
+ });
125
+ }
126
+ logManagerReview(subtask, workerResult) {
127
+ this.writeEvent({
128
+ timestamp: new Date().toISOString(),
129
+ phase: 'MANAGER',
130
+ event: 'REVIEW_SUBTASK',
131
+ details: {
132
+ subtask,
133
+ workerResultLength: workerResult.length,
134
+ workerResultPreview: workerResult.substring(0, 200),
135
+ },
136
+ });
137
+ }
138
+ logManagerDecision(isComplete, reasoning, nextAction) {
139
+ this.writeEvent({
140
+ timestamp: new Date().toISOString(),
141
+ phase: 'MANAGER',
142
+ event: 'DECISION',
143
+ details: {
144
+ isComplete,
145
+ reasoning,
146
+ nextAction,
147
+ },
148
+ });
149
+ }
150
+ logManagerSynthesize(resultsCount) {
151
+ this.writeEvent({
152
+ timestamp: new Date().toISOString(),
153
+ phase: 'MANAGER',
154
+ event: 'SYNTHESIZE',
155
+ details: { resultsCount },
156
+ });
157
+ }
158
+ // Worker events
159
+ logWorkerStart(subtask, context) {
160
+ this.writeEvent({
161
+ timestamp: new Date().toISOString(),
162
+ phase: 'WORKER',
163
+ event: 'START_SUBTASK',
164
+ details: { subtask, context },
165
+ });
166
+ }
167
+ logWorkerIteration(iteration, maxIterations) {
168
+ this.writeEvent({
169
+ timestamp: new Date().toISOString(),
170
+ phase: 'WORKER',
171
+ event: 'ITERATION',
172
+ details: { iteration, maxIterations },
173
+ });
174
+ }
175
+ logWorkerToolCall(toolName, args) {
176
+ this.writeEvent({
177
+ timestamp: new Date().toISOString(),
178
+ phase: 'WORKER',
179
+ event: 'TOOL_CALL',
180
+ details: { toolName, args },
181
+ });
182
+ }
183
+ logWorkerToolResult(toolName, success, hasImages) {
184
+ this.writeEvent({
185
+ timestamp: new Date().toISOString(),
186
+ phase: 'WORKER',
187
+ event: 'TOOL_RESULT',
188
+ details: { toolName, success, hasImages },
189
+ });
190
+ }
191
+ logWorkerComplete(success, toolsUsed, iterations) {
192
+ this.writeEvent({
193
+ timestamp: new Date().toISOString(),
194
+ phase: 'WORKER',
195
+ event: 'COMPLETE',
196
+ details: {
197
+ success,
198
+ toolsUsed,
199
+ iterations,
200
+ uniqueTools: [...new Set(toolsUsed)],
201
+ },
202
+ });
203
+ }
204
+ // Utility
205
+ getLogFilePath() {
206
+ return this.logFilePath;
207
+ }
208
+ close() {
209
+ if (this.logStream) {
210
+ const footer = [
211
+ '',
212
+ '='.repeat(80),
213
+ `Session ended: ${new Date().toISOString()}`,
214
+ `Duration: ${Date.now() - this.sessionStart.getTime()}ms`,
215
+ '='.repeat(80),
216
+ ].join('\n');
217
+ this.logStream.write(footer);
218
+ this.logStream.end();
219
+ this.logStream = null;
220
+ }
221
+ }
222
+ }
223
+ export const orchestrationLogger = OrchestrationLogger.getInstance();
224
+ //# sourceMappingURL=orchestration-logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"orchestration-logger.js","sourceRoot":"","sources":["../../src/utils/orchestration-logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AASzB,MAAM,mBAAmB;IACf,MAAM,CAAC,QAAQ,CAAsB;IACrC,WAAW,GAAkB,IAAI,CAAC;IAClC,SAAS,GAA0B,IAAI,CAAC;IACxC,YAAY,CAAO;IAE3B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC;QAC/B,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC3B,CAAC;IAED,MAAM,CAAC,WAAW;QAChB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;YAClC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC;IACtC,CAAC;IAEO,iBAAiB;QACvB,IAAI,CAAC;YACH,yCAAyC;YACzC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YACzD,EAAE,CAAC,SAAS,CAAC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3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Versatile autonomous AI agent powered by gpt-oss-120b with full MCP support. Mission-driven execution, smart conversations, and extensible tooling.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
Binary file
Binary file
package/image.avif DELETED
Binary file
package/ms_image.avif DELETED
Binary file
package/screenshot.png DELETED
Binary file
Binary file
package/tmp_image.avif DELETED
Binary file