@pugi/cli 0.1.0-beta.20 → 0.1.0-beta.22

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 (40) hide show
  1. package/dist/core/bare-mode/index.js +107 -0
  2. package/dist/core/diagnostics/probes/bare-mode.js +42 -0
  3. package/dist/core/engine/native-pugi.js +21 -10
  4. package/dist/core/engine/prompts.js +30 -2
  5. package/dist/core/engine/tool-bridge.js +32 -0
  6. package/dist/core/feedback/queue.js +177 -0
  7. package/dist/core/feedback/submitter.js +145 -0
  8. package/dist/core/onboarding/marker.js +111 -0
  9. package/dist/core/onboarding/telemetry-state.js +108 -0
  10. package/dist/core/output-style/presets.js +176 -0
  11. package/dist/core/output-style/state.js +185 -0
  12. package/dist/core/permissions/index.js +1 -1
  13. package/dist/core/permissions/state.js +55 -0
  14. package/dist/core/repl/session.js +375 -12
  15. package/dist/core/repl/slash-commands.js +99 -1
  16. package/dist/core/repl/workspace-context.js +22 -0
  17. package/dist/core/share/formatter.js +271 -0
  18. package/dist/core/share/redactor.js +221 -0
  19. package/dist/core/share/uploader.js +267 -0
  20. package/dist/core/todos/invariant.js +10 -0
  21. package/dist/core/todos/state.js +177 -0
  22. package/dist/runtime/cli.js +386 -1
  23. package/dist/runtime/commands/doctor.js +8 -0
  24. package/dist/runtime/commands/feedback.js +184 -0
  25. package/dist/runtime/commands/onboarding.js +275 -0
  26. package/dist/runtime/commands/plan.js +143 -0
  27. package/dist/runtime/commands/share.js +316 -0
  28. package/dist/runtime/commands/stickers.js +82 -0
  29. package/dist/runtime/commands/style.js +194 -0
  30. package/dist/runtime/version.js +1 -1
  31. package/dist/tools/registry.js +8 -0
  32. package/dist/tools/todo-write.js +184 -0
  33. package/dist/tui/compact-banner.js +28 -1
  34. package/dist/tui/conversation-pane.js +13 -0
  35. package/dist/tui/feedback-prompt.js +156 -0
  36. package/dist/tui/onboarding-wizard.js +240 -0
  37. package/dist/tui/repl-render.js +9 -1
  38. package/dist/tui/stickers-art.js +136 -0
  39. package/dist/tui/style-table.js +22 -0
  40. package/package.json +2 -2
