@cassiomc1/forgeloop 1.2.4 → 1.5.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 (92) hide show
  1. package/.github/copilot-instructions.md +1 -0
  2. package/AGENTS.md +1 -0
  3. package/AGENT_COMPATIBILITY.md +4 -0
  4. package/CLAUDE.md +1 -0
  5. package/DOCS_INDEX.md +14 -0
  6. package/EXECUTION_STATE.md +48 -0
  7. package/LOOP_ENGINEERING.md +55 -6
  8. package/LOOP_SYSTEM_DESIGN.md +32 -1
  9. package/PROTOCOL_INTEGRATION.md +71 -0
  10. package/README.md +86 -0
  11. package/TERMINOLOGY.md +15 -0
  12. package/THIRD_PARTY_NOTICES.md +15 -0
  13. package/THREAT_MODEL.md +22 -1
  14. package/docs/ARTIFACT_REFERENCE.md +54 -0
  15. package/docs/CLI_REFERENCE.md +177 -5
  16. package/docs/CROSS_HARNESS_CONTINUITY.md +34 -0
  17. package/docs/DOCUMENTATION_GUIDE.md +31 -0
  18. package/docs/GETTING_STARTED.md +10 -0
  19. package/docs/MCP.md +126 -0
  20. package/docs/RECIPES.md +87 -1
  21. package/docs/RELEASE_CHECKLIST_1_4.md +38 -0
  22. package/docs/RELEASE_CHECKLIST_1_5_MCP.md +78 -0
  23. package/docs/TROUBLESHOOTING.md +243 -40
  24. package/docs/UNIVERSAL_INTEGRATION.md +48 -0
  25. package/package.json +17 -3
  26. package/schemas/execution.schema.json +11 -1
  27. package/schemas/task-recovery.schema.json +61 -0
  28. package/schemas/work-state.schema.json +1 -0
  29. package/src/cli.js +182 -337
  30. package/src/commands/audit.js +5 -0
  31. package/src/commands/doctor.js +22 -0
  32. package/src/commands/inspect.js +6 -0
  33. package/src/commands/migrate-protocol.js +18 -0
  34. package/src/commands/progress.js +6 -2
  35. package/src/commands/protocol-info.js +16 -0
  36. package/src/commands/run-check.js +2 -0
  37. package/src/commands/status.js +17 -0
  38. package/src/commands/task-create.js +42 -3
  39. package/src/commands/task-list.js +14 -1
  40. package/src/commands/task-lock-status.js +29 -0
  41. package/src/commands/task-recover.js +202 -0
  42. package/src/commands/task-repair-legacy-recovery.js +417 -0
  43. package/src/commands/task-resume.js +172 -0
  44. package/src/commands/task-scope.js +23 -4
  45. package/src/commands/task-show.js +21 -7
  46. package/src/commands/task-unlock.js +8 -6
  47. package/src/commands/validate-protocol.js +19 -2
  48. package/src/core/artifact-registry.js +12 -0
  49. package/src/core/artifacts.js +17 -4
  50. package/src/core/audit.js +20 -4
  51. package/src/core/bundles.js +15 -0
  52. package/src/core/cli-command-definitions.js +94 -4
  53. package/src/core/command-executors.js +387 -0
  54. package/src/core/command-input.js +107 -0
  55. package/src/core/command-runtime.js +106 -0
  56. package/src/core/completion-artifacts.js +17 -6
  57. package/src/core/completion-ownership.js +88 -0
  58. package/src/core/completion.js +15 -3
  59. package/src/core/diagnosis.js +15 -11
  60. package/src/core/error-codes.js +136 -1
  61. package/src/core/events.js +239 -9
  62. package/src/core/execution.js +73 -9
  63. package/src/core/filesystem.js +75 -8
  64. package/src/core/inspect.js +27 -0
  65. package/src/core/integration-invocation-policy.js +170 -0
  66. package/src/core/integration-limits.js +20 -0
  67. package/src/core/integration-resources.js +127 -0
  68. package/src/core/next-action-model.js +60 -0
  69. package/src/core/next-action.js +31 -0
  70. package/src/core/phase.js +10 -3
  71. package/src/core/project-root.js +21 -0
  72. package/src/core/protocol-info.js +54 -0
  73. package/src/core/protocol-migration.js +59 -0
  74. package/src/core/reconcile-closure.js +54 -14
  75. package/src/core/recovery-history.js +116 -0
  76. package/src/core/resumability.js +8 -6
  77. package/src/core/schema-validation.js +1 -0
  78. package/src/core/task-claim-state.js +272 -0
  79. package/src/core/task-command.js +8 -4
  80. package/src/core/task-conflict-inspection.js +321 -0
  81. package/src/core/task-context.js +32 -29
  82. package/src/core/task-discovery.js +14 -1
  83. package/src/core/task-lock.js +248 -18
  84. package/src/core/task-migration.js +24 -1
  85. package/src/core/task-paths.js +6 -3
  86. package/src/core/task-recovery-migration.js +192 -0
  87. package/src/core/task-recovery.js +205 -0
  88. package/src/core/task-scope.js +33 -1
  89. package/src/core/templates.js +1 -0
  90. package/src/core/transaction.js +285 -0
  91. package/src/core/work-state.js +70 -6
  92. package/src/integration.js +47 -0
@@ -8,6 +8,7 @@ Do not treat ForgeLoop as vendor-specific, optional, or to follow only "in spiri
8
8
  Use these instructions across the repository while preserving local rules.
9
9
 
10
10
  - Read [`LOOP_ENGINEERING.md`](../LOOP_ENGINEERING.md) and [`PROTOCOL_INTEGRATION.md`](../PROTOCOL_INTEGRATION.md).
11
+ - If an official ForgeLoop structured integration is available in your host, prefer it for protocol operations; otherwise use the project-local ForgeLoop CLI. Never simulate ForgeLoop-managed lifecycle, claim, recovery, ledger, or completion state directly.
11
12
  - Confirm [`PROJECT_PROFILE.md`](../PROJECT_PROFILE.md) from evidence; initialize if in `template` mode.
