@somewhere-cloud/cli 0.38.49 → 0.38.51

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 (142) hide show
  1. package/dist/commands/advisor.d.ts +9 -0
  2. package/dist/commands/ai.d.ts +2 -0
  3. package/dist/commands/api.d.ts +14 -0
  4. package/dist/commands/auth.d.ts +30 -0
  5. package/dist/commands/browser.d.ts +247 -0
  6. package/dist/commands/call.d.ts +22 -0
  7. package/dist/commands/catalog.d.ts +16 -0
  8. package/dist/commands/check.d.ts +114 -0
  9. package/dist/commands/claim.d.ts +5 -0
  10. package/dist/commands/cron.d.ts +14 -0
  11. package/dist/commands/db-rows.d.ts +2 -0
  12. package/dist/commands/db.d.ts +2 -0
  13. package/dist/commands/deploy.d.ts +235 -0
  14. package/dist/commands/dev.d.ts +171 -0
  15. package/dist/commands/docs.d.ts +85 -0
  16. package/dist/commands/email.d.ts +8 -0
  17. package/dist/commands/env.d.ts +2 -0
  18. package/dist/commands/errors.d.ts +2 -0
  19. package/dist/commands/feedback.d.ts +2 -0
  20. package/dist/commands/fs.d.ts +2 -0
  21. package/dist/commands/git.d.ts +2 -0
  22. package/dist/commands/grep.d.ts +2 -0
  23. package/dist/commands/hooks.d.ts +2 -0
  24. package/dist/commands/init.d.ts +17 -0
  25. package/dist/commands/link.d.ts +8 -0
  26. package/dist/commands/lint.d.ts +2 -0
  27. package/dist/commands/logs.d.ts +2 -0
  28. package/dist/commands/mcp.d.ts +4 -0
  29. package/dist/commands/open.d.ts +2 -0
  30. package/dist/commands/postgres.d.ts +2 -0
  31. package/dist/commands/project.d.ts +8 -0
  32. package/dist/commands/promote.d.ts +28 -0
  33. package/dist/commands/pull.d.ts +2 -0
  34. package/dist/commands/restore.d.ts +5 -0
  35. package/dist/commands/rollback.d.ts +21 -0
  36. package/dist/commands/run.d.ts +2 -0
  37. package/dist/commands/skills.d.ts +2 -0
  38. package/dist/commands/status.d.ts +27 -0
  39. package/dist/commands/support.d.ts +2 -0
  40. package/dist/commands/tasks.d.ts +2 -0
  41. package/dist/commands/test-users.d.ts +4 -0
  42. package/dist/commands/test.d.ts +2 -0
  43. package/dist/commands/test.js +74 -0
  44. package/dist/commands/test.js.map +1 -0
  45. package/dist/commands/typecheck.d.ts +9 -0
  46. package/dist/commands/update.d.ts +25 -0
  47. package/dist/commands/upgrade.d.ts +12 -0
  48. package/dist/commands/usage.d.ts +2 -0
  49. package/dist/commands/verify.d.ts +419 -0
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.js +2 -0
  52. package/dist/index.js.map +1 -1
  53. package/dist/lib/advisor-context.d.ts +20 -0
  54. package/dist/lib/advisor-runs.d.ts +26 -0
  55. package/dist/lib/agent-hooks.d.ts +74 -0
  56. package/dist/lib/allowed-origins.d.ts +11 -0
  57. package/dist/lib/auth.d.ts +12 -0
  58. package/dist/lib/base-files.d.ts +31 -0
  59. package/dist/lib/browser-actions.d.ts +106 -0
  60. package/dist/lib/browser-flow-preflight.d.ts +6 -0
  61. package/dist/lib/browser-refusal.d.ts +17 -0
  62. package/dist/lib/browser-run.d.ts +102 -0
  63. package/dist/lib/build-errors.d.ts +24 -0
  64. package/dist/lib/chrome.d.ts +66 -0
  65. package/dist/lib/claim-handoff.d.ts +11 -0
  66. package/dist/lib/client.d.ts +150 -0
  67. package/dist/lib/config.d.ts +125 -0
  68. package/dist/lib/declared-data.d.ts +50 -0
  69. package/dist/lib/deploy-check.d.ts +56 -0
  70. package/dist/lib/device-login.d.ts +41 -0
  71. package/dist/lib/device.d.ts +2 -0
  72. package/dist/lib/envfile-write.d.ts +17 -0
  73. package/dist/lib/files.d.ts +111 -0
  74. package/dist/lib/frontend-dev.d.ts +28 -0
  75. package/dist/lib/generic-lint.d.ts +9 -0
  76. package/dist/lib/help-summary.d.ts +2 -0
  77. package/dist/lib/http.d.ts +9 -0
  78. package/dist/lib/init-agent-guide.d.ts +13 -0
  79. package/dist/lib/init-feature-template.d.ts +8 -0
  80. package/dist/lib/init-features.d.ts +50 -0
  81. package/dist/lib/init-green-template.d.ts +2 -0
  82. package/dist/lib/init-install.d.ts +14 -0
  83. package/dist/lib/init-scaffold.d.ts +44 -0
  84. package/dist/lib/init-template.d.ts +2 -0
  85. package/dist/lib/init-test-template.d.ts +2 -0
  86. package/dist/lib/init-ui-kit.d.ts +8 -0
  87. package/dist/lib/last-run.d.ts +38 -0
  88. package/dist/lib/link-hint.d.ts +5 -0
  89. package/dist/lib/next-actions.d.ts +48 -0
  90. package/dist/lib/notify/index.d.ts +18 -0
  91. package/dist/lib/notify/providers/update.d.ts +45 -0
  92. package/dist/lib/notify/types.d.ts +25 -0
  93. package/dist/lib/open.d.ts +1 -0
  94. package/dist/lib/output.d.ts +61 -0
  95. package/dist/lib/platform-command.d.ts +6 -0
  96. package/dist/lib/platform-contract.d.ts +26 -0
  97. package/dist/lib/platform-tools.d.ts +77 -0
  98. package/dist/lib/playwright-fixtures.d.ts +19 -0
  99. package/dist/lib/playwright-fixtures.js +140 -0
  100. package/dist/lib/playwright-fixtures.js.map +1 -0
  101. package/dist/lib/post-live-render.d.ts +48 -0
  102. package/dist/lib/project-notices.d.ts +18 -0
  103. package/dist/lib/project-pin.d.ts +57 -0
  104. package/dist/lib/project-ref.d.ts +32 -0
  105. package/dist/lib/project-urls.d.ts +18 -0
  106. package/dist/lib/promote-handoff.d.ts +65 -0
  107. package/dist/lib/promote-outcome.d.ts +98 -0
  108. package/dist/lib/publish-surface.d.ts +8 -0
  109. package/dist/lib/repro-packet.d.ts +35 -0
  110. package/dist/lib/scaffold.d.ts +46 -0
  111. package/dist/lib/skills-pack.d.ts +81 -0
  112. package/dist/lib/skills-pack.generated.d.ts +2 -0
  113. package/dist/lib/source-lint.d.ts +42 -0
  114. package/dist/lib/spinner.d.ts +14 -0
  115. package/dist/lib/startup-notice.d.ts +23 -0
  116. package/dist/lib/surface-counts.d.ts +88 -0
  117. package/dist/lib/temp-auth.d.ts +53 -0
  118. package/dist/lib/terminal-text.d.ts +10 -0
  119. package/dist/lib/test-identities.d.ts +122 -0
  120. package/dist/lib/test-identities.js +1 -1
  121. package/dist/lib/test-identities.js.map +1 -1
  122. package/dist/lib/test-reporter.d.ts +13 -0
  123. package/dist/lib/test-reporter.js +28 -0
  124. package/dist/lib/test-reporter.js.map +1 -0
  125. package/dist/lib/typecheck-version.d.ts +1 -0
  126. package/dist/lib/typecheck.d.ts +136 -0
  127. package/dist/lib/update-security.d.ts +25 -0
  128. package/dist/lib/vendor/deploy-paths.d.ts +21 -0
  129. package/dist/lib/vendor/repro-guidance.d.ts +111 -0
  130. package/dist/lib/verify-keep.d.ts +92 -0
  131. package/dist/lib/verify-progress.d.ts +2 -0
  132. package/dist/lib/verify-report.d.ts +4 -0
  133. package/dist/lib/version.d.ts +1 -0
  134. package/dist/testing.d.ts +37 -0
  135. package/dist/testing.js +2 -0
  136. package/dist/testing.js.map +1 -1
  137. package/dist/types.d.ts +104 -0
  138. package/npm-shrinkwrap.json +48 -2
  139. package/package.json +14 -3
  140. package/runtime/PLATFORM-SOURCE.json +1 -1
  141. package/runtime/SOURCE-LINT-VENDOR.json +1 -1
  142. package/src/testing.ts +3 -0
