@ishlabs/cli 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,10 +2,11 @@
2
2
  * Helpers for setting OTel Baggage entries and propagating them on
3
3
  * outbound fetches.
4
4
  *
5
- * The CLI carries three baggage entries on every backend call so the
6
- * backend can attribute spans + Sentry events to the right surface:
5
+ * The CLI carries four baggage entries on every backend call so the
6
+ * backend can attribute spans + Sentry events to the right surface and,
7
+ * when the command is workspace-scoped, the right workspace:
7
8
  *
8
- * baggage: client.name=ish-cli,client.surface=<command>,client.version=<x.y.z>
9
+ * baggage: client.name=ish-cli,client.surface=<command>,client.version=<x.y.z>[,workspace_id=<uuid>]
9
10
  *
10
11
  * In Node mode, `@opentelemetry/instrumentation-undici` will inject the
11
12
  * active baggage onto outbound `fetch` automatically once
@@ -25,13 +26,15 @@ export const BAGGAGE_KEY_CLIENT_NAME = "client.name";
25
26
  export const BAGGAGE_KEY_CLIENT_SURFACE = "client.surface";
26
27
  export const BAGGAGE_KEY_CLIENT_VERSION = "client.version";
27
28
  export const BAGGAGE_KEY_CONSENT_ANALYTICS = "consent.analytics";
29
+ export const BAGGAGE_KEY_WORKSPACE_ID = "workspace_id";
28
30
  /** The fixed ``client.name`` we tag every CLI invocation with. The plan
29
31
  * pins this string — backend dashboards filter on it. */
30
32
  export const CLIENT_NAME = "ish-cli";
31
33
  /**
32
34
  * Stamp the active OTel baggage with ``client.name`` / ``client.surface``
33
- * / ``client.version`` and stash a process-local copy for the
34
- * manual-injection ``withBaggage`` helper.
35
+ * / ``client.version`` (always) and ``workspace_id`` (when the command
36
+ * carries one), then stash a process-local copy for the manual-injection
37
+ * ``withBaggage`` helper.
35
38
  *
36
39
  * Idempotent — subsequent calls overwrite the previous surface, which is
37
40
  * what we want when Commander invokes ``preAction`` once per resolved
@@ -51,17 +54,20 @@ export const CLIENT_NAME = "ish-cli";
51
54
  * Safe to call even with no OTel SDK registered — `@opentelemetry/api`
52
55
  * ships no-op fallbacks.
53
56
  */
54
- export function setSurfaceBaggage(commandName) {
57
+ export function setSurfaceBaggage(input) {
55
58
  const existing = propagation.getActiveBaggage() ?? propagation.createBaggage();
56
- const next = existing
59
+ let next = existing
57
60
  .setEntry(BAGGAGE_KEY_CLIENT_NAME, { value: CLIENT_NAME })
58
- .setEntry(BAGGAGE_KEY_CLIENT_SURFACE, { value: commandName })
61
+ .setEntry(BAGGAGE_KEY_CLIENT_SURFACE, { value: input.surface })
59
62
  .setEntry(BAGGAGE_KEY_CLIENT_VERSION, { value: pkg.version })
60
63
  // CLI runs on a developer's machine with no client-side consent UI.
61
64
  // Emit "unknown" so the backend resolver falls through to the
62
65
  // authenticated user's persisted consent rather than default-denying
63
66
  // via baggage absence.
64
67
  .setEntry(BAGGAGE_KEY_CONSENT_ANALYTICS, { value: "unknown" });
68
+ if (input.workspaceId) {
69
+ next = next.setEntry(BAGGAGE_KEY_WORKSPACE_ID, { value: input.workspaceId });
70
+ }
65
71
  _activeBaggage = next;
66
72
  }
67
73
  /** Process-local copy of the active baggage for the manual-injection path.
@@ -23,6 +23,7 @@ export interface PersonResolveOpts {
23
23
  /** Profile IDs to exclude from the fetched pool (e.g. participants already on an ask). */
24
24
  excludeProfileIds?: Set<string>;
25
25
  }
26
+ export declare function normalizeVisibility(raw: string | undefined): string | undefined;
26
27
  /** True when any person-selection flag is set on the command. */
27
28
  export declare function hasPersonFlags(flags: PersonFilterOpts): boolean;