12
13
  - Select context with [`GUIDE_ROUTER.md`](../GUIDE_ROUTER.md) and report activated guide IDs.
13
14
  - Respect the latest request, scope, and higher-level instructions.
package/AGENTS.md CHANGED
@@ -7,6 +7,7 @@ Do not treat ForgeLoop as vendor-specific, optional, or to follow only "in spiri
7
7
 
8
8
  1. Follow platform rules, the user's latest request, and local instructions first.
9
9
  1. Read [`LOOP_ENGINEERING.md`](./LOOP_ENGINEERING.md) and [`PROTOCOL_INTEGRATION.md`](./PROTOCOL_INTEGRATION.md).
10
+ 1. If an official ForgeLoop structured integration is available in your host, prefer it for protocol operations; otherwise use the project-local ForgeLoop CLI. Never simulate ForgeLoop-managed lifecycle, claim, recovery, ledger, or completion state directly.
10
11
  1. Inspect [`PROJECT_PROFILE.md`](./PROJECT_PROFILE.md). Confirm facts from sources; initialize if in `template` mode.
11
12
  1. Use [`GUIDE_ROUTER.md`](./GUIDE_ROUTER.md) to select relevant guides and report activated guide IDs.
12
13
  1. Make the smallest coherent change, run specific checks, and proportional regression checks.
@@ -1,5 +1,9 @@
1
1
  # Deprecated filename
2
2
 
3
+ > Deprecated since package `1.2.4`; retained as a repository compatibility stub.
4
+ > It is not part of the public integration surface and is scheduled for removal
5
+ > in the next compatibility-breaking release.
6
+
3
7
  ForgeLoop is vendor-neutral and does not use a supported-agent allowlist.
4
8
 
5
9
  The canonical integration contract is:
package/CLAUDE.md CHANGED
@@ -9,6 +9,7 @@ When working in this repository:
9
9
 
10
10
  1. Follow higher-level instructions, the user's latest request, and local rules first.
11
11
  1. Read [`LOOP_ENGINEERING.md`](./LOOP_ENGINEERING.md) and [`PROTOCOL_INTEGRATION.md`](./PROTOCOL_INTEGRATION.md).
12
+ 1. If an official ForgeLoop structured integration is available in your host, prefer it for protocol operations; otherwise use the project-local ForgeLoop CLI. Never simulate ForgeLoop-managed lifecycle, claim, recovery, ledger, or completion state directly.
12
13
  1. Verify [`PROJECT_PROFILE.md`](./PROJECT_PROFILE.md) against real sources; initialize if in `template` mode.
13
14
  1. Consult [`GUIDE_ROUTER.md`](./GUIDE_ROUTER.md), select relevant guides, and announce their IDs.
14
15
  1. Make small changes, run specific checks, and run proportional regression checks.
package/DOCS_INDEX.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Documentation index
2
2
 
3
+ The machine-readable inventory is
4
+ [`docs/documentation-manifest.json`](./docs/documentation-manifest.json). It
5
+ classifies every package-shipped document, names canonical concept owners, and
6
+ records generated/deprecated-document metadata. Normative requirements and
7
+ their implementation/test mappings are in
8
+ [`docs/protocol-requirements.json`](./docs/protocol-requirements.json).
9
+
3
10
  ForgeLoop keeps one canonical process and separates protocol behavior from
4
11
  integration and guide context. Use this map before editing documentation.
5
12
 
@@ -13,7 +20,11 @@ integration and guide context. Use this map before editing documentation.
13
20
  | Artifact and schema reference | [`docs/ARTIFACT_REFERENCE.md`](./docs/ARTIFACT_REFERENCE.md) | Purpose, mutability, and trust classifications of `.forgeloop/` |
14
21
  | Troubleshooting and recovery | [`docs/TROUBLESHOOTING.md`](./docs/TROUBLESHOOTING.md) | Symptom-first recovery and stable error code reference |
15
22
  | Operational recipes | [`docs/RECIPES.md`](./docs/RECIPES.md) | Short copy-paste recipes for daily workflows |
23
+ | Universal integration API | [`docs/UNIVERSAL_INTEGRATION.md`](./docs/UNIVERSAL_INTEGRATION.md) | Programmatic integration subpath, envelope semantics, and consumer map |
24
+ | Local-first MCP adapter | [`docs/MCP.md`](./docs/MCP.md) | stdio default, optional strict loopback HTTP; server modes/capabilities and canonical resources |
16
25
  | Documentation guide | [`docs/DOCUMENTATION_GUIDE.md`](./docs/DOCUMENTATION_GUIDE.md) | Rules and checklist for modifying documentation |
26
+ | ForgeLoop 1.5/MCP release checklist | [`docs/RELEASE_CHECKLIST_1_5_MCP.md`](./docs/RELEASE_CHECKLIST_1_5_MCP.md) | Integration API v1, MCP package, and publication gates |
27
+ | ForgeLoop 1.4 release checklist | [`docs/RELEASE_CHECKLIST_1_4.md`](./docs/RELEASE_CHECKLIST_1_4.md) | Claim-recovery, compatibility, package, and publication gates |
17
28
  | Lifecycle, gates, planning, verification, and recovery | [`LOOP_ENGINEERING.md`](./LOOP_ENGINEERING.md) | Normative process for agents and developer workflows |
18
29
  | Capability levels, discovery, and degradation | [`PROTOCOL_INTEGRATION.md`](./PROTOCOL_INTEGRATION.md) | Vendor-neutral harness contract |
19
30
  | Host/orchestrator integration | [`ORCHESTRATOR_INTEGRATION.md`](./ORCHESTRATOR_INTEGRATION.md) | Serializable phases, transition boundaries, host responsibilities, and no-runtime integration contract |
@@ -39,6 +50,8 @@ integration and guide context. Use this map before editing documentation.
39
50
  | **Fixing a broken or stale state** | [`docs/TROUBLESHOOTING.md`](./docs/TROUBLESHOOTING.md) |
