@ory/argus 0.1.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 (80) hide show
  1. package/README.md +134 -0
  2. package/assets/commands/local-down.md +19 -0
  3. package/assets/commands/local-up.md +27 -0
  4. package/assets/skills/auth-setup/SKILL.md +279 -0
  5. package/assets/skills/local-dev/SKILL.md +206 -0
  6. package/assets/skills/login-flow/SKILL.md +383 -0
  7. package/assets/skills/social-login/SKILL.md +312 -0
  8. package/dist/agent-auth.d.ts +204 -0
  9. package/dist/agent-auth.js +553 -0
  10. package/dist/auth-gate.d.ts +71 -0
  11. package/dist/auth-gate.js +308 -0
  12. package/dist/auth-store.d.ts +75 -0
  13. package/dist/auth-store.js +261 -0
  14. package/dist/auth.d.ts +93 -0
  15. package/dist/auth.js +323 -0
  16. package/dist/cli.d.ts +73 -0
  17. package/dist/cli.js +484 -0
  18. package/dist/client.d.ts +158 -0
  19. package/dist/client.js +679 -0
  20. package/dist/config.d.ts +135 -0
  21. package/dist/config.js +344 -0
  22. package/dist/denial.d.ts +79 -0
  23. package/dist/denial.js +103 -0
  24. package/dist/dev.d.ts +95 -0
  25. package/dist/dev.js +514 -0
  26. package/dist/index.d.ts +20 -0
  27. package/dist/index.js +137 -0
  28. package/dist/local/cli.d.ts +12 -0
  29. package/dist/local/cli.js +95 -0
  30. package/dist/local/configs.d.ts +89 -0
  31. package/dist/local/configs.js +634 -0
  32. package/dist/local/health.d.ts +32 -0
  33. package/dist/local/health.js +65 -0
  34. package/dist/local/index.d.ts +6 -0
  35. package/dist/local/index.js +38 -0
  36. package/dist/local/jaeger-main.d.ts +13 -0
  37. package/dist/local/jaeger-main.js +85 -0
  38. package/dist/local/jaeger.d.ts +50 -0
  39. package/dist/local/jaeger.js +162 -0
  40. package/dist/local/main.d.ts +7 -0
  41. package/dist/local/main.js +14 -0
  42. package/dist/local/manager.d.ts +45 -0
  43. package/dist/local/manager.js +676 -0
  44. package/dist/local/seed.d.ts +71 -0
  45. package/dist/local/seed.js +237 -0
  46. package/dist/logger.d.ts +29 -0
  47. package/dist/logger.js +139 -0
  48. package/dist/mcp.d.ts +76 -0
  49. package/dist/mcp.js +122 -0
  50. package/dist/otel/exporter.d.ts +17 -0
  51. package/dist/otel/exporter.js +12 -0
  52. package/dist/otel/index.d.ts +2 -0
  53. package/dist/otel/index.js +8 -0
  54. package/dist/otel/otlp-http.d.ts +116 -0
  55. package/dist/otel/otlp-http.js +322 -0
  56. package/dist/registry/cli.d.ts +12 -0
  57. package/dist/registry/cli.js +76 -0
  58. package/dist/registry/config.d.ts +23 -0
  59. package/dist/registry/config.js +80 -0
  60. package/dist/registry/index.d.ts +3 -0
  61. package/dist/registry/index.js +21 -0
  62. package/dist/registry/main.d.ts +7 -0
  63. package/dist/registry/main.js +14 -0
  64. package/dist/registry/manager.d.ts +38 -0
  65. package/dist/registry/manager.js +674 -0
  66. package/dist/setup.d.ts +118 -0
  67. package/dist/setup.js +398 -0
  68. package/dist/skills.d.ts +78 -0
  69. package/dist/skills.js +264 -0
  70. package/dist/subject.d.ts +43 -0
  71. package/dist/subject.js +55 -0
  72. package/dist/tool-metadata.d.ts +41 -0
  73. package/dist/tool-metadata.js +127 -0
  74. package/dist/tracer.d.ts +172 -0
  75. package/dist/tracer.js +452 -0
  76. package/dist/types.d.ts +57 -0
  77. package/dist/types.js +3 -0
  78. package/dist/watch-sandbox.d.ts +9 -0
  79. package/dist/watch-sandbox.js +81 -0
  80. package/package.json +79 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /**
3
+ * Health-checking utilities for the local Ory development environment.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.checkAllServices = checkAllServices;
7
+ exports.waitForGateway = waitForGateway;
8
+ const configs_js_1 = require("./configs.js");
9
+ async function checkEndpoint(name, url) {
10
+ try {
11
+ const res = await fetch(url, { signal: AbortSignal.timeout(3000) });
12
+ if (res.ok) {
13
+ return { name, url, healthy: true };
14
+ }
15
+ return { name, url, healthy: false, error: `HTTP ${res.status}` };
16
+ }
17
+ catch (err) {
18
+ const msg = err instanceof Error ? err.message : String(err);
19
+ return { name, url, healthy: false, error: msg };
20
+ }
21
+ }
22
+ /**
23
+ * Check the health of all local Ory services.
24
+ *
25
+ * `gatewayUrl` overrides the gateway probe URL (used by the manager after
26
+ * a runtime gateway-mode fallback, where re-resolving via env var would
27
+ * give a stale path). When omitted, falls back to env-var resolution
28
+ * anchored at `projectRoot`.
29
+ */
30
+ async function checkAllServices(options = {}) {
31
+ const gateway = options.gatewayUrl ?? (0, configs_js_1.gatewayHealthUrl)();
32
+ const checks = [
33
+ checkEndpoint("Gateway", gateway),
34
+ checkEndpoint("Kratos", `http://localhost:${configs_js_1.KRATOS_PUBLIC_PORT}/health/ready`),
35
+ checkEndpoint("Keto", `http://localhost:${configs_js_1.KETO_READ_PORT}/health/ready`),
36
+ checkEndpoint("Hydra", `http://localhost:${configs_js_1.HYDRA_PUBLIC_PORT}/health/ready`),
37
+ checkEndpoint("Jaeger", `http://localhost:${configs_js_1.JAEGER_UI_PORT}/`),
38
+ ];
39
+ return Promise.all(checks);
40
+ }
41
+ /**
42
+ * Wait for the gateway to become healthy, polling at the given interval.
43
+ * Returns true if healthy within the timeout, false otherwise.
44
+ *
45
+ * `gatewayUrl` overrides the probe URL (see `checkAllServices`). Otherwise
46
+ * the URL is computed from env-var resolution anchored at `projectRoot`.
47
+ */
48
+ async function waitForGateway(timeoutMs = 120_000, intervalMs = 2000, options = {}) {
49
+ const deadline = Date.now() + timeoutMs;
50
+ const url = options.gatewayUrl ?? (0, configs_js_1.gatewayHealthUrl)();
51
+ while (Date.now() < deadline) {
52
+ try {
53
+ const res = await fetch(url, {
54
+ signal: AbortSignal.timeout(2000),
55
+ });
56
+ if (res.ok)
57
+ return true;
58
+ }
59
+ catch {
60
+ // Not ready yet
61
+ }
62
+ await new Promise((r) => setTimeout(r, intervalMs));
63
+ }
64
+ return false;
65
+ }
@@ -0,0 +1,6 @@
1
+ export { runLocalCommand } from "./cli.js";
2
+ export { localUp, localDown, localStatus, localSeed, localLogs, localReset, localEnv, localConfigure, ensureLocalOryStack, type EnsureLocalOryStackResult, } from "./manager.js";
3
+ export { checkAllServices, waitForGateway, type ServiceHealth } from "./health.js";
4
+ export { seedLocalEnvironment, type SeedResult } from "./seed.js";
5
+ export { GATEWAY_URL, GATEWAY_PORT, KRATOS_PUBLIC_PORT, KRATOS_ADMIN_PORT, KETO_READ_PORT, KETO_WRITE_PORT, HYDRA_PUBLIC_PORT, HYDRA_ADMIN_PORT, JAEGER_UI_PORT, JAEGER_OTLP_HTTP_PORT, JAEGER_UI_URL, JAEGER_OTLP_HTTP_URL, } from "./configs.js";
6
+ export { ensureDevJaeger, stopDevJaeger, DEV_JAEGER_CONTAINER, DEV_JAEGER_IMAGE, type EnsureDevJaegerResult, type StopDevJaegerResult, } from "./jaeger.js";
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEV_JAEGER_IMAGE = exports.DEV_JAEGER_CONTAINER = exports.stopDevJaeger = exports.ensureDevJaeger = exports.JAEGER_OTLP_HTTP_URL = exports.JAEGER_UI_URL = exports.JAEGER_OTLP_HTTP_PORT = exports.JAEGER_UI_PORT = exports.HYDRA_ADMIN_PORT = exports.HYDRA_PUBLIC_PORT = exports.KETO_WRITE_PORT = exports.KETO_READ_PORT = exports.KRATOS_ADMIN_PORT = exports.KRATOS_PUBLIC_PORT = exports.GATEWAY_PORT = exports.GATEWAY_URL = exports.seedLocalEnvironment = exports.waitForGateway = exports.checkAllServices = exports.ensureLocalOryStack = exports.localConfigure = exports.localEnv = exports.localReset = exports.localLogs = exports.localSeed = exports.localStatus = exports.localDown = exports.localUp = exports.runLocalCommand = void 0;
4
+ var cli_js_1 = require("./cli.js");
5
+ Object.defineProperty(exports, "runLocalCommand", { enumerable: true, get: function () { return cli_js_1.runLocalCommand; } });
6
+ var manager_js_1 = require("./manager.js");
7
+ Object.defineProperty(exports, "localUp", { enumerable: true, get: function () { return manager_js_1.localUp; } });
8
+ Object.defineProperty(exports, "localDown", { enumerable: true, get: function () { return manager_js_1.localDown; } });
9
+ Object.defineProperty(exports, "localStatus", { enumerable: true, get: function () { return manager_js_1.localStatus; } });
10
+ Object.defineProperty(exports, "localSeed", { enumerable: true, get: function () { return manager_js_1.localSeed; } });
11
+ Object.defineProperty(exports, "localLogs", { enumerable: true, get: function () { return manager_js_1.localLogs; } });
12
+ Object.defineProperty(exports, "localReset", { enumerable: true, get: function () { return manager_js_1.localReset; } });
13
+ Object.defineProperty(exports, "localEnv", { enumerable: true, get: function () { return manager_js_1.localEnv; } });
14
+ Object.defineProperty(exports, "localConfigure", { enumerable: true, get: function () { return manager_js_1.localConfigure; } });
15
+ Object.defineProperty(exports, "ensureLocalOryStack", { enumerable: true, get: function () { return manager_js_1.ensureLocalOryStack; } });
16
+ var health_js_1 = require("./health.js");
17
+ Object.defineProperty(exports, "checkAllServices", { enumerable: true, get: function () { return health_js_1.checkAllServices; } });
18
+ Object.defineProperty(exports, "waitForGateway", { enumerable: true, get: function () { return health_js_1.waitForGateway; } });
19
+ var seed_js_1 = require("./seed.js");
20
+ Object.defineProperty(exports, "seedLocalEnvironment", { enumerable: true, get: function () { return seed_js_1.seedLocalEnvironment; } });
21
+ var configs_js_1 = require("./configs.js");
22
+ Object.defineProperty(exports, "GATEWAY_URL", { enumerable: true, get: function () { return configs_js_1.GATEWAY_URL; } });
23
+ Object.defineProperty(exports, "GATEWAY_PORT", { enumerable: true, get: function () { return configs_js_1.GATEWAY_PORT; } });
24
+ Object.defineProperty(exports, "KRATOS_PUBLIC_PORT", { enumerable: true, get: function () { return configs_js_1.KRATOS_PUBLIC_PORT; } });
25
+ Object.defineProperty(exports, "KRATOS_ADMIN_PORT", { enumerable: true, get: function () { return configs_js_1.KRATOS_ADMIN_PORT; } });
26
+ Object.defineProperty(exports, "KETO_READ_PORT", { enumerable: true, get: function () { return configs_js_1.KETO_READ_PORT; } });
27
+ Object.defineProperty(exports, "KETO_WRITE_PORT", { enumerable: true, get: function () { return configs_js_1.KETO_WRITE_PORT; } });
28
+ Object.defineProperty(exports, "HYDRA_PUBLIC_PORT", { enumerable: true, get: function () { return configs_js_1.HYDRA_PUBLIC_PORT; } });
29
+ Object.defineProperty(exports, "HYDRA_ADMIN_PORT", { enumerable: true, get: function () { return configs_js_1.HYDRA_ADMIN_PORT; } });
30
+ Object.defineProperty(exports, "JAEGER_UI_PORT", { enumerable: true, get: function () { return configs_js_1.JAEGER_UI_PORT; } });
31
+ Object.defineProperty(exports, "JAEGER_OTLP_HTTP_PORT", { enumerable: true, get: function () { return configs_js_1.JAEGER_OTLP_HTTP_PORT; } });
32
+ Object.defineProperty(exports, "JAEGER_UI_URL", { enumerable: true, get: function () { return configs_js_1.JAEGER_UI_URL; } });
33
+ Object.defineProperty(exports, "JAEGER_OTLP_HTTP_URL", { enumerable: true, get: function () { return configs_js_1.JAEGER_OTLP_HTTP_URL; } });
34
+ var jaeger_js_1 = require("./jaeger.js");
35
+ Object.defineProperty(exports, "ensureDevJaeger", { enumerable: true, get: function () { return jaeger_js_1.ensureDevJaeger; } });
36
+ Object.defineProperty(exports, "stopDevJaeger", { enumerable: true, get: function () { return jaeger_js_1.stopDevJaeger; } });
37
+ Object.defineProperty(exports, "DEV_JAEGER_CONTAINER", { enumerable: true, get: function () { return jaeger_js_1.DEV_JAEGER_CONTAINER; } });
38
+ Object.defineProperty(exports, "DEV_JAEGER_IMAGE", { enumerable: true, get: function () { return jaeger_js_1.DEV_JAEGER_IMAGE; } });
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Standalone entry point for managing the dev-launcher Jaeger container.
4
+ *
5
+ * Used by root package.json scripts:
6
+ * pnpm jaeger:up → node packages/core/dist/local/jaeger-main.js up
7
+ * pnpm jaeger:down → node packages/core/dist/local/jaeger-main.js down
8
+ *
9
+ * The container started here (`ory-jaeger-dev`) is independent of the
10
+ * Compose-managed Jaeger that ships with `pnpm local:up` (`ory-jaeger`),
11
+ * so they cannot collide.
12
+ */
13
+ export {};
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Standalone entry point for managing the dev-launcher Jaeger container.
5
+ *
6
+ * Used by root package.json scripts:
7
+ * pnpm jaeger:up → node packages/core/dist/local/jaeger-main.js up
8
+ * pnpm jaeger:down → node packages/core/dist/local/jaeger-main.js down
9
+ *
10
+ * The container started here (`ory-jaeger-dev`) is independent of the
11
+ * Compose-managed Jaeger that ships with `pnpm local:up` (`ory-jaeger`),
12
+ * so they cannot collide.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const jaeger_js_1 = require("./jaeger.js");
16
+ async function main() {
17
+ const subcommand = process.argv[2];
18
+ switch (subcommand) {
19
+ case "up": {
20
+ const result = await (0, jaeger_js_1.ensureDevJaeger)();
21
+ switch (result.status) {
22
+ case "already-running":
23
+ console.log(`Jaeger is already reachable at ${result.endpoint} (UI: ${result.uiUrl}).`);
24
+ break;
25
+ case "started":
26
+ console.log(`Jaeger started in Docker. OTLP endpoint: ${result.endpoint}, UI: ${result.uiUrl}.`);
27
+ console.log("Use 'pnpm jaeger:down' to stop it.");
28
+ break;
29
+ case "skipped:no-docker":
30
+ console.error(`Could not start Jaeger: ${result.detail}`);
31
+ process.exit(1);
32
+ case "skipped:probe-failed":
33
+ console.error(`Jaeger did not become healthy: ${result.detail}`);
34
+ process.exit(1);
35
+ case "error":
36
+ console.error(`Jaeger failed to start: ${result.detail}`);
37
+ process.exit(1);
38
+ }
39
+ break;
40
+ }
41
+ case "down": {
42
+ const result = (0, jaeger_js_1.stopDevJaeger)();
43
+ switch (result.status) {
44
+ case "stopped":
45
+ console.log("Stopped the dev Jaeger container.");
46
+ break;
47
+ case "not-running":
48
+ console.log("No dev Jaeger container is running.");
49
+ break;
50
+ case "skipped:no-docker":
51
+ console.error(`Cannot stop Jaeger: ${result.detail}`);
52
+ process.exit(1);
53
+ case "error":
54
+ console.error(`Failed to stop Jaeger: ${result.detail}`);
55
+ process.exit(1);
56
+ }
57
+ break;
58
+ }
59
+ case "help":
60
+ case "--help":
61
+ case "-h":
62
+ case undefined:
63
+ console.log(`
64
+ ory-jaeger — Manage the standalone Jaeger container used by dev launchers
65
+
66
+ Usage:
67
+ pnpm jaeger:up Start a local Jaeger all-in-one container (UI on :16686, OTLP HTTP on :4318)
68
+ pnpm jaeger:down Stop and remove the dev Jaeger container
69
+
70
+ Dev launchers (pnpm dev:<harness>) call 'jaeger up' automatically when no
71
+ OTEL_EXPORTER_OTLP_ENDPOINT is set in the parent shell. Run these manually
72
+ if you want to inspect traces without launching a harness.
73
+
74
+ Requires Docker.
75
+ `);
76
+ break;
77
+ default:
78
+ console.error(`Unknown subcommand: ${subcommand}`);
79
+ process.exit(1);
80
+ }
81
+ }
82
+ main().catch((err) => {
83
+ console.error(err.message ?? err);
84
+ process.exit(1);
85
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Standalone Jaeger lifecycle for the dev launcher.
3
+ *
4
+ * Runs Jaeger all-in-one as a single Docker container (no Compose project)
5
+ * so `pnpm dev:<harness>` can ship traces to a local Jaeger UI without
6
+ * spinning up the rest of the local Ory stack.
7
+ *
8
+ * The container is named distinctly from the `local up` Jaeger container
9
+ * (`ory-jaeger`) so the two cannot collide. If `local up` is already running
10
+ * its Jaeger, the OTLP port is bound and `ensureDevJaeger` short-circuits via
11
+ * the reachability probe.
12
+ */
13
+ export declare const DEV_JAEGER_CONTAINER = "jaeger";
14
+ export declare const DEV_JAEGER_IMAGE = "jaegertracing/all-in-one:1";
15
+ export interface EnsureDevJaegerResult {
16
+ /** OTLP HTTP endpoint to use, or undefined when Jaeger is unavailable. */
17
+ endpoint?: string;
18
+ /** UI URL when Jaeger is available. */
19
+ uiUrl?: string;
20
+ /** Human-readable status — "running", "started", "skipped:no-docker", "skipped:port-in-use", "error". */
21
+ status: "already-running" | "started" | "skipped:no-docker" | "skipped:probe-failed" | "error";
22
+ /** Detail / error message for logging. */
23
+ detail?: string;
24
+ }
25
+ export interface StopDevJaegerResult {
26
+ status: "stopped" | "not-running" | "skipped:no-docker" | "error";
27
+ detail?: string;
28
+ }
29
+ /**
30
+ * Ensure a local Jaeger is reachable on the OTLP HTTP port.
31
+ *
32
+ * Order of operations:
33
+ * 1. Probe `localhost:4318` — return `already-running` when something
34
+ * already serves it (the `local up` Jaeger, a previous dev-launcher
35
+ * Jaeger, or any other OTLP collector the user has running).
36
+ * 2. If Docker is unavailable, return `skipped:no-docker`.
37
+ * 3. If our standalone container exists but is stopped, remove it so the
38
+ * `--rm` flag stays meaningful, then re-run.
39
+ * 4. `docker run` Jaeger all-in-one and wait for the OTLP port to come up.
40
+ */
41
+ export declare function ensureDevJaeger(opts?: {
42
+ startupTimeoutMs?: number;
43
+ }): Promise<EnsureDevJaegerResult>;
44
+ /**
45
+ * Stop the standalone dev Jaeger container.
46
+ *
47
+ * Idempotent: returns `not-running` when nothing matching is up. Does not
48
+ * touch the `local up` Jaeger (different container name).
49
+ */
50
+ export declare function stopDevJaeger(): StopDevJaegerResult;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ /**
3
+ * Standalone Jaeger lifecycle for the dev launcher.
4
+ *
5
+ * Runs Jaeger all-in-one as a single Docker container (no Compose project)
6
+ * so `pnpm dev:<harness>` can ship traces to a local Jaeger UI without
7
+ * spinning up the rest of the local Ory stack.
8
+ *
9
+ * The container is named distinctly from the `local up` Jaeger container
10
+ * (`ory-jaeger`) so the two cannot collide. If `local up` is already running
11
+ * its Jaeger, the OTLP port is bound and `ensureDevJaeger` short-circuits via
12
+ * the reachability probe.
13
+ */
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.DEV_JAEGER_IMAGE = exports.DEV_JAEGER_CONTAINER = void 0;
16
+ exports.ensureDevJaeger = ensureDevJaeger;
17
+ exports.stopDevJaeger = stopDevJaeger;
18
+ const node_child_process_1 = require("node:child_process");
19
+ const configs_js_1 = require("./configs.js");
20
+ exports.DEV_JAEGER_CONTAINER = "jaeger";
21
+ exports.DEV_JAEGER_IMAGE = "jaegertracing/all-in-one:1";
22
+ function dockerAvailable() {
23
+ const result = (0, node_child_process_1.spawnSync)("docker", ["info"], { stdio: "ignore" });
24
+ return result.status === 0;
25
+ }
26
+ async function isOtlpReachable(timeoutMs = 800) {
27
+ try {
28
+ const ctrl = new AbortController();
29
+ const timer = setTimeout(() => ctrl.abort(), timeoutMs);
30
+ try {
31
+ const res = await fetch(`${configs_js_1.JAEGER_OTLP_HTTP_URL}/v1/traces`, {
32
+ method: "GET",
33
+ signal: ctrl.signal,
34
+ });
35
+ return res.status >= 200 && res.status < 600;
36
+ }
37
+ finally {
38
+ clearTimeout(timer);
39
+ }
40
+ }
41
+ catch {
42
+ return false;
43
+ }
44
+ }
45
+ function inspectContainer(name) {
46
+ const result = (0, node_child_process_1.spawnSync)("docker", ["inspect", "--format", "{{.State.Running}}", name], { stdio: ["ignore", "pipe", "ignore"] });
47
+ if (result.status !== 0) {
48
+ return { exists: false, running: false };
49
+ }
50
+ const out = (result.stdout?.toString() ?? "").trim();
51
+ return { exists: true, running: out === "true" };
52
+ }
53
+ function startContainer() {
54
+ // Use --rm so the container is wiped on stop — no stale state between runs.
55
+ const args = [
56
+ "run",
57
+ "-d",
58
+ "--rm",
59
+ "--name",
60
+ exports.DEV_JAEGER_CONTAINER,
61
+ "-p",
62
+ `${configs_js_1.JAEGER_UI_PORT}:${configs_js_1.JAEGER_UI_PORT}`,
63
+ "-p",
64
+ `${configs_js_1.JAEGER_OTLP_HTTP_PORT}:${configs_js_1.JAEGER_OTLP_HTTP_PORT}`,
65
+ "-e",
66
+ "COLLECTOR_OTLP_ENABLED=true",
67
+ "-e",
68
+ "LOG_LEVEL=warn",
69
+ exports.DEV_JAEGER_IMAGE,
70
+ ];
71
+ const result = (0, node_child_process_1.spawnSync)("docker", args, { stdio: ["ignore", "ignore", "pipe"] });
72
+ if (result.status === 0)
73
+ return { ok: true };
74
+ const stderr = (result.stderr?.toString() ?? "").trim();
75
+ return { ok: false, detail: stderr || `docker run exited ${result.status}` };
76
+ }
77
+ async function waitUntilReachable(timeoutMs) {
78
+ const deadline = Date.now() + timeoutMs;
79
+ while (Date.now() < deadline) {
80
+ if (await isOtlpReachable(500))
81
+ return true;
82
+ await new Promise((r) => setTimeout(r, 250));
83
+ }
84
+ return false;
85
+ }
86
+ /**
87
+ * Ensure a local Jaeger is reachable on the OTLP HTTP port.
88
+ *
89
+ * Order of operations:
90
+ * 1. Probe `localhost:4318` — return `already-running` when something
91
+ * already serves it (the `local up` Jaeger, a previous dev-launcher
92
+ * Jaeger, or any other OTLP collector the user has running).
93
+ * 2. If Docker is unavailable, return `skipped:no-docker`.
94
+ * 3. If our standalone container exists but is stopped, remove it so the
95
+ * `--rm` flag stays meaningful, then re-run.
96
+ * 4. `docker run` Jaeger all-in-one and wait for the OTLP port to come up.
97
+ */
98
+ async function ensureDevJaeger(opts = {}) {
99
+ if (await isOtlpReachable()) {
100
+ return {
101
+ status: "already-running",
102
+ endpoint: configs_js_1.JAEGER_OTLP_HTTP_URL,
103
+ uiUrl: configs_js_1.JAEGER_UI_URL,
104
+ };
105
+ }
106
+ if (!dockerAvailable()) {
107
+ return {
108
+ status: "skipped:no-docker",
109
+ detail: "Docker is not running. Start Docker Desktop to auto-launch Jaeger.",
110
+ };
111
+ }
112
+ const state = inspectContainer(exports.DEV_JAEGER_CONTAINER);
113
+ if (state.exists && !state.running) {
114
+ // Stale --rm container could only exist if Docker died mid-run; clean it up.
115
+ (0, node_child_process_1.spawnSync)("docker", ["rm", "-f", exports.DEV_JAEGER_CONTAINER], { stdio: "ignore" });
116
+ }
117
+ const start = startContainer();
118
+ if (!start.ok) {
119
+ return { status: "error", detail: start.detail };
120
+ }
121
+ const ready = await waitUntilReachable(opts.startupTimeoutMs ?? 15_000);
122
+ if (!ready) {
123
+ return {
124
+ status: "skipped:probe-failed",
125
+ detail: "Jaeger container started but OTLP port did not respond in time.",
126
+ };
127
+ }
128
+ return {
129
+ status: "started",
130
+ endpoint: configs_js_1.JAEGER_OTLP_HTTP_URL,
131
+ uiUrl: configs_js_1.JAEGER_UI_URL,
132
+ };
133
+ }
134
+ /**
135
+ * Stop the standalone dev Jaeger container.
136
+ *
137
+ * Idempotent: returns `not-running` when nothing matching is up. Does not
138
+ * touch the `local up` Jaeger (different container name).
139
+ */
140
+ function stopDevJaeger() {
141
+ if (!dockerAvailable()) {
142
+ return {
143
+ status: "skipped:no-docker",
144
+ detail: "Docker is not running.",
145
+ };
146
+ }
147
+ const state = inspectContainer(exports.DEV_JAEGER_CONTAINER);
148
+ if (!state.exists) {
149
+ return { status: "not-running" };
150
+ }
151
+ const result = (0, node_child_process_1.spawnSync)("docker", ["rm", "-f", exports.DEV_JAEGER_CONTAINER], {
152
+ stdio: ["ignore", "ignore", "pipe"],
153
+ });
154
+ if (result.status === 0) {
155
+ return { status: "stopped" };
156
+ }
157
+ const stderr = (result.stderr?.toString() ?? "").trim();
158
+ return {
159
+ status: "error",
160
+ detail: stderr || `docker rm exited ${result.status}`,
161
+ };
162
+ }
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Standalone entry point for `local` commands.
4
+ *
5
+ * Used by root package.json scripts: node packages/core/dist/local/main.js <subcommand>
6
+ */
7
+ export {};
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * Standalone entry point for `local` commands.
5
+ *
6
+ * Used by root package.json scripts: node packages/core/dist/local/main.js <subcommand>
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ const cli_js_1 = require("./cli.js");
10
+ const args = process.argv.slice(2);
11
+ (0, cli_js_1.runLocalCommand)("ory-local", args).catch((err) => {
12
+ console.error(err.message ?? err);
13
+ process.exit(1);
14
+ });
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Local Ory environment manager.
3
+ *
4
+ * Manages the Docker Compose lifecycle for running Kratos, Keto, Hydra,
5
+ * and an API gateway locally. The gateway defaults to Ory Console Lite when
6
+ * its source tree is present at `<projectRoot>/../cloud/console/console`,
7
+ * and falls back to the bundled nginx routing layer otherwise.
8
+ * `ORY_CONSOLE_LITE_PATH` overrides the path explicitly.
9
+ *
10
+ * Runtime directory: .ory-dev/ory/ (relative to where the command is run,
11
+ * or the project root when invoked from a plugin CLI). Sibling of
12
+ * .ory-dev/registry/ owned by the local npm registry manager.
13
+ */
14
+ export interface EnsureLocalOryStackResult {
15
+ status: "already-running" | "started" | "skipped:no-docker" | "compose-failed" | "gateway-unhealthy" | "console-misconfigured";
16
+ /** Local Ory gateway URL. Set when status is `already-running` or `started`. */
17
+ gatewayUrl?: string;
18
+ /** Filesystem path to the compose project (for log hints). */
19
+ localDir: string;
20
+ /** Human-readable detail / error message for logging. */
21
+ detail?: string;
22
+ }
23
+ /**
24
+ * Bring up the local Ory stack and wait for the gateway to be healthy.
25
+ *
26
+ * Idempotent and fail-graceful: returns a typed result instead of exiting.
27
+ * If the gateway is already healthy the function short-circuits without
28
+ * touching Docker. When `quiet` is set, progress is logged to stderr only
29
+ * (suitable for the dev launcher); otherwise it prints to stdout in the
30
+ * format `localUp` historically used.
31
+ */
32
+ export declare function ensureLocalOryStack(opts?: {
33
+ quiet?: boolean;
34
+ localDir?: string;
35
+ }): Promise<EnsureLocalOryStackResult>;
36
+ export declare function localUp(opts?: {
37
+ seed?: boolean;
38
+ }): Promise<void>;
39
+ export declare function localDown(): Promise<void>;
40
+ export declare function localStatus(): Promise<void>;
41
+ export declare function localSeed(): Promise<void>;
42
+ export declare function localLogs(args: string[]): void;
43
+ export declare function localReset(): Promise<void>;
44
+ export declare function localEnv(): void;
45
+ export declare function localConfigure(): void;