@whyshu/argent-engine 0.13.29 → 0.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/MANIFEST.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "schema": 1,
3
3
  "package": "@whyshu/argent-engine",
4
4
  "files": {
5
- "VERSION": "34dc0bd74802a6ef030986290da79cb546a75d005c95a4bec1c23c02d9bdf29e",
5
+ "VERSION": "c6fb87657a4ee72e2b549cdd39c12854fdbecbdfef033c04f523d4bfcb02aa4c",
6
6
  "agents/catalog.json": "5356a812f2554dfd3115370363d4c3f787a82c9e5928a85d05b2a07c9e4b324d",
7
7
  "configs/_aliases.proposed.json": "3a59edf80563bcc20d410d488decad6fd787bd3de9489321367b0783904cd3e5",
8
8
  "configs/_migration-plan.proposed.json": "dd9f90b0b9b2f217dd23367a618402e57997d44f7fddcfa88a7cadf52e056c0d",
@@ -14,7 +14,7 @@
14
14
  "configs/mcp-tools.snapshot.json": "cfa94a6ba64a7ae9d133a4a878ce3d5e0e85e554ccd3e3ebaf0d51ad750acf6a",
15
15
  "configs/notify.json": "cb9ef11c1c498fcf99af99ec50271b8a2598061b77ed73a6099032e837474ef0",
16
16
  "core/cli/argent.mjs": "9a8977324c238ca4e20435f9817eb7ec76157da32b1d510977dc03e0feb416a9",
17
- "core/contracts/argent.contracts.json": "983deb0371aa44307ec360412c6a3f622d73c997a719ff99f7a34c8b957ff069",
17
+ "core/contracts/argent.contracts.json": "271b32e1b880e85b5e0cbf43b7ff473fa1cc593dc01b18436f08186643805e54",
18
18
  "core/contracts/verbs.schema.json": "54d726181c11536eb30bd25090584a7af103e4c0462f8ef078053c8177e19dcb",
19
19
  "core/lib/account-token.mjs": "35faad2c34e67755c1867f74a74885f0f268d5daabe01d339cf30dc747f86501",
20
20
  "core/lib/argent-datadir.mjs": "1fdd799c933382c4f9e36bd4af33d51b8ac4a466a9d67a8f2296bb267b5251ac",
@@ -161,7 +161,7 @@
161
161
  "scripts/final-check.mjs": "45e2004e778c83fe08b35921a555b2ca57ddb375672cc965544ef1bb6ff10aa8",
162
162
  "scripts/fix-skill-frontmatter.py": "c77cb8d389bd96bc40655bbdd712435bfb06f74453a2f54dad58013f615ea748",
163
163
  "scripts/flow-auto-retry.py": "2474e649e2e7c2803c3140b5c0780648059d3aadae299ea77a706a552b1fab63",
164
- "scripts/flow-requirements.json": "bc48886dd33ec10cd4daa8a35487bd3febb26db6ee73c0c9f89ed23cf4ab4d58",
164
+ "scripts/flow-requirements.json": "c4af2dbd9cb09575f804d1272aef10d01babc558813eacdd242b1d49328cb48b",
165
165
  "scripts/flow-scaffold.py": "d886e4e5d5cf0e80991d1d1a40e54a7281d87fec7c781c89101277795e401ae1",
166
166
  "scripts/flow-session-retention.mjs": "a9a2d261dce959bcd0eb26361413b9fc10fd1cbd562f86c614face66861c9793",
167
167
  "scripts/flow-timers-plist.sh": "a7b1007526fe21923566a002ef4e50fade5cbcdef38799f1a52e50c7b9c21131",
@@ -193,7 +193,7 @@
193
193
  "scripts/flow_write_verify.py": "a9123838b00cb60b43fbc761f6dae740dfa3692906c2985e9b98a7c4538c2491",
194
194
  "scripts/fulfillment.js": "8de1ea386ebfe628caf4eaf2df5f1941938c07d4b8b2dcf79a78d45ac231669f",
195
195
  "scripts/fulfillment_sites.py": "7120ddcd891b1de588b4c80420af9b7291bfd2e582a7bb41cf9fcd91a0699fe7",
196
- "scripts/full-exec-worker.mjs": "99dfe3f84e53f0958b172f0bb28431150384fb141035539adf82310dd698e287",
196
+ "scripts/full-exec-worker.mjs": "ddc10b18ee29ff85b782a1145ef0e94e32af3397c16d7e4697ac3925796bf805",
197
197
  "scripts/gen-agent-bundles.mjs": "3ab452fb7b1026a1bfab02977c85229985b390db4bc8458ce974b94bc207ed17",
198
198
  "scripts/gen-preset-rows.mjs": "1c074432be25148e9babce7ea1cb68d8fcef257abc2329f66b4ce488bc504578",
199
199
  "scripts/handover-sheet.mjs": "4e27095ccdd79586391abf7a7d5eb7aabbc3f0d7d9a1dd5161e9af8e8a9338de",
@@ -297,7 +297,7 @@
297
297
  "scripts/ops-codefix-queue.mjs": "bf377ee88f0b5c0493067fe38fd7355bc081285dfd3b06f8a48c2efaa297f705",
298
298
  "scripts/ops-digest.mjs": "7fcb827d2ad258a9014c677d35be3222e7985894d483e6d18b8b089ac7f80e0d",
299
299
  "scripts/ops-verify.mjs": "cfe80ad4693c0ebc8c1782f7f09934529b98cd8edbdd9c980028754e370370f1",
300
- "scripts/orchestrator.py": "ce54b7a9d1f5de08aacf3b120e786dfc89eb619f0be7b207302a02fc983273df",
300
+ "scripts/orchestrator.py": "6faa9ff8b22645b003a1ebbb9a9ab29efec3f8deed84965f6ee582308a834b0d",
301
301
  "scripts/orchestrator_br.py": "103544e887add1f8d2bc7bfd0168fc8a0f2cd8a0547874e064a2465fd5626459",
302
302
  "scripts/p2-report-run.mjs": "86bd6b3005f1a5fca3f808f4ea77dcce43a11a4a9be7ee814a029daaae201fb5",
303
303
  "scripts/pack-plugins.mjs": "b1b42fb30ebd27f320af72bc28b5b8e2b76e54031b4ac1ba5c3909374990b38b",
@@ -427,7 +427,7 @@
427
427
  "verticals/mercadolibre/brazil-full-sop.json": "722630b859d7a1c42ab3a243cae75598bf92a562663d9ebe376afd093f02bbfb",
428
428
  "verticals/mercadolibre/config.json": "85e592d700383b9b191ed6a809dc47fffba8e6850842c3699058a679ef6546a7",
429
429
  "verticals/mercadolibre/flows.json": "69c11df91a53f15149b168989be14cba1ec66f1bc30fb71cf5fda16c914a0886",
430
- "verticals/mercadolibre/manifest.json": "dce158c74d3924b94ff0f034fbf8957b724d4052a3d126ac4d0113aebe33aaf4",
430
+ "verticals/mercadolibre/manifest.json": "09d7f0503ebd33e9d8e866b5998951ac472342b49dd45d30762ae691e901fad4",
431
431
  "verticals/mercadolibre/migrate-machine-state.mjs": "a5a55f3c6b5057365621b4d976f5f16792532bd392d9379bf06b596a3e178f77",
432
432
  "verticals/mercadolibre/preflight.py": "24a490c19bad174f3eddb86d651ff767e55979270b780b6e43b8f0f8cb01acc2",
433
433
  "verticals/mercadolibre/prompts/daily-report.failure.md": "528b322931ed459516e6909c5eeff1dbbc89f3a38bd5ec68628ada85160cf0a8",
package/engine/VERSION CHANGED
@@ -1 +1 @@
1
- 0.13.29
1
+ 0.14.1
@@ -1,6 +1,6 @@
1
1
  {
2
- "argentVersion": "0.13.29",
3
- "_syncNote": "argentVersion 必须与仓库根 VERSION 同批更新:发布前置校验 scripts/check-version-consistency.mjs;2026-11-24 按 VERSION=0.13.29 校正。",
2
+ "argentVersion": "0.14.1",
3
+ "_syncNote": "argentVersion 必须与仓库根 VERSION 同批更新:发布前置校验 scripts/check-version-consistency.mjs;2026-11-24 按 VERSION=0.14.1 校正。",
4
4
  "principle": "宿主无关:宿主只依赖 `argent <verb>`;确定性逻辑在 CLI/MCP,不在提示词里。",
5
5
  "verbs": {
6
6
  "version": {
@@ -271,6 +271,7 @@
271
271
  "scripts/ml_hub_status.py",
272
272
  "scripts/ml_capacity_probe.py",
273
273
  "scripts/analyze-full-day.py",
274
+ "scripts/appointment_grab.py",
274
275
  "scripts/fulfillment.js",
275
276
  "scripts/full-exec-worker.mjs",
276
277
  "scripts/appointment_rules.py",
@@ -23,7 +23,7 @@ import { spawn } from 'node:child_process'
23
23
  import { mkdtemp, readdir, rm, stat, writeFile } from 'node:fs/promises'
24
24
  import { existsSync } from 'node:fs'
25
25
  import { tmpdir } from 'node:os'
26
- import { basename, join } from 'node:path'
26
+ import { basename, dirname, join } from 'node:path'
27
27
  import { uploadFulfillmentFiles } from './lib/fulfillment-upload.mjs'
28
28
 
29
29
  const BASE = String(process.env.ARGENT_ERP_BASE || 'https://whyshu.com').replace(/\/+$/, '')
@@ -36,6 +36,11 @@ const TABS = Math.max(1, Math.min(5, Number(process.env.FULL_EXEC_TABS || 2) ||
36
36
  const POLL_MS = Math.max(1000, Number(process.env.FULL_EXEC_POLL_MS || 5000) || 5000)
37
37
  const DOWNLOAD_ROOT = String(process.env.ZINIAO_DOWNLOAD_ROOT || '')
38
38
  || join(process.env.HOME || '', 'Library', 'Application Support', 'ziniaobrowserdatas', 'ziniao browser')
39
+ // 客户机引擎必须用带 playwright/yaml/selenium 的 venv,不能默认系统 python3。
40
+ const PYTHON = String(process.env.ARGENT_PY || '').trim()
41
+ || (existsSync(join(process.env.HOME || '', '.dsh', 'argent', 'venv', 'bin', 'python3'))
42
+ ? join(process.env.HOME || '', '.dsh', 'argent', 'venv', 'bin', 'python3')
43
+ : 'python3')
39
44
 
40
45
  if (!APP || !TOKEN || !ENGINE || !STORES.length) {
41
46
  console.error('缺少 ARGENT_TENANT_APP_ID / ARGENT_MACHINE_TOKEN / ARGENT_ENGINE_DIR / FULL_EXEC_STORES')
@@ -121,7 +126,7 @@ async function findArtifacts(filesUploaded, sinceMs) {
121
126
  return found
122
127
  }
123
128
 
124
- let activeChild = null
129
+ const activeChildren = new Set()
125
130
  const activeTasks = new Map()
126
131
  let shuttingDown = false
127
132
 
@@ -129,7 +134,7 @@ async function shutdown(signal = 'SIGTERM') {
129
134
  if (shuttingDown) return
130
135
  shuttingDown = true
131
136
  console.log(`[worker] 收到 ${signal},停止并释放任务…`)
132
- try { activeChild?.kill('SIGTERM') } catch { /* noop */ }
137
+ for (const child of activeChildren) { try { child.kill('SIGTERM') } catch { /* noop */ } }
133
138
  for (const t of activeTasks.values()) {
134
139
  await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.id)}/release`, {
135
140
  workerId, reason: `worker_shutdown:${signal}`,
@@ -141,106 +146,214 @@ async function shutdown(signal = 'SIGTERM') {
141
146
  process.on('SIGTERM', () => { void shutdown('SIGTERM') })
142
147
  process.on('SIGINT', () => { void shutdown('SIGINT') })
143
148
 
149
+ async function runAppointmentPhase(ctx) {
150
+ const task = ctx.task
151
+ const record = ctx.record
152
+ const ruleSnapshot = task.appointmentRuleSnapshot || null
153
+ const today = new Date()
154
+ const day = (n) => {
155
+ const d = new Date(today.getTime() + n * 86400000)
156
+ return d.toISOString().slice(0, 10)
157
+ }
158
+ const body = {
159
+ store: task.store,
160
+ sku: record.sku || '',
161
+ quantity: Number(record.qty) || undefined,
162
+ boxCount: Number(record.box) || undefined,
163
+ shipmentNo: record.shipmentNo || task.shipmentNo || '',
164
+ dateMode: ruleSnapshot ? 'rule' : 'range',
165
+ ruleSnapshot,
166
+ dateFrom: ruleSnapshot ? undefined : day(1),
167
+ dateTo: ruleSnapshot ? undefined : day(7),
168
+ weekdays: ruleSnapshot ? undefined : [1, 2, 3, 4, 5, 6, 7],
169
+ timeFrom: ruleSnapshot ? undefined : '07:00',
170
+ timeTo: ruleSnapshot ? undefined : '21:00',
171
+ windowText: ruleSnapshot ? `FULL 时间规则:${ruleSnapshot.name || ''}` : 'FULL 自动预约',
172
+ }
173
+ const out = await new Promise((resolve) => {
174
+ const child = spawn(PYTHON, [join(ENGINE, 'scripts', 'appointment_grab.py'), '--task-json', JSON.stringify(body)], {
175
+ cwd: ENGINE,
176
+ env: { ...process.env, PYTHONPATH: 'scripts', PATH: `${dirname(process.execPath)}:${process.env.PATH || ''}` },
177
+ })
178
+ activeChildren.add(child)
179
+ let stdout = ''; let stderr = ''
180
+ child.stdout.on('data', (b) => { stdout += String(b) })
181
+ child.stderr.on('data', (b) => { stderr += String(b) })
182
+ child.on('close', () => { activeChildren.delete(child); resolve(`${stdout}\n${stderr}`.trim()) })
183
+ child.on('error', (e) => { activeChildren.delete(child); resolve(`WORKER_ERROR: ${e.message}`) })
184
+ })
185
+ let result = null
186
+ for (const line of String(out).split('\n').reverse()) {
187
+ try { const j = JSON.parse(line); if (j && j.status) { result = j; break } } catch { /* next */ }
188
+ }
189
+ if (!result) {
190
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(task.id)}/result`, {
191
+ workerId, status: 'failed', error: '抢预约未返回结果',
192
+ }).catch(() => {})
193
+ return false
194
+ }
195
+ const ok = ['booked', 'succeeded', 'success'].includes(String(result.status || ''))
196
+ if (!ok) {
197
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(task.id)}/result`, {
198
+ workerId, status: 'failed', error: String(result.summary || result.status || '抢预约失败').slice(0, 400),
199
+ }).catch(() => {})
200
+ return false
201
+ }
202
+ const r = await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(task.id)}/appointment-result`, {
203
+ workerId,
204
+ result: {
205
+ date: result.date || '',
206
+ slot: result.slot || '',
207
+ summary: result.summary || `预约成功:${result.date || ''} ${result.slot || ''}`.trim(),
208
+ windowText: body.windowText,
209
+ },
210
+ })
211
+ if (!r || r.ok === false) {
212
+ console.warn('[worker] 预约结果回写失败', task.id, r?.message || r?.error?.message || '')
213
+ return false
214
+ }
215
+ ctx.task.phase = 'label_ready'
216
+ return true
217
+ }
218
+
144
219
  async function executeBatch(tasks) {
145
- const records = []
146
220
  const contexts = []
147
221
  for (const t of tasks) {
148
222
  activeTasks.set(String(t.id), t)
149
223
  const c = await api('GET', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.id)}/context`)
150
- records.push(c.record)
151
- contexts.push({ task: t, record: c.record })
224
+ contexts.push({ task: c.task || t, record: c.record })
152
225
  }
153
- const dir = await mkdtemp(join(tmpdir(), 'argent-full-exec-'))
154
- const file = join(dir, 'records.json')
155
- await writeFile(file, JSON.stringify(records), 'utf8')
226
+ let cancelSeen = false
156
227
  const hb = setInterval(() => {
157
- for (const t of tasks) api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.id)}/heartbeat`, { workerId }).catch(() => {})
228
+ for (const t of tasks) {
229
+ api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.id)}/heartbeat`, { workerId })
230
+ .then((r) => {
231
+ if (String(r?.task?.status || '') === 'cancelled') {
232
+ cancelSeen = true
233
+ console.log('[worker] 任务已人工接管取消,终止子进程', t.id)
234
+ for (const child of activeChildren) { try { child.kill('SIGTERM') } catch { /* noop */ } }
235
+ }
236
+ })
237
+ .catch(() => {})
238
+ }
158
239
  }, 30_000)
159
- let out = ''
160
240
  try {
161
- out = await new Promise((resolve) => {
162
- const child = spawn(process.env.ARGENT_PY || 'python3', [
163
- join(ENGINE, 'scripts', 'orchestrator.py'), '--mode', 'full',
164
- '--record-jsons-file', file, '--parallel-records', String(Math.min(tasks.length, TABS)),
165
- '--allow-write', '--no-lip',
166
- ], { cwd: ENGINE, env: { ...process.env, PYTHONPATH: 'scripts' } })
167
- activeChild = child
168
- let stdout = ''; let stderr = ''
169
- child.stdout.on('data', (b) => { stdout += String(b) })
170
- child.stderr.on('data', (b) => { stderr += String(b) })
171
- child.on('close', () => { activeChild = null; resolve(stdout || stderr) })
172
- child.on('error', (e) => { activeChild = null; resolve(`WORKER_ERROR: ${e.message}`) })
173
- })
174
- } finally {
175
- clearInterval(hb)
176
- await rm(dir, { recursive: true, force: true }).catch(() => {})
177
- }
178
- let batch = null
179
- for (const line of String(out).split('\n').reverse()) {
180
- try { const j = JSON.parse(line); if (j && j.status) { batch = j; break } } catch { /* next */ }
181
- }
182
- if (!batch) {
183
- for (const t of tasks) await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.id)}/result`, { workerId, status: 'failed', error: 'worker 未解析到引擎结果' }).catch(() => {})
184
- return
185
- }
186
- const results = Array.isArray(batch.results) ? batch.results : []
187
- for (const ctx of contexts) {
188
- const rid = String(ctx.record.record_id || '')
189
- const result = results.find((x) => String(x.record_id || '') === rid)
190
- || (results.length === contexts.length ? results[contexts.indexOf(ctx)] : null)
191
- || { status: 'failed', error: { message: batch.error || '引擎未返回该记录结果' } }
192
- if (String(result.status || '') !== 'success') {
193
- await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
194
- workerId, status: 'failed', error: String(result?.error?.message || result?.message || result?.status || 'FULL 失败'),
195
- }).catch(() => {})
196
- continue
241
+ // 一个槽位先处理抢预约阶段;抢到后同一批继续进入标签执行。
242
+ const waiting = contexts.filter((x) => String(x.task.phase || '') === 'appointment_wait')
243
+ if (waiting.length) {
244
+ await Promise.all(waiting.map(async (x) => {
245
+ try { await runAppointmentPhase(x) } catch (e) {
246
+ console.warn('[worker] 抢预约阶段异常', x.task.id, e.message)
247
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(x.task.id)}/result`, {
248
+ workerId, status: 'failed', error: String(e.message || e).slice(0, 400),
249
+ }).catch(() => {})
250
+ }
251
+ }))
197
252
  }
198
- const taskStarted = ctx.task.createdAt ? new Date(ctx.task.createdAt).getTime() : Date.now() - 2 * 3600_000
199
- const files = await findArtifacts(result.files_uploaded || {}, taskStarted)
200
- if (!files.length) {
201
- await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
202
- workerId, status: 'failed', error: 'FULL 成功但未找到可上传的产物文件',
203
- }).catch(() => {})
204
- continue
253
+ const labels = contexts.filter((x) => !String(x.task.phase || '') || ['label_ready', 'executing'].includes(String(x.task.phase || '')))
254
+ if (!labels.length) return
255
+ const dir = await mkdtemp(join(tmpdir(), 'argent-full-exec-'))
256
+ const file = join(dir, 'records.json')
257
+ await writeFile(file, JSON.stringify(labels.map((x) => x.record)), 'utf8')
258
+ let out = ''
259
+ try {
260
+ out = await new Promise((resolve) => {
261
+ const skipSteps = labels.some((x) => String(x.task.resumeFrom || '') === 'afterProductLabel') ? ['6'] : []
262
+ const args = [
263
+ join(ENGINE, 'scripts', 'orchestrator.py'), '--mode', 'full',
264
+ '--record-jsons-file', file, '--parallel-records', String(Math.min(labels.length, TABS)),
265
+ '--allow-write', '--no-lip',
266
+ ]
267
+ if (skipSteps.length) args.push('--skip-steps', skipSteps.join(','))
268
+ const child = spawn(PYTHON, args, { cwd: ENGINE, env: { ...process.env, PYTHONPATH: 'scripts', PATH: `${dirname(process.execPath)}:${process.env.PATH || ''}` } })
269
+ activeChildren.add(child)
270
+ let stdout = ''; let stderr = ''
271
+ child.stdout.on('data', (b) => { stdout += String(b) })
272
+ child.stderr.on('data', (b) => { stderr += String(b) })
273
+ child.on('close', () => { activeChildren.delete(child); resolve(`${stdout}\n${stderr}`.trim()) })
274
+ child.on('error', (e) => { activeChildren.delete(child); resolve(`WORKER_ERROR: ${e.message}`) })
275
+ })
276
+ } finally {
277
+ await rm(dir, { recursive: true, force: true }).catch(() => {})
205
278
  }
206
- const uploaded = await uploadFulfillmentFiles({
207
- files,
208
- cmdBase: `/api/argent/v1/tenants/${encodeURIComponent(APP)}/machines/${encodeURIComponent(MACHINE || workerId)}`,
209
- apiCall: (method, path, body, timeoutMs) => api(method, path, body, timeoutMs),
210
- }).catch((e) => ({ files: [], errors: [String(e?.message || e)] }))
211
- if (!uploaded.files.length) {
279
+ let batch = null
280
+ for (const line of String(out).split('\n').reverse()) {
281
+ try { const j = JSON.parse(line); if (j && j.status) { batch = j; break } } catch { /* next */ }
282
+ }
283
+ if (!batch) {
284
+ console.error('[worker] 引擎未返回 JSON,输出尾部:', String(out).slice(-4000))
285
+ for (const t of labels) await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(t.task.id)}/result`, { workerId, status: 'failed', error: 'worker 未解析到引擎结果' }).catch(() => {})
286
+ return
287
+ }
288
+ const results = Array.isArray(batch.results) ? batch.results : []
289
+ for (const ctx of labels) {
290
+ const rid = String(ctx.record.record_id || '')
291
+ const result = results.find((x) => String(x.record_id || '') === rid)
292
+ || (results.length === labels.length ? results[labels.indexOf(ctx)] : null)
293
+ || { status: 'failed', error: { message: batch.error || '引擎未返回该记录结果' } }
294
+ if (String(result.status || '') !== 'success') {
295
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
296
+ workerId, status: 'failed', error: String(result?.error?.message || result?.message || result?.status || 'FULL 失败'),
297
+ }).catch(() => {})
298
+ continue
299
+ }
300
+ const taskStarted = ctx.task.createdAt ? new Date(ctx.task.createdAt).getTime() : Date.now() - 2 * 3600_000
301
+ const files = await findArtifacts(result.files_uploaded || {}, taskStarted)
302
+ if (!files.length) {
303
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
304
+ workerId, status: 'failed', error: 'FULL 成功但未找到可上传的产物文件',
305
+ }).catch(() => {})
306
+ continue
307
+ }
308
+ const uploaded = await uploadFulfillmentFiles({
309
+ files,
310
+ cmdBase: `/api/argent/v1/tenants/${encodeURIComponent(APP)}/machines/${encodeURIComponent(MACHINE || workerId)}`,
311
+ apiCall: (method, path, body, timeoutMs) => api(method, path, body, timeoutMs),
312
+ }).catch((e) => ({ files: [], errors: [String(e?.message || e)] }))
313
+ if (!uploaded.files.length) {
314
+ await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
315
+ workerId, status: 'failed', error: `产物上传失败: ${uploaded.errors.join('; ').slice(0, 300)}`,
316
+ }).catch(() => {})
317
+ continue
318
+ }
212
319
  await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
