@pugi/cli 0.1.0-alpha.9 → 0.1.0-beta.2
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/edits/worktree.js +229 -0
- package/dist/core/engine/native-pugi.js +6 -1
- package/dist/core/engine/prompts.js +4 -1
- package/dist/core/engine/tool-bridge.js +33 -1
- package/dist/core/lsp/client.js +631 -0
- 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 +1896 -13
- 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 +767 -10
- package/dist/runtime/commands/agents.js +385 -0
- package/dist/runtime/commands/config.js +338 -8
- package/dist/runtime/commands/lsp.js +184 -0
- package/dist/runtime/commands/patch.js +111 -0
- package/dist/runtime/commands/review-consensus.js +399 -0
- package/dist/runtime/commands/skills.js +401 -0
- package/dist/runtime/commands/worktree.js +133 -0
- package/dist/tools/apply-patch.js +314 -0
- package/dist/tools/file-tools.js +90 -0
- package/dist/tools/lsp-tools.js +189 -0
- package/dist/tools/registry.js +18 -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 +185 -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
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `.pugiignore` parser - α6.5 Phase 1 (three-tier context).
|
|
3
|
+
*
|
|
4
|
+
* The CLI walks the workspace to build a repo skeleton and to feed the
|
|
5
|
+
* chokidar watcher. Both passes need a single source of truth for which
|
|
6
|
+
* paths are off-limits. `.pugiignore` extends (not replaces) `.gitignore`
|
|
7
|
+
* with Pugi-specific defaults: secret files, large binaries, build
|
|
8
|
+
* outputs, lockfiles.
|
|
9
|
+
*
|
|
10
|
+
* Design choices:
|
|
11
|
+
*
|
|
12
|
+
* 1. We layer four sources, last-write-wins per the .gitignore spec:
|
|
13
|
+
* (a) Built-in DEFAULT_IGNORE_PATTERNS - secret / binary / build
|
|
14
|
+
* paths every workspace should drop.
|
|
15
|
+
* (b) `~/.pugi/global.pugiignore` - operator-global overrides.
|
|
16
|
+
* (c) Repo `.gitignore` (when present) - so we don't re-walk
|
|
17
|
+
* node_modules / dist / etc.
|
|
18
|
+
* (d) Repo `.pugiignore` - workspace-local extensions.
|
|
19
|
+
*
|
|
20
|
+
* 2. The `ignore` npm package handles negation (`!path`) and nested
|
|
21
|
+
* directories correctly. Rolling a minimal glob matcher is doable
|
|
22
|
+
* but the test surface for gitignore semantics (esp. negation +
|
|
23
|
+
* ancestor matching) is wide enough that pulling the audited
|
|
24
|
+
* library is the safer call. It is already in the workspace via
|
|
25
|
+
* transitive deps; we add it as an explicit pugi-cli dep.
|
|
26
|
+
*
|
|
27
|
+
* 3. Privacy is defense-in-depth: even if the operator deletes the
|
|
28
|
+
* built-in defaults from their `.pugiignore`, we re-add the
|
|
29
|
+
* secret patterns at the END of the chain so a typo in user
|
|
30
|
+
* config cannot expose `.env` / `*.pem` / `*.key`. The user can
|
|
31
|
+
* explicitly negate (`!.env.example`) but cannot wipe the
|
|
32
|
+
* defense.
|
|
33
|
+
*
|
|
34
|
+
* 4. Paths are normalised to forward slashes (the `ignore` package
|
|
35
|
+
* requires POSIX-style separators even on Windows) and stripped
|
|
36
|
+
* of any leading workspace root so `isIgnored` answers in
|
|
37
|
+
* repo-relative terms.
|
|
38
|
+
*
|
|
39
|
+
* The API surface is minimal: `loadPugiIgnore(cwd)` returns a
|
|
40
|
+
* `PugiIgnore` matcher with `isIgnored(absPath): boolean`. The matcher
|
|
41
|
+
* is built once at session bootstrap and reused by the skeleton walker
|
|
42
|
+
* and the chokidar watcher.
|
|
43
|
+
*/
|
|
44
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
45
|
+
import { homedir } from 'node:os';
|
|
46
|
+
import { relative, resolve, sep } from 'node:path';
|
|
47
|
+
// The `ignore` package ships as CommonJS with `module.exports = factory`
|
|
48
|
+
// plus a `.d.ts` that re-exports the factory as default. Under
|
|
49
|
+
// `module: nodenext` TypeScript treats CJS default imports as the
|
|
50
|
+
// `module.exports` shape, which for `ignore` IS the callable factory -
|
|
51
|
+
// but only when we use the namespace-default dance below. A bare
|
|
52
|
+
// `import ignore from 'ignore'` fails with "expression is not callable"
|
|
53
|
+
// because TS resolves the import to the `typeof` shape rather than the
|
|
54
|
+
// callable value.
|
|
55
|
+
import * as ignoreModule from 'ignore';
|
|
56
|
+
const ignoreFactory = ignoreModule.default
|
|
57
|
+
?? ignoreModule;
|
|
58
|
+
/**
|
|
59
|
+
* Built-in patterns shipped with every Pugi workspace. The list is a
|
|
60
|
+
* conservative union of three categories:
|
|
61
|
+
*
|
|
62
|
+
* - **Secrets** (defense in depth): `.env*`, `*.pem`, `*.key`,
|
|
63
|
+
* `secrets/**`, `.netrc`, `id_rsa*`, `*.secret`, `credentials*`.
|
|
64
|
+
* These are re-applied at the END of the chain so user config
|
|
65
|
+
* cannot accidentally expose them.
|
|
66
|
+
*
|
|
67
|
+
* - **Build outputs / caches**: `node_modules/`, `dist/`, `build/`,
|
|
68
|
+
* `.next/`, `.nuxt/`, `.svelte-kit/`, `coverage/`, `.nx/`, `.cache/`,
|
|
69
|
+
* `.turbo/`, `.parcel-cache/`, `out/`, `.output/`, `*.tsbuildinfo`.
|
|
70
|
+
*
|
|
71
|
+
* - **Large binaries / data**: lockfiles (`*.lock`, `*-lock.json`,
|
|
72
|
+
* `*-lock.yaml`), images (`*.png`, `*.jpg`, `*.jpeg`, `*.gif`,
|
|
73
|
+
* `*.ico`), PDFs, videos, archives (`*.zip`, `*.tar`, `*.gz`),
|
|
74
|
+
* DB dumps (`*.sql`, `*.dump`), logs.
|
|
75
|
+
*
|
|
76
|
+
* The split between baseline patterns (applied first) and secret
|
|
77
|
+
* patterns (applied last) matters: a user `.pugiignore` can `!`-negate
|
|
78
|
+
* baseline entries (e.g. unignore a particular generated file under
|
|
79
|
+
* `dist/`) but cannot reach the trailing secret block. The trailing
|
|
80
|
+
* block is exported as `SECRET_IGNORE_PATTERNS` for tests.
|
|
81
|
+
*/
|
|
82
|
+
export const BASELINE_IGNORE_PATTERNS = Object.freeze([
|
|
83
|
+
// VCS / Pugi state
|
|
84
|
+
'.git/',
|
|
85
|
+
'.pugi/',
|
|
86
|
+
'.hg/',
|
|
87
|
+
'.svn/',
|
|
88
|
+
// Build outputs / package manager caches
|
|
89
|
+
'node_modules/',
|
|
90
|
+
'.pnpm-store/',
|
|
91
|
+
'dist/',
|
|
92
|
+
'build/',
|
|
93
|
+
'out/',
|
|
94
|
+
'.output/',
|
|
95
|
+
'.next/',
|
|
96
|
+
'.nuxt/',
|
|
97
|
+
'.svelte-kit/',
|
|
98
|
+
'.astro/',
|
|
99
|
+
'coverage/',
|
|
100
|
+
'.nyc_output/',
|
|
101
|
+
'.nx/',
|
|
102
|
+
'.turbo/',
|
|
103
|
+
'.parcel-cache/',
|
|
104
|
+
'.cache/',
|
|
105
|
+
'.vercel/',
|
|
106
|
+
'.netlify/',
|
|
107
|
+
'*.tsbuildinfo',
|
|
108
|
+
// Lockfiles - rebuilds, never agent-relevant
|
|
109
|
+
'*.lock',
|
|
110
|
+
'package-lock.json',
|
|
111
|
+
'yarn.lock',
|
|
112
|
+
'pnpm-lock.yaml',
|
|
113
|
+
'bun.lockb',
|
|
114
|
+
'composer.lock',
|
|
115
|
+
'poetry.lock',
|
|
116
|
+
'Cargo.lock',
|
|
117
|
+
'Gemfile.lock',
|
|
118
|
+
// Logs
|
|
119
|
+
'*.log',
|
|
120
|
+
'logs/',
|
|
121
|
+
'.pm2/',
|
|
122
|
+
// Large binaries
|
|
123
|
+
'*.png',
|
|
124
|
+
'*.jpg',
|
|
125
|
+
'*.jpeg',
|
|
126
|
+
'*.gif',
|
|
127
|
+
'*.ico',
|
|
128
|
+
'*.webp',
|
|
129
|
+
'*.bmp',
|
|
130
|
+
'*.tiff',
|
|
131
|
+
'*.svg',
|
|
132
|
+
'*.pdf',
|
|
133
|
+
'*.mp3',
|
|
134
|
+
'*.mp4',
|
|
135
|
+
'*.mov',
|
|
136
|
+
'*.webm',
|
|
137
|
+
'*.zip',
|
|
138
|
+
'*.tar',
|
|
139
|
+
'*.tar.gz',
|
|
140
|
+
'*.tgz',
|
|
141
|
+
'*.gz',
|
|
142
|
+
'*.bz2',
|
|
143
|
+
'*.7z',
|
|
144
|
+
'*.rar',
|
|
145
|
+
'*.dmg',
|
|
146
|
+
'*.iso',
|
|
147
|
+
// DB dumps / fixtures
|
|
148
|
+
'*.sql',
|
|
149
|
+
'*.dump',
|
|
150
|
+
'*.sqlite',
|
|
151
|
+
'*.sqlite3',
|
|
152
|
+
'*.db',
|
|
153
|
+
// OS noise
|
|
154
|
+
'.DS_Store',
|
|
155
|
+
'Thumbs.db',
|
|
156
|
+
]);
|
|
157
|
+
/**
|
|
158
|
+
* Secret patterns re-applied at the END of every layered chain. Even
|
|
159
|
+
* if the operator deletes these from `.pugiignore` (or accidentally
|
|
160
|
+
* negates them with `!.env`), the trailing block restores the gate.
|
|
161
|
+
* This is defense-in-depth: the skeleton walker MUST NOT read
|
|
162
|
+
* credentials into the agent context, period.
|
|
163
|
+
*/
|
|
164
|
+
export const SECRET_IGNORE_PATTERNS = Object.freeze([
|
|
165
|
+
'.env',
|
|
166
|
+
'.env.*',
|
|
167
|
+
'*.pem',
|
|
168
|
+
'*.key',
|
|
169
|
+
'*.crt',
|
|
170
|
+
'*.cert',
|
|
171
|
+
// X.509 cert formats - `*.cer` is the PEM-style cert extension common
|
|
172
|
+
// on Windows / Java keystores, `*.der` is the binary DER-encoded form
|
|
173
|
+
// used by Java + .NET tooling. Both can carry private keys when
|
|
174
|
+
// bundled (PKCS#7 / PKCS#12) and the file extension alone does not
|
|
175
|
+
// tell us whether the bundle includes a key. Treat as secrets by
|
|
176
|
+
// default. triple-review P1 (PR #380).
|
|
177
|
+
'*.cer',
|
|
178
|
+
'*.der',
|
|
179
|
+
'*.p12',
|
|
180
|
+
'*.pfx',
|
|
181
|
+
'*.jks',
|
|
182
|
+
'*.keystore',
|
|
183
|
+
'secrets/**',
|
|
184
|
+
'.netrc',
|
|
185
|
+
'id_rsa',
|
|
186
|
+
'id_rsa.*',
|
|
187
|
+
'id_ed25519',
|
|
188
|
+
'id_ed25519.*',
|
|
189
|
+
'*.secret',
|
|
190
|
+
'credentials',
|
|
191
|
+
'credentials.json',
|
|
192
|
+
'service-account*.json',
|
|
193
|
+
'*.kdbx',
|
|
194
|
+
'.aws/',
|
|
195
|
+
'.ssh/',
|
|
196
|
+
'.gnupg/',
|
|
197
|
+
]);
|
|
198
|
+
/**
|
|
199
|
+
* Where the operator's global ignore file lives. Mirrors the
|
|
200
|
+
* `~/.gitignore_global` convention. We do NOT auto-create it; if it
|
|
201
|
+
* exists, we load its non-empty / non-comment lines.
|
|
202
|
+
*/
|
|
203
|
+
export function globalPugiIgnorePath(home = homedir()) {
|
|
204
|
+
return resolve(home, '.pugi', 'global.pugiignore');
|
|
205
|
+
}
|
|
206
|
+
/** Path to the workspace `.pugiignore`. */
|
|
207
|
+
export function workspacePugiIgnorePath(cwd) {
|
|
208
|
+
return resolve(cwd, '.pugiignore');
|
|
209
|
+
}
|
|
210
|
+
/** Path to the workspace `.gitignore`. */
|
|
211
|
+
export function workspaceGitIgnorePath(cwd) {
|
|
212
|
+
return resolve(cwd, '.gitignore');
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Load and compile the layered ignore matcher for `cwd`. The chain
|
|
216
|
+
* is built in this exact order so later layers override earlier ones,
|
|
217
|
+
* with the trailing secret block as the inviolable backstop:
|
|
218
|
+
*
|
|
219
|
+
* 1. BASELINE_IGNORE_PATTERNS (built-in defaults)
|
|
220
|
+
* 2. ~/.pugi/global.pugiignore (operator global, optional)
|
|
221
|
+
* 3. <cwd>/.gitignore (workspace, optional)
|
|
222
|
+
* 4. <cwd>/.pugiignore (workspace, optional)
|
|
223
|
+
* 5. SECRET_IGNORE_PATTERNS (defense-in-depth backstop)
|
|
224
|
+
*
|
|
225
|
+
* Any FS error reading optional files is swallowed - workspace
|
|
226
|
+
* context is best-effort and must never block the REPL bootstrap.
|
|
227
|
+
*/
|
|
228
|
+
export function loadPugiIgnore(cwd, options = {}) {
|
|
229
|
+
const home = options.home ?? homedir();
|
|
230
|
+
const normalisedCwd = resolve(cwd);
|
|
231
|
+
const patterns = [];
|
|
232
|
+
patterns.push(...BASELINE_IGNORE_PATTERNS);
|
|
233
|
+
const globalPath = globalPugiIgnorePath(home);
|
|
234
|
+
const globalPatterns = readPatternFile(globalPath);
|
|
235
|
+
patterns.push(...globalPatterns);
|
|
236
|
+
const gitignorePath = workspaceGitIgnorePath(normalisedCwd);
|
|
237
|
+
const gitPatterns = readPatternFile(gitignorePath);
|
|
238
|
+
patterns.push(...gitPatterns);
|
|
239
|
+
const pugiIgnorePath = workspacePugiIgnorePath(normalisedCwd);
|
|
240
|
+
const pugiPatterns = readPatternFile(pugiIgnorePath);
|
|
241
|
+
patterns.push(...pugiPatterns);
|
|
242
|
+
// Secrets last so they cannot be silently negated by user config.
|
|
243
|
+
patterns.push(...SECRET_IGNORE_PATTERNS);
|
|
244
|
+
const matcher = ignoreFactory().add(patterns);
|
|
245
|
+
return {
|
|
246
|
+
cwd: normalisedCwd,
|
|
247
|
+
patterns: Object.freeze(patterns.slice()),
|
|
248
|
+
isIgnored(absPath, isDir) {
|
|
249
|
+
return isIgnoredImpl(matcher, normalisedCwd, absPath, isDir === true);
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Read a `.gitignore`-shaped file and return the non-comment / non-empty
|
|
255
|
+
* lines. Returns `[]` on any FS error. Lines are returned verbatim - the
|
|
256
|
+
* `ignore` library parses leading `!`, trailing `/`, and `**` correctly
|
|
257
|
+
* on its own.
|
|
258
|
+
*/
|
|
259
|
+
export function readPatternFile(path) {
|
|
260
|
+
try {
|
|
261
|
+
if (!existsSync(path))
|
|
262
|
+
return [];
|
|
263
|
+
const raw = readFileSync(path, 'utf8');
|
|
264
|
+
return parsePatternText(raw);
|
|
265
|
+
}
|
|
266
|
+
catch {
|
|
267
|
+
return [];
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Pure parser for a `.gitignore`-shaped string. Splits on newlines,
|
|
272
|
+
* strips comment lines (`#`), trims whitespace, drops empty lines.
|
|
273
|
+
* Exported for the test suite so the chain is exercisable without a
|
|
274
|
+
* real filesystem.
|
|
275
|
+
*/
|
|
276
|
+
export function parsePatternText(raw) {
|
|
277
|
+
const lines = raw.split(/\r?\n/);
|
|
278
|
+
const out = [];
|
|
279
|
+
for (const line of lines) {
|
|
280
|
+
const trimmed = line.trim();
|
|
281
|
+
if (trimmed.length === 0)
|
|
282
|
+
continue;
|
|
283
|
+
if (trimmed.startsWith('#'))
|
|
284
|
+
continue;
|
|
285
|
+
out.push(trimmed);
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Normalise an absolute path to a repo-relative POSIX path, then run
|
|
291
|
+
* it through the `ignore` matcher. Inputs outside the workspace return
|
|
292
|
+
* `false` - the matcher has no opinion about paths above its root.
|
|
293
|
+
*/
|
|
294
|
+
function isIgnoredImpl(matcher, cwd, absPath, isDir) {
|
|
295
|
+
const normalisedAbs = resolve(absPath);
|
|
296
|
+
if (normalisedAbs === cwd)
|
|
297
|
+
return false;
|
|
298
|
+
const rel = relative(cwd, normalisedAbs);
|
|
299
|
+
// Paths above the workspace root come back as `..` or `../foo`.
|
|
300
|
+
// The matcher has no opinion about those; treat as not-ignored.
|
|
301
|
+
if (rel.length === 0)
|
|
302
|
+
return false;
|
|
303
|
+
if (rel.startsWith('..'))
|
|
304
|
+
return false;
|
|
305
|
+
// `ignore` requires POSIX-style separators on every platform.
|
|
306
|
+
const posixRel = sep === '/' ? rel : rel.split(sep).join('/');
|
|
307
|
+
// Append a trailing slash for directories so gitignore-style
|
|
308
|
+
// dir patterns (`node_modules/`, `dist/`) match the dir itself,
|
|
309
|
+
// not just its children. Without this, `isIgnored('/abs/node_modules', true)`
|
|
310
|
+
// would return false because `ignore` only matches the child path
|
|
311
|
+
// shape for those patterns. See the spec for the failing case
|
|
312
|
+
// (skeleton walker descending into node_modules/).
|
|
313
|
+
const queryPath = isDir ? `${posixRel}/` : posixRel;
|
|
314
|
+
return matcher.ignores(queryPath);
|
|
315
|
+
}
|
|
316
|
+
//# sourceMappingURL=pugiignore.js.map
|