taskforce-loop-engineering 0.15.21 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/MIGRATING.md +80 -0
  3. package/README.md +37 -8
  4. package/bin/loop-engineering.mjs +142 -114
  5. package/docs/architecture.md +3 -2
  6. package/docs/human-gate-command.md +1 -1
  7. package/docs/operator-dashboard.md +16 -5
  8. package/docs/operator-workspace-project.md +2 -2
  9. package/docs/production-trust-contract.md +9 -2
  10. package/docs/transactional-kernel-and-goal-api.md +3 -1
  11. package/lib/action-reservations.mjs +21 -23
  12. package/lib/core.mjs +643 -109
  13. package/lib/durable-journal.mjs +23 -6
  14. package/lib/execution-ledger.mjs +4 -4
  15. package/lib/file-mutex.mjs +102 -0
  16. package/lib/human-gate-channel-adapter.mjs +4 -2
  17. package/lib/human-gate-command.mjs +5 -3
  18. package/lib/operator-dashboard.mjs +72 -10
  19. package/lib/production-evidence.mjs +37 -15
  20. package/lib/quota-runtime-decision.mjs +11 -6
  21. package/lib/redaction.mjs +34 -0
  22. package/lib/todo-control-plane.mjs +12 -16
  23. package/lib/transactional-state-kernel.mjs +96 -18
  24. package/package.json +2 -3
  25. package/scripts/dashboard-autostart-install.mjs +33 -8
  26. package/scripts/dashboard-autostart-self-test.mjs +12 -3
  27. package/scripts/final-judgement-self-test.mjs +21 -0
  28. package/scripts/hermes-install-self-test.mjs +8 -1
  29. package/scripts/hermes-install.mjs +29 -8
  30. package/scripts/hermes-smoke.mjs +2 -1
  31. package/scripts/human-gate-command-self-test.mjs +34 -5
  32. package/scripts/install-shared.mjs +61 -0
  33. package/scripts/openclaw-install-self-test.mjs +47 -1
  34. package/scripts/openclaw-install.mjs +42 -17
  35. package/scripts/openclaw-manage.mjs +22 -3
  36. package/scripts/openclaw-smoke.mjs +2 -1
  37. package/scripts/project-relay-self-test.mjs +145 -1
  38. package/scripts/run-loop-cron.sh +22 -7
  39. package/scripts/safety-regression-self-test.mjs +349 -0
  40. package/skills/taskforce-loop-engineering/SKILL.md +1 -1
@@ -1,6 +1,6 @@
1
1
  # Operator Dashboard and projection API
2
2
 
3
- P3 provides a local-first, read-only view over durable Loop Engineering artifacts. It does not maintain a database, lock queue state, or write beneath `runtime/loops`. Every live request rebuilds a normalized projection; static export writes only to the explicitly selected output directory.
3
+ P3 provides a local-first view over durable Loop Engineering artifacts. The projection itself is read-only; the only mutation is the authenticated Human Gate command endpoint described below. It does not maintain a database, lock queue state, or write beneath `runtime/loops`. Every live request rebuilds a normalized projection; static export writes only to the explicitly selected output directory.
4
4
 
5
5
  ## Commands
6
6
 
@@ -12,9 +12,20 @@ loop-engineering dashboard-export --output-dir /tmp/loop-dashboard --root /path/
12
12
  loop-engineering dashboard-serve --root /path/to/workspace