213
- workerId, status: 'failed', error: `产物上传失败: ${uploaded.errors.join('; ').slice(0, 300)}`,
214
- }).catch(() => {})
215
- continue
320
+ workerId, status: 'succeeded',
321
+ files: uploaded.files,
322
+ resultSummary: { summary: result.summary || `FULL 完成:${result.shipment_id || ctx.task.shipmentNo || ''}`, shipmentNo: result.shipment_id || ctx.task.shipmentNo || '' },
323
+ ticketComplete: Boolean(result.ticket_complete),
324
+ completedSteps: Array.isArray(result.completed_steps) ? result.completed_steps : [],
325
+ }).catch((e) => console.warn('[worker] 回写失败', ctx.task.id, e.message))
216
326
  }
217
- await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/${encodeURIComponent(ctx.task.id)}/result`, {
218
- workerId, status: 'succeeded',
219
- files: uploaded.files,
220
- resultSummary: { summary: result.summary || `FULL 完成:${result.shipment_id || ctx.task.shipmentNo || ''}`, shipmentNo: result.shipment_id || ctx.task.shipmentNo || '' },
221
- ticketComplete: Boolean(result.ticket_complete),
222
- completedSteps: Array.isArray(result.completed_steps) ? result.completed_steps : [],
223
- }).catch((e) => console.warn('[worker] 回写失败', ctx.task.id, e.message))
327
+ } finally {
328
+ clearInterval(hb)
329
+ for (const t of tasks) activeTasks.delete(String(t.id))
224
330
  }
225
- for (const t of tasks) activeTasks.delete(String(t.id))
226
331
  }
227
332
 
228
- async function tick() {
229
- for (const store of STORES) {
230
- try {
231
- const claimed = await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/claim-batch`, {
232
- store, workerId, capacity: TABS, max: TABS,
233
- })
234
- const tasks = Array.isArray(claimed.tasks) ? claimed.tasks : []
235
- if (!tasks.length) continue
236
- console.log(`[worker] ${store}: 领取 ${tasks.length} 个任务`)
237
- await executeBatch(tasks)
238
- } catch (e) {
239
- console.warn(`[worker] ${store} 轮询失败:${e.message}`)
240
- }
333
+ const storeBusy = new Set()
334
+
335
+ async function tickStore(store) {
336
+ if (storeBusy.has(store)) return
337
+ storeBusy.add(store)
338
+ try {
339
+ const claimed = await api('POST', `/api/argent/v1/tenants/${encodeURIComponent(APP)}/full-executions/claim-batch`, {
340
+ store, workerId, capacity: TABS, max: TABS,
341
+ })
342
+ const tasks = Array.isArray(claimed.tasks) ? claimed.tasks : []
343
+ if (!tasks.length) return
344
+ console.log(`[worker] ${store}: 领取 ${tasks.length} 个任务`)
345
+ await executeBatch(tasks)
346
+ } catch (e) {
347
+ console.warn(`[worker] ${store} 轮询失败:${e.message}`)
348
+ } finally {
349
+ storeBusy.delete(store)
241
350
  }
242
351
  }
