@nodetool-ai/cli-common 0.0.0-stage → 0.8.9-bootstrap.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.
Files changed (75) hide show
  1. package/dist/.nodetool-build-stamp +1 -0
  2. package/dist/child-exit.d.ts +2 -0
  3. package/dist/child-exit.d.ts.map +1 -0
  4. package/dist/child-exit.js +2 -0
  5. package/dist/child-exit.js.map +1 -0
  6. package/dist/command-errors.d.ts +2 -0
  7. package/dist/command-errors.d.ts.map +1 -0
  8. package/dist/command-errors.js +2 -0
  9. package/dist/command-errors.js.map +1 -0
  10. package/dist/commands/debug-summary-output.d.ts +22 -0
  11. package/dist/commands/debug-summary-output.d.ts.map +1 -0
  12. package/dist/commands/debug-summary-output.js +28 -0
  13. package/dist/commands/debug-summary-output.js.map +1 -0
  14. package/dist/commands/output.d.ts +2 -0
  15. package/dist/commands/output.d.ts.map +1 -0
  16. package/dist/commands/output.js +2 -0
  17. package/dist/commands/output.js.map +1 -0
  18. package/dist/commands/validation-output.d.ts +25 -0
  19. package/dist/commands/validation-output.d.ts.map +1 -0
  20. package/dist/commands/validation-output.js +29 -0
  21. package/dist/commands/validation-output.js.map +1 -0
  22. package/dist/commands/version-commands.d.ts +91 -0
  23. package/dist/commands/version-commands.d.ts.map +1 -0
  24. package/dist/commands/version-commands.js +222 -0
  25. package/dist/commands/version-commands.js.map +1 -0
  26. package/dist/debug-bundle.d.ts +12 -0
  27. package/dist/debug-bundle.d.ts.map +1 -0
  28. package/dist/debug-bundle.js +21 -0
  29. package/dist/debug-bundle.js.map +1 -0
  30. package/dist/document-json.d.ts +11 -0
  31. package/dist/document-json.d.ts.map +1 -0
  32. package/dist/document-json.js +27 -0
  33. package/dist/document-json.js.map +1 -0
  34. package/dist/index.d.ts +4 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +4 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/interaction-script.d.ts +40 -0
  39. package/dist/interaction-script.d.ts.map +1 -0
  40. package/dist/interaction-script.js +104 -0
  41. package/dist/interaction-script.js.map +1 -0
  42. package/dist/numeric-options.d.ts +22 -0
  43. package/dist/numeric-options.d.ts.map +1 -0
  44. package/dist/numeric-options.js +45 -0
  45. package/dist/numeric-options.js.map +1 -0
  46. package/dist/optional-node-root.d.ts +10 -0
  47. package/dist/optional-node-root.d.ts.map +1 -0
  48. package/dist/optional-node-root.js +26 -0
  49. package/dist/optional-node-root.js.map +1 -0
  50. package/dist/package-assets.d.ts +8 -0
  51. package/dist/package-assets.d.ts.map +1 -0
  52. package/dist/package-assets.js +21 -0
  53. package/dist/package-assets.js.map +1 -0
  54. package/dist/predicates.d.ts +6 -0
  55. package/dist/predicates.d.ts.map +1 -0
  56. package/dist/predicates.js +6 -0
  57. package/dist/predicates.js.map +1 -0
  58. package/dist/rpc-client.d.ts +4 -0
  59. package/dist/rpc-client.d.ts.map +1 -0
  60. package/dist/rpc-client.js +15 -0
  61. package/dist/rpc-client.js.map +1 -0
  62. package/dist/runtime-env.d.ts +4 -0
  63. package/dist/runtime-env.d.ts.map +1 -0
  64. package/dist/runtime-env.js +31 -0
  65. package/dist/runtime-env.js.map +1 -0
  66. package/dist/telemetry.d.ts +38 -0
  67. package/dist/telemetry.d.ts.map +1 -0
  68. package/dist/telemetry.js +158 -0
  69. package/dist/telemetry.js.map +1 -0
  70. package/dist/trimHyphens.d.ts +3 -0
  71. package/dist/trimHyphens.d.ts.map +1 -0
  72. package/dist/trimHyphens.js +13 -0
  73. package/dist/trimHyphens.js.map +1 -0
  74. package/package.json +55 -4
  75. package/README.md +0 -3
