dsh-aiterm 0.5.0 → 0.5.12

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.
@@ -2445,13 +2445,62 @@ await closePanelViaBar()
2445
2445
  }
2446
2446
 
2447
2447
  // ── history panel: export (current / all) + auto-log switch ────────────
2448
- scene.handlers.set('history.sessions', async () => ({
2449
- sessions: [
2450
- { id: 'st-ssh', title: 'web-1', transport: 'ssh', host: '10.0.0.5', port: 22, username: 'root', createdAt: now - 60_000, bytes: 2048, lastTs: now },
2451
- ],
2448
+ let raceResolve = null
2449
+ let raceReject = null
2450
+ let raceActive = false
2451
+ let legacyRaceResolve = null
2452
+ let legacyRaceActive = false
2453
+ let reloadResolve = null
2454
+ let reloadActive = false
2455
+ let legacyQueryResolve = null
2456
+ let legacyQueryActive = false
2457
+ let normalQueryResolve = null
2458
+ let normalQueryActive = false
2459
+ scene.handlers.set('history.sessions', async (params) => {
2460
+ if (reloadActive && (params.offset === undefined || params.offset === 0)) {
2461
+ return await new Promise((resolve) => { reloadResolve = resolve })
2462
+ }
2463
+ if (raceActive && params.offset === 1) {
2464
+ return await new Promise((resolve, reject) => { raceResolve = resolve; raceReject = reject })
2465
+ }
2466
+ if (params.offset === 1 && params.snapshot === 'snap-1') {
2467
+ return { sessions: [], total: 2, truncated: true, stale: true, snapshot: 'snap-2' }
2468
+ }
2469
+ return {
2470
+ sessions: [
2471
+ { id: 'st-ssh', title: 'web-1', transport: 'ssh', host: '10.0.0.5', port: 22, username: 'root', createdAt: now - 60_000, bytes: 2048, lastTs: now },
2472
+ ],
2473
+ total: 2,
2474
+ truncated: true,
2475
+ snapshot: 'snap-1',
2476
+ }
2477
+ })
2478
+ scene.handlers.set('history.query', async () => {
2479
+ if (normalQueryActive) return await new Promise((resolve) => { normalQueryResolve = resolve })
2480
+ return { matches: [], scannedBytes: 0 }
2481
+ })
2482
+ scene.handlers.set('history.legacy.sessions', async () => {
2483
+ if (legacyRaceActive) {
2484
+ return await new Promise((resolve) => { legacyRaceResolve = resolve })
2485
+ }
2486
+ return {
2487
+ sessions: [
2488
+ { id: 'st-legacy', title: 'old-unowned', transport: 'ssh', host: 'old.example', port: 22, username: 'old', createdAt: now - 120_000, bytes: 100, lastTs: now - 100_000 },
2489
+ ],
2490
+ total: 1,
2491
+ truncated: false,
2492
+ snapshot: 'legacy-snap-1',
2493
+ }
2494
+ })
2495
+ scene.handlers.set('history.legacy.query', async () => {
2496
+ if (legacyQueryActive) return await new Promise((resolve) => { legacyQueryResolve = resolve })
2497
+ return { matches: [{ at: now, line: 'LEGACY-OUT', before: [], after: [] }], scannedBytes: 50, truncated: false }
2498
+ })
2499
+ scene.handlers.set('history.legacy.export', async (params) => ({
2500
+ dir: '/home/u/.dsh/aiterm/exports',
2501
+ files: [{ sessionId: params.sessionId, path: '/home/u/.dsh/aiterm/exports/st-legacy-old-20261023.log', bytes: 64, lines: 2 }],
2452
2502
  }))
2453
- scene.handlers.set('history.query', async () => ({ matches: [], scannedBytes: 0 }))
2454
- scene.handlers.set('autolog.get', async () => ({ enabled: false, dir: '/home/u/.dsh/aiterm/logs' }))
2503
+ scene.handlers.set('autolog.get', async () => ({ enabled: false, dir: '/home/u/.dsh/aiterm/logs', needsReview: true }))
2455
2504
  scene.handlers.set('autolog.set', async (params) => ({ enabled: params.enabled === true, dir: '/home/u/.dsh/aiterm/logs' }))
2456
2505
  scene.handlers.set('history.export', async (params) => ({
2457
2506
  dir: '/home/u/.dsh/aiterm/exports',
@@ -2486,6 +2535,7 @@ await closePanelViaBar()
2486
2535
  assert.ok(call, 'exporting must call history.export')
2487
2536
  assert.equal(call.params.all, undefined, 'exporting one session must not ask for all')
2488
2537
  assert.ok(call.params.sessionId, 'exporting one session must name it')
2538
+ assert.equal(call.params.owner, 'session-smoke', 'history.export must be scoped to the DSH session')
2489
2539
  const flat = textOf(lastTree)
2490
2540
  assert.ok(flat.includes('-web-1-'), 'the exported file path must be rendered, got: ' + flat.slice(-200))
2491
2541
  assert.ok(flat.includes(dict('historyExportLines').split('{')[0]), 'the exported line count must render')
@@ -2498,6 +2548,122 @@ await closePanelViaBar()
2498
2548
  const call = scene.rpcCalls.slice(mark).find((entry) => entry.method === 'history.export')
2499
2549
  assert.ok(call, 'export-all must call history.export')
2500
2550
  assert.equal(call.params.all, true, 'export-all must pass all: true')
2551
+ assert.equal(call.params.owner, 'session-smoke', 'export-all must be scoped to the DSH session')
2552
+ }
2553
+
2554
+ // Paging with a stale snapshot must reload rather than silently skip rows.
2555
+ {
2556
+ const mark = scene.rpcCalls.length
2557
+ await clickNode(findButtonByText(dict('historyLoadMore')), 'load more history')
2558
+ await settle('history stale page handled')
2559
+ const calls = scene.rpcCalls.slice(mark).filter((entry) => entry.method === 'history.sessions')
2560
+ assert.ok(calls.some((entry) => entry.params.offset === 1 && entry.params.snapshot === 'snap-1'), 'load more must send the snapshot and raw offset')
2561
+ assert.ok(calls.some((entry) => (entry.params.offset === undefined || entry.params.offset === 0)), 'a stale response must reload the first page')
2562
+ assert.ok(textOf(lastTree).includes(dict('historyStaleReload').slice(0, 8)), 'the stale reload must be explained')
2563
+ }
2564
+
2565
+ // A normal loadMore that fails after switching to a slow legacy load must not
2566
+ // paint, error, or leave a clickable old Load more (real bundle async race).
2567
+ {
2568
+ raceActive = true
2569
+ legacyRaceActive = true
2570
+ await clickNode(findButtonByText(dict('historyLoadMore')), 'start racing normal page')
2571
+ await settle('normal page pending')
2572
+ await clickNode(findButtonByText(dict('historyLegacyEntry')), 'switch to legacy while normal page pending')
2573
+ await settle('legacy page pending')
2574
+ assert.ok(!findButtonByText(dict('historyLoadMore')), 'the old Load more must disappear on source switch')
2575
+ assert.ok(
2576
+ !collect(lastTree, (node) => node.props && node.props.role === 'option').some((node) => textOf(node).includes('web-1')),
2577
+ 'the old normal list must be cleared on source switch',
2578
+ )
2579
+ assert.equal(typeof legacyRaceResolve, 'function')
2580
+ assert.equal(typeof raceReject, 'function')
2581
+ raceReject(new Error('late normal failure'))
2582
+ await settle('late normal failure ignored')
2583
+ assert.equal(textOf(lastTree).includes('late normal failure'), false, 'a late normal failure must not paint the legacy page')
2584
+ legacyRaceResolve({ sessions: [{ id: 'st-legacy', title: 'old-unowned', transport: 'ssh', host: 'old.example', port: 22, username: 'old', createdAt: now - 120_000, bytes: 100, lastTs: now - 100_000 }], total: 1, truncated: false, snapshot: 'legacy-snap-2' })
2585
+ await settle('slow legacy page resolved')
2586
+ assert.ok(textOf(lastTree).includes('old-unowned'), 'the legacy page must render after its slow response')
2587
+ raceActive = false
2588
+ legacyRaceActive = false
2589
+ await clickNode(findButtonByText(dict('historyLegacyBack')), 'return from race legacy')
2590
+ await settle('returned to normal history')
2591
+ }
2592
+
2593
+ // A delayed query from the old source must not paint into the new source.
2594
+ {
2595
+ await clickNode(findButtonByText(dict('historyLegacyEntry')), 'legacy for delayed query')
2596
+ await settle('legacy query baseline')
2597
+ legacyQueryActive = true
2598
+ await clickNode(findButtonByText('old-unowned'), 'trigger delayed legacy query')
2599
+ await settle('legacy query pending')
2600
+ await clickNode(findButtonByText(dict('historyLegacyBack')), 'switch to normal while legacy query pending')
2601
+ await settle('normal after legacy query')
2602
+ assert.equal(typeof legacyQueryResolve, 'function')
2603
+ legacyQueryResolve({ matches: [{ at: now, line: 'STALE-LEGACY-QUERY', before: [], after: [] }], scannedBytes: 10, truncated: false })
2604
+ await settle('stale legacy query resolved')
2605
+ assert.equal(textOf(lastTree).includes('STALE-LEGACY-QUERY'), false, 'a stale legacy query must not paint into normal')
2606
+
2607
+ normalQueryActive = true
2608
+ const webOption = collect(lastTree, (node) => node.type === 'button' && node.props && node.props.role === 'option' && textOf(node).includes('web-1'))[0]
2609
+ assert.ok(webOption, 'the normal history option must be selectable')
2610
+ await clickNode(webOption, 'trigger delayed normal query')
2611
+ await settle('normal query pending')
2612
+ await clickNode(findButtonByText(dict('historyLegacyEntry')), 'switch to legacy while normal query pending')
2613
+ await settle('legacy after normal query')
2614
+ assert.equal(typeof normalQueryResolve, 'function')
2615
+ normalQueryResolve({ matches: [{ at: now, line: 'STALE-NORMAL-QUERY', before: [], after: [] }], scannedBytes: 10, truncated: false })
2616
+ await settle('stale normal query resolved')
2617
+ assert.equal(textOf(lastTree).includes('STALE-NORMAL-QUERY'), false, 'a stale normal query must not paint into legacy')
2618
+ legacyQueryActive = false
2619
+ normalQueryActive = false
2620
+ await clickNode(findButtonByText(dict('historyLegacyBack')), 'return after delayed query')
2621
+ await settle('returned after delayed query')
2622
+ }
2623
+
2624
+ // Explicit human-only legacy view: owner-bound GUI still reaches it.
2625
+ {
2626
+ const mark = scene.rpcCalls.length
2627
+ await clickNode(findButtonByText(dict('historyLegacyEntry')), 'open legacy history')
2628
+ await settle('legacy history opened')
2629
+ const listCall = scene.rpcCalls.slice(mark).find((entry) => entry.method === 'history.legacy.sessions')
2630
+ assert.ok(listCall, 'the legacy button must call history.legacy.sessions')
2631
+ assert.equal(listCall.params.owner, undefined, 'the legacy view is an explicit human path, not an owner-scoped call')
2632
+ const queryCall = scene.rpcCalls.slice(mark).find((entry) => entry.method === 'history.legacy.query')
2633
+ assert.ok(queryCall, 'selecting legacy history must call history.legacy.query')
2634
+ assert.equal(queryCall.params.sessionId, 'st-legacy')
2635
+ assert.ok(textOf(lastTree).includes(dict('historyLegacyHint').slice(0, 8)), 'the legacy view must explain its boundary')
2636
+
2637
+ const exportMark = scene.rpcCalls.length
2638
+ await clickNode(findButtonByText(dict('historyExportOne')), 'export legacy session')
2639
+ const exportCall = scene.rpcCalls.slice(exportMark).find((entry) => entry.method === 'history.legacy.export')
2640
+ assert.ok(exportCall, 'exporting legacy history must use history.legacy.export')
2641
+ assert.equal(exportCall.params.sessionId, 'st-legacy')
2642
+
2643
+ const backMark = scene.rpcCalls.length
2644
+ await clickNode(findButtonByText(dict('historyLegacyBack')), 'leave legacy history')
2645
+ await settle('legacy history closed')
2646
+ assert.ok(
2647
+ scene.rpcCalls.slice(backMark).some((entry) => entry.method === 'history.sessions'),
2648
+ 'leaving the legacy view must restore the normal owner-scoped list',
2649
+ )
2650
+ }
2651
+
2652
+ // A legacy enabled auto-log setting is paused pending an explicit human choice.
2653
+ {
2654
+ assert.ok(
2655
+ textOf(lastTree).includes(dict('historyAutoLogLegacyReview').slice(0, 10)),
2656
+ 'the panel must explain the legacy auto-log review',
2657
+ )
2658
+ assert.ok(textOf(lastTree).includes('/home/u/.dsh/aiterm/logs'), 'the old autolog path must be shown before confirming')
2659
+ assert.ok(textOf(lastTree).includes(dict('historyAutoLogLegacyEnable').slice(0, 6)), 'an explicit confirm action must be present')
2660
+ const reviewBoxes = collect(lastTree, (node) => node.type === 'input' && node.props && node.props.type === 'checkbox')
2661
+ assert.equal(reviewBoxes[reviewBoxes.length - 1].props.disabled, true, 'the one-click switch must stay disabled during review')
2662
+ const mark = scene.rpcCalls.length
2663
+ await clickNode(findButtonByText(dict('historyAutoLogLegacyKeepOff')), 'keep legacy auto-log off')
2664
+ const call = scene.rpcCalls.slice(mark).find((entry) => entry.method === 'autolog.set')
2665
+ assert.ok(call, 'the keep-off confirmation must call autolog.set')
2666
+ assert.equal(call.params.enabled, false, 'keep-off must persist an explicit disabled state')
2501
2667
  }
2502
2668
 
2503
2669
  // Flip the auto-log switch on.
@@ -2512,6 +2678,27 @@ await closePanelViaBar()
2512
2678
  assert.ok(textOf(lastTree).includes(dict('historyAutoLogWhere').split('{')[0]), 'the writing directory must be shown')
2513
2679
  }
2514
2680
 
2681
+ // A delayed initial normal load that resolves after switching to legacy must
2682
+ // not overwrite the legacy page either (initial-load race, not just loadMore).
2683
+ await closePanelViaBar()
2684
+ reloadActive = true
2685
+ await openPanelViaBar('history')
2686
+ await settle('initial normal load pending')
2687
+ await clickNode(findButtonByText(dict('historyLegacyEntry')), 'enter legacy during initial load')
2688
+ await settle('legacy during initial load')
2689
+ assert.ok(textOf(lastTree).includes('old-unowned'), 'legacy must render before the initial normal response')
2690
+ assert.equal(typeof reloadResolve, 'function')
2691
+ reloadResolve({
2692
+ sessions: [{ id: 'st-ssh-initial', title: 'normal-initial', transport: 'ssh', host: '10.0.0.5', port: 22, username: 'root', createdAt: now - 20_000, bytes: 10, lastTs: now }],
2693
+ total: 1,
2694
+ truncated: false,
2695
+ snapshot: 'initial-snap',
2696
+ })
2697
+ await settle('late initial normal resolved')
2698
+ assert.equal(textOf(lastTree).includes('normal-initial'), false, 'a late initial normal response must not overwrite legacy')
2699
+ assert.ok(textOf(lastTree).includes('old-unowned'), 'legacy remains after the late initial response')
2700
+ reloadActive = false
2701
+
2515
2702
  await closePanelViaBar()
2516
2703
  await setSessions([sessionRecord()])
2517
2704
  }
@@ -0,0 +1,31 @@
1
+ # vendor/ssh2.cjs
2
+
3
+ `ssh2` 1.17.0 的**纯 JS** 构建产物,由 `scripts/build-vendor.mjs` 用 esbuild 打包成单文件。
4
+
5
+ ## 为什么要打包
6
+
7
+ `ssh2` 本身是纯 JS(协议实现全在 `lib/**.js`),但它有两个**可选**的原生加速件:
8
+
9
+ - `cpu-features`(探测 CPU 指令集,用于调优包大小)——在 `lib/protocol/constants.js` 里 `try/catch` 加载;
10
+ - 内建的 `sshcrypto` 绑定(`lib/protocol/crypto.js` 里的 `try/catch`)——由 `ssh2` 自己的 `install` 脚本尝试用 node-gyp 编译。
11
+
12
+ 两者都**缺失时 ssh2 自动回落到纯 JS 实现**,功能不受影响。
13
+
14
+ 问题是 pnpm 10+ 默认**拦截一切安装脚本**:只要依赖图里出现 `install`/`postinstall`,
15
+ 安装就会被挂起等人工批准(`ssh2` 的 `install` 脚本 + `cpu-features` 的 `node-gyp rebuild`)。
16
+ 把它打包进本包之后,`dsh-aiterm` 的依赖图里**不再有任何安装脚本**,装包即用。
17
+
18
+ ## 怎么重新生成
19
+
20
+ ```bash
21
+ npm install # 需要 devDependency ssh2 与 esbuild
22
+ npm run build:vendor # 重新生成 vendor/ssh2.cjs
23
+ ```
24
+
25
+ 打包时显式把两个原生件标记为 external,保持它们在运行时的 `try/catch` 里失败并回落:
26
+
27
+ ```
28
+ --external:cpu-features --external:nan --external:./crypto/build/Release/sshcrypto.node
29
+ ```
30
+
31
+ `ssh2` 的许可证见同目录 `ssh2.LICENSE`(MIT)。
@@ -0,0 +1,19 @@
1
+ Copyright Brian White. All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.