diff --git a/.trail/learnings/2026-11-17-share-session-s-preview-is-four-anirudhkumar.md b/.trail/learnings/2026-11-17-share-session-s-preview-is-four-anirudhkumar.md new file mode 100644 index 000000000..2d8477ade --- /dev/null +++ b/.trail/learnings/2026-11-17-share-session-s-preview-is-four-anirudhkumar.md @@ -0,0 +1,32 @@ +--- +title: "share-session's preview is four short sections, then one line that says what to type: y, n, or folder numbers to leave out" +author: Anirudhkumar-nanonets +date: 2026-11-17 +branch: fix/share-ask-offers-leave-out +cost: { minutes: 42, tokens: 740869 } +id: l-9cb501d1 +scope: repo +status: active +replaces: l-69e4953a +src: agent +touches: + - src/cloud/share-bundle.ts + - src/cli.ts + - test/share-bundle.test.ts +--- + +## Decided +- The preview stays four headed sections: what's sent, from these folders, removed before sending, after you say yes. Its last line is where the copy is. A flat list of about 15 rows made a teammate miss the question entirely (16 Nov). +- After it comes one line saying what to type and what each answer does, then a bare `→` prompt: "Type y to send it all, n to send nothing, or folder numbers to leave out (like 2 3)." Enter still sends nothing. +- Folder numbers are offered whenever more than one folder is still in. With only "→ Send it? [y/N]", Aarsh (17 Nov) didn't know folders could be kept back, though typing numbers still worked. +- Leaving out can happen more than once: the preview is shown again with what's left, and the line asks about "the rest". The example numbers never name every folder still in, and a folder already left out can't be picked again. + +## Tried and ruled out +- "→ Send it? [y/N, or folder numbers to leave out]": two questions in one line. The user (17 Nov) asked for a line that says what to enter instead. +- Dropping the folder option from the question (16 Nov): people couldn't find it. +- "Not sent" as the heading of the removed list: too terse. The heading is "Removed before sending". + +## Watch out +- Review copy changes in a real terminal: run `node --import tsx src/bin/trail.ts share-session --once` under `script` with a throwaway HOME (a `~/.trail/cloud.json` pointing at a local stand-in that answers `/api/cli/shared-sessions/allowed` and the POST). Type the answers after the prompt shows: piped input ends first and reads as no. + +In the code: `sendAsk` and `parseLeaveOut` in src/cloud/share-bundle.ts; the answer loop in `shareWholeClaude` in src/cli.ts. diff --git a/src/cli.ts b/src/cli.ts index f9e34ea2c..9624ba967 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -132,7 +132,7 @@ import { trackFirstRunIfNew, } from "./telemetry/index.js"; import { bundleSession, listLines, MAX_GZ_BYTES, pickSession, previewLines, redactedCount, sessionsHere, shortId, sizeLabel, whoIAm } from "./cloud/share-session.js"; -import { bundlePreviewLines, deleteCode, deleteHash, itemPayload, leaveOut, newCopyDir, newSentState, parseDeleteCode, parseLeaveOut, prepareBundle, readSent, SEND_ASK, SEND_REST_ASK, unfinishedCopy, writeSent, type Manifest, type SentState } from "./cloud/share-bundle.js"; +import { bundlePreviewLines, deleteCode, deleteHash, itemPayload, leaveOut, newCopyDir, newSentState, parseDeleteCode, parseLeaveOut, prepareBundle, readSent, sendAsk, unfinishedCopy, writeSent, type Manifest, type SentState } from "./cloud/share-bundle.js"; import { trailHome } from "./notes/trail-home.js"; import { readSyncState, runSync, syncDir, writeSyncState, type SyncState } from "./cloud/share-sync.js"; import { hasShareSyncHook, installShareSyncHook, removeShareSyncHook, settingsPath, type HookResult } from "./cloud/share-hook.js"; @@ -2841,8 +2841,9 @@ async function shareWholeClaude(cloud: Cloud, opts: { days: number; leaveOut?: s track("share_bundle", { outcome: "declined", items_bucket: shareItemsBucket(m.items.length), size_bucket: shareSizeBucket(bundleGz(m)) }, { repo: checkout }); console.error("· nothing sent, and the copy is deleted"); }; + // Asked until y or n: folders can be left out in more than one go, and the preview shows what's left each time. for (;;) { - const a = await askLine(SEND_ASK); + const a = await askLine(sendAsk(m, m.dropped.length > 0)); if (a === null || /^(n|no)?$/i.test(a)) return declined(); if (/^y(es)?$/i.test(a)) return void (await sendCopy(cloud, out, m, newSentState(), checkout, opts.sync)); const ns = parseLeaveOut(a, m); @@ -2852,8 +2853,6 @@ async function shareWholeClaude(cloud: Cloud, opts: { days: number; leaveOut?: s } m = leaveOut(out, m, ns); show(); - if (await askYes(SEND_REST_ASK)) return void (await sendCopy(cloud, out, m, newSentState(), checkout, opts.sync)); - return declined(); } } diff --git a/src/cloud/share-bundle.ts b/src/cloud/share-bundle.ts index dee04aa76..a46775a58 100644 --- a/src/cloud/share-bundle.ts +++ b/src/cloud/share-bundle.ts @@ -224,7 +224,8 @@ export function parseLeaveOut(answer: string, m: Manifest): number[] | null { const parts = answer.split(/[\s,]+/).filter(Boolean); if (!parts.length || !parts.every((p) => /^\d{1,4}$/.test(p))) return null; const ns = [...new Set(parts.map(Number))]; - return ns.every((n) => m.folders.some((f) => f.n === n)) ? ns : null; + // Only folders still in: one already left out is no longer on the list. + return ns.every((n) => m.folders.some((f) => f.n === n && !m.dropped.includes(f.label))) ? ns : null; } /** Take the numbered folders out of the copy: their files go, and the summary says so. */ @@ -311,16 +312,27 @@ function plural(n: number, one: string, many = `${one}s`): string { return `${n} ${n === 1 ? one : many}`; } -/** The question after the preview: always its last line, with Enter meaning no. */ -export const SEND_ASK = "→ Send it? [y/N] "; -/** Asked again after folders were left out. */ -export const SEND_REST_ASK = "→ Send the rest? [y/N] "; +/** + * What to type after the preview: one line that says each answer and what it + * does, then the `→` prompt, so nobody has to guess what a question with three + * answers wants. Folder numbers are offered while more than one folder is in: + * with "→ Send it? [y/N]" alone, a teammate didn't know folders could be kept + * back. Enter still sends nothing. `rest`: asked again after some were left out. + */ +export function sendAsk(m: Manifest, rest = false): string { + const kept = m.folders.filter((f) => !m.dropped.includes(f.label)); + const what = rest ? "the rest" : kept.length > 1 ? "it all" : "it"; + if (kept.length < 2) return `Type y to send ${what}, or n to send nothing.\n→ `; + // The example never names every folder still in: that would send nothing but the setup. + const example = kept.slice(kept.length > 2 ? -2 : -1).map((f) => f.n).join(" "); + return `Type y to send ${what}, n to send nothing, or ${rest ? "more " : ""}folder numbers to leave out (like ${example}).\n→ `; +} /** * What will be sent, for the person to say yes to, in four short sections: * what's sent, from which folders, what isn't, and what happens after yes. * `copy` is the folder as shown (`~/.trail/share/…`). The send question - * (`SEND_ASK`) follows it, so nothing here may read like the last line. + * (`sendAsk`) follows it, so nothing here may read like the last line. */ export function bundlePreviewLines(m: Manifest, copy: string, to: { url: string }, opts: { sync?: string } = {}): string[] { const sessions = m.items.filter((it) => it.kind === "session"); diff --git a/test/share-bundle.test.ts b/test/share-bundle.test.ts index 0fc8b30fe..ab9d69013 100644 --- a/test/share-bundle.test.ts +++ b/test/share-bundle.test.ts @@ -24,6 +24,7 @@ import { parseLeaveOut, prepareBundle, readManifest, + sendAsk, unfinishedCopy, writeSent, } from "../src/cloud/share-bundle.js"; @@ -139,6 +140,19 @@ test("parseLeaveOut and leaveOut: folder numbers drop those folders' files from assert.deepEqual(readdirSync(join(out, "sessions")), ["work-web"]); assert.match(readFileSync(join(out, "SUMMARY.md"), "utf8"), /2\. \/work\/api · 1 session · left out/); assert.match(bundlePreviewLines(next, "~/x", { url: "https://team.trailhq.com" }).join("\n"), /^ {2}1 folder you left out: \/work\/api$/m); + assert.equal(parseLeaveOut("2", next), null, "a folder already left out is no longer on the list"); +}); + +test("sendAsk: says what to type, folder numbers included while more than one folder is in, then asks about the rest", () => { + const { out, m } = prepared(); + // A teammate saw only "→ Send it? [y/N]" and asked how to keep a folder back: the numbers worked, nothing said so. + assert.equal(sendAsk(m), "Type y to send it all, n to send nothing, or folder numbers to leave out (like 2).\n→ "); + const one = leaveOut(out, m, [2]); + assert.equal(sendAsk(one, true), "Type y to send the rest, or n to send nothing.\n→ ", "one folder left: leaving it out would send nothing"); + assert.equal(sendAsk({ ...m, folders: [m.folders[0]!] }), "Type y to send it, or n to send nothing.\n→ "); + const three = { ...m, folders: [...m.folders, { n: 3, label: "/work/docs", sessions: 1 }] }; + assert.equal(sendAsk(three), "Type y to send it all, n to send nothing, or folder numbers to leave out (like 2 3).\n→ ", "the example never names every folder"); + assert.equal(sendAsk({ ...three, dropped: ["/work/api"] }, true), "Type y to send the rest, n to send nothing, or more folder numbers to leave out (like 3).\n→ "); }); test("itemPayload: a session goes as its zipped file, the setup zipped on the way", () => {