taskforce-loop-engineering 0.15.20 → 0.15.21

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/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.15.21 - 2026-09-30
6
+
7
+ - Add opt-in reconciliation of mutable project relay backlog statuses against unique accepted done-task evidence, while preserving fail-closed project, backlog, and task-binding checks.
8
+ - Defer internal relay tasks and accept their bound project-relay markers in the OpenClaw route installer.
9
+
5
10
  ## 0.15.20 - 2026-09-29
6
11
 
7
12
  - Add opt-in, source-preserving project backlog relay after accepted scoped tasks; fail closed on external or gated items, missing terminal authority, busy queues, and duplicates.
package/README.md CHANGED
@@ -441,6 +441,16 @@ queue, human gates, missing authority, or accepted project terminal state stop
441
441
  the relay. The existing scheduler executes that queued item on its next tick.
442
442
  The relay does not infer safe work from prose or promote project acceptance.
443
443
 
444
+ Projects with a mutable `backlogSource` may also set
445
+ `relayStatusReconciliation: true`. After an accepted task, Loop changes a
446
+ `ready` local-only relay item to `completed` only when exactly one matching
447
+ same-project task is in the done queue and its persisted final judgement is
448
+ `ready_to_apply` without a human gate. Missing, duplicate, failed, gated, or
449
+ external-action tasks leave the source unchanged. Reconciliation is idempotent
450
+ and also runs on subsequent non-plan-only scheduler ticks, so an interrupted
451
+ completion write can recover. It does not change the project acceptance ledger or requirement matrix. Do
452
+ not enable it on an immutable or generated authoritative backlog source.
453
+
444
454
  ## Observability
445
455
 
446
456
  Use `doctor` for a read-only health view of the loop workspace:
package/lib/core.mjs CHANGED
@@ -2590,6 +2590,65 @@ async function projectHasSafeActionableBacklog(root, spec, checkpoint = null) {
2590
2590
  });
2591
2591
  }
2592
2592
 
