@pugi/cli 0.1.0-alpha.9 → 0.1.0-beta.1
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/README.md +33 -0
- package/assets/pugi-mascot.ansi +41 -0
- package/dist/commands/deploy.js +439 -0
- package/dist/core/agents/loader.js +104 -0
- package/dist/core/agents/registry.js +1 -1
- package/dist/core/consensus/anvil-fanout.js +276 -0
- package/dist/core/consensus/diff-capture.js +382 -0
- package/dist/core/consensus/rubric.js +233 -0
- package/dist/core/context/index.js +21 -0
- package/dist/core/context/pugiignore.js +316 -0
- package/dist/core/context/repo-skeleton.js +533 -0
- package/dist/core/context/watcher.js +342 -0
- package/dist/core/context/working-set.js +165 -0
- package/dist/core/edits/dispatch.js +185 -0
- package/dist/core/edits/index.js +15 -0
- package/dist/core/edits/layer-a-apply.js +217 -0
- package/dist/core/edits/layer-b-apply.js +211 -0
- package/dist/core/edits/layer-c-apply.js +160 -0
- package/dist/core/edits/layer-d-ast.js +29 -0
- package/dist/core/edits/marker-parser.js +401 -0
- package/dist/core/edits/security-gate.js +223 -0
- package/dist/core/engine/native-pugi.js +6 -1
- package/dist/core/engine/tool-bridge.js +33 -1
- package/dist/core/repl/ask.js +512 -0
- package/dist/core/repl/cancellation.js +98 -0
- package/dist/core/repl/dispatch-fsm.js +220 -0
- package/dist/core/repl/privacy-banner.js +71 -0
- package/dist/core/repl/session.js +1882 -12
- package/dist/core/repl/slash-commands.js +59 -32
- package/dist/core/repl/store/index.js +12 -0
- package/dist/core/repl/store/jsonl-log.js +321 -0
- package/dist/core/repl/store/lockfile.js +155 -0
- package/dist/core/repl/store/session-store.js +792 -0
- package/dist/core/repl/store/types.js +44 -0
- package/dist/core/repl/store/uuid-v7.js +68 -0
- package/dist/core/repl/workspace-context.js +72 -1
- package/dist/core/skills/loader.js +454 -0
- package/dist/core/skills/sources.js +480 -0
- package/dist/core/skills/trust.js +172 -0
- package/dist/runtime/cli.js +721 -10
- package/dist/runtime/commands/agents.js +385 -0
- package/dist/runtime/commands/config.js +338 -8
- package/dist/runtime/commands/review-consensus.js +399 -0
- package/dist/runtime/commands/skills.js +401 -0
- package/dist/tools/file-tools.js +90 -0
- package/dist/tools/web-fetch.js +1 -1
- package/dist/tui/agent-tree-pane.js +9 -0
- package/dist/tui/ask-cli.js +52 -0
- package/dist/tui/ask-modal.js +211 -0
- package/dist/tui/conversation-pane.js +48 -3
- package/dist/tui/input-box.js +48 -5
- package/dist/tui/markdown-render.js +266 -0
- package/dist/tui/repl-render.js +157 -0
- package/dist/tui/repl-splash-mascot.js +130 -0
- package/dist/tui/repl-splash.js +7 -1
- package/dist/tui/repl.js +82 -11
- package/dist/tui/status-bar.js +63 -3
- package/dist/tui/tool-stream-pane.js +91 -0
- package/package.json +11 -5
package/dist/tui/repl-render.js
CHANGED
|
@@ -19,8 +19,12 @@
|
|
|
19
19
|
import React from 'react';
|
|
20
20
|
import { render } from 'ink';
|
|
21
21
|
import { Repl } from './repl.js';
|
|
22
|
+
import { printPugMascotPreInk } from './repl-splash-mascot.js';
|
|
22
23
|
import { ReplSession, } from '../core/repl/session.js';
|
|
23
24
|
import { resolveWorkspaceContext } from '../core/repl/workspace-context.js';
|
|
25
|
+
import { SqliteSessionStore } from '../core/repl/store/index.js';
|
|
26
|
+
import { slugForCwd } from '../core/repl/history.js';
|
|
27
|
+
import { WorkingSet, buildRepoSkeleton, loadPugiIgnore, PugiWatcher, } from '../core/context/index.js';
|
|
24
28
|
/**
|
|
25
29
|
* Mount the REPL and resolve when the user exits via Ctrl+C × 2 or
|
|
26
30
|
* `/quit`. The session is closed (server-side stays alive; resume via
|
|
@@ -33,6 +37,26 @@ export async function renderRepl(options) {
|
|
|
33
37
|
// best-effort — any FS error falls back to a basename-only summary,
|
|
34
38
|
// never blocks REPL launch. Wave 4 fix 2026-05-25.
|
|
35
39
|
const workspace = options.workspace ?? resolveWorkspaceContext(process.cwd());
|
|
40
|
+
// α6.4: open the local SessionStore for `/resume` persistence. The
|
|
41
|
+
// store lives under `~/.pugi/projects/<slug>/`; failure is fail-safe
|
|
42
|
+
// — we log a one-line warning to stderr and continue with the REPL
|
|
43
|
+
// in memory-only mode. Lock-busy errors get the friendliest message
|
|
44
|
+
// so an operator running two REPLs in the same project understands
|
|
45
|
+
// the constraint.
|
|
46
|
+
const projectSlug = slugForCwd(process.cwd());
|
|
47
|
+
const { store, openedSessionId } = await openLocalStore({
|
|
48
|
+
projectSlug,
|
|
49
|
+
workspaceRoot: process.cwd(),
|
|
50
|
+
resumeLocalSessionId: options.resumeLocalSessionId,
|
|
51
|
+
});
|
|
52
|
+
// α6.5 three-tier context bootstrap. The skeleton + working set
|
|
53
|
+
// + watcher are local-first and best-effort: every step is wrapped
|
|
54
|
+
// in try/catch so an unreadable workspace never blocks REPL launch.
|
|
55
|
+
// Opt-out via PUGI_DISABLE_CONTEXT=1 for hermetic test runs.
|
|
56
|
+
const { skeleton, workingSet, watcher } = await bootstrapContext({
|
|
57
|
+
cwd: process.cwd(),
|
|
58
|
+
env: process.env,
|
|
59
|
+
});
|
|
36
60
|
const session = new ReplSession({
|
|
37
61
|
apiUrl: options.apiUrl,
|
|
38
62
|
apiKey: options.apiKey,
|
|
@@ -40,21 +64,154 @@ export async function renderRepl(options) {
|
|
|
40
64
|
cliVersion: options.cliVersion,
|
|
41
65
|
transport,
|
|
42
66
|
workspace,
|
|
67
|
+
store,
|
|
68
|
+
localSessionId: openedSessionId,
|
|
69
|
+
repoSkeleton: skeleton,
|
|
70
|
+
workingSet,
|
|
71
|
+
watcher,
|
|
43
72
|
});
|
|
73
|
+
// Restore the transcript from the JSONL log if we resumed an
|
|
74
|
+
// existing session. The restore is idempotent and bypasses persist
|
|
75
|
+
// (no double-write of replayed rows).
|
|
76
|
+
if (store && openedSessionId && options.resumeLocalSessionId) {
|
|
77
|
+
try {
|
|
78
|
+
const events = await store.loadEvents(openedSessionId, { limit: 500 });
|
|
79
|
+
session.restoreTranscript(events);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
83
|
+
process.stderr.write(`[pugi] Could not restore session ${openedSessionId.slice(0, 13)}: ${msg}\n`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
44
86
|
// Kick off the connect; the Repl renders the connecting state until
|
|
45
87
|
// the session pushes `connection: 'on_watch'` from the SSE onOpen.
|
|
46
88
|
void session.start();
|
|
89
|
+
// α6.14.2 wave 5: paint the chafa-baked brand-pug ANSI render to
|
|
90
|
+
// stdout BEFORE Ink mounts. Ink's layout engine would mis-measure
|
|
91
|
+
// the truecolor escape sequences, so the pug must land verbatim.
|
|
92
|
+
// The flag is passed into <Repl /> so the splash component knows to
|
|
93
|
+
// skip its own hand-crafted PUG_MASCOT column — otherwise the
|
|
94
|
+
// operator sees both the chafa pug AND the ASCII fallback stacked.
|
|
95
|
+
// When skipSplash is true (operator opted out via --no-splash), we
|
|
96
|
+
// suppress the pre-print too so the boot stays silent.
|
|
97
|
+
const mascotPrePrinted = options.skipSplash === true ? false : printPugMascotPreInk(process.stdout);
|
|
47
98
|
const instance = render(React.createElement(Repl, {
|
|
48
99
|
session,
|
|
49
100
|
updateBanner: options.updateBanner ?? null,
|
|
50
101
|
skipSplash: options.skipSplash === true,
|
|
102
|
+
hideToolStream: options.hideToolStream === true,
|
|
103
|
+
mascotPrePrinted,
|
|
51
104
|
}));
|
|
52
105
|
try {
|
|
53
106
|
await instance.waitUntilExit();
|
|
54
107
|
}
|
|
55
108
|
finally {
|
|
56
109
|
session.close();
|
|
110
|
+
if (store) {
|
|
111
|
+
try {
|
|
112
|
+
await store.close();
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
/* idempotent — already closed */
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (watcher) {
|
|
119
|
+
try {
|
|
120
|
+
await watcher.close();
|
|
121
|
+
}
|
|
122
|
+
catch {
|
|
123
|
+
/* idempotent — chokidar may already be torn down */
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Open the local SessionStore for the REPL bootstrap. Returns
|
|
130
|
+
* `{ store: null, openedSessionId: undefined }` on any error so the
|
|
131
|
+
* caller falls through to memory-only mode rather than failing the
|
|
132
|
+
* launch. The one error we surface verbatim is the lock-busy case —
|
|
133
|
+
* that one is operator-actionable.
|
|
134
|
+
*/
|
|
135
|
+
async function openLocalStore(input) {
|
|
136
|
+
// Honour an explicit opt-out for offline-strict environments / CI.
|
|
137
|
+
// PUGI_DISABLE_SESSION_STORE=1 wipes the integration to zero. Useful
|
|
138
|
+
// for hermetic test runs and for operators who do not want any
|
|
139
|
+
// persistence under $HOME.
|
|
140
|
+
if (process.env.PUGI_DISABLE_SESSION_STORE === '1') {
|
|
141
|
+
return { store: null, openedSessionId: undefined };
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const store = new SqliteSessionStore({ projectSlug: input.projectSlug });
|
|
145
|
+
const row = await store.open({
|
|
146
|
+
id: input.resumeLocalSessionId,
|
|
147
|
+
workspaceRoot: input.workspaceRoot,
|
|
148
|
+
projectSlug: input.projectSlug,
|
|
149
|
+
});
|
|
150
|
+
return { store, openedSessionId: row.id };
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
const code = error?.code;
|
|
154
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
155
|
+
if (code === 'EBUSY_SESSION_LOCK') {
|
|
156
|
+
process.stderr.write(`[pugi] ${msg} Continuing without local session persistence.\n`);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
process.stderr.write(`[pugi] Local session store unavailable (${msg}). Continuing in memory-only mode.\n`);
|
|
160
|
+
}
|
|
161
|
+
return { store: null, openedSessionId: undefined };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Bootstrap the α6.5 three-tier context primitives:
|
|
166
|
+
*
|
|
167
|
+
* - Tier 0: `RepoSkeleton` (~5KB ASCII tree + meta) for prompt injection.
|
|
168
|
+
* - Tier 1: `WorkingSet` LRU bounded at 50 entries.
|
|
169
|
+
* - Filewatch: chokidar started against cwd, ignore-filtered.
|
|
170
|
+
*
|
|
171
|
+
* The bootstrap is fail-safe: every primitive is wrapped so the REPL
|
|
172
|
+
* still launches when (e.g.) chokidar refuses to start on a
|
|
173
|
+
* permission-blocked dir. The PUGI_DISABLE_CONTEXT=1 env var skips
|
|
174
|
+
* the bootstrap entirely for hermetic test runs and for operators
|
|
175
|
+
* who want a zero-touch REPL.
|
|
176
|
+
*/
|
|
177
|
+
async function bootstrapContext(input) {
|
|
178
|
+
if (input.env.PUGI_DISABLE_CONTEXT === '1') {
|
|
179
|
+
return { skeleton: null, workingSet: null, watcher: null };
|
|
180
|
+
}
|
|
181
|
+
let ignore;
|
|
182
|
+
try {
|
|
183
|
+
ignore = loadPugiIgnore(input.cwd);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
187
|
+
process.stderr.write(`[pugi] Three-tier context bootstrap skipped (ignore matcher failed: ${msg}).\n`);
|
|
188
|
+
return { skeleton: null, workingSet: null, watcher: null };
|
|
189
|
+
}
|
|
190
|
+
let skeleton = null;
|
|
191
|
+
try {
|
|
192
|
+
skeleton = buildRepoSkeleton(input.cwd, { ignore });
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
196
|
+
process.stderr.write(`[pugi] Repo skeleton bootstrap failed (${msg}). Continuing without Tier 0.\n`);
|
|
197
|
+
}
|
|
198
|
+
const workingSet = new WorkingSet();
|
|
199
|
+
let watcher = null;
|
|
200
|
+
// chokidar opt-out: PUGI_DISABLE_FILEWATCH=1 keeps Tier 0/1 wired
|
|
201
|
+
// but skips the live-update channel. Useful on CI runners and on
|
|
202
|
+
// network mounts where fsevents misbehaves.
|
|
203
|
+
if (input.env.PUGI_DISABLE_FILEWATCH !== '1') {
|
|
204
|
+
try {
|
|
205
|
+
const w = new PugiWatcher({ cwd: input.cwd, ignore });
|
|
206
|
+
await w.start();
|
|
207
|
+
watcher = w;
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
211
|
+
process.stderr.write(`[pugi] Filewatch bootstrap failed (${msg}). Continuing without live updates.\n`);
|
|
212
|
+
}
|
|
57
213
|
}
|
|
214
|
+
return { skeleton, workingSet, watcher };
|
|
58
215
|
}
|
|
59
216
|
/* ------------------------------------------------------------------ */
|
|
60
217
|
/* Production transport */
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chafa-validated brand-pug ANSI loader (α6.14.4 wave 6, mascot regen).
|
|
3
|
+
*
|
|
4
|
+
* CEO dogfood 2026-05-25 (first pass, α6.14.2 wave 5): the hand-crafted
|
|
5
|
+
* 9-row ASCII pug in `repl-splash-art.ts` reads as "точно не похожа" —
|
|
6
|
+
* too abstract to carry the brand at boot. This module loads a pre-baked
|
|
7
|
+
* truecolor ANSI render of the canonical hero-pug PNG (cyber-zoo pug
|
|
8
|
+
* face with cyan eyes + circuit + chip) so the splash matches the brand
|
|
9
|
+
* glyph the operator already sees on pugi.io.
|
|
10
|
+
*
|
|
11
|
+
* CEO dogfood 2026-05-25 (α6.14.4): the first chafa bake at 32x16 still
|
|
12
|
+
* read as "monitor on stand", not pug — too few rows to resolve the
|
|
13
|
+
* snout / eyes / wrinkles. The vertical resolution was the bottleneck:
|
|
14
|
+
* 16 char rows ≈ 16 pixel rows with the block symbol set. The fresh
|
|
15
|
+
* bake uses `vhalf` (vertical half blocks ▀ / ▄ with independent fg+bg
|
|
16
|
+
* colours per cell) which doubles the vertical resolution per character
|
|
17
|
+
* cell, at an 80x40 frame which is 2.5× the prior dimensions. End
|
|
18
|
+
* result: ~80×80 effective pixel resolution — enough to read the
|
|
19
|
+
* snout, eye sockets, ear lines, and the circuit board accent the
|
|
20
|
+
* brand glyph carries. File grew from 8.8KB to ~40KB; ship budget
|
|
21
|
+
* gates at 100KB so we stay well under cap.
|
|
22
|
+
*
|
|
23
|
+
* Generation (operator-side, one-shot):
|
|
24
|
+
* chafa --size 80x40 --symbols=vhalf --colors=full \
|
|
25
|
+
* apps/clawhost-web/public/brand/hero-pug.png \
|
|
26
|
+
* > apps/pugi-cli/assets/pugi-mascot.ansi
|
|
27
|
+
*
|
|
28
|
+
* The output is committed verbatim to the repo and shipped inside the
|
|
29
|
+
* `@pugi/cli` npm tarball under `assets/pugi-mascot.ansi` (the
|
|
30
|
+
* `package.json` `files` allowlist explicitly opts in). Runtime does
|
|
31
|
+
* NOT need `chafa` installed — we just read the file bytes and write
|
|
32
|
+
* them to stdout. If the file is missing (degraded install, tarball
|
|
33
|
+
* corruption, dev cwd drift), the splash falls back to the hand-crafted
|
|
34
|
+
* `PUG_MASCOT` art so the boot never crashes.
|
|
35
|
+
*
|
|
36
|
+
* The pre-Ink write convention mirrors the Claude Code Chrome plugin
|
|
37
|
+
* splash pattern: raw bytes go to `process.stdout` BEFORE the Ink
|
|
38
|
+
* render mount, so the terminal interprets the truecolor escapes
|
|
39
|
+
* directly instead of Ink trying to layout-engine over them.
|
|
40
|
+
*/
|
|
41
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
42
|
+
import { dirname, resolve as resolvePath } from 'node:path';
|
|
43
|
+
import { fileURLToPath } from 'node:url';
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the on-disk path to `pugi-mascot.ansi` relative to the
|
|
46
|
+
* compiled module. The CLI ships to `node_modules/@pugi/cli/dist/tui/`
|
|
47
|
+
* so the asset lives at `node_modules/@pugi/cli/assets/pugi-mascot.ansi`
|
|
48
|
+
* — two directory hops up from this file. In a local `pnpm dev`
|
|
49
|
+
* checkout the structure is the same (`src/tui/` ⇒ `../../assets/`)
|
|
50
|
+
* because tsx re-resolves the same relative tree.
|
|
51
|
+
*/
|
|
52
|
+
export function pugMascotAssetPath() {
|
|
53
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
54
|
+
return resolvePath(here, '..', '..', 'assets', 'pugi-mascot.ansi');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Read the chafa-baked ANSI render of the brand pug. Returns the raw
|
|
58
|
+
* bytes verbatim (UTF-8 string) — the terminal interprets the truecolor
|
|
59
|
+
* escapes directly. Returns null when the file is missing, unreadable,
|
|
60
|
+
* or trivially empty so the caller can fall back to `PUG_MASCOT`.
|
|
61
|
+
*
|
|
62
|
+
* `chafa --colors=full` wraps the render with cursor-hide (`\e[?25l`)
|
|
63
|
+
* on the head and cursor-show (`\e[?25h`) on the tail. We strip those
|
|
64
|
+
* so the splash does not accidentally hide the cursor across the rest
|
|
65
|
+
* of the REPL boot (Ink itself manages the cursor once it mounts).
|
|
66
|
+
*
|
|
67
|
+
* The asset is supply-chain controlled (committed in-repo, shipped in
|
|
68
|
+
* the npm tarball) so an arbitrary attacker cannot inject escapes
|
|
69
|
+
* today. The defence-in-depth strip below still drops categories of
|
|
70
|
+
* escapes that the splash has no legitimate need to emit — OSC window
|
|
71
|
+
* title sets, mouse-tracking enables, screen clears, cursor-position
|
|
72
|
+
* reports — so a future swap of the asset (or a corrupt tarball) cannot
|
|
73
|
+
* disrupt the terminal beyond the splash region. Truecolor (`CSI 38;2;
|
|
74
|
+
* R;G;B m`), reset (`CSI 0 m`), and explicit forms of cursor / line
|
|
75
|
+
* motion the render needs are left in.
|
|
76
|
+
*/
|
|
77
|
+
export function loadPugMascotAnsi() {
|
|
78
|
+
const path = pugMascotAssetPath();
|
|
79
|
+
try {
|
|
80
|
+
if (!existsSync(path))
|
|
81
|
+
return null;
|
|
82
|
+
const raw = readFileSync(path, 'utf8');
|
|
83
|
+
if (!raw || raw.length === 0)
|
|
84
|
+
return null;
|
|
85
|
+
// 1. Drop OSC sequences. Two terminator forms:
|
|
86
|
+
// ESC ] ... BEL (0x1b 0x5d ... 0x07)
|
|
87
|
+
// ESC ] ... ESC \ (0x1b 0x5d ... 0x1b 0x5c, the ST form)
|
|
88
|
+
// A truecolor splash never needs OSC (those are for window title,
|
|
89
|
+
// icon, clipboard, hyperlinks, color-palette change). Drop them
|
|
90
|
+
// so a corrupted asset cannot rename the operator's terminal tab
|
|
91
|
+
// or smuggle a hyperlink into the splash region.
|
|
92
|
+
// 2. Drop CSI ? <mode> [hl] for mouse-tracking and screen-buffer
|
|
93
|
+
// switch modes (1000, 1001, 1002, 1003, 1004, 1005, 1006, 1015,
|
|
94
|
+
// 1049, 47, 1047, 1048). These would either start swallowing
|
|
95
|
+
// mouse input or flip the terminal into the alternate screen.
|
|
96
|
+
// 3. Drop CSI 6 n (cursor-position report). Would inject a fake
|
|
97
|
+
// CPR into the operator's stdin stream.
|
|
98
|
+
// 4. Drop CSI [23]J / CSI [23]K (full screen / line clear). A
|
|
99
|
+
// chafa render uses cursor-positioning per row, not bulk
|
|
100
|
+
// erases; bulk clears would wipe whatever the operator already
|
|
101
|
+
// had on screen above the splash.
|
|
102
|
+
// The cursor-hide/show wrappers (CSI ? 25 [lh]) are handled by
|
|
103
|
+
// the same CSI-?-mode pattern as the mouse / alt-screen modes.
|
|
104
|
+
const stripped = raw
|
|
105
|
+
.replace(/\x1b\][^\x07\x1b]*(?:\x07|\x1b\\)/g, '')
|
|
106
|
+
.replace(/\x1b\[\?(?:25|47|1000|1001|1002|1003|1004|1005|1006|1015|1047|1048|1049)[lh]/g, '')
|
|
107
|
+
.replace(/\x1b\[6n/g, '')
|
|
108
|
+
.replace(/\x1b\[[23]?[JK]/g, '');
|
|
109
|
+
if (stripped.trim().length === 0)
|
|
110
|
+
return null;
|
|
111
|
+
return stripped;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
// Best-effort: any FS / decode error returns null so the splash
|
|
115
|
+
// falls back to the hand-crafted ASCII art. Never throws.
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function printPugMascotPreInk(sink) {
|
|
120
|
+
const ansi = loadPugMascotAnsi();
|
|
121
|
+
if (ansi === null)
|
|
122
|
+
return false;
|
|
123
|
+
// Trailing newline so the Ink header lands on a fresh row rather
|
|
124
|
+
// than smashing into the last pug row.
|
|
125
|
+
sink.write(ansi);
|
|
126
|
+
if (!ansi.endsWith('\n'))
|
|
127
|
+
sink.write('\n');
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=repl-splash-mascot.js.map
|
package/dist/tui/repl-splash.js
CHANGED
|
@@ -61,7 +61,13 @@ export function ReplSplash(props) {
|
|
|
61
61
|
if (props.skipSplash) {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
// α6.14.2 wave 5: when the host pre-printed the chafa-baked brand-pug
|
|
65
|
+
// ANSI render to stdout before Ink mounted, suppress the hand-crafted
|
|
66
|
+
// PUG_MASCOT column here so the operator does not see two stacked
|
|
67
|
+
// pugs. The header card still renders inline so wordmark + status
|
|
68
|
+
// rows stay attached to the splash flow.
|
|
69
|
+
const showHandCraftedMascot = props.mascotPrePrinted !== true;
|
|
70
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, paddingY: 1, children: [_jsxs(Box, { flexDirection: "row", children: [showHandCraftedMascot ? _jsx(MascotColumn, {}) : null, _jsxs(Box, { flexDirection: "column", marginLeft: showHandCraftedMascot ? 2 : 0, marginTop: 1, children: [_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "Pugi" }), _jsx(Text, { bold: true, color: "cyan", children: ".io" }), _jsx(Text, { dimColor: true, children: ` v${props.cliVersion}` })] }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(HeaderRow, { label: "Plan", value: props.plan ?? PLACEHOLDER }), _jsx(HeaderRow, { label: "Model", value: props.model ?? PLACEHOLDER }), _jsx(HeaderRow, { label: "Tenant", value: props.tenant ?? PLACEHOLDER }), _jsx(HeaderRow, { label: "Workspace", value: props.workspaceLabel })] })] })] }), _jsx(Box, { marginTop: 1, children: _jsx(Text, { dimColor: true, children: '─'.repeat(40) }) }), _jsxs(Box, { marginTop: 1, flexDirection: "column", children: [_jsx(Text, { dimColor: true, children: "Tips for getting started:" }), _jsx(TipRow, { index: 1, text: "Type a brief, the workforce dispatches" }), _jsx(TipRow, { index: 2, text: "/help for slash commands, /web <url> to pull a page" }), _jsx(TipRow, { index: 3, text: "/skills install <name> for Anthropic / OpenClaw skills" })] })] }));
|
|
65
71
|
}
|
|
66
72
|
/**
|
|
67
73
|
* Renders the multi-line ASCII pug. Each row is split into colored
|
package/dist/tui/repl.js
CHANGED
|
@@ -20,22 +20,32 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
20
20
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
21
21
|
import { Box, Text, useApp, useInput } from 'ink';
|
|
22
22
|
import { PUGI_TAGLINE, THE_TEN } from '@pugi/personas';
|
|
23
|
-
import {
|
|
23
|
+
import { AgentTreePane } from './agent-tree-pane.js';
|
|
24
|
+
import { AskModal, PlanReviewModal } from './ask-modal.js';
|
|
24
25
|
import { ConversationPane } from './conversation-pane.js';
|
|
25
26
|
import { InputBox } from './input-box.js';
|
|
26
27
|
import { ReplSplash } from './repl-splash.js';
|
|
27
28
|
import { StatusBar } from './status-bar.js';
|
|
29
|
+
import { ToolStreamPane } from './tool-stream-pane.js';
|
|
28
30
|
import { UpdateBanner } from './update-banner.js';
|
|
29
31
|
import { collectWorkspaceContext } from './workspace-context.js';
|
|
30
32
|
import { slugForCwd } from '../core/repl/history.js';
|
|
31
33
|
import { SLASH_COMMAND_HELP, SLASH_COMMAND_GROUPS } from '../core/repl/slash-commands.js';
|
|
32
34
|
const TICK_INTERVAL_MS = 200;
|
|
33
35
|
const PULSE_INTERVAL_MS = 700;
|
|
36
|
+
// α6.12: maximum transcript rows the conversation pane renders at once.
|
|
37
|
+
// Older rows scroll off the top; full history stays in session state.
|
|
38
|
+
const CONVERSATION_WINDOW = 12;
|
|
34
39
|
export function Repl(props) {
|
|
35
40
|
const [state, setState] = useState(props.session.getState());
|
|
36
41
|
const [overlay, setOverlay] = useState('none');
|
|
37
42
|
const [pulsePhase, setPulsePhase] = useState(0);
|
|
38
43
|
const [tickNow, setTickNow] = useState((props.now ?? Date.now)());
|
|
44
|
+
// α6.12: operator-driven collapse for the tool stream pane. The CLI
|
|
45
|
+
// host can hide the pane entirely via `--no-tool-stream`; this state
|
|
46
|
+
// is the runtime toggle (Ctrl+T) for operators who want the pane on
|
|
47
|
+
// screen but folded to a single row while they read a long reply.
|
|
48
|
+
const [toolStreamCollapsed, setToolStreamCollapsed] = useState(false);
|
|
39
49
|
// α6.14 wave 3: boot splash visible until first input, first
|
|
40
50
|
// `agent.spawned` event, or 10s idle. The host gates the initial
|
|
41
51
|
// visibility on `--no-splash` / PUGI_SKIP_SPLASH via `skipSplash`.
|
|
@@ -122,22 +132,78 @@ export function Repl(props) {
|
|
|
122
132
|
setOverlay('none');
|
|
123
133
|
}
|
|
124
134
|
}, { isActive: overlay === 'help' || overlay === 'roster' });
|
|
125
|
-
|
|
135
|
+
// α6.12: Ctrl+T toggles the tool stream pane between expanded and
|
|
136
|
+
// collapsed states. Active only while no overlay is open, so the
|
|
137
|
+
// toggle never fights the help/roster dismiss handler. The input box
|
|
138
|
+
// owns its own raw-input mode, so this listener only fires on the
|
|
139
|
+
// global Ctrl+T binding rather than every printable keystroke.
|
|
140
|
+
useInput((input, key) => {
|
|
141
|
+
if (key.ctrl && input === 't') {
|
|
142
|
+
setToolStreamCollapsed((prev) => !prev);
|
|
143
|
+
}
|
|
144
|
+
}, { isActive: overlay === 'none' && props.hideToolStream !== true });
|
|
145
|
+
// α6.3 office-hours: a pending ask or plan-review modal pauses input
|
|
146
|
+
// until the operator resolves it. The modal owns its own useInput
|
|
147
|
+
// hook, so the InputBox unmounts while a modal is open to avoid two
|
|
148
|
+
// raw-input listeners competing for the same keystroke. Resolution
|
|
149
|
+
// forwards through ReplSession.resolveAsk / resolvePlanReview.
|
|
150
|
+
const askPending = state.pendingAsk !== null;
|
|
151
|
+
const planPending = state.pendingPlanReview !== null;
|
|
152
|
+
const modalActive = askPending || planPending;
|
|
153
|
+
const handleAskResolve = useCallback((verdict) => {
|
|
154
|
+
void props.session.resolveAsk(verdict);
|
|
155
|
+
}, [props.session]);
|
|
156
|
+
const handlePlanReviewResolve = useCallback((result) => {
|
|
157
|
+
void props.session.resolvePlanReview(result);
|
|
158
|
+
}, [props.session]);
|
|
159
|
+
// α6.9: Ctrl+C abort handler. Forwards to ReplSession.cancel() which
|
|
160
|
+
// aborts the in-flight dispatch, closes the SSE stream, and surfaces
|
|
161
|
+
// "Aborted." in the transcript.
|
|
162
|
+
//
|
|
163
|
+
// Return contract (consumed by InputBox):
|
|
164
|
+
// - true - dispatch was cancelled (keep the buffer + DO arm
|
|
165
|
+
// the press-again-to-exit timer; second Ctrl+C in
|
|
166
|
+
// the window exits).
|
|
167
|
+
// - false - idle / nothing to cancel (legacy: clear buffer +
|
|
168
|
+
// arm the exit timer so the operator sees the hint
|
|
169
|
+
// and can confirm exit on the next press).
|
|
170
|
+
// - undefined - bypassed entirely (e.g. a modal owns the input).
|
|
171
|
+
// InputBox MUST NOT arm the exit timer and MUST
|
|
172
|
+
// NOT clear the buffer. P2 fix: previously this
|
|
173
|
+
// returned `false` and the buffer-clear path wiped
|
|
174
|
+
// the operator's mid-typed modal text on the first
|
|
175
|
+
// Ctrl+C, costing a press of work.
|
|
176
|
+
const handleCancel = useCallback(() => {
|
|
177
|
+
if (modalActive)
|
|
178
|
+
return undefined;
|
|
179
|
+
return props.session.cancel();
|
|
180
|
+
}, [props.session, modalActive]);
|
|
181
|
+
return (_jsxs(Box, { flexDirection: "column", paddingX: 1, children: [props.updateBanner ? _jsx(UpdateBanner, { result: props.updateBanner }) : null, splashVisible ? (_jsx(ReplSplash, { cliVersion: state.cliVersion, workspaceLabel: state.workspaceLabel, plan: props.splashPlan, model: props.splashModel, tenant: props.splashTenant, onDismiss: dismissSplash, mascotPrePrinted: props.mascotPrePrinted === true })) : null, _jsx(Header, { state: state }), _jsx(Box, { flexDirection: "column", marginTop: 1, children: overlay === 'help' ? (_jsx(HelpOverlay, {})) : overlay === 'roster' ? (_jsx(RosterOverlay, {})) : overlay === 'farewell' ? (_jsx(FarewellOverlay, {})) : (_jsx(MainArea, { state: state, personaNames: personaNames, nowEpochMs: tickNow, hideToolStream: props.hideToolStream === true, toolStreamCollapsed: toolStreamCollapsed })) }), state.pendingAsk ? (_jsx(Box, { marginTop: 1, children: _jsx(AskModal, { tag: state.pendingAsk, onResolve: handleAskResolve }) })) : null, state.pendingPlanReview ? (_jsx(Box, { marginTop: 1, children: _jsx(PlanReviewModal, { tag: state.pendingPlanReview, onResolve: handlePlanReviewResolve }) })) : null, _jsxs(Box, { flexDirection: "column", marginTop: 1, children: [overlay === 'farewell' || modalActive ? null : (_jsx(InputBox, { onSubmit: handleSubmit, onExit: handleExit, onCancel: handleCancel, now: props.now,
|
|
126
182
|
// Slug from process.cwd() (full path) so two workspaces with
|
|
127
183
|
// the same basename do not share history. state.workspaceLabel
|
|
128
184
|
// is the basename only. Codex review P2.
|
|
129
|
-
workspaceSlug: slugForCwd(process.cwd()) })), _jsx(StatusBar, { connection: state.connection, activeAgentCount: countActive(state), tokensDownstreamTotal: state.tokensDownstreamTotal, briefStartedAtEpochMs: state.briefStartedAtEpochMs, nowEpochMs: tickNow, pulsePhase: pulsePhase, pugiMdCount: workspaceContext.pugiMdCount, mcpServerCount: workspaceContext.mcpServerCount, skillCount: workspaceContext.skillCount, quotaPct: props.quotaPct })] })] }));
|
|
185
|
+
workspaceSlug: slugForCwd(process.cwd()) })), _jsx(StatusBar, { connection: state.connection, activeAgentCount: countActive(state), tokensDownstreamTotal: state.tokensDownstreamTotal, briefStartedAtEpochMs: state.briefStartedAtEpochMs, nowEpochMs: tickNow, pulsePhase: pulsePhase, pugiMdCount: workspaceContext.pugiMdCount, mcpServerCount: workspaceContext.mcpServerCount, skillCount: workspaceContext.skillCount, quotaPct: props.quotaPct, dispatchState: state.dispatchState, dispatchToolLabel: state.dispatchToolLabel })] })] }));
|
|
130
186
|
}
|
|
131
187
|
function Header({ state }) {
|
|
132
188
|
return (_jsxs(Box, { children: [_jsx(Text, { bold: true, children: "Pugi" }), _jsx(Text, { bold: true, color: "cyan", children: ".io" }), _jsx(Text, { dimColor: true, children: ` · workspace: ${state.workspaceLabel} · v${state.cliVersion} · ` }), _jsx(Text, { color: "cyan", children: state.connection === 'on_watch' ? 'on watch' : state.connection.replace('_', ' ') })] }));
|
|
133
189
|
}
|
|
134
|
-
function MainArea({ state, personaNames, nowEpochMs, }) {
|
|
135
|
-
//
|
|
136
|
-
//
|
|
137
|
-
//
|
|
138
|
-
//
|
|
139
|
-
|
|
140
|
-
|
|
190
|
+
function MainArea({ state, personaNames, nowEpochMs, hideToolStream, toolStreamCollapsed, }) {
|
|
191
|
+
// α6.12: three vertical panes stacked above the input box.
|
|
192
|
+
//
|
|
193
|
+
// 1. Conversation pane (top) - transcript with Markdown render.
|
|
194
|
+
// 2. Tool stream pane (mid) - live Read/Edit/Bash/Grep lines.
|
|
195
|
+
// Hidden when `--no-tool-stream` is
|
|
196
|
+
// set; collapsed via Ctrl+T while
|
|
197
|
+
// the pane is visible.
|
|
198
|
+
// 3. Agent tree pane (bottom) - Cyber-Zoo roster with persona /
|
|
199
|
+
// status / duration / token counts.
|
|
200
|
+
//
|
|
201
|
+
// The window over the transcript is small (last 12 rows) so the
|
|
202
|
+
// bottom of the frame stays anchored to the input box. New agents
|
|
203
|
+
// push the operator line up the screen, mirroring Claude Code /
|
|
204
|
+
// Codex CLI / Gemini CLI rendering.
|
|
205
|
+
const conversationSlice = state.transcript.slice(-CONVERSATION_WINDOW);
|
|
206
|
+
return (_jsxs(Box, { flexDirection: "column", children: [_jsx(ConversationPane, { rows: conversationSlice, personaNames: personaNames }), hideToolStream ? null : (_jsx(Box, { marginTop: 1, children: _jsx(ToolStreamPane, { calls: state.toolCalls, collapsed: toolStreamCollapsed }) })), _jsx(Box, { marginTop: 1, children: _jsx(AgentTreePane, { agents: state.agents, nowEpochMs: nowEpochMs }) })] }));
|
|
141
207
|
}
|
|
142
208
|
function HelpOverlay() {
|
|
143
209
|
// Group commands by their `group` field so the operator scans the
|
|
@@ -187,12 +253,17 @@ function applyVerdictSideEffects(verdict, handlers) {
|
|
|
187
253
|
case 'clear':
|
|
188
254
|
case 'version':
|
|
189
255
|
case 'jobs':
|
|
256
|
+
case 'ask':
|
|
257
|
+
case 'consensus':
|
|
190
258
|
case 'diff':
|
|
191
259
|
case 'cost':
|
|
192
260
|
case 'status':
|
|
261
|
+
case 'resume':
|
|
193
262
|
case 'stub':
|
|
194
263
|
// All non-overlay verdicts: the session module already appended
|
|
195
|
-
// any operator-visible system lines
|
|
264
|
+
// any operator-visible system lines (and, for `ask`, set
|
|
265
|
+
// pendingAsk so the modal renders on the next frame). No further
|
|
266
|
+
// UI side effect needed here.
|
|
196
267
|
return;
|
|
197
268
|
}
|
|
198
269
|
}
|
package/dist/tui/status-bar.js
CHANGED
|
@@ -12,7 +12,12 @@ export function StatusBar(props) {
|
|
|
12
12
|
const tokenLabel = formatTokens(props.tokensDownstreamTotal);
|
|
13
13
|
const phase = clampPhase(props.pulsePhase);
|
|
14
14
|
const glyph = PULSE_DOTS[Math.min(phase, PULSE_DOTS.length - 1)] ?? PULSE_DOTS[0];
|
|
15
|
-
|
|
15
|
+
// α6.9: composite status label — connection problems trump dispatch
|
|
16
|
+
// state because the operator needs to know about a dropped admin-api
|
|
17
|
+
// first. When the connection is healthy (`on_watch` / `connecting`),
|
|
18
|
+
// the FSM dispatch state takes over to show the dispatch lifecycle
|
|
19
|
+
// (`dispatching` / `tool: read` / `aborting` / etc.).
|
|
20
|
+
const status = composeStatusLabel(props.connection, props.dispatchState, props.dispatchToolLabel);
|
|
16
21
|
return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: status.color, children: `${glyph ?? '●'} ${status.label}` }), _jsx(Text, { dimColor: true, children: ` · ${props.activeAgentCount} agents · ` }), _jsx(Text, { children: `↓ ${tokenLabel} tokens` }), _jsx(Text, { dimColor: true, children: ` · ${elapsedLabel}` })] }), _jsx(Box, { children: _jsx(Text, { dimColor: true, children: `${formatCount(props.pugiMdCount)} PUGI.md · ${formatCount(props.mcpServerCount)} MCP · ${formatCount(props.skillCount)} skills · ${formatQuota(props.quotaPct)} quota` }) })] }));
|
|
17
22
|
}
|
|
18
23
|
/**
|
|
@@ -28,10 +33,17 @@ function formatQuota(pct) {
|
|
|
28
33
|
return '—';
|
|
29
34
|
return `${Math.round(pct)}%`;
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
// Exported for test introspection (status-bar-fsm.spec.tsx asserts
|
|
37
|
+
// connecting vs on_watch render in distinct colors; ink-testing-library
|
|
38
|
+
// strips ANSI from lastFrame() so we read the resolved color directly).
|
|
39
|
+
export function connectionLabel(connection) {
|
|
32
40
|
switch (connection) {
|
|
33
41
|
case 'connecting':
|
|
34
|
-
|
|
42
|
+
// P2 fix: was 'cyan', same as 'on_watch' - operator could not
|
|
43
|
+
// tell boot from stable. Magenta is distinct from every other
|
|
44
|
+
// state in this palette (cyan steady, yellow reconnect, gray
|
|
45
|
+
// offline) so a brief flicker through this state stands out.
|
|
46
|
+
return { label: 'connecting', color: 'magenta' };
|
|
35
47
|
case 'on_watch':
|
|
36
48
|
return { label: 'on watch', color: 'cyan' };
|
|
37
49
|
case 'reconnecting':
|
|
@@ -40,6 +52,54 @@ function connectionLabel(connection) {
|
|
|
40
52
|
return { label: 'offline', color: 'gray' };
|
|
41
53
|
}
|
|
42
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* α6.9: compose the visible status label from connection + FSM state.
|
|
57
|
+
*
|
|
58
|
+
* Priority order:
|
|
59
|
+
*
|
|
60
|
+
* 1. `offline` / `reconnecting` — transport health wins; the
|
|
61
|
+
* operator needs to know about a dropped stream before anything
|
|
62
|
+
* about the dispatch.
|
|
63
|
+
* 2. `aborting` / `aborted` / `failed` — operator-visible terminal
|
|
64
|
+
* states the FSM reached; the colour shifts to amber/red so the
|
|
65
|
+
* anomaly stands out vs the calm cyan baseline.
|
|
66
|
+
* 3. `tool_running` — surfaces the tool label when available
|
|
67
|
+
* (`tool: read`), falls back to `tool` when not.
|
|
68
|
+
* 4. `awaiting_response` — `dispatching` (matches Codex CLI's verb
|
|
69
|
+
* for the same state).
|
|
70
|
+
* 5. `completed` — `shipped` (matches the agent tree status glyph
|
|
71
|
+
* so the operator's eye links the two surfaces).
|
|
72
|
+
* 6. `idle` / unknown — connection label (`on watch` / `connecting`).
|
|
73
|
+
*
|
|
74
|
+
* The dispatch label `dispatchToolLabel` is already shaped as
|
|
75
|
+
* `tool: <kind>` upstream so we just concatenate; null falls through
|
|
76
|
+
* to the bare `tool` placeholder.
|
|
77
|
+
*/
|
|
78
|
+
function composeStatusLabel(connection, dispatchState, toolLabel) {
|
|
79
|
+
// Transport health wins.
|
|
80
|
+
if (connection === 'offline' || connection === 'reconnecting') {
|
|
81
|
+
return connectionLabel(connection);
|
|
82
|
+
}
|
|
83
|
+
// FSM dispatch state overlay (only when the FSM was wired).
|
|
84
|
+
switch (dispatchState) {
|
|
85
|
+
case 'aborting':
|
|
86
|
+
return { label: 'aborting', color: 'yellow' };
|
|
87
|
+
case 'aborted':
|
|
88
|
+
return { label: 'aborted', color: 'gray' };
|
|
89
|
+
case 'failed':
|
|
90
|
+
return { label: 'failed', color: 'red' };
|
|
91
|
+
case 'tool_running':
|
|
92
|
+
return { label: toolLabel ?? 'tool', color: 'cyan' };
|
|
93
|
+
case 'awaiting_response':
|
|
94
|
+
return { label: 'dispatching', color: 'cyan' };
|
|
95
|
+
case 'completed':
|
|
96
|
+
return { label: 'shipped', color: 'green' };
|
|
97
|
+
case 'idle':
|
|
98
|
+
case undefined:
|
|
99
|
+
default:
|
|
100
|
+
return connectionLabel(connection);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
43
103
|
function formatElapsed(startedAt, now) {
|
|
44
104
|
if (typeof startedAt !== 'number')
|
|
45
105
|
return 'idle';
|