@deepseek-harness-tui/dsh-tui 0.19.0 → 0.20.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.
- package/README.md +63 -57
- package/cordis.patch.yml +5 -3
- package/cordis.yml +3 -2
- package/guide/dsh-tui-guide/configuration.en.md +1 -1
- package/guide/dsh-tui-guide/configuration.md +1 -1
- package/guide/dsh-tui-guide/getting-started.en.md +2 -2
- package/guide/dsh-tui-guide/getting-started.md +2 -2
- package/guide/dsh-tui-guide/user-guide.en.md +7 -2
- package/guide/dsh-tui-guide/user-guide.md +7 -2
- package/lib/settings.json +24 -8
- package/lib/types/adapter/ports/channel-view.d.ts +39 -3
- package/lib/types/adapter/ports/channel-view.d.ts.map +1 -1
- package/lib/types/agent/events.d.ts +3 -1
- package/lib/types/agent/events.d.ts.map +1 -1
- package/lib/types/backends/claude/tools.d.ts.map +1 -1
- package/lib/types/backends/claude/tools.js +8 -3
- package/lib/types/backends/codex/translate/presentation.d.ts.map +1 -1
- package/lib/types/backends/codex/translate/presentation.js +5 -2
- package/lib/types/channel/interaction.d.ts.map +1 -1
- package/lib/types/channel/interaction.js +1 -0
- package/lib/types/channel/permissions.d.ts +15 -0
- package/lib/types/channel/permissions.d.ts.map +1 -1
- package/lib/types/channel/permissions.js +28 -0
- package/lib/types/channel/projection.d.ts.map +1 -1
- package/lib/types/channel/projection.js +11 -1
- package/lib/types/channel/questions.d.ts +26 -0
- package/lib/types/channel/questions.d.ts.map +1 -1
- package/lib/types/channel/questions.js +43 -0
- package/lib/types/commands.js +1 -1
- package/lib/types/components/MessageList.d.ts.map +1 -1
- package/lib/types/components/MessageList.js +3 -3
- package/lib/types/components/SplitDiffView.d.ts.map +1 -1
- package/lib/types/components/SplitDiffView.js +3 -2
- package/lib/types/components/StarPrompt.d.ts +5 -3
- package/lib/types/components/StarPrompt.d.ts.map +1 -1
- package/lib/types/components/StarPrompt.js +56 -6
- package/lib/types/components/SubagentCard.d.ts.map +1 -1
- package/lib/types/components/SubagentCard.js +1 -1
- package/lib/types/components/SubagentDashboard.d.ts.map +1 -1
- package/lib/types/components/SubagentDashboard.js +3 -2
- package/lib/types/components/SubagentDetailScene.d.ts.map +1 -1
- package/lib/types/components/SubagentDetailScene.js +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.d.ts.map +1 -1
- package/lib/types/components/messages/AssistantToolUseMessage.js +121 -23
- package/lib/types/components/teamRoster.d.ts +6 -3
- package/lib/types/components/teamRoster.d.ts.map +1 -1
- package/lib/types/dsh-adapter/approvals.d.ts +19 -0
- package/lib/types/dsh-adapter/approvals.d.ts.map +1 -1
- package/lib/types/dsh-adapter/approvals.js +17 -1
- package/lib/types/dsh-adapter/backend/translate.d.ts.map +1 -1
- package/lib/types/dsh-adapter/backend/translate.js +15 -3
- package/lib/types/dsh-adapter/channel/extensions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/extensions.js +7 -4
- package/lib/types/dsh-adapter/channel/local-actions.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/local-actions.js +7 -3
- package/lib/types/dsh-adapter/channel/projection-helpers.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/projection-helpers.js +4 -2
- package/lib/types/dsh-adapter/channel/settings-host.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/settings-host.js +179 -33
- package/lib/types/dsh-adapter/channel/subagent-projection.d.ts +55 -4
- package/lib/types/dsh-adapter/channel/subagent-projection.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/subagent-projection.js +80 -16
- package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts +1 -1
- package/lib/types/dsh-adapter/channel/subagent-transcript.d.ts.map +1 -1
- package/lib/types/dsh-adapter/channel/subagent-transcript.js +6 -5
- package/lib/types/dsh-adapter/channel/task-completion.js +2 -10
- package/lib/types/dsh-adapter/compat/compaction-previews.d.ts +11 -0
- package/lib/types/dsh-adapter/compat/compaction-previews.d.ts.map +1 -0
- package/lib/types/dsh-adapter/compat/compaction-previews.js +38 -0
- package/lib/types/dsh-adapter/compat/messages.d.ts +1 -1
- package/lib/types/dsh-adapter/compat/messages.d.ts.map +1 -1
- package/lib/types/dsh-adapter/compat/messages.js +2 -2
- package/lib/types/dsh-adapter/contract.d.ts +7 -4
- package/lib/types/dsh-adapter/contract.d.ts.map +1 -1
- package/lib/types/dsh-adapter/contract.js +8 -4
- package/lib/types/dsh-adapter/experimental-bundles.d.ts +5 -0
- package/lib/types/dsh-adapter/experimental-bundles.d.ts.map +1 -1
- package/lib/types/dsh-adapter/experimental-bundles.js +0 -2
- package/lib/types/dsh-adapter/host-contract.d.ts +1 -1
- package/lib/types/dsh-adapter/host-contract.js +2 -2
- package/lib/types/dsh-adapter/host-dsh.d.ts +2 -0
- package/lib/types/dsh-adapter/host-dsh.d.ts.map +1 -1
- package/lib/types/dsh-adapter/host-dsh.js +3 -0
- package/lib/types/dsh-adapter/index.d.ts +9 -1
- package/lib/types/dsh-adapter/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/index.js +5 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.d.ts +73 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.d.ts.map +1 -0
- package/lib/types/dsh-adapter/oauth/account-notifications.js +250 -0
- package/lib/types/dsh-adapter/oauth/bonus.d.ts +34 -9
- package/lib/types/dsh-adapter/oauth/bonus.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/bonus.js +47 -5
- package/lib/types/dsh-adapter/oauth/deepseek.d.ts +7 -2
- package/lib/types/dsh-adapter/oauth/deepseek.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/deepseek.js +6 -1
- package/lib/types/dsh-adapter/oauth/index.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/index.js +44 -0
- package/lib/types/dsh-adapter/oauth/service.d.ts.map +1 -1
- package/lib/types/dsh-adapter/oauth/service.js +5 -6
- package/lib/types/dsh-adapter/plugin-manage.d.ts +6 -4
- package/lib/types/dsh-adapter/plugin-manage.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin-manage.js +3 -2
- package/lib/types/dsh-adapter/plugin.d.ts +237 -6
- package/lib/types/dsh-adapter/plugin.d.ts.map +1 -1
- package/lib/types/dsh-adapter/plugin.js +608 -23
- package/lib/types/dsh-adapter/session-projection-store.d.ts +1 -1
- package/lib/types/dsh-adapter/session-projection-store.d.ts.map +1 -1
- package/lib/types/dsh-adapter/session-projection-store.js +30 -23
- package/lib/types/dsh-adapter/sessionTree.d.ts.map +1 -1
- package/lib/types/dsh-adapter/sessionTree.js +4 -1
- package/lib/types/dsh-adapter/subagents.d.ts +1 -0
- package/lib/types/dsh-adapter/subagents.d.ts.map +1 -1
- package/lib/types/dsh-adapter/subagents.js +10 -2
- package/lib/types/dsh-adapter/team-mode.d.ts +29 -17
- package/lib/types/dsh-adapter/team-mode.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-mode.js +138 -17
- package/lib/types/dsh-adapter/team-roster.d.ts +53 -18
- package/lib/types/dsh-adapter/team-roster.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-roster.js +206 -39
- package/lib/types/dsh-adapter/team-tools.d.ts +25 -12
- package/lib/types/dsh-adapter/team-tools.d.ts.map +1 -1
- package/lib/types/dsh-adapter/team-tools.js +81 -26
- package/lib/types/i18n.d.ts +65 -9
- package/lib/types/i18n.d.ts.map +1 -1
- package/lib/types/i18n.js +29 -8
- package/lib/types/ink/dom.d.ts.map +1 -1
- package/lib/types/ink/dom.js +13 -3
- package/lib/types/ink/flush-tick.d.ts +6 -0
- package/lib/types/ink/flush-tick.d.ts.map +1 -1
- package/lib/types/ink/flush-tick.js +31 -0
- package/lib/types/ink/hooks/use-terminal-title.d.ts +15 -0
- package/lib/types/ink/hooks/use-terminal-title.d.ts.map +1 -1
- package/lib/types/ink/hooks/use-terminal-title.js +23 -3
- package/lib/types/ink/ink.js +2 -2
- package/lib/types/ink/jumpback-state.d.ts +33 -0
- package/lib/types/ink/jumpback-state.d.ts.map +1 -0
- package/lib/types/ink/jumpback-state.js +51 -0
- package/lib/types/ink/jumpback.d.ts +78 -0
- package/lib/types/ink/jumpback.d.ts.map +1 -0
- package/lib/types/ink/jumpback.js +515 -0
- package/lib/types/ink/log-update.js +37 -14
- package/lib/types/ink/notify-helper/activate.cs +836 -0
- package/lib/types/ink/notify-helper/compile.d.ts +30 -0
- package/lib/types/ink/notify-helper/compile.d.ts.map +1 -0
- package/lib/types/ink/notify-helper/compile.js +235 -0
- package/lib/types/ink/terminal-notification-windows.d.ts +8 -4
- package/lib/types/ink/terminal-notification-windows.d.ts.map +1 -1
- package/lib/types/ink/terminal-notification-windows.js +14 -21
- package/lib/types/ink/terminal-notification.d.ts +31 -2
- package/lib/types/ink/terminal-notification.d.ts.map +1 -1
- package/lib/types/ink/terminal-notification.js +51 -0
- package/lib/types/ink/terminal.d.ts +2 -1
- package/lib/types/ink/terminal.d.ts.map +1 -1
- package/lib/types/ink/terminal.js +9 -4
- package/lib/types/screens/AgentTranscriptScene.d.ts.map +1 -1
- package/lib/types/screens/AgentTranscriptScene.js +1 -1
- package/lib/types/screens/Chat.d.ts +4 -3
- package/lib/types/screens/Chat.d.ts.map +1 -1
- package/lib/types/screens/Chat.js +38 -9
- package/lib/types/settings/definitions.d.ts +12 -0
- package/lib/types/settings/definitions.d.ts.map +1 -1
- package/lib/types/settings/definitions.js +15 -7
- package/package.json +112 -112
- package/presets/liangshen/agent.cordis.yml +4 -0
- package/tui-profile/feed/README.md +1 -1
- package/tui-profile/feed/first-party.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jumpback.d.ts","sourceRoot":"","sources":["../../../src/ink/jumpback.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAK7D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,qCAAqC,CAAA;AAExE;;;;GAIG;AACH,eAAO,MAAM,8BAA8B,2DAAoD,CAAA;AAe/F,qFAAqF;AACrF,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAE9D;AAWD,oFAAoF;AACpF,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,YAAY,CAAA;AAE3F,wEAAwE;AACxE,MAAM,MAAM,aAAa,GACrB;IAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACvD;IAAE,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAA;AAE5F;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAA;IAC1B,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;IACxC,kFAAkF;IAClF,GAAG,CAAC,EAAE,OAAO,eAAe,CAAA;IAC5B,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,MAAM,CAAA;IAClB,4EAA4E;IAC5E,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAA;IACnC,yFAAyF;IACzF,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;CAC/C;AAED,oDAAoD;AACpD,MAAM,WAAW,QAAQ;IACvB,uFAAuF;IACvF,KAAK,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAA;IAC7C,sFAAsF;IACtF,cAAc,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;IACpD,mEAAmE;IACnE,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,uEAAuE;IACvE,WAAW,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;IAClE,6FAA6F;IAC7F,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACxB,yFAAyF;IACzF,UAAU,IAAI,IAAI,CAAA;CACnB;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,GAAE,aAAkB,GAAG,QAAQ,CAoTlE"}
|
|
@@ -0,0 +1,515 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jump-back orchestration (D4/D7/D8): the single place that asks whether this
|
|
3
|
+
* pane can be promised a jump, registers the `dsh-tui:` protocol a toast click
|
|
4
|
+
* comes back through, and keeps the documented marker files truthful. The UIA
|
|
5
|
+
* work itself belongs to the helper under `notify-helper/`.
|
|
6
|
+
*
|
|
7
|
+
* Every system side effect sits behind the win32 guard and behind the injected
|
|
8
|
+
* ports, so a POSIX process neither writes the registry nor leaves marker files.
|
|
9
|
+
* Nothing here throws: a failure answers "not capable", the caller degrades to a
|
|
10
|
+
* plain toast, and the stage and reason stay in the debug log (AC-3/AC-9).
|
|
11
|
+
*/
|
|
12
|
+
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
import { pidAlive } from '../sessionMounts.js';
|
|
15
|
+
import { logForDebugging } from '../utils/debug.js';
|
|
16
|
+
import { execFileNoThrow } from '../utils/execFileNoThrow.js';
|
|
17
|
+
import { DATA_DIR } from '../utils/paths.js';
|
|
18
|
+
import { ensureHelper } from './notify-helper/compile.js';
|
|
19
|
+
/**
|
|
20
|
+
* The URI scheme root (D7): Windows hands `dsh-tui:` to a handler only when this
|
|
21
|
+
* key carries the named value `URL Protocol`; the click command sits below it.
|
|
22
|
+
*/
|
|
23
|
+
export const JUMP_BACK_PROTOCOL_KEY = 'HKCU\\Software\\Classes\\dsh-tui';
|
|
24
|
+
/**
|
|
25
|
+
* The command a toast click runs (D7). It quotes both the helper and the data
|
|
26
|
+
* directory: the shell starts the handler with none of our environment, so the
|
|
27
|
+
* helper must be told where the profile lives explicitly.
|
|
28
|
+
*/
|
|
29
|
+
export const JUMP_BACK_PROTOCOL_COMMAND_KEY = `${JUMP_BACK_PROTOCOL_KEY}\\shell\\open\\command`;
|
|
30
|
+
/** The named value that marks the scheme root as a URI handler; its data is empty (D7). */
|
|
31
|
+
const URL_PROTOCOL_VALUE = 'URL Protocol';
|
|
32
|
+
/** 16 lowercase hex characters; the title, the URI and the marker file all carry this (D2). */
|
|
33
|
+
const MARKER_PATTERN = /^[0-9a-f]{16}$/u;
|
|
34
|
+
/**
|
|
35
|
+
* A session id becomes a file name, so only characters that cannot introduce a
|
|
36
|
+
* path separator are admitted. DSH ids are `session-<uuid>`; `.` and `..` are
|
|
37
|
+
* harmless because `.json` is appended, so neither can name a directory.
|
|
38
|
+
*/
|
|
39
|
+
const SESSION_ID_PATTERN = /^[A-Za-z0-9._-]{1,128}$/u;
|
|
40
|
+
/** True when the id can name a marker file; `writeMarker` enforces the same rule. */
|
|
41
|
+
export function isMarkerFileSession(sessionId) {
|
|
42
|
+
return SESSION_ID_PATTERN.test(sessionId);
|
|
43
|
+
}
|
|
44
|
+
/** The helper probes in ~0.5 s (D4); 1.5 s means stuck, not slow. */
|
|
45
|
+
const PROBE_TIMEOUT_MS = 1_500;
|
|
46
|
+
/** `reg.exe` answers in milliseconds; a write that takes longer is stuck, not slow (D7). */
|
|
47
|
+
const REGISTRY_TIMEOUT_MS = 15_000;
|
|
48
|
+
/** A marker file is stale after a week even when its pid still answers (D8). */
|
|
49
|
+
const STALE_AFTER_MS = 7 * 24 * 60 * 60 * 1_000;
|
|
50
|
+
/**
|
|
51
|
+
* Create the orchestration for one process.
|
|
52
|
+
* @returns The jump-back orchestration.
|
|
53
|
+
*/
|
|
54
|
+
export function createJumpBack(ports = {}) {
|
|
55
|
+
const platform = ports.platform ?? process.platform;
|
|
56
|
+
const env = ports.env ?? process.env;
|
|
57
|
+
const run = ports.run ?? execFileNoThrow;
|
|
58
|
+
const resolveHelper = ports.helperPath ?? ensureHelper;
|
|
59
|
+
const now = ports.now ?? Date.now;
|
|
60
|
+
const dataDir = ports.dataDir ?? DATA_DIR;
|
|
61
|
+
const markerDir = join(dataDir, 'notify', 'jumpback');
|
|
62
|
+
const alive = ports.pidAlive ?? pidAlive;
|
|
63
|
+
/** Marker files this process wrote; the only ones cleanup may remove. */
|
|
64
|
+
const written = new Set();
|
|
65
|
+
/** Whether this process registered the key; re-checked before every later promise (D7). */
|
|
66
|
+
let registered = false;
|
|
67
|
+
/**
|
|
68
|
+
* The helper this process registered (or found its own template for). Cleanup
|
|
69
|
+
* uses it to recognise a shared key another instance wrote for every instance
|
|
70
|
+
* under this profile, so the last one out can still release it.
|
|
71
|
+
*/
|
|
72
|
+
let lastHelper;
|
|
73
|
+
/**
|
|
74
|
+
* Whether this process ever took part in jump-back (registered or wrote a
|
|
75
|
+
* marker). A default-off process stays untouched: cleanup must not even read
|
|
76
|
+
* the registry for it, or the "no trace" promise grows a pair of queries.
|
|
77
|
+
*/
|
|
78
|
+
let armed = false;
|
|
79
|
+
/** The one registration or re-check in flight, so concurrent notifications share it. */
|
|
80
|
+
let pendingEnsure;
|
|
81
|
+
const unavailable = (stage, reason) => {
|
|
82
|
+
logForDebugging('jumpback: probe unavailable', { stage, reason });
|
|
83
|
+
return { capable: false, stage, reason };
|
|
84
|
+
};
|
|
85
|
+
async function probe(marker) {
|
|
86
|
+
try {
|
|
87
|
+
// The platform gate comes first: a non-Windows process has no UIA to ask.
|
|
88
|
+
if (platform !== 'win32')
|
|
89
|
+
return unavailable('not-win32', `the platform is ${platform}`);
|
|
90
|
+
if (!MARKER_PATTERN.test(marker)) {
|
|
91
|
+
return unavailable('marker', 'expected 16 lowercase hex characters');
|
|
92
|
+
}
|
|
93
|
+
const helper = await resolveHelper();
|
|
94
|
+
if (helper === undefined)
|
|
95
|
+
return unavailable('helper', 'the helper could not be compiled');
|
|
96
|
+
const result = await run(helper, ['--probe', marker, '-DataDir', dataDir], {
|
|
97
|
+
timeout: PROBE_TIMEOUT_MS,
|
|
98
|
+
});
|
|
99
|
+
if (result.code !== 0)
|
|
100
|
+
return unavailable('probe', probeFailure(result));
|
|
101
|
+
logForDebugging('jumpback: the helper reports a reachable target', { marker });
|
|
102
|
+
return { capable: true, helperPath: helper };
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
// A rejecting port must not reach the notification path (AC-3).
|
|
106
|
+
return unavailable('unexpected', describe(error));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
async function register(helper) {
|
|
110
|
+
if (platform !== 'win32') {
|
|
111
|
+
logForDebugging('jumpback: protocol registration skipped', { reason: 'not-win32' });
|
|
112
|
+
return false;
|
|
113
|
+
}
|
|
114
|
+
const reg = regExe(env);
|
|
115
|
+
if (reg === undefined) {
|
|
116
|
+
logForDebugging('jumpback: protocol registration skipped', { reason: 'system-root-missing' });
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (helper === '' || helper.includes('"')) {
|
|
120
|
+
// Recording an unquotable path would produce a handler that silently
|
|
121
|
+
// never starts; refuse now so the click degrades to a plain toast.
|
|
122
|
+
logForDebugging('jumpback: protocol registration refused', {
|
|
123
|
+
reason: 'the helper path cannot be quoted',
|
|
124
|
+
helper,
|
|
125
|
+
});
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
// Windows needs both halves: the empty `URL Protocol` marker on the root and
|
|
129
|
+
// the command below it. Either refusal means no click, and a half-written
|
|
130
|
+
// key is never remembered as registered, so the next notification retries (D7).
|
|
131
|
+
for (const value of registrationValues(helper, dataDir)) {
|
|
132
|
+
const detail = await addRegistryValue(run, reg, value);
|
|
133
|
+
if (detail !== undefined) {
|
|
134
|
+
logForDebugging('jumpback: protocol registration failed', {
|
|
135
|
+
key: value.key,
|
|
136
|
+
value: value.name ?? '(default)',
|
|
137
|
+
detail,
|
|
138
|
+
});
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
registered = true;
|
|
143
|
+
lastHelper = helper;
|
|
144
|
+
armed = true;
|
|
145
|
+
logForDebugging('jumpback: protocol registered', { key: JUMP_BACK_PROTOCOL_KEY });
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
function ensureProtocol(helper) {
|
|
149
|
+
if (pendingEnsure !== undefined)
|
|
150
|
+
return pendingEnsure;
|
|
151
|
+
// A write that succeeded earlier is not proof the key is still there: the
|
|
152
|
+
// user, another instance or a crash may have deleted or rewritten it since.
|
|
153
|
+
// Every later notification re-checks the pair and rewrites it on failure
|
|
154
|
+
// (D7); a failed attempt is not cached, so the next notification retries
|
|
155
|
+
// after a transient policy refusal.
|
|
156
|
+
pendingEnsure = ensureCurrent(helper)
|
|
157
|
+
.catch((error) => {
|
|
158
|
+
logForDebugging('jumpback: protocol registration threw', { detail: describe(error) });
|
|
159
|
+
return false;
|
|
160
|
+
})
|
|
161
|
+
.finally(() => {
|
|
162
|
+
pendingEnsure = undefined;
|
|
163
|
+
});
|
|
164
|
+
return pendingEnsure;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Answer "is the promise still backed by the key?", writing the pair when it
|
|
168
|
+
* is not. The first notification pays for two writes; later ones pay for two
|
|
169
|
+
* `reg query` calls unless the key changed (D7).
|
|
170
|
+
* @returns Whether both values now hold this process's template.
|
|
171
|
+
*/
|
|
172
|
+
async function ensureCurrent(helper) {
|
|
173
|
+
if (!registered)
|
|
174
|
+
return register(helper);
|
|
175
|
+
const reg = regExe(env);
|
|
176
|
+
if (reg !== undefined && await registrationMatches(run, reg, helper, dataDir)) {
|
|
177
|
+
lastHelper = helper;
|
|
178
|
+
armed = true;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
return register(helper);
|
|
182
|
+
}
|
|
183
|
+
async function unregisterProtocol() {
|
|
184
|
+
registered = false;
|
|
185
|
+
try {
|
|
186
|
+
if (platform !== 'win32')
|
|
187
|
+
return;
|
|
188
|
+
const reg = regExe(env);
|
|
189
|
+
if (reg === undefined) {
|
|
190
|
+
logForDebugging('jumpback: protocol unregistration skipped', { reason: 'system-root-missing' });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
// The whole scheme root goes, not just the command below it: leaving the
|
|
194
|
+
// empty `dsh-tui` key behind would contradict "a normal exit leaves no
|
|
195
|
+
// protocol key" and make the next default-off snapshot look wrong (D7).
|
|
196
|
+
const result = await run(reg, ['delete', JUMP_BACK_PROTOCOL_KEY, '/f'], {
|
|
197
|
+
timeout: REGISTRY_TIMEOUT_MS,
|
|
198
|
+
});
|
|
199
|
+
// A key another instance removed first is the normal multi-instance case;
|
|
200
|
+
// the refusal costs nothing and is recorded for the post-mortem (D7).
|
|
201
|
+
if (result.code !== 0) {
|
|
202
|
+
logForDebugging('jumpback: protocol unregistration failed', {
|
|
203
|
+
code: result.code,
|
|
204
|
+
detail: firstOutputLine(result),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
logForDebugging('jumpback: protocol unregistration threw', { detail: describe(error) });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
function writeMarker(sessionId, marker) {
|
|
213
|
+
if (platform !== 'win32') {
|
|
214
|
+
logForDebugging('jumpback: marker file skipped', { reason: 'not-win32' });
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
if (!isMarkerFileSession(sessionId)) {
|
|
218
|
+
logForDebugging('jumpback: marker file refused', { reason: 'unusable session id', sessionId });
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
if (!MARKER_PATTERN.test(marker)) {
|
|
222
|
+
logForDebugging('jumpback: marker file refused', { reason: 'unusable marker', marker });
|
|
223
|
+
return undefined;
|
|
224
|
+
}
|
|
225
|
+
const path = join(markerDir, `${sessionId}.json`);
|
|
226
|
+
try {
|
|
227
|
+
const record = {
|
|
228
|
+
schemaVersion: 1,
|
|
229
|
+
marker,
|
|
230
|
+
pid: process.pid,
|
|
231
|
+
startedAt: new Date(now()).toISOString(),
|
|
232
|
+
};
|
|
233
|
+
mkdirSync(markerDir, { recursive: true });
|
|
234
|
+
writeFileSync(path, `${JSON.stringify(record, null, 2)}\n`, 'utf8');
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
logForDebugging('jumpback: marker file unwritable', { path, detail: describe(error) });
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
written.add(path);
|
|
241
|
+
armed = true;
|
|
242
|
+
logForDebugging('jumpback: marker file written', { path });
|
|
243
|
+
return path;
|
|
244
|
+
}
|
|
245
|
+
async function cleanup() {
|
|
246
|
+
// A registration still in flight may land after this check; waiting for it
|
|
247
|
+
// makes "we do not leave a key behind" true even on a fast exit.
|
|
248
|
+
if (pendingEnsure !== undefined)
|
|
249
|
+
await pendingEnsure;
|
|
250
|
+
const reg = regExe(env);
|
|
251
|
+
const helper = lastHelper ?? join(dataDir, 'notify', 'helper', 'activate.exe');
|
|
252
|
+
// A process that never registered can still be the last one out: another
|
|
253
|
+
// instance registered the same shared key for this profile. Recognise our
|
|
254
|
+
// own template instead of trusting this object's `registered` flag, and
|
|
255
|
+
// never remove a key that belongs to something else.
|
|
256
|
+
const keyIsOurs = registered || (armed && platform === 'win32' && reg !== undefined
|
|
257
|
+
&& await registrationMatches(run, reg, helper, dataDir));
|
|
258
|
+
if (keyIsOurs) {
|
|
259
|
+
if (hasOtherLiveInstance()) {
|
|
260
|
+
// The key is shared by every instance under this profile: removing it
|
|
261
|
+
// would turn another live instance's next toast clicks into dead ones.
|
|
262
|
+
// Its next notification re-checks and rewrites the pair if needed (D7).
|
|
263
|
+
registered = false;
|
|
264
|
+
logForDebugging('jumpback: left the protocol key for a live instance', {
|
|
265
|
+
key: JUMP_BACK_PROTOCOL_KEY,
|
|
266
|
+
reason: 'another process still owns a marker file',
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
await unregisterProtocol();
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
for (const path of written) {
|
|
274
|
+
try {
|
|
275
|
+
rmSync(path, { force: true });
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
logForDebugging('jumpback: marker file removal failed', { path, detail: describe(error) });
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
written.clear();
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* List the marker directory, or undefined when there is nothing to read yet;
|
|
285
|
+
* the startup sweep and the cleanup yield check share this one read (D8).
|
|
286
|
+
* @returns The directory entries, or undefined when the directory is absent.
|
|
287
|
+
*/
|
|
288
|
+
function markerEntries() {
|
|
289
|
+
try {
|
|
290
|
+
return readdirSync(markerDir, { withFileTypes: true });
|
|
291
|
+
}
|
|
292
|
+
catch (error) {
|
|
293
|
+
// No directory yet is the normal first run; anything else is worth a line.
|
|
294
|
+
if (error.code !== 'ENOENT') {
|
|
295
|
+
logForDebugging('jumpback: marker directory unreadable', { dir: markerDir, detail: describe(error) });
|
|
296
|
+
}
|
|
297
|
+
return undefined;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Whether a marker file belongs to another process that is still alive: such
|
|
302
|
+
* an instance still needs the shared key, so cleanup must not remove it. Files
|
|
303
|
+
* this process wrote, unreadable files and dead pids do not block removal; the
|
|
304
|
+
* stale sweep owns whatever is left behind.
|
|
305
|
+
* @returns True when at least one other live pid owns a marker file.
|
|
306
|
+
*/
|
|
307
|
+
function hasOtherLiveInstance() {
|
|
308
|
+
const entries = markerEntries();
|
|
309
|
+
if (entries === undefined)
|
|
310
|
+
return false;
|
|
311
|
+
for (const entry of entries) {
|
|
312
|
+
if (!entry.isFile() || !entry.name.endsWith('.json'))
|
|
313
|
+
continue;
|
|
314
|
+
const record = readMarkerRecord(join(markerDir, entry.name));
|
|
315
|
+
const pid = record?.pid;
|
|
316
|
+
if (typeof pid !== 'number' || !Number.isSafeInteger(pid) || pid <= 0 || pid === process.pid)
|
|
317
|
+
continue;
|
|
318
|
+
if (alive(pid))
|
|
319
|
+
return true;
|
|
320
|
+
}
|
|
321
|
+
return false;
|
|
322
|
+
}
|
|
323
|
+
function sweepStale() {
|
|
324
|
+
if (platform !== 'win32')
|
|
325
|
+
return;
|
|
326
|
+
try {
|
|
327
|
+
removeStaleMarkers();
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
// The sweep is housekeeping: a surprise in it must not take startup down.
|
|
331
|
+
logForDebugging('jumpback: stale marker sweep failed', { detail: describe(error) });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
function removeStaleMarkers() {
|
|
335
|
+
const entries = markerEntries();
|
|
336
|
+
if (entries === undefined)
|
|
337
|
+
return;
|
|
338
|
+
for (const entry of entries) {
|
|
339
|
+
if (!entry.isFile() || !entry.name.endsWith('.json'))
|
|
340
|
+
continue;
|
|
341
|
+
const path = join(markerDir, entry.name);
|
|
342
|
+
const record = readMarkerRecord(path);
|
|
343
|
+
if (record === undefined)
|
|
344
|
+
continue;
|
|
345
|
+
const pid = record.pid;
|
|
346
|
+
if (typeof pid !== 'number' || !Number.isSafeInteger(pid) || pid <= 0) {
|
|
347
|
+
logForDebugging('jumpback: marker file left in place', { path, reason: 'no usable pid' });
|
|
348
|
+
continue;
|
|
349
|
+
}
|
|
350
|
+
if (!alive(pid)) {
|
|
351
|
+
removeStale(path, 'the owning process is gone');
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
const started = typeof record.startedAt === 'string' ? Date.parse(record.startedAt) : Number.NaN;
|
|
355
|
+
if (Number.isFinite(started) && now() - started > STALE_AFTER_MS) {
|
|
356
|
+
removeStale(path, 'older than 7 days');
|
|
357
|
+
}
|
|
358
|
+
else if (!Number.isFinite(started)) {
|
|
359
|
+
logForDebugging('jumpback: marker file left in place', { path, reason: 'no usable startedAt' });
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return {
|
|
364
|
+
probe,
|
|
365
|
+
ensureProtocol,
|
|
366
|
+
unregisterProtocol,
|
|
367
|
+
writeMarker,
|
|
368
|
+
cleanup,
|
|
369
|
+
sweepStale,
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* The two values a full registration writes (D7), each with the data this
|
|
374
|
+
* process would leave behind. The pair doubles as the template every later
|
|
375
|
+
* notification checks against.
|
|
376
|
+
* @returns The root marker and the command, in the order they are written.
|
|
377
|
+
*/
|
|
378
|
+
function registrationValues(helper, dataDir) {
|
|
379
|
+
return [
|
|
380
|
+
{ key: JUMP_BACK_PROTOCOL_KEY, name: URL_PROTOCOL_VALUE, data: '' },
|
|
381
|
+
{ key: JUMP_BACK_PROTOCOL_COMMAND_KEY, name: null, data: `"${helper}" --activate "%1" -DataDir "${dataDir}"` },
|
|
382
|
+
];
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Whether both values still hold this process's template: a missing value, a
|
|
386
|
+
* command rewritten to another helper, half a root key or unreadable output all
|
|
387
|
+
* answer false, so the caller rewrites the pair instead of trusting the cache (D7).
|
|
388
|
+
* @returns True only when both values match the template exactly.
|
|
389
|
+
*/
|
|
390
|
+
async function registrationMatches(run, reg, helper, dataDir) {
|
|
391
|
+
for (const value of registrationValues(helper, dataDir)) {
|
|
392
|
+
if (await readRegistryValue(run, reg, value) !== value.data)
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
return true;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Read one value back with `reg query`. A gone value (non-zero exit) or output
|
|
399
|
+
* this parser cannot read answers undefined; both mean "not provably ours",
|
|
400
|
+
* never "probably fine" (D7).
|
|
401
|
+
* @returns The data string, or undefined when the value is not provably there.
|
|
402
|
+
*/
|
|
403
|
+
async function readRegistryValue(run, reg, value) {
|
|
404
|
+
const nameArgs = value.name === null ? ['/ve'] : ['/v', value.name];
|
|
405
|
+
const result = await run(reg, ['query', value.key, ...nameArgs], { timeout: REGISTRY_TIMEOUT_MS });
|
|
406
|
+
if (result.code !== 0)
|
|
407
|
+
return undefined;
|
|
408
|
+
return parseRegistryValue(result.stdout, value.name);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* The data of one value from `reg query` output. The line carries the type
|
|
412
|
+
* token, so the label before it is skipped for the default value (Windows
|
|
413
|
+
* localises `(Default)`) and compared exactly for the named root marker (so a
|
|
414
|
+
* data line cannot be mistaken for the value).
|
|
415
|
+
* @param name - The value name, or null for the key's default value.
|
|
416
|
+
* @returns The data string, or undefined when no value line is present.
|
|
417
|
+
*/
|
|
418
|
+
function parseRegistryValue(stdout, name) {
|
|
419
|
+
for (const line of stdout.split(/\r?\n/u)) {
|
|
420
|
+
const trimmed = line.trim();
|
|
421
|
+
const typeAt = trimmed.indexOf('REG_SZ');
|
|
422
|
+
if (typeAt === -1)
|
|
423
|
+
continue;
|
|
424
|
+
if (name !== null && trimmed.slice(0, typeAt).trim() !== name)
|
|
425
|
+
continue;
|
|
426
|
+
return trimmed.slice(typeAt + 'REG_SZ'.length).trimStart();
|
|
427
|
+
}
|
|
428
|
+
return undefined;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Write one `REG_SZ` value with `reg.exe add`. The named value and the default
|
|
432
|
+
* share one argv shape; `name === null` means the default value (`/ve`), the
|
|
433
|
+
* form verified against a real registry (D7).
|
|
434
|
+
* @returns undefined on success, or the line a failure left for the log.
|
|
435
|
+
*/
|
|
436
|
+
async function addRegistryValue(run, reg, value) {
|
|
437
|
+
const nameArgs = value.name === null ? ['/ve'] : ['/v', value.name];
|
|
438
|
+
const result = await run(reg, ['add', value.key, ...nameArgs, '/t', 'REG_SZ', '/d', value.data, '/f'], {
|
|
439
|
+
timeout: REGISTRY_TIMEOUT_MS,
|
|
440
|
+
});
|
|
441
|
+
if (result.code === 0)
|
|
442
|
+
return undefined;
|
|
443
|
+
const detail = firstOutputLine(result);
|
|
444
|
+
return detail === '' ? `exited with code ${result.code}` : detail;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* The in-box registry tool under `%WINDIR%`, or undefined when the environment
|
|
448
|
+
* names no Windows directory. Resolved by absolute path, never through `PATH`
|
|
449
|
+
* (the same rule the toast transport follows for its own registry writes).
|
|
450
|
+
* @returns The absolute `reg.exe` path, or undefined.
|
|
451
|
+
*/
|
|
452
|
+
function regExe(env) {
|
|
453
|
+
const root = env.WINDIR ?? env.SystemRoot;
|
|
454
|
+
if (root === undefined || root === '')
|
|
455
|
+
return undefined;
|
|
456
|
+
return join(root, 'System32', 'reg.exe');
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Parse one marker file. Unreadable and unshaped files are left in place: not
|
|
460
|
+
* being able to read a file is not proof that its owner is gone, and a newer
|
|
461
|
+
* process may still know the format (D8).
|
|
462
|
+
* @returns The record, or undefined when it cannot be interpreted.
|
|
463
|
+
*/
|
|
464
|
+
function readMarkerRecord(path) {
|
|
465
|
+
try {
|
|
466
|
+
const parsed = JSON.parse(readFileSync(path, 'utf8'));
|
|
467
|
+
if (typeof parsed !== 'object' || parsed === null) {
|
|
468
|
+
logForDebugging('jumpback: marker file left in place', { path, reason: 'not a JSON object' });
|
|
469
|
+
return undefined;
|
|
470
|
+
}
|
|
471
|
+
return parsed;
|
|
472
|
+
}
|
|
473
|
+
catch (error) {
|
|
474
|
+
logForDebugging('jumpback: marker file left in place', { path, detail: describe(error) });
|
|
475
|
+
return undefined;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
/** Remove one stale marker file; a removal that fails only leaves the file. */
|
|
479
|
+
function removeStale(path, reason) {
|
|
480
|
+
try {
|
|
481
|
+
rmSync(path, { force: true });
|
|
482
|
+
logForDebugging('jumpback: removed a stale marker file', { path, reason });
|
|
483
|
+
}
|
|
484
|
+
catch (error) {
|
|
485
|
+
logForDebugging('jumpback: stale marker file removal failed', { path, detail: describe(error) });
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
/** Why the probe did not answer 0: a timeout or the helper's own exit code. */
|
|
489
|
+
function probeFailure(result) {
|
|
490
|
+
if (result.code === null) {
|
|
491
|
+
return `the helper timed out after ${PROBE_TIMEOUT_MS} ms or was killed`;
|
|
492
|
+
}
|
|
493
|
+
const detail = firstOutputLine(result);
|
|
494
|
+
return detail === ''
|
|
495
|
+
? `the helper exited with code ${result.code}`
|
|
496
|
+
: `the helper exited with code ${result.code}: ${detail}`;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* The line a failed command printed that explains the failure: a line that
|
|
500
|
+
* reports `ok=false` or an error wins over banners and the first stdout line,
|
|
501
|
+
* and the last line is the fallback.
|
|
502
|
+
*/
|
|
503
|
+
function firstOutputLine(result) {
|
|
504
|
+
for (const stream of [result.stderr, result.stdout]) {
|
|
505
|
+
const lines = stream.trim().split(/\r?\n/u).filter(line => line !== '');
|
|
506
|
+
if (lines.length === 0)
|
|
507
|
+
continue;
|
|
508
|
+
const failure = [...lines].reverse().find(line => /ok=false|error|failed/u.test(line));
|
|
509
|
+
return (failure ?? lines[lines.length - 1]).slice(0, 300);
|
|
510
|
+
}
|
|
511
|
+
return '';
|
|
512
|
+
}
|
|
513
|
+
function describe(error) {
|
|
514
|
+
return error instanceof Error ? error.message : String(error);
|
|
515
|
+
}
|
|
@@ -361,7 +361,7 @@ export class LogUpdate {
|
|
|
361
361
|
// Unreachable frame rows = terminal scrollback. Two contributors, take
|
|
362
362
|
// the MAX, never the sum: after an anchored shrink repaint the pad rows
|
|
363
363
|
// ARE the scrollback (heights undercount while H < V); once growth
|
|
364
|
-
// scrolls
|
|
364
|
+
// scrolls those rows out, the heights formula takes over (summing
|
|
365
365
|
// would overcount and skip REACHABLE viewport rows — changes inside
|
|
366
366
|
// the viewport would never paint, scrambling the layout on mid-frame
|
|
367
367
|
// edits like Ctrl+O expansion).
|
|
@@ -613,9 +613,16 @@ function fullResetSequence_CAUSES_FLICKER(frame, reason, stylePool, debug) {
|
|
|
613
613
|
const height = frame.screen.height;
|
|
614
614
|
const contentRows = Math.min(height, Math.max(1, frame.viewport.height - 1));
|
|
615
615
|
const startY = height - contentRows;
|
|
616
|
+
// A frame shorter than the viewport is anchored to the BOTTOM, not the top:
|
|
617
|
+
// pad the rows above it so its tail ends on the cursor-park row. Painting it
|
|
618
|
+
// from the viewport top strands the composer/status block in the upper half
|
|
619
|
+
// with blank rows below, and nothing re-anchors it while the frame fits (the
|
|
620
|
+
// steady-state diff emits no LFs then) — issue #1919.
|
|
621
|
+
const blankBand = Math.max(0, frame.viewport.height - 1 - contentRows);
|
|
622
|
+
const anchor = blankBand > 0 ? [{ type: 'stdout', content: cursorDown(blankBand) }] : [];
|
|
616
623
|
const screen = new VirtualScreen({ x: 0, y: startY }, frame.viewport.width);
|
|
617
624
|
renderFrameSlice(screen, frame, startY, height, stylePool, false);
|
|
618
|
-
return [{ type: 'clearTerminal', reason, debug }, ...screen.diff];
|
|
625
|
+
return [{ type: 'clearTerminal', reason, debug }, ...anchor, ...screen.diff];
|
|
619
626
|
}
|
|
620
627
|
/**
|
|
621
628
|
* Anchored tail repaint for shrink-to-fit frames — the fix for the
|
|
@@ -630,14 +637,14 @@ function fullResetSequence_CAUSES_FLICKER(frame, reason, stylePool, debug) {
|
|
|
630
637
|
* common small shrink — a fold, a spinner unmounting): those rows
|
|
631
638
|
* already live in scrollback and keep their originals. Erase the
|
|
632
639
|
* viewport in place (no 2J — history untouched) and repaint ONLY the
|
|
633
|
-
* changed tail,
|
|
634
|
-
* the scrollback
|
|
635
|
-
*
|
|
636
|
-
*
|
|
637
|
-
*
|
|
640
|
+
* changed tail, starting at the viewport TOP so its first row sits
|
|
641
|
+
* directly under the scrollback's deepest row and the frame continues
|
|
642
|
+
* the transcript seamlessly. The `skip` rows that stayed in scrollback
|
|
643
|
+
* are recorded as `anchoredPad`, so later frames' viewportY math skips
|
|
644
|
+
* them and relative addressing stays consistent.
|
|
638
645
|
* - The frame's top content CHANGED (a panel collapsing, 38 rows → 2):
|
|
639
646
|
* nothing in scrollback represents the new frame — repaint the whole
|
|
640
|
-
* short frame
|
|
647
|
+
* short frame bottom-anchored, matching a fresh render (collapse-shrink's
|
|
641
648
|
* contract), pad 0.
|
|
642
649
|
*/
|
|
643
650
|
function shrinkAnchoredRepaint(prev, next, stylePool, scrollbackRows) {
|
|
@@ -649,7 +656,7 @@ function shrinkAnchoredRepaint(prev, next, stylePool, scrollbackRows) {
|
|
|
649
656
|
// status header's ticking counters) don't matter — only the seam does.
|
|
650
657
|
// Walk the skip down until the seam matches; 0 means the frame's top
|
|
651
658
|
// content changed (a collapsing panel) and the whole short frame gets a
|
|
652
|
-
//
|
|
659
|
+
// bottom-anchored repaint instead.
|
|
653
660
|
const width = Math.min(prev.screen.width, next.screen.width);
|
|
654
661
|
const rowsDiffer = (y) => {
|
|
655
662
|
if (y >= prev.screen.height || y >= next.screen.height)
|
|
@@ -668,18 +675,28 @@ function shrinkAnchoredRepaint(prev, next, stylePool, scrollbackRows) {
|
|
|
668
675
|
const viewportHeight = prev.viewport.height;
|
|
669
676
|
const height = next.screen.height;
|
|
670
677
|
if (skip <= 0) {
|
|
671
|
-
//
|
|
678
|
+
// Whole-frame repaint anchored at the viewport bottom — the fresh-render
|
|
679
|
+
// layout for frames that fit. Padding the leading rows keeps a short frame
|
|
680
|
+
// on the park row instead of stranding it at the viewport top (#1919).
|
|
672
681
|
const contentRows = Math.min(height, Math.max(1, viewportHeight - 1));
|
|
673
682
|
const startY = height - contentRows;
|
|
674
|
-
const
|
|
683
|
+
const blankBand = Math.max(0, viewportHeight - 1 - contentRows);
|
|
684
|
+
const anchor = CURSOR_HOME + eraseToEndOfScreen() + (blankBand > 0 ? cursorDown(blankBand) : '');
|
|
675
685
|
const screen = new VirtualScreen({ x: 0, y: startY }, next.viewport.width);
|
|
676
686
|
renderFrameSlice(screen, next, startY, height, stylePool, false);
|
|
677
687
|
return { patches: [{ type: 'stdout', content: anchor }, ...screen.diff], anchoredPad: 0 };
|
|
678
688
|
}
|
|
679
689
|
const rowsToPaint = Math.max(1, Math.min(height, viewportHeight - 1, height - skip));
|
|
680
690
|
const startY = height - rowsToPaint;
|
|
681
|
-
|
|
682
|
-
|
|
691
|
+
// Paint the tail flush with the viewport top: frame row `skip` (the first
|
|
692
|
+
// row without a scrollback original) lands directly under the scrollback's
|
|
693
|
+
// deepest row. Bottom-aligning the tail instead manufactures a blank band
|
|
694
|
+
// between them, which is the narrow-resize gap: a frame that fits the
|
|
695
|
+
// viewport has no rows stranded in scrollback, so the band is pure hole
|
|
696
|
+
// between the transcript and the last row (the status hint) pinned near
|
|
697
|
+
// the viewport bottom. A frame that still overflows paints the full
|
|
698
|
+
// viewport either way, so this only decides the fitting case.
|
|
699
|
+
const anchor = CURSOR_HOME + eraseToEndOfScreen();
|
|
683
700
|
const screen = new VirtualScreen({ x: 0, y: startY }, next.viewport.width);
|
|
684
701
|
renderFrameSlice(screen, next, startY, height, stylePool, false);
|
|
685
702
|
return {
|
|
@@ -745,6 +762,11 @@ function viewportRepaintPatches(prev, next, stylePool, resetPrefix, origin) {
|
|
|
745
762
|
// steady state, where the park LF materializes one row below the frame).
|
|
746
763
|
const contentRows = Math.min(height, viewportHeight - 1);
|
|
747
764
|
const startY = height - contentRows;
|
|
765
|
+
// Bottom-anchor a frame shorter than the viewport: pad the leading rows so
|
|
766
|
+
// the frame tail lands on the cursor-park row (issue #1919). Painting from
|
|
767
|
+
// the viewport top leaves the composer/status block stranded in the upper
|
|
768
|
+
// half with blank rows below, and no later frame re-anchors it.
|
|
769
|
+
const blankBand = Math.max(0, viewportHeight - 1 - contentRows);
|
|
748
770
|
// Anchor with CSI H (cursor to viewport origin) instead of a RELATIVE
|
|
749
771
|
// cursor-up walk. The relative form assumed the physical cursor sits
|
|
750
772
|
// exactly on the park row — an assumption that breaks after a terminal
|
|
@@ -759,7 +781,8 @@ function viewportRepaintPatches(prev, next, stylePool, resetPrefix, origin) {
|
|
|
759
781
|
// prompt/status pixels survive below short content.
|
|
760
782
|
const anchor = (resetPrefix ? SGR_RESET + LINK_END : '') +
|
|
761
783
|
CURSOR_HOME +
|
|
762
|
-
eraseToEndOfScreen()
|
|
784
|
+
eraseToEndOfScreen() +
|
|
785
|
+
(blankBand > 0 ? cursorDown(blankBand) : '');
|
|
763
786
|
const screen = new VirtualScreen({ x: 0, y: startY }, next.viewport.width);
|
|
764
787
|
renderFrameSlice(screen, next, startY, height, stylePool, false);
|
|
765
788
|
return [{ type: 'stdout', content: anchor }, ...screen.diff];
|