@pugi/cli 0.1.0-beta.21 → 0.1.0-beta.23

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 (63) hide show
  1. package/dist/core/auth/env-provider.js +238 -0
  2. package/dist/core/bare-mode/index.js +107 -0
  3. package/dist/core/diagnostics/probes/bare-mode.js +42 -0
  4. package/dist/core/diagnostics/probes/pugi-md.js +89 -0
  5. package/dist/core/engine/native-pugi.js +55 -11
  6. package/dist/core/engine/prompts.js +30 -2
  7. package/dist/core/engine/tool-bridge.js +32 -0
  8. package/dist/core/feedback/queue.js +177 -0
  9. package/dist/core/feedback/submitter.js +145 -0
  10. package/dist/core/onboarding/marker.js +111 -0
  11. package/dist/core/onboarding/telemetry-state.js +108 -0
  12. package/dist/core/output-style/presets.js +176 -0
  13. package/dist/core/output-style/state.js +185 -0
  14. package/dist/core/permissions/index.js +1 -1
  15. package/dist/core/permissions/state.js +55 -0
  16. package/dist/core/pugi-md/context-injector.js +76 -0
  17. package/dist/core/pugi-md/walk-up.js +207 -0
  18. package/dist/core/release-notes/parser.js +241 -0
  19. package/dist/core/release-notes/state.js +116 -0
  20. package/dist/core/repl/session.js +482 -12
  21. package/dist/core/repl/slash-commands.js +134 -1
  22. package/dist/core/repl/workspace-context.js +22 -0
  23. package/dist/core/share/formatter.js +271 -0
  24. package/dist/core/share/redactor.js +221 -0
  25. package/dist/core/share/uploader.js +267 -0
  26. package/dist/core/theme/context.js +91 -0
  27. package/dist/core/theme/presets.js +228 -0
  28. package/dist/core/theme/state.js +181 -0
  29. package/dist/core/todos/invariant.js +10 -0
  30. package/dist/core/todos/state.js +177 -0
  31. package/dist/core/vim/keymap.js +288 -0
  32. package/dist/core/vim/state.js +92 -0
  33. package/dist/runtime/cli.js +603 -15
  34. package/dist/runtime/commands/doctor.js +21 -0
  35. package/dist/runtime/commands/feedback.js +184 -0
  36. package/dist/runtime/commands/onboarding.js +275 -0
  37. package/dist/runtime/commands/plan.js +143 -0
  38. package/dist/runtime/commands/release-notes.js +229 -0
  39. package/dist/runtime/commands/share.js +316 -0
  40. package/dist/runtime/commands/stickers.js +82 -0
  41. package/dist/runtime/commands/style.js +194 -0
  42. package/dist/runtime/commands/theme.js +196 -0
  43. package/dist/runtime/commands/vim.js +140 -0
  44. package/dist/runtime/version.js +1 -1
  45. package/dist/tools/registry.js +8 -0
  46. package/dist/tools/todo-write.js +184 -0
  47. package/dist/tui/compact-banner.js +28 -1
  48. package/dist/tui/conversation-pane.js +13 -0
  49. package/dist/tui/doctor-table.js +32 -17
  50. package/dist/tui/feedback-prompt.js +156 -0
  51. package/dist/tui/onboarding-wizard.js +240 -0
  52. package/dist/tui/repl-render.js +26 -3
  53. package/dist/tui/repl.js +9 -1
  54. package/dist/tui/stickers-art.js +136 -0
  55. package/dist/tui/style-table.js +28 -0
  56. package/dist/tui/theme-table.js +29 -0
  57. package/dist/tui/vim-input.js +267 -0
  58. package/package.json +2 -2
  59. package/dist/core/engine/compaction-hook.js +0 -154
  60. package/dist/core/init/scaffold.js +0 -195
  61. package/dist/core/repl/codebase-survey.js +0 -308
  62. package/dist/core/repl/init-interview.js +0 -457
  63. package/dist/core/repl/onboarding-state.js +0 -297
@@ -0,0 +1,229 @@
1
+ /**
2
+ * `pugi release-notes` — changelog diff between last-seen + current
3
+ * (Leak L24, 2026-05-27).
4
+ *
5
+ * Parity command with Claude Code's `/release-notes`, which shows
6
+ * what changed between the previously-installed CLI version and the
7
+ * currently-installed one. The Pugi variant reads the bundled
8
+ * `CHANGELOG.md`, slices it к the range `(last-seen, current]`, and
9
+ * renders the Markdown sections to the operator. After а successful
10
+ * render the marker is bumped к `current` so the next invocation is а
11
+ * no-op until the operator upgrades again.
12
+ *
13
+ * # Module contract
14
+ *
15
+ * - This file owns the WIRING from CLI flags + ambient state к the
16
+ * parser + state I/O helpers. The parser + state modules в
17
+ * `core/release-notes/` have zero coupling к the CLI dispatch
18
+ * surface.
19
+ *
20
+ * - `runReleaseNotesCommand` is the single entry point. Both the
21
+ * top-level `pugi release-notes` handler в `runtime/cli.ts` AND
22
+ * the in-REPL `/release-notes` slash command call it. The
23
+ * function returns а structured `ReleaseNotesResult` so the
24
+ * slash dispatcher can route the lines к the system pane
25
+ * without re-reading the changelog.
26
+ *
27
+ * - Exit code is ALWAYS 0. The command is informational, never а
28
+ * gate. Read failures, missing CHANGELOG, and write failures all
29
+ * degrade к а structured envelope with а human-readable footer.
30
+ *
31
+ * - The changelog source is captured behind а function so the spec
32
+ * can stub it without touching disk. The default reads the file
33
+ * bundled with the CLI install (resolved relative к the package
34
+ * root); fixtures pass an in-memory string.
35
+ *
36
+ * - `--reset` flag clears the last-seen marker AND re-renders the
37
+ * full bundled changelog as if the operator had never run the
38
+ * command. Distinct from а plain `--all` toggle because the
39
+ * reset PERSISTS (the next invocation again shows everything
40
+ * newer than the cleared marker — `none`).
41
+ */
42
+ import { existsSync, readFileSync } from 'node:fs';
43
+ import { homedir } from 'node:os';
44
+ import { dirname, resolve } from 'node:path';
45
+ import { fileURLToPath } from 'node:url';
46
+ import { parseChangelog, sliceVersionsBetween, } from '../../core/release-notes/parser.js';
47
+ import { clearLastSeenVersion, readLastSeenVersion, writeLastSeenVersion, } from '../../core/release-notes/state.js';
48
+ import { PUGI_CLI_VERSION } from '../version.js';
49
+ /**
50
+ * Default loader для the bundled `apps/pugi-cli/CHANGELOG.md`. The
51
+ * compiled bundle ships under `dist/runtime/commands/release-notes.js`;
52
+ * the CHANGELOG sits next к `package.json` at the package root, two
53
+ * directories up from `dist/runtime/commands/`. We also probe а
54
+ * couple of fallback locations so the dev path (running the source
55
+ * directly из `src/`) works без а compile step.
56
+ */
57
+ export function defaultReadChangelog() {
58
+ const candidates = resolveChangelogCandidates();
59
+ for (const candidate of candidates) {
60
+ try {
61
+ if (existsSync(candidate)) {
62
+ return readFileSync(candidate, 'utf8');
63
+ }
64
+ }
65
+ catch {
66
+ // Permission errors, transient FS hiccups — keep probing the
67
+ // remaining candidates. Returning null at the end is fine; the
68
+ // renderer surfaces а "changelog-missing" envelope.
69
+ }
70
+ }
71
+ return null;
72
+ }
73
+ function resolveChangelogCandidates() {
74
+ // import.meta.url points к the compiled JS in production
75
+ // (`dist/runtime/commands/release-notes.js`) and к the source TS в
76
+ // tests / dev runs. We probe both relative ancestries so either
77
+ // path lands on `<package>/CHANGELOG.md`.
78
+ try {
79
+ const here = dirname(fileURLToPath(import.meta.url));
80
+ return [
81
+ resolve(here, '../../..', 'CHANGELOG.md'),
82
+ resolve(here, '../../../..', 'CHANGELOG.md'),
83
+ resolve(process.cwd(), 'apps/pugi-cli/CHANGELOG.md'),
84
+ resolve(process.cwd(), 'CHANGELOG.md'),
85
+ ];
86
+ }
87
+ catch {
88
+ // Some non-ESM contexts (very old node, eval'd code) reject
89
+ // `import.meta.url`. Fall back к cwd-relative probes — works for
90
+ // tests that run from the package root.
91
+ return [
92
+ resolve(process.cwd(), 'apps/pugi-cli/CHANGELOG.md'),
93
+ resolve(process.cwd(), 'CHANGELOG.md'),
94
+ ];
95
+ }
96
+ }
97
+ /**
98
+ * Default home dir resolver. Centralised so the CLI handler can call
99
+ * `runReleaseNotesCommand` without re-importing `os.homedir`.
100
+ */
101
+ export function defaultReleaseNotesHome() {
102
+ return homedir();
103
+ }
104
+ /**
105
+ * Pick + render the release notes, hand the result к the output
106
+ * sink, persist the marker. Always exits 0.
107
+ */
108
+ export function runReleaseNotesCommand(ctx) {
109
+ const readChangelog = ctx.readChangelog ?? defaultReadChangelog;
110
+ const currentVersion = ctx.currentVersion ?? PUGI_CLI_VERSION;
111
+ // `--reset` clears the marker before slicing. We capture the
112
+ // pre-clear value so the JSON envelope still shows the operator
113
+ // what their previous marker was, which makes scripting + bug
114
+ // reports easier.
115
+ const lastSeenBefore = readLastSeenVersion(ctx.home);
116
+ if (ctx.reset) {
117
+ clearLastSeenVersion(ctx.home);
118
+ }
119
+ const lastSeen = ctx.reset ? null : lastSeenBefore;
120
+ const raw = readChangelog();
121
+ if (raw === null) {
122
+ const result = {
123
+ command: 'release-notes',
124
+ currentVersion,
125
+ lastSeenVersion: lastSeenBefore ?? 'none',
126
+ sections: [],
127
+ status: 'changelog-missing',
128
+ markerPersisted: false,
129
+ persistFailure: null,
130
+ text: renderMissingChangelog(currentVersion),
131
+ };
132
+ ctx.writeOutput(result, result.text);
133
+ process.exitCode = 0;
134
+ return result;
135
+ }
136
+ const sections = parseChangelog(raw);
137
+ if (sections.length === 0) {
138
+ const result = {
139
+ command: 'release-notes',
140
+ currentVersion,
141
+ lastSeenVersion: lastSeenBefore ?? 'none',
142
+ sections: [],
143
+ status: 'changelog-empty',
144
+ markerPersisted: false,
145
+ persistFailure: null,
146
+ text: renderEmptyChangelog(currentVersion),
147
+ };
148
+ ctx.writeOutput(result, result.text);
149
+ process.exitCode = 0;
150
+ return result;
151
+ }
152
+ const slice = sliceVersionsBetween(sections, lastSeen, currentVersion);
153
+ if (slice.length === 0) {
154
+ // Nothing new — render the no-op message and DO NOT touch the
155
+ // marker (marker already equals current OR is newer; either way
156
+ // re-writing it is а no-op write we can avoid).
157
+ const result = {
158
+ command: 'release-notes',
159
+ currentVersion,
160
+ lastSeenVersion: lastSeenBefore ?? 'none',
161
+ sections: [],
162
+ status: 'up-to-date',
163
+ markerPersisted: false,
164
+ persistFailure: null,
165
+ text: renderUpToDate(currentVersion, lastSeenBefore),
166
+ };
167
+ ctx.writeOutput(result, result.text);
168
+ process.exitCode = 0;
169
+ return result;
170
+ }
171
+ const persist = writeLastSeenVersion(ctx.home, currentVersion);
172
+ const text = renderSections(slice, currentVersion, lastSeen, persist);
173
+ const result = {
174
+ command: 'release-notes',
175
+ currentVersion,
176
+ lastSeenVersion: lastSeenBefore ?? 'none',
177
+ sections: slice,
178
+ status: ctx.reset ? 'reset' : 'rendered',
179
+ markerPersisted: persist.status === 'ok',
180
+ persistFailure: persist.status === 'failed' ? persist.reason : null,
181
+ text,
182
+ };
183
+ ctx.writeOutput(result, text);
184
+ process.exitCode = 0;
185
+ return result;
186
+ }
187
+ function renderSections(sections, current, lastSeen, persist) {
188
+ const header = lastSeen
189
+ ? `Pugi release notes — ${lastSeen} → ${current}`
190
+ : `Pugi release notes — up to ${current}`;
191
+ const blocks = [header, '═'.repeat(Math.max(header.length, 30))];
192
+ for (const section of sections) {
193
+ const subhead = section.date
194
+ ? `## [${section.version}] - ${section.date}`
195
+ : `## [${section.version}]`;
196
+ blocks.push('');
197
+ blocks.push(subhead);
198
+ if (section.body.length > 0) {
199
+ blocks.push('');
200
+ blocks.push(section.body);
201
+ }
202
+ }
203
+ if (persist.status === 'failed') {
204
+ blocks.push('');
205
+ blocks.push(`Warning: could not persist last-seen marker (${persist.reason}). Next run will surface the same notes.`);
206
+ }
207
+ return blocks.join('\n');
208
+ }
209
+ function renderUpToDate(current, lastSeen) {
210
+ const lines = ['No new release notes.'];
211
+ lines.push(`Installed: ${current}`);
212
+ lines.push(`Last seen: ${lastSeen ?? 'none'}`);
213
+ return lines.join('\n');
214
+ }
215
+ function renderMissingChangelog(current) {
216
+ return [
217
+ 'Release notes are not bundled with this install.',
218
+ `Installed: ${current}`,
219
+ 'See https://pugi.io/changelog for the rendered changelog.',
220
+ ].join('\n');
221
+ }
222
+ function renderEmptyChangelog(current) {
223
+ return [
224
+ 'Bundled changelog is empty — no parsed sections.',
225
+ `Installed: ${current}`,
226
+ 'See https://pugi.io/changelog for the rendered changelog.',
227
+ ].join('\n');
228
+ }
229
+ //# sourceMappingURL=release-notes.js.map
@@ -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