Repository navigation
feat(shell cards): Shell cards with minimal content and customize selection between default and minimal #1836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Alan-TheGentleman
merged 3 commits into
Gentleman-Programming:main
from
carolitascl:feat/card-content-minimal-cards
Oct 8, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4fb668c
feat(cards): Card content preference with minimal command-only cards
carolitascl b23dcb3
feat(cards): extend minimal command-only cards to every quiet tool
carolitascl 6d8f7b6
Merge main into feat/card-content-minimal-cards with review fixes
Alan-TheGentleman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| import { mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs"; | ||
| import { randomUUID } from "node:crypto"; | ||
| import { join } from "node:path"; | ||
| import { gentlePiConfigHome } from "./agent-home.ts"; | ||
|
|
||
| // The conversation card content level chosen in Gentle → Customize. `default` | ||
| // keeps the quiet tools' result previews; `minimal` draws every quiet tool | ||
| // card as the command alone. A missing file means default, so nobody loses the | ||
| // previews without choosing to; a malformed or unreadable one also reads as | ||
| // default, and the writer refuses | ||
| // to replace it so a hand edit is never lost. There is no environment override. | ||
| export const CARD_CONTENT_SCHEMA = "gentle-pi.card-content/v1"; | ||
| const CARD_CONTENT_FILE = "card-content.json"; | ||
|
|
||
| export const CARD_CONTENT = { | ||
| DEFAULT: "default", | ||
| MINIMAL: "minimal", | ||
| } as const; | ||
|
|
||
| export type CardContent = (typeof CARD_CONTENT)[keyof typeof CARD_CONTENT]; | ||
|
|
||
| interface CardContentOptions { gentlePiConfigHome?: string } | ||
|
|
||
| export interface CardContentResolution { | ||
| content: CardContent; | ||
| source: "global_file" | "default"; | ||
| malformed: boolean; | ||
| globalFile: string; | ||
| } | ||
|
|
||
| function isCardContent(value: unknown): value is CardContent { | ||
| return value === CARD_CONTENT.DEFAULT || value === CARD_CONTENT.MINIMAL; | ||
| } | ||
|
|
||
| export function parseCardContentFile(raw: string): CardContent | undefined { | ||
| try { | ||
| const value: unknown = JSON.parse(raw); | ||
| if (typeof value !== "object" || value === null || Array.isArray(value)) return undefined; | ||
| if (Object.keys(value).length !== 2 || !("schema" in value) || value.schema !== CARD_CONTENT_SCHEMA || !("content" in value)) return undefined; | ||
| return isCardContent(value.content) ? value.content : undefined; | ||
| } catch { return undefined; } | ||
| } | ||
|
|
||
| export function resolveCardContent(options: CardContentOptions = {}): CardContentResolution { | ||
| const globalFile = join(options.gentlePiConfigHome ?? gentlePiConfigHome(), CARD_CONTENT_FILE); | ||
| try { | ||
| const content = parseCardContentFile(readFileSync(globalFile, "utf8")); | ||
| return { content: content ?? CARD_CONTENT.DEFAULT, source: "global_file", malformed: content === undefined, globalFile }; | ||
| } catch (error) { | ||
| const missing = typeof error === "object" && error !== null && "code" in error && error.code === "ENOENT"; | ||
| return { content: CARD_CONTENT.DEFAULT, source: missing ? "default" : "global_file", malformed: !missing, globalFile }; | ||
| } | ||
| } | ||
|
|
||
| export function writeCardContent(content: CardContent, options: CardContentOptions = {}): string { | ||
| if (!isCardContent(content)) throw new TypeError("Invalid card content"); | ||
| const home = options.gentlePiConfigHome ?? gentlePiConfigHome(); | ||
| const current = resolveCardContent({ gentlePiConfigHome: home }); | ||
| if (current.malformed) throw new Error(`Cannot update malformed or unreadable card content preference: ${current.globalFile}`); | ||
| const path = current.globalFile; | ||
| const temporary = `${path}.${randomUUID()}.tmp`; | ||
| mkdirSync(home, { recursive: true }); | ||
| try { | ||
| writeFileSync(temporary, `${JSON.stringify({ schema: CARD_CONTENT_SCHEMA, content })}\n`, { flag: "wx", mode: 0o600 }); | ||
| renameSync(temporary, path); | ||
| } finally { | ||
| try { unlinkSync(temporary); } catch { /* Rename consumed the temporary file. */ } | ||
| } | ||
| return path; | ||
| } | ||
|
|
||
| // Pi loads every extension with its own module cache, so the renderers in | ||
| // quiet-tools and the customize command in gentle-shell never share a module | ||
| // instance. The process-wide slot keeps one live content level per process, | ||
| // exactly like the card style slot; an unset slot reads as default. | ||
| const CARD_CONTENT_SLOT = Symbol.for("gentle-pi.card-content"); | ||
| const contentState = globalThis as typeof globalThis & { [CARD_CONTENT_SLOT]?: unknown }; | ||
|
|
||
| export function cardContent(): CardContent { | ||
| return contentState[CARD_CONTENT_SLOT] === CARD_CONTENT.MINIMAL ? CARD_CONTENT.MINIMAL : CARD_CONTENT.DEFAULT; | ||
| } | ||
|
|
||
| export function setCardContent(content: CardContent): void { | ||
| contentState[CARD_CONTENT_SLOT] = content; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { test } from "node:test"; | ||
| import assert from "node:assert/strict"; | ||
| import { chmodSync, existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import { join } from "node:path"; | ||
| import { CARD_CONTENT, CARD_CONTENT_SCHEMA, cardContent, parseCardContentFile, resolveCardContent, setCardContent, writeCardContent } from "../lib/card-content-policy.ts"; | ||
|
|
||
| const home = () => mkdtempSync(join(tmpdir(), "gentle-card-content-")); | ||
|
|
||
| test("a missing preference means the default content level", () => { | ||
| const dir = home(); | ||
| assert.deepEqual(resolveCardContent({ gentlePiConfigHome: dir }), { content: "default", source: "default", malformed: false, globalFile: join(dir, "card-content.json") }); | ||
| }); | ||
|
|
||
| test("the preference round-trips through the atomic writer", () => { | ||
| const dir = home(); | ||
| const path = writeCardContent(CARD_CONTENT.MINIMAL, { gentlePiConfigHome: dir }); | ||
| assert.equal(path, join(dir, "card-content.json")); | ||
| assert.deepEqual(JSON.parse(readFileSync(path, "utf8")), { schema: CARD_CONTENT_SCHEMA, content: "minimal" }); | ||
| assert.deepEqual(resolveCardContent({ gentlePiConfigHome: dir }), { content: "minimal", source: "global_file", malformed: false, globalFile: path }); | ||
| writeCardContent(CARD_CONTENT.DEFAULT, { gentlePiConfigHome: dir }); | ||
| assert.equal(resolveCardContent({ gentlePiConfigHome: dir }).content, "default"); | ||
| assert.deepEqual(readdirSync(dir), ["card-content.json"], "no temporary file survives the rename"); | ||
| }); | ||
|
|
||
| test("the writer rejects values outside the content domain", () => { | ||
| const dir = home(); | ||
| assert.throws(() => writeCardContent("clean" as never, { gentlePiConfigHome: dir }), TypeError); | ||
| assert.equal(existsSync(join(dir, "card-content.json")), false); | ||
| }); | ||
|
|
||
| test("invalid or unreadable preference files read as default and are never overwritten", () => { | ||
| for (const raw of ["", "{", "[]", "null", `{"schema":"${CARD_CONTENT_SCHEMA}","content":"clean"}`, `{"schema":"other/v1","content":"minimal"}`, `{"schema":"${CARD_CONTENT_SCHEMA}","content":"default","extra":1}`]) { | ||
| assert.equal(parseCardContentFile(raw), undefined, raw); | ||
| const dir = home(); | ||
| const path = join(dir, "card-content.json"); | ||
| writeFileSync(path, raw); | ||
| assert.deepEqual(resolveCardContent({ gentlePiConfigHome: dir }), { content: "default", source: "global_file", malformed: true, globalFile: path }, raw); | ||
| assert.throws(() => writeCardContent(CARD_CONTENT.MINIMAL, { gentlePiConfigHome: dir }), /Cannot update malformed or unreadable card content preference/, raw); | ||
| assert.equal(readFileSync(path, "utf8"), raw, "the malformed file is preserved"); | ||
| } | ||
| const dir = home(); | ||
| mkdirSync(join(dir, "card-content.json")); | ||
| assert.equal(resolveCardContent({ gentlePiConfigHome: dir }).malformed, true, "a directory in its place is unreadable, not missing"); | ||
| if (process.getuid?.() !== 0) { | ||
| const locked = home(); | ||
| writeCardContent(CARD_CONTENT.MINIMAL, { gentlePiConfigHome: locked }); | ||
| chmodSync(join(locked, "card-content.json"), 0o000); | ||
| try { | ||
| assert.deepEqual({ ...resolveCardContent({ gentlePiConfigHome: locked }), globalFile: "" }, { content: "default", source: "global_file", malformed: true, globalFile: "" }); | ||
| } finally { | ||
| chmodSync(join(locked, "card-content.json"), 0o600); | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| test("the live slot shares one content level per process and an unset slot reads default", (t) => { | ||
| const slot = Symbol.for("gentle-pi.card-content"); | ||
| const state = globalThis as typeof globalThis & { [slot]?: unknown }; | ||
| const found = state[slot]; | ||
| t.after(() => { state[slot] = found; }); | ||
| delete state[slot]; | ||
| assert.equal(cardContent(), CARD_CONTENT.DEFAULT); | ||
| setCardContent(CARD_CONTENT.DEFAULT); | ||
| assert.equal(cardContent(), CARD_CONTENT.DEFAULT); | ||
| setCardContent(CARD_CONTENT.MINIMAL); | ||
| assert.equal(cardContent(), CARD_CONTENT.MINIMAL); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Re-apply the saved card content on
session_start.applyCardStyle()runs again in thesession_starthandler (Line 1795).applyCardContent()runs only once, at factory time. The two cases behave differently:card-content.json, the live slot keeps the stale value until Pi rebuilds the extension runtime.Call
applyCardContent()next toapplyCardStyle()in thesession_starthandler.🤖 Prompt for AI Agents