@online-tools/work-agent-runner 0.0.5-alpha-1 → 0.1.0-alpha-2

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/lib/service.mjs CHANGED
@@ -78,21 +78,30 @@ function systemdExecWord(value) {
78
78
  return systemdWord(value).replace(/\$/g, '$$$$');
79
79
  }
80
80
 
81
+ /**
82
+ * The systemd user unit (design 10.6). No network-online.target: it does
83
+ * nothing for user services; the program retries its connection itself.
84
+ * KillMode=mixed: stop sends SIGTERM to the program alone, which ends its
85
+ * jobs and reports their exits (claude runs in process groups of its own)
86
+ * before TimeoutStopSec kills what is left. Reload is SIGHUP: config.json's
87
+ * maintenance times, limits and isolation apply at once.
88
+ */
81
89
  export function systemdUnit({ nodePath, entry, args = ['start'], environment }) {
82
90
  const lines = [
83
91
  '[Unit]',
84
92
  'Description=work-agent-runner(GitCode 在线工具执行机器)',
85
- 'After=network-online.target',
86
- 'Wants=network-online.target',
87
93
  'StartLimitIntervalSec=300',
88
94
  'StartLimitBurst=10',
89
95
  '',
90
96
  '[Service]',
91
97
  'Type=simple',
92
98
  `ExecStart=${[nodePath, entry, ...args].map(systemdExecWord).join(' ')}`,
99
+ 'ExecReload=/bin/kill -HUP $MAINPID',
93
100
  'Restart=on-failure',
94
101
  'RestartSec=5',
95
102
  `RestartPreventExitStatus=${EXIT_NEEDS_ATTENTION}`,
103
+ 'KillMode=mixed',
104
+ 'TimeoutStopSec=90',
96
105
  ...Object.entries(environment).map(([name, value]) => `Environment=${systemdWord(`${name}=${value}`)}`),
97
106
  '',
98
107
  '[Install]',
@@ -132,6 +141,10 @@ ${variables}
132
141
  <key>SuccessfulExit</key>
133
142
  <false/>
134
143
  </dict>
144
+ <key>ProcessType</key>
145
+ <string>Background</string>
146
+ <key>ExitTimeOut</key>
147
+ <integer>90</integer>
135
148
  <key>StandardOutPath</key>
136
149
  <string>${xml(logFile)}</string>
137
150
  <key>StandardErrorPath</key>
@@ -178,7 +191,12 @@ function logHintFor(paths) {
178
191
  }
179
192
 
180
193
  /** Writes the definition (0600), loads it and (re)starts the service. */
181
- export function installService({ platform = process.platform, nodePath, entry, args, env = process.env, say }) {
194
+ /**
195
+ * Writes the definition (0600), loads it and (re)starts the service.
196
+ * `start: false`: written and enabled only — the first run starts it once
197
+ * its own process has let go of the instance lock (controlService('start')).
198
+ */
199
+ export function installService({ platform = process.platform, nodePath, entry, args, env = process.env, say, start = true }) {
182
200
  const paths = servicePaths({ platform, env });
183
201
  const environment = serviceEnvironment(env, paths.kind);
184
202
  say('服务将使用以下环境变量(来自当前终端):');
@@ -190,6 +208,10 @@ export function installService({ platform = process.platform, nodePath, entry, a
190
208
  fs.chmodSync(paths.file, 0o600);
191
209
  const domain = `gui/${process.getuid()}`;
192
210
  run('launchctl', ['bootout', `${domain}/${paths.name}`], { quiet: true }); // an older definition, if loaded
211
+ if (!start) {
212
+ say(`已安装后台服务(launchd,${paths.name}),稍后启动`);
213
+ return paths;
214
+ }
193
215
  const loaded = run('launchctl', ['bootstrap', domain, paths.file]);
194
216
  if (!loaded.ok) throw new Error('launchctl bootstrap 失败');
195
217
  say(`已安装并启动后台服务(launchd,${paths.name})。${logHintFor(paths)}`);
@@ -197,12 +219,13 @@ export function installService({ platform = process.platform, nodePath, entry, a
197
219
  }
198
220
  fs.writeFileSync(paths.file, systemdUnit({ nodePath, entry, args, environment }), { mode: 0o600 });
199
221
  fs.chmodSync(paths.file, 0o600);
200
- for (const command of [['daemon-reload'], ['enable', paths.name], ['restart', paths.name]]) {
222
+ const commands = [['daemon-reload'], ['enable', paths.name], ...(start ? [['restart', paths.name]] : [])];
223
+ for (const command of commands) {
201
224
  const result = run('systemctl', ['--user', ...command]);
202
225
  if (!result.ok) throw new Error(`systemctl --user ${command.join(' ')} 失败`);
203
226
  }
204
- say(`已安装并启动后台服务(systemd 用户服务 ${paths.name})。`);
205
- say('退出登录后服务会停止;要让它一直运行,请让管理员执行一次:loginctl enable-linger $USER');
227
+ say(start ? `已安装并启动后台服务(systemd 用户服务 ${paths.name})。` : `已安装后台服务(systemd 用户服务 ${paths.name}),稍后启动`);
228
+ if (lingerEnabled({ platform }) === false) say('退出登录后服务会停止;要让它一直运行,请让管理员执行一次:loginctl enable-linger $USER');
206
229
  say(`查看日志:journalctl --user -u ${paths.name} -f`);
207
230
  return paths;
208
231
  }
@@ -270,6 +293,19 @@ export function uninstallService({ platform = process.platform, env = process.en
270
293
  else if (!legacy) say('没有安装后台服务');
271
294
  }
272
295
 
296
+ /**
297
+ * Whether systemd keeps this user's services running after they log out
298
+ * (`loginctl enable-linger`): true / false, null when it cannot tell (macOS,
299
+ * no loginctl). A user service without it stops at logout.
300
+ */
301
+ export function lingerEnabled({ platform = process.platform, user = os.userInfo().username } = {}) {
302
+ if (platform !== 'linux') return null;
303
+ const result = run('loginctl', ['show-user', user, '-p', 'Linger', '--value'], { quiet: true });
304
+ if (!result.ok) return null;
305
+ const value = result.stdout.trim();
306
+ return value === 'yes' ? true : value === 'no' ? false : null;
307
+ }
308
+
273
309
  /** { installed, state, logHint, name } */
274
310
  export function serviceStatus({ platform = process.platform, env = process.env } = {}) {
275
311
  const paths = servicePaths({ platform, env });
@@ -0,0 +1,119 @@
1
+ // `setup` as resumable steps (docs/remediation-and-install-plan.md 4.3, design
2
+ // 10.2): what each step came to, kept in state/setup.json, so a second run
3
+ // skips what is done or was declined and starts again where something failed;
4
+ // and the setup log (logs/setup-<time>.log, every line redacted).
5
+ //
6
+ // Only node: built-ins and files in this directory.
7
+
8
+ import fs from 'node:fs';
9
+ import path from 'node:path';
10
+
11
+ import { readJsonFile, writeJsonAtomic } from './fs-safe.mjs';
12
+ import { redact } from './log.mjs';
13
+ import { displayWidth } from './views.mjs';
14
+
15
+ export const SETUP_SCHEMA = 1;
16
+ export const SETUP_STEPS = [
17
+ ['precheck', '预检'],
18
+ ['token', '接入令牌与机器名称'],
19
+ ['deps', '系统依赖'],
20
+ ['claude', 'Claude Code'],
21
+ ['prereq', '沙箱前提'],
22
+ ['repo', 'work-agent 仓库'],
23
+ ['sandbox', '沙箱实测'],
24
+ ['pool', '知识仓(可选)'],
25
+ ['service', '后台服务(可选)'],
26
+ ];
27
+ const STATUSES = new Set(['pending', 'done', 'skipped', 'failed']);
28
+ const LOGS_KEPT = 10;
29
+
30
+ /** state/setup.json: { schema, version, updatedAt, steps: { [id]: { status, at, detail, error } } }. */
31
+ export class SetupState {
32
+ constructor(file, { version = '', now = () => Date.now() } = {}) {
33
+ this.file = file;
34
+ this.version = version;
35
+ this.now = now;
36
+ const saved = readJsonFile(file);
37
+ this.steps = {};
38
+ if (saved?.schema === SETUP_SCHEMA && saved.steps && typeof saved.steps === 'object') {
39
+ for (const [id] of SETUP_STEPS) {
40
+ const step = saved.steps[id];
41
+ if (step && STATUSES.has(step.status)) this.steps[id] = { status: step.status, at: String(step.at || ''), detail: String(step.detail || ''), error: step.error || null };
42
+ }
43
+ }
44
+ }
45
+
46
+ status(id) {
47
+ return this.steps[id]?.status || 'pending';
48
+ }
49
+
50
+ /** Records a step's outcome at once (a Ctrl+C later keeps what was done). */
51
+ set(id, status, { detail = '', error = null } = {}) {
52
+ this.steps[id] = { status, at: new Date(this.now()).toISOString(), detail: String(detail || ''), error };
53
+ this.save();
54
+ }
55
+
56
+ reset() {
57
+ this.steps = {};
58
+ this.save();
59
+ }
60
+
61
+ /** Every step done or declined: the first run is over. */
62
+ complete() {
63
+ return SETUP_STEPS.every(([id]) => ['done', 'skipped'].includes(this.status(id)));
64
+ }
65
+
66
+ save() {
67
+ try {
68
+ fs.mkdirSync(path.dirname(this.file), { recursive: true, mode: 0o700 });
69
+ writeJsonAtomic(this.file, { schema: SETUP_SCHEMA, version: this.version, updatedAt: new Date(this.now()).toISOString(), steps: this.steps });
70
+ } catch {
71
+ // A record only: never a reason to stop the setup.
72
+ }
73
+ }
74
+
75
+ toJSON() {
76
+ return Object.fromEntries(SETUP_STEPS.map(([id]) => [id, this.steps[id] || { status: 'pending' }]));
77
+ }
78
+ }
79
+
80
+ /** "[3/9] 系统依赖 .............. ✓ 完成(41 秒)": the step's title dotted out to a fixed column. */
81
+ export function stepLine(index, title, result = '') {
82
+ const head = `[${index + 1}/${SETUP_STEPS.length}] ${title} `;
83
+ const dots = '.'.repeat(Math.max(3, 34 - displayWidth(head)));
84
+ return `${head}${dots} ${result}`.trimEnd();
85
+ }
86
+
87
+ /**
88
+ * A new setup log, logs/setup-<yyyymmdd-hhmmss>.log (0600); the oldest beyond
89
+ * the last ten are deleted. Returns { file, write(line) } — every line is
90
+ * redacted (a token pasted at a prompt never reaches it).
91
+ */
92
+ export function openSetupLog(logsDir, { now = new Date() } = {}) {
93
+ const pad = (value) => String(value).padStart(2, '0');
94
+ const stamp = `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`;
95
+ let file = '';
96
+ try {
97
+ fs.mkdirSync(logsDir, { recursive: true, mode: 0o700 });
98
+ file = path.join(logsDir, `setup-${stamp}.log`);
99
+ fs.writeFileSync(file, '', { mode: 0o600, flag: 'a' });
100
+ const logs = fs
101
+ .readdirSync(logsDir)
102
+ .filter((name) => /^setup-\d{8}-\d{6}\.log$/.test(name))
103
+ .sort();
104
+ for (const name of logs.slice(0, Math.max(0, logs.length - LOGS_KEPT))) fs.rmSync(path.join(logsDir, name), { force: true });
105
+ } catch {
106
+ file = '';
107
+ }
108
+ return {
109
+ file,
110
+ write(line) {
111
+ if (!file) return;
112
+ try {
113
+ fs.appendFileSync(file, `${redact(line)}\n`);
114
+ } catch {
115
+ // The log must never stop the setup.
116
+ }
117
+ },
118
+ };
119
+ }
package/lib/setup.mjs CHANGED
@@ -42,6 +42,8 @@ export function npmPrefixWritable(prefix) {
42
42
  * manager 'apt' | … | 'brew' | ''
43
43
  * isRoot, sudo absolute path of sudo or ''
44
44
  * npm, npmWritable absolute path of npm, and whether its global dir is writable
45
+ * managedClaude claude is installed by this program (lib/claude-install.mjs),
46
+ * not with npm: it is left out of this plan
45
47
  * Returns { commands: [[file, ...args]], manual: [[...]], missing: [names], ignored: [names], notes: [text] }.
46
48
  */
47
49
  export function planSetup({
@@ -56,6 +58,7 @@ export function planSetup({
56
58
  sudo = '',
57
59
  npm = '',
58
60
  npmWritable = false,
61
+ managedClaude = false,
59
62
  }) {
60
63
  const ignored = requiredTools.filter((name) => !SKILL_TOOLS.includes(name));
61
64
  const wanted = SKILL_TOOLS.filter((name) => requiredTools.includes(name) || extraTools.includes(name));
@@ -92,7 +95,7 @@ export function planSetup({
92
95
  }
93
96
  }
94
97
 
95
- const needsClaude = !claudeVersion || (minClaudeVersion && compareVersions(claudeVersion, minClaudeVersion) < 0);
98
+ const needsClaude = !managedClaude && (!claudeVersion || (minClaudeVersion && compareVersions(claudeVersion, minClaudeVersion) < 0));
96
99
  if (needsClaude) {
97
100
  if (!npm) {
98
101
  notes.push('没有找到 npm,无法安装 claude');
package/lib/state.mjs ADDED
@@ -0,0 +1,145 @@
1
+ // What the running instance knows about itself, kept where a terminal can
2
+ // read it even when the instance does not answer (docs/design.md 9.1, 9.2):
3
+ //
4
+ // state/status.json a snapshot: instance, connection, jobs and their
5
+ // phases, maintenance, resources — rewritten (atomically)
6
+ // at most every 2 s while something changes
7
+ // state/history.jsonl one line per finished job: run id, feature, phase
8
+ // times, result, exit, error code — the last 1000
9
+ // jobs or 30 days
10
+ //
11
+ // Neither ever holds a task's text, a model, an API key, GITCODE_CRED or an
12
+ // answer of 交互执行; the website's 操作记录 has who ran what.
13
+ //
14
+ // Only node: built-ins and files in this directory.
15
+
16
+ import fs from 'node:fs';
17
+ import path from 'node:path';
18
+
19
+ import { readJsonFile, writeJsonAtomic } from './fs-safe.mjs';
20
+
21
+ export const STATUS_SCHEMA = 1;
22
+ export const HISTORY_MAX = 1000;
23
+ export const HISTORY_DAYS = 30;
24
+ const WRITE_DELAY_MS = 2000;
25
+ const TRIM_EVERY = 50;
26
+
27
+ export class StateStore {
28
+ constructor({ statusFile, historyFile, writeDelayMs = WRITE_DELAY_MS, now = () => Date.now() }) {
29
+ this.statusFile = statusFile;
30
+ this.historyFile = historyFile;
31
+ this.writeDelayMs = writeDelayMs;
32
+ this.now = now;
33
+ this.status = { schema: STATUS_SCHEMA };
34
+ this.timer = null;
35
+ this.appends = 0;
36
+ }
37
+
38
+ /** Merges `patch` into the snapshot; written within writeDelayMs. */
39
+ set(patch) {
40
+ Object.assign(this.status, patch);
41
+ if (this.timer) return;
42
+ this.timer = setTimeout(() => {
43
+ this.timer = null;
44
+ this.flush();
45
+ }, this.writeDelayMs);
46
+ this.timer.unref?.();
47
+ }
48
+
49
+ /** The snapshot as written, with its time. */
50
+ snapshot() {
51
+ return { ...this.status, updatedAt: new Date(this.now()).toISOString() };
52
+ }
53
+
54
+ flush() {
55
+ clearTimeout(this.timer);
56
+ this.timer = null;
57
+ try {
58
+ fs.mkdirSync(path.dirname(this.statusFile), { recursive: true, mode: 0o700 });
59
+ writeJsonAtomic(this.statusFile, this.snapshot());
60
+ } catch {
61
+ // Status is for display: never a reason to stop.
62
+ }
63
+ }
64
+
65
+ /** One finished job. Trimmed to the last HISTORY_MAX within HISTORY_DAYS now and then. */
66
+ appendHistory(record) {
67
+ try {
68
+ fs.mkdirSync(path.dirname(this.historyFile), { recursive: true, mode: 0o700 });
69
+ fs.appendFileSync(this.historyFile, `${JSON.stringify(record)}\n`, { mode: 0o600 });
70
+ this.appends += 1;
71
+ if (this.appends % TRIM_EVERY === 0) this.trimHistory();
72
+ } catch {
73
+ // Same as above.
74
+ }
75
+ }
76
+
77
+ trimHistory() {
78
+ try {
79
+ const cutoff = this.now() - HISTORY_DAYS * 86_400_000;
80
+ const kept = readLines(this.historyFile)
81
+ .filter((record) => Date.parse(record?.at?.done || '') >= cutoff)
82
+ .slice(-HISTORY_MAX);
83
+ const temp = `${this.historyFile}.${process.pid}.tmp`;
84
+ fs.writeFileSync(temp, kept.map((record) => `${JSON.stringify(record)}\n`).join(''), { mode: 0o600 });
85
+ fs.renameSync(temp, this.historyFile);
86
+ } catch {
87
+ // Next time.
88
+ }
89
+ }
90
+ }
91
+
92
+ function readLines(file) {
93
+ let text = '';
94
+ try {
95
+ text = fs.readFileSync(file, 'utf8');
96
+ } catch {
97
+ return [];
98
+ }
99
+ const records = [];
100
+ for (const line of text.split('\n')) {
101
+ if (!line.trim()) continue;
102
+ try {
103
+ const record = JSON.parse(line);
104
+ if (record && typeof record === 'object' && typeof record.runId === 'string') records.push(record);
105
+ } catch {
106
+ // A line cut by a crash: skipped.
107
+ }
108
+ }
109
+ return records;
110
+ }
111
+
112
+ /** The last snapshot an instance wrote, or null. */
113
+ export function readStatus(statusFile) {
114
+ return readJsonFile(statusFile);
115
+ }
116
+
117
+ /** Whether `wanted` names the run `runId`: the whole id, or any part of it of at least 6 characters. */
118
+ export function matchesRunId(runId, wanted) {
119
+ const id = String(runId || '');
120
+ const part = String(wanted || '');
121
+ return Boolean(part) && (id === part || (part.length >= 6 && id.includes(part)));
122
+ }
123
+
124
+ /**
125
+ * Finished jobs, newest first: `since` (ms) by finish time, `failedOnly`
126
+ * (anything but ok), `runId` (see matchesRunId()), at most `limit`.
127
+ */
128
+ export function readHistory(historyFile, { since = 0, limit = 20, failedOnly = false, runId = '' } = {}) {
129
+ return readLines(historyFile)
130
+ .filter((record) => !since || Date.parse(record?.at?.done || '') >= since)
131
+ .filter((record) => !failedOnly || record.result !== 'ok')
132
+ .filter((record) => !runId || matchesRunId(record.runId, runId))
133
+ .reverse()
134
+ .slice(0, limit);
135
+ }
136
+
137
+ /** { ok, failed, cancelled, timeout } over the records given (e.g. the last 24 hours). */
138
+ export function countResults(records) {
139
+ const counts = { ok: 0, failed: 0, cancelled: 0, timeout: 0 };
140
+ for (const record of records) {
141
+ if (record.result in counts) counts[record.result] += 1;
142
+ else if (record.result !== 'not_accepted') counts.failed += 1;
143
+ }
144
+ return counts;
145
+ }
@@ -0,0 +1,122 @@
1
+ // `work-agent-runner uninstall` (design 3.21): what goes and what stays.
2
+ // Only what is this program's own goes — the work root's runs/ archive/
3
+ // trash/ and marker (the directory itself only when the program made it and
4
+ // it is empty), a marked clone, the program home (all of it with --purge,
5
+ // else all but config.json); work-agent's home and the knowledge pool are
6
+ // the user's and stay, with where they are and how big.
7
+ //
8
+ // Only node: built-ins and files in this directory.
9
+
10
+ import fs from 'node:fs';
11
+ import path from 'node:path';
12
+
13
+ import { WORK_ROOT_MARKER, isInside } from './config.mjs';
14
+ import { readJsonFile, removeTree } from './fs-safe.mjs';
15
+ import { CLONE_MARKER } from './work-agent.mjs';
16
+
17
+ function exists(target) {
18
+ try {
19
+ fs.lstatSync(target);
20
+ return true;
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
25
+
26
+ /** Bytes under `dir` (regular files, symlinks not followed); 0 when it is not there. */
27
+ export function treeSize(dir) {
28
+ let total = 0;
29
+ const walk = (target) => {
30
+ let stat;
31
+ try {
32
+ stat = fs.lstatSync(target);
33
+ } catch {
34
+ return;
35
+ }
36
+ if (stat.isFile()) total += stat.size;
37
+ else if (stat.isDirectory()) {
38
+ let names = [];
39
+ try {
40
+ names = fs.readdirSync(target);
41
+ } catch {
42
+ return;
43
+ }
44
+ for (const name of names) walk(path.join(target, name));
45
+ }
46
+ };
47
+ walk(dir);
48
+ return total;
49
+ }
50
+
51
+ /**
52
+ * { remove: [{ path, what }], removeIfEmpty: [{ path, what }], keep: [{ path, what }] }.
53
+ * `paths` (configPaths + withRepoPaths), `workRoot` (the one in use), `purge`.
54
+ */
55
+ export function uninstallPlan({ paths, workRoot, purge = false }) {
56
+ const remove = [];
57
+ const removeIfEmpty = [];
58
+ const keep = [];
59
+ const home = path.resolve(paths.baseDir);
60
+ const root = path.resolve(workRoot || home);
61
+ if (root !== home && !isInside(root, home)) {
62
+ for (const name of ['runs', 'archive', 'trash', WORK_ROOT_MARKER]) {
63
+ const target = path.join(root, name);
64
+ if (exists(target)) remove.push({ path: target, what: name === WORK_ROOT_MARKER ? '工作目录的标记' : `任务目录 ${name}/` });
65
+ }
66
+ const marker = readJsonFile(path.join(root, WORK_ROOT_MARKER));
67
+ if (marker?.createdByProgram === true) removeIfEmpty.push({ path: root, what: '工作目录(程序建的,空了就删除)' });
68
+ else keep.push({ path: root, what: '工作目录(原来就有,只删除了程序放进去的东西)' });
69
+ }
70
+ const clone = path.resolve(paths.repoDir);
71
+ if (!isInside(clone, home) && exists(clone)) {
72
+ if (exists(path.join(clone, '.git', CLONE_MARKER))) remove.push({ path: clone, what: 'work-agent 仓库的克隆' });
73
+ else keep.push({ path: clone, what: 'work-agent 仓库(不是本程序创建的,不动)' });
74
+ }
75
+ if (purge) remove.push({ path: home, what: '程序目录(全部,含 config.json)' });
76
+ else {
77
+ let names = [];
78
+ try {
79
+ names = fs.readdirSync(home);
80
+ } catch {
81
+ names = [];
82
+ }
83
+ for (const name of names) {
84
+ if (name === 'config.json') continue;
85
+ remove.push({ path: path.join(home, name), what: `程序目录里的 ${name}` });
86
+ }
87
+ if (exists(paths.configFile)) keep.push({ path: paths.configFile, what: '配置(接入令牌和机器标识;重装后沿用同一台机器,不想要了就删除它)' });
88
+ }
89
+ for (const [target, what] of [
90
+ [paths.workAgentHome, 'work-agent 的家(你手工使用 work-agent 时也用它)'],
91
+ [paths.poolDir, '知识仓'],
92
+ ]) {
93
+ if (exists(target) && !isInside(path.resolve(target), home)) keep.push({ path: target, what, size: treeSize(target) });
94
+ }
95
+ return { remove, removeIfEmpty, keep };
96
+ }
97
+
98
+ /** Deletes what the plan says (removeTree: no symlink is followed); { removed, failed }. */
99
+ export function performUninstall(plan) {
100
+ const removed = [];
101
+ const failed = [];
102
+ for (const item of plan.remove) {
103
+ const outcome = removeTree(item.path);
104
+ (outcome.removed ? removed : failed).push(item);
105
+ }
106
+ for (const item of plan.removeIfEmpty) {
107
+ let names = null;
108
+ try {
109
+ names = fs.readdirSync(item.path);
110
+ } catch {
111
+ continue;
112
+ }
113
+ if (names.length) continue;
114
+ try {
115
+ fs.rmdirSync(item.path);
116
+ removed.push(item);
117
+ } catch {
118
+ failed.push(item);
119
+ }
120
+ }
121
+ return { removed, failed };
122
+ }