@cassiomc1/forgeloop 1.1.1 → 1.2.2

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 (79) 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 +124 -0
  7. package/ENG/premium-sites-studio-eng.md +28 -0
  8. package/ENG/taste-frontend-eng.md +3 -2
  9. package/ENG/test-code-eng.md +45 -0
  10. package/LOOP_ENGINEERING.md +74 -0
  11. package/LOOP_SYSTEM_DESIGN.md +9 -5
  12. package/ORCHESTRATOR_INTEGRATION.md +41 -6
  13. package/PROTOCOL_INTEGRATION.md +13 -0
  14. package/README.md +40 -6
  15. package/TERMINOLOGY.md +10 -0
  16. package/THIRD_PARTY_NOTICES.md +58 -1
  17. package/THREAT_MODEL.md +12 -1
  18. package/docs/ARTIFACT_REFERENCE.md +152 -2
  19. package/docs/CLI_REFERENCE.md +346 -30
  20. package/docs/CROSS_HARNESS_CONTINUITY.md +1 -0
  21. package/docs/DOCUMENTATION_GUIDE.md +41 -4
  22. package/docs/GETTING_STARTED.md +39 -8
  23. package/docs/RECIPES.md +66 -7
  24. package/docs/TROUBLESHOOTING.md +279 -6
  25. package/package.json +1 -1
  26. package/schemas/policy-baseline.schema.json +26 -0
  27. package/schemas/policy-discovery.schema.json +45 -0
  28. package/schemas/policy-lock.schema.json +16 -0
  29. package/schemas/policy-rules.schema.json +48 -0
  30. package/schemas/policy-snapshot.schema.json +16 -0
  31. package/src/cli.js +102 -1
  32. package/src/commands/baseline.js +120 -0
  33. package/src/commands/init.js +304 -6
  34. package/src/commands/next.js +15 -1
  35. package/src/commands/policy-diff.js +51 -0
  36. package/src/commands/policy-discover.js +42 -0
  37. package/src/commands/policy-status.js +33 -0
  38. package/src/commands/profile-interview.js +50 -0
  39. package/src/commands/progress.js +51 -0
  40. package/src/commands/reconcile-closure.js +49 -0
  41. package/src/commands/record-decision-criterion.js +34 -0
  42. package/src/commands/record-diagnosis.js +49 -0
  43. package/src/commands/rule-verify.js +36 -0
  44. package/src/commands/validate-receipt.js +38 -3
  45. package/src/core/artifact-registry.js +60 -0
  46. package/src/core/audit.js +24 -0
  47. package/src/core/cli-command-definitions.js +163 -7
  48. package/src/core/cli-metadata.js +1 -1
  49. package/src/core/completion-artifacts.js +29 -3
  50. package/src/core/completion.js +101 -10
  51. package/src/core/diagnosis-model.js +214 -0
  52. package/src/core/diagnosis.js +171 -0
  53. package/src/core/error-codes.js +292 -0
  54. package/src/core/events.js +47 -1
  55. package/src/core/execution-prerequisites.js +38 -20
  56. package/src/core/execution.js +20 -3
  57. package/src/core/native-adapters.js +14 -4
  58. package/src/core/next-action-model.js +40 -5
  59. package/src/core/next-action.js +234 -91
  60. package/src/core/phase.js +29 -0
  61. package/src/core/policy-adapters.js +276 -0
  62. package/src/core/policy-baseline.js +144 -0
  63. package/src/core/policy-diff.js +133 -0
  64. package/src/core/policy-discovery.js +225 -0
  65. package/src/core/policy-engine.js +533 -0
  66. package/src/core/policy-mutation.js +139 -0
  67. package/src/core/preflight-consistency.js +23 -15
  68. package/src/core/preflight-model.js +10 -2
  69. package/src/core/preflight.js +65 -1
  70. package/src/core/progress.js +143 -0
  71. package/src/core/protocol.js +8 -0
  72. package/src/core/reconcile-closure.js +173 -0
  73. package/src/core/schema-validation.js +6 -0
  74. package/src/core/settlement-model.js +85 -0
  75. package/src/core/settlement.js +78 -0
  76. package/src/core/task-context.js +11 -0
  77. package/src/core/task-discovery.js +67 -1
  78. package/src/core/task-paths.js +9 -0
  79. package/src/core/templates.js +5 -0
