@reticlehq/server 2.12.0 → 2.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SKILL.md +67 -109
- package/dist/bridge/auth-failure-reason.d.ts +6 -2
- package/dist/bridge/auth-failure-reason.js +15 -8
- package/dist/bridge/bridge.d.ts +18 -1
- package/dist/bridge/bridge.js +247 -164
- package/dist/bridge/pairing-token.d.ts +5 -0
- package/dist/bridge/pairing-token.js +28 -0
- package/dist/bridge/protocol-skew.d.ts +37 -0
- package/dist/bridge/protocol-skew.js +45 -0
- package/dist/capsule/capsule-store.d.ts +6 -6
- package/dist/capsule/causal-summary.js +7 -2
- package/dist/cli/cli-doctor.js +31 -1
- package/dist/cli/cli-launch.d.ts +11 -1
- package/dist/cli/cli-launch.js +59 -10
- package/dist/cli/cli-parse.d.ts +15 -1
- package/dist/cli/cli-parse.js +212 -8
- package/dist/cli/cli-verify.d.ts +1 -0
- package/dist/cli/cli-verify.js +3 -2
- package/dist/cli/cloud-cli.js +428 -259
- package/dist/cli/cloud-keystore.d.ts +37 -0
- package/dist/cli/cloud-keystore.js +97 -0
- package/dist/cli/cloud-kit.d.ts +37 -0
- package/dist/cli/cloud-kit.js +121 -0
- package/dist/cli/cloud-login.d.ts +17 -0
- package/dist/cli/cloud-login.js +183 -0
- package/dist/cli/cloud-session.d.ts +48 -0
- package/dist/cli/cloud-session.js +53 -0
- package/dist/cli/config-discovery.js +1 -0
- package/dist/cli/daemon-start-options.d.ts +32 -0
- package/dist/cli/daemon-start-options.js +38 -0
- package/dist/cli/device-flow.d.ts +76 -0
- package/dist/cli/device-flow.js +56 -0
- package/dist/cli/doctor-rows.d.ts +9 -0
- package/dist/cli/doctor-rows.js +9 -0
- package/dist/cli/drive-attach.d.ts +13 -0
- package/dist/cli/drive-attach.js +18 -0
- package/dist/cli/drive-command.js +7 -3
- package/dist/cli/mcp-command.js +51 -20
- package/dist/cli/project-name.d.ts +30 -0
- package/dist/cli/project-name.js +44 -0
- package/dist/cli/status-next-action.d.ts +14 -0
- package/dist/cli/status-next-action.js +4 -4
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +134 -80
- package/dist/cloud/cloud-config.d.ts +22 -1
- package/dist/cloud/cloud-config.js +64 -5
- package/dist/cloud/cloud-sync.d.ts +5 -5
- package/dist/cloud/cloud-sync.js +33 -2
- package/dist/cloud/sync-cycle.d.ts +110 -0
- package/dist/cloud/sync-cycle.js +270 -0
- package/dist/cloud/sync-daemon.d.ts +69 -0
- package/dist/cloud/sync-daemon.js +260 -0
- package/dist/cloud/sync-disk.d.ts +9 -0
- package/dist/cloud/sync-disk.js +191 -0
- package/dist/cloud/sync-hash.d.ts +2 -0
- package/dist/cloud/sync-hash.js +35 -0
- package/dist/crawl/crawl-tools.js +5 -3
- package/dist/crawl/crawl.d.ts +3 -0
- package/dist/crawl/crawl.js +5 -0
- package/dist/daemon/daemon-resolve.d.ts +43 -0
- package/dist/daemon/daemon-resolve.js +69 -0
- package/dist/daemon/dev-servers.d.ts +15 -0
- package/dist/daemon/dev-servers.js +68 -0
- package/dist/daemon/wake-decision.d.ts +32 -0
- package/dist/daemon/wake-decision.js +38 -0
- package/dist/domain/domain-tools.js +2 -2
- package/dist/events/contradictions.d.ts +18 -0
- package/dist/events/contradictions.js +134 -21
- package/dist/events/declared.d.ts +7 -4
- package/dist/events/declared.js +15 -6
- package/dist/events/echo-mismatch.js +64 -14
- package/dist/events/event-filters.d.ts +8 -0
- package/dist/events/event-filters.js +19 -2
- package/dist/events/predicate-eval.js +53 -5
- package/dist/events/predicate-precheck.d.ts +8 -0
- package/dist/events/predicate-precheck.js +41 -0
- package/dist/events/predicate-route.d.ts +14 -0
- package/dist/events/predicate-route.js +36 -8
- package/dist/events/predicate.d.ts +5 -0
- package/dist/events/predicate.js +37 -5
- package/dist/events/split-text-miss.d.ts +30 -0
- package/dist/events/split-text-miss.js +44 -0
- package/dist/flows/flake.d.ts +6 -6
- package/dist/flows/flow-memory-consult.d.ts +55 -0
- package/dist/flows/flow-memory-consult.js +38 -0
- package/dist/flows/flow-replay-run.d.ts +18 -7
- package/dist/flows/flow-replay-run.js +239 -22
- package/dist/flows/flow-replay.js +11 -2
- package/dist/flows/flow-step-runners.d.ts +8 -0
- package/dist/flows/flow-step-runners.js +8 -2
- package/dist/flows/flow-store-for-session.d.ts +31 -0
- package/dist/flows/flow-store-for-session.js +33 -0
- package/dist/flows/flow-tools.js +58 -32
- package/dist/flows/flows.d.ts +8 -0
- package/dist/flows/flows.js +468 -2
- package/dist/flows/heal-run.js +5 -2
- package/dist/flows/predicate-to-expect.d.ts +17 -12
- package/dist/flows/predicate-to-expect.js +30 -12
- package/dist/flows/recordings.d.ts +13 -1
- package/dist/flows/recordings.js +17 -2
- package/dist/flows/replay.d.ts +22 -2
- package/dist/flows/replay.js +28 -2
- package/dist/flows/verify-change-tools.js +5 -2
- package/dist/honesty/blind-spots.d.ts +55 -2
- package/dist/honesty/blind-spots.js +63 -3
- package/dist/honesty/honesty.d.ts +24 -0
- package/dist/honesty/honesty.js +25 -1
- package/dist/honesty/instrumentation-gaps.d.ts +9 -0
- package/dist/honesty/instrumentation-gaps.js +29 -2
- package/dist/honesty/verified.d.ts +2 -1
- package/dist/honesty/verified.js +16 -1
- package/dist/http-server.js +12 -0
- package/dist/impact/impact-recorder.d.ts +31 -8
- package/dist/impact/impact-recorder.js +104 -21
- package/dist/impact/impact-store.d.ts +15 -1
- package/dist/impact/impact-store.js +43 -2
- package/dist/index.js +113 -7
- package/dist/init/agent-rules.d.ts +13 -6
- package/dist/init/agent-rules.js +23 -12
- package/dist/init/astro-patch.d.ts +16 -0
- package/dist/init/astro-patch.js +28 -0
- package/dist/init/capabilities.d.ts +4 -1
- package/dist/init/capabilities.js +22 -2
- package/dist/init/confirm.d.ts +31 -7
- package/dist/init/confirm.js +48 -8
- package/dist/init/cra.d.ts +20 -4
- package/dist/init/cra.js +57 -17
- package/dist/init/csp-check.js +17 -2
- package/dist/init/csp-doctor.d.ts +8 -1
- package/dist/init/csp-doctor.js +8 -3
- package/dist/init/dev-script.d.ts +3 -1
- package/dist/init/dev-script.js +8 -5
- package/dist/init/format-generated.d.ts +18 -0
- package/dist/init/format-generated.js +39 -0
- package/dist/init/install-hint.d.ts +9 -0
- package/dist/init/install-hint.js +29 -0
- package/dist/init/mcp-clients.d.ts +7 -0
- package/dist/init/mcp-clients.js +7 -0
- package/dist/init/mcp.d.ts +1 -1
- package/dist/init/mcp.js +1 -1
- package/dist/init/node-io.js +11 -1
- package/dist/init/plan-framework.js +81 -45
- package/dist/init/plan.d.ts +20 -7
- package/dist/init/plan.js +20 -45
- package/dist/init/preflight.d.ts +28 -0
- package/dist/init/preflight.js +38 -0
- package/dist/init/run.d.ts +32 -9
- package/dist/init/run.js +141 -119
- package/dist/init/slash-command.d.ts +1 -1
- package/dist/init/snippets.js +41 -25
- package/dist/init/vite-config.d.ts +1 -1
- package/dist/init/vite-config.js +39 -25
- package/dist/init/workspace-apps.d.ts +17 -10
- package/dist/init/workspace-apps.js +110 -0
- package/dist/input/network-mock-tools.js +3 -6
- package/dist/input/real-input.js +25 -5
- package/dist/input/scroll-tools.js +4 -6
- package/dist/input/viewport-tools.js +5 -4
- package/dist/intent/inline-intent.d.ts +10 -19
- package/dist/intent/inline-intent.js +91 -1
- package/dist/intent/intent-shard-store.d.ts +72 -0
- package/dist/intent/intent-shard-store.js +203 -0
- package/dist/intent/intent-shard.d.ts +411 -0
- package/dist/intent/intent-shard.js +176 -0
- package/dist/intent/intent-store.d.ts +12 -0
- package/dist/intent/intent-store.js +21 -0
- package/dist/intent/intent-subject.d.ts +45 -0
- package/dist/intent/intent-subject.js +177 -0
- package/dist/intent/intent-tools.js +65 -2
- package/dist/intent/open-intents.d.ts +21 -0
- package/dist/intent/open-intents.js +15 -0
- package/dist/license/license-env.d.ts +29 -0
- package/dist/license/license-env.js +148 -0
- package/dist/loopback-agent.d.ts +31 -0
- package/dist/loopback-agent.js +57 -0
- package/dist/mcp/attach-memory.d.ts +18 -2
- package/dist/mcp/attach-memory.js +50 -7
- package/dist/mcp/client-identity.d.ts +31 -0
- package/dist/mcp/client-identity.js +51 -0
- package/dist/mcp/mcp-post-transport.d.ts +26 -0
- package/dist/mcp/mcp-post-transport.js +109 -0
- package/dist/mcp/mcp-proxy.d.ts +2 -1
- package/dist/mcp/mcp-proxy.js +52 -62
- package/dist/mcp/mcp.js +7 -1
- package/dist/mcp/proxy-backoff.d.ts +11 -0
- package/dist/mcp/proxy-backoff.js +13 -0
- package/dist/mcp/proxy-daemon-probe.d.ts +1 -0
- package/dist/mcp/proxy-daemon-probe.js +7 -1
- package/dist/mcp/proxy-handshake.d.ts +23 -0
- package/dist/mcp/proxy-handshake.js +31 -0
- package/dist/mcp/tool-catalog-cache.d.ts +8 -0
- package/dist/mcp/tool-catalog-cache.js +12 -0
- package/dist/memory/memory-tools.d.ts +2 -0
- package/dist/memory/memory-tools.js +82 -0
- package/dist/memory/project-memory.d.ts +34 -0
- package/dist/memory/project-memory.js +96 -0
- package/dist/oracles/propose-consequences.js +12 -3
- package/dist/pool/browser-pool.d.ts +63 -4
- package/dist/pool/browser-pool.js +113 -4
- package/dist/pool/playwright-launcher.js +9 -0
- package/dist/project/project-tools.js +3 -3
- package/dist/project/reticle-dir.d.ts +15 -2
- package/dist/project/reticle-dir.js +21 -4
- package/dist/runs/run-store.d.ts +10 -0
- package/dist/runs/run-store.js +10 -0
- package/dist/runs/verification-sync.d.ts +0 -11
- package/dist/runs/verification-sync.js +22 -1
- package/dist/runs/verify-server.d.ts +8 -1
- package/dist/runs/verify-server.js +14 -2
- package/dist/session/command-timeout.d.ts +5 -2
- package/dist/session/command-timeout.js +5 -4
- package/dist/session/lease-visibility.d.ts +67 -0
- package/dist/session/lease-visibility.js +76 -0
- package/dist/session/no-session-diagnosis.d.ts +23 -0
- package/dist/session/no-session-diagnosis.js +58 -17
- package/dist/session/no-session-next-action.d.ts +7 -0
- package/dist/session/no-session-next-action.js +42 -3
- package/dist/session/no-session-watch.d.ts +10 -6
- package/dist/session/no-session-watch.js +51 -19
- package/dist/session/pending-commands.d.ts +11 -1
- package/dist/session/pending-commands.js +12 -2
- package/dist/session/resolve-within.d.ts +34 -0
- package/dist/session/resolve-within.js +53 -0
- package/dist/session/session-info.d.ts +18 -0
- package/dist/session/session-info.js +11 -0
- package/dist/session/session-manager.d.ts +14 -0
- package/dist/session/session-manager.js +61 -3
- package/dist/session/session-mirror.d.ts +16 -0
- package/dist/session/session-mirror.js +22 -0
- package/dist/session/session-recommendation.d.ts +19 -5
- package/dist/session/session-recommendation.js +25 -9
- package/dist/session/session-successor.js +36 -1
- package/dist/session/session-tools.js +2 -2
- package/dist/session/session.d.ts +22 -2
- package/dist/session/session.js +87 -7
- package/dist/session/wall-clock.d.ts +12 -0
- package/dist/session/wall-clock.js +14 -0
- package/dist/setup/agent-configs.d.ts +96 -0
- package/dist/setup/agent-configs.js +333 -0
- package/dist/setup/agent-io.d.ts +9 -0
- package/dist/setup/agent-io.js +16 -0
- package/dist/setup/agent-writer.d.ts +51 -0
- package/dist/setup/agent-writer.js +115 -0
- package/dist/setup/approval-migration.d.ts +47 -0
- package/dist/setup/approval-migration.js +68 -0
- package/dist/setup/auto-approve.d.ts +85 -0
- package/dist/setup/auto-approve.js +150 -0
- package/dist/setup/bridge-port.d.ts +15 -0
- package/dist/setup/bridge-port.js +24 -0
- package/dist/setup/desktop-shape.d.ts +57 -0
- package/dist/setup/desktop-shape.js +63 -0
- package/dist/setup/dev-server-wait.d.ts +68 -0
- package/dist/setup/dev-server-wait.js +67 -0
- package/dist/setup/drive-agent.d.ts +71 -0
- package/dist/setup/drive-agent.js +171 -0
- package/dist/setup/drive-plan.d.ts +68 -0
- package/dist/setup/drive-plan.js +130 -0
- package/dist/setup/ensure-daemon.d.ts +29 -0
- package/dist/setup/ensure-daemon.js +58 -0
- package/dist/setup/init-runtime.d.ts +47 -0
- package/dist/setup/init-runtime.js +160 -0
- package/dist/setup/interrupt.d.ts +25 -0
- package/dist/setup/interrupt.js +40 -0
- package/dist/setup/license-key.d.ts +39 -0
- package/dist/setup/license-key.js +72 -0
- package/dist/setup/listeners.d.ts +37 -0
- package/dist/setup/listeners.js +85 -0
- package/dist/setup/node-effects.d.ts +60 -0
- package/dist/setup/node-effects.js +210 -0
- package/dist/setup/page-probe.d.ts +39 -0
- package/dist/setup/page-probe.js +49 -0
- package/dist/setup/relaunch.d.ts +36 -0
- package/dist/setup/relaunch.js +57 -0
- package/dist/setup/remaining-steps.d.ts +19 -0
- package/dist/setup/remaining-steps.js +31 -0
- package/dist/setup/run-setup.d.ts +99 -0
- package/dist/setup/run-setup.js +203 -0
- package/dist/setup/session-pick.d.ts +47 -0
- package/dist/setup/session-pick.js +51 -0
- package/dist/setup/setup-command.d.ts +45 -0
- package/dist/setup/setup-command.js +199 -0
- package/dist/setup/setup-options.d.ts +74 -0
- package/dist/setup/setup-options.js +67 -0
- package/dist/setup/transcripts.d.ts +16 -0
- package/dist/setup/transcripts.js +43 -0
- package/dist/status-payload.d.ts +14 -1
- package/dist/status-payload.js +23 -1
- package/dist/telemetry/daemon-telemetry.d.ts +8 -1
- package/dist/telemetry/daemon-telemetry.js +52 -5
- package/dist/telemetry/error-class.js +1 -1
- package/dist/telemetry/feedback-context.d.ts +9 -1
- package/dist/telemetry/feedback-context.js +60 -29
- package/dist/telemetry/feedback-local.d.ts +15 -0
- package/dist/telemetry/feedback-local.js +56 -0
- package/dist/telemetry/feedback.d.ts +11 -0
- package/dist/telemetry/feedback.js +19 -6
- package/dist/telemetry/init-telemetry.d.ts +2 -0
- package/dist/telemetry/init-telemetry.js +2 -0
- package/dist/telemetry/install-source.d.ts +14 -0
- package/dist/telemetry/install-source.js +30 -0
- package/dist/telemetry/license-activation.d.ts +7 -1
- package/dist/telemetry/license-activation.js +9 -5
- package/dist/telemetry/mcp-connection.js +7 -0
- package/dist/telemetry/project-profile.d.ts +12 -1
- package/dist/telemetry/project-profile.js +11 -6
- package/dist/telemetry/proxy-telemetry.d.ts +3 -0
- package/dist/telemetry/proxy-telemetry.js +21 -0
- package/dist/telemetry/session-metrics.d.ts +12 -0
- package/dist/telemetry/session-metrics.js +35 -1
- package/dist/telemetry/telemetry.js +17 -2
- package/dist/telemetry/tool-refused.d.ts +3 -1
- package/dist/telemetry/tool-refused.js +34 -2
- package/dist/tools/act-capsule.d.ts +10 -0
- package/dist/tools/act-capsule.js +8 -2
- package/dist/tools/act-danger.d.ts +2 -1
- package/dist/tools/act-danger.js +11 -3
- package/dist/tools/act-observation.d.ts +41 -0
- package/dist/tools/act-observation.js +36 -0
- package/dist/tools/act-preflight.d.ts +20 -0
- package/dist/tools/act-preflight.js +98 -0
- package/dist/tools/act-sequence-retry.d.ts +45 -0
- package/dist/tools/act-sequence-retry.js +58 -0
- package/dist/tools/act-sequence-tool.d.ts +13 -0
- package/dist/tools/act-sequence-tool.js +135 -0
- package/dist/tools/act-target.d.ts +14 -0
- package/dist/tools/act-target.js +47 -0
- package/dist/tools/act-tools.d.ts +21 -1
- package/dist/tools/act-tools.js +100 -213
- package/dist/tools/assert-verdict.js +22 -16
- package/dist/tools/browser-tools.js +6 -2
- package/dist/tools/dynamic-tools.js +24 -5
- package/dist/tools/error-recovery.d.ts +1 -0
- package/dist/tools/error-recovery.js +8 -0
- package/dist/tools/invoke-tool.js +59 -9
- package/dist/tools/lease-tools.d.ts +30 -4
- package/dist/tools/lease-tools.js +169 -5
- package/dist/tools/merged-name-redirect.d.ts +13 -0
- package/dist/tools/merged-name-redirect.js +22 -0
- package/dist/tools/numeric-bounds.d.ts +100 -0
- package/dist/tools/numeric-bounds.js +125 -0
- package/dist/tools/observe-tools.js +47 -40
- package/dist/tools/read-tools.js +28 -7
- package/dist/tools/real-input-attempt.d.ts +10 -0
- package/dist/tools/real-input-attempt.js +59 -1
- package/dist/tools/reconcile-tools.js +4 -4
- package/dist/tools/tool-kit.d.ts +12 -0
- package/dist/tools/tool-kit.js +6 -1
- package/dist/tools/tool-names.d.ts +2 -0
- package/dist/tools/tool-names.js +2 -0
- package/dist/tools/tools-helpers.d.ts +19 -0
- package/dist/tools/tools-helpers.js +46 -0
- package/dist/tools/tools.d.ts +2 -0
- package/dist/tools/tools.js +56 -8
- package/dist/update/reticle-deps.d.ts +9 -0
- package/dist/update/reticle-deps.js +27 -0
- package/dist/update/sdk-sync.d.ts +1 -2
- package/dist/update/sdk-sync.js +1 -21
- package/dist/update/update-nudge.d.ts +18 -0
- package/dist/update/update-nudge.js +20 -0
- package/dist/version/peer-announce.js +4 -2
- package/dist/version/sdk-fix.d.ts +47 -0
- package/dist/version/sdk-fix.js +127 -0
- package/dist/version/version-nudge.d.ts +14 -0
- package/dist/version/version-nudge.js +21 -0
- package/dist/version/version-skew.d.ts +38 -3
- package/dist/version/version-skew.js +83 -7
- package/dist/visual/visual-store.d.ts +6 -6
- package/dist/visual/visual-store.js +18 -16
- package/dist/visual/visual-tools.js +57 -12
- package/docs/cli/doctor.mdx +1 -0
- package/docs/cli/serve.mdx +4 -2
- package/docs/cli.mdx +7 -3
- package/docs/desktop.mdx +1 -1
- package/docs/docs.json +1 -1
- package/docs/getting-started.md +19 -3
- package/docs/index.mdx +9 -6
- package/docs/install-agentic.mdx +38 -12
- package/docs/install-manual.mdx +1 -1
- package/docs/packages.mdx +1 -1
- package/docs/skill-file.mdx +3 -3
- package/docs/telemetry-contract.md +108 -4
- package/docs/tools-act-sequence.mdx +16 -0
- package/docs/usage.md +1 -1
- package/package.json +4 -3
- package/dist/init/cursor.d.ts +0 -24
- package/dist/init/cursor.js +0 -80
package/dist/cli/cloud-cli.js
CHANGED
|
@@ -1,28 +1,45 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Cloud subcommands for the `reticle` CLI — the user/agent door to
|
|
2
|
+
* Cloud subcommands for the `reticle` CLI — the user/agent door to the hosted service, folded into the ONE
|
|
3
3
|
* tool (was the standalone `reticle-cloud` bootstrap script). These are THIN clients over the `/v1` API:
|
|
4
4
|
* the moat is the server, not these verbs, and OSS reticle already ships the cloud-sync client — this just
|
|
5
5
|
* surfaces it. Creds live under `~/.reticle`: `session.json` (human token from `reticle login`) and
|
|
6
6
|
* `credentials.json` (per-project api keys from `reticle link`). The non-secret repo binding + sync policy
|
|
7
7
|
* is `<repo>/.reticle/cloud.json`. Auth for a command = `RETICLE_CLOUD_KEY` env (agent) OR the login token.
|
|
8
8
|
*/
|
|
9
|
-
import { mkdir, writeFile
|
|
10
|
-
import { NodePlatform } from '../platform.js';
|
|
11
|
-
import { spawn } from 'node:child_process';
|
|
9
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
12
10
|
import { setTimeout as sleep } from 'node:timers/promises';
|
|
13
11
|
import { homedir } from 'node:os';
|
|
14
|
-
import { join } from 'node:path';
|
|
12
|
+
import { basename, join } from 'node:path';
|
|
15
13
|
import { z } from 'zod';
|
|
16
14
|
import { createNodeFileSystem } from '../project/fs-port.js';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
15
|
+
import { CLOUD_LINK_FILE, resolveProjectCloud } from '../cloud/cloud-config.js';
|
|
16
|
+
import { applyCredential, findCredential } from './cloud-keystore.js';
|
|
17
|
+
import { defaultProjectFor } from './project-name.js';
|
|
18
|
+
import { RETICLE_CONFIG_BASENAME } from './cli-port.js';
|
|
19
|
+
import { normalizeUrl } from './cloud-session.js';
|
|
20
|
+
import { cmdLogin, cmdLogout } from './cloud-login.js';
|
|
21
|
+
import { api, baseUrl, bearer, CREDENTIALS_FILE, emit, err, flags, hint, home, readJson, readSession, readSessionFor, RETICLE_DIR, } from './cloud-kit.js';
|
|
22
|
+
import { describeSync, runSyncCycle } from '../cloud/sync-cycle.js';
|
|
23
|
+
import { diskSink, diskSource, readCloudIssues, readCloudState } from '../cloud/sync-disk.js';
|
|
24
|
+
/**
|
|
25
|
+
* Where `reticle login` dials when nothing says otherwise: the hosted service.
|
|
26
|
+
*
|
|
27
|
+
* This is the same origin as the dashboard — the API serves the built console — so there is one
|
|
28
|
+
* host for a user to know and one for us to configure.
|
|
29
|
+
*
|
|
30
|
+
* It used to be `http://localhost:8890`, which is correct for exactly one audience: whoever is
|
|
31
|
+
* developing the service itself. Every other user — the entire point of publishing the package —
|
|
32
|
+
* typed `reticle login` and got a connection refused against a port on their own machine, which
|
|
33
|
+
* reads as "the cloud is down", not "you are dialling the wrong host". Developing against a local
|
|
34
|
+
* API is now what needs saying out loud, via RETICLE_CLOUD_URL, because that is the rarer case.
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* One session file per host, so more than one environment can be logged in at once.
|
|
38
|
+
*
|
|
39
|
+
* `session.json` stays what it always was — the ACTIVE login, and the thing a bare command with no
|
|
40
|
+
* override resolves through. This directory is what makes staging and production hold at the same
|
|
41
|
+
* time instead of clobbering each other, which is the whole reason a single file was not enough.
|
|
42
|
+
*/
|
|
26
43
|
const CLOUD_COMMANDS = new Set([
|
|
27
44
|
'login',
|
|
28
45
|
'logout',
|
|
@@ -30,232 +47,98 @@ const CLOUD_COMMANDS = new Set([
|
|
|
30
47
|
'link',
|
|
31
48
|
'project',
|
|
32
49
|
'config',
|
|
50
|
+
'issues',
|
|
51
|
+
'memory',
|
|
33
52
|
'push',
|
|
53
|
+
'sync',
|
|
34
54
|
'runs',
|
|
35
55
|
'regression',
|
|
36
56
|
'share',
|
|
37
57
|
]);
|
|
38
58
|
export const isCloudCommand = (cmd) => cmd !== undefined && CLOUD_COMMANDS.has(cmd);
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
59
|
+
/** `reticle sync --watch` — keep cycling instead of exiting. */
|
|
60
|
+
const WATCH_FLAG = '--watch';
|
|
61
|
+
/**
|
|
62
|
+
* How often `--watch` cycles.
|
|
63
|
+
*
|
|
64
|
+
* A minute is chosen against what a cycle COSTS, not against how fresh anybody needs the dashboard:
|
|
65
|
+
* an unchanged session sends one small GET and nothing else, so a minute is cheap enough that nobody
|
|
66
|
+
* turns it off — and a sync people turn off is the only kind that actually loses data.
|
|
67
|
+
*/
|
|
68
|
+
const DEFAULT_SYNC_INTERVAL_MS = 60_000;
|
|
69
|
+
/**
|
|
70
|
+
* How a key is named out loud: enough to match it against the dashboard, never enough to use.
|
|
71
|
+
*
|
|
72
|
+
* The same shape the console shows (`displayPrefix`), so the two surfaces name one key identically
|
|
73
|
+
* and somebody can tell at a glance which row this repo is using.
|
|
74
|
+
*/
|
|
75
|
+
const KEY_HINT_CHARS = 16;
|
|
76
|
+
const keyHint = (key) => key.length <= KEY_HINT_CHARS ? key : `${key.slice(0, KEY_HINT_CHARS)}…`;
|
|
77
|
+
/**
|
|
78
|
+
* The api key this machine already holds for a project ON THIS CLOUD, if any.
|
|
79
|
+
*
|
|
80
|
+
* Two shapes, matching the resolver: `{ key, url }` is what `link` writes now and is only returned
|
|
81
|
+
* when the URL matches, and a bare string is the legacy shape with no URL to check. Without the URL
|
|
82
|
+
* check this would happily reuse a production key for a self-hosted link, because `link` names
|
|
83
|
+
* every project "default" and the two collide in one slot.
|
|
84
|
+
*/
|
|
85
|
+
const storedCredential = async (projectId, url, orgId) => findCredential(await readJson(join(home(), CREDENTIALS_FILE)), projectId, url, orgId);
|
|
86
|
+
/**
|
|
87
|
+
* What a key is good for, or undefined when the cloud will not accept it.
|
|
88
|
+
*
|
|
89
|
+
* Never throws: a revoked key, a rotated one and an unreachable cloud are all "cannot reuse this",
|
|
90
|
+
* and the caller's answer to every one of them is the same — mint a fresh one.
|
|
91
|
+
*/
|
|
92
|
+
const validateKey = async (url, key) => {
|
|
52
93
|
try {
|
|
53
|
-
return
|
|
94
|
+
return WhoamiSchema.parse(await api('GET', `${url}/v1/cloud/whoami`, key));
|
|
54
95
|
}
|
|
55
96
|
catch {
|
|
56
|
-
return
|
|
97
|
+
return undefined;
|
|
57
98
|
}
|
|
58
99
|
};
|
|
59
|
-
/** Parse `--flag value` pairs out of an argv tail. */
|
|
60
|
-
const flags = (argv) => {
|
|
61
|
-
const f = {};
|
|
62
|
-
for (let i = 0; i < argv.length; i += 1) {
|
|
63
|
-
const a = argv[i];
|
|
64
|
-
if (a !== undefined && a.startsWith('--') && i + 1 < argv.length) {
|
|
65
|
-
const v = argv[i + 1];
|
|
66
|
-
if (v !== undefined)
|
|
67
|
-
f[a.slice(2)] = v;
|
|
68
|
-
i += 1;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return f;
|
|
72
|
-
};
|
|
73
|
-
const SessionSchema = z.object({ url: z.string(), token: z.string(), orgName: z.string() });
|
|
74
|
-
const readSession = async () => {
|
|
75
|
-
const parsed = SessionSchema.safeParse(await readJson(join(home(), SESSION_FILE)));
|
|
76
|
-
return parsed.success ? parsed.data : null;
|
|
77
|
-
};
|
|
78
|
-
const baseUrl = (session) => {
|
|
79
|
-
const env = process.env['RETICLE_CLOUD_URL'];
|
|
80
|
-
if (env !== undefined && env.length > 0)
|
|
81
|
-
return env.replace(/\/+$/, '');
|
|
82
|
-
if (null !== session && session.url.length > 0)
|
|
83
|
-
return session.url;
|
|
84
|
-
// Falling back to the local dev default WITHOUT being told to: say so on stderr, so a fresh
|
|
85
|
-
// `reticle login` never silently dials localhost. Humans read the hint; agents parse stdout
|
|
86
|
-
// JSON and ignore stderr, so stdout stays machine-readable either way.
|
|
87
|
-
hint(`no RETICLE_CLOUD_URL set — dialling the local dev default ${DEFAULT_URL} (set it for a real deployment)`);
|
|
88
|
-
return DEFAULT_URL;
|
|
89
|
-
};
|
|
90
|
-
/** Bearer for a command: an explicit api key (agent) wins, else the human login token. */
|
|
91
|
-
const bearer = (session) => {
|
|
92
|
-
const key = process.env['RETICLE_CLOUD_KEY'];
|
|
93
|
-
if (key !== undefined && key.length > 0)
|
|
94
|
-
return key;
|
|
95
|
-
return session?.token ?? null;
|
|
96
|
-
};
|
|
97
|
-
/** One `/v1` call. Throws a friendly Error on a non-2xx so the command surfaces it and exits 1. */
|
|
98
|
-
const api = async (method, url, token, body) => {
|
|
99
|
-
const headers = {};
|
|
100
|
-
if (token !== null)
|
|
101
|
-
headers['authorization'] = `Bearer ${token}`;
|
|
102
|
-
if (body !== undefined)
|
|
103
|
-
headers['content-type'] = 'application/json';
|
|
104
|
-
const init = {
|
|
105
|
-
method,
|
|
106
|
-
headers,
|
|
107
|
-
};
|
|
108
|
-
if (body !== undefined)
|
|
109
|
-
init.body = JSON.stringify(body);
|
|
110
|
-
const res = await cloudFetch(url, init);
|
|
111
|
-
const text = await res.text();
|
|
112
|
-
let json = null;
|
|
113
|
-
if (text.length > 0) {
|
|
114
|
-
try {
|
|
115
|
-
json = JSON.parse(text);
|
|
116
|
-
}
|
|
117
|
-
catch {
|
|
118
|
-
throw new Error(`expected JSON from ${method} ${url} but got: ${text.slice(0, 120)}`);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (!res.ok) {
|
|
122
|
-
const parsed = z.object({ error: z.object({ message: z.string() }) }).safeParse(json);
|
|
123
|
-
throw new Error(parsed.success ? parsed.data.error.message : `${res.status} ${res.statusText}`);
|
|
124
|
-
}
|
|
125
|
-
return json;
|
|
126
|
-
};
|
|
127
|
-
const LoginSchema = z.object({ token: z.string(), org: z.object({ name: z.string() }) });
|
|
128
100
|
const KeySchema = z.object({ projectId: z.string(), projectName: z.string(), key: z.string() });
|
|
129
|
-
const WhoamiSchema = z.object({
|
|
101
|
+
const WhoamiSchema = z.object({
|
|
102
|
+
projectId: z.string(),
|
|
103
|
+
projectName: z.string(),
|
|
104
|
+
/**
|
|
105
|
+
* Which tenant the key belongs to. Optional for the same reason `dashboardUrl` is — an older
|
|
106
|
+
* cloud does not send it — and when it is missing a stored key cannot be proved to be ours, which
|
|
107
|
+
* is why the reuse path below mints instead of guessing.
|
|
108
|
+
*/
|
|
109
|
+
orgId: z.string().optional(),
|
|
110
|
+
/**
|
|
111
|
+
* Where this project's dashboard lives. Optional because an older cloud does not send it, and a
|
|
112
|
+
* CLI that refused to link against one would break the thing it is supposed to connect.
|
|
113
|
+
*/
|
|
114
|
+
dashboardUrl: z.string().optional(),
|
|
115
|
+
});
|
|
130
116
|
const CreatedProjectSchema = z.object({ projectId: z.string(), name: z.string() });
|
|
131
117
|
const ProjectsListSchema = z.object({
|
|
132
118
|
projects: z.array(z.object({ projectId: z.string(), name: z.string() })),
|
|
133
119
|
});
|
|
134
120
|
/** Resolve a --project value that may be a slug id OR a display name into the canonical projectId. */
|
|
135
|
-
const resolveProjectId = async (url, token, wanted) => {
|
|
136
|
-
const { projects } = ProjectsListSchema.parse(await api('GET', `${url}/v1/projects`, token));
|
|
137
|
-
const lc = wanted.toLowerCase();
|
|
138
|
-
const match = projects.find((p) => p.projectId === wanted || p.name.toLowerCase() === lc);
|
|
139
|
-
if (match === undefined)
|
|
140
|
-
throw new Error(`no project "${wanted}" — create it with \`reticle project create "${wanted}"\``);
|
|
141
|
-
return match.projectId;
|
|
142
|
-
};
|
|
143
121
|
/**
|
|
144
|
-
*
|
|
145
|
-
* ~/.reticle.
|
|
122
|
+
* The id for the project the caller named, creating it if it does not exist yet.
|
|
146
123
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
124
|
+
* It used to refuse — "create it with `reticle project create`" — which made naming a project a
|
|
125
|
+
* two-command bookkeeping ritual for the COMMON case: a first repo, whose project has of course not
|
|
126
|
+
* been created yet. That refusal is also the only reason the magic path existed: bare `link` binds
|
|
127
|
+
* to a project called `Default` precisely so nobody has to meet this error.
|
|
150
128
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* code out of a server log they may not even be tailing.
|
|
155
|
-
*/
|
|
156
|
-
const RequestCodeSchema = z.object({ devCode: z.string().optional() });
|
|
157
|
-
const DeviceStartSchema = z.object({
|
|
158
|
-
deviceCode: z.string(),
|
|
159
|
-
userCode: z.string(),
|
|
160
|
-
verificationUri: z.string(),
|
|
161
|
-
verificationUriComplete: z.string(),
|
|
162
|
-
interval: z.number(),
|
|
163
|
-
expiresAt: z.number(),
|
|
164
|
-
});
|
|
165
|
-
const DevicePollSchema = z.object({
|
|
166
|
-
status: z.string(),
|
|
167
|
-
token: z.string().optional(),
|
|
168
|
-
org: z.object({ name: z.string() }).optional(),
|
|
169
|
-
});
|
|
170
|
-
/** Best-effort open the approval page in the default browser; the printed URL is the headless fallback. */
|
|
171
|
-
const openBrowser = (target) => {
|
|
172
|
-
const cmd = NodePlatform.MACOS === process.platform
|
|
173
|
-
? 'open'
|
|
174
|
-
: NodePlatform.WINDOWS === process.platform
|
|
175
|
-
? 'cmd'
|
|
176
|
-
: 'xdg-open';
|
|
177
|
-
const args = NodePlatform.WINDOWS === process.platform ? ['/c', 'start', '', target] : [target];
|
|
178
|
-
try {
|
|
179
|
-
const child = spawn(cmd, args, { stdio: 'ignore', detached: true });
|
|
180
|
-
child.on('error', () => undefined);
|
|
181
|
-
child.unref();
|
|
182
|
-
}
|
|
183
|
-
catch {
|
|
184
|
-
/* no opener available — the user opens the printed URL manually */
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
/** Persist a session token under ~/.reticle and print the next step. Shared by both login paths. */
|
|
188
|
-
const writeSession = async (url, token, orgName) => {
|
|
189
|
-
await mkdir(home(), { recursive: true });
|
|
190
|
-
await writeFile(join(home(), SESSION_FILE), `${JSON.stringify({ url, token, orgName }, null, 2)}\n`);
|
|
191
|
-
emit({ loggedIn: orgName, session: join(home(), SESSION_FILE) });
|
|
192
|
-
hint('next: `reticle link` to bind this repo to your Default project (or `reticle project create <name>` first)');
|
|
193
|
-
};
|
|
194
|
-
/**
|
|
195
|
-
* Browser device flow — the DEFAULT `reticle login` (like `gh auth login`): fetch a device + user code,
|
|
196
|
-
* open the browser to approve, then poll until the user confirms. No email to type, no code to copy back.
|
|
129
|
+
* Creating is announced rather than silent. A tool that quietly invents a durable, billable object
|
|
130
|
+
* is its own surprise, and the whole point of this change is that the automatic path SAYS what it
|
|
131
|
+
* did.
|
|
197
132
|
*/
|
|
198
|
-
const
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if ('approved' === poll.status && poll.token !== undefined && poll.org !== undefined) {
|
|
208
|
-
await writeSession(url, poll.token, poll.org.name);
|
|
209
|
-
return 0;
|
|
210
|
-
}
|
|
211
|
-
if ('pending' === poll.status) {
|
|
212
|
-
if (Date.now() > started.expiresAt) {
|
|
213
|
-
err('device login expired — run `reticle login` again');
|
|
214
|
-
return 1;
|
|
215
|
-
}
|
|
216
|
-
continue;
|
|
217
|
-
}
|
|
218
|
-
err('denied' === poll.status
|
|
219
|
-
? 'device login was denied in the browser'
|
|
220
|
-
: 'device login expired — run `reticle login` again');
|
|
221
|
-
return 1;
|
|
222
|
-
}
|
|
223
|
-
};
|
|
224
|
-
/**
|
|
225
|
-
* `reticle login` — browser device flow by default; `--email <e>` (or a positional email) keeps the
|
|
226
|
-
* headless two-step code path for CI/servers where opening a browser makes no sense.
|
|
227
|
-
*/
|
|
228
|
-
const cmdLogin = async (argv) => {
|
|
229
|
-
const f = flags(argv);
|
|
230
|
-
const positional = argv[0] !== undefined && !argv[0].startsWith('--') ? argv[0] : undefined;
|
|
231
|
-
const email = f['email'] ?? positional;
|
|
232
|
-
if (email === undefined)
|
|
233
|
-
return cmdLoginDevice();
|
|
234
|
-
const org = f['org'];
|
|
235
|
-
const url = baseUrl(null);
|
|
236
|
-
let code = f['code'];
|
|
237
|
-
if (code === undefined) {
|
|
238
|
-
const requested = RequestCodeSchema.parse(await api('POST', `${url}/v1/auth/request-code`, null, {
|
|
239
|
-
email,
|
|
240
|
-
...(org !== undefined ? { orgName: org } : {}),
|
|
241
|
-
}));
|
|
242
|
-
// A real cloud mails the code and never echoes it; a local one cannot mail, so it hands it back.
|
|
243
|
-
if (requested.devCode === undefined) {
|
|
244
|
-
emit({ codeSent: true, to: email });
|
|
245
|
-
hint(`check your inbox, then: \`reticle login --email ${email} --code <the 6-digit code>\``);
|
|
246
|
-
return 0;
|
|
247
|
-
}
|
|
248
|
-
code = requested.devCode;
|
|
249
|
-
}
|
|
250
|
-
const parsed = LoginSchema.parse(await api('POST', `${url}/v1/auth/login`, null, { email, code }));
|
|
251
|
-
await writeSession(url, parsed.token, parsed.org.name);
|
|
252
|
-
return 0;
|
|
253
|
-
};
|
|
254
|
-
/** `reticle logout` — forget the cached session token (per-project keys under credentials.json stay). */
|
|
255
|
-
const cmdLogout = async () => {
|
|
256
|
-
await writeFile(join(home(), SESSION_FILE), '').catch(() => undefined);
|
|
257
|
-
emit({ loggedOut: true });
|
|
258
|
-
return 0;
|
|
133
|
+
const resolveProjectId = async (url, token, wanted) => {
|
|
134
|
+
const { projects } = ProjectsListSchema.parse(await api('GET', `${url}/v1/projects`, token));
|
|
135
|
+
const lc = wanted.toLowerCase();
|
|
136
|
+
const match = projects.find((p) => p.projectId === wanted || p.name.toLowerCase() === lc);
|
|
137
|
+
if (match !== undefined)
|
|
138
|
+
return match.projectId;
|
|
139
|
+
const created = CreatedProjectSchema.parse(await api('POST', `${url}/v1/projects`, token, { name: wanted }));
|
|
140
|
+
hint(`created project "${wanted}" (${created.projectId}) — it did not exist yet`);
|
|
141
|
+
return created.projectId;
|
|
259
142
|
};
|
|
260
143
|
/**
|
|
261
144
|
* `reticle whoami` — the one call an agent (or a confused human) makes to know its state: who am I logged
|
|
@@ -265,8 +148,25 @@ const cmdWhoami = async () => {
|
|
|
265
148
|
const session = await readSession();
|
|
266
149
|
const fs = createNodeFileSystem();
|
|
267
150
|
const cloud = await resolveProjectCloud(fs, join(process.cwd(), RETICLE_DIR), homedir(), process.env);
|
|
151
|
+
/*
|
|
152
|
+
* The sync half of "what is my state". Without it the honest answer to "why does the dashboard
|
|
153
|
+
* look old?" was to go and read a JSON file — and the two failure modes a person actually hits
|
|
154
|
+
* (nothing has synced yet, and the last attempt errored) looked identical from out here.
|
|
155
|
+
*/
|
|
156
|
+
const reticleRoot = join(process.cwd(), RETICLE_DIR);
|
|
157
|
+
const state = readCloudState(reticleRoot);
|
|
158
|
+
const decisions = Object.keys(readCloudIssues(reticleRoot).triage).length;
|
|
268
159
|
emit({
|
|
269
160
|
loggedInAs: session?.orgName ?? null,
|
|
161
|
+
sync: {
|
|
162
|
+
lastPushAt: state.lastPushAt ?? null,
|
|
163
|
+
lastPullAt: state.lastPullAt ?? null,
|
|
164
|
+
/** Present only when the machine is behind BECAUSE something failed, which is the useful case. */
|
|
165
|
+
...(state.lastError === undefined ? {} : { lastError: state.lastError }),
|
|
166
|
+
/** Decisions collected from the dashboard and readable locally. */
|
|
167
|
+
decisionsHeld: decisions,
|
|
168
|
+
neverSynced: state.lastPullAt === undefined,
|
|
169
|
+
},
|
|
270
170
|
repo: {
|
|
271
171
|
attached: cloud.config !== null,
|
|
272
172
|
projectId: cloud.projectId,
|
|
@@ -281,11 +181,16 @@ const cmdWhoami = async () => {
|
|
|
281
181
|
};
|
|
282
182
|
/** `reticle project ls` / `reticle project create <name>` — key- or session-authed. */
|
|
283
183
|
const cmdProject = async (argv) => {
|
|
284
|
-
const
|
|
184
|
+
const active = await readSession();
|
|
185
|
+
const url = baseUrl(active);
|
|
186
|
+
const session = await readSessionFor(url);
|
|
285
187
|
const token = bearer(session);
|
|
286
|
-
const url = baseUrl(session);
|
|
287
188
|
if (null === token) {
|
|
288
|
-
|
|
189
|
+
// Name BOTH hosts when there is a session for a different one. "Run reticle login" on its own is
|
|
190
|
+
// baffling to somebody who just did — the useful fact is that they logged in somewhere else.
|
|
191
|
+
err(null !== active && normalizeUrl(active.url) !== url
|
|
192
|
+
? `signed in to ${normalizeUrl(active.url)}, but this command targets ${url} — run \`reticle login --url ${url}\`, or set RETICLE_CLOUD_KEY`
|
|
193
|
+
: `not signed in to ${url} — run \`reticle login --url ${url}\`, or set RETICLE_CLOUD_KEY`);
|
|
289
194
|
return 2;
|
|
290
195
|
}
|
|
291
196
|
const sub = argv[0];
|
|
@@ -334,31 +239,128 @@ const cmdProject = async (argv) => {
|
|
|
334
239
|
*/
|
|
335
240
|
const cmdLink = async (argv) => {
|
|
336
241
|
const f = flags(argv);
|
|
337
|
-
const
|
|
338
|
-
|
|
242
|
+
const url = baseUrl(await readSession(), f['url']);
|
|
243
|
+
// Same rule as every other authed verb: the token is looked up by the host it will be sent to.
|
|
244
|
+
const session = await readSessionFor(url);
|
|
339
245
|
const envKey = process.env['RETICLE_CLOUD_KEY'];
|
|
246
|
+
/*
|
|
247
|
+
* Read the existing binding FIRST, because it decides which project a bare `link` targets.
|
|
248
|
+
* Re-running `link` is ordinary — rotating a key, repointing an environment — and it must land in
|
|
249
|
+
* the project this repo already reports to, or its history splits in two without saying so.
|
|
250
|
+
*/
|
|
251
|
+
const priorLink = await readJson(join(process.cwd(), RETICLE_DIR, CLOUD_LINK_FILE));
|
|
252
|
+
const priorProjectId = 'object' === typeof priorLink && priorLink !== null
|
|
253
|
+
? priorLink['projectId']
|
|
254
|
+
: undefined;
|
|
340
255
|
let projectId;
|
|
341
256
|
let projectName;
|
|
342
257
|
let key;
|
|
258
|
+
/**
|
|
259
|
+
* The tenant this binding belongs to, recorded so the credential can be filed and found per-org.
|
|
260
|
+
* Undefined against an older cloud, where the slot stays cloud+project as it always was.
|
|
261
|
+
*/
|
|
262
|
+
let orgId;
|
|
263
|
+
/** The key this machine already had for the slot, and whether it provably belongs to another tenant. */
|
|
264
|
+
let priorKey;
|
|
265
|
+
let priorIsForeign = false;
|
|
266
|
+
/*
|
|
267
|
+
* Where this project's dashboard lives. Asked of the cloud rather than derived from `url`: the API
|
|
268
|
+
* origin and the console origin are different hosts in every deployment that is not a laptop, so a
|
|
269
|
+
* link the CLI guessed would be wrong exactly where it matters.
|
|
270
|
+
*/
|
|
271
|
+
let dashboardUrl;
|
|
272
|
+
/** Whether the key was already on this machine — so the report can say so instead of "minted". */
|
|
273
|
+
let reusedKey = false;
|
|
274
|
+
// Tracked separately from the value: an OLDER cloud answers whoami without a dashboardUrl, and
|
|
275
|
+
// keying the fallback off the value would ask the same question twice every time.
|
|
276
|
+
let askedWhoami = false;
|
|
343
277
|
if (envKey !== undefined && envKey.length > 0) {
|
|
344
278
|
const who = WhoamiSchema.parse(await api('GET', `${url}/v1/cloud/whoami`, envKey));
|
|
345
279
|
projectId = who.projectId;
|
|
346
280
|
projectName = who.projectName;
|
|
281
|
+
dashboardUrl = who.dashboardUrl;
|
|
282
|
+
orgId = who.orgId;
|
|
283
|
+
askedWhoami = true;
|
|
347
284
|
key = envKey;
|
|
348
285
|
}
|
|
349
286
|
else if (session !== null) {
|
|
350
287
|
// --project accepts a slug id OR a display name; default when omitted. Resolve to the canonical id.
|
|
351
288
|
const wanted = f['project'];
|
|
289
|
+
/*
|
|
290
|
+
* A repo is named after itself, not "Default".
|
|
291
|
+
*
|
|
292
|
+
* Every repo used to bind to one project called "Default" — measured, two unrelated checkouts on
|
|
293
|
+
* one account merged their runs, issues and impact into a single bucket, and the dashboard's
|
|
294
|
+
* per-project view described nothing. It is also what let two TENANTS collide, since a
|
|
295
|
+
* credential slot built from a project id is only as distinct as the ids are.
|
|
296
|
+
*/
|
|
297
|
+
const fallback = defaultProjectFor(basename(process.cwd()), 'string' === typeof priorProjectId ? priorProjectId : undefined);
|
|
352
298
|
const targetId = wanted === undefined
|
|
353
|
-
?
|
|
299
|
+
? await resolveProjectId(url, session.token, fallback)
|
|
354
300
|
: await resolveProjectId(url, session.token, wanted);
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
301
|
+
/*
|
|
302
|
+
* Reuse the key this machine already holds for the project, rather than minting another.
|
|
303
|
+
*
|
|
304
|
+
* `link` was idempotent about the BINDING and not about the KEY: two runs against one project
|
|
305
|
+
* left two live `reticle-cli` keys on the account, each valid, neither identifiable to a repo.
|
|
306
|
+
* Agents retry — that is what agents do — so it accumulates silently until somebody has a key
|
|
307
|
+
* list they cannot reason about and revokes the wrong one. Measured: proving an unrelated fix
|
|
308
|
+
* with two `link` runs created exactly that.
|
|
309
|
+
*
|
|
310
|
+
* Validated before trusting, because a stored key can have been revoked or rotated from the
|
|
311
|
+
* dashboard and a stale credential must not strand the repo. The check is the whoami call the
|
|
312
|
+
* mint path already makes for `dashboardUrl`, so the common path costs no extra round trip —
|
|
313
|
+
* and a key that fails it is replaced rather than reported.
|
|
314
|
+
*/
|
|
315
|
+
const existing = await storedCredential(targetId, url, session.orgId);
|
|
316
|
+
const validated = existing === undefined ? undefined : await validateKey(url, existing);
|
|
317
|
+
/*
|
|
318
|
+
* A valid key is not the same as OUR key.
|
|
319
|
+
*
|
|
320
|
+
* `validateKey` only asks whether the cloud still accepts it, and a key belonging to another
|
|
321
|
+
* organisation on the same cloud passes that question perfectly. With every project named
|
|
322
|
+
* "default", the slot `<url>::default` was shared across tenants — so a brand-new workspace
|
|
323
|
+
* signing in on a machine that had linked a different account reused that account's key and
|
|
324
|
+
* would have pushed its runs into a stranger's dashboard. Measured, not hypothesised.
|
|
325
|
+
*
|
|
326
|
+
* So reuse now requires PROOF of a tenant match, and treats anything less as no match: an older
|
|
327
|
+
* cloud that omits `orgId`, or a session file written before we recorded one, both fall through
|
|
328
|
+
* to minting. Minting a second key is a tidiness problem; pushing to the wrong tenant is a
|
|
329
|
+
* disclosure, and only one of those is worth defaulting to.
|
|
330
|
+
*/
|
|
331
|
+
const sameTenant = validated !== undefined &&
|
|
332
|
+
session.orgId !== undefined &&
|
|
333
|
+
validated.orgId !== undefined &&
|
|
334
|
+
validated.orgId === session.orgId;
|
|
335
|
+
const reusable = sameTenant ? validated : undefined;
|
|
336
|
+
priorKey = existing;
|
|
337
|
+
// Provably somebody else's: it still works on this cloud AND whoami names a different org. A key
|
|
338
|
+
// that merely FAILED validation is our own revoked one, and overwriting that is the point.
|
|
339
|
+
priorIsForeign =
|
|
340
|
+
validated !== undefined &&
|
|
341
|
+
validated.orgId !== undefined &&
|
|
342
|
+
session.orgId !== undefined &&
|
|
343
|
+
validated.orgId !== session.orgId;
|
|
344
|
+
if (existing !== undefined && reusable !== undefined) {
|
|
345
|
+
projectId = reusable.projectId;
|
|
346
|
+
projectName = reusable.projectName;
|
|
347
|
+
dashboardUrl = reusable.dashboardUrl;
|
|
348
|
+
orgId = reusable.orgId;
|
|
349
|
+
askedWhoami = true;
|
|
350
|
+
key = existing;
|
|
351
|
+
reusedKey = true;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const minted = KeySchema.parse(await api('POST', `${url}/v1/keys`, session.token, {
|
|
355
|
+
name: 'reticle-cli',
|
|
356
|
+
projectId: targetId,
|
|
357
|
+
}));
|
|
358
|
+
projectId = minted.projectId;
|
|
359
|
+
projectName = minted.projectName;
|
|
360
|
+
key = minted.key;
|
|
361
|
+
// The key was minted WITH this session, so its tenant is this session's by construction.
|
|
362
|
+
orgId = session.orgId;
|
|
363
|
+
}
|
|
362
364
|
}
|
|
363
365
|
else {
|
|
364
366
|
err('run `reticle login` first, or set RETICLE_CLOUD_KEY to link with an existing key');
|
|
@@ -369,10 +371,28 @@ const cmdLink = async (argv) => {
|
|
|
369
371
|
const linkPath = join(reticleDir, CLOUD_LINK_FILE);
|
|
370
372
|
const prev = await readJson(linkPath);
|
|
371
373
|
const prevObj = 'object' === typeof prev && prev !== null ? prev : {};
|
|
374
|
+
// The minted-key path has not asked yet. Best-effort: a link that works is worth more than a link
|
|
375
|
+
// that also has a link in it, and an older cloud simply does not send one.
|
|
376
|
+
if (!askedWhoami) {
|
|
377
|
+
try {
|
|
378
|
+
const who = WhoamiSchema.parse(await api('GET', `${url}/v1/cloud/whoami`, key));
|
|
379
|
+
dashboardUrl = who.dashboardUrl;
|
|
380
|
+
// Only FILL IN a tenant we do not have. The session we minted with is the authority on which
|
|
381
|
+
// org this key belongs to; letting a later lookup overwrite it is how the answer drifts.
|
|
382
|
+
orgId = orgId ?? who.orgId;
|
|
383
|
+
}
|
|
384
|
+
catch {
|
|
385
|
+
// Older cloud, or a transient failure. The HUD shows its list without a link.
|
|
386
|
+
}
|
|
387
|
+
}
|
|
372
388
|
const cloudJson = {
|
|
373
389
|
projectId,
|
|
374
390
|
projectName,
|
|
391
|
+
// Recorded so the daemon resolves the credential in the ORG slot rather than the ambiguous
|
|
392
|
+
// cloud+project one, which two tenants on one cloud both answer to.
|
|
393
|
+
...(orgId === undefined ? {} : { orgId }),
|
|
375
394
|
url,
|
|
395
|
+
...(dashboardUrl === undefined ? {} : { dashboardUrl }),
|
|
376
396
|
sync: prevObj['sync'] ?? { runs: true, memory: true, flows: true },
|
|
377
397
|
verify: prevObj['verify'] ?? 'local',
|
|
378
398
|
};
|
|
@@ -380,11 +400,43 @@ const cmdLink = async (argv) => {
|
|
|
380
400
|
await mkdir(home(), { recursive: true });
|
|
381
401
|
const credPath = join(home(), CREDENTIALS_FILE);
|
|
382
402
|
const creds = (await readJson(credPath)) ?? {};
|
|
383
|
-
const credObj = 'object' === typeof creds && creds !== null ? creds : {};
|
|
384
|
-
credObj[projectId] = key;
|
|
403
|
+
const credObj = applyCredential('object' === typeof creds && creds !== null ? creds : {}, { projectId, url, key, orgId, priorKey, priorIsForeign });
|
|
385
404
|
await writeFile(credPath, `${JSON.stringify(credObj, null, 2)}\n`);
|
|
386
405
|
emit({ linked: projectName, projectId, cloudJson: linkPath, credentials: credPath });
|
|
406
|
+
/*
|
|
407
|
+
* Say what just happened, in the vocabulary of somebody who has used other tools.
|
|
408
|
+
*
|
|
409
|
+
* `link` mints the key and stores it for you, which is the product's whole edge — and it is
|
|
410
|
+
* invisible, which is its whole cost. A real report: somebody pasted a masked placeholder key
|
|
411
|
+
* into a `.env` because their mental model said "I must make a key and put it somewhere". One had
|
|
412
|
+
* already been minted and filed outside the repo. They did not need another step; they needed to
|
|
413
|
+
* be told the step had happened.
|
|
414
|
+
*
|
|
415
|
+
* The key is identified the way the dashboard identifies it — a prefix, never the secret — so
|
|
416
|
+
* this can be read aloud, pasted into an issue, or left in a terminal without leaking anything.
|
|
417
|
+
*/
|
|
418
|
+
hint(`bound this repo to project "${projectName}"`);
|
|
419
|
+
hint(reusedKey
|
|
420
|
+
? `reusing key ${keyHint(key)} — already stored in ${credPath}, not in your repo`
|
|
421
|
+
: `minted key ${keyHint(key)} — stored in ${credPath}, not in your repo`);
|
|
422
|
+
hint('to change it: `reticle link --project <other>`; to inspect: `reticle whoami`');
|
|
387
423
|
hint('linked ✓ runs auto-push on `reticle verify`; `reticle push` sends existing local runs; `reticle whoami` shows state');
|
|
424
|
+
/*
|
|
425
|
+
* A binding is not a connection.
|
|
426
|
+
*
|
|
427
|
+
* Without `.reticle.json` the app's bundle carries no projectId, so the daemon cannot attribute a
|
|
428
|
+
* session to this repo: its runs pool into whichever root the daemon itself was started in, and
|
|
429
|
+
* `sync` here reports "nothing to send" however much was actually recorded. Measured on this
|
|
430
|
+
* repo's bench app — two verdicts driven, then a sync that claimed there was nothing.
|
|
431
|
+
*
|
|
432
|
+
* Said AFTER the success line rather than refusing: the binding really was written and really is
|
|
433
|
+
* correct, and the missing half is one command away. Refusing would strand somebody who links
|
|
434
|
+
* before they install, which is a legitimate order to work in.
|
|
435
|
+
*/
|
|
436
|
+
if (!(await createNodeFileSystem().exists(join(process.cwd(), RETICLE_CONFIG_BASENAME)))) {
|
|
437
|
+
hint(`no ${RETICLE_CONFIG_BASENAME} here, so this app announces no project — its runs will not be ` +
|
|
438
|
+
'attributed to this binding. Run `reticle init` in the app, then restart the dev server.');
|
|
439
|
+
}
|
|
388
440
|
return 0;
|
|
389
441
|
};
|
|
390
442
|
/** `reticle config [--runs on|off] [--memory on|off] [--flows on|off] [--verify local|server]`. */
|
|
@@ -423,8 +475,17 @@ const cmdConfig = async (argv) => {
|
|
|
423
475
|
emit({ updated: linkPath, sync: cfg['sync'], verify: cfg['verify'] });
|
|
424
476
|
return 0;
|
|
425
477
|
};
|
|
426
|
-
/**
|
|
427
|
-
|
|
478
|
+
/**
|
|
479
|
+
* `reticle sync [--watch]` — one full cycle: send the difference, collect what came back.
|
|
480
|
+
*
|
|
481
|
+
* This replaced a `push` that re-uploaded every run artifact on every invocation. That was fine with
|
|
482
|
+
* three runs and absurd with three hundred, and it only ever went one way — so a bug somebody
|
|
483
|
+
* resolved on the dashboard stayed open on the laptop forever.
|
|
484
|
+
*
|
|
485
|
+
* The sync POLICY is applied here rather than inside the protocol: a project that has turned runs or
|
|
486
|
+
* flows off simply presents a source with nothing in it, and the cycle does not need to know why.
|
|
487
|
+
*/
|
|
488
|
+
const cmdSync = async (argv) => {
|
|
428
489
|
const fs = createNodeFileSystem();
|
|
429
490
|
const reticleRoot = join(process.cwd(), RETICLE_DIR);
|
|
430
491
|
const cloud = await resolveProjectCloud(fs, reticleRoot, homedir(), process.env);
|
|
@@ -432,29 +493,54 @@ const cmdPush = async () => {
|
|
|
432
493
|
err('cloud not attached here — run `reticle link` (or set RETICLE_CLOUD_URL/KEY)');
|
|
433
494
|
return 1;
|
|
434
495
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
496
|
+
const config = cloud.config;
|
|
497
|
+
const full = diskSource(reticleRoot);
|
|
498
|
+
const source = {
|
|
499
|
+
runs: () => (cloud.policy.runs ? full.runs() : []),
|
|
500
|
+
flows: () => (cloud.policy.flows ? full.flows() : []),
|
|
501
|
+
// `memory` is the project's cross-run history and the derived records that summarise it.
|
|
502
|
+
derived: (kind) => cloud.policy.memory ? full.derived(kind) : undefined,
|
|
503
|
+
};
|
|
504
|
+
const once = async () => {
|
|
505
|
+
const report = await runSyncCycle({
|
|
506
|
+
config,
|
|
507
|
+
source,
|
|
508
|
+
sink: diskSink(reticleRoot),
|
|
509
|
+
state: readCloudState(reticleRoot),
|
|
510
|
+
now: () => Date.now(),
|
|
511
|
+
request: async (url, init) => {
|
|
512
|
+
const res = await fetch(url, init);
|
|
513
|
+
return { status: res.status, text: await res.text() };
|
|
514
|
+
},
|
|
515
|
+
});
|
|
516
|
+
emit({
|
|
517
|
+
ok: report.ok,
|
|
518
|
+
project: cloud.projectId,
|
|
519
|
+
sent: {
|
|
520
|
+
runs: report.runsSent,
|
|
521
|
+
flows: report.flowsSent,
|
|
522
|
+
records: report.derivedSent,
|
|
523
|
+
...(report.runsRejected.length > 0 ? { rejected: report.runsRejected } : {}),
|
|
524
|
+
},
|
|
525
|
+
pulled: report.pulled,
|
|
526
|
+
...(report.morePending ? { morePending: true } : {}),
|
|
527
|
+
...(report.error === undefined ? {} : { error: report.error }),
|
|
528
|
+
});
|
|
529
|
+
hint(describeSync(report));
|
|
530
|
+
return report.ok ? 0 : 1;
|
|
531
|
+
};
|
|
532
|
+
const watch = argv.includes(WATCH_FLAG);
|
|
533
|
+
if (!watch)
|
|
534
|
+
return once();
|
|
535
|
+
const everyMs = Number(process.env['RETICLE_SYNC_INTERVAL_MS'] ?? DEFAULT_SYNC_INTERVAL_MS);
|
|
536
|
+
hint(`watching ${reticleRoot} — syncing every ${String(Math.round(everyMs / 1000))}s`);
|
|
537
|
+
for (;;) {
|
|
538
|
+
await once();
|
|
539
|
+
await sleep(everyMs);
|
|
452
540
|
}
|
|
453
|
-
emit({ pushed, failed, total: ids.length, project: cloud.projectId });
|
|
454
|
-
if (pushed > 0)
|
|
455
|
-
hint(`pushed ✓ see them in the dashboard Runs tab (${cloud.config.url})`);
|
|
456
|
-
return 0;
|
|
457
541
|
};
|
|
542
|
+
/** `reticle push` — the name people already type. One cycle, same as `reticle sync`. */
|
|
543
|
+
const cmdPush = async () => cmdSync([]);
|
|
458
544
|
/** Resolve THIS repo's linked cloud (url + project-scoped key). Throws a friendly error if not attached. */
|
|
459
545
|
const repoCloud = async () => {
|
|
460
546
|
const fs = createNodeFileSystem();
|
|
@@ -469,6 +555,81 @@ const cmdRuns = async () => {
|
|
|
469
555
|
emit(await api('GET', `${url}/v1/runs`, apiKey));
|
|
470
556
|
return 0;
|
|
471
557
|
};
|
|
558
|
+
/**
|
|
559
|
+
* `reticle issues [--fix <fingerprint>]` — the triage queue, where the agent can reach it.
|
|
560
|
+
*
|
|
561
|
+
* The dashboard is a place a PERSON looks. The defects it lists were found by an agent, are usually
|
|
562
|
+
* fixed by an agent, and every one of them carries the prompt that would fix it — so requiring a
|
|
563
|
+
* browser to read them puts a human copy-paste in the middle of a loop that has no other human step
|
|
564
|
+
* in it.
|
|
565
|
+
*
|
|
566
|
+
* `--fix <fingerprint>` prints that one issue's fix prompt as BARE TEXT on stdout, nothing else: no
|
|
567
|
+
* JSON envelope, no label, no trailing commentary. That is what makes it pipeable — `reticle issues
|
|
568
|
+
* --fix <fp> | pbcopy`, or straight into an agent's stdin. Anything wrapped around it would have to
|
|
569
|
+
* be stripped by every caller, and the ones that forgot would paste our prose into their codebase.
|
|
570
|
+
*/
|
|
571
|
+
const cmdIssues = async (argv) => {
|
|
572
|
+
const { url, apiKey } = await repoCloud();
|
|
573
|
+
const fixAt = argv.indexOf('--fix');
|
|
574
|
+
const wanted = -1 === fixAt ? undefined : argv[fixAt + 1];
|
|
575
|
+
if (fixAt !== -1 && wanted === undefined) {
|
|
576
|
+
err('usage: reticle issues --fix <fingerprint>');
|
|
577
|
+
return 2;
|
|
578
|
+
}
|
|
579
|
+
const body = await api('GET', `${url}/v1/issues`, apiKey);
|
|
580
|
+
if (wanted === undefined) {
|
|
581
|
+
emit(body);
|
|
582
|
+
return 0;
|
|
583
|
+
}
|
|
584
|
+
const parsed = z
|
|
585
|
+
.object({
|
|
586
|
+
issues: z.array(z.object({ fingerprint: z.string(), title: z.string(), fixPrompt: z.string().nullish() })),
|
|
587
|
+
})
|
|
588
|
+
.safeParse(body);
|
|
589
|
+
if (!parsed.success) {
|
|
590
|
+
err('the server did not return an issue list this build understands');
|
|
591
|
+
return 1;
|
|
592
|
+
}
|
|
593
|
+
const found = parsed.data.issues.find((i) => i.fingerprint === wanted);
|
|
594
|
+
if (found === undefined) {
|
|
595
|
+
err(`no issue with fingerprint '${wanted}' — run \`reticle issues\` to list them`);
|
|
596
|
+
return 2;
|
|
597
|
+
}
|
|
598
|
+
const prompt = found.fixPrompt;
|
|
599
|
+
if (prompt === undefined || null === prompt || 0 === prompt.length) {
|
|
600
|
+
// Silent on stdout, explicit on stderr: a caller piping this into an agent must get NOTHING
|
|
601
|
+
// rather than an apology, or the apology becomes the prompt.
|
|
602
|
+
err(`issue '${found.title}' carries no suggested fix — not every origin produces one`);
|
|
603
|
+
return 4;
|
|
604
|
+
}
|
|
605
|
+
process.stdout.write(`${prompt}\n`);
|
|
606
|
+
return 0;
|
|
607
|
+
};
|
|
608
|
+
/**
|
|
609
|
+
* `reticle memory [--subject <name>]` — what this project knows, where an agent can reach it.
|
|
610
|
+
*
|
|
611
|
+
* Shared memory only pays for itself if something READS it. An agent about to verify checkout should
|
|
612
|
+
* be able to ask what the team already knows about checkout before it starts, and it cannot open a
|
|
613
|
+
* browser to find out — so the knowledge has to arrive on stdout like everything else it consumes.
|
|
614
|
+
*
|
|
615
|
+
* Every call is recorded server-side as a consultation. That is the number which separates memory
|
|
616
|
+
* that is worth keeping from a wiki nobody opens, and it cannot be measured from the writing side.
|
|
617
|
+
*
|
|
618
|
+
* `--subject` narrows to one area, which is the call an agent should actually make: pulling the
|
|
619
|
+
* whole corpus to answer one question is the cost the sharded store was built to avoid.
|
|
620
|
+
*/
|
|
621
|
+
const cmdMemory = async (argv) => {
|
|
622
|
+
const { url, apiKey } = await repoCloud();
|
|
623
|
+
const at = argv.indexOf('--subject');
|
|
624
|
+
const subject = -1 === at ? undefined : argv[at + 1];
|
|
625
|
+
if (-1 !== at && subject === undefined) {
|
|
626
|
+
err('usage: reticle memory [--subject <name>]');
|
|
627
|
+
return 2;
|
|
628
|
+
}
|
|
629
|
+
const query = subject === undefined ? '' : `?subject=${encodeURIComponent(subject)}`;
|
|
630
|
+
emit(await api('GET', `${url}/v1/memory${query}`, apiKey));
|
|
631
|
+
return 0;
|
|
632
|
+
};
|
|
472
633
|
/** `reticle regression` — the CI gate: broken flows vs before. Exit 3 if any regressed (pipeline-friendly). */
|
|
473
634
|
const cmdRegression = async () => {
|
|
474
635
|
const { url, apiKey } = await repoCloud();
|
|
@@ -494,9 +655,11 @@ export const runCloudCommand = async (argv) => {
|
|
|
494
655
|
try {
|
|
495
656
|
switch (cmd) {
|
|
496
657
|
case 'login':
|
|
497
|
-
|
|
658
|
+
// The linker is passed in rather than imported by cloud-login: login ends by linking and
|
|
659
|
+
// link needs a session, so the cycle is broken at this one call site.
|
|
660
|
+
return await cmdLogin(rest, cmdLink);
|
|
498
661
|
case 'logout':
|
|
499
|
-
return await cmdLogout();
|
|
662
|
+
return await cmdLogout(rest);
|
|
500
663
|
case 'whoami':
|
|
501
664
|
return await cmdWhoami();
|
|
502
665
|
case 'project':
|
|
@@ -507,8 +670,14 @@ export const runCloudCommand = async (argv) => {
|
|
|
507
670
|
return await cmdConfig(rest);
|
|
508
671
|
case 'push':
|
|
509
672
|
return await cmdPush();
|
|
673
|
+
case 'sync':
|
|
674
|
+
return await cmdSync(rest);
|
|
510
675
|
case 'runs':
|
|
511
676
|
return await cmdRuns();
|
|
677
|
+
case 'issues':
|
|
678
|
+
return await cmdIssues(rest);
|
|
679
|
+
case 'memory':
|
|
680
|
+
return await cmdMemory(rest);
|
|
512
681
|
case 'regression':
|
|
513
682
|
return await cmdRegression();
|
|
514
683
|
case 'share':
|