@aion0/forge 0.1.9 → 0.1.10

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/CLAUDE.md CHANGED
@@ -1,3 +1,46 @@
1
+ ## Project: Forge (@aion0/forge)
2
+
3
+ ### Dev Commands
4
+ ```bash
5
+ # Development (hot-reload)
6
+ pnpm dev
7
+
8
+ # Production (local)
9
+ pnpm build && pnpm start
10
+
11
+ # Publish to npm (bump version in package.json first)
12
+ npm publish --access public --otp=<code>
13
+
14
+ # Install globally from local source (for testing)
15
+ npm install -g /Users/zliu/IdeaProjects/my-workflow
16
+
17
+ # Install from npm
18
+ npm install -g @aion0/forge
19
+
20
+ # Run via npm global install
21
+ forge-server # foreground (auto-builds if needed)
22
+ forge-server --dev # dev mode
23
+ forge-server --background # background, logs to ~/.forge/forge.log
24
+ forge-server --stop # stop background server
25
+ forge-server --rebuild # force rebuild
26
+
27
+ # CLI
28
+ forge # help
29
+ forge password # show today's login password
30
+ forge tasks # list tasks
31
+ forge task <project> "prompt" # submit task
32
+
33
+ # Terminal server runs on port 3001 (auto-started by Next.js)
34
+ # Data directory: ~/.forge/
35
+ # Config: ~/.forge/settings.yaml
36
+ # Env: ~/.forge/.env.local
37
+ ```
38
+
39
+ ### Key Paths
40
+ - Data: `~/.forge/` (settings, db, password, terminal-state, flows, bin)
41
+ - npm package: `@aion0/forge`
42
+ - GitHub: `github.com/aiwatching/forge`
43
+
1
44
  ## Obsidian Vault
2
45
  Location: /Users/zliu/MyDocuments/obsidian-project/Projects/Bastion
3
46
  When I ask about my notes, use bash to search and read files from this directory.