28
29
  /**
@@ -28,7 +28,7 @@ const VISIBILITY_ALIASES = {
28
28
  private: "workspace",
29
29
  public: "platform",
30
30
  };
31
- function normalizeVisibility(raw) {
31
+ export function normalizeVisibility(raw) {
32
32
  if (raw === undefined)
33
33
  return undefined;
34
34
  return VISIBILITY_ALIASES[raw] ?? raw;
@@ -186,6 +186,12 @@ export async function resolvePersonIds(client, workspace, flags, opts = {}) {
186
186
  if (sampleN === undefined && !flags.all && !filtersUsed) {
187
187
  throw new Error(`Select people: pass --person <id> (repeatable), --sample <N>, ${allFlagName}, or filter flags (--bio, --country, --gender, --min-age, --max-age, --occupation, --search, --visibility).`);
188
188
  }
189
+ // NEW-CP-2 / Pattern H: --sample N > backend cap is detectable without
190
+ // any API call — fail fast so a bad value doesn't burn a /people round-trip
191
+ // before the cap message surfaces.
192
+ if (sampleN !== undefined && sampleN > PARTICIPANT_BATCH_CAP) {
193
+ throw new Error(`--sample ${sampleN} exceeds the per-dispatch participant cap of ${PARTICIPANT_BATCH_CAP}. Pass --sample ${PARTICIPANT_BATCH_CAP} or fewer, or split the run into multiple dispatches.`);
194
+ }
189
195
  const params = {
190
196
  product_id: workspace,
191
197
  type: "ai",
@@ -245,15 +251,41 @@ export async function resolvePersonIds(client, workspace, flags, opts = {}) {
245
251
  throw new Error(`No ${sim}people found in workspace ${workspace}.${opts.requireSimulatable ? " Create people with simulation configs first." : ""}`);
246
252
  }
247
253
  if (flags.all)
248
- return pool.map((p) => p.id);
254
+ return enforceParticipantCap(pool.map((p) => p.id), flags, opts);
249
255
  if (sampleN !== undefined) {
250
256
  if (sampleN > pool.length) {
251
257
  throw new Error(`--sample ${sampleN} requested but only ${pool.length} matching person${pool.length === 1 ? "" : "s"} available.`);
252
258
  }
259
+ // sampleN > PARTICIPANT_BATCH_CAP is caught earlier (before the
260
+ // /people fetch) so we don't reach here with an over-cap sample.
253
261
  return shuffleInPlace([...pool]).slice(0, sampleN).map((p) => p.id);
254
262
  }
255
- // Filters only, no --sample/--all → return every match.
256
- return pool.map((p) => p.id);
263
+ // Filters only, no --sample/--all → return every match (subject to cap).
264
+ return enforceParticipantCap(pool.map((p) => p.id), flags, opts);
265
+ }
266
+ /**
267
+ * Backend caps each dispatch batch at 20 simulations (Pydantic
268
+ * `max_length=20` on the `simulations` array in
269
+ * app/api/models/simulation.py, media.py, and chat.py). Without a
270
+ * client-side guard, `--all` on a workspace with platform-visible
271
+ * people resolves to ~200 (the `/people` pagination limit) and the
272
+ * backend returns a `validation_error` ("List should have at most 20
273
+ * items after validation, not 200") that's confusing without context.
274
+ * Throw a helpful client-side error before the dispatch so the user
275
+ * knows to sample explicitly.
276
+ *
277
+ * Discovered during the 2026-05-26 post-remediation checkpoint sweep
278
+ * (NEW-CP-2). If the backend cap changes, update PARTICIPANT_BATCH_CAP.
279
+ */
280
+ const PARTICIPANT_BATCH_CAP = 20;
281
+ function enforceParticipantCap(ids, flags, opts) {
282
+ if (ids.length <= PARTICIPANT_BATCH_CAP)
283
+ return ids;
284
+ const allFlagName = opts.allFlagName ?? "--all";
285
+ const filterDesc = describeFilters(flags) || "no filter";
286
+ throw new Error(`Resolved ${ids.length} participants (${filterDesc}) but the backend caps each dispatch at ${PARTICIPANT_BATCH_CAP}. ` +
287
+ `Pass \`--sample ${PARTICIPANT_BATCH_CAP}\` to randomly subsample the pool, narrow your filters, or run the dispatch ` +
288
+ `multiple times against different slices. ${allFlagName} without --sample is only safe when the matching pool is ≤${PARTICIPANT_BATCH_CAP}.`);
257
289
  }