@@ -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), [`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), [`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 -->
@@ -201,13 +201,40 @@ Creates a protocol/session activation marker for the current harness session.
201
201
  forgeloop activate --json
202
202
  ```
203
203
 
204
+ ### `record-decision-criterion`
205
+
206
+ Records an append-only decision settlement criterion bound to the active contract fingerprint.
207
+
208
+ - **Purpose**: Records settlement guidance or criteria for open contract decisions without modifying contract schema.
209
+ - **When to use**: To attach settlement guidance to unresolved decisions in `current-contract.unresolvedDecisions[]`.
210
+ - **Mutation**: Appends `DECISION_CRITERION_RECORDED` to event ledger.
211
+ - **Options**:
212
+
213
+ <!-- BEGIN FORGELOOP GENERATED: cli:record-decision-criterion:options -->
214
+
215
+ - `--path <directory>`: target project directory (default: current directory)
216
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
217
+ - `--decision <text>`: unresolved decision text matching current contract
218
+ - `--settled-by <text>`: criteria or guidance that settles the decision
219
+ - `--json`: emit structured output as JSON
220
+
221
+ <!-- END FORGELOOP GENERATED: cli:record-decision-criterion:options -->
222
+
223
+ - **Example**:
224
+
225
+ ```bash
226
+ forgeloop record-decision-criterion \
227
+ --decision="Which authentication provider should be used?" \
228
+ --settled-by="Use provider supporting current session token middleware"
229
+ ```
230
+
204
231
  ### `advance`
205
232
 
206
233
  Advances the protocol lifecycle phase.
207
234
 
208
- - **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.
209
236
  - **When to use**: To declare transitions between workflow stages.
210
- - **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.
211
238
  - **Options**:
212
239
 
213
240
  <!-- BEGIN FORGELOOP GENERATED: cli:advance:options -->
@@ -242,10 +269,14 @@ Computes the deterministic next action required by the protocol.
242
269
 
243
270
  <!-- END FORGELOOP GENERATED: cli:next:options -->
244
271
 
245
- - **Example**:
272
+ - **Examples**:
246
273
 
247
274
  ```bash
248
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
249
280
  ```
250
281
 
251
282
  ---
@@ -281,7 +312,7 @@ Records operational handoff context before pausing or switching tools.
281
312
 
282
313
  - **Purpose**: Stores immediate work-in-progress notes to help the next harness continue without confusion.
283
314
  - **When to use**: Before ending a session or transferring control.
284
- - **Mutation**: Writes `.forgeloop/continuity.json`.
315
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/continuity.json`.
285
316
  - **Options**:
286
317
 
287
318
  <!-- BEGIN FORGELOOP GENERATED: cli:record-continuity:options -->
@@ -339,7 +370,7 @@ Clears operational continuity context while preserving canonical work state.
339
370
 
340
371
  - **Purpose**: Removes stale or corrupt continuity handoff data when starting fresh from the last work-state checkpoint.
341
372
  - **When to use**: When continuity is unrecoverably stale or no longer relevant.
342
- - **Mutation**: Removes `.forgeloop/continuity.json`.
373
+ - **Mutation**: Removes `.forgeloop/task-state/<taskKey>/continuity.json`.
343
374
  - **Options**:
344
375
 
345
376
  <!-- BEGIN FORGELOOP GENERATED: cli:clear-continuity:options -->
@@ -364,9 +395,9 @@ Clears operational continuity context while preserving canonical work state.
364
395
 
365
396
  Executes a verification command with ForgeLoop-attested provenance.
366
397
 
367
- - **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`.
368
399
  - **When to use**: During `VERIFYING` phase to execute test suites, linters, or validators.
369
- - **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.
370
401
  - **Options**:
371
402
 
372
403
  <!-- BEGIN FORGELOOP GENERATED: cli:run-check:options -->
@@ -393,7 +424,7 @@ Records an observed or manual verification check result without executing comman
393
424
 
394
425
  - **Purpose**: Records manual review evidence or external observations.
395
426
  - **When to use**: For manual reviews, accessibility inspections, or external validations.
396
- - **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.
397
428
  - **Options**:
398
429
 
399
430
  <!-- BEGIN FORGELOOP GENERATED: cli:record-check:options -->
@@ -427,9 +458,42 @@ Records an observed or manual verification check result without executing comman
427
458
  --result "Verified contrast ratios exceed 4.5:1 across all color schemes"
428
459
  ```
429
460
 
461
+ ### `record-diagnosis`
462
+
463
+ Records an append-only diagnosis event in the lifecycle event ledger for the active cycle.
464
+
465
+ - **Purpose**: Records root-cause hypotheses, failure classes, and settlement criteria for failed verification checks.
466
+ - **When to use**: In `DIAGNOSING` phase before advancing to `CORRECTING`.
467
+ - **Mutation**: Appends `DIAGNOSIS_RECORDED` to event ledger and updates work state projection.
468
+ - **Options**:
469
+
470
+ <!-- BEGIN FORGELOOP GENERATED: cli:record-diagnosis:options -->
471
+
472
+ - `--path <directory>`: target project directory (default: current directory)
473
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
474
+ - `--hypothesis <text>`: specific root-cause hypothesis explaining the verification failure
475
+ - `--failure-class <class>`: canonical failure class taxonomy
476
+ - `--evidence-ref <check-id>`: reference to failed/blocked check from current cycle (repeatable)
477
+ - `--settled-by <text>`: falsification or settlement criteria for the hypothesis
478
+ - `--next-safe-action <text>`: smallest safe action to address the hypothesis
479
+ - `--json`: emit structured output as JSON
480
+
481
+ <!-- END FORGELOOP GENERATED: cli:record-diagnosis:options -->
482
+
483
+ - **Example**:
484
+
485
+ ```bash
486
+ forgeloop record-diagnosis \
487
+ --hypothesis="Off-by-one index calculation in slice function" \
488
+ --failure-class="VERIFICATION_FAILURE" \
489
+ --evidence-ref="unit-tests" \
490
+ --settled-by="Test returns expected slice length" \
491
+ --next-safe-action="Adjust offset +1 in slice.js"
492
+ ```
493
+
430
494
  ### `validate-state`
431
495
 
432
- 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.
433
497
 
434
498
  - **Purpose**: Integrity check for work state.
435
499
  - **Mutation**: Read-only.
@@ -451,26 +515,42 @@ Validates `.forgeloop/work-state.json` structure, hash chain, and repository bin
451
515
 
452
516
  ### `validate-receipt`
453
517
 
454
- Validates `.forgeloop/execution-receipt.json` schema and check references.
518
+ Validates `.forgeloop/task-state/<taskKey>/execution-receipt.json` schema and check references.
455
519
 
456
520
  - **Purpose**: Integrity check for completion receipt.
457
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.
458
523
  - **Options**:
459
524
 
460
525
  <!-- BEGIN FORGELOOP GENERATED: cli:validate-receipt:options -->
461
526
 
462
527
  - `--path <directory>`: target project directory (default: current directory)
463
- - `--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)
464
530
  - `--json`: emit structured output as JSON
465
531
 
466
532
  <!-- END FORGELOOP GENERATED: cli:validate-receipt:options -->
467
533
 
468
- - **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):
469
543
 
470
544
  ```bash
471
- forgeloop validate-receipt --json
545
+ forgeloop validate-receipt --file .forgeloop/task-state/<taskKey>/execution-receipt.json --json
472
546
  ```
473
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
+
474
554
  ### `validate-protocol`
475
555
 
476
556
  Performs comprehensive protocol validation across all active artifacts.
@@ -500,17 +580,40 @@ Performs comprehensive protocol validation across all active artifacts.
500
580
  forgeloop validate-protocol --json
501
581
  ```
502
582
 
583
+ ### `progress`
584
+
585
+ Evaluates task progress across verification cycles and detects stalls deterministically.
586
+
587
+ - **Purpose**: Evaluates whether iterative correction cycles are advancing, on watch, or stalled.
588
+ - **When to use**: Any time during execution, verification, or diagnosis to inspect progress signals and prevent repeated ineffective retries.
589
+ - **Mutation**: Read-only.
590
+ - **Options**:
591
+
592
+ <!-- BEGIN FORGELOOP GENERATED: cli:progress:options -->
593
+
594
+ - `--path <directory>`: target project directory (default: current directory)
595
+ - `--task <id>`: task ID to operate on (when omitted, resolved from context or single active task)
596
+ - `--json`: emit progress evaluation as JSON
597
+
598
+ <!-- END FORGELOOP GENERATED: cli:progress:options -->
599
+
600
+ - **Example**:
601
+
602
+ ```bash
603
+ forgeloop progress --json
604
+ ```
605
+
503
606
  ---
504
607
 
505
608
  ## 5. Completion & Reporting
506
609
 
507
610
  ### `prepare-completion`
508
611
 
509
- Initializes or refreshes `.forgeloop/execution-receipt.json`.
612
+ Initializes or refreshes `.forgeloop/task-state/<taskKey>/execution-receipt.json`.
510
613
 
511
614
  - **Purpose**: Maps contract requirements to evidence coverage slots.
512
615
  - **When to use**: Upon entering the `VERIFYING` phase before recording checks.
513
- - **Mutation**: Writes `.forgeloop/execution-receipt.json`.
616
+ - **Mutation**: Writes `.forgeloop/task-state/<taskKey>/execution-receipt.json`.
514
617
  - **Options**:
515
618
 
516
619
  <!-- BEGIN FORGELOOP GENERATED: cli:prepare-completion:options -->
@@ -556,11 +659,19 @@ Records external publication or production-readiness observations.
556
659
  forgeloop record-terminal-result \
557
660
  --requirement release-publish \
558
661
  --type PUBLICATION \
559
- --status passed \
662
+ --status published \
560
663
  --source "npm publish" \
561
664
  --result "v1.1.0 published to registry"
562
665
  ```
563
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
+
564
675
  ### `audit`
565
676
 
566
677
  Performs a read-only dry-run evaluation of completion readiness.
@@ -591,8 +702,9 @@ Validates protocol completion and transitions the task to `COMPLETE`.
591
702
 
592
703
  - **Purpose**: Authoritative protocol validation of the entire task lifecycle.
593
704
  - **When to use**: In `REVIEWING` phase when all checks have passed.
594
- - **Mutation**: Updates `.forgeloop/work-state.json` to `COMPLETE` and records completion event.
595
- - **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.
596
708
  - **Options**:
597
709
 
598
710
  <!-- BEGIN FORGELOOP GENERATED: cli:complete:options -->
@@ -728,13 +840,177 @@ Evaluates compliance against a named policy pack.
728
840
  forgeloop policy default --json
729
841
  ```
730
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
+
731
1007
  ### `clear-state`
732
1008
 
733
1009
  Clears canonical work-state checkpoint for the current task.
734
1010
 
735
1011
  - **Purpose**: Emergency reset of local work-state checkpoint.
736
1012
  - **When to use**: Only when abandoning a task or resetting state after an unrecoverable corruption.
737
- - **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.
738
1014
  - **Safety Note**: This is not a full `.forgeloop/` reset command.
739
1015
  - **Options**:
740
1016
 
@@ -754,6 +1030,38 @@ Clears canonical work-state checkpoint for the current task.
754
1030
 
755
1031
  ---
756
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
+
757
1065
  ## 7. Multi-Task Management
758
1066
 
759
1067
  ### `task-create`
@@ -777,9 +1085,17 @@ Initializes a new isolated task namespace with write claims and contract.
777
1085
  - **Example**:
778
1086
 
779
1087
  ```bash
780
- 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
781
1089
  ```
782
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
1095
+ ```
1096
+
1097
+ `--contract-file` points to a contract JSON that is validated and copied into the task namespace.
1098
+
783
1099
  ### `task-list`
784
1100
 
785
1101
  Lists all tasks discovered in `.forgeloop/task-state/`.
@@ -843,7 +1159,7 @@ Updates or inspects write claims for a task.
843
1159
  - **Example**:
844
1160
 
845
1161
  ```bash
846
- 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
847
1163
  ```
848
1164
 
849
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 |
@@ -35,6 +35,10 @@ Documentation routing -> DOCS_INDEX.md
35
35
 
36
36
  Operational documentation must explain canonical behavior, not redefine it.
37
37
 
38
+ Canonical phase and transition inventories must be derived from `WORK_PHASES`
39
+ and `WORK_TRANSITIONS`; do not maintain independent hand-written transition
40
+ enums when a generated or mechanically validated representation is available.
41
+
38
42
  ---
39
43
 
40
44
  ## 3. Generated Documentation Provenance & Pipeline
@@ -60,10 +64,11 @@ cross-platform CI (.github/workflows/docs-quality.yml)
60
64
  | Fact Category | Canonical Machine Source | Generated Target File | Generated Region Marker |
61
65
  | --- | --- | --- | --- |
62
66
  | **Artifact Inventory** | `ARTIFACT_REGISTRY` (`src/core/artifact-registry.js`) | `docs/ARTIFACT_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: artifact-registry -->` |
63
- | **Artifact Fields** (12 schemas) | `schemas/*.schema.json` | `docs/ARTIFACT_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: schema:<name> -->` |
67
+ | **Artifact Fields** | `schemas/*.schema.json` | `docs/ARTIFACT_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: schema:<name> -->` |
64
68
  | **CLI Command Index** | `CLI_COMMAND_DEFINITIONS` (`src/core/cli-command-definitions.js`) | `docs/CLI_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: cli-command-index -->` |
65
69
  | **CLI Common Options** | `CLI_COMMAND_DEFINITIONS` (`src/core/cli-command-definitions.js`) | `docs/CLI_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: cli-common-options -->` |
66
- | **CLI Command Options** (27 commands) | `CLI_COMMAND_DEFINITIONS` (`src/core/cli-command-definitions.js`) | `docs/CLI_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: cli:<command>:options -->` |
70
+ | **CLI Command Options** | `CLI_COMMAND_DEFINITIONS` (`src/core/cli-command-definitions.js`) | `docs/CLI_REFERENCE.md` | `<!-- BEGIN FORGELOOP GENERATED: cli:<command>:options -->` |
71
+ | **Work-State Transitions** | `WORK_PHASES` / `WORK_TRANSITIONS` (`src/core/protocol.js`) | `ORCHESTRATOR_INTEGRATION.md` | `<!-- BEGIN FORGELOOP GENERATED: work-transitions -->` |
67
72
  | **Public Error Codes** | `PUBLIC_ERROR_CODES` (`src/core/error-codes.js`) | `docs/TROUBLESHOOTING.md` | `<!-- BEGIN FORGELOOP GENERATED: public-error-codes -->` |
68
73
  | **Architecture Flow** | `docs/forgeloop-flow.mmd` | `docs/assets/forgeloop-flow.svg` | Verified via embedded SHA-256 fingerprint |
69
74
 
@@ -82,6 +87,11 @@ npm test
82
87
  npm run docs:check
83
88
  ```
84
89
 
90
+ Do not hard-code inventory totals in prose or headings. Counts of commands,
91
+ schemas, fields, and public codes are derived from the registries and schemas;
92
+ when those sources change, regenerate the reference documents and let the
93
+ conformance checks detect omissions.
94
+
85
95
  ---
86
96
 
87
97
  ## 4. Documentation Conformance Matrix
@@ -93,9 +103,10 @@ npm run docs:check
93
103
  | **Artifact fields & types** | `schemas/*.schema.json` | `scripts/validate_documentation_conformance.mjs` |
94
104
  | **Enums & consts** | `schemas/*.schema.json` | `scripts/validate_documentation_conformance.mjs` |
95
105
  | **Lifecycle phases** | `WORK_PHASES` (`src/core/protocol.js`) | `scripts/validate_documentation_conformance.mjs` |
106
+ | **Lifecycle transitions** | `WORK_TRANSITIONS` (`src/core/protocol.js`) + the special `BLOCKED` rule | `scripts/generate_documentation_reference.mjs` and `scripts/validate_documentation_conformance.mjs` |
96
107
  | **Stable error codes** | `PUBLIC_ERROR_CODES` (`src/core/error-codes.js`) | `scripts/validate_documentation_conformance.mjs` |
97
108
  | **Discovery resume rules** | `DISCOVERY_SURFACES` & `nativeShim` | `scripts/validate_documentation_conformance.mjs` |
98
- | **Operational path freshness** | `OPERATIONAL_DOCUMENTS` & `task-paths.js` | `scripts/validate_documentation_conformance.mjs` |
109
+ | **Task-layout path freshness** | `TASK_LAYOUT_DOCUMENTS` & `task-paths.js` | `scripts/validate_documentation_conformance.mjs` |
99
110
  | **Package-shipped docs** | `package.json` (`files`) | `tests/package.test.js` |
100
111
  | **Architecture diagram** | `docs/forgeloop-flow.mmd` | `scripts/check-generated-diagram.mjs` |
101
112
 
@@ -116,6 +127,7 @@ Avoid ambiguous phrases like *"should generally"* or *"usually"* for behaviors t
116
127
 
117
128
  - Canonical task-scoped paths are defined in `src/core/task-paths.js` under `.forgeloop/task-state/<taskKey>/`.
118
129
  - Operational guides (`README.md`, `GETTING_STARTED.md`, `RECIPES.md`, `CROSS_HARNESS_CONTINUITY.md`, `TROUBLESHOOTING.md`) must document namespaced paths by default.
130
+ - Architecture/integration documents (`LOOP_SYSTEM_DESIGN.md`, `ORCHESTRATOR_INTEGRATION.md`) are covered by the same task-layout conformance scope (`TASK_LAYOUT_DOCUMENTS`).
119
131
  - Legacy ForgeLoop 1.0 singleton paths (e.g. `.forgeloop/current-contract.json`) are permitted **only** inside explicit legacy migration regions:
120
132
 
121
133
  ```markdown
@@ -145,7 +157,32 @@ Avoid ambiguous phrases like *"should generally"* or *"usually"* for behaviors t
145
157
 
146
158
  ---
147
159
 
148
- ## 8. Documentation Change Checklist for Pull Requests
160
+ ## 8. README Hero and Package Boundary
161
+
162
+ README hero assets are branding/conceptual illustrations. They are not the
163
+ canonical protocol diagram. `docs/forgeloop-flow.mmd` remains the canonical
164
+ architecture flow source and `docs/assets/forgeloop-flow.svg` remains its
165
+ generated render.
166
+
167
+ The README hero is intentionally GitHub-repository-only:
168
+
169
+ - `README.md` may reference `docs/assets/eng_readme_forgeloop.png`; GitHub
170
+ renders it from the repository.
171
+ - The hero PNG is excluded from the npm package (`package.json` `files`), and
172
+ `tests/package.test.js` asserts that exclusion so it cannot be silently
173
+ re-included.
174
+ - The packaged README is therefore not self-contained for that relative hero
175
+ path; do not claim otherwise.
176
+ - If a portable hero is ever shipped, any relative README asset referenced by
177
+ packaged Markdown must be present in the package and covered by
178
+ `tests/package.test.js`.
179
+
180
+ Never delete `docs/assets/forgeloop-flow.svg`; it is generator-owned output of
181
+ the diagram workflow.
182
+
183
+ ---
184
+
185
+ ## 9. Documentation Change Checklist for Pull Requests
149
186
 
150
187
  For documentation-impacting changes, verify each item before merging:
151
188