@namzu/computer-use 3.1.0 → 4.0.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.
Files changed (125) hide show
  1. package/CHANGELOG.md +64 -1
  2. package/README.md +3 -3
  3. package/dist/SubprocessComputerUseHost.d.ts +58 -10
  4. package/dist/SubprocessComputerUseHost.d.ts.map +1 -1
  5. package/dist/SubprocessComputerUseHost.js +214 -47
  6. package/dist/SubprocessComputerUseHost.js.map +1 -1
  7. package/dist/adapters/cua-driver/adapter.d.ts +171 -10
  8. package/dist/adapters/cua-driver/adapter.d.ts.map +1 -1
  9. package/dist/adapters/cua-driver/adapter.js +1479 -161
  10. package/dist/adapters/cua-driver/adapter.js.map +1 -1
  11. package/dist/adapters/cua-driver/client.d.ts +16 -0
  12. package/dist/adapters/cua-driver/client.d.ts.map +1 -1
  13. package/dist/adapters/cua-driver/client.js +54 -5
  14. package/dist/adapters/cua-driver/client.js.map +1 -1
  15. package/dist/adapters/cua-driver/escalation.d.ts +67 -0
  16. package/dist/adapters/cua-driver/escalation.d.ts.map +1 -0
  17. package/dist/adapters/cua-driver/escalation.js +82 -0
  18. package/dist/adapters/cua-driver/escalation.js.map +1 -0
  19. package/dist/adapters/cua-driver/keys.d.ts +5 -0
  20. package/dist/adapters/cua-driver/keys.d.ts.map +1 -1
  21. package/dist/adapters/cua-driver/keys.js +23 -0
  22. package/dist/adapters/cua-driver/keys.js.map +1 -1
  23. package/dist/adapters/cua-driver/observe.d.ts +99 -0
  24. package/dist/adapters/cua-driver/observe.d.ts.map +1 -0
  25. package/dist/adapters/cua-driver/observe.js +227 -0
  26. package/dist/adapters/cua-driver/observe.js.map +1 -0
  27. package/dist/adapters/cua-driver/provision.d.ts +13 -13
  28. package/dist/adapters/cua-driver/provision.js +13 -13
  29. package/dist/adapters/cua-driver/ui-tree.d.ts +75 -2
  30. package/dist/adapters/cua-driver/ui-tree.d.ts.map +1 -1
  31. package/dist/adapters/cua-driver/ui-tree.js +142 -14
  32. package/dist/adapters/cua-driver/ui-tree.js.map +1 -1
  33. package/dist/adapters/types.d.ts +4 -4
  34. package/dist/adapters/types.d.ts.map +1 -1
  35. package/dist/adapters/types.js.map +1 -1
  36. package/dist/adapters/win32.d.ts +10 -0
  37. package/dist/adapters/win32.d.ts.map +1 -1
  38. package/dist/adapters/win32.js +12 -2
  39. package/dist/adapters/win32.js.map +1 -1
  40. package/dist/errors.d.ts +19 -0
  41. package/dist/errors.d.ts.map +1 -1
  42. package/dist/errors.js +26 -0
  43. package/dist/errors.js.map +1 -1
  44. package/dist/foreground/guard.d.ts +31 -0
  45. package/dist/foreground/guard.d.ts.map +1 -0
  46. package/dist/foreground/guard.js +156 -0
  47. package/dist/foreground/guard.js.map +1 -0
  48. package/dist/foreground/index.d.ts +11 -0
  49. package/dist/foreground/index.d.ts.map +1 -0
  50. package/dist/foreground/index.js +7 -0
  51. package/dist/foreground/index.js.map +1 -0
  52. package/dist/foreground/ladder.d.ts +143 -0
  53. package/dist/foreground/ladder.d.ts.map +1 -0
  54. package/dist/foreground/ladder.js +505 -0
  55. package/dist/foreground/ladder.js.map +1 -0
  56. package/dist/foreground/lease.d.ts +69 -0
  57. package/dist/foreground/lease.d.ts.map +1 -0
  58. package/dist/foreground/lease.js +182 -0
  59. package/dist/foreground/lease.js.map +1 -0
  60. package/dist/foreground/types.d.ts +287 -0
  61. package/dist/foreground/types.d.ts.map +1 -0
  62. package/dist/foreground/types.js +32 -0
  63. package/dist/foreground/types.js.map +1 -0
  64. package/dist/foreground/windows-helper-script.d.ts +19 -0
  65. package/dist/foreground/windows-helper-script.d.ts.map +1 -0
  66. package/dist/foreground/windows-helper-script.js +472 -0
  67. package/dist/foreground/windows-helper-script.js.map +1 -0
  68. package/dist/foreground/windows-monitor.d.ts +75 -0
  69. package/dist/foreground/windows-monitor.d.ts.map +1 -0
  70. package/dist/foreground/windows-monitor.js +216 -0
  71. package/dist/foreground/windows-monitor.js.map +1 -0
  72. package/dist/foreground/windows.d.ts +21 -0
  73. package/dist/foreground/windows.d.ts.map +1 -0
  74. package/dist/foreground/windows.js +54 -0
  75. package/dist/foreground/windows.js.map +1 -0
  76. package/dist/index.d.ts +6 -1
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +3 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/presence/helper-script.d.ts +39 -0
  81. package/dist/presence/helper-script.d.ts.map +1 -0
  82. package/dist/presence/helper-script.js +320 -0
  83. package/dist/presence/helper-script.js.map +1 -0
  84. package/dist/presence/index.d.ts +6 -0
  85. package/dist/presence/index.d.ts.map +1 -0
  86. package/dist/presence/index.js +4 -0
  87. package/dist/presence/index.js.map +1 -0
  88. package/dist/presence/presence.d.ts +70 -0
  89. package/dist/presence/presence.d.ts.map +1 -0
  90. package/dist/presence/presence.js +147 -0
  91. package/dist/presence/presence.js.map +1 -0
  92. package/dist/presence/windows.d.ts +19 -0
  93. package/dist/presence/windows.d.ts.map +1 -0
  94. package/dist/presence/windows.js +39 -0
  95. package/dist/presence/windows.js.map +1 -0
  96. package/dist/util/call-scope.d.ts +34 -0
  97. package/dist/util/call-scope.d.ts.map +1 -0
  98. package/dist/util/call-scope.js +58 -0
  99. package/dist/util/call-scope.js.map +1 -0
  100. package/package.json +2 -2
  101. package/src/SubprocessComputerUseHost.ts +288 -46
  102. package/src/adapters/cua-driver/adapter.ts +1754 -175
  103. package/src/adapters/cua-driver/client.ts +59 -2
  104. package/src/adapters/cua-driver/escalation.ts +137 -0
  105. package/src/adapters/cua-driver/keys.ts +20 -0
  106. package/src/adapters/cua-driver/observe.ts +310 -0
  107. package/src/adapters/cua-driver/provision.ts +13 -13
  108. package/src/adapters/cua-driver/ui-tree.ts +219 -15
  109. package/src/adapters/types.ts +8 -3
  110. package/src/adapters/win32.ts +26 -3
  111. package/src/errors.ts +32 -0
  112. package/src/foreground/guard.ts +182 -0
  113. package/src/foreground/index.ts +45 -0
  114. package/src/foreground/ladder.ts +616 -0
  115. package/src/foreground/lease.ts +232 -0
  116. package/src/foreground/types.ts +318 -0
  117. package/src/foreground/windows-helper-script.ts +471 -0
  118. package/src/foreground/windows-monitor.ts +288 -0
  119. package/src/foreground/windows.ts +73 -0
  120. package/src/index.ts +15 -1
  121. package/src/presence/helper-script.ts +323 -0
  122. package/src/presence/index.ts +17 -0
  123. package/src/presence/presence.ts +195 -0
  124. package/src/presence/windows.ts +54 -0
  125. package/src/util/call-scope.ts +73 -0
