@pugi/cli 0.1.0-beta.87 → 0.1.0-beta.88
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/CHANGELOG.md +36 -0
- package/LICENSE +1 -1
- package/dist/core/agents/registry.js +1 -1
- package/dist/core/checkpoints/shadow-git.js +1 -1
- package/dist/core/context/compaction.js +1 -1
- package/dist/core/denial-tracking/state.js +1 -1
- package/dist/core/edits/fuzzy-ladder.js +1 -1
- package/dist/core/edits/layer-a-fuzzy-apply.js +1 -1
- package/dist/core/engine/anvil-client.js +13 -2
- package/dist/core/mcp/server-tools.js +1 -1
- package/dist/core/mcp/server.js +1 -1
- package/dist/core/memory/secret-scanner.js +6 -6
- package/dist/core/onboarding/ensure-initialized.js +1 -1
- package/dist/core/plans/plan-artifact.js +2 -2
- package/dist/core/repl/cap-warning.js +1 -1
- package/dist/core/routing/pre-flight-estimator.js +1 -1
- package/dist/core/settings.js +12 -0
- package/dist/index.js +8 -0
- package/dist/runtime/cli.js +68 -20
- package/dist/runtime/commands/config.js +41 -7
- package/dist/runtime/sigint-guard.js +272 -0
- package/dist/runtime/version.js +1 -1
- package/dist/skills/bundled/batch.js +2 -2
- package/dist/skills/bundled/index.js +3 -3
- package/dist/skills/bundled/loop.js +2 -2
- package/dist/skills/bundled/remember.js +1 -1
- package/dist/skills/bundled/simplify.js +1 -1
- package/dist/skills/bundled/skillify.js +2 -2
- package/dist/skills/bundled/stuck.js +1 -1
- package/dist/skills/bundled/verify.js +2 -2
- package/dist/testing/vcr.js +2 -2
- package/dist/tools/ask-user-question.js +66 -0
- package/dist/tools/bash.js +2 -2
- package/dist/tools/powershell.js +1 -1
- package/dist/tui/ask-user-question-chips.js +257 -0
- package/dist/tui/welcome-data.js +4 -4
- package/package.json +5 -4
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Double-press Ctrl+C exit guard for the Pugi CLI top-level lifecycle.
|
|
3
|
+
*
|
|
4
|
+
* # Problem
|
|
5
|
+
*
|
|
6
|
+
* Operator dogfood reported a single Ctrl+C exits the REPL / headless
|
|
7
|
+
* loop. Operators expect a forgiving "press again to confirm" gesture
|
|
8
|
+
* — the same shell convention `^C ^C` already used by the per-engine
|
|
9
|
+
* task abort path in `runtime/cli.ts` (`runEngineTask`). Without the
|
|
10
|
+
* gesture at the top level, a stray Ctrl+C while typing a slash command
|
|
11
|
+
* or scrolling a transcript kills the session and any in-memory state
|
|
12
|
+
* the operator hasn't synced yet.
|
|
13
|
+
*
|
|
14
|
+
* # Behavior
|
|
15
|
+
*
|
|
16
|
+
* 1. **First Ctrl+C** — emit a one-line stderr prompt
|
|
17
|
+
* "Press Ctrl+C again to exit (within 2s), or any key to continue."
|
|
18
|
+
* Arm a 2-second window timer. Install a one-shot `stdin.once('data', …)`
|
|
19
|
+
* so the FIRST keystroke after the prompt cancels the exit gesture.
|
|
20
|
+
* 2. **Second Ctrl+C inside window** — flush log streams, persist a
|
|
21
|
+
* minimal session-state snapshot to `~/.pugi/session-state.json`,
|
|
22
|
+
* and exit with code 0. The state file is best-effort: any write
|
|
23
|
+
* error is swallowed so the operator's exit is never blocked on
|
|
24
|
+
* a disk hiccup.
|
|
25
|
+
* 3. **Other key inside window** — clear the timer, drop the prompt,
|
|
26
|
+
* emit "Exit cancelled." to stderr, and resume normally.
|
|
27
|
+
* 4. **Window expires** — clear `lastSigintTs`. A subsequent isolated
|
|
28
|
+
* Ctrl+C is treated as a NEW first press, not a confirmation.
|
|
29
|
+
* 5. **Headless mode** — when `process.stdin.isTTY === false`, the
|
|
30
|
+
* guard switches strategy: it closes stdin (so any `for await rl`
|
|
31
|
+
* loop in `headless-repl.ts` unwinds naturally), emits a
|
|
32
|
+
* `session-end` envelope to stdout (single JSON line, matches
|
|
33
|
+
* the envelope schema), and exits 0. Stdin can't deliver "any
|
|
34
|
+
* other key" when it's not a TTY, so the double-press dance is
|
|
35
|
+
* skipped in this mode.
|
|
36
|
+
*
|
|
37
|
+
* # Coexistence with the per-engine-run handler
|
|
38
|
+
*
|
|
39
|
+
* `runEngineTask` in `runtime/cli.ts` installs its OWN
|
|
40
|
+
* `process.on('SIGINT', …)` for the duration of an engine dispatch
|
|
41
|
+
* (lines around 6233). That handler aborts the in-flight turn on the
|
|
42
|
+
* first press and exits 130 on a second press inside its OWN 2s
|
|
43
|
+
* window. Both handlers receive every SIGINT — Node delivers signals
|
|
44
|
+
* to every listener.
|
|
45
|
+
*
|
|
46
|
+
* To avoid a double prompt while an engine turn is running, this
|
|
47
|
+
* guard checks `process.listenerCount('SIGINT')` at the start of its
|
|
48
|
+
* handler: if any other listener is attached (i.e. an engine run owns
|
|
49
|
+
* the foreground), we step aside and let that handler drive the UX.
|
|
50
|
+
* The engine handler's "press again to exit" prompt already covers
|
|
51
|
+
* the abort-then-quit story for that window. When the engine run
|
|
52
|
+
* unwinds, it detaches its listener and the REPL-level guard regains
|
|
53
|
+
* control.
|
|
54
|
+
*
|
|
55
|
+
* # Why module-scope, not per-call closure
|
|
56
|
+
*
|
|
57
|
+
* The press-count state must survive between two distinct SIGINT
|
|
58
|
+
* deliveries. A closure-scoped flag would reset on the second SIGINT
|
|
59
|
+
* because Node invokes the handler in a fresh microtask each time.
|
|
60
|
+
* Module-scope `let` is the simplest store that gives us cross-press
|
|
61
|
+
* persistence without leaking to other files.
|
|
62
|
+
*
|
|
63
|
+
* # Testability
|
|
64
|
+
*
|
|
65
|
+
* `installSigintGuard()` takes an optional `SigintGuardOptions` bag
|
|
66
|
+
* so the spec can inject:
|
|
67
|
+
* - a fake `stdin` (for "any key cancels"),
|
|
68
|
+
* - a fake `stdout` / `stderr` sink,
|
|
69
|
+
* - a `now()` clock seam,
|
|
70
|
+
* - a `setTimeout` / `clearTimeout` pair,
|
|
71
|
+
* - a `exit(code)` seam (the test never lets the real process exit),
|
|
72
|
+
* - and a `persistSessionState(payload)` injection so the spec
|
|
73
|
+
* observes the persisted snapshot without touching `~/`.
|
|
74
|
+
*
|
|
75
|
+
* In production all seams default to the real Node primitives.
|
|
76
|
+
*/
|
|
77
|
+
import { writeFile, mkdir } from 'node:fs/promises';
|
|
78
|
+
import { homedir } from 'node:os';
|
|
79
|
+
import { resolve as resolvePath, dirname } from 'node:path';
|
|
80
|
+
/**
|
|
81
|
+
* Default double-press window. Matches the per-engine-run handler so
|
|
82
|
+
* operators see one consistent timing rule across the CLI.
|
|
83
|
+
*/
|
|
84
|
+
export const SIGINT_DOUBLE_PRESS_WINDOW_MS = 2000;
|
|
85
|
+
/**
|
|
86
|
+
* Default location for the session-state snapshot the guard writes on
|
|
87
|
+
* a confirmed exit. Resolved at call time so `homedir()` is read late
|
|
88
|
+
* enough to honor a test override of the `HOME` env var.
|
|
89
|
+
*/
|
|
90
|
+
export function defaultSessionStatePath(home = homedir()) {
|
|
91
|
+
return resolvePath(home, '.pugi', 'session-state.json');
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Default JSON-file persister. Best-effort: a failed write is logged
|
|
95
|
+
* to stderr (so the operator notices in debug runs) and then
|
|
96
|
+
* swallowed — the exit must not block on filesystem health.
|
|
97
|
+
*/
|
|
98
|
+
async function defaultPersist(snapshot) {
|
|
99
|
+
const filePath = defaultSessionStatePath();
|
|
100
|
+
try {
|
|
101
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
102
|
+
await writeFile(filePath, JSON.stringify(snapshot, null, 2), {
|
|
103
|
+
mode: 0o600,
|
|
104
|
+
encoding: 'utf8',
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
109
|
+
process.stderr.write(`pugi: session-state write failed: ${message}\n`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Default SIGINT subscription wires the handler onto `process` and
|
|
114
|
+
* returns an unsubscribe closure that detaches it. We use `.on` (not
|
|
115
|
+
* `.once`) so the handler stays attached across multiple presses
|
|
116
|
+
* within the same process lifetime.
|
|
117
|
+
*/
|
|
118
|
+
function defaultOnSigint(handler) {
|
|
119
|
+
process.on('SIGINT', handler);
|
|
120
|
+
return () => {
|
|
121
|
+
process.off('SIGINT', handler);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Install the double-press Ctrl+C exit guard. Returns a handle whose
|
|
126
|
+
* `uninstall()` detaches the SIGINT listener and clears any pending
|
|
127
|
+
* window timer; production never calls it.
|
|
128
|
+
*
|
|
129
|
+
* This function is idempotent: calling it a second time installs a
|
|
130
|
+
* NEW guard alongside the old one, which would cause duplicate
|
|
131
|
+
* prompts. The caller (cli.ts main entry) MUST call it exactly once,
|
|
132
|
+
* at the very top of the run. Tests that need multiple installs are
|
|
133
|
+
* expected to `uninstall()` between scenarios.
|
|
134
|
+
*/
|
|
135
|
+
export function installSigintGuard(options = {}) {
|
|
136
|
+
const stdin = options.stdin ?? process.stdin;
|
|
137
|
+
const stderr = options.stderr ?? process.stderr;
|
|
138
|
+
const stdout = options.stdout ?? process.stdout;
|
|
139
|
+
const now = options.now ?? Date.now;
|
|
140
|
+
const setTimer = options.setTimer ?? ((fn, ms) => setTimeout(fn, ms));
|
|
141
|
+
const clearTimer = options.clearTimer ?? ((handle) => clearTimeout(handle));
|
|
142
|
+
const exit = options.exit ?? ((code) => process.exit(code));
|
|
143
|
+
const persist = options.persistSessionState ?? defaultPersist;
|
|
144
|
+
const subscribe = options.onSigint ?? defaultOnSigint;
|
|
145
|
+
const isHeadless = options.isHeadless ?? (() => stdin.isTTY !== true);
|
|
146
|
+
const windowMs = options.windowMs ?? SIGINT_DOUBLE_PRESS_WINDOW_MS;
|
|
147
|
+
// State scoped to THIS install. Each call to `installSigintGuard`
|
|
148
|
+
// gets a fresh closure so concurrent tests do not bleed into each
|
|
149
|
+
// other. Production calls the function once at the top of the run.
|
|
150
|
+
let lastSigintTs = null;
|
|
151
|
+
let pendingTimer = null;
|
|
152
|
+
let pendingDataListener = null;
|
|
153
|
+
const resetWindow = () => {
|
|
154
|
+
lastSigintTs = null;
|
|
155
|
+
if (pendingTimer !== null) {
|
|
156
|
+
clearTimer(pendingTimer);
|
|
157
|
+
pendingTimer = null;
|
|
158
|
+
}
|
|
159
|
+
if (pendingDataListener !== null) {
|
|
160
|
+
// Detach via the same instance we attached; never the typed
|
|
161
|
+
// overload that re-binds 'data' to all listeners.
|
|
162
|
+
stdin.removeListener('data', pendingDataListener);
|
|
163
|
+
pendingDataListener = null;
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
const performExit = (reason) => {
|
|
167
|
+
const snapshot = {
|
|
168
|
+
exitedAt: new Date(now()).toISOString(),
|
|
169
|
+
reason,
|
|
170
|
+
cwd: process.cwd(),
|
|
171
|
+
pid: process.pid,
|
|
172
|
+
};
|
|
173
|
+
// Fire-and-forget persistence: we attempt to flush, but do not
|
|
174
|
+
// block the exit on the result. The promise is observed only to
|
|
175
|
+
// suppress unhandled-rejection noise in the test runner.
|
|
176
|
+
void persist(snapshot).catch(() => {
|
|
177
|
+
/* defaultPersist already logged */
|
|
178
|
+
});
|
|
179
|
+
exit(0);
|
|
180
|
+
};
|
|
181
|
+
const handleHeadless = () => {
|
|
182
|
+
// In headless mode we never prompt — the operator (or harness)
|
|
183
|
+
// has no keyboard to confirm with. We emit one final
|
|
184
|
+
// session-end envelope so any line-buffered consumer sees a
|
|
185
|
+
// clean terminator, close stdin so the `for await rl` loop in
|
|
186
|
+
// headless-repl.ts unwinds, and exit 0.
|
|
187
|
+
const envelope = {
|
|
188
|
+
kind: 'session-end',
|
|
189
|
+
body: JSON.stringify({ reason: 'sigint' }),
|
|
190
|
+
ts: now(),
|
|
191
|
+
};
|
|
192
|
+
stdout.write(`${JSON.stringify(envelope)}\n`);
|
|
193
|
+
// Best-effort stdin close so any in-flight readline loop terminates.
|
|
194
|
+
// Some stream implementations (e.g. test doubles) lack `.destroy`;
|
|
195
|
+
// guard the call so we never throw out of a signal handler.
|
|
196
|
+
const stdinAsAny = stdin;
|
|
197
|
+
try {
|
|
198
|
+
if (typeof stdinAsAny.destroy === 'function') {
|
|
199
|
+
stdinAsAny.destroy();
|
|
200
|
+
}
|
|
201
|
+
else if (typeof stdinAsAny.pause === 'function') {
|
|
202
|
+
stdinAsAny.pause();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
catch {
|
|
206
|
+
/* ignore — destroy/pause is opportunistic */
|
|
207
|
+
}
|
|
208
|
+
performExit('sigint-headless');
|
|
209
|
+
};
|
|
210
|
+
const handleInteractive = () => {
|
|
211
|
+
const ts = now();
|
|
212
|
+
if (lastSigintTs !== null && ts - lastSigintTs <= windowMs) {
|
|
213
|
+
// Confirmed double-press. Drop the prompt artifacts, persist
|
|
214
|
+
// state, exit clean. resetWindow() handles the listener
|
|
215
|
+
// cleanup so a stray `data` event after exit does not fire.
|
|
216
|
+
resetWindow();
|
|
217
|
+
stderr.write('\npugi: exiting (^C^C confirmed).\n');
|
|
218
|
+
performExit('sigint-double-press');
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
// First press — arm the window.
|
|
222
|
+
lastSigintTs = ts;
|
|
223
|
+
stderr.write('\nPress Ctrl+C again to exit (within 2s), or any key to continue.\n');
|
|
224
|
+
// Schedule a window-expiry reset. When the timer fires the
|
|
225
|
+
// operator's prior press no longer "counts" — the next ^C is
|
|
226
|
+
// treated as a fresh first press.
|
|
227
|
+
pendingTimer = setTimer(() => {
|
|
228
|
+
lastSigintTs = null;
|
|
229
|
+
pendingTimer = null;
|
|
230
|
+
if (pendingDataListener !== null) {
|
|
231
|
+
stdin.removeListener('data', pendingDataListener);
|
|
232
|
+
pendingDataListener = null;
|
|
233
|
+
}
|
|
234
|
+
}, windowMs);
|
|
235
|
+
// Install a one-shot 'data' listener so any keystroke other than
|
|
236
|
+
// a follow-up SIGINT cancels the exit gesture. We use
|
|
237
|
+
// `removeListener` after firing rather than `.once` because we
|
|
238
|
+
// also detach the listener from `resetWindow()` (the timer or
|
|
239
|
+
// a second SIGINT can both kill it).
|
|
240
|
+
const onData = (_chunk) => {
|
|
241
|
+
resetWindow();
|
|
242
|
+
stderr.write('Exit cancelled.\n');
|
|
243
|
+
};
|
|
244
|
+
pendingDataListener = onData;
|
|
245
|
+
stdin.on('data', onData);
|
|
246
|
+
};
|
|
247
|
+
const handler = () => {
|
|
248
|
+
// Coexistence guard: if another SIGINT listener is registered
|
|
249
|
+
// (e.g. the per-engine-run handler in runEngineTask), step aside
|
|
250
|
+
// and let it drive the UX. We count `> 1` because OUR handler
|
|
251
|
+
// is also in the list.
|
|
252
|
+
if (process.listenerCount('SIGINT') > 1 && !options.onSigint) {
|
|
253
|
+
// Drop any state we'd accumulated so an interactive prompt
|
|
254
|
+
// after the engine run starts from a clean slate.
|
|
255
|
+
resetWindow();
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (isHeadless()) {
|
|
259
|
+
handleHeadless();
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
handleInteractive();
|
|
263
|
+
};
|
|
264
|
+
const unsubscribe = subscribe(handler);
|
|
265
|
+
return {
|
|
266
|
+
uninstall: () => {
|
|
267
|
+
resetWindow();
|
|
268
|
+
unsubscribe();
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
//# sourceMappingURL=sigint-guard.js.map
|
package/dist/runtime/version.js
CHANGED
|
@@ -44,7 +44,7 @@ export function sanitizeSemver(raw) {
|
|
|
44
44
|
* during import). When bumping the CLI version BOTH literals must be
|
|
45
45
|
* updated; the release smoke-test (`pack:smoke`) verifies they agree.
|
|
46
46
|
*/
|
|
47
|
-
export const PUGI_CLI_VERSION = sanitizeSemver('0.1.0-beta.
|
|
47
|
+
export const PUGI_CLI_VERSION = sanitizeSemver('0.1.0-beta.88');
|
|
48
48
|
/**
|
|
49
49
|
* Outbound: the CLI's installed semver. Read at request time by
|
|
50
50
|
* `version-interceptor.ts` and injected on every `fetch` call.
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
*
|
|
42
42
|
* # Provenance
|
|
43
43
|
*
|
|
44
|
-
* Inspired by the
|
|
45
|
-
* leak-research memos,
|
|
44
|
+
* Inspired by the external bundled-skills pattern (intel from
|
|
45
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
46
46
|
*/
|
|
47
47
|
import { spawn } from 'node:child_process';
|
|
48
48
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* - `pugi simplify` — local 3-agent parallel review + auto-fix.
|
|
10
10
|
* - `pugi remember` — proposal-first memory curator.
|
|
11
11
|
*
|
|
12
|
-
* - Batch 2 (`#169`,
|
|
12
|
+
* - Batch 2 (`#169`, external independent implementation):
|
|
13
13
|
* - `pugi batch` — fan-out multi-task parallel execution scaffold.
|
|
14
14
|
* - `pugi verify` — post-execution claim verification.
|
|
15
15
|
* - `pugi loop` — drive a prompt against the engine to a stop condition.
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
* in `runtime/cli.ts` (and any future REPL slash wrapper) imports
|
|
20
20
|
* through one barrel. New batches append to the union types here.
|
|
21
21
|
*
|
|
22
|
-
* Inspired by the upstream tool /
|
|
23
|
-
* leak-research memos,
|
|
22
|
+
* Inspired by the upstream tool / external bundled-skills patterns (intel from
|
|
23
|
+
* leak-research memos, independent implementation TS).
|
|
24
24
|
*/
|
|
25
25
|
export { runStuckCommand, classifyPeers, classifyChildren, readDebugTail, captureSampleStack, postSnapshotToWebhook, readProcessTable, } from './stuck.js';
|
|
26
26
|
export { runSimplifyCommand, aggregateReviewerResults, parseReviewerFindings, defaultCaptureDiff, } from './simplify.js';
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
*
|
|
30
30
|
* # Provenance
|
|
31
31
|
*
|
|
32
|
-
* Inspired by the
|
|
33
|
-
* leak-research memos,
|
|
32
|
+
* Inspired by the external bundled-skills pattern (intel from
|
|
33
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
34
34
|
* Multi-provider council mode inside loop is backlog; today the
|
|
35
35
|
* skill is single-engine.
|
|
36
36
|
*/
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
* # Provenance
|
|
46
46
|
*
|
|
47
47
|
* Inspired by the the upstream tool bundled-skills pattern (intel from
|
|
48
|
-
* leak-research memos,
|
|
48
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
49
49
|
*/
|
|
50
50
|
import { readFileSync } from 'node:fs';
|
|
51
51
|
import { PERSONA_MEMORY_KINDS, enqueueMemoryOp, } from '../../core/memory-sync/queue.js';
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
* # Provenance
|
|
44
44
|
*
|
|
45
45
|
* Inspired by the the upstream tool bundled-skills pattern (intel from
|
|
46
|
-
* leak-research memos,
|
|
46
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
47
47
|
*/
|
|
48
48
|
import { execFileSync } from 'node:child_process';
|
|
49
49
|
const DEFAULT_BASE_REF = 'origin/main';
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
*
|
|
30
30
|
* # Provenance
|
|
31
31
|
*
|
|
32
|
-
* Inspired by the
|
|
33
|
-
* leak-research memos,
|
|
32
|
+
* Inspired by the external bundled-skills pattern (intel from
|
|
33
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
34
34
|
*/
|
|
35
35
|
import { existsSync, mkdirSync, renameSync, rmSync, writeFileSync, } from 'node:fs';
|
|
36
36
|
import { dirname, join } from 'node:path';
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
* # Provenance
|
|
35
35
|
*
|
|
36
36
|
* Inspired by the the upstream tool bundled-skills pattern (intel from
|
|
37
|
-
* leak-research memos,
|
|
37
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
38
38
|
*/
|
|
39
39
|
import { execFileSync, spawnSync } from 'node:child_process';
|
|
40
40
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
*
|
|
40
40
|
* # Provenance
|
|
41
41
|
*
|
|
42
|
-
* Inspired by the
|
|
43
|
-
* leak-research memos,
|
|
42
|
+
* Inspired by the external bundled-skills pattern (intel from
|
|
43
|
+
* leak-research memos, independent implementation TS). No upstream code reused.
|
|
44
44
|
*/
|
|
45
45
|
import { spawnSync } from 'node:child_process';
|
|
46
46
|
import { existsSync, readFileSync, statSync } from 'node:fs';
|
package/dist/testing/vcr.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* VCR — Pugi CLI test helper that records `fetch` interactions to a JSON
|
|
3
|
-
* cassette and replays them deterministically.
|
|
4
|
-
* of the
|
|
3
|
+
* cassette and replays them deterministically. independent implementation re-implementation
|
|
4
|
+
* of the external `vcr.ts` pattern; Node built-ins only (`node:fs`,
|
|
5
5
|
* `node:crypto`, `node:path`), no new dependencies.
|
|
6
6
|
*
|
|
7
7
|
* # Why this exists
|
|
@@ -48,6 +48,22 @@ export const ASK_USER_QUESTION_OPTION_DESC_MAX = 200;
|
|
|
48
48
|
/** Option count: 2-4 strict. UI adds "Other" automatically. */
|
|
49
49
|
export const ASK_USER_QUESTION_OPTIONS_MIN = 2;
|
|
50
50
|
export const ASK_USER_QUESTION_OPTIONS_MAX = 4;
|
|
51
|
+
/** PUGI-480 short-format chip rules: ≤ 5 words / option label, ≤ 3 questions / call. */
|
|
52
|
+
export const ASK_USER_QUESTION_CHIP_LABEL_WORD_MAX = 5;
|
|
53
|
+
export const ASK_USER_QUESTION_CHIPS_MAX = 3;
|
|
54
|
+
/**
|
|
55
|
+
* Reusable validator for option labels rendered в chip mode.
|
|
56
|
+
* Counts whitespace-delimited words. Throws с a clear message that
|
|
57
|
+
* names the offending question + option so the model can self-correct.
|
|
58
|
+
*/
|
|
59
|
+
export function assertChipLabelWordCap(questionHeader, optionLabel) {
|
|
60
|
+
const words = optionLabel.trim().split(/\s+/u).filter((w) => w.length > 0);
|
|
61
|
+
if (words.length > ASK_USER_QUESTION_CHIP_LABEL_WORD_MAX) {
|
|
62
|
+
throw new Error(`ask_user_question chip "${questionHeader}" option "${optionLabel}" ` +
|
|
63
|
+
`exceeds the ${ASK_USER_QUESTION_CHIP_LABEL_WORD_MAX}-word label cap ` +
|
|
64
|
+
`(saw ${words.length} words). Shorten the label before dispatch.`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
51
67
|
/**
|
|
52
68
|
* Structured option. `label` is the display text; `description` is the
|
|
53
69
|
* implication line shown dim below it. Both are required — the model
|
|
@@ -100,6 +116,56 @@ export const askUserQuestionSchema = z.strictObject({
|
|
|
100
116
|
.default(false)
|
|
101
117
|
.describe('Allow multiple selections. Default false.'),
|
|
102
118
|
});
|
|
119
|
+
/**
|
|
120
|
+
* PUGI-480 multi-question chip payload — a bundle of up to 3 short-format
|
|
121
|
+
* chip questions rendered side-by-side. Schema is intentionally narrow:
|
|
122
|
+
* the chip renderer relies on the ≤ 5-word label invariant и will
|
|
123
|
+
* truncate с "…" if the model ever bypasses Zod. The 3-question cap
|
|
124
|
+
* forecloses paragraph-wall prompts at the schema level — the model
|
|
125
|
+
* cannot legally ask "10 quick questions" in one shot.
|
|
126
|
+
*/
|
|
127
|
+
export const askUserQuestionChipsQuestionSchema = z.strictObject({
|
|
128
|
+
header: z
|
|
129
|
+
.string()
|
|
130
|
+
.min(ASK_USER_QUESTION_HEADER_MIN)
|
|
131
|
+
.max(ASK_USER_QUESTION_HEADER_MAX)
|
|
132
|
+
.describe('Short chip label (max 12 chars). E.g. "Stack".'),
|
|
133
|
+
question: z
|
|
134
|
+
.string()
|
|
135
|
+
.min(ASK_USER_QUESTION_MIN)
|
|
136
|
+
.max(ASK_USER_QUESTION_MAX)
|
|
137
|
+
.optional()
|
|
138
|
+
.describe('Optional full-prose question (shown in non-TTY fallback only).'),
|
|
139
|
+
options: z
|
|
140
|
+
.array(askUserQuestionOptionSchema)
|
|
141
|
+
.min(ASK_USER_QUESTION_OPTIONS_MIN)
|
|
142
|
+
.max(ASK_USER_QUESTION_OPTIONS_MAX + 1)
|
|
143
|
+
.superRefine((opts, ctx) => {
|
|
144
|
+
// Enforce ≤ 5-word label cap on every option. Schema-level so
|
|
145
|
+
// the model gets immediate feedback on overflow rather than a
|
|
146
|
+
// silent truncation at render time.
|
|
147
|
+
for (const opt of opts) {
|
|
148
|
+
const words = opt.label
|
|
149
|
+
.trim()
|
|
150
|
+
.split(/\s+/u)
|
|
151
|
+
.filter((w) => w.length > 0);
|
|
152
|
+
if (words.length > ASK_USER_QUESTION_CHIP_LABEL_WORD_MAX) {
|
|
153
|
+
ctx.addIssue({
|
|
154
|
+
code: z.ZodIssueCode.custom,
|
|
155
|
+
message: `option "${opt.label}" has ${words.length} words; chip labels must be ≤ ${ASK_USER_QUESTION_CHIP_LABEL_WORD_MAX} words`,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
.describe('2-5 mutually-exclusive options. Each label ≤ 5 words. UI inserts "Skip — use defaults" as a final option when defaults are present.'),
|
|
161
|
+
});
|
|
162
|
+
export const askUserQuestionChipsSchema = z.strictObject({
|
|
163
|
+
questions: z
|
|
164
|
+
.array(askUserQuestionChipsQuestionSchema)
|
|
165
|
+
.min(1)
|
|
166
|
+
.max(ASK_USER_QUESTION_CHIPS_MAX)
|
|
167
|
+
.describe('Bundle of 1-3 short clarifier questions rendered side-by-side as chips.'),
|
|
168
|
+
});
|
|
103
169
|
/**
|
|
104
170
|
* Dispatch the structured tool: validate args via Zod, then route
|
|
105
171
|
* through the shared `askUser` primitive so abort/timeout/non-TTY
|
package/dist/tools/bash.js
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
* `jobId`. `listJobs()` and `killJob(jobId)` are exported.
|
|
24
24
|
* 5. 60s default timeout. SIGTERM at deadline, SIGKILL 5s later.
|
|
25
25
|
* Emit `bash.timeout`.
|
|
26
|
-
* 6. POSIX-only (`/bin/sh`). The non-goal in
|
|
26
|
+
* 6. POSIX-only (`/bin/sh`). The non-goal in explicitly
|
|
27
27
|
* drops Windows shell support for M1.
|
|
28
28
|
*/
|
|
29
29
|
import { randomUUID } from 'node:crypto';
|
|
@@ -191,7 +191,7 @@ export async function bashTool(input, ctx) {
|
|
|
191
191
|
};
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
|
-
// POSIX-only `/bin/sh -c <cmd>`. The
|
|
194
|
+
// POSIX-only `/bin/sh -c <cmd>`. The non-goals explicitly
|
|
195
195
|
// exclude Windows for M1.
|
|
196
196
|
//
|
|
197
197
|
// stdio layout:
|
package/dist/tools/powershell.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* на cross-platform PowerShell 7+ binary so Windows-first workflows are
|
|
7
7
|
* first-class на Pugi.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
9
|
+
* independent implementation re-implementation. Surface mirrors bashTool's permission
|
|
10
10
|
* gate, env sanitiser, output cap, timeout, and exit-code propagation;
|
|
11
11
|
* the only difference is the shell binary selection. Per-platform
|
|
12
12
|
* resolution:
|