40
51
  | **Looking for quick recipes** | [`docs/RECIPES.md`](./docs/RECIPES.md) |
41
52
  | **Documentation contributor** | [`docs/DOCUMENTATION_GUIDE.md`](./docs/DOCUMENTATION_GUIDE.md) |
53
+ | **Release maintainer (current)** | [`docs/RELEASE_CHECKLIST_1_5_MCP.md`](./docs/RELEASE_CHECKLIST_1_5_MCP.md) |
54
+ | **Release maintainer (historical 1.4)** | [`docs/RELEASE_CHECKLIST_1_4.md`](./docs/RELEASE_CHECKLIST_1_4.md) |
42
55
  | **Protocol architect / maintainer** | [`LOOP_SYSTEM_DESIGN.md`](./LOOP_SYSTEM_DESIGN.md) + [`schemas/`](./schemas/) |
43
56
  | **Security auditor** | [`THREAT_MODEL.md`](./THREAT_MODEL.md) |
44
57
  | **Engineering guide author** | [`GUIDE_ROUTER.md`](./GUIDE_ROUTER.md) + [`ENG/`](./ENG/) |
@@ -50,6 +63,7 @@ integration and guide context. Use this map before editing documentation.
50
63
  - **Check CLI options and syntax**: [`docs/CLI_REFERENCE.md`](./docs/CLI_REFERENCE.md)
51
64
  - **Understand what `.forgeloop/` stores**: [`docs/ARTIFACT_REFERENCE.md`](./docs/ARTIFACT_REFERENCE.md)
52
65
  - **Fix a blocked, stale, or invalid state**: [`docs/TROUBLESHOOTING.md`](./docs/TROUBLESHOOTING.md)
