@pugi/cli 0.1.0-beta.1 → 0.1.0-beta.11
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/THIRD_PARTY_NOTICES.md +40 -0
- package/assets/pugi-mascot.ansi +15 -40
- package/dist/core/edits/worktree.js +322 -0
- package/dist/core/engine/anvil-client.js +16 -0
- package/dist/core/engine/budgets.js +89 -0
- package/dist/core/engine/native-pugi.js +112 -12
- package/dist/core/engine/prompts.js +8 -0
- package/dist/core/engine/tool-bridge.js +267 -8
- package/dist/core/init/scaffold.js +195 -0
- package/dist/core/lsp/client.js +719 -0
- package/dist/core/repl/codebase-survey.js +308 -0
- package/dist/core/repl/init-interview.js +457 -0
- package/dist/core/repl/onboarding-state.js +297 -0
- package/dist/core/repl/session.js +72 -1
- package/dist/core/repl/slash-commands.js +41 -0
- package/dist/core/settings.js +28 -0
- package/dist/core/skills/defaults.js +457 -0
- package/dist/runtime/cli.js +366 -14
- package/dist/runtime/commands/delegate.js +289 -0
- package/dist/runtime/commands/lsp.js +206 -0
- package/dist/runtime/commands/patch.js +128 -0
- package/dist/runtime/commands/roster.js +117 -0
- package/dist/runtime/commands/worktree.js +177 -0
- package/dist/runtime/plan-decompose.js +531 -0
- package/dist/tools/apply-patch.js +495 -0
- package/dist/tools/ask-user.js +115 -0
- package/dist/tools/lsp-tools.js +189 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/skill-tool.js +96 -0
- package/dist/tools/tasks.js +208 -0
- package/dist/tui/ask-modal.js +2 -2
- package/dist/tui/conversation-pane.js +1 -1
- package/dist/tui/input-box.js +1 -1
- package/dist/tui/markdown-render.js +4 -4
- package/dist/tui/repl-render.js +169 -10
- package/dist/tui/repl-splash.js +2 -2
- package/dist/tui/repl.js +18 -5
- package/dist/tui/splash.js +1 -1
- package/dist/tui/update-banner.js +1 -1
- package/docs/examples/codegraph.mcp.json +10 -0
- package/package.json +6 -4
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace scaffold — extracted from `pugi init` so the bare REPL boot
|
|
3
|
+
* can call it automatically when the operator launches `pugi` in a
|
|
4
|
+
* fresh directory (CEO directive 2026-05-26).
|
|
5
|
+
*
|
|
6
|
+
* Before this module, `pugi init` was the only path that materialised
|
|
7
|
+
* `.pugi/` + the canonical config files. Launching the REPL in an empty
|
|
8
|
+
* directory printed `workspace: (not bound - run /init OR cd into
|
|
9
|
+
* project)` and instructed the operator to Ctrl+C, run `pugi init`,
|
|
10
|
+
* relaunch. That round trip is hostile on a first-touch install — CEO
|
|
11
|
+
* escalated "auto = решение" on 2026-05-26.
|
|
12
|
+
*
|
|
13
|
+
* The module is intentionally side-effect free at import time: the
|
|
14
|
+
* scaffold runs only when `ensureWorkspaceInitialized` is called. The
|
|
15
|
+
* scaffold is also idempotent — every file write is gated by an
|
|
16
|
+
* `existsSync` check, so re-running against a workspace that already has
|
|
17
|
+
* `.pugi/settings.json` (e.g. a manual `pugi init` followed by auto-init
|
|
18
|
+
* on next REPL launch) is a no-op. The function is safe to call before
|
|
19
|
+
* any other init logic.
|
|
20
|
+
*
|
|
21
|
+
* Two CRITICAL invariants:
|
|
22
|
+
*
|
|
23
|
+
* 1. **Atomic per-file.** Every write uses `existsSync` + `writeFileSync`
|
|
24
|
+
* against the final path. There is no read-modify-write pattern that
|
|
25
|
+
* could lose data on a concurrent `pugi init` race. The one path
|
|
26
|
+
* that DOES mutate an existing file — `.gitignore` (append `.pugi/`
|
|
27
|
+
* marker) — also gates on the marker being absent before appending,
|
|
28
|
+
* so the worst-case race is a duplicate marker line that the next
|
|
29
|
+
* run skips.
|
|
30
|
+
*
|
|
31
|
+
* 2. **Silent by default.** When `opts.silent` is true (the REPL
|
|
32
|
+
* auto-init path) the scaffold writes NOTHING to stderr/stdout.
|
|
33
|
+
* The REPL bootstrap runs before Ink mounts, and a stray
|
|
34
|
+
* stdout/stderr write at that point would land on the operator's
|
|
35
|
+
* shell ABOVE the alt-screen entry — visible until they scroll up,
|
|
36
|
+
* and noisy in a CI tail. The explicit `pugi init` path stays
|
|
37
|
+
* verbose via the standalone command in `runtime/cli.ts`.
|
|
38
|
+
*/
|
|
39
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
40
|
+
import { resolve } from 'node:path';
|
|
41
|
+
import { emptyIndex } from '../index-store.js';
|
|
42
|
+
/**
|
|
43
|
+
* Materialise the canonical `.pugi/` workspace scaffold under `cwd`.
|
|
44
|
+
* Returns a `{created, dir, createdPaths, skippedPaths}` summary so the
|
|
45
|
+
* caller can log a one-shot "initialized" line on the first call without
|
|
46
|
+
* re-checking the filesystem.
|
|
47
|
+
*
|
|
48
|
+
* The scaffold mirrors `pugi init` minus the bundled default-skills
|
|
49
|
+
* install (that is a heavier operation gated on the `--no-defaults`
|
|
50
|
+
* flag, and the standalone `pugi init` command keeps owning it).
|
|
51
|
+
*
|
|
52
|
+
* Idempotent: every file write gates on `existsSync`, so re-running
|
|
53
|
+
* against an existing workspace is a no-op and returns
|
|
54
|
+
* `{created: false}` with every path in `skippedPaths`.
|
|
55
|
+
*/
|
|
56
|
+
export function ensureWorkspaceInitialized(cwd, opts = {}) {
|
|
57
|
+
const silent = opts.silent !== false;
|
|
58
|
+
const pugiDir = resolve(cwd, '.pugi');
|
|
59
|
+
// Local trackers so the existing helpers (mkdirIfMissing /
|
|
60
|
+
// writeJsonIfMissing / writeTextIfMissing) keep their (created, skipped)
|
|
61
|
+
// signature. The explicit `pugi init` command forwards these straight
|
|
62
|
+
// into its JSON payload.
|
|
63
|
+
const created = [];
|
|
64
|
+
const skipped = [];
|
|
65
|
+
mkdirIfMissing(pugiDir, created, skipped);
|
|
66
|
+
mkdirIfMissing(resolve(pugiDir, 'artifacts'), created, skipped);
|
|
67
|
+
mkdirIfMissing(resolve(pugiDir, 'sessions'), created, skipped);
|
|
68
|
+
mkdirIfMissing(resolve(pugiDir, 'skills'), created, skipped);
|
|
69
|
+
writeJsonIfMissing(resolve(pugiDir, 'settings.json'), {
|
|
70
|
+
schema: 1,
|
|
71
|
+
workflow: {
|
|
72
|
+
brand: 'pugi',
|
|
73
|
+
legacyName: 'codeforge',
|
|
74
|
+
approvals: 'auto',
|
|
75
|
+
notAutomatic: [],
|
|
76
|
+
defaultBaseBranch: 'dev',
|
|
77
|
+
branchPrefixes: ['feature', 'fix', 'refactor', 'chore'],
|
|
78
|
+
aiCoAuthorTrailers: false,
|
|
79
|
+
},
|
|
80
|
+
permissions: {
|
|
81
|
+
mode: 'auto',
|
|
82
|
+
allow: [],
|
|
83
|
+
deny: [],
|
|
84
|
+
notAutomatic: [],
|
|
85
|
+
},
|
|
86
|
+
privacy: {
|
|
87
|
+
mode: 'balanced',
|
|
88
|
+
telemetry: 'off',
|
|
89
|
+
},
|
|
90
|
+
artifacts: {
|
|
91
|
+
defaultPath: '.pugi/artifacts',
|
|
92
|
+
promoteExplicitly: true,
|
|
93
|
+
},
|
|
94
|
+
}, created, skipped);
|
|
95
|
+
writeJsonIfMissing(resolve(pugiDir, 'mcp.json'), { schema: 1, servers: [] }, created, skipped);
|
|
96
|
+
writeJsonIfMissing(resolve(pugiDir, 'index.json'), emptyIndex(), created, skipped);
|
|
97
|
+
writeTextIfMissing(resolve(pugiDir, 'PUGI.md'), [
|
|
98
|
+
'# Pugi Project Context',
|
|
99
|
+
'',
|
|
100
|
+
'## Product Workflow',
|
|
101
|
+
'',
|
|
102
|
+
'- Public product name: Pugi',
|
|
103
|
+
'- Default flow: idea -> build -> review',
|
|
104
|
+
'- Approvals are automatic by default until a repo, environment, workflow, or action is marked notAutomatic.',
|
|
105
|
+
'- Do not add AI Co-Authored-By trailers.',
|
|
106
|
+
'- Generated code, comments, commits, PR text, and technical docs default to English.',
|
|
107
|
+
'',
|
|
108
|
+
'## Project Notes',
|
|
109
|
+
'',
|
|
110
|
+
'- Add repo-specific architecture, commands, and business rules here.',
|
|
111
|
+
'- Do not store secrets, real IPs, private key paths, tokens, or credentials here.',
|
|
112
|
+
'',
|
|
113
|
+
].join('\n'), created, skipped);
|
|
114
|
+
writeTextIfMissing(resolve(cwd, '.pugiignore'), [
|
|
115
|
+
'# Pugi ignore rules',
|
|
116
|
+
'.env',
|
|
117
|
+
'.env.*',
|
|
118
|
+
'!.env.example',
|
|
119
|
+
'node_modules/',
|
|
120
|
+
'dist/',
|
|
121
|
+
'.next/',
|
|
122
|
+
'coverage/',
|
|
123
|
+
'*.log',
|
|
124
|
+
'*.pem',
|
|
125
|
+
'*.key',
|
|
126
|
+
'*.crt',
|
|
127
|
+
'*.p12',
|
|
128
|
+
'*.sql',
|
|
129
|
+
'*.dump',
|
|
130
|
+
'',
|
|
131
|
+
].join('\n'), created, skipped);
|
|
132
|
+
ensurePugiGitIgnore(cwd, created, skipped);
|
|
133
|
+
// `silent` is honoured implicitly — this module never writes to
|
|
134
|
+
// stdout/stderr. The flag exists so the standalone `pugi init` command
|
|
135
|
+
// can layer its own logger on top (it does, in runtime/cli.ts), while
|
|
136
|
+
// the auto-init REPL path leaves the boot stream untouched. We
|
|
137
|
+
// reference the flag here to defeat the lint "unused" warning and to
|
|
138
|
+
// document the contract in the source.
|
|
139
|
+
void silent;
|
|
140
|
+
return {
|
|
141
|
+
created: created.length > 0,
|
|
142
|
+
dir: pugiDir,
|
|
143
|
+
createdPaths: created,
|
|
144
|
+
skippedPaths: skipped,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/* ------------------------------------------------------------------ */
|
|
148
|
+
/* Helpers (mirror the previous in-file implementations in cli.ts) */
|
|
149
|
+
/* ------------------------------------------------------------------ */
|
|
150
|
+
function mkdirIfMissing(path, created, skipped) {
|
|
151
|
+
if (existsSync(path)) {
|
|
152
|
+
skipped.push(path);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
mkdirSync(path, { recursive: true });
|
|
156
|
+
created.push(path);
|
|
157
|
+
}
|
|
158
|
+
function writeJsonIfMissing(path, value, created, skipped) {
|
|
159
|
+
writeTextIfMissing(path, `${JSON.stringify(value, null, 2)}\n`, created, skipped);
|
|
160
|
+
}
|
|
161
|
+
function writeTextIfMissing(path, value, created, skipped) {
|
|
162
|
+
if (existsSync(path)) {
|
|
163
|
+
skipped.push(path);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
writeFileSync(path, value, { encoding: 'utf8', mode: 0o600 });
|
|
167
|
+
created.push(path);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Ensure the workspace `.gitignore` ignores `.pugi/`. The function is
|
|
171
|
+
* additive: it leaves an existing `.gitignore` body intact and appends
|
|
172
|
+
* the marker only when none of `.pugi/`, `/.pugi/`, or `.pugi` is
|
|
173
|
+
* already present. On a fresh repo with no `.gitignore` it creates the
|
|
174
|
+
* file with the single marker line. Mode 0o600 matches the rest of the
|
|
175
|
+
* scaffold so a paranoid CI does not surface "world-readable" warnings.
|
|
176
|
+
*/
|
|
177
|
+
function ensurePugiGitIgnore(cwd, created, skipped) {
|
|
178
|
+
const gitignorePath = resolve(cwd, '.gitignore');
|
|
179
|
+
const marker = '.pugi/';
|
|
180
|
+
if (!existsSync(gitignorePath)) {
|
|
181
|
+
writeFileSync(gitignorePath, `${marker}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
182
|
+
created.push(gitignorePath);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const current = readFileSync(gitignorePath, 'utf8');
|
|
186
|
+
const lines = current.split('\n').map((line) => line.trim());
|
|
187
|
+
if (lines.includes(marker) || lines.includes('/.pugi/') || lines.includes('.pugi')) {
|
|
188
|
+
skipped.push(gitignorePath);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
const next = current.endsWith('\n') ? `${current}${marker}\n` : `${current}\n${marker}\n`;
|
|
192
|
+
writeFileSync(gitignorePath, next, { encoding: 'utf8' });
|
|
193
|
+
created.push(`${gitignorePath} (+${marker})`);
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=scaffold.js.map
|