@formigio/fazemos-cli 0.10.92 → 0.10.94

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.
@@ -0,0 +1,65 @@
1
+ /**
2
+ * BUG178 slice (i) — `agents override` preview/confirm surface.
3
+ *
4
+ * The command used to describe itself as a "shallow merge" and only listed
5
+ * the keys present in `--config`. Both were false: the API (`PATCH
6
+ * /api/organizations/:orgId/projects/:projectId/agents/:name`) stores
7
+ * `override` as the entire Project override document — any key that was in
8
+ * the previous override but is absent from the new `--config` is silently
9
+ * dropped and reverts to the Org baseline (and an empty `{}` deletes the
10
+ * override row outright). The old preview only showed the keys the caller
11
+ * typed, so a drop was invisible until it happened.
12
+ *
13
+ * This module is the pure, unit-testable half of the fix: given the
14
+ * existing override document, the document about to be written, and the Org
15
+ * baseline (for computing what a dropped key reverts to), it produces a
16
+ * status for every key in play and the exact lines to print. No API calls,
17
+ * no process.exit, no stdin — the command action handler (src/index.ts,
18
+ * `agents override`) owns I/O and wraps `.text` in the right chalk color
19
+ * per `.style`.
20
+ *
21
+ * Kate ruling 3c234ae3 / Marco brief 2026-10-19h §1, test rows T1-T6.
22
+ */
23
+ /** A single line of preview output, with an optional chalk style for the caller to apply. */
24
+ export interface PreviewLine {
25
+ text: string;
26
+ style?: 'red' | 'yellow' | 'gray';
27
+ }
28
+ export type KeyStatus = 'ADDED' | 'CHANGED' | 'UNCHANGED' | 'DROPPED';
29
+ export interface KeyDiff {
30
+ key: string;
31
+ status: KeyStatus;
32
+ }
33
+ export interface OverridePreviewResult {
34
+ /** Full set of lines to print, in order. */
35
+ lines: PreviewLine[];
36
+ /** Per-key status, sorted by key, for callers that need the raw table (e.g. tests). */
37
+ diffs: KeyDiff[];
38
+ /** Keys present in `existing` but absent from `next` — the confirm prompt names these. */
39
+ droppedKeys: string[];
40
+ /** True when `next` is `{}` — the API deletes the override row entirely. */
41
+ isDelete: boolean;
42
+ }
43
+ export interface RenderOverridePreviewOptions {
44
+ /** Agent name, for the {}-delete line ("This DELETES the Project override for <name>..."). */
45
+ name: string;
46
+ /** Print full values instead of truncating anything over 200 chars. */
47
+ verbose?: boolean;
48
+ }
49
+ /**
50
+ * Build the full override preview: per-key ADDED/CHANGED/UNCHANGED/DROPPED
51
+ * table, both full documents (pretty JSON, truncated unless `--verbose`),
52
+ * and (when `next` is `{}`) the red delete line.
53
+ *
54
+ * @param existing `current.agent.project_override_config` — `null` means no override exists yet.
55
+ * @param next The parsed `--config` exactly as it will be stored.
56
+ * @param baseline `current.agent.org_baseline_config` — only used to show what a DROPPED key reverts to.
57
+ */
58
+ export declare function renderOverridePreview(existing: Record<string, unknown> | null, next: Record<string, unknown>, baseline: Record<string, unknown>, opts: RenderOverridePreviewOptions): OverridePreviewResult;
59
+ /**
60
+ * The exact copy (Marco brief 2026-10-19h §1 item 6) replacing every
61
+ * "shallow merge" claim in the command's description, JSDoc, and printed
62
+ * copy — all of which were false (BUG178): the write is a whole-document
63
+ * replace, not a merge.
64
+ */
65
+ export declare const OVERRIDE_REPLACE_COPY = "Replaces the entire Project override document with --config. Keys in the current override that are absent from --config are DROPPED and revert to the Org baseline. To change one field, start from the current override (`fazemos agents show <name>`) and pass the full document.";
@@ -0,0 +1,149 @@
1
+ /**
2
+ * BUG178 slice (i) — `agents override` preview/confirm surface.
3
+ *
4
+ * The command used to describe itself as a "shallow merge" and only listed
5
+ * the keys present in `--config`. Both were false: the API (`PATCH
6
+ * /api/organizations/:orgId/projects/:projectId/agents/:name`) stores
7
+ * `override` as the entire Project override document — any key that was in
8
+ * the previous override but is absent from the new `--config` is silently
9
+ * dropped and reverts to the Org baseline (and an empty `{}` deletes the
10
+ * override row outright). The old preview only showed the keys the caller
11
+ * typed, so a drop was invisible until it happened.
12
+ *
13
+ * This module is the pure, unit-testable half of the fix: given the
14
+ * existing override document, the document about to be written, and the Org
15
+ * baseline (for computing what a dropped key reverts to), it produces a
16
+ * status for every key in play and the exact lines to print. No API calls,
17
+ * no process.exit, no stdin — the command action handler (src/index.ts,
18
+ * `agents override`) owns I/O and wraps `.text` in the right chalk color
19
+ * per `.style`.
20
+ *
21
+ * Kate ruling 3c234ae3 / Marco brief 2026-10-19h §1, test rows T1-T6.
22
+ */
23
+ import { isDeepStrictEqual } from 'node:util';
24
+ import { hashBuffer } from './assetHash.js';
25
+ const TRUNCATE_AT = 200;
26
+ /**
27
+ * Replace any string longer than TRUNCATE_AT chars with a truncation
28
+ * marker carrying the original length and a 12-char sha256 prefix, so a
29
+ * truncated value is still identifiable (e.g. "did my new systemPrompt
30
+ * actually change?") without printing 5,000 chars to a terminal. Applies
31
+ * recursively via JSON.stringify's replacer, so it covers both whole-
32
+ * document pretty-printing and single-value formatting with one function.
33
+ */
34
+ function truncatingReplacer(verbose) {
35
+ return (_key, val) => {
36
+ if (!verbose && typeof val === 'string' && val.length > TRUNCATE_AT) {
37
+ const hex = hashBuffer(Buffer.from(val, 'utf-8')).hex.slice(0, 12);
38
+ return `${val.slice(0, TRUNCATE_AT)}… (${val.length} chars, sha256:${hex})`;
39
+ }
40
+ return val;
41
+ };
42
+ }
43
+ function stringifyTruncated(value, verbose, indent) {
44
+ return JSON.stringify(value, truncatingReplacer(verbose), indent);
45
+ }
46
+ /** Render a single field value (for the per-key table), or "(unset)" when absent. */
47
+ function formatValue(value, verbose) {
48
+ if (value === undefined)
49
+ return '(unset)';
50
+ return stringifyTruncated(value, verbose);
51
+ }
52
+ function indentLines(text, indent = ' ') {
53
+ return text.split('\n').map((line) => ({ text: `${indent}${line}` }));
54
+ }
55
+ /**
56
+ * Deep-equal for JSON-shaped values (req 2: "deep-equal compare, not ===").
57
+ *
58
+ * `existing` comes back from a JSONB column, and Postgres re-orders object
59
+ * keys on the stored side (shorter keys first, then bytewise) — so a naive
60
+ * `JSON.stringify(a) === JSON.stringify(b)` comparison is key-order-
61
+ * sensitive and reports a false CHANGED for a structurally-identical nested
62
+ * object whose keys happen to come back in a different order (Y1). Use
63
+ * `node:util`'s `isDeepStrictEqual`, which compares structurally regardless
64
+ * of key order (and still treats `[1,2]` vs `[2,1]` as different, since
65
+ * array order is semantic).
66
+ */
67
+ function deepEqual(a, b) {
68
+ return isDeepStrictEqual(a, b);
69
+ }
70
+ /**
71
+ * Build the full override preview: per-key ADDED/CHANGED/UNCHANGED/DROPPED
72
+ * table, both full documents (pretty JSON, truncated unless `--verbose`),
73
+ * and (when `next` is `{}`) the red delete line.
74
+ *
75
+ * @param existing `current.agent.project_override_config` — `null` means no override exists yet.
76
+ * @param next The parsed `--config` exactly as it will be stored.
77
+ * @param baseline `current.agent.org_baseline_config` — only used to show what a DROPPED key reverts to.
78
+ */
79
+ export function renderOverridePreview(existing, next, baseline, opts) {
80
+ const verbose = !!opts.verbose;
81
+ const existingDoc = existing ?? {};
82
+ const isDelete = Object.keys(next).length === 0;
83
+ const allKeys = Array.from(new Set([...Object.keys(existingDoc), ...Object.keys(next)])).sort();
84
+ const diffs = allKeys.map((key) => {
85
+ const inExisting = Object.prototype.hasOwnProperty.call(existingDoc, key);
86
+ const inNext = Object.prototype.hasOwnProperty.call(next, key);
87
+ if (inExisting && !inNext)
88
+ return { key, status: 'DROPPED' };
89
+ if (!inExisting && inNext)
90
+ return { key, status: 'ADDED' };
91
+ return {
92
+ key,
93
+ status: deepEqual(existingDoc[key], next[key])
94
+ ? 'UNCHANGED'
95
+ : 'CHANGED',
96
+ };
97
+ });
98
+ const droppedKeys = diffs.filter((d) => d.status === 'DROPPED').map((d) => d.key);
99
+ const lines = [];
100
+ lines.push({ text: 'Current override:' });
101
+ if (existing === null) {
102
+ lines.push({ text: ' (no override)', style: 'gray' });
103
+ }
104
+ else {
105
+ lines.push(...indentLines(stringifyTruncated(existingDoc, verbose, 2)));
106
+ }
107
+ lines.push({ text: '' });
108
+ lines.push({ text: 'New override (what --config will store):' });
109
+ lines.push(...indentLines(stringifyTruncated(next, verbose, 2)));
110
+ lines.push({ text: '' });
111
+ if (isDelete) {
112
+ lines.push({
113
+ text: `This DELETES the Project override for ${opts.name}; every field reverts to the Org baseline.`,
114
+ style: 'red',
115
+ });
116
+ lines.push({ text: '' });
117
+ }
118
+ lines.push({ text: 'Fields:' });
119
+ for (const diff of diffs) {
120
+ if (diff.status === 'ADDED') {
121
+ lines.push({ text: ` ${diff.key}: ADDED` });
122
+ lines.push({ text: ` + ${formatValue(next[diff.key], verbose)}` });
123
+ }
124
+ else if (diff.status === 'CHANGED') {
125
+ lines.push({ text: ` ${diff.key}: CHANGED` });
126
+ lines.push({ text: ` − ${formatValue(existingDoc[diff.key], verbose)}` });
127
+ lines.push({ text: ` + ${formatValue(next[diff.key], verbose)}` });
128
+ }
129
+ else if (diff.status === 'UNCHANGED') {
130
+ lines.push({ text: ` ${diff.key}: UNCHANGED` });
131
+ lines.push({ text: ` = ${formatValue(next[diff.key], verbose)}` });
132
+ }
133
+ else {
134
+ const baselineHas = Object.prototype.hasOwnProperty.call(baseline, diff.key);
135
+ const revertText = baselineHas ? formatValue(baseline[diff.key], verbose) : '(unset)';
136
+ lines.push({ text: ` ${diff.key}: DROPPED`, style: 'yellow' });
137
+ lines.push({ text: ` → reverts to Org baseline: ${revertText}` });
138
+ }
139
+ }
140
+ return { lines, diffs, droppedKeys, isDelete };
141
+ }
142
+ /**
143
+ * The exact copy (Marco brief 2026-10-19h §1 item 6) replacing every
144
+ * "shallow merge" claim in the command's description, JSDoc, and printed
145
+ * copy — all of which were false (BUG178): the write is a whole-document
146
+ * replace, not a merge.
147
+ */
148
+ export const OVERRIDE_REPLACE_COPY = 'Replaces the entire Project override document with --config. Keys in the current override that are absent from --config are DROPPED and revert to the Org baseline. To change one field, start from the current override (`fazemos agents show <name>`) and pass the full document.';
149
+ //# sourceMappingURL=overridePreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"overridePreview.js","sourceRoot":"","sources":["../../src/lib/overridePreview.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,W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AAM,WAAW,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;YAC7E,MAAM,UAAU,GAAG,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACtF,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC,GAAG,WAAW,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;YAChE,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,kCAAkC,UAAU,EAAE,EAAE,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC;AACjD,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAChC,qRAAqR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formigio/fazemos-cli",
3
- "version": "0.10.92",
3
+ "version": "0.10.94",
4
4
  "description": "CLI for the Fazemos Team Accomplishment Platform",
5
5
  "type": "module",
6
6
  "license": "MIT",