@pugi/cli 0.1.0-beta.22 → 0.1.0-beta.23
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/core/auth/env-provider.js +238 -0
- package/dist/core/diagnostics/probes/pugi-md.js +89 -0
- package/dist/core/engine/native-pugi.js +34 -1
- package/dist/core/pugi-md/context-injector.js +76 -0
- package/dist/core/pugi-md/walk-up.js +207 -0
- package/dist/core/release-notes/parser.js +241 -0
- package/dist/core/release-notes/state.js +116 -0
- package/dist/core/repl/session.js +107 -0
- package/dist/core/repl/slash-commands.js +35 -0
- package/dist/core/theme/context.js +91 -0
- package/dist/core/theme/presets.js +228 -0
- package/dist/core/theme/state.js +181 -0
- package/dist/core/vim/keymap.js +288 -0
- package/dist/core/vim/state.js +92 -0
- package/dist/runtime/cli.js +217 -14
- package/dist/runtime/commands/doctor.js +13 -0
- package/dist/runtime/commands/release-notes.js +229 -0
- package/dist/runtime/commands/theme.js +196 -0
- package/dist/runtime/commands/vim.js +140 -0
- package/dist/runtime/version.js +1 -1
- package/dist/tui/doctor-table.js +32 -17
- package/dist/tui/repl-render.js +17 -2
- package/dist/tui/repl.js +9 -1
- package/dist/tui/style-table.js +9 -3
- package/dist/tui/theme-table.js +29 -0
- package/dist/tui/vim-input.js +267 -0
- package/package.json +2 -2
- package/dist/core/engine/compaction-hook.js +0 -154
- package/dist/core/init/scaffold.js +0 -195
- package/dist/core/repl/codebase-survey.js +0 -308
- package/dist/core/repl/init-interview.js +0 -457
- package/dist/core/repl/onboarding-state.js +0 -297
|
@@ -1,195 +0,0 @@
|
|
|
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
|
|
@@ -1,308 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codebase survey for the `/init` interview - Phase 2.
|
|
3
|
-
*
|
|
4
|
-
* Inspired by Claude Code's /init Phase 2 (the upstream spawns a
|
|
5
|
-
* Task-tool subagent to read manifest files + CI config + existing
|
|
6
|
-
* agent rules and produce a structured "what this repo is" digest).
|
|
7
|
-
* Independent implementation: Pugi's subagent infra is admin-api
|
|
8
|
-
* scheduled and not available in the local REPL boot path, so the
|
|
9
|
-
* survey runs as a direct filesystem scan instead. The shape of the
|
|
10
|
-
* output matches the upstream pattern - manifest, languages, build /
|
|
11
|
-
* test / lint commands, existing AI-tool configs - so the downstream
|
|
12
|
-
* Phase 3 / Phase 4 logic stays portable.
|
|
13
|
-
*
|
|
14
|
-
* # Design notes
|
|
15
|
-
*
|
|
16
|
-
* - Pure fs reads. No spawn, no network, no LLM call. Safe to run on
|
|
17
|
-
* every `/init` invocation without rate-limit concern.
|
|
18
|
-
* - Bounded: every read caps at 16 KB to defend against an enormous
|
|
19
|
-
* manifest pinning memory. Real package.json / pyproject.toml are
|
|
20
|
-
* well under that.
|
|
21
|
-
* - Defensive: a missing or unreadable file maps to `undefined` in the
|
|
22
|
-
* returned record. Phase 3 treats unknowns as "ask the operator".
|
|
23
|
-
* - Manifest grammar is closed: package.json (Node) and pyproject.toml
|
|
24
|
-
* (Python) are recognised explicitly because Pugi customers ship one
|
|
25
|
-
* of those nine times out of ten. Cargo.toml / go.mod / pom.xml are
|
|
26
|
-
* detected by filename only - we surface "rust"/"go"/"java" as the
|
|
27
|
-
* language hint but do not parse them, because the Phase 3 question
|
|
28
|
-
* set asks for build commands directly when the manifest is opaque.
|
|
29
|
-
*
|
|
30
|
-
* # What we collect
|
|
31
|
-
*
|
|
32
|
-
* 1. `manifest`: which manifest file was found (closed enum).
|
|
33
|
-
* 2. `languages`: deduped list inferred from manifest + file extension
|
|
34
|
-
* heuristics under the workspace root (one-level deep scan).
|
|
35
|
-
* 3. `packageManager`: pnpm / npm / yarn (Node only) or `unknown`.
|
|
36
|
-
* 4. `buildCommand` / `testCommand` / `lintCommand`: parsed out of
|
|
37
|
-
* `package.json` scripts when a Node manifest is present.
|
|
38
|
-
* 5. `aiToolConfigs`: a record of which sibling-agent config files
|
|
39
|
-
* already exist (CLAUDE.md, AGENTS.md, .cursorrules,
|
|
40
|
-
* .github/copilot-instructions.md, .windsurfrules, .clinerules,
|
|
41
|
-
* .mcp.json). Phase 4 mines these for "important parts" without
|
|
42
|
-
* duplicating them into PUGI.md.
|
|
43
|
-
* 6. `hasReadme`, `hasGit`, `hasCi`: simple booleans for the
|
|
44
|
-
* gap-question logic.
|
|
45
|
-
* 7. `hasExistingPugiMd`: true when re-running `/init` against a
|
|
46
|
-
* workspace that already produced PUGI.md.
|
|
47
|
-
*
|
|
48
|
-
* # Why not spawn a Pugi subagent
|
|
49
|
-
*
|
|
50
|
-
* The Pugi subagent dispatcher (apps/pugi-cli/src/core/subagents/)
|
|
51
|
-
* speaks to admin-api over the SSE transport. Running the codebase
|
|
52
|
-
* survey through that path would (a) burn a tenant token quota on
|
|
53
|
-
* every `/init`, (b) require an online connection, and (c) round-trip
|
|
54
|
-
* structured data through the persona prompt - which is the wrong
|
|
55
|
-
* tool for "list which files exist". A direct fs scan is faster,
|
|
56
|
-
* deterministic, and works offline. The upstream Task-tool decision
|
|
57
|
-
* makes sense in a hosted product where every operation is metered;
|
|
58
|
-
* Pugi runs locally so we keep the survey local too.
|
|
59
|
-
*/
|
|
60
|
-
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
61
|
-
import { join } from 'node:path';
|
|
62
|
-
/**
|
|
63
|
-
* Maximum bytes the survey reads from any single file. Real manifests
|
|
64
|
-
* are tiny (<8 KB); this cap defends against a hostile or accidental
|
|
65
|
-
* gigabyte JSON pinning the REPL boot.
|
|
66
|
-
*/
|
|
67
|
-
const MAX_READ_BYTES = 16 * 1024;
|
|
68
|
-
/**
|
|
69
|
-
* Top-level directory scan budget. The survey looks at the workspace
|
|
70
|
-
* root + at most this many entries when inferring languages from file
|
|
71
|
-
* extensions. Deep walks are not needed - the manifest is the source
|
|
72
|
-
* of truth for the active stack.
|
|
73
|
-
*/
|
|
74
|
-
const MAX_TOP_LEVEL_ENTRIES = 200;
|
|
75
|
-
/**
|
|
76
|
-
* Run a codebase survey against `workspaceRoot`. Pure: returns a
|
|
77
|
-
* snapshot record; the caller decides how to render it.
|
|
78
|
-
*/
|
|
79
|
-
export function surveyCodebase(workspaceRoot) {
|
|
80
|
-
const errors = [];
|
|
81
|
-
const manifest = detectManifest(workspaceRoot);
|
|
82
|
-
const packageJson = manifest === 'package.json'
|
|
83
|
-
? safeReadJson(join(workspaceRoot, 'package.json'), errors)
|
|
84
|
-
: undefined;
|
|
85
|
-
const packageManager = inferPackageManager(workspaceRoot, packageJson);
|
|
86
|
-
const languages = inferLanguages(workspaceRoot, manifest, errors);
|
|
87
|
-
const scripts = (packageJson && typeof packageJson === 'object' && packageJson !== null
|
|
88
|
-
? packageJson.scripts
|
|
89
|
-
: undefined) ?? {};
|
|
90
|
-
const buildCommand = pickScript(scripts, ['build', 'compile']);
|
|
91
|
-
const testCommand = pickScript(scripts, ['test', 'tests']);
|
|
92
|
-
const lintCommand = pickScript(scripts, ['lint', 'check']);
|
|
93
|
-
const formatCommand = pickScript(scripts, ['format', 'fmt', 'prettier']);
|
|
94
|
-
const aiToolConfigs = scanAiToolConfigs(workspaceRoot);
|
|
95
|
-
return {
|
|
96
|
-
workspaceRoot,
|
|
97
|
-
manifest,
|
|
98
|
-
packageManager,
|
|
99
|
-
languages,
|
|
100
|
-
buildCommand,
|
|
101
|
-
testCommand,
|
|
102
|
-
lintCommand,
|
|
103
|
-
formatCommand,
|
|
104
|
-
aiToolConfigs,
|
|
105
|
-
hasReadme: existsSafe(join(workspaceRoot, 'README.md')) ||
|
|
106
|
-
existsSafe(join(workspaceRoot, 'readme.md')),
|
|
107
|
-
hasGit: existsSafe(join(workspaceRoot, '.git')),
|
|
108
|
-
hasCi: detectCi(workspaceRoot),
|
|
109
|
-
hasExistingPugiMd: aiToolConfigs['PUGI.md'],
|
|
110
|
-
readErrors: errors,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/* ------------------------------------------------------------------ */
|
|
114
|
-
/* Manifest detection */
|
|
115
|
-
/* ------------------------------------------------------------------ */
|
|
116
|
-
const MANIFEST_PROBE_ORDER = Object.freeze([
|
|
117
|
-
'package.json',
|
|
118
|
-
'pyproject.toml',
|
|
119
|
-
'Cargo.toml',
|
|
120
|
-
'go.mod',
|
|
121
|
-
'pom.xml',
|
|
122
|
-
'Gemfile',
|
|
123
|
-
'composer.json',
|
|
124
|
-
]);
|
|
125
|
-
function detectManifest(root) {
|
|
126
|
-
for (const candidate of MANIFEST_PROBE_ORDER) {
|
|
127
|
-
if (existsSafe(join(root, candidate)))
|
|
128
|
-
return candidate;
|
|
129
|
-
}
|
|
130
|
-
return 'unknown';
|
|
131
|
-
}
|
|
132
|
-
function inferPackageManager(root, packageJson) {
|
|
133
|
-
// package.json `packageManager` field wins when present (corepack convention).
|
|
134
|
-
if (packageJson &&
|
|
135
|
-
typeof packageJson === 'object' &&
|
|
136
|
-
packageJson !== null &&
|
|
137
|
-
'packageManager' in packageJson) {
|
|
138
|
-
const declared = packageJson.packageManager;
|
|
139
|
-
if (typeof declared === 'string') {
|
|
140
|
-
if (declared.startsWith('pnpm@'))
|
|
141
|
-
return 'pnpm';
|
|
142
|
-
if (declared.startsWith('yarn@'))
|
|
143
|
-
return 'yarn';
|
|
144
|
-
if (declared.startsWith('npm@'))
|
|
145
|
-
return 'npm';
|
|
146
|
-
if (declared.startsWith('bun@'))
|
|
147
|
-
return 'bun';
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
// Lockfile fallback.
|
|
151
|
-
if (existsSafe(join(root, 'pnpm-lock.yaml')))
|
|
152
|
-
return 'pnpm';
|
|
153
|
-
if (existsSafe(join(root, 'yarn.lock')))
|
|
154
|
-
return 'yarn';
|
|
155
|
-
if (existsSafe(join(root, 'bun.lockb')) || existsSafe(join(root, 'bun.lock')))
|
|
156
|
-
return 'bun';
|
|
157
|
-
if (existsSafe(join(root, 'package-lock.json')))
|
|
158
|
-
return 'npm';
|
|
159
|
-
return 'unknown';
|
|
160
|
-
}
|
|
161
|
-
/* ------------------------------------------------------------------ */
|
|
162
|
-
/* Language inference */
|
|
163
|
-
/* ------------------------------------------------------------------ */
|
|
164
|
-
const EXT_TO_LANG = Object.freeze({
|
|
165
|
-
'.ts': 'typescript',
|
|
166
|
-
'.tsx': 'typescript',
|
|
167
|
-
'.js': 'javascript',
|
|
168
|
-
'.jsx': 'javascript',
|
|
169
|
-
'.mjs': 'javascript',
|
|
170
|
-
'.cjs': 'javascript',
|
|
171
|
-
'.py': 'python',
|
|
172
|
-
'.rs': 'rust',
|
|
173
|
-
'.go': 'go',
|
|
174
|
-
'.java': 'java',
|
|
175
|
-
'.kt': 'kotlin',
|
|
176
|
-
'.swift': 'swift',
|
|
177
|
-
'.rb': 'ruby',
|
|
178
|
-
'.php': 'php',
|
|
179
|
-
'.cs': 'csharp',
|
|
180
|
-
'.cpp': 'cpp',
|
|
181
|
-
'.c': 'c',
|
|
182
|
-
});
|
|
183
|
-
const MANIFEST_TO_LANG = Object.freeze({
|
|
184
|
-
'package.json': ['javascript'],
|
|
185
|
-
'pyproject.toml': ['python'],
|
|
186
|
-
'Cargo.toml': ['rust'],
|
|
187
|
-
'go.mod': ['go'],
|
|
188
|
-
'pom.xml': ['java'],
|
|
189
|
-
'Gemfile': ['ruby'],
|
|
190
|
-
'composer.json': ['php'],
|
|
191
|
-
'unknown': [],
|
|
192
|
-
});
|
|
193
|
-
function inferLanguages(root, manifest, errors) {
|
|
194
|
-
const collected = new Set(MANIFEST_TO_LANG[manifest]);
|
|
195
|
-
// Top-level extension scan, bounded.
|
|
196
|
-
try {
|
|
197
|
-
const entries = readdirSync(root);
|
|
198
|
-
let scanned = 0;
|
|
199
|
-
for (const entry of entries) {
|
|
200
|
-
if (scanned >= MAX_TOP_LEVEL_ENTRIES)
|
|
201
|
-
break;
|
|
202
|
-
scanned += 1;
|
|
203
|
-
// Skip dotfiles + common dependency dirs - they pollute the
|
|
204
|
-
// language inference with build/cache content.
|
|
205
|
-
if (entry.startsWith('.') || entry === 'node_modules' || entry === 'dist')
|
|
206
|
-
continue;
|
|
207
|
-
const dot = entry.lastIndexOf('.');
|
|
208
|
-
if (dot <= 0)
|
|
209
|
-
continue;
|
|
210
|
-
const ext = entry.slice(dot);
|
|
211
|
-
const lang = EXT_TO_LANG[ext];
|
|
212
|
-
if (lang)
|
|
213
|
-
collected.add(lang);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
catch (error) {
|
|
217
|
-
errors.push(`readdir ${root}: ${normalizeError(error)}`);
|
|
218
|
-
}
|
|
219
|
-
// `typescript` implies `javascript` runtime; keep both so the
|
|
220
|
-
// interview can ask "compiled-with vs run-with" if needed.
|
|
221
|
-
return Array.from(collected).sort();
|
|
222
|
-
}
|
|
223
|
-
/* ------------------------------------------------------------------ */
|
|
224
|
-
/* Script picker */
|
|
225
|
-
/* ------------------------------------------------------------------ */
|
|
226
|
-
function pickScript(scripts, candidates) {
|
|
227
|
-
for (const key of candidates) {
|
|
228
|
-
const value = scripts[key];
|
|
229
|
-
if (typeof value === 'string' && value.trim().length > 0) {
|
|
230
|
-
// Surface the npm-style invocation so Phase 4 can quote it
|
|
231
|
-
// verbatim. The package manager name is filled in by the caller
|
|
232
|
-
// once it has resolved `packageManager`.
|
|
233
|
-
return key;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
return undefined;
|
|
237
|
-
}
|
|
238
|
-
/* ------------------------------------------------------------------ */
|
|
239
|
-
/* AI tool config scan */
|
|
240
|
-
/* ------------------------------------------------------------------ */
|
|
241
|
-
const AI_TOOL_CONFIG_PATHS = Object.freeze([
|
|
242
|
-
'CLAUDE.md',
|
|
243
|
-
'CLAUDE.local.md',
|
|
244
|
-
'AGENTS.md',
|
|
245
|
-
'.cursorrules',
|
|
246
|
-
'.cursor/rules',
|
|
247
|
-
'.github/copilot-instructions.md',
|
|
248
|
-
'.windsurfrules',
|
|
249
|
-
'.clinerules',
|
|
250
|
-
'.mcp.json',
|
|
251
|
-
'PUGI.md',
|
|
252
|
-
'PUGI.local.md',
|
|
253
|
-
]);
|
|
254
|
-
function scanAiToolConfigs(root) {
|
|
255
|
-
const result = {};
|
|
256
|
-
for (const rel of AI_TOOL_CONFIG_PATHS) {
|
|
257
|
-
result[rel] = existsSafe(join(root, rel));
|
|
258
|
-
}
|
|
259
|
-
return Object.freeze(result);
|
|
260
|
-
}
|
|
261
|
-
/* ------------------------------------------------------------------ */
|
|
262
|
-
/* CI detection */
|
|
263
|
-
/* ------------------------------------------------------------------ */
|
|
264
|
-
const CI_PROBE_PATHS = Object.freeze([
|
|
265
|
-
'.github/workflows',
|
|
266
|
-
'.gitlab-ci.yml',
|
|
267
|
-
'.circleci/config.yml',
|
|
268
|
-
'azure-pipelines.yml',
|
|
269
|
-
'.travis.yml',
|
|
270
|
-
'.buildkite',
|
|
271
|
-
]);
|
|
272
|
-
function detectCi(root) {
|
|
273
|
-
return CI_PROBE_PATHS.some((rel) => existsSafe(join(root, rel)));
|
|
274
|
-
}
|
|
275
|
-
/* ------------------------------------------------------------------ */
|
|
276
|
-
/* Safe IO helpers */
|
|
277
|
-
/* ------------------------------------------------------------------ */
|
|
278
|
-
function existsSafe(path) {
|
|
279
|
-
try {
|
|
280
|
-
return existsSync(path);
|
|
281
|
-
}
|
|
282
|
-
catch {
|
|
283
|
-
return false;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
function safeReadJson(path, errors) {
|
|
287
|
-
try {
|
|
288
|
-
const stats = statSync(path);
|
|
289
|
-
if (!stats.isFile())
|
|
290
|
-
return undefined;
|
|
291
|
-
if (stats.size > MAX_READ_BYTES) {
|
|
292
|
-
errors.push(`oversize ${path}: ${stats.size} bytes`);
|
|
293
|
-
return undefined;
|
|
294
|
-
}
|
|
295
|
-
const raw = readFileSync(path, 'utf8');
|
|
296
|
-
return JSON.parse(raw);
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
errors.push(`read ${path}: ${normalizeError(error)}`);
|
|
300
|
-
return undefined;
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
function normalizeError(error) {
|
|
304
|
-
if (error instanceof Error)
|
|
305
|
-
return error.message;
|
|
306
|
-
return String(error);
|
|
307
|
-
}
|
|
308
|
-
//# sourceMappingURL=codebase-survey.js.map
|