@rise-x/apps-sdk 0.11.1 → 0.15.1

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 (86) hide show
  1. package/README.md +915 -19
  2. package/build/_internal.d.ts +4 -1
  3. package/build/_internal.js +67 -0
  4. package/build/cli/index.d.ts +7 -1
  5. package/build/cli/index.js +68 -14
  6. package/build/cli/scan.d.ts +60 -0
  7. package/build/cli/scan.js +725 -0
  8. package/build/cli/validate.d.ts +33 -0
  9. package/build/cli/validate.js +169 -0
  10. package/build/connectors/agents.d.ts +10 -6
  11. package/build/connectors/agents.js +59 -44
  12. package/build/connectors/attachments.d.ts +51 -0
  13. package/build/connectors/attachments.js +76 -0
  14. package/build/connectors/errors.js +24 -0
  15. package/build/connectors/flows.d.ts +13 -2
  16. package/build/connectors/flows.js +64 -19
  17. package/build/connectors/index.d.ts +5 -1
  18. package/build/connectors/index.js +14 -2
  19. package/build/connectors/integrations.d.ts +29 -0
  20. package/build/connectors/integrations.js +32 -0
  21. package/build/connectors/offline.d.ts +34 -0
  22. package/build/connectors/offline.js +135 -0
  23. package/build/connectors/readPolicy.d.ts +29 -0
  24. package/build/connectors/readPolicy.js +105 -0
  25. package/build/connectors/types.d.ts +75 -0
  26. package/build/connectors/types.js +128 -0
  27. package/build/connectors/vectorStores.d.ts +45 -0
  28. package/build/connectors/vectorStores.js +199 -0
  29. package/build/connectors/work.d.ts +14 -2
  30. package/build/connectors/work.js +43 -19
  31. package/build/dependencies/bound.d.ts +87 -0
  32. package/build/dependencies/bound.js +207 -0
  33. package/build/dependencies/index.d.ts +2 -0
  34. package/build/dependencies/index.js +13 -0
  35. package/build/dependencyRegistry.d.ts +15 -0
  36. package/build/dependencyRegistry.js +28 -0
  37. package/build/index.d.ts +2 -1
  38. package/build/index.js +12 -1
  39. package/build/lifecycle.d.ts +10 -1
  40. package/build/manifest.d.ts +69 -0
  41. package/build/manifest.js +229 -0
  42. package/build/manifestSource.d.ts +27 -0
  43. package/build/manifestSource.js +99 -0
  44. package/build/mockShell.d.ts +2 -0
  45. package/build/mockShell.js +13 -0
  46. package/build/query/client.js +9 -1
  47. package/build/query/dependencies.d.ts +22 -0
  48. package/build/query/dependencies.js +73 -0
  49. package/build/query/flows.d.ts +8 -8
  50. package/build/query/index.d.ts +1 -0
  51. package/build/query/index.js +4 -2
  52. package/build/query/layer.d.ts +9 -9
  53. package/build/query/shared.js +10 -0
  54. package/build/query/work.d.ts +4 -4
  55. package/build/rsbuild/index.d.ts +3 -1
  56. package/build/rsbuild/index.js +35 -1
  57. package/build/rsbuild/riseAppManifestPlugin.d.ts +19 -0
  58. package/build/rsbuild/riseAppManifestPlugin.js +79 -0
  59. package/build/shell/installShellBridge.d.ts +2 -0
  60. package/build/shell/installShellBridge.js +3 -1
  61. package/build/shellBridge.d.ts +233 -1
  62. package/build/shellBridge.js +8 -7
  63. package/build/ui/classes.json +2 -2
  64. package/build/ui/components/app-frame.d.ts +1 -1
  65. package/build/ui/components/data-table.d.ts +39 -4
  66. package/build/ui/components/statistic.d.ts +1 -1
  67. package/build/ui/demo.html +671 -543
  68. package/build/ui/shadcn.css +629 -0
  69. package/build/ui/standalone.js +45 -44
  70. package/build/ui/styles.css +1 -1
  71. package/build/ui/tailwind.css +12 -0
  72. package/build/ui/theme.css +412 -0
  73. package/build/ui/tw-animate.css +1 -0
  74. package/build/webpack/index.d.ts +1 -0
  75. package/build/webpack/index.js +7 -0
  76. package/build/webpack/riseAppManifestPlugin.d.ts +61 -0
  77. package/build/webpack/riseAppManifestPlugin.js +103 -0
  78. package/dependencies/package.json +8 -0
  79. package/package.json +17 -4
  80. package/template/AGENTS.md +34 -4
  81. package/template/README.md +85 -2
  82. package/template/package.json +4 -0
  83. package/template/rise-x-app.json +4 -0
  84. package/template/src/App.tsx +7 -17
  85. package/template/src/styles.css +5 -0
  86. package/webpack/package.json +8 -0