243
352
 
353
+ async function tick() {
354
+ await Promise.all(STORES.map((store) => tickStore(store)))
355
+ }
356
+
244
357
  if (process.argv.includes('--check')) await preflightCheck()
245
358
  console.log(`[worker] 启动 stores=${STORES.join(',')} tabs=${TABS} base=${BASE}`)
246
359
  await tick()
@@ -13387,6 +13387,9 @@ class Orchestrator:
13387
13387
  force=True)
13388
13388
  step_summaries: dict[int, Any] = {}
13389
13389
  steps = [step_filter] if step_filter else list(range(1, 9))
13390
+ _skip = _parse_skip_steps(getattr(self.args, "skip_steps", ""))
13391
+ if _skip:
13392
+ steps = [x for x in steps if x not in _skip]
13390
13393
  result = await self._execute_steps(steps, allow_write, dry_run, step_summaries)
13391
13394
  if result is None:
13392
13395
  # 步骤序列走完:收尾决策走**唯一入口**(`run()` 与批处理同一个)
@@ -13657,6 +13660,9 @@ class Orchestrator:
13657
13660
  steps = [4, 5, 6, 7, 8]
13658
13661
  else:
13659
13662
  steps = [step_filter] if step_filter else list(range(1, 9))
13663
+ _skip = _parse_skip_steps(getattr(self.args, "skip_steps", ""))
13664
+ if _skip:
13665
+ steps = [x for x in steps if x not in _skip]
13660
13666
  step_summaries: dict[int, Any] = {}
