shellpuppet 0.4.2 → 0.5.1
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 +16 -5
- package/dist/agents/agy/index.js +1 -1
- package/dist/agents/agy/index.js.map +1 -1
- package/dist/agents/claude/index.js +1 -1
- package/dist/agents/claude/index.js.map +1 -1
- package/dist/agents/claude/nudge.js +1 -1
- package/dist/agents/claude/nudge.js.map +1 -1
- package/dist/agents/codex/draft.js +13 -6
- package/dist/agents/codex/draft.js.map +1 -1
- package/dist/agents/codex/index.js +1 -1
- package/dist/agents/codex/index.js.map +1 -1
- package/dist/agents/codex/nudge.js +7 -1
- package/dist/agents/codex/nudge.js.map +1 -1
- package/dist/agents/grok/index.js +1 -1
- package/dist/agents/grok/index.js.map +1 -1
- package/dist/agents/grok/nudge.js +13 -5
- package/dist/agents/grok/nudge.js.map +1 -1
- package/dist/agents/hermes/frame.js +4 -4
- package/dist/agents/hermes/frame.js.map +1 -1
- package/dist/agents/hermes/index.js +1 -1
- package/dist/agents/hermes/index.js.map +1 -1
- package/dist/agents/index.d.ts +2 -0
- package/dist/agents/index.js +7 -0
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/mimo/index.js +1 -1
- package/dist/agents/mimo/index.js.map +1 -1
- package/dist/agents/muse/index.js +1 -1
- package/dist/agents/muse/index.js.map +1 -1
- package/dist/agents/muse/nudge.js +8 -3
- package/dist/agents/muse/nudge.js.map +1 -1
- package/dist/agents/nudgeReading.d.ts +2 -0
- package/dist/agents/nudgeReading.js +3 -3
- package/dist/agents/nudgeReading.js.map +1 -1
- package/dist/agents/opencode/index.js +1 -1
- package/dist/agents/opencode/index.js.map +1 -1
- package/dist/agents/qoder/index.js +1 -1
- package/dist/agents/qoder/index.js.map +1 -1
- package/dist/agents/types.d.ts +4 -0
- package/dist/cli/index.js +244 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/client/http.d.ts +3 -0
- package/dist/client/http.js +7 -0
- package/dist/client/http.js.map +1 -1
- package/dist/client/input.d.ts +18 -0
- package/dist/client/input.js +15 -0
- package/dist/client/input.js.map +1 -1
- package/dist/core/session.d.ts +43 -4
- package/dist/core/session.js +169 -29
- package/dist/core/session.js.map +1 -1
- package/dist/core/windowsPtyStart.d.ts +2 -0
- package/dist/core/windowsPtyStart.js +6 -0
- package/dist/core/windowsPtyStart.js.map +1 -1
- package/dist/daemon/audit.d.ts +1 -1
- package/dist/daemon/audit.js +1 -1
- package/dist/daemon/index.js +1 -0
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/launchProfiles.d.ts +9 -2
- package/dist/daemon/launchProfiles.js +27 -8
- package/dist/daemon/launchProfiles.js.map +1 -1
- package/dist/daemon/liveness.d.ts +11 -0
- package/dist/daemon/liveness.js +39 -0
- package/dist/daemon/liveness.js.map +1 -1
- package/dist/daemon/schedules.d.ts +1 -1
- package/dist/daemon/schedules.js +8 -3
- package/dist/daemon/schedules.js.map +1 -1
- package/dist/daemon/screenshot.d.ts +2 -0
- package/dist/daemon/screenshot.js +21 -3
- package/dist/daemon/screenshot.js.map +1 -1
- package/dist/daemon/server.d.ts +17 -1
- package/dist/daemon/server.js +498 -187
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/sessionFeed.d.ts +1 -1
- package/dist/daemon/sessionFeed.js +3 -1
- package/dist/daemon/sessionFeed.js.map +1 -1
- package/dist/daemon/terminalReports.d.ts +9 -1
- package/dist/daemon/terminalReports.js +54 -0
- package/dist/daemon/terminalReports.js.map +1 -1
- package/dist/mcp/tools.js +12 -9
- package/dist/mcp/tools.js.map +1 -1
- package/dist/viewer/dashboard.css +20 -7
- package/dist/viewer/dashboard.js +120 -31
- package/dist/viewer/pane.js +159 -26
- package/package.json +1 -1
package/dist/core/session.js
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*
|
|
14
14
|
* No stdout/stderr: logging via the injected Logger only (lint-enforced).
|
|
15
15
|
*/
|
|
16
|
-
import { agentResumeIds, moduleFor } from '../agents/index.js';
|
|
16
|
+
import { agentResumeIds, hasAgentShellNoColor, moduleFor, programName } from '../agents/index.js';
|
|
17
17
|
import { nudgeVerdict, NUDGE_QUIET_MS } from './nudge.js';
|
|
18
18
|
import { validateStall, possibleStall, resolveSessionAgent, signatureForSession, stallTranscriptContent, stallTurnVisible, StallScreenCache, StallTracker } from './reasoning.js';
|
|
19
19
|
import { execFile } from 'node:child_process';
|
|
@@ -27,7 +27,7 @@ import { commandLine } from './policy.js';
|
|
|
27
27
|
import { detectPrompt, createPromptReader, StalePromptGuard } from './promptDetector.js';
|
|
28
28
|
import { waitFor } from './waiter.js';
|
|
29
29
|
import { readinessFor, trackReadiness, waitUntilReady } from './readiness.js';
|
|
30
|
-
import { canReadExitCode, listenForTerminalErrors, observeConptyStartError, recordedExitCode, releaseFailedStarts, } from './windowsPtyStart.js';
|
|
30
|
+
import { canReadExitCode, listenForTerminalErrors, observeConptyStartError, recordedExitCode, releaseFailedStarts, temporaryResizeReady, } from './windowsPtyStart.js';
|
|
31
31
|
import { queueConsoleHostEnd, registerConsoleHostWindow } from './windowsConsoleHost.js';
|
|
32
32
|
import { DEFAULT_COLS, DEFAULT_ROWS, DEFAULT_SCROLLBACK, MAX_WAIT_TIMEOUT_MS, NULL_LOGGER, RESERVED_FEATURE_CREDENTIALS, SESSION_IDENTITY_ENV_NAMES, validResumeId, } from './types.js';
|
|
33
33
|
/**
|
|
@@ -155,9 +155,10 @@ const SHELL_PROMPTS = [
|
|
|
155
155
|
const TYPED_PLACEHOLDER_SETTLE_MS = 1_000;
|
|
156
156
|
const lineNotSeen = 'The typed text was not seen in the composer; Enter was not sent.';
|
|
157
157
|
const otherInputArrived = 'Other input arrived after the typed text; Enter was not sent.';
|
|
158
|
-
/**
|
|
159
|
-
export function submitOutcome(written) {
|
|
160
|
-
|
|
158
|
+
/** Retain the legacy screen inference, while marked input makes no unproved acceptance claim. */
|
|
159
|
+
export function submitOutcome(written, honest = false) {
|
|
160
|
+
// The legacy positive field is a screen inference, not a correlated acceptance event.
|
|
161
|
+
if (!honest && written.submitted === true)
|
|
161
162
|
return { outcome: 'submitted' };
|
|
162
163
|
if (written.submitted === false && !written.submitRetried) {
|
|
163
164
|
if (written.message === lineNotSeen)
|
|
@@ -297,6 +298,12 @@ export class SessionProgramEndedError extends Error {
|
|
|
297
298
|
this.name = 'SessionProgramEndedError';
|
|
298
299
|
}
|
|
299
300
|
}
|
|
301
|
+
export class TemporaryResizeNotReadyError extends Error {
|
|
302
|
+
constructor() {
|
|
303
|
+
super('A wider read cannot resize this Windows terminal before its first output. Try again after it prints.');
|
|
304
|
+
this.name = 'TemporaryResizeNotReadyError';
|
|
305
|
+
}
|
|
306
|
+
}
|
|
300
307
|
/**
|
|
301
308
|
* Resolve a command to a concrete executable path before spawning directly
|
|
302
309
|
* (`shell: false`). Necessary on **every** platform, for different reasons:
|
|
@@ -539,7 +546,7 @@ export function credentialShapedNames(source = process.env) {
|
|
|
539
546
|
* here rather than in one caller. The session identity names and home are also
|
|
540
547
|
* removed from `passed`; the daemon assigns fresh values to each session.
|
|
541
548
|
*/
|
|
542
|
-
export function buildSessionEnv(mode, platform, source = process.env, passed = {}, reserved = RESERVED_FEATURE_CREDENTIALS) {
|
|
549
|
+
export function buildSessionEnv(mode, platform, source = process.env, passed = {}, reserved = RESERVED_FEATURE_CREDENTIALS, omitInheritedNoColor = hasAgentShellNoColor(source, platform)) {
|
|
543
550
|
const env = {};
|
|
544
551
|
// Session-owned names are reserved in every casing. Windows also reads
|
|
545
552
|
// other reserved names without case; elsewhere those names are exact.
|
|
@@ -549,7 +556,8 @@ export function buildSessionEnv(mode, platform, source = process.env, passed = {
|
|
|
549
556
|
: reserved.has(name));
|
|
550
557
|
if (mode === 'passthrough') {
|
|
551
558
|
for (const [key, value] of Object.entries(source)) {
|
|
552
|
-
if (value !== undefined && !isReserved(key)
|
|
559
|
+
if (value !== undefined && !isReserved(key)
|
|
560
|
+
&& !(omitInheritedNoColor && (platform === 'win32' ? key.toUpperCase() : key) === 'NO_COLOR'))
|
|
553
561
|
env[key] = value;
|
|
554
562
|
}
|
|
555
563
|
}
|
|
@@ -640,9 +648,18 @@ export class Session {
|
|
|
640
648
|
/** Serialises write() so chunked writes cannot interleave. See write(). */
|
|
641
649
|
writeChain = Promise.resolve();
|
|
642
650
|
inputVersion = 0;
|
|
651
|
+
/** Non-empty input from a person or nudge, excluding terminal reports. */
|
|
652
|
+
promptInputRevision = 0;
|
|
653
|
+
/** Every queued PTY write, including terminal reports, preserves submit ordering. */
|
|
654
|
+
writeQueueVersion = 0;
|
|
643
655
|
inputQueueVersion = 0;
|
|
644
656
|
/** A nudge body accepted by the PTY without a confirmed submit. */
|
|
645
657
|
pendingNudgeLine = null;
|
|
658
|
+
pendingNudgeTypedChars = 0;
|
|
659
|
+
pendingNudgeWholeBody = false;
|
|
660
|
+
pendingNudgeInputVersion = 0;
|
|
661
|
+
pendingNudgeQueueVersion = 0;
|
|
662
|
+
pendingNudgeAuditRecorded = false;
|
|
646
663
|
nudgeSchedule;
|
|
647
664
|
writingNudge = false;
|
|
648
665
|
pendingNudgeIds = [];
|
|
@@ -660,7 +677,7 @@ export class Session {
|
|
|
660
677
|
/** Why the input pipe failed (Windows), once it has: input is refused from then on. */
|
|
661
678
|
inputFailure = null;
|
|
662
679
|
lastChange = Date.now();
|
|
663
|
-
/** When
|
|
680
|
+
/** When typing or a nudge was last accepted, excluding terminal reports. */
|
|
664
681
|
lastInputAt = 0;
|
|
665
682
|
recentInputUntil = 0;
|
|
666
683
|
/** Sticky: the rendered screen has shown something at least once. */
|
|
@@ -776,7 +793,7 @@ export class Session {
|
|
|
776
793
|
// for Windows without a Windows process.
|
|
777
794
|
const trackConsoleHost = this.platform === 'win32';
|
|
778
795
|
const consoleHostT0 = trackConsoleHost ? Date.now() : 0;
|
|
779
|
-
const sessionEnv = buildSessionEnv(deps.sessionEnv ?? DEFAULT_SESSION_ENV, this.platform, process.env, options.env);
|
|
796
|
+
const sessionEnv = buildSessionEnv(deps.sessionEnv ?? DEFAULT_SESSION_ENV, this.platform, process.env, options.env, RESERVED_FEATURE_CREDENTIALS, deps.omitInheritedNoColor);
|
|
780
797
|
if (this.launchProfile) {
|
|
781
798
|
if (deps.identity && this.agentModule?.resumeIdMarkers) {
|
|
782
799
|
this.inheritedResumeIds = agentResumeIds(this.agentModule, sessionEnv, this.platform);
|
|
@@ -1134,15 +1151,57 @@ export class Session {
|
|
|
1134
1151
|
write(data, options = {}) {
|
|
1135
1152
|
return this.writeWithResult(data, options).then((result) => result.before);
|
|
1136
1153
|
}
|
|
1154
|
+
/** Queue raw terminal bytes without applying text paste or submit rules. */
|
|
1155
|
+
writeBinary(data, options = {}) {
|
|
1156
|
+
const terminalReport = options.terminalReport === true;
|
|
1157
|
+
// Every frame keeps submit ordering; only non-report bytes count as typing.
|
|
1158
|
+
this.writeQueueVersion++;
|
|
1159
|
+
if (!terminalReport)
|
|
1160
|
+
this.inputQueueVersion++;
|
|
1161
|
+
const queued = this.writeChain.then(() => {
|
|
1162
|
+
this.refuseIfInputFailed();
|
|
1163
|
+
this.refuseIfEnded();
|
|
1164
|
+
if (!terminalReport && data.length > 0)
|
|
1165
|
+
this.noteBinaryInput();
|
|
1166
|
+
this.pty.write(data);
|
|
1167
|
+
});
|
|
1168
|
+
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
1169
|
+
return queued;
|
|
1170
|
+
}
|
|
1171
|
+
/** The human-input bookkeeping a text write does, for raw bytes that are not a terminal report. */
|
|
1172
|
+
noteBinaryInput() {
|
|
1173
|
+
if (this.pendingNudgeLine !== null)
|
|
1174
|
+
this.pendingNudgeTouched = true;
|
|
1175
|
+
this.recentInputUntil = Date.now() + RECENT_INPUT_MS;
|
|
1176
|
+
if (this.stallTracker.reason !== 'server-lost' && this.stallState?.reason !== 'server-lost') {
|
|
1177
|
+
this.stallTracker.noteInput();
|
|
1178
|
+
this.clearStallTimer();
|
|
1179
|
+
this.publishStall(undefined);
|
|
1180
|
+
}
|
|
1181
|
+
const { screen, lines } = this.renderer.snapshot();
|
|
1182
|
+
this.lastInputAt = Date.now();
|
|
1183
|
+
this.inputVersion++;
|
|
1184
|
+
this.promptInputRevision++;
|
|
1185
|
+
this.stalePrompts.noteInput(screen, this.agent, this.renderer.promptStyles(lines));
|
|
1186
|
+
}
|
|
1137
1187
|
/** Write and report what a module can establish about a typed submission. */
|
|
1138
1188
|
writeWithResult(data, options = {}) {
|
|
1139
|
-
this.
|
|
1140
|
-
|
|
1189
|
+
this.writeQueueVersion++;
|
|
1190
|
+
if (options.terminalReport !== true)
|
|
1191
|
+
this.inputQueueVersion++;
|
|
1192
|
+
const delayedSubmit = this.delayedSubmission(data) || options.submitMode === 'on' ||
|
|
1193
|
+
(options.submitMode === 'auto' && this.autoSubmitEligible());
|
|
1141
1194
|
if (delayedSubmit)
|
|
1142
1195
|
this.submissionsQueued++;
|
|
1143
1196
|
const queued = this.writeChain.then(async () => {
|
|
1197
|
+
if (options.submitMode === 'auto')
|
|
1198
|
+
this.refuseIfEnded();
|
|
1144
1199
|
const result = { before: '', submitRetried: false };
|
|
1145
|
-
|
|
1200
|
+
const effective = data + (options.submitMode === 'on' ||
|
|
1201
|
+
(options.submitMode === 'auto' && this.autoSubmitEligible()) ? '\r' : '');
|
|
1202
|
+
result.submitApplied = effective !== data;
|
|
1203
|
+
result.inputBytes = effective.length;
|
|
1204
|
+
result.before = (await this.writeInput(effective, options.terminalReport === true, undefined, undefined, undefined, [], () => 'line-not-seen', (outcome) => Object.assign(result, outcome))) ?? '';
|
|
1146
1205
|
if (result.submitted === true)
|
|
1147
1206
|
this.recentInputUntil = 0;
|
|
1148
1207
|
return result;
|
|
@@ -1154,6 +1213,14 @@ export class Session {
|
|
|
1154
1213
|
this.submissionsQueued--; });
|
|
1155
1214
|
return queued;
|
|
1156
1215
|
}
|
|
1216
|
+
/** The stored command precedes ShellPuppet's own one-shot shell wrapper. */
|
|
1217
|
+
autoSubmitEligible() {
|
|
1218
|
+
const module = this.agentModule;
|
|
1219
|
+
if (module?.input?.submit?.auto !== true || this.exitedFlag || this.isKilled || this.programEnded)
|
|
1220
|
+
return false;
|
|
1221
|
+
const program = programName(this.command);
|
|
1222
|
+
return module.programs.some(pattern => pattern === program || module.matchesProgram?.(pattern, program) === true);
|
|
1223
|
+
}
|
|
1157
1224
|
/** Queue a nudge and retain the original result expected by direct callers. */
|
|
1158
1225
|
async writeNudge(data, ready) {
|
|
1159
1226
|
const result = await this.writeNudgeWithReason(data, ready);
|
|
@@ -1185,6 +1252,22 @@ export class Session {
|
|
|
1185
1252
|
return queued;
|
|
1186
1253
|
}
|
|
1187
1254
|
nudgePendingLine() { return this.pendingNudgeLine; }
|
|
1255
|
+
nudgePendingBodyMeta() {
|
|
1256
|
+
return { pendingBody: this.pendingNudgeLine !== null && this.pendingNudgeTypedChars > 0,
|
|
1257
|
+
typedChars: this.pendingNudgeTypedChars, submitSent: false };
|
|
1258
|
+
}
|
|
1259
|
+
nudgePendingSafeToSubmit() {
|
|
1260
|
+
return this.pendingNudgeLine !== null && this.pendingNudgeWholeBody &&
|
|
1261
|
+
this.pendingNudgeTypedChars === this.pendingNudgeLine.length && !this.pendingNudgeTouched &&
|
|
1262
|
+
this.pendingNudgeInputVersion === this.inputVersion &&
|
|
1263
|
+
this.pendingNudgeQueueVersion === this.inputQueueVersion;
|
|
1264
|
+
}
|
|
1265
|
+
nudgePendingAuditOnce() {
|
|
1266
|
+
if (this.pendingNudgeAuditRecorded)
|
|
1267
|
+
return false;
|
|
1268
|
+
this.pendingNudgeAuditRecorded = true;
|
|
1269
|
+
return true;
|
|
1270
|
+
}
|
|
1188
1271
|
pendingSchedule() { return this.pendingNudgeLine === null ? undefined : this.nudgeSchedule; }
|
|
1189
1272
|
nudgePendingIds() { return this.pendingNudgeIds; }
|
|
1190
1273
|
nudgePendingUntouched() { return !this.pendingNudgeTouched; }
|
|
@@ -1194,6 +1277,23 @@ export class Session {
|
|
|
1194
1277
|
this.pendingTouchRefusalAudited = true;
|
|
1195
1278
|
return true;
|
|
1196
1279
|
}
|
|
1280
|
+
/** Forget a stale mailbox body without writing to or clearing the terminal. */
|
|
1281
|
+
discardStalePendingNudge(line, messageIds) {
|
|
1282
|
+
if (this.writingNudge || this.pendingNudgeLine !== line || messageIds.length === 0 ||
|
|
1283
|
+
this.pendingNudgeIds.length !== messageIds.length ||
|
|
1284
|
+
!messageIds.every((id, index) => this.pendingNudgeIds[index] === id))
|
|
1285
|
+
return false;
|
|
1286
|
+
this.pendingNudgeLine = null;
|
|
1287
|
+
this.pendingNudgeIds = [];
|
|
1288
|
+
this.pendingNudgeTypedChars = 0;
|
|
1289
|
+
this.pendingNudgeWholeBody = false;
|
|
1290
|
+
this.pendingNudgeAuditRecorded = false;
|
|
1291
|
+
this.pendingNudgeTouched = false;
|
|
1292
|
+
this.pendingTouchRefusalAudited = false;
|
|
1293
|
+
this.pendingTurnSubmitted = false;
|
|
1294
|
+
this.pendingTurnBusy = false;
|
|
1295
|
+
return true;
|
|
1296
|
+
}
|
|
1197
1297
|
/** Clear after an observed submitted turn or a whole quiet period of proven emptiness. */
|
|
1198
1298
|
async clearConsumedNudge() {
|
|
1199
1299
|
if (this.pendingNudgeLine === null || this.writingNudge)
|
|
@@ -1213,6 +1313,9 @@ export class Session {
|
|
|
1213
1313
|
return false;
|
|
1214
1314
|
this.pendingNudgeLine = null;
|
|
1215
1315
|
this.pendingNudgeIds = [];
|
|
1316
|
+
this.pendingNudgeTypedChars = 0;
|
|
1317
|
+
this.pendingNudgeWholeBody = false;
|
|
1318
|
+
this.pendingNudgeAuditRecorded = false;
|
|
1216
1319
|
this.pendingNudgeTouched = false;
|
|
1217
1320
|
this.pendingTouchRefusalAudited = false;
|
|
1218
1321
|
this.pendingTurnSubmitted = false;
|
|
@@ -1225,18 +1328,22 @@ export class Session {
|
|
|
1225
1328
|
this.refuseIfInputFailed();
|
|
1226
1329
|
await this.renderer.flush();
|
|
1227
1330
|
this.refuseIfEnded();
|
|
1228
|
-
if (this.pendingNudgeLine !== line || this.
|
|
1331
|
+
if (this.pendingNudgeLine !== line || !this.nudgePendingSafeToSubmit() ||
|
|
1229
1332
|
!ready(this.renderer.snapshot().screen) ||
|
|
1230
1333
|
!this.nudgeReadyWithLine(line))
|
|
1231
1334
|
return false;
|
|
1232
1335
|
this.pty.write(this.nudgeSubmit());
|
|
1233
1336
|
this.pendingNudgeLine = null;
|
|
1234
1337
|
this.pendingNudgeIds = [];
|
|
1338
|
+
this.pendingNudgeTypedChars = 0;
|
|
1339
|
+
this.pendingNudgeWholeBody = false;
|
|
1340
|
+
this.pendingNudgeAuditRecorded = false;
|
|
1235
1341
|
this.pendingNudgeTouched = false;
|
|
1236
1342
|
this.pendingTouchRefusalAudited = false;
|
|
1237
1343
|
this.pendingTurnSubmitted = false;
|
|
1238
1344
|
this.pendingTurnBusy = false;
|
|
1239
1345
|
this.inputVersion++;
|
|
1346
|
+
this.promptInputRevision++;
|
|
1240
1347
|
return true;
|
|
1241
1348
|
});
|
|
1242
1349
|
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
@@ -1309,6 +1416,7 @@ export class Session {
|
|
|
1309
1416
|
return this.agentModule?.input?.submit?.key ?? '\r';
|
|
1310
1417
|
}
|
|
1311
1418
|
nudgeInputVersion() { return this.inputVersion; }
|
|
1419
|
+
promptInputVersion() { return this.promptInputRevision; }
|
|
1312
1420
|
nudgeQueuedInputVersion() { return this.inputQueueVersion; }
|
|
1313
1421
|
nudgeScreenRevision() { return this.screenRevision; }
|
|
1314
1422
|
nudgeReadyWithLine(line, queued = false, whenBusy) {
|
|
@@ -1349,9 +1457,10 @@ export class Session {
|
|
|
1349
1457
|
}
|
|
1350
1458
|
/** A paste is ready only after its draft has appeared and output has settled. */
|
|
1351
1459
|
async waitForTypedDraft(body, placeholdersBefore, startedAt, minimumMs, bodyInputVersion) {
|
|
1352
|
-
const
|
|
1460
|
+
const submit = this.agentModule?.input?.submit;
|
|
1461
|
+
const quietMs = submit?.quietMs ?? 150;
|
|
1353
1462
|
const deadline = startedAt + minimumMs +
|
|
1354
|
-
(
|
|
1463
|
+
(submit?.maxWaitMs ?? TYPED_SUBMIT_WAIT_MS);
|
|
1355
1464
|
for (;;) {
|
|
1356
1465
|
await this.renderer.flush();
|
|
1357
1466
|
this.refuseIfInputFailed();
|
|
@@ -1393,7 +1502,8 @@ export class Session {
|
|
|
1393
1502
|
// Recorded BEFORE the bytes go in, when the screen still shows what this
|
|
1394
1503
|
// input is answering: the waiter's stale-prompt guard needs that prompt,
|
|
1395
1504
|
// and its echo guard needs the input itself.
|
|
1396
|
-
|
|
1505
|
+
if (!terminalReport)
|
|
1506
|
+
this.lastInputData = data;
|
|
1397
1507
|
if (!nudge && !terminalReport && data.length > 0) {
|
|
1398
1508
|
this.recentInputUntil = Date.now() + RECENT_INPUT_MS;
|
|
1399
1509
|
}
|
|
@@ -1413,9 +1523,14 @@ export class Session {
|
|
|
1413
1523
|
// waiting to paint its placeholder, so a new placeholder can only be this body's.
|
|
1414
1524
|
const settledBefore = Date.now() - this.lastInputAt >= TYPED_PLACEHOLDER_SETTLE_MS &&
|
|
1415
1525
|
Date.now() - this.lastChange >= TYPED_PLACEHOLDER_SETTLE_MS;
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1526
|
+
if (!terminalReport) {
|
|
1527
|
+
this.lastInputAt = Date.now();
|
|
1528
|
+
this.inputVersion++;
|
|
1529
|
+
}
|
|
1530
|
+
if (!terminalReport && data.length > 0)
|
|
1531
|
+
this.promptInputRevision++;
|
|
1532
|
+
if (!terminalReport)
|
|
1533
|
+
this.stalePrompts.noteInput(screen, this.agent, this.renderer.promptStyles(lines));
|
|
1419
1534
|
if (nudge || this.delayedSubmission(data)) {
|
|
1420
1535
|
const submit = this.agentModule?.input?.submit;
|
|
1421
1536
|
const key = nudgeKey ?? submit.key;
|
|
@@ -1423,6 +1538,7 @@ export class Session {
|
|
|
1423
1538
|
const delayMs = nudge ? Math.max(NUDGE_SUBMIT_DELAY_MS, submit?.delayMs ?? 0)
|
|
1424
1539
|
: Math.max(submit.delayMs, Math.ceil(Array.from(body).length * (submit?.perCharacterMs ?? 0)));
|
|
1425
1540
|
const queuedInputVersion = this.inputQueueVersion;
|
|
1541
|
+
const queuedWriteVersion = this.writeQueueVersion;
|
|
1426
1542
|
if (!nudge && this.agentModule?.nudge !== undefined)
|
|
1427
1543
|
await this.renderer.flush();
|
|
1428
1544
|
// Typed text waits for proof only when the agent's own composer is on screen. Before the
|
|
@@ -1437,13 +1553,20 @@ export class Session {
|
|
|
1437
1553
|
if (nudge) {
|
|
1438
1554
|
this.pendingNudgeLine = body;
|
|
1439
1555
|
this.pendingNudgeIds = [...messageIds];
|
|
1556
|
+
this.pendingNudgeTypedChars = 0;
|
|
1557
|
+
this.pendingNudgeWholeBody = false;
|
|
1558
|
+
this.pendingNudgeInputVersion = this.inputVersion;
|
|
1559
|
+
this.pendingNudgeQueueVersion = this.inputQueueVersion;
|
|
1560
|
+
this.pendingNudgeAuditRecorded = false;
|
|
1440
1561
|
this.pendingNudgeTouched = false;
|
|
1441
1562
|
this.pendingTouchRefusalAudited = false;
|
|
1442
1563
|
this.pendingTurnSubmitted = false;
|
|
1443
1564
|
this.pendingTurnBusy = false;
|
|
1444
1565
|
this.pendingQuietSince = Date.now();
|
|
1445
1566
|
}
|
|
1446
|
-
await this.writeData(body);
|
|
1567
|
+
await this.writeData(body, nudge ? (accepted) => { this.pendingNudgeTypedChars += accepted.length; } : undefined);
|
|
1568
|
+
if (nudge)
|
|
1569
|
+
this.pendingNudgeWholeBody = this.pendingNudgeTypedChars === body.length;
|
|
1447
1570
|
const bodyInputVersion = this.inputVersion;
|
|
1448
1571
|
const bodyWrittenAt = Date.now();
|
|
1449
1572
|
try {
|
|
@@ -1509,7 +1632,7 @@ export class Session {
|
|
|
1509
1632
|
this.pty.write(key);
|
|
1510
1633
|
if (!nudge) {
|
|
1511
1634
|
onTypedSubmit?.(readableComposer || this.agentModule?.nudge === undefined
|
|
1512
|
-
? await this.checkTypedSubmission(body, key,
|
|
1635
|
+
? await this.checkTypedSubmission(body, key, queuedWriteVersion, typedDraftSeen, beforeSubmitScreen, wasBusy, placeholdersBefore)
|
|
1513
1636
|
: { submitRetried: false,
|
|
1514
1637
|
message: "Submit key sent; the agent's composer was not on screen when the text was typed." });
|
|
1515
1638
|
}
|
|
@@ -1520,6 +1643,9 @@ export class Session {
|
|
|
1520
1643
|
if (nudge) {
|
|
1521
1644
|
this.pendingNudgeLine = null;
|
|
1522
1645
|
this.pendingNudgeIds = [];
|
|
1646
|
+
this.pendingNudgeTypedChars = 0;
|
|
1647
|
+
this.pendingNudgeWholeBody = false;
|
|
1648
|
+
this.pendingNudgeAuditRecorded = false;
|
|
1523
1649
|
this.pendingNudgeTouched = false;
|
|
1524
1650
|
this.pendingTouchRefusalAudited = false;
|
|
1525
1651
|
this.pendingTurnSubmitted = false;
|
|
@@ -1554,7 +1680,7 @@ export class Session {
|
|
|
1554
1680
|
const after = transcript(this.renderer.snapshot().screen);
|
|
1555
1681
|
return after.includes(body) && !transcript(beforeScreen).includes(body);
|
|
1556
1682
|
}
|
|
1557
|
-
async checkTypedSubmission(body, key,
|
|
1683
|
+
async checkTypedSubmission(body, key, queuedWriteVersion, draftSeen, beforeSubmitScreen, wasBusy, placeholdersBefore) {
|
|
1558
1684
|
if (this.agentModule?.nudge === undefined) {
|
|
1559
1685
|
return { submitRetried: false,
|
|
1560
1686
|
message: 'Submit key sent; this programme has no readable composer.' };
|
|
@@ -1562,7 +1688,7 @@ export class Session {
|
|
|
1562
1688
|
const settleMs = this.agentModule.input?.submit?.settleMs ?? TYPED_SUBMIT_SETTLE_MS;
|
|
1563
1689
|
await new Promise((resolve) => setTimeout(resolve, settleMs));
|
|
1564
1690
|
await this.renderer.flush();
|
|
1565
|
-
if (this.
|
|
1691
|
+
if (this.writeQueueVersion !== queuedWriteVersion) {
|
|
1566
1692
|
return { submitRetried: false,
|
|
1567
1693
|
message: 'Submit key sent; later input arrived before the composer check.' };
|
|
1568
1694
|
}
|
|
@@ -1578,7 +1704,7 @@ export class Session {
|
|
|
1578
1704
|
this.refuseIfInputFailed();
|
|
1579
1705
|
this.refuseIfEnded();
|
|
1580
1706
|
// A prompt or changed composer can appear while the first Enter settles.
|
|
1581
|
-
if (this.
|
|
1707
|
+
if (this.writeQueueVersion !== queuedWriteVersion ||
|
|
1582
1708
|
!this.typedDraftVisible(body, placeholdersBefore)) {
|
|
1583
1709
|
return { submitRetried: false,
|
|
1584
1710
|
message: 'Submit key sent; the composer changed before a retry.' };
|
|
@@ -1586,7 +1712,7 @@ export class Session {
|
|
|
1586
1712
|
this.pty.write(key);
|
|
1587
1713
|
await new Promise((resolve) => setTimeout(resolve, settleMs));
|
|
1588
1714
|
await this.renderer.flush();
|
|
1589
|
-
if (this.
|
|
1715
|
+
if (this.writeQueueVersion !== queuedWriteVersion) {
|
|
1590
1716
|
return { submitRetried: true,
|
|
1591
1717
|
message: 'Submit key retried; later input arrived before confirmation.' };
|
|
1592
1718
|
}
|
|
@@ -1599,11 +1725,12 @@ export class Session {
|
|
|
1599
1725
|
this.typedLineInTranscript(body, beforeSubmitScreen)) ? { submitted: true } : {}), submitRetried: true,
|
|
1600
1726
|
message: 'Submit key retried once after the typed text remained in the composer.' };
|
|
1601
1727
|
}
|
|
1602
|
-
async writeData(data) {
|
|
1728
|
+
async writeData(data, onAccepted) {
|
|
1603
1729
|
if (data.length <= WRITE_CHUNK_CHARS) {
|
|
1604
1730
|
if (data !== '' && this.pendingNudgeLine !== null)
|
|
1605
1731
|
this.pendingQuietSince = Date.now();
|
|
1606
1732
|
this.pty.write(data);
|
|
1733
|
+
onAccepted?.(data);
|
|
1607
1734
|
return;
|
|
1608
1735
|
}
|
|
1609
1736
|
// Bracketed paste: ONE write, no chunking, exactly as a terminal delivers a
|
|
@@ -1619,6 +1746,7 @@ export class Session {
|
|
|
1619
1746
|
if (this.pendingNudgeLine !== null)
|
|
1620
1747
|
this.pendingQuietSince = Date.now();
|
|
1621
1748
|
this.pty.write(`${PASTE_START}${body}${PASTE_END}${trailer}`);
|
|
1749
|
+
onAccepted?.(data);
|
|
1622
1750
|
return;
|
|
1623
1751
|
}
|
|
1624
1752
|
this.lastWriteWrapped = false;
|
|
@@ -1638,6 +1766,7 @@ export class Session {
|
|
|
1638
1766
|
if (this.pendingNudgeLine !== null)
|
|
1639
1767
|
this.pendingQuietSince = Date.now();
|
|
1640
1768
|
this.pty.write(data.slice(offset, end));
|
|
1769
|
+
onAccepted?.(data.slice(offset, end));
|
|
1641
1770
|
offset = end;
|
|
1642
1771
|
if (offset < data.length) {
|
|
1643
1772
|
await new Promise((resolve) => setTimeout(resolve, WRITE_CHUNK_DELAY_MS));
|
|
@@ -1675,13 +1804,19 @@ export class Session {
|
|
|
1675
1804
|
* dropped (`windowsPtyStart.ts`).
|
|
1676
1805
|
*/
|
|
1677
1806
|
resize(cols, rows, options = {}) {
|
|
1807
|
+
const apply = () => {
|
|
1808
|
+
if (options.shouldApply?.() === false)
|
|
1809
|
+
return;
|
|
1810
|
+
if (!options.skipIfSame || cols !== this.renderer.cols || rows !== this.renderer.rows)
|
|
1811
|
+
this.resizeNow(cols, rows, options);
|
|
1812
|
+
options.onApplied?.();
|
|
1813
|
+
};
|
|
1678
1814
|
if (this.agentModule?.input?.resizeBehindSubmit === true && this.submissionsQueued > 0) {
|
|
1679
|
-
const queued = this.writeChain.then(
|
|
1815
|
+
const queued = this.writeChain.then(apply);
|
|
1680
1816
|
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
1681
1817
|
return queued;
|
|
1682
1818
|
}
|
|
1683
|
-
|
|
1684
|
-
options.onApplied?.();
|
|
1819
|
+
apply();
|
|
1685
1820
|
}
|
|
1686
1821
|
/** Decide and apply a geometry act together at its place in the submit queue. */
|
|
1687
1822
|
resizeIfCurrent(cols, rows, shouldApply, onApplied, skipIfSame = false) {
|
|
@@ -1704,6 +1839,11 @@ export class Session {
|
|
|
1704
1839
|
resizeNow(cols, rows, options) {
|
|
1705
1840
|
if (this.exitedFlag || this.isKilled)
|
|
1706
1841
|
throw new SessionProgramEndedError(this.id, this.exitCodeValue);
|
|
1842
|
+
if (options.temporarySignal?.aborted)
|
|
1843
|
+
throw new Error('Temporary resize was cancelled.');
|
|
1844
|
+
if (options.temporarySignal !== undefined && this.platform === 'win32' && !temporaryResizeReady(this.pty)) {
|
|
1845
|
+
throw new TemporaryResizeNotReadyError();
|
|
1846
|
+
}
|
|
1707
1847
|
const ended = recordedExitCode(this.pty);
|
|
1708
1848
|
if (ended !== undefined)
|
|
1709
1849
|
throw new SessionProgramEndedError(this.id, ended);
|