13
13
  ```
14
14
 
15
- `dashboard-serve` binds to `127.0.0.1` and an ephemeral port by default. A wider bind is rejected unless `--allow-non-loopback` is explicit. The server has no authentication and is intended for trusted local use.
15
+ `dashboard-serve` binds to `127.0.0.1` and an ephemeral port by default. A wider bind is rejected unless `--allow-non-loopback` is explicit. Read endpoints have no login and are intended for trusted local or Tailnet use. On a loopback bind the server answers only requests whose `Host` is `127.0.0.1`, `localhost` or `[::1]` with its port, so a DNS-rebinding web page cannot read or drive it; add other names with `--allowed-host name:port`.
16
16
 
17
- The OpenClaw and Hermes integration installers also install a Dashboard service on port `4174` and systemd gateway drop-ins. Starting `openclaw-gateway.service` or `hermes-gateway.service` therefore starts the read-only Dashboard. The default `localhost` mode binds only `127.0.0.1`. Optional `tailscale` mode resolves `tailscale ip -4` at install time and binds only that Tailnet address; it never binds `0.0.0.0`. Tailnet access is governed by Tailscale ACLs/Grants, while the Dashboard itself remains read-only and has no application-level login.
17
+ ### Human Gate commands
18
+
19
+ `POST /api/v1/gate-commands` approves, rejects or requests revision of a Human Gate through `executeGateCommand`. It is disabled until an operator is registered:
20
+
21
+ ```sh
22
+ loop-engineering dashboard-operator-add --actor-id alice --root /path/to/workspace
23
+ loop-engineering dashboard-operator-remove --actor-id alice --root /path/to/workspace
24
+ ```
25
+
26
+ `dashboard-operator-add` prints a random token once and stores only its SHA-256 digest in `configs/loops/dashboard-operators.json`; running it again rotates the token. Requests must send `Content-Type: application/json` and `Authorization: Bearer <token>`. The acting identity is the operator bound to the token; any `actor_id` in the request body is ignored, so the gate's `allowed_actors` check applies to the authenticated operator. Gate evidence returned by `/api/v1/gates` is redacted like the rest of the projection.
27
+
28
+ The OpenClaw and Hermes integration installers also install a Dashboard service on port `4174` and systemd gateway drop-ins. Starting `openclaw-gateway.service` or `hermes-gateway.service` therefore starts the Dashboard. The default `localhost` mode binds only `127.0.0.1`. Optional `tailscale` mode resolves `tailscale ip -4` at install time and binds only that Tailnet address; it never binds `0.0.0.0`. Tailnet access to the read endpoints is governed by Tailscale ACLs/Grants; Human Gate commands additionally require an operator token.
18
29
 
19
30
  ```bash
20
31
  loop-engineering-dashboard-autostart-install --root /path/to/workspace
@@ -33,11 +44,11 @@ This creates `loop-engineering-dashboard.service` on fixed port `4174` and syste
33
44
 
34
45
  The platform installers expose the same choice as `--dashboard-listen localhost|tailscale` and accept `--tailscale-bin` when the CLI is outside `PATH`.
35
46
 
36
- Endpoints are `GET /api/v1/overview`, `/api/v1/health`, `/api/v1/projects`, `/api/v1/projects/:id`, `/api/v1/todos`, `/api/v1/todos/:id`, and `/api/v1/actions`. Overview and todo lists support `q` and `state` filters. Private raw files are not served.
47
+ Endpoints are `GET /api/v1/overview`, `/api/v1/health`, `/api/v1/projects`, `/api/v1/projects/:id`, `/api/v1/todos`, `/api/v1/todos/:id`, `/api/v1/actions`, `/api/v1/gates`, and the authenticated `POST /api/v1/gate-commands`. Overview and todo lists support `q` and `state` filters. Private raw files are not served.
37
48
 
38
49
  The browser workspace leads with projects rather than queue rows. A project card keeps milestone progress separate from terminal acceptance; project detail exposes the terminal outcome/rules, milestone acceptance, checkpoint revision lineage, human gates, reservations, acceptance reviews, and the independent final-judge event. Task workspaces are linked to a project only by explicit `checkpoint.project_id`, so the projection does not guess ownership from names. Unlinked tasks remain available in `task_workspaces` and the operational queue.
39
50
 
40
- The interface is responsive down to a narrow phone viewport, keyboard-operable for project selection, dependency-free, and safe for static export. It remains deliberately read-only: there are no approve, retry, settle, resume, or mutation controls.
51
+ The interface is responsive down to a narrow phone viewport, keyboard-operable for project selection, dependency-free, and safe for static export. Apart from operator-token Human Gate decisions, it has no retry, settle, resume, or other mutation controls.
41
52
 
42
53
  ## Projection and security rules
43
54
 
@@ -17,13 +17,13 @@ No single page, milestone, checkpoint, or passing test subset completes this pro
17
17
  - Terminal contract, milestone and project status: milestone 1 projection/API/UI tests.
18
18
  - Revision lineage and acceptance/final-judge timeline: milestone 1 task workspace fixtures.
19
19
  - Human gates and external-action reservations: milestones 1–2 projection and inspection views.
20
- - Safe read-only boundary: no mutation endpoints or controls; loopback default, explicit non-loopback override, redaction, XSS/path traversal checks.
20
+ - Safe boundary: read-only projection; the only mutation is operator-token Human Gate commands through `executeGateCommand`; loopback default with Host checking, explicit non-loopback override, redaction, XSS/path traversal checks.
21
21
  - Information architecture, interaction and responsive UI: milestones 1–2.
22
22
  - Tests, documentation and release-level acceptance: milestones 1–3.
23
23
 
24
24
  ## Explicit boundaries
25
25
 