@@ -0,0 +1,156 @@
1
+ import { currentCallSignal } from '../util/call-scope.js';
2
+ import { STOPPED_TEXT } from './ladder.js';
3
+ /** Display actions that put input on the user's screen. */
4
+ const SCREEN_ACTIONS = new Set([
5
+ 'mouse_move',
6
+ 'mouse_click',
7
+ 'mouse_drag',
8
+ 'scroll',
9
+ 'type_text',
10
+ 'key',
11
+ ]);
12
+ const heldText = (ms) => `${(Math.max(ms, 100) / 1000).toFixed(1)} s`;
13
+ /**
14
+ * What an interrupted or stopped burst tells the model. Neither is proof that
15
+ * the input arrived or did not, so both leave the action unconfirmed.
16
+ */
17
+ export function interferenceNote(outcome) {
18
+ if (outcome.stopped)
19
+ return STOPPED_TEXT;
20
+ if (outcome.interfered)
21
+ return 'The user used the keyboard or mouse while the screen was in use, so the input may have landed somewhere else or only in part. Look at the window before repeating it.';
22
+ return undefined;
23
+ }
24
+ /**
25
+ * Set when a burst that sent input was not registered by the system at all:
26
+ * Windows dropped it, so it reached no window and sending it again is safe
27
+ * once the cause (an administrator window in front) is gone.
28
+ */
29
+ export function droppedInputNote(outcome) {
30
+ if (outcome.inputLanded !== false)
31
+ return undefined;
32
+ return `${outcome.inputDroppedWhy ?? 'Windows dropped the input before it reached any window.'} Nothing was sent to the window; try again once that window is closed or the user has acted in it.`;
33
+ }
34
+ /** The sentence that tells the model a background action ran in the foreground. */
35
+ export function foregroundNote(outcome) {
36
+ const put = outcome.restoredForeground || outcome.restoredCursor
37
+ ? ' The window and pointer that were there before were put back.'
38
+ : outcome.restoreNote &&
39
+ outcome.restoreNote !== 'the burst had no window to put back' &&
40
+ !outcome.restoreNote.startsWith('the window that was in front is in front')
41
+ ? ` The window that was in front was not put back: ${outcome.restoreNote}.`
42
+ : '';
43
+ return `Background input was not possible here, so this used the screen for ${heldText(outcome.heldMs)}.${put}`;
44
+ }
45
+ /**
46
+ * Display input and `focusWindow` through the foreground ladder, for an
47
+ * adapter that has no ladder of its own (the PowerShell path) and for the
48
+ * display-scope calls of one that has. Window-scoped input is the wrapped
49
+ * adapter's business: it decides when background is impossible.
50
+ */
51
+ export function guardForeground(adapter, ladder) {
52
+ const apps = new Map();
53
+ const guarded = {
54
+ get capabilities() {
55
+ return adapter.capabilities;
56
+ },
57
+ get backend() {
58
+ return adapter.backend;
59
+ },
60
+ get fallbackReason() {
61
+ return adapter.fallbackReason;
62
+ },
63
+ getDisplayGeometry: () => adapter.getDisplayGeometry(),
64
+ async execute(action) {
65
+ if (!SCREEN_ACTIONS.has(action.type))
66
+ return adapter.execute(action);
67
+ const outcome = await ladder.run({
68
+ subject: { app: 'the desktop' },
69
+ keepCursor: action.type === 'mouse_move',
70
+ sendsInput: action.type !== 'mouse_move',
71
+ ...(currentCallSignal() ? { signal: currentCallSignal() } : {}),
72
+ }, async () => adapter.execute(action));
73
+ if (outcome.kind === 'blocked')
74
+ return {
75
+ type: 'ok',
76
+ delivery: 'not_delivered',
77
+ retrySafety: 'safe',
78
+ detail: outcome.block.detail,
79
+ };
80
+ const dropped = droppedInputNote(outcome);
81
+ if (dropped)
82
+ return {
83
+ type: 'ok',
84
+ delivery: 'not_delivered',
85
+ retrySafety: 'safe',
86
+ detail: dropped,
87
+ };
88
+ const note = interferenceNote(outcome);
89
+ if (!note || outcome.value.type !== 'ok')
90
+ return outcome.value;
91
+ return mergeNote(outcome.value, note);
92
+ },
93
+ async dispose() {
94
+ await ladder.dispose();
95
+ await adapter.dispose?.();
96
+ },
97
+ };
98
+ if (adapter.listWindows) {
99
+ const list = adapter.listWindows.bind(adapter);
100
+ guarded.listWindows = async () => {
101
+ const windows = await list();
102
+ apps.clear();
103
+ for (const window of windows)
104
+ apps.set(window.id, window);
105
+ return windows;
106
+ };
107
+ }
108
+ if (adapter.focusWindow) {
109
+ const focus = adapter.focusWindow.bind(adapter);
110
+ guarded.focusWindow = async (id) => {
111
+ let window = apps.get(id);
112
+ if (!window && guarded.listWindows) {
113
+ await guarded.listWindows().catch(() => undefined);
114
+ window = apps.get(id);
115
+ }
116
+ const subject = window
117
+ ? { app: window.app, pid: window.pid, hwnd: window.id }
118
+ : { app: 'the window you named', hwnd: id };
119
+ const outcome = await ladder.run({
120
+ subject,
121
+ ...(currentCallSignal() ? { signal: currentCallSignal() } : {}),
122
+ }, () => focus(id));
123
+ if (outcome.kind === 'blocked')
124
+ return {
125
+ ok: false,
126
+ focusedId: null,
127
+ delivery: 'not_delivered',
128
+ retrySafety: 'safe',
129
+ detail: outcome.block.detail,
130
+ };
131
+ const note = interferenceNote(outcome);
132
+ return note ? { ...outcome.value, detail: note } : outcome.value;
133
+ };
134
+ }
135
+ for (const name of [
136
+ 'captureWindow',
137
+ 'executeWindow',
138
+ 'captureRegion',
139
+ 'uiSnapshot',
140
+ 'uiAct',
141
+ ]) {
142
+ const method = adapter[name];
143
+ if (method)
144
+ guarded[name] = method.bind(adapter);
145
+ }
146
+ return guarded;
147
+ }
148
+ function mergeNote(result, note) {
149
+ return {
150
+ type: 'ok',
151
+ delivery: result.delivery === 'not_delivered' ? 'not_delivered' : 'delivered_unverified',
152
+ retrySafety: result.delivery === 'not_delivered' ? (result.retrySafety ?? 'safe') : 'unsafe',
153
+ detail: [result.detail, note].filter(Boolean).join(' '),
154
+ };
155
+ }
156
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/foreground/guard.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAA;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,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M;YAAG,OAA8C,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACzF,CAAC;IACD,OAAO,OAAO,CAAA;AACf,CAAC;AAED,SAAS,SAAS,CACjB,MAAkD,EAClD,IAAY;IAEZ,OAAO;QACN,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,MAAM,CAAC,QAAQ,KAAK,eAAe,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,sBAAsB;QACxF,WAAW,EAAE,MAAM,CAAC,QAAQ,KAAK,eAAe,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,WAAW,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ;QAC5F,MAAM,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;KACvD,CAAA;AACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ export { DEFAULT_TIMING, ForegroundLadder, STOPPED_TEXT, realClock, } from './ladder.js';
2
+ export type { ForegroundLadderOptions, LadderClock, LadderTiming, } from './ladder.js';
3
+ export { ScreenLease } from './lease.js';
4
+ export type { LeaseRecord } from './lease.js';
5
+ export { foregroundNote, guardForeground, interferenceNote } from './guard.js';
6
+ export { HELPER_BOOTSTRAP, WindowsInputMonitor, encodeHelperCommand, helperScriptLine, } from './windows-monitor.js';
7
+ export type { BurstContext, EditTextRequest, EditTextResult, ForegroundAnswer, ForegroundApprover, ForegroundBlock, ForegroundBlockCode, ForegroundMonitor, ForegroundOutcome, ForegroundSubject, MonitorBurstEnd, MonitorState, MenuCommandRequest, MenuCommandResult, SelectItemRequest, SelectItemResult, } from './types.js';
8
+ export { BurstInterrupted, PROTECTED_PROCESSES } from './types.js';
9
+ export { createWindowsForegroundLadder, screenLeasePath, windowsPathFor, } from './windows.js';
10
+ export type { WindowsLadderOptions } from './windows.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/foreground/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,SAAS,GACT,MAAM,aAAa,CAAA;AACpB,YAAY,EACX,uBAAuB,EACvB,WAAW,EACX,YAAY,GACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AACxC,YAAY,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GAChB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EACX,YAAY,EACZ,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,YAAY,EACZ,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,GAChB,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,EACN,6BAA6B,EAC7B,eAAe,EACf,cAAc,GACd,MAAM,cAAc,CAAA;AACrB,YAAY,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { DEFAULT_TIMING, ForegroundLadder, STOPPED_TEXT, realClock, } from './ladder.js';
2
+ export { ScreenLease } from './lease.js';
3
+ export { foregroundNote, guardForeground, interferenceNote } from './guard.js';
4
+ export { HELPER_BOOTSTRAP, WindowsInputMonitor, encodeHelperCommand, helperScriptLine, } from './windows-monitor.js';
5
+ export { BurstInterrupted, PROTECTED_PROCESSES } from './types.js';
6
+ export { createWindowsForegroundLadder, screenLeasePath, windowsPathFor, } from './windows.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/foreground/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,cAAc,EACd,gBAAgB,EAChB,YAAY,EACZ,SAAS,GACT,MAAM,aAAa,CAAA;AAMpB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAExC,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC9E,OAAO,EACN,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,GAChB,MAAM,sBAAsB,CAAA;AAmB7B,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAClE,OAAO,EACN,6BAA6B,EAC7B,eAAe,EACf,cAAc,GACd,MAAM,cAAc,CAAA"}
@@ -0,0 +1,143 @@
1
+ import { ScreenLease } from './lease.js';
2
+ import { type BurstContext, type EditTextRequest, type EditTextResult, type ForegroundApprover, type ForegroundMonitor, type ForegroundOutcome, type ForegroundSubject, type MenuCommandRequest, type MenuCommandResult, type SelectItemRequest, type SelectItemResult } from './types.js';
3
+ /** Time, replaceable so the waits below run on a fake clock in tests. */
4
+ export interface LadderClock {
5
+ now(): number;
6
+ sleep(ms: number, signal?: AbortSignal): Promise<void>;
7
+ }
8
+ export declare const realClock: LadderClock;
9
+ /** The thresholds and bounds of the ladder. Every wait is bounded. */
10
+ export interface LadderTiming {
11
+ /**
12
+ * How long the user must have been still before the screen is used.
13
+ * 2 000 ms: on the machine this was measured on, the gaps between a person's
14
+ * inputs rarely reach 5 s while 2 s is common between bursts of activity,
15
+ * and a keep-awake nudge every ~26 s leaves 24 s of every 26 free.
16
+ */
17
+ readonly idleMs: number;
18
+ /** Idle needed once the user has agreed to give up the screen for a moment. */
19
+ readonly approvedIdleMs: number;
20
+ /** How often the monitor is read while waiting. */
21
+ readonly pollMs: number;
22
+ /** How long to wait for the user to go idle before asking them. */
23
+ readonly userActiveWaitMs: number;
24
+ /** How long to keep waiting after they agreed. */
25
+ readonly approvedWaitMs: number;
26
+ /** Where nobody can be asked (exec, scheduled): how long to wait for a still moment. */
27
+ readonly parkMs: number;
28
+ readonly parkPollMs: number;
29
+ /** How long to wait for another session to release the lease. */
30
+ readonly leaseWaitMs: number;
31
+ readonly leasePollMs: number;
32
+ /** How often a held lease is refreshed while a burst runs (well inside its time-to-live). */
33
+ readonly leaseBeatMs: number;
34
+ /** Most time one turn may spend parked, over all its calls. */
35
+ readonly parkTurnMs: number;
36
+ }
37
+ export declare const DEFAULT_TIMING: LadderTiming;
38
+ export interface ForegroundLadderOptions {
39
+ /** A fresh monitor each time one is needed (it is stopped between turns). */
40
+ readonly createMonitor: () => ForegroundMonitor;
41
+ /** Full path of the lease file. */
42
+ readonly leasePath: string;
43
+ readonly session?: string;
44
+ /** Present where a person can be asked. */
45
+ readonly approve?: ForegroundApprover;
46
+ readonly timing?: Partial<LadderTiming>;
47
+ readonly clock?: LadderClock;
48
+ readonly lease?: ScreenLease;
49
+ }
50
+ /** What the model reads once Escape has stopped the turn. Fixed on purpose. */
51
+ export declare const STOPPED_TEXT = "The user pressed Escape, so computer use is stopped for the rest of this turn. Stop now: tell the user what is still undone, and do not call computer_use again until they send a new message.";
52
+ /** What one burst asks of the ladder. */
53
+ export interface LadderRequest {
54
+ readonly subject: ForegroundSubject;
55
+ /** The burst leaves the cursor where it put it (a `mouse_move`). */
56
+ readonly keepCursor?: boolean;
57
+ /** Stops waiting for the screen (the idle gate, the lease) when aborted. */
58
+ readonly signal?: AbortSignal;
59
+ /** The burst sends keyboard or mouse input: the outcome says whether the system registered it. */
60
+ readonly sendsInput?: boolean;
61
+ /**
62
+ * Awaited after the burst function returns or throws and before the window
63
+ * and cursor are put back: calls a cancelled burst left in flight must
64
+ * finish first, or they would act after the restore.
65
+ */
66
+ readonly settle?: () => Promise<void>;
67
+ }
68
+ /**
69
+ * The foreground ladder. `run` takes a burst (a function that sends input
70
+ * which can only be delivered in the foreground) through:
71
+ *
72
+ * 1. the lease: one session at a time, a stale lease taken over;
73
+ * 2. the safety checks: lock screen, system prompts, administrator windows;
74
+ * 3. the idle gate: the user still for `idleMs`;
75
+ * 4. if the user stays busy for `userActiveWaitMs`: one question to them, or,
76
+ * where nobody can be asked, a bounded wait that retries;
77
+ * 5. the burst, watched for real input from start to end;
78
+ * 6. a conditional restore of the window and cursor that were there before.
79
+ *
80
+ * Nothing here sends input itself and nothing waits without a bound.
81
+ */
82
+ export declare class ForegroundLadder {
83
+ private readonly options;
84
+ private readonly timing;
85
+ private readonly clock;
86
+ private readonly lease;
87
+ private monitor;
88
+ private queue;
89
+ /** The restore of a cancelled burst, which runs after its caller has been answered. */
90
+ private background;
91
+ private stop;
92
+ private readonly leaseBeatMs;
93
+ private parkedMs;
94
+ private turn;
95
+ private readonly allowed;
96
+ private readonly denied;
97
+ constructor(options: ForegroundLadderOptions);
98
+ /** True after a physical Escape, until the next user turn. */
99
+ get stopped(): boolean;
100
+ /**
101
+ * The model's turn `turnId` is starting a tool call. A new turn lifts an
102
+ * Escape stop and forgets refused permissions. A caller that has no turn id
103
+ * passes undefined, which always counts as a new turn.
104
+ */
105
+ beginTurn(turnId: string | undefined): void;
106
+ /**
107
+ * Reads or changes a classic edit control by window message through the
108
+ * monitor. It uses neither the screen nor the lease: nothing is raised and
109
+ * no input is sent. Undefined where no monitor can reach controls.
110
+ */
111
+ editText(request: EditTextRequest): Promise<EditTextResult | undefined>;
112
+ /**
113
+ * Selects one list or tree item through its selection pattern. Like
114
+ * `editText` it uses neither the screen nor the lease. Undefined where no
115
+ * monitor can reach controls.
116
+ */
117
+ selectItem(request: SelectItemRequest): Promise<SelectItemResult | undefined>;
118
+ /**
119
+ * Sends the menu command a shortcut stands for, as a window message: no
120
+ * screen, no lease, no key. Undefined where no monitor can reach windows.
121
+ */
122
+ menuCommand(request: MenuCommandRequest): Promise<MenuCommandResult | undefined>;
123
+ /**
124
+ * Whether the computer is locked, read from the long-lived helper (cheap once
125
+ * it runs): the input desktop is not the normal one, or the lock screen's own
126
+ * program is in front. `null` when unsure (no helper, or a state that is not
127
+ * clearly either), so a caller treats it as unlocked.
128
+ */
129
+ lockState(): Promise<'locked' | 'unlocked' | null>;
130
+ /** The model's turn ended or was interrupted: nothing stays watched or held. */
131
+ endTurn(): Promise<void>;
132
+ dispose(): Promise<void>;
133
+ run<T>(request: LadderRequest, burst: (context: BurstContext) => Promise<T>): Promise<ForegroundOutcome<T>>;
134
+ private runOne;
135
+ private retryAfterInterference;
136
+ private ensureMonitor;
137
+ private dropMonitor;
138
+ private acquireLease;
139
+ /** Safety checks and the idle gate, with the one question to the user. */
140
+ private gate;
141
+ private unsafe;
142
+ }
143
+ //# sourceMappingURL=ladder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ladder.d.ts","sourceRoot":"","sources":["../../src/foreground/ladder.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,WAAW,EAAE,MAAM,YAAY,CAAA;AAC3D,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAEvB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAItB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,MAAM,YAAY,CAAA;AAEnB,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC3B,GAAG,IAAI,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACtD;AAED,eAAO,MAAM,SAAS,EAAE,WAcvB,CAAA;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,QAAQ,CAAC,MA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