@venizia/vulcan 0.4.0 → 0.4.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/base/claude/remote-hosts.json +1 -1
- package/base/claude/settings.json +75 -3
- package/base/hooks/guard-git.ts +55 -0
- package/base/hooks/guard-manifest.ts +1 -1
- package/base/hooks/guard-outside.ts +66 -0
- package/base/hooks/guard-package.ts +3 -2
- package/base/hooks/guard-remote-hosts.ts +3 -2
- package/base/hooks/guard-writes.ts +1 -1
- package/base/hooks/post-tool.ts +36 -0
- package/base/hooks/prompt-submit.ts +52 -0
- package/base/hooks/stop.ts +38 -0
- package/base/hooks/subagent-start.ts +18 -0
- package/base/references/delegation-brief.md +63 -0
- package/base/references/design-pass.md +39 -0
- package/base/references/evidence.md +36 -0
- package/base/references/phase-boundaries.md +20 -0
- package/base/references/testing.md +89 -0
- package/base/rules.md +11 -2
- package/base/skills/build-a-feature/SKILL.md +49 -23
- package/base/skills/docs-update/SKILL.md +12 -1
- package/base/skills/docs-writing/SKILL.md +2 -2
- package/base/skills/docs-writing/references/agent-documents.md +53 -0
- package/base/skills/fix-a-bug/SKILL.md +84 -0
- package/base/skills/fix-a-bug/evals/evals.json +17 -0
- package/base/skills/knowledge-sync/SKILL.md +4 -1
- package/base/skills/knowledge-sync/knowledge-sync.workflow.js +10 -10
- package/base/skills/plan-a-change/SKILL.md +95 -0
- package/base/skills/plan-a-change/evals/evals.json +23 -0
- package/base/skills/plan-a-change/references/spec-card.md +39 -0
- package/base/skills/report-back/SKILL.md +112 -0
- package/base/skills/report-back/evals/evals.json +23 -0
- package/base/skills/research/SKILL.md +64 -0
- package/base/skills/research/evals/evals.json +17 -0
- package/base/skills/retro/SKILL.md +69 -0
- package/base/skills/retro/evals/evals.json +17 -0
- package/base/skills/review-a-change/SKILL.md +90 -0
- package/base/skills/review-a-change/evals/evals.json +17 -0
- package/base/skills/ship/SKILL.md +82 -0
- package/base/skills/ship/evals/evals.json +23 -0
- package/base/skills/visualize-work/SKILL.md +87 -0
- package/base/skills/visualize-work/evals/evals.json +17 -0
- package/base/skills/visualize-work/references/spec.md +65 -0
- package/package.json +3 -3
- package/src/agents/common/schema.ts +2 -2
- package/src/agents/detect.ts +5 -5
- package/src/agents/exclude.ts +3 -3
- package/src/agents/local.ts +1 -1
- package/src/agents/prompt.ts +2 -2
- package/src/agents/render.ts +2 -2
- package/src/agents/resolve.ts +6 -6
- package/src/agents/table.ts +1 -1
- package/src/commands/agents.command.ts +4 -4
- package/src/commands/clean.command.ts +72 -0
- package/src/commands/help.command.ts +11 -0
- package/src/commands/index.ts +6 -0
- package/src/commands/init.command.ts +4 -1
- package/src/commands/profile.command.ts +255 -0
- package/src/commands/sync.command.ts +6 -4
- package/src/commands/upgrade.command.ts +1 -1
- package/src/commands/visualize.command.ts +107 -0
- package/src/common/constants.ts +23 -0
- package/src/config/common/constants.ts +2 -0
- package/src/config/loader.ts +4 -4
- package/src/config/packages.ts +1 -1
- package/src/config/schema.ts +16 -5
- package/src/create/add-app.ts +15 -15
- package/src/create/add-lib.ts +7 -7
- package/src/create/bunfig.ts +1 -1
- package/src/create/dockerignore.ts +4 -4
- package/src/create/init-monorepo.ts +3 -1
- package/src/create/lib-preset.ts +1 -1
- package/src/create/names.ts +7 -6
- package/src/create/next.ts +4 -4
- package/src/create/preset-menu.ts +4 -4
- package/src/create/preset.ts +3 -3
- package/src/create/scratch.ts +27 -6
- package/src/create/workspace.ts +11 -11
- package/src/doctor/checks.ts +231 -45
- package/src/doctor/common/constants.ts +4 -0
- package/src/doctor/makefile.ts +3 -3
- package/src/doctor/runner.ts +16 -1
- package/src/doctor/skills.ts +8 -8
- package/src/doctor/tags.ts +5 -5
- package/src/hooks/common/constants.ts +29 -0
- package/src/hooks/common/types.ts +20 -0
- package/src/hooks/decision.ts +15 -0
- package/src/hooks/guard-git.ts +288 -0
- package/src/hooks/guard-manifest.ts +1 -1
- package/src/hooks/guard-outside.ts +399 -0
- package/src/hooks/guard-package.ts +4 -4
- package/src/hooks/guard-writes.ts +5 -5
- package/src/hooks/index.ts +6 -0
- package/src/hooks/owner-reply.ts +148 -0
- package/src/hooks/post-tool.ts +137 -0
- package/src/hooks/remote-hosts.ts +25 -23
- package/src/hooks/session-digest.ts +24 -4
- package/src/hooks/shell.ts +325 -0
- package/src/hooks/subagent-card.ts +32 -0
- package/src/init/scaffold.ts +6 -6
- package/src/local/clean.ts +88 -0
- package/src/local/constants.ts +50 -0
- package/src/local/format.ts +25 -0
- package/src/local/index.ts +4 -0
- package/src/local/scan.ts +368 -0
- package/src/manifest/render.ts +1 -1
- package/src/owner/card.ts +85 -0
- package/src/owner/constants.ts +105 -0
- package/src/owner/index.ts +8 -0
- package/src/owner/profile.ts +123 -0
- package/src/owner/schema.ts +147 -0
- package/src/owner/shape.ts +388 -0
- package/src/owner/survey.ts +289 -0
- package/src/owner/view.ts +76 -0
- package/src/owner/violations.ts +202 -0
- package/src/router.ts +18 -1
- package/src/rules/base.ts +1 -1
- package/src/rules/parser.ts +5 -5
- package/src/signals/claims.ts +71 -0
- package/src/signals/classify.ts +132 -0
- package/src/signals/constants.ts +88 -0
- package/src/signals/index.ts +5 -0
- package/src/signals/loop.ts +46 -0
- package/src/signals/state.ts +276 -0
- package/src/sync/agent-files.ts +4 -4
- package/src/sync/agent-removal.ts +6 -6
- package/src/sync/atlas-block.ts +1 -1
- package/src/sync/base-rules.ts +1 -1
- package/src/sync/exclude.ts +9 -9
- package/src/sync/local-choice.ts +35 -5
- package/src/sync/planner.ts +16 -16
- package/src/sync/prune.ts +3 -3
- package/src/sync/settings.ts +15 -15
- package/src/ui/prompt.ts +3 -3
- package/src/visualize/assets.ts +80 -0
- package/src/visualize/constants.ts +126 -0
- package/src/visualize/index.ts +6 -0
- package/src/visualize/layout.ts +107 -0
- package/src/visualize/page.ts +211 -0
- package/src/visualize/render.ts +161 -0
- package/src/visualize/schema.ts +178 -0
- package/src/visualize/validate.ts +127 -0
package/src/create/add-lib.ts
CHANGED
|
@@ -39,7 +39,7 @@ const isProjectFolder = (opts: { folder: string }): boolean =>
|
|
|
39
39
|
opts.folder
|
|
40
40
|
.replace(/\/+$/, '')
|
|
41
41
|
.split('/')
|
|
42
|
-
.every(segment => DIRECTORY_SEGMENT.test(segment) && segment !== '..');
|
|
42
|
+
.every((segment) => DIRECTORY_SEGMENT.test(segment) && segment !== '..');
|
|
43
43
|
|
|
44
44
|
const scopeOf = (opts: { name: string }): string =>
|
|
45
45
|
opts.name.startsWith('@') ? opts.name.split('/')[0] : '';
|
|
@@ -59,8 +59,8 @@ const folderOf = async (opts: {
|
|
|
59
59
|
const libFolders = [
|
|
60
60
|
...new Set(
|
|
61
61
|
opts.packages
|
|
62
|
-
.filter(entry => entry.kind === 'lib' && !entry.retired)
|
|
63
|
-
.map(entry => dirname(entry.path)),
|
|
62
|
+
.filter((entry) => entry.kind === 'lib' && !entry.retired)
|
|
63
|
+
.map((entry) => dirname(entry.path)),
|
|
64
64
|
),
|
|
65
65
|
];
|
|
66
66
|
const fallback =
|
|
@@ -113,14 +113,14 @@ const nameOf = (opts: {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
const siblings = opts.packages.filter(
|
|
116
|
-
entry => !entry.retired && dirname(entry.path) === opts.folder,
|
|
116
|
+
(entry) => !entry.retired && dirname(entry.path) === opts.folder,
|
|
117
117
|
);
|
|
118
|
-
const scopes = [...new Set(siblings.map(entry => scopeOf({ name: entry.name })))].sort();
|
|
118
|
+
const scopes = [...new Set(siblings.map((entry) => scopeOf({ name: entry.name })))].sort();
|
|
119
119
|
|
|
120
120
|
if (scopes.length > 1) {
|
|
121
121
|
return {
|
|
122
122
|
ok: false,
|
|
123
|
-
error: `the packages in ${opts.folder} use more than one scope (${scopes.map(scope => scope || 'unscoped').join(', ')}) - pass ${CreateFlags.SCOPE} <@scope>`,
|
|
123
|
+
error: `the packages in ${opts.folder} use more than one scope (${scopes.map((scope) => scope || 'unscoped').join(', ')}) - pass ${CreateFlags.SCOPE} <@scope>`,
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
|
|
@@ -189,7 +189,7 @@ export const addLibrary = async (opts: {
|
|
|
189
189
|
|
|
190
190
|
if (
|
|
191
191
|
existsSync(join(cwd, path)) ||
|
|
192
|
-
opts.packages.some(entry => entry.dir === libName || entry.name === named.name)
|
|
192
|
+
opts.packages.some((entry) => entry.dir === libName || entry.name === named.name)
|
|
193
193
|
) {
|
|
194
194
|
return fail({ message: `${path} already exists` });
|
|
195
195
|
}
|
package/src/create/bunfig.ts
CHANGED
|
@@ -30,16 +30,16 @@ const SECRET_COMMENT =
|
|
|
30
30
|
*/
|
|
31
31
|
export const renderDockerignore = (): string => {
|
|
32
32
|
const agentPaths = excludePathsOf({
|
|
33
|
-
agents: readAgentTable().map(entry => entry.id),
|
|
33
|
+
agents: readAgentTable().map((entry) => entry.id),
|
|
34
34
|
skillNames: shippedSkillNames(),
|
|
35
35
|
})
|
|
36
|
-
.flatMap(group => group.paths)
|
|
37
|
-
.map(path => path.replace(/^\//, '').replace(/\/$/, ''));
|
|
36
|
+
.flatMap((group) => group.paths)
|
|
37
|
+
.map((path) => path.replace(/^\//, '').replace(/\/$/, ''));
|
|
38
38
|
const patterns = [...new Set([...BASE_PATTERNS, ...SECRET_PATTERNS, ...agentPaths])];
|
|
39
39
|
|
|
40
40
|
return [
|
|
41
41
|
'# Written by vulcan init; edit it freely, vulcan never overwrites it. .git is excluded, so pass the commit: docker build --build-arg APP_BUILD_COMMIT="$(git rev-parse HEAD)" ...',
|
|
42
|
-
...patterns.flatMap(pattern =>
|
|
42
|
+
...patterns.flatMap((pattern) =>
|
|
43
43
|
pattern === SECRET_PATTERNS[0] ? [SECRET_COMMENT, pattern] : [pattern],
|
|
44
44
|
),
|
|
45
45
|
'',
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
import { copyPresetFiles, locatePreset, parsePresetSpec } from './preset.ts';
|
|
31
31
|
import { renderNext } from './next.ts';
|
|
32
32
|
import { isInstallSkipped, runBun, runGitInit } from './process.ts';
|
|
33
|
+
import { offerProfile } from '../commands/profile.command.ts';
|
|
33
34
|
import { installNpmPreset, withScratch } from './scratch.ts';
|
|
34
35
|
import {
|
|
35
36
|
filePresetWarning,
|
|
@@ -389,9 +390,10 @@ const runCreate = async (opts: {
|
|
|
389
390
|
apps: [{ port: located.preset.devPort, urls: located.preset.urls }],
|
|
390
391
|
}),
|
|
391
392
|
);
|
|
393
|
+
await offerProfile({ root });
|
|
392
394
|
|
|
393
395
|
return ExitCodes.OK;
|
|
394
396
|
};
|
|
395
397
|
|
|
396
398
|
export const createMonorepo = async (opts: { cwd: string; args: string[] }): Promise<number> =>
|
|
397
|
-
withScratch({ run: scratch => runCreate({ ...opts, scratch }) });
|
|
399
|
+
withScratch({ root: opts.cwd, run: (scratch) => runCreate({ ...opts, scratch }) });
|
package/src/create/lib-preset.ts
CHANGED
|
@@ -120,7 +120,7 @@ export const readLibPreset = (opts: { located: ILocatedPreset }): TLibPresetResu
|
|
|
120
120
|
|
|
121
121
|
if (!parsed.success) {
|
|
122
122
|
const issues = parsed.error.issues
|
|
123
|
-
.map(issue => `${issue.path.join('.')} ${issue.message}`)
|
|
123
|
+
.map((issue) => `${issue.path.join('.')} ${issue.message}`)
|
|
124
124
|
.join('; ');
|
|
125
125
|
|
|
126
126
|
return { ok: false, error: `${shown}: lib preset: ${issues}` };
|
package/src/create/names.ts
CHANGED
|
@@ -35,7 +35,7 @@ export const SCOPE_PATTERN = /^@[a-z0-9][a-z0-9-]*$/;
|
|
|
35
35
|
export const askScope = async (): Promise<string | undefined | null> => {
|
|
36
36
|
const answer = await promptText({
|
|
37
37
|
message: 'Package scope (optional, like @acme; empty for none)',
|
|
38
|
-
validate: value =>
|
|
38
|
+
validate: (value) =>
|
|
39
39
|
value.trim() === '' || SCOPE_PATTERN.test(value.trim())
|
|
40
40
|
? undefined
|
|
41
41
|
: `'${value.trim()}' is not a scope like @acme`,
|
|
@@ -78,7 +78,8 @@ const NEWLINE = 0x0a;
|
|
|
78
78
|
const CARRIAGE_RETURN = 0x0d;
|
|
79
79
|
const RETRY_PAUSE_MILLISECONDS = 5;
|
|
80
80
|
|
|
81
|
-
const readFromDescriptor: TByteReader = opts =>
|
|
81
|
+
const readFromDescriptor: TByteReader = (opts) =>
|
|
82
|
+
readSync(opts.descriptor, opts.buffer, 0, 1, null);
|
|
82
83
|
|
|
83
84
|
/** A sleep that does not burn the CPU: nothing else runs on this thread while a prompt waits. */
|
|
84
85
|
const pauseBriefly = (): void => {
|
|
@@ -152,12 +153,12 @@ export const askWithPrompt = (opts: IAskOptions): string | null => {
|
|
|
152
153
|
const NEW_FOLDER = ':new-folder';
|
|
153
154
|
|
|
154
155
|
/** A menu, not a line: existing folders are picked, a new name is typed with its default shown. */
|
|
155
|
-
const askWithMenus: TAsk = async opts => {
|
|
156
|
+
const askWithMenus: TAsk = async (opts) => {
|
|
156
157
|
if (opts.choices !== undefined && opts.choices.length > 0) {
|
|
157
158
|
const picked = await promptSelect({
|
|
158
159
|
message: opts.question,
|
|
159
160
|
choices: [
|
|
160
|
-
...opts.choices.map(value => ({ value, label: value })),
|
|
161
|
+
...opts.choices.map((value) => ({ value, label: value })),
|
|
161
162
|
{ value: NEW_FOLDER, label: 'New folder...' },
|
|
162
163
|
],
|
|
163
164
|
initial: opts.previous,
|
|
@@ -176,7 +177,7 @@ const askWithMenus: TAsk = async opts => {
|
|
|
176
177
|
};
|
|
177
178
|
|
|
178
179
|
/** Menus in a terminal that can draw them, the plain question everywhere else. */
|
|
179
|
-
export const askInTerminal: TAsk = opts =>
|
|
180
|
+
export const askInTerminal: TAsk = (opts) =>
|
|
180
181
|
menusAvailable() ? askWithMenus(opts) : askWithPrompt(opts);
|
|
181
182
|
|
|
182
183
|
const askUntilValid = async (opts: { field: INameField; ask: TAsk }): Promise<string | null> => {
|
|
@@ -282,7 +283,7 @@ export const findFolderClash = (opts: {
|
|
|
282
283
|
folders: { flag: string; value: string }[];
|
|
283
284
|
}): string | undefined => {
|
|
284
285
|
for (const [index, first] of opts.folders.entries()) {
|
|
285
|
-
const second = opts.folders.slice(index + 1).find(other => other.value === first.value);
|
|
286
|
+
const second = opts.folders.slice(index + 1).find((other) => other.value === first.value);
|
|
286
287
|
|
|
287
288
|
if (second !== undefined) {
|
|
288
289
|
return `${first.flag} and ${second.flag} both name '${first.value}' - each kind of code needs its own folder`;
|
package/src/create/next.ts
CHANGED
|
@@ -26,12 +26,12 @@ const readRecordedUrls = (opts: { directory: string }): string[] => {
|
|
|
26
26
|
const recorded = existsSync(file) ? readJson({ file })?.vulcan : undefined;
|
|
27
27
|
const urls = (recorded as { urls?: unknown } | undefined)?.urls;
|
|
28
28
|
|
|
29
|
-
return Array.isArray(urls) ? urls.filter(url => typeof url === 'string') : [];
|
|
29
|
+
return Array.isArray(urls) ? urls.filter((url) => typeof url === 'string') : [];
|
|
30
30
|
};
|
|
31
31
|
|
|
32
32
|
/** The apps already in the monorepo: those with a `*PORT=` line in .env.example, as they were made. */
|
|
33
33
|
export const readExistingApps = (opts: { root: string; paths: string[] }): INextApp[] =>
|
|
34
|
-
opts.paths.flatMap(path => {
|
|
34
|
+
opts.paths.flatMap((path) => {
|
|
35
35
|
const directory = join(opts.root, path);
|
|
36
36
|
const envFile = join(directory, '.env.example');
|
|
37
37
|
const port = existsSync(envFile)
|
|
@@ -43,9 +43,9 @@ export const readExistingApps = (opts: { root: string; paths: string[] }): INext
|
|
|
43
43
|
|
|
44
44
|
/** The closing message: what ran, then one `open` line per url, or per app root when it has none. */
|
|
45
45
|
export const renderNext = (opts: { done: string; command: string; apps: INextApp[] }): string => {
|
|
46
|
-
const lines = opts.apps.flatMap(app =>
|
|
46
|
+
const lines = opts.apps.flatMap((app) =>
|
|
47
47
|
(app.urls.length === 0 ? [''] : app.urls).map(
|
|
48
|
-
path => ` open http://localhost:${app.port}${path}`,
|
|
48
|
+
(path) => ` open http://localhost:${app.port}${path}`,
|
|
49
49
|
),
|
|
50
50
|
);
|
|
51
51
|
|
|
@@ -16,16 +16,16 @@ export interface IKnownPreset {
|
|
|
16
16
|
* or `file:` path. null when the user cancelled.
|
|
17
17
|
*/
|
|
18
18
|
export const askPresetSpec = async (opts: { recorded: IKnownPreset[] }): Promise<string | null> => {
|
|
19
|
-
const used = new Set(opts.recorded.map(entry => officialIdOf({ spec: entry.spec })));
|
|
19
|
+
const used = new Set(opts.recorded.map((entry) => officialIdOf({ spec: entry.spec })));
|
|
20
20
|
const picked = await promptSelect({
|
|
21
21
|
message: 'Which preset?',
|
|
22
22
|
choices: [
|
|
23
|
-
...opts.recorded.map(entry => ({
|
|
23
|
+
...opts.recorded.map((entry) => ({
|
|
24
24
|
value: entry.spec,
|
|
25
25
|
label: entry.spec,
|
|
26
26
|
hint: `${entry.side}: ${entry.summary}`,
|
|
27
27
|
})),
|
|
28
|
-
...OFFICIAL_PRESETS.filter(entry => !used.has(entry.id)).map(entry => ({
|
|
28
|
+
...OFFICIAL_PRESETS.filter((entry) => !used.has(entry.id)).map((entry) => ({
|
|
29
29
|
value: entry.id,
|
|
30
30
|
label: entry.id,
|
|
31
31
|
hint: `official, ${entry.side} (app or lib)`,
|
|
@@ -40,6 +40,6 @@ export const askPresetSpec = async (opts: { recorded: IKnownPreset[] }): Promise
|
|
|
40
40
|
|
|
41
41
|
return promptText({
|
|
42
42
|
message: 'Preset (a package name, or file:<path>)',
|
|
43
|
-
validate: value => (value.trim() === '' ? 'a package name, or file:<path>' : undefined),
|
|
43
|
+
validate: (value) => (value.trim() === '' ? 'a package name, or file:<path>' : undefined),
|
|
44
44
|
});
|
|
45
45
|
};
|
package/src/create/preset.ts
CHANGED
|
@@ -148,14 +148,14 @@ export const locatePreset = (opts: { spec: IPresetSpec; root: string }): TPreset
|
|
|
148
148
|
const shown = `${packageName}@${packageVersion}`;
|
|
149
149
|
const vulcan = manifest[CreateConstants.PRESET_FIELD];
|
|
150
150
|
const oldKeys = ['preset', 'lib'].filter(
|
|
151
|
-
key => readProperty({ value: vulcan, key }) !== undefined,
|
|
151
|
+
(key) => readProperty({ value: vulcan, key }) !== undefined,
|
|
152
152
|
);
|
|
153
153
|
|
|
154
154
|
// No fallback to the keys before `presets`: say what the contract is now.
|
|
155
155
|
if (oldKeys.length > 0) {
|
|
156
156
|
return {
|
|
157
157
|
ok: false,
|
|
158
|
-
error: `${shown} uses the old keys "vulcan": { ${oldKeys.map(key => `"${key}"`).join(', ')} }; the contract is now "vulcan": { "presets": { "app": "./path/preset.json", "lib": "./path/lib.json" } }`,
|
|
158
|
+
error: `${shown} uses the old keys "vulcan": { ${oldKeys.map((key) => `"${key}"`).join(', ')} }; the contract is now "vulcan": { "presets": { "app": "./path/preset.json", "lib": "./path/lib.json" } }`,
|
|
159
159
|
};
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -199,7 +199,7 @@ export const locatePreset = (opts: { spec: IPresetSpec; root: string }): TPreset
|
|
|
199
199
|
|
|
200
200
|
if (!parsed.success) {
|
|
201
201
|
const issues = parsed.error.issues
|
|
202
|
-
.map(issue => `${issue.path.join('.')} ${issue.message}`)
|
|
202
|
+
.map((issue) => `${issue.path.join('.')} ${issue.message}`)
|
|
203
203
|
.join('; ');
|
|
204
204
|
|
|
205
205
|
return { ok: false, error: `${shown}: ${field}: ${issues}` };
|
package/src/create/scratch.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { tmpdir } from 'node:os';
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
2
|
import { join } from 'node:path';
|
|
3
|
+
import { ProjectLayout } from '../common/index.ts';
|
|
4
4
|
import type { IPresetSpec } from './common/index.ts';
|
|
5
5
|
import { runBun } from './process.ts';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* An npm preset is read from node_modules, so it is installed into a scratch folder
|
|
9
|
-
* project: every refusal that depends on what the package says happens before anything is written.
|
|
8
|
+
* An npm preset is read from node_modules, so it is installed into a scratch folder apart from the
|
|
9
|
+
* project's own files, under `.agents/local/tmp/` (nothing goes outside the project): every refusal that depends on what the package says happens before anything is written.
|
|
10
10
|
* One line says what is fetched; bun's own output would land between the questions, so it is kept
|
|
11
11
|
* and shown only when the install fails.
|
|
12
12
|
*/
|
|
@@ -31,15 +31,36 @@ export const installNpmPreset = async (opts: {
|
|
|
31
31
|
});
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
/**
|
|
34
|
+
/** Removes `directory` when nothing is in it; one that holds anything stays. */
|
|
35
|
+
const removeIfEmpty = (opts: { directory: string }): void => {
|
|
36
|
+
try {
|
|
37
|
+
rmdirSync(opts.directory);
|
|
38
|
+
} catch {
|
|
39
|
+
// not empty, or not there
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The scratch folder lives as long as the flow: the located preset's files are copied from it. It is
|
|
45
|
+
* made under `<root>/.agents/local/tmp/`, and the folders made for it go with it when they are empty.
|
|
46
|
+
*/
|
|
35
47
|
export const withScratch = async <TResult>(opts: {
|
|
48
|
+
root: string;
|
|
36
49
|
run: (scratch: string) => Promise<TResult>;
|
|
37
50
|
}): Promise<TResult> => {
|
|
38
|
-
const
|
|
51
|
+
const local = join(opts.root, ProjectLayout.LOCAL_DIRECTORY);
|
|
52
|
+
const parent = join(local, 'tmp');
|
|
53
|
+
|
|
54
|
+
mkdirSync(parent, { recursive: true });
|
|
55
|
+
|
|
56
|
+
const scratch = mkdtempSync(join(parent, 'preset-'));
|
|
39
57
|
|
|
40
58
|
try {
|
|
41
59
|
return await opts.run(scratch);
|
|
42
60
|
} finally {
|
|
43
61
|
rmSync(scratch, { recursive: true, force: true });
|
|
62
|
+
removeIfEmpty({ directory: parent });
|
|
63
|
+
removeIfEmpty({ directory: local });
|
|
64
|
+
removeIfEmpty({ directory: join(opts.root, '.agents') });
|
|
44
65
|
}
|
|
45
66
|
};
|
package/src/create/workspace.ts
CHANGED
|
@@ -147,7 +147,7 @@ const toCatalog = (opts: { dependencies: Record<string, string> }): Record<strin
|
|
|
147
147
|
Object.fromEntries(
|
|
148
148
|
Object.keys(opts.dependencies)
|
|
149
149
|
.sort()
|
|
150
|
-
.map(name => [name, 'catalog:']),
|
|
150
|
+
.map((name) => [name, 'catalog:']),
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
export const renderAppManifest = (opts: {
|
|
@@ -310,8 +310,8 @@ export const presetSpecOf = (opts: { value: string; root: string; cwd: string })
|
|
|
310
310
|
|
|
311
311
|
/** The block with this preset recorded: once per spec, its side and summary refreshed. */
|
|
312
312
|
export const recordPreset = (opts: { block: IAppsBlock; preset: IRecordedPreset }): IAppsBlock => {
|
|
313
|
-
const others = (opts.block.presets ?? []).filter(item => item.spec !== opts.preset.spec);
|
|
314
|
-
const index = (opts.block.presets ?? []).findIndex(item => item.spec === opts.preset.spec);
|
|
313
|
+
const others = (opts.block.presets ?? []).filter((item) => item.spec !== opts.preset.spec);
|
|
314
|
+
const index = (opts.block.presets ?? []).findIndex((item) => item.spec === opts.preset.spec);
|
|
315
315
|
const presets =
|
|
316
316
|
index === -1
|
|
317
317
|
? [...others, opts.preset]
|
|
@@ -341,7 +341,7 @@ export const replaceAppsBlock = (opts: {
|
|
|
341
341
|
const hasStrings = (opts: { value: unknown; keys: string[] }): boolean => {
|
|
342
342
|
const { value } = opts;
|
|
343
343
|
|
|
344
|
-
return isRecord(value) && opts.keys.every(key => typeof value[key] === 'string');
|
|
344
|
+
return isRecord(value) && opts.keys.every((key) => typeof value[key] === 'string');
|
|
345
345
|
};
|
|
346
346
|
|
|
347
347
|
const isRecordedPreset = (value: unknown): boolean =>
|
|
@@ -353,13 +353,13 @@ const isRecordedPreset = (value: unknown): boolean =>
|
|
|
353
353
|
const isAppsBlock = (value: unknown): value is IAppsBlock =>
|
|
354
354
|
isRecord(value) &&
|
|
355
355
|
(value.presets === undefined ||
|
|
356
|
-
(Array.isArray(value.presets) && value.presets.every(entry => isRecordedPreset(entry)))) &&
|
|
356
|
+
(Array.isArray(value.presets) && value.presets.every((entry) => isRecordedPreset(entry)))) &&
|
|
357
357
|
isRecord(value.layout) &&
|
|
358
|
-
Object.values(value.layout).every(folder => typeof folder === 'string') &&
|
|
358
|
+
Object.values(value.layout).every((folder) => typeof folder === 'string') &&
|
|
359
359
|
Array.isArray(value.packages) &&
|
|
360
|
-
value.packages.every(entry => hasStrings({ value: entry, keys: ['dir', 'name', 'path'] })) &&
|
|
360
|
+
value.packages.every((entry) => hasStrings({ value: entry, keys: ['dir', 'name', 'path'] })) &&
|
|
361
361
|
Array.isArray(value.sources) &&
|
|
362
|
-
value.sources.every(entry => hasStrings({ value: entry, keys: ['name', 'repo', 'ref'] }));
|
|
362
|
+
value.sources.every((entry) => hasStrings({ value: entry, keys: ['name', 'repo', 'ref'] }));
|
|
363
363
|
|
|
364
364
|
export type TAppsBlockResult =
|
|
365
365
|
| { ok: true; block: IAppsBlock }
|
|
@@ -422,7 +422,7 @@ export const addAppBullet = (opts: {
|
|
|
422
422
|
const eol = opts.source.includes('\r\n') ? '\r\n' : '\n';
|
|
423
423
|
const bullet = renderAppBullet({ app: opts.app });
|
|
424
424
|
const lines = opts.source.split(eol);
|
|
425
|
-
const heading = lines.findIndex(line => APPS_HEADING.test(line));
|
|
425
|
+
const heading = lines.findIndex((line) => APPS_HEADING.test(line));
|
|
426
426
|
|
|
427
427
|
if (heading === -1) {
|
|
428
428
|
const kept = opts.source.trimEnd();
|
|
@@ -432,7 +432,7 @@ export const addAppBullet = (opts: {
|
|
|
432
432
|
|
|
433
433
|
const next = lines.findIndex((line, index) => index > heading && ANY_HEADING.test(line));
|
|
434
434
|
const section = lines.slice(heading + 1, next === -1 ? lines.length : next);
|
|
435
|
-
const last = section.findLastIndex(line => line.startsWith('- ['));
|
|
435
|
+
const last = section.findLastIndex((line) => line.startsWith('- ['));
|
|
436
436
|
|
|
437
437
|
if (last === -1) {
|
|
438
438
|
lines.splice(heading, 1, lines[heading] ?? '', '', bullet);
|
|
@@ -467,7 +467,7 @@ export const renderKnowledgeIndex = (opts: {
|
|
|
467
467
|
'',
|
|
468
468
|
'## Apps',
|
|
469
469
|
'',
|
|
470
|
-
...opts.apps.map(app => renderAppBullet({ app })),
|
|
470
|
+
...opts.apps.map((app) => renderAppBullet({ app })),
|
|
471
471
|
'',
|
|
472
472
|
].join('\n');
|
|
473
473
|
|