@@ -0,0 +1,316 @@
1
+ /**
2
+ * `pugi share` / `/share` command handler — Leak L20 (2026-05-27).
3
+ *
4
+ * Exports the current session transcript as Markdown to either a GitHub
5
+ * Gist (default when `gh` is available + auth'd) or a pugi.io public URL
6
+ * (`--pugi`). Mirrors Claude Code's `/share` ergonomics — operator can
7
+ * pin a session for portfolio / debugging / team sharing without copy-
8
+ * pasting the REPL pane by hand.
9
+ *
10
+ * Subcommands / flags (see L20 spec):
11
+ *
12
+ * pugi share Default upload — picks gist when available,
13
+ * falls back to pugi.io.
14
+ * pugi share --gist Force gist target; refuses if `gh` is not
15
+ * installed / authenticated.
16
+ * pugi share --pugi Force pugi.io target.
17
+ * pugi share --redact Run PII scrubber first; shows finding
18
+ * counts in the privacy gate banner.
19
+ * pugi share --preview Print transcript to stdout WITHOUT
20
+ * upload. Always implies a redact step IF
21
+ * `--redact` is also set so the operator
22
+ * inspects the scrubbed shape, not the raw.
23
+ * pugi share --yes Skip the y/n confirmation prompt
24
+ * (CI / scripted callers). Default is
25
+ * ALWAYS to ask before uploading. Refuses
26
+ * if the heuristic detects an active
27
+ * `Bearer ` credential regardless of `--yes`.
28
+ * pugi share --json Emit the result envelope as JSON.
29
+ *
30
+ * Privacy gates (mandatory):
31
+ *
32
+ * 1. Active credential heuristic — refuses upload entirely when the
33
+ * transcript contains a live `Bearer <token>` span. Operators who
34
+ * want to share a debug session that captured an auth header MUST
35
+ * run `--redact` first; the redactor masks the credential before
36
+ * the upload path sees it.
37
+ * 2. Confirmation prompt — y/n question shown to the operator before
38
+ * every upload. Bypassed with `--yes`. Refuses upload on `n` /
39
+ * empty / Ctrl-C.
40
+ * 3. Redact preview — when `--redact` is set, the gate banner shows
41
+ * the per-category finding counts BEFORE the upload prompt so the
42
+ * operator sees what would leave the machine.
43
+ *
44
+ * Same handler powers both `pugi share` (top-level) and `/share`
45
+ * (in-REPL slash). The slash side wires `writeOutput` to the REPL's
46
+ * `appendSystemLine` and never hits stdout directly.
47
+ */
48
+ import { existsSync, readFileSync } from 'node:fs';
49
+ import { resolve } from 'node:path';
50
+ import { createInterface } from 'node:readline/promises';
51
+ import { formatTranscript } from '../../core/share/formatter.js';
52
+ import { containsActiveCredential, redactPii, summariseFindings, } from '../../core/share/redactor.js';
53
+ import { uploadShare, } from '../../core/share/uploader.js';
54
+ export function parseShareFlags(args) {
55
+ const flags = {
56
+ target: 'auto',
57
+ redact: false,
58
+ preview: false,
59
+ yes: false,
60
+ json: false,
61
+ };
62
+ for (const arg of args) {
63
+ if (arg === '--gist')
64
+ flags.target = 'gist';
65
+ else if (arg === '--pugi')
66
+ flags.target = 'pugi';
67
+ else if (arg === '--redact')
68
+ flags.redact = true;
69
+ else if (arg === '--preview')
70
+ flags.preview = true;
71
+ else if (arg === '--yes' || arg === '-y')
72
+ flags.yes = true;
73
+ else if (arg === '--json')
74
+ flags.json = true;
75
+ }
76
+ return flags;
77
+ }
78
+ export async function runShareCommand(args, ctx) {
79
+ const flags = parseShareFlags(args);
80
+ const eventsPath = resolve(ctx.workspaceRoot, '.pugi/events.jsonl');
81
+ if (!existsSync(eventsPath)) {
82
+ ctx.writeOutput({
83
+ command: 'share',
84
+ status: 'no_session',
85
+ message: '.pugi/events.jsonl not found',
86
+ }, 'pugi share: no session log found. Run any pugi command first to create .pugi/events.jsonl.');
87
+ process.exitCode = 2;
88
+ return;
89
+ }
90
+ // Read + format. The formatter walks the events stream once; size cap
91
+ // is implicit (we do not chunk multi-GB files because session logs are
92
+ // capped at a few MB by the cost-tracker / compaction subsystems).
93
+ const eventsJsonl = readFileSync(eventsPath, 'utf8');
94
+ const sessionId = ctx.sessionId ?? deriveSessionIdFromEvents(eventsJsonl) ?? 'no-session';
95
+ const formatted = formatTranscript({
96
+ sessionId,
97
+ workspaceRoot: ctx.workspaceRoot,
98
+ cliVersion: ctx.cliVersion,
99
+ eventsJsonl,
100
+ now: ctx.now,
101
+ });
102
+ // Active-credential gate. Refuses even with `--yes`; redact-first IS
103
+ // the only path to share a transcript with a Bearer token. We check
104
+ // BEFORE redact so the operator's intent is clear in the gate banner.
105
+ const hasLiveCredential = containsActiveCredential(formatted.markdown);
106
+ if (hasLiveCredential && !flags.redact) {
107
+ ctx.writeOutput({
108
+ command: 'share',
109
+ status: 'refused_active_credential',
110
+ message: 'Transcript contains an active Bearer credential. Re-run with --redact to scrub it before sharing.',
111
+ }, 'pugi share: refused — transcript contains an active `Bearer ` credential. ' +
112
+ 'Re-run with --redact to scrub it before sharing, or open .pugi/events.jsonl to inspect manually.');
113
+ process.exitCode = 4;
114
+ return;
115
+ }
116
+ // Optional redact pass. We run BEFORE the preview/upload decisions so
117
+ // the operator sees what would actually leave their machine.
118
+ let body = formatted.markdown;
119
+ let redactionSummary = null;
120
+ let redactionFindings = [];
121
+ if (flags.redact) {
122
+ const result = redactPii(body);
123
+ body = result.output;
124
+ redactionSummary = summariseFindings(result);
125
+ redactionFindings = result.findings;
126
+ }
127
+ // Preview path. Always non-destructive: prints the (possibly redacted)
128
+ // transcript + the redact summary, no upload, no prompt. Operators
129
+ // chain `--preview --redact` to see what would be shared before they
130
+ // commit, which is the L20 spec's "inspect first" affordance.
131
+ if (flags.preview) {
132
+ const payload = {
133
+ command: 'share',
134
+ status: 'preview',
135
+ sessionId,
136
+ turnCount: formatted.turnCount,
137
+ eventCount: formatted.eventCount,
138
+ redact: flags.redact,
139
+ redactionSummary,
140
+ redactionFindings,
141
+ markdown: body,
142
+ };
143
+ const text = [
144
+ redactionSummary ? `${redactionSummary}` : null,
145
+ '--- transcript preview (not uploaded) ---',
146
+ body,
147
+ ]
148
+ .filter((line) => line !== null)
149
+ .join('\n');
150
+ ctx.writeOutput(payload, text);
151
+ return;
152
+ }
153
+ // Resolve the target. `auto` picks gist if `gh` is available, else
154
+ // falls back to pugi.io. The probe is best-effort — a missing `gh`
155
+ // surfaces as `ghAvailable -> false` and we route to pugi without an
156
+ // error.
157
+ const resolvedTarget = await pickTarget(flags.target, ctx);
158
+ // Confirmation gate. Refused by default unless `--yes`.
159
+ if (!flags.yes) {
160
+ const promptText = redactionSummary
161
+ ? `${redactionSummary} Share session transcript to ${resolvedTarget}? [y/N] `
162
+ : `Share session transcript to ${resolvedTarget}? [y/N] `;
163
+ const answer = (await ((ctx.promptYesNo ?? defaultPromptYesNo)(promptText))).trim().toLowerCase();
164
+ if (answer !== 'y' && answer !== 'yes') {
165
+ ctx.writeOutput({
166
+ command: 'share',
167
+ status: 'cancelled',
168
+ target: resolvedTarget,
169
+ message: 'Operator declined the upload.',
170
+ }, 'pugi share: cancelled.');
171
+ return;
172
+ }
173
+ }
174
+ // Resolve pugi.io credentials lazily — gist target does not need them.
175
+ let credential = null;
176
+ if (resolvedTarget === 'pugi') {
177
+ credential = ctx.resolveCredential ? await safeResolveCredential(ctx.resolveCredential) : null;
178
+ }
179
+ const uploadReq = {
180
+ target: resolvedTarget,
181
+ sessionId,
182
+ markdown: body,
183
+ description: `Pugi session ${sessionId}`,
184
+ ...(credential?.apiUrl !== undefined ? { apiUrl: credential.apiUrl } : {}),
185
+ ...(credential?.apiToken !== undefined ? { apiToken: credential.apiToken } : {}),
186
+ ...(ctx.execaLike !== undefined ? { execaLike: ctx.execaLike } : {}),
187
+ ...(ctx.fetchLike !== undefined ? { fetchLike: ctx.fetchLike } : {}),
188
+ };
189
+ const result = await uploadShare(uploadReq);
190
+ emitUploadResult(ctx, sessionId, resolvedTarget, redactionSummary, redactionFindings, result);
191
+ }
192
+ /**
193
+ * Default-target selection. `--gist` / `--pugi` are honoured verbatim;
194
+ * `auto` consults the `gh` probe and picks gist when available. We
195
+ * deliberately do not cache the probe — it costs one syscall and the
196
+ * operator might `gh auth login` between two `pugi share` runs.
197
+ */
198
+ async function pickTarget(requested, ctx) {
199
+ if (requested === 'gist')
200
+ return 'gist';
201
+ if (requested === 'pugi')
202
+ return 'pugi';
203
+ // auto
204
+ const probe = ctx.ghAvailable ?? defaultGhAvailable(ctx.execaLike);
205
+ return (await probe()) ? 'gist' : 'pugi';
206
+ }
207
+ function defaultGhAvailable(execaLike) {
208
+ return async () => {
209
+ if (!execaLike) {
210
+ // Production: try to spawn `gh --version`. The default execa shim
211
+ // in uploader.ts is the right one but importing it here would
212
+ // create a small cycle; instead we replicate the minimal probe.
213
+ try {
214
+ const { defaultExecaLike } = await import('../../core/share/uploader.js');
215
+ const result = await defaultExecaLike('gh', ['--version']);
216
+ return result.exitCode === 0;
217
+ }
218
+ catch {
219
+ return false;
220
+ }
221
+ }
222
+ try {
223
+ const result = await execaLike('gh', ['--version']);
224
+ return result.exitCode === 0;
225
+ }
226
+ catch {
227
+ return false;
228
+ }
229
+ };
230
+ }
231
+ async function defaultPromptYesNo(question) {
232
+ if (!process.stdin.isTTY) {
233
+ // Non-interactive caller without --yes: refuse rather than block on
234
+ // an empty stdin. Mirrors the install-trust pattern in skills.ts.
235
+ process.stdout.write(`${question}\n(non-interactive stdin; declining)\n`);
236
+ return 'n';
237
+ }
238
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
239
+ try {
240
+ return await rl.question(question);
241
+ }
242
+ finally {
243
+ rl.close();
244
+ }
245
+ }
246
+ async function safeResolveCredential(resolver) {
247
+ try {
248
+ return await resolver();
249
+ }
250
+ catch {
251
+ return null;
252
+ }
253
+ }
254
+ /**
255
+ * Walk the JSONL log from the tail and pick the newest `session.created`
256
+ * id. Mirrors the helper in cost.ts so the two surfaces agree on what
257
+ * "current session" means.
258
+ */
259
+ function deriveSessionIdFromEvents(raw) {
260
+ const lines = raw.split('\n').filter((line) => line.trim().length > 0);
261
+ for (let i = lines.length - 1; i >= 0; i -= 1) {
262
+ try {
263
+ const parsed = JSON.parse(lines[i]);
264
+ if (parsed.type === 'session' && parsed.name === 'created' && typeof parsed.sessionId === 'string') {
265
+ return parsed.sessionId;
266
+ }
267
+ }
268
+ catch {
269
+ // skip
270
+ }
271
+ }
272
+ return null;
273
+ }
274
+ function emitUploadResult(ctx, sessionId, target, redactionSummary, redactionFindings, result) {
275
+ if (result.ok) {
276
+ const payload = {
277
+ command: 'share',
278
+ status: 'ok',
279
+ sessionId,
280
+ target,
281
+ url: result.url,
282
+ remoteId: result.remoteId ?? null,
283
+ redact: redactionSummary !== null,
284
+ redactionSummary,
285
+ redactionFindings,
286
+ };
287
+ const text = [
288
+ redactionSummary,
289
+ `pugi share: uploaded to ${target}.`,
290
+ `URL: ${result.url}`,
291
+ ]
292
+ .filter((line) => line !== null)
293
+ .join('\n');
294
+ ctx.writeOutput(payload, text);
295
+ return;
296
+ }
297
+ const payload = {
298
+ command: 'share',
299
+ status: 'upload_failed',
300
+ sessionId,
301
+ target,
302
+ reason: result.reason,
303
+ message: result.message,
304
+ redact: redactionSummary !== null,
305
+ redactionSummary,
306
+ };
307
+ const text = [
308
+ redactionSummary,
309
+ `pugi share: ${result.reason} — ${result.message}`,
310
+ ]
311
+ .filter((line) => line !== null)
312
+ .join('\n');
313
+ ctx.writeOutput(payload, text);
314
+ process.exitCode = 3;
315
+ }
316
+ //# sourceMappingURL=share.js.map
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `pugi stickers` — brand-personality gimmick command (Leak L33, 2026-05-27).
3
+ *
4
+ * Parity command with Claude Code's `/stickers` easter egg. Claude
5
+ * ships physical stickers OR shows ASCII brand art; Pugi's variant
6
+ * focuses на the ASCII branch — picks one of the curated pug-face
7
+ * variants at random and footers it with a rotating brand quote.
8
+ *
9
+ * # Module contract
10
+ *
11
+ * - This file owns the WIRING from CLI flags + ambient state to the
12
+ * art + quote pickers. The corpus + pure renderers live in
13
+ * `tui/stickers-art.tsx` and have zero coupling к the CLI dispatch
14
+ * surface.
15
+ *
16
+ * - `runStickersCommand` is the single entry point. Both the top-
17
+ * level `pugi stickers` handler в `runtime/cli.ts` AND the in-REPL
18
+ * `/stickers` slash command call it. The function returns the
19
+ * resolved `StickersResult` so the slash dispatcher can route the
20
+ * output к the REPL's system pane without re-picking the art.
21
+ *
22
+ * - Exit code is ALWAYS 0. The command is a brand surface — never a
23
+ * gate. Even when the corpus is somehow exhausted (impossible
24
+ * today, the lists are frozen), the handler synthesises a fallback
25
+ * line and exits 0 instead of crashing.
26
+ *
27
+ * - The random source is injected so the spec can pin the chosen
28
+ * art + quote without monkey-patching `Math.random`.
29
+ */
30
+ import { PUG_QUOTES, PUG_STICKERS, pickArtVariant, pickQuote, renderPugStickersText, } from '../../tui/stickers-art.js';
31
+ /**
32
+ * Pick + render the sticker, hand it к the output sink, exit 0.
33
+ * Returns the picked result so the REPL slash handler can mount the
34
+ * Ink renderer without re-picking.
35
+ */
36
+ export function runStickersCommand(ctx) {
37
+ const rng = ctx.rng ?? Math.random;
38
+ let art;
39
+ let quote;
40
+ try {
41
+ art = pickArtVariant(rng);
42
+ quote = pickQuote(rng);
43
+ }
44
+ catch {
45
+ // Defensive: the pickers are pure + the corpus is frozen, so this
46
+ // path is unreachable in production. If a future refactor swaps
47
+ // the corpus к an empty array we still want к exit 0 with a
48
+ // deterministic fallback so monitoring scripts that probe
49
+ // `pugi stickers` do not flap.
50
+ art = {
51
+ id: 'fallback',
52
+ caption: 'fallback',
53
+ art: '/\\___/\\\n( o o )\n( =^= )',
54
+ };
55
+ quote = 'Pugi: your engineering co-pilot.';
56
+ }
57
+ const text = renderPugStickersText(art, quote);
58
+ const result = {
59
+ command: 'stickers',
60
+ art,
61
+ quote,
62
+ text,
63
+ meta: {
64
+ artVariants: PUG_STICKERS.length,
65
+ quotes: PUG_QUOTES.length,
66
+ },
67
+ };
68
+ ctx.writeOutput(result, text);
69
+ // Brand surface — never a gate. The caller may have set a different
70
+ // exit code (e.g. dispatch loop reused this handler for an inline
71
+ // brand banner); we explicitly stamp 0 so `pugi stickers && echo ok`
72
+ // stays predictable.
73
+ process.exitCode = 0;
74
+ // Silence the unused-import warning in the rare case `ctx.asciiOnly`
75
+ // is added in a future surface without a switch. Today the flag is
76
+ // honoured by the CLI handler choosing the writeOutput sink — the
77
+ // result.text is the same regardless because the boxed renderer
78
+ // never lands в the plain stdout sink.
79
+ void ctx.asciiOnly;
80
+ return result;
81
+ }
82
+ //# sourceMappingURL=stickers.js.map
@@ -0,0 +1,194 @@
1
+ /**
2
+ * Leak L18 (2026-05-27) — `pugi style` top-level command + REPL slash
3
+ * companion.
4
+ *
5
+ * Operator surface:
6
+ *
7
+ * pugi style Show active preset + table.
8
+ * pugi style <name> Switch workspace preset (current cwd).
9
+ * pugi style <name> --persist Switch + also write user default.
10
+ * pugi style --reset Clear workspace override → back to default.
11
+ * pugi style --reset --user Also clear the user default.
12
+ * pugi style --list Print the catalogue (no flip).
13
+ * pugi style --json Structured envelope variant.
14
+ *
15
+ * The same runner powers `/style` from inside the REPL. The REPL
16
+ * dispatcher (see `core/repl/session.ts`) routes through here so the
17
+ * two surfaces stay single-sourced — operators trained on one read
18
+ * the same payload + table on the other.
19
+ *
20
+ * Exit codes:
21
+ * 0 — show / switch / reset all succeed
22
+ * 1 — unknown preset slug (returned BEFORE any write)
23
+ * 2 — conflicting flags (e.g. `--reset` with a positional slug)
24
+ *
25
+ * The exit codes are surfaced through `process.exitCode` by the
26
+ * dispatcher in `cli.ts` — this module returns a structured payload
27
+ * + writes via the injected `writeOutput`. Throwing is reserved for
28
+ * truly unexpected errors (fs permissions etc.); the spec hooks the
29
+ * happy + sad paths through `writeOutput` shape, not via try/catch
30
+ * on the throw.
31
+ */
32
+ import { DEFAULT_OUTPUT_STYLE, isOutputStyleSlug, OUTPUT_STYLE_SLUGS, renderStyleTable, } from '../../core/output-style/presets.js';
33
+ import { clearUserOutputStyle, clearWorkspaceOutputStyle, resolveOutputStyle, setUserOutputStyle, setWorkspaceOutputStyle, } from '../../core/output-style/state.js';
34
+ /**
35
+ * Entry point. Parses `args`, applies the operation, emits the
36
+ * payload + text via `ctx.writeOutput`, and returns the exit code the
37
+ * dispatcher should hand back to the shell.
38
+ */
39
+ export async function runStyleCommand(args, ctx) {
40
+ const flags = parseFlags(args);
41
+ // Reset path
42
+ if (flags.reset) {
43
+ if (flags.slug !== null) {
44
+ const payload = buildPayload({
45
+ status: 'invalid_flags',
46
+ ctx,
47
+ message: '/style --reset cannot be combined with a preset name. Use one or the other.',
48
+ });
49
+ ctx.writeOutput(payload, payload.message);
50
+ return 2;
51
+ }
52
+ if (flags.persist) {
53
+ const payload = buildPayload({
54
+ status: 'invalid_flags',
55
+ ctx,
56
+ message: '/style --reset cannot be combined with --persist. Use --reset --user to also clear the user default.',
57
+ });
58
+ ctx.writeOutput(payload, payload.message);
59
+ return 2;
60
+ }
61
+ clearWorkspaceOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
62
+ if (flags.user) {
63
+ clearUserOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
64
+ }
65
+ const payload = buildPayload({
66
+ status: 'reset',
67
+ ctx,
68
+ message: flags.user
69
+ ? `Cleared workspace + user output style. Active: ${DEFAULT_OUTPUT_STYLE} (default).`
70
+ : `Cleared workspace output style. Active: ${describeActive(ctx)}.`,
71
+ });
72
+ ctx.writeOutput(payload, payload.message);
73
+ return 0;
74
+ }
75
+ // List path
76
+ if (flags.list && flags.slug === null) {
77
+ const resolved = resolveOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
78
+ const payload = buildPayload({
79
+ status: 'listed',
80
+ ctx,
81
+ message: renderStyleTable(resolved.slug),
82
+ });
83
+ ctx.writeOutput(payload, payload.message);
84
+ return 0;
85
+ }
86
+ // Switch path
87
+ if (flags.slug !== null) {
88
+ if (!isOutputStyleSlug(flags.slug)) {
89
+ const payload = buildPayload({
90
+ status: 'invalid_slug',
91
+ ctx,
92
+ attemptedSlug: flags.slug,
93
+ message: `Unknown style "${flags.slug}". Try one of: ${OUTPUT_STYLE_SLUGS.join(', ')}.`,
94
+ });
95
+ ctx.writeOutput(payload, payload.message);
96
+ return 1;
97
+ }
98
+ const before = resolveOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
99
+ setWorkspaceOutputStyle(flags.slug, { workspaceRoot: ctx.workspaceRoot, env: ctx.env });
100
+ if (flags.persist) {
101
+ setUserOutputStyle(flags.slug, { workspaceRoot: ctx.workspaceRoot, env: ctx.env });
102
+ }
103
+ const tail = flags.persist ? ' (workspace + user default)' : ' (workspace)';
104
+ const payload = buildPayload({
105
+ status: 'switched',
106
+ ctx,
107
+ previous: before.slug,
108
+ persistedToUser: flags.persist,
109
+ message: `Output style → ${flags.slug}${tail}. Was: ${before.slug} (${before.source}).`,
110
+ });
111
+ ctx.writeOutput(payload, payload.message);
112
+ return 0;
113
+ }
114
+ // Show path (no args)
115
+ const resolved = resolveOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
116
+ const banner = `Active output style: ${resolved.slug} (${resolved.source})`;
117
+ const table = renderStyleTable(resolved.slug);
118
+ const payload = buildPayload({
119
+ status: 'show',
120
+ ctx,
121
+ message: `${banner}\n\n${table}`,
122
+ });
123
+ ctx.writeOutput(payload, payload.message);
124
+ return 0;
125
+ }
126
+ function describeActive(ctx) {
127
+ const resolved = resolveOutputStyle({ workspaceRoot: ctx.workspaceRoot, env: ctx.env });
128
+ return `${resolved.slug} (${resolved.source})`;
129
+ }
130
+ function buildPayload(args) {
131
+ const resolved = resolveOutputStyle({ workspaceRoot: args.ctx.workspaceRoot, env: args.ctx.env });
132
+ const payload = {
133
+ command: 'style',
134
+ status: args.status,
135
+ active: resolved.slug,
136
+ source: resolved.source,
137
+ presets: OUTPUT_STYLE_SLUGS,
138
+ message: args.message,
139
+ };
140
+ if (args.previous !== undefined)
141
+ payload.previous = args.previous;
142
+ if (args.persistedToUser !== undefined)
143
+ payload.persistedToUser = args.persistedToUser;
144
+ if (args.attemptedSlug !== undefined)
145
+ payload.attemptedSlug = args.attemptedSlug;
146
+ return payload;
147
+ }
148
+ function parseFlags(args) {
149
+ const flags = {
150
+ slug: null,
151
+ persist: false,
152
+ reset: false,
153
+ user: false,
154
+ list: false,
155
+ };
156
+ for (const arg of args) {
157
+ if (arg === '--persist')
158
+ flags.persist = true;
159
+ else if (arg === '--reset')
160
+ flags.reset = true;
161
+ else if (arg === '--user')
162
+ flags.user = true;
163
+ else if (arg === '--list')
164
+ flags.list = true;
165
+ else if (arg.startsWith('-')) {
166
+ // Unknown flag — keep simple parser. Treat as positional so the
167
+ // downstream isOutputStyleSlug check rejects it with a clear
168
+ // "unknown style" message rather than swallowing silently.
169
+ if (flags.slug === null)
170
+ flags.slug = arg;
171
+ }
172
+ else if (flags.slug === null) {
173
+ flags.slug = arg;
174
+ }
175
+ }
176
+ // Normalise the slug to lowercase so `pugi style TERSE` works the
177
+ // same as `pugi style terse`. The catalogue is lowercase-only by
178
+ // contract; this keeps operators from tripping on shift-key habits.
179
+ if (flags.slug !== null)
180
+ flags.slug = flags.slug.toLowerCase();
181
+ return flags;
182
+ }
183
+ /**
184
+ * Re-export for the slash-command dispatcher in `core/repl/session.ts`
185
+ * so it can render a compiled prompt block when the operator runs
186
+ * `/style --preview` (follow-up surface; current slash returns the
187
+ * runner's standard payload).
188
+ *
189
+ * Kept here so the runtime module is the single import point for
190
+ * style-related surfaces; consumers should NOT reach into
191
+ * `core/output-style/*` directly.
192
+ */
193
+ export { OUTPUT_STYLES as OUTPUT_STYLE_CATALOGUE, } from '../../core/output-style/presets.js';
194
+ //# sourceMappingURL=style.js.map
@@ -44,7 +44,7 @@ export function sanitizeSemver(raw) {
44
44
  * during import). When bumping the CLI version BOTH literals must be
