@formigio/fazemos-cli 0.10.94 → 0.10.96

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug,
8
8
  // Directory-scoped context override (.fazemos.json)
9
9
  setOrgOverride, setProjectOverride, setDirContextSource, getDirContextSource, } from './config.js';
10
10
  import { findDirContextFile, readDirContextFile, writeDirContextFile, removeDirContextFile, DIR_CONFIG_FILENAME, applyDirContext, } from './dircontext.js';
11
+ import { exitForError } from './exitCodes.js';
11
12
  import { loginWithBrowser, hostedLogoutUrl, signup, confirmSignup, adminLogin } from './auth.js';
12
13
  import { fetchAuthConfig } from './authConfig.js';
13
14
  import { api, ApiError, refreshAuthMeCache, invalidateAuthMeCache, resolveOrgIdMaybeSlug, resolveProjectIdBySlug, resolveProjectBySlug, patchProjectDocsRepo, patchOrgWorkspace, isAgentCredential, fetchCredentialScope } from './api.js';
@@ -5926,8 +5927,12 @@ pipelines
5926
5927
  }
5927
5928
  }
5928
5929
  catch (err) {
5930
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): force-transition is the
5931
+ // "advance" write in the pl/step wiring set — it forces a pipeline,
5932
+ // step, or execution forward, so a gateway-dropped POST here is
5933
+ // exactly the "did it land?" ambiguity TR-3/R4 exists for.
5929
5934
  console.error(chalk.red(err.message));
5930
- process.exit(1);
5935
+ exitForError(err);
5931
5936
  }
5932
5937
  });
5933
5938
  // ── P-TOOL-1 — `pl rematerialize <instanceId>` ──
@@ -6406,8 +6411,9 @@ step
6406
6411
  }
6407
6412
  }
6408
6413
  catch (err) {
6414
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "submit" write.
6409
6415
  console.error(chalk.red(err.message));
6410
- process.exit(1);
6416
+ exitForError(err);
6411
6417
  }
6412
6418
  });
6413
6419
  step
@@ -6450,8 +6456,9 @@ step
6450
6456
  console.log(chalk.green('Step marked as failed'));
6451
6457
  }
6452
6458
  catch (err) {
6459
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "fail" write (step).
6453
6460
  console.error(chalk.red(err.message));
6454
- process.exit(1);
6461
+ exitForError(err);
6455
6462
  }
6456
6463
  });
6457
6464
  step
@@ -7216,8 +7223,9 @@ executions
7216
7223
  console.log(chalk.green('Execution completed'));
7217
7224
  }
7218
7225
  catch (err) {
7226
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "complete" write.
7219
7227
  console.error(chalk.red(err.message));
7220
- process.exit(1);
7228
+ exitForError(err);
7221
7229
  }
7222
7230
  });
7223
7231
  executions
@@ -7247,8 +7255,9 @@ executions
7247
7255
  console.log(chalk.green('Execution marked as failed'));
7248
7256
  }
7249
7257
  catch (err) {
7258
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "fail" write (execution).
7250
7259
  console.error(chalk.red(err.message));
7251
- process.exit(1);
7260
+ exitForError(err);
7252
7261
  }
7253
7262
  });
7254
7263
  executions
@@ -10629,6 +10638,25 @@ Types: question | task | signal | response | flag | decision | direction | brief
10629
10638
  unresolvedResp = await api('POST', '/api/dispatches', unresolvedReqBody);
10630
10639
  }
10631
10640
  catch (err) {
10641
+ // R1 (tech-lead-reviewer CLI-OUTCOME-UNKNOWN-EXIT-WIRING review,
10642
+ // 2026-10-30f): an OUTCOME_UNKNOWN ApiError (status 0, the
10643
+ // TR-3/R4 "request may have landed" case) fails
10644
+ // `shouldFallBackToFile` the same way a deliberate 4xx refusal
10645
+ // does — `0 >= 500` is false — so without this branch it fell
10646
+ // into the "Dispatch refused" / exit 1 branch below. That told
10647
+ // the caller "refused" when nothing refused anything, and
10648
+ // invited a blind re-send into exactly the duplicate-dispatch
10649
+ // case RULE-OUTCOME-UNKNOWN-IS-NOT-FAILURE exists to prevent.
10650
+ // Any ApiError carrying `.exitCode` (today, only OUTCOME_UNKNOWN)
10651
+ // must be caught here, before the shouldFallBackToFile check,
10652
+ // and must exit with that code instead of being folded into
10653
+ // "refused" / exit 1.
10654
+ if (err instanceof ApiError && err.exitCode != null) {
10655
+ console.error(chalk.yellow(`⚠ Dispatch outcome unknown (${err.code}): ${err.message}`));
10656
+ console.error(chalk.gray(' It may have landed. Read back (fazemos inbox / the thread) before re-sending.'));
10657
+ process.exitCode = err.exitCode;
10658
+ return;
10659
+ }
10632
10660
  // rul_dispatch_4xx_still_hard_fails (BUG53 semantics preserved)
10633
10661
  // Deliberate 4xx (FROM_ROLE_FORBIDDEN, depth ceiling, validation) hard-fails
10634
10662
  // in the registry-less path too. No local file fallback — no role.inbox
@@ -10741,6 +10769,25 @@ Types: question | task | signal | response | flag | decision | direction | brief
10741
10769
  apiResp = await api('POST', '/api/dispatches', reqBody);
10742
10770
  }