@@ -478,6 +478,7 @@ const WebTerminal = forwardRef<WebTerminalHandle>(function WebTerminal(_props, r
478
478
 
479
479
  {/* Toolbar */}
480
480
  <div className="flex items-center gap-1 px-2 ml-auto">
481
+ <span className="text-[9px] text-gray-600 mr-2">Shift+drag to copy</span>
481
482
  <button onClick={() => onSplit('vertical')} className="text-[10px] px-2 py-0.5 text-gray-400 hover:text-white hover:bg-[#2a2a4a] rounded">
482
483
  Split Right
483
484
  </button>
@@ -828,7 +829,7 @@ const MemoTerminalPane = memo(function TerminalPane({
828
829
  background: '#1a1a2e',
829
830
  foreground: '#e0e0e0',
830
831
  cursor: '#7c5bf0',
831
- selectionBackground: '#7c5bf044',
832
+ selectionBackground: '#7c5bf066',
832
833
  black: '#1a1a2e',
833
834
  red: '#ff6b6b',
834
835
  green: '#69db7c',
@@ -94,8 +94,12 @@ async function poll() {
94
94
  }
95
95
  }
96
96
  }
97
- } catch (err) {
98
- console.error('[telegram] Poll error:', err);
97
+ } catch (err: any) {
98
+ // Network errors (ECONNRESET, fetch failed) are normal during sleep/wake — silent retry
99
+ const isNetworkError = err?.cause?.code === 'ECONNRESET' || err?.message?.includes('fetch failed');
100
+ if (!isNetworkError) {
101
+ console.error('[telegram] Poll error:', err);
102
+ }
99
103
  }
100
104
 
101
105
  pollTimer = setTimeout(poll, 1000);
@@ -188,7 +192,13 @@ async function handleMessage(msg: any) {
188
192
  await handleRetry(chatId, args[0]);
189
193
  break;
190
194
  case '/tunnel':
191
- await handleTunnel(chatId, args[0], args[1], msg.message_id);
195
+ await handleTunnelStatus(chatId);
196
+ break;
197
+ case '/tunnel_start':
198
+ await handleTunnelStart(chatId);
199
+ break;
200
+ case '/tunnel_stop':
201
+ await handleTunnelStop(chatId);
192
202
  break;
193
203
  case '/tunnel_password':
194
204
  await handleTunnelPassword(chatId, args[0], msg.message_id);
@@ -230,7 +240,9 @@ async function sendHelp(chatId: number) {
230
240
  `📝 Submit task:\nproject-name: your instructions\n\n` +
231
241
  `🔧 /cancel <id> /retry <id>\n` +
232
242
  `/projects — list projects\n\n` +
233
- `🌐 /tunnel [start|stop] remote access\n` +
243
+ `🌐 /tunnel — tunnel status\n` +
244
+ `/tunnel_start — start tunnel\n` +
245
+ `/tunnel_stop — stop tunnel\n` +
234
246
  `/tunnel_password <pw> — get login password\n\n` +
235
247
  `Reply number to select`
236
248
  );
@@ -644,57 +656,64 @@ async function handleUnwatch(chatId: number, watcherId?: string) {
644
656
 
645
657
  // ─── Tunnel Commands ─────────────────────────────────────────
646
658
 
647
- async function handleTunnel(chatId: number, action?: string, password?: string, userMsgId?: number) {
659
+ async function handleTunnelStatus(chatId: number) {
648
660
  const settings = loadSettings();
649
- if (String(chatId) !== settings.telegramChatId) {
650
- await send(chatId, '⛔ Unauthorized');
651
- return;
652
- }
661
+ if (String(chatId) !== settings.telegramChatId) { await send(chatId, '⛔ Unauthorized'); return; }
653
662
 
654
- // start/stop require password
655
- if (action === 'start' || action === 'stop') {
656
- if (!settings.telegramTunnelPassword) {
657
- await send(chatId, '⚠️ Set telegram tunnel password in Settings first.');
658
- return;
659
- }
660
- if (!password || password !== settings.telegramTunnelPassword) {
661
- await send(chatId, `⛔ Password required\nUsage: /tunnel ${action} <password>`);
662
- return;
663
- }
664
- // Delete user's message containing password
665
- if (userMsgId) deleteMessageLater(chatId, userMsgId, 0);
663
+ const status = getTunnelStatus();
664
+ if (status.status === 'running' && status.url) {
665
+ await sendHtml(chatId, `🌐 Tunnel running:\n<a href="${status.url}">${status.url}</a>\n\n/tunnel_stop — stop tunnel`);
666
+ } else if (status.status === 'starting') {
667
+ await send(chatId, '⏳ Tunnel is starting...');
668
+ } else {
669
+ await send(chatId, `🌐 Tunnel is ${status.status}\n\n/tunnel_start — start tunnel`);
666
670
  }
671
+ }
667
672
 
668
- if (action === 'start') {
669
- const status = getTunnelStatus();
670
- if (status.status === 'running' && status.url) {
671
- await send(chatId, `🌐 Tunnel already running:\n${status.url}`);
673
+ async function handleTunnelStart(chatId: number) {
674
+ const settings = loadSettings();
675
+ if (String(chatId) !== settings.telegramChatId) { await send(chatId, '⛔ Unauthorized'); return; }
676
+
677
+ // Check if tunnel is already running and still reachable
678
+ const status = getTunnelStatus();
679
+ if (status.status === 'running' && status.url) {
680
+ // Verify it's actually alive
681
+ let alive = false;
682
+ try {
683
+ const controller = new AbortController();
684
+ const timeout = setTimeout(() => controller.abort(), 8000);
685
+ const res = await fetch(status.url, { method: 'HEAD', signal: controller.signal, redirect: 'manual' });
686
+ clearTimeout(timeout);
687
+ alive = res.status > 0;
688
+ } catch {}
689
+
690
+ if (alive) {
691
+ await sendHtml(chatId, `🌐 Tunnel already running:\n<a href="${status.url}">${status.url}</a>`);
672
692
  return;
673
693
  }
674
- await send(chatId, '🌐 Starting tunnel...');
675
- const result = await startTunnel();
676
- if (result.url) {
677
- await send(chatId, '✅ Tunnel started:');
678
- await sendHtml(chatId, `<a href="${result.url}">${result.url}</a>`);
679
- } else {
680
- await send(chatId, `❌ Failed: ${result.error}`);
681
- }
682
- } else if (action === 'stop') {
694
+ // Tunnel process alive but URL unreachable — kill and restart
695
+ await send(chatId, '🌐 Tunnel URL unreachable, restarting...');
683
696
  stopTunnel();
684
- await send(chatId, '🛑 Tunnel stopped');
697
+ }
698
+
699
+ await send(chatId, '🌐 Starting tunnel...');
700
+ const result = await startTunnel();
701
+ if (result.url) {
702
+ await send(chatId, '✅ Tunnel started:');
703
+ await sendHtml(chatId, `<a href="${result.url}">${result.url}</a>`);
685
704
  } else {
686
- // Status (no password needed)
687
- const status = getTunnelStatus();
688
- if (status.status === 'running' && status.url) {
689
- await send(chatId, `🌐 Tunnel running:\n${status.url}\n\n/tunnel stop <pw> — stop tunnel`);
690
- } else if (status.status === 'starting') {
691
- await send(chatId, '⏳ Tunnel is starting...');
692
- } else {
693
- await send(chatId, `🌐 Tunnel is ${status.status}\n\n/tunnel start <pw> — start tunnel`);
694
- }
705
+ await send(chatId, `❌ Failed: ${result.error}`);
695
706
  }
696
707
  }
697
708
 
709
+ async function handleTunnelStop(chatId: number) {
710
+ const settings = loadSettings();
711
+ if (String(chatId) !== settings.telegramChatId) { await send(chatId, '⛔ Unauthorized'); return; }
712
+
713
+ stopTunnel();
714
+ await send(chatId, '🛑 Tunnel stopped');
715
+ }
716
+
698
717
  async function handleTunnelPassword(chatId: number, password?: string, userMsgId?: number) {
699
718
  const settings = loadSettings();
700
719
  if (String(chatId) !== settings.telegramChatId) {
@@ -861,7 +880,9 @@ async function setBotCommands(token: string) {
861
880
  { command: 'task', description: 'Create task: /task project prompt' },
862
881
  { command: 'sessions', description: 'Browse sessions' },
863
882
  { command: 'projects', description: 'List projects' },
864
- { command: 'tunnel', description: 'Tunnel status / start / stop' },
883
+ { command: 'tunnel', description: 'Tunnel status' },
884
+ { command: 'tunnel_start', description: 'Start tunnel' },
885
+ { command: 'tunnel_stop', description: 'Stop tunnel' },
865
886
  { command: 'tunnel_password', description: 'Get login password' },
866
887
  { command: 'watch', description: 'Monitor session' },
867
888
  { command: 'watchers', description: 'List watchers' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aion0/forge",
3
- "version": "0.1.9",
3
+ "version": "0.1.10",
4
4
  "description": "Unified AI workflow platform — multi-model task orchestration, persistent sessions, web terminal, remote access",
5
5
  "type": "module",
6
6
  "scripts": {