doukui 0.0.0-stage → 0.3.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.
Files changed (135) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +42 -0
  3. package/README.md +147 -2
  4. package/bin/commands/build.js +178 -0
  5. package/bin/commands/config.js +88 -0
  6. package/bin/commands/help.js +83 -0
  7. package/bin/commands/init.js +194 -0
  8. package/bin/commands/install.js +202 -0
  9. package/bin/commands/interactive.js +352 -0
  10. package/bin/commands/list.js +108 -0
  11. package/bin/commands/loop-server.js +357 -0
  12. package/bin/commands/loop.js +1398 -0
  13. package/bin/commands/migrate.js +120 -0
  14. package/bin/commands/setup-global.js +81 -0
  15. package/bin/commands/status.js +140 -0
  16. package/bin/commands/team-cleanup.js +190 -0
  17. package/bin/commands/validate-config.js +35 -0
  18. package/bin/commands/validate.js +21 -0
  19. package/bin/commands/version.js +22 -0
  20. package/bin/context.js +143 -0
  21. package/bin/doukui.js +216 -0
  22. package/package.json +47 -4
  23. package/plugins/contracts/capabilities.js +268 -0
  24. package/plugins/contracts/checkresult-schema.json +75 -0
  25. package/plugins/contracts/config-schema.json +179 -0
  26. package/plugins/contracts/plugin-interface.js +262 -0
  27. package/plugins/contracts/plugin-schema.json +104 -0
  28. package/plugins/core/hook-session-start/index.js +281 -0
  29. package/plugins/core/hook-session-start/plugin.json +7 -0
  30. package/plugins/core/hook-skill-gate/index.js +661 -0
  31. package/plugins/core/hook-skill-gate/plugin.json +12 -0
  32. package/plugins/core/provider-loop-engine/index.js +1397 -0
  33. package/plugins/core/provider-loop-engine/plugin.json +15 -0
  34. package/plugins/core/provider-memory-store/index.js +510 -0
  35. package/plugins/core/provider-memory-store/plugin.json +9 -0
  36. package/plugins/core/provider-role-registry/index.js +376 -0
  37. package/plugins/core/provider-role-registry/plugin.json +9 -0
  38. package/plugins/core/provider-state-store/index.js +244 -0
  39. package/plugins/core/provider-state-store/plugin.json +9 -0
  40. package/plugins/core/provider-watchdog/assets/daemon-config.template.json +32 -0
  41. package/plugins/core/provider-watchdog/assets/lib/watchdog-multi-window.js +676 -0
  42. package/plugins/core/provider-watchdog/assets/watchdog.js +754 -0
  43. package/plugins/core/provider-watchdog/index.js +151 -0
  44. package/plugins/core/provider-watchdog/plugin.json +13 -0
  45. package/plugins/core/skill-agent-dispatcher/cleanup-reference.md +214 -0
  46. package/plugins/core/skill-agent-dispatcher/daemon-helpers-reference.md +249 -0
  47. package/plugins/core/skill-agent-dispatcher/plugin.json +13 -0
  48. package/plugins/core/skill-agent-dispatcher/roles-reference.md +253 -0
  49. package/plugins/core/skill-agent-dispatcher/skill.md +1291 -0
  50. package/plugins/core/skill-agentic-loop/plugin.json +20 -0
  51. package/plugins/core/skill-agentic-loop/skill.md +572 -0
  52. package/plugins/core/skill-batch-task-creator/plugin.json +15 -0
  53. package/plugins/core/skill-batch-task-creator/skill.md +620 -0
  54. package/plugins/core/skill-checklist/plugin.json +10 -0
  55. package/plugins/core/skill-checklist/skill.md +171 -0
  56. package/plugins/core/skill-completion-report/plugin.json +10 -0
  57. package/plugins/core/skill-completion-report/skill.md +331 -0
  58. package/plugins/core/skill-doukui-plan/plugin.json +15 -0
  59. package/plugins/core/skill-doukui-plan/skill.md +233 -0
  60. package/plugins/core/skill-doukui-sync/plugin.json +10 -0
  61. package/plugins/core/skill-doukui-sync/skill.md +76 -0
  62. package/plugins/core/skill-experience-logger/plugin.json +10 -0
  63. package/plugins/core/skill-experience-logger/skill.md +235 -0
  64. package/plugins/core/skill-human-checkpoint/plugin.json +10 -0
  65. package/plugins/core/skill-human-checkpoint/skill.md +194 -0
  66. package/plugins/core/skill-progress-tracker/plugin.json +10 -0
  67. package/plugins/core/skill-progress-tracker/skill.md +228 -0
  68. package/plugins/core/skill-role-manager/plugin.json +10 -0
  69. package/plugins/core/skill-role-manager/skill.md +252 -0
  70. package/plugins/core/skill-split-work-package/plugin.json +15 -0
  71. package/plugins/core/skill-split-work-package/skill.md +441 -0
  72. package/plugins/core/skill-task-archive/plugin.json +10 -0
  73. package/plugins/core/skill-task-archive/skill.md +116 -0
  74. package/plugins/core/skill-task-creator/plugin.json +15 -0
  75. package/plugins/core/skill-task-creator/skill.md +886 -0
  76. package/plugins/core/skill-team-cleanup/plugin.json +10 -0
  77. package/plugins/core/skill-team-cleanup/skill.md +266 -0
  78. package/plugins/core/skill-watchdog-manager/plugin.json +10 -0
  79. package/plugins/core/skill-watchdog-manager/skill.md +143 -0
  80. package/plugins/core/skill-workflow-orchestrator/plugin.json +13 -0
  81. package/plugins/core/skill-workflow-orchestrator/skill.md +273 -0
  82. package/plugins/core/validator-doc-sync/index.js +248 -0
  83. package/plugins/core/validator-doc-sync/plugin.json +12 -0
  84. package/plugins/core/validator-work-package/index.js +300 -0
  85. package/plugins/core/validator-work-package/plugin.json +12 -0
  86. package/plugins/plugin-registry.json +186 -0
  87. package/plugins/runtime/agent-def-generator.js +150 -0
  88. package/plugins/runtime/audit-logger.js +311 -0
  89. package/plugins/runtime/build-cli.js +89 -0
  90. package/plugins/runtime/checkresult-validator.js +131 -0
  91. package/plugins/runtime/claude-md-injector.js +159 -0
  92. package/plugins/runtime/cleanup-utils.js +293 -0
  93. package/plugins/runtime/config-manager.js +317 -0
  94. package/plugins/runtime/config-validator.js +320 -0
  95. package/plugins/runtime/context-window.js +81 -0
  96. package/plugins/runtime/event-bus.js +207 -0
  97. package/plugins/runtime/executor-claude.js +828 -0
  98. package/plugins/runtime/executor-default.js +448 -0
  99. package/plugins/runtime/executor-local.js +178 -0
  100. package/plugins/runtime/executor-sdk.js +390 -0
  101. package/plugins/runtime/harness-build.js +1037 -0
  102. package/plugins/runtime/hook-dispatcher.js +315 -0
  103. package/plugins/runtime/logger.js +192 -0
  104. package/plugins/runtime/loop-actuator.js +292 -0
  105. package/plugins/runtime/loop-coordinator.js +347 -0
  106. package/plugins/runtime/loop-defaults.js +29 -0
  107. package/plugins/runtime/loop-dispatch-batch.js +247 -0
  108. package/plugins/runtime/loop-executor.js +120 -0
  109. package/plugins/runtime/loop-report.js +327 -0
  110. package/plugins/runtime/loop-server-core.js +750 -0
  111. package/plugins/runtime/loop-snapshot.js +581 -0
  112. package/plugins/runtime/loop-trace.js +242 -0
  113. package/plugins/runtime/loop-worktree.js +404 -0
  114. package/plugins/runtime/manifest-resolver.js +457 -0
  115. package/plugins/runtime/multi-window-coordinator.js +560 -0
  116. package/plugins/runtime/objective-verifier.js +136 -0
  117. package/plugins/runtime/plan-reader.js +763 -0
  118. package/plugins/runtime/plugin-loader.js +798 -0
  119. package/plugins/runtime/plugin-trust.js +182 -0
  120. package/plugins/runtime/plugin-validator.js +491 -0
  121. package/plugins/runtime/provider-failover.js +114 -0
  122. package/plugins/runtime/provider-resolver.js +342 -0
  123. package/plugins/runtime/reflection-evaluator.js +540 -0
  124. package/plugins/runtime/resolve-plugin-path.js +297 -0
  125. package/plugins/runtime/safe-path.js +119 -0
  126. package/plugins/runtime/sandbox-context.js +235 -0
  127. package/plugins/runtime/sandbox-manager.js +609 -0
  128. package/plugins/runtime/sandbox-worker.js +215 -0
  129. package/plugins/runtime/settings-merger.js +172 -0
  130. package/plugins/runtime/state-store.js +527 -0
  131. package/plugins/runtime/team-cleanup.js +497 -0
  132. package/plugins/runtime/text-tokenize.js +25 -0
  133. package/plugins/runtime/validator-pipeline.js +475 -0
  134. package/plugins/runtime/yaml-parser.js +692 -0
  135. package/templates/harness-config.yaml +388 -0
