shellpuppet 0.5.1 → 0.5.3
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 +5 -5
- package/dist/agents/agy/nudge.js +58 -5
- package/dist/agents/agy/nudge.js.map +1 -1
- package/dist/agents/codex/index.js +1 -1
- package/dist/agents/codex/index.js.map +1 -1
- package/dist/agents/hermes/index.js +2 -2
- package/dist/agents/hermes/index.js.map +1 -1
- package/dist/agents/hermes/nudge.d.ts +1 -0
- package/dist/agents/hermes/nudge.js +5 -0
- package/dist/agents/hermes/nudge.js.map +1 -1
- package/dist/agents/types.d.ts +4 -0
- package/dist/cli/index.js +47 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/client/http.d.ts +2 -2
- package/dist/client/http.js +1 -1
- package/dist/client/http.js.map +1 -1
- package/dist/core/dialogs.d.ts +4 -1
- package/dist/core/dialogs.js +25 -5
- package/dist/core/dialogs.js.map +1 -1
- package/dist/core/mailbox.d.ts +25 -4
- package/dist/core/mailbox.js +36 -5
- package/dist/core/mailbox.js.map +1 -1
- package/dist/core/manager.d.ts +1 -0
- package/dist/core/manager.js +5 -1
- package/dist/core/manager.js.map +1 -1
- package/dist/core/policy.d.ts +5 -3
- package/dist/core/policy.js +25 -23
- package/dist/core/policy.js.map +1 -1
- package/dist/core/readingContext.d.ts +9 -0
- package/dist/core/readingContext.js +4 -0
- package/dist/core/readingContext.js.map +1 -0
- package/dist/core/reasoning.d.ts +2 -1
- package/dist/core/reasoning.js +33 -11
- package/dist/core/reasoning.js.map +1 -1
- package/dist/core/renderer.d.ts +5 -0
- package/dist/core/renderer.js +31 -2
- package/dist/core/renderer.js.map +1 -1
- package/dist/core/session.d.ts +50 -32
- package/dist/core/session.js +333 -164
- package/dist/core/session.js.map +1 -1
- package/dist/daemon/config.d.ts +11 -1
- package/dist/daemon/config.js +42 -20
- package/dist/daemon/config.js.map +1 -1
- package/dist/daemon/configReload.d.ts +55 -0
- package/dist/daemon/configReload.js +284 -0
- package/dist/daemon/configReload.js.map +1 -0
- package/dist/daemon/configWatcher.d.ts +55 -0
- package/dist/daemon/configWatcher.js +313 -0
- package/dist/daemon/configWatcher.js.map +1 -0
- package/dist/daemon/homeOwner.d.ts +2 -1
- package/dist/daemon/homeOwner.js +33 -8
- package/dist/daemon/homeOwner.js.map +1 -1
- package/dist/daemon/index.js +3 -50
- package/dist/daemon/index.js.map +1 -1
- package/dist/daemon/launchProfiles.d.ts +5 -3
- package/dist/daemon/launchProfiles.js +12 -7
- package/dist/daemon/launchProfiles.js.map +1 -1
- package/dist/daemon/nudgeScheduler.d.ts +4 -4
- package/dist/daemon/nudgeScheduler.js +16 -15
- package/dist/daemon/nudgeScheduler.js.map +1 -1
- package/dist/daemon/paths.d.ts +22 -4
- package/dist/daemon/paths.js +126 -24
- package/dist/daemon/paths.js.map +1 -1
- package/dist/daemon/restartSource.d.ts +3 -3
- package/dist/daemon/restartSource.js +5 -4
- package/dist/daemon/restartSource.js.map +1 -1
- package/dist/daemon/schedules.d.ts +6 -5
- package/dist/daemon/schedules.js +15 -51
- package/dist/daemon/schedules.js.map +1 -1
- package/dist/daemon/server.d.ts +27 -17
- package/dist/daemon/server.js +576 -453
- package/dist/daemon/server.js.map +1 -1
- package/dist/daemon/standaloneOptions.d.ts +4 -0
- package/dist/daemon/standaloneOptions.js +29 -0
- package/dist/daemon/standaloneOptions.js.map +1 -0
- package/dist/mcp/index.js +0 -4
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/tools.d.ts +0 -6
- package/dist/mcp/tools.js +90 -85
- package/dist/mcp/tools.js.map +1 -1
- package/dist/viewer/dashboard.css +24 -2
- package/dist/viewer/dashboard.html +1 -1
- package/dist/viewer/dashboard.js +127 -16
- package/dist/viewer/index.html +4 -3
- package/dist/viewer/pane.js +91 -395
- package/dist/viewer/viewer.css +23 -4
- package/dist/viewer/viewer.js +2 -0
- package/package.json +1 -1
package/dist/core/session.js
CHANGED
|
@@ -30,6 +30,13 @@ import { readinessFor, trackReadiness, waitUntilReady } from './readiness.js';
|
|
|
30
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
|
+
export class MailNudgeWriteError extends Error {
|
|
34
|
+
typedChars;
|
|
35
|
+
constructor(typedChars, cause) {
|
|
36
|
+
super('Writing the mailbox nudge failed.', { cause });
|
|
37
|
+
this.typedChars = typedChars;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
33
40
|
/**
|
|
34
41
|
* Hard cap on `taskkill`. Without it a wedged kill never calls back, so
|
|
35
42
|
* `kill()` never resolves, `killAll()` never resolves and daemon shutdown
|
|
@@ -641,6 +648,7 @@ export class Session {
|
|
|
641
648
|
// again when the PTY reports it with the program's first later output.
|
|
642
649
|
stallPtyCols = 0;
|
|
643
650
|
stallPtyRows = 0;
|
|
651
|
+
sessionEnvMode;
|
|
644
652
|
stallScreen = new StallScreenCache();
|
|
645
653
|
stallInk;
|
|
646
654
|
/** Whether the program has hidden the cursor (DECTCEM off), carried to viewers. */
|
|
@@ -648,27 +656,23 @@ export class Session {
|
|
|
648
656
|
/** Serialises write() so chunked writes cannot interleave. See write(). */
|
|
649
657
|
writeChain = Promise.resolve();
|
|
650
658
|
inputVersion = 0;
|
|
659
|
+
outputVersion = 0;
|
|
660
|
+
outputBeforeClear;
|
|
661
|
+
unconfirmedNudge;
|
|
662
|
+
confirmedMailVersion = 0;
|
|
651
663
|
/** Non-empty input from a person or nudge, excluding terminal reports. */
|
|
652
664
|
promptInputRevision = 0;
|
|
653
665
|
/** Every queued PTY write, including terminal reports, preserves submit ordering. */
|
|
654
666
|
writeQueueVersion = 0;
|
|
655
667
|
inputQueueVersion = 0;
|
|
656
|
-
/** A
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
pendingNudgeInputVersion = 0;
|
|
661
|
-
pendingNudgeQueueVersion = 0;
|
|
662
|
-
pendingNudgeAuditRecorded = false;
|
|
663
|
-
nudgeSchedule;
|
|
664
|
-
writingNudge = false;
|
|
665
|
-
pendingNudgeIds = [];
|
|
666
|
-
/** Any input from outside the daemon permanently claims this pending composer. */
|
|
667
|
-
pendingNudgeTouched = false;
|
|
668
|
-
pendingTouchRefusalAudited = false;
|
|
668
|
+
/** A scheduled prompt whose guarded write has yet to clear. */
|
|
669
|
+
scheduleDraft = null;
|
|
670
|
+
scheduleName;
|
|
671
|
+
writingSchedule = false;
|
|
669
672
|
pendingTurnSubmitted = false;
|
|
670
673
|
pendingTurnBusy = false;
|
|
671
674
|
pendingQuietSince = 0;
|
|
675
|
+
pendingClock = () => performance.now();
|
|
672
676
|
pendingNudgeSettleMs;
|
|
673
677
|
screenRevision = 0;
|
|
674
678
|
nudgeComposerKey = '';
|
|
@@ -679,6 +683,7 @@ export class Session {
|
|
|
679
683
|
lastChange = Date.now();
|
|
680
684
|
/** When typing or a nudge was last accepted, excluding terminal reports. */
|
|
681
685
|
lastInputAt = 0;
|
|
686
|
+
pasteWindowEnd = 0;
|
|
682
687
|
recentInputUntil = 0;
|
|
683
688
|
/** Sticky: the rendered screen has shown something at least once. */
|
|
684
689
|
painted = false;
|
|
@@ -793,7 +798,8 @@ export class Session {
|
|
|
793
798
|
// for Windows without a Windows process.
|
|
794
799
|
const trackConsoleHost = this.platform === 'win32';
|
|
795
800
|
const consoleHostT0 = trackConsoleHost ? Date.now() : 0;
|
|
796
|
-
|
|
801
|
+
this.sessionEnvMode = deps.sessionEnv ?? DEFAULT_SESSION_ENV;
|
|
802
|
+
const sessionEnv = buildSessionEnv(this.sessionEnvMode, this.platform, process.env, options.env, RESERVED_FEATURE_CREDENTIALS, deps.omitInheritedNoColor);
|
|
797
803
|
if (this.launchProfile) {
|
|
798
804
|
if (deps.identity && this.agentModule?.resumeIdMarkers) {
|
|
799
805
|
this.inheritedResumeIds = agentResumeIds(this.agentModule, sessionEnv, this.platform);
|
|
@@ -806,7 +812,8 @@ export class Session {
|
|
|
806
812
|
sessionEnv['SHELLPUPPET_DAEMON_INSTANCE'] = deps.identity.instanceId;
|
|
807
813
|
sessionEnv['SHELLPUPPET_CLI'] = deps.identity.cliPath;
|
|
808
814
|
if (deps.identity.home !== undefined) {
|
|
809
|
-
|
|
815
|
+
const home = typeof deps.identity.home === 'function' ? deps.identity.home() : deps.identity.home;
|
|
816
|
+
setEnvValue(sessionEnv, this.platform, 'SHELLPUPPET_HOME', home);
|
|
810
817
|
}
|
|
811
818
|
}
|
|
812
819
|
const spawnOptions = {
|
|
@@ -875,8 +882,8 @@ export class Session {
|
|
|
875
882
|
this.pty.onData((data) => {
|
|
876
883
|
if (this.exitedFlag || this.isKilled)
|
|
877
884
|
return;
|
|
878
|
-
if (this.
|
|
879
|
-
this.pendingQuietSince =
|
|
885
|
+
if (this.scheduleDraft !== null)
|
|
886
|
+
this.pendingQuietSince = this.pendingClock();
|
|
880
887
|
// node-pty can apply a requested resize later, after its first output.
|
|
881
888
|
// Observe the dimensions it reports as well as our explicit requests.
|
|
882
889
|
if (this.pty.cols !== this.stallPtyCols || this.pty.rows !== this.stallPtyRows) {
|
|
@@ -899,6 +906,7 @@ export class Session {
|
|
|
899
906
|
this.bracketedPaste = bracketedPasteAfter(scan, this.bracketedPaste);
|
|
900
907
|
this.cursorHidden = cursorHiddenAfter(scan, this.cursorHidden);
|
|
901
908
|
this.modeScanTail = scan.slice(-MODE_SCAN_TAIL_CHARS);
|
|
909
|
+
this.outputVersion++;
|
|
902
910
|
const rendered = this.renderer.write(data);
|
|
903
911
|
if (this.agentModule?.stalls !== undefined) {
|
|
904
912
|
void rendered.then(() => {
|
|
@@ -1149,7 +1157,7 @@ export class Session {
|
|
|
1149
1157
|
* including for the rest of a chunked write it fails part-way through.
|
|
1150
1158
|
*/
|
|
1151
1159
|
write(data, options = {}) {
|
|
1152
|
-
return this.writeWithResult(data, options).then((result) => result.before);
|
|
1160
|
+
return this.writeWithResult(data, { ...options, kind: 'raw' }).then((result) => result.before);
|
|
1153
1161
|
}
|
|
1154
1162
|
/** Queue raw terminal bytes without applying text paste or submit rules. */
|
|
1155
1163
|
writeBinary(data, options = {}) {
|
|
@@ -1158,21 +1166,37 @@ export class Session {
|
|
|
1158
1166
|
this.writeQueueVersion++;
|
|
1159
1167
|
if (!terminalReport)
|
|
1160
1168
|
this.inputQueueVersion++;
|
|
1161
|
-
|
|
1169
|
+
return this.queueInput(() => {
|
|
1162
1170
|
this.refuseIfInputFailed();
|
|
1163
1171
|
this.refuseIfEnded();
|
|
1164
1172
|
if (!terminalReport && data.length > 0)
|
|
1165
|
-
this.
|
|
1173
|
+
this.noteRawInput(data);
|
|
1166
1174
|
this.pty.write(data);
|
|
1167
1175
|
});
|
|
1176
|
+
}
|
|
1177
|
+
queueInput(write) {
|
|
1178
|
+
const queued = this.writeChain.then(write);
|
|
1168
1179
|
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
1169
1180
|
return queued;
|
|
1170
1181
|
}
|
|
1171
|
-
|
|
1172
|
-
noteBinaryInput() {
|
|
1173
|
-
if (this.pendingNudgeLine !== null)
|
|
1174
|
-
this.pendingNudgeTouched = true;
|
|
1182
|
+
notePersonInput(data) {
|
|
1175
1183
|
this.recentInputUntil = Date.now() + RECENT_INPUT_MS;
|
|
1184
|
+
this.outputBeforeClear = undefined;
|
|
1185
|
+
const module = this.agentModule?.nudge;
|
|
1186
|
+
if (!module || module.waitAfterPersonInput)
|
|
1187
|
+
return;
|
|
1188
|
+
const key = data.length === 1 ? data.toString() : '';
|
|
1189
|
+
if (key === '\x15' || key === this.nudgeSubmit() || key === this.nudgeSubmit(true)) {
|
|
1190
|
+
const view = this.nudgeView();
|
|
1191
|
+
if (module.readiness({ ...view, whenBusy: 'queue' }) === 'draft' &&
|
|
1192
|
+
(key === '\x15' || key === this.nudgeSubmit(module.readiness(view) === 'busy'))) {
|
|
1193
|
+
this.outputBeforeClear = this.outputVersion;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1197
|
+
/** The human-input bookkeeping a text write does, for raw bytes that are not a terminal report. */
|
|
1198
|
+
noteRawInput(data) {
|
|
1199
|
+
this.notePersonInput(data);
|
|
1176
1200
|
if (this.stallTracker.reason !== 'server-lost' && this.stallState?.reason !== 'server-lost') {
|
|
1177
1201
|
this.stallTracker.noteInput();
|
|
1178
1202
|
this.clearStallTimer();
|
|
@@ -1201,7 +1225,15 @@ export class Session {
|
|
|
1201
1225
|
(options.submitMode === 'auto' && this.autoSubmitEligible()) ? '\r' : '');
|
|
1202
1226
|
result.submitApplied = effective !== data;
|
|
1203
1227
|
result.inputBytes = effective.length;
|
|
1204
|
-
|
|
1228
|
+
const submit = this.agentModule?.input?.submit;
|
|
1229
|
+
if (options.kind === 'enter' && performance.now() < this.pasteWindowEnd) {
|
|
1230
|
+
result.warning = "Enter may be absorbed by the agent's paste window. Type with submit instead.";
|
|
1231
|
+
}
|
|
1232
|
+
result.before = (await this.writeInput(effective, options.terminalReport === true, undefined, undefined, undefined, () => 'line-not-seen', (outcome) => Object.assign(result, outcome))) ?? '';
|
|
1233
|
+
if (submit?.perCharacterMs !== undefined && !options.terminalReport &&
|
|
1234
|
+
(options.kind === undefined || options.humanInput) && effective.length > 0 && !effective.endsWith(submit.key)) {
|
|
1235
|
+
this.pasteWindowEnd = Math.max(this.pasteWindowEnd, performance.now() + this.typedSubmitDelay(effective));
|
|
1236
|
+
}
|
|
1205
1237
|
if (result.submitted === true)
|
|
1206
1238
|
this.recentInputUntil = 0;
|
|
1207
1239
|
return result;
|
|
@@ -1213,6 +1245,9 @@ export class Session {
|
|
|
1213
1245
|
this.submissionsQueued--; });
|
|
1214
1246
|
return queued;
|
|
1215
1247
|
}
|
|
1248
|
+
async writeEnter() {
|
|
1249
|
+
return (await this.writeWithResult('\r', { kind: 'enter' })).warning;
|
|
1250
|
+
}
|
|
1216
1251
|
/** The stored command precedes ShellPuppet's own one-shot shell wrapper. */
|
|
1217
1252
|
autoSubmitEligible() {
|
|
1218
1253
|
const module = this.agentModule;
|
|
@@ -1221,21 +1256,235 @@ export class Session {
|
|
|
1221
1256
|
const program = programName(this.command);
|
|
1222
1257
|
return module.programs.some(pattern => pattern === program || module.matchesProgram?.(pattern, program) === true);
|
|
1223
1258
|
}
|
|
1259
|
+
get hasUnconfirmedMail() { return this.unconfirmedNudge?.editRevision === this.promptInputRevision; }
|
|
1260
|
+
/** A null batch only observes the previous submit. It cannot type a body or retry a key. */
|
|
1261
|
+
deliverMailNudge(batch, now, onWrite, onConfirmed) {
|
|
1262
|
+
if (!this.painted || !this.agentModule?.nudge || !this.agentModule.input?.submit) {
|
|
1263
|
+
return Promise.resolve({ outcome: 'wait' });
|
|
1264
|
+
}
|
|
1265
|
+
if (batch && !this.hasUnconfirmedMail && !this.nudgeState(now(), undefined, true).ready) {
|
|
1266
|
+
return Promise.resolve({ outcome: 'wait' });
|
|
1267
|
+
}
|
|
1268
|
+
const confirmed = this.confirmedMailVersion;
|
|
1269
|
+
this.submissionsQueued++;
|
|
1270
|
+
const run = this.writeChain.then(async () => {
|
|
1271
|
+
// A schedule and a mail scan can both select the same waiting IDs. If an
|
|
1272
|
+
// earlier slot confirmed mail, let the scheduler select a fresh batch.
|
|
1273
|
+
if (confirmed !== this.confirmedMailVersion)
|
|
1274
|
+
return { outcome: 'wait' };
|
|
1275
|
+
const result = await this.deliverMailInQueue(batch, now, onWrite);
|
|
1276
|
+
if (result.outcome === 'sent') {
|
|
1277
|
+
try {
|
|
1278
|
+
onConfirmed?.(result.ids, result.queued);
|
|
1279
|
+
}
|
|
1280
|
+
finally {
|
|
1281
|
+
this.confirmedMailVersion++;
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
return result;
|
|
1285
|
+
});
|
|
1286
|
+
this.writeChain = run.then(() => { this.submissionsQueued--; }, () => { this.submissionsQueued--; });
|
|
1287
|
+
return run;
|
|
1288
|
+
}
|
|
1289
|
+
async deliverMailInQueue(batch, now, onWrite) {
|
|
1290
|
+
const submit = this.agentModule?.input?.submit;
|
|
1291
|
+
if (!submit || !this.agentModule?.nudge || !this.painted || this.scheduleDraft !== null)
|
|
1292
|
+
return { outcome: 'wait' };
|
|
1293
|
+
const settleMs = submit.settleMs ?? TYPED_SUBMIT_SETTLE_MS;
|
|
1294
|
+
let deadline = performance.now() + settleMs;
|
|
1295
|
+
if (await this.flushMailBefore(deadline) !== this.outputVersion)
|
|
1296
|
+
return { outcome: 'wait' };
|
|
1297
|
+
if (this.unconfirmedNudge?.editRevision !== this.promptInputRevision)
|
|
1298
|
+
this.unconfirmedNudge = undefined;
|
|
1299
|
+
const previous = this.unconfirmedNudge;
|
|
1300
|
+
const composer = previous && this.mailComposer(previous);
|
|
1301
|
+
if (previous && composer && this.mailDraftCleared(previous, composer)) {
|
|
1302
|
+
this.unconfirmedNudge = undefined;
|
|
1303
|
+
return { outcome: 'sent', ids: previous.ids, queued: previous.queued };
|
|
1304
|
+
}
|
|
1305
|
+
if (batch === null) {
|
|
1306
|
+
// A submitted line with no signal can yield an empty composer to a due
|
|
1307
|
+
// schedule. Its IDs still wait for the next eligible mailbox scan.
|
|
1308
|
+
if (previous?.lastKey && composer?.empty && !composer.ownDraft)
|
|
1309
|
+
this.unconfirmedNudge = undefined;
|
|
1310
|
+
return { outcome: 'wait' };
|
|
1311
|
+
}
|
|
1312
|
+
// A slow drain can end the retry's confirmation window. Finish that
|
|
1313
|
+
// observation on the next scan before sending any further key.
|
|
1314
|
+
if (previous?.lastKey?.retried && !previous.audited && composer?.exact) {
|
|
1315
|
+
previous.audited = true;
|
|
1316
|
+
return { outcome: 'unconfirmed', ids: previous.ids, queued: previous.queued };
|
|
1317
|
+
}
|
|
1318
|
+
const resume = previous !== undefined && (!previous.lastKey || composer?.exact === true);
|
|
1319
|
+
let attempt = resume ? previous : undefined;
|
|
1320
|
+
if (!attempt) {
|
|
1321
|
+
// An available empty composer can receive waiting mail again after a submit without a signal.
|
|
1322
|
+
const state = this.nudgeState(now(), undefined, true);
|
|
1323
|
+
if (!state.ready)
|
|
1324
|
+
return { outcome: 'wait' };
|
|
1325
|
+
this.unconfirmedNudge = undefined;
|
|
1326
|
+
if (batch.ids.length === 0)
|
|
1327
|
+
return { outcome: 'done' };
|
|
1328
|
+
const { screen, lines } = this.renderer.snapshot();
|
|
1329
|
+
if (this.answerablePrompt(screen))
|
|
1330
|
+
return { outcome: 'wait' };
|
|
1331
|
+
const placeholdersBefore = submit.pastePlaceholder &&
|
|
1332
|
+
Date.now() - Math.max(this.lastInputAt, this.lastChange) >= TYPED_PLACEHOLDER_SETTLE_MS
|
|
1333
|
+
? this.visiblePastePlaceholders() : undefined;
|
|
1334
|
+
this.stalePrompts.noteInput(screen, this.agent, this.renderer.promptStyles(lines));
|
|
1335
|
+
this.lastInputData = batch.line + this.nudgeSubmit(state.queued);
|
|
1336
|
+
this.lastInputAt = Date.now();
|
|
1337
|
+
this.inputVersion++;
|
|
1338
|
+
this.promptInputRevision++;
|
|
1339
|
+
let typedChars = 0;
|
|
1340
|
+
try {
|
|
1341
|
+
await this.writeData(batch.line, chunk => {
|
|
1342
|
+
if (typedChars === 0)
|
|
1343
|
+
onWrite?.();
|
|
1344
|
+
typedChars += chunk.length;
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
catch (error) {
|
|
1348
|
+
throw new MailNudgeWriteError(typedChars, error);
|
|
1349
|
+
}
|
|
1350
|
+
attempt = { ...batch, queued: state.queued, editRevision: this.promptInputRevision,
|
|
1351
|
+
placeholdersBefore, needsDraft: false, audited: false };
|
|
1352
|
+
const delay = Math.max(submit.delayMs ?? 0, Math.ceil(Array.from(batch.line).length * (submit.perCharacterMs ?? 0)));
|
|
1353
|
+
deadline += delay;
|
|
1354
|
+
await new Promise(resolve => setTimeout(resolve, delay));
|
|
1355
|
+
}
|
|
1356
|
+
// A failed key write can also leave the complete body in the composer.
|
|
1357
|
+
this.unconfirmedNudge = attempt;
|
|
1358
|
+
const firstKey = !attempt.lastKey;
|
|
1359
|
+
let result = await this.submitMailNudge(attempt, deadline, settleMs, resume ? onWrite : undefined);
|
|
1360
|
+
if (result === 'exact' && firstKey) {
|
|
1361
|
+
result = await this.submitMailNudge(attempt, performance.now() + settleMs, settleMs);
|
|
1362
|
+
}
|
|
1363
|
+
if (result === 'sent') {
|
|
1364
|
+
this.unconfirmedNudge = undefined;
|
|
1365
|
+
return { outcome: 'sent', ids: attempt.ids, queued: attempt.queued };
|
|
1366
|
+
}
|
|
1367
|
+
if (result === 'exact' && !attempt.audited) {
|
|
1368
|
+
attempt.audited = true;
|
|
1369
|
+
return { outcome: 'unconfirmed', ids: attempt.ids, queued: attempt.queued };
|
|
1370
|
+
}
|
|
1371
|
+
return { outcome: 'wait' };
|
|
1372
|
+
}
|
|
1373
|
+
/** A parser drain may outlive the input slot. Only this caller can write a key. */
|
|
1374
|
+
async flushMailBefore(deadline) {
|
|
1375
|
+
const remaining = deadline - performance.now();
|
|
1376
|
+
if (remaining <= 0)
|
|
1377
|
+
return undefined;
|
|
1378
|
+
let timer;
|
|
1379
|
+
const timeout = new Promise(resolve => { timer = setTimeout(() => resolve(false), remaining); });
|
|
1380
|
+
try {
|
|
1381
|
+
let output;
|
|
1382
|
+
do {
|
|
1383
|
+
output = this.outputVersion;
|
|
1384
|
+
const flushed = await Promise.race([this.renderer.flush().then(() => true), timeout]);
|
|
1385
|
+
this.refuseIfEnded();
|
|
1386
|
+
this.refuseIfInputFailed();
|
|
1387
|
+
if (!flushed || performance.now() >= deadline)
|
|
1388
|
+
return undefined;
|
|
1389
|
+
} while (this.outputVersion !== output);
|
|
1390
|
+
return output;
|
|
1391
|
+
}
|
|
1392
|
+
finally {
|
|
1393
|
+
clearTimeout(timer);
|
|
1394
|
+
}
|
|
1395
|
+
}
|
|
1396
|
+
async submitMailNudge(attempt, deadline, settleMs, onWrite) {
|
|
1397
|
+
let before;
|
|
1398
|
+
for (;;) {
|
|
1399
|
+
if (await this.flushMailBefore(deadline) !== this.outputVersion || this.promptInputRevision !== attempt.editRevision)
|
|
1400
|
+
return 'wait';
|
|
1401
|
+
this.refuseIfEnded();
|
|
1402
|
+
before = this.mailComposer(attempt);
|
|
1403
|
+
if (this.mailDraftCleared(attempt, before))
|
|
1404
|
+
return 'sent';
|
|
1405
|
+
if (!before.safe || this.answerablePrompt(this.renderer.snapshot().screen))
|
|
1406
|
+
return 'wait';
|
|
1407
|
+
if (attempt.lastKey) {
|
|
1408
|
+
if (!before.exact)
|
|
1409
|
+
return 'wait';
|
|
1410
|
+
break;
|
|
1411
|
+
}
|
|
1412
|
+
if (before.ownDraft || (before.empty && !attempt.needsDraft))
|
|
1413
|
+
break;
|
|
1414
|
+
// A partial echo can finish painting within this input slot. Once an
|
|
1415
|
+
// occupied frame appears, only the module recognising our body permits a key.
|
|
1416
|
+
attempt.needsDraft = true;
|
|
1417
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(deadline - performance.now(), NUDGE_SUBMIT_POLL_MS)));
|
|
1418
|
+
}
|
|
1419
|
+
if (performance.now() >= deadline)
|
|
1420
|
+
return 'wait';
|
|
1421
|
+
attempt.queued = before.queued;
|
|
1422
|
+
const output = this.outputVersion;
|
|
1423
|
+
this.pty.write(this.nudgeSubmit(attempt.queued));
|
|
1424
|
+
attempt.lastKey = { output, draftSeen: before.ownDraft, retried: attempt.lastKey !== undefined };
|
|
1425
|
+
const confirmUntil = performance.now() + settleMs;
|
|
1426
|
+
onWrite?.();
|
|
1427
|
+
let exact = before.exact;
|
|
1428
|
+
let observed = output;
|
|
1429
|
+
while (performance.now() < confirmUntil) {
|
|
1430
|
+
if (await this.flushMailBefore(confirmUntil) !== this.outputVersion)
|
|
1431
|
+
return 'wait';
|
|
1432
|
+
const after = this.mailComposer(attempt);
|
|
1433
|
+
if (this.mailDraftCleared(attempt, after))
|
|
1434
|
+
return 'sent';
|
|
1435
|
+
if (this.outputVersion !== output && after.safe && !after.ownDraft &&
|
|
1436
|
+
((!before.queued && after.busy) || (attempt.queued && !before.acknowledged && after.acknowledged)))
|
|
1437
|
+
return 'sent';
|
|
1438
|
+
exact = after.exact;
|
|
1439
|
+
observed = this.outputVersion;
|
|
1440
|
+
const remaining = confirmUntil - performance.now();
|
|
1441
|
+
if (remaining <= 0)
|
|
1442
|
+
break;
|
|
1443
|
+
await new Promise(resolve => setTimeout(resolve, Math.min(remaining, NUDGE_SUBMIT_POLL_MS)));
|
|
1444
|
+
}
|
|
1445
|
+
this.refuseIfEnded();
|
|
1446
|
+
return observed === this.outputVersion && exact ? 'exact' : 'wait';
|
|
1447
|
+
}
|
|
1448
|
+
mailComposer(attempt) {
|
|
1449
|
+
const view = this.nudgeView();
|
|
1450
|
+
const module = this.agentModule.nudge;
|
|
1451
|
+
const reading = module.readiness(view);
|
|
1452
|
+
const busy = reading === 'busy' || reading === 'queue';
|
|
1453
|
+
const queued = reading === 'unknown' ? attempt.queued : busy;
|
|
1454
|
+
const safe = !this.getStalled() && !detectPrompt(view.rows.join('\n'), this.agent, view.viewportRows, view.styled);
|
|
1455
|
+
const exact = safe && module.readiness({ ...view, expectedDraft: attempt.line,
|
|
1456
|
+
queueDraft: queued && module.queueKey !== undefined }) === 'ready';
|
|
1457
|
+
const ownDraft = exact || (safe && attempt.placeholdersBefore !== undefined &&
|
|
1458
|
+
this.typedDraftVisible(attempt.line, attempt.placeholdersBefore));
|
|
1459
|
+
const acknowledged = safe && module.confirmQueued?.(view) === true;
|
|
1460
|
+
const empty = safe && (reading === 'ready' || reading === 'queue' || acknowledged);
|
|
1461
|
+
return { busy, queued, safe, exact, ownDraft, empty, acknowledged };
|
|
1462
|
+
}
|
|
1463
|
+
mailDraftCleared(attempt, composer) {
|
|
1464
|
+
const before = attempt.lastKey;
|
|
1465
|
+
if (!before || this.outputVersion === before.output)
|
|
1466
|
+
return false;
|
|
1467
|
+
if (composer.ownDraft) {
|
|
1468
|
+
before.draftSeen = true;
|
|
1469
|
+
return false;
|
|
1470
|
+
}
|
|
1471
|
+
return before.draftSeen && composer.empty;
|
|
1472
|
+
}
|
|
1224
1473
|
/** Queue a nudge and retain the original result expected by direct callers. */
|
|
1225
1474
|
async writeNudge(data, ready) {
|
|
1226
1475
|
const result = await this.writeNudgeWithReason(data, ready);
|
|
1227
1476
|
return result === 'sent' || result === 'wait' ? result : 'aborted';
|
|
1228
1477
|
}
|
|
1229
1478
|
/** Queue a daemon nudge, reporting why a typed body could not be submitted. */
|
|
1230
|
-
writeNudgeWithReason(data, ready,
|
|
1479
|
+
writeNudgeWithReason(data, ready, failedCheck = () => 'line-not-seen', schedule, queuedDelivery = false) {
|
|
1231
1480
|
let abortReason = null;
|
|
1232
1481
|
const queued = this.writeChain.then(async () => {
|
|
1233
1482
|
try {
|
|
1234
|
-
if (this.
|
|
1483
|
+
if (this.scheduleDraft !== null || this.hasUnconfirmedMail)
|
|
1235
1484
|
return 'wait';
|
|
1236
|
-
this.
|
|
1237
|
-
this.
|
|
1238
|
-
const result = await this.writeInput(data, false, ready, (reason) => { abortReason = reason; }, this.nudgeSubmit(queuedDelivery),
|
|
1485
|
+
this.scheduleName = schedule;
|
|
1486
|
+
this.writingSchedule = true;
|
|
1487
|
+
const result = await this.writeInput(data, false, ready, (reason) => { abortReason = reason; }, this.nudgeSubmit(queuedDelivery), failedCheck);
|
|
1239
1488
|
return abortReason !== null ? `aborted-${abortReason}`
|
|
1240
1489
|
: result === null ? 'wait' : 'sent';
|
|
1241
1490
|
}
|
|
@@ -1245,110 +1494,36 @@ export class Session {
|
|
|
1245
1494
|
throw error;
|
|
1246
1495
|
}
|
|
1247
1496
|
finally {
|
|
1248
|
-
this.
|
|
1497
|
+
this.writingSchedule = false;
|
|
1249
1498
|
}
|
|
1250
1499
|
});
|
|
1251
1500
|
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
1252
1501
|
return queued;
|
|
1253
1502
|
}
|
|
1254
|
-
nudgePendingLine() { return this.
|
|
1255
|
-
|
|
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
|
-
}
|
|
1271
|
-
pendingSchedule() { return this.pendingNudgeLine === null ? undefined : this.nudgeSchedule; }
|
|
1272
|
-
nudgePendingIds() { return this.pendingNudgeIds; }
|
|
1273
|
-
nudgePendingUntouched() { return !this.pendingNudgeTouched; }
|
|
1274
|
-
nudgePendingTouchRefusal() {
|
|
1275
|
-
if (!this.pendingNudgeTouched || this.pendingTouchRefusalAudited)
|
|
1276
|
-
return false;
|
|
1277
|
-
this.pendingTouchRefusalAudited = true;
|
|
1278
|
-
return true;
|
|
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
|
-
}
|
|
1503
|
+
nudgePendingLine() { return this.scheduleDraft; }
|
|
1504
|
+
pendingSchedule() { return this.scheduleDraft === null ? undefined : this.scheduleName; }
|
|
1297
1505
|
/** Clear after an observed submitted turn or a whole quiet period of proven emptiness. */
|
|
1298
1506
|
async clearConsumedNudge() {
|
|
1299
|
-
if (this.
|
|
1507
|
+
if (this.scheduleDraft === null || this.writingSchedule)
|
|
1300
1508
|
return false;
|
|
1301
|
-
const line = this.
|
|
1509
|
+
const line = this.scheduleDraft;
|
|
1302
1510
|
await this.renderer.flush();
|
|
1303
|
-
if (this.
|
|
1511
|
+
if (this.scheduleDraft !== line || this.writingSchedule)
|
|
1304
1512
|
return false;
|
|
1305
1513
|
const verdict = this.pendingComposerVerdict();
|
|
1306
1514
|
if (!verdict.ready && verdict.reason === 'busy' && this.pendingTurnSubmitted)
|
|
1307
1515
|
this.pendingTurnBusy = true;
|
|
1308
1516
|
if (!verdict.ready) {
|
|
1309
|
-
this.pendingQuietSince =
|
|
1517
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1310
1518
|
return false;
|
|
1311
1519
|
}
|
|
1312
|
-
if (!(this.pendingTurnBusy ||
|
|
1520
|
+
if (!(this.pendingTurnBusy || this.pendingClock() - this.pendingQuietSince >= this.pendingNudgeSettleMs))
|
|
1313
1521
|
return false;
|
|
1314
|
-
this.
|
|
1315
|
-
this.pendingNudgeIds = [];
|
|
1316
|
-
this.pendingNudgeTypedChars = 0;
|
|
1317
|
-
this.pendingNudgeWholeBody = false;
|
|
1318
|
-
this.pendingNudgeAuditRecorded = false;
|
|
1319
|
-
this.pendingNudgeTouched = false;
|
|
1320
|
-
this.pendingTouchRefusalAudited = false;
|
|
1522
|
+
this.scheduleDraft = null;
|
|
1321
1523
|
this.pendingTurnSubmitted = false;
|
|
1322
1524
|
this.pendingTurnBusy = false;
|
|
1323
1525
|
return true;
|
|
1324
1526
|
}
|
|
1325
|
-
/** A pending body may receive its submit key only after it is visible exactly once. */
|
|
1326
|
-
submitPendingNudge(line, ready) {
|
|
1327
|
-
const queued = this.writeChain.then(async () => {
|
|
1328
|
-
this.refuseIfInputFailed();
|
|
1329
|
-
await this.renderer.flush();
|
|
1330
|
-
this.refuseIfEnded();
|
|
1331
|
-
if (this.pendingNudgeLine !== line || !this.nudgePendingSafeToSubmit() ||
|
|
1332
|
-
!ready(this.renderer.snapshot().screen) ||
|
|
1333
|
-
!this.nudgeReadyWithLine(line))
|
|
1334
|
-
return false;
|
|
1335
|
-
this.pty.write(this.nudgeSubmit());
|
|
1336
|
-
this.pendingNudgeLine = null;
|
|
1337
|
-
this.pendingNudgeIds = [];
|
|
1338
|
-
this.pendingNudgeTypedChars = 0;
|
|
1339
|
-
this.pendingNudgeWholeBody = false;
|
|
1340
|
-
this.pendingNudgeAuditRecorded = false;
|
|
1341
|
-
this.pendingNudgeTouched = false;
|
|
1342
|
-
this.pendingTouchRefusalAudited = false;
|
|
1343
|
-
this.pendingTurnSubmitted = false;
|
|
1344
|
-
this.pendingTurnBusy = false;
|
|
1345
|
-
this.inputVersion++;
|
|
1346
|
-
this.promptInputRevision++;
|
|
1347
|
-
return true;
|
|
1348
|
-
});
|
|
1349
|
-
this.writeChain = queued.then(() => undefined, () => undefined);
|
|
1350
|
-
return queued;
|
|
1351
|
-
}
|
|
1352
1527
|
nudgeReady(now) {
|
|
1353
1528
|
return this.nudgeState(now).ready;
|
|
1354
1529
|
}
|
|
@@ -1358,7 +1533,7 @@ export class Session {
|
|
|
1358
1533
|
* running turn. Each call also measures how long the composer block (the
|
|
1359
1534
|
* last rows on screen) has stayed the same, which a queued nudge waits on.
|
|
1360
1535
|
*/
|
|
1361
|
-
nudgeState(now, whenBusy) {
|
|
1536
|
+
nudgeState(now, whenBusy, mailbox = false) {
|
|
1362
1537
|
const view = this.nudgeView();
|
|
1363
1538
|
const nudge = this.agentModule?.nudge;
|
|
1364
1539
|
const pane = nudge?.idlePane?.(view);
|
|
@@ -1367,7 +1542,10 @@ export class Session {
|
|
|
1367
1542
|
this.nudgeComposerKey = key;
|
|
1368
1543
|
this.nudgeComposerSince = now;
|
|
1369
1544
|
}
|
|
1370
|
-
|
|
1545
|
+
// Only a clear or submit of an occupied composer can release mail early.
|
|
1546
|
+
// A subsequent editing write may still be buffered behind the empty repaint.
|
|
1547
|
+
const afterClear = this.outputBeforeClear !== undefined && this.outputVersion !== this.outputBeforeClear;
|
|
1548
|
+
if (this.recentInput && (!mailbox || !afterClear)) {
|
|
1371
1549
|
return { ready: false, reason: 'recent-input', queued: false, paneQuiet: pane !== undefined, regionKey: key };
|
|
1372
1550
|
}
|
|
1373
1551
|
const verdict = nudgeVerdict(this.agentModule, {
|
|
@@ -1480,7 +1658,14 @@ export class Session {
|
|
|
1480
1658
|
const submit = this.agentModule?.input?.submit;
|
|
1481
1659
|
return submit?.delayMs !== undefined && submit.matches?.(data) === true;
|
|
1482
1660
|
}
|
|
1483
|
-
|
|
1661
|
+
typedSubmitDelay(body) {
|
|
1662
|
+
const submit = this.agentModule?.input?.submit;
|
|
1663
|
+
return Math.max(submit?.delayMs ?? 0, Math.ceil(Array.from(body).length * (submit?.perCharacterMs ?? 0)));
|
|
1664
|
+
}
|
|
1665
|
+
pasteBaselineSettled() {
|
|
1666
|
+
return Date.now() - Math.max(this.lastInputAt, this.lastChange) >= TYPED_PLACEHOLDER_SETTLE_MS;
|
|
1667
|
+
}
|
|
1668
|
+
async writeInput(data, terminalReport, ready, onNudgeAbort, nudgeKey, failedCheck = () => 'line-not-seen', onTypedSubmit) {
|
|
1484
1669
|
const nudge = nudgeKey !== undefined;
|
|
1485
1670
|
this.refuseIfInputFailed();
|
|
1486
1671
|
if (ready !== undefined)
|
|
@@ -1496,16 +1681,13 @@ export class Session {
|
|
|
1496
1681
|
if (!ready(this.renderer.snapshot().screen, 'before'))
|
|
1497
1682
|
return null;
|
|
1498
1683
|
}
|
|
1499
|
-
if (!nudge && !terminalReport && data !== '' && this.pendingNudgeLine !== null) {
|
|
1500
|
-
this.pendingNudgeTouched = true;
|
|
1501
|
-
}
|
|
1502
1684
|
// Recorded BEFORE the bytes go in, when the screen still shows what this
|
|
1503
1685
|
// input is answering: the waiter's stale-prompt guard needs that prompt,
|
|
1504
1686
|
// and its echo guard needs the input itself.
|
|
1505
1687
|
if (!terminalReport)
|
|
1506
1688
|
this.lastInputData = data;
|
|
1507
1689
|
if (!nudge && !terminalReport && data.length > 0) {
|
|
1508
|
-
this.
|
|
1690
|
+
this.notePersonInput(data);
|
|
1509
1691
|
}
|
|
1510
1692
|
if (!terminalReport && data.length > 0) {
|
|
1511
1693
|
// Discovery may still be queued. Capture the screen this input answers
|
|
@@ -1521,8 +1703,7 @@ export class Session {
|
|
|
1521
1703
|
const { screen, lines } = this.renderer.snapshot();
|
|
1522
1704
|
// Nothing written and nothing painted for a while: no earlier paste can still be
|
|
1523
1705
|
// waiting to paint its placeholder, so a new placeholder can only be this body's.
|
|
1524
|
-
const settledBefore =
|
|
1525
|
-
Date.now() - this.lastChange >= TYPED_PLACEHOLDER_SETTLE_MS;
|
|
1706
|
+
const settledBefore = this.pasteBaselineSettled();
|
|
1526
1707
|
if (!terminalReport) {
|
|
1527
1708
|
this.lastInputAt = Date.now();
|
|
1528
1709
|
this.inputVersion++;
|
|
@@ -1536,7 +1717,7 @@ export class Session {
|
|
|
1536
1717
|
const key = nudgeKey ?? submit.key;
|
|
1537
1718
|
const body = data.slice(0, -key.length);
|
|
1538
1719
|
const delayMs = nudge ? Math.max(NUDGE_SUBMIT_DELAY_MS, submit?.delayMs ?? 0)
|
|
1539
|
-
:
|
|
1720
|
+
: this.typedSubmitDelay(body);
|
|
1540
1721
|
const queuedInputVersion = this.inputQueueVersion;
|
|
1541
1722
|
const queuedWriteVersion = this.writeQueueVersion;
|
|
1542
1723
|
if (!nudge && this.agentModule?.nudge !== undefined)
|
|
@@ -1551,22 +1732,12 @@ export class Session {
|
|
|
1551
1732
|
const placeholdersBefore = readableComposer && settledBefore
|
|
1552
1733
|
? this.visiblePastePlaceholders() : null;
|
|
1553
1734
|
if (nudge) {
|
|
1554
|
-
this.
|
|
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;
|
|
1561
|
-
this.pendingNudgeTouched = false;
|
|
1562
|
-
this.pendingTouchRefusalAudited = false;
|
|
1735
|
+
this.scheduleDraft = body;
|
|
1563
1736
|
this.pendingTurnSubmitted = false;
|
|
1564
1737
|
this.pendingTurnBusy = false;
|
|
1565
|
-
this.pendingQuietSince =
|
|
1738
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1566
1739
|
}
|
|
1567
|
-
await this.writeData(body
|
|
1568
|
-
if (nudge)
|
|
1569
|
-
this.pendingNudgeWholeBody = this.pendingNudgeTypedChars === body.length;
|
|
1740
|
+
await this.writeData(body);
|
|
1570
1741
|
const bodyInputVersion = this.inputVersion;
|
|
1571
1742
|
const bodyWrittenAt = Date.now();
|
|
1572
1743
|
try {
|
|
@@ -1636,18 +1807,12 @@ export class Session {
|
|
|
1636
1807
|
: { submitRetried: false,
|
|
1637
1808
|
message: "Submit key sent; the agent's composer was not on screen when the text was typed." });
|
|
1638
1809
|
}
|
|
1639
|
-
if (!nudge && this.
|
|
1640
|
-
this.pendingQuietSince =
|
|
1810
|
+
if (!nudge && this.scheduleDraft !== null) {
|
|
1811
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1641
1812
|
this.pendingTurnSubmitted = true;
|
|
1642
1813
|
}
|
|
1643
1814
|
if (nudge) {
|
|
1644
|
-
this.
|
|
1645
|
-
this.pendingNudgeIds = [];
|
|
1646
|
-
this.pendingNudgeTypedChars = 0;
|
|
1647
|
-
this.pendingNudgeWholeBody = false;
|
|
1648
|
-
this.pendingNudgeAuditRecorded = false;
|
|
1649
|
-
this.pendingNudgeTouched = false;
|
|
1650
|
-
this.pendingTouchRefusalAudited = false;
|
|
1815
|
+
this.scheduleDraft = null;
|
|
1651
1816
|
this.pendingTurnSubmitted = false;
|
|
1652
1817
|
this.pendingTurnBusy = false;
|
|
1653
1818
|
}
|
|
@@ -1659,17 +1824,17 @@ export class Session {
|
|
|
1659
1824
|
return screen;
|
|
1660
1825
|
}
|
|
1661
1826
|
await this.writeData(data);
|
|
1662
|
-
if (!terminalReport && this.
|
|
1827
|
+
if (!terminalReport && this.scheduleDraft !== null &&
|
|
1663
1828
|
data.endsWith(this.nudgeSubmit()))
|
|
1664
1829
|
this.pendingTurnSubmitted = true;
|
|
1665
1830
|
return screen;
|
|
1666
1831
|
}
|
|
1667
1832
|
typedLineInTranscript(body, beforeScreen) {
|
|
1833
|
+
const signature = this.agentModule?.reading.composer.text;
|
|
1834
|
+
if (signature === undefined)
|
|
1835
|
+
return false;
|
|
1836
|
+
const composer = new RegExp(signature, 'u');
|
|
1668
1837
|
const transcript = (screen) => {
|
|
1669
|
-
const signature = this.agentModule?.reading.composer.text;
|
|
1670
|
-
if (signature === undefined)
|
|
1671
|
-
return '';
|
|
1672
|
-
const composer = new RegExp(signature, 'u');
|
|
1673
1838
|
const lines = screen.split('\n');
|
|
1674
1839
|
let at = -1;
|
|
1675
1840
|
for (let i = 0; i < lines.length; i++)
|
|
@@ -1727,8 +1892,8 @@ export class Session {
|
|
|
1727
1892
|
}
|
|
1728
1893
|
async writeData(data, onAccepted) {
|
|
1729
1894
|
if (data.length <= WRITE_CHUNK_CHARS) {
|
|
1730
|
-
if (data !== '' && this.
|
|
1731
|
-
this.pendingQuietSince =
|
|
1895
|
+
if (data !== '' && this.scheduleDraft !== null)
|
|
1896
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1732
1897
|
this.pty.write(data);
|
|
1733
1898
|
onAccepted?.(data);
|
|
1734
1899
|
return;
|
|
@@ -1743,8 +1908,8 @@ export class Session {
|
|
|
1743
1908
|
const body = newlineAt === -1 ? data : data.slice(0, newlineAt);
|
|
1744
1909
|
const trailer = newlineAt === -1 ? '' : data.slice(newlineAt);
|
|
1745
1910
|
this.lastWriteWrapped = true;
|
|
1746
|
-
if (this.
|
|
1747
|
-
this.pendingQuietSince =
|
|
1911
|
+
if (this.scheduleDraft !== null)
|
|
1912
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1748
1913
|
this.pty.write(`${PASTE_START}${body}${PASTE_END}${trailer}`);
|
|
1749
1914
|
onAccepted?.(data);
|
|
1750
1915
|
return;
|
|
@@ -1763,8 +1928,8 @@ export class Session {
|
|
|
1763
1928
|
if (code >= 0xd800 && code <= 0xdbff)
|
|
1764
1929
|
end -= 1;
|
|
1765
1930
|
}
|
|
1766
|
-
if (this.
|
|
1767
|
-
this.pendingQuietSince =
|
|
1931
|
+
if (this.scheduleDraft !== null)
|
|
1932
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1768
1933
|
this.pty.write(data.slice(offset, end));
|
|
1769
1934
|
onAccepted?.(data.slice(offset, end));
|
|
1770
1935
|
offset = end;
|
|
@@ -1850,8 +2015,8 @@ export class Session {
|
|
|
1850
2015
|
const oldCols = this.renderer.cols;
|
|
1851
2016
|
const oldRows = this.renderer.rows;
|
|
1852
2017
|
this.pty.resize(cols, rows);
|
|
1853
|
-
if (this.
|
|
1854
|
-
this.pendingQuietSince =
|
|
2018
|
+
if (this.scheduleDraft !== null)
|
|
2019
|
+
this.pendingQuietSince = this.pendingClock();
|
|
1855
2020
|
this.screenRevision++;
|
|
1856
2021
|
this.stallPtyCols = this.pty.cols;
|
|
1857
2022
|
this.stallPtyRows = this.pty.rows;
|
|
@@ -1980,6 +2145,10 @@ export class Session {
|
|
|
1980
2145
|
}
|
|
1981
2146
|
this.stallTranscript = transcript;
|
|
1982
2147
|
}
|
|
2148
|
+
refreshReadingRules() {
|
|
2149
|
+
if (this.agentModule?.stalls && !this.exitedFlag && !this.isKilled)
|
|
2150
|
+
this.refreshStall(true);
|
|
2151
|
+
}
|
|
1983
2152
|
scheduleStall() {
|
|
1984
2153
|
if (this.exitedFlag || this.isKilled)
|
|
1985
2154
|
return;
|
|
@@ -2061,7 +2230,7 @@ export class Session {
|
|
|
2061
2230
|
return this.agentModule.stalls.some(shape => this.renderer.hasForeground(plain.flatMap((line, row) => (typeof shape.marker.text === 'string' ? line.trimEnd() === shape.marker.text :
|
|
2062
2231
|
shape.marker.text.test(line.trimEnd())) ? [row] : []), shape.marker.fg));
|
|
2063
2232
|
}
|
|
2064
|
-
refreshStall() {
|
|
2233
|
+
refreshStall(rulesChanged = false) {
|
|
2065
2234
|
this.clearStallTimer();
|
|
2066
2235
|
if (this.exitedFlag || this.isKilled)
|
|
2067
2236
|
return;
|
|
@@ -2069,19 +2238,20 @@ export class Session {
|
|
|
2069
2238
|
if (this.stallState !== undefined && this.stallResizeUntil !== 0) {
|
|
2070
2239
|
const remaining = this.stallResizeUntil - Date.now();
|
|
2071
2240
|
if (remaining > 0) {
|
|
2072
|
-
this.queueStallCheck(() => this.refreshStall(), remaining);
|
|
2241
|
+
this.queueStallCheck(() => this.refreshStall(rulesChanged), remaining);
|
|
2073
2242
|
return;
|
|
2074
2243
|
}
|
|
2075
2244
|
}
|
|
2076
2245
|
this.stallNextCheck = Date.now() + 250;
|
|
2077
2246
|
const signature = signatureForSession(this);
|
|
2078
2247
|
if (signature === null) {
|
|
2248
|
+
this.stallTracker.observe(null);
|
|
2079
2249
|
this.publishStall(undefined);
|
|
2080
2250
|
return;
|
|
2081
2251
|
}
|
|
2082
2252
|
const plain = this.renderer.plainViewport();
|
|
2083
2253
|
const content = this.stallScreen.content(plain, this.agentModule.stalls);
|
|
2084
|
-
if (!resized && this.stallState !== undefined && content === this.stallValidatedContent) {
|
|
2254
|
+
if (!rulesChanged && !resized && this.stallState !== undefined && content === this.stallValidatedContent) {
|
|
2085
2255
|
// A due validation can beat the deferred output task to a restored
|
|
2086
2256
|
// frame. Cancel here too, before materialising its styled context.
|
|
2087
2257
|
this.stallContent = content;
|
|
@@ -2126,7 +2296,7 @@ export class Session {
|
|
|
2126
2296
|
}
|
|
2127
2297
|
// A partial redraw may temporarily lose the block or composer. Confirm
|
|
2128
2298
|
// invalidation at the next bounded check; output cannot postpone it.
|
|
2129
|
-
if (this.stallState !== undefined && !this.stallTracker.matchesBlock(candidate) && !this.stallValidationPending) {
|
|
2299
|
+
if (!rulesChanged && this.stallState !== undefined && !this.stallTracker.matchesBlock(candidate) && !this.stallValidationPending) {
|
|
2130
2300
|
this.stallValidationPending = true;
|
|
2131
2301
|
this.queueStallCheck(() => this.refreshStall(), 250);
|
|
2132
2302
|
return;
|
|
@@ -2152,8 +2322,7 @@ export class Session {
|
|
|
2152
2322
|
* nothing received after it.
|
|
2153
2323
|
*/
|
|
2154
2324
|
async viewerState(options = {}) {
|
|
2155
|
-
//
|
|
2156
|
-
// snapshot, not whatever arrives while it is being taken.
|
|
2325
|
+
// Capture cursor visibility at the same output boundary as the renderer.
|
|
2157
2326
|
const hidden = this.cursorHidden;
|
|
2158
2327
|
const state = await this.renderer.serialize(options);
|
|
2159
2328
|
return hidden ? state + CURSOR_HIDE : state;
|