@@ -0,0 +1,150 @@
1
+ import type { BodyInit, Response as UndiciResponse } from 'undici';
2
+ /** The /v1 API host. Override for staging/tests via SOMEWHERE_API_URL
3
+ * (mirrors SOMEWHERE_RUNNER_URL below); the value should include the /v1
4
+ * suffix or a host the route paths can hang off of. Exported so other
5
+ * modules that need the same base (e.g. lib/temp-auth.ts's unauthenticated
6
+ * PoW endpoints) reuse this one env-resolution instead of duplicating it. */
7
+ export declare const API_BASE_URL: string;
8
+ /** Budget for calls that run a real build server-side (npm install alone
9
+ * can take minutes): /deploy, /deploy/patch, pull/export. */
10
+ export declare const LONG_CALL_TIMEOUT_MS: number;
11
+ export declare class ApiClient {
12
+ /** Mutable: the refresh-on-401 path swaps in a fresh access key in place so
13
+ * the retry (and every later call on this instance) uses the new token. */
14
+ /** null: an unauthenticated client (no Authorization header, never a
15
+ * stored-login refresh), for the public anonymous-deploy routes. */
16
+ private token;
17
+ constructor(token: string | null);
18
+ private authHeader;
19
+ /** Run a one-off script against the project's live DEV bindings via the
20
+ * dedicated runner worker. Same auth + `{ ok, data }` envelope as call(), but
21
+ * rooted at RUNNER_BASE_URL instead of the /v1 API (see that constant for the
22
+ * loop-protection reason). Body: { project_id, code, timeout_ms?, include_env?, args? };
23
+ * resolves to { result, logs, duration_ms, error? }. */
24
+ callRunner<T = unknown>(body: unknown, opts?: {
25
+ timeoutMs?: number;
26
+ }): Promise<T>;
27
+ /** Run one handler from inline function source (`deploy-check --run`). Rooted
28
+ * at RUNNER_BASE_URL for the same loop-protection reason as callRunner: the
29
+ * /v1 API cannot dispatch a handler, only the runner can. Body: { project_id,
30
+ * functions, path, method, headers?, body?, timeout_ms? }. */
31
+ checkHandler<T = unknown>(body: unknown, opts?: {
32
+ timeoutMs?: number;
33
+ }): Promise<T>;
34
+ /** Authenticated API call. On a 401 API_KEY_EXPIRED — the short-lived
35
+ * cli-pair access key timed out — and with a stored refresh token, this
36
+ * swaps in a fresh access key via POST /v1/keys/cli-pair/refresh and
37
+ * retries ONCE, so a long-lived agent session never logs itself out
38
+ * (tsk_3642f3c4). Without a refresh token (older login flows) refreshAccessKey
39
+ * throws a clear SESSION_EXPIRED "run `somewhere login`" error rather than
40
+ * letting the opaque 401 propagate (tsk_8ba2113d). */
41
+ call<T = unknown>(method: string, path: string, body?: unknown, query?: Record<string, string | number | undefined>,
42
+ /** refresh: false checks THIS client's key only. The refresh path renews the
43
+ * stored login, which is a different credential from one being verified. */
44
+ opts?: {
45
+ timeoutMs?: number;
46
+ baseUrl?: string;
47
+ refresh?: false;
48
+ signal?: AbortSignal;
49
+ }): Promise<T>;
50
+ /** Authenticated request whose body and response remain streams. The body is
51
+ * supplied by a factory so a file can be reopened if an expired access key
52
+ * is refreshed and the request is retried. Stdin is deliberately marked
53
+ * non-replayable by callers: after refreshing, we fail with a clear rerun
54
+ * message instead of silently sending an empty second request. */
55
+ callStream(method: string, path: string, bodyFactory?: () => BodyInit, opts?: {
56
+ headers?: Record<string, string>;
57
+ timeoutMs?: number;
58
+ replayableBody?: boolean;
59
+ }): Promise<UndiciResponse>;
60
+ private requestStream;
61
+ /** Exchange the stored cli-pair refresh token for a fresh access key and
62
+ * persist both. Returns true if the access key was swapped in. Throws a
63
+ * clear SESSION_EXPIRED CliApiError ("run `somewhere login`") when it can't
64
+ * refresh — either there's no refresh token (old-format config) or the
65
+ * refresh token itself is expired/revoked — so the user is told the cause +
66
+ * the fix instead of seeing a bare expired-key 401. Returns false only for a
67
+ * malformed refresh response, where the caller surfaces the original
68
+ * API_KEY_EXPIRED. */
69
+ refreshAccessKey(timeoutMs?: number): Promise<boolean>;
70
+ private request;
71
+ /** Like call(), but returns the raw response TEXT instead of JSON-parsing it
72
+ * — for endpoints that legitimately return non-JSON (e.g. a SQL db dump). A
73
+ * 200 with a non-JSON body is NOT an error (audit #14 / tsk_30633bb3). Used
74
+ * by `somewhere api --raw`. call() is intentionally left untouched so every
75
+ * existing command keeps its exact behavior. */
76
+ callRaw(method: string, path: string, body?: unknown, opts?: {
77
+ timeoutMs?: number;
78
+ captureIncompleteBody?: true;
79
+ }): Promise<{
80
+ status: number;
81
+ ok: boolean;
82
+ body: string;
83
+ headers: Record<string, string>;
84
+ }>;
85
+ }
86
+ /**
87
+ * What the RESPONSE said about itself, as opposed to what the error said.
88
+ *
89
+ * Kept separate from `data` on purpose: `data` is the route's own payload,
90
+ * while these four come from the envelope every route shares — the two
91
+ * correlation ids the edge stamps, and the platform's explicit verdict on
92
+ * whether sending the same request again is safe.
93
+ */
94
+ export interface CliApiErrorMeta {
95
+ /** `X-Request-Id` — the edge ray. */
96
+ requestId?: string;
97
+ /** `X-Trace-Id` — what finds this request in the platform's own logs. */
98
+ traceId?: string;
99
+ /** The platform's own answer to "is retrying safe?". Absent means it did not say. */
100
+ retry?: boolean;
101
+ /** How long the platform asked us to wait first, when it said. */
102
+ retryAfterMs?: number;
103
+ /** Headers arrived but no complete response body was read; never an automatic retry. */
104
+ responseBodyIncomplete?: true;
105
+ /** NETWORK_ERROR only: the connection was never opened (refused, DNS
106
+ * failure, connect timeout), so no request reached the server. */
107
+ notSent?: true;
108
+ }
109
+ export declare class CliApiError extends Error {
110
+ readonly code: string;
111
+ readonly statusCode: number;
112
+ /** Structured payload some errors carry (e.g. BUILD_ERROR file/line/frame). */
113
+ readonly data?: Record<string, unknown> | undefined;
114
+ readonly hint?: string | undefined;
115
+ readonly meta: CliApiErrorMeta;
116
+ /** Original body-reader failure, retained only so raw command output stays unchanged. */
117
+ originalCause?: unknown;
118
+ constructor(code: string, message: string, statusCode: number,
119
+ /** Structured payload some errors carry (e.g. BUILD_ERROR file/line/frame). */
120
+ data?: Record<string, unknown> | undefined, hint?: string | undefined, meta?: CliApiErrorMeta);
121
+ }
122
+ /** Typed capture for interrupted bodies; headers alone never establish a mutation's outcome. */
123
+ export declare function incompleteResponseFailure(cause: unknown, status: number, header: (name: string) => string | null): CliApiError;
124
+ /**
125
+ * The message for a JSON error body carrying neither `error` nor `message`.
126
+ *
127
+ * `JSON.parse` succeeded and both fields were absent, so this is structured
128
+ * JSON of a shape the CLI does not know — not an HTML error page, which raises
129
+ * INVALID_RESPONSE and prints its first bytes. Rendering it as the bare string
130
+ * "Unknown error" threw away the only evidence there was (tsk_9c5ed7f8): show
131
+ * the status and the body, and let the caller add the correlation ids.
132
+ */
133
+ export declare function unclassifiedResponseMessage(status: number, body: string): string;
134
+ /**
135
+ * The one-line reference a developer can hand us to find this exact request.
136
+ * Empty when the response carried neither id (an old platform, or a failure
137
+ * that never reached one).
138
+ */
139
+ export declare function formatErrorReference(meta: CliApiErrorMeta | undefined): string | null;
140
+ /**
141
+ * A typed refusal: an HTTP answer that carries an error code (the platform's, or the
142
+ * CLI's own named login state such as SESSION_EXPIRED). Every formatter prints its code
143
+ * and message rather than guessing a cause (tsk_224b77a0): an out-of-date client told
144
+ * "token may be expired" goes to the wrong fix. Null for an untyped answer or no answer.
145
+ */
146
+ export declare function typedServerError(err: unknown): {
147
+ code: string;
148
+ message: string;
149
+ status: number;
150
+ } | null;
@@ -0,0 +1,125 @@
1
+ import type { CliConfig, ProjectConfig, ProjectDeployState, SourceBaseState } from '../types.js';
2
+ export declare function cliConfigDir(): string;
3
+ /** The login file path, for messages: `~/.somewhere/config.json` by default,
4
+ * the real path when SOMEWHERE_CONFIG_DIR is set. */
5
+ export declare function cliConfigPathForDisplay(): string;
6
+ /** Only a missing file means "not signed in". A file this process cannot
7
+ * read (a sandboxed agent shell is the usual case) or cannot parse is said
8
+ * out loud: read as "signed out", it refused deploys to the folder's own
9
+ * temporary project and invited a new sign-in over the existing one
10
+ * (tsk_b9900dbb). */
11
+ export declare function loadConfig(): CliConfig | null;
12
+ export declare function saveConfig(config: CliConfig): void;
13
+ export declare function clearConfig(): void;
14
+ /**
15
+ * A temporary-workspace credential held BESIDE a real login.
16
+ *
17
+ * `--temporary` means temporary whatever the login state (pfb_9bbc936e5001),
18
+ * so a signed-in developer can ship a throwaway app without being switched to
19
+ * their account. Their real credential has to survive that, which is the whole
20
+ * reason this is a separate file: config.json keeps the account login
21
+ * untouched, and `somewhere login` / `logout` / `whoami` never read this one.
22
+ *
23
+ * It carries the temp projects too, one per project root, so a second
24
+ * `--temporary` deploy from the same directory redeploys the SAME throwaway
25
+ * instead of minting another, and a deploy from an unrelated directory gets its
26
+ * own throwaway instead of replacing that one (pfb_29428f76480e). The
27
+ * project link is deliberately NOT written into the directory's
28
+ * `.somewhere.json`: that file is the developer's own link, and a throwaway
29
+ * their account does not own does not belong in it.
30
+ *
31
+ * When there is no real login the temporary credential stays in config.json,
32
+ * exactly as before — that is the logged-out first-touch path.
33
+ */
34
+ export interface StoredTempSession {
35
+ token: string;
36
+ temp_expires_at?: string;
37
+ claim_url?: string;
38
+ /** Throwaway projects this session auto-created, keyed by the canonical
39
+ * project root they were deployed from (see canonicalProjectRoot). */
40
+ projects?: Record<string, ProjectConfig>;
41
+ /** Written by CLI <= 0.35.2 without recording its directory. Kept so the
42
+ * record is not lost, but never used as a deploy target: an unrelated
43
+ * directory must not silently adopt it. */
44
+ project?: ProjectConfig;
45
+ }
46
+ /** The directory a temporary throwaway belongs to: the deploy target with
47
+ * symlinks and `..` resolved, so every spelling of one directory is one root.
48
+ * Like project discovery (`.somewhere.json` is read from the target itself),
49
+ * a subdirectory is its own root. */
50
+ export declare function canonicalProjectRoot(dir: string): string;
51
+ export declare function tempProjectFor(session: StoredTempSession | null, root: string): ProjectConfig | undefined;
52
+ export declare function withTempProject(session: StoredTempSession, root: string, project: ProjectConfig): StoredTempSession;
53
+ export declare function loadTempSession(): StoredTempSession | null;
54
+ export declare function saveTempSession(session: StoredTempSession): void;
55
+ /**
56
+ * Read-modify-write the sidecar under an exclusive lock, so two CLI
57
+ * processes (say, deploys from two project roots) cannot lose each other's
58
+ * update by saving copies they loaded before the other one saved.
59
+ * `change` receives what is on disk NOW and returns what to store; returning
60
+ * `current` unchanged writes nothing. Returns what is stored afterwards.
61
+ */
62
+ export declare function updateTempSession(change: (current: StoredTempSession | null) => StoredTempSession | null): StoredTempSession | null;
63
+ export declare function clearTempSession(): void;
64
+ /** Swap in a freshly-refreshed access key + rotated refresh token, preserving
65
+ * the rest of the stored config (user, etc.). Used by the API client's
66
+ * refresh-on-401 path (tsk_3642f3c4). No-op if there's no config to update. */
67
+ export declare function updateTokens(token: string, refreshToken: string, accessExpiresAt?: string): void;
68
+ /** A stored temporary credential whose own expiry time has passed. A missing
69
+ * or unreadable expiry is not treated as expired. */
70
+ export declare function temporaryConfigExpired(config: CliConfig | null, nowMs?: number): config is CliConfig & {
71
+ temporary: true;
72
+ temp_expires_at: string;
73
+ };
74
+ /** A stored credential that is not locally known to be expired. Says nothing
75
+ * about whether the platform still accepts it. Read WITHOUT `getToken()`,
76
+ * whose "Not logged in" / "Temporary session expired" paths exit the process. */
77
+ export declare function hasUsableCredential(config?: CliConfig | null): boolean;
78
+ export declare function getToken(): string;
79
+ export declare function loadProjectConfig(dir?: string): ProjectConfig | null;
80
+ export declare function saveProjectConfig(dir: string, config: ProjectConfig): void;
81
+ /** Record the platform-reported app URL for the folder's linked project. */
82
+ export declare function saveProjectAppUrl(dir: string, projectId: string, appUrl: string | null): ProjectConfig | null;
83
+ export interface ProjectConfigEntry {
84
+ dir: string;
85
+ config: ProjectConfig;
86
+ }
87
+ export declare function loadProjectConfigEntry(dir?: string): ProjectConfigEntry | null;
88
+ export declare function readProjectDeployState(config: ProjectConfig | null, projectId: string): ProjectDeployState | null;
89
+ /** Has this project directory already been told that files outside the app are
90
+ * not published? Kept on the project's own .somewhere.json so no new file is
91
+ * ever written into a customer's repo. An unlinked directory has no store, so
92
+ * the notice repeats — the safe direction (tsk_c166924f). */
93
+ export declare function publishNoticeSeen(dir: string): boolean;
94
+ export declare function markPublishNoticeSeen(dir: string): void;
95
+ export declare function projectConfigMatchesRef(config: ProjectConfig, ref: string): boolean;
96
+ /** The base this folder's source was prepared from, or null when unknown.
97
+ * Falls back to the release recorded by an older CLI's last deploy. */
98
+ export declare function readSourceBase(config: ProjectConfig | null | undefined, projectId: string): {
99
+ releaseId: string | null;
100
+ } | null;
101
+ export declare function sourceBaseState(projectId: string, releaseId: string | null, at?: string): SourceBaseState;
102
+ /** Record the published version this folder now matches. */
103
+ export declare function saveSourceBase(dir: string, projectId: string, releaseId: string | null): void;
104
+ export declare function saveProjectDeployState(dir: string, projectId: string, version: number, releaseId?: string, at?: string): ProjectConfig | null;
105
+ /** The entry for this invocation. When SOMEWHERE_CONFIG_DIR is set, the host
106
+ * must launch the bridge with the same root, or the bridge would read the
107
+ * default ~/.somewhere login instead of the one this CLI is using. */
108
+ export declare function somewhereStdioEntry(): {
109
+ command: string;
110
+ args: string[];
111
+ env?: Record<string, string>;
112
+ };
113
+ /** Project-local `.mcp.json` (read by Claude Code in the project dir). Uses the
114
+ * stdio bridge, not a baked token — see SOMEWHERE_STDIO_ENTRY. */
115
+ export declare function saveMcpConfig(dir: string): void;
116
+ /** Global Claude Code config (~/.claude.json). Uses the stdio bridge, not a
117
+ * baked token — see SOMEWHERE_STDIO_ENTRY. */
118
+ export declare function saveGlobalMcpConfig(): void;
119
+ export declare function hasGlobalMcpConfig(): boolean;
120
+ export declare const CURSOR_MCP_PATH: string;
121
+ /** Cursor gets the stdio bridge (`somewhere mcp`) rather than an embedded
122
+ * bearer token: the bridge reads ~/.somewhere/config.json at runtime, so a
123
+ * re-login never leaves a stale token behind in Cursor's config. */
124
+ export declare function saveCursorMcpConfig(): void;
125
+ export declare function hasCursorMcpConfig(): boolean;
@@ -0,0 +1,50 @@
1
+ export declare const DATA_MODULE = "somewhere:data";
2
+ export declare const DATA_VIRTUAL_ID = "\0somewhere:data";
3
+ export declare const DATA_DECLARATION_FILE = "__somewhere_data.d.ts";
4
+ export declare const GENERATED_DATA_HEADER = "// Generated by Somewhere from db/schema.ts. Do not edit.\n";
5
+ export interface DeclaredDataClient {
6
+ contract_digest: string;
7
+ declaration: string;
8
+ runtime: string;
9
+ manifest: {
10
+ version: number;
11
+ contract_digest: string;
12
+ tables: unknown[];
13
+ declaration: string;
14
+ };
15
+ }
16
+ export interface LocalDeclaredData {
17
+ client: DeclaredDataClient | undefined;
18
+ declarationPath: string;
19
+ /** Present only when db/schema.ts declares file collections (somewhere:files). */
20
+ filesDeclarationPath: string | undefined;
21
+ /** Absent in a project without db/schema.ts (runtime types only). */
22
+ schemaPath: string | undefined;
23
+ }
24
+ /** The generated somewhere:files declaration; the compiler's own file name. */
25
+ export declare const FILES_DECLARATION_FILE: string;
26
+ /** Source only: no evaluation, backend requests, npm installs or customer build. */
27
+ export declare function prepareDeclaredData(projectDir: string): LocalDeclaredData | undefined;
28
+ interface DataDevServer {
29
+ watcher: {
30
+ add(path: string): void;
31
+ on(event: string, callback: (path: string) => void): void;
32
+ off(event: string, callback: (path: string) => void): void;
33
+ };
34
+ moduleGraph: {
35
+ getModuleById(id: string): unknown;
36
+ invalidateModule(module: unknown): void;
37
+ };
38
+ ws: {
39
+ send(payload: unknown): void;
40
+ };
41
+ }
42
+ export declare function declaredDataPlugin(projectDir: string): {
43
+ name: string;
44
+ enforce: "pre";
45
+ resolveId(id: string): "\0somewhere:data" | undefined;
46
+ load(id: string): string | undefined;
47
+ configureServer(server: DataDevServer): void;
48
+ closeBundle(): void;
49
+ };
50
+ export {};
@@ -0,0 +1,56 @@
1
+ export interface DeployCheckFinding {
2
+ /** 'reference': an undefined name; 'type': an advisory shape mistake. */
3
+ kind: 'reference' | 'type';
4
+ code: string;
5
+ file: string;
6
+ line: number;
7
+ column: number;
8
+ message: string;
9
+ }
10
+ export interface DeployCheckResult {
11
+ /** true = the deploy's reference check would report nothing. */
12
+ ok: boolean;
13
+ findings: DeployCheckFinding[];
14
+ /** The TypeScript version that ran (always the deploy's). */
15
+ typescript: string;
16
+ checkedFiles: number;
17
+ /** Set when the check could not run; findings are then not a verdict. */
18
+ error?: string;
19
+ }
20
+ /** The deploy's TypeScript version. */
21
+ export declare const DEPLOY_CHECK_TYPESCRIPT_VERSION: string;
22
+ interface TscInvocation {
23
+ command: string;
24
+ args: string[];
25
+ }
26
+ /** The project's own TypeScript when it is exactly the deploy's version,
27
+ * otherwise that version through npx. Never a different version. */
28
+ /** The TypeScript version installed in the project, if any. */
29
+ export declare function projectTypeScriptVersion(projectDir: string): string | null;
30
+ /** The deploy check runs the deploy's own pinned TypeScript; when the project
31
+ * does not have exactly that version it is fetched with npx. Said on stderr,
32
+ * and true whether or not the project has another TypeScript
33
+ * (pfb_d615d6b6c581). */
34
+ export declare function announceDeployCheckFetch(projectDir: string): void;
35
+ export declare function deployCheckTsc(projectDir: string, platform?: NodeJS.Platform): TscInvocation;
36
+ /**
37
+ * tsconfig.json text → its compilerOptions, read as the deploy reads it:
38
+ * comments and trailing commas allowed, `extends` not followed, anything
39
+ * unreadable treated as no options.
40
+ */
41
+ export declare function projectCompilerOptions(tsconfigText: string | undefined): unknown;
42
+ export interface DeployCheckOutput {
43
+ findings: DeployCheckFinding[];
44
+ /** Errors that are not about the checked source: a config or global error
45
+ * (unknown option, missing type library). tsc may stop before checking
46
+ * source when one occurs, so any of these means the check did not run. */
47
+ problems: string[];
48
+ }
49
+ /** tsc --pretty false output → the findings the deploy reports, and any
50
+ * error that means the check itself did not run. */
51
+ export declare function parseDeployOutput(output: string, projectDir: string, functions: Record<string, string>): DeployCheckOutput;
52
+ /** Run the deploy's reference check over `projectDir`. Writes only a
53
+ * uniquely named dot-prefixed config and directory in the project root
54
+ * (outside the deploy's file set), removed when the check ends. */
55
+ export declare function runDeployCheck(projectDir: string): Promise<DeployCheckResult>;
56
+ export {};
@@ -0,0 +1,41 @@
1
+ import type { CliConfig } from '../types.js';
2
+ /** What this session may touch, as approved in the browser. null = all projects. */
3
+ export interface DeviceSessionScope {
4
+ projects: string[];
5
+ }
6
+ export interface DeviceLoginCallbacks {
7
+ onPrompt: (info: {
8
+ code: string;
9
+ approvalUrl: string;
10
+ }) => void;
11
+ onWaiting?: () => void;
12
+ }
13
+ export declare class DeviceLoginTimeout extends Error {
14
+ constructor();
15
+ }
16
+ export declare class DeviceCodeUnsupported extends Error {
17
+ constructor();
18
+ }
19
+ export declare class DeviceLoginDenied extends Error {
20
+ constructor();
21
+ }
22
+ /**
23
+ * What the approval page shows the account owner about THIS machine, so they
24
+ * can tell their own VM from someone else's before allowing access. Only
25
+ * facts the CLI can read locally; the platform adds the request's IP and
26
+ * approximate location itself and never trusts these for anything but
27
+ * display.
28
+ */
29
+ export interface DeviceClientMeta {
30
+ hostname: string;
31
+ cli_version: string;
32
+ runtime_version: string;
33
+ platform: string;
34
+ arch: string;
35
+ }
36
+ export declare function describeThisDevice(): DeviceClientMeta;
37
+ export interface DeviceLoginResult {
38
+ config: CliConfig;
39
+ scope: DeviceSessionScope | null;
40
+ }
41
+ export declare function deviceLogin(callbacks: DeviceLoginCallbacks): Promise<DeviceLoginResult>;
@@ -0,0 +1,2 @@
1
+ export declare function getDeviceId(): string;
2
+ export declare function getDeviceKeyName(): string;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Build a local `.env` file body from a project's env-var KEY list.
3
+ *
4
+ * Values are intentionally blank: the platform never returns env-var values
5
+ * from any API route — they are decrypted into the deployed function bundle at
6
+ * deploy time and never leave that boundary. So `somewhere env pull` writes the
7
+ * exact set of keys the project expects (grouped by scope) with empty values
8
+ * as a local key inventory. Backend values remain configured on the deployed
9
+ * project; frontend hot reload does not supply values to its backend.
10
+ */
11
+ export interface EnvKey {
12
+ key: string;
13
+ scope?: string;
14
+ }
15
+ export declare function buildEnvTemplate(keys: EnvKey[], opts?: {
16
+ projectId?: string;
17
+ }): string;
@@ -0,0 +1,111 @@
1
+ export declare const IGNORE: Set<string>;
2
+ export declare const MAX_FILE_SIZE: number;
3
+ export declare const BINARY_EXTS: Set<string>;
4
+ export declare function isTestSourcePath(relPath: string): boolean;
5
+ /** The folders held back by default, matched by name at any depth. */
6
+ export declare const TEST_FOLDERS: readonly string[];
7
+ /** The first folder of relPath that is a test folder, e.g. `src/__tests__`. */
8
+ export declare function testFolderOf(relPath: string): string | null;
9
+ /**
10
+ * Why a collected file is held back as a test, or null when it publishes.
11
+ * `optedIn(path, isDirectory)` answers whether an explicit opt-in names that
12
+ * path. A folder default is lifted by an opt-in for the file or any folder
13
+ * above it; the file-name default only by an opt-in for the file itself.
14
+ */
15
+ export declare function testExclusionReason(relPath: string, optedIn: (path: string, isDirectory: boolean) => boolean): string | null;
16
+ export declare function isFunctionPath(p: string): boolean;
17
+ export declare function isBinaryPath(p: string): boolean;
18
+ export interface CollectedFiles {
19
+ files: Record<string, string>;
20
+ binaryFiles: Record<string, string>;
21
+ functions: Record<string, string>;
22
+ /** Files intentionally NOT uploaded (too big / symlink). A deploy is a full
23
+ * replacement, so a silent skip DELETES the file from production — the caller
24
+ * must surface these, not drop them quietly. */
25
+ skipped: Array<{
26
+ path: string;
27
+ reason: string;
28
+ }>;
29
+ /** Files that would be published but exceed MAX_FILE_SIZE (also listed in
30
+ * `skipped`). Deploy and preview refuse on these before any request
31
+ * (oversizeRefusal): uploading without them would delete the live copy. */
32
+ oversize: Array<{
33
+ path: string;
34
+ bytes: number;
35
+ }>;
36
+ /** Opt-ins that changed nothing: an --include entry or a "!" line in
37
+ * .somewhereignore that cannot publish what it names. Said, never silent
38
+ * (pfb_7b36450727ee); the upload policy itself is unchanged. */
39
+ notes: Array<{
40
+ source: string;
41
+ reason: string;
42
+ }>;
43
+ /** Root files held back because they are not part of the app (notes, logs,
44
+ * transcripts). Always printed by name — see printExcludedFiles. */
45
+ excluded: Array<{
46
+ path: string;
47
+ reason: string;
48
+ }>;
49
+ /** Files the deploy API's sensitive-path policy names
50
+ * (src/lib/vendor/deploy-paths.ts). Never read, never uploaded, and no
51
+ * opt-in reopens them. `referencedBy` lists published source files whose
52
+ * text contains the file's name: a filename match, not import analysis. */
53
+ sensitive: Array<{
54
+ path: string;
55
+ reason: string;
56
+ referencedBy: string[];
57
+ }>;
58
+ /** Relative paths a deploy of this folder would upload (the publish rules'
59
+ * verdict, oversize files excluded). `somewhere pull` only ever removes
60
+ * files in this set. */
61
+ published: string[];
62
+ }
63
+ export declare const SENSITIVE_FILE_REASON = "blocked by the sensitive-path policy \u2014 never uploaded";
64
+ export interface CollectOptions {
65
+ /** Root files to publish on purpose (`somewhere deploy --include NOTES.md`). */
66
+ include?: string[];
67
+ /** Read binary assets into base64 (deploy needs them). Lint only reads
68
+ * text, so it passes false and binaries are recorded with empty content. */
69
+ readBinary?: boolean;
70
+ }
71
+ /** Walk a directory tree and bucket every file into static / binary / function,
72
+ * applying the same path remapping the deploy command uses. */
73
+ export declare function collectFiles(baseDir: string, options?: CollectOptions): CollectedFiles;
74
+ export type FileKind = 'static' | 'binary' | 'function';
75
+ /** The deploy key + bucket a relative path maps to. `functions/`-prefixed paths
76
+ * are stripped to their route; root-level api/_lib/[param] paths are functions. */
77
+ export declare function classifyKey(relPath: string): {
78
+ kind: FileKind;
79
+ key: string;
80
+ };
81
+ /** Read one file off disk and place it in the right bucket of `out`. */
82
+ export declare function classifyInto(out: CollectedFiles, baseDir: string, relPath: string, readBinary?: boolean): void;
83
+ export declare function formatBytes(bytes: number): string;
84
+ /** Refusal text when published source names a held-back credentials file, or
85
+ * null. Names paths only; never the file's contents. */
86
+ /** A file that would be published is over the per-file limit. Deploying
87
+ * without it would remove the live copy, so nothing is sent (tsk_97979518,
88
+ * pfb_9c4d1d7fc75c). Deliberate exclusions (.somewhereignore, .gitignore)
89
+ * are how a large local file stays out. */
90
+ export declare function oversizeRefusal(collected: Pick<CollectedFiles, 'oversize'>): string | null;
91
+ /**
92
+ * Preview's save loop uploads changed files one batch at a time. Judge each
93
+ * batch the way a deploy judges the tree: files the project's .gitignore or
94
+ * .somewhereignore keeps out are not uploaded, and an uploaded file over the
95
+ * per-file limit refuses the whole batch before anything is read or sent
96
+ * (pfb_9c4d1d7fc75c). `paths` are relative to `baseDir`.
97
+ */
98
+ export declare function previewBatchCheck(baseDir: string, paths: string[]): {
99
+ upload: string[];
100
+ ignored: string[];
101
+ oversize: Array<{
102
+ path: string;
103
+ bytes: number;
104
+ }>;
105
+ };
106
+ /** The save-loop form of oversizeRefusal: nothing in this save was sent. */
107
+ export declare function previewOversizeRefusal(oversize: Array<{
108
+ path: string;
109
+ bytes: number;
110
+ }>): string;
111
+ export declare function sensitiveReferenceRefusal(collected: Pick<CollectedFiles, 'sensitive'>): string | null;
@@ -0,0 +1,28 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type Server as NetServer } from 'node:net';
3
+ export interface FrontendDevServer {
4
+ listen(): Promise<unknown>;
5
+ close(): Promise<unknown>;
6
+ printUrls(): void;
7
+ }
8
+ export declare const FRONTEND_API_PATH = "^/api(?:/|\\?|$)";
9
+ export declare const FRONTEND_DATA_PATH = "^/__sw/data(?:\\?|$)";
10
+ export declare function deployedOrigin(value: string): string;
11
+ /** Only a request to this exact loopback authority may cross the proxy. */
12
+ export declare function authorizeFrontendProxy(req: IncomingMessage, localOrigin: string): boolean;
13
+ export declare function frontendProxy(target: string, localOrigin: string): {
14
+ target: string;
15
+ changeOrigin: boolean;
16
+ secure: boolean;
17
+ cookieDomainRewrite: string;
18
+ bypass(req: IncomingMessage, res: ServerResponse | undefined): string | undefined;
19
+ };
20
+ /**
21
+ * `localhost` resolves to ::1 first on many machines, and Vite binds exactly one
22
+ * address, so a browser opening http://localhost:<port> could be refused while
23
+ * the server sat on 127.0.0.1. Relay the IPv6 loopback to the IPv4 one so both
24
+ * families reach the same server — loopback only, never a wildcard address.
25
+ * Resolves null where the machine has no IPv6 loopback.
26
+ */
27
+ export declare function relayIpv6Loopback(port: number): Promise<NetServer | null>;
28
+ export declare function startFrontendDev(cwd: string, target: string, port?: number, open?: boolean): Promise<FrontendDevServer>;
@@ -0,0 +1,9 @@
1
+ import type { LintFinding } from './source-lint.js';
2
+ export interface GenericLintResult {
3
+ status: 'not-requested' | 'completed' | 'unavailable' | 'failed';
4
+ findings: LintFinding[];
5
+ reason?: string;
6
+ }
7
+ /** Use the project's existing Oxlint installation. Never download a binary or
8
+ * install packages during an ordinary lint run. Type-aware rules are separate. */
9
+ export declare function genericLint(directory: string): GenericLintResult;
@@ -0,0 +1,2 @@
1
+ /** Keep the first sentence or line without splitting dotted API names or URLs. */
2
+ export declare function helpSummary(description: string): string;
@@ -0,0 +1,9 @@
1
+ import { fetch as undiciFetch } from 'undici';
2
+ export declare function fetchWithProxy(input: Parameters<typeof undiciFetch>[0], init?: Parameters<typeof undiciFetch>[1], timeoutMs?: number): ReturnType<typeof undiciFetch>;
3
+ /** Undici rejects a request that got no response with a bare "fetch failed"
4
+ * and hides the reason in `cause`. Every CLI request goes through here, so
5
+ * every such failure names the host it tried, the reason, and what to do
6
+ * (tsk_b9900dbb: `somewhere login` in a sandboxed agent shell printed only
7
+ * "fetch failed"). Timeouts and aborts pass through for their own messages;
8
+ * `cause` is kept so callers that read `cause.code` still can. */
9
+ export declare function describeNetworkFailure(err: unknown, url: string): unknown;
@@ -0,0 +1,13 @@
1
+ export declare const AGENT_WORKFLOW = "## Getting started \u2014 build, deploy, verify\n\n`somewhere init --name <slug>` writes React + TypeScript. Signed out: local only;\nsigned in: also creates and links a project.\nDefault: sign-in UI; minimal: SDK/auth route; bare: neither. `init --catalog --json`: modules.\n`npx @somewhere-cloud/cli deploy` publishes raw source: signed out, a temporary URL, claim URL\nand expiry; linked, your account project. On a hosted VM, `somewhere login` uses browser approval and keeps you signed in.\nAccount operations, test inbox and cron need login.\nStart auth/data/cron with `somewhere docs recipe-signed-in-app --full`.\n\nAfter edits: `somewhere typecheck` and focused local/browser tests. Publish:\n1. `somewhere deploy` (do not build first). Deploy\n checks compilation, schema and secrets; `somewhere deploy-check` runs them without publishing\n (diagnosis, review, `--run /api/x`).\n2. Run `somewhere verify` on the final journey (`--flow flow.json`); rerun after fixes. Sign test users up\n in-app at `*.test.somewhere.site`; more: `actors` + `journey` (`somewhere docs browser`).\n3. Inspect: `somewhere browser`; diagnose: `somewhere logs --tail 10`, `somewhere errors`.\n4. Test mail: `somewhere email test-inbox <addr>` includes `verification_code`.\n Don't retest sign-in or `sw.db.from` scoping; test each table's scope, auth before `sw.db.server`/raw SQL, bad input and journeys.\n\nRoutes: `index.html` loads `src/main.tsx`; unmatched extensionless paths\n(`/signin`) serve it. Route the app by `location.pathname`.\n`api/notes/[id].ts` is `/api/notes/:id`; `_`-prefixed names are import-only\nhelpers. Avoid names differing only in case.\n\nWith auth enabled, `api/auth/[...path].ts` is\n`export { somewhereAuth as default } from '@somewhere-cloud/sdk/server'`; pages\nuse `createSomewhereAuth()` from `@somewhere-cloud/sdk/auth` (client and React hooks:\n`somewhere docs auth-client --section react-auth-state`). `auth.signUp({ email, password,\ndisplayName? })` / `auth.signIn({ email, password })` return the user or throw\nwith the message. Gate on `auth.getState().status` (React: `useAuthState()`). Sign-up sets `email_verified: false`; unverified users pass\n`auth: 'required'`. `sw.auth.requireUser(req)` returns `{ id, email,\nrole, email_verified, \u2026 }` or throws 401 `AUTH_REQUIRED`;\n`sw.auth.fromRequest(req)` returns it or `null`.\n\nFunctions: JSON endpoints use `sw.endpoint({ auth, body, rateLimit, handler:\nasync ({ body, user, params }, sw) => value })`; set `auth` (`'required'`,\n`'optional'`, `'none'`) or deploy refuses it. Webhooks and streaming use a bare `export default async\nfunction (req: Request, sw: SomewhereRuntimeContext)` returning a `Response`.\nParams: `params.id` there, `sw.params.id` bare.\n\nData: `id()` is a random text key on new tables (reference with `text()`); integer-id tables keep integers. The starter's `id({ uuid: false })` is deliberate.\nDeclare tables in `db/schema.ts`; pages use `somewhere:data`\n(`data.notes.list()`, `.create()`, `.update(id, \u2026)`) without API files.\nUse `owner()` for personal rows, `group()` for invited teams, `appRole()`\nfor app-wide roles, `anyOf()` for owner or a role, `allOf()` for members-only rows.\nSharing your own rows with specific people: `anyOf(owner(), grant())`\n(`somewhere docs declared-data --section per-owner-sharing`).\nBooking/help desk: `somewhere docs sw.db --section provider-or-booker-and-owner-or-staff-recipes`.\nKeep fitting scopes when an exceptional write needs `sw.db.server.tx`.\n`shared()` gives signed-in reads and creator-only writes. `client` sets browser\ncolumns; `publicRead: { where }` admits visitors. Public-profile enquiries use\n`client.intake` (`somewhere docs declared-data`). Keep scopes and grants;\nfunctions handle authorized exceptional writes and side effects. Declare the\nbody schema (a missing or mistyped field is a 400); `handle` below is a\npublic address its owner claimed:\n\n```ts\nexport default sw.endpoint({\n auth: 'none',\n body: { handle: 'string', title: 'string', from_email: 'email' },\n handler: async ({ body }, sw) => {\n const title = body.title.trim();\n if (!title || title.length > 200 || /[\\r\\n]/.test(title)) return Response.json({ error: 'bad title' }, { status: 400 });\n const { data: [profile] } = await sw.db.server.from('profiles', { where: { handle: body.handle }, limit: 1 });\n if (!profile) return Response.json({ error: 'unknown handle' }, { status: 404 });\n await sw.db.server.insert('entries', { user_id: profile.user_id, owner_email: profile.owner_email,\n title, from_email: body.from_email, created_ms: Date.now() });\n },\n});\n```\n\nUse the looked-up owner, never the body. Rate limits/alerts: `recipe-signed-in-app`.\nUse `serverOnly()` only when every operation needs a function's own access check.\nStructured queries: `sw.db.from` / `insert` / `update` / `remove` return `{ data: rows[], count,\nchanges }`; `where: { a: 1, b: { in: ids }, c: { gte: 2 }, d: null }` (one\noperator per column). Raw SQL uses a separate raw database, never managed tables.\nFor cross-user managed work, authorize the caller and use `sw.db.server.from` /\n`insert` / `update` / `remove`; keep `owner()`/`group()`. Parallel reads: `Promise.all`.\n\nUnique pair: `unique: [['org_id','email']]` in table options.\n\nTest schedules now: `somewhere cron run <id> --wait`. Do not wait for it to fire.\n";
2
+ export declare const SKILLS_POINTER: string;
3
+ /** One line pointing agents at the declared-access recipes (tsk_d433436b): in
4
+ * the testing lane's experiment all three agents given it moved from
5
+ * serverOnly() plus hand-written checks to declared access. Kept outside
6
+ * AGENT_WORKFLOW, which is a byte mirror of the platform's agent workflow. */
7
+ export declare const DECLARED_ACCESS_POINTER: string;
8
+ /** One line telling agents the app's data and code can leave (tsk_9b4a27f7):
9
+ * an evaluating agent concluded the platform had no exits. Kept outside
10
+ * AGENT_WORKFLOW, which is a byte mirror of the platform's agent workflow. */
11
+ export declare const PORTABILITY_POINTER: string;
12
+ export declare const INIT_AGENTS_MD: string;
13
+ export declare const INIT_CLAUDE_MD = "Read AGENTS.md for project instructions.\n";
@@ -0,0 +1,8 @@
1
+ import type { InitScaffoldFile } from './init-scaffold.js';
2
+ import type { InitSelection } from './init-features.js';
3
+ export interface FeatureTemplateOptions {
4
+ appName: string;
5
+ }
6
+ /** Where to build, restyle, route and change data, for the init report. */
7
+ export declare function extensionPoints(selection: InitSelection): Record<string, string>;
8
+ export declare function createFeatureTemplate(selection: InitSelection, options: FeatureTemplateOptions): InitScaffoldFile[];