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

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.
@@ -0,0 +1,297 @@
1
+ /**
2
+ * Project onboarding state for the Pugi REPL.
3
+ *
4
+ * Inspired by Claude Code's projectOnboardingState pattern (the leaked
5
+ * upstream file ships a 4-flag memoized check called on every prompt
6
+ * submit). Independent implementation: the storage location, the steps,
7
+ * the reset path, and the cap counter are all Pugi-shaped.
8
+ *
9
+ * # Why this exists
10
+ *
11
+ * The REPL's status bar can flash a `setup needed: run /init` hint when
12
+ * a workspace is still ungoverned (no PUGI.md, no skills installed). The
13
+ * hint must NEVER show on a workspace where the operator already ran the
14
+ * interview - otherwise the prompt becomes nag-noise. Three layered
15
+ * short-circuits guarantee that:
16
+ *
17
+ * 1. `hasCompletedOnboarding === true` in `~/.pugi/state.json` -> stop.
18
+ * The interview's final phase writes this flag once; subsequent
19
+ * REPL boots short-circuit at the global ledger and never even
20
+ * stat the workspace.
21
+ * 2. `onboardingSeenCount >= 4` -> stop. If the operator dismissed
22
+ * the hint four times without finishing the interview, assume they
23
+ * do not want it. The bar stays clean from boot 5 onward.
24
+ * 3. `PUGI_IS_DEMO=1` -> stop. The demo / snapshot recorder sets this
25
+ * so the screen capture stays free of onboarding chrome.
26
+ *
27
+ * If none short-circuit, the function checks the per-workspace steps
28
+ * (`PUGI.md` present, at least one skill installed, auth ok, workspace
29
+ * dir bound) and returns `true` only when at least one step is still
30
+ * incomplete.
31
+ *
32
+ * # Storage shape
33
+ *
34
+ * The global state file is JSON-on-disk at
35
+ * `~/.pugi/state.json`. It carries two scalars:
36
+ *
37
+ * {
38
+ * "hasCompletedOnboarding": boolean,
39
+ * "onboardingSeenCount": integer >= 0
40
+ * }
41
+ *
42
+ * The file is read at most once per process (memoized) so the hot path
43
+ * is in-memory. `incrementSeenCount()` re-reads the file before
44
+ * mutating to avoid clobbering a sibling Pugi process's increment
45
+ * (concurrent REPLs in two terminals). Atomic-ish: we write to
46
+ * `state.json.tmp` then rename. A race that overwrites another
47
+ * increment is benign - the worst case is a single missed +1 across
48
+ * two siblings.
49
+ *
50
+ * # Reset path
51
+ *
52
+ * `rm ~/.pugi/state.json` resets every flag. Tests rely on this:
53
+ * `resetOnboardingStateForTests(stateDir)` is the public helper that
54
+ * removes the file and clears the memoization cache.
55
+ */
56
+ import { existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
57
+ import { homedir } from 'node:os';
58
+ import { join } from 'node:path';
59
+ const DEFAULT_STATE = Object.freeze({
60
+ hasCompletedOnboarding: false,
61
+ onboardingSeenCount: 0,
62
+ });
63
+ /** Hard cap; once the operator has seen the hint this many times we stop. */
64
+ export const ONBOARDING_SEEN_CAP = 4;
65
+ /**
66
+ * Singleton memoization cache - cleared by `resetMemoizationForTests`.
67
+ * Keyed by stateDir so concurrent specs in the same process do not
68
+ * interfere with each other.
69
+ */
70
+ const SHOULD_SHOW_CACHE = new Map();
71
+ const PERSISTED_STATE_CACHE = new Map();
72
+ /**
73
+ * Default fs implementation - the real `node:fs` module wrapped into
74
+ * the minimal surface this file uses.
75
+ */
76
+ const REAL_FS = {
77
+ existsSync,
78
+ readFileSync: (path, encoding) => readFileSync(path, encoding),
79
+ writeFileSync: (path, data, options) => writeFileSync(path, data, options),
80
+ mkdirSync: (path, opts) => {
81
+ mkdirSync(path, opts);
82
+ },
83
+ renameSync,
84
+ rmSync: (path, opts) => rmSync(path, opts),
85
+ readdirSync: (path) => readdirSync(path),
86
+ };
87
+ /**
88
+ * Compute the four Pugi-specific onboarding steps for the given
89
+ * workspace. Pure: the only side effect is the filesystem probe (which
90
+ * tests stub via `probes.fs`).
91
+ */
92
+ export function getSteps(probes) {
93
+ const fs = probes.fs ?? REAL_FS;
94
+ const pugiDirPath = join(probes.cwd, '.pugi');
95
+ const hasWorkspaceDir = fs.existsSync(pugiDirPath);
96
+ const hasPugiMd = fs.existsSync(join(probes.cwd, 'PUGI.md')) ||
97
+ fs.existsSync(join(pugiDirPath, 'PUGI.md'));
98
+ const skillsDir = join(pugiDirPath, 'skills');
99
+ const hasSkill = fs.existsSync(skillsDir) && !isEmptyDir(skillsDir, fs);
100
+ return [
101
+ {
102
+ key: 'workspace',
103
+ text: 'Bind a workspace by running pugi init',
104
+ isComplete: hasWorkspaceDir,
105
+ isEnabled: true,
106
+ },
107
+ {
108
+ key: 'pugimd',
109
+ text: 'Run /init to write PUGI.md with project context',
110
+ isComplete: hasPugiMd,
111
+ isEnabled: hasWorkspaceDir,
112
+ },
113
+ {
114
+ key: 'skills',
115
+ text: 'Install at least one skill under .pugi/skills/',
116
+ isComplete: hasSkill,
117
+ isEnabled: hasWorkspaceDir,
118
+ },
119
+ {
120
+ key: 'auth',
121
+ text: 'Run pugi login to authenticate',
122
+ isComplete: probes.authOk,
123
+ isEnabled: true,
124
+ },
125
+ ];
126
+ }
127
+ /**
128
+ * Roll-up over the steps. True when every ENABLED step is complete -
129
+ * disabled steps (e.g. `pugimd` before `workspace` is set up) are
130
+ * excluded so the operator does not get stuck on a step they cannot
131
+ * action yet.
132
+ */
133
+ export function isOnboardingComplete(probes) {
134
+ const steps = getSteps(probes);
135
+ return steps
136
+ .filter((s) => s.isEnabled)
137
+ .every((s) => s.isComplete);
138
+ }
139
+ /**
140
+ * The exported gate the REPL status bar consults. Memoized per
141
+ * stateDir; the hot path is one map lookup once the first call has run.
142
+ */
143
+ export function shouldShowOnboarding(probes) {
144
+ const stateDir = probes.stateDir ?? defaultStateDir();
145
+ const cached = SHOULD_SHOW_CACHE.get(stateDir);
146
+ if (cached !== undefined)
147
+ return cached;
148
+ const persisted = loadPersistedState(stateDir, probes.fs ?? REAL_FS);
149
+ const isDemo = probes.isDemoOverride ?? (process.env.PUGI_IS_DEMO === '1');
150
+ if (persisted.hasCompletedOnboarding) {
151
+ SHOULD_SHOW_CACHE.set(stateDir, false);
152
+ return false;
153
+ }
154
+ if (persisted.onboardingSeenCount >= ONBOARDING_SEEN_CAP) {
155
+ SHOULD_SHOW_CACHE.set(stateDir, false);
156
+ return false;
157
+ }
158
+ if (isDemo) {
159
+ SHOULD_SHOW_CACHE.set(stateDir, false);
160
+ return false;
161
+ }
162
+ const verdict = !isOnboardingComplete(probes);
163
+ SHOULD_SHOW_CACHE.set(stateDir, verdict);
164
+ return verdict;
165
+ }
166
+ /**
167
+ * Idempotent setter: if the workspace is now fully onboarded, flip the
168
+ * persisted flag. Cheap to call on every prompt submit because the
169
+ * fast path short-circuits on the in-memory cache.
170
+ *
171
+ * The "maybe" prefix mirrors the upstream pattern: a no-op is the
172
+ * common case; the write only fires once when the operator's most
173
+ * recent action just completed the ladder.
174
+ */
175
+ export function maybeMarkOnboardingComplete(probes) {
176
+ const stateDir = probes.stateDir ?? defaultStateDir();
177
+ const fs = probes.fs ?? REAL_FS;
178
+ const persisted = loadPersistedState(stateDir, fs);
179
+ if (persisted.hasCompletedOnboarding)
180
+ return;
181
+ if (!isOnboardingComplete(probes))
182
+ return;
183
+ persistState(stateDir, fs, { ...persisted, hasCompletedOnboarding: true });
184
+ // Invalidate the cache so the next `shouldShowOnboarding` call sees
185
+ // the new value without restarting the process.
186
+ SHOULD_SHOW_CACHE.delete(stateDir);
187
+ }
188
+ /**
189
+ * Increment the seen counter. The REPL status bar calls this once per
190
+ * boot where it actually rendered the hint. After
191
+ * `ONBOARDING_SEEN_CAP` increments the cap guard in
192
+ * `shouldShowOnboarding` flips the gate off permanently for this user.
193
+ */
194
+ export function incrementOnboardingSeenCount(probes) {
195
+ const stateDir = probes.stateDir ?? defaultStateDir();
196
+ const fs = probes.fs ?? REAL_FS;
197
+ const persisted = loadPersistedState(stateDir, fs);
198
+ const next = {
199
+ ...persisted,
200
+ onboardingSeenCount: persisted.onboardingSeenCount + 1,
201
+ };
202
+ persistState(stateDir, fs, next);
203
+ SHOULD_SHOW_CACHE.delete(stateDir);
204
+ }
205
+ /**
206
+ * Reset every persisted flag. Tests use this via the public helper; an
207
+ * operator can achieve the same effect by `rm ~/.pugi/state.json`.
208
+ */
209
+ export function resetOnboardingStateForTests(probes) {
210
+ const stateDir = probes.stateDir ?? defaultStateDir();
211
+ const fs = probes.fs ?? REAL_FS;
212
+ const file = stateFilePath(stateDir);
213
+ if (fs.existsSync(file)) {
214
+ fs.rmSync(file, { force: true });
215
+ }
216
+ SHOULD_SHOW_CACHE.delete(stateDir);
217
+ PERSISTED_STATE_CACHE.delete(stateDir);
218
+ }
219
+ /**
220
+ * Clear the in-memory memoization without touching the disk. The
221
+ * spec uses this between assertions when it wants to force a re-read.
222
+ */
223
+ export function resetMemoizationForTests(stateDir) {
224
+ if (stateDir) {
225
+ SHOULD_SHOW_CACHE.delete(stateDir);
226
+ PERSISTED_STATE_CACHE.delete(stateDir);
227
+ return;
228
+ }
229
+ SHOULD_SHOW_CACHE.clear();
230
+ PERSISTED_STATE_CACHE.clear();
231
+ }
232
+ /* ------------------------------------------------------------------ */
233
+ /* Internal helpers */
234
+ /* ------------------------------------------------------------------ */
235
+ function defaultStateDir() {
236
+ return join(homedir(), '.pugi');
237
+ }
238
+ function stateFilePath(stateDir) {
239
+ return join(stateDir, 'state.json');
240
+ }
241
+ function loadPersistedState(stateDir, fs) {
242
+ const cached = PERSISTED_STATE_CACHE.get(stateDir);
243
+ if (cached !== undefined)
244
+ return cached;
245
+ const file = stateFilePath(stateDir);
246
+ if (!fs.existsSync(file)) {
247
+ PERSISTED_STATE_CACHE.set(stateDir, DEFAULT_STATE);
248
+ return DEFAULT_STATE;
249
+ }
250
+ try {
251
+ const raw = fs.readFileSync(file, 'utf8');
252
+ const parsed = JSON.parse(raw);
253
+ const normalized = {
254
+ hasCompletedOnboarding: parsed.hasCompletedOnboarding === true,
255
+ onboardingSeenCount: typeof parsed.onboardingSeenCount === 'number' &&
256
+ Number.isFinite(parsed.onboardingSeenCount) &&
257
+ parsed.onboardingSeenCount >= 0
258
+ ? Math.floor(parsed.onboardingSeenCount)
259
+ : 0,
260
+ };
261
+ PERSISTED_STATE_CACHE.set(stateDir, normalized);
262
+ return normalized;
263
+ }
264
+ catch {
265
+ // Corrupt file - treat as if it were absent. The next persist
266
+ // overwrites with a clean shape; we never crash the REPL boot on
267
+ // an unreadable state file.
268
+ PERSISTED_STATE_CACHE.set(stateDir, DEFAULT_STATE);
269
+ return DEFAULT_STATE;
270
+ }
271
+ }
272
+ function persistState(stateDir, fs, next) {
273
+ if (!fs.existsSync(stateDir)) {
274
+ fs.mkdirSync(stateDir, { recursive: true });
275
+ }
276
+ const file = stateFilePath(stateDir);
277
+ const tmp = `${file}.tmp`;
278
+ fs.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, { encoding: 'utf8', mode: 0o600 });
279
+ fs.renameSync(tmp, file);
280
+ PERSISTED_STATE_CACHE.set(stateDir, next);
281
+ }
282
+ function isEmptyDir(path, fs) {
283
+ // An empty `skills/` directory counts as "no skill installed yet" so
284
+ // the onboarding step stays incomplete. The injected fs shim may
285
+ // omit `readdirSync` - in that case we conservatively report
286
+ // non-empty (the dir existed, so the operator likely did something
287
+ // intentional) to avoid false-positive nag.
288
+ if (!fs.readdirSync)
289
+ return false;
290
+ try {
291
+ return fs.readdirSync(path).length === 0;
292
+ }
293
+ catch {
294
+ return true;
295
+ }
296
+ }
297
+ //# sourceMappingURL=onboarding-state.js.map
@@ -27,6 +27,7 @@
27
27
  * verbatim - the brand gate on those happens at the controller.
28
28
  */
29
29
  import { randomUUID } from 'node:crypto';
30
+ import { homedir } from 'node:os';
30
31
  import { getPersona } from '@pugi/personas';
31
32
  import { listRoles, getPersonaForRole } from '../agents/registry.js';
32
33
  import { evaluateCap, describeVerdict } from './cap-warning.js';
@@ -1167,6 +1168,54 @@ export class ReplSession {
1167
1168
  }
1168
1169
  return verdict;
1169
1170
  }
1171
+ case 'update': {
1172
+ // Leak L27 (2026-05-27): /update probes the npm registry for a
1173
+ // newer @pugi/cli version on the configured channel and prints
1174
+ // the install command. The slash form NEVER spawns `npm install
1175
+ // -g` — that would corrupt the binary we are currently running.
1176
+ // Operators see the install command + run it manually (or run
1177
+ // `pugi update --apply` from a fresh shell after the REPL
1178
+ // exits). The slash + top-level paths share the dispatcher so
1179
+ // channel resolution + last-check persistence stay single-
1180
+ // sourced.
1181
+ try {
1182
+ const { parseUpdateArgs, runUpdateCommand } = await import('../../runtime/commands/update.js');
1183
+ const parsed = parseUpdateArgs(verdict.args);
1184
+ if ('error' in parsed) {
1185
+ this.appendSystemLine(parsed.error);
1186
+ return verdict;
1187
+ }
1188
+ // Force `apply=false` on the slash path — see comment above.
1189
+ const slashFlags = { ...parsed, apply: false };
1190
+ const lines = [];
1191
+ await runUpdateCommand({
1192
+ cwd: process.cwd(),
1193
+ home: homedir(),
1194
+ env: process.env,
1195
+ flags: slashFlags,
1196
+ promptConfirm: async () => false,
1197
+ writeOutput: (_payload, text) => {
1198
+ for (const line of text.split('\n')) {
1199
+ const trimmed = line.replace(/\s+$/u, '');
1200
+ if (trimmed.length > 0)
1201
+ lines.push(trimmed);
1202
+ }
1203
+ },
1204
+ });
1205
+ if (lines.length === 0) {
1206
+ this.appendSystemLine('/update: no output.');
1207
+ }
1208
+ else {
1209
+ for (const line of lines)
1210
+ this.appendSystemLine(line);
1211
+ }
1212
+ }
1213
+ catch (error) {
1214
+ const message = error instanceof Error ? error.message : String(error);
1215
+ this.appendSystemLine(`/update failed: ${message}`);
1216
+ }
1217
+ return verdict;
1218
+ }
1170
1219
  case 'feedback': {
1171
1220
  // Leak L21 (2026-05-27): in-CLI feedback collector. The wizard
1172
1221
  // mounts a fresh Ink tree (renderFeedbackPrompt) outside the
@@ -95,6 +95,7 @@ export const SLASH_COMMAND_HELP = Object.freeze([
95
95
  { name: 'feedback', args: '', gloss: 'file a bug / feature / general comment without leaving the REPL', group: 'Meta' },
96
96
  { name: 'share', args: '[--gist|--pugi] [--redact] [--preview]', gloss: 'Export session transcript to gist / pugi.io (leak L20)', group: 'Meta' },
97
97
  { name: 'release-notes', args: '[--reset]', gloss: 'Show changelog diff since last upgrade (leak L24)', group: 'Meta' },
98
+ { name: 'update', args: '[--check|--apply [--yes]] [--channel <name>]', gloss: 'Check for / apply CLI update on stable / beta / canary (leak L27)', group: 'Meta' },
98
99
  { name: 'quit', args: '', gloss: 'Exit the REPL', group: 'Meta' },
99
100
  ]);
100
101
  /**
@@ -474,6 +475,20 @@ export function parseSlashCommand(input) {
474
475
  const reset = tokens.includes('--reset') || tokens.includes('-r');
475
476
  return { kind: 'release-notes', reset };
476
477
  }
478
+ case 'update': {
479
+ // Leak L27 (2026-05-27): forward the tokenized argv to the
480
+ // session module which delegates to `runUpdateCommand`. The
481
+ // dispatcher owns argv validation (unknown channel / flag) so
482
+ // the slash parser stays as thin as the rest of the surface.
483
+ // The slash form does NOT support `--apply` because spawning
484
+ // `npm install -g` from inside a running REPL session would
485
+ // corrupt the operator's running binary — the dispatcher treats
486
+ // `--apply` from a slash as a non-interactive offer (probe +
487
+ // install command, no shell-out). Top-level `pugi update --apply`
488
+ // remains the recommended path for the actual install.
489
+ const tokens = tail.length === 0 ? [] : tail.split(/\s+/).filter((s) => s.length > 0);
490
+ return { kind: 'update', args: tokens };
491
+ }
477
492
  case 'memory':
478
493
  case 'config':
479
494
  case 'budget':
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import { execFileSync } from 'node:child_process';
3
3
  import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
4
4
  import { statSync } from 'node:fs';
5
+ import { homedir } from 'node:os';
5
6
  import { dirname, relative, resolve } from 'node:path';
6
7
  import { fileURLToPath } from 'node:url';
7
8
  import { AnvilEngineLoopClient } from '../core/engine/anvil-client.js';
@@ -151,6 +152,12 @@ const handlers = {
151
152
  // handler, same flags. Operators trained on Claude Code expect either
152
153
  // verb to surface the per-model token + USD table.
153
154
  usage: dispatchCost,
155
+ // Leak L27 (2026-05-27): `pugi update` — channel-aware npm registry
156
+ // probe + optional npm install shell-out. Same handler powers the
157
+ // in-REPL `/update` slash via the session module. R2 atomic swap
158
+ // deferred to Phase 2 per the sprint plan; npm is the single
159
+ // distribution channel today.
160
+ update: dispatchUpdate,
154
161
  version,
155
162
  web: dispatchWeb,
156
163
  whoami,
@@ -1503,6 +1510,32 @@ const COMMAND_HELP_BODIES = {
1503
1510
  'Useful in shell scripts that need a human-confirm before a destructive',
1504
1511
  'step. Exits 0 on yes, 1 on no, 2 on cancel.',
1505
1512
  ],
1513
+ update: [
1514
+ 'pugi update — channel-aware @pugi/cli update check + install.',
1515
+ '',
1516
+ 'Polls npm registry dist-tags for a newer @pugi/cli on the configured',
1517
+ 'channel (stable / beta / canary). Without flags, prints the install',
1518
+ 'command and exits. With --apply, shells out to `npm install -g …`.',
1519
+ '',
1520
+ ' --check Non-interactive probe + JSON envelope.',
1521
+ ' --channel <name> Switch channel (stable | beta | canary) and probe.',
1522
+ ' Persisted to ~/.pugi/config.json::updateChannel.',
1523
+ ' --apply Shell out to `npm install -g @pugi/cli@<tag>`',
1524
+ ' after a y/n confirmation.',
1525
+ ' --yes, -y Skip the confirmation prompt on --apply.',
1526
+ ' --json Force JSON envelope (auto-on with --check).',
1527
+ '',
1528
+ 'Channel mapping: stable -> npm `latest`, beta -> npm `beta`,',
1529
+ 'canary -> npm `next`. Default channel is `beta` (Pugi currently',
1530
+ 'ships beta releases only).',
1531
+ '',
1532
+ 'Also available as /update from inside the REPL — slash form NEVER',
1533
+ 'spawns npm (would corrupt the running binary); it only prints the',
1534
+ 'install command for the operator к run after exit.',
1535
+ '',
1536
+ 'R2 atomic swap (sprint plan L27) deferred к Phase 2 — npm is the',
1537
+ 'only distribution channel today.',
1538
+ ],
1506
1539
  stickers: [
1507
1540
  'pugi stickers — show a Pugi brand sticker (gimmick).',
1508
1541
  '',
@@ -1668,6 +1701,53 @@ async function doctor(_args, flags, _session) {
1668
1701
  writeOutput: (payload, text) => writeOutput(flags, payload, text),
1669
1702
  });
1670
1703
  }
1704
+ /**
1705
+ * `pugi update` — Leak L27 (2026-05-27). Channel-aware npm registry
1706
+ * probe + optional shell-out to `npm install -g @pugi/cli@<tag>`.
1707
+ *
1708
+ * Argument grammar:
1709
+ * pugi update -> probe + offer install command
1710
+ * pugi update --check -> probe + JSON envelope (scripted)
1711
+ * pugi update --channel <name> -> persist channel + probe
1712
+ * pugi update --apply [--yes] -> probe + shell out to npm
1713
+ * pugi update --json -> JSON envelope (any subcommand)
1714
+ *
1715
+ * The handler delegates to `runUpdateCommand` in
1716
+ * `runtime/commands/update.ts` so the in-REPL `/update` slash + the
1717
+ * top-level shell command share one channel-resolution + persistence
1718
+ * + probe surface. Exit codes:
1719
+ *
1720
+ * 0 — happy path (no update OR update completed OR probe-only)
1721
+ * 1 — install / probe failure with structured error
1722
+ * 2 — argument error (unknown flag, unknown channel)
1723
+ */
1724
+ async function dispatchUpdate(args, flags, _session) {
1725
+ const { parseUpdateArgs, runUpdateCommand, defaultSpawnInstaller } = await import('./commands/update.js');
1726
+ const parsed = parseUpdateArgs(args, { jsonDefault: flags.json });
1727
+ if ('error' in parsed) {
1728
+ writeOutput(flags, { ok: false, error: parsed.error }, parsed.error);
1729
+ process.exitCode = 2;
1730
+ return;
1731
+ }
1732
+ const envelope = await runUpdateCommand({
1733
+ cwd: process.cwd(),
1734
+ home: homedir(),
1735
+ env: process.env,
1736
+ flags: parsed,
1737
+ promptConfirm: async (question) => {
1738
+ const answer = await readSingleChoice(`${question} `);
1739
+ return /^y(es)?$/i.test(answer.trim());
1740
+ },
1741
+ writeOutput: (payload, text) => writeOutput(flags, payload, text),
1742
+ spawnInstaller: defaultSpawnInstaller,
1743
+ });
1744
+ if (!envelope.ok) {
1745
+ // `apply_cancelled_by_operator` is a benign decline; we still
1746
+ // surface a non-zero exit so scripted callers can detect that the
1747
+ // operator did not green-light the install.
1748
+ process.exitCode = 1;
1749
+ }
1750
+ }
1671
1751
  /**
1672
1752
  * `pugi status` — Leak L34 (2026-05-27). Concise session-state probe
1673
1753
  * mirroring Claude Code's `/status`. Distinct from `pugi doctor`