26
- The workspace does not approve gates, resume tasks, settle reservations, modify contracts, repair artifacts, or serve arbitrary evidence files. Those actions remain in governed CLI/control-plane workflows. A future authenticated mutation product would require a separate authority model and project contract.
26
+ The workspace approves or rejects Human Gates only for an authenticated operator (see `docs/operator-dashboard.md`). It does not resume tasks, settle reservations, modify contracts, repair artifacts, or serve arbitrary evidence files. Those actions remain in governed CLI/control-plane workflows. A future authenticated mutation product would require a separate authority model and project contract.
27
27
 
28
28
  ## Project completion rule
29
29
 
@@ -27,8 +27,15 @@ error rate, and recovery time remain independently reviewable.
27
27
  simulated I/O. The boundary is explicit: fixtures prove adapter compatibility,
28
28
  not availability of a real gateway or provider.
29
29
  4. Evidence schema v1 supports baselines and metric deltas, threshold failures
30
- with attribution, SHA-256 tamper detection, credential-shaped field redaction,
31
- and a minimized public summary. Offline reruns require no network or secret.
30
+ with attribution, an integrity seal, credential-shaped field redaction
31
+ (including camelCase keys such as `accessToken` and `Authorization`), and a
32
+ minimized public summary. Offline reruns require no network or secret. The
33
+ `passed` verdict is recomputed from thresholds, scenarios and compatibility
34
+ when sealing and when summarizing, so it cannot be asserted by hand. Without a
35
+ key the seal is a plain SHA-256 digest: it detects accidental corruption, but
36
+ anyone who can edit the file can recompute it. Set `LOOP_EVIDENCE_HMAC_KEY`
37
+ (or pass `{ key }`) to seal with HMAC-SHA-256; verifying such a report then
38
+ requires the same key and a forged report cannot be re-sealed without it.
32
39
  5. GitHub CI template/artifact upload and badge markup are release candidates;
33
40
  no workflow is published in this local task. Doctor and dashboard project the
34
41
  latest evidence state without mutating it.
@@ -12,7 +12,9 @@ loop-engineering doctor --id demo
12
12
 
13
13
  ## Transaction model
14
14
 
15
- Every mutation enters `TransactionalStateKernel.transact` with typed effects. Writers hold an exclusive lease, receive a monotonically increasing fencing token, and may provide `expectedGeneration` for compare-and-swap. Each new effect produces a receipt containing its digest and the previous receipt hash. State records the receipt head and exact effect keys, so replay applies the same logical effect zero or one times.
15
+ Every mutation enters `TransactionalStateKernel.transact` with typed effects. Writers hold an exclusive lease, receive a monotonically increasing fencing token, and may provide `expectedGeneration` for compare-and-swap. Each new effect produces a receipt containing its digest and the previous receipt hash. State records the receipt head and exact effect keys, so replay applies the same logical effect zero or one times. Fencing tokens are persisted when a lease is issued, so no two leases share a token and a released lease cannot commit.
16
+
17
+ `replayEffect(effect, execute)` holds the writer lease from the applied-effect check through the commit, so concurrent callers wait and then receive the existing receipt. Before `execute` runs, an intent is stored in `pending_effects`; if the process dies before the commit, a later `replayEffect` returns `reconcileRequired: true` instead of executing again. Settle it with `reconcileEffect(effect, { executed: true, outcome })` once the upstream result is known, or `{ executed: false }` to allow a retry.
16
18
 
17
19
  Completion is fenced. Its validator must accept the complete terminal contract; a successful milestone alone cannot set `completed`. Human gates, revisions, action reservations, evidence, and completion are effect types rather than replacement state machines, so existing queue and reservation artifacts remain compatible.
18
20
 
@@ -1,5 +1,6 @@
1
1
  import { mkdir, readFile, rename, rm, stat, writeFile } from 'node:fs/promises';
2
2
  import path from 'node:path';
3
+ import { withFileMutex } from './file-mutex.mjs';
3
4
  import { createHash, randomUUID } from 'node:crypto';
4
5
  import { migrateActionReservation } from './execution-ledger.mjs';
5
6
 
@@ -44,35 +45,15 @@ async function atomicWrite(file, value) {
44
45
  await rename(temp, file);
45
46
  }
46
47
 