258
290
  /**
259
291
  * Attach the person-selection flag set to a Commander command.
@@ -375,7 +407,25 @@ export function exitCodeFromError(err) {
375
407
  return 5;
376
408
  }
377
409
  if (err instanceof Error) {
378
- // Auth-related client errors (e.g. missing token)
410
+ // Pattern D: structured `error_code` on the Error object takes
411
+ // precedence over message-regex sniffing. Sites that self-tag
412
+ // (alias-store, auth, sub-command envelopes) get a deterministic
413
+ // exit code; sites that don't fall back to the legacy regex below.
414
+ // Order matters: this block must run BEFORE the /^invalid /i and
415
+ // /no auth token found/ regexes (which would otherwise misclassify
416
+ // the new `not_found` tag as `2` because the message starts with
417
+ // "Invalid ID").
418
+ const code = err.error_code;
419
+ if (typeof code === "string") {
420
+ if (code === "usage_error")
421
+ return 2;
422
+ if (code === "auth_failed")
423
+ return 3;
424
+ if (code === "not_found")
425
+ return 4;
426
+ }
427
+ // Auth-related client errors (e.g. missing token) — legacy regex
428
+ // path; the new error_code tagging above is the preferred route.
379
429
  if (/no auth token found|run "ish login"|saved token is invalid|session expired/i.test(err.message))
380
430
  return 3;
381
431
  // Client-side validation failures
@@ -393,8 +443,30 @@ export function exitCodeFromError(err) {
393
443
  // Structured error_kind on the Error object (set by chat endpoint test/init,
394
444
  // simulation routes, etc.). TunnelInactive is the canonical transient one.
395
445
  const kind = err.error_kind;
396
- if (typeof kind === "string" && kind === "TunnelInactive")
397
- return 5;
446
+ if (typeof kind === "string") {
447
+ // Transient: user can fix the cause and retry (tunnel down, bot
448
+ // auth credentials missing/wrong, upstream rate-limited).
449
+ if (kind === "TunnelInactive" || kind === "BotAuthError")
450
+ return 5;
451
+ // Validation-shaped: user passed something bad to the CLI/endpoint.
452
+ if (kind === "ConfirmationRequired" || kind === "BotShapeError")
453
+ return 2;
454
+ }
455
+ // (error_code mapping moved earlier in the function — see top of the
456
+ // `err instanceof Error` block. Order matters: it must run BEFORE
457
+ // the legacy regex sniffers to honor self-tagged errors.)
458
+ // Pattern E (ISSUE-021): DNS / connection failures are transient.
459
+ // Node's fetch surfaces them as TypeError with .cause = { code: "..." }.
460
+ const cause = err.cause;
461
+ if (cause && typeof cause === "object") {
462
+ const causeCode = cause.code;
463
+ if (typeof causeCode === "string" && (causeCode === "ENOTFOUND"
464
+ || causeCode === "ECONNREFUSED"
465
+ || causeCode === "ECONNRESET"
466
+ || causeCode === "ETIMEDOUT"
467
+ || causeCode === "EAI_AGAIN"))
468
+ return 5;
469
+ }
398
470
  }
399
471
  return 1;
400
472
  }
package/dist/lib/docs.js CHANGED
@@ -156,6 +156,25 @@ first scraping the list.
156
156
  The full saturated-account walkthrough (with branch logic + a worked
157
157
  transcript) lives at \`guides/cold-start\`.
158
158
 
159
+ ## Deleting a workspace
160
+
161
+ \`ish workspace delete <id>\` is the **highest-blast-radius destructive op
162
+ in the CLI** — it removes ALL nested studies, asks, people, secrets,
163
+ configs, sources, and chat endpoints. The confirmation guard is
164
+ mandatory:
165
+
166
+ - **Interactive (TTY)**: prompts on stderr naming the workspace; type
167
+ \`y\` to proceed.
168
+ - **Non-interactive** (\`--json\`, piped, or non-TTY stdin): pass
169
+ \`-y\` / \`--yes\` to confirm. Without it, the CLI exits with usage
170
+ code 2 rather than deleting silently.
171
+
172
+ \`\`\`
173
+ ish workspace delete w-6ec # interactive prompt
174
+ ish workspace delete w-6ec --yes # skip prompt
175
+ ish workspace delete w-6ec --json --yes # JSON/agent consumers must be explicit
176
+ \`\`\`
177
+
159
178
  ## Related
160
179
 
161
180
  - \`guides/cold-start\` — saturated-account first-step playbook
@@ -1083,12 +1102,32 @@ round-trips when you know them up front:
1083
1102
  - \`image:./hero-a.png\` — local image (auto-uploaded)
1084
1103
  - \`image:./a.png::label=A\` — with explicit label
1085
1104
 
1105
+ ## Deleting an ask
1106
+
1107
+ \`ish ask delete <id>\` requires explicit confirmation (parallels
1108
+ \`workspace delete\`, \`study delete\`, \`person delete\`, \`source
1109
+ delete\`, \`chat endpoint delete\`):
1110
+
1111
+ - **Interactive (TTY)**: prompts on stderr; type \`y\` to proceed.
1112
+ - **Non-interactive** (\`--json\`, piped, or non-TTY stdin): pass
1113
+ \`-y\` / \`--yes\` to confirm. Without it, the CLI exits with usage
1114
+ code 2 rather than deleting silently.
1115
+
1116
+ \`\`\`
1117
+ ish ask delete a-6ec # interactive prompt
1118
+ ish ask delete a-6ec --yes # skip prompt
1119
+ ish ask delete a-6ec --json --yes # JSON consumers must be explicit
1120
+ \`\`\`
1121
+
1122
+ The active ask is auto-cleared from \`~/.ish/config.json\` if the
1123
+ deleted ask was the active one.
1124
+
1086
1125
  ## Related
1087
1126
 
1088
1127
  - \`concepts/round\` — what a round is and how it executes.
1089
1128
  - \`concepts/people\` — how participants are chosen at ask creation.
1090
1129
  - \`concepts/run-verbs\` — \`ish ask run\` vs \`ish study run\`.
1091
- - \`reference/credits\` — ask rounds bill 1 credit per successful response.
1130
+ - \`reference/credits\` — ask rounds bill \`n_participants * (1 + len(questions))\` credits per round; \`questions\` follow-ups bill *per participant* on top of the base response, so a 3-person panel with 2 follow-up questions costs \`3 * (1 + 2) = 9\` credits when all complete (not 3).
1092
1131
  `;
1093
1132
  const CONCEPT_ROUND = `# concept: round
1094
1133
 
@@ -1261,6 +1300,21 @@ The legacy \`--tech-savviness\` flag was removed in
1261
1300
  \`person-schema-v2\`; passing it now produces commander's standard
1262
1301
  "unknown option" error.
1263
1302
 
1303
+ ## Deleting a person
1304
+
1305
+ \`ish person delete <id>\` requires explicit confirmation:
1306
+
1307
+ - **Interactive (TTY)**: prompts on stderr; type \`y\` to proceed.
1308
+ - **Non-interactive** (\`--json\`, piped, or non-TTY stdin): pass
1309
+ \`-y\` / \`--yes\` to confirm. Without it, the CLI exits with usage
1310
+ code 2 rather than deleting silently.
1311
+
1312
+ \`\`\`
1313
+ ish person delete p-d4e # interactive prompt
1314
+ ish person delete p-d4e --yes # skip prompt
1315
+ ish person delete p-d4e --json --yes # JSON consumers must be explicit
1316
+ \`\`\`
1317
+
1264
1318
  ## Related
1265
1319
 
1266
1320
  - \`concepts/source\` — the inputs to \`person generate\`.
@@ -1303,6 +1357,24 @@ in real customer evidence.
1303
1357
  ish source get ps-3a4
1304
1358
  \`\`\`
1305
1359
 
1360
+ ## Deleting a source
1361
+
1362
+ \`ish source delete <id>\` requires explicit confirmation:
1363
+
1364
+ - **Interactive (TTY)**: prompts on stderr; type \`y\` to proceed.
1365
+ - **Non-interactive** (\`--json\`, piped, or non-TTY stdin): pass
1366
+ \`-y\` / \`--yes\` to confirm. Without it, the CLI exits with usage
1367
+ code 2 rather than deleting silently.
1368
+
1369
+ \`\`\`
1370
+ ish source delete ps-3a4 # interactive prompt
1371
+ ish source delete ps-3a4 --yes # skip prompt
1372
+ ish source delete ps-3a4 --json --yes # JSON consumers must be explicit
1373
+ \`\`\`
1374
+
1375
+ The backend ref-counts the underlying file: the storage object is
1376
+ removed only when no profile mappings remain.
1377
+
1306
1378
  ## Related
1307
1379
 
1308
1380
  - \`concepts/person\` — sources feed profile generation.
@@ -1405,6 +1477,30 @@ manager"\` or \`"retail associate"\` return many. Two adaptations:
1405
1477
  - \`ish ask run\` (without \`--new\`) → cannot change participants; the ask
1406
1478
  fixes it at creation. Audience flags only apply with \`--new\`.
1407
1479
 
1480
+ ## Per-dispatch cap (20)
1481
+
1482
+ Each \`study run\` / \`ask run\` / \`chat\` dispatch is capped at **20
1483
+ participants** by the backend (\`max_length=20\` on the \`simulations\`
1484
+ list). The CLI enforces this client-side BEFORE the network round-trip
1485
+ so a too-large \`--sample\` or an unbounded \`--all\` returns a clear
1486
+ error instead of a confusing server-side \`validation_error\`:
1487
+
1488
+ \`\`\`
1489
+ $ ish study run --all # on a workspace with platform pool
1490
+ Error: Resolved 200 participants (no filter) but the backend caps each dispatch at 20.
1491
+ Pass \`--sample 20\` to randomly subsample the pool, narrow your filters, or run
1492
+ the dispatch multiple times against different slices. --all without --sample is
1493
+ only safe when the matching pool is ≤20.
1494
+
1495
+ $ ish study run --sample 25 # bad value caught before /people fetch
1496
+ Error: --sample 25 exceeds the per-dispatch participant cap of 20.
1497
+ Pass --sample 20 or fewer, or split the run into multiple dispatches.
1498
+ \`\`\`
1499
+
1500
+ For larger panels: dispatch multiple times against different demographic
1501
+ slices (\`--country SE\`, then \`--country GB\`, etc.) or use the web UI
1502
+ which batches behind the scenes.
1503
+
1408
1504
  ## Examples
1409
1505
 
1410
1506
  \`\`\`
@@ -2059,6 +2155,15 @@ The CLI guarantees these contracts so agents can chain safely:
2059
2155
  sentiment histogram + per-participant {alias, status, sentiment, comment,
2060
2156
  error_message}. Drops \`interview_answers\` and per-interaction
2061
2157
  breakdowns. Cheapest "did this run land?" shape.
2158
+ - **\`study get --json\` carries a flat top-level \`participants[]\`**
2159
+ (post backend-split). Each row carries \`iteration_id\` as a
2160
+ discriminator and the per-participant graph
2161
+ (\`person\`, \`interactions[]\`, \`participant_summary\`,
2162
+ \`interview_answers\`, \`conversation_id\`, …). The previous nesting
2163
+ under \`iterations[*].participants[*]\` is gone — read participants from
2164
+ the top level. The lite iteration list under \`iterations[]\` still
2165
+ carries each iteration's \`details\` and (for pair-mode chat) the
2166
+ conversation refs at \`iterations[*].conversations[]\`.
2062
2167
  - **\`study get --json\` carries assignment step completion** when an
2063
2168
  assignment has a checklist (see \`concepts/assignment\`). Each
2064
2169
  \`assignments[].step_completion[]\` row is
@@ -2245,17 +2350,33 @@ The CLI guarantees these contracts so agents can chain safely:
2245
2350
 
2246
2351
  ## Exit codes
2247
2352
 
2248
- | Code | Meaning |
2249
- |------|----------------------|
2250
- | 0 | Success |
2251
- | 1 | General error |
2252
- | 2 | Usage / validation |
2253
- | 3 | Auth (re-run \`ish login\`) |
2254
- | 4 | Not found |
2255
- | 5 | Transient — retryable (timeout, 5xx, network) |
2353
+ | Code | Meaning | Common \`error_code\` values |
2354
+ |------|----------------------|------------------------------|
2355
+ | 0 | Success | — |
2356
+ | 1 | General error | \`server\`, \`client_error\` (uncategorized) |
2357
+ | 2 | Usage / validation | \`usage_error\` (Commander), \`validation_error\` (server), \`ConfirmationRequired\` |
2358
+ | 3 | Auth (re-run \`ish login\`) | \`auth_failed\`, missing-token errors |
2359
+ | 4 | Not found | \`not_found\` |
2360
+ | 5 | Transient — retryable | \`timeout\`, \`TunnelInactive\`, \`BotAuthError\`, DNS / network (\`ENOTFOUND\`, \`ECONNREFUSED\`) |
2256
2361
 
2257
2362
  Use these to branch in scripts; do not parse the human stderr message.
2258
2363
 
2364
+ **Commander-level errors** (unknown command, missing required argument,
2365
+ missing required option) all exit **2** with \`error_code: "usage_error"\`.
2366
+ The suggestion field points at the right help target:
2367
+
2368
+ - Unknown command → \`Run \`ish --help\` for usage\` (the typo IS the
2369
+ command name — don't point at it; Commander also appends
2370
+ \`(Did you mean workspace?)\` for near-matches).
2371
+ - Missing argument / option → \`Run \`ish <command> --help\` for usage\`
2372
+ (substituted with the actual command, e.g. \`ish workspace --help\`).
2373
+
2374
+ **DNS / connection failures** (a wrong \`--api-url\`, a backend that's
2375
+ down, a captive portal) exit **5** so scripts retry rather than abort
2376
+ permanently. The underlying \`fetch\` \`TypeError\` is detected via its
2377
+ \`cause.code\` (\`ENOTFOUND\`, \`ECONNREFUSED\`, \`ECONNRESET\`,
2378
+ \`ETIMEDOUT\`, \`EAI_AGAIN\`).
2379
+
2259
2380
  ## Error envelope
2260
2381
 
2261
2382
  When a command fails with \`--json\` (or piped stdout), the CLI prints
@@ -2285,6 +2406,12 @@ a structured error object on **stdout** and a human message on
2285
2406
  (\`validation\`, \`auth\`, \`not_found\`, \`timeout\`, \`server\`,
2286
2407
  \`network\`, …). \`retryable: true\` matches exit code 5.
2287
2408
 
2409
+ The \`status\` field carries the upstream **HTTP status code** when one
2410
+ is available (e.g. \`401\`, \`404\`, \`422\`). It is **omitted entirely**
2411
+ from envelopes that don't originate from an HTTP response (Commander
2412
+ parse errors, local validation failures, alias-resolution errors). Do
2413
+ not branch on \`status: 0\` — that value is never emitted as of 0.20.
2414
+
2288
2415
  ## Conventions
2289
2416
 
2290
2417
  - Successful commands exit 0 and print one JSON object/array on stdout.
@@ -2402,13 +2529,19 @@ The CLI keeps a small amount of session state in \`~/.ish/config.json\`
2402
2529
  (or wherever \`ISH_HOME\` points) so commands don't need to repeat IDs:
2403
2530
 
2404
2531
  - \`access_token\` / \`refresh_token\` — the OAuth pair from \`ish login\`.
2405
- - \`workspace\` — set by \`ish workspace use <id>\`.
2406
- - \`study\` — set by \`ish study use <id>\`.
2407
- - \`ask\` — set by \`ish ask use <id>\`.
2532
+ - \`workspace\` — set by \`ish workspace use <id>\`.
2533
+ - \`study\` — set by \`ish study use <id>\` (or implicitly by \`ish study create\`).
2534
+ - \`ask\` — set by \`ish ask use <id>\` (or implicitly by \`ish ask create\`).
2535
+ - \`chat_endpoint\` — set by \`ish chat endpoint use <id>\`.
2408
2536
 
2409
2537
  Most commands fall back to these when their corresponding flag is
2410
2538
  omitted (\`--workspace\`, \`--study\`, \`--ask\`).
2411
2539
 
2540
+ **\`workspace\` is the parent** of \`study\`, \`ask\`, and \`chat_endpoint\` —
2541
+ all three are scoped to a single workspace. Switching workspaces
2542
+ (\`ish workspace use <other>\`) clears all three to avoid cross-workspace
2543
+ footguns, and the CLI prints a one-line stderr note when it does so.
2544
+
2412
2545
  ## Inspecting active context
2413
2546
 
2414
2547
  \`ish status\` (alias: \`ish whoami\`) is the canonical way to see what's
@@ -2421,7 +2554,8 @@ ish status
2421
2554
  # User: you@example.com (token valid, expires in 47m)
2422
2555
  # Workspace: Onboarding revamp (w-6ec)
2423
2556
  # Study: —
2424
- # Ask: a-6ec "tagline AB"
2557
+ # Ask: tagline AB (a-6ec)
2558
+ # Chat ep: —
2425
2559
  # Home: /home/you/.ish
2426
2560
  # API: https://api.ishlabs.io
2427
2561
  \`\`\`
@@ -2430,12 +2564,13 @@ JSON shape (\`ish status --json\` or piped):
2430
2564
 
2431
2565
  \`\`\`json
2432
2566
  {
2433
- "user": { "email": "...", "token_valid": true, "expires_in_seconds": 2820 },
2434
- "workspace": { "id": "...", "alias": "w-6ec", "name": "Onboarding revamp" },
2435
- "study": null,
2436
- "ask": { "id": "...", "alias": "a-6ec", "name": "tagline AB" },
2437
- "api_url": "https://api.ishlabs.io",
2438
- "home": "/home/you/.ish"
2567
+ "user": { "email": "...", "token_valid": true, "expires_in_seconds": 2820 },
2568
+ "workspace": { "id": "...", "alias": "w-6ec", "name": "Onboarding revamp" },
2569
+ "study": null,
2570
+ "ask": { "id": "...", "alias": "a-6ec", "name": "tagline AB" },
2571
+ "chat_endpoint": null,
2572
+ "api_url": "https://api.ishlabs.io",
2573
+ "home": "/home/you/.ish"
2439
2574
  }
2440
2575
  \`\`\`
2441
2576
 
@@ -2444,19 +2579,83 @@ JSON shape (\`ish status --json\` or piped):
2444
2579
  \`ish login\`. Safe to run unconditionally at the start of any
2445
2580
  script or agent session.
2446
2581
 
2582
+ ### \`ish login\` is idempotent
2583
+
2584
+ When you already have a valid saved token, \`ish login\` short-circuits
2585
+ with a friendly "Already logged in" message and **does not** open a new
2586
+ browser tab or register a fresh OAuth client. Use \`--force\` (or \`-f\`)
2587
+ to bypass the guard — typical reason is switching accounts.
2588
+
2589
+ \`\`\`bash
2590
+ ish login # no-op when already authenticated
2591
+ ish login --force # always re-run the browser flow
2592
+ \`\`\`
2593
+
2594
+ The short-circuit returns a structured envelope under \`--json\`:
2595
+
2596
+ \`\`\`json
2597
+ {
2598
+ "message": "Already logged in",
2599
+ "email": "you@example.com",
2600
+ "token_valid": true,
2601
+ "expires_in_seconds": 2820,
2602
+ "hint": "Pass --force to re-run the browser flow (e.g. to switch accounts)."
2603
+ }
2604
+ \`\`\`
2605
+
2606
+ ### Orphan / stale active refs
2607
+
2608
+ If an active ref points at an entity that no longer exists or moved
2609
+ workspace, \`status\` surfaces a \`warning\` field on that ref (instead
2610
+ of silently dropping the \`name\`). Each warned ref also gets a \`hint\`
2611
+ field with the exact command to clear or replace it:
2612
+
2613
+ \`\`\`json
2614
+ {
2615
+ "study": {
2616
+ "id": "...",
2617
+ "alias": "s-74d",
2618
+ "warning": "orphan — entity no longer exists in this workspace",
2619
+ "hint": "Active study is no longer accessible (deleted, moved workspace, or auth issue). Use \`ish study use <id>\` to switch, or \`ish study use --clear\` to drop."
2620
+ }
2621
+ }
2622
+ \`\`\`
2623
+
2624
+ In human output the warning prints as \`⚠ ...\` under the row and a
2625
+ follow-up line shows the hint.
2626
+
2447
2627
  ## Setting / clearing active context
2448
2628
 
2449
2629
  \`\`\`bash
2450
- ish workspace use w-6ec # set
2451
- ish workspace use --clear # clear
2630
+ ish workspace use w-6ec # set (also clears active study/ask/chat_endpoint if workspace changed)
2631
+ ish workspace use --clear # clear workspace + all workspace-scoped children
2452
2632
 
2453
2633
  ish study use s-b2c
2454
2634
  ish study use --clear
2455
2635
 
2456
2636
  ish ask use a-6ec
2457
2637
  ish ask use --clear
2638
+
2639
+ ish chat endpoint use ep-abc
2640
+ ish chat endpoint use --clear
2458
2641
  \`\`\`
2459
2642
 
2643
+ ### Auto-activation on create
2644
+
2645
+ \`ish study create\`, \`ish ask create\`, and \`ish workspace use\` all
2646
+ update the active context as a side-effect (so the natural next command
2647
+ — \`ish iteration create --study <new>\`, \`ish ask add-round\`, etc. —
2648
+ "just works" without re-typing the ID). The CLI **emits a one-line
2649
+ stderr notice** when this happens; consumers piping stdout get the new
2650
+ record while the auto-activate is visible to operators.
2651
+
2652
+ ### Cleanup on delete
2653
+
2654
+ \`ish workspace delete\`, \`ish study delete\`, \`ish ask delete\`, and
2655
+ \`ish chat endpoint delete\` automatically clear matching active refs
2656
+ from \`~/.ish/config.json\` so subsequent commands don't render orphans.
2657
+ \`workspace delete\` also clears all workspace-scoped children.
2658
+
2460
2659
  ## Overriding without persisting
2461
2660
 
2462
2661
  Every read command accepts \`--workspace <id>\`, \`--study <id>\`, or
@@ -3079,7 +3278,7 @@ ish study run stu-xyz --sample 5 --wait
3079
3278
 
3080
3279
  Pull raw interactions:
3081
3280
  \`\`\`
3082
- ish study results stu-xyz --json | jq '.interactions'
3281
+ ish study results stu-xyz --json | jq '.participants[].interactions'
3083
3282
  \`\`\`
3084
3283
 
3085
3284
  Note: chat is currently excluded from the LLM-analysis route; the
@@ -47,15 +47,15 @@ export declare function formatWorkspaceList(workspaces: Record<string, unknown>[
47
47
  export declare function formatWorkspaceDetail(workspace: Record<string, unknown>, json: boolean, options?: OutputOptions): void;
48
48
  export declare function formatSiteAccessStatus(summary: import("./site-access.js").SiteAccessSummary, json: boolean): void;
49
49
  export declare function formatStudyList(studies: Record<string, unknown>[], json: boolean): void;
50
- export declare function formatStudyDetail(study: Record<string, unknown>, json: boolean, options?: OutputOptions): void;
51
- export declare function formatStudyResults(study: Record<string, unknown>, json: boolean): void;
50
+ export declare function formatStudyDetail(study: Record<string, unknown>, json: boolean, options?: OutputOptions, participants?: ReadonlyArray<Record<string, unknown>>): void;
51
+ export declare function formatStudyResults(study: Record<string, unknown>, participants: ReadonlyArray<Record<string, unknown>>, json: boolean): void;
52
52
  /**
53
53
  * `study results --summary` projection. Drops interview_answers + per-participant
54
54
  * interaction breakdowns; keeps headline counters, sentiment histogram, and a
55
55
  * per-participant {alias, status, sentiment, comment} row. Useful for agents that
56
56
  * need to branch on outcome without paying for the full envelope.
57
57
  */
58
- export declare function buildStudyResultsSummary(study: Record<string, unknown>): Record<string, unknown>;
58
+ export declare function buildStudyResultsSummary(study: Record<string, unknown>, participants: ReadonlyArray<Record<string, unknown>>): Record<string, unknown>;
59
59
  /**
60
60
  * `study results --transcript <participant_id>` projection. Mirrors the schema
61
61
  * MCP's `get_chat_transcript` returns (`src/ish_mcp/projections.py: