@cassiomc1/forgeloop 1.2.1 → 1.2.3

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 (65) hide show
  1. package/.cursor/rules/project-loop.mdc +1 -1
  2. package/.github/copilot-instructions.md +1 -1
  3. package/AGENTS.md +1 -1
  4. package/CLAUDE.md +1 -1
  5. package/DOCS_INDEX.md +3 -0
  6. package/ENG/design-code-eng.md +59 -0
  7. package/ENG/premium-sites-studio-eng.md +28 -0
  8. package/LOOP_ENGINEERING.md +23 -0
  9. package/LOOP_SYSTEM_DESIGN.md +9 -5
  10. package/ORCHESTRATOR_INTEGRATION.md +37 -4
  11. package/PROTOCOL_INTEGRATION.md +13 -0
  12. package/README.md +34 -2
  13. package/TERMINOLOGY.md +10 -0
  14. package/THIRD_PARTY_NOTICES.md +34 -0
  15. package/THREAT_MODEL.md +12 -1
  16. package/docs/ARTIFACT_REFERENCE.md +150 -0
  17. package/docs/CLI_REFERENCE.md +263 -30
  18. package/docs/CROSS_HARNESS_CONTINUITY.md +1 -0
  19. package/docs/DOCUMENTATION_GUIDE.md +41 -4
  20. package/docs/GETTING_STARTED.md +9 -4
  21. package/docs/RECIPES.md +31 -1
  22. package/docs/TROUBLESHOOTING.md +191 -0
  23. package/package.json +1 -1
  24. package/schemas/policy-baseline.schema.json +26 -0
  25. package/schemas/policy-discovery.schema.json +45 -0
  26. package/schemas/policy-lock.schema.json +16 -0
  27. package/schemas/policy-rules.schema.json +48 -0
  28. package/schemas/policy-snapshot.schema.json +16 -0
  29. package/src/cli.js +69 -1
  30. package/src/commands/baseline.js +120 -0
  31. package/src/commands/init.js +304 -6
  32. package/src/commands/policy-diff.js +51 -0
  33. package/src/commands/policy-discover.js +42 -0
  34. package/src/commands/policy-status.js +33 -0
  35. package/src/commands/profile-interview.js +50 -0
  36. package/src/commands/reconcile-closure.js +49 -0
  37. package/src/commands/rule-verify.js +36 -0
  38. package/src/commands/validate-receipt.js +38 -3
  39. package/src/core/artifact-registry.js +60 -0
  40. package/src/core/audit.js +24 -0
  41. package/src/core/cli-command-definitions.js +114 -7
  42. package/src/core/cli-metadata.js +1 -1
  43. package/src/core/completion-artifacts.js +29 -3
  44. package/src/core/completion.js +101 -10
  45. package/src/core/error-codes.js +227 -0
  46. package/src/core/events.js +22 -0
  47. package/src/core/execution-prerequisites.js +38 -20
  48. package/src/core/execution.js +20 -3
  49. package/src/core/native-adapters.js +14 -4
  50. package/src/core/next-action-model.js +9 -0
  51. package/src/core/next-action.js +128 -82
  52. package/src/core/policy-adapters.js +276 -0
  53. package/src/core/policy-baseline.js +144 -0
  54. package/src/core/policy-diff.js +133 -0
  55. package/src/core/policy-discovery.js +225 -0
  56. package/src/core/policy-engine.js +533 -0
  57. package/src/core/policy-mutation.js +139 -0
  58. package/src/core/preflight-consistency.js +23 -15
  59. package/src/core/preflight.js +65 -1
  60. package/src/core/reconcile-closure.js +175 -0
  61. package/src/core/schema-validation.js +6 -0
  62. package/src/core/task-context.js +11 -0
  63. package/src/core/task-discovery.js +67 -1
  64. package/src/core/task-paths.js +9 -0
  65. package/src/core/templates.js +5 -0
@@ -25,6 +25,11 @@ All artifact schemas are defined in `schemas/*.schema.json`. Persisted artifact
25
25
  | `task-state/<task-key>/continuity.json` | `continuity` | Agent Or Harness | Mutable Handoff Notes | Non Evidence Handoff |
26
26
  | `task-state/<task-key>/execution-receipt.json` | `execution-receipt` | Protocol Compiled | Atomic Compilation | Evidence Compilation |
27
27
  | `task-state/<task-key>/executions/exec-<id>.json` | `execution` | Protocol Executed | Immutable Once Written | Execution Provenance |
28
+ | `policy/rules.json` | `policy-rules` | Operator Or Agent | Mutable Configuration | Policy Specification |
29
+ | `policy/discovery.json` | `policy-discovery` | Protocol Generated | Mutable On Discovery | Discovered Policy Specification |
30
+ | `policy/baseline.json` | `policy-baseline` | Protocol Generated Or Operator | Monotonic Ratchet Down | Brownfield Baseline |
31
+ | `policy/policy.lock` | `policy-lock` | Protocol Generated | Atomic Digest Compilation | Policy Integrity Lock |
32
+ | `task-state/<task-key>/policy-snapshot.json` | `policy-snapshot` | Protocol Generated | Mutable Before Execution | Task Policy Attestation |
28
33
 
29
34
  <!-- END FORGELOOP GENERATED: artifact-registry -->
30
35
 