47
- async function acquireMutex(lock, timeoutMs = 5000) {
48
- const deadline = Date.now() + timeoutMs;
49
- while (true) {
50
- try {
51
- await mkdir(lock);
52
- await writeFile(path.join(lock, 'owner.json'), JSON.stringify({ pid: process.pid, created_at: new Date().toISOString() }));
53
- return;
54
- } catch (error) {
55
- if (error.code !== 'EEXIST') throw error;
56
- const info = await stat(lock).catch(() => null);
57
- if (info && Date.now() - info.mtimeMs > 30_000) await rm(lock, { recursive: true, force: true });
58
- else if (Date.now() >= deadline) throw new Error('Timed out acquiring action reservation mutex.');
59
- else await new Promise((resolve) => setTimeout(resolve, 10));
60
- }
61
- }
62
- }
63
-
64
48
  async function mutate(root, key, operation) {
65
49
  const location = paths(root, key);
66
50
  await mkdir(location.dir, { recursive: true });
67
- await acquireMutex(location.lock);
68
- try {
51
+ return withFileMutex(location.lock, { label: 'action reservation mutex' }, async () => {
69
52
  const record = await readJson(location.file).catch((error) => error.code === 'ENOENT' ? null : Promise.reject(error));
70
53
  const result = await operation(record, location.file);
71
54
  if (result.write) await atomicWrite(location.file, result.record);
72
55
  return result.output ?? result.record;
73
- } finally {
74
- await rm(location.lock, { recursive: true, force: true });
75
- }
56
+ });
76
57
  }
77
58
 
78
59
  export async function reserveAction(root, input) {
@@ -129,6 +110,17 @@ function assertFence(record, token) {
129
110
  if (record.state !== 'claimed' || record.claim?.fencing_token !== Number(token)) throw new Error('Stale or invalid fencing token.');
130
111
  }
131
112
 
113
+ // A claim whose lease has lapsed no longer proves exclusive execution, so a
114
+ // late settle or release becomes an unknown outcome for an operator to
115
+ // reconcile. The worker's report is kept as evidence.
116
+ function lateOutcome(record, type, input) {
117
+ if (Date.parse(record.claim?.lease_expires_at ?? '') > Date.now()) return null;
118
+ const at = new Date().toISOString();
119
+ const report = { type, evidence: input.evidence ?? null, reason: input.reason ?? null, fencing_token: Number(input.fencingToken), reported_at: at };
120
+ const unknown = { ...record, state: 'unknown', updated_at: at, reconciliation: { required: true, reason: 'lease_expired_before_report', marked_at: at, late_report: report }, events: [...record.events, { type: 'outcome_unknown', reason: 'lease_expired_before_report', late_report: type, at }] };
121
+ return { write: true, record: unknown, output: { [type === 'settle' ? 'settled' : 'released']: false, reason: 'reconcile_required', record: unknown } };
122
+ }
123
+
132
124
  export async function markActionUnknown(root, input) {
133
125
  return mutate(root, input.idempotencyKey, async (record) => {
134
126
  if (!record) throw new Error('Action reservation not found.');
@@ -144,6 +136,8 @@ export async function settleAction(root, input) {
144
136
  if (!record) throw new Error('Action reservation not found.');
145
137
  if (record.state === 'settled') return { write: false, output: { settled: false, duplicate: true, record } };
146
138
  assertFence(record, input.fencingToken);
139
+ const late = lateOutcome(record, 'settle', input);
140
+ if (late) return late;
147
141
  const at = new Date().toISOString();
148
142
  const next = { ...record, state: 'settled', updated_at: at, authorization: { ...record.authorization, state: 'consumed', consumed_at: at }, settlement: { status: 'succeeded', evidence: input.evidence ?? null, settled_at: at, fencing_token: Number(input.fencingToken) }, reconciliation: null, events: [...record.events, { type: 'settled', fencing_token: Number(input.fencingToken), at }] };
149
143
  return { write: true, record: next, output: { settled: true, duplicate: false, record: next } };
@@ -155,7 +149,11 @@ export async function releaseAction(root, input) {
155
149
  if (!record) throw new Error('Action reservation not found.');
156
150
  if (record.state === 'settled') throw new Error('Consumed authorization cannot be released.');
157
151
  if (record.state === 'released') return { write: false, output: { released: false, duplicate: true, record } };
158
- if (record.state === 'claimed') assertFence(record, input.fencingToken);
152
+ if (record.state === 'claimed') {
153
+ assertFence(record, input.fencingToken);
154
+ const late = lateOutcome(record, 'release', input);
155
+ if (late) return late;
156
+ }
159
157
  if (record.state === 'unknown') throw new Error('Unknown upstream outcome must be reconciled before release.');
160
158
  const at = new Date().toISOString();
161
159
  const next = { ...record, state: 'released', updated_at: at, authorization: { ...record.authorization, state: 'released', released_at: at }, release: { reason: requireText(input.reason, 'reason'), evidence: input.evidence ?? null, released_at: at }, events: [...record.events, { type: 'released', at }] };