13661
13667
 
13662
13668
  result = await self._execute_steps(steps, allow_write, dry_run, step_summaries)
@@ -14249,6 +14255,8 @@ def build_parser() -> argparse.ArgumentParser:
14249
14255
  help="step 模式下的步骤号")
14250
14256
  p.add_argument("--allow-write", action="store_true",
14251
14257
  help="批准写步骤(3/4/5/7/8)执行(默认拒绝)")
14258
+ p.add_argument("--skip-steps", default="",
14259
+ help="逗号分隔强制跳过的步骤号(人工接管续传用;如 6=产品标已人工上传,只跑预约/箱唛/取消)")
14252
14260
  p.add_argument("--skip-appointment", action="store_true",
14253
14261
  help="FULL 流程跳过步骤4 预约(预约交给 ERP 的 FULL 预约队列;2026-11-18)")
14254
14262
  p.add_argument("--record-id", help="指定飞书记录 ID 定向处理(店铺从记录字段读取,忽略 --store-name 取第一条逻辑;供并发调度/定向重跑)")
@@ -14406,6 +14414,15 @@ async def _run_batch_parallel(orch: "Orchestrator", args: argparse.Namespace) ->
14406
14414
  "parallel": parallel, "store": store, "results": list(results)}
14407
14415
 
