runcloud 0.1.106 → 0.1.107

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.
@@ -263,6 +263,33 @@ function secretSelector(opts) {
263
263
  function collectRepeatable(value, previous) {
264
264
  return [...previous, value];
265
265
  }
266
+ export function parseTagPairs(values) {
267
+ return values.map((raw) => {
268
+ const at = raw.indexOf('=');
269
+ if (at <= 0) {
270
+ throw new Error(`--tag must be key=value (got ${JSON.stringify(raw)})`);
271
+ }
272
+ return [raw.slice(0, at), raw.slice(at + 1)];
273
+ });
274
+ }
275
+ export async function resolveSandboxByTag(api, tags) {
276
+ if (tags.length === 0) {
277
+ throw new Error('Provide a sandbox id, or --tag key=value to find one.');
278
+ }
279
+ const query = new URLSearchParams();
280
+ for (const [key, value] of parseTagPairs(tags))
281
+ query.append('tag', `${key}:${value}`);
282
+ const data = await api.get(`/run-cloud/sandboxes?${query}`);
283
+ const items = data?.items ?? [];
284
+ if (items.length === 0) {
285
+ throw new Error(`No sandbox matches ${tags.join(' ')}.`);
286
+ }
287
+ if (items.length > 1) {
288
+ const listed = items.map((s) => ` ${s.id}${s.name ? ` ${s.name}` : ''}`).join('\n');
289
+ throw new Error(`${items.length} sandboxes match ${tags.join(' ')} — narrow it, or pass an id:\n${listed}`);
290
+ }
291
+ return items[0].id;
292
+ }
266
293
  export function registerSandbox(program) {
267
294
  const sandbox = program.command('sandbox').description('Spawn and control microVM sandboxes');
268
295
  const defaultHelp = new Help();
@@ -362,12 +389,16 @@ export function registerSandbox(program) {
362
389
  .command('list')
363
390
  .description('List sandboxes')
364
391
  .option('--state <state>', 'filter by state')
365
- .option('--name <name>', 'filter by name (exact)')).action((opts) => run(async () => {
392
+ .option('--name <name>', 'filter by name (exact)')
393
+ .option('--tag <key=value>', 'filter by tag; repeatable, and a sandbox must carry every one', collectRepeatable, [])).action((opts) => run(async () => {
366
394
  const query = new URLSearchParams();
367
395
  if (opts.state)
368
396
  query.set('state', opts.state);
369
397
  if (opts.name)
370
398
  query.set('name', opts.name);
399
+ for (const [key, value] of parseTagPairs(opts.tag ?? [])) {
400
+ query.append('tag', `${key}:${value}`);
401
+ }
371
402
  const qs = query.size ? `?${query}` : '';
372
403
  const api = runCloudApi();
373
404
  const [data, boxes] = await Promise.all([
@@ -384,6 +415,23 @@ export function registerSandbox(program) {
384
415
  else
385
416
  console.log(renderSandboxList(items));
386
417
  }));
418
+ withOutput(sandbox
419
+ .command('tag')
420
+ .description('Set or remove tags on a sandbox')
421
+ .argument('<id>', 'sandbox id')
422
+ .argument('<pairs...>', 'key=value to set, or key= to remove')).action((id, pairs, opts) => run(async () => {
423
+ const tags = Object.fromEntries(parseTagPairs(pairs).map(([key, value]) => [key, value === '' ? null : value]));
424
+ const updated = await runCloudApi().patch(`/run-cloud/sandboxes/${encodeURIComponent(id)}/tags`, { tags });
425
+ if (opts.json)
426
+ printJson(updated);
427
+ else {
428
+ const applied = (updated?.tags ?? {});
429
+ const entries = Object.entries(applied);
430
+ console.log(entries.length === 0
431
+ ? `${id} now has no tags`
432
+ : `${id}\n${entries.map(([k, v]) => ` ${k}=${v}`).join('\n')}`);
433
+ }
434
+ }));
387
435
  withOutput(sandbox
388
436
  .command('get')
389
437
  .description('Inspect a sandbox, including its public hostname when exposed')
@@ -497,15 +545,17 @@ export function registerSandbox(program) {
497
545
  sandbox
498
546
  .command('shell')
499
547
  .description('Open an interactive shell (resumes paused sandboxes)')
500
- .argument('<id>', 'sandbox id')
501
- .action((id) => run(async () => {
548
+ .argument('[id]', 'sandbox id; omit when using --tag')
549
+ .option('--tag <key=value>', 'find the sandbox by tag instead of id; repeatable, must match exactly one', collectRepeatable, [])
550
+ .action((id, opts) => run(async () => {
502
551
  const credentials = requireCredentials();
503
552
  const api = new ApiClient(credentials.apiUrl, credentials.token);
504
- await prepareSandboxShell(api, id);
553
+ const sandboxId = id ?? (await resolveSandboxByTag(api, opts.tag ?? []));
554
+ await prepareSandboxShell(api, sandboxId);
505
555
  process.exitCode = await runSandboxShell({
506
556
  apiUrl: credentials.apiUrl,
507
557
  token: credentials.token,
508
- sandboxId: id,
558
+ sandboxId,
509
559
  });
510
560
  }));
511
561
  for (const lifecycle of [
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.1.106';
1
+ export const CLI_VERSION = '0.1.107';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runcloud",
3
- "version": "0.1.106",
3
+ "version": "0.1.107",
4
4
  "description": "Create and control run.cloud remote mobile simulators and cloud sandboxes",
5
5
  "license": "Apache-2.0",
6
6
  "keywords": [
@@ -204,6 +204,76 @@ signed browser desktop. The CLI also provides `screenshot`, `click`, `type`,
204
204
  and `key` subcommands for explicit pixel-coordinate automation. Keep signed
205
205
  desktop URLs private and inspect each subcommand's help before automation.
206
206
 
207
+ ## Tag Sandboxes, and Find Them Again
208
+
209
+ Tags are arbitrary `key=value` metadata on a lease. They are how an operator
210
+ gets from a symptom back to the machine that caused it, and they **outlive the
211
+ sandbox** — so "which sandbox ran this?" is still answerable after the VM is
212
+ gone, which is usually when you are asking.
213
+
214
+ Tag on create, or on an existing sandbox:
215
+
216
+ ```bash
217
+ runcloud sandbox create --image runcloud/agent-base # then:
218
+ runcloud sandbox tag sbx_123 newly.run=run-42 owner=qasim
219
+ runcloud sandbox tag sbx_123 owner= # empty value removes the key
220
+ ```
221
+
222
+ Find by tag — repeatable, and a sandbox must carry every one:
223
+
224
+ ```bash
225
+ runcloud sandbox list --tag newly.run=run-42 --json
226
+ runcloud sandbox shell --tag newly.run=run-42 # resolves, then opens a shell
227
+ ```
228
+
229
+ `shell --tag` refuses to guess: no match and several matches are both errors,
230
+ and the ambiguous case lists what it found. Opening a shell on the wrong
231
+ machine is worse than being told to be precise.
232
+
233
+ Reserved keys the platform sets itself — do not overwrite them:
234
+
235
+ | key | meaning |
236
+ | --- | --- |
237
+ | `newly.kind` | what created it (`ci`, …) |
238
+ | `newly.run` | the CI run id |
239
+ | `newly.environment` | the CI environment id |
240
+ | `newly.session` / `newly.role` | Newly session association, for simulators |
241
+
242
+ ### Debugging when you have only a log line
243
+
244
+ The control plane logs a sandbox's tags on **create** and **destroy**, so the
245
+ first step needs no API token and no database access:
246
+
247
+ ```bash
248
+ gcloud logging read \
249
+ 'resource.labels.service_name="cp-api-dev" AND jsonPayload.message="run.cloud sandbox created"' \
250
+ --limit 20 --freshness=6h --format=json
251
+ ```
252
+
253
+ Then either query as a normal user (`runcloud sandbox list --tag …`), or use the
254
+ ops endpoint, which is org-agnostic and audited — the right tool when you do not
255
+ know whose org it was:
256
+
257
+ ```
258
+ GET /diagnose/sandbox?tag=newly.run:run-42
259
+ ```
260
+
261
+ It is gated by an ops OIDC token, not a user credential: mint one by
262
+ impersonating the `cp-diagnose-ops-<env>` service account, which every engineer
263
+ can do. Destroyed sandboxes are included on purpose.
264
+
265
+ **Credentials.** The CLI defaults to **prod**. For dev, set both:
266
+
267
+ ```bash
268
+ export RUN_CLOUD_API_URL=https://cp-api-dev-97683904813.us-east4.run.app
269
+ export RUN_CLOUD_API_TOKEN=... # RUN_CLOUD_DEV_API_TOKEN in secrets/dev.yaml
270
+ ```
271
+
272
+ Key names do not match the env vars, and `sops` needs
273
+ `gcloud auth application-default login` rather than plain `gcloud auth login` —
274
+ see the Secrets section of the root `CLAUDE.md`/`AGENTS.md` before concluding
275
+ you lack access.
276
+
207
277
  ## Guardrails
208
278
 
209
279
  - Destroy every sandbox created during a task unless the user explicitly asks
@@ -215,3 +285,5 @@ desktop URLs private and inspect each subcommand's help before automation.
215
285
  URLs in logs, screenshots, PR comments, or chat output.
216
286
  - Do not claim that CLI-only lifecycle, image, secret-group, desktop, or stable
217
287
  hostname commands are TypeScript SDK methods.
288
+ - Do not overwrite a `newly.*` tag; the platform sets those and support reads
289
+ them. Add your own key instead.