45
45
  * updated; the release smoke-test (`pack:smoke`) verifies they agree.
46
46
  */
47
- export const PUGI_CLI_VERSION = sanitizeSemver('0.1.0-beta.20');
47
+ export const PUGI_CLI_VERSION = sanitizeSemver('0.1.0-beta.22');
48
48
  /**
49
49
  * Outbound: the CLI's installed semver. Read at request time by
50
50
  * `version-interceptor.ts` and injected on every `fetch` call.
@@ -33,6 +33,14 @@ const registry = [
33
33
  { name: 'task_get', permission: 'none', risk: 'low', concurrencySafe: true, m1: true },
34
34
  { name: 'task_list', permission: 'none', risk: 'low', concurrencySafe: true, m1: true },
35
35
  { name: 'task_update', permission: 'none', risk: 'low', concurrencySafe: false, m1: true },
36
+ // Leak L16 (2026-05-27): batch TodoWrite. Mirrors Claude Code's upstream
37
+ // surface — full board snapshot, single-in-progress invariant, atomic
38
+ // tmp+rename persistence to `.pugi/todos.json`. `concurrencySafe = false`
39
+ // because two concurrent writes could lose the loser's snapshot (the
40
+ // rename is atomic but the read-modify-write loop is not). Risk = low
41
+ // because the only filesystem mutation lands inside `.pugi/todos.json`,
42
+ // which is metadata, not source.
43
+ { name: 'todo_write', permission: 'none', risk: 'low', concurrencySafe: false, m1: true },
36
44
  { name: 'web_fetch', permission: 'network', risk: 'medium', concurrencySafe: true, m1: true },
37
45
  // α7.7: scratch worktree management. `worktree_create` writes nothing
38
46
  // dangerous (a clone under `.pugi/worktrees/`); `worktree_promote`