@runeditrun/rer 0.2.29 → 0.2.31

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 (71) hide show
  1. package/README.md +16 -0
  2. package/cli/README.md +17 -0
  3. package/cli/business/command.mjs +27 -0
  4. package/cli/business/detector.mjs +42 -0
  5. package/cli/business/parsers-config.mjs +91 -0
  6. package/cli/business/parsers-infrastructure.mjs +68 -0
  7. package/cli/business/parsers-packages.mjs +84 -0
  8. package/cli/business/parsers-pulumi.mjs +64 -0
  9. package/cli/business/parsers-syntax.mjs +113 -0
  10. package/cli/business/parsers-terraform.mjs +53 -0
  11. package/cli/business/parsers.mjs +62 -0
  12. package/cli/business/policy.mjs +46 -0
  13. package/cli/business/scan.mjs +67 -0
  14. package/cli/contract.mjs +2 -2
  15. package/cli/demo-build.mjs +23 -0
  16. package/cli/demo-host.mjs +10 -70
  17. package/cli/demo-native.mjs +74 -0
  18. package/cli/lifecycle.mjs +1 -1
  19. package/cli/main.mjs +1 -0
  20. package/cli/parse.mjs +1 -1
  21. package/cli/release.mjs +5 -2
  22. package/global/CHANGELOG.md +30 -0
  23. package/global/README.md +16 -0
  24. package/global/main.mjs +3 -0
  25. package/modules/container/README.md +2 -15
  26. package/modules/container/host.mjs +1 -3
  27. package/modules/container/ingress.mjs +1 -15
  28. package/modules/container/worker-engine.mjs +2 -3
  29. package/modules/demo-host/README.md +23 -156
  30. package/modules/demo-host/build.mjs +49 -0
  31. package/modules/demo-host/capacity.mjs +8 -2
  32. package/modules/demo-host/claim.mjs +2 -2
  33. package/modules/demo-host/diagnostics.mjs +1 -18
  34. package/modules/demo-host/native/alarms.mjs +51 -0
  35. package/modules/demo-host/native/bindings.mjs +24 -0
  36. package/modules/demo-host/native/bridge.mjs +17 -0
  37. package/modules/demo-host/native/config.mjs +35 -0
  38. package/modules/demo-host/native/cron.mjs +31 -0
  39. package/modules/demo-host/native/d1.mjs +37 -0
  40. package/modules/demo-host/native/deploy-r2.mjs +43 -0
  41. package/modules/demo-host/native/isolate.mjs +36 -0
  42. package/modules/demo-host/native/loader.mjs +30 -0
  43. package/modules/demo-host/native/namespace.mjs +35 -0
  44. package/modules/demo-host/native/prepare.mjs +35 -0
  45. package/modules/demo-host/native/queues.mjs +62 -0
  46. package/modules/demo-host/native/r2-client.mjs +37 -0
  47. package/modules/demo-host/native/r2.mjs +43 -0
  48. package/modules/demo-host/native/resources.mjs +37 -0
  49. package/modules/demo-host/native/seed-object.mjs +22 -0
  50. package/modules/demo-host/native/sql.mjs +17 -0
  51. package/modules/demo-host/native/visitor.mjs +147 -0
  52. package/modules/demo-host/native/worker.mjs +22 -0
  53. package/modules/demo-host/pages.mjs +1 -1
  54. package/modules/demo-host/plan.mjs +9 -30
  55. package/modules/demo-host/remove.mjs +13 -23
  56. package/modules/demo-host/upgrade.mjs +41 -0
  57. package/modules/demo-host/worker.mjs +3 -4
  58. package/modules/owner-claim/verify.d.mts +5 -0
  59. package/modules/release/README.md +11 -1
  60. package/modules/release/github-verify.mjs +30 -26
  61. package/modules/release/produce.mjs +2 -2
  62. package/modules/release/source-verification.mjs +2 -2
  63. package/modules/release/verify-workflow.mjs +23 -0
  64. package/package.json +1 -1
  65. package/modules/demo-host/container.mjs +0 -221
  66. package/modules/demo-host/entrypoint.sh +0 -9
  67. package/modules/demo-host/image.mjs +0 -18
  68. package/modules/demo-host/placement.mjs +0 -37
  69. package/modules/demo-host/prepare.mjs +0 -28
  70. package/modules/demo-host/startup.mjs +0 -27
  71. package/modules/demo-host/template.mjs +0 -71
package/README.md CHANGED
@@ -296,3 +296,19 @@ No global package manager installation or sudo is needed. Independent projects
296
296
  continue to run their declared commands with their own tools. Server and job
297
297
  state default to `$HOME/.rer/servers` and `$HOME/.rer/jobs`; supplied
298
298
  `RER_SERVERS_DIR` and `RER_JOBS_DIR` take precedence and are passed to older pins.
299
+
300
+ ## Inspect local business signals
301
+
302
+ `rer business scan [DIR...] [--json]` scans the current directory or the named
303
+ local directories without installing dependencies, executing project code or
304
+ using the network. It works outside RER checkouts. Both forms print one JSON
305
+ document: `{schema: "rer-business-signals/1", source: "local", signals: [...],
306
+ withheld: N}`. Signals identify package, environment, CI, infrastructure and
307
+ configuration names with a relative `locator`, repository basename `repo`,
308
+ `class` (`live-use` or `trace`) and `observedAt`.
309
+
310
+ Only names leave the scanner. Secret files are never opened and contribute
311
+ `secret-file` metadata (filename, path, size and modification time).
312
+ Sensitive-looking outbound names are dropped and counted in `withheld`.
313
+ Symlinks, generated outputs and dependency trees are skipped; unsupported
314
+ formats and syntax may yield no signals.
package/cli/README.md CHANGED
@@ -336,3 +336,20 @@ or deploy hook. Failure reports distinguish deployment, owner claim and token
336
336
  retirement and preserve the environment, checkout and env-file in recovery