@@ -0,0 +1,40 @@
1
+ export interface InteractionStep {
2
+ tool: string;
3
+ input: Record<string, unknown>;
4
+ }
5
+ export interface InteractionScript<Step extends InteractionStep> {
6
+ /** `add_track`, `ui_timeline_add_track`, and `ui_add_track` all normalize alike. */
7
+ normalizeToolName(name: string): string;
8
+ /** Parse a `--interact` argument, naming the offending step on bad input. */
9
+ parseInteractionScript(json: string): Step[];
10
+ }
11
+ /**
12
+ * @param prefix the domain's canonical tool prefix, e.g. `"ui_timeline_"`.
13
+ * @param exampleStep one `{"tool":...,"input":...}` step embedded in the
14
+ * "must be a JSON array" error message.
15
+ */
16
+ export declare function createInteractionScript<Step extends InteractionStep = InteractionStep>(prefix: string, exampleStep: string): InteractionScript<Step>;
17
+ export interface InteractionTool {
18
+ name: string;
19
+ /**
20
+ * HOLDOUT (anti-slop/no-unknown-returns): a bridge tool answers in the open
21
+ * tool-result domain.
22
+ */
23
+ execute: (args: Record<string, unknown>) => Promise<unknown>;
24
+ }
25
+ export interface InteractionRecord {
26
+ tool: string;
27
+ input: unknown;
28
+ ok: boolean;
29
+ result?: unknown;
30
+ error?: string;
31
+ }
32
+ /**
33
+ * Replay parsed steps against a bridge's tools. A failing or unknown tool is
34
+ * recorded and the session continues with the next step.
35
+ *
36
+ * @param noun how the domain names its tools in the unknown-tool error,
37
+ * e.g. `"sketch"` gives `No sketch tool named "…"`.
38
+ */
39
+ export declare function runInteractionSteps(steps: readonly InteractionStep[], tools: readonly InteractionTool[], noun: string, onLog?: (line: string) => void): Promise<InteractionRecord[]>;
40
+ //# sourceMappingURL=interaction-script.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interaction-script.d.ts","sourceRoot":"","sources":["../src/interaction-script.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,iBAAiB,CAAC,IAAI,SAAS,eAAe;IAC7D,oFAAoF;IACpF,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IACxC,6EAA6E;IAC7E,sBAAsB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,CAAC;CAC9C;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,SAAS,eAAe,GAAG,eAAe,EAC9C,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAwC9D;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,OAAO,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9D;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,KAAK,EAAE,SAAS,eAAe,EAAE,EACjC,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAC7B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CA6C9B"}
@@ -0,0 +1,104 @@
1
+ /**
2
+ * The `--interact` script engine shared by `timeline debug`, `sketch debug`,
3
+ * and `jsscript debug`. A step names one tool (as the bridge/browser knows
4
+ * it, or without its `ui_<domain>_` prefix) and the input to call it with —
5
+ * see each domain's `interactions.ts` for a worked example.
6
+ */
7
+ import { isNonBlankString, isRecord, isString } from "./predicates.js";
8
+ /**
9
+ * @param prefix the domain's canonical tool prefix, e.g. `"ui_timeline_"`.
10
+ * @param exampleStep one `{"tool":...,"input":...}` step embedded in the
11
+ * "must be a JSON array" error message.
12
+ */
13
+ export function createInteractionScript(prefix, exampleStep) {
14
+ function normalizeToolName(name) {
15
+ const trimmed = name.trim();
16
+ if (trimmed.startsWith(prefix))
17
+ return trimmed;
18
+ const bare = trimmed.startsWith("ui_")
19
+ ? trimmed.slice("ui_".length)
20
+ : trimmed;
21
+ return `${prefix}${bare}`;
22
+ }
23
+ function parseInteractionScript(json) {
24
+ let parsed;
25
+ try {
26
+ parsed = JSON.parse(json);
27
+ }
28
+ catch (e) {
29
+ throw new Error(`--interact is not valid JSON: ${e.message}`);
30
+ }
31
+ if (!Array.isArray(parsed)) {
32
+ throw new Error(`--interact must be a JSON array of steps, e.g. '[${exampleStep}]'`);
33
+ }
34
+ return parsed.map((step, index) => {
35
+ if (!isRecord(step) || !isNonBlankString(step.tool)) {
36
+ throw new Error(`--interact step ${index + 1} has no \`tool\` name.`);
37
+ }
38
+ const input = step.input ?? {};
39
+ if (!isRecord(input)) {
40
+ throw new Error(`--interact step ${index + 1}: \`input\` must be an object.`);
41
+ }
42
+ return {
43
+ tool: normalizeToolName(step.tool),
44
+ input: { ...input }
45
+ };
46
+ });
47
+ }
48
+ return { normalizeToolName, parseInteractionScript };
49
+ }
50
+ /**
51
+ * Replay parsed steps against a bridge's tools. A failing or unknown tool is
52
+ * recorded and the session continues with the next step.
53
+ *
54
+ * @param noun how the domain names its tools in the unknown-tool error,
55
+ * e.g. `"sketch"` gives `No sketch tool named "…"`.
56
+ */
57
+ export async function runInteractionSteps(steps, tools, noun, onLog) {
58
+ const byName = new Map(tools.map((t) => [t.name, t]));
59
+ const interactions = [];
60
+ for (const step of steps) {
61
+ const tool = byName.get(step.tool);
62
+ if (!tool) {
63
+ const known = [...byName.keys()].sort().join(", ");
64
+ interactions.push({
65
+ tool: step.tool,
66
+ input: step.input,
67
+ ok: false,
68
+ error: `No ${noun} tool named "${step.tool}". Available: ${known}.`
69
+ });
70
+ onLog?.(`✗ ${step.tool}: unknown tool`);
71
+ continue;
72
+ }
73
+ try {
74
+ const result = await tool.execute(step.input);
75
+ const ok = !(isRecord(result) && result.ok === false);
76
+ const error = !ok && isRecord(result) && isString(result.error)
77
+ ? result.error
78
+ : undefined;
79
+ const interaction = {
80
+ tool: step.tool,
81
+ input: step.input,
82
+ ok,
83
+ result
84
+ };
85
+ if (error !== undefined) {
86
+ interaction.error = error;
87
+ }
88
+ interactions.push(interaction);
89
+ onLog?.(`${ok ? "✓" : "✗"} ${step.tool}${error ? `: ${error}` : ""}`);
90
+ }
91
+ catch (e) {
92
+ const error = e instanceof Error ? e.message : String(e);
93
+ interactions.push({
94
+ tool: step.tool,
95
+ input: step.input,
96
+ ok: false,
97
+ error
98
+ });
99
+ onLog?.(`✗ ${step.tool}: ${error}`);
100
+ }
101
+ }
102
+ return interactions;
103
+ }
104
+ //# sourceMappingURL=interaction-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interaction-script.js","sourceRoot":"","sources":["../src/interaction-script.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAcvE;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAErC,MAAc,EAAE,WAAmB;IACnC,SAAS,iBAAiB,CAAC,IAAY;QACrC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,OAAO,CAAC;QAC/C,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,KAAK,CAAC;YACpC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,OAAO,CAAC;QACZ,OAAO,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED,SAAS,sBAAsB,CAAC,IAAY;QAC1C,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,iCAAkC,CAAW,CAAC,OAAO,EAAE,CAAC,CAAC;QAC3E,C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AG,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACxE,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,KAAK,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACzD,YAAY,CAAC,IAAI,CAAC;gBAChB,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,EAAE,EAAE,KAAK;gBACT,KAAK;aACN,CAAC,CAAC;YACH,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
@@ -0,0 +1,22 @@
1
+ interface NumericOptionConstraints {
2
+ /** Reject values below this bound (inclusive). */
3
+ min?: number;
4
+ /** Reject values above this bound (inclusive). */
5
+ max?: number;
6
+ /** Reject non-integers. */
7
+ integer?: boolean;
8
+ }
9
+ /**
10
+ * Parse a numeric CLI option, throwing a message that names the flag.
11
+ *
12
+ * @param value Raw option text as Commander handed it over.
13
+ * @param flag Flag name for the error message, e.g. `--min-success`.
14
+ */
15
+ export declare function parseNumericOption(value: string, flag: string, constraints?: NumericOptionConstraints): number;
16
+ /**
17
+ * Commander `argParser` form: `.option("--timeout <ms>", "…",
18
+ * numericOptionParser("--timeout", { integer: true, min: 0 }))`.
19
+ */
20
+ export declare function numericOptionParser(flag: string, constraints?: NumericOptionConstraints): (value: string) => number;
21
+ export {};
22
+ //# sourceMappingURL=numeric-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric-options.d.ts","sourceRoot":"","sources":["../src/numeric-options.ts"],"names":[],"mappings":"AAcA,UAAU,wBAAwB;IAChC,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,2BAA2B;IAC3B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,wBAA6B,GACzC,MAAM,CAuBR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,WAAW,GAAE,wBAA6B,GACzC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAE3B"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * One numeric-flag parser for every CLI command.
3
+ *
4
+ * `Number(opts.x)` fails open: `--min-success 0,8` becomes `NaN`, and every
5
+ * comparison against `NaN` is false — so a CI gate silently stops gating and a
6
+ * cost cap silently stops capping. A flag that cannot be read is an error, not
7
+ * a default, so this throws with the flag named.
8
+ *
9
+ * The error is Commander's `InvalidArgumentError`, so a parser used as an
10
+ * `argParser` prints one clean line instead of a stack trace; everywhere else
11
+ * it is an ordinary `Error` the command's own catch reports.
12
+ */
13
+ import { InvalidArgumentError } from "commander";
14
+ /**
15
+ * Parse a numeric CLI option, throwing a message that names the flag.
16
+ *
17
+ * @param value Raw option text as Commander handed it over.
18
+ * @param flag Flag name for the error message, e.g. `--min-success`.
19
+ */
20
+ export function parseNumericOption(value, flag, constraints = {}) {
21
+ const trimmed = value.trim();
22
+ const n = trimmed === "" ? Number.NaN : Number(trimmed);
23
+ const kind = constraints.integer ? "an integer" : "a number";
24
+ if (!Number.isFinite(n)) {
25
+ throw new InvalidArgumentError(`${flag} must be ${kind} (got "${value}")`);
26
+ }
27
+ if (constraints.integer && !Number.isInteger(n)) {
28
+ throw new InvalidArgumentError(`${flag} must be an integer (got "${value}")`);
29
+ }
30
+ if (constraints.min !== undefined && n < constraints.min) {
31
+ throw new InvalidArgumentError(`${flag} must be ${kind} >= ${constraints.min} (got "${value}")`);
32
+ }
33
+ if (constraints.max !== undefined && n > constraints.max) {
34
+ throw new InvalidArgumentError(`${flag} must be ${kind} <= ${constraints.max} (got "${value}")`);
35
+ }
36
+ return n;
37
+ }
38
+ /**
39
+ * Commander `argParser` form: `.option("--timeout <ms>", "…",
40
+ * numericOptionParser("--timeout", { integer: true, min: 0 }))`.
41
+ */
42
+ export function numericOptionParser(flag, constraints = {}) {
43
+ return (value) => parseNumericOption(value, flag, constraints);
44
+ }
45
+ //# sourceMappingURL=numeric-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"numeric-options.js","sourceRoot":"","sources":["../src/numeric-options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAWjD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAAa,EACb,IAAY,EACZ,WAAW,GAA6B,EAAE;IAE1C,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,MAAM,CAAC,GAAG,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,IAAI,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,oBAAoB,CAAC,GAAG,IAAI,YAAY,IAAI,UAAU,KAAK,IAAI,CAAC,CAAC;IAC7E,CAAC;IACD,IAAI,WAAW,CAAC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAChD,MAAM,IAAI,oBAAoB,CAC5B,GAAG,IAAI,6BAA6B,KAAK,IAAI,CAC9C,CAAC;IACJ,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAC5B,GAAG,IAAI,YAAY,IAAI,OAAO,WAAW,CAAC,GAAG,UAAU,KAAK,IAAI,CACjE,CAAC;IACJ,CAAC;IACD,IAAI,WAAW,CAAC,GAAG,KAAK,SAAS,IAAI,CAAC,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACzD,MAAM,IAAI,oBAAoB,CAC5B,GAAG,IAAI,YAAY,IAAI,OAAO,WAAW,CAAC,GAAG,UAAU,KAAK,IAAI,CACjE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAY,EACZ,WAAW,GAA6B,EAAE;IAE1C,OAAO,CAAC,KAAa,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,10 @@
1
+ /** The directory `npm install --prefix` runs in. */
2
+ export declare function optionalNodeRoot(): string;
3
+ /** The `node_modules` directory inside the optional-node root. */
4
+ export declare function optionalNodeModulesDir(): string;
5
+ /**
6
+ * Compatibility entry for callers that only need runtime path initialization.
7
+ * Managed paths are set even before installation. Explicit overrides win.
8
+ */
9
+ export declare function applyOptionalNodeModules(): void;
10
+ //# sourceMappingURL=optional-node-root.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional-node-root.d.ts","sourceRoot":"","sources":["../src/optional-node-root.ts"],"names":[],"mappings":"AASA,oDAAoD;AACpD,wBAAgB,gBAAgB,IAAI,MAAM,CAIzC;AAED,kEAAkE;AAClE,wBAAgB,sBAAsB,IAAI,MAAM,CAE/C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,IAAI,CAAuB"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * The CLI's optional-node root: `<data dir>/optional-node`, where
3
+ * `nodetool runtime add` installs heavy third-party libraries that the npm
4
+ * package does not ship. `importOptionalModule` falls back to its
5
+ * `node_modules` through NODETOOL_OPTIONAL_NODE_MODULES.
6
+ */
7
+ import { join } from "node:path";
8
+ import { applyRuntimeEnv, runtimeLocations } from "@nodetool-ai/config";
9
+ /** The directory `npm install --prefix` runs in. */
10
+ export function optionalNodeRoot() {
11
+ const root = runtimeLocations().optionalNodeRoot;
12
+ if (!root) {
13
+ throw new Error("This host does not manage npm runtime installs");
14
+ }
15
+ return root;
16
+ }
17
+ /** The `node_modules` directory inside the optional-node root. */
18
+ export function optionalNodeModulesDir() {
19
+ return join(optionalNodeRoot(), "node_modules");
20
+ }
21
+ /**
22
+ * Compatibility entry for callers that only need runtime path initialization.
23
+ * Managed paths are set even before installation. Explicit overrides win.
24
+ */
25
+ export function applyOptionalNodeModules() { applyRuntimeEnv(); }
26
+ //# sourceMappingURL=optional-node-root.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optional-node-root.js","sourceRoot":"","sources":["../src/optional-node-root.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAExE,oDAAoD;AACpD,MAAM,UAAU,gBAAgB;IAC9B,MAAM,IAAI,GAAG,gBAAgB,EAAE,CAAC,gBAAgB,CAAC;IACjD,IAAI,CAAC,IAAI,EAAE,CAAC;QAAC,MAAM,IAAI,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAAC,CAAC;IACjF,OAAO,IAAI,CAAC;AACd,CAAC;AAED,kEAAkE;AAClE,MAAM,UAAU,sBAAsB;IACpC,OAAO,IAAI,CAAC,gBAAgB,EAAE,EAAE,cAAc,CAAC,CAAC;AAClD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,wBAAwB,KAAW,eAAe,EAAE,CAAC,CAAC,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The shipped `package://` assets in a checkout, which the server serves from
3
+ * `packages/base-nodes/nodetool/assets`. The runtime reads that directory when
4
+ * `NODETOOL_PACKAGE_ASSETS_DIR` names it and otherwise asks a running server,
5
+ * so without it a run that reads a shipped input needs the server up.
6
+ */
7
+ export declare function checkoutPackageAssetsDir(): string | null;
8
+ //# sourceMappingURL=package-assets.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-assets.d.ts","sourceRoot":"","sources":["../src/package-assets.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,wBAAwB,IAAI,MAAM,GAAG,IAAI,CASxD"}
@@ -0,0 +1,21 @@
1
+ import { existsSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, resolve } from "node:path";
4
+ /**
5
+ * The shipped `package://` assets in a checkout, which the server serves from
6
+ * `packages/base-nodes/nodetool/assets`. The runtime reads that directory when
7
+ * `NODETOOL_PACKAGE_ASSETS_DIR` names it and otherwise asks a running server,
8
+ * so without it a run that reads a shipped input needs the server up.
9
+ */
10
+ export function checkoutPackageAssetsDir() {
11
+ try {
12
+ const entry = createRequire(import.meta.url).resolve("@nodetool-ai/base-nodes");
13
+ const dir = resolve(dirname(entry), "..", "nodetool", "assets");
14
+ return existsSync(dir) ? dir : null;
15
+ }
16
+ catch {
17
+ // Not installed beside the CLI: package assets resolve over HTTP.
18
+ return null;
19
+ }
20
+ }
21
+ //# sourceMappingURL=package-assets.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package-assets.js","sourceRoot":"","sources":["../src/package-assets.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB;IACtC,IAAI,CAAC;QACH,MAAM,KAAK,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,yBAAyB,CAAC,CAAC;QAChF,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;QAChE,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACtC,CAAC;IAAC,MAAM,CAAC;QACP,kEAAkE;QAClE,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The workspace's named type predicates, re-exported for the CLI's call sites.
3
+ * The definitions live in `@nodetool-ai/protocol`.
4
+ */
5
+ export { isBoolean, isFiniteNumber, isNonBlankString, isNonEmptyString, isNumber, isObjectLike, isPositiveFiniteNumber, isRecord, isString, isCallable as isFunctionValue } from "@nodetool-ai/protocol";
6
+ //# sourceMappingURL=predicates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.d.ts","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,sBAAsB,EACtB,QAAQ,EACR,QAAQ,EACR,UAAU,IAAI,eAAe,EAC9B,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * The workspace's named type predicates, re-exported for the CLI's call sites.
3
+ * The definitions live in `@nodetool-ai/protocol`.
4
+ */
5
+ export { isBoolean, isFiniteNumber, isNonBlankString, isNonEmptyString, isNumber, isObjectLike, isPositiveFiniteNumber, isRecord, isString, isCallable as isFunctionValue } from "@nodetool-ai/protocol";
6
+ //# sourceMappingURL=predicates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"predicates.js","sourceRoot":"","sources":["../src/predicates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACL,SAAS,EACT,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,YAAY,EACZ,sBAAsB,EACtB,QAAQ,EACR,QAAQ,EACR,UAAU,IAAI,eAAe,EAC9B,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { createTRPCUntypedClient } from "@trpc/client";
2
+ /** Share the existing tRPC transport while each domain validates its own response contract. */
3
+ export declare function createRpcClient(apiUrl: string): ReturnType<typeof createTRPCUntypedClient>;
4
+ //# sourceMappingURL=rpc-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client.d.ts","sourceRoot":"","sources":["../src/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAiB,MAAM,cAAc,CAAC;AAGtE,+FAA+F;AAC/F,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,GACb,UAAU,CAAC,OAAO,uBAAuB,CAAC,CAU5C"}
@@ -0,0 +1,15 @@
1
+ import { createTRPCUntypedClient, httpBatchLink } from "@trpc/client";
2
+ import { TRPC_MAX_BATCH_SIZE } from "@nodetool-ai/protocol";
3
+ /** Share the existing tRPC transport while each domain validates its own response contract. */
4
+ export function createRpcClient(apiUrl) {
5
+ return createTRPCUntypedClient({
6
+ links: [
7
+ httpBatchLink({
8
+ url: `${apiUrl}/trpc`,
9
+ maxItems: TRPC_MAX_BATCH_SIZE,
10
+ methodOverride: "POST"
11
+ })
12
+ ]
13
+ });
14
+ }
15
+ //# sourceMappingURL=rpc-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rpc-client.js","sourceRoot":"","sources":["../src/rpc-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAE5D,+FAA+F;AAC/F,MAAM,UAAU,eAAe,CAC7B,MAAc;IAEd,OAAO,uBAAuB,CAAC;QAC7B,KAAK,EAAE;YACL,aAAa,CAAC;gBACZ,GAAG,EAAE,GAAG,MAAM,OAAO;gBACrB,QAAQ,EAAE,mBAAmB;gBAC7B,cAAc,EAAE,MAAM;aACvB,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { type NodetoolHost } from "@nodetool-ai/config";
2
+ export declare function cliHostForPath(path: string): NodetoolHost;
3
+ export declare function initializeCliRuntime(entryUrl: string): void;
4
+ //# sourceMappingURL=runtime-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-env.d.ts","sourceRoot":"","sources":["../src/runtime-env.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmC,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAIzF,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,CAKzD;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAa3D"}
@@ -0,0 +1,31 @@
1
+ import { readFileSync, realpathSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ import { z } from "zod";
4
+ import { applyRuntimeEnv, isNodetoolHost } from "@nodetool-ai/config";
5
+ const cliManifestSchema = z.object({ version: z.string() });
6
+ export function cliHostForPath(path) {
7
+ const normalized = path.replaceAll("\\", "/");
8
+ if (normalized.split("/").includes("_npx")) {
9
+ return "npx";
10
+ }
11
+ if (normalized.endsWith(".ts") || /\/packages\/cli(?:-[a-z]+)?\/(?:src|dist)\//.test(normalized)) {
12
+ return "source";
13
+ }
14
+ return "cli";
15
+ }
16
+ export function initializeCliRuntime(entryUrl) {
17
+ if (process.env["NODETOOL_HOST"] === undefined) {
18
+ process.env["NODETOOL_HOST"] = cliHostForPath(realpathSync(fileURLToPath(entryUrl)));
19
+ }
20
+ else if (!isNodetoolHost(process.env["NODETOOL_HOST"])) {
21
+ throw new Error(`Unknown NODETOOL_HOST: ${process.env["NODETOOL_HOST"]}`);
22
+ }
23
+ if (process.env["NODETOOL_CLI_VERSION"] === undefined) {
24
+ const manifest = cliManifestSchema.safeParse(JSON.parse(readFileSync(new URL("../package.json", entryUrl), "utf8")));
25
+ if (manifest.success) {
26
+ process.env["NODETOOL_CLI_VERSION"] = manifest.data.version;
27
+ }
28
+ }
29
+ applyRuntimeEnv();
30
+ }
31
+ //# sourceMappingURL=runtime-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-env.js","sourceRoot":"","sources":["../src/runtime-env.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,cAAc,EAAqB,MAAM,qBAAqB,CAAC;AAEzF,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AAE5D,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IAC9C,IAAI,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;IAC7D,IAAI,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,6CAA6C,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAAC,OAAO,QAAQ,CAAC;IAAC,CAAC;IACtH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,QAAgB;IACnD,IAAI,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,KAAK,SAAS,EAAE,CAAC;QAC/C,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,cAAc,CAAC,YAAY,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IACvF,CAAC;SAAM,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,0BAA0B,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;IACD,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,KAAK,SAAS,EAAE,CAAC;QACtD,MAAM,QAAQ,GAAG,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,iBAAiB,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;QACrH,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC;QAC9D,CAAC;IACH,CAAC;IACD,eAAe,EAAE,CAAC;AACpB,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { type AnalyticsClient, type AnalyticsEvent, type AnalyticsTransport, type CommandCategory } from "@nodetool-ai/analytics";
2
+ type Env = Readonly<Record<string, string | undefined>>;
3
+ /** How long the CLI waits for a send after the command finished. */
4
+ export declare const CLI_FLUSH_BUDGET_MS = 1000;
5
+ /**
6
+ * Map a top-level command name to its category. Only the name commander
7
+ * matched is used, never `process.argv`, so no user value can reach it.
8
+ */
9
+ export declare function commandCategory(commandName: string | undefined): CommandCategory;
10
+ /**
11
+ * The ingestion URL. `NODETOOL_ANALYTICS_ENDPOINT` points a self-hosted or
12
+ * test install elsewhere; it only redirects events, it never enables them.
13
+ */
14
+ export declare function cliAnalyticsEndpoint(env: Env): string;
15
+ export interface CliTelemetryOptions {
16
+ env?: Env;
17
+ storePath?: string;
18
+ transport?: AnalyticsTransport;
19
+ platform?: NodeJS.Platform;
20
+ }
21
+ export declare function createCliAnalyticsClient(options?: CliTelemetryOptions): AnalyticsClient;
22
+ export interface CliTelemetrySession {
23
+ track(event: AnalyticsEvent): void;
24
+ /** Send what was recorded, waiting at most {@link CLI_FLUSH_BUDGET_MS}. */
25
+ finish(): Promise<void>;
26
+ }
27
+ /**
28
+ * Begin telemetry for one invocation. With consent absent or an env override
29
+ * set, every later call is a no-op and nothing is read beyond the consent
30
+ * file. Never throws.
31
+ */
32
+ export declare function startCliTelemetry(commandName: string | undefined, options?: CliTelemetryOptions): CliTelemetrySession;
33
+ /** Record an event on the current invocation, if telemetry is on. */
34
+ export declare function trackCliEvent(event: AnalyticsEvent): void;
35
+ /** Flush the current invocation's events. Call before `process.exit`. */
36
+ export declare function finishCliTelemetry(): Promise<void>;
37
+ export {};
38
+ //# sourceMappingURL=telemetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAcA,OAAO,EAOL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAMhC,KAAK,GAAG,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC;AAExD,oEAAoE;AACpE,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAoBzC;;;GAGG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,SAAS,GAAG,eAAe,CAOhF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAarD;AAED,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,EAAE,GAAG,CAAC;IACV,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAC/B,QAAQ,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC;CAC5B;AAED,wBAAgB,wBAAwB,CACtC,OAAO,GAAE,mBAAwB,GAChC,eAAe,CAajB;AAED,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;IACnC,2EAA2E;IAC3E,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB;AASD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,GAAE,mBAAwB,GAChC,mBAAmB,CA4CrB;AAED,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CAMzD;AAED,yEAAyE;AACzE,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,IAAI,CAAC,CAMxD"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * CLI product analytics: off unless the user ran `nodetool telemetry enable`.
3
+ *
4
+ * The CLI never prompts for consent, so scripts, CI, agents and `npx` runs
5
+ * behave the same whether or not anyone could answer. `NODETOOL_TELEMETRY=0`
6
+ * and `DO_NOT_TRACK=1` always win over stored consent, and no variable turns
7
+ * telemetry on. Events carry the top-level command category and buckets only:
8
+ * never arguments, paths, the working directory, environment variables or
9
+ * any output. Sending is bounded to about a second after the command has
10
+ * finished, never prints, and never changes the exit code.
11
+ *
12
+ * See docs/analytics.md.
13
+ */
14
+ import { createRequire } from "node:module";
15
+ import { COMMAND_CATEGORIES, DEFAULT_ANALYTICS_ENDPOINT, createAnalyticsClient, createFetchTransport, isAnalyticsDisabledByEnv, platformFromNode } from "@nodetool-ai/analytics";
16
+ import { createFileAnalyticsStore, defaultCliAnalyticsPath } from "@nodetool-ai/analytics/node";
17
+ /** How long the CLI waits for a send after the command finished. */
18
+ export const CLI_FLUSH_BUDGET_MS = 1_000;
19
+ const CLI_VERSION = createRequire(import.meta.url)("../package.json").version;
20
+ /** Top-level commands reported under a category other than their own name. */
21
+ const COMMAND_ALIASES = {
22
+ apps: "app",
23
+ generate: "run",
24
+ pack: "packs",
25
+ package: "packs",
26
+ runtime: "packs",
27
+ extension: "packs",
28
+ "js-script": "run",
29
+ jobs: "workflows",
30
+ runs: "workflows",
31
+ assets: "workflows"
32
+ };
33
+ /**
34
+ * Map a top-level command name to its category. Only the name commander
35
+ * matched is used, never `process.argv`, so no user value can reach it.
36
+ */
37
+ export function commandCategory(commandName) {
38
+ if (!commandName)
39
+ return "other";
40
+ const alias = COMMAND_ALIASES[commandName];
41
+ if (alias)
42
+ return alias;
43
+ return COMMAND_CATEGORIES.includes(commandName)
44
+ ? commandName
45
+ : "other";
46
+ }
47
+ /**
48
+ * The ingestion URL. `NODETOOL_ANALYTICS_ENDPOINT` points a self-hosted or
49
+ * test install elsewhere; it only redirects events, it never enables them.
50
+ */
51
+ export function cliAnalyticsEndpoint(env) {
52
+ const configured = env["NODETOOL_ANALYTICS_ENDPOINT"]?.trim();
53
+ if (!configured)
54
+ return DEFAULT_ANALYTICS_ENDPOINT;
55
+ try {
56
+ const url = new URL(configured);
57
+ const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
58
+ if (url.protocol === "https:" || (url.protocol === "http:" && local)) {
59
+ return url.toString();
60
+ }
61
+ }
62
+ catch {
63
+ // Fall through to the default.
64
+ }
65
+ return DEFAULT_ANALYTICS_ENDPOINT;
66
+ }
67
+ export function createCliAnalyticsClient(options = {}) {
68
+ const env = options.env ?? process.env;
69
+ return createAnalyticsClient({
70
+ clientType: "npm_cli",
71
+ appVersion: CLI_VERSION,
72
+ platform: platformFromNode(options.platform ?? process.platform),
73
+ store: createFileAnalyticsStore(options.storePath ?? defaultCliAnalyticsPath()),
74
+ transport: options.transport ??
75
+ createFetchTransport({ url: cliAnalyticsEndpoint(env), timeoutMs: CLI_FLUSH_BUDGET_MS }),
76
+ // The CLI sends once, after the command, instead of on a timer.
77
+ flushDelayMs: null
78
+ });
79
+ }
80
+ const NOOP_SESSION = {
81
+ track: () => undefined,
82
+ finish: async () => undefined
83
+ };
84
+ let active = NOOP_SESSION;
85
+ /**
86
+ * Begin telemetry for one invocation. With consent absent or an env override
87
+ * set, every later call is a no-op and nothing is read beyond the consent
88
+ * file. Never throws.
89
+ */
90
+ export function startCliTelemetry(commandName, options = {}) {
91
+ try {
92
+ const env = options.env ?? process.env;
93
+ if (isAnalyticsDisabledByEnv(env)) {
94
+ active = NOOP_SESSION;
95
+ return active;
96
+ }
97
+ // `telemetry status|inspect|enable|disable` manage consent; reporting
98
+ // them would send an event as a side effect of turning telemetry on.
99
+ if (commandName === "telemetry") {
100
+ active = NOOP_SESSION;
101
+ return active;
102
+ }
103
+ const client = createCliAnalyticsClient(options);
104
+ client.track({
105
+ event: "cli_started",
106
+ properties: { commandCategory: commandCategory(commandName) }
107
+ });
108
+ let finished = false;
109
+ active = {
110
+ track: (event) => client.track(event),
111
+ async finish() {
112
+ if (finished)
113
+ return;
114
+ finished = true;
115
+ let timer;
116
+ const budget = new Promise((resolve) => {
117
+ timer = setTimeout(resolve, CLI_FLUSH_BUDGET_MS);
118
+ timer.unref();
119
+ });
120
+ try {
121
+ await Promise.race([client.flush({ force: true }), budget]);
122
+ }
123
+ catch {
124
+ // Telemetry never affects the command.
125
+ }
126
+ finally {
127
+ if (timer)
128
+ clearTimeout(timer);
129
+ client.shutdown();
130
+ }
131
+ }
132
+ };
133
+ return active;
134
+ }
135
+ catch {
136
+ active = NOOP_SESSION;
137
+ return active;
138
+ }
139
+ }
140
+ /** Record an event on the current invocation, if telemetry is on. */
141
+ export function trackCliEvent(event) {
142
+ try {
143
+ active.track(event);
144
+ }
145
+ catch {
146
+ // Never surfaces.
147
+ }
148
+ }
149
+ /** Flush the current invocation's events. Call before `process.exit`. */
150
+ export async function finishCliTelemetry() {
151
+ try {
152
+ await active.finish();
153
+ }
154
+ catch {
155
+ // Never surfaces.
156
+ }
157
+ }
158
+ //# sourceMappingURL=telemetry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,kBAAkB,EAClB,0BAA0B,EAC1B,qBAAqB,EACrB,oBAAoB,EACpB,wBAAwB,EACxB,gBAAgB,EAKjB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACxB,MAAM,6BAA6B,CAAC;AAIrC,oEAAoE;AACpE,MAAM,CAAC,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAEzC,MAAM,WAAW,GACf,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,iBAAiB,CACjD,CAAC,OAAO,CAAC;AAEV,8EAA8E;AAC9E,MAAM,eAAe,GAA8C;IACjE,IAAI,EAAE,KAAK;IACX,QAAQ,EAAE,KAAK;IACf,IAAI,EAAE,OAAO;IACb,OAAO,EAAE,OAAO;IAChB,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,OAAO;IAClB,WAAW,EAAE,KAAK;IAClB,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,WAAW;IACjB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,WAA+B;IAC7D,IAAI,CAAC,WAAW;QAAE,OAAO,OAAO,CAAC;IACjC,MAAM,KAAK,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAC3C,IAAI,KAAK;QAAE,OAAO,KAAK,CAAC;IACxB,OAAQ,kBAAwC,CAAC,QAAQ,CAAC,WAAW,CAAC;QACpE,CAAC,CAAE,WAA+B;QAClC,CAAC,CAAC,OAAO,CAAC;AACd,CA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AAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;gBAC9D,CAAC;gBAAC,MAAM,CAAC;oBACP,uCAAuC;gBACzC,CAAC;wBAAS,CAAC;oBACT,IAAI,KAAK;wBAAE,YAAY,CAAC,KAAK,CAAC,CAAC;oBAC/B,MAAM,CAAC,QAAQ,EAAE,CAAC;gBACpB,CAAC;YACH,CAAC;SACF,CAAC;QACF,OAAO,MAAM,CAAC;IAChB,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,GAAG,YAAY,CAAC;QACtB,OAAO,MAAM,CAAC;IAChB,CAAC;AACH,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,aAAa,CAAC,KAAqB;IACjD,IAAI,CAAC;QACH,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC;AAED,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,kBAAkB;IACtC,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,MAAM,EAAE,CAAC;IACxB,CAAC;IAAC,MAAM,CAAC;QACP,kBAAkB;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Strip leading and trailing ASCII hyphens without rescanning the interior. */
2
+ export declare function trimHyphens(value: string): string;
3
+ //# sourceMappingURL=trimHyphens.d.ts.map