66
+ - **Recover a stale task or reacquire released claims**: [`docs/RECIPES.md`](./docs/RECIPES.md#recipe-15--release-and-reacquire-claims-for-an-abandoned-task)
53
67
  - **Find operational copy-paste commands**: [`docs/RECIPES.md`](./docs/RECIPES.md)
54
68
  - **Read the normative protocol specification**: [`LOOP_ENGINEERING.md`](./LOOP_ENGINEERING.md)
55
69
  - **Integrate a new AI environment**: [`PROTOCOL_INTEGRATION.md`](./PROTOCOL_INTEGRATION.md)
@@ -10,6 +10,27 @@ Compatible agents may persist a handoff checkpoint at:
10
10
  .forgeloop/task-state/<taskKey>/work-state.json
11
11
  ```
12
12
 
13
+ Claim-release recovery has a separate current-state artifact:
14
+
15
+ ```text
16
+ .forgeloop/task-state/<taskKey>/recovery.json
17
+ ```
18
+
19
+ `work-state.json` remains the lifecycle authority. `recovery.json` records a
20
+ request to suspend ordinary mutation and release effective claims; it does not
21
+ change the phase, refresh repository evidence, erase failures, or imply
22
+ completion. Its `recoveryId`, event sequence, previous revision, released
23
+ claims, repository fingerprint, classification, and authority kind are bound
24
+ to the append-only recovery event. Claims are released only after the canonical
25
+ resolver validates that complete relationship. An unresolved recovery event
26
+ with a missing tombstone, or a tombstone without its matching event, is
27
+ `INCONSISTENT`, retains historical claims, and disables mutation. The same
28
+ fail-closed rule applies to completion: `phase: COMPLETE` alone never releases
29
+ claims — the canonical completion ownership proof (validated ledger with the
30
+ task-bound `COMPLETION_VALIDATED` event and coherent state) is required, and a
31
+ forged or unproven COMPLETE state is `INCONSISTENT` with historical claims
32
+ retained.
33
+
13
34
  The file is local, ignored by Git, schema-versioned, and never a replacement
14
35
  for the manifest or the target project profile (installed as
15
36
  `.forgeloop/kit/PROJECT_PROFILE.md`). It contains no secrets and is untrusted
@@ -51,6 +72,14 @@ and rename it into place. The host filesystem's rename guarantee is the
51
72
  atomicity boundary; no database or remote state is involved. A truncated,
52
73
  malformed, or secret-bearing file is invalid and is never resumed silently.
53
74
 
75
+ Lifecycle mutations that change more than one artifact use a task transaction
76
+ under `.forgeloop/.txn/<transactionId>/`. The transaction records every staged
77
+ replacement and append. Ledger appends validate a bounded tail checkpoint and
78
+ stage only the new NDJSON suffix; if publication is interrupted, recovery
79
+ truncates that suffix to its recorded pre-append size. A stale checkpoint never
80
+ authorizes a new sequence number: ForgeLoop rebuilds it from the ledger before
81
+ continuing.
82
+
54
83
  Before resuming, compare:
55
84
 
56
85
  - the task contract fingerprint;
@@ -58,6 +87,25 @@ Before resuming, compare:
58
87
  - the protocol version;
59
88
  - required artifacts and assumptions recorded by the task.
60
89
 
90
+ If validated recovery state is active, ordinary lifecycle mutation fails with
91
+ `E_TASK_RECOVERED`. If recovery ownership is inconsistent, mutation fails with
92
+ `E_TASK_CLAIM_OWNERSHIP_INCONSISTENT`. Resume claim ownership explicitly:
93
+
94
+ ```bash
95
+ forgeloop task-resume --task <id> --json
96
+ ```
97
+
98
+ Optional repeatable `--claim <path>` arguments replace the historical claim set
99
+ only after normal overlap and clean-checkout enforcement succeeds. Recovery
100
+ state deletion, any descriptor update, and `TASK_RECOVERY_RESUMED` are staged
101
+ transactionally. `TASK_RECOVERY_RESUMED` counts as meaningful activity. A
102
+ missing artifact returns `E_TASK_NOT_RECOVERED` only when the ledger also proves
103
+ there is no unresolved recovery; otherwise it is an ownership inconsistency.
104
+
105
+ Never create, delete, or edit `recovery.json` manually. Never remove recovery
106
+ state to resume a task. Never interpret `recovery.json` without validating its
107
+ ledger binding.
108
+
61
109
  Any material difference produces `REVALIDATION_REQUIRED`. A non-Git target
62
110
  reports that branch/HEAD drift is not verifiable. Cheap checks may be rerun,
63
111
  but a completed destructive or publication action is never rerun automatically.
@@ -1275,7 +1275,7 @@ to inspect first.
1275
1275
  `CONTINUITY_CONTEXT_IS_NOT_EVIDENCE`: continuity may guide inspection but can
1276
1276
  never satisfy verification coverage, publication, production readiness, or
1277
1277
  completion. `CONTINUITY_CANNOT_GRANT_AUTHORITY`: continuity cannot authorize an
1278
- installation or external action. The receiving harness MUST reconcile
1278
+ installation or external action. <a id="FL-CONT-001"></a> **FL-CONT-001 — A receiving harness MUST reconcile**
1279
1279
  continuity against the current work state and checkout before acting on it.
1280
1280
 
1281
1281
  ## Multi-task concurrent project state
@@ -1289,7 +1289,7 @@ corruption through three fundamental protocol mechanisms:
1289
1289
  `taskKey` derived as `SHA-256(taskId)` in 64 lowercase hexadecimal characters. All
1290
1290
  task-scoped artifacts (`task.json`, `contract.json`, `routing-result.json`,
1291
1291
  `preflight.json`, `work-state.json`, `events.ndjson`, `execution-receipt.json`,
1292
- `continuity.json`, gates, and execution records) are stored strictly under
1292
+ `continuity.json`, `recovery.json`, gates, and execution records) are stored strictly under
1293
1293
  `.forgeloop/task-state/<taskKey>/`. Shared repository configuration and sources
1294
1294
  (`config.json`, `sources.json`) remain at `.forgeloop/`.
1295
1295
 
@@ -1304,16 +1304,65 @@ corruption through three fundamental protocol mechanisms:
1304
1304
  (`E_TASK_SCOPE_FROZEN`).
1305
1305
  - At verification and completion, Git modifications are validated to ensure no changes
1306
1306
  escaped the task's declared scope (`E_TASK_CHANGE_OUTSIDE_SCOPE`).
1307
+ - `task.json` retains historical claims. Effective claims are empty only after
1308
+ validator-backed `COMPLETE` or when the canonical claim-state resolver
1309
+ validates `recovery.json` against the descriptor, work state, and complete
1310
+ hash-chained recovery history. A tombstone alone never releases claims.
1311
+ - Fake, missing, corrupt, deleted, or mismatched recovery evidence is
1312
+ `INCONSISTENT`: every provable historical claim remains reserved,
1313
+ `mutationAllowed=false`, and overlapping claim acquisition fails with
1314
+ `E_TASK_CLAIM_OWNERSHIP_INCONSISTENT`.
1315
+ - Recovery is not completion. `task-recover` accepts only deterministic
1316
+ `STALE` or `ABANDONED` classifications, preserves work state, receipts,
1317
+ failures, policy, continuity, and repository fingerprints, and suspends
1318
+ ordinary task mutation with `E_TASK_RECOVERED`.
1319
+ - Only `forgeloop task-resume --task <id>` may remove recovery state. It
1320
+ first validates recovery ownership and lifecycle revision, safely settles
1321
+ only an unchanged stale task lease, then reacquires the released (or
1322
+ explicitly supplied) claims through the normal overlap and clean-checkout
1323
+ checks under the project claims lock. A claim held by another task remains
1324
+ unavailable. `TASK_RECOVERY_RESUMED` is meaningful activity.
1307
1325
 
1308
1326
  3. **Per-Task Exclusive Mutex Locking**:
1309
1327
  Mutating lifecycle commands (`advance`, `preflight`, `run-check`, `complete`, etc.)
1310
- acquire an exclusive filesystem lock at `.forgeloop/task-state/<taskKey>/.lock` using
1328
+ acquire an exclusive filesystem lock at `.forgeloop/locks/<taskKey>.lock` using
1311
1329
  atomic creation flags (`wx`). Concurrent mutations on the same task reject with
1312
1330
  `E_TASK_LOCKED`. Read-only commands (`status`, `audit`, `inspect`, `continuity`) bypass
1313
- locking. Stale locks can be cleared with `forgeloop task-unlock --task <id> --force`.
1331
+ locking. Lock inspection distinguishes `NONE`, `LIVE`, `STALE`, `UNKNOWN`,
1332
+ and `CORRUPT`; unknown or corrupt ownership fails closed. Stale-only release
1333
+ compares the observed lock ID, heartbeat, and owner instance before deletion.
1334
+
1335
+ Recovery that changes claim ownership acquires the project claims lock before
1336
+ the task lock, safely settles an unchanged stale lease, then revalidates phase,
1337
+ work-state revision, ledger sequence, and the `STALE`/`ABANDONED` allowlist
1338
+ before committing `recovery.json` and its append-only event in one transaction.
1339
+ The project claims lock itself uses the same `NONE`/`LIVE`/`STALE`/`UNKNOWN`/
1340
+ `CORRUPT` lease classification and CAS-safe quarantine/restore semantics;
1341
+ unknown, corrupt, or concurrently replaced ownership fails with
1342
+ `E_PROJECT_CLAIMS_LOCK_INCONSISTENT`.
1343
+ The standalone acknowledgement flag does not grant host authority:
1344
+
1345
+ ```text
1346
+ --acknowledge-recovery
1347
+
1348
+ HOST_ATTESTED
1349
+ ```
1350
+
1351
+ `forgeloop next --task <id> --json` maps conflict evidence to structured
1352
+ `RECONCILE_CLOSURE`, `RECOVER_TASK`, `RESUME_RECOVERED_TASK`, or
1353
+ `RESOLVE_RECOVERY_INCONSISTENCY` guidance. A `RECOVERABLE` task must use its
1354
+ canonical reconciliation path and cannot release claims through `task-recover`.
1314
1355
 
1315
1356
  4. **Task Resolution & Legacy Migration**:
1316
1357
  Commands select their target task via `--task <id>`, the `FORGELOOP_TASK` environment
1317
- variable, or implicit single-task fallback. If multiple active tasks exist without a
1318
- selector, ForgeLoop fails closed with `E_TASK_AMBIGUOUS`. Legacy ForgeLoop 1.0 single-task
1358
+ variable, or implicit single-task fallback. Only mutation-active tasks are
1359
+ implicit candidates; recovered, inconsistent, and `COMPLETE` tasks remain
1360
+ explicitly addressable but do not make unrelated work ambiguous. If multiple
1361
+ mutation-active tasks exist without a selector, ForgeLoop fails closed with
1362
+ `E_TASK_AMBIGUOUS`. Legacy ForgeLoop 1.0 single-task
1319
1363
  layouts can be migrated into namespaced layout using `forgeloop task-migrate`.
1364
+
1365
+ A project containing active task recovery state requires ForgeLoop 1.4.0 or
1366
+ newer.
1367
+ <a id="FL-CLAIM-002"></a> **FL-CLAIM-002 — Harnesses that cannot validate task-recovery schema v1 and its linked ledger history MUST refuse**
1368
+ ownership mutation rather than fall back to descriptor-only claims.
@@ -218,6 +218,16 @@ The threat model records path, symlink, artifact, secret, stale-state,
218
218
  publication, schema, dependency, and resource-limit boundaries with their
219
219
  mitigations, residual limitations, and executable evidence.
220
220
 
221
+ Persistent task mutations use a task lease lock and a recoverable transaction
222
+ journal. State writes carry a monotonically increasing revision, while event
223
+ appends are serialized and hash chained. The ledger keeps a validated tail
224
+ checkpoint (`seq` and last hash), so a normal append stages and publishes only
225
+ its new NDJSON suffix; a mismatched tail forces a full checkpoint rebuild. A
226
+ crash during a multi-file publish leaves a journal that `doctor --fix` can roll
227
+ back deterministically — including truncating an interrupted ledger suffix to
228
+ its recorded pre-append size. It never permits a partial artifact set to be
229
+ presented as a completed protocol state.
230
+
221
231
  ### `ENG/*.md`
222
232
 
223
233
  Nine canonical guides cover:
@@ -370,12 +380,33 @@ registry. If it is not available yet, the same commands can run as
370
380
  documents into `.forgeloop/kit/`, keeps only native instruction shims at the
371
381
  target root, and leaves project-scoped configuration under `.forgeloop/` while
372
382
  isolating modern mutable task protocol state (contract, route, gate, state,
373
- event, preflight, and receipt artifacts) under
383
+ event, preflight, receipt, and recovery artifacts) under
374
384
  `.forgeloop/task-state/<taskKey>/`. Legacy singleton artifacts remain under
375
385
  `.forgeloop/` for compatibility and migration only. Manual copying must
376
386
  preserve that target layout; copying package-source root files directly is not
377
387
  equivalent to `forgeloop init`.
378
388
 
389
+ Recovery uses a relational state model: `work-state.json` owns the lifecycle
390
+ phase, `task.json` retains historical claims, `recovery.json` records current
391
+ suspension, and the complete hash-chained ledger proves recovery/resume cycles.
392
+ Only their canonical validated projection can release effective claims. The
393
+ same holds for completion: `RELEASED_BY_COMPLETION` requires the canonical
394
+ completion ownership proof (COMPLETE phase plus a validated ledger containing
395
+ the task-bound `COMPLETION_VALIDATED` event with coherent state and no
396
+ contradicting later lifecycle event); a manually forged COMPLETE state is
397
+ `INCONSISTENT`, retains historical claims, and disables mutation. Any
398
+ missing, corrupt, forged, or mismatched relationship is `INCONSISTENT`, retains
399
+ historical claims, and disables mutation. Recovery never fabricates completion;
400
+ `task-resume` is the only path that rechecks and reacquires ownership before
401
+ removing the recovery artifact. Project claim serialization always precedes
402
+ the per-task lock for create, scope, recover, and resume operations, and both
403
+ lock classes use lease classification plus CAS-safe stale settlement. Task
404
+ locks additionally require complete owner identity (`taskId`, `lockId`,
405
+ `ownerInstanceId`, `operation`, heartbeat, positive lease): incomplete identity
406
+ classifies `UNKNOWN` and is never eligible for stale release. Implicit task
407
+ selection distinguishes read-only discoverability (`READ`: any single healthy
408
+ task) from mutation authority (`MUTATION`: only operationally active tasks).
409
+
379
410
  The README explains the file set, activation behavior, current/relative/absolute
380
411
  target installation, first-run profile flow, local validation commands, and safe
381
412
  update practice.
@@ -108,6 +108,36 @@ workflows that do not automatically discover one of the default files:
108
108
 
109
109
  A developer or custom automation can execute ForgeLoop identically to an AI agent.
110
110
 
111
+ ### Compatibility handshake
112
+
113
+ Before a harness creates or resumes task state, it can read the complete
114
+ machine-readable compatibility boundary:
115
+
116
+ ```bash
117
+ forgeloop protocol-info --json
118
+ ```
119
+
120
+ When a compatibility change requires persisted state conversion, inspect it
121
+ before writing anything:
122
+
123
+ ```bash
124
+ forgeloop migrate-protocol --to 1 --dry-run --json
125
+ ```
126
+
127
+ `migrate-protocol` accepts only versions with an explicit migration in the
128
+ installed release. Unsupported targets fail without rewriting state. The
129
+ current protocol's only supported conversion is the receipt-backed legacy
130
+ singleton-layout migration; a future protocol version must add its own
131
+ validated migration before it can become an accepted `--to` value.
132
+
133
+ The response separates package and protocol identity. `packageVersion` is the
134
+ installed CLI version; `readsProtocol` and `writesProtocol` enumerate protocol
135
+ versions supported by this CLI; `readsSchemaVersions` and
136
+ `writesSchemaVersions` map every public artifact schema to its supported
137
+ versions. A harness must not infer compatibility from the package version
138
+ alone, and it must fail closed when its required protocol or schema version is
139
+ absent from the relevant list.
140
+
111
141
  ## CLI resolution policy
112
142
 
113
143
  Lifecycle-owned protocol state must be managed through the project-local ForgeLoop CLI:
@@ -128,6 +158,7 @@ The following protocol artifacts are strictly owned by ForgeLoop:
128
158
  - `.forgeloop/task-state/<taskKey>/work-state.json`
129
159
  - `.forgeloop/task-state/<taskKey>/events.ndjson`
130
160
  - `.forgeloop/task-state/<taskKey>/execution-receipt.json`
161
+ - `.forgeloop/task-state/<taskKey>/recovery.json`
131
162
  - `.forgeloop/task-state/<taskKey>/executions/<executionId>.json`
132
163
  - Canonical check, evidence, and terminal-result state
133
164
 
@@ -201,6 +232,21 @@ actor claim ≠ operator grant
201
232
  Authority cannot be self-issued by the actor consuming it. Boolean fields inside
202
233
  verification evidence are not sufficient proof of installation authority.
203
234
 
235
+ The same rule applies to claim-release recovery. The standalone
236
+ `--acknowledge-recovery` flag records `CALLER_ACKNOWLEDGED`; it is an explicit
237
+ request, not a host grant. The deprecated `--operator-authorized` spelling is
238
+ only a compatibility alias and has identical caller-acknowledgement semantics.
239
+ `HOST_ATTESTED` recovery metadata is valid only when a host integration supplies
240
+ a trusted grant reference through a boundary the active actor cannot mint or
241
+ replace. The standalone CLI does not expose such a self-attestation option.
242
+
243
+ Claim ownership is a validated relationship, not an artifact preference.
244
+ <a id="FL-CLAIM-001"></a> **FL-CLAIM-001 — Every harness MUST consume the canonical claim-state resolver**
245
+ over the descriptor, work state, recovery artifact, and complete validated
246
+ recovery history. The resolver retains historical claims and disables mutation
247
+ when that relationship is `INCONSISTENT`; reading `recovery.json` alone is
248
+ non-conforming.
249
+
204
250
  ### Authority provenance
205
251
 
206
252
  Authority provenance is external to actor-authored project state. An external
@@ -324,4 +370,29 @@ ForgeLoop integrates executable verification rules directly into the lifecycle:
324
370
  - **Autonomy Principle**: Non-interactive execution is preserved. Tools, commands, and validators operate unattended with standard input closed and without interactive prompt dependencies.
325
371
  - **Baseline Protection**: Re-recording baseline debt mid-task is rejected with `E_BASELINE_RECORD_DURING_ACTIVE_TASK`; only monotonic ratchet-down is allowed during active tasks (`baseline --update`). Explicit re-recording requires `--policy-reset-authorized`.
326
372
  - **Semantic Recovery**: `forgeloop next` maps policy findings directly to actionable recovery actions (`RESTORE_POLICY`, `REPAIR_CHECKER`, `REPAIR_POLICY`, `REVERIFY_AFTER_POLICY_CHANGE`, `RESTORE_BASELINE`, `CONTINUE_WITH_EXISTING_BASELINE`, `RESOLVE_INERT_CHECK`).
373
+ - **Claim Recovery**: `forgeloop next` maps validated task ownership to `RECONCILE_CLOSURE`, `RECOVER_TASK`, `RESUME_RECOVERED_TASK`, or `RESOLVE_RECOVERY_INCONSISTENCY`. `task-recover` is restricted to `STALE`/`ABANDONED`; it writes durable `recovery.json` plus an append-only event without changing lifecycle evidence. `task-resume` validates the same ownership projection, safely settles an unchanged stale task lock, reuses canonical scope conflict checks, and removes recovery state transactionally.
327
374
  - **Task Scoping**: Task-specific policy snapshots and state live under `.forgeloop/task-state/<taskKey>/` to ensure clean multi-task isolation and cross-harness continuity.
375
+
376
+ ## Structured integration surfaces
377
+
378
+ When a host provides an official ForgeLoop structured integration, prefer it
379
+ for protocol operations; otherwise use the project-local ForgeLoop CLI. Both
380
+ surfaces execute the same canonical commands and share one protocol authority:
381
+ `.forgeloop/` state written only by ForgeLoop itself.
382
+
383
+ - `@cassiomc1/forgeloop/integration` (integration API version 1): the
384
+ transport-neutral programmatic runtime. Domain rejections keep `ok:true`
385
+ with a non-zero exit code; public error codes are preserved verbatim.
386
+ - `@cassiomc1/forgeloop-mcp` (local stdio MCP): an adapter over the same API.
387
+ It never edits `.forgeloop/` state directly, never synthesizes authority,
388
+ and never derives claim ownership outside the canonical resolver
389
+ (`features.integrationApi.version >= 1` in `protocol-info --json`).
390
+
391
+ ForgeLoop applicability never depends on MCP availability: instruction-only
392
+ hosts remain fully supported through the CLI and instruction adapters.
393
+
394
+ `protocol-info --json` advertises claim-recovery capability version 1 under
395
+ `features.taskClaimRecovery`. A project containing active task recovery state
396
+ requires ForgeLoop 1.4.0 or newer.
397
+ <a id="FL-CLAIM-003"></a> **FL-CLAIM-003 — A reader without `validatedClaimProjection=true` MUST fail closed**
398
+ and must not mutate claims.
package/README.md CHANGED
@@ -4,7 +4,13 @@
4
4
  <img src="./docs/assets/eng_readme_forgeloop.png" alt="ForgeLoop — Loop Engineering for AI Agents" width="100%">
5
5
  </p>
6
6
 
7
+ [![CodeQL](https://github.com/cassiomc1/forgeloop/actions/workflows/codeql.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/codeql.yml)
8
+ [![Dependency review](https://github.com/cassiomc1/forgeloop/actions/workflows/dependency-review.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/dependency-review.yml)
7
9
  [![Docs quality](https://github.com/cassiomc1/forgeloop/actions/workflows/docs-quality.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/docs-quality.yml)
10
+ [![ForgeLoop audit](https://github.com/cassiomc1/forgeloop/actions/workflows/forgeloop-audit.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/forgeloop-audit.yml)
11
+ [![Publish npm package](https://github.com/cassiomc1/forgeloop/actions/workflows/npm-publish.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/npm-publish.yml)
12
+ [![Package smoke](https://github.com/cassiomc1/forgeloop/actions/workflows/package-smoke.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/package-smoke.yml)
13
+ [![Release notes](https://github.com/cassiomc1/forgeloop/actions/workflows/release-notes.yml/badge.svg?branch=main)](https://github.com/cassiomc1/forgeloop/actions/workflows/release-notes.yml)
8
14
 
9
15
  ForgeLoop is a portable, vendor-neutral protocol for AI-assisted development
10
16
  and developer workflows. It turns an outcome into a contract, deterministic
@@ -52,6 +58,45 @@ frontmatter. Repository validators keep the catalog and metadata synchronized.
52
58
 
53
59
  ## Quickstart
54
60
 
61
+ ### Demonstração em 60 segundos
62
+
63
+ Em um diretório descartável, inicialize o kit e crie uma tarefa isolada. O
64
+ resultado é determinístico e pode ser inspecionado por qualquer harness
65
+ compatível:
66
+
67
+ ```bash
68
+ npx @cassiomc1/forgeloop init
69
+ forgeloop task-create --task demo --claim src --json
70
+ forgeloop route --task demo --work clean-code --json
71
+ forgeloop preflight --task demo --json
72
+ forgeloop next --task demo --json
73
+ ```
74
+
75
+ O último comando informa a ação segura seguinte; ele não executa código nem
76
+ agenda agentes.
77
+
78
+ Antes de um harness criar ou retomar uma tarefa, ele pode confirmar a
79
+ compatibilidade pública sem depender de detalhes internos:
80
+
81
+ <!-- FORGELOOP EXAMPLE: readme:compatibility | exit=0 | json.protocolVersion=1 -->
82
+ ```bash
83
+ forgeloop protocol-info --json
84
+ ```
85
+ <!-- END FORGELOOP EXAMPLE -->
86
+
87
+ ### Responsabilidades
88
+
89
+ | Responsabilidade | ForgeLoop | Harness ou desenvolvedor |
90
+ | --- | --- | --- |
91
+ | Validar contrato e rotas | Sim | Fornece intenção e sinais |
92
+ | Implementar código | Não | Sim |
93
+ | Registrar proveniência de comando | Sim, com `run-check` | Fornece comando e ambiente |
94
+ | Validar conclusão | Sim | Fornece trabalho e evidência reais |
95
+ | Agendar agentes ou inferência LLM | Não | Externo ao protocolo |
96
+
97
+ Para uma troca concreta entre ferramentas, veja a
98
+ [continuidade entre harnesses](./docs/CROSS_HARNESS_CONTINUITY.md).
99
+
55
100
  From a published package, initialize a target project with:
56
101
 
57
102
  ```bash
@@ -150,6 +195,15 @@ forgeloop task-create --task auth-feature --claim src/auth --claim tests/auth --
150
195
  # List active and completed tasks
151
196
  forgeloop task-list --json
152
197
 
198
+ # Ask for deterministic conflict/recovery guidance
199
+ forgeloop next --task auth-feature --json
200
+
201
+ # Only for a task classified STALE or ABANDONED: release effective claims
202
+ forgeloop task-recover --task auth-feature --acknowledge-recovery --json
203
+
204
+ # Reacquire conflict-free claims before mutating a recovered task again
205
+ forgeloop task-resume --task auth-feature --json
206
+
153
207
  # Run standard lifecycle commands targeting the task
154
208
  forgeloop route --task auth-feature --work clean-code --surface backend
155
209
  forgeloop preflight --task auth-feature --json
@@ -160,6 +214,16 @@ forgeloop complete --task auth-feature --json
160
214
  forgeloop task-migrate --json
161
215
  ```
162
216
 
217
+ Recovery is not completion. Effective claims become empty only when the
218
+ canonical claim-state resolver validates the relationship between `task.json`,
219
+ `work-state.json`, `recovery.json`, and the complete hash-chained recovery
220
+ history. Fake, missing, corrupt, deleted, or mismatched recovery evidence is
221
+ `INCONSISTENT`: historical claims remain reserved and mutation remains
222
+ disabled. The standalone acknowledgement flag is not host-attested authority.
223
+ `task-resume` removes recovery state only after validated ownership, stale-lock
224
+ settlement, normal claim-overlap, and clean-checkout checks succeed. Never
225
+ create, edit, or delete `recovery.json` manually.
226
+
163
227
  ### Executable policy verification & brownfield baselines
164
228
 
165
229
  ForgeLoop enforces automated, non-interactive verification rules (`rules.json`) with zero interactive dependencies:
@@ -227,6 +291,11 @@ Consumers must reject unknown artifact fields rather than silently treating
227
291
  unrecognized protocol data as valid. The compatibility marker is
228
292
  [`tests/fixtures/compatibility/protocol-v1.json`](./tests/fixtures/compatibility/protocol-v1.json).
229
293
 
294
+ A project containing active task recovery state requires ForgeLoop 1.4.0 or
295
+ newer. A reader that does not advertise
296
+ `features.taskClaimRecovery.validatedClaimProjection=true` must fail closed;
297
+ it must not infer current ownership from `task.json` or `recovery.json` alone.
298
+
230
299
  ## Security and dependency boundary
231
300
 
232
301
  The runtime uses Node built-ins only and does not install agents, providers,
@@ -240,6 +309,9 @@ repository policy allows only ESLint, c8, and Mermaid CLI as development
240
309
  dependencies; `npm run dependency:policy` fails if runtime or unapproved
241
310
  dependencies appear.
242
311
 
312
+ Para reportar vulnerabilidades ou contribuir com alterações, consulte
313
+ [`SECURITY.md`](./SECURITY.md) e [`CONTRIBUTING.md`](./CONTRIBUTING.md).
314
+
243
315
  ## Autonomous blind-run isolation
244
316
 
245
317
  The repository does not claim a live blind conformance result for an external
@@ -330,3 +402,17 @@ Task-scoped mutable protocol state is stored under
330
402
 
331
403
  For document ownership, guide routing, capability degradation, and integration
332
404
  details, start at [`DOCS_INDEX.md`](./DOCS_INDEX.md).
405
+
406
+ ## Programmatic integration and MCP
407
+
408
+ ForgeLoop exposes a stable programmatic surface:
409
+
410
+ ```js
411
+ import { executeForgeLoopCommand } from "@cassiomc1/forgeloop/integration";
412
+ ```
413
+
414
+ The local MCP server (`@cassiomc1/forgeloop-mcp`, stdio) is an adapter over
415
+ this exact API — it never reimplements ForgeLoop. See
416
+ [`docs/UNIVERSAL_INTEGRATION.md`](./docs/UNIVERSAL_INTEGRATION.md) and
417
+ [`docs/MCP.md`](./docs/MCP.md). MCP is optional; the CLI and instruction-only
418
+ hosts remain fully supported without it.
package/TERMINOLOGY.md CHANGED
@@ -18,9 +18,24 @@
18
18
  | Runtime | A process that owns execution, scheduling, model calls, or persistence; `ForgeLoop` intentionally does not provide one. |
19
19
  | Evidence kind | One of `OBSERVED`, `INFERRED`, `NOT_VERIFIED`, or `BLOCKED`; evidence never upgrades an unverified claim by itself. |
20
20
  | Required artifact | A checkpoint-recorded relative path and SHA-256 hash that must still match before resume. |
21
+ | Integration API | The stable programmatic surface (`@cassiomc1/forgeloop/integration`) used by structured consumers instead of parsing CLI output. |
22
+ | MCP adapter | The local-first Model Context Protocol server package; an adapter over canonical ForgeLoop commands, never a second implementation. |
23
+ | Server mode | The MCP launch policy tier (`readonly`, `safe`, `full`) that determines which tool classes are available. |
24
+ | Launch capability | A process-scoped, immutable MCP flag (`--allow-*`) required by higher-risk invocation classes; tool input cannot grant it. |
25
+ | Claim state | Canonical ownership classification (`ACTIVE`, `RELEASED_BY_COMPLETION`, `RELEASED_BY_RECOVERY`, `INCONSISTENT`) produced only by the validated claim resolver. |
26
+ | Historical write claims | Claims recorded as evidence in the task descriptor/recovery history after validated release. |
27
+ | Effective write claims | The claims currently enforced against overlapping acquisition; empty only for validated completion or recovery. |
28
+ | Completion ownership proof | The validated lifecycle/ledger evidence (canonical `COMPLETION_VALIDATED` + coherence) required before COMPLETE releases claims. |
29
+ | Caller acknowledgement | Explicit current-caller authorization for recovery actions; never equivalent to host attestation. |
30
+ | Legacy recovery migration | The narrow append-only repair that materializes one recognized historical recovery boundary into the modern durable representation. |
21
31
  | Conformance | Relationship validation across route, state, receipt, task brief, and delegated-result artifacts. |
22
32
  | Universal applicability | ForgeLoop applies whenever an execution environment discovers a project adapter, regardless of model, provider, agent, IDE, or tool name. |
23
33
  | Integration level | The capability tier of an execution environment (`INSTRUCTION_DISCOVERED`, `PROTOCOL_CAPABLE`, `PROTOCOL_LIMITED`, `CONFORMANCE_VERIFIED`). |
34
+ | Recovered task | A non-terminal task whose ordinary mutation authority is suspended and whose effective write claims are released by durable `recovery.json` state. |
35
+ | Recovery acknowledgement | A caller declaration that it intends to recover a task classified `STALE` or `ABANDONED`; it is not a host-attested authority grant. |
36
+ | Historical claims | The write claims retained in `task.json` as task history, including while recovery releases their active ownership. |
37
+ | Effective claims | The claims currently enforced for ownership conflicts: descriptor claims for an active task, or an empty set after validator-backed completion or active recovery. |
38
+ | Claim reacquisition | The serialized `task-resume` operation that rechecks conflicts and checkout cleanliness before removing recovery state and restoring mutation authority. |
24
39
 
25
40
  | Execution continuity | Bounded current-task implementation context used to resume the same ForgeLoop task across sessions or harnesses. |
26
41
  | Continuity artifact | `.forgeloop/continuity.json`; non-evidence operational context bound to canonical work state. |
@@ -195,3 +195,18 @@ The contextual frontend taste guide is informed by Taste Skill:
195
195
  ForgeLoop includes a short, adapted guide under `ENG/taste-frontend-eng.md`.
196
196
  It does not vendor upstream runtime code, depend on its repository at runtime,
197
197
  or make its prescriptive examples universal.
198
+
199
+ ## Runtime dependencies with upstream notices
200
+
201
+ ### Model Context Protocol SDK (MCP package only)
202
+
203
+ - Packages: `@modelcontextprotocol/server` and `@modelcontextprotocol/client`
204
+ (test/smoke only), used by `integrations/mcp`. Published from the canonical
205
+ upstream repository:
206
+ [modelcontextprotocol/typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk).
207
+ - License declared by the upstream project: MIT.
208
+ - Use in this collection: official SDK transport/server primitives for the
209
+ local stdio ForgeLoop MCP adapter.
210
+ - Boundary: the ForgeLoop core package (`@cassiomc1/forgeloop`) has no
211
+ dependency on the MCP SDK; the SDK ships only inside
212
+ `@cassiomc1/forgeloop-mcp`. Review upstream terms before redistribution.