aiden-runtime 3.16.2 → 3.17.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.
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ // ============================================================
3
+ // DevOS — Plugin Loader (flat .js format)
4
+ // Loads workspace/plugins/*.js (files NOT starting with _)
5
+ // Runs alongside the existing pluginSystem.ts (subdirectory format).
6
+ // ============================================================
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || (function () {
24
+ var ownKeys = function(o) {
25
+ ownKeys = Object.getOwnPropertyNames || function (o) {
26
+ var ar = [];
27
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
28
+ return ar;
29
+ };
30
+ return ownKeys(o);
31
+ };
32
+ return function (mod) {
33
+ if (mod && mod.__esModule) return mod;
34
+ var result = {};
35
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
36
+ __setModuleDefault(result, mod);
37
+ return result;
38
+ };
39
+ })();
40
+ Object.defineProperty(exports, "__esModule", { value: true });
41
+ exports.loadedFlatPlugins = exports.pluginHooks = void 0;
42
+ exports.loadPlugins = loadPlugins;
43
+ exports.reloadPlugins = reloadPlugins;
44
+ exports.listFlatPlugins = listFlatPlugins;
45
+ const fs = __importStar(require("fs"));
46
+ const path = __importStar(require("path"));
47
+ const toolRegistry_1 = require("./toolRegistry");
48
+ exports.pluginHooks = {
49
+ preTool: [],
50
+ postTool: [],
51
+ onSessionStart: [],
52
+ onSessionEnd: [],
53
+ };
54
+ exports.loadedFlatPlugins = [];
55
+ // ── Plugin context (passed to init) ──────────────────────────
56
+ function makeContext(pluginName) {
57
+ return {
58
+ registerTool(def) {
59
+ (0, toolRegistry_1.registerExternalTool)(def.name, def.execute, pluginName);
60
+ },
61
+ hooks: {
62
+ preTool(fn) { exports.pluginHooks.preTool.push(fn); },
63
+ postTool(fn) { exports.pluginHooks.postTool.push(fn); },
64
+ onSessionStart(fn) { exports.pluginHooks.onSessionStart.push(fn); },
65
+ onSessionEnd(fn) { exports.pluginHooks.onSessionEnd.push(fn); },
66
+ },
67
+ log(...args) {
68
+ console.log(`[Plugin:${pluginName}]`, ...args);
69
+ },
70
+ };
71
+ }
72
+ // ── Loader ────────────────────────────────────────────────────
73
+ async function loadPlugins(pluginDir) {
74
+ if (!fs.existsSync(pluginDir)) {
75
+ fs.mkdirSync(pluginDir, { recursive: true });
76
+ return;
77
+ }
78
+ const entries = fs.readdirSync(pluginDir).filter(f => {
79
+ if (!f.endsWith('.js'))
80
+ return false; // .js only
81
+ if (f.startsWith('_'))
82
+ return false; // skip _example.js etc.
83
+ return true;
84
+ });
85
+ for (const file of entries) {
86
+ const fullPath = path.resolve(pluginDir, file);
87
+ try {
88
+ // Clear require cache so reload works
89
+ delete require.cache[require.resolve(fullPath)];
90
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
91
+ const def = require(fullPath);
92
+ const name = def.name || path.basename(file, '.js');
93
+ const version = def.version || '0.0.0';
94
+ if (typeof def.init !== 'function') {
95
+ console.warn(`[PluginLoader] ${file}: no init() — skipping`);
96
+ continue;
97
+ }
98
+ const ctx = makeContext(name);
99
+ const dispose = await def.init(ctx);
100
+ exports.loadedFlatPlugins.push({
101
+ name,
102
+ version,
103
+ file: fullPath,
104
+ loadedAt: Date.now(),
105
+ dispose: typeof dispose === 'function' ? dispose : def.dispose,
106
+ });
107
+ console.log(`[PluginLoader] Loaded: ${name} v${version} (${file})`);
108
+ }
109
+ catch (err) {
110
+ console.error(`[PluginLoader] Failed to load ${file}:`, err.message);
111
+ }
112
+ }
113
+ }
114
+ // ── Reload — dispose old plugins then reload all flat plugins ─
115
+ async function reloadPlugins(pluginDir) {
116
+ // Dispose in reverse order
117
+ for (let i = exports.loadedFlatPlugins.length - 1; i >= 0; i--) {
118
+ const p = exports.loadedFlatPlugins[i];
119
+ if (p.dispose) {
120
+ try {
121
+ await p.dispose();
122
+ }
123
+ catch { /* ignore dispose errors */ }
124
+ }
125
+ }
126
+ exports.loadedFlatPlugins.length = 0;
127
+ // Clear hooks contributed by flat plugins (note: subdirectory plugins aren't touched)
128
+ exports.pluginHooks.preTool.length = 0;
129
+ exports.pluginHooks.postTool.length = 0;
130
+ exports.pluginHooks.onSessionStart.length = 0;
131
+ exports.pluginHooks.onSessionEnd.length = 0;
132
+ await loadPlugins(pluginDir);
133
+ }
134
+ // ── Status ────────────────────────────────────────────────────
135
+ function listFlatPlugins() {
136
+ return exports.loadedFlatPlugins.map(p => ({
137
+ name: p.name,
138
+ version: p.version,
139
+ file: path.basename(p.file),
140
+ loadedAt: p.loadedAt,
141
+ }));
142
+ }
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // AUTO-GENERATED by scripts/inject-version.js — do not edit by hand
5
- exports.VERSION = '3.16.2';
5
+ exports.VERSION = '3.17.0';