2593
+ export async function projectRelayReconcile(root, { queue, project } = {}) {
2594
+ project = normalizeProjectId(project);
2595
+ const spec = await readJson(projectConfigPathFor(root, project));
2596
+ if (spec.relayStatusReconciliation !== true || !spec.backlogSource
2597
+ || !spec.queues?.some((entry) => entry.queue === queue && entry.autostart === true)) return { changed: 0 };
2598
+ const acceptance = await projectAcceptanceRecord(root, spec);
2599
+ const ledger = acceptance?.record;
2600
+ if (!ledger || typeof ledger !== 'object' || Array.isArray(ledger)
2601
+ || !['in_progress', 'ongoing'].includes(ledger.status)
2602
+ || ledger.terminalState?.accepted === true || ledger.terminalAccepted === true) return { changed: 0 };
2603
+ const backlogFile = path.resolve(root, safeRelativePath(spec.backlogSource, 'project backlog source'));
2604
+ let backlog;
2605
+ try { backlog = await readJson(backlogFile); } catch { return { changed: 0 }; }
2606
+ if (!backlog || typeof backlog !== 'object' || Array.isArray(backlog)) return { changed: 0 };
2607
+ const field = Array.isArray(backlog.items) ? 'items' : Array.isArray(backlog.tasks) ? 'tasks' : null;
2608
+ if (!field) return { changed: 0 };
2609
+ const completed = new Map();
2610
+ for (const file of await listJson(queueSubdirFor(root, queue, 'done'))) {
2611
+ const task = await readJson(path.join(queueSubdirFor(root, queue, 'done'), file));
2612
+ if (task.projectId !== project || task.status !== 'completed' || !task.id
2613
+ || !task.source?.channel || !task.source?.target || !task.source?.account || !task.source?.message_id) continue;
2614
+ const marker = String(task.body ?? '').match(/^\[project-relay:([a-zA-Z0-9._-]+)\/([a-zA-Z0-9._-]+)\](?:\n|$)/);
2615
+ if (marker?.[1] !== project || task.backlogItemId !== marker[2]) continue;
2616
+ const ids = completed.get(marker[2]) ?? [];
2617
+ ids.push(task.id);
2618
+ completed.set(marker[2], ids);
2619
+ }
2620
+ const itemCounts = new Map();
2621
+ for (const item of backlog[field]) {
2622
+ if (item?.id) itemCounts.set(item.id, (itemCounts.get(item.id) ?? 0) + 1);
2623
+ }
2624
+ let changed = 0;
2625
+ const items = [];
2626
+ for (const item of backlog[field]) {
2627
+ if (!item || typeof item !== 'object' || !/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(String(item.id ?? ''))
2628
+ || itemCounts.get(item.id) !== 1
2629
+ || (completed.get(item.id) ?? []).length !== 1
2630
+ || item.status !== 'ready' || item.autoRun !== true || item.scope !== 'local_only'
2631
+ || item.externalActionsAllowed !== false || item.humanGateRequired !== false) {
2632
+ items.push(item);
2633
+ continue;
2634
+ }
2635
+ const judgementFile = path.join(taskRuntimeDirFor(root, queue, completed.get(item.id)[0]), 'final_judgement.json');
2636
+ const judgement = await exists(judgementFile) ? await readJson(judgementFile) : null;
2637
+ if (judgement?.outcome !== 'ready_to_apply' || judgement.requires_human_gate !== false) {
2638
+ items.push(item);
2639
+ continue;
2640
+ }
2641
+ items.push({ ...item, status: 'completed' });
2642
+ changed += 1;
2643
+ }
2644
+ if (changed) {
2645
+ const temporary = `${backlogFile}.${process.pid}.tmp`;
2646
+ await writeJson(temporary, { ...backlog, [field]: items });
2647
+ await rename(temporary, backlogFile);
2648
+ }
2649
+ return { changed };
2650
+ }
2651
+
2593
2652
  export async function projectRelayNext(root, { queue, task, finalJudgement } = {}) {
2594
2653
  if (!task?.projectId || finalJudgement?.outcome !== 'ready_to_apply' || finalJudgement.requires_human_gate) return null;
2595
2654
  const project = normalizeProjectId(task.projectId);
@@ -2607,6 +2666,7 @@ export async function projectRelayNext(root, { queue, task, finalJudgement } = {
2607
2666
  if (typeof predecessorId !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/.test(predecessorId)) return null;
2608
2667
  const queueState = await queueStatus(root, queue);
2609
2668
  if (queueState.queued || queueState.active || queueState.waiting) return null;
2669
+ await projectRelayReconcile(root, { queue, project });
2610
2670
  const backlogSource = spec.backlogSource ?? spec.authoritativeBacklog;
2611
2671
  if (typeof backlogSource !== 'string' || !backlogSource.trim()) return null;
2612
2672
  let backlog;
@@ -4686,6 +4746,18 @@ export async function queueSchedulerTick(root, options) {
4686
4746
  status = statusBefore.queued > 0 ? 'planned_due' : 'empty';
4687
4747
  }
4688
4748
 
4749
+ const relayReconciliation = [];
4750
+ if (!options.planOnly) {
4751
+ for (const spec of await projectSpecs(root)) {
4752
+ if (spec.relayStatusReconciliation !== true || !spec.queues?.some((entry) => entry.queue === queue && entry.autostart === true)) continue;
4753
+ try {
4754
+ relayReconciliation.push({ project: spec.project, ...await projectRelayReconcile(root, { queue, project: spec.project }) });
4755
+ } catch (error) {
4756
+ relayReconciliation.push({ project: spec.project, error: error instanceof Error ? error.message : String(error) });
4757
+ }
4758
+ }
4759
+ }
4760
+
4689
4761
  const statusAfter = await queueStatus(root, queue);
4690
4762
  const run = runResult?.run ?? null;
4691
4763
  const observed = {
@@ -4776,6 +4848,7 @@ export async function queueSchedulerTick(root, options) {
4776
4848
  progressReportPath: path.relative(root, queueProgressStatePath(root, queue)),
4777
4849
  statusBefore,
4778
4850
  statusAfter,
4851
+ relayReconciliation,
4779
4852
  run: runResult
4780
4853
  };
4781
4854
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "taskforce-loop-engineering",
3
- "version": "0.15.20",
3
+ "version": "0.15.21",
4
4
  "private": false,
5
5
  "description": "OpenClaw-native loop engineering CLI, templates, and skill for verifiable agent work loops.",
6
6
  "type": "module",
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import { chmod, mkdtemp, readFile, writeFile } from 'node:fs/promises';
2
+ import { chmod, mkdtemp, readFile, readdir, writeFile } from 'node:fs/promises';
3
3
  import { spawn } from 'node:child_process';
4
4
  import { tmpdir } from 'node:os';
5
5
  import path from 'node:path';
@@ -205,4 +205,28 @@ const zhInstructions = await readFile(path.join(root, 'AGENTS.md'), 'utf8');
205
205
  const zhDispatcher = await readFile(path.join(root, 'scripts/loops/openclaw-loop-dispatch.mjs'), 'utf8');
206
206
  const zhNotifier = await readFile(path.join(root, 'scripts/loops/openclaw-loop-notify.mjs'), 'utf8');
207
207
  if (zhQueue.language !== 'zh' || !zhInstructions.includes('Loop Engineering 会话路由') || !zhDispatcher.includes('已经由 Loop Engineering 管理') || !zhNotifier.includes('通知器需要消息参数')) throw new Error('Chinese installation did not localize generated configuration and runtime files');
208
+ const installedWrapper = path.join(root, 'scripts/loops/openclaw-loop.mjs');
209
+ async function routeWithRelayFlag(message) {
210
+ return new Promise((resolve) => {
211
+ const child = spawn(process.execPath, [installedWrapper, 'route', '--relay-enqueue', '--message', message,
212
+ '--source-channel', 'feishu', '--source-target', 'owner', '--source-account', 'main',
213
+ '--source-message-id', 'relay-source-1'], { cwd: root, stdio: ['ignore', 'pipe', 'pipe'] });
214
+ let stderr = '';
215
+ child.stderr.on('data', (chunk) => { stderr += chunk; });
216
+ child.on('close', (code) => resolve({ code, stderr }));
217
+ });
218
+ }
219
+ const rejectedRelay = await routeWithRelayFlag('走 loop:普通任务');
220
+ if (rejectedRelay.code !== 2 || !rejectedRelay.stderr.includes('internal project relay marker')) throw new Error('internal enqueue flag accepted an unmarked task');
221
+ const projectRelay = await routeWithRelayFlag('走 loop: [project-relay:relay-project/local-1] 本地任务');
222
+ if (projectRelay.code !== 0) throw new Error(`project relay marker was rejected: ${projectRelay.stderr}`);
223
+ const internalRelay = await routeWithRelayFlag('走 loop: [project-scout:abc123] 本地只读扫描');
224
+ if (internalRelay.code !== 0) throw new Error(`internal relay enqueue failed: ${internalRelay.stderr}`);
225
+ const inboxDir = path.join(root, 'runtime/loops/test-tasks/inbox');
226
+ const queuedFiles = (await readdir(inboxDir)).filter((name) => name.endsWith('.json'));
227
+ if (queuedFiles.length !== 2) throw new Error('internal relays did not defer exactly two tasks to the scheduler');
228
+ const queuedTasks = await Promise.all(queuedFiles.map(async (file) => JSON.parse(await readFile(path.join(inboxDir, file), 'utf8'))));
229
+ if (!queuedTasks.some((task) => task.body.includes('[project-relay:relay-project/local-1]'))
230
+ || !queuedTasks.some((task) => task.body.includes('[project-scout:abc123]'))
231
+ || queuedTasks.some((task) => task.body.includes('只入队'))) throw new Error('internal relay corrupted task intent');
208
232
  console.log('openclaw installer self-test passed');
@@ -194,6 +194,11 @@ async function runWhenUnlocked(args, waitMs = 300000) {
194
194
  if (command === 'route') {
195
195
  const messageIndex = rest.indexOf('--message');
196
196
  const message = messageIndex >= 0 ? String(rest[messageIndex + 1] || '') : '';
197
+ const relayEnqueue = rest.includes('--relay-enqueue');
198
+ if (relayEnqueue && !/\\[project-(?:relay:[a-zA-Z0-9._-]+\\/[a-zA-Z0-9._-]+|scout:[a-z0-9_-]+)\\]/.test(message)) {
199
+ console.error('--relay-enqueue requires an internal project relay marker');
200
+ process.exit(2);
201
+ }
197
202
  const optionValue = (name) => {
198
203
  const index = rest.indexOf(name);
199
204
  return index >= 0 ? String(rest[index + 1] || '').trim() : '';
@@ -207,8 +212,9 @@ if (command === 'route') {
207
212
  }
208
213
  const amendment = new RegExp(${JSON.stringify(amendmentPattern)}, 'i').test(message);
209
214
  const routeMode = amendment ? '--amend-active' : '--supersede-active';
210
- const routeCode = await run(['route-message', '--queue', ${JSON.stringify(queue)}, '--route', '--confirm-execute', routeMode, ...rest]);
211
- const queueOnly = new RegExp(${JSON.stringify(queueOnlyPattern)}, 'i').test(message);
215
+ const routedArgs = rest.filter((arg) => arg !== '--relay-enqueue');
216
+ const routeCode = await run(['route-message', '--queue', ${JSON.stringify(queue)}, '--route', '--confirm-execute', routeMode, ...routedArgs]);
217
+ const queueOnly = relayEnqueue || new RegExp(${JSON.stringify(queueOnlyPattern)}, 'i').test(message);
212
218
  const runCode = routeCode || queueOnly || amendment ? routeCode : await runWhenUnlocked(['run-queue', '--config', ${JSON.stringify(`configs/loops/queues/${queue}.json`)}, '--progress-notify-command', 'node scripts/loops/openclaw-loop-notify.mjs']);
213
219
  const humanNotifyCode = await run(['queue-human-input-notify', '--queue', ${JSON.stringify(queue)}, '--notify-command', 'node scripts/loops/openclaw-loop-notify.mjs']);
214
220
  const terminalNotifyCode = await run(['queue-terminal-notify', '--queue', ${JSON.stringify(queue)}, '--notify-command', 'node scripts/loops/openclaw-loop-notify.mjs']);
@@ -1,8 +1,8 @@
1
1
  import assert from 'node:assert/strict';
2
- import { mkdtemp, mkdir, readFile, writeFile, unlink } from 'node:fs/promises';
2
+ import { mkdtemp, mkdir, readFile, rm, writeFile, unlink } from 'node:fs/promises';
3
3
  import os from 'node:os';
4
4
  import path from 'node:path';
5
- import { ensureQueueDirs, projectRelayNext, queueStatus } from '../lib/core.mjs';
5
+ import { ensureQueueDirs, projectRelayNext, projectRelayReconcile, queueSchedulerTick, queueStatus } from '../lib/core.mjs';
6
6
 
7
7
  const root = await mkdtemp(path.join(os.tmpdir(), 'loop-project-relay-'));
8
8
  const queue = 'relay-test';
@@ -67,4 +67,42 @@ assert.equal(await projectRelayNext(root, { queue, task, finalJudgement }), null
67
67
  assert.equal((await queueStatus(root, queue)).queued, 1);
68
68
  await writeJson(ledgerFile, { status: 'accepted' });
69
69
  assert.equal(await projectRelayNext(root, { queue, task, finalJudgement }), null, 'accepted project cannot relay');
70
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'reconciliation is opt-in');
71
+ await writeJson(configFile, { ...spec, relayStatusReconciliation: true });
72
+ await writeJson(path.join(root, 'runtime/loops', queue, 'done', `${queued.id}.json`), { ...queued, status: 'completed' });
73
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'a queue row alone is not acceptance');
74
+ await writeJson(path.join(root, 'runtime/loops', queue, 'tasks', queued.id, 'final_judgement.json'), { outcome: 'ready_to_apply', requires_human_gate: false });
75
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'accepted project cannot mutate backlog');
76
+ await writeJson(ledgerFile, { status: 'in_progress' });
77
+ await writeJson(path.join(root, 'runtime/loops', queue, 'done', `${queued.id}.json`), { ...queued, backlogItemId: 'wrong', status: 'completed' });
78
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'marker without matching backlog binding is not evidence');
79
+ await writeJson(path.join(root, 'runtime/loops', queue, 'done', `${queued.id}.json`), { ...queued, status: 'completed' });
80
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 1);
81
+ assert.equal((await readFile(backlogFile, 'utf8')).includes('"status": "completed"'), true);
82
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'reconciliation is idempotent');
83
+ await writeJson(backlogFile, { items: [{ ...item, externalActionsAllowed: true }] });
84
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'unsafe backlog rows are not promoted');
85
+ await writeJson(backlogFile, { items: [item] });
86
+ await writeJson(path.join(root, 'runtime/loops', queue, 'done', 'duplicate.json'), { ...queued, id: 'duplicate', status: 'completed' });
87
+ await writeJson(path.join(root, 'runtime/loops', queue, 'tasks', 'duplicate', 'final_judgement.json'), { outcome: 'ready_to_apply' });
88
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'duplicate task evidence cannot promote a row');
89
+ await writeJson(backlogFile, { items: [item] });
90
+ await writeJson(path.join(root, 'runtime/loops', queue, 'scheduler/state.json'), { nextRunAt: '2999-01-01T00:00:00.000Z' });
91
+ const planned = await queueSchedulerTick(root, { queue, planOnly: true });
92
+ assert.equal(planned.relayReconciliation.length, 0, 'plan-only scheduler cannot mutate the backlog');
93
+ assert.equal(JSON.parse(await readFile(backlogFile, 'utf8')).items[0].status, 'ready');
94
+ await writeJson(path.join(root, 'runtime/loops', queue, 'done', 'duplicate.json'), { ...queued, id: 'duplicate', projectId: 'another-project', status: 'completed' });
95
+ await writeJson(backlogFile, { items: [item, { ...item }] });
96
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'duplicate backlog ids cannot be reconciled');
97
+ await writeJson(backlogFile, { items: [item] });
98
+ await writeJson(ledgerFile, { status: 'unknown' });
99
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'invalid project acceptance cannot change backlog');
100
+ await writeJson(ledgerFile, { status: 'in_progress' });
101
+ await unlink(backlogFile);
102
+ assert.equal((await projectRelayReconcile(root, { queue, project })).changed, 0, 'missing authoritative backlog fails closed');
103
+ await writeJson(backlogFile, { items: [item] });
104
+ await rm(path.join(root, result.file));
105
+ const tick = await queueSchedulerTick(root, { queue });
106
+ assert.deepEqual(tick.relayReconciliation, [{ project, changed: 1 }], 'idle scheduler repairs interrupted status writes');
107
+ assert.equal((await readFile(backlogFile, 'utf8')).includes('"status": "completed"'), true);
70
108
  console.log('project relay self-test passed');