@@ -440,3 +445,148 @@ Canonical task descriptor declaring task identity, key, timestamps, and write cl
440
445
  - `writeClaims` *(array<string>, required)*
441
446
 
442
447
  <!-- END FORGELOOP GENERATED: schema:task-descriptor -->
448
+
449
+ ---
450
+
451
+ ### 2.14 `policy/rules.json`
452
+
453
+ <!-- forgeloop-doc: schema=policy-rules artifact=.forgeloop/policy/rules.json -->
454
+
455
+ Repository-level executable policy rules declaring verification constraints.
456
+
457
+ #### Canonical Fields
458
+
459
+ <!-- BEGIN FORGELOOP GENERATED: schema:policy-rules -->
460
+
461
+ - `schemaVersion` *(number, required, const: 1)*
462
+ - `rules` *(array<object>, required)*
463
+ - `id` *(string, required, minLength: 1)*
464
+ - `severity` *(string, required, enum: `HIGH`, `MEDIUM`, `LOW`, `INFO`)*
465
+ - `source` *(string, required, enum: `builtin`, `discovered`, `project`)*
466
+ - `blocking` *(boolean, required)*
467
+ - `why` *(string, required, minLength: 1)*
468
+ - `fix` *(string, required, minLength: 1)*
469
+ - `confidence` *(string, optional, enum: `HIGH`, `MEDIUM`, `LOW`, `UNKNOWN`)*
470
+ - `scope` *(object, optional)*
471
+ - `includes` *(array<string>, optional)*
472
+ - `excludes` *(array<string>, optional)*
473
+ - `check` *(object, required)*
474
+ - `type` *(string, required, minLength: 1)*
475
+ - `adapter` *(string, optional)*
476
+ - `command` *(array<string>, optional)*
477
+ - `threshold` *(number, optional)*
478
+ - `parameters` *(object, optional)*
479
+
480
+ <!-- END FORGELOOP GENERATED: schema:policy-rules -->
481
+
482
+ ---
483
+
484
+ ### 2.15 `policy/discovery.json`
485
+
486
+ <!-- forgeloop-doc: schema=policy-discovery artifact=.forgeloop/policy/discovery.json -->
487
+
488
+ Automated non-interactive discovery report recording inferred architecture, conventions, and confidence scores.
489
+
490
+ #### Canonical Fields
491
+
492
+ <!-- BEGIN FORGELOOP GENERATED: schema:policy-discovery -->
493
+
494
+ - `schemaVersion` *(number, required, const: 1)*
495
+ - `languages` *(array<string>, required)*
496
+ - `testing` *(object, required)*
497
+ - `detected` *(boolean, required)*
498
+ - `command` *(array<string>, optional)*
499
+ - `framework` *(string, optional)*
500
+ - `confidence` *(string, required, enum: `HIGH`, `MEDIUM`, `LOW`, `UNKNOWN`)*
501
+ - `linting` *(object, required)*
502
+ - `detected` *(boolean, required)*
503
+ - `command` *(array<string>, optional)*
504
+ - `tool` *(string, optional)*
505
+ - `confidence` *(string, required, enum: `HIGH`, `MEDIUM`, `LOW`, `UNKNOWN`)*
506
+ - `architecture` *(object, required)*
507
+ - `value` *(string,null, optional)*
508
+ - `confidence` *(string, required, enum: `HIGH`, `MEDIUM`, `LOW`, `UNKNOWN`)*
509
+ - `enforcement` *(string, required, enum: `BLOCKING`, `ADVISORY`, `NONE`)*
510
+ - `discoveredRules` *(array<object>, required)*
511
+
512
+ <!-- END FORGELOOP GENERATED: schema:policy-discovery -->
513
+
514
+ ---
515
+
516
+ ### 2.16 `policy/baseline.json`
517
+
518
+ <!-- forgeloop-doc: schema=policy-baseline artifact=.forgeloop/policy/baseline.json -->
519
+
520
+ Brownfield policy baseline recording tolerated legacy violations by cryptographic fingerprint.
521
+
522
+ #### Canonical Fields
523
+
524
+ <!-- BEGIN FORGELOOP GENERATED: schema:policy-baseline -->
525
+
526
+ - `schemaVersion` *(number, required, const: 1)*
527
+ - `createdAt` *(string, required, minLength: 1)*
528
+ - `entries` *(array<object>, required)*
529
+ - `ruleId` *(string, required, minLength: 1)*
530
+ - `fingerprints` *(array<string>, required)*
531
+ - `reviewBy` *(string, optional)*
532
+ - `details` *(array<object>, optional)*
533
+
534
+ <!-- END FORGELOOP GENERATED: schema:policy-baseline -->
535
+
536
+ ---
537
+
538
+ ### 2.17 `policy/policy.lock`
539
+
540
+ <!-- forgeloop-doc: schema=policy-lock artifact=.forgeloop/policy/policy.lock -->
541
+
542
+ Cryptographic policy digest lock securing effective rules and baseline state.
543
+
544
+ The lock protects the **effective policy** — built-in rules plus discovered
545
+ rules plus project rules/overrides, combined with the baseline. `algorithm`,
546
+ `digest`, `rulesDigest`, and `baselineDigest` all participate in lock integrity
547
+ validation; a disagreement with the current effective policy produces
548
+ `E_POLICY_LOCK_MISMATCH`. `capturedAt` is informational metadata only — it is
549
+ not part of semantic policy identity, and changing it alone does not represent
550
+ a policy change. A missing or malformed lock fails closed rather than being
551
+ silently ignored.
552
+
553
+ #### Canonical Fields
554
+
555
+ <!-- BEGIN FORGELOOP GENERATED: schema:policy-lock -->
556
+
557
+ - `schemaVersion` *(number, required, const: 1)*
558
+ - `algorithm` *(string, required, const: `sha256`)*
559
+ - `digest` *(string, required, minLength: 1)*
560
+ - `rulesDigest` *(string, required)*
561
+ - `baselineDigest` *(string, required)*
562
+ - `capturedAt` *(string, optional)*
563
+
564
+ <!-- END FORGELOOP GENERATED: schema:policy-lock -->
565
+
566
+ ---
567
+
568
+ ### 2.18 `task-state/<taskKey>/policy-snapshot.json`
569
+
570
+ <!-- forgeloop-doc: schema=policy-snapshot artifact=.forgeloop/task-state/<task-key>/policy-snapshot.json -->
571
+
572
+ Task-scoped immutable snapshot of effective policy captured during preflight to detect policy drift.
573
+
574
+ A snapshot binds the task to the policy that was authorized at activation:
575
+ `policyDigest`, the effective `rules`, semantic `baseline` entries, and
576
+ `baselineDigest`. Later policy changes are classified by semantic diff as
577
+ `TIGHTEN`, `NEUTRAL`, `WEAKEN`, or `UNKNOWN`. Modern snapshots carry the full
578
+ semantic baseline; legacy snapshots without baseline state leave baseline
579
+ comparison explicitly `UNKNOWN` rather than assuming an empty baseline.
580
+
581
+ #### Canonical Fields
582
+
583
+ <!-- BEGIN FORGELOOP GENERATED: schema:policy-snapshot -->
584
+
585
+ - `schemaVersion` *(number, required, const: 1)*
586
+ - `policyDigest` *(string, required, minLength: 1)*
587
+ - `rules` *(array<string,object>, required)*
588
+ - `baseline` *(object, optional)*
589
+ - `baselineDigest` *(string, optional)*
590
+ - `capturedAt` *(string, optional)*
591
+
592
+ <!-- END FORGELOOP GENERATED: schema:policy-snapshot -->
@@ -40,11 +40,11 @@ ForgeLoop uses a definition-driven command-line parser:
40
40
  | Category | Commands |
