@dsh-workbench/shared 1.5.5-rc.0 → 1.5.6
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/dist/api/dsh.d.ts +9 -1
- package/dist/components/card/ApprovalPlan.css +3 -0
- package/dist/components/card/ApprovalPlan.js +7 -2
- package/dist/components/card/LongTaskRow.css +32 -0
- package/dist/components/card/LongTaskRow.d.ts +8 -2
- package/dist/components/card/LongTaskRow.js +26 -5
- package/dist/components/card/board-module.d.ts +35 -4
- package/dist/components/card/use-text-marquee.d.ts +15 -0
- package/dist/components/card/use-text-marquee.js +66 -0
- package/dist/components/feedback/ProgressBar.css +56 -0
- package/dist/components/feedback/ProgressBar.d.ts +25 -0
- package/dist/components/feedback/ProgressBar.js +22 -0
- package/dist/config/constants.d.ts +2 -0
- package/dist/config/constants.js +2 -0
- package/dist/contract/guards.d.ts +1 -0
- package/dist/contract/guards.js +3 -0
- package/dist/contract/long-task.d.ts +56 -0
- package/dist/contract/long-task.js +41 -0
- package/dist/contract/protocol/long-tasks.d.ts +8 -2
- package/dist/contract/unit.d.ts +1 -0
- package/dist/host/diy/diy-preset.d.ts +1 -1
- package/dist/host/diy/diy-preset.js +3 -3
- package/dist/host/flow/create.d.ts +2 -1
- package/dist/host/flow/create.js +6 -0
- package/dist/host/flow/dsh-journal.d.ts +3 -0
- package/dist/host/flow/dsh-journal.js +55 -0
- package/dist/host/flow/journal.d.ts +20 -0
- package/dist/host/flow/journal.js +30 -0
- package/dist/host/flow/open.js +43 -26
- package/dist/host/flow/task.js +12 -1
- package/dist/host/flow/types.d.ts +5 -0
- package/dist/host/platform/integration/browser-launch.d.ts +1 -0
- package/dist/host/platform/integration/browser-launch.js +9 -2
- package/dist/host/profile/bundle-manager.js +4 -6
- package/dist/host/unit/long-task-host.d.ts +18 -0
- package/dist/host/unit/long-task-host.js +44 -0
- package/dist/host/unit/long-task-progress.d.ts +3 -0
- package/dist/host/unit/long-task-progress.js +32 -0
- package/dist/host/unit/long-task.d.ts +14 -38
- package/dist/host/unit/long-task.js +95 -94
- package/dist/host/unit/unit-face.d.ts +2 -1
- package/dist/host/unit/with-intervention-retry.d.ts +20 -0
- package/dist/host/unit/with-intervention-retry.js +45 -0
- package/dist/host.d.ts +30 -19
- package/dist/host.js +30 -19
- package/dist/i18n/en.js +33 -7
- package/dist/i18n/index.d.ts +33 -7
- package/dist/i18n/zh.d.ts +32 -6
- package/dist/i18n/zh.js +32 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/package.json +2 -1
- package/src/api/dsh.ts +12 -1
- package/src/components/card/ApprovalPlan.css +3 -0
- package/src/components/card/ApprovalPlan.tsx +9 -2
- package/src/components/card/LongTaskRow.css +32 -0
- package/src/components/card/LongTaskRow.tsx +51 -4
- package/src/components/card/__tests__/ApprovalPlan.test.tsx +50 -0
- package/src/components/card/__tests__/long-task-row.test.ts +64 -2
- package/src/components/card/board-module.ts +36 -4
- package/src/components/card/use-text-marquee.ts +79 -0
- package/src/components/feedback/ProgressBar.css +56 -0
- package/src/components/feedback/ProgressBar.tsx +60 -0
- package/src/config/constants.ts +3 -0
- package/src/contract/__tests__/long-task.test.ts +43 -1
- package/src/contract/guards.ts +4 -0
- package/src/contract/long-task.ts +75 -0
- package/src/contract/protocol/long-tasks.ts +9 -1
- package/src/contract/unit.ts +1 -0
- package/src/host/diy/__tests__/diy-preset.test.ts +2 -0
- package/src/host/diy/diy-preset.ts +3 -2
- package/src/host/flow/__tests__/dsh-journal.test.ts +56 -0
- package/src/host/flow/__tests__/flow-create.test.ts +41 -1
- package/src/host/flow/__tests__/flow-open.test.ts +32 -0
- package/src/host/flow/create.ts +8 -5
- package/src/host/flow/dsh-journal.ts +74 -0
- package/src/host/flow/journal.ts +46 -0
- package/src/host/flow/open.ts +41 -26
- package/src/host/flow/task.ts +11 -1
- package/src/host/flow/types.ts +6 -0
- package/src/host/platform/integration/__tests__/browser-launch.test.ts +27 -0
- package/src/host/platform/integration/browser-launch.ts +15 -3
- package/src/host/profile/bundle-manager.ts +4 -7
- package/src/host/unit/__tests__/long-task.test.ts +203 -2
- package/src/host/unit/long-task-host.ts +64 -0
- package/src/host/unit/long-task-progress.ts +37 -0
- package/src/host/unit/long-task.ts +112 -126
- package/src/host/unit/unit-face.ts +2 -1
- package/src/host/unit/with-intervention-retry.ts +55 -0
- package/src/host.ts +31 -20
- package/src/i18n/en.ts +33 -7
- package/src/i18n/zh.ts +32 -6
- package/src/index.ts +4 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { epochOf, now as clockNow, nowIso } from '../runtime/time.js';
|
|
2
|
-
import {
|
|
2
|
+
import { derivedLongTaskProgress, nextLongTaskProgress } from './long-task-progress.js';
|
|
3
|
+
import { LONG_TASK_HISTORY_MAX, LONG_TASK_LINK_MAX, longTaskPlanTotalOf, longTaskPlanStepsOf, } from '../../contract/long-task.js';
|
|
3
4
|
function isLiveStatus(status) {
|
|
4
5
|
return status === 'running' || status === 'needs-human' || status === 'needs-login';
|
|
5
6
|
}
|
|
@@ -43,6 +44,9 @@ export function longTaskRowBase(snapshot) {
|
|
|
43
44
|
'loginUrl',
|
|
44
45
|
'why',
|
|
45
46
|
'session',
|
|
47
|
+
'seen',
|
|
48
|
+
'progress',
|
|
49
|
+
'plan',
|
|
46
50
|
]),
|
|
47
51
|
};
|
|
48
52
|
}
|
|
@@ -50,6 +54,9 @@ export function createLongTaskRegistry(deps) {
|
|
|
50
54
|
let bound = deps;
|
|
51
55
|
const runs = new Map();
|
|
52
56
|
const controls = new Map();
|
|
57
|
+
const reported = new Set();
|
|
58
|
+
const counted = new Set();
|
|
59
|
+
const warned = new Set();
|
|
53
60
|
const now = () => (bound.now ?? nowIso)();
|
|
54
61
|
let counter = 0;
|
|
55
62
|
const nextId = () => (bound.nextId ?? (() => `run-${clockNow()}-${(counter += 1)}`))();
|
|
@@ -74,10 +81,41 @@ export function createLongTaskRegistry(deps) {
|
|
|
74
81
|
const current = runs.get(id);
|
|
75
82
|
if (current === undefined)
|
|
76
83
|
return;
|
|
77
|
-
const
|
|
84
|
+
const resolved = next.progress === undefined
|
|
85
|
+
? current.progress
|
|
86
|
+
: (nextLongTaskProgress(next.progress, current.progress) ?? undefined);
|
|
87
|
+
const patched = {
|
|
88
|
+
...current,
|
|
89
|
+
...next,
|
|
90
|
+
at: now(),
|
|
91
|
+
};
|
|
92
|
+
if (resolved === undefined)
|
|
93
|
+
delete patched.progress;
|
|
94
|
+
else
|
|
95
|
+
patched.progress = resolved;
|
|
78
96
|
runs.set(id, patched);
|
|
79
97
|
notify({ ...change, snapshot: patched });
|
|
80
98
|
};
|
|
99
|
+
const setProgress = (id, next) => {
|
|
100
|
+
const current = runs.get(id);
|
|
101
|
+
if (current === undefined)
|
|
102
|
+
return;
|
|
103
|
+
const resolved = next === undefined ? null : nextLongTaskProgress(next, current.progress);
|
|
104
|
+
if (resolved === null) {
|
|
105
|
+
if (current.progress === undefined)
|
|
106
|
+
return;
|
|
107
|
+
const cleared = { ...current };
|
|
108
|
+
delete cleared.progress;
|
|
109
|
+
runs.set(id, cleared);
|
|
110
|
+
notify({ kind: 'progress', snapshot: cleared });
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (current.progress?.done === resolved.done && current.progress.total === resolved.total)
|
|
114
|
+
return;
|
|
115
|
+
const patched = { ...current, progress: resolved };
|
|
116
|
+
runs.set(id, patched);
|
|
117
|
+
notify({ kind: 'progress', snapshot: patched });
|
|
118
|
+
};
|
|
81
119
|
return {
|
|
82
120
|
get resumable() {
|
|
83
121
|
return bound.recheck !== undefined;
|
|
@@ -116,12 +154,18 @@ export function createLongTaskRegistry(deps) {
|
|
|
116
154
|
live() {
|
|
117
155
|
return [...runs.values()].filter((snapshot) => isLiveStatus(snapshot.status));
|
|
118
156
|
},
|
|
157
|
+
recent() {
|
|
158
|
+
const floor = epochOf(now()) - recentMs();
|
|
159
|
+
return [...runs.values()].filter((snapshot) => isLiveStatus(snapshot.status) || epochOf(snapshot.at) >= floor);
|
|
160
|
+
},
|
|
119
161
|
start(options) {
|
|
120
162
|
const running = this.active(options.workspace, options.target);
|
|
121
163
|
if (running !== null)
|
|
122
164
|
return running;
|
|
123
165
|
const id = nextId();
|
|
124
166
|
const startedAt = now();
|
|
167
|
+
const planTotal = bound.plan === undefined ? 0 : longTaskPlanTotalOf(bound.plan);
|
|
168
|
+
const planSteps = bound.plan === undefined ? [] : longTaskPlanStepsOf(bound.plan);
|
|
125
169
|
runs.set(id, {
|
|
126
170
|
id,
|
|
127
171
|
workspace: options.workspace,
|
|
@@ -132,6 +176,9 @@ export function createLongTaskRegistry(deps) {
|
|
|
132
176
|
history: [],
|
|
133
177
|
startedAt,
|
|
134
178
|
at: startedAt,
|
|
179
|
+
seen: false,
|
|
180
|
+
...(planTotal > 0 ? { progress: { done: 0, total: planTotal } } : {}),
|
|
181
|
+
...(planSteps.length === 0 ? {} : { plan: planSteps }),
|
|
135
182
|
...(options.session === undefined ? {} : { session: options.session }),
|
|
136
183
|
});
|
|
137
184
|
notify({ kind: 'start', snapshot: runs.get(id) });
|
|
@@ -156,9 +203,25 @@ export function createLongTaskRegistry(deps) {
|
|
|
156
203
|
: mergeStepRow(current.history ?? [], historyRow);
|
|
157
204
|
const steps = history.map((row) => `${row.kind === 'fail' ? '✗ ' : ''}${row.text}`);
|
|
158
205
|
const extra = bound.step?.(step, current) ?? {};
|
|
206
|
+
if (extra.progress !== undefined)
|
|
207
|
+
reported.add(id);
|
|
208
|
+
const derived = reported.has(id)
|
|
209
|
+
? undefined
|
|
210
|
+
: derivedLongTaskProgress(history, planTotal, planSteps);
|
|
211
|
+
if (derived !== undefined)
|
|
212
|
+
counted.add(id);
|
|
213
|
+
if (planTotal === 0 && !reported.has(id) && !warned.has(id)) {
|
|
214
|
+
const ids = new Set(history.map((row) => row.stepId));
|
|
215
|
+
if (ids.size >= 3) {
|
|
216
|
+
warned.add(id);
|
|
217
|
+
console.warn(`[dsh-workbench] 长任务(${current.target})已经报了 ${String(ids.size)} 个步骤却没有计划 —— ` +
|
|
218
|
+
'行上没有进度条:在 longTasks.create 里给一次 plan({ steps } 或 { total }),步数由外壳自己数');
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
const next = derived === undefined ? extra : { ...extra, progress: derived };
|
|
159
222
|
if (step.intervention !== undefined) {
|
|
160
223
|
patch(id, {
|
|
161
|
-
...
|
|
224
|
+
...next,
|
|
162
225
|
status: 'needs-human',
|
|
163
226
|
step: step.text,
|
|
164
227
|
steps,
|
|
@@ -170,7 +233,7 @@ export function createLongTaskRegistry(deps) {
|
|
|
170
233
|
}
|
|
171
234
|
if (step.loginUrl !== undefined && step.loginUrl !== '') {
|
|
172
235
|
patch(id, {
|
|
173
|
-
...
|
|
236
|
+
...next,
|
|
174
237
|
status: 'needs-login',
|
|
175
238
|
step: step.text,
|
|
176
239
|
steps,
|
|
@@ -180,7 +243,7 @@ export function createLongTaskRegistry(deps) {
|
|
|
180
243
|
return;
|
|
181
244
|
}
|
|
182
245
|
patch(id, {
|
|
183
|
-
...
|
|
246
|
+
...next,
|
|
184
247
|
status: 'running',
|
|
185
248
|
step: step.text,
|
|
186
249
|
steps,
|
|
@@ -191,16 +254,29 @@ export function createLongTaskRegistry(deps) {
|
|
|
191
254
|
};
|
|
192
255
|
const control = new AbortController();
|
|
193
256
|
controls.set(id, control);
|
|
257
|
+
const onProgress = (next) => {
|
|
258
|
+
if (live(id) === null)
|
|
259
|
+
return;
|
|
260
|
+
reported.add(id);
|
|
261
|
+
counted.add(id);
|
|
262
|
+
setProgress(id, next);
|
|
263
|
+
};
|
|
194
264
|
void bound
|
|
195
|
-
.run({ payload: options.payload, onStep, signal: control.signal })
|
|
265
|
+
.run({ payload: options.payload, onStep, onProgress, signal: control.signal })
|
|
196
266
|
.then((result) => {
|
|
197
267
|
const current = live(id);
|
|
198
268
|
if (current === null)
|
|
199
269
|
return;
|
|
200
270
|
controls.delete(id);
|
|
271
|
+
const outcome = bound.outcome?.(result, current) ?? {};
|
|
272
|
+
const filled = outcome.progress ??
|
|
273
|
+
(current.progress === undefined
|
|
274
|
+
? undefined
|
|
275
|
+
: { done: current.progress.total, total: current.progress.total });
|
|
201
276
|
patch(id, {
|
|
277
|
+
...outcome,
|
|
202
278
|
status: 'ok',
|
|
203
|
-
...(
|
|
279
|
+
...(filled === undefined ? {} : { progress: filled }),
|
|
204
280
|
intervention: undefined,
|
|
205
281
|
loginUrl: undefined,
|
|
206
282
|
}, { kind: 'settle' });
|
|
@@ -260,6 +336,17 @@ export function createLongTaskRegistry(deps) {
|
|
|
260
336
|
}, { kind: 'settle', by });
|
|
261
337
|
return true;
|
|
262
338
|
},
|
|
339
|
+
seen(id) {
|
|
340
|
+
const current = runs.get(id);
|
|
341
|
+
if (current === undefined || isLiveStatus(current.status))
|
|
342
|
+
return false;
|
|
343
|
+
if (current.seen === true)
|
|
344
|
+
return true;
|
|
345
|
+
const patched = { ...current, seen: true };
|
|
346
|
+
runs.set(id, patched);
|
|
347
|
+
notify({ kind: 'seen', snapshot: patched });
|
|
348
|
+
return true;
|
|
349
|
+
},
|
|
263
350
|
snapshot(id) {
|
|
264
351
|
return runs.get(id) ?? null;
|
|
265
352
|
},
|
|
@@ -272,90 +359,4 @@ export function createLongTaskRegistry(deps) {
|
|
|
272
359
|
},
|
|
273
360
|
};
|
|
274
361
|
}
|
|
275
|
-
|
|
276
|
-
const INTERVENTION_RETRY_DELAY_MS = 1500;
|
|
277
|
-
function defaultInterventionSleep(ms) {
|
|
278
|
-
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* 把「看一眼接上没有」包成能交给 `longTasks.create({ recheck })` 的 handler:
|
|
282
|
-
* 用户在人工干预节点上按「我处理完了」时先立刻试一次,没接上就有界地再试(第 2 轮起每轮先等)。
|
|
283
|
-
* `check` 返回 true = 已经接上,不用再试;抛错算没接上、继续下一轮。
|
|
284
|
-
* 同一 id 上一轮还在飞时再按直接忽略;成功 / 用尽都清单飞;**永不抛错**(fire-and-forget)。
|
|
285
|
-
* @param check 看一眼接上没有,可同步可异步。
|
|
286
|
-
* @param options 轮次上限(默认 5)、第几次等待等多久(默认 1500ms,可给函数,从第 1 次等待起算)、怎么等(默认真等,测试可注入假的)。
|
|
287
|
-
* @returns 一条同签名的 handler,直接交给 `const longTasks = create({ recheck })`。
|
|
288
|
-
*/
|
|
289
|
-
export function withInterventionRetry(check, options = {}) {
|
|
290
|
-
const attempts = options.attempts ?? INTERVENTION_RETRY_ATTEMPTS;
|
|
291
|
-
const delayMs = options.delayMs ?? INTERVENTION_RETRY_DELAY_MS;
|
|
292
|
-
const sleep = options.sleep ?? defaultInterventionSleep;
|
|
293
|
-
const inFlight = new Set();
|
|
294
|
-
return (current) => {
|
|
295
|
-
if (inFlight.has(current.id))
|
|
296
|
-
return;
|
|
297
|
-
inFlight.add(current.id);
|
|
298
|
-
void (async () => {
|
|
299
|
-
try {
|
|
300
|
-
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
301
|
-
if (attempt > 1) {
|
|
302
|
-
await sleep(typeof delayMs === 'function' ? delayMs(attempt - 1) : delayMs);
|
|
303
|
-
}
|
|
304
|
-
try {
|
|
305
|
-
if (await check(current))
|
|
306
|
-
return;
|
|
307
|
-
}
|
|
308
|
-
catch {
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
catch {
|
|
313
|
-
}
|
|
314
|
-
finally {
|
|
315
|
-
inFlight.delete(current.id);
|
|
316
|
-
}
|
|
317
|
-
})();
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
function isRegistry(value) {
|
|
321
|
-
if (typeof value !== 'object' || value === null)
|
|
322
|
-
return false;
|
|
323
|
-
const candidate = value;
|
|
324
|
-
return (typeof candidate.start === 'function' &&
|
|
325
|
-
typeof candidate.current === 'function' &&
|
|
326
|
-
typeof candidate.snapshot === 'function' &&
|
|
327
|
-
typeof candidate.onChange === 'function');
|
|
328
|
-
}
|
|
329
|
-
export function sharedLongTaskRegistry(scope, key, deps) {
|
|
330
|
-
const store = globalThis;
|
|
331
|
-
const slot = Symbol.for(`dsh-workbench:long-task:${scope}:${key}`);
|
|
332
|
-
const existing = store[slot];
|
|
333
|
-
if (existing !== undefined && isRegistry(existing)) {
|
|
334
|
-
existing.rebind?.(deps);
|
|
335
|
-
return existing;
|
|
336
|
-
}
|
|
337
|
-
const created = createLongTaskRegistry(deps);
|
|
338
|
-
store[slot] = created;
|
|
339
|
-
return created;
|
|
340
|
-
}
|
|
341
|
-
export function createLongTaskHost(options) {
|
|
342
|
-
const offs = [];
|
|
343
|
-
return {
|
|
344
|
-
host: {
|
|
345
|
-
create(createOptions) {
|
|
346
|
-
const { key, facts, ...deps } = createOptions;
|
|
347
|
-
const registry = sharedLongTaskRegistry(options.scope, `${options.unit}:${key}`, deps);
|
|
348
|
-
offs.push(registry.onChange((change) => {
|
|
349
|
-
const named = [runsRouteOf(options.unit), ...(facts?.(change) ?? [])];
|
|
350
|
-
options.bump([...new Set(named)]);
|
|
351
|
-
options.notify?.(change);
|
|
352
|
-
}));
|
|
353
|
-
return registry;
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
dispose() {
|
|
357
|
-
for (const off of offs.splice(0))
|
|
358
|
-
off();
|
|
359
|
-
},
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
+
export { withInterventionRetry } from './with-intervention-retry.js';
|
|
@@ -2,7 +2,8 @@ import type { HostContext } from '../../contract/module-context.js';
|
|
|
2
2
|
import type { UnitManifest } from '../../contract/unit.js';
|
|
3
3
|
import type { Need } from '../../contract/needs.js';
|
|
4
4
|
import type { RouteTable } from '../runtime/http.js';
|
|
5
|
-
import type { LongTaskBase,
|
|
5
|
+
import type { LongTaskBase, LongTaskRegistry } from './long-task.js';
|
|
6
|
+
import type { LongTaskHost } from './long-task-host.js';
|
|
6
7
|
import type { ProvisionHandler } from '../supply/provision.js';
|
|
7
8
|
import type { UnitCapability } from '../../contract/unit-capability.js';
|
|
8
9
|
import type { ApprovalCall, ApprovalFacts, ApprovalPolicy } from './tool-approval.js';
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `withInterventionRetry` 的口径:最多试几次、每轮先等多久(也可按轮次算)、怎么等。
|
|
3
|
+
*/
|
|
4
|
+
export interface InterventionRetryOptions {
|
|
5
|
+
readonly attempts?: number | undefined;
|
|
6
|
+
readonly delayMs?: number | ((attempt: number) => number) | undefined;
|
|
7
|
+
readonly sleep?: ((ms: number) => Promise<void>) | undefined;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* 把「看一眼接上没有」包成能交给 `longTasks.create({ recheck })` 的 handler:
|
|
11
|
+
* 用户在人工干预节点上按「我处理完了」时先立刻试一次,没接上就有界地再试(第 2 轮起每轮先等)。
|
|
12
|
+
* `check` 返回 true = 已经接上,不用再试;抛错算没接上、继续下一轮。
|
|
13
|
+
* 同一 id 上一轮还在飞时再按直接忽略;成功 / 用尽都清单飞;**永不抛错**(fire-and-forget)。
|
|
14
|
+
* @param check 看一眼接上没有,可同步可异步。
|
|
15
|
+
* @param options 轮次上限(默认 5)、第几次等待等多久(默认 1500ms,可给函数,从第 1 次等待起算)、怎么等(默认真等,测试可注入假的)。
|
|
16
|
+
* @returns 一条同签名的 handler,直接交给 `const longTasks = create({ recheck })`。
|
|
17
|
+
*/
|
|
18
|
+
export declare function withInterventionRetry<S extends {
|
|
19
|
+
readonly id: string;
|
|
20
|
+
}>(check: (current: S) => boolean | Promise<boolean>, options?: InterventionRetryOptions): (current: S) => void;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const INTERVENTION_RETRY_ATTEMPTS = 5;
|
|
2
|
+
const INTERVENTION_RETRY_DELAY_MS = 1500;
|
|
3
|
+
function defaultInterventionSleep(ms) {
|
|
4
|
+
return new Promise((resolve) => setTimeout(resolve, Math.max(0, ms)));
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 把「看一眼接上没有」包成能交给 `longTasks.create({ recheck })` 的 handler:
|
|
8
|
+
* 用户在人工干预节点上按「我处理完了」时先立刻试一次,没接上就有界地再试(第 2 轮起每轮先等)。
|
|
9
|
+
* `check` 返回 true = 已经接上,不用再试;抛错算没接上、继续下一轮。
|
|
10
|
+
* 同一 id 上一轮还在飞时再按直接忽略;成功 / 用尽都清单飞;**永不抛错**(fire-and-forget)。
|
|
11
|
+
* @param check 看一眼接上没有,可同步可异步。
|
|
12
|
+
* @param options 轮次上限(默认 5)、第几次等待等多久(默认 1500ms,可给函数,从第 1 次等待起算)、怎么等(默认真等,测试可注入假的)。
|
|
13
|
+
* @returns 一条同签名的 handler,直接交给 `const longTasks = create({ recheck })`。
|
|
14
|
+
*/
|
|
15
|
+
export function withInterventionRetry(check, options = {}) {
|
|
16
|
+
const attempts = options.attempts ?? INTERVENTION_RETRY_ATTEMPTS;
|
|
17
|
+
const delayMs = options.delayMs ?? INTERVENTION_RETRY_DELAY_MS;
|
|
18
|
+
const sleep = options.sleep ?? defaultInterventionSleep;
|
|
19
|
+
const inFlight = new Set();
|
|
20
|
+
return (current) => {
|
|
21
|
+
if (inFlight.has(current.id))
|
|
22
|
+
return;
|
|
23
|
+
inFlight.add(current.id);
|
|
24
|
+
void (async () => {
|
|
25
|
+
try {
|
|
26
|
+
for (let attempt = 1; attempt <= attempts; attempt += 1) {
|
|
27
|
+
if (attempt > 1) {
|
|
28
|
+
await sleep(typeof delayMs === 'function' ? delayMs(attempt - 1) : delayMs);
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
if (await check(current))
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
inFlight.delete(current.id);
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
};
|
|
45
|
+
}
|
package/dist/host.d.ts
CHANGED
|
@@ -30,7 +30,6 @@ export * from './host/adapters/adapter-contract.js';
|
|
|
30
30
|
export * from './host/adapters/adapter-set.js';
|
|
31
31
|
export * from './host/adapters/adapter-types.js';
|
|
32
32
|
export * from './host/adapters/adapters.js';
|
|
33
|
-
export * from './host/platform/integration/host-surface.js';
|
|
34
33
|
export * from './host/adapters/port-types.js';
|
|
35
34
|
export * from './host/adapters/supply-port.js';
|
|
36
35
|
export * from './host/adapters/toolbox-port.js';
|
|
@@ -51,16 +50,18 @@ export * from './host/data/recipe-rules.js';
|
|
|
51
50
|
export * from './host/data/recipe.js';
|
|
52
51
|
export * from './host/data/site.js';
|
|
53
52
|
export * from './host/data/spec.js';
|
|
54
|
-
export * from './host/drafts/draft-store.js';
|
|
55
53
|
export * from './host/diy/diy-debug.js';
|
|
56
54
|
export * from './host/diy/diy-preset.js';
|
|
57
55
|
export * from './host/diy/diy-record.js';
|
|
58
56
|
export * from './host/diy/hold.js';
|
|
57
|
+
export * from './host/drafts/draft-store.js';
|
|
59
58
|
export * from './host/flow/agent.js';
|
|
60
59
|
export * from './host/flow/check.js';
|
|
61
60
|
export * from './host/flow/create.js';
|
|
62
61
|
export * from './host/flow/data.js';
|
|
62
|
+
export * from './host/flow/dsh-journal.js';
|
|
63
63
|
export * from './host/flow/expr.js';
|
|
64
|
+
export * from './host/flow/journal.js';
|
|
64
65
|
export * from './host/flow/kit.js';
|
|
65
66
|
export * from './host/flow/login-retry.js';
|
|
66
67
|
export * from './host/flow/open.js';
|
|
@@ -75,12 +76,27 @@ export * from './host/git/auth-loss.js';
|
|
|
75
76
|
export * from './host/git/git.js';
|
|
76
77
|
export * from './host/patch/patch-blocks.js';
|
|
77
78
|
export * from './host/patch/patch.js';
|
|
79
|
+
export * from './host/platform/facts.js';
|
|
80
|
+
export * from './host/platform/integration/bridge.js';
|
|
81
|
+
export * from './host/platform/integration/browser-launch.js';
|
|
82
|
+
export * from './host/platform/integration/browser-process.js';
|
|
83
|
+
export * from './host/platform/integration/browser-read.js';
|
|
84
|
+
export * from './host/platform/integration/browsers.js';
|
|
85
|
+
export * from './host/platform/integration/data.js';
|
|
86
|
+
export * from './host/platform/integration/env-policy.js';
|
|
87
|
+
export * from './host/platform/integration/front-app.js';
|
|
88
|
+
export * from './host/platform/integration/host-surface.js';
|
|
89
|
+
export * from './host/platform/integration/process.js';
|
|
90
|
+
export * from './host/platform/integration/tool-lookup.js';
|
|
91
|
+
export * from './host/platform/ops/shell-render.js';
|
|
92
|
+
export * from './host/platform/ops/shell-text.js';
|
|
93
|
+
export * from './host/platform/ops/shell.js';
|
|
94
|
+
export * from './host/profile/build-approval.js';
|
|
78
95
|
export * from './host/profile/bundle-manager.js';
|
|
79
96
|
export * from './host/profile/config-sync.js';
|
|
80
97
|
export * from './host/profile/dsh-plugins.js';
|
|
81
|
-
export * from './host/profile/build-approval.js';
|
|
82
|
-
export * from './host/profile/module-rows.js';
|
|
83
98
|
export * from './host/profile/hmr-reload.js';
|
|
99
|
+
export * from './host/profile/module-rows.js';
|
|
84
100
|
export * from './host/profile/pnpm-command.js';
|
|
85
101
|
export * from './host/profile/profile-bundles.js';
|
|
86
102
|
export * from './host/profile/profile-create.js';
|
|
@@ -90,20 +106,12 @@ export * from './host/runtime/boot-record.js';
|
|
|
90
106
|
export * from './host/runtime/changelog.js';
|
|
91
107
|
export * from './host/runtime/cli-error.js';
|
|
92
108
|
export * from './host/runtime/cli.js';
|
|
93
|
-
export * from './host/runtime/
|
|
94
|
-
export * from './host/platform/integration/env-policy.js';
|
|
95
|
-
export * from './host/platform/integration/browser-read.js';
|
|
96
|
-
export * from './host/platform/integration/data.js';
|
|
97
|
-
export * from './host/platform/integration/front-app.js';
|
|
98
|
-
export * from './host/platform/integration/tool-lookup.js';
|
|
99
|
-
export * from './host/platform/integration/browsers.js';
|
|
100
|
-
export * from './host/platform/integration/bridge.js';
|
|
101
|
-
export * from './host/platform/integration/browser-process.js';
|
|
102
|
-
export * from './host/platform/integration/browser-launch.js';
|
|
109
|
+
export * from './host/runtime/diag-bundle.js';
|
|
103
110
|
export * from './host/runtime/diag-records.js';
|
|
104
111
|
export * from './host/runtime/diag-sink.js';
|
|
105
|
-
export * from './host/runtime/diag-bundle.js';
|
|
106
112
|
export * from './host/runtime/diag-summary.js';
|
|
113
|
+
export * from './host/runtime/dsh-compat.js';
|
|
114
|
+
export * from './host/runtime/env-policy.js';
|
|
107
115
|
export * from './host/runtime/fs-write.js';
|
|
108
116
|
export * from './host/runtime/http.js';
|
|
109
117
|
export * from './host/runtime/lease.js';
|
|
@@ -111,8 +119,8 @@ export * from './host/runtime/paths.js';
|
|
|
111
119
|
export * from './host/runtime/process-alive.js';
|
|
112
120
|
export * from './host/runtime/read-json.js';
|
|
113
121
|
export * from './host/runtime/time.js';
|
|
114
|
-
export * from './host/runtime/version-range.js';
|
|
115
122
|
export * from './host/runtime/verified-dsh.js';
|
|
123
|
+
export * from './host/runtime/version-range.js';
|
|
116
124
|
export * from './host/runtime/version.js';
|
|
117
125
|
export * from './host/runtime/workspace-store.js';
|
|
118
126
|
export * from './host/runtime/write-result.js';
|
|
@@ -127,17 +135,17 @@ export * from './host/seam/process.js';
|
|
|
127
135
|
export * from './host/seam/run.js';
|
|
128
136
|
export * from './host/seam/service.js';
|
|
129
137
|
export * from './host/seam/unit-seam.js';
|
|
130
|
-
export * from './host/
|
|
131
|
-
export * from './host/
|
|
138
|
+
export * from './host/shell/shell-render.js';
|
|
139
|
+
export * from './host/shell/shell-text.js';
|
|
132
140
|
export * from './host/shell/shell.js';
|
|
133
141
|
export * from './host/shell/tokens.js';
|
|
142
|
+
export * from './host/supply/builtin-catalog.js';
|
|
134
143
|
export * from './host/supply/install-failure.js';
|
|
135
144
|
export * from './host/supply/installed-module.js';
|
|
136
145
|
export * from './host/supply/installed-sources.js';
|
|
137
146
|
export * from './host/supply/lib-capabilities.js';
|
|
138
147
|
export * from './host/supply/lib-install.js';
|
|
139
148
|
export * from './host/supply/lib-runners.js';
|
|
140
|
-
export * from './host/supply/builtin-catalog.js';
|
|
141
149
|
export * from './host/supply/market-index-claim.js';
|
|
142
150
|
export * from './host/supply/market-index-doc.js';
|
|
143
151
|
export * from './host/supply/market-index-parse.js';
|
|
@@ -172,6 +180,8 @@ export * from './host/unit/facts.js';
|
|
|
172
180
|
export * from './host/unit/host-actions.js';
|
|
173
181
|
export * from './host/unit/host-kit.js';
|
|
174
182
|
export * from './host/unit/local-declaration.js';
|
|
183
|
+
export * from './host/unit/long-task-host.js';
|
|
184
|
+
export * from './host/unit/long-task-progress.js';
|
|
175
185
|
export * from './host/unit/long-task.js';
|
|
176
186
|
export * from './host/unit/needs.js';
|
|
177
187
|
export * from './host/unit/panel-state.js';
|
|
@@ -182,3 +192,4 @@ export * from './host/unit/unit-data.js';
|
|
|
182
192
|
export * from './host/unit/unit-face.js';
|
|
183
193
|
export * from './host/unit/unit-plugin.js';
|
|
184
194
|
export * from './host/unit/value-handoff.js';
|
|
195
|
+
export * from './host/unit/with-intervention-retry.js';
|
package/dist/host.js
CHANGED
|
@@ -30,7 +30,6 @@ export * from './host/adapters/adapter-contract.js';
|
|
|
30
30
|
export * from './host/adapters/adapter-set.js';
|
|
31
31
|
export * from './host/adapters/adapter-types.js';
|
|
32
32
|
export * from './host/adapters/adapters.js';
|
|
33
|
-
export * from './host/platform/integration/host-surface.js';
|
|
34
33
|
export * from './host/adapters/port-types.js';
|
|
35
34
|
export * from './host/adapters/supply-port.js';
|
|
36
35
|
export * from './host/adapters/toolbox-port.js';
|
|
@@ -51,16 +50,18 @@ export * from './host/data/recipe-rules.js';
|
|
|
51
50
|
export * from './host/data/recipe.js';
|
|
52
51
|
export * from './host/data/site.js';
|
|
53
52
|
export * from './host/data/spec.js';
|
|
54
|
-
export * from './host/drafts/draft-store.js';
|
|
55
53
|
export * from './host/diy/diy-debug.js';
|
|
56
54
|
export * from './host/diy/diy-preset.js';
|
|
57
55
|
export * from './host/diy/diy-record.js';
|
|
58
56
|
export * from './host/diy/hold.js';
|
|
57
|
+
export * from './host/drafts/draft-store.js';
|
|
59
58
|
export * from './host/flow/agent.js';
|
|
60
59
|
export * from './host/flow/check.js';
|
|
61
60
|
export * from './host/flow/create.js';
|
|
62
61
|
export * from './host/flow/data.js';
|
|
62
|
+
export * from './host/flow/dsh-journal.js';
|
|
63
63
|
export * from './host/flow/expr.js';
|
|
64
|
+
export * from './host/flow/journal.js';
|
|
64
65
|
export * from './host/flow/kit.js';
|
|
65
66
|
export * from './host/flow/login-retry.js';
|
|
66
67
|
export * from './host/flow/open.js';
|
|
@@ -75,12 +76,27 @@ export * from './host/git/auth-loss.js';
|
|
|
75
76
|
export * from './host/git/git.js';
|
|
76
77
|
export * from './host/patch/patch-blocks.js';
|
|
77
78
|
export * from './host/patch/patch.js';
|
|
79
|
+
export * from './host/platform/facts.js';
|
|
80
|
+
export * from './host/platform/integration/bridge.js';
|
|
81
|
+
export * from './host/platform/integration/browser-launch.js';
|
|
82
|
+
export * from './host/platform/integration/browser-process.js';
|
|
83
|
+
export * from './host/platform/integration/browser-read.js';
|
|
84
|
+
export * from './host/platform/integration/browsers.js';
|
|
85
|
+
export * from './host/platform/integration/data.js';
|
|
86
|
+
export * from './host/platform/integration/env-policy.js';
|
|
87
|
+
export * from './host/platform/integration/front-app.js';
|
|
88
|
+
export * from './host/platform/integration/host-surface.js';
|
|
89
|
+
export * from './host/platform/integration/process.js';
|
|
90
|
+
export * from './host/platform/integration/tool-lookup.js';
|
|
91
|
+
export * from './host/platform/ops/shell-render.js';
|
|
92
|
+
export * from './host/platform/ops/shell-text.js';
|
|
93
|
+
export * from './host/platform/ops/shell.js';
|
|
94
|
+
export * from './host/profile/build-approval.js';
|
|
78
95
|
export * from './host/profile/bundle-manager.js';
|
|
79
96
|
export * from './host/profile/config-sync.js';
|
|
80
97
|
export * from './host/profile/dsh-plugins.js';
|
|
81
|
-
export * from './host/profile/build-approval.js';
|
|
82
|
-
export * from './host/profile/module-rows.js';
|
|
83
98
|
export * from './host/profile/hmr-reload.js';
|
|
99
|
+
export * from './host/profile/module-rows.js';
|
|
84
100
|
export * from './host/profile/pnpm-command.js';
|
|
85
101
|
export * from './host/profile/profile-bundles.js';
|
|
86
102
|
export * from './host/profile/profile-create.js';
|
|
@@ -90,20 +106,12 @@ export * from './host/runtime/boot-record.js';
|
|
|
90
106
|
export * from './host/runtime/changelog.js';
|
|
91
107
|
export * from './host/runtime/cli-error.js';
|
|
92
108
|
export * from './host/runtime/cli.js';
|
|
93
|
-
export * from './host/runtime/
|
|
94
|
-
export * from './host/platform/integration/env-policy.js';
|
|
95
|
-
export * from './host/platform/integration/browser-read.js';
|
|
96
|
-
export * from './host/platform/integration/data.js';
|
|
97
|
-
export * from './host/platform/integration/front-app.js';
|
|
98
|
-
export * from './host/platform/integration/tool-lookup.js';
|
|
99
|
-
export * from './host/platform/integration/browsers.js';
|
|
100
|
-
export * from './host/platform/integration/bridge.js';
|
|
101
|
-
export * from './host/platform/integration/browser-process.js';
|
|
102
|
-
export * from './host/platform/integration/browser-launch.js';
|
|
109
|
+
export * from './host/runtime/diag-bundle.js';
|
|
103
110
|
export * from './host/runtime/diag-records.js';
|
|
104
111
|
export * from './host/runtime/diag-sink.js';
|
|
105
|
-
export * from './host/runtime/diag-bundle.js';
|
|
106
112
|
export * from './host/runtime/diag-summary.js';
|
|
113
|
+
export * from './host/runtime/dsh-compat.js';
|
|
114
|
+
export * from './host/runtime/env-policy.js';
|
|
107
115
|
export * from './host/runtime/fs-write.js';
|
|
108
116
|
export * from './host/runtime/http.js';
|
|
109
117
|
export * from './host/runtime/lease.js';
|
|
@@ -111,8 +119,8 @@ export * from './host/runtime/paths.js';
|
|
|
111
119
|
export * from './host/runtime/process-alive.js';
|
|
112
120
|
export * from './host/runtime/read-json.js';
|
|
113
121
|
export * from './host/runtime/time.js';
|
|
114
|
-
export * from './host/runtime/version-range.js';
|
|
115
122
|
export * from './host/runtime/verified-dsh.js';
|
|
123
|
+
export * from './host/runtime/version-range.js';
|
|
116
124
|
export * from './host/runtime/version.js';
|
|
117
125
|
export * from './host/runtime/workspace-store.js';
|
|
118
126
|
export * from './host/runtime/write-result.js';
|
|
@@ -127,17 +135,17 @@ export * from './host/seam/process.js';
|
|
|
127
135
|
export * from './host/seam/run.js';
|
|
128
136
|
export * from './host/seam/service.js';
|
|
129
137
|
export * from './host/seam/unit-seam.js';
|
|
130
|
-
export * from './host/
|
|
131
|
-
export * from './host/
|
|
138
|
+
export * from './host/shell/shell-render.js';
|
|
139
|
+
export * from './host/shell/shell-text.js';
|
|
132
140
|
export * from './host/shell/shell.js';
|
|
133
141
|
export * from './host/shell/tokens.js';
|
|
142
|
+
export * from './host/supply/builtin-catalog.js';
|
|
134
143
|
export * from './host/supply/install-failure.js';
|
|
135
144
|
export * from './host/supply/installed-module.js';
|
|
136
145
|
export * from './host/supply/installed-sources.js';
|
|
137
146
|
export * from './host/supply/lib-capabilities.js';
|
|
138
147
|
export * from './host/supply/lib-install.js';
|
|
139
148
|
export * from './host/supply/lib-runners.js';
|
|
140
|
-
export * from './host/supply/builtin-catalog.js';
|
|
141
149
|
export * from './host/supply/market-index-claim.js';
|
|
142
150
|
export * from './host/supply/market-index-doc.js';
|
|
143
151
|
export * from './host/supply/market-index-parse.js';
|
|
@@ -172,6 +180,8 @@ export * from './host/unit/facts.js';
|
|
|
172
180
|
export * from './host/unit/host-actions.js';
|
|
173
181
|
export * from './host/unit/host-kit.js';
|
|
174
182
|
export * from './host/unit/local-declaration.js';
|
|
183
|
+
export * from './host/unit/long-task-host.js';
|
|
184
|
+
export * from './host/unit/long-task-progress.js';
|
|
175
185
|
export * from './host/unit/long-task.js';
|
|
176
186
|
export * from './host/unit/needs.js';
|
|
177
187
|
export * from './host/unit/panel-state.js';
|
|
@@ -182,3 +192,4 @@ export * from './host/unit/unit-data.js';
|
|
|
182
192
|
export * from './host/unit/unit-face.js';
|
|
183
193
|
export * from './host/unit/unit-plugin.js';
|
|
184
194
|
export * from './host/unit/value-handoff.js';
|
|
195
|
+
export * from './host/unit/with-intervention-retry.js';
|