@uipath/maestro-builder-sdk 6.106.0 → 6.107.0

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.
@@ -20,6 +20,11 @@
20
20
  * other draft, such as one an agent just wrote (even of an operation the canvas
21
21
  * has a draft of), is refused.
22
22
  *
23
+ * Writing into a Flow project (`project.uiproj` at or above the output) that
24
+ * already holds another `.flow` below it, outside dot-folders, warns
25
+ * `SECOND_FLOW_IN_PROJECT` (project-flows.ts): `uip` or a reader that globs the
26
+ * project can take it for the project's flow.
27
+ *
23
28
  * `--no-check` is a deprecated no-op: it is accepted for one minor version, with
24
29
  * a warning, and then removed.
25
30
  */
@@ -43,6 +48,7 @@ import { flowSources, projectMainFlow, resourceSourcesOfOtherFlows } from './pro
43
48
  import { fnv1aX4Uuid } from './core/stable-id.js';
44
49
  import { cliSpelling } from './core/cli-spelling.js';
45
50
  import { readNodeCatalog } from './node-catalog-files.js';
51
+ import { secondFlowWarning } from './project-flows.js';
46
52
  /** An agent folder name: a uuid, any case. */
47
53
  const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
48
54
  export async function run(argv) {
@@ -201,6 +207,14 @@ export async function run(argv) {
201
207
  reportDiagnostics(diagnostics);
202
208
  return 1;
203
209
  }
210
+ // A second `.flow` in the Flow project, outside dot-folders (a backup, a
211
+ // baseline/ compile), is one `uip` or a globbing reader can take for the
212
+ // project's (#1996). Said here, where the `.flow` is written; never fatal.
213
+ const second = secondFlowWarning(out);
214
+ if (second !== undefined) {
215
+ console.error(` ${diagnosticLine(second)}`);
216
+ diagnostics.push(second);
217
+ }
204
218
  // Reported before the first write, so a write that throws still carries it.
205
219
  reportDiagnostics(diagnostics);
206
220
  writeJsonFile(out, flowJson);
@@ -281,6 +281,7 @@ export declare const REFUSALS: {
281
281
  readonly DATAFABRIC_UNKNOWN_FIELD: "lint";
282
282
  readonly DEAD_END: "lint";
283
283
  readonly DECLARATION_SHAPE: "lowering";
284
+ readonly DECLARATION_FORMAT_INVALID: "lowering";
284
285
  readonly DECLARATION_TYPE_NOT_FLOW: "lowering";
285
286
  readonly DECLARATION_TYPE_UNKNOWN: "lowering";
286
287
  readonly DECOMPILE_NOT_A_NUMBER: "lowering";
@@ -355,6 +355,7 @@ export const REFUSALS = {
355
355
  DATAFABRIC_UNKNOWN_FIELD: 'lint',
356
356
  DEAD_END: 'lint',
357
357
  DECLARATION_SHAPE: 'lowering',
358
+ DECLARATION_FORMAT_INVALID: 'lowering',
358
359
  DECLARATION_TYPE_NOT_FLOW: 'lowering',
359
360
  DECLARATION_TYPE_UNKNOWN: 'lowering',
360
361
  DECOMPILE_NOT_A_NUMBER: 'lowering',
package/dist/decompile.js CHANGED
@@ -40,7 +40,7 @@ import { tsKey as key, tsLiteral, tsNumber, tsObject as objLit, tsOptions as opt
40
40
  import { wireExprBody } from './core/wire-expr.js';
41
41
  import { hasExits } from './core/step-ports.js';
42
42
  import { readFlowGlobals } from './flow-variables.js';
43
- import { FLOW_TYPE_NAMES, nonFlowTypeReplacement, runtimeEquivalentFlowType } from './flow-types.js';
43
+ import { FLOW_TYPE_NAMES, runtimeEquivalentFlowType } from './flow-types.js';
44
44
  import { outputBackingGlobal, outputBackingName } from './flow-output-backing.js';
45
45
  import { mapJsCode } from './core/js-code-spans.js';
46
46
  import { VARS_READ_RE } from './core/vars-read.js';
@@ -1222,61 +1222,106 @@ function camel(id) {
1222
1222
  // ─── Variables ────────────────────────────────────────────────────────────────
1223
1223
  const TYPE_NAMES = new Set(FLOW_TYPE_NAMES);
1224
1224
  /**
1225
- * `types.<name>` for a global's type (#861).
1225
+ * `types.<name>` for a global's type (#861, #1997).
1226
1226
  *
1227
- * A Flow type prints as itself. Every other type warns once per variable (an
1228
- * error when `bestEffort` is false), and then:
1227
+ * A Flow type prints as itself. The Case-only types print as the Flow type
1228
+ * the run already sees, so an untouched global never blocks a brownfield
1229
+ * edit:
1230
+ * - `float` / `double` print as `{ type: types.number, format: 'double' }`
1231
+ * (`VarSpec.format`), which recompiles to the file's own `"type":"double"`.
1232
+ * Nothing changes, so nothing warns. The width matters: `flow pack` writes
1233
+ * it into the entry point's schema as `"format":"double"`.
1229
1234
  * - `date` / `datetime` print as `types.string`, the type Flow packaging
1230
- * already gives them, so an untouched global never blocks a brownfield
1231
- * edit. The recompiled `.flow` says `"type":"string"`; the warning says so.
1232
- * - `float`, `double` and `jsonSchema` print as written (`types.float`),
1233
- * because a recompile would lose a format or a schema kind: the declaration
1234
- * is a TypeScript error and `DECLARATION_TYPE_NOT_FLOW` at build until the
1235
- * author picks the type the warning names.
1236
- * - any other string prints as a string literal: `DECLARATION_TYPE_UNKNOWN`.
1237
- */
1238
- function typeExpr(g, imp) {
1235
+ * already gives them. The recompiled `.flow` says `"type":"string"`.
1236
+ * - `jsonSchema` prints as `types.object` (`types.array` when its schema is
1237
+ * an array's) with the file's schema (its `body`, else `schema`, as `flow pack` reads them) in
1238
+ * `{ schema }`. The recompiled `.flow` says `"type":"object"`.
1239
+ * A type that changes warns once per variable (an error when `bestEffort` is
1240
+ * false), naming what the recompile writes. Any other string prints as a
1241
+ * string literal: `DECLARATION_TYPE_UNKNOWN`.
1242
+ */
1243
+ function printedType(g) {
1239
1244
  if (TYPE_NAMES.has(g.type))
1240
- return `${imp.use('types')}.${g.type}`;
1241
- const replacement = nonFlowTypeReplacement(g.type);
1242
- const equivalent = runtimeEquivalentFlowType(g.type);
1245
+ return { type: g.type };
1246
+ if (g.type === 'float' || g.type === 'double')
1247
+ return { type: 'number', format: g.type };
1243
1248
  const head = `variable ${tsLiteral(g.id)} has type ${tsLiteral(g.type)}`;
1244
- const message = equivalent !== undefined
1245
- ? `${head}, a Case type Flow does not model. The source declares it types.${equivalent}, so a recompile `
1249
+ const equivalent = runtimeEquivalentFlowType(g.type);
1250
+ let printed;
1251
+ let message;
1252
+ if (equivalent !== undefined) {
1253
+ printed = { type: equivalent };
1254
+ message = `${head}, a Case type Flow does not model. The source declares it types.${equivalent}, so a recompile `
1246
1255
  + `writes "type":"${equivalent}" in its place; nothing changes at run time, because flow pack already `
1247
- + `writes a ${g.type} as a plain string.`
1248
- : replacement !== undefined
1249
- ? `${head}, a Case type Flow does not model (packaging and the Workbench do not know it). The source `
1250
- + `keeps types.${g.type}, which the builder refuses (DECLARATION_TYPE_NOT_FLOW): declare it as ${replacement}.`
1251
- : `${head}, which is not a Flow type. The source keeps it as a string, which the builder refuses `
1252
- + `(DECLARATION_TYPE_UNKNOWN): declare one of ${FLOW_TYPE_NAMES.map((t) => `types.${t}`).join(', ')}.`;
1256
+ + `writes a ${g.type} as a plain string.`;
1257
+ }
1258
+ else if (g.type === 'jsonSchema') {
1259
+ const schema = jsonSchemaBody(g);
1260
+ const kind = schema?.type === 'array' ? 'array' : 'object';
1261
+ printed = { type: kind, ...(schema !== undefined ? { schema } : {}) };
1262
+ message = `${head}, a Case type Flow does not model. The source declares it types.${kind}`
1263
+ + `${schema !== undefined ? ' with its schema in { schema }' : ''}, so a recompile writes "type":"${kind}" in its `
1264
+ + `place; nothing changes at run time, because the engine reads both as JSON.`;
1265
+ }
1266
+ else {
1267
+ printed = { type: g.type };
1268
+ message = `${head}, which is not a Flow type. The source keeps it as a string, which the builder refuses `
1269
+ + `(DECLARATION_TYPE_UNKNOWN): declare one of ${FLOW_TYPE_NAMES.map((t) => `types.${t}`).join(', ')}.`;
1270
+ }
1253
1271
  if (runStrict)
1254
1272
  throw new Error(`decompile: ${message}`);
1255
1273
  warnOnce(message);
1256
- if (equivalent !== undefined)
1257
- return `${imp.use('types')}.${equivalent}`;
1258
- return replacement !== undefined ? `${imp.use('types')}.${g.type}` : tsLiteral(g.type);
1274
+ return printed;
1275
+ }
1276
+ /**
1277
+ * A `jsonSchema` global's shape: the `body` Case writes it in (an object, or
1278
+ * that object as JSON text), else its `schema`. `undefined` when it has
1279
+ * neither. `body` first, because `flow pack` packs `body ?? schema`
1280
+ * (flow-workbench `variableToJsonSchema`), so the recompiled entry point packs
1281
+ * the shape the original did.
1282
+ */
1283
+ function jsonSchemaBody(g) {
1284
+ const isObject = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
1285
+ const fromBody = (body) => {
1286
+ if (isObject(body))
1287
+ return body;
1288
+ if (typeof body !== 'string')
1289
+ return undefined;
1290
+ try {
1291
+ const parsed = JSON.parse(body);
1292
+ return isObject(parsed) ? parsed : undefined;
1293
+ }
1294
+ catch {
1295
+ return undefined;
1296
+ }
1297
+ };
1298
+ return fromBody(g.body) ?? (isObject(g.schema) ? g.schema : undefined);
1259
1299
  }
1260
1300
  /**
1261
1301
  * A global carrying metadata decompiles to the rich VarSpec spelling
1262
- * (`{ type: types.x, description, subType, schema }`); a bare one keeps the
1263
- * compact `name: types.x` form.
1302
+ * (`{ type: types.x, format, description, subType, schema }`); a bare one
1303
+ * keeps the compact `name: types.x` form.
1264
1304
  */
1265
1305
  function declExpr(g, withDefault, imp, shared) {
1306
+ const printed = printedType(g);
1307
+ const type = TYPE_NAMES.has(printed.type) ? `${imp.use('types')}.${printed.type}` : tsLiteral(printed.type);
1308
+ const schema = printed.schema ?? g.schema;
1266
1309
  const meta = [];
1310
+ if (printed.format !== undefined)
1311
+ meta.push(`format: ${tsLiteral(printed.format)}`);
1267
1312
  if (withDefault && g.defaultValue !== undefined)
1268
1313
  meta.push(`default: ${tsLiteral(g.defaultValue)}`);
1269
1314
  if (g.description !== undefined)
1270
1315
  meta.push(`description: ${tsLiteral(g.description)}`);
1271
1316
  if (g.subType !== undefined)
1272
1317
  meta.push(`subType: ${tsLiteral(g.subType)}`);
1273
- if (g.schema !== undefined)
1274
- meta.push(`schema: ${tsLiteral(g.schema)}`);
1318
+ if (schema !== undefined)
1319
+ meta.push(`schema: ${tsLiteral(schema)}`);
1275
1320
  if (shared !== undefined)
1276
1321
  meta.push(`shared: ${tsLiteral(shared)}`);
1277
1322
  if (meta.length === 0)
1278
- return typeExpr(g, imp);
1279
- return `{ type: ${typeExpr(g, imp)}, ${meta.join(', ')} }`;
1323
+ return type;
1324
+ return `{ type: ${type}, ${meta.join(', ')} }`;
1280
1325
  }
1281
1326
  function sharedCopies(flow, triggers) {
1282
1327
  const globals = readFlowGlobals(flow.variables, runStrict);
@@ -67,6 +67,7 @@ export declare function planOutputBacking(built: Pick<BuiltFlow, 'inputs' | 'ste
67
67
  export declare function outputBackingGlobal(o: {
68
68
  name: string;
69
69
  type: string;
70
+ format?: string;
70
71
  default?: unknown;
71
72
  subType?: string;
72
73
  schema?: Record<string, unknown>;
@@ -221,7 +221,7 @@ export function planOutputBacking(built, outputs, vars, sharedOutputs = new Set(
221
221
  /** The `inout` global that backs output `o`: its type and value metadata, no description. */
222
222
  export function outputBackingGlobal(o, id) {
223
223
  return {
224
- id, name: id, direction: 'inout', type: o.type,
224
+ id, name: id, direction: 'inout', type: o.format ?? o.type,
225
225
  ...(o.default !== undefined ? { defaultValue: o.default } : {}),
226
226
  ...(o.subType !== undefined ? { subType: o.subType } : {}),
227
227
  ...(o.schema !== undefined ? { schema: o.schema } : {}),
@@ -74,9 +74,13 @@ export interface VarDecl {
74
74
  subType?: string;
75
75
  /** JSON schema for complex type validation (object/array shapes). */
76
76
  schema?: Record<string, unknown>;
77
+ /** A `number`'s width, written as the global's `type`. See {@link VarSpec.format}. */
78
+ format?: NumberFormat;
77
79
  /** Inputs only: the flow variable this root's input is copied into when the root fires. See {@link VarSpec.shared}. */
78
80
  shared?: string;
79
81
  }
82
+ /** The widths a `types.number` variable may keep: {@link VarSpec.format}. */
83
+ export type NumberFormat = 'float' | 'double';
80
84
  /**
81
85
  * The rich spelling of a variable declaration: pass it instead of a bare
82
86
  * `types.*` descriptor wherever `.input()` / `.output()` / `.var()` take one,
@@ -93,6 +97,17 @@ export interface VarSpec {
93
97
  subType?: string;
94
98
  /** JSON schema for complex type validation (object/array shapes). */
95
99
  schema?: Record<string, unknown>;
100
+ /**
101
+ * `types.number` only: keep a `float` or `double` width the `.flow` already
102
+ * carries. The global is written `"type":"double"` instead of `"number"`, and
103
+ * `flow pack` puts `{ "type": "number", "format": "double" }` in the entry
104
+ * point's schema. The run is the same either way: the engine reads every
105
+ * number as a double. Decompile prints it for a global a Case-era or Studio
106
+ * Web file typed `float` / `double`, so a recompile writes the file's own type
107
+ * back, e.g. `.input({ rate: { type: types.number, format: 'double' } })`.
108
+ * Any other type, or another value, is `DECLARATION_FORMAT_INVALID`.
109
+ */
110
+ format?: NumberFormat;
96
111
  /**
97
112
  * Default value — the variable's value before anything assigns it. On an
98
113
  * output it is the starting value a `{ updates }` accumulator reads, e.g.
package/dist/flow-sdk.js CHANGED
@@ -91,6 +91,10 @@ function varDeclOf(method, name, value) {
91
91
  if (value !== null && typeof value === 'object' && !Array.isArray(value)) {
92
92
  const spec = value;
93
93
  assertType(method, name, spec.type);
94
+ if (spec.format !== undefined && (spec.type !== 'number' || !NUMBER_FORMATS.includes(spec.format))) {
95
+ throw new CompileRefusal('DECLARATION_FORMAT_INVALID', `.${method}() declared ${JSON.stringify(name)} with format ${JSON.stringify(spec.format)} on types.${String(spec.type)}. `
96
+ + `A format keeps a number's width: use { type: types.number, format: 'float' } or 'double', or drop it.`);
97
+ }
94
98
  if (spec.shared !== undefined) {
95
99
  if (method !== 'input') {
96
100
  throw new CompileRefusal('SHARED_INPUT_NOT_INPUT', `.${method}() declared ${JSON.stringify(name)} with { shared }, which only an input takes: it names `
@@ -108,6 +112,7 @@ function varDeclOf(method, name, value) {
108
112
  ...(spec.description !== undefined ? { description: spec.description } : {}),
109
113
  ...(spec.subType !== undefined ? { subType: spec.subType } : {}),
110
114
  ...(spec.schema !== undefined ? { schema: spec.schema } : {}),
115
+ ...(spec.format !== undefined ? { format: spec.format } : {}),
111
116
  ...(spec.shared !== undefined ? { shared: spec.shared } : {}),
112
117
  };
113
118
  }
@@ -135,6 +140,7 @@ function assertType(method, name, type) {
135
140
  throw new CompileRefusal('DECLARATION_TYPE_UNKNOWN', `.${method}() declared ${JSON.stringify(name)} with type ${JSON.stringify(type)}, which is not `
136
141
  + `a type. Use one of ${flowTypes}.`);
137
142
  }
143
+ const NUMBER_FORMATS = ['float', 'double'];
138
144
  export function onEvent(a, opts) {
139
145
  return builtinTriggerSpec({ kind: 'event', subscription: subscriptionFrom(a, opts) });
140
146
  }
@@ -22,7 +22,10 @@ import type { TypeDesc } from './core/expr.js';
22
22
  *
23
23
  * The others are Case-only. Packaging turns `date` / `datetime` into a plain
24
24
  * `string` with no format, the expression model types `float` / `double` /
25
- * `jsonSchema` as `any`, and no Flow editor offers any of them.
25
+ * `jsonSchema` as `any`, and no Flow editor offers any of them. One thing is
26
+ * kept: packaging writes a `float` / `double` global as `"type":"number"` with
27
+ * `"format":"float"` / `"double"` in the entry point's schema, so a Flow
28
+ * number may carry that width as `{ type: types.number, format }`.
26
29
  *
27
30
  * `satisfies Record<TypeDesc, …>` makes this exhaustive: adding a type to
28
31
  * `types` without deciding whether Flow takes it is a compile error here.
@@ -36,8 +39,8 @@ declare const flowTypeSupport: {
36
39
  readonly file: true;
37
40
  readonly any: true;
38
41
  readonly integer: true;
39
- readonly float: "types.number";
40
- readonly double: "types.number";
42
+ readonly float: "{ type: types.number, format: 'float' }";
43
+ readonly double: "{ type: types.number, format: 'double' }";
41
44
  readonly date: "types.string";
42
45
  readonly datetime: "types.string";
43
46
  readonly jsonSchema: "types.object or types.array, with its shape in { schema }";
@@ -65,8 +68,10 @@ export declare function nonFlowTypeReplacement(type: string): string | undefined
65
68
  * older SDK or Studio Web wrote still round-trips; the recompile writes
66
69
  * `"type":"string"`, which the decompile warning announces.
67
70
  *
68
- * `undefined` for every other type: `float` / `double` lose a format and
69
- * `jsonSchema` a schema kind, so those keep the builder's hard stop.
71
+ * `undefined` for every other type. Decompile prints `float` / `double` as
72
+ * `{ type: types.number, format }` (`VarSpec.format`), which writes the same
73
+ * type back, and `jsonSchema` as `types.object` / `types.array` with the
74
+ * shape in `{ schema }`.
70
75
  */
71
76
  export declare function runtimeEquivalentFlowType(type: string): FlowTypeDesc | undefined;
72
77
  export {};
@@ -11,7 +11,10 @@
11
11
  *
12
12
  * The others are Case-only. Packaging turns `date` / `datetime` into a plain
13
13
  * `string` with no format, the expression model types `float` / `double` /
14
- * `jsonSchema` as `any`, and no Flow editor offers any of them.
14
+ * `jsonSchema` as `any`, and no Flow editor offers any of them. One thing is
15
+ * kept: packaging writes a `float` / `double` global as `"type":"number"` with
16
+ * `"format":"float"` / `"double"` in the entry point's schema, so a Flow
17
+ * number may carry that width as `{ type: types.number, format }`.
15
18
  *
16
19
  * `satisfies Record<TypeDesc, …>` makes this exhaustive: adding a type to
17
20
  * `types` without deciding whether Flow takes it is a compile error here.
@@ -25,8 +28,8 @@ const flowTypeSupport = {
25
28
  file: true,
26
29
  any: true,
27
30
  integer: true,
28
- float: 'types.number',
29
- double: 'types.number',
31
+ float: "{ type: types.number, format: 'float' }",
32
+ double: "{ type: types.number, format: 'double' }",
30
33
  date: 'types.string',
31
34
  datetime: 'types.string',
32
35
  jsonSchema: 'types.object or types.array, with its shape in { schema }',
@@ -54,8 +57,10 @@ export function nonFlowTypeReplacement(type) {
54
57
  * older SDK or Studio Web wrote still round-trips; the recompile writes
55
58
  * `"type":"string"`, which the decompile warning announces.
56
59
  *
57
- * `undefined` for every other type: `float` / `double` lose a format and
58
- * `jsonSchema` a schema kind, so those keep the builder's hard stop.
60
+ * `undefined` for every other type. Decompile prints `float` / `double` as
61
+ * `{ type: types.number, format }` (`VarSpec.format`), which writes the same
62
+ * type back, and `jsonSchema` as `types.object` / `types.array` with the
63
+ * shape in `{ schema }`.
59
64
  */
60
65
  export function runtimeEquivalentFlowType(type) {
61
66
  return type === 'date' || type === 'datetime' ? 'string' : undefined;
@@ -93,6 +93,8 @@ export interface SharedInputFeed {
93
93
  export interface SharedInputTarget {
94
94
  name: string;
95
95
  type: string;
96
+ /** An `auto` target's number width, from the first input feeding it. */
97
+ format?: string;
96
98
  /** What declares it: an explicit `.var()` / `.output()`, or the SDK (`auto`). */
97
99
  declaredAs: 'var' | 'output' | 'auto';
98
100
  hasDefault: boolean;
@@ -112,12 +114,14 @@ export interface SharedInputsPlan {
112
114
  autoVars: {
113
115
  name: string;
114
116
  type: string;
117
+ format?: string;
115
118
  }[];
116
119
  problems: SharedInputsProblem[];
117
120
  }
118
121
  /** The `{ shared }` slice of an input declaration. */
119
122
  interface SharedCapable extends DeclaredVariable {
120
123
  shared?: string;
124
+ format?: string;
121
125
  }
122
126
  /**
123
127
  * Plan the variables that root inputs feed with `{ shared: '<var>' }`.
@@ -157,6 +157,7 @@ export function planSharedInputs(decl) {
157
157
  target = {
158
158
  name,
159
159
  type: declared ? String(declared.type) : String(inp.type),
160
+ ...(!declared && inp.format !== undefined ? { format: inp.format } : {}),
160
161
  declaredAs: od ? 'output' : vd ? 'var' : 'auto',
161
162
  hasDefault: (od?.default ?? vd?.default) !== undefined,
162
163
  feeds: [],
@@ -216,7 +217,10 @@ export function planSharedInputs(decl) {
216
217
  const targets = [...byName.values()];
217
218
  // A target that names an input is already refused above; leaving it out here
218
219
  // keeps the global plan from reporting the same name a second time.
219
- const autoVars = targets.filter((t) => t.declaredAs === 'auto' && !inputNames.has(t.name)).map((t) => ({ name: t.name, type: t.type }));
220
+ // An auto variable keeps the first feeding input's number width, so its global has the input's type.
221
+ const autoVars = targets.filter((t) => t.declaredAs === 'auto' && !inputNames.has(t.name)).map((t) => ({
222
+ name: t.name, type: t.type, ...(t.format !== undefined ? { format: t.format } : {}),
223
+ }));
220
224
  return { targets, autoVars, problems };
221
225
  }
222
226
  /**
package/dist/merge-cli.js CHANGED
@@ -63,6 +63,10 @@
63
63
  * the sidecars in memory; what merge cannot carry is warned, and refused under
64
64
  * `--strict`. See merge-sidecars.ts.
65
65
  *
66
+ * Writing into a Flow project that already holds another `.flow` outside its
67
+ * dot-folders (a candidate beside the original, a backup) warns
68
+ * `SECOND_FLOW_IN_PROJECT` (project-flows.ts).
69
+ *
66
70
  * Agent resources (#1221): a context or tool the edit adds or changes is written
67
71
  * beside the merged output too. One the edit REMOVES is listed, one
68
72
  * `flow-merge: remove <dir>` line each (and `removed` in `--json`), because
@@ -72,7 +76,7 @@
72
76
  * merged flow and its agents, as compile does, and written beside the merged
73
77
  * output when it changes.
74
78
  */
75
- import { reportCompileRefusal, reportDiagnostics, reportResult } from './cli-result.js';
79
+ import { diagnosticLine, reportCompileRefusal, reportDiagnostics, reportResult } from './cli-result.js';
76
80
  import { writeJsonFile } from './core/json-file.js';
77
81
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
78
82
  import { inlineAgentResources, mergeBindingsV2, projectBindingRows, refreshInlineAgentRows } from './bindings-v2.js';
@@ -82,6 +86,7 @@ import { MergeRefusedError, mergeFlowWithSidecars } from './merge.js';
82
86
  import { sidecarSetFromList } from './merge-sidecars.js';
83
87
  import { isWithin } from './path-within.js';
84
88
  import { flowSources, projectMainFlow, resourceSourcesOfOtherFlows } from './project-resource-users.js';
89
+ import { secondFlowWarning } from './project-flows.js';
85
90
  import { flagValue, flagValues, runWhenInvokedDirectly } from './cli-run.js';
86
91
  import { readFlowFile } from './decompile-file.js';
87
92
  import { readFlowStamp, restampFlowSource, sourceDigest, STAMP_MARKER } from './decompile-stamp.js';
@@ -508,6 +513,14 @@ export async function run(argv) {
508
513
  mkdirSync(outDir, { recursive: true });
509
514
  writeJsonFile(out, flow);
510
515
  console.log(`flow-merge: wrote ${basename(out)} (${(flow.nodes ?? []).length} nodes, ${(flow.edges ?? []).length} edges)`);
516
+ // A candidate written into the original's Flow project outside a dot-folder, or an
517
+ // in-place merge into a project that holds a backup, leaves a second `.flow` where
518
+ // `uip` or a globbing reader can take it for the project's (#1996). Never fatal.
519
+ const second = secondFlowWarning(out);
520
+ if (second !== undefined) {
521
+ console.error(` ${diagnosticLine(second)}`);
522
+ reportDiagnostics([second]);
523
+ }
511
524
  for (const { sidecar, target } of targets) {
512
525
  mkdirSync(dirname(target), { recursive: true });
513
526
  writeJsonFile(target, sidecar.json);
@@ -0,0 +1,40 @@
1
+ /** How many folder levels below the project the scan reads. */
2
+ export declare const MAX_DEPTH = 8;
3
+ /** How many folders the scan reads before it stops. */
4
+ export declare const MAX_DIRS = 2000;
5
+ /**
6
+ * The Flow project folder that holds `file`, or `undefined` when no
7
+ * `project.uiproj` sits at or above its folder.
8
+ *
9
+ * @example
10
+ * // Solution/Order/project.uiproj exists
11
+ * flowProjectOf('Solution/Order/backup/Order.flow') // '<abs>/Solution/Order'
12
+ * flowProjectOf('scratch/Order.flow') // undefined
13
+ */
14
+ export declare function flowProjectOf(file: string): string | undefined;
15
+ /**
16
+ * Every `.flow` file in the Flow project that holds `file`, other than `file`
17
+ * itself: paths relative to the project folder, sorted. Empty outside a project.
18
+ *
19
+ * @example
20
+ * otherProjectFlows('Solution/Order/Order.flow')
21
+ * // { project: '<abs>/Solution/Order', others: ['backup/Order.flow'] }
22
+ */
23
+ export declare function otherProjectFlows(file: string): {
24
+ project: string | undefined;
25
+ others: string[];
26
+ };
27
+ /**
28
+ * The `SECOND_FLOW_IN_PROJECT` warning for writing `file`, or `undefined` when
29
+ * its project holds no other `.flow` a reader sees, or `file` itself sits where
30
+ * none looks (a dot-folder).
31
+ *
32
+ * @example
33
+ * secondFlowWarning('Solution/Order/Order.flow')?.message
34
+ * // 'the Flow project Order/ holds another .flow besides Order.flow: backup/Order.flow. …'
35
+ */
36
+ export declare function secondFlowWarning(file: string): {
37
+ level: 'warning';
38
+ code: 'SECOND_FLOW_IN_PROJECT';
39
+ message: string;
40
+ } | undefined;
@@ -0,0 +1,136 @@
1
+ /**
2
+ * project-flows — the other `.flow` files in the Flow project a write lands in,
3
+ * for compile's and merge's `SECOND_FLOW_IN_PROJECT` warning (#1996).
4
+ *
5
+ * Two readers take a project's `.flow` from its folder, not from a name:
6
+ *
7
+ * - `uip` (pack, debug, validate, `solution resources refresh`) picks one from
8
+ * the project root, `content/` or `flow_files/` (`scanProjectFlowFile` in the
9
+ * CLI's packager-tool-flow `flow-io.ts`). With several there and no
10
+ * `MainFile`, it takes whichever the file system lists first.
11
+ * - A reader that globs the project, as the eval graders do
12
+ * (`glob('**' + '/*.flow', recursive=True)`), reads every `.flow` below it
13
+ * outside dot-folders: Python's glob skips those.
14
+ *
15
+ * Neither reads a dot-folder, so `.flow-sdk/`, where the generated pipeline
16
+ * compiles its baseline, edited and merged candidates, is not scanned. A backup
17
+ * or a `baseline/` compile anywhere else in the project is. Compile and merge are
18
+ * the only writers of a `.flow`, so they say so:
19
+ *
20
+ * Solution/Order/project.uiproj
21
+ * Solution/Order/Order.flow <- the deliverable
22
+ * Solution/Order/backup/Order.flow <- warned: a second .flow
23
+ * Solution/Order/.flow-sdk/Order.merged.flow (not warned: no reader sees it)
24
+ *
25
+ * The project is found as `uip` finds it (`findFlowProjectRoot` in the CLI's
26
+ * packager-tool-flow `flow-project-root.ts`): the nearest folder at or above the
27
+ * written file that holds `project.uiproj`. Like `uip`, the climb tests only for
28
+ * that file, one `exists` per level: it never lists an ancestor, which for a
29
+ * write under a crowded `/tmp` would read every entry there. Outside a project
30
+ * nothing is a deliverable, and nothing is warned.
31
+ *
32
+ * The scan is bounded: it does not follow links, skips dot-folders,
33
+ * `node_modules/` and any nested folder that is a project of its own, and stops after
34
+ * {@link MAX_DEPTH} levels or {@link MAX_DIRS} folders.
35
+ *
36
+ * Library module (FB010): it returns the files, and the CLIs print the warning.
37
+ */
38
+ import { existsSync, readdirSync } from 'node:fs';
39
+ import { dirname, join, relative, resolve } from 'node:path';
40
+ /** How many folder levels below the project the scan reads. */
41
+ export const MAX_DEPTH = 8;
42
+ /** How many folders the scan reads before it stops. */
43
+ export const MAX_DIRS = 2000;
44
+ /** Folders the scan never enters besides dot-folders. */
45
+ const SKIPPED = new Set(['node_modules']);
46
+ /**
47
+ * The Flow project folder that holds `file`, or `undefined` when no
48
+ * `project.uiproj` sits at or above its folder.
49
+ *
50
+ * @example
51
+ * // Solution/Order/project.uiproj exists
52
+ * flowProjectOf('Solution/Order/backup/Order.flow') // '<abs>/Solution/Order'
53
+ * flowProjectOf('scratch/Order.flow') // undefined
54
+ */
55
+ export function flowProjectOf(file) {
56
+ let dir = dirname(resolve(file));
57
+ for (;;) {
58
+ if (existsSync(join(dir, 'project.uiproj')))
59
+ return dir;
60
+ const parent = dirname(dir);
61
+ if (parent === dir)
62
+ return undefined;
63
+ dir = parent;
64
+ }
65
+ }
66
+ /**
67
+ * Every `.flow` file in the Flow project that holds `file`, other than `file`
68
+ * itself: paths relative to the project folder, sorted. Empty outside a project.
69
+ *
70
+ * @example
71
+ * otherProjectFlows('Solution/Order/Order.flow')
72
+ * // { project: '<abs>/Solution/Order', others: ['backup/Order.flow'] }
73
+ */
74
+ export function otherProjectFlows(file) {
75
+ const project = flowProjectOf(file);
76
+ if (project === undefined)
77
+ return { project, others: [] };
78
+ const self = resolve(file);
79
+ const others = [];
80
+ const queue = [{ dir: project, depth: 0 }];
81
+ let read = 0;
82
+ while (queue.length > 0 && read < MAX_DIRS) {
83
+ const { dir, depth } = queue.shift();
84
+ read++;
85
+ let entries;
86
+ try {
87
+ entries = readdirSync(dir, { withFileTypes: true });
88
+ }
89
+ catch {
90
+ continue;
91
+ }
92
+ for (const e of entries) {
93
+ const path = join(dir, e.name);
94
+ if (e.isFile() && e.name.endsWith('.flow')) {
95
+ if (path !== self)
96
+ others.push(relative(project, path));
97
+ }
98
+ else if (e.isDirectory() && !e.name.startsWith('.') && !SKIPPED.has(e.name) && depth < MAX_DEPTH && !existsSync(join(path, 'project.uiproj'))) {
99
+ queue.push({ dir: path, depth: depth + 1 });
100
+ }
101
+ }
102
+ }
103
+ return { project, others: others.sort() };
104
+ }
105
+ /** A project-relative path inside a folder the scan does not read (a dot-folder, `node_modules/`). */
106
+ function unread(rel) {
107
+ return rel.split(/[\\/]/).slice(0, -1).some((seg) => seg.startsWith('.') || SKIPPED.has(seg));
108
+ }
109
+ /**
110
+ * The `SECOND_FLOW_IN_PROJECT` warning for writing `file`, or `undefined` when
111
+ * its project holds no other `.flow` a reader sees, or `file` itself sits where
112
+ * none looks (a dot-folder).
113
+ *
114
+ * @example
115
+ * secondFlowWarning('Solution/Order/Order.flow')?.message
116
+ * // 'the Flow project Order/ holds another .flow besides Order.flow: backup/Order.flow. …'
117
+ */
118
+ export function secondFlowWarning(file) {
119
+ const { project, others } = otherProjectFlows(file);
120
+ if (project === undefined || others.length === 0)
121
+ return undefined;
122
+ // Written into a dot-folder (the pipeline's `.flow-sdk/Order.baseline/Order.flow`):
123
+ // no reader sees this file, so it competes with nothing.
124
+ if (unread(relative(project, resolve(file))))
125
+ return undefined;
126
+ const shown = others.length > 5 ? `${others.slice(0, 5).join(', ')}, and ${others.length - 5} more` : others.join(', ');
127
+ const name = relative(dirname(project), project) || project;
128
+ return {
129
+ level: 'warning',
130
+ code: 'SECOND_FLOW_IN_PROJECT',
131
+ message: `the Flow project ${name}/ holds another .flow besides ${relative(project, resolve(file))}: ${shown}. `
132
+ + '`uip` packs and validates one .flow per project, taken from its root, content/ or flow_files/ (the first listed when there are several and no MainFile), '
133
+ + 'and a reader that globs the project (**/*.flow) reads every .flow outside dot-folders. '
134
+ + 'Keep one .flow in the project: delete the others, or move them out of it or into .flow-sdk/.',
135
+ };
136
+ }