41
41
  | --- | --- |
42
42
  | **Setup & Maintenance** | [`init`](#init), [`update`](#update), [`task-migrate`](#task-migrate), [`task-unlock`](#task-unlock) |
43
- | **Inspection & Diagnostics** | [`doctor`](#doctor), [`progress`](#progress), [`inspect`](#inspect), [`status`](#status), [`validate-state`](#validate-state), [`validate-protocol`](#validate-protocol) |
44
- | **Lifecycle & State** | [`activate`](#activate), [`route`](#route), [`preflight`](#preflight), [`advance`](#advance), [`next`](#next), [`record-diagnosis`](#record-diagnosis), [`record-decision-criterion`](#record-decision-criterion), [`complete`](#complete), [`clear-state`](#clear-state), [`task-create`](#task-create), [`task-list`](#task-list), [`task-show`](#task-show), [`task-scope`](#task-scope) |
43
+ | **Inspection & Diagnostics** | [`doctor`](#doctor), [`progress`](#progress), [`profile-interview`](#profile-interview), [`inspect`](#inspect), [`status`](#status), [`validate-state`](#validate-state), [`validate-protocol`](#validate-protocol) |
44
+ | **Lifecycle & State** | [`activate`](#activate), [`route`](#route), [`preflight`](#preflight), [`advance`](#advance), [`next`](#next), [`record-diagnosis`](#record-diagnosis), [`record-decision-criterion`](#record-decision-criterion), [`complete`](#complete), [`clear-state`](#clear-state), [`reconcile-closure`](#reconcile-closure), [`task-create`](#task-create), [`task-list`](#task-list), [`task-show`](#task-show), [`task-scope`](#task-scope) |
45
45
  | **Cross-Harness Continuity** | [`continuity`](#continuity), [`record-continuity`](#record-continuity), [`reconcile-continuity`](#reconcile-continuity), [`clear-continuity`](#clear-continuity) |
46
46
  | **Verification & Completion** | [`prepare-completion`](#prepare-completion), [`run-check`](#run-check), [`record-check`](#record-check), [`record-terminal-result`](#record-terminal-result), [`audit`](#audit), [`report`](#report), [`validate-receipt`](#validate-receipt) |
47
- | **Policy & Auditing** | [`policy`](#policy), [`bundle`](#bundle) |
47
+ | **Policy & Auditing** | [`policy`](#policy), [`policy-discover`](#policy-discover), [`policy-status`](#policy-status), [`policy-diff`](#policy-diff), [`rule-verify`](#rule-verify), [`baseline`](#baseline), [`bundle`](#bundle) |
48
48
 
49
49
  <!-- END FORGELOOP GENERATED: cli-command-index -->
50
50
 
@@ -64,7 +64,7 @@ Initializes ForgeLoop in a target repository.
64
64
  <!-- BEGIN FORGELOOP GENERATED: cli:init:options -->
65
65
 
66
66
  - `--path <directory>`: target project directory (default: current directory)
67
- - `--dry-run`: show planned writes without changing files
67
+ - `--dry-run`: perform deterministic init planning and conflict detection without writing
68
68
 
69
69
  <!-- END FORGELOOP GENERATED: cli:init:options -->
70
70
 
@@ -80,7 +80,7 @@ Inspects repository health, adapter synchronization, and template integrity.
80
80
 
81
81
  - **Purpose**: Diagnose missing files, unmanaged adapters, profile issues, and broken kit references.
82
82
  - **When to use**: After initialization, after git merges, or when troubleshooting.
83
- - **Mutation**: Read-only (unless `--fix` is passed).
83
+ - **Mutation**: Writes `.forgeloop/.manifest.json` only when `--fix` is passed; otherwise performs no mutation.
84
84
  - **Options**:
85
85
 
86
86
  <!-- BEGIN FORGELOOP GENERATED: cli:doctor:options -->
@@ -111,7 +111,7 @@ Updates the managed instruction kit to match the current ForgeLoop package versi
111
111
  <!-- BEGIN FORGELOOP GENERATED: cli:update:options -->
112
112
 
113
113
  - `--path <directory>`: target project directory (default: current directory)
114
- - `--dry-run`: show planned writes without changing files
114
+ - `--dry-run`: perform deterministic update planning and conflict detection without writing
115
115
 
116
116
  <!-- END FORGELOOP GENERATED: cli:update:options -->
117
117
 
@@ -131,7 +131,7 @@ Calculates and persists deterministic engineering guide routing.
131
131
 
132
132
  - **Purpose**: Selects relevant technical guides (e.g. `clean`, `test`, `security`, `design`) based on declared work attributes.
133
133
  - **When to use**: During discovery before preflight.
134
- - **Mutation**: Writes `.forgeloop/routing-result.json`.
134
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/routing-result.json`.
135
135
  - **Options**:
136
136
 
137
137
  <!-- BEGIN FORGELOOP GENERATED: cli:route:options -->
@@ -160,7 +160,7 @@ Validates pre-implementation readiness and establishes protocol readiness state.
160
160
 
161
161
  - **Purpose**: Verifies that the contract, route, profile facts, and mandatory pre-implementation gates (e.g. `design`) are satisfied and consistent.
162
162
  - **When to use**: Before starting implementation.
163
- - **Mutation**: Persists `.forgeloop/preflight.json` and, when the protocol is ready, may create or synchronize resumable work state and lifecycle events.
163
+ - **Mutation**: Persists `.forgeloop/task-state/<taskKey>/preflight.json` and, when the protocol is ready, may create or synchronize task-scoped resumable work state and lifecycle events.
164
164
  - **Return Status**: `READY` or `BLOCKED`.
165
165
  - **Options**:
166
166
 
@@ -185,7 +185,7 @@ Creates a protocol/session activation marker for the current harness session.
185
185
 
186
186
  - **Purpose**: Creates an activation marker containing `sessionId`, `activationMarker`, and `createdAt` for the current harness session. It does not create the canonical lifecycle work state.
187
187
  - **When to use**: When starting a session after `preflight` is established.
188
- - **Mutation**: Writes `.forgeloop/session.json`.
188
+ - **Mutation**: Writes `.forgeloop/sessions/<sessionId>.json`.
189
189
  - **Options**:
190
190
 
191
191
  <!-- BEGIN FORGELOOP GENERATED: cli:activate:options -->
@@ -232,9 +232,9 @@ Records an append-only decision settlement criterion bound to the active contrac
232
232
 
233
233
  Advances the protocol lifecycle phase.
234
234
 
235
- - **Purpose**: Transitions between valid protocol phases (`PLANNED`, `EXECUTING`, `VERIFYING`, `REVIEWING`).
235
+ - **Purpose**: Transitions the task along a valid edge of the canonical ForgeLoop work-state machine. The destination is validated against the current phase and the canonical lifecycle transition rules.
236
236
  - **When to use**: To declare transitions between workflow stages.
237
- - **Mutation**: Updates `.forgeloop/work-state.json` and appends transition event to ledger.
237
+ - **Mutation**: Updates `.forgeloop/task-state/<taskKey>/work-state.json` and appends transition event to ledger.
238
238
  - **Options**:
239
239
 
240
240
  <!-- BEGIN FORGELOOP GENERATED: cli:advance:options -->
@@ -269,10 +269,14 @@ Computes the deterministic next action required by the protocol.
269
269
 
270
270
  <!-- END FORGELOOP GENERATED: cli:next:options -->
271
271
 
272
- - **Example**:
272
+ - **Examples**:
273
273
 
274
274
  ```bash
275
275
  forgeloop next --json
276
+
277
+ # Explicit task selection prevents another concurrent task from
278
+ # becoming the implicit source of lifecycle state
279
+ forgeloop next --task <id> --json
276
280
  ```
277
281
 
278
282
  ---
@@ -308,7 +312,7 @@ Records operational handoff context before pausing or switching tools.
308
312
 
309
313
  - **Purpose**: Stores immediate work-in-progress notes to help the next harness continue without confusion.
310
314
  - **When to use**: Before ending a session or transferring control.
311
- - **Mutation**: Writes `.forgeloop/continuity.json`.
315
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/continuity.json`.
312
316
  - **Options**:
313
317
 
314
318
  <!-- BEGIN FORGELOOP GENERATED: cli:record-continuity:options -->
@@ -366,7 +370,7 @@ Clears operational continuity context while preserving canonical work state.
366
370
 
367
371
  - **Purpose**: Removes stale or corrupt continuity handoff data when starting fresh from the last work-state checkpoint.
368
372
  - **When to use**: When continuity is unrecoverably stale or no longer relevant.
369
- - **Mutation**: Removes `.forgeloop/continuity.json`.
373
+ - **Mutation**: Removes `.forgeloop/task-state/<taskKey>/continuity.json`.
370
374
  - **Options**:
371
375
 
372
376
  <!-- BEGIN FORGELOOP GENERATED: cli:clear-continuity:options -->
@@ -391,9 +395,9 @@ Clears operational continuity context while preserving canonical work state.
391
395
 
392
396
  Executes a verification command with ForgeLoop-attested provenance.
393
397
 
394
- - **Purpose**: Runs an exact command, records the execution artifact in `.forgeloop/executions/`, and binds the resulting observed check evidence to that execution through `executionRef`.
398
+ - **Purpose**: Runs an exact command, records the execution artifact in `.forgeloop/task-state/<taskKey>/executions/`, and binds the resulting observed check evidence to that execution through `executionRef`.
395
399
  - **When to use**: During `VERIFYING` phase to execute test suites, linters, or validators.
396
- - **Mutation**: Writes `.forgeloop/executions/exec-*.json`, updates `.forgeloop/execution-receipt.json`, appends to ledger.
400
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/executions/exec-*.json`, updates `.forgeloop/task-state/<taskKey>/execution-receipt.json`, appends to task ledger.
397
401
  - **Options**:
398
402
 
399
403
  <!-- BEGIN FORGELOOP GENERATED: cli:run-check:options -->
@@ -420,7 +424,7 @@ Records an observed or manual verification check result without executing comman
420
424
 
421
425
  - **Purpose**: Records manual review evidence or external observations.
422
426
  - **When to use**: For manual reviews, accessibility inspections, or external validations.
423
- - **Mutation**: Updates `.forgeloop/execution-receipt.json` and appends to ledger.
427
+ - **Mutation**: Updates `.forgeloop/task-state/<taskKey>/execution-receipt.json` and appends to task ledger.
424
428
  - **Options**:
425
429
 
426
430
  <!-- BEGIN FORGELOOP GENERATED: cli:record-check:options -->
@@ -489,7 +493,7 @@ Records an append-only diagnosis event in the lifecycle event ledger for the act
489
493
 
490
494
  ### `validate-state`
491
495
 
492
- Validates `.forgeloop/work-state.json` structure, hash chain, and repository binding.
496
+ Validates `.forgeloop/task-state/<taskKey>/work-state.json` structure, hash chain, and repository binding.
493
497
 
494
498
  - **Purpose**: Integrity check for work state.
495
499
  - **Mutation**: Read-only.
@@ -511,26 +515,42 @@ Validates `.forgeloop/work-state.json` structure, hash chain, and repository bin
511
515
 
512
516
  ### `validate-receipt`
513
517
 
514
- Validates `.forgeloop/execution-receipt.json` schema and check references.
518
+ Validates `.forgeloop/task-state/<taskKey>/execution-receipt.json` schema and check references.
515
519
 
516
520
  - **Purpose**: Integrity check for completion receipt.
517
521
  - **Mutation**: Read-only.
522
+ - **Receipt Resolution**: Without `--file`, the receipt is resolved from the task context: an explicit `--task` (or `FORGELOOP_TASK`) selects that task's namespaced receipt, otherwise a single active task is resolved automatically. `--file` overrides task-based receipt resolution and validates exactly the given relative file.
518
523
  - **Options**:
519
524
 
520
525
  <!-- BEGIN FORGELOOP GENERATED: cli:validate-receipt:options -->
521
526
 
522
527
  - `--path <directory>`: target project directory (default: current directory)
523
- - `--file <path>`: receipt file relative to target
528
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
529
+ - `--file <path>`: receipt file relative to target (overrides task-based receipt resolution)
524
530
  - `--json`: emit structured output as JSON
525
531
 
526
532
  <!-- END FORGELOOP GENERATED: cli:validate-receipt:options -->
527
533
 
528
- - **Example**:
534
+ - **Examples**:
535
+
536
+ Validate the selected task's namespaced receipt:
537
+
538
+ ```bash
539
+ forgeloop validate-receipt --task task-001 --json
540
+ ```
541
+
542
+ Validate an explicit receipt file (`--file` overrides task-based receipt resolution):
529
543
 
530
544
  ```bash
531
- forgeloop validate-receipt --json
545
+ forgeloop validate-receipt --file .forgeloop/task-state/<taskKey>/execution-receipt.json --json
532
546
  ```
533
547
 
548
+ <!-- BEGIN FORGELOOP LEGACY LAYOUT EXAMPLE -->
549
+
550
+ When no task is selected and no task descriptors exist, the legacy singleton `.forgeloop/execution-receipt.json` compatibility path is validated.
551
+
552
+ <!-- END FORGELOOP LEGACY LAYOUT EXAMPLE -->
553
+
534
554
  ### `validate-protocol`
535
555
 
536
556
  Performs comprehensive protocol validation across all active artifacts.
@@ -589,11 +609,11 @@ Evaluates task progress across verification cycles and detects stalls determinis
589
609
 
590
610
  ### `prepare-completion`
591
611
 
592
- Initializes or refreshes `.forgeloop/execution-receipt.json`.
612
+ Initializes or refreshes `.forgeloop/task-state/<taskKey>/execution-receipt.json`.
593
613
 
594
614
  - **Purpose**: Maps contract requirements to evidence coverage slots.
595
615
  - **When to use**: Upon entering the `VERIFYING` phase before recording checks.
596
- - **Mutation**: Writes `.forgeloop/execution-receipt.json`.
616
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/execution-receipt.json`.
597
617
  - **Options**:
598
618
 
599
619
  <!-- BEGIN FORGELOOP GENERATED: cli:prepare-completion:options -->
@@ -639,11 +659,19 @@ Records external publication or production-readiness observations.
639
659
  forgeloop record-terminal-result \
640
660
  --requirement release-publish \
641
661
  --type PUBLICATION \
642
- --status passed \
662
+ --status published \
643
663
  --source "npm publish" \
644
664
  --result "v1.1.0 published to registry"
645
665
  ```
646
666
 
667
+ - **Terminal Statuses**: The `--status` value must be one of the canonical
668
+ statuses for the declared `--type`:
669
+
670
+ | `--type` | Allowed `--status` values |
671
+ | --- | --- |
672
+ | `PUBLICATION` | `committed`, `pushed`, `published`, `deployed` |
673
+ | `PRODUCTION_READINESS` | `ready`, `blocked` |
674
+
647
675
  ### `audit`
648
676
 
649
677
  Performs a read-only dry-run evaluation of completion readiness.
@@ -674,8 +702,9 @@ Validates protocol completion and transitions the task to `COMPLETE`.
674
702
 
675
703
  - **Purpose**: Authoritative protocol validation of the entire task lifecycle.
676
704
  - **When to use**: In `REVIEWING` phase when all checks have passed.
677
- - **Mutation**: Updates `.forgeloop/work-state.json` to `COMPLETE` and records completion event.
678
- - **Return Status**: `VALID`, `INCOMPLETE`, `STALE`, `INCONSISTENT`, or `INVALID`.
705
+ - **Mutation**: Updates `.forgeloop/task-state/<taskKey>/work-state.json` to `COMPLETE` and records completion event.
706
+ - **Return Status**: `VALID` or `REJECTED`.
707
+ - **Return Dimensions**: The evaluation result reports separate dimensions alongside the return status: `taskStatus` (`COMPLETE`/`INCOMPLETE`/`BLOCKED`), `verificationStatus` (`VALID`/`invalid`), `publicationStatus`, `productionReadiness`, and `errors[]` with the concrete rejection reasons.
679
708
  - **Options**:
680
709
 
681
710
  <!-- BEGIN FORGELOOP GENERATED: cli:complete:options -->
@@ -811,13 +840,177 @@ Evaluates compliance against a named policy pack.
811
840
  forgeloop policy default --json
812
841
  ```
813
842
 
843
+ ### `policy-discover`
844
+
845
+ Discovers architectural patterns, project conventions, and candidate verification rules deterministically.
846
+
847
+ - **Purpose**: Runs non-interactive repository inspection to derive policy rules with confidence scores.
848
+ - **Mutation**: Read-only by default; writes `.forgeloop/policy/discovery.json` and regenerates `.forgeloop/policy/policy.lock` only with `--write`. Without `--write`, discovery is observational and persists nothing.
849
+ - **Options**:
850
+
851
+ <!-- BEGIN FORGELOOP GENERATED: cli:policy-discover:options -->
852
+
853
+ - `--path <directory>`: target project directory (default: current directory)
854
+ - `--write`: persist discovered policy to .forgeloop/policy/discovery.json
855
+ - `--json`: emit structured output as JSON
856
+
857
+ <!-- END FORGELOOP GENERATED: cli:policy-discover:options -->
858
+
859
+ - **Examples**:
860
+
861
+ Read-only discovery (observational, persists nothing):
862
+
863
+ ```bash
864
+ forgeloop policy-discover --json
865
+ ```
866
+
867
+ Persist discovery and regenerate the policy lock:
868
+
869
+ ```bash
870
+ forgeloop policy-discover --write --json
871
+ ```
872
+
873
+ ### `policy-status`
874
+
875
+ Reports effective executable policy verification status, baselines, lock integrity, and drift.
876
+
877
+ - **Purpose**: Evaluates all rules, verifies `policy.lock` integrity, identifies inert checks, baselined debt, unbaselined violations, and drift against the task snapshot.
878
+ - **Mutation**: Read-only.
879
+ - **Options**:
880
+
881
+ <!-- BEGIN FORGELOOP GENERATED: cli:policy-status:options -->
882
+
883
+ - `--path <directory>`: target project directory (default: current directory)
884
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
885
+ - `--json`: emit structured output as JSON
886
+
887
+ <!-- END FORGELOOP GENERATED: cli:policy-status:options -->
888
+
889
+ - **Examples**:
890
+
891
+ ```bash
892
+ forgeloop policy-status --json
893
+
894
+ # Evaluate drift against a specific task snapshot
895
+ forgeloop policy-status --task <id> --json
896
+ ```
897
+
898
+ ### `policy-diff`
899
+
900
+ Semantically diffs policy rules and classifies changes as tightening, neutral, or weakening.
901
+
902
+ - **Purpose**: Compares proposed or current policy against a base or task snapshot.
903
+ - **Mutation**: Read-only.
904
+ - **Options**:
905
+
906
+ <!-- BEGIN FORGELOOP GENERATED: cli:policy-diff:options -->
907
+
908
+ - `--path <directory>`: target project directory (default: current directory)
909
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
910
+ - `--before <path>`: path to before policy JSON
911
+ - `--after <path>`: path to after policy JSON
912
+ - `--json`: emit structured output as JSON
913
+
914
+ <!-- END FORGELOOP GENERATED: cli:policy-diff:options -->
915
+
916
+ - **Examples**:
917
+
918
+ ```bash
919
+ # Diff the current effective policy against the task snapshot
920
+ forgeloop policy-diff --task <id> --json
921
+
922
+ # Diff two explicit policy JSON files
923
+ forgeloop policy-diff --before .forgeloop/policy/before.json --after .forgeloop/policy/after.json --json
924
+ ```
925
+
926
+ ### `rule-verify`
927
+
928
+ Runs mutation verification on policy rules to prove checkers actively detect invalid states.
929
+
930
+ - **Purpose**: Validates that rule checkers fail on mutant fixtures, generating proof digests.
931
+ - **Mutation**: Read-only.
932
+ - **Options**:
933
+
934
+ <!-- BEGIN FORGELOOP GENERATED: cli:rule-verify:options -->
935
+
936
+ - `--path <directory>`: target project directory (default: current directory)
937
+ - `--rule <id>`: verify a specific policy rule ID
938
+ - `--json`: emit structured output as JSON
939
+
940
+ <!-- END FORGELOOP GENERATED: cli:rule-verify:options -->
941
+
942
+ - **Example**:
943
+
944
+ ```bash
945
+ forgeloop rule-verify --rule SECURITY.NO_HARDCODED_SECRET --json
946
+ ```
947
+
948
+ ### `baseline`
949
+
950
+ Manages the brownfield policy baseline and monotonic ratchet-down.
951
+
952
+ - **Purpose**: Records current violations into baseline, or ratchets baseline downward as debt is fixed.
953
+ - **Mutation**: Writes `.forgeloop/policy/baseline.json` and regenerates `.forgeloop/policy/policy.lock`.
954
+ - **Options**:
955
+
956
+ <!-- BEGIN FORGELOOP GENERATED: cli:baseline:options -->
957
+
958
+ - `--path <directory>`: target project directory (default: current directory)
959
+ - `--record`: record current violations as brownfield baseline
960
+ - `--update`: ratchet baseline downward by removing resolved violations
961
+ - `--policy-reset-authorized`: explicit operator authority to re-record baseline during active tasks
962
+ - `--json`: emit structured output as JSON
963
+
964
+ <!-- END FORGELOOP GENERATED: cli:baseline:options -->
965
+
966
+ - **Examples**:
967
+
968
+ ```bash
969
+ # Adopt pre-existing violations as brownfield debt
970
+ forgeloop baseline --record --json
971
+
972
+ # Remove resolved debt (monotonic; additions are rejected)
973
+ forgeloop baseline --update --json
974
+
975
+ # Explicit operator authority to re-record during an active task
976
+ forgeloop baseline --record --policy-reset-authorized --json
977
+ ```
978
+
979
+ During an active task bound to a policy snapshot, `--record` without
980
+ `--policy-reset-authorized` fails with `E_BASELINE_RECORD_DURING_ACTIVE_TASK`;
981
+ `--update` is monotonic and fails with `E_BASELINE_EXPANSION` if it would add
982
+ debt.
983
+
984
+ ### `profile-interview`
985
+
986
+ Optional operator-facing interview guidance (never invoked autonomously by agent).
987
+
988
+ - **Purpose**: Returns optional discovery/interview guidance to help an operator inspect or refine project assumptions. It does not write `PROJECT_PROFILE.md` automatically.
989
+ - **When to use**: Optional; never required for normal autonomous execution.
990
+ - **Mutation**: Read-only.
991
+ - **Options**:
992
+
993
+ <!-- BEGIN FORGELOOP GENERATED: cli:profile-interview:options -->
994
+
995
+ - `--path <directory>`: target project directory (default: current directory)
996
+ - `--dry-run`: show planned interview questions without changing files
997
+ - `--json`: emit structured output as JSON
998
+
999
+ <!-- END FORGELOOP GENERATED: cli:profile-interview:options -->
1000
+
1001
+ - **Example**:
1002
+
1003
+ ```bash
1004
+ forgeloop profile-interview
1005
+ ```
1006
+
814
1007
  ### `clear-state`
815
1008
 
816
1009
  Clears canonical work-state checkpoint for the current task.
817
1010
 
818
1011
  - **Purpose**: Emergency reset of local work-state checkpoint.
819
1012
  - **When to use**: Only when abandoning a task or resetting state after an unrecoverable corruption.
820
- - **Mutation**: Removes `.forgeloop/work-state.json` only. Sibling ForgeLoop artifacts (such as contracts, routes, gates, and ledger history) are preserved.
1013
+ - **Mutation**: Removes `.forgeloop/task-state/<taskKey>/work-state.json` only. Sibling ForgeLoop artifacts (such as contracts, routes, gates, and ledger history) are preserved.
821
1014
  - **Safety Note**: This is not a full `.forgeloop/` reset command.
822
1015
  - **Options**:
823
1016
 
@@ -837,6 +1030,38 @@ Clears canonical work-state checkpoint for the current task.
837
1030
 
838
1031
  ---
839
1032
 
1033
+ ### `reconcile-closure`
1034
+
1035
+ Reconciles the checkpoint of an EXECUTING task whose objective is already satisfied in the current repository.
1036
+
1037
+ - **Purpose**: Refresh the work-state repository fingerprint of a stale EXECUTING task after repository movement, using executed contract-bound evidence that the objective is present, so the canonical completion pipeline can close it.
1038
+ - **When to use**: When a task is stuck in EXECUTING with `E_REPOSITORY_CHANGED` / `E_STATE_REVALIDATION_REQUIRED` and its objective was already satisfied by other changes in the current repository.
1039
+ - **Mutation**: Appends a `CHECKPOINT_RECONCILED` ledger event (previous/current repository fingerprints plus evidence) and refreshes the work-state repository fingerprint. Phase stays EXECUTING; claims release only through canonical `COMPLETE`.
1040
+ - **Safety Note**: Refuses non-EXECUTING tasks, fresh checkpoints, contract or artifact drift, invalid ledgers, unknown requirements, and failing evidence.
1041
+ - **Options**:
1042
+
1043
+ <!-- BEGIN FORGELOOP GENERATED: cli:reconcile-closure:options -->
1044
+
1045
+ - `--path <directory>`: target project directory (default: current directory)
1046
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
1047
+ - `--id <id>`: contract verification item id used as evidence
1048
+ - `--requirement <id>`: exact contract verification item requirement text
1049
+ - `--details <json>`: additional structured execution details
1050
+ - `-- <argv...>`: exact command argv to execute as objective-satisfaction evidence
1051
+ - `--json`: emit structured output as JSON
1052
+
1053
+ <!-- END FORGELOOP GENERATED: cli:reconcile-closure:options -->
1054
+
1055
+ - **Example**:
1056
+
1057
+ ```bash
1058
+ forgeloop reconcile-closure --task <id> --id regression-tests \
1059
+ --requirement "pack tarball test asserts the README image is excluded from the npm package" \
1060
+ -- node --test tests/package.test.js
1061
+ ```
1062
+
1063
+ ---
1064
+
840
1065
  ## 7. Multi-Task Management
841
1066
 
842
1067
  ### `task-create`
@@ -860,9 +1085,17 @@ Initializes a new isolated task namespace with write claims and contract.
860
1085
  - **Example**:
861
1086
 
862
1087
  ```bash
863
- forgeloop task-create --id task-001 --claim src/auth --prompt "Add auth module" --json
1088
+ forgeloop task-create --task task-001 --claim src/auth --json
1089
+ ```
1090
+
1091
+ With an explicit initial contract file:
1092
+
1093
+ ```bash
1094
+ forgeloop task-create --task task-001 --claim src/auth --claim tests/auth --contract-file task-contract.json --json
864
1095
  ```
865
1096
 
1097
+ `--contract-file` points to a contract JSON that is validated and copied into the task namespace.
1098
+
866
1099
  ### `task-list`
867
1100
 
868
1101
  Lists all tasks discovered in `.forgeloop/task-state/`.
@@ -926,7 +1159,7 @@ Updates or inspects write claims for a task.
926
1159
  - **Example**:
927
1160
 
928
1161
  ```bash
929
- forgeloop task-scope --task task-001 --claim src/auth tests/auth --json
1162
+ forgeloop task-scope --task task-001 --claim src/auth --claim tests/auth --json
930
1163
  ```
931
1164
 
932
1165
  ### `task-migrate`
@@ -48,6 +48,7 @@ Key continuity invariants:
48
48
  | **Operational Continuity** | `.forgeloop/task-state/<taskKey>/continuity.json` | Active focus, remaining items, known issues, inspect-first paths | Operational context only (non-evidence) |
49
49
  | **Implementation Truth** | Git checkout / filesystem | Actual source code and files | Ground truth for changes |
50
50
  | **Task Intent** | `.forgeloop/task-state/<taskKey>/contract.json` | Objectives, constraints, deliverables, verification requirements | Contract authority |
51
+ | **Task Policy Snapshot** | `.forgeloop/task-state/<taskKey>/policy-snapshot.json` | Effective policy rules and baseline authorized at preflight | Policy integrity binding; a replacement harness must resume against this snapshot, not re-discover policy |
51
52
  | **Execution Guidance** | `.forgeloop/task-state/<taskKey>/routing-result.json` | Deterministically selected engineering guides | Guidance |
52
53
  | **Verification Provenance** | `.forgeloop/task-state/<taskKey>/executions/*.json` | Attested process execution records | Verification truth |
53
54
  | **Next Action** | `forgeloop next` | Deterministic computation of the valid next command | Control authority |