@@ -0,0 +1,315 @@
1
+ /**
2
+ * HookDispatcher - Dual-mode hook execution dispatcher for AI Agent Harness
3
+ *
4
+ * Two execution modes:
5
+ * - External: Command-based execution via settings.json (default, backward compatible)
6
+ * - Internal: Programmatic execution by calling HookPlugin.handle() directly
7
+ *
8
+ * Features:
9
+ * - Route hook events to appropriate hooks based on trigger configuration
10
+ * - Support PreToolUse, PostToolUse, SessionStart event types
11
+ * - Priority-based hook execution (lower priority = earlier execution)
12
+ * - Graceful handling of unregistered events
13
+ * - Integration with PluginLoader for internal mode
14
+ *
15
+ * Usage:
16
+ * const dispatcher = new HookDispatcher({ pluginLoader, logger });
17
+ * await dispatcher.dispatch({ event: 'PreToolUse', tool: 'Edit', ... });
18
+ */
19
+
20
+ 'use strict';
21
+
22
+ var { PluginType, PluginState } = require('../contracts/plugin-interface');
23
+
24
+ /**
25
+ * Execution mode constants.
26
+ * @public
27
+ */
28
+ var ExecutionMode = Object.freeze({
29
+ EXTERNAL: 'external', // Command-based via settings.json (default)
30
+ INTERNAL: 'internal', // Programmatic via HookPlugin.handle()
31
+ });
32
+
33
+ /**
34
+ * Default configuration.
35
+ */
36
+ var DEFAULT_CONFIG = {
37
+ mode: ExecutionMode.EXTERNAL,
38
+ priorityThreshold: 1000,
39
+ };
40
+
41
+ /**
42
+ * HookDispatcher class.
43
+ * @public
44
+ */
45
+ class HookDispatcher {
46
+ /**
47
+ * @public
48
+ * @param {object} options
49
+ * @param {object} options.pluginLoader - PluginLoader instance (required for internal mode)
50
+ * @param {object} options.logger - Logger instance (optional)
51
+ * @param {string} [options.mode] - default execution mode
52
+ */
53
+ constructor(options) {
54
+ options = options || {};
55
+ this._pluginLoader = options.pluginLoader || null;
56
+ this._logger = options.logger || null;
57
+ this._mode = options.mode || DEFAULT_CONFIG.mode;
58
+ this._priorityThreshold = options.priorityThreshold || DEFAULT_CONFIG.priorityThreshold;
59
+ }
60
+
61
+ /**
62
+ * Dispatch a hook event to appropriate hooks.
63
+ *
64
+ * @public
65
+ * @param {object} context
66
+ * @param {string} context.event - Event type: 'PreToolUse', 'PostToolUse', 'SessionStart'
67
+ * @param {string} [context.tool] - Tool name (for PreToolUse/PostToolUse)
68
+ * @param {string} [context.skill] - Skill name (for PostToolUse)
69
+ * @param {string} [context.mode] - Override execution mode for this call
70
+ * @returns {Promise<{ allowed: boolean, results?: object[], reason?: string }>}
71
+ */
72
+ async dispatch(context) {
73
+ if (!context || !context.event) {
74
+ this._log('warn', 'dispatch() called with invalid context');
75
+ return { allowed: true, results: [] };
76
+ }
77
+
78
+ var mode = context.mode || this._mode;
79
+ this._log('debug', 'Dispatching event "' + context.event + '" in ' + mode + ' mode');
80
+
81
+ if (mode === ExecutionMode.INTERNAL) {
82
+ return await this._dispatchInternal(context);
83
+ }
84
+
85
+ // External mode: no-op (hooks are executed via settings.json commands)
86
+ return { allowed: true, results: [], mode: 'external' };
87
+ }
88
+
89
+ /**
90
+ * Internal mode dispatch: call loaded HookPlugin.handle() directly.
91
+ *
92
+ * @param {object} context
93
+ * @returns {Promise<{ allowed: boolean, results: object[], reason?: string }>}
94
+ * @private
95
+ */
96
+ async _dispatchInternal(context) {
97
+ if (!this._pluginLoader) {
98
+ this._log('warn', 'Internal mode requested but no pluginLoader provided');
99
+ return { allowed: true, results: [], mode: 'internal' };
100
+ }
101
+
102
+ var matchingHooks = this._findMatchingHooks(context);
103
+ if (matchingHooks.length === 0) {
104
+ this._log('debug', 'No matching hooks found for event "' + context.event + '"');
105
+ return { allowed: true, results: [], mode: 'internal' };
106
+ }
107
+
108
+ // Sort by priority (lower = earlier execution)
109
+ matchingHooks.sort(function (a, b) {
110
+ var pa = (a.plugin && a.plugin.priority) || 100;
111
+ var pb = (b.plugin && b.plugin.priority) || 100;
112
+ return pa - pb;
113
+ });
114
+
115
+ this._log('debug', 'Found ' + matchingHooks.length + ' matching hook(s)');
116
+
117
+ var results = [];
118
+ var overallAllowed = true;
119
+ var blockReason = null;
120
+
121
+ for (var i = 0; i < matchingHooks.length; i++) {
122
+ var item = matchingHooks[i];
123
+ var plugin = item.plugin;
124
+
125
+ // Skip inactive plugins
126
+ if (plugin.state !== PluginState.ACTIVATED) {
127
+ this._log('debug', 'Hook "' + plugin.name + '" is not activated, skipping');
128
+ continue;
129
+ }
130
+
131
+ try {
132
+ this._log('debug', 'Executing hook "' + plugin.name + '" (priority: ' + plugin.priority + ')');
133
+ var result = await plugin.handle(context);
134
+ results.push({
135
+ hook: plugin.name,
136
+ result: result,
137
+ });
138
+
139
+ // If any hook disallows, set overall allowed to false
140
+ if (result && result.allowed === false) {
141
+ overallAllowed = false;
142
+ blockReason = result.reason || ('Blocked by hook: ' + plugin.name);
143
+ this._log('info', 'Hook "' + plugin.name + '" disallowed action: ' + blockReason);
144
+ // Continue executing remaining hooks for side effects
145
+ }
146
+ } catch (err) {
147
+ this._log('error', 'Hook "' + plugin.name + '" threw error: ' + err.message);
148
+ results.push({
149
+ hook: plugin.name,
150
+ error: err.message,
151
+ });
152
+ }
153
+ }
154
+
155
+ var response = {
156
+ allowed: overallAllowed,
157
+ results: results,
158
+ mode: 'internal',
159
+ };
160
+
161
+ if (blockReason) {
162
+ response.reason = blockReason;
163
+ }
164
+
165
+ return response;
166
+ }
167
+
168
+ /**
169
+ * Find all loaded hooks that match the event context.
170
+ *
171
+ * @param {object} context
172
+ * @returns {Array<{ plugin: HookPlugin, trigger: object }>}
173
+ * @private
174
+ */
175
+ _findMatchingHooks(context) {
176
+ var matches = [];
177
+ var loadedNames = this._pluginLoader.getLoadedNames();
178
+
179
+ for (var i = 0; i < loadedNames.length; i++) {
180
+ var plugin = this._pluginLoader.getPlugin(loadedNames[i]);
181
+
182
+ if (!plugin || plugin.type !== PluginType.HOOK) {
183
+ continue;
184
+ }
185
+
186
+ var trigger = plugin.trigger || {};
187
+
188
+ // Check event type match
189
+ if (trigger.event !== context.event) {
190
+ continue;
191
+ }
192
+
193
+ // Check tool filter (for PreToolUse/PostToolUse)
194
+ if (trigger.tools && trigger.tools.length > 0) {
195
+ var tool = context.tool || '';
196
+ var toolMatched = false;
197
+ for (var j = 0; j < trigger.tools.length; j++) {
198
+ if (trigger.tools[j] === tool) {
199
+ toolMatched = true;
200
+ break;
201
+ }
202
+ }
203
+ if (!toolMatched) continue;
204
+ }
205
+
206
+ // Check skill filter (for PostToolUse)
207
+ if (trigger.skills && trigger.skills.length > 0) {
208
+ var skill = context.skill || '';
209
+ var skillMatched = false;
210
+ for (var k = 0; k < trigger.skills.length; k++) {
211
+ if (trigger.skills[k] === skill) {
212
+ skillMatched = true;
213
+ break;
214
+ }
215
+ }
216
+ if (!skillMatched) continue;
217
+ }
218
+
219
+ matches.push({
220
+ plugin: plugin,
221
+ trigger: trigger,
222
+ });
223
+ }
224
+
225
+ return matches;
226
+ }
227
+
228
+ /**
229
+ * Set the default execution mode.
230
+ * @public
231
+ * @param {string} mode - 'external' or 'internal'
232
+ */
233
+ setMode(mode) {
234
+ if (mode !== ExecutionMode.EXTERNAL && mode !== ExecutionMode.INTERNAL) {
235
+ throw new Error('Invalid mode: ' + mode + '. Use "external" or "internal"');
236
+ }
237
+ this._mode = mode;
238
+ this._log('info', 'Execution mode set to "' + mode + '"');
239
+ }
240
+
241
+ /**
242
+ * Get the current default execution mode.
243
+ * @public
244
+ * @returns {string}
245
+ */
246
+ getMode() {
247
+ return this._mode;
248
+ }
249
+
250
+ /**
251
+ * Check if internal mode is available (requires pluginLoader).
252
+ * @public
253
+ * @returns {boolean}
254
+ */
255
+ canUseInternalMode() {
256
+ return this._pluginLoader !== null;
257
+ }
258
+
259
+ /**
260
+ * Get statistics about loaded hooks.
261
+ * @public
262
+ * @returns {{ total: number, byEvent: object, byPriority: object[] }}
263
+ */
264
+ getHookStats() {
265
+ if (!this._pluginLoader) {
266
+ return { total: 0, byEvent: {}, byPriority: [] };
267
+ }
268
+
269
+ var stats = {
270
+ total: 0,
271
+ byEvent: {},
272
+ byPriority: [],
273
+ };
274
+
275
+ var loadedNames = this._pluginLoader.getLoadedNames();
276
+ for (var i = 0; i < loadedNames.length; i++) {
277
+ var plugin = this._pluginLoader.getPlugin(loadedNames[i]);
278
+ if (!plugin || plugin.type !== PluginType.HOOK) continue;
279
+
280
+ stats.total++;
281
+
282
+ var event = (plugin.trigger && plugin.trigger.event) || 'unknown';
283
+ stats.byEvent[event] = (stats.byEvent[event] || 0) + 1;
284
+
285
+ stats.byPriority.push({
286
+ name: plugin.name,
287
+ event: event,
288
+ priority: plugin.priority || 100,
289
+ });
290
+ }
291
+
292
+ stats.byPriority.sort(function (a, b) {
293
+ return a.priority - b.priority;
294
+ });
295
+
296
+ return stats;
297
+ }
298
+
299
+ /**
300
+ * Internal logging helper.
301
+ * @param {string} level
302
+ * @param {string} message
303
+ * @private
304
+ */
305
+ _log(level, message) {
306
+ if (this._logger && typeof this._logger[level] === 'function') {
307
+ this._logger[level]('hook-dispatcher', message);
308
+ }
309
+ }
310
+ }
311
+
312
+ module.exports = {
313
+ HookDispatcher,
314
+ ExecutionMode,
315
+ };
@@ -0,0 +1,192 @@
1
+ /**
2
+ * Logger - Plugin-level logging service for AI Agent Harness
3
+ *
4
+ * @module logger
5
+ *
6
+ * Features:
7
+ * - debug / info / warn / error log levels
8
+ * - Per-plugin log segregation
9
+ * - History query interface for debugging
10
+ * - No external dependencies
11
+ */
12
+
13
+ 'use strict';
14
+
15
+ var LOG_LEVELS = Object.freeze({
16
+ debug: 0,
17
+ info: 1,
18
+ warn: 2,
19
+ error: 3,
20
+ });
21
+
22
+ /**
23
+ * Logger class.
24
+ * @public
25
+ */
26
+ class Logger {
27
+ /**
28
+ * @public
29
+ * @param {object} [options]
30
+ * @param {string} [options.level='info'] - minimum log level
31
+ * @param {number} [options.maxHistory=500] - max history entries to retain
32
+ */
33
+ constructor(options) {
34
+ options = options || {};
35
+ this._minLevel = LOG_LEVELS[options.level] !== undefined
36
+ ? LOG_LEVELS[options.level]
37
+ : LOG_LEVELS.info;
38
+ this._maxHistory = options.maxHistory || 500;
39
+ this._history = [];
40
+ }
41
+
42
+ // --- public API ---
43
+
44
+ /**
45
+ * Log a debug message.
46
+ * @public
47
+ * @param {string} plugin - plugin name
48
+ * @param {string} message
49
+ * @param {object} [data]
50
+ */
51
+ debug(plugin, message, data) {
52
+ this._log('debug', plugin, message, data);
53
+ }
54
+
55
+ /**
56
+ * Log an info message.
57
+ * @public
58
+ * @param {string} plugin
59
+ * @param {string} message
60
+ * @param {object} [data]
61
+ */
62
+ info(plugin, message, data) {
63
+ this._log('info', plugin, message, data);
64
+ }
65
+
66
+ /**
67
+ * Log a warning message.
68
+ * @public
69
+ * @param {string} plugin
70
+ * @param {string} message
71
+ * @param {object} [data]
72
+ */
73
+ warn(plugin, message, data) {
74
+ this._log('warn', plugin, message, data);
75
+ }
76
+
77
+ /**
78
+ * Log an error message.
79
+ * @public
80
+ * @param {string} plugin
81
+ * @param {string} message
82
+ * @param {object} [data]
83
+ */
84
+ error(plugin, message, data) {
85
+ this._log('error', plugin, message, data);
86
+ }
87
+
88
+ /**
89
+ * Query log history.
90
+ * @public
91
+ * @param {object} [filter]
92
+ * @param {string} [filter.plugin] - filter by plugin name
93
+ * @param {string} [filter.level] - filter by level (debug/info/warn/error)
94
+ * @param {number} [filter.since] - timestamp lower bound (ms)
95
+ * @param {number} [filter.until] - timestamp upper bound (ms)
96
+ * @param {number} [filter.limit] - max entries to return
97
+ * @returns {object[]}
98
+ */
99
+ query(filter) {
100
+ filter = filter || {};
101
+ var results = this._history;
102
+
103
+ if (filter.plugin) {
104
+ results = results.filter(function (e) { return e.plugin === filter.plugin; });
105
+ }
106
+ if (filter.level) {
107
+ var levelNum = LOG_LEVELS[filter.level];
108
+ if (levelNum !== undefined) {
109
+ results = results.filter(function (e) { return LOG_LEVELS[e.level] >= levelNum; });
110
+ }
111
+ }
112
+ if (filter.since) {
113
+ results = results.filter(function (e) { return e.timestamp >= filter.since; });
114
+ }
115
+ if (filter.until) {
116
+ results = results.filter(function (e) { return e.timestamp <= filter.until; });
117
+ }
118
+ if (filter.limit) {
119
+ results = results.slice(-filter.limit);
120
+ }
121
+
122
+ return results;
123
+ }
124
+
125
+ /**
126
+ * Clear all history entries.
127
+ * @public
128
+ */
129
+ clear() {
130
+ this._history = [];
131
+ }
132
+
133
+ /**
134
+ * Create a child logger bound to a specific plugin name.
135
+ * The child logger exposes debug/info/warn/error without needing the plugin arg.
136
+ * @public
137
+ * @param {string} pluginName
138
+ * @returns {object} child logger with debug/info/warn/error methods
139
+ */
140
+ createChild(pluginName) {
141
+ var self = this;
142
+ return {
143
+ debug: function (message, data) { self.debug(pluginName, message, data); },
144
+ info: function (message, data) { self.info(pluginName, message, data); },
145
+ warn: function (message, data) { self.warn(pluginName, message, data); },
146
+ error: function (message, data) { self.error(pluginName, message, data); },
147
+ };
148
+ }
149
+
150
+ // --- internal ---
151
+
152
+ /**
153
+ * Internal log handler.
154
+ * @internal
155
+ */
156
+ _log(level, plugin, message, data) {
157
+ var levelNum = LOG_LEVELS[level];
158
+ if (levelNum === undefined) {
159
+ return;
160
+ }
161
+ if (levelNum < this._minLevel) {
162
+ return;
163
+ }
164
+
165
+ var entry = {
166
+ level: level,
167
+ plugin: plugin || 'system',
168
+ message: message,
169
+ timestamp: Date.now(),
170
+ };
171
+ if (data !== undefined) {
172
+ entry.data = data;
173
+ }
174
+
175
+ this._history.push(entry);
176
+ if (this._history.length > this._maxHistory) {
177
+ this._history.shift();
178
+ }
179
+
180
+ // Also write to console for immediate visibility
181
+ var prefix = '[' + entry.timestamp + '] [' + level.toUpperCase() + '] [' + entry.plugin + ']';
182
+ if (level === 'error') {
183
+ console.error(prefix, message, data !== undefined ? data : '');
184
+ } else if (level === 'warn') {
185
+ console.warn(prefix, message, data !== undefined ? data : '');
186
+ } else {
187
+ console.log(prefix, message, data !== undefined ? data : '');
188
+ }
189
+ }
190
+ }
191
+
192
+ module.exports = Logger;