@formigio/fazemos-cli 0.10.92 → 0.10.93
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 +178 -35
- package/dist/index.js.map +1 -1
- package/dist/lib/overridePreview.d.ts +65 -0
- package/dist/lib/overridePreview.js +149 -0
- package/dist/lib/overridePreview.js.map +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Command } from 'commander';
|
|
3
3
|
import chalk from 'chalk';
|
|
4
|
+
import { renderOverridePreview, OVERRIDE_REPLACE_COPY } from './lib/overridePreview.js';
|
|
4
5
|
import { config, getEnv, getToken, getActiveEnvName, getActiveEnvSource, setEnvOverride, getActiveOrgId, setActiveOrgId, addEnvironment, hasEnvironments,
|
|
5
6
|
// F15 — project context helpers
|
|
6
7
|
getActiveProjectId, setActiveProjectId, clearActiveProjectId, findProjectBySlug, findProjectById, findOrgById,
|
|
@@ -8301,19 +8302,27 @@ async function preCheckAgentSourceForDelete(opts) {
|
|
|
8301
8302
|
process.exit(1);
|
|
8302
8303
|
}
|
|
8303
8304
|
/**
|
|
8304
|
-
* F17 §8.3 — `agents override <name>`: create/update a
|
|
8305
|
-
* for the named Org agent. PATCH with `{override: <parsed>}`.
|
|
8305
|
+
* F17 §8.3 / BUG178 slice (i) — `agents override <name>`: create/update a
|
|
8306
|
+
* Project override for the named Org agent. PATCH with `{override: <parsed>}`.
|
|
8306
8307
|
*
|
|
8307
|
-
*
|
|
8308
|
-
*
|
|
8308
|
+
* This is a whole-document replace, not a merge: any key present in the
|
|
8309
|
+
* current override but absent from `--config` is DROPPED and reverts to
|
|
8310
|
+
* the Org baseline, and `--config '{}'` deletes the override row entirely.
|
|
8311
|
+
* `renderOverridePreview` (src/lib/overridePreview.ts) computes the
|
|
8312
|
+
* ADDED/CHANGED/UNCHANGED/DROPPED status for every key so the preview
|
|
8313
|
+
* cannot lie about what a save will do (BUG178). --dry-run prints that
|
|
8314
|
+
* preview and exits without calling the API (Kate Q2). --verbose prints
|
|
8315
|
+
* full values instead of the >200-char truncation marker. --yes bypasses
|
|
8316
|
+
* the confirmation prompt.
|
|
8309
8317
|
*/
|
|
8310
8318
|
agentsCmd
|
|
8311
8319
|
.command('override')
|
|
8312
|
-
.description(
|
|
8320
|
+
.description(OVERRIDE_REPLACE_COPY)
|
|
8313
8321
|
.argument('<name>', 'Agent name (e.g., marco)')
|
|
8314
8322
|
.requiredOption('--config <json-or-file>', 'Override config as inline JSON or a file path')
|
|
8315
8323
|
.option('--project <slug>', 'Override active Project for this call')
|
|
8316
8324
|
.option('--dry-run', 'Print the diff without calling the API', false)
|
|
8325
|
+
.option('--verbose', 'Print full values instead of truncating long ones', false)
|
|
8317
8326
|
.option('--yes', 'Skip the confirmation prompt', false)
|
|
8318
8327
|
.action(async (name, opts) => {
|
|
8319
8328
|
try {
|
|
@@ -8339,7 +8348,6 @@ agentsCmd
|
|
|
8339
8348
|
const existing = current.agent;
|
|
8340
8349
|
const proj = findProjectById(orgId, projectId);
|
|
8341
8350
|
const projSlug = proj?.slug ?? projectId;
|
|
8342
|
-
const fieldsToUpdate = Object.keys(override);
|
|
8343
8351
|
console.log(chalk.cyan(`Overriding ${name} for project: ${projSlug}`));
|
|
8344
8352
|
if (existing.source === 'org') {
|
|
8345
8353
|
console.log(`Source: org agent → project-override`);
|
|
@@ -8351,30 +8359,33 @@ agentsCmd
|
|
|
8351
8359
|
console.log(chalk.yellow(`Warning: ${name} is a Project-only agent — this will be rejected by the API.`));
|
|
8352
8360
|
console.log(chalk.gray('Use `fazemos agents add` (update) or PATCH via the UI.'));
|
|
8353
8361
|
}
|
|
8354
|
-
console.log(`Fields to update: ${fieldsToUpdate.join(', ')}`);
|
|
8355
8362
|
console.log('');
|
|
8356
|
-
console.log(chalk.gray(
|
|
8357
|
-
console.log(chalk.gray('Arrays are not merged — they replace.'));
|
|
8363
|
+
console.log(chalk.gray(OVERRIDE_REPLACE_COPY));
|
|
8358
8364
|
console.log('');
|
|
8359
|
-
console.log(chalk.gray('Diff (Org baseline → Project override):'));
|
|
8360
8365
|
const baseline = (existing.org_baseline_config ?? {});
|
|
8361
|
-
|
|
8362
|
-
|
|
8363
|
-
const
|
|
8364
|
-
|
|
8365
|
-
const afterStr = JSON.stringify(after).slice(0, 80);
|
|
8366
|
-
console.log(` ${k}:`);
|
|
8367
|
-
console.log(` − ${beforeStr}`);
|
|
8368
|
-
console.log(` + ${afterStr}`);
|
|
8366
|
+
const preview = renderOverridePreview(existing.project_override_config ?? null, override, baseline, { name, verbose: !!opts.verbose });
|
|
8367
|
+
for (const line of preview.lines) {
|
|
8368
|
+
const text = line.style ? chalk[line.style](line.text) : line.text;
|
|
8369
|
+
console.log(text);
|
|
8369
8370
|
}
|
|
8370
8371
|
console.log('');
|
|
8371
8372
|
if (opts.dryRun) {
|
|
8372
8373
|
console.log(chalk.yellow('[dry run] No changes sent to the API.'));
|
|
8373
8374
|
return;
|
|
8374
8375
|
}
|
|
8375
|
-
if (existing.source === 'org' || existing.source === 'project_override') {
|
|
8376
|
+
if (!preview.isDelete && (existing.source === 'org' || existing.source === 'project_override')) {
|
|
8376
8377
|
console.log(`This will diverge ${name}'s config in ${projSlug} from the Org baseline.`);
|
|
8377
8378
|
console.log(`Future Org-level changes to these fields will not propagate.`);
|
|
8379
|
+
}
|
|
8380
|
+
if (preview.isDelete) {
|
|
8381
|
+
console.log(chalk.red(`This DELETES the Project override for ${name}; every field reverts to the Org baseline.`));
|
|
8382
|
+
}
|
|
8383
|
+
if (preview.droppedKeys.length > 0) {
|
|
8384
|
+
console.log(chalk.yellow(`This drops: ${preview.droppedKeys.join(', ')} (reverting to Org baseline).`));
|
|
8385
|
+
}
|
|
8386
|
+
if (existing.source === 'org' ||
|
|
8387
|
+
existing.source === 'project_override' ||
|
|
8388
|
+
preview.droppedKeys.length > 0) {
|
|
8378
8389
|
await confirmOrAbort('Proceed? [y/N]: ', !!opts.yes);
|
|
8379
8390
|
}
|
|
8380
8391
|
const result = await api('PATCH', `/api/organizations/${orgId}/projects/${projectId}/agents/${encodeURIComponent(name)}`, { override }, { noProjectHeader: true });
|
|
@@ -10973,18 +10984,31 @@ transition), so this PATCHes to read first when a row is still unread, then
|
|
|
10973
10984
|
PATCHes to actioned. A 409 on a row that is already terminal (actioned or
|
|
10974
10985
|
archived) is reported and is non-fatal — it does not stop the remaining ids.
|
|
10975
10986
|
|
|
10987
|
+
Project scoping (BUG277-CLI containment): the listing and --mark-read are
|
|
10988
|
+
scoped to the caller's resolved project — --project <slug> if given, else the
|
|
10989
|
+
active project (.fazemos.json / fazemos projects switch). A dispatch with a
|
|
10990
|
+
NULL project_id is org-level: it is always listed, but --mark-read NEVER
|
|
10991
|
+
bulk-marks it — org-level rows are only markable by id, via --mark-actioned.
|
|
10992
|
+
--mark-read with no resolvable project fails closed (exits non-zero, marks
|
|
10993
|
+
nothing). Pass --all-projects to skip the project filter on the listing only
|
|
10994
|
+
(read-only widen; refused together with --mark-read).
|
|
10995
|
+
|
|
10976
10996
|
Examples:
|
|
10977
10997
|
fazemos inbox --role chief-of-staff # unread for role
|
|
10978
10998
|
fazemos inbox --role engineering-director --status all
|
|
10979
|
-
fazemos inbox --role project-manager --mark-read # drain + mark read
|
|
10999
|
+
fazemos inbox --role project-manager --mark-read # drain + mark read, scoped to the active project (NULL-project rows are listed but never bulk-marked)
|
|
11000
|
+
fazemos inbox --project other-proj --mark-read # drain a specific project
|
|
11001
|
+
fazemos inbox --all-projects # list across every project in the org (read-only)
|
|
10980
11002
|
fazemos inbox --format json --role luca | jq .
|
|
10981
|
-
fazemos inbox --mark-actioned <id> [<id>...] # stage row(s) to actioned`)
|
|
11003
|
+
fazemos inbox --mark-actioned <id> [<id>...] # stage row(s) to actioned (by id; works on org-level rows too)`)
|
|
10982
11004
|
.option('--role <slug>', 'filter to a specific role-slug (defaults to all roles the caller fills)')
|
|
10983
11005
|
.option('--status <status>', 'unread | read | all (default: unread)', 'unread')
|
|
10984
11006
|
.option('--limit <n>', 'max dispatches to return (default: 50)', (v) => parseInt(v, 10), 50)
|
|
10985
11007
|
.option('--format <format>', 'table | json (default: table)', 'table')
|
|
10986
|
-
.option('--mark-read', 'after listing, PATCH each dispatch to status=read')
|
|
11008
|
+
.option('--mark-read', 'after listing, PATCH each dispatch to status=read (own-project rows only; NULL-project rows are never bulk-marked)')
|
|
10987
11009
|
.option('--mark-actioned <ids...>', 'mark the given dispatch id(s) as actioned (staged read→actioned; a 409 on an already-terminal row is reported and non-fatal)')
|
|
11010
|
+
.option('--project <slug>', 'scope the listing / --mark-read to this project (default: the active project)')
|
|
11011
|
+
.option('--all-projects', 'skip the project filter on the listing (read-only; refused together with --mark-read)', false)
|
|
10988
11012
|
.action(async (opts) => {
|
|
10989
11013
|
try {
|
|
10990
11014
|
// ── DISPATCH-DB-ONLY-INBOX (P2, T2.6) — `--mark-actioned <ids...>` ────
|
|
@@ -11055,23 +11079,126 @@ Examples:
|
|
|
11055
11079
|
if (!validFormats.includes(opts.format)) {
|
|
11056
11080
|
throw new Error(`Invalid --format "${opts.format}". Valid: ${validFormats.join(', ')}`);
|
|
11057
11081
|
}
|
|
11082
|
+
// ── BUG277-CLI: project-scope guard + resolution ────────────────────
|
|
11083
|
+
// Dispatch reads/writes are not server-project-scoped today (fix (b),
|
|
11084
|
+
// API, is a separate train). This is the CLI-side containment: scope
|
|
11085
|
+
// the listing and --mark-read to the caller's resolved project so a
|
|
11086
|
+
// shared filler (e.g. a role filled in both fazemos and
|
|
11087
|
+
// formigio-graph) can't drain another project's rows.
|
|
11088
|
+
//
|
|
11089
|
+
// --mark-read + --all-projects is refused outright — bulk-marking
|
|
11090
|
+
// across every project in the org is exactly the cross-project write
|
|
11091
|
+
// this fix exists to close off.
|
|
11092
|
+
if (opts.markRead && opts.allProjects) {
|
|
11093
|
+
console.error(chalk.red('--mark-read cannot be combined with --all-projects.'));
|
|
11094
|
+
console.error(chalk.gray('Scope the drain with --project <slug>, or drop --mark-read to just list.'));
|
|
11095
|
+
process.exit(1);
|
|
11096
|
+
return;
|
|
11097
|
+
}
|
|
11098
|
+
// Resolution is for the CLIENT-SIDE filter only — `noProjectHeader:
|
|
11099
|
+
// true` stays on every call below, unchanged. --all-projects skips
|
|
11100
|
+
// resolution entirely: it's a "don't filter" switch, never a
|
|
11101
|
+
// `?view=all` query param (the server doesn't define one for this
|
|
11102
|
+
// endpoint). An unresolvable --project <slug> throws
|
|
11103
|
+
// ApiError(UNKNOWN_PROJECT), which the outer catch turns into the
|
|
11104
|
+
// standard exit 1.
|
|
11105
|
+
const resolvedProjectId = opts.allProjects
|
|
11106
|
+
? null
|
|
11107
|
+
: await resolveProjectIdBySlug(opts.project);
|
|
11108
|
+
// Fail closed: a null resolution (no active project, no --project)
|
|
11109
|
+
// marks nothing. `null === null` must never be read as "no filter" —
|
|
11110
|
+
// that would bulk-mark every project's rows, the opposite of the fix.
|
|
11111
|
+
if (opts.markRead && resolvedProjectId == null) {
|
|
11112
|
+
console.error(chalk.red('No active project resolved — refusing to bulk-mark dispatches as read.'));
|
|
11113
|
+
console.error(chalk.gray('Pass --project <slug>, or set an active project: fazemos projects switch <slug>'));
|
|
11114
|
+
process.exit(1);
|
|
11115
|
+
return;
|
|
11116
|
+
}
|
|
11058
11117
|
// Build query
|
|
11059
11118
|
const params = new URLSearchParams();
|
|
11060
11119
|
if (opts.role)
|
|
11061
11120
|
params.set('role', opts.role);
|
|
11062
11121
|
params.set('status', opts.status);
|
|
11063
11122
|
params.set('limit', String(opts.limit));
|
|
11064
|
-
|
|
11065
|
-
|
|
11066
|
-
|
|
11067
|
-
|
|
11123
|
+
// ── Fetch ────────────────────────────────────────────────
|
|
11124
|
+
// Plain listing: one page, as before. --mark-read pages through
|
|
11125
|
+
// ?cursor= until exhausted (capped at PAGE_CAP) — the client-side
|
|
11126
|
+
// project filter runs AFTER the server's LIMIT, so other-project rows
|
|
11127
|
+
// can fill a page and hide the caller's own-project unread rows
|
|
11128
|
+
// underneath it (page starvation; a false "nothing to mark" on a
|
|
11129
|
+
// shared filler). This is a containment limit: PR B's server-side
|
|
11130
|
+
// project filter removes the need for client paging.
|
|
11131
|
+
const PAGE_CAP = 10;
|
|
11132
|
+
let items = [];
|
|
11133
|
+
let nextCursor = null;
|
|
11134
|
+
let pageCapHit = false;
|
|
11135
|
+
if (opts.markRead) {
|
|
11136
|
+
let cursor;
|
|
11137
|
+
let pages = 0;
|
|
11138
|
+
do {
|
|
11139
|
+
const pageQuery = new URLSearchParams(params);
|
|
11140
|
+
if (cursor)
|
|
11141
|
+
pageQuery.set('cursor', cursor);
|
|
11142
|
+
const page = await api('GET', `/api/dispatches?${pageQuery.toString()}`, undefined, {
|
|
11143
|
+
noProjectHeader: true,
|
|
11144
|
+
});
|
|
11145
|
+
items = items.concat(page.items ?? []);
|
|
11146
|
+
nextCursor = page.nextCursor ?? null;
|
|
11147
|
+
cursor = nextCursor ?? undefined;
|
|
11148
|
+
pages++;
|
|
11149
|
+
} while (cursor && pages < PAGE_CAP);
|
|
11150
|
+
if (cursor) {
|
|
11151
|
+
pageCapHit = true;
|
|
11152
|
+
}
|
|
11153
|
+
}
|
|
11154
|
+
else {
|
|
11155
|
+
const result = await api('GET', `/api/dispatches?${params.toString()}`, undefined, {
|
|
11156
|
+
noProjectHeader: true,
|
|
11157
|
+
});
|
|
11158
|
+
items = result.items ?? [];
|
|
11159
|
+
nextCursor = result.nextCursor ?? null;
|
|
11160
|
+
}
|
|
11161
|
+
// ── Client-side project filter (BUG277-CLI containment) ─────────────
|
|
11162
|
+
// Default: own-project + org-level (NULL project_id) rows. --all-
|
|
11163
|
+
// projects: unfiltered. Unresolved (no --project, no active project,
|
|
11164
|
+
// and NOT --all-projects): NULL rows only — never fail open to
|
|
11165
|
+
// everything.
|
|
11166
|
+
let filteredItems;
|
|
11167
|
+
let unresolvedListing = false;
|
|
11168
|
+
if (opts.allProjects) {
|
|
11169
|
+
filteredItems = items;
|
|
11170
|
+
}
|
|
11171
|
+
else if (resolvedProjectId == null) {
|
|
11172
|
+
unresolvedListing = true;
|
|
11173
|
+
filteredItems = items.filter(d => d.project_id == null);
|
|
11174
|
+
}
|
|
11175
|
+
else {
|
|
11176
|
+
filteredItems = items.filter(d => d.project_id === resolvedProjectId || d.project_id == null);
|
|
11177
|
+
}
|
|
11178
|
+
const hiddenCount = items.length - filteredItems.length;
|
|
11179
|
+
const notes = [];
|
|
11180
|
+
if (unresolvedListing) {
|
|
11181
|
+
notes.push('No active project resolved; showing org-level (NULL-project) dispatches only. Pass --project <slug> or --all-projects to see more.');
|
|
11182
|
+
}
|
|
11183
|
+
if (hiddenCount > 0) {
|
|
11184
|
+
notes.push(`${hiddenCount} other-project row(s) hidden.`);
|
|
11185
|
+
}
|
|
11186
|
+
if (opts.markRead) {
|
|
11187
|
+
const orgLevelUnreadCount = items.filter(d => d.project_id == null && d.status === 'unread').length;
|
|
11188
|
+
if (orgLevelUnreadCount > 0) {
|
|
11189
|
+
notes.push(`${orgLevelUnreadCount} org-level row(s) not marked; use --mark-actioned <id>.`);
|
|
11190
|
+
}
|
|
11191
|
+
}
|
|
11192
|
+
if (pageCapHit) {
|
|
11193
|
+
notes.push(`Stopped after ${PAGE_CAP} page(s) while draining; more dispatches may remain unmarked. Re-run --mark-read to continue.`);
|
|
11194
|
+
}
|
|
11068
11195
|
// ── JSON output ──────────────────────────────────────────
|
|
11069
11196
|
if (opts.format === 'json') {
|
|
11070
|
-
console.log(JSON.stringify(
|
|
11197
|
+
console.log(JSON.stringify({ items: filteredItems, nextCursor }, null, 2));
|
|
11071
11198
|
}
|
|
11072
11199
|
else {
|
|
11073
11200
|
// ── Table output ─────────────────────────────────────
|
|
11074
|
-
if (
|
|
11201
|
+
if (filteredItems.length === 0) {
|
|
11075
11202
|
if (opts.role) {
|
|
11076
11203
|
console.log(chalk.gray(`No ${opts.status} dispatches for role "${opts.role}".`));
|
|
11077
11204
|
}
|
|
@@ -11111,32 +11238,48 @@ Examples:
|
|
|
11111
11238
|
].join(' ');
|
|
11112
11239
|
console.log(header);
|
|
11113
11240
|
console.log(chalk.gray('─'.repeat(130)));
|
|
11114
|
-
for (const d of
|
|
11241
|
+
for (const d of filteredItems) {
|
|
11115
11242
|
const priColor = d.priority === 'high' ? chalk.red : d.priority === 'low' ? chalk.gray : chalk.white;
|
|
11243
|
+
// BUG277-CLI — flag org-level (NULL project_id) rows in the table
|
|
11244
|
+
// so it's visible they're never swept by --mark-read.
|
|
11245
|
+
const orgLevelTag = d.project_id == null ? '[org-level] ' : '';
|
|
11116
11246
|
const row = [
|
|
11117
11247
|
pad(d.to_role ?? '', COL_ROLE),
|
|
11118
11248
|
pad(d.from_role ?? '', COL_FROM),
|
|
11119
11249
|
pad(d.type ?? '', COL_TYPE),
|
|
11120
11250
|
priColor(pad(d.priority ?? 'normal', COL_PRI)),
|
|
11121
11251
|
chalk.gray(pad(age(d.created_at), COL_AGE)),
|
|
11122
|
-
chalk.cyan(pad(d.summary ?? d.body?.split('\n')[0] ?? '', COL_BODY)),
|
|
11252
|
+
chalk.cyan(pad(orgLevelTag + (d.summary ?? d.body?.split('\n')[0] ?? ''), COL_BODY)),
|
|
11123
11253
|
].join(' ');
|
|
11124
11254
|
console.log(row);
|
|
11125
11255
|
}
|
|
11126
11256
|
console.log(chalk.gray('─'.repeat(130)));
|
|
11127
|
-
console.log(chalk.gray(`${
|
|
11257
|
+
console.log(chalk.gray(`${filteredItems.length} dispatch(es) shown.${nextCursor ? ' More available (use --limit to increase).' : ''}`));
|
|
11258
|
+
}
|
|
11259
|
+
}
|
|
11260
|
+
// Notes go to stderr in JSON mode (stdout must stay pure, parseable
|
|
11261
|
+
// JSON) and to stdout alongside the table in table mode.
|
|
11262
|
+
for (const note of notes) {
|
|
11263
|
+
if (opts.format === 'json') {
|
|
11264
|
+
console.error(chalk.gray(note));
|
|
11265
|
+
}
|
|
11266
|
+
else {
|
|
11267
|
+
console.log(chalk.gray(note));
|
|
11128
11268
|
}
|
|
11129
11269
|
}
|
|
11130
11270
|
// ── --mark-read ──────────────────────────────────────────
|
|
11131
11271
|
if (opts.markRead && items.length > 0) {
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11272
|
+
// AC1-NULL: explicit `project_id != null` BEFORE the equality check
|
|
11273
|
+
// — a NULL row must never compare equal to a resolved id by
|
|
11274
|
+
// incidental null-handling.
|
|
11275
|
+
const bulkSet = items.filter(d => d.status === 'unread' && d.project_id != null && d.project_id === resolvedProjectId);
|
|
11276
|
+
if (bulkSet.length === 0) {
|
|
11277
|
+
console.log(chalk.gray('\nAll shown dispatches already read, or excluded by project scope; nothing to mark.'));
|
|
11135
11278
|
}
|
|
11136
11279
|
else {
|
|
11137
11280
|
let marked = 0;
|
|
11138
11281
|
let failed = 0;
|
|
11139
|
-
for (const d of
|
|
11282
|
+
for (const d of bulkSet) {
|
|
11140
11283
|
try {
|
|
11141
11284
|
await api('PATCH', `/api/dispatches/${d.id}`, { status: 'read' }, {
|
|
11142
11285
|
noProjectHeader: true,
|