14408
14416
 
14417
+ def _parse_skip_steps(raw: str) -> set[int]:
14418
+ out = set()
14419
+ for part in str(raw or "").split(","):
14420
+ part = part.strip()
14421
+ if part.isdigit() and 1 <= int(part) <= 8:
14422
+ out.add(int(part))
14423
+ return out
14424
+
14425
+
14409
14426
  async def _run_and_close(orch: "Orchestrator", args: argparse.Namespace) -> dict[str, Any]:
14410
14427
  """统一运行入口:无论成功/失败/needs_approval/异常,finally 必关自建标签页(防泄漏)。
14411
14428
 
@@ -1 +1 @@
1
- export const VERSION = "0.13.29"
1
+ export const VERSION = "0.14.1"
@@ -5,7 +5,7 @@
5
5
  "_note": "P2a 落位:flows/prompts/暂停开关/日志/会话文件已命名空间化;角色/preset/技能仍是旧名(legacyNaming,P2b/P5 在有重启窗口时改名);能力与计费单位仍在 base(随重装窗口改 SKU id);适配器仍在 scripts/integrations(P4 端口化时搬)。",
6
6
  "_versionNote": "0.1.1(2026-10-06):`requires.argent` 由 `>=0.2 <0.3` 抬到 `>=0.3 <0.4`(平台现役 VERSION=0.3.0)—— 修前「Argent 能力 → 概览」把这唯一的业务线标成 `⚠️ 版本不满足`,而它实际能跑(口径与事实相反)。同批 `version` +1(P0-5,见 docs/Argent-工作台口径审计-2026-10-06.md)。|0.1.2(2026-10-09):**平台抬到 0.4.0** ⇒ `requires.argent` 同步抬到 `>=0.4 <0.5`(不改则会重演 P0-5:兼容区间把现役平台挡在门外)。判据已固化为门禁 `node scripts/check-version-consistency.mjs`(**平台版本必须落在每条业务线声明的兼容区间内**),不再靠人记得复核。⚠️ `verifiedOn.argent` **刻意维持 `0.3.0`**:该字段记的是\"**真装真跑过**\",本批只抬版本号、内核无行为改动,未在 0.4.0 上跑过生产 ⇒ 落地后补登,⛔ 不预填。|0.1.3(2026-10-21):平台版本线已到 0.7.6 ⇒ `requires.argent` 由 `>=0.4 <0.5` 抬到 `>=0.7 <0.8`(原区间把现役平台挡在门外;`check-version-consistency` R1-LOCKSTEP 实测报红)。|0.1.4(2026-11-20):平台版本线到 0.12.25 ⇒ `requires.argent` 抬到 `>=0.11 <0.13`(容纳 0.11/0.12;原文 `>=0.11 <0.12` 把 0.12 挡在门外,R1-LOCKSTEP 报红);`requires.dsh` 同步到 `>=0.2 <0.3`;`verifiedOn.argent` 补 0.12.25(六禾园客户机实装)。",
7
7
  "requires": {
8
- "argent": ">=0.11 <0.14",
8
+ "argent": ">=0.11 <0.15",
9
9
  "dsh": ">=0.2 <0.3"
10
10
  },
11
11
  "verifiedOn": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whyshu/argent-engine",
3
- "version": "0.13.29",
3
+ "version": "0.14.1",
4
4
  "description": "Argent 引擎(L1):流程/台账/重试/守卫/审计/浏览器自动化 —— 逐字节来自 argent-dsh 仓库",
5
5
  "type": "module",
6
6
  "engines": {