@pugi/cli 0.1.0-beta.21 → 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.
- package/dist/core/bare-mode/index.js +107 -0
- package/dist/core/diagnostics/probes/bare-mode.js +42 -0
- package/dist/core/engine/native-pugi.js +21 -10
- package/dist/core/engine/prompts.js +30 -2
- package/dist/core/engine/tool-bridge.js +32 -0
- package/dist/core/feedback/queue.js +177 -0
- package/dist/core/feedback/submitter.js +145 -0
- package/dist/core/onboarding/marker.js +111 -0
- package/dist/core/onboarding/telemetry-state.js +108 -0
- package/dist/core/output-style/presets.js +176 -0
- package/dist/core/output-style/state.js +185 -0
- package/dist/core/permissions/index.js +1 -1
- package/dist/core/permissions/state.js +55 -0
- package/dist/core/repl/session.js +375 -12
- package/dist/core/repl/slash-commands.js +99 -1
- package/dist/core/repl/workspace-context.js +22 -0
- package/dist/core/share/formatter.js +271 -0
- package/dist/core/share/redactor.js +221 -0
- package/dist/core/share/uploader.js +267 -0
- package/dist/core/todos/invariant.js +10 -0
- package/dist/core/todos/state.js +177 -0
- package/dist/runtime/cli.js +386 -1
- package/dist/runtime/commands/doctor.js +8 -0
- package/dist/runtime/commands/feedback.js +184 -0
- package/dist/runtime/commands/onboarding.js +275 -0
- package/dist/runtime/commands/plan.js +143 -0
- package/dist/runtime/commands/share.js +316 -0
- package/dist/runtime/commands/stickers.js +82 -0
- package/dist/runtime/commands/style.js +194 -0
- package/dist/runtime/version.js +1 -1
- package/dist/tools/registry.js +8 -0
- package/dist/tools/todo-write.js +184 -0
- package/dist/tui/compact-banner.js +28 -1
- package/dist/tui/conversation-pane.js +13 -0
- package/dist/tui/feedback-prompt.js +156 -0
- package/dist/tui/onboarding-wizard.js +240 -0
- package/dist/tui/repl-render.js +9 -1
- package/dist/tui/stickers-art.js +136 -0
- package/dist/tui/style-table.js +22 -0
- package/package.json +2 -2
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* todo_write tool — Leak L16 (TodoWrite single-in-progress invariant).
|
|
3
|
+
*
|
|
4
|
+
* Mirrors Claude Code's `TodoWrite` tool 1:1 so a model trained on the
|
|
5
|
+
* upstream grammar speaks Pugi's variant verbatim. The tool dispatches
|
|
6
|
+
* a BATCH replace of the workspace todo board (not an incremental
|
|
7
|
+
* mutation — the model emits the FULL list every call). At most ONE
|
|
8
|
+
* todo may carry `status: 'in_progress'` at any time; violations
|
|
9
|
+
* reject with the `TODO_INVARIANT_VIOLATED` sentinel and the board on
|
|
10
|
+
* disk is left unchanged.
|
|
11
|
+
*
|
|
12
|
+
* Relationship to `task_*` (β1 T1/T6, tools/tasks.ts):
|
|
13
|
+
* - `task_*` is GRANULAR (create/get/list/update one task at a
|
|
14
|
+
* time) with an append-only JSONL journal scoped to the SESSION.
|
|
15
|
+
* - `todo_write` is BATCH (snapshot the whole board) with an atomic
|
|
16
|
+
* JSON snapshot scoped to the WORKSPACE.
|
|
17
|
+
* They are complementary surfaces: agents that prefer the upstream
|
|
18
|
+
* TodoWrite grammar use `todo_write`; agents that want a fine-grained
|
|
19
|
+
* audit trail use `task_*`.
|
|
20
|
+
*
|
|
21
|
+
* Hard rules (enforced by Zod + dispatcher):
|
|
22
|
+
* - `todos.length` ≤ 50 (board overload guard).
|
|
23
|
+
* - Every item: id (≥1 char, ≤128), content (≥1 char), status enum.
|
|
24
|
+
* - At most ONE item with `status === 'in_progress'`.
|
|
25
|
+
* - All ids unique within the batch.
|
|
26
|
+
*
|
|
27
|
+
* Dispatch returns the persisted board as JSON; callers can read
|
|
28
|
+
* `todos: [...]` directly. Errors return the sentinel-prefixed message
|
|
29
|
+
* so the engine adapter can pattern-match.
|
|
30
|
+
*/
|
|
31
|
+
import { z } from 'zod';
|
|
32
|
+
import { saveTodoBoard } from '../core/todos/state.js';
|
|
33
|
+
/** Cap matches the `task_*` family's title cap for parity. */
|
|
34
|
+
export const TODO_CONTENT_MAX = 2_000;
|
|
35
|
+
/** id is opaque to us but must be slug-safe so file paths could embed it. */
|
|
36
|
+
export const TODO_ID_MIN = 1;
|
|
37
|
+
export const TODO_ID_MAX = 128;
|
|
38
|
+
/** Hard cap on board size. Beyond this the operator should split work. */
|
|
39
|
+
export const TODO_BATCH_MAX = 50;
|
|
40
|
+
export const todoItemSchema = z
|
|
41
|
+
.strictObject({
|
|
42
|
+
id: z
|
|
43
|
+
.string()
|
|
44
|
+
.min(TODO_ID_MIN)
|
|
45
|
+
.max(TODO_ID_MAX)
|
|
46
|
+
.describe('Stable id for this todo. Opaque, ≤128 chars.'),
|
|
47
|
+
content: z
|
|
48
|
+
.string()
|
|
49
|
+
.min(1)
|
|
50
|
+
.max(TODO_CONTENT_MAX)
|
|
51
|
+
.describe('Imperative task description. E.g. "Add invariant check".'),
|
|
52
|
+
status: z
|
|
53
|
+
.enum(['pending', 'in_progress', 'completed'])
|
|
54
|
+
.describe('Lifecycle status. At most ONE in_progress per board.'),
|
|
55
|
+
activeForm: z
|
|
56
|
+
.string()
|
|
57
|
+
.min(1)
|
|
58
|
+
.max(TODO_CONTENT_MAX)
|
|
59
|
+
.optional()
|
|
60
|
+
.describe('Present-continuous form. E.g. "Adding invariant check".'),
|
|
61
|
+
});
|
|
62
|
+
export const todoWriteArgsSchema = z.strictObject({
|
|
63
|
+
todos: z
|
|
64
|
+
.array(todoItemSchema)
|
|
65
|
+
.max(TODO_BATCH_MAX)
|
|
66
|
+
.describe(`Full todo board (batch replace, not incremental). Max ${TODO_BATCH_MAX} items. ` +
|
|
67
|
+
`At most ONE item may carry status="in_progress".`),
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* JSON-Schema fragment surfaced to the model via the tool-bridge
|
|
71
|
+
* `parameters` field. Mirrors the Zod schema 1:1 — kept hand-written
|
|
72
|
+
* (same convention as ask_user_question) because the runtime engine
|
|
73
|
+
* wires OpenAI-compatible JSON Schema and we have not greenlit the
|
|
74
|
+
* zod-to-json-schema transitive dep. Keep both in lockstep.
|
|
75
|
+
*/
|
|
76
|
+
export const todoWriteJsonSchema = {
|
|
77
|
+
type: 'object',
|
|
78
|
+
additionalProperties: false,
|
|
79
|
+
required: ['todos'],
|
|
80
|
+
properties: {
|
|
81
|
+
todos: {
|
|
82
|
+
type: 'array',
|
|
83
|
+
maxItems: TODO_BATCH_MAX,
|
|
84
|
+
description: `Full todo board (batch replace, not incremental). Max ${TODO_BATCH_MAX} items. ` +
|
|
85
|
+
`At most ONE item may carry status="in_progress".`,
|
|
86
|
+
items: {
|
|
87
|
+
type: 'object',
|
|
88
|
+
additionalProperties: false,
|
|
89
|
+
required: ['id', 'content', 'status'],
|
|
90
|
+
properties: {
|
|
91
|
+
id: {
|
|
92
|
+
type: 'string',
|
|
93
|
+
minLength: TODO_ID_MIN,
|
|
94
|
+
maxLength: TODO_ID_MAX,
|
|
95
|
+
description: 'Stable id for this todo. Opaque, ≤128 chars.',
|
|
96
|
+
},
|
|
97
|
+
content: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
minLength: 1,
|
|
100
|
+
maxLength: TODO_CONTENT_MAX,
|
|
101
|
+
description: 'Imperative task description.',
|
|
102
|
+
},
|
|
103
|
+
status: {
|
|
104
|
+
type: 'string',
|
|
105
|
+
enum: ['pending', 'in_progress', 'completed'],
|
|
106
|
+
description: 'Lifecycle status. At most ONE in_progress per board.',
|
|
107
|
+
},
|
|
108
|
+
activeForm: {
|
|
109
|
+
type: 'string',
|
|
110
|
+
minLength: 1,
|
|
111
|
+
maxLength: TODO_CONTENT_MAX,
|
|
112
|
+
description: 'Present-continuous form.',
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
/**
|
|
120
|
+
* Sentinel prefix the dispatcher returns when Zod schema validation
|
|
121
|
+
* rejects the raw arguments. Distinct from `TODO_INVARIANT_VIOLATED`
|
|
122
|
+
* (>1 in_progress) and `TODO_DUPLICATE_ID` (collision within batch),
|
|
123
|
+
* which are emitted from `saveTodoBoard` AFTER schema parsing.
|
|
124
|
+
*
|
|
125
|
+
* Surfaced as a return string (not a throw) so the engine adapter sees
|
|
126
|
+
* a recoverable tool error and the model can self-correct its args,
|
|
127
|
+
* instead of the engine loop tearing down on an uncaught ZodError.
|
|
128
|
+
*/
|
|
129
|
+
export const TODO_INVALID_ARGS = 'INVALID_ARGS';
|
|
130
|
+
/**
|
|
131
|
+
* Render a ZodError into a deterministic `INVALID_ARGS: ...` sentinel
|
|
132
|
+
* the model can pattern-match. Each issue contributes one
|
|
133
|
+
* `path: message` clause; clauses are joined with `; ` so the model
|
|
134
|
+
* sees every offence in a single line. Path with the root scope is
|
|
135
|
+
* rendered as `<root>` to avoid an empty colon.
|
|
136
|
+
*/
|
|
137
|
+
function renderZodIssues(error) {
|
|
138
|
+
const parts = error.issues.map((issue) => {
|
|
139
|
+
const path = issue.path.length === 0 ? '<root>' : issue.path.join('.');
|
|
140
|
+
return `${path}: ${issue.message}`;
|
|
141
|
+
});
|
|
142
|
+
return `${TODO_INVALID_ARGS}: ${parts.join('; ')}`;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validate via Zod + persist atomically. Surfaces three sentinel
|
|
146
|
+
* families the dispatcher pattern-matches on:
|
|
147
|
+
* - `INVALID_ARGS: <path>: <issue>; ...` — Zod schema rejected
|
|
148
|
+
* the raw arguments (returned as STRING, not thrown).
|
|
149
|
+
* - `TODO_INVARIANT_VIOLATED: ...` — >1 in_progress
|
|
150
|
+
* (thrown by `saveTodoBoard`).
|
|
151
|
+
* - `TODO_DUPLICATE_ID: ...` — collision within batch
|
|
152
|
+
* (thrown by `saveTodoBoard`).
|
|
153
|
+
*
|
|
154
|
+
* Why the asymmetry: schema rejection means the model emitted malformed
|
|
155
|
+
* structure (missing field, wrong type) and CAN self-correct given a
|
|
156
|
+
* clear breakdown of the offending path. The invariant + duplicate-id
|
|
157
|
+
* paths mean the model emitted structurally-valid but semantically
|
|
158
|
+
* conflicting state — those still throw so the engine loop's tool-error
|
|
159
|
+
* hook can surface them through `PostToolUseFailure` for observability,
|
|
160
|
+
* mirroring how the file-tools layer surfaces `STALE_READ` / `PermissionDenied`.
|
|
161
|
+
*/
|
|
162
|
+
export function dispatchTodoWrite(ctx, rawArgs) {
|
|
163
|
+
// L16 P1 fix (2026-05-27): `.parse` throws a `ZodError` on validation
|
|
164
|
+
// failure. The previous implementation let that throw bubble through
|
|
165
|
+
// the engine adapter's catch arm as a free-form `error.message`,
|
|
166
|
+
// which (a) loses the issue-by-issue structure the model needs to
|
|
167
|
+
// self-correct, and (b) tears down the tool-call as a hard failure
|
|
168
|
+
// rather than a recoverable tool result. Switch to `safeParse` and
|
|
169
|
+
// emit a structured `INVALID_ARGS: <path>: <issue>; ...` sentinel
|
|
170
|
+
// string instead — the engine sees a successful tool call, the model
|
|
171
|
+
// sees the offending paths, and the dispatcher's catch arm reserves
|
|
172
|
+
// throws for the genuine semantic conflicts emitted by `saveTodoBoard`.
|
|
173
|
+
const parsed = todoWriteArgsSchema.safeParse(rawArgs);
|
|
174
|
+
if (!parsed.success) {
|
|
175
|
+
return renderZodIssues(parsed.error);
|
|
176
|
+
}
|
|
177
|
+
const stateCtx = {
|
|
178
|
+
workspaceRoot: ctx.workspaceRoot,
|
|
179
|
+
...(ctx.now ? { now: ctx.now } : {}),
|
|
180
|
+
};
|
|
181
|
+
const board = saveTodoBoard(stateCtx, parsed.data.todos);
|
|
182
|
+
return JSON.stringify(board);
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=todo-write.js.map
|
|
@@ -36,14 +36,27 @@ export function CompactBanner(props) {
|
|
|
36
36
|
* Build the centred label. Examples:
|
|
37
37
|
* "context compacted (12 turns → 1 summary, auto)"
|
|
38
38
|
* "context compacted (4 turns → 1 summary, manual · ~3.2k tokens)"
|
|
39
|
+
* "context compacted (12 turns → summary at 14:32, auto)"
|
|
40
|
+
* "context compacted (12 turns → 1 summary, manual) · 6 turns ago"
|
|
39
41
|
*/
|
|
40
42
|
export function buildLabel(props) {
|
|
41
43
|
const trigger = props.trigger === 'auto' ? 'auto' : 'manual';
|
|
42
44
|
const turns = `${props.turnsBefore} ${props.turnsBefore === 1 ? 'turn' : 'turns'}`;
|
|
45
|
+
const summarySlot = typeof props.summaryAtEpochMs === 'number' && props.summaryAtEpochMs > 0
|
|
46
|
+
? `summary at ${formatClock(props.summaryAtEpochMs)}`
|
|
47
|
+
: '1 summary';
|
|
43
48
|
const tokens = props.summaryTokenCount && props.summaryTokenCount > 0
|
|
44
49
|
? ` · ~${formatTokens(props.summaryTokenCount)} tokens`
|
|
45
50
|
: '';
|
|
46
|
-
|
|
51
|
+
const base = `context compacted (${turns} → ${summarySlot}, ${trigger}${tokens})`;
|
|
52
|
+
// L29 history-replay suffix. Only render when the boundary has live
|
|
53
|
+
// turns following it — a fresh in-REPL `/compact` lands with
|
|
54
|
+
// `turnsAgo === 0` and we keep the label compact.
|
|
55
|
+
if (typeof props.turnsAgo === 'number' && props.turnsAgo > 0) {
|
|
56
|
+
const ago = `${props.turnsAgo} ${props.turnsAgo === 1 ? 'turn' : 'turns'} ago`;
|
|
57
|
+
return `${base} · ${ago}`;
|
|
58
|
+
}
|
|
59
|
+
return base;
|
|
47
60
|
}
|
|
48
61
|
/** Format token counts like 1234 → 1.2k, 950 → 950. */
|
|
49
62
|
function formatTokens(n) {
|
|
@@ -51,4 +64,18 @@ function formatTokens(n) {
|
|
|
51
64
|
return `${n}`;
|
|
52
65
|
return `${(n / 1000).toFixed(1)}k`;
|
|
53
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Render an epoch-ms instant as a deterministic `HH:MM` clock in the
|
|
69
|
+
* operator's local timezone. Used only inside the centred label so a
|
|
70
|
+
* boundary that landed mid-session reads `summary at 14:32` instead of
|
|
71
|
+
* the generic `1 summary`. Pure (no side effects), constant-time.
|
|
72
|
+
*/
|
|
73
|
+
function formatClock(epochMs) {
|
|
74
|
+
const d = new Date(epochMs);
|
|
75
|
+
if (Number.isNaN(d.getTime()))
|
|
76
|
+
return '--:--';
|
|
77
|
+
const hh = d.getHours().toString().padStart(2, '0');
|
|
78
|
+
const mm = d.getMinutes().toString().padStart(2, '0');
|
|
79
|
+
return `${hh}:${mm}`;
|
|
80
|
+
}
|
|
54
81
|
//# sourceMappingURL=compact-banner.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Box, Text } from 'ink';
|
|
3
3
|
import { MarkdownRender } from './markdown-render.js';
|
|
4
|
+
import { CompactBanner } from './compact-banner.js';
|
|
4
5
|
const HUE_COLOR_BY_SLUG = {
|
|
5
6
|
// Mira (Pug) - coordinator
|
|
6
7
|
main: 'cyan',
|
|
@@ -39,6 +40,18 @@ function ConversationRow({ row, personaNames, }) {
|
|
|
39
40
|
return (_jsxs(Box, { children: [_jsx(Text, { bold: true, color: "#3da9fc", children: '› ' }), _jsx(Text, { children: row.text })] }));
|
|
40
41
|
case 'system':
|
|
41
42
|
return (_jsxs(Box, { children: [_jsx(Text, { dimColor: true, children: '· ' }), _jsx(Text, { dimColor: true, children: row.text })] }));
|
|
43
|
+
case 'compact-boundary': {
|
|
44
|
+
// L29 (2026-05-27): structured render. When the row carries the
|
|
45
|
+
// `compaction` payload, drive the Ink banner directly so the
|
|
46
|
+
// operator sees a width-aware gray separator with the canonical
|
|
47
|
+
// label. Fallback: a legacy boundary missing the structured
|
|
48
|
+
// payload (older replay events, hand-built rows) renders through
|
|
49
|
+
// the dim text path so the operator still sees the marker.
|
|
50
|
+
if (row.compaction) {
|
|
51
|
+
return (_jsx(CompactBanner, { turnsBefore: row.compaction.turnsBefore, trigger: row.compaction.trigger, summaryTokenCount: row.compaction.summaryTokenCount, turnsAgo: row.compaction.turnsAgo, summaryAtEpochMs: row.timestampEpochMs, columns: process.stdout?.columns }));
|
|
52
|
+
}
|
|
53
|
+
return (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: row.text }) }));
|
|
54
|
+
}
|
|
42
55
|
case 'persona': {
|
|
43
56
|
const slug = row.personaSlug ?? '';
|
|
44
57
|
const color = HUE_COLOR_BY_SLUG[slug] ?? 'white';
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* `/feedback` interactive prompt — Leak L21 (2026-05-27).
|
|
4
|
+
*
|
|
5
|
+
* Five-step wizard mounted from both the top-level `pugi feedback`
|
|
6
|
+
* shell handler and the in-REPL `/feedback` slash. Steps:
|
|
7
|
+
*
|
|
8
|
+
* 1. category — bug / feature / general / praise (numeric pick 1-4)
|
|
9
|
+
* 2. rating — 1-5 stars (numeric pick 1-5)
|
|
10
|
+
* 3. comment — free-text, multi-line, Ctrl-D submits, Esc cancels
|
|
11
|
+
* 4. context — y/n include last 5 turns (redacted)? default no
|
|
12
|
+
* 5. confirm — y/n submit?
|
|
13
|
+
*
|
|
14
|
+
* Brand voice gate: ASCII glyphs only, no em-dashes, no banned brand
|
|
15
|
+
* words. Copy is intentionally power-word neutral so the future i18n
|
|
16
|
+
* landing localises cleanly.
|
|
17
|
+
*
|
|
18
|
+
* The component is PURE in the Ink sense — props in, one terminal
|
|
19
|
+
* `onResolve` event out. The caller owns the submit + queue logic.
|
|
20
|
+
*
|
|
21
|
+
* The verdict the operator submits is:
|
|
22
|
+
* - `{ cancelled: true }` when the operator presses Esc at any step
|
|
23
|
+
* - `{ cancelled: false, draft }` when the wizard completes
|
|
24
|
+
*
|
|
25
|
+
* `draft` is the assembled `FeedbackDraft` — NOT yet a full envelope
|
|
26
|
+
* (the caller still injects `ts` + `cliVersion` + maybe `tier`).
|
|
27
|
+
*/
|
|
28
|
+
import { useState } from 'react';
|
|
29
|
+
import { Box, Text, render, useApp, useInput } from 'ink';
|
|
30
|
+
const CATEGORIES = [
|
|
31
|
+
{ value: 'bug', label: 'bug', gloss: 'something broke or behaves unexpectedly' },
|
|
32
|
+
{ value: 'feature', label: 'feature', gloss: 'request a new capability' },
|
|
33
|
+
{ value: 'general', label: 'general', gloss: 'observation, idea, comment' },
|
|
34
|
+
{ value: 'praise', label: 'praise', gloss: 'positive note for the team' },
|
|
35
|
+
];
|
|
36
|
+
export function FeedbackPrompt(props) {
|
|
37
|
+
const [step, setStep] = useState('category');
|
|
38
|
+
const [category, setCategory] = useState(null);
|
|
39
|
+
const [rating, setRating] = useState(null);
|
|
40
|
+
const [commentBuffer, setCommentBuffer] = useState('');
|
|
41
|
+
const [includeContext, setIncludeContext] = useState(false);
|
|
42
|
+
useInput((input, key) => {
|
|
43
|
+
if (key.escape) {
|
|
44
|
+
props.onResolve({ cancelled: true });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (step === 'category') {
|
|
48
|
+
const n = Number.parseInt(input, 10);
|
|
49
|
+
if (!Number.isNaN(n) && n >= 1 && n <= CATEGORIES.length) {
|
|
50
|
+
const picked = CATEGORIES[n - 1];
|
|
51
|
+
if (picked) {
|
|
52
|
+
setCategory(picked.value);
|
|
53
|
+
setStep('rating');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (step === 'rating') {
|
|
59
|
+
const n = Number.parseInt(input, 10);
|
|
60
|
+
if (!Number.isNaN(n) && n >= 1 && n <= 5) {
|
|
61
|
+
setRating(n);
|
|
62
|
+
setStep('comment');
|
|
63
|
+
}
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (step === 'comment') {
|
|
67
|
+
// Ctrl-D submits the comment (even when empty — rating-only
|
|
68
|
+
// feedback is allowed). Enter inserts a newline so the
|
|
69
|
+
// operator can write multi-line bug repros without the wizard
|
|
70
|
+
// ending the buffer prematurely.
|
|
71
|
+
if (key.ctrl && (input === 'd' || input === '')) {
|
|
72
|
+
setStep('context');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
if (key.return) {
|
|
76
|
+
setCommentBuffer((prev) => prev + '\n');
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (key.backspace || key.delete) {
|
|
80
|
+
setCommentBuffer((prev) => prev.slice(0, -1));
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
// Printable characters land in the buffer. We accept anything
|
|
84
|
+
// non-empty + non-control. Ink's useInput sometimes delivers
|
|
85
|
+
// multi-char paste bursts as one `input` — we append the whole
|
|
86
|
+
// burst so paste lands intact.
|
|
87
|
+
if (input && !key.ctrl && !key.meta) {
|
|
88
|
+
setCommentBuffer((prev) => prev + input);
|
|
89
|
+
}
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (step === 'context') {
|
|
93
|
+
if (input === 'y' || input === 'Y') {
|
|
94
|
+
setIncludeContext(true);
|
|
95
|
+
setStep('confirm');
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (input === 'n' || input === 'N' || key.return) {
|
|
99
|
+
// Default no — Enter at the context prompt picks "no" so
|
|
100
|
+
// the operator can blast through with all defaults.
|
|
101
|
+
setIncludeContext(false);
|
|
102
|
+
setStep('confirm');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (step === 'confirm') {
|
|
108
|
+
if (input === 'y' || input === 'Y' || key.return) {
|
|
109
|
+
if (category != null && rating != null) {
|
|
110
|
+
props.onResolve({
|
|
111
|
+
cancelled: false,
|
|
112
|
+
draft: {
|
|
113
|
+
category,
|
|
114
|
+
rating,
|
|
115
|
+
comment: commentBuffer,
|
|
116
|
+
includeSessionContext: includeContext,
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (input === 'n' || input === 'N') {
|
|
123
|
+
props.onResolve({ cancelled: true });
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}, { isActive: !props.inert });
|
|
129
|
+
return (_jsxs(Box, { flexDirection: "column", borderStyle: "round", borderColor: "cyan", paddingX: 1, children: [_jsxs(Box, { marginBottom: 1, children: [_jsx(Text, { bold: true, color: "cyan", children: "Pugi /feedback" }), _jsx(Text, { children: " \u2014 share what you saw. Esc cancels at any step." })] }), step === 'category' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "1. Category" }), CATEGORIES.map((c, idx) => (_jsx(Text, { children: ` ${idx + 1}. ${c.label.padEnd(8)} ${c.gloss}` }, c.value))), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Pick 1-4." }) })] })), step === 'rating' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "2. Rating" }), _jsx(Text, { children: ` 1=poor, 5=excellent. Picked category: ${category ?? '?'}` }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Pick 1-5." }) })] })), step === 'comment' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "3. Comment" }), _jsx(Text, { dimColor: true, children: "Multi-line. Enter inserts a newline. Ctrl-D submits." }), _jsx(Box, { marginTop: 1, flexDirection: "column", children: commentBuffer.length === 0 ? (_jsx(Text, { dimColor: true, children: "(empty \u2014 Ctrl-D submits without a comment)" })) : (commentBuffer.split('\n').map((line, idx) => (_jsx(Text, { children: `> ${line}` }, idx)))) })] })), step === 'context' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "4. Include session context?" }), _jsx(Text, { children: ' Last 5 turns, redacted (tokens / *_KEY=* values stripped).' }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "y / n \u2014 default n (Enter)." }) })] })), step === 'confirm' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { bold: true, children: "5. Submit?" }), _jsx(Text, { children: ` category=${category ?? '?'} rating=${rating ?? '?'} context=${includeContext ? 'yes' : 'no'}` }), _jsx(Text, { children: ` comment=${commentBuffer.length} chars` }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "y / n \u2014 default y (Enter)." }) })] }))] }));
|
|
130
|
+
}
|
|
131
|
+
export async function renderFeedbackPrompt() {
|
|
132
|
+
let resolveOuter;
|
|
133
|
+
const outerPromise = new Promise((resolve) => {
|
|
134
|
+
resolveOuter = resolve;
|
|
135
|
+
});
|
|
136
|
+
function App() {
|
|
137
|
+
const { exit } = useApp();
|
|
138
|
+
return (_jsx(FeedbackPrompt, { onResolve: (verdict) => {
|
|
139
|
+
resolveOuter(verdict);
|
|
140
|
+
// Mirror renderAskCli: tiny delay so Ink flushes unmount
|
|
141
|
+
// before the caller prints the toast line.
|
|
142
|
+
setTimeout(() => exit(), 16);
|
|
143
|
+
} }));
|
|
144
|
+
}
|
|
145
|
+
const instance = render(_jsx(App, {}));
|
|
146
|
+
const verdict = await outerPromise;
|
|
147
|
+
try {
|
|
148
|
+
await instance.waitUntilExit();
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Ink can throw when exit() races with a re-render — the verdict
|
|
152
|
+
// is already captured so we ignore.
|
|
153
|
+
}
|
|
154
|
+
return verdict;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=feedback-prompt.js.map
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Leak L25 (2026-05-27) — Onboarding Ink wizard.
|
|
4
|
+
*
|
|
5
|
+
* Six-screen interactive walk:
|
|
6
|
+
*
|
|
7
|
+
* 1. Welcome + auth status (single Enter to continue)
|
|
8
|
+
* 2. Default permission mode (4-row picker)
|
|
9
|
+
* 3. Output style preset (5-row picker)
|
|
10
|
+
* 4. MCP server pointer (informational, Enter to continue)
|
|
11
|
+
* 5. Telemetry consent (3-row picker)
|
|
12
|
+
* 6. Recap card (Enter to commit + exit)
|
|
13
|
+
*
|
|
14
|
+
* Driven entirely by Ink's `useInput`. The component does NOT perform
|
|
15
|
+
* any fs writes — it resolves the verdict back to the caller
|
|
16
|
+
* (`runOnboardingCommand`), which translates verdicts into L6 / L18 /
|
|
17
|
+
* telemetry-state mutations. Single source of truth: the runner.
|
|
18
|
+
*
|
|
19
|
+
* Each picker step pre-selects the CURRENT persisted value (from the
|
|
20
|
+
* snapshot passed in props) so pressing Enter on Step 2/3/5 keeps the
|
|
21
|
+
* current value — that is the idempotency contract.
|
|
22
|
+
*
|
|
23
|
+
* Cancellation:
|
|
24
|
+
* - Esc / Ctrl-C at any step → verdict.cancelled = true, the runner
|
|
25
|
+
* skips ALL writes (including the marker touch) so the next bare
|
|
26
|
+
* `pugi` invocation still surfaces the first-run hint.
|
|
27
|
+
*
|
|
28
|
+
* Keystrokes:
|
|
29
|
+
* - ↑/↓ or j/k — move selection in pickers.
|
|
30
|
+
* - Enter — confirm step (keep current = pass through; new pick
|
|
31
|
+
* = update verdict for that tier).
|
|
32
|
+
* - 's' — skip current step explicitly (verdict slot stays null).
|
|
33
|
+
* - Esc / 'q' — cancel the wizard.
|
|
34
|
+
*/
|
|
35
|
+
import { useState } from 'react';
|
|
36
|
+
import { Box, Text, render, useApp, useInput } from 'ink';
|
|
37
|
+
import { PERMISSION_MODES, PERMISSION_MODE_GLOSS, } from '../core/permissions/index.js';
|
|
38
|
+
import { OUTPUT_STYLES, OUTPUT_STYLE_SLUGS, } from '../core/output-style/presets.js';
|
|
39
|
+
import { TELEMETRY_CHOICES, } from '../core/onboarding/telemetry-state.js';
|
|
40
|
+
const EMPTY_DRAFT = {
|
|
41
|
+
permissionMode: null,
|
|
42
|
+
outputStyle: null,
|
|
43
|
+
telemetry: null,
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Lookup the snapshot value's index within the picker rows so the
|
|
47
|
+
* initial cursor sits on the current value. Returns 0 (safe default)
|
|
48
|
+
* when the snapshot value is outside the closed list — should never
|
|
49
|
+
* happen given the type guards in the state modules, but the index
|
|
50
|
+
* fallback keeps Ink from crashing on a malformed config.
|
|
51
|
+
*/
|
|
52
|
+
function indexOf(rows, value) {
|
|
53
|
+
const idx = rows.indexOf(value);
|
|
54
|
+
return idx === -1 ? 0 : idx;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The wizard component. Pure: no fs, no env, no network. Verdicts
|
|
58
|
+
* flow up via `onComplete`; the caller owns the writes.
|
|
59
|
+
*/
|
|
60
|
+
export function OnboardingWizard(props) {
|
|
61
|
+
const { snapshot, onComplete } = props;
|
|
62
|
+
const [step, setStep] = useState(1);
|
|
63
|
+
const [permissionIdx, setPermissionIdx] = useState(indexOf(PERMISSION_MODES, snapshot.permissionMode));
|
|
64
|
+
const [styleIdx, setStyleIdx] = useState(indexOf(OUTPUT_STYLE_SLUGS, snapshot.outputStyle));
|
|
65
|
+
const [telemetryIdx, setTelemetryIdx] = useState(indexOf(TELEMETRY_CHOICES, snapshot.telemetry));
|
|
66
|
+
const [draft, setDraft] = useState(EMPTY_DRAFT);
|
|
67
|
+
const finish = (final, cancelled) => {
|
|
68
|
+
onComplete({
|
|
69
|
+
permissionMode: final.permissionMode,
|
|
70
|
+
outputStyle: final.outputStyle,
|
|
71
|
+
telemetry: final.telemetry,
|
|
72
|
+
cancelled,
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
useInput((input, key) => {
|
|
76
|
+
// Universal cancel.
|
|
77
|
+
if (key.escape || (key.ctrl && input === 'c')) {
|
|
78
|
+
finish(EMPTY_DRAFT, true);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
// Universal skip — Enter on a picker means "keep current"; explicit
|
|
82
|
+
// 's' makes the skip intent obvious in the recap.
|
|
83
|
+
const isAdvance = key.return;
|
|
84
|
+
const moveUp = key.upArrow || input === 'k';
|
|
85
|
+
const moveDown = key.downArrow || input === 'j';
|
|
86
|
+
const explicitSkip = input === 's';
|
|
87
|
+
switch (step) {
|
|
88
|
+
case 1: {
|
|
89
|
+
if (isAdvance)
|
|
90
|
+
setStep(2);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
case 2: {
|
|
94
|
+
if (moveUp) {
|
|
95
|
+
setPermissionIdx((i) => (i === 0 ? PERMISSION_MODES.length - 1 : i - 1));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (moveDown) {
|
|
99
|
+
setPermissionIdx((i) => (i === PERMISSION_MODES.length - 1 ? 0 : i + 1));
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (isAdvance || explicitSkip) {
|
|
103
|
+
const picked = PERMISSION_MODES[permissionIdx];
|
|
104
|
+
const verdict = explicitSkip || picked === snapshot.permissionMode ? null : picked ?? null;
|
|
105
|
+
setDraft((d) => ({ ...d, permissionMode: verdict }));
|
|
106
|
+
setStep(3);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
case 3: {
|
|
112
|
+
if (moveUp) {
|
|
113
|
+
setStyleIdx((i) => (i === 0 ? OUTPUT_STYLE_SLUGS.length - 1 : i - 1));
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (moveDown) {
|
|
117
|
+
setStyleIdx((i) => (i === OUTPUT_STYLE_SLUGS.length - 1 ? 0 : i + 1));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (isAdvance || explicitSkip) {
|
|
121
|
+
const picked = OUTPUT_STYLE_SLUGS[styleIdx];
|
|
122
|
+
const verdict = explicitSkip || picked === snapshot.outputStyle ? null : picked ?? null;
|
|
123
|
+
setDraft((d) => ({ ...d, outputStyle: verdict }));
|
|
124
|
+
setStep(4);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
case 4: {
|
|
130
|
+
if (isAdvance)
|
|
131
|
+
setStep(5);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
case 5: {
|
|
135
|
+
if (moveUp) {
|
|
136
|
+
setTelemetryIdx((i) => (i === 0 ? TELEMETRY_CHOICES.length - 1 : i - 1));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (moveDown) {
|
|
140
|
+
setTelemetryIdx((i) => (i === TELEMETRY_CHOICES.length - 1 ? 0 : i + 1));
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
if (isAdvance || explicitSkip) {
|
|
144
|
+
const picked = TELEMETRY_CHOICES[telemetryIdx];
|
|
145
|
+
const verdict = explicitSkip || picked === snapshot.telemetry ? null : picked ?? null;
|
|
146
|
+
setDraft((d) => ({ ...d, telemetry: verdict }));
|
|
147
|
+
setStep(6);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
case 6: {
|
|
153
|
+
if (isAdvance)
|
|
154
|
+
finish(draft, false);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 2, paddingY: 1, children: [_jsx(StepHeader, { step: step }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [step === 1 && _jsx(WelcomeStep, { snapshot: snapshot }), step === 2 && (_jsx(ModeStep, { current: snapshot.permissionMode, selectedIdx: permissionIdx })), step === 3 && (_jsx(StyleStep, { current: snapshot.outputStyle, currentSource: snapshot.outputStyleSource, selectedIdx: styleIdx })), step === 4 && _jsx(McpStep, {}), step === 5 && (_jsx(TelemetryStep, { current: snapshot.telemetry, selectedIdx: telemetryIdx })), step === 6 && _jsx(RecapStep, { snapshot: snapshot, draft: draft })] }), _jsx(FooterHints, { step: step })] }));
|
|
160
|
+
}
|
|
161
|
+
function StepHeader({ step }) {
|
|
162
|
+
const titles = {
|
|
163
|
+
1: 'Welcome to Pugi',
|
|
164
|
+
2: 'Step 2 / 5 — Default permission mode',
|
|
165
|
+
3: 'Step 3 / 5 — Output style',
|
|
166
|
+
4: 'Step 4 / 5 — MCP servers',
|
|
167
|
+
5: 'Step 5 / 5 — Telemetry consent',
|
|
168
|
+
6: 'Setup complete',
|
|
169
|
+
};
|
|
170
|
+
return (_jsx(Text, { bold: true, color: "cyan", children: titles[step] }));
|
|
171
|
+
}
|
|
172
|
+
function WelcomeStep({ snapshot }) {
|
|
173
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "Brief it. It ships." }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: snapshot.authPresent
|
|
174
|
+
? 'You are signed in. The wizard configures local defaults; values persist to ~/.pugi/config.json.'
|
|
175
|
+
: 'You are NOT signed in. The wizard still configures local defaults, but you should run `pugi login` after.' }) })] }));
|
|
176
|
+
}
|
|
177
|
+
function ModeStep({ current, selectedIdx, }) {
|
|
178
|
+
return (_jsx(Box, { flexDirection: "column", children: PERMISSION_MODES.map((mode, idx) => (_jsx(PickerRow, { isSelected: idx === selectedIdx, isCurrent: mode === current, title: mode, gloss: PERMISSION_MODE_GLOSS[mode] }, mode))) }));
|
|
179
|
+
}
|
|
180
|
+
function StyleStep({ current, currentSource, selectedIdx, }) {
|
|
181
|
+
return (_jsxs(Box, { flexDirection: "column", children: [OUTPUT_STYLE_SLUGS.map((slug, idx) => (_jsx(PickerRow, { isSelected: idx === selectedIdx, isCurrent: slug === current, title: slug, gloss: OUTPUT_STYLES[slug].gloss }, slug))), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: currentSource === 'workspace'
|
|
182
|
+
? 'Active style is currently a workspace override. The wizard writes the user-tier default.'
|
|
183
|
+
: `Active source: ${currentSource}.` }) })] }));
|
|
184
|
+
}
|
|
185
|
+
function McpStep() {
|
|
186
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: "MCP servers extend Pugi with extra tools (filesystem, browser, custom APIs)." }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Add one with:" }) }), _jsx(Text, { children: ' pugi mcp add <name> <command>' }), _jsx(Text, { children: ' pugi mcp list' }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "You can skip for now and add servers later." }) })] }));
|
|
187
|
+
}
|
|
188
|
+
function TelemetryStep({ current, selectedIdx, }) {
|
|
189
|
+
const gloss = {
|
|
190
|
+
off: 'No telemetry of any kind.',
|
|
191
|
+
anonymous: 'Counts + error categories only; no payloads.',
|
|
192
|
+
community: 'Anonymous + opt-in usage panels.',
|
|
193
|
+
};
|
|
194
|
+
return (_jsx(Box, { flexDirection: "column", children: TELEMETRY_CHOICES.map((choice, idx) => (_jsx(PickerRow, { isSelected: idx === selectedIdx, isCurrent: choice === current, title: choice, gloss: gloss[choice] }, choice))) }));
|
|
195
|
+
}
|
|
196
|
+
function RecapStep({ snapshot, draft, }) {
|
|
197
|
+
const finalMode = draft.permissionMode ?? snapshot.permissionMode;
|
|
198
|
+
const finalStyle = draft.outputStyle ?? snapshot.outputStyle;
|
|
199
|
+
const finalTelemetry = draft.telemetry ?? snapshot.telemetry;
|
|
200
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { children: ` Permission mode: ${finalMode}${draft.permissionMode === null ? ' (unchanged)' : ''}` }), _jsx(Text, { children: ` Output style: ${finalStyle}${draft.outputStyle === null ? ' (unchanged)' : ''}` }), _jsx(Text, { children: ` Telemetry: ${finalTelemetry}${draft.telemetry === null ? ' (unchanged)' : ''}` }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: "Press Enter to write defaults + exit. Esc to cancel without saving." }) })] }));
|
|
201
|
+
}
|
|
202
|
+
function PickerRow({ isSelected, isCurrent, title, gloss, }) {
|
|
203
|
+
const indicator = isSelected ? '▸ ' : ' ';
|
|
204
|
+
const currentTag = isCurrent ? ' [current]' : '';
|
|
205
|
+
return (_jsxs(Text, { children: [_jsxs(Text, { color: isSelected ? 'cyan' : undefined, bold: isSelected, children: [indicator, title.padEnd(18, ' ')] }), _jsx(Text, { dimColor: true, children: `${gloss}${currentTag}` })] }));
|
|
206
|
+
}
|
|
207
|
+
function FooterHints({ step }) {
|
|
208
|
+
const hint = step === 1 || step === 4
|
|
209
|
+
? 'Enter continue Esc cancel'
|
|
210
|
+
: step === 6
|
|
211
|
+
? 'Enter commit + exit Esc cancel'
|
|
212
|
+
: '↑/↓ select Enter confirm s skip Esc cancel';
|
|
213
|
+
return (_jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: hint }) }));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Mount the wizard, await the operator's verdict, unmount Ink, return
|
|
217
|
+
* the verdict to the runner. Wrapped in a `useApp` consumer so we can
|
|
218
|
+
* call `exit()` and let `waitUntilExit()` resolve cleanly.
|
|
219
|
+
*/
|
|
220
|
+
export async function renderOnboardingWizard(opts) {
|
|
221
|
+
return new Promise((resolvePromise) => {
|
|
222
|
+
let resolved = false;
|
|
223
|
+
const handleComplete = (verdict) => {
|
|
224
|
+
if (resolved)
|
|
225
|
+
return;
|
|
226
|
+
resolved = true;
|
|
227
|
+
app.unmount();
|
|
228
|
+
resolvePromise(verdict);
|
|
229
|
+
};
|
|
230
|
+
const Wrapper = () => {
|
|
231
|
+
const { exit } = useApp();
|
|
232
|
+
return (_jsx(OnboardingWizard, { snapshot: opts.snapshot, onComplete: (verdict) => {
|
|
233
|
+
handleComplete(verdict);
|
|
234
|
+
exit();
|
|
235
|
+
} }));
|
|
236
|
+
};
|
|
237
|
+
const app = render(_jsx(Wrapper, {}));
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
//# sourceMappingURL=onboarding-wizard.js.map
|