@@ -0,0 +1,725 @@
1
+ "use strict";
2
+ // Reports Rise-X ids hardcoded in app source.
3
+ //
4
+ // Parser only, never a ts.Program: a type-checked pass needs the app's tsconfig
5
+ // and dies on an app that doesn't compile, which is the half-migrated app most
6
+ // worth scanning. So this is a lint, not a proof — hence warnings in `validate`
7
+ // and failure only under `scan --strict`.
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.scanSource = scanSource;
43
+ exports.runScan = runScan;
44
+ exports.reportScan = reportScan;
45
+ exports.scan = scan;
46
+ const node_module_1 = require("node:module");
47
+ const fs = __importStar(require("node:fs"));
48
+ const path = __importStar(require("node:path"));
49
+ const manifest_1 = require("../manifest");
50
+ const manifestSource_1 = require("../manifestSource");
51
+ // "Looks like a GUID", which is a wider question than resolveAppManifest's "is a
52
+ // valid dependency id" — a scanner has to consider strings it will then reject.
53
+ const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
54
+ // Skipped when a finding's own line, or the line above it, carries this marker.
55
+ const IGNORE_MARKER = "rise-x-app-ignore";
56
+ // Only the first token of a comment body counts, so a string literal holding
57
+ // the marker, or a doc comment that merely mentions it, silences nothing.
58
+ const MARKER_OPENS_A_COMMENT = new RegExp(`(?://|/\\*+|^\\s*\\*+)\\s*${IGNORE_MARKER}`);
59
+ // Never walked, at any depth.
60
+ const SKIP_DIRS = new Set(["node_modules", ".git"]);
61
+ // Build output. Skipped only when the walk starts at the app directory itself —
62
+ // an app WITH a src/ keeps its code there, so `src/build/` is app code and
63
+ // silently not scanning it is the worst failure this tool has.
64
+ const SKIP_AT_ROOT = new Set(["dist", "dist-local", "build", "coverage"]);
65
+ // Canned data, the largest single source of noise (bwo-expense-claim). Checked
66
+ // outside the hint list too: a field name says nothing about provenance, so it
67
+ // must not be able to overrule this rule.
68
+ const CANNED_DATA = /sample|mock|fixture|stub|dummy|example|placeholder|seed/;
69
+ // Matched against any lowercased identifier. Names, not a list of SDK methods:
70
+ // a method added tomorrow classifies without an edit here. First hit wins, so
71
+ // the ignore patterns precede the rest.
72
+ const NAME_HINTS = [
73
+ // Ids the manifest does not carry: flow internals, single rows, endpoints.
74
+ // Every one was a false positive on a real app in rise-x-apps.
75
+ [/step|task|section|layout/, "ignore"],
76
+ [
77
+ /workid|work_id|assetid|asset_id|chatid|chat_id|uploadid|upload_id/,
78
+ "ignore",
79
+ ],
80
+ [CANNED_DATA, "ignore"],
81
+ // Narrower than the derived rules below, so it has to precede them.
82
+ [/entitytype|entity_type/, "assetType"],
83
+ // Every kind matches its own name, derived from the manifest's own list: a
84
+ // kind added to APP_DEPENDENCY_KINDS is classifiable here for free.
85
+ ...manifest_1.APP_DEPENDENCY_KINDS.map((kind) => [
86
+ // Escaped: the point of deriving these is that a new kind needs no edit
87
+ // here, and a kind with a `.` or `-` in it must not become a metacharacter.
88
+ new RegExp(kind.toLowerCase().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")),
89
+ kind,
90
+ ]),
91
+ [/asset|entity/, "assetType"],
92
+ [/type/, "assetType"],
93
+ ];
94
+ // Mirrors manifest.ts's ID_FIELDS_BY_KIND, underscores stripped so
95
+ // `flow_origin_id` reads the same as `flowOriginId`. Flat list, not paired —
96
+ // this only decides "is this identifier an id field at all" (which outranks
97
+ // the ignore rules below); it does not attempt to match an integrationId
98
+ // finding to its sibling endpointId the way a manifest entry pairs them.
99
+ const ID_FIELD_NAMES = [
100
+ "floworiginid",
101
+ "agentid",
102
+ "integrationid",
103
+ "endpointid",
104
+ ];
105
+ function loadTypeScript(dir) {
106
+ // The app's own copy first: the CLI can be running from a global install where
107
+ // typescript is not a sibling of the SDK.
108
+ try {
109
+ return (0, node_module_1.createRequire)(path.join(dir, "package.json"))("typescript");
110
+ }
111
+ catch {
112
+ try {
113
+ return require("typescript");
114
+ }
115
+ catch {
116
+ return null;
117
+ }
118
+ }
119
+ }
120
+ function sourceFiles(root, skipBuildOutput) {
121
+ const found = [];
122
+ const walk = (dir, atRoot) => {
123
+ let entries;
124
+ try {
125
+ entries = fs.readdirSync(dir, { withFileTypes: true });
126
+ }
127
+ catch {
128
+ return;
129
+ }
130
+ for (const entry of entries) {
131
+ const full = path.join(dir, entry.name);
132
+ if (entry.isDirectory()) {
133
+ const skip = SKIP_DIRS.has(entry.name) ||
134
+ (atRoot && skipBuildOutput && SKIP_AT_ROOT.has(entry.name));
135
+ if (!skip)
136
+ walk(full, false);
137
+ continue;
138
+ }
139
+ if (!entry.isFile() || entry.name.endsWith(".d.ts"))
140
+ continue;
141
+ if (/\.(ts|tsx)$/.test(entry.name))
142
+ found.push(full);
143
+ }
144
+ };
145
+ walk(root, true);
146
+ return found.sort();
147
+ }
148
+ /** Every id rise-x-app.json declares, across every environment and kind, plus
149
+ * the aliases it declares them under (lowercased: resolveAppManifest folds
150
+ * alias casing before comparing, so a suggestion differing only by case would
151
+ * still write that JSON key twice). */
152
+ function declaredIds(dir) {
153
+ const ids = new Set();
154
+ const aliases = new Set();
155
+ let read;
156
+ try {
157
+ read = (0, manifestSource_1.readAppManifestSource)((0, manifestSource_1.appManifestPath)(dir));
158
+ }
159
+ catch {
160
+ // An unparseable manifest is validate's problem to report, not the
161
+ // scanner's; treat it as declaring nothing.
162
+ return { ids, aliases };
163
+ }
164
+ if (!read)
165
+ return { ids, aliases };
166
+ const source = read.source;
167
+ for (const [alias, dependency] of Object.entries(source?.dependencies ?? {})) {
168
+ aliases.add(alias.toLowerCase());
169
+ for (const envIds of Object.values(dependency?.ids ?? {})) {
170
+ for (const value of Object.values((envIds ?? {}))) {
171
+ if (typeof value === "string")
172
+ ids.add(value.toLowerCase());
173
+ }
174
+ }
175
+ }
176
+ return { ids, aliases };
177
+ }
178
+ function kindFromName(name) {
179
+ const lower = name.toLowerCase();
180
+ // An id field is the decisive signal, so it outranks the ignore rules:
181
+ // TASK_APPROVAL_FLOW_ORIGIN_ID is a flow, whatever else the name says. Canned
182
+ // data is not one of those rules: MOCK_AGENT_ID stays dismissed.
183
+ const bare = lower.replace(/_/g, "");
184
+ const isIdField = ID_FIELD_NAMES.some((field) => bare.includes(field)) &&
185
+ !CANNED_DATA.test(lower);
186
+ for (const [pattern, kind] of NAME_HINTS) {
187
+ if (kind === "ignore" && isIdField)
188
+ continue;
189
+ if (pattern.test(lower))
190
+ return kind;
191
+ }
192
+ return null;
193
+ }
194
+ function calleeName(ts, call) {
195
+ const target = call.expression;
196
+ if (ts.isIdentifier(target))
197
+ return target.text;
198
+ if (ts.isPropertyAccessExpression(target)) {
199
+ const object = ts.isIdentifier(target.expression)
200
+ ? target.expression.text
201
+ : "";
202
+ return object ? `${object}.${target.name.text}` : target.name.text;
203
+ }
204
+ return "";
205
+ }
206
+ function propertyName(ts, property) {
207
+ const { name } = property;
208
+ if (ts.isIdentifier(name) || ts.isStringLiteralLike(name))
209
+ return name.text;
210
+ return null;
211
+ }
212
+ /** `risk` in `{ risk: { flowOriginId: '<id>' } }`: the property that names the
213
+ * object an id field sits in, which the enclosing variable cannot distinguish
214
+ * from its siblings. */
215
+ function owningPropertyName(ts, property) {
216
+ const object = property.parent;
217
+ if (!object || !ts.isObjectLiteralExpression(object))
218
+ return null;
219
+ const owner = object.parent;
220
+ if (!owner || !ts.isPropertyAssignment(owner))
221
+ return null;
222
+ if (owner.initializer !== object)
223
+ return null;
224
+ return propertyName(ts, owner);
225
+ }
226
+ /** `variablesOnly` for the alias: a function name is a fair signal for the KIND
227
+ * (`getFlowConfig` is about a flow) but never names the object. */
228
+ function enclosingName(ts, node, variablesOnly = false) {
229
+ for (let current = node.parent; current; current = current.parent) {
230
+ if (ts.isVariableDeclaration(current) && ts.isIdentifier(current.name)) {
231
+ return current.name.text;
232
+ }
233
+ if (variablesOnly)
234
+ continue;
235
+ if ((ts.isFunctionDeclaration(current) || ts.isMethodDeclaration(current)) &&
236
+ current.name &&
237
+ ts.isIdentifier(current.name)) {
238
+ return current.name.text;
239
+ }
240
+ }
241
+ return null;
242
+ }
243
+ /** Looks through the default-value idioms, so `endpointId: endpointId || '<id>'`
244
+ * is named by its property rather than the enclosing function. */
245
+ function throughDefaults(ts, node) {
246
+ let value = node;
247
+ while (value.parent) {
248
+ const up = value.parent;
249
+ const passthrough = ts.isParenthesizedExpression(up) ||
250
+ ts.isAsExpression(up) ||
251
+ (ts.isConditionalExpression(up) && up.condition !== value) ||
252
+ (ts.isBinaryExpression(up) &&
253
+ (up.operatorToken.kind === ts.SyntaxKind.BarBarToken ||
254
+ up.operatorToken.kind === ts.SyntaxKind.QuestionQuestionToken));
255
+ if (!passthrough)
256
+ break;
257
+ value = up;
258
+ }
259
+ return { value, parent: value.parent };
260
+ }
261
+ /** A name rule fired: either it named a kind, or it named a non-dependency. */
262
+ function verdict(hint, context, alias) {
263
+ if (hint === "ignore") {
264
+ return { kind: null, context, ignore: true, alias: null };
265
+ }
266
+ return { kind: hint, context, ignore: false, alias };
267
+ }
268
+ function classify(ts, node) {
269
+ const { value, parent } = throughDefaults(ts, node);
270
+ const enclosing = enclosingName(ts, node);
271
+ // The alias names the dependency, so only a variable can supply it, and the
272
+ // id-noise words are trimmed off. Null is a legitimate answer.
273
+ const alias = toAlias(enclosingName(ts, node, true) ?? "");
274
+ if (!parent)
275
+ return fromEnclosing(enclosing, alias);
276
+ // A declared dependency's id is always a value. A GUID used as an object key
277
+ // is a lookup table — step-id-to-label and friends — and the manifest carries
278
+ // no step or task ids at all.
279
+ if (ts.isPropertyAssignment(parent) && parent.name === node) {
280
+ return { kind: null, context: "object key", ignore: true, alias: null };
281
+ }
282
+ if (ts.isPropertyAssignment(parent) && parent.initializer === value) {
283
+ const name = propertyName(ts, parent);
284
+ if (name) {
285
+ // The property name first, since `flowOriginId` and `agentId` name their
286
+ // own kind. A generic `id:` decides nothing, so the enclosing name gets
287
+ // the next say — and whichever one fired is what `context` reports, so a
288
+ // reader can check the verdict against the right identifier.
289
+ const byProperty = kindFromName(name);
290
+ // The property named the KIND, so it is an id field (`agentId`) and names
291
+ // nothing. The property owning the object says which sibling this is;
292
+ // failing that, the enclosing variable identifies the thing.
293
+ if (byProperty) {
294
+ const owner = owningPropertyName(ts, parent);
295
+ // A kind word owns nothing: every sibling could claim it, for the same
296
+ // reason the enclosing-map branch below prefers the property.
297
+ const owned = owner && !kindFromName(owner) ? toAlias(owner) : null;
298
+ return verdict(byProperty, name, owned ?? alias);
299
+ }
300
+ const byEnclosing = enclosing ? kindFromName(enclosing) : null;
301
+ if (byEnclosing) {
302
+ // The enclosing map supplied only the kind (`AGENT`, `ASSET`), so the
303
+ // property is what distinguishes this entry from its siblings: prefer
304
+ // `focusCoach` over `agent`, which every sibling would also claim.
305
+ return verdict(byEnclosing, `${enclosing}.${name}`, toAlias(name) ?? alias);
306
+ }
307
+ return {
308
+ kind: null,
309
+ context: name,
310
+ ignore: false,
311
+ alias: toAlias(name) ?? alias,
312
+ };
313
+ }
314
+ }
315
+ // A search filter names the kind through a sibling property:
316
+ // { field: 'flowOriginId', operator: 'equals', values: ['<guid>'] }
317
+ const pinned = pinnedField(ts, value);
318
+ if (pinned) {
319
+ const byPin = kindFromName(pinned);
320
+ if (byPin && byPin !== "ignore") {
321
+ return {
322
+ kind: byPin,
323
+ context: `search filter on ${pinned}`,
324
+ ignore: false,
325
+ alias,
326
+ };
327
+ }
328
+ }
329
+ if (ts.isCallExpression(parent) &&
330
+ parent.arguments.includes(value)) {
331
+ const callee = calleeName(ts, parent);
332
+ // The receiver, or the hook's own name: `flows.getConfig` and `useFlow` are
333
+ // both "about a flow" whatever the method is called, which is what keeps a
334
+ // new SDK method working here with no change.
335
+ const target = callee.includes(".") ? callee.split(".")[0] : callee;
336
+ const byTarget = kindFromName(target);
337
+ if (byTarget === "flow" || byTarget === "agent") {
338
+ // No alias: a bare id argument means the source never named the object.
339
+ // `agents.get('<guid>')` gets its name from the user, not from us.
340
+ return {
341
+ kind: byTarget,
342
+ context: `${callee}()`,
343
+ ignore: false,
344
+ alias: null,
345
+ };
346
+ }
347
+ // A bare id argument on the asset or work surface identifies ONE row —
348
+ // assets.get(assetId), work.get(workId) — and a row id is never a declared
349
+ // dependency. Their type/flow refs arrive as a named property instead, which
350
+ // the branch above already read.
351
+ // Anchored: `networkService` and `worker` are not the work surface.
352
+ if (byTarget === "assetType" || /^work/.test(target.toLowerCase())) {
353
+ return { kind: null, context: `${callee}()`, ignore: true, alias: null };
354
+ }
355
+ }
356
+ if (ts.isVariableDeclaration(parent) && parent.initializer === value) {
357
+ const byName = enclosing ? kindFromName(enclosing) : null;
358
+ if (byName === "ignore") {
359
+ return {
360
+ kind: null,
361
+ context: enclosing ?? "",
362
+ ignore: true,
363
+ alias: null,
364
+ };
365
+ }
366
+ return {
367
+ kind: byName ?? null,
368
+ context: enclosing ?? "variable",
369
+ ignore: false,
370
+ alias,
371
+ };
372
+ }
373
+ return fromEnclosing(enclosing, alias);
374
+ }
375
+ /** Nothing but the surrounding name to go on. Also the answer when the literal
376
+ * has no parent to read at all. */
377
+ function fromEnclosing(enclosing, alias) {
378
+ const byEnclosing = enclosing ? kindFromName(enclosing) : null;
379
+ if (byEnclosing === "ignore") {
380
+ return { kind: null, context: enclosing ?? "", ignore: true, alias: null };
381
+ }
382
+ return {
383
+ kind: byEnclosing ?? null,
384
+ context: enclosing ?? "unknown",
385
+ ignore: false,
386
+ alias,
387
+ };
388
+ }
389
+ /** The `field` value of the search-condition object this literal sits in. */
390
+ function pinnedField(ts, node) {
391
+ const array = node.parent;
392
+ if (!array || !ts.isArrayLiteralExpression(array))
393
+ return null;
394
+ const values = array.parent;
395
+ if (!values || !ts.isPropertyAssignment(values))
396
+ return null;
397
+ if (propertyName(ts, values) !== "values")
398
+ return null;
399
+ const condition = values.parent;
400
+ if (!condition || !ts.isObjectLiteralExpression(condition))
401
+ return null;
402
+ for (const member of condition.properties) {
403
+ if (!ts.isPropertyAssignment(member))
404
+ continue;
405
+ if (propertyName(ts, member) !== "field")
406
+ continue;
407
+ const { initializer } = member;
408
+ if (ts.isStringLiteralLike(initializer))
409
+ return initializer.text;
410
+ }
411
+ return null;
412
+ }
413
+ // Trailing words that describe the id rather than the thing it identifies. An
414
+ // alias names the dependency, so `EXPENSE_FLOW_ORIGIN_ID` should read
415
+ // `expenseFlow` — the manifest already knows it holds an origin id.
416
+ const ID_NOISE = new Set([
417
+ "id",
418
+ "ids",
419
+ "guid",
420
+ "uuid",
421
+ "origin",
422
+ "originid",
423
+ "fallback",
424
+ "default",
425
+ "value",
426
+ "key",
427
+ "const",
428
+ ]);
429
+ /**
430
+ * `RISK_MGMT_FLOW` → `riskMgmtFlow`, `EXPENSE_FLOW_ORIGIN_ID` → `expenseFlow`.
431
+ * Null when every word is id-noise (`id`, `value`), because an alias of `id`
432
+ * names nothing and would collide with the next one.
433
+ */
434
+ function toAlias(name) {
435
+ const parts = name
436
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
437
+ .split(/[^a-zA-Z0-9]+/)
438
+ .filter(Boolean);
439
+ while (parts.length > 0 &&
440
+ ID_NOISE.has(parts[parts.length - 1].toLowerCase())) {
441
+ parts.pop();
442
+ }
443
+ if (parts.length === 0)
444
+ return null;
445
+ return parts
446
+ .map((part, i) => i === 0
447
+ ? part.toLowerCase()
448
+ : part[0].toUpperCase() + part.slice(1).toLowerCase())
449
+ .join("");
450
+ }
451
+ // A marker alone on a line is written for the line below it. One trailing real
452
+ // code marks only that code — without the distinction, `const a = '<id>'; //
453
+ // rise-x-app-ignore` would also silence the id on the next line.
454
+ function ignoredLines(text) {
455
+ const lines = new Set();
456
+ // Every terminator TypeScript's scanner counts, or these line numbers drift
457
+ // from the ones the findings carry and the marker silences the wrong line.
458
+ text.split(/\r\n|[\r\n\u2028\u2029]/).forEach((line, i) => {
459
+ if (!MARKER_OPENS_A_COMMENT.test(line))
460
+ return;
461
+ lines.add(i + 1);
462
+ if (/^\s*(\{\/\*|\/\/|\/\*|\*)/.test(line))
463
+ lines.add(i + 2);
464
+ });
465
+ return lines;
466
+ }
467
+ function scanSource(ts, files, root, declared) {
468
+ const byId = new Map();
469
+ const dismissedById = new Map();
470
+ const silencedById = new Map();
471
+ // Distinct ids, so the tally counts the same thing findings and dismissals do
472
+ // rather than every occurrence of one already-declared id.
473
+ const declaredSeen = new Set();
474
+ const dismiss = (into, id, by, location) => {
475
+ const existing = into.get(id.toLowerCase());
476
+ if (existing)
477
+ existing.locations.push(location);
478
+ else
479
+ into.set(id.toLowerCase(), { id, by, locations: [location] });
480
+ };
481
+ let unreadable = 0;
482
+ for (const file of files) {
483
+ let text;
484
+ try {
485
+ text = fs.readFileSync(file, "utf8");
486
+ }
487
+ catch {
488
+ // A locked or mid-walk-deleted file is counted, never thrown: validate
489
+ // runs this pass and its contract is that the scan cannot fail it.
490
+ unreadable += 1;
491
+ continue;
492
+ }
493
+ // Cheap gate: most files hold no GUID at all, and parsing them is the
494
+ // expensive part.
495
+ if (!/[0-9a-f]{8}-[0-9a-f]{4}-/i.test(text))
496
+ continue;
497
+ const skipLines = ignoredLines(text);
498
+ const source = ts.createSourceFile(file, text, ts.ScriptTarget.Latest, true, file.endsWith(".tsx") ? ts.ScriptKind.TSX : ts.ScriptKind.TS);
499
+ const visit = (node) => {
500
+ if (ts.isStringLiteralLike(node) && GUID.test(node.text)) {
501
+ const id = node.text.toLowerCase();
502
+ const line = source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;
503
+ // Already declared: nothing downstream needs the classification, and
504
+ // walking the ancestors for it is the expensive part.
505
+ if (declared.ids.has(id)) {
506
+ declaredSeen.add(id);
507
+ }
508
+ else {
509
+ const { kind, context, ignore, alias } = classify(ts, node);
510
+ const location = {
511
+ file: path.relative(root, file) || path.basename(file),
512
+ line,
513
+ context,
514
+ };
515
+ if (skipLines.has(line)) {
516
+ dismiss(silencedById, node.text, "marker", location);
517
+ }
518
+ else if (ignore) {
519
+ dismiss(dismissedById, node.text, "rule", location);
520
+ }
521
+ else {
522
+ const existing = byId.get(id);
523
+ if (existing) {
524
+ existing.locations.push(location);
525
+ existing.kind ?? (existing.kind = kind);
526
+ existing.suggestedAlias ?? (existing.suggestedAlias = alias);
527
+ }
528
+ else {
529
+ byId.set(id, {
530
+ id: node.text,
531
+ kind,
532
+ suggestedAlias: alias,
533
+ locations: [location],
534
+ });
535
+ }
536
+ }
537
+ }
538
+ }
539
+ ts.forEachChild(node, visit);
540
+ };
541
+ visit(source);
542
+ }
543
+ const findings = [...byId.values()];
544
+ dropCollidingAliases(findings, declared.aliases);
545
+ return {
546
+ findings,
547
+ declaredHits: declaredSeen.size,
548
+ dismissed: [...dismissedById.values()],
549
+ silenced: [...silencedById.values()],
550
+ unreadable,
551
+ };
552
+ }
553
+ /** Sibling ids can name the same thing (`CONFIG.risk.flowOriginId` and
554
+ * `CONFIG.ops.flowOriginId` both read `config`), and a developer applying both
555
+ * suggestions writes two JSON keys of one name. An alias rise-x-app.json
556
+ * already declares does it in one step. No suggestion is safer. */
557
+ function dropCollidingAliases(findings, declaredAliases) {
558
+ const byAlias = new Map();
559
+ for (const finding of findings) {
560
+ if (!finding.suggestedAlias)
561
+ continue;
562
+ // Grouped case-insensitively: resolveAppManifest folds alias casing too.
563
+ const key = finding.suggestedAlias.toLowerCase();
564
+ const group = byAlias.get(key);
565
+ if (group)
566
+ group.push(finding);
567
+ else
568
+ byAlias.set(key, [finding]);
569
+ }
570
+ for (const [alias, group] of byAlias) {
571
+ // A declared alias already holds the key, so one finding is enough to clash.
572
+ if (group.length + (declaredAliases.has(alias) ? 1 : 0) < 2)
573
+ continue;
574
+ for (const finding of group) {
575
+ finding.collidedAlias = finding.suggestedAlias ?? undefined;
576
+ finding.suggestedAlias = null;
577
+ finding.aliasCollision = true;
578
+ }
579
+ }
580
+ }
581
+ function runScan(dir) {
582
+ const ts = loadTypeScript(dir);
583
+ if (!ts) {
584
+ return {
585
+ ok: true,
586
+ filesScanned: 0,
587
+ findings: [],
588
+ declared: 0,
589
+ dismissed: [],
590
+ silenced: [],
591
+ unreadable: 0,
592
+ skipped: "typescript is not installed here — add it as a devDependency to scan for hardcoded ids",
593
+ };
594
+ }
595
+ const src = path.join(dir, "src");
596
+ const hasSrc = fs.existsSync(src);
597
+ const root = hasSrc ? src : dir;
598
+ const files = sourceFiles(root, !hasSrc);
599
+ // Nothing to read is not a clean scan: a mistyped path or the wrong CI
600
+ // working directory looks identical to an app with no hardcoded ids, and
601
+ // --strict has to fail rather than pass on a scan that never happened.
602
+ if (files.length === 0) {
603
+ return {
604
+ ok: true,
605
+ filesScanned: 0,
606
+ findings: [],
607
+ declared: 0,
608
+ dismissed: [],
609
+ silenced: [],
610
+ unreadable: 0,
611
+ skipped: fs.existsSync(root)
612
+ ? `no .ts or .tsx sources found under ${root}`
613
+ : `${root} does not exist`,
614
+ };
615
+ }
616
+ const { findings, declaredHits, dismissed, silenced, unreadable } = scanSource(ts, files, dir, declaredIds(dir));
617
+ return {
618
+ // A file the walk found but could not read is not a clean scan either: it
619
+ // holds whatever it holds, and --strict asks for every file to be checked.
620
+ ok: findings.length === 0 && unreadable === 0,
621
+ filesScanned: files.length,
622
+ findings,
623
+ declared: declaredHits,
624
+ dismissed,
625
+ silenced,
626
+ unreadable,
627
+ };
628
+ }
629
+ /** The counts that say what the scan looked at and set aside, so a clean report
630
+ * is distinguishable from a blind one. */
631
+ function tallies(result) {
632
+ return [
633
+ result.declared > 0 ? `${result.declared} already declared` : "",
634
+ result.dismissed.length > 0
635
+ ? `${result.dismissed.length} dismissed by rule`
636
+ : "",
637
+ result.silenced.length > 0 ? `${result.silenced.length} silenced` : "",
638
+ result.unreadable > 0 ? `${result.unreadable} unreadable` : "",
639
+ ].filter(Boolean);
640
+ }
641
+ function reportDismissals(result) {
642
+ const all = [...result.dismissed, ...result.silenced];
643
+ if (all.length === 0)
644
+ return;
645
+ console.log(" Set aside:");
646
+ for (const item of all) {
647
+ const why = item.by === "marker" ? IGNORE_MARKER : "not a dependency kind";
648
+ console.log(` ${item.id} ${why}`);
649
+ for (const at of item.locations) {
650
+ console.log(` ${at.file}:${at.line} (${at.context})`);
651
+ }
652
+ }
653
+ console.log("");
654
+ }
655
+ /** The findings block, shared by `scan` and `validate`. Indented to sit under
656
+ * either report. `showDismissed` lists what was set aside and why. */
657
+ function reportScan(result, showDismissed = false) {
658
+ if (result.skipped) {
659
+ console.log(` Hardcoded-id scan skipped: ${result.skipped}`);
660
+ console.log("");
661
+ return;
662
+ }
663
+ if (result.findings.length === 0) {
664
+ const extras = tallies(result);
665
+ const headline = result.unreadable > 0
666
+ ? ` Could not check ${result.unreadable} of ${result.filesScanned}` +
667
+ ` source files (unreadable); no undeclared ids in the rest`
668
+ : ` No undeclared ids in ${result.filesScanned} source files`;
669
+ console.log(headline + (extras.length ? ` (${extras.join(", ")})` : ""));
670
+ console.log("");
671
+ if (showDismissed)
672
+ reportDismissals(result);
673
+ return;
674
+ }
675
+ console.log(" Hardcoded ids — declare these in rise-x-app.json:");
676
+ console.log("");
677
+ for (const finding of result.findings) {
678
+ const kind = finding.kind ?? "kind unclear";
679
+ console.log(` ${finding.id} ${kind}`);
680
+ if (finding.suggestedAlias) {
681
+ console.log(` alias? ${finding.suggestedAlias}`);
682
+ }
683
+ else if (finding.aliasCollision) {
684
+ console.log(` alias? (${finding.collidedAlias} is already taken, ignoring` +
685
+ ` case, by another finding or by rise-x-app.json. Same object: add` +
686
+ ` this id under that alias. Different: pick another name.)`);
687
+ }
688
+ for (const at of finding.locations) {
689
+ console.log(` ${at.file}:${at.line} (${at.context})`);
690
+ }
691
+ console.log("");
692
+ }
693
+ if (showDismissed)
694
+ reportDismissals(result);
695
+ const unclear = result.findings.filter((f) => f.kind === null).length;
696
+ const extras = tallies(result);
697
+ console.log(` ${result.findings.length} undeclared id${result.findings.length === 1 ? "" : "s"}` +
698
+ (unclear > 0 ? `, ${unclear} of unclear kind` : "") +
699
+ (extras.length ? ` (${extras.join(", ")})` : ""));
700
+ console.log(` Move each into ${manifest_1.APP_MANIFEST_FILENAME} (kinds: ${manifest_1.APP_DEPENDENCY_KINDS.join(", ")}) and read it through useAppDependencies().`);
701
+ console.log(` A GUID that is not a Rise-X object id — a step id, a fixture — takes a` +
702
+ ` \`${IGNORE_MARKER}\` comment.`);
703
+ if (!showDismissed && result.dismissed.length > 0) {
704
+ console.log(` --show-ignored lists what was set aside, and on what grounds.`);
705
+ }
706
+ console.log("");
707
+ }
708
+ /**
709
+ * Reports Rise-X ids hardcoded in app source. Exits non-zero only under
710
+ * `--strict`, because the classification is a heuristic and a false positive
711
+ * must never be able to block a deploy by default.
712
+ */
713
+ async function scan(args) {
714
+ const dir = path.resolve(process.cwd(), args.positional[0] ?? ".");
715
+ const result = runScan(dir);
716
+ if (args.flags.json === true) {
717
+ process.stdout.write(JSON.stringify(result) + "\n");
718
+ return result;
719
+ }
720
+ console.log("");
721
+ console.log(` ${dir}`);
722
+ console.log("");
723
+ reportScan(result, args.flags["show-ignored"] === true);
724
+ return result;
725
+ }