-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvoidide-genesis-v2.html
More file actions
1917 lines (1620 loc) · 67.8 KB
/
voidide-genesis-v2.html
File metadata and controls
1917 lines (1620 loc) · 67.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>🌟 VoidIDE Genesis v2.0 - Complete Self-Creating IDE</title>
<!-- Monaco Editor CDN -->
<script src="https://cdn.jsdelivr.net/npm/monaco-editor@0.44.0/min/vs/loader.js"></script>
<!-- JSZip Library (AMD競合回避のため事前読み込み) -->
<script>
// AMD競合を一時的に回避
const originalDefine = window.define;
window.define = undefined;
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script>
// defineを復元
window.define = originalDefine;
</script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
background: #1e1e1e;
color: #d4d4d4;
height: 100vh;
overflow: hidden;
}
.ide-container {
display: grid;
grid-template-columns: 250px 1fr 300px;
grid-template-rows: 40px 1fr 250px;
height: 100vh;
gap: 1px;
background: #3e3e42;
}
.title-bar {
grid-column: 1 / -1;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
display: flex;
align-items: center;
padding: 0 15px;
font-weight: bold;
font-size: 14px;
}
.title-bar .version {
margin-left: auto;
font-size: 12px;
opacity: 0.8;
}
.sidebar {
background: #252526;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.main-editor {
background: #1e1e1e;
display: flex;
flex-direction: column;
}
.right-panel {
background: #252526;
overflow-y: auto;
display: flex;
flex-direction: column;
}
.bottom-panel {
grid-column: 1 / -1;
background: #1e1e1e;
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 1px;
background: #3e3e42;
}
.toolbar {
height: 40px;
background: #2d2d30;
border-bottom: 1px solid #3e3e42;
display: flex;
align-items: center;
padding: 0 15px;
gap: 10px;
}
.toolbar button {
background: #0e639c;
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
transition: all 0.2s;
}
.toolbar button:hover {
background: #1177bb;
transform: translateY(-1px);
}
.toolbar button:disabled {
background: #5a5a5a;
cursor: not-allowed;
transform: none;
}
.toolbar .status {
margin-left: auto;
font-size: 12px;
color: #cccccc;
display: flex;
align-items: center;
gap: 8px;
}
.status-indicator {
width: 8px;
height: 8px;
border-radius: 50%;
background: #888;
}
.status-indicator.running {
background: #73c991;
animation: pulse 1s infinite;
}
.status-indicator.error {
background: #f48771;
}
@keyframes pulse {
0% { opacity: 1; }
50% { opacity: 0.5; }
100% { opacity: 1; }
}
.editor-container {
flex: 1;
position: relative;
}
.monaco-editor-container {
width: 100%;
height: 100%;
}
.panel {
background: #252526;
overflow-y: auto;
padding: 15px;
}
.panel h3 {
margin: 0 0 15px 0;
font-size: 14px;
color: #cccccc;
border-bottom: 1px solid #3e3e42;
padding-bottom: 8px;
}
.file-tree {
list-style: none;
}
.file-item {
padding: 4px 8px;
cursor: pointer;
border-radius: 3px;
font-size: 13px;
transition: background 0.2s;
}
.file-item:hover {
background: #2a2d2e;
}
.file-item.active {
background: #094771;
color: #4fc1ff;
}
.plugin-list {
list-style: none;
}
.plugin-item {
background: #2d2d30;
margin: 5px 0;
padding: 10px;
border-radius: 4px;
font-size: 12px;
border-left: 3px solid #4fc1ff;
}
.plugin-item.error {
border-left-color: #f48771;
}
.plugin-item.warning {
border-left-color: #dcdcaa;
}
.plugin-name {
font-weight: bold;
color: #4fc1ff;
margin-bottom: 4px;
}
.plugin-status {
color: #cccccc;
font-size: 11px;
}
.tab-container {
display: flex;
background: #2d2d30;
border-bottom: 1px solid #3e3e42;
}
.tab {
padding: 8px 16px;
cursor: pointer;
border-right: 1px solid #3e3e42;
font-size: 12px;
color: #cccccc;
transition: all 0.2s;
}
.tab:hover {
background: #3e3e42;
}
.tab.active {
background: #094771;
color: #4fc1ff;
}
.tab-content {
flex: 1;
overflow: hidden;
}
.visualization-container {
height: 100%;
position: relative;
}
.loading {
display: flex;
align-items: center;
justify-content: center;
height: 100px;
color: #888;
font-size: 14px;
}
.welcome-panel {
padding: 20px;
text-align: center;
background: linear-gradient(135deg, #0e639c, #1177bb);
color: white;
margin: 15px;
border-radius: 8px;
}
.welcome-panel h2 {
margin: 0 0 10px 0;
font-size: 18px;
}
.welcome-panel p {
margin: 0;
opacity: 0.9;
font-size: 13px;
}
.quick-actions {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 8px;
margin: 15px;
}
.quick-action {
background: #2d2d30;
border: 1px solid #3e3e42;
color: #cccccc;
padding: 10px;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
transition: all 0.2s;
text-align: center;
}
.quick-action:hover {
background: #3e3e42;
border-color: #4fc1ff;
}
.stats-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin: 15px;
}
.stat-card {
background: #2d2d30;
padding: 12px;
border-radius: 4px;
text-align: center;
}
.stat-value {
font-size: 18px;
font-weight: bold;
color: #4fc1ff;
}
.stat-label {
font-size: 11px;
color: #cccccc;
text-transform: uppercase;
}
.notification {
position: fixed;
top: 20px;
right: 20px;
background: #2d2d30;
color: #cccccc;
padding: 12px 16px;
border-radius: 6px;
border-left: 3px solid #4fc1ff;
box-shadow: 0 4px 12px rgba(0,0,0,0.3);
z-index: 1000;
opacity: 0;
transform: translateX(100%);
transition: all 0.3s ease;
}
.notification.show {
opacity: 1;
transform: translateX(0);
}
.notification.error {
border-left-color: #f48771;
}
.notification.success {
border-left-color: #73c991;
}
.scrollbar-thin {
scrollbar-width: thin;
scrollbar-color: #3e3e42 #252526;
}
.scrollbar-thin::-webkit-scrollbar {
width: 6px;
}
.scrollbar-thin::-webkit-scrollbar-track {
background: #252526;
}
.scrollbar-thin::-webkit-scrollbar-thumb {
background: #3e3e42;
border-radius: 3px;
}
.scrollbar-thin::-webkit-scrollbar-thumb:hover {
background: #4e4e52;
}
</style>
</head>
<body>
<div class="ide-container">
<!-- タイトルバー -->
<div class="title-bar">
🌟 VoidIDE Genesis v2.0 - Self-Creating IDE with Advanced Analytics
<div class="version">Phase 2 Complete | Build 2025.07.06</div>
</div>
<!-- 左サイドバー -->
<div class="sidebar scrollbar-thin">
<div class="welcome-panel">
<h2>🧠 Genesis v2.0</h2>
<p>自己創造システム + 高度解析</p>
</div>
<div class="panel">
<h3>📁 Project Explorer</h3>
<ul class="file-tree">
<li class="file-item active" data-file="main.js" onclick="selectFile('main.js')">
📄 main.js
</li>
<li class="file-item" data-file="template" onclick="selectFile('template')">
📋 Plugin Template
</li>
<li class="file-item" data-file="advanced" onclick="selectFile('advanced')">
🚀 Advanced Template
</li>
</ul>
</div>
<div class="stats-grid">
<div class="stat-card">
<div class="stat-value" id="pluginCount">0</div>
<div class="stat-label">Plugins</div>
</div>
<div class="stat-card">
<div class="stat-value" id="messageCount">0</div>
<div class="stat-label">Messages</div>
</div>
<div class="stat-card">
<div class="stat-value" id="uptime">0s</div>
<div class="stat-label">Uptime</div>
</div>
<div class="stat-card">
<div class="stat-value" id="performance">100%</div>
<div class="stat-label">Performance</div>
</div>
</div>
<div class="quick-actions">
<button class="quick-action" onclick="loadBasicTemplate()">
📋 Basic Template
</button>
<button class="quick-action" onclick="loadAdvancedTemplate()">
🚀 Advanced Template
</button>
<button class="quick-action" onclick="showCodeHelper()">
💡 Code Helper
</button>
<button class="quick-action" onclick="openSettings()">
⚙️ Settings
</button>
</div>
</div>
<!-- メインエディタ -->
<div class="main-editor">
<div class="toolbar">
<button id="runButton" onclick="executeCode()">
▶️ Run (Ctrl+Enter)
</button>
<button id="stopButton" onclick="stopExecution()" disabled>
⏹️ Stop
</button>
<button onclick="saveCode()" title="Save project to localStorage (use Projects→Export ZIP for file)">
💾 Save
</button>
<button onclick="loadProject()" title="Load project from ZIP file">
📂 Load
</button>
<button onclick="formatCode()">
🎨 Format
</button>
<button onclick="toggleAnalytics()">
📊 Analytics
</button>
<div class="status">
<span class="status-indicator" id="statusIndicator"></span>
<span id="statusText">Ready</span>
</div>
</div>
<div class="editor-container">
<div id="monaco-editor" class="monaco-editor-container"></div>
</div>
</div>
<!-- 右パネル -->
<div class="right-panel scrollbar-thin">
<div class="tab-container">
<div class="tab active" data-tab="plugins">🔧 Plugins</div>
<div class="tab" data-tab="analytics">📊 Analytics</div>
<div class="tab" data-tab="projects">🗂️ Projects</div>
</div>
<div class="tab-content">
<div id="pluginsTab" class="panel">
<h3>🔧 Active Plugins</h3>
<ul class="plugin-list" id="pluginsList">
<li class="plugin-item">
<div class="plugin-name">VoidIDE Genesis</div>
<div class="plugin-status">✅ System Plugin - Always Active</div>
</li>
</ul>
</div>
<div id="analyticsTab" class="panel" style="display: none;">
<h3>📊 Real-time Analytics</h3>
<div id="analyticsContent">
<div class="loading">Loading analytics...</div>
</div>
</div>
<div id="projectsTab" class="panel" style="display: none;">
<h3>🗂️ Project Manager</h3>
<div id="projectManagerContainer" class="visualization-container">
<div class="loading">Loading project manager...</div>
</div>
</div>
</div>
</div>
<!-- ボトムパネル -->
<div class="bottom-panel">
<!-- 出力・ログ -->
<div class="panel">
<h3>📝 Output & Logs</h3>
<div id="output" class="scrollbar-thin" style="height: 180px; overflow-y: auto; font-family: monospace; font-size: 12px; line-height: 1.4;"></div>
</div>
<!-- メッセージフロー可視化 -->
<div class="panel">
<h3>🌊 Message Flow</h3>
<div id="messageVisualization" class="visualization-container">
<div class="loading">Initializing visualization...</div>
</div>
</div>
<!-- パフォーマンス監視 -->
<div class="panel">
<h3>⚡ Performance Monitor</h3>
<div id="performanceMonitor" class="visualization-container">
<div class="loading">Starting performance monitoring...</div>
</div>
</div>
</div>
</div>
<!-- 通知システム -->
<div id="notification" class="notification"></div>
<script type="module">
import { voidCore, createPlugin, Message } from './src/index.js';
import { MessageFlowVisualizer } from './src/message-flow-visualizer.js';
import { PluginMonitorDashboard } from './src/plugin-monitor-dashboard.js';
import { PerformanceMetricsSystem } from './src/performance-metrics-system.js';
import { ProjectManager } from './src/project-manager.js';
// グローバル変数
let monacoEditor = null;
let voidIDEPlugin = null;
let messageVisualizer = null;
let pluginMonitor = null;
let performanceMonitor = null;
let projectManager = null;
let startTime = Date.now();
let executionCount = 0;
let pluginCount = 0;
let messageCount = 0;
let isExecuting = false;
let currentExecutionAbortController = null;
let runningPlugins = new Map(); // 実行中のプラグインを追跡
// Monaco Editorの初期化
require.config({ paths: { vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.44.0/min/vs' }});
require(['vs/editor/editor.main'], function() {
initializeVoidIDE();
});
async function initializeVoidIDE() {
try {
showNotification('🚀 Initializing VoidIDE Genesis v2.0...', 'info');
// VoidIDEプラグインを作成
voidIDEPlugin = createPlugin({
pluginId: 'void-ide-genesis-v2',
name: 'VoidIDE Genesis v2.0',
version: '2.0.0',
capabilities: ['code-editor', 'plugin-builder', 'runtime-eval', 'analytics', 'visualization']
}, {
async run() {
await this.initialize();
this.log('🌟 VoidIDE Genesis v2.0 initialized!');
// 高度なメッセージ監視
this.on('Notice', '*', (message) => {
messageCount++;
updateStats();
});
this.on('Notice', 'plugin.created', (message) => {
updatePluginsList();
showNotification(`🔧 Plugin created: ${message.payload.pluginId}`, 'success');
});
}
});
// VoidCoreに登録して実行
voidCore.registerPlugin(voidIDEPlugin);
await voidIDEPlugin.run();
// Monaco Editorを初期化
await initializeMonacoEditor();
// 高度な可視化システムを初期化
await initializeVisualizationSystems();
// UI イベントリスナー設定
setupUIEventListeners();
showNotification('✅ VoidIDE Genesis v2.0 ready!', 'success');
updateStatus('Ready', 'idle');
// 統計更新開始
setInterval(updateStats, 1000);
} catch (error) {
log(`❌ Initialization error: ${error.message}`, 'error');
showNotification(`Initialization failed: ${error.message}`, 'error');
}
}
async function initializeMonacoEditor() {
monacoEditor = monaco.editor.create(document.getElementById('monaco-editor'), {
value: getAdvancedTemplate(),
language: 'javascript',
theme: 'vs-dark',
fontSize: 14,
automaticLayout: true,
minimap: { enabled: true },
wordWrap: 'on',
bracketPairColorization: { enabled: true },
guides: { bracketPairs: true, indentation: true }
});
// グローバルアクセス用に window に代入
window.monacoEditor = monacoEditor;
console.log('🎨 Monaco Editor assigned to window.monacoEditor');
// 高度なコード補完設定
setupAdvancedCodeCompletion();
// エディタイベント
monacoEditor.onDidChangeModelContent(() => {
updateStatus('Modified', 'idle');
});
// キーボードショートカット
monacoEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => {
executeCode();
});
monacoEditor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KEY_S, () => {
saveCode();
});
}
async function initializeVisualizationSystems() {
try {
// メッセージフロー可視化
messageVisualizer = new MessageFlowVisualizer(
document.getElementById('messageVisualization'),
voidCore
);
await messageVisualizer.initialize();
messageVisualizer.start();
// プラグイン監視ダッシュボード
pluginMonitor = new PluginMonitorDashboard(
document.getElementById('analyticsContent'),
voidCore
);
await pluginMonitor.initialize();
// パフォーマンス監視システム
performanceMonitor = new PerformanceMetricsSystem(voidCore);
await performanceMonitor.initialize(document.getElementById('performanceMonitor'));
// プロジェクト管理システム
projectManager = new ProjectManager(voidCore);
console.log('🔧 Initializing ProjectManager...');
const projectManagerInit = await projectManager.initialize(document.getElementById('projectManagerContainer'));
console.log('🔧 ProjectManager initialized:', projectManagerInit);
console.log('🔧 ProjectManager currentProject:', projectManager.currentProject);
// 初期化が失敗した場合、手動で currentProject を設定
if (!projectManager.currentProject) {
console.log('⚠️ Manual currentProject initialization...');
projectManager.currentProject = { ...projectManager.defaultProject };
console.log('🔧 Manual currentProject set:', projectManager.currentProject);
}
log('🎨 Advanced visualization systems initialized', 'success');
} catch (error) {
log(`❌ Visualization initialization error: ${error.message}`, 'error');
}
}
function setupAdvancedCodeCompletion() {
monaco.languages.registerCompletionItemProvider('javascript', {
provideCompletionItems: (model, position) => {
const word = model.getWordUntilPosition(position);
const range = {
startLineNumber: position.lineNumber,
endLineNumber: position.lineNumber,
startColumn: word.startColumn,
endColumn: word.endColumn
};
const suggestions = [
{
label: 'voidcore-analytics-plugin',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: getAnalyticsPluginTemplate(),
documentation: 'Advanced analytics plugin template',
range: range
},
{
label: 'voidcore-visualizer-plugin',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: getVisualizerPluginTemplate(),
documentation: 'Visualization plugin template',
range: range
},
{
label: 'voidcore-monitor-plugin',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: getMonitorPluginTemplate(),
documentation: 'Monitoring plugin template',
range: range
}
];
return { suggestions };
}
});
}
async function executeCode() {
const runButton = document.getElementById('runButton');
const stopButton = document.getElementById('stopButton');
let skipStopButtonUpdate = false;
if (isExecuting) {
showNotification('Code is already executing...', 'warning');
return;
}
// 連打防止のため、短時間だけRunボタンを無効に
runButton.disabled = true;
setTimeout(() => {
runButton.disabled = false;
}, 1000); // 1秒後に再有効化
try {
isExecuting = true;
updateStatus('Executing...', 'running');
// AbortController for cancellation
currentExecutionAbortController = new AbortController();
const code = monacoEditor.getValue();
log('🚀 Executing advanced code...', 'info');
const result = await safeExecuteCode(code, currentExecutionAbortController.signal);
if (result.success) {
log('✅ Code executed successfully!', 'success');
if (result.plugin) {
pluginCount++;
// 同じIDのプラグインが複数実行される場合、ユニークIDを作成
let uniquePluginId = result.plugin.pluginId;
let counter = 1;
while (runningPlugins.has(uniquePluginId)) {
uniquePluginId = `${result.plugin.pluginId}-${counter}`;
counter++;
}
// ユニークIDを設定
result.plugin.uniqueId = uniquePluginId;
// 実行中プラグインとして追跡
runningPlugins.set(uniquePluginId, result.plugin);
log(`🔧 Plugin created: ${result.plugin.pluginId} (unique: ${uniquePluginId})`, 'success');
updatePluginsList();
showNotification(`Plugin ${result.plugin.pluginId} created successfully!`, 'success');
// プラグインが実行開始される時にStopボタンを有効に
updateStatus('Plugin Running', 'running');
stopButton.disabled = false;
// プラグインが実行中の場合、finallyでStopボタン状態を変更しない
if (result.plugin.running) {
log('🎯 Plugin is running, Skip stop button update in finally', 'info');
skipStopButtonUpdate = true;
}
}
updateStatus('Success', 'idle');
} else if (result.aborted) {
log('⏹️ Execution stopped by user', 'warn');
updateStatus('Stopped', 'idle');
showNotification('Execution stopped', 'info');
} else {
log(`❌ Execution error: ${result.error}`, 'error');
updateStatus('Error', 'error');
showNotification(`Execution failed: ${result.error}`, 'error');
}
executionCount++;
} catch (error) {
if (error.name === 'AbortError') {
log('⏹️ Execution aborted', 'warn');
updateStatus('Stopped', 'idle');
showNotification('Execution stopped', 'info');
} else {
log(`❌ Execution failed: ${error.message}`, 'error');
updateStatus('Error', 'error');
showNotification(`Execution failed: ${error.message}`, 'error');
}
} finally {
// 実行状態をリセット
isExecuting = false;
// プラグインが実行中の場合はStopボタン状態を変更しない
if (!skipStopButtonUpdate) {
setTimeout(() => {
updateStopButtonState();
}, 100);
} else {
log('⏭️ Skipping stop button update (plugin still running)', 'info');
}
}
}
function updateStopButtonState() {
const stopButton = document.getElementById('stopButton');
// デバッグ: 現在の実行中プラグインを表示
const runningPluginsList = Array.from(runningPlugins.keys());
log(`🔍 Current running plugins: [${runningPluginsList.join(', ')}] (${runningPluginsList.length} total)`, 'info');
// プラグインが実行中かどうかチェック
const hasRunningPlugins = Array.from(runningPlugins.values()).some(plugin => plugin.running);
if (hasRunningPlugins) {
// プラグインが実行中の場合、Stopボタンは有効
stopButton.disabled = false;
log('🔄 Plugin(s) still running, Stop button remains active', 'info');
} else {
// プラグインが実行中でない場合、Stopボタンを無効に
stopButton.disabled = true;
currentExecutionAbortController = null;
log('⏸️ No running plugins, Stop button disabled', 'info');
}
}
async function stopExecution() {
log('⏹️ Stop button pressed...', 'warn');
// 現在の実行を中止
if (currentExecutionAbortController) {
currentExecutionAbortController.abort();
log('🚫 Current execution aborted', 'warn');
}
// 実行中のプラグインを停止
const runningCount = runningPlugins.size;
if (runningCount > 0) {
log(`🛑 Stopping ${runningCount} running plugin(s)...`, 'warn');
await stopRunningPlugins();
} else {
log('ℹ️ No running plugins to stop', 'info');
}
// ボタン状態を更新
document.getElementById('stopButton').disabled = true;
updateStatus('Stopped', 'idle');
showNotification('All plugins stopped', 'success');
}
async function stopRunningPlugins() {
const pluginsToStop = Array.from(runningPlugins.values());
for (const plugin of pluginsToStop) {
try {
// プラグインに停止通知を送信
if (typeof plugin.shutdown === 'function') {
await plugin.shutdown('User requested stop');
log(`🛑 Plugin stopped: ${plugin.pluginId} (${plugin.uniqueId || plugin.pluginId})`, 'info');
}
// VoidCoreから削除
if (voidCore.unregisterPlugin) {
voidCore.unregisterPlugin(plugin.pluginId);
}
// 追跡リストから削除(uniqueIdを使用)
const uniqueId = plugin.uniqueId || plugin.pluginId;
runningPlugins.delete(uniqueId);
} catch (error) {
log(`❌ Error stopping plugin ${plugin.pluginId}: ${error.message}`, 'error');
}
}
// プラグインリスト更新
updatePluginsList();
pluginCount = Math.max(0, pluginCount - pluginsToStop.length);
}
async function stopSpecificPlugin(pluginId) {
const plugin = runningPlugins.get(pluginId);
if (!plugin) {
showNotification(`Plugin ${pluginId} not found`, 'error');
return;
}
try {
if (typeof plugin.shutdown === 'function') {
await plugin.shutdown('Manual stop');
}
if (voidCore.unregisterPlugin) {
voidCore.unregisterPlugin(pluginId);
}
runningPlugins.delete(pluginId);
updatePluginsList();
pluginCount--;
log(`🛑 Plugin stopped: ${pluginId}`, 'success');
showNotification(`Plugin ${pluginId} stopped`, 'success');
} catch (error) {
log(`❌ Error stopping plugin ${pluginId}: ${error.message}`, 'error');
showNotification(`Failed to stop plugin: ${error.message}`, 'error');
}
}
async function safeExecuteCode(code, abortSignal = null) {
try {
// 中断チェック
if (abortSignal && abortSignal.aborted) {
return { success: false, aborted: true };
}
const wrappedCode = `
const { createPlugin, voidCore, Message } = voidcoreAPI;
const result = (function() {
${code}
})();
return result;
`;
const sandboxGlobals = {
console: {
log: (...args) => log(`[User] ${args.join(' ')}`, 'info'),
warn: (...args) => log(`[User] ${args.join(' ')}`, 'warn'),
error: (...args) => log(`[User] ${args.join(' ')}`, 'error')
},
voidcoreAPI: {
createPlugin,
voidCore,
Message
},
setTimeout,
setInterval,
clearTimeout,
clearInterval,
Date,
Math,
JSON
};
// 中断チェック
if (abortSignal && abortSignal.aborted) {