10743
10771
  catch (err) {
10772
+ // R1 (tech-lead-reviewer CLI-OUTCOME-UNKNOWN-EXIT-WIRING review,
10773
+ // 2026-10-30f): an OUTCOME_UNKNOWN ApiError (status 0, the TR-3/R4
10774
+ // "request may have landed" case) fails `shouldFallBackToFile` the
10775
+ // same way a deliberate 4xx refusal does — `0 >= 500` is false —
10776
+ // so without this branch it fell into the "Dispatch refused" /
10777
+ // exit 1 branch below. That told the caller "refused" when
10778
+ // nothing refused anything, and invited a blind re-send into
10779
+ // exactly the duplicate-dispatch case
10780
+ // RULE-OUTCOME-UNKNOWN-IS-NOT-FAILURE exists to prevent. Any
10781
+ // ApiError carrying `.exitCode` (today, only OUTCOME_UNKNOWN) must
10782
+ // be caught here, before the shouldFallBackToFile check, and must
10783
+ // exit with that code instead of being folded into "refused" /
10784
+ // exit 1.
10785
+ if (err instanceof ApiError && err.exitCode != null) {
10786
+ console.error(chalk.yellow(`⚠ Dispatch outcome unknown (${err.code}): ${err.message}`));
10787
+ console.error(chalk.gray(' It may have landed. Read back (fazemos inbox / the thread) before re-sending.'));
10788
+ process.exitCode = err.exitCode;
10789
+ return;
10790
+ }
10744
10791
  // BUG53: a deliberate API refusal (4xx) must HARD-FAIL — do NOT fall
10745
10792
  // back to writing a local inbox file. Inside an agent that file gets
10746
10793
  // committed/pushed and re-drained, re-introducing the dispatch with no
@@ -10791,8 +10838,22 @@ Types: question | task | signal | response | flag | decision | direction | brief
10791
10838
  // delivery artifact; the recipient drains it via the DB, not git.
10792
10839
  }
10793
10840
  catch (err) {
10841
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "dispatch". NOTE — both
10842
+ // `api('POST', '/api/dispatches', ...)` call sites above already have
10843
+ // their own non-rethrowing catch (BUG53 4xx hard-fail / network
10844
+ // fallback-to-file-only logic), each of which sets `process.exitCode`
10845
+ // and `return`s before an ApiError would ever reach here. As of R1
10846
+ // (tech-lead-reviewer review, 2026-10-30f) the OUTCOME_UNKNOWN case
10847
+ // (status 0) is handled explicitly in each of those inline catches —
10848
+ // it is caught and exits with `err.exitCode` (5) before the
10849
+ // `shouldFallBackToFile` check, rather than falling into that
10850
+ // check's 4xx-shaped "refused" / exit 1 branch. This outer catch is
10851
+ // reachable only by non-network errors (bad JSON, missing registry,
10852
+ // etc.), none of which carry `.exitCode`, so wiring it is a
10853
+ // consistency change for future throws — see the EW handoff notes
10854
+ // for the matching tests.
10794
10855
  console.error(chalk.red(err instanceof Error ? err.message : String(err)));
10795
- process.exit(1);
10856
+ exitForError(err);
10796
10857
  }
10797
10858
  });
10798
10859
  // ── `fazemos roles sync` — upsert roles.json into role_registrations ──
@@ -11342,8 +11403,19 @@ Examples:
11342
11403
  }
11343
11404
  }
11344
11405
  catch (err) {
11406
+ // EW-2 (CLI-OUTCOME-UNKNOWN-EXIT-WIRING): "inbox --mark-read/--mark-actioned".
11407
+ // The per-id --mark-actioned loop and the --mark-read PATCH loop both
11408
+ // catch-and-continue internally (never rethrow), but the listing GET
11409
+ // (both the --mark-read paging loop and the plain-listing branch) is
11410
+ // unguarded and propagates straight here. In practice TR-3's
11411
+ // OUTCOME_UNKNOWN ApiError (with `.exitCode`) is a non-GET-only throw
11412
+ // in `requestWithRetry` today, so a GET here won't produce it — this
11413
+ // wiring is forward consistency (and a defense against a future
11414
+ // GET-side `.exitCode`), not an exercised exit-5 path for `inbox`
11415
+ // right now. Any other ApiError (non-2xx response) is unaffected:
11416
+ // it has no `.exitCode`, so this still exits 1, same as before.
11345
11417
  console.error(chalk.red(err instanceof Error ? err.message : String(err)));
11346
- process.exit(1);
11418
+ exitForError(err);
11347
11419
  }
11348
11420
  });
11349
11421
  // ── F32 — Pause Switches: pause / resume / pause status ─────────────────────