337
337
  commands. Retirement can be finished with `rer deploy --unset-secret SETUP_TOKEN`
338
338
  plus the same `--environment`, `--env-file` and `--cwd` arguments.
339
+
340
+ ## Local business signals
341
+
342
+ `rer business scan [DIR...] [--json]` reads local source and configuration names;
343
+ with no directories it scans the current directory. It needs no RER project
344
+ declaration, dependency installation, network access or command execution.
345
+ Both forms write one JSON document with schema `rer-business-signals/1`,
346
+ `source: "local"`, a `signals` array and a numeric `withheld` count. Each signal
347
+ has `kind`, `value` (a name), relative `locator`, repository basename `repo`,
348
+ `class` (`live-use` or `trace` for examples/comments), and `observedAt`.
349
+
350
+ This is names-only discovery: configuration values and file contents are not
351
+ emitted. Denied secret files are never opened; their `secret-file` observations
352
+ contain only the filename, path, size and modification time. Sensitive-looking
353
+ outbound names are dropped entirely and counted in `withheld`. Symlinks, build
354
+ outputs and dependency trees are skipped. Unsupported syntax yields no signal;
355
+ an empty result is not proof that a repository has no business dependencies.
@@ -0,0 +1,27 @@
1
+ import { scan } from './scan.mjs';
2
+
3
+ const usage = 'Usage: rer business scan [DIR...] [--json]\nNames-only local discovery; returns rer-business-signals/1 JSON. No network calls.\n';
4
+
5
+ export async function businessCommand(argv) {
6
+ if (!argv.length || argv.length === 1 && ['--help', '-h'].includes(argv[0]) || argv[0] === 'scan' && argv.slice(1).some(arg => ['--help', '-h'].includes(arg))) {
7
+ process.stdout.write(usage); return 0;
8
+ }
9
+ if (argv[0] !== 'scan') { process.stderr.write(usage); return 2; }
10
+ const directories = [];
11
+ let positional = false, json = false;
12
+ for (const arg of argv.slice(1)) {
13
+ if (!positional && arg === '--') { positional = true; continue; }
14
+ if (!positional && arg === '--json' && !json) { json = true; continue; }
15
+ if (!positional && arg.startsWith('-') || !arg.trim()) { process.stderr.write(usage); return 2; }
16
+ directories.push(arg);
17
+ }
18
+ try {
19
+ const result = await scan(directories.length ? directories : [process.cwd()]);
20
+ process.stdout.write(JSON.stringify(result) + '\n');
21
+ return 0;
22
+ } catch {
23
+ // Node/format errors can contain input paths, keys or source excerpts.
24
+ process.stderr.write('Business scan could not read a local input. No scan document was emitted.\n');
25
+ return 1;
26
+ }
27
+ }
@@ -0,0 +1,42 @@
1
+ // Inspect every outbound string, including locators and repository names. There
2
+ // is no diagnostic containing a match, and no value-masking stage.
3
+ const shapes = [
4
+ /-----\s*BEGIN\b/i,
5
+ /(?:sk_live_|rk_live_|AKIA|ghp_|gho_|github_pat_|xox[abpr]-)/,
6
+ /\beyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/,
7
+ /\b(?:ssh-(?:rsa|ed25519)|ecdsa-sha2-[\w-]+)\s+[A-Za-z0-9+/=]+/,
8
+ /\bMII[A-Za-z0-9+/]{40,}={0,2}/,
9
+ /(?:^|[^a-z])(?:TunnelSecret|TunnelID|AccountTag)(?:$|[^a-z])/i,
10
+ /[\u0000-\u001f\u007f]/,
11
+ ];
12
+
13
+ function entropy(value) {
14
+ const counts = new Map();
15
+ for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
16
+ let bits = 0;
17
+ for (const count of counts.values()) { const p = count / value.length; bits -= p * Math.log2(p); }
18
+ return bits;
19
+ }
20
+
21
+ function highEntropy(text, tokens) {
22
+ for (const match of text.matchAll(tokens)) {
23
+ const value = match[0];
24
+ if (/^[a-f\d]{32,}$/i.test(value) && entropy(value.toLowerCase()) >= 3.5) return true;
25
+ if (entropy(value) >= 4.2) return true;
26
+ }
27
+ return false;
28
+ }
29
+
30
+ export function sensitive(text) {
31
+ return shapes.some(pattern => pattern.test(text)) || highEntropy(text, /[A-Za-z0-9_+\/=\-]{24,}/g);
32
+ }
33
+
34
+ function sensitivePath(path) {
35
+ // Keep shape checks across the full path, but never combine ordinary path
36
+ // segments into an apparent high-entropy credential.
37
+ return shapes.some(pattern => pattern.test(path)) ||
38
+ path.split('/').some(part => highEntropy(part, /[A-Za-z0-9_+=\-]{24,}/g));
39
+ }
40
+
41
+ export const blockedSignal = signal => Object.entries(signal).some(([key, value]) =>
42
+ typeof value === 'string' && (key === 'locator' || key === 'repo' ? sensitivePath(value) : sensitive(value)));
@@ -0,0 +1,91 @@
1
+ import { flowEntries, keyParts, literal, splitOutside } from './parsers-syntax.mjs';
2
+
3
+ export function yamlEntries(source) {
4
+ const entries = [], stack = [];
5
+ let blockIndent, multilineQuote = '';
6
+ for (const line of source.split(/\r?\n/)) {
7
+ if (multilineQuote) { multilineQuote = remainingQuote(line, multilineQuote); continue; }
8
+ if (!line.trim() || /^\s*(?:---|\.\.\.)\s*$/.test(line)) continue;
9
+ const indent = /^ */.exec(line)[0].length;
10
+ if (blockIndent !== undefined) { if (indent > blockIndent) continue; blockIndent = undefined; }
11
+ while (stack.length && indent <= stack.at(-1).indent) stack.pop();
12
+ let raw = line.trim(), path = stack.at(-1)?.path ?? [], keyIndent = indent;
13
+ if (raw.startsWith('- ')) {
14
+ path = [...path, '[]']; raw = raw.slice(2).trim(); keyIndent += 2;
15
+ stack.push({ indent, path });
16
+ }
17
+ if (raw.startsWith('{') || raw.startsWith('[')) { flowEntries(raw, path, ':', entries); continue; }
18
+ const parts = splitOutside(raw, ':');
19
+ if (parts.length < 2 || !/^\s/.test(parts[1]) && parts[1] !== '') {
20
+ if (path.at(-1) === '[]') entries.push({ path, value: literal(raw) });
21
+ continue;
22
+ }
23
+ const keys = keyParts(parts.shift()); if (!keys) continue;
24
+ const child = [...path, ...keys], value = parts.join(':').trim();
25
+ entries.push({ path: child, value: literal(value) });
26
+ if (/^["']/.test(value)) { multilineQuote = remainingQuote(value); if (multilineQuote) continue; }
27
+ if (/^[|>][+-]?[0-9]?$|^[|>][0-9][+-]?$/.test(value)) { blockIndent = keyIndent; continue; }
28
+ if (!value || /^(?:&[A-Za-z0-9_-]+|![^ ]+)\s*$/.test(value)) stack.push({ indent: keyIndent, path: child });
29
+ else flowEntries(value, child, ':', entries);
30
+ }
31
+ return entries;
32
+ }
33
+
34
+ function remainingQuote(source, initial = '') {
35
+ let quote = initial;
36
+ for (let i = 0; i < source.length; i++) {
37
+ const char = source[i];
38
+ if (quote) {
39
+ if (char === '\\' && quote === '"') i++;
40
+ else if (char === quote) {
41
+ if (quote === "'" && source[i + 1] === "'") i++;
42
+ else quote = '';
43
+ }
44
+ } else if (char === '"' || char === "'") quote = char;
45
+ }
46
+ return quote;
47
+ }
48
+
49
+ function statements(source) {
50
+ const result = []; let current = '', quote = '', depth = 0, triple = false;
51
+ for (let i = 0; i < source.length; i++) {
52
+ const char = source[i]; current += char;
53
+ if (quote) {
54
+ if (char === '\\' && quote === '"') { current += source[++i] ?? ''; }
55
+ else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { current += source.slice(i + 1, i + 3); i += 2; quote = ''; triple = false; }
56
+ else if (!triple && char === quote) quote = '';
57
+ } else if (char === '"' || char === "'") {
58
+ quote = char;
59
+ if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; current += source.slice(i + 1, i + 3); i += 2; }
60
+ } else if (char === '[' || char === '{') depth++;
61
+ else if (char === ']' || char === '}') depth--;
62
+ else if (char === '\n' && depth === 0) { result.push(current.trim()); current = ''; }
63
+ }
64
+ if (current.trim()) result.push(current.trim()); return result;
65
+ }
66
+
67
+ export function tomlEntries(source) {
68
+ const entries = []; let table = [];
69
+ for (const statement of statements(source)) {
70
+ const header = /^(\[\[?)([\s\S]*?)(\]\]?)$/.exec(statement);
71
+ if (header && header[1].length === header[3].length) {
72
+ table = keyParts(header[2], true) ?? [];
73
+ if (table.length) {
74
+ entries.push({ path: table, value: undefined });
75
+ if (header[1] === '[[') table = [...table, '[]'];
76
+ }
77
+ continue;
78
+ }
79
+ const parts = splitOutside(statement, '='); if (parts.length < 2) continue;
80
+ const keys = keyParts(parts.shift(), true); if (!keys) continue;
81
+ const path = [...table, ...keys], raw = parts.join('=').trim();
82
+ entries.push({ path, value: literal(raw) }); flowEntries(raw, path, '=', entries);
83
+ }
84
+ return entries;
85
+ }
86
+
87
+ export function configNames(entries, add) {
88
+ for (const { path } of entries) {
89
+ if (path.at(-1) !== '[]') add('config-key', path.join('.'));
90
+ }
91
+ }
@@ -0,0 +1,68 @@
1
+ import { identifier } from './parsers-syntax.mjs';
2
+ import { terraformNames } from './parsers-terraform.mjs';
3
+
4
+ function registryHost(image) {
5
+ if (typeof image !== 'string' || /[\s?#\\]|:\/\//.test(image)) return undefined;
6
+ const slash = image.indexOf('/'); if (slash < 1) return undefined;
7
+ const first = image.slice(0, slash); if (first.includes('@')) return undefined;
8
+ // Docker interprets a dotted first component, localhost or a host:port as
9
+ // an explicit registry. An unqualified image does not identify a registry.
10
+ if (!first.includes('.') && first !== 'localhost' && !first.includes(':')) return undefined;
11
+ const host = first.replace(/:[0-9]{1,5}$/, '');
12
+ if (first !== host && !/^\d{1,5}$/.test(first.slice(host.length + 1))) return undefined;
13
+ if (host === 'localhost' || (host.length <= 253 && host.split('.').every(label => /^[A-Za-z0-9](?:[A-Za-z0-9-]*[A-Za-z0-9])?$/.test(label)))) return host.toLowerCase();
14
+ return undefined;
15
+ }
16
+
17
+ function ciNames(source, entries, add) {
18
+ for (const match of source.matchAll(/\b(?:secrets|vars)\s*(?:\.\s*([A-Za-z_][A-Za-z0-9_]*)|\[\s*(["'])([A-Za-z_][A-Za-z0-9_]*)\2\s*\])/g)) add('ci-secret', match[1] ?? match[3]);
19
+ for (const { path, value } of entries) {
20
+ const parent = path.at(-2), key = path.at(-1);
21
+ if (['env', 'environment', 'variables', 'secrets'].includes(parent) && identifier.test(key)) add('ci-secret', key);
22
+ if (parent === '[]' && ['env', 'variables'].includes(path.at(-3))) {
23
+ if (key === 'name' && typeof value === 'string' && identifier.test(value)) add('ci-secret', value);
24
+ }
25
+ if (key === '[]' && path.some(part => ['env', 'environment', 'variables'].includes(part)) && typeof value === 'string') {
26
+ const match = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(value); if (match) add('ci-secret', match[1]);
27
+ }
28
+ }
29
+ }
30
+
31
+ export function infrastructureDocument(pathname, entries) {
32
+ return /\.(?:tf|hcl|tf\.json)$/i.test(pathname)
33
+ || /(?:^|\/)(?:charts?|helm)\//i.test(pathname)
34
+ || /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname)
35
+ || entries.some(({ path }) => path.length === 1 && path[0] === 'Resources')
36
+ || entries.some(({ path }) => path.at(-1) === 'apiVersion') && entries.some(({ path }) => path.at(-1) === 'kind');
37
+ }
38
+
39
+ export function infrastructureNames(pathname, source, entries, ci, add) {
40
+ if (ci) ciNames(source, entries, add);
41
+ if (/\.(?:tf|hcl)$/i.test(pathname)) terraformNames(source, add);
42
+ const kubernetes = new Set(entries.filter(entry => entry.path.at(-1) === 'apiVersion').map(entry => entry.path.slice(0, -1).join('\0')));
43
+ const images = ci || infrastructureDocument(pathname, entries);
44
+ for (const { path, value } of entries) {
45
+ if (/\.tf\.json$/i.test(pathname)) {
46
+ if (path[0] === 'provider' && path.length === 2) add('iac-provider', path[1]);
47
+ if (['resource', 'data'].includes(path[0]) && path.length === 2) add('iac-resource', path[1]);
48
+ if (path.includes('required_providers') && path.at(-1) === 'source' && typeof value === 'string'
49
+ && /^[A-Za-z0-9][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9][A-Za-z0-9_.-]*){1,2}$/.test(value)) add('iac-provider', value);
50
+ }
51
+ if (typeof value !== 'string') continue;
52
+ const key = path.at(-1);
53
+ if (key === 'kind' && kubernetes.has(path.slice(0, -1).join('\0')) && /^[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
54
+ if (/^(?:Type|type)$/.test(key)) {
55
+ if (path[0] === 'Resources' && path.length === 3 && /^[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*::[A-Za-z][A-Za-z0-9]*$/.test(value)) add('iac-resource', value);
56
+ if (path[0] === 'resources' && path.length === 3 && /(?:^|\/)Pulumi[^/]*\.(?:ya?ml|json)$/i.test(pathname) && /^[A-Za-z][A-Za-z0-9_-]*:[A-Za-z0-9_./-]*:[A-Za-z][A-Za-z0-9_]*$/.test(value)) {
57
+ const provider = /^pulumi:providers:([A-Za-z][A-Za-z0-9_-]*)$/.exec(value);
58
+ add(provider ? 'iac-provider' : 'iac-resource', provider?.[1] ?? value);
59
+ }
60
+ }
61
+ if (images && (key === 'image' || (key === 'repository' && path.includes('image')))) {
62
+ const host = registryHost(value); if (host) add('iac-provider', host);
63
+ }
64
+ if (images && key === 'registry' && path.includes('image')) {
65
+ const host = registryHost(`${value}/_`); if (host) add('iac-provider', host);
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,84 @@
1
+ import { identifier, literal, packageName, splitOutside } from './parsers-syntax.mjs';
2
+
3
+ function requirement(value) {
4
+ // In a direct reference, only the package before @ is a name. Bare URLs,
5
+ // editable paths, index options and includes are deliberately not followed.
6
+ const match = /^([A-Za-z0-9][A-Za-z0-9._-]*)(?=\s*(?:\[|[<>=!~;@]|\(|$))/.exec(value.trim());
7
+ return match?.[1];
8
+ }
9
+
10
+ function jsonDependencies(source, sections, add) {
11
+ let manifest;
12
+ try { manifest = JSON.parse(source); } catch { return; }
13
+ if (!manifest || typeof manifest !== 'object' || Array.isArray(manifest)) return;
14
+ for (const section of sections) {
15
+ const dependencies = manifest[section];
16
+ if (!dependencies || typeof dependencies !== 'object' || Array.isArray(dependencies)) continue;
17
+ for (const name of Object.keys(dependencies)) if (packageName.test(name)) add('package', name);
18
+ }
19
+ }
20
+
21
+ function cargoDependencies(source, add) {
22
+ let dependencyTable = false;
23
+ for (const line of source.split(/\r?\n/)) {
24
+ const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
25
+ if (header) {
26
+ const table = header[1].trim();
27
+ dependencyTable = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)$/.test(table);
28
+ const detail = /(?:^|\.)(?:dependencies|dev-dependencies|build-dependencies)\.([A-Za-z0-9_-]+)$/.exec(table);
29
+ if (detail) add('package', detail[1]);
30
+ continue;
31
+ }
32
+ if (!dependencyTable) continue;
33
+ const parts = splitOutside(line, '='); if (parts.length < 2) continue;
34
+ const name = literal(parts.shift()); if (!name || !packageName.test(name)) continue;
35
+ // Cargo renames name a different package explicitly inside an inline table.
36
+ const renamed = /(?:^|[,\s{])package\s*=\s*(["'])([A-Za-z0-9_-]+)\1/.exec(parts.join('='));
37
+ add('package', renamed?.[2] ?? name);
38
+ }
39
+ }
40
+
41
+ function goDependencies(source, add) {
42
+ let group = false;
43
+ const name = '[A-Za-z0-9][A-Za-z0-9._~-]*(?:/[A-Za-z0-9][A-Za-z0-9._~-]*)+';
44
+ for (const line of source.split(/\r?\n/)) {
45
+ if (/^\s*require\s*\(\s*$/.test(line)) { group = true; continue; }
46
+ if (group && /^\s*\)\s*$/.test(line)) { group = false; continue; }
47
+ const match = new RegExp(group ? `^\\s*(${name})\\s+v[^\\s]+\\s*$` : `^\\s*require\\s+(${name})\\s+v[^\\s]+\\s*$`).exec(line);
48
+ if (match) add('package', match[1]);
49
+ }
50
+ }
51
+
52
+ export function packageNames(filename, source, entries, add) {
53
+ if (filename === 'package.json') {
54
+ jsonDependencies(source, ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'], add);
55
+ } else if (filename === 'composer.json') {
56
+ jsonDependencies(source, ['require', 'require-dev'], add);
57
+ } else if (/^requirements[^/]*\.txt$/.test(filename)) {
58
+ for (const line of source.split(/\r?\n/)) { const name = requirement(line); if (name) add('package', name); }
59
+ } else if (filename === 'pyproject.toml') {
60
+ for (const { path, value } of entries) {
61
+ if (typeof value === 'string' && ((path[0] === 'project' && path[1] === 'dependencies' && path[2] === '[]')
62
+ || (path[0] === 'project' && path[1] === 'optional-dependencies' && path[3] === '[]'))) {
63
+ const name = requirement(value); if (name) add('package', name);
64
+ }
65
+ const poetry = path[0] === 'tool' && path[1] === 'poetry';
66
+ const dependencyIndex = poetry && (path[2] === 'dependencies' || path[2] === 'dev-dependencies') ? 3
67
+ : poetry && path[2] === 'group' && path[4] === 'dependencies' ? 5 : -1;
68
+ if (dependencyIndex !== -1 && path.length === dependencyIndex + 1 && path[dependencyIndex] !== 'python' && packageName.test(path[dependencyIndex])) add('package', path[dependencyIndex]);
69
+ }
70
+ } else if (filename === 'gemfile') {
71
+ for (const line of source.split(/\r?\n/)) {
72
+ const match = /^\s*gem\s*(?:\(\s*)?(["'])([A-Za-z0-9][A-Za-z0-9_.-]*)\1(?=\s*[,)]|\s*$)/.exec(line);
73
+ if (match) add('package', match[2]);
74
+ }
75
+ } else if (filename === 'go.mod') goDependencies(source, add);
76
+ else if (filename === 'cargo.toml') cargoDependencies(source, add);
77
+ }
78
+
79
+ export function environmentNames(source, add) {
80
+ for (const line of source.split(/\r?\n/)) {
81
+ const match = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]*)\s*=/.exec(line);
82
+ if (match && identifier.test(match[1])) add('env-key', match[1]);
83
+ }
84
+ }
@@ -0,0 +1,64 @@
1
+ // Source support is deliberately limited to literal provider imports and calls
2
+ // through those imports. Nothing is imported, instantiated or executed.
3
+ export function pulumiNames(pathname, source, add) {
4
+ const aliases = new Map(), executable = maskStrings(source), maskedLines = executable.split(/\r?\n/), lines = source.split(/\r?\n/);
5
+ const register = (alias, provider) => {
6
+ if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(alias) || !/^[a-z][a-z0-9_-]*$/.test(provider)) return;
7
+ if (provider === 'pulumi') return;
8
+ aliases.set(alias, provider); add('iac-provider', provider);
9
+ };
10
+ if (/\.[cm]?[jt]sx?$/i.test(pathname)) {
11
+ for (let index = 0; index < lines.length; index++) {
12
+ const line = lines[index]; if (!/^\s*(?:import|const|let|var)\b/.test(maskedLines[index])) continue;
13
+ const imported = /^\s*import\s+(?:\*\s+as\s+)?([A-Za-z_][A-Za-z0-9_]*)\s+from\s+(["'])@pulumi\/([a-z][a-z0-9_-]*)\2(?=\s*(?:;|$))/.exec(line);
14
+ if (imported) register(imported[1], imported[3]);
15
+ const required = /^\s*(?:const|let|var)\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*require\(\s*(["'])@pulumi\/([a-z][a-z0-9_-]*)\2\s*\)(?=\s*(?:;|$))/.exec(line);
16
+ if (required) register(required[1], required[3]);
17
+ }
18
+ } else if (/\.py$/i.test(pathname)) {
19
+ for (let index = 0; index < lines.length; index++) {
20
+ const line = lines[index]; if (!/^\s*(?:import|from)\b/.test(maskedLines[index])) continue;
21
+ const imported = /^\s*import\s+pulumi_([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
22
+ if (imported) register(imported[2] ?? `pulumi_${imported[1]}`, imported[1]);
23
+ const from = /^\s*from\s+pulumi_([a-z][a-z0-9_]*)\s+import\s+([a-z][a-z0-9_]*)(?:\s+as\s+([A-Za-z_][A-Za-z0-9_]*))?\s*$/.exec(line);
24
+ if (from) register(from[3] ?? from[2], from[1]);
25
+ }
26
+ } else if (/\.go$/i.test(pathname)) {
27
+ let imports = false;
28
+ for (const line of source.split(/\r?\n/)) {
29
+ if (/^\s*import\s*\(\s*$/.test(line)) { imports = true; continue; }
30
+ if (/^\s*\)\s*$/.test(line)) imports = false;
31
+ const imported = new RegExp(`^\\s*${imports ? '' : 'import\\s+'}(?:([A-Za-z_][A-Za-z0-9_]*)\\s+)?"github\\.com/pulumi/pulumi-([a-z][a-z0-9_-]*)/sdk/(?:v[0-9]+/)?go/([A-Za-z0-9_/]+)"\\s*$`).exec(line);
32
+ if (imported) register(imported[1] ?? imported[3].split('/').at(-1), imported[2]);
33
+ }
34
+ }
35
+ // Mask all strings and heredocs before looking for constructor expressions.
36
+ // Otherwise a code example embedded in a description could become live use.
37
+ for (const match of executable.matchAll(/\b(?:new\s+)?([A-Za-z_][A-Za-z0-9_]*)((?:\.[A-Za-z_][A-Za-z0-9_]*)+)\s*\(/g)) {
38
+ if (!aliases.has(match[1])) continue;
39
+ const type = match[2].slice(1).split('.').at(-1);
40
+ if (/^[A-Z]/.test(type) && type !== 'Provider') add('iac-resource', `${match[1]}${match[2]}`);
41
+ }
42
+ if (/\.cs$/i.test(pathname)) {
43
+ for (const match of executable.matchAll(/\bnew\s+(Pulumi\.([A-Za-z][A-Za-z0-9_]*)(?:\.[A-Za-z][A-Za-z0-9_]*)+)\s*\(/g)) {
44
+ add('iac-provider', match[2]); if (!match[1].endsWith('.Provider')) add('iac-resource', match[1]);
45
+ }
46
+ }
47
+ }
48
+
49
+ export function maskStrings(source) {
50
+ let result = '', quote = '', triple = false;
51
+ for (let i = 0; i < source.length; i++) {
52
+ const char = source[i];
53
+ if (quote) {
54
+ result += char === '\n' ? '\n' : ' ';
55
+ if (char === '\\' && quote !== '`') { const next = source[++i]; result += next === '\n' ? '\n' : ' '; }
56
+ else if (triple && source.slice(i, i + 3) === quote.repeat(3)) { result += ' '; i += 2; quote = ''; triple = false; }
57
+ else if (!triple && char === quote) quote = '';
58
+ } else if (['"', "'", '`'].includes(char)) {
59
+ quote = char; result += ' ';
60
+ if (source.slice(i, i + 3) === char.repeat(3)) { triple = true; result += ' '; i += 2; }
61
+ } else result += char;
62
+ }
63
+ return result;
64
+ }
@@ -0,0 +1,113 @@
1
+ // These readers describe syntax only. They never resolve a tag, alias, include,
2
+ // interpolation or executable expression. Unsupported syntax contributes no value.
3
+ export const identifier = /^[A-Za-z_][A-Za-z0-9_.-]*$/;
4
+ export const packageName = /^(?:@[a-z0-9_.-]+\/)?[a-z0-9][a-z0-9_.-]*(?:\/[a-z0-9][a-z0-9_.-]*)*$/i;
5
+
6
+ export function literal(source) {
7
+ const value = source.trim();
8
+ if (value.startsWith('"')) {
9
+ try { const parsed = JSON.parse(value); return typeof parsed === 'string' ? parsed : undefined; } catch { return undefined; }
10
+ }
11
+ if (value.startsWith("'")) return /^'(?:[^']|'')*'$/.test(value) ? value.slice(1, -1).replace(/''/g, "'") : undefined;
12
+ return /^[^\s\[\]{},#'"`]+$/.test(value) ? value : undefined;
13
+ }
14
+
15
+ // Keep offsets/newlines, so a removed comment cannot join adjacent tokens.
16
+ // In YAML/TOML, # starts comments; // only starts comments in JSON/HCL/code.
17
+ export function comments(source, slash = false) {
18
+ let clean = '', quote = '', block = false, comment = '';
19
+ const traces = [];
20
+ for (let i = 0; i < source.length; i++) {
21
+ const char = source[i], next = source[i + 1];
22
+ if (block) {
23
+ if (char === '*' && next === '/') { traces.push(comment); comment = ''; block = false; clean += ' '; i++; }
24
+ else { comment += char; clean += char === '\n' ? '\n' : ' '; }
25
+ } else if (quote) {
26
+ clean += char;
27
+ if (char === '\\' && quote !== "'") { clean += next ?? ''; i++; }
28
+ else if (char === quote) {
29
+ if (quote === "'" && next === "'") { clean += next; i++; }
30
+ else quote = '';
31
+ }
32
+ } else if (char === '"' || char === "'" || (slash && char === '`')) { quote = char; clean += char; }
33
+ else if (slash && char === '/' && next === '*') { block = true; clean += ' '; i++; }
34
+ else if (char === '#' || (slash && char === '/' && next === '/')) {
35
+ const start = i + (char === '#' ? 1 : 2);
36
+ let end = source.indexOf('\n', start); if (end === -1) end = source.length;
37
+ traces.push(source.slice(start, end)); clean += ' '.repeat(end - i); i = end - 1;
38
+ } else clean += char;
39
+ }
40
+ if (block) traces.push(comment);
41
+ return { clean, traces };
42
+ }
43
+
44
+ // Split delimiters outside strings and flow collections. No regexp can safely
45
+ // split an inline table containing a quoted comma or colon.
46
+ export function splitOutside(source, delimiter) {
47
+ const result = []; let start = 0, quote = '', depth = 0;
48
+ for (let i = 0; i < source.length; i++) {
49
+ const char = source[i];
50
+ if (quote) {
51
+ if (char === '\\' && quote === '"') i++;
52
+ else if (char === quote) {
53
+ if (quote === "'" && source[i + 1] === "'") i++;
54
+ else quote = '';
55
+ }
56
+ } else if (char === '"' || char === "'") quote = char;
57
+ else if (char === '[' || char === '{') depth++;
58
+ else if (char === ']' || char === '}') depth--;
59
+ else if (char === delimiter && depth === 0) { result.push(source.slice(start, i)); start = i + 1; }
60
+ }
61
+ result.push(source.slice(start)); return result;
62
+ }
63
+
64
+ export function keyParts(source, dotted = false) {
65
+ const pieces = dotted ? splitOutside(source, '.') : [source];
66
+ const result = pieces.map(piece => {
67
+ const trimmed = piece.trim(), value = literal(trimmed);
68
+ return value && (/^["']/.test(trimmed) || identifier.test(value)) ? value : undefined;
69
+ });
70
+ return result.length && result.every(part => part !== undefined) ? result : undefined;
71
+ }
72
+
73
+ export function flowEntries(source, path, delimiter, entries, depth = 0) {
74
+ if (depth > 48) return;
75
+ const value = source.trim();
76
+ if (value.startsWith('{') && value.endsWith('}')) {
77
+ for (const pair of splitOutside(value.slice(1, -1), ',')) {
78
+ const parts = splitOutside(pair, delimiter); if (parts.length < 2) continue;
79
+ const keys = keyParts(parts.shift(), delimiter === '='); if (!keys) continue;
80
+ const child = [...path, ...keys], raw = parts.join(delimiter).trim();
81
+ entries.push({ path: child, value: literal(raw) }); flowEntries(raw, child, delimiter, entries, depth + 1);
82
+ }
83
+ } else if (value.startsWith('[') && value.endsWith(']')) {
84
+ for (const item of splitOutside(value.slice(1, -1), ',')) {
85
+ const child = [...path, '[]']; entries.push({ path: child, value: literal(item) });
86
+ flowEntries(item, child, delimiter, entries, depth + 1);
87
+ }
88
+ }
89
+ }
90
+
91
+ export function jsonEntries(source) {
92
+ let root;
93
+ try { root = JSON.parse(source); } catch { return []; }
94
+ const entries = [], pending = [{ value: root, path: [] }];
95
+ while (pending.length) {
96
+ const { value, path } = pending.pop(); if (path.length > 48) continue;
97
+ if (Array.isArray(value)) {
98
+ for (const child of value) {
99
+ const next = [...path, '[]']; entries.push({ path: next, value: typeof child === 'string' ? child : undefined });
100
+ if (child && typeof child === 'object') pending.push({ path: next, value: child });
101
+ }
102
+ } else if (value && typeof value === 'object') {
103
+ for (const [key, child] of Object.entries(value)) {
104
+ // JSON object keys are names, including quoted names with spaces. The
105
+ // caller applies its output detector to every candidate, including keys.
106
+ if (!key) continue;
107
+ const next = [...path, key]; entries.push({ path: next, value: typeof child === 'string' ? child : undefined });
108
+ if (child && typeof child === 'object') pending.push({ path: next, value: child });
109
+ }
110
+ }
111
+ }
112
+ return entries;
113
+ }
@@ -0,0 +1,53 @@
1
+ function tokens(source) {
2
+ const result = [];
3
+ for (let i = 0; i < source.length;) {
4
+ if (/\s/.test(source[i])) { i++; continue; }
5
+ if (source.slice(i, i + 2) === '<<') {
6
+ const marker = /^<<-?([A-Za-z_][A-Za-z0-9_]*)[^\S\n]*\r?\n/.exec(source.slice(i));
7
+ if (marker) {
8
+ i += marker[0].length;
9
+ while (i < source.length) {
10
+ let end = source.indexOf('\n', i); if (end === -1) end = source.length;
11
+ const line = source.slice(i, end).trim(); i = end + 1;
12
+ if (line === marker[1]) break;
13
+ }
14
+ continue;
15
+ }
16
+ }
17
+ if (source[i] === '"') {
18
+ let end = i + 1;
19
+ for (; end < source.length; end++) {
20
+ if (source[end] === '\\') end++;
21
+ else if (source[end] === '"') { end++; break; }
22
+ }
23
+ let value; try { value = JSON.parse(source.slice(i, end)); } catch { /* Opaque malformed string. */ }
24
+ result.push({ type: 'string', value }); i = end; continue;
25
+ }
26
+ const word = /^[A-Za-z_][A-Za-z0-9_-]*/.exec(source.slice(i));
27
+ if (word) { result.push({ type: 'word', value: word[0] }); i += word[0].length; }
28
+ else { result.push({ type: source[i], value: source[i] }); i++; }
29
+ }
30
+ return result;
31
+ }
32
+
33
+ export function terraformNames(source, add) {
34
+ const syntax = tokens(source), stack = [];
35
+ for (let i = 0; i < syntax.length; i++) {
36
+ const token = syntax[i];
37
+ if (token.type === '{') { stack.push(syntax[i - 1]?.value === 'required_providers'); continue; }
38
+ if (token.type === '}') { stack.pop(); continue; }
39
+ if (token.type !== 'word') continue;
40
+ if (['provider', 'resource', 'data'].includes(token.value) && syntax[i + 1]?.type === 'string') {
41
+ const label = syntax[i + 1].value, next = i + (token.value === 'provider' ? 2 : 3);
42
+ if (typeof label === 'string' && /^[A-Za-z][A-Za-z0-9_-]*$/.test(label) && syntax[next]?.type === '{'
43
+ && (token.value === 'provider' || syntax[i + 2]?.type === 'string')) {
44
+ add(token.value === 'provider' ? 'iac-provider' : 'iac-resource', label);
45
+ }
46
+ }
47
+ if (stack.at(-1) && syntax[i + 1]?.type === '=' && syntax[i + 2]?.type === '{') add('iac-provider', token.value);
48
+ if (stack.includes(true) && token.value === 'source' && syntax[i + 1]?.type === '=' && syntax[i + 2]?.type === 'string') {
49
+ const value = syntax[i + 2].value;
50
+ if (typeof value === 'string' && /^[A-Za-z0-9][A-Za-z0-9_.-]*(?:\/[A-Za-z0-9][A-Za-z0-9_.-]*){1,2}$/.test(value)) add('iac-provider', value);
51
+ }
52
+ }
53
+ }
@@ -0,0 +1,62 @@
1
+ import { comments, jsonEntries } from './parsers-syntax.mjs';
2
+ import { configNames, tomlEntries, yamlEntries } from './parsers-config.mjs';
3
+ import { environmentNames, packageNames } from './parsers-packages.mjs';
4
+ import { infrastructureDocument, infrastructureNames } from './parsers-infrastructure.mjs';
5
+ import { pulumiNames } from './parsers-pulumi.mjs';
6
+
7
+ const examples = /(?:^|[/.\-_])(?:examples?|samples?|templates?|fixtures?)(?:[/.\-_]|$)/i;
8
+ const manifests = /^(?:package\.json|composer\.json|requirements[^/]*\.txt|pyproject\.toml|gemfile|go\.mod|cargo\.toml)$/;
9
+ const code = /\.(?:[cm]?[jt]sx?|py|go|cs)$/i;
10
+
11
+ function entriesFor(pathname, source) {
12
+ if (/\.jsonc?(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return jsonEntries(source);
13
+ if (/\.toml(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return tomlEntries(source);
14
+ if (/\.ya?ml(?:\.(?:example|sample|template|tpl))?$/i.test(pathname)) return yamlEntries(source);
15
+ return [];
16
+ }
17
+
18
+ // No I/O, evaluation or diagnostics containing input. Each extractor emits a
19
+ // narrow syntactic name at its source, rather than redacting scalar values later.
20
+ export function parseNames(relativePath, text) {
21
+ if (typeof relativePath !== 'string' || typeof text !== 'string') return [];
22
+ const pathname = relativePath.replace(/\\/g, '/'), filename = pathname.split('/').at(-1).toLowerCase();
23
+ const ci = /(?:^|\/)(?:\.github\/workflows\/|\.circleci\/|\.gitlab-ci(?:[./-]|$)|azure-pipelines[./-]|\.travis[./-]|jenkinsfile$|bitbucket-pipelines[./-]|\.buildkite\/)/i.test(pathname);
24
+ const env = /(?:^|\/)(?:\.?env(?:[.\-_]|$)|[^/]*(?:env|config|settings)[^/]*(?:example|sample|template))/i.test(pathname);
25
+ const helm = /(?:^|\/)(?:charts?|helm)\/.*(?:^|\/)templates\//i.test(pathname)
26
+ || /(?:^|\/)(?:charts?|helm)\/templates\//i.test(pathname);
27
+ const explicitExample = /(?:^|[/.\-_])(?:examples?|samples?|fixtures?)(?:[/.\-_]|$)/i.test(pathname);
28
+ const manifest = manifests.test(filename), classification = examples.test(pathname) && (!helm || explicitExample) ? 'trace' : 'live-use';
29
+ const result = [], seen = new Set();
30
+ const emit = evidenceClass => (kind, value) => {
31
+ if (typeof value !== 'string' || !value || value.length > 512 || /[\r\n\0]/.test(value)) return;
32
+ const key = `${evidenceClass}\0${kind}\0${value}`;
33
+ if (!seen.has(key)) { seen.add(key); result.push({ kind, value, class: evidenceClass }); }
34
+ };
35
+ const parse = (source, evidenceClass, isComment) => {
36
+ const entries = entriesFor(pathname, source);
37
+ const deployed = !isComment && !explicitExample && (ci || infrastructureDocument(pathname, entries));
38
+ const add = emit(deployed ? 'live-use' : evidenceClass);
39
+ if (manifest) packageNames(filename, source, entries, add);
40
+ if (env) environmentNames(source, add);
41
+ if (!manifest && !code.test(pathname)) configNames(entries, add);
42
+ infrastructureNames(pathname, source, entries, ci, add);
43
+ if (code.test(pathname)) pulumiNames(pathname, source, add);
44
+ // Commented-out env declarations are useful traces even in config files.
45
+ if (isComment && !manifest) environmentNames(source, add);
46
+ };
47
+ try {
48
+ const templateTraces = [];
49
+ const templateClean = text.replace(/\{\{\s*\/\*([\s\S]*?)\*\/\s*\}\}/g, (whole, content) => {
50
+ templateTraces.push(content); return whole.replace(/[^\n]/g, ' ');
51
+ });
52
+ const { clean, traces } = comments(templateClean, filename === 'go.mod' || /\.(?:jsonc?|tf|hcl|[cm]?[jt]sx?|go|cs)(?:\.(?:example|sample|template|tpl))?$/i.test(pathname));
53
+ parse(clean, classification, false);
54
+ // Group consecutive comment lines so commented TOML/YAML sections retain
55
+ // their structural context. Comments never inherit live-use classification.
56
+ if (traces.length) parse(traces.join('\n'), 'trace', true);
57
+ for (const trace of templateTraces) parse(trace, 'trace', true);
58
+ } catch {
59
+ // Invalid/unsupported syntax is not permission to expose its scalar text.
60
+ }
61
+ return result;
62
+ }