@pugi/cli 0.1.0-beta.16 → 0.1.0-beta.18
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/commands/jobs-watch.js +201 -0
- package/dist/commands/jobs.js +15 -0
- package/dist/core/agent-progress/cleanup.js +134 -0
- package/dist/core/agent-progress/schema.js +144 -0
- package/dist/core/agent-progress/writer.js +101 -0
- package/dist/core/diagnostics/probe-runner.js +93 -0
- package/dist/core/diagnostics/probes/api.js +46 -0
- package/dist/core/diagnostics/probes/auth.js +86 -0
- package/dist/core/diagnostics/probes/cli-version.js +127 -0
- package/dist/core/diagnostics/probes/config.js +72 -0
- package/dist/core/diagnostics/probes/disk.js +81 -0
- package/dist/core/diagnostics/probes/git.js +65 -0
- package/dist/core/diagnostics/probes/mcp.js +75 -0
- package/dist/core/diagnostics/probes/node.js +59 -0
- package/dist/core/diagnostics/probes/pnpm.js +36 -0
- package/dist/core/diagnostics/probes/session.js +74 -0
- package/dist/core/diagnostics/probes/workspace.js +63 -0
- package/dist/core/diagnostics/types.js +70 -0
- package/dist/core/engine/strip-internal-fields.js +124 -0
- package/dist/core/engine/tool-bridge.js +96 -27
- package/dist/core/file-cache.js +113 -1
- package/dist/core/mcp/client.js +66 -6
- package/dist/core/mcp/registry.js +24 -2
- package/dist/core/repl/session.js +64 -5
- package/dist/core/repl/slash-commands.js +9 -0
- package/dist/runtime/cli.js +153 -64
- package/dist/runtime/commands/doctor.js +357 -0
- package/dist/runtime/commands/mcp.js +290 -3
- package/dist/runtime/version.js +1 -1
- package/dist/tools/agent-tool.js +18 -4
- package/dist/tools/ask-user-question.js +213 -0
- package/dist/tools/file-tools.js +85 -14
- package/dist/tools/registry.js +7 -0
- package/dist/tui/agent-progress-card.js +111 -0
- package/dist/tui/ask-user-question-prompt.js +192 -0
- package/dist/tui/conversation-pane.js +68 -7
- package/dist/tui/doctor-table.js +31 -0
- package/dist/tui/tool-stream-pane.js +7 -0
- package/package.json +2 -2
package/dist/core/file-cache.js
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-session file-read cache + stale-read gate.
|
|
3
|
+
*
|
|
4
|
+
* Leak intel L1 (openclaude `FileEditTool.ts`, 2026-05-27 gap analysis
|
|
5
|
+
* §5.1): every FileEdit must validate the operator's last-known view of
|
|
6
|
+
* the file before mutating disk. The gate compares BOTH `mtimeMs` and
|
|
7
|
+
* `sha256(content)` of the file on disk against the record captured at
|
|
8
|
+
* read time:
|
|
9
|
+
*
|
|
10
|
+
* - mtimeMs is a cheap fast-path. If the inode mtime hasn't moved
|
|
11
|
+
* since the read, the content hash cannot have changed (barring a
|
|
12
|
+
* filesystem with hash-on-mtime-skew bugs) and we can short-circuit.
|
|
13
|
+
* - sha256 is the authoritative gate. A user editor that writes back
|
|
14
|
+
* identical content can leave mtime untouched on some filesystems
|
|
15
|
+
* (atomic-rename with preserved metadata), and conversely `touch`
|
|
16
|
+
* bumps mtime without changing content. Hash is the truth.
|
|
17
|
+
*
|
|
18
|
+
* Both signals must agree for the gate to PASS. Any divergence => STALE
|
|
19
|
+
* => refuse the edit, force the model to re-read.
|
|
20
|
+
*
|
|
21
|
+
* Cache lifetime: per-session. `FileReadCache.clear()` is called at
|
|
22
|
+
* session.end (see `core/session.ts`). The cache is intentionally NOT
|
|
23
|
+
* durable across sessions — a re-read after restart is cheap and stale
|
|
24
|
+
* cross-session entries would themselves be a soundness hazard.
|
|
25
|
+
*
|
|
26
|
+
* Exception: writeTool for create-new (path doesn't exist on disk) does
|
|
27
|
+
* not consult the cache. Creating a brand new file has no "last-known
|
|
28
|
+
* view" to invalidate.
|
|
29
|
+
*/
|
|
1
30
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { statSync } from 'node:fs';
|
|
31
|
+
import { existsSync, statSync } from 'node:fs';
|
|
3
32
|
import { resolve } from 'node:path';
|
|
33
|
+
export class StaleReadError extends Error {
|
|
34
|
+
reason;
|
|
35
|
+
path;
|
|
36
|
+
constructor(path, reason, detail) {
|
|
37
|
+
super(`stale_read: ${path} — ${detail}. Re-read the file before editing.`);
|
|
38
|
+
this.name = 'StaleReadError';
|
|
39
|
+
this.reason = reason;
|
|
40
|
+
this.path = path;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
4
43
|
export class FileReadCache {
|
|
5
44
|
records = new Map();
|
|
6
45
|
set(record) {
|
|
@@ -9,6 +48,70 @@ export class FileReadCache {
|
|
|
9
48
|
get(root, path) {
|
|
10
49
|
return this.records.get(resolve(root, path));
|
|
11
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Validate a candidate edit against the cached read record. Returns
|
|
53
|
+
* a tagged-union: `{ stale: false }` when the edit may proceed, or
|
|
54
|
+
* `{ stale: true, reason, detail }` when the gate must refuse.
|
|
55
|
+
*
|
|
56
|
+
* Pure function over the cache + supplied `currentMtimeMs` /
|
|
57
|
+
* `currentContent` — does NOT touch disk. Callers (editTool /
|
|
58
|
+
* writeTool) do their own `statSync` + `readFileSync` because they
|
|
59
|
+
* also need the content for the diff/edit itself.
|
|
60
|
+
*
|
|
61
|
+
* @param root workspace root (used to resolve relative path)
|
|
62
|
+
* @param path workspace-relative file path
|
|
63
|
+
* @param currentMtimeMs `fs.statSync().mtimeMs` of the on-disk file
|
|
64
|
+
* @param currentContent UTF-8 contents of the on-disk file
|
|
65
|
+
*/
|
|
66
|
+
validate(root, path, currentMtimeMs, currentContent) {
|
|
67
|
+
const record = this.get(root, path);
|
|
68
|
+
if (!record) {
|
|
69
|
+
return {
|
|
70
|
+
stale: true,
|
|
71
|
+
reason: 'no_prior_read',
|
|
72
|
+
detail: 'file must be read first',
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
// Fast-path: mtime hasn't moved. Hash check is redundant in the
|
|
76
|
+
// common case but cheap, so we still verify below. Skipping hash
|
|
77
|
+
// when mtime matches would allow a subtle bug class (in-place
|
|
78
|
+
// writers that preserve mtime) to slip through.
|
|
79
|
+
if (currentMtimeMs > record.mtimeMs) {
|
|
80
|
+
// mtime advanced — confirm with hash before flagging. A bump
|
|
81
|
+
// without a content change (e.g. `touch`) shouldn't fire stale.
|
|
82
|
+
const currentHash = hashContent(currentContent);
|
|
83
|
+
if (currentHash !== record.sha256) {
|
|
84
|
+
return {
|
|
85
|
+
stale: true,
|
|
86
|
+
reason: 'mtime_drift',
|
|
87
|
+
detail: `mtime advanced (${record.mtimeMs} → ${currentMtimeMs}) and content hash diverged`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// mtime bumped but content identical — treat as fresh. The cache
|
|
91
|
+
// entry's mtime is intentionally NOT refreshed here; the next
|
|
92
|
+
// edit will hit the same path and the gate will keep agreeing.
|
|
93
|
+
return { stale: false };
|
|
94
|
+
}
|
|
95
|
+
// mtime hasn't moved — hash MUST still match the record. A
|
|
96
|
+
// mismatch is a filesystem-level inconsistency or an in-place
|
|
97
|
+
// editor that preserves mtime; either way, refuse.
|
|
98
|
+
const currentHash = hashContent(currentContent);
|
|
99
|
+
if (currentHash !== record.sha256) {
|
|
100
|
+
return {
|
|
101
|
+
stale: true,
|
|
102
|
+
reason: 'hash_drift',
|
|
103
|
+
detail: 'content hash diverged from last read (mtime unchanged)',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return { stale: false };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Drop every cached record. Called by session.end so a fresh REPL
|
|
110
|
+
* session never inherits stale cross-session entries.
|
|
111
|
+
*/
|
|
112
|
+
clear() {
|
|
113
|
+
this.records.clear();
|
|
114
|
+
}
|
|
12
115
|
}
|
|
13
116
|
export function hashContent(content) {
|
|
14
117
|
return createHash('sha256').update(content).digest('hex');
|
|
@@ -26,4 +129,13 @@ export function createReadRecord(root, path, content, source) {
|
|
|
26
129
|
source,
|
|
27
130
|
};
|
|
28
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Convenience helper: does this absolute path exist on disk? Wraps the
|
|
134
|
+
* existsSync import so file-tools.ts can decide between create-new
|
|
135
|
+
* (skip stale gate) and update-existing (apply stale gate) without
|
|
136
|
+
* pulling in another fs import.
|
|
137
|
+
*/
|
|
138
|
+
export function pathExists(absolutePath) {
|
|
139
|
+
return existsSync(absolutePath);
|
|
140
|
+
}
|
|
29
141
|
//# sourceMappingURL=file-cache.js.map
|
package/dist/core/mcp/client.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
|
+
import { createWriteStream } from 'node:fs';
|
|
2
3
|
import { z } from 'zod';
|
|
3
4
|
/**
|
|
4
5
|
* Minimal JSON-RPC 2.0 over stdio MCP client for Pugi CLI M1.
|
|
@@ -79,6 +80,22 @@ export async function connect(serverName, config, options = {}) {
|
|
|
79
80
|
env: { ...process.env, ...config.env },
|
|
80
81
|
stdio: ['pipe', 'pipe', 'pipe'],
|
|
81
82
|
});
|
|
83
|
+
// L13: optional stderr → log file. We open the stream lazily so a bad
|
|
84
|
+
// path surfaces synchronously to the caller instead of getting buried
|
|
85
|
+
// in the child's stderr handler. `mkdir -p` of the parent dir is the
|
|
86
|
+
// caller's responsibility (the registry does it once per session).
|
|
87
|
+
let logStream;
|
|
88
|
+
if (options.logFile) {
|
|
89
|
+
try {
|
|
90
|
+
logStream = createWriteStream(options.logFile, { flags: 'a' });
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
// Log directory missing or unwritable — degrade silently rather
|
|
94
|
+
// than refuse the handshake. The operator still gets the same
|
|
95
|
+
// surface they had pre-L13 (stderr dropped on the floor).
|
|
96
|
+
logStream = undefined;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
82
99
|
const connection = {
|
|
83
100
|
serverName,
|
|
84
101
|
child,
|
|
@@ -86,6 +103,8 @@ export async function connect(serverName, config, options = {}) {
|
|
|
86
103
|
pending: new Map(),
|
|
87
104
|
nextId: 1,
|
|
88
105
|
closed: false,
|
|
106
|
+
...(logStream ? { logStream } : {}),
|
|
107
|
+
startedAt: Date.now(),
|
|
89
108
|
};
|
|
90
109
|
// Attach the spawn-error handler BEFORE the reader: ENOENT and similar
|
|
91
110
|
// are emitted asynchronously on the next tick, and without this
|
|
@@ -193,11 +212,25 @@ export async function callTool(connection, name, args, options = {}) {
|
|
|
193
212
|
* SIGKILL if the child has not exited. Safe to call multiple times.
|
|
194
213
|
*/
|
|
195
214
|
export async function disconnect(connection) {
|
|
196
|
-
|
|
215
|
+
const closeLogStream = () => {
|
|
216
|
+
const stream = connection.logStream;
|
|
217
|
+
if (!stream)
|
|
218
|
+
return;
|
|
219
|
+
try {
|
|
220
|
+
stream.end();
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Best-effort — stream may already be destroyed.
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
if (connection.closed) {
|
|
227
|
+
closeLogStream();
|
|
197
228
|
return;
|
|
229
|
+
}
|
|
198
230
|
const { child } = connection;
|
|
199
231
|
if (child.exitCode !== null || child.killed) {
|
|
200
232
|
connection.closed = true;
|
|
233
|
+
closeLogStream();
|
|
201
234
|
return;
|
|
202
235
|
}
|
|
203
236
|
return new Promise((resolveDone) => {
|
|
@@ -207,6 +240,7 @@ export async function disconnect(connection) {
|
|
|
207
240
|
return;
|
|
208
241
|
settled = true;
|
|
209
242
|
connection.closed = true;
|
|
243
|
+
closeLogStream();
|
|
210
244
|
resolveDone();
|
|
211
245
|
};
|
|
212
246
|
child.once('exit', settle);
|
|
@@ -232,6 +266,22 @@ export async function disconnect(connection) {
|
|
|
232
266
|
}, SHUTDOWN_GRACE_MS);
|
|
233
267
|
});
|
|
234
268
|
}
|
|
269
|
+
/**
|
|
270
|
+
* L13: cheap liveness probe for `pugi mcp doctor`. True when the child
|
|
271
|
+
* process is still running AND the connection has not been torn down.
|
|
272
|
+
* Does NOT issue a JSON-RPC call — that would race with in-flight tool
|
|
273
|
+
* dispatch and the doctor surface is read-only.
|
|
274
|
+
*/
|
|
275
|
+
export function isAlive(connection) {
|
|
276
|
+
if (connection.closed)
|
|
277
|
+
return false;
|
|
278
|
+
const { child } = connection;
|
|
279
|
+
if (child.killed)
|
|
280
|
+
return false;
|
|
281
|
+
if (child.exitCode !== null)
|
|
282
|
+
return false;
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
235
285
|
function writeFrame(connection, message) {
|
|
236
286
|
if (connection.closed) {
|
|
237
287
|
throw new Error(`mcp server "${connection.serverName}" connection is closed`);
|
|
@@ -283,11 +333,21 @@ function attachReader(connection) {
|
|
|
283
333
|
newlineIndex = buffer.indexOf('\n');
|
|
284
334
|
}
|
|
285
335
|
});
|
|
286
|
-
// stderr is captured
|
|
287
|
-
//
|
|
288
|
-
//
|
|
289
|
-
//
|
|
290
|
-
connection.child.stderr.on('data', () => {
|
|
336
|
+
// stderr is captured and (when `connect({ logFile })` was set) mirrored
|
|
337
|
+
// to a per-server log file under `.pugi/logs/`. Operators can tail the
|
|
338
|
+
// file via `pugi mcp logs <server>`. Default sink remains "drop on the
|
|
339
|
+
// floor" so the CLI stdout stays pure JSON envelope output.
|
|
340
|
+
connection.child.stderr.on('data', (chunk) => {
|
|
341
|
+
const stream = connection.logStream;
|
|
342
|
+
if (!stream || stream.destroyed)
|
|
343
|
+
return;
|
|
344
|
+
try {
|
|
345
|
+
stream.write(typeof chunk === 'string' ? chunk : chunk);
|
|
346
|
+
}
|
|
347
|
+
catch {
|
|
348
|
+
// Disk full / fd revoked — drop silently. Mirroring is best-effort.
|
|
349
|
+
}
|
|
350
|
+
});
|
|
291
351
|
}
|
|
292
352
|
function handleLine(connection, line) {
|
|
293
353
|
let parsed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { homedir } from 'node:os';
|
|
3
3
|
import { resolve } from 'node:path';
|
|
4
4
|
import { z } from 'zod';
|
|
@@ -38,6 +38,13 @@ import { getMcpTrust } from './trust.js';
|
|
|
38
38
|
const mcpFileSchema = z.object({
|
|
39
39
|
servers: z.record(mcpServerConfigSchema).default({}),
|
|
40
40
|
});
|
|
41
|
+
/**
|
|
42
|
+
* L13: workspace-relative path for per-server log files. Surfaces in
|
|
43
|
+
* `pugi mcp logs <name>` and is mkdir -p'd before the first connect.
|
|
44
|
+
*/
|
|
45
|
+
export function mcpLogPath(workspaceRoot, serverName) {
|
|
46
|
+
return resolve(workspaceRoot, '.pugi/logs', `mcp-${serverName}.log`);
|
|
47
|
+
}
|
|
41
48
|
/**
|
|
42
49
|
* Load and (optionally) connect every approved MCP server defined in the
|
|
43
50
|
* workspace + user configs. Pending and denied servers stay in the
|
|
@@ -45,6 +52,7 @@ const mcpFileSchema = z.object({
|
|
|
45
52
|
*/
|
|
46
53
|
export async function loadMcpRegistry(workspaceRoot, options = {}) {
|
|
47
54
|
const shouldConnect = options.connect !== false;
|
|
55
|
+
const handshakeTimeoutMs = options.handshakeTimeoutMs ?? 5_000;
|
|
48
56
|
const userConfig = readMcpFile(resolve(userHomeDir(), 'mcp.json'));
|
|
49
57
|
const workspaceConfig = readMcpFile(resolve(workspaceRoot, '.pugi/mcp.json'));
|
|
50
58
|
const merged = new Map();
|
|
@@ -52,6 +60,17 @@ export async function loadMcpRegistry(workspaceRoot, options = {}) {
|
|
|
52
60
|
merged.set(name, config);
|
|
53
61
|
for (const [name, config] of Object.entries(workspaceConfig))
|
|
54
62
|
merged.set(name, config);
|
|
63
|
+
// L13: ensure the log dir exists once per session so per-server log
|
|
64
|
+
// streams can `append` without each one having to mkdir -p.
|
|
65
|
+
if (shouldConnect && merged.size > 0) {
|
|
66
|
+
try {
|
|
67
|
+
mkdirSync(resolve(workspaceRoot, '.pugi/logs'), { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
// Workspace may be read-only (CI sandbox). Log routing degrades
|
|
71
|
+
// silently in that case — see `client.ts::connect`.
|
|
72
|
+
}
|
|
73
|
+
}
|
|
55
74
|
const servers = new Map();
|
|
56
75
|
for (const [name, config] of merged) {
|
|
57
76
|
const ledgerTrust = await getMcpTrust(name);
|
|
@@ -70,7 +89,10 @@ export async function loadMcpRegistry(workspaceRoot, options = {}) {
|
|
|
70
89
|
};
|
|
71
90
|
if (shouldConnect && trust === 'trusted') {
|
|
72
91
|
try {
|
|
73
|
-
const connection = await connect(name, config
|
|
92
|
+
const connection = await connect(name, config, {
|
|
93
|
+
timeoutMs: handshakeTimeoutMs,
|
|
94
|
+
logFile: mcpLogPath(workspaceRoot, name),
|
|
95
|
+
});
|
|
74
96
|
state.connection = connection;
|
|
75
97
|
state.surfacedTools = await listTools(connection);
|
|
76
98
|
}
|
|
@@ -765,6 +765,40 @@ export class ReplSession {
|
|
|
765
765
|
}
|
|
766
766
|
return verdict;
|
|
767
767
|
}
|
|
768
|
+
case 'doctor': {
|
|
769
|
+
// L17 (2026-05-27): run the doctor probe sweep inline. We
|
|
770
|
+
// dynamic-import the runtime/commands/doctor module so the
|
|
771
|
+
// slash dispatcher does not pull the diagnostics graph
|
|
772
|
+
// (execFileSync + fs probes) into every keystroke. The
|
|
773
|
+
// module's output is captured into local lines so we can
|
|
774
|
+
// render it as system entries in the conversation pane;
|
|
775
|
+
// an Ink-rendered table inside the REPL frame is a follow-up.
|
|
776
|
+
try {
|
|
777
|
+
const { runDoctorCommand, defaultHome } = await import('../../runtime/commands/doctor.js');
|
|
778
|
+
const lines = [];
|
|
779
|
+
await runDoctorCommand({
|
|
780
|
+
cwd: process.cwd(),
|
|
781
|
+
home: defaultHome(),
|
|
782
|
+
env: process.env,
|
|
783
|
+
json: false,
|
|
784
|
+
writeOutput: (_payload, text) => {
|
|
785
|
+
const trimmed = text.replace(/\n+$/u, '');
|
|
786
|
+
if (trimmed.length > 0)
|
|
787
|
+
lines.push(trimmed);
|
|
788
|
+
},
|
|
789
|
+
});
|
|
790
|
+
for (const line of lines)
|
|
791
|
+
this.appendSystemLine(line);
|
|
792
|
+
if (lines.length === 0) {
|
|
793
|
+
this.appendSystemLine('/doctor: no output.');
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
catch (error) {
|
|
797
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
798
|
+
this.appendSystemLine(`/doctor failed: ${message}`);
|
|
799
|
+
}
|
|
800
|
+
return verdict;
|
|
801
|
+
}
|
|
768
802
|
case 'stub': {
|
|
769
803
|
this.appendSystemLine(verdict.message);
|
|
770
804
|
return verdict;
|
|
@@ -2604,7 +2638,7 @@ export function synthesiseToolCall(input) {
|
|
|
2604
2638
|
// Pattern: ToolName(args) optionally suffixed with a result hint.
|
|
2605
2639
|
// We allow the canonical Claude Code casing AND the snake_case
|
|
2606
2640
|
// alias `web_fetch` so the synthesiser matches what personas write.
|
|
2607
|
-
const match = /^(Read|Edit|Bash|Grep|Glob|WebFetch|web_fetch)\s*\(\s*([^)]*)\s*\)\s*(.*)$/i
|
|
2641
|
+
const match = /^(Read|Write|Edit|Bash|Grep|Glob|WebFetch|web_fetch)\s*\(\s*([^)]*)\s*\)\s*(.*)$/i
|
|
2608
2642
|
.exec(detail);
|
|
2609
2643
|
if (!match)
|
|
2610
2644
|
return null;
|
|
@@ -2628,6 +2662,8 @@ function normaliseToolName(raw) {
|
|
|
2628
2662
|
return 'web_fetch';
|
|
2629
2663
|
if (lower === 'read')
|
|
2630
2664
|
return 'read';
|
|
2665
|
+
if (lower === 'write')
|
|
2666
|
+
return 'write';
|
|
2631
2667
|
if (lower === 'edit')
|
|
2632
2668
|
return 'edit';
|
|
2633
2669
|
if (lower === 'bash')
|
|
@@ -2853,7 +2889,22 @@ export function stripPersonaPrefixEcho(personaSlug, text) {
|
|
|
2853
2889
|
// Escape regex specials in the display name even though THE_TEN
|
|
2854
2890
|
// names are alpha-only today (forward-defense).
|
|
2855
2891
|
const escaped = display.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
2892
|
+
// Match `<DisplayName>` (case-insensitive) followed by EITHER:
|
|
2893
|
+
// - an end-of-string, OR
|
|
2894
|
+
// - a separator (whitespace / comma / colon / dash / period+space).
|
|
2895
|
+
// The `i` flag is needed so a model writing "PUGI:" or "pugi," still
|
|
2896
|
+
// strips. After this match the post-fix `noSepUppercaseRe` handles
|
|
2897
|
+
// the "PugiПринял" / "PugiHello" no-separator emission pattern
|
|
2898
|
+
// (CEO red-alert 2026-05-27) using a SEPARATE regex without the `i`
|
|
2899
|
+
// flag so the lookahead is case-strict (Pugineous must NOT strip).
|
|
2856
2900
|
const re = new RegExp(`^${escaped}(?:[\\s,:;\\-—–]+|$)`, 'i');
|
|
2901
|
+
// No-separator case-strict matcher. Display name in either of its
|
|
2902
|
+
// canonical casings ("Pugi" / "PUGI") immediately followed by an
|
|
2903
|
+
// uppercase Cyrillic or Latin letter. The strip is intentionally
|
|
2904
|
+
// narrower than the case-insensitive `re` above because a lowercase
|
|
2905
|
+
// continuation ("Pugineous") is a single word, not a display-name
|
|
2906
|
+
// echo - we must not eat real content.
|
|
2907
|
+
const noSepUppercaseRe = new RegExp(`^(?:${escaped}|${escaped.toUpperCase()})(?=[А-ЯЁA-Z])`);
|
|
2857
2908
|
// Loop the strip so cascading echoes ("Pugi Pugi Pugi, координатор ...")
|
|
2858
2909
|
// collapse to a single name. The model occasionally emits the display
|
|
2859
2910
|
// name two or three times back-to-back when the pane prefix also
|
|
@@ -2865,10 +2916,18 @@ export function stripPersonaPrefixEcho(personaSlug, text) {
|
|
|
2865
2916
|
// matches an empty string (defence-in-depth even though the current
|
|
2866
2917
|
// pattern guarantees at least one consumed char).
|
|
2867
2918
|
for (let i = 0; i < 3; i += 1) {
|
|
2868
|
-
|
|
2869
|
-
if (
|
|
2870
|
-
|
|
2871
|
-
|
|
2919
|
+
let m = re.exec(working);
|
|
2920
|
+
if (m && m[0].length > 0) {
|
|
2921
|
+
working = working.slice(m[0].length).trimStart();
|
|
2922
|
+
continue;
|
|
2923
|
+
}
|
|
2924
|
+
// Fallback: no-separator match for "PugiПринял" / "PugiHello" shape.
|
|
2925
|
+
m = noSepUppercaseRe.exec(working);
|
|
2926
|
+
if (m && m[0].length > 0) {
|
|
2927
|
+
working = working.slice(m[0].length);
|
|
2928
|
+
continue;
|
|
2929
|
+
}
|
|
2930
|
+
break;
|
|
2872
2931
|
}
|
|
2873
2932
|
return working;
|
|
2874
2933
|
}
|
|
@@ -81,6 +81,7 @@ export const SLASH_COMMAND_HELP = Object.freeze([
|
|
|
81
81
|
// Meta
|
|
82
82
|
{ name: 'help', args: '', gloss: 'Show this help overlay', group: 'Meta' },
|
|
83
83
|
{ name: 'version', args: '', gloss: 'Show CLI version', group: 'Meta' },
|
|
84
|
+
{ name: 'doctor', args: '', gloss: 'Environment health report (auth · API · Node · disk · MCP · …)', group: 'Meta' },
|
|
84
85
|
{ name: 'quit', args: '', gloss: 'Exit the REPL', group: 'Meta' },
|
|
85
86
|
]);
|
|
86
87
|
/**
|
|
@@ -271,6 +272,14 @@ export function parseSlashCommand(input) {
|
|
|
271
272
|
const tokens = tail.length === 0 ? [] : tail.split(/\s+/).filter((s) => s.length > 0);
|
|
272
273
|
return { kind: 'mcp', args: tokens };
|
|
273
274
|
}
|
|
275
|
+
case 'doctor':
|
|
276
|
+
case 'health': {
|
|
277
|
+
// L17 (2026-05-27): run the probe sweep inline. Tail is ignored —
|
|
278
|
+
// the doctor command has no operator-facing arguments (every
|
|
279
|
+
// probe runs unconditionally; per-probe disable lives on the CLI
|
|
280
|
+
// shell surface, not the slash one).
|
|
281
|
+
return { kind: 'doctor' };
|
|
282
|
+
}
|
|
274
283
|
case 'compact':
|
|
275
284
|
case 'memory':
|
|
276
285
|
case 'config':
|