@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.
- package/dist/core/auth/env-provider.js +238 -0
- package/dist/core/bare-mode/index.js +107 -0
- package/dist/core/diagnostics/probes/bare-mode.js +42 -0
- package/dist/core/diagnostics/probes/pugi-md.js +89 -0
- package/dist/core/engine/native-pugi.js +55 -11
- 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/pugi-md/context-injector.js +76 -0
- package/dist/core/pugi-md/walk-up.js +207 -0
- package/dist/core/release-notes/parser.js +241 -0
- package/dist/core/release-notes/state.js +116 -0
- package/dist/core/repl/session.js +482 -12
- package/dist/core/repl/slash-commands.js +134 -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/theme/context.js +91 -0
- package/dist/core/theme/presets.js +228 -0
- package/dist/core/theme/state.js +181 -0
- package/dist/core/todos/invariant.js +10 -0
- package/dist/core/todos/state.js +177 -0
- package/dist/core/vim/keymap.js +288 -0
- package/dist/core/vim/state.js +92 -0
- package/dist/runtime/cli.js +603 -15
- package/dist/runtime/commands/doctor.js +21 -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/release-notes.js +229 -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/commands/theme.js +196 -0
- package/dist/runtime/commands/vim.js +140 -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/doctor-table.js +32 -17
- package/dist/tui/feedback-prompt.js +156 -0
- package/dist/tui/onboarding-wizard.js +240 -0
- package/dist/tui/repl-render.js +26 -3
- package/dist/tui/repl.js +9 -1
- package/dist/tui/stickers-art.js +136 -0
- package/dist/tui/style-table.js +28 -0
- package/dist/tui/theme-table.js +29 -0
- package/dist/tui/vim-input.js +267 -0
- package/package.json +2 -2
- package/dist/core/engine/compaction-hook.js +0 -154
- package/dist/core/init/scaffold.js +0 -195
- package/dist/core/repl/codebase-survey.js +0 -308
- package/dist/core/repl/init-interview.js +0 -457
- package/dist/core/repl/onboarding-state.js +0 -297
|
@@ -4,6 +4,7 @@ import { askUser } from '../../tools/ask-user.js';
|
|
|
4
4
|
import { askUserQuestionJsonSchema, dispatchAskUserQuestion, } from '../../tools/ask-user-question.js';
|
|
5
5
|
import { skillInvoke, skillList } from '../../tools/skill-tool.js';
|
|
6
6
|
import { taskCreate, taskGet, taskList, taskUpdate, } from '../../tools/tasks.js';
|
|
7
|
+
import { dispatchTodoWrite, todoWriteJsonSchema, } from '../../tools/todo-write.js';
|
|
7
8
|
import { webFetchTool } from '../../tools/web-fetch.js';
|
|
8
9
|
import { webSearchTool } from '../../tools/web-search.js';
|
|
9
10
|
import { agentTool } from '../../tools/agent-tool.js';
|
|
@@ -53,6 +54,12 @@ const READ_ONLY_TOOLS = new Set([
|
|
|
53
54
|
'task_get',
|
|
54
55
|
'task_list',
|
|
55
56
|
'task_update',
|
|
57
|
+
// Leak L16 (2026-05-27): `todo_write` writes to `.pugi/todos.json`
|
|
58
|
+
// — metadata, not source. From the workspace's perspective it is
|
|
59
|
+
// read-only (no source mutation), so plan-mode keeps the tool
|
|
60
|
+
// available: planning a refactor frequently means writing the
|
|
61
|
+
// todo board BEFORE picking which file to touch.
|
|
62
|
+
'todo_write',
|
|
56
63
|
'web_fetch',
|
|
57
64
|
// β1b T4 (2026-05-26): web_search is read-only from the workspace's
|
|
58
65
|
// perspective (no file writes, no shell). Egress goes through the
|
|
@@ -82,6 +89,8 @@ const WIRED_TOOLS = new Set([
|
|
|
82
89
|
'task_get',
|
|
83
90
|
'task_list',
|
|
84
91
|
'task_update',
|
|
92
|
+
// Leak L16: see READ_ONLY_TOOLS above for the rationale.
|
|
93
|
+
'todo_write',
|
|
85
94
|
'web_fetch',
|
|
86
95
|
// β1b T4: see READ_ONLY_TOOLS above.
|
|
87
96
|
'web_search',
|
|
@@ -190,6 +199,21 @@ export function buildToolsSchema(kind, options = { allowFetch: false, allowSearc
|
|
|
190
199
|
},
|
|
191
200
|
},
|
|
192
201
|
});
|
|
202
|
+
// Leak L16 (2026-05-27): `todo_write` — batch TodoWrite mirror of
|
|
203
|
+
// Claude Code's upstream tool. Whereas `task_*` above is granular
|
|
204
|
+
// (one mutation per call, JSONL append, session-scoped),
|
|
205
|
+
// `todo_write` snapshots the FULL board in one call, JSON snapshot
|
|
206
|
+
// at `.pugi/todos.json`, workspace-scoped. Enforces the single-
|
|
207
|
+
// in-progress invariant at dispatch time: a batch with >1
|
|
208
|
+
// `in_progress` rejects with `TODO_INVARIANT_VIOLATED` and the
|
|
209
|
+
// on-disk board is left unchanged.
|
|
210
|
+
toolDefs.push({
|
|
211
|
+
name: 'todo_write',
|
|
212
|
+
description: 'Replace the workspace todo board (batch snapshot, not incremental). Emit the FULL todo list every call. ' +
|
|
213
|
+
'At most ONE item may carry status="in_progress" — violations reject with TODO_INVARIANT_VIOLATED. ' +
|
|
214
|
+
'Persisted atomically to .pugi/todos.json. Mirrors Claude Code TodoWrite verbatim.',
|
|
215
|
+
parameters: todoWriteJsonSchema,
|
|
216
|
+
});
|
|
193
217
|
// β1 T2 → leak L5 (2026-05-27): structured AskUserQuestion bridge.
|
|
194
218
|
// Schema upgraded to openclaude's multi-choice form: header chip +
|
|
195
219
|
// {label, description} per option. Dispatcher accepts the structured
|
|
@@ -684,6 +708,14 @@ export function buildExecutor(input) {
|
|
|
684
708
|
if (name === 'task_create' || name === 'task_get' || name === 'task_list' || name === 'task_update') {
|
|
685
709
|
return dispatchTaskTool(name, args, { workspaceRoot, sessionId });
|
|
686
710
|
}
|
|
711
|
+
if (name === 'todo_write') {
|
|
712
|
+
// Leak L16: batch TodoWrite. The dispatcher delegates the
|
|
713
|
+
// Zod validation + atomic persist to the tool module — any
|
|
714
|
+
// ZodError or `TODO_INVARIANT_VIOLATED` sentinel surfaces here
|
|
715
|
+
// as a thrown Error and lands on the catch arm below, which
|
|
716
|
+
// re-emits it through the PostToolUseFailure hook.
|
|
717
|
+
return dispatchTodoWrite({ workspaceRoot }, args);
|
|
718
|
+
}
|
|
687
719
|
if (name === 'ask_user_question') {
|
|
688
720
|
return dispatchAskUser(args, { interactive: Boolean(interactive), bridge: askUserBridge });
|
|
689
721
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local feedback queue — Leak L21 (2026-05-27).
|
|
3
|
+
*
|
|
4
|
+
* `pugi feedback` POSTs collected operator feedback to the admin-api
|
|
5
|
+
* `/api/pugi/feedback` route. When that round-trip fails (endpoint
|
|
6
|
+
* missing, network down, server 5xx), the submitter falls back to
|
|
7
|
+
* appending the envelope to `<cwd>/.pugi/feedback-queue.jsonl`. On the
|
|
8
|
+
* next online session the flusher drains the queue silently in the
|
|
9
|
+
* background.
|
|
10
|
+
*
|
|
11
|
+
* # Module contract
|
|
12
|
+
*
|
|
13
|
+
* - Per-workspace storage. The queue file lives at
|
|
14
|
+
* `<cwd>/.pugi/feedback-queue.jsonl` so the operator-visible state
|
|
15
|
+
* stays alongside the project's other Pugi metadata. Multi-repo
|
|
16
|
+
* operators get one queue per repo — matches the rest of `.pugi/`.
|
|
17
|
+
*
|
|
18
|
+
* - JSONL append-only format. One envelope per line. Newlines inside
|
|
19
|
+
* the comment field are escaped as `\n` by `JSON.stringify`. The
|
|
20
|
+
* enqueue path uses an atomic `O_APPEND` write so concurrent
|
|
21
|
+
* `pugi feedback` invocations from a split-screen REPL + shell do
|
|
22
|
+
* not interleave half-records.
|
|
23
|
+
*
|
|
24
|
+
* - The flusher is best-effort. It returns counts but never throws —
|
|
25
|
+
* a failed flush leaves the queue untouched and a successful flush
|
|
26
|
+
* atomically rewrites the file with the remaining (unsubmitted)
|
|
27
|
+
* envelopes. Partial-success is the normal path when the server
|
|
28
|
+
* accepts the first N but 5xx's the (N+1)th.
|
|
29
|
+
*
|
|
30
|
+
* - The queue file is intentionally NOT readable by anything beyond
|
|
31
|
+
* the flusher. The operator's free-text comments are confidential
|
|
32
|
+
* — we do not surface them in `/status` / `/doctor` / telemetry.
|
|
33
|
+
*
|
|
34
|
+
* - All filesystem writes go through `mkdirSync({recursive: true})`
|
|
35
|
+
* so the first-ever enqueue on a fresh workspace lazily creates
|
|
36
|
+
* `.pugi/` without depending on an earlier `pugi init`.
|
|
37
|
+
*/
|
|
38
|
+
import { appendFileSync, existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from 'node:fs';
|
|
39
|
+
import { dirname, resolve } from 'node:path';
|
|
40
|
+
/**
|
|
41
|
+
* Resolve the queue file path for a workspace. Centralised so the
|
|
42
|
+
* submitter + flusher + tests agree on a single canonical location.
|
|
43
|
+
*/
|
|
44
|
+
export function feedbackQueuePath(cwd) {
|
|
45
|
+
return resolve(cwd, '.pugi', 'feedback-queue.jsonl');
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Append one envelope atomically. Uses `O_APPEND` semantics via
|
|
49
|
+
* `appendFileSync` so concurrent invocations from a split-screen
|
|
50
|
+
* REPL + shell cannot interleave bytes mid-line.
|
|
51
|
+
*
|
|
52
|
+
* Returns the absolute path written so callers can surface it in the
|
|
53
|
+
* "Feedback queued locally" toast.
|
|
54
|
+
*/
|
|
55
|
+
export function enqueueFeedback(env, cwd) {
|
|
56
|
+
const path = feedbackQueuePath(cwd);
|
|
57
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
58
|
+
// JSON.stringify of an object never emits raw newlines; the trailing
|
|
59
|
+
// '\n' is the line separator. JSONL parsers split on '\n' so the
|
|
60
|
+
// separator survives round-trips.
|
|
61
|
+
const line = `${JSON.stringify(env)}\n`;
|
|
62
|
+
appendFileSync(path, line, { encoding: 'utf8' });
|
|
63
|
+
return path;
|
|
64
|
+
}
|
|
65
|
+
export function readFeedbackQueue(cwd) {
|
|
66
|
+
const path = feedbackQueuePath(cwd);
|
|
67
|
+
if (!existsSync(path)) {
|
|
68
|
+
return { envelopes: [], parseErrors: [] };
|
|
69
|
+
}
|
|
70
|
+
const contents = readFileSync(path, 'utf8');
|
|
71
|
+
const lines = contents.split('\n');
|
|
72
|
+
const envelopes = [];
|
|
73
|
+
const parseErrors = [];
|
|
74
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
75
|
+
const raw = lines[i]?.trim();
|
|
76
|
+
if (!raw)
|
|
77
|
+
continue;
|
|
78
|
+
try {
|
|
79
|
+
const parsed = JSON.parse(raw);
|
|
80
|
+
// Minimal shape check — we don't full-validate here because the
|
|
81
|
+
// server is the trust boundary. Just guard against obvious
|
|
82
|
+
// corruption that would make the line un-submittable.
|
|
83
|
+
if (typeof parsed.category === 'string'
|
|
84
|
+
&& typeof parsed.rating === 'number'
|
|
85
|
+
&& typeof parsed.comment === 'string'
|
|
86
|
+
&& typeof parsed.ts === 'string'
|
|
87
|
+
&& typeof parsed.cliVersion === 'string') {
|
|
88
|
+
envelopes.push(parsed);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
parseErrors.push(i + 1);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
parseErrors.push(i + 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { envelopes, parseErrors };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Rewrite the queue file atomically with the remaining (unsubmitted)
|
|
102
|
+
* envelopes. Called by the flusher after a partial-success drain.
|
|
103
|
+
*
|
|
104
|
+
* Atomicity: write to a sibling `.tmp` then rename. On a crash mid-
|
|
105
|
+
* rewrite the original file is preserved (rename is atomic on POSIX
|
|
106
|
+
* + on NTFS via `MoveFileEx`).
|
|
107
|
+
*/
|
|
108
|
+
export function rewriteFeedbackQueue(remaining, cwd) {
|
|
109
|
+
const path = feedbackQueuePath(cwd);
|
|
110
|
+
if (remaining.length === 0) {
|
|
111
|
+
// Clear the file by truncating to empty. Done in-place — we still
|
|
112
|
+
// want the file to exist (presence signals an active workspace)
|
|
113
|
+
// but with zero bytes so the next read returns no envelopes.
|
|
114
|
+
if (existsSync(path)) {
|
|
115
|
+
writeFileSync(path, '', { encoding: 'utf8' });
|
|
116
|
+
}
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
120
|
+
const tmp = `${path}.tmp`;
|
|
121
|
+
const body = remaining.map((env) => JSON.stringify(env)).join('\n') + '\n';
|
|
122
|
+
writeFileSync(tmp, body, { encoding: 'utf8' });
|
|
123
|
+
// Use writeFileSync's atomic-replace semantics by going through
|
|
124
|
+
// tmp + rename. Node's `fs.renameSync` is the atomic primitive
|
|
125
|
+
// on POSIX. We avoid `fs.writeFileSync` directly on `path`
|
|
126
|
+
// because writeFileSync truncates first which leaves a brief
|
|
127
|
+
// window of zero-byte state if the process is killed mid-write.
|
|
128
|
+
renameSync(tmp, path);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Drain the queue. Best-effort: each envelope is submitted in order;
|
|
132
|
+
* a `false` return keeps it in the queue for the next attempt; a
|
|
133
|
+
* `true` return removes it. After all envelopes are processed the
|
|
134
|
+
* queue file is rewritten with the unsubmitted ones.
|
|
135
|
+
*
|
|
136
|
+
* The function NEVER throws — it returns a structured result and
|
|
137
|
+
* the caller decides whether to log / surface failures. This keeps
|
|
138
|
+
* the silent-background-drain path on session-start safe.
|
|
139
|
+
*/
|
|
140
|
+
export async function flushFeedbackQueue(cwd, submit) {
|
|
141
|
+
const { envelopes, parseErrors } = readFeedbackQueue(cwd);
|
|
142
|
+
if (envelopes.length === 0) {
|
|
143
|
+
return {
|
|
144
|
+
attempted: 0,
|
|
145
|
+
succeeded: 0,
|
|
146
|
+
failed: 0,
|
|
147
|
+
failedEnvelopes: [],
|
|
148
|
+
parseErrors,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
let succeeded = 0;
|
|
152
|
+
const failedEnvelopes = [];
|
|
153
|
+
for (const env of envelopes) {
|
|
154
|
+
let ok = false;
|
|
155
|
+
try {
|
|
156
|
+
ok = await submit(env);
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
ok = false;
|
|
160
|
+
}
|
|
161
|
+
if (ok) {
|
|
162
|
+
succeeded += 1;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
failedEnvelopes.push(env);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
rewriteFeedbackQueue(failedEnvelopes, cwd);
|
|
169
|
+
return {
|
|
170
|
+
attempted: envelopes.length,
|
|
171
|
+
succeeded,
|
|
172
|
+
failed: failedEnvelopes.length,
|
|
173
|
+
failedEnvelopes,
|
|
174
|
+
parseErrors,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Feedback POST submitter — Leak L21 (2026-05-27).
|
|
3
|
+
*
|
|
4
|
+
* Submits one `FeedbackEnvelope` to the admin-api `/api/pugi/feedback`
|
|
5
|
+
* route. Designed for graceful degradation:
|
|
6
|
+
*
|
|
7
|
+
* - 200/201/204 → success
|
|
8
|
+
* - 404 / route not found → "endpoint missing, fall back to queue"
|
|
9
|
+
* - 4xx (other) → permanent — discard (do NOT requeue)
|
|
10
|
+
* - 5xx / network error / abort → transient — caller should enqueue
|
|
11
|
+
*
|
|
12
|
+
* The submitter does NOT touch the local queue. The caller wires the
|
|
13
|
+
* submitter to `enqueueFeedback` on a `transient` result, and to a
|
|
14
|
+
* silent log on a `permanent` failure. This split keeps the submitter
|
|
15
|
+
* a pure HTTP wrapper that the flusher (`flushFeedbackQueue`) can
|
|
16
|
+
* reuse without filesystem side effects.
|
|
17
|
+
*/
|
|
18
|
+
const DEFAULT_TIMEOUT_MS = 8000;
|
|
19
|
+
/**
|
|
20
|
+
* Build the absolute submit URL from the base API URL. Centralised so
|
|
21
|
+
* the spec can reference one canonical place when asserting the
|
|
22
|
+
* outgoing path. The leading slash is normalised so a base URL with
|
|
23
|
+
* or without trailing slash both produce a well-formed URL.
|
|
24
|
+
*/
|
|
25
|
+
export function feedbackSubmitUrl(apiUrl) {
|
|
26
|
+
const base = apiUrl.replace(/\/+$/u, '');
|
|
27
|
+
return `${base}/api/pugi/feedback`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Submit one envelope. See `FeedbackSubmitResult` for the contract.
|
|
31
|
+
*
|
|
32
|
+
* Never throws — every failure path is mapped to a result variant so
|
|
33
|
+
* callers do not need a try/catch boundary.
|
|
34
|
+
*/
|
|
35
|
+
export async function submitFeedback(env, config) {
|
|
36
|
+
const url = feedbackSubmitUrl(config.apiUrl);
|
|
37
|
+
const fetchImpl = config.fetchImpl ?? fetch;
|
|
38
|
+
const timeoutMs = config.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
41
|
+
try {
|
|
42
|
+
const headers = {
|
|
43
|
+
'content-type': 'application/json',
|
|
44
|
+
'user-agent': `pugi-cli/${env.cliVersion}`,
|
|
45
|
+
};
|
|
46
|
+
if (config.apiKey) {
|
|
47
|
+
headers['authorization'] = `Bearer ${config.apiKey}`;
|
|
48
|
+
}
|
|
49
|
+
const res = await fetchImpl(url, {
|
|
50
|
+
method: 'POST',
|
|
51
|
+
headers,
|
|
52
|
+
body: JSON.stringify(env),
|
|
53
|
+
signal: controller.signal,
|
|
54
|
+
});
|
|
55
|
+
const status = res.status;
|
|
56
|
+
if (status >= 200 && status < 300) {
|
|
57
|
+
return { kind: 'ok', httpStatus: status };
|
|
58
|
+
}
|
|
59
|
+
if (status === 404) {
|
|
60
|
+
// The most common transient cause: admin-api hasn't shipped the
|
|
61
|
+
// route yet. Treat as retry-worthy so once the controller lands
|
|
62
|
+
// a future flush picks it up.
|
|
63
|
+
return {
|
|
64
|
+
kind: 'transient',
|
|
65
|
+
reason: 'admin-api /api/pugi/feedback not deployed yet',
|
|
66
|
+
httpStatus: status,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
if (status >= 500) {
|
|
70
|
+
return {
|
|
71
|
+
kind: 'transient',
|
|
72
|
+
reason: `server error ${status}`,
|
|
73
|
+
httpStatus: status,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Any other 4xx — auth failure, payload rejected, rate-limit
|
|
77
|
+
// exceeded. None of those will fix themselves on a silent retry,
|
|
78
|
+
// so we mark them permanent. The operator sees a one-line error
|
|
79
|
+
// and the envelope is dropped (not queued).
|
|
80
|
+
return {
|
|
81
|
+
kind: 'permanent',
|
|
82
|
+
reason: `client error ${status}`,
|
|
83
|
+
httpStatus: status,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
88
|
+
// AbortController.abort fires when the timeout elapses. We treat
|
|
89
|
+
// it as transient so the queue picks it up on the next online
|
|
90
|
+
// session. Same for plain network errors (`fetch failed`, ECONNREFUSED).
|
|
91
|
+
return { kind: 'transient', reason: `network: ${message}` };
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Bundle the last N turns of the conversation into a redacted
|
|
99
|
+
* `FeedbackSessionContext`. The redactor:
|
|
100
|
+
*
|
|
101
|
+
* - Caps at 5 turns (most recent). Older context is dropped — the
|
|
102
|
+
* submitter never sees it.
|
|
103
|
+
* - Truncates each turn to 240 chars + ellipsis. Operator comments
|
|
104
|
+
* are the primary signal; raw transcript is just disambiguation.
|
|
105
|
+
* - Strips bearer tokens, JWT-like blobs, and `PUGI_API_KEY=`-style
|
|
106
|
+
* env-var prefixes. Conservative — we'd rather drop a few
|
|
107
|
+
* non-secret characters than leak a key.
|
|
108
|
+
*
|
|
109
|
+
* The function is pure + sync so tests can pin its output without a
|
|
110
|
+
* worktree harness.
|
|
111
|
+
*/
|
|
112
|
+
export function redactSessionContext(turns, options = {}) {
|
|
113
|
+
const lastFive = turns.slice(-5);
|
|
114
|
+
const previewed = lastFive.map((turn) => ({
|
|
115
|
+
role: turn.role,
|
|
116
|
+
preview: redactPreview(truncate(turn.text, 240)),
|
|
117
|
+
}));
|
|
118
|
+
return {
|
|
119
|
+
turnCount: previewed.length,
|
|
120
|
+
turns: previewed,
|
|
121
|
+
...(options.gitBranch ? { gitBranch: options.gitBranch } : {}),
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
function truncate(s, max) {
|
|
125
|
+
if (s.length <= max)
|
|
126
|
+
return s;
|
|
127
|
+
return `${s.slice(0, max - 1)}…`;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Conservative secret-blanking. The rules:
|
|
131
|
+
* - Bearer tokens: `Bearer <token>` → `Bearer ***REDACTED***`
|
|
132
|
+
* - Long base64/JWT-ish blobs (≥ 40 chars of [A-Za-z0-9_-/=+]):
|
|
133
|
+
* replace the inner middle with `***`. Keeps a head + tail so the
|
|
134
|
+
* operator can still spot which kind of secret it was.
|
|
135
|
+
* - `PUGI_API_KEY=...` and similar `*_KEY=`/`*_TOKEN=` lookalikes:
|
|
136
|
+
* replace the value with `***REDACTED***`.
|
|
137
|
+
*/
|
|
138
|
+
function redactPreview(s) {
|
|
139
|
+
let out = s;
|
|
140
|
+
out = out.replace(/bearer\s+[A-Za-z0-9._-]{20,}/giu, 'Bearer ***REDACTED***');
|
|
141
|
+
out = out.replace(/([A-Z][A-Z0-9_]*?(?:KEY|TOKEN|SECRET|PASSWORD))\s*=\s*\S+/gu, '$1=***REDACTED***');
|
|
142
|
+
out = out.replace(/\b([A-Za-z0-9_-]{6})[A-Za-z0-9_/+=-]{30,}([A-Za-z0-9_-]{4})\b/gu, '$1***$2');
|
|
143
|
+
return out;
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=submitter.js.map
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Leak L25 (2026-05-27) — Onboarding marker file.
|
|
3
|
+
*
|
|
4
|
+
* `~/.pugi/.onboarded` is a single, contentless marker. Its existence
|
|
5
|
+
* tells the bare-invocation hint check that the operator has already
|
|
6
|
+
* walked the `/onboarding` wizard at least once, so we no longer print
|
|
7
|
+
* the "Tip: run `pugi onboarding` to configure defaults" line on
|
|
8
|
+
* cold-start. The wizard re-runs cleanly — idempotency lives in the
|
|
9
|
+
* wizard itself, not in the marker.
|
|
10
|
+
*
|
|
11
|
+
* Why a marker file (and not just `~/.pugi/config.json`'s existence)?
|
|
12
|
+
*
|
|
13
|
+
* - The config file is touched the moment ANY surface writes a
|
|
14
|
+
* default — `pugi style terse --persist`, `pugi permissions ask`,
|
|
15
|
+
* `pugi config set …`. Using "config exists" as the proxy for
|
|
16
|
+
* "operator has onboarded" would silence the first-run hint for
|
|
17
|
+
* operators who never saw the wizard.
|
|
18
|
+
*
|
|
19
|
+
* - The marker is explicit: it is written ONLY by the wizard's exit
|
|
20
|
+
* step (or `pugi onboarding --mark-only` for the upgrade-path
|
|
21
|
+
* where we want to suppress the hint without forcing a re-walk).
|
|
22
|
+
*
|
|
23
|
+
* - Removing the marker (`rm ~/.pugi/.onboarded`) re-arms the hint
|
|
24
|
+
* without nuking the operator's accumulated config — useful for
|
|
25
|
+
* QA, support flows, and demo-machine resets.
|
|
26
|
+
*
|
|
27
|
+
* Path resolution mirrors the L6/L18 convention: `PUGI_HOME` env wins,
|
|
28
|
+
* else `~/.pugi`. The marker is touched as an empty file (no JSON, no
|
|
29
|
+
* timestamp payload) — readers MUST treat existence as the only signal
|
|
30
|
+
* so a future change to mtime semantics does not break us.
|
|
31
|
+
*
|
|
32
|
+
* IO contract:
|
|
33
|
+
* - `isOnboarded(env)` — pure read; never throws, returns false on
|
|
34
|
+
* any fs error so a corrupted home dir cannot hide the hint.
|
|
35
|
+
* - `markOnboarded(env)` — best-effort write; creates `<home>/.pugi/`
|
|
36
|
+
* if missing, mode 0o600 on the marker so it never lands in a
|
|
37
|
+
* world-readable backup.
|
|
38
|
+
* - `clearOnboarded(env)` — best-effort delete; absent file is a
|
|
39
|
+
* no-op (not an error). Used by `pugi onboarding --reset` and the
|
|
40
|
+
* spec teardown.
|
|
41
|
+
*/
|
|
42
|
+
import { existsSync, mkdirSync, rmSync, writeFileSync, } from 'node:fs';
|
|
43
|
+
import { homedir } from 'node:os';
|
|
44
|
+
import { resolve } from 'node:path';
|
|
45
|
+
/**
|
|
46
|
+
* Env override for `~/.pugi`. Same convention as L6 / L18 — spec
|
|
47
|
+
* fixtures point this at a temp dir so a real developer machine never
|
|
48
|
+
* lands a stray marker.
|
|
49
|
+
*/
|
|
50
|
+
export const PUGI_HOME_ENV = 'PUGI_HOME';
|
|
51
|
+
/**
|
|
52
|
+
* Marker basename. Hidden (leading dot) so it does not clutter `ls`
|
|
53
|
+
* inside `~/.pugi/` next to `config.json` / `session.json`.
|
|
54
|
+
*/
|
|
55
|
+
const MARKER_BASENAME = '.onboarded';
|
|
56
|
+
/**
|
|
57
|
+
* Resolve the absolute path to the onboarding marker. Exported for the
|
|
58
|
+
* spec; production callers go through `isOnboarded` / `markOnboarded`.
|
|
59
|
+
*/
|
|
60
|
+
export function onboardingMarkerPath(env = process.env) {
|
|
61
|
+
const home = env[PUGI_HOME_ENV] ?? resolve(homedir(), '.pugi');
|
|
62
|
+
return resolve(home, MARKER_BASENAME);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* True when the marker exists. Pure read. Defensive: any fs error
|
|
66
|
+
* (race with deletion, permission flip) degrades to `false` — printing
|
|
67
|
+
* the hint twice is harmless, silently swallowing the wizard would
|
|
68
|
+
* surprise the operator.
|
|
69
|
+
*/
|
|
70
|
+
export function isOnboarded(env = process.env) {
|
|
71
|
+
try {
|
|
72
|
+
return existsSync(onboardingMarkerPath(env));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Touch the marker. Creates `<home>/.pugi/` if missing. Idempotent —
|
|
80
|
+
* re-touching an existing marker is a no-op for the consumer (the file
|
|
81
|
+
* was already there; the hint was already suppressed).
|
|
82
|
+
*
|
|
83
|
+
* Best-effort: a write failure is swallowed because the wizard already
|
|
84
|
+
* completed its real work (mode + style + telemetry were persisted).
|
|
85
|
+
* The worst case is a redundant hint on the next `pugi` invocation —
|
|
86
|
+
* preferable to crashing the freshly-completed wizard with a stat EIO.
|
|
87
|
+
*/
|
|
88
|
+
export function markOnboarded(env = process.env) {
|
|
89
|
+
const path = onboardingMarkerPath(env);
|
|
90
|
+
try {
|
|
91
|
+
mkdirSync(resolve(path, '..'), { recursive: true });
|
|
92
|
+
writeFileSync(path, '', { encoding: 'utf8', mode: 0o600 });
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// intentionally swallowed — see header
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Remove the marker. Used by `pugi onboarding --reset` (and the spec
|
|
100
|
+
* teardown). Absent file is a no-op; any other fs error is swallowed
|
|
101
|
+
* so a permission glitch never leaks out of the reset surface.
|
|
102
|
+
*/
|
|
103
|
+
export function clearOnboarded(env = process.env) {
|
|
104
|
+
try {
|
|
105
|
+
rmSync(onboardingMarkerPath(env), { force: true });
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
// intentionally swallowed — see header
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=marker.js.map
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Leak L25 (2026-05-27) — Telemetry consent state.
|
|
3
|
+
*
|
|
4
|
+
* The onboarding wizard's Step 5 asks the operator for telemetry
|
|
5
|
+
* consent. We persist the verdict in the user-tier
|
|
6
|
+
* `~/.pugi/config.json::telemetry` field so a future REPL boot can
|
|
7
|
+
* read it without re-asking. Choices mirror `core/settings.ts`'s
|
|
8
|
+
* `privacy.telemetry` enum:
|
|
9
|
+
*
|
|
10
|
+
* - `off` — no telemetry of any kind (default).
|
|
11
|
+
* - `anonymous` — counts + error categories only, no payloads.
|
|
12
|
+
* - `community` — anonymous + opt-in skill/usage panels.
|
|
13
|
+
*
|
|
14
|
+
* This module is intentionally narrow: it only owns the `telemetry`
|
|
15
|
+
* key inside `~/.pugi/config.json`. The full settings parsing lives in
|
|
16
|
+
* `core/settings.ts` (workspace-tier `.pugi/settings.json`); we do NOT
|
|
17
|
+
* route through it here because:
|
|
18
|
+
*
|
|
19
|
+
* 1. The settings schema is workspace-scoped — its file path is
|
|
20
|
+
* `<root>/.pugi/settings.json`, not `~/.pugi/config.json`.
|
|
21
|
+
* 2. The wizard records a user-level default that workspace settings
|
|
22
|
+
* can later override. Mixing the two would conflate scope.
|
|
23
|
+
* 3. Read-modify-write on a partial JSON file is the same pattern
|
|
24
|
+
* L6 / L18 use for adjacent keys — keeping it self-contained
|
|
25
|
+
* preserves the "one module, one key" invariant.
|
|
26
|
+
*/
|
|
27
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, } from 'node:fs';
|
|
28
|
+
import { homedir } from 'node:os';
|
|
29
|
+
import { dirname, resolve } from 'node:path';
|
|
30
|
+
import { PUGI_HOME_ENV } from './marker.js';
|
|
31
|
+
export const TELEMETRY_CHOICES = Object.freeze([
|
|
32
|
+
'off',
|
|
33
|
+
'anonymous',
|
|
34
|
+
'community',
|
|
35
|
+
]);
|
|
36
|
+
export const DEFAULT_TELEMETRY = 'off';
|
|
37
|
+
/**
|
|
38
|
+
* Path to the user-tier config. Mirrors `userConfigPath()` from L18
|
|
39
|
+
* `output-style/state.ts` — duplicated here (not imported) to keep the
|
|
40
|
+
* marker + telemetry module self-contained. Any future drift between
|
|
41
|
+
* the two would surface a spec failure: both modules read the same
|
|
42
|
+
* file in the spec sandbox.
|
|
43
|
+
*/
|
|
44
|
+
export function telemetryConfigPath(env = process.env) {
|
|
45
|
+
const home = env[PUGI_HOME_ENV] ?? resolve(homedir(), '.pugi');
|
|
46
|
+
return resolve(home, 'config.json');
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Type guard for arbitrary string input (CLI argv, config.json
|
|
50
|
+
* deserialisation). Returns false for any non-string or out-of-set
|
|
51
|
+
* value so a malformed config degrades to the default verdict.
|
|
52
|
+
*/
|
|
53
|
+
export function isTelemetryChoice(value) {
|
|
54
|
+
return (typeof value === 'string'
|
|
55
|
+
&& TELEMETRY_CHOICES.includes(value));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Read the persisted telemetry verdict. Returns the default (`'off'`)
|
|
59
|
+
* when the file is absent, empty, malformed, or holds an unknown
|
|
60
|
+
* value. Never throws — the wizard re-asks every time it runs, so a
|
|
61
|
+
* defensive read is the right posture.
|
|
62
|
+
*/
|
|
63
|
+
export function readTelemetryChoice(io = {}) {
|
|
64
|
+
const config = readConfigFile(telemetryConfigPath(io.env ?? process.env));
|
|
65
|
+
return isTelemetryChoice(config.telemetry) ? config.telemetry : DEFAULT_TELEMETRY;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Persist the telemetry verdict. Read-modify-write preserves any
|
|
69
|
+
* neighbouring keys (`outputStyle`, `defaultPermissionMode`, …) the
|
|
70
|
+
* other tier-state modules own.
|
|
71
|
+
*/
|
|
72
|
+
export function writeTelemetryChoice(choice, io = {}) {
|
|
73
|
+
const path = telemetryConfigPath(io.env ?? process.env);
|
|
74
|
+
const config = readConfigFile(path);
|
|
75
|
+
config.telemetry = choice;
|
|
76
|
+
writeConfigFile(path, config);
|
|
77
|
+
}
|
|
78
|
+
function readConfigFile(path) {
|
|
79
|
+
if (!existsSync(path))
|
|
80
|
+
return {};
|
|
81
|
+
let raw;
|
|
82
|
+
try {
|
|
83
|
+
raw = readFileSync(path, 'utf8');
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
return {};
|
|
87
|
+
}
|
|
88
|
+
if (raw.trim().length === 0)
|
|
89
|
+
return {};
|
|
90
|
+
let parsed;
|
|
91
|
+
try {
|
|
92
|
+
parsed = JSON.parse(raw);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return {};
|
|
96
|
+
}
|
|
97
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
|
|
98
|
+
return {};
|
|
99
|
+
return parsed;
|
|
100
|
+
}
|
|
101
|
+
function writeConfigFile(path, config) {
|
|
102
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
103
|
+
writeFileSync(path, `${JSON.stringify(config, null, 2)}\n`, {
|
|
104
|
+
encoding: 'utf8',
|
|
105
|
+
mode: 0o600,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=telemetry-state.js.map
|