@venizia/vulcan 0.4.9-0 → 0.4.9-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/extensions/vulcan-guards.ts +48 -41
- package/base/hooks/antigravity-guards.ts +2 -2
- package/base/hooks/codex-guards.ts +15 -5
- package/base/hooks/guard-git.ts +8 -8
- package/base/hooks/guard-manifest.ts +4 -5
- package/base/hooks/guard-outside.ts +8 -8
- package/base/hooks/guard-package.ts +5 -6
- package/base/hooks/guard-remote-hosts.ts +6 -7
- package/base/hooks/guard-scripting.ts +5 -6
- package/base/hooks/guard-writes.ts +8 -9
- package/base/hooks/post-tool.ts +2 -2
- package/base/hooks/prompt-submit.ts +2 -2
- package/base/hooks/session-start.ts +3 -3
- package/base/hooks/stop.ts +2 -2
- package/base/hooks/subagent-start.ts +2 -2
- package/base/skills/docs-update/SKILL.md +4 -2
- package/base/skills/visualize-work/SKILL.md +9 -0
- package/package.json +3 -3
- package/src/agents/atlas-block.ts +43 -43
- package/src/agents/codex-hooks.ts +45 -43
- package/src/agents/detect.ts +19 -16
- package/src/agents/exclude.ts +96 -97
- package/src/agents/hooks-json.ts +38 -36
- package/src/agents/local.ts +46 -43
- package/src/agents/prompt.ts +45 -42
- package/src/agents/render.ts +201 -195
- package/src/agents/resolve.ts +133 -134
- package/src/agents/table.ts +12 -8
- package/src/commands/add.command.ts +2 -2
- package/src/commands/agents.command.ts +11 -17
- package/src/commands/clean.command.ts +6 -6
- package/src/commands/doctor.command.ts +4 -4
- package/src/commands/init.command.ts +12 -8
- package/src/commands/preset.command.ts +2 -2
- package/src/commands/profile.command.ts +42 -49
- package/src/commands/sync.command.ts +109 -111
- package/src/commands/upgrade.command.ts +80 -75
- package/src/commands/visualize.command.ts +7 -13
- package/src/commands/x.command.ts +55 -50
- package/src/common/format.ts +23 -21
- package/src/common/json.ts +8 -5
- package/src/common/layout-folder.ts +94 -91
- package/src/common/paths.ts +14 -12
- package/src/config/loader.ts +52 -49
- package/src/config/packages.ts +14 -11
- package/src/config/schema.ts +3 -3
- package/src/create/add-app.ts +519 -509
- package/src/create/add-lib.ts +237 -240
- package/src/create/bunfig.ts +26 -23
- package/src/create/checks.ts +36 -34
- package/src/create/diff.ts +21 -23
- package/src/create/dockerignore.ts +26 -24
- package/src/create/files.ts +7 -5
- package/src/create/init-monorepo.ts +75 -80
- package/src/create/lib-preset.ts +59 -63
- package/src/create/manifest-json.ts +10 -4
- package/src/create/names.ts +217 -210
- package/src/create/next.ts +26 -23
- package/src/create/plan.ts +15 -12
- package/src/create/preset-diff.ts +301 -303
- package/src/create/preset-menu.ts +38 -32
- package/src/create/preset.ts +202 -197
- package/src/create/process.ts +79 -72
- package/src/create/scratch.ts +48 -49
- package/src/create/workspace.ts +404 -396
- package/src/doctor/checks.ts +1027 -1014
- package/src/doctor/makefile.ts +17 -13
- package/src/doctor/runner.ts +88 -118
- package/src/doctor/skills.ts +97 -95
- package/src/doctor/tags.ts +42 -37
- package/src/hooks/codex-patch.ts +25 -22
- package/src/hooks/command-view.ts +44 -39
- package/src/hooks/decision.ts +37 -37
- package/src/hooks/guard-git.ts +51 -49
- package/src/hooks/guard-manifest.ts +58 -55
- package/src/hooks/guard-outside.ts +93 -91
- package/src/hooks/guard-package.ts +82 -79
- package/src/hooks/guard-scripting.ts +19 -14
- package/src/hooks/guard-writes.ts +154 -149
- package/src/hooks/owner-reply.ts +127 -127
- package/src/hooks/post-tool.ts +94 -93
- package/src/hooks/project-guards.ts +65 -62
- package/src/hooks/project-tmp.ts +27 -24
- package/src/hooks/remote-hosts.ts +153 -130
- package/src/hooks/session-digest.ts +98 -101
- package/src/hooks/shell.ts +509 -499
- package/src/hooks/subagent-card.ts +11 -7
- package/src/hooks/trusted-scripts.ts +106 -104
- package/src/init/scaffold.ts +135 -132
- package/src/local/clean.ts +38 -36
- package/src/local/format.ts +21 -17
- package/src/local/scan.ts +144 -138
- package/src/manifest/render.ts +110 -104
- package/src/owner/card.ts +51 -46
- package/src/owner/profile.ts +99 -93
- package/src/owner/reply-switch.ts +9 -6
- package/src/owner/shape.ts +71 -69
- package/src/owner/survey.ts +173 -171
- package/src/owner/view.ts +62 -59
- package/src/owner/violations.ts +119 -123
- package/src/rules/base.ts +15 -11
- package/src/rules/parser.ts +39 -32
- package/src/rules/slots.ts +8 -6
- package/src/signals/claims.ts +30 -28
- package/src/signals/classify.ts +38 -33
- package/src/signals/loop.ts +39 -37
- package/src/signals/state.ts +79 -81
- package/src/skills/frontmatter.ts +28 -28
- package/src/sync/agent-files.ts +217 -199
- package/src/sync/agent-removal.ts +56 -59
- package/src/sync/atlas-block.ts +45 -43
- package/src/sync/base-rules.ts +32 -30
- package/src/sync/claude-launch.ts +36 -34
- package/src/sync/exclude.ts +77 -69
- package/src/sync/local-choice.ts +50 -47
- package/src/sync/planner.ts +59 -61
- package/src/sync/prune.ts +52 -48
- package/src/sync/settings.ts +166 -167
- package/src/ui/capability.ts +12 -7
- package/src/ui/keyboard.ts +38 -38
- package/src/ui/prompt.ts +79 -77
- package/src/visualize/assets.ts +33 -24
- package/src/visualize/charts.ts +179 -176
- package/src/visualize/compare-css.ts +3 -2
- package/src/visualize/compare-render.ts +9 -7
- package/src/visualize/diagrams.ts +189 -174
- package/src/visualize/grid-span.ts +34 -0
- package/src/visualize/icons.ts +7 -5
- package/src/visualize/kinds-render.ts +50 -45
- package/src/visualize/kinds-validate.ts +12 -10
- package/src/visualize/labels.ts +21 -17
- package/src/visualize/layout.ts +112 -97
- package/src/visualize/page.ts +92 -104
- package/src/visualize/render.ts +143 -140
- package/src/visualize/sections.ts +395 -384
- package/src/visualize/sources.ts +2 -2
- package/src/visualize/theme.ts +12 -10
- package/src/visualize/validate.ts +13 -9
- package/src/wiki/anchors.ts +38 -36
- package/src/wiki/command.ts +4 -4
- package/src/wiki/source-links.ts +46 -44
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { lstatSync, readlinkSync, realpathSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { dirname, isAbsolute, join, resolve, sep } from 'node:path';
|
|
4
|
-
import {
|
|
4
|
+
import { ShellParser } from './shell.ts';
|
|
5
5
|
import type { ISimpleCommand } from './shell.ts';
|
|
6
6
|
import { HookConstants } from './common/index.ts';
|
|
7
|
-
import {
|
|
7
|
+
import { ProjectTmp } from './project-tmp.ts';
|
|
8
8
|
import type { IManifestHookInput, IOutsideHit } from './common/index.ts';
|
|
9
9
|
|
|
10
10
|
const FILE_TOOLS = new Set(['Write', 'Edit', 'MultiEdit', 'NotebookEdit']);
|
|
@@ -251,8 +251,8 @@ const gitTargets = (opts: { rest: string[]; base: string; dir: string | undefine
|
|
|
251
251
|
|
|
252
252
|
/** The words a simple command would create or write, with a name for what writes them. */
|
|
253
253
|
const targetsOf = (opts: { command: ISimpleCommand; base: string; tmp: string }): ITarget[] => {
|
|
254
|
-
const program = programOf({ command: opts.command });
|
|
255
|
-
const name = basenameOf({ word: program.name });
|
|
254
|
+
const program = ShellParser.programOf({ command: opts.command });
|
|
255
|
+
const name = ShellParser.basenameOf({ word: program.name });
|
|
256
256
|
const { args } = program;
|
|
257
257
|
const { base } = opts;
|
|
258
258
|
const targets: ITarget[] = opts.command.redirects.map((word) => ({
|
|
@@ -351,108 +351,110 @@ const commandTmpdirOf = (opts: { env: TEnvironment; projectRoot: string }): stri
|
|
|
351
351
|
|
|
352
352
|
return opts.env.CLAUDE_PROJECT_DIR === undefined
|
|
353
353
|
? tmpdir()
|
|
354
|
-
:
|
|
354
|
+
: ProjectTmp.projectOf({ root: opts.projectRoot });
|
|
355
355
|
};
|
|
356
356
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
patterns
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const start = resolve(opts.input.cwd ?? opts.projectRoot);
|
|
380
|
-
// `$PWD` is the call's folder only when the host said which one it is; otherwise the hook's own `PWD` stays the fallback.
|
|
381
|
-
const startPwd = opts.input.cwd === undefined ? undefined : start;
|
|
382
|
-
const tmp = commandTmpdirOf({ env, projectRoot: opts.projectRoot });
|
|
383
|
-
const targets: ITarget[] = [];
|
|
384
|
-
|
|
385
|
-
if (FILE_TOOLS.has(opts.input.tool) && opts.input.filePath !== undefined) {
|
|
386
|
-
targets.push({
|
|
387
|
-
word: opts.input.filePath,
|
|
388
|
-
base: start,
|
|
389
|
-
pwd: startPwd,
|
|
390
|
-
message: `${opts.input.tool} writes ${opts.input.filePath}`,
|
|
357
|
+
export class OutsideGuard {
|
|
358
|
+
/**
|
|
359
|
+
* Every file, worktree, clone or temp file `input` would create outside the project. Files a package
|
|
360
|
+
* manager, a runtime or the agent tool manage themselves are allowed (`toolOwnedPaths`, extending the
|
|
361
|
+
* defaults); pointing `TMPDIR` or `mktemp` at the system temp directory is not. It reads common
|
|
362
|
+
* forms - redirects, mkdir, cp, mv, tee, curl -o, git clone, git worktree add, mktemp, `cd` - and is a
|
|
363
|
+
* guard against drift, not a sandbox: a path it cannot work out (an unset variable, a glob) passes.
|
|
364
|
+
*/
|
|
365
|
+
static inspect(opts: {
|
|
366
|
+
input: IManifestHookInput;
|
|
367
|
+
projectRoot: string;
|
|
368
|
+
toolOwnedPaths?: string[];
|
|
369
|
+
home?: string;
|
|
370
|
+
env?: TEnvironment;
|
|
371
|
+
}): IOutsideHit[] {
|
|
372
|
+
const env = opts.env ?? process.env;
|
|
373
|
+
const home = opts.home ?? env.HOME ?? '';
|
|
374
|
+
const root = realOf({ path: resolve(opts.projectRoot) });
|
|
375
|
+
const patterns = allowPatterns({
|
|
376
|
+
patterns: [...HookConstants.TOOL_OWNED_PATHS, ...(opts.toolOwnedPaths ?? [])],
|
|
377
|
+
home,
|
|
378
|
+
env,
|
|
391
379
|
});
|
|
392
|
-
|
|
380
|
+
const start = resolve(opts.input.cwd ?? opts.projectRoot);
|
|
381
|
+
// `$PWD` is the call's folder only when the host said which one it is; otherwise the hook's own `PWD` stays the fallback.
|
|
382
|
+
const startPwd = opts.input.cwd === undefined ? undefined : start;
|
|
383
|
+
const tmp = commandTmpdirOf({ env, projectRoot: opts.projectRoot });
|
|
384
|
+
const targets: ITarget[] = [];
|
|
385
|
+
|
|
386
|
+
if (FILE_TOOLS.has(opts.input.tool) && opts.input.filePath !== undefined) {
|
|
387
|
+
targets.push({
|
|
388
|
+
word: opts.input.filePath,
|
|
389
|
+
base: start,
|
|
390
|
+
pwd: startPwd,
|
|
391
|
+
message: `${opts.input.tool} writes ${opts.input.filePath}`,
|
|
392
|
+
});
|
|
393
|
+
}
|
|
393
394
|
|
|
394
|
-
|
|
395
|
+
let isUnread = false;
|
|
395
396
|
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
397
|
+
if (opts.input.command !== undefined) {
|
|
398
|
+
let base = start;
|
|
399
|
+
let pwd = startPwd;
|
|
399
400
|
|
|
400
|
-
|
|
401
|
+
const parsed = ShellParser.parseChecked({ command: opts.input.command });
|
|
401
402
|
|
|
402
|
-
|
|
403
|
+
isUnread = parsed.isOverBudget;
|
|
403
404
|
|
|
404
|
-
|
|
405
|
-
|
|
405
|
+
for (const command of parsed.commands) {
|
|
406
|
+
const program = ShellParser.programOf({ command });
|
|
406
407
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
408
|
+
if (ShellParser.basenameOf({ word: program.name }) === 'cd') {
|
|
409
|
+
const [destination] = positional({ args: program.args });
|
|
410
|
+
const expanded =
|
|
411
|
+
destination === undefined
|
|
412
|
+
? undefined
|
|
413
|
+
: expandPath({ word: destination, home, env, cwd: pwd });
|
|
413
414
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
415
|
+
base = expanded === undefined ? base : resolve(base, expanded);
|
|
416
|
+
// A `cd` the guard cannot work out leaves the shell's folder unknown.
|
|
417
|
+
pwd = expanded === undefined ? undefined : base;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
419
420
|
|
|
420
|
-
|
|
421
|
+
targets.push(...targetsOf({ command, base, tmp }).map((target) => ({ ...target, pwd })));
|
|
422
|
+
}
|
|
421
423
|
}
|
|
422
|
-
}
|
|
423
424
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
425
|
+
// Part of the line was not read: never an allow.
|
|
426
|
+
const hits: IOutsideHit[] = isUnread
|
|
427
|
+
? [
|
|
428
|
+
{
|
|
429
|
+
path: '(the command line)',
|
|
430
|
+
message:
|
|
431
|
+
'this command line is larger, or nests deeper, than the guard reads, so it could not be checked',
|
|
432
|
+
isAgentToolScratchpad: false,
|
|
433
|
+
},
|
|
434
|
+
]
|
|
435
|
+
: [];
|
|
436
|
+
|
|
437
|
+
for (const target of targets) {
|
|
438
|
+
const expanded = expandPath({ word: target.word, home, env, cwd: target.pwd });
|
|
439
|
+
|
|
440
|
+
if (expanded === undefined) {
|
|
441
|
+
continue;
|
|
442
|
+
}
|
|
442
443
|
|
|
443
|
-
|
|
444
|
+
const path = realOf({ path: resolve(target.base, expanded) });
|
|
444
445
|
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
path,
|
|
448
|
-
message: target.message,
|
|
449
|
-
isAgentToolScratchpad: matchesAny({
|
|
446
|
+
if (!isInside({ path, root }) && !matchesAny({ path, patterns })) {
|
|
447
|
+
hits.push({
|
|
450
448
|
path,
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
449
|
+
message: target.message,
|
|
450
|
+
isAgentToolScratchpad: matchesAny({
|
|
451
|
+
path,
|
|
452
|
+
patterns: HookConstants.AGENT_TOOL_SCRATCHPAD_PATTERNS,
|
|
453
|
+
}),
|
|
454
|
+
});
|
|
455
|
+
}
|
|
454
456
|
}
|
|
455
|
-
}
|
|
456
457
|
|
|
457
|
-
|
|
458
|
-
}
|
|
458
|
+
return hits;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
@@ -2,8 +2,8 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import { basename, dirname, isAbsolute, join, normalize, relative, sep } from 'node:path';
|
|
3
3
|
import { GuardDecisions, HookConstants, PackageVerdictKinds } from './common/index.ts';
|
|
4
4
|
import type { IManifestHookInput, TPackageVerdictKind } from './common/index.ts';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { HookDecision } from './decision.ts';
|
|
6
|
+
import { LayoutFolder, LayoutKeys } from '../common/layout-folder.ts';
|
|
7
7
|
|
|
8
8
|
const MANIFEST_FILE = '.agents/vulcan.manifest.json';
|
|
9
9
|
const PACKAGE_FILE = 'package.json';
|
|
@@ -85,7 +85,7 @@ const readProject = (opts: { start: string }): IProjectView | undefined => {
|
|
|
85
85
|
// The manifest is read through the same validator as the config: a folder that is not one is dropped.
|
|
86
86
|
if (isRecord(layoutHolder)) {
|
|
87
87
|
for (const key of LayoutKeys.MANAGED) {
|
|
88
|
-
const folders =
|
|
88
|
+
const folders = LayoutFolder.valid({ value: layoutHolder.value[key] });
|
|
89
89
|
|
|
90
90
|
if (folders.length > 0) {
|
|
91
91
|
layout[key] = folders;
|
|
@@ -131,93 +131,96 @@ const newPackageOf = (opts: {
|
|
|
131
131
|
const appCommand = (opts: { preset: IRecordedPreset; name: string; folderFlag: string }): string =>
|
|
132
132
|
`${ADD} --preset ${opts.preset.spec} --app ${opts.name}${opts.folderFlag}${opts.preset.side === 'frontend' ? ' --api <backend app> | --no-api' : ''}`;
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
input: IManifestHookInput
|
|
141
|
-
|
|
142
|
-
const { tool, filePath, cwd } = opts.input;
|
|
143
|
-
|
|
144
|
-
if (tool !== 'Write' || filePath === undefined || basename(filePath) !== PACKAGE_FILE) {
|
|
145
|
-
return undefined;
|
|
146
|
-
}
|
|
134
|
+
export class PackageGuard {
|
|
135
|
+
/**
|
|
136
|
+
* Whether this tool call creates the `package.json` of a new app or shared package in one of the
|
|
137
|
+
* project's layout folders. A real `vulcan add` command for that folder makes it a `deny`; with no
|
|
138
|
+
* preset behind the folder it is only a `warn`: the guard never blocks without a command to offer.
|
|
139
|
+
*/
|
|
140
|
+
static inspectWrite(opts: { input: IManifestHookInput }): IPackageVerdict | undefined {
|
|
141
|
+
const { tool, filePath, cwd } = opts.input;
|
|
147
142
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
143
|
+
if (tool !== 'Write' || filePath === undefined || basename(filePath) !== PACKAGE_FILE) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
151
146
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
const absolute = normalize(
|
|
148
|
+
isAbsolute(filePath) ? filePath : join(cwd ?? process.cwd(), filePath),
|
|
149
|
+
);
|
|
155
150
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
151
|
+
if (absolute.split(sep).includes(NODE_MODULES) || existsSync(absolute)) {
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
159
154
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
155
|
+
const project = readProject({ start: dirname(absolute) });
|
|
156
|
+
const created =
|
|
157
|
+
project === undefined ? undefined : newPackageOf({ root: project.root, path: absolute });
|
|
163
158
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
159
|
+
if (project === undefined || created === undefined) {
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
167
162
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
163
|
+
const entry = Object.entries(project.layout).find(([, folders]) =>
|
|
164
|
+
folders.includes(created.folder),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
if (entry === undefined) {
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const [key, folders] = entry;
|
|
172
|
+
const isLib = key === 'shared';
|
|
173
|
+
const what = isLib ? 'lib' : `${key} app`;
|
|
174
|
+
// A side with several folders needs the one it is written in named, so the command is exact.
|
|
175
|
+
const folderFlag =
|
|
176
|
+
folders.length > 1 ? ` ${isLib ? '--dir' : `--${key}-dir`} ${created.folder}` : '';
|
|
177
|
+
const commands = isLib
|
|
178
|
+
? [
|
|
179
|
+
...project.presets
|
|
180
|
+
.filter((preset) => preset.lib)
|
|
181
|
+
.map((preset) => `${ADD} --preset ${preset.spec} --lib ${created.name}${folderFlag}`),
|
|
182
|
+
...project.presets
|
|
183
|
+
.filter((preset) => preset.shared)
|
|
184
|
+
.map(
|
|
185
|
+
(preset) => `${ADD} --preset ${preset.spec} --shared ${created.name}${folderFlag}`,
|
|
186
|
+
),
|
|
187
|
+
]
|
|
188
|
+
: project.presets
|
|
189
|
+
.filter((preset) => preset.side === key)
|
|
190
|
+
.map((preset) => appCommand({ preset, name: created.name, folderFlag }));
|
|
191
|
+
|
|
192
|
+
if (commands.length > 0) {
|
|
193
|
+
return {
|
|
194
|
+
kind: PackageVerdictKinds.DENY,
|
|
195
|
+
message: `${created.folder}/${created.name} is a new ${what}: create it with a preset, not by hand - run ${commands.join(' or ')} (ask atlas \`presets\` for the choice); ${NO_HAND_WRITING}`,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
171
198
|
|
|
172
|
-
const [key, folders] = entry;
|
|
173
|
-
const isLib = key === 'shared';
|
|
174
|
-
const what = isLib ? 'lib' : `${key} app`;
|
|
175
|
-
// A side with several folders needs the one it is written in named, so the command is exact.
|
|
176
|
-
const folderFlag =
|
|
177
|
-
folders.length > 1 ? ` ${isLib ? '--dir' : `--${key}-dir`} ${created.folder}` : '';
|
|
178
|
-
const commands = isLib
|
|
179
|
-
? [
|
|
180
|
-
...project.presets
|
|
181
|
-
.filter((preset) => preset.lib)
|
|
182
|
-
.map((preset) => `${ADD} --preset ${preset.spec} --lib ${created.name}${folderFlag}`),
|
|
183
|
-
...project.presets
|
|
184
|
-
.filter((preset) => preset.shared)
|
|
185
|
-
.map((preset) => `${ADD} --preset ${preset.spec} --shared ${created.name}${folderFlag}`),
|
|
186
|
-
]
|
|
187
|
-
: project.presets
|
|
188
|
-
.filter((preset) => preset.side === key)
|
|
189
|
-
.map((preset) => appCommand({ preset, name: created.name, folderFlag }));
|
|
190
|
-
|
|
191
|
-
if (commands.length > 0) {
|
|
192
199
|
return {
|
|
193
|
-
kind: PackageVerdictKinds.
|
|
194
|
-
message:
|
|
200
|
+
kind: PackageVerdictKinds.WARN,
|
|
201
|
+
message:
|
|
202
|
+
project.presets.length === 0
|
|
203
|
+
? `${created.folder}/${created.name} looks like a new ${what} and this project recorded no preset: ask the user which preset to use (\`vulcan add --preset <name|file:path> --app <name>\`, --lib <name> for a library other apps import, --shared <name> for a side-neutral package); ${NO_HAND_WRITING}`
|
|
204
|
+
: `${created.folder}/${created.name} looks like a new ${what} but no recorded preset makes a ${what}: ask the user how it should be made; ${NO_HAND_WRITING}`,
|
|
195
205
|
};
|
|
196
206
|
}
|
|
197
207
|
|
|
198
|
-
|
|
199
|
-
kind
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
output: {
|
|
208
|
+
static buildDecision(opts: { verdict: IPackageVerdict }) {
|
|
209
|
+
return opts.verdict.kind === PackageVerdictKinds.DENY
|
|
210
|
+
? HookDecision.forHost({
|
|
211
|
+
output: {
|
|
212
|
+
hookSpecificOutput: {
|
|
213
|
+
hookEventName: HookConstants.PRE_TOOL_USE,
|
|
214
|
+
permissionDecision: GuardDecisions.DENY,
|
|
215
|
+
permissionDecisionReason: opts.verdict.message,
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
})
|
|
219
|
+
: {
|
|
211
220
|
hookSpecificOutput: {
|
|
212
221
|
hookEventName: HookConstants.PRE_TOOL_USE,
|
|
213
|
-
|
|
214
|
-
permissionDecisionReason: opts.verdict.message,
|
|
222
|
+
additionalContext: opts.verdict.message,
|
|
215
223
|
},
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
hookSpecificOutput: {
|
|
220
|
-
hookEventName: HookConstants.PRE_TOOL_USE,
|
|
221
|
-
additionalContext: opts.verdict.message,
|
|
222
|
-
},
|
|
223
|
-
};
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HookConstants } from './common/index.ts';
|
|
2
|
-
import {
|
|
2
|
+
import { ShellParser } from './shell.ts';
|
|
3
3
|
|
|
4
4
|
/** `python`, `python3`, `python3.12`, `pip`, `pip3`: the program a command runs, not a word it mentions. */
|
|
5
5
|
const SCRIPTING_PROGRAM = /^(?:python\d*(?:\.\d+)?|pip\d*(?:\.\d+)?)$/;
|
|
@@ -15,17 +15,22 @@ const isExistenceProbe = (opts: { words: string[] }): boolean => {
|
|
|
15
15
|
return at !== -1 && ['-v', '-V'].includes(opts.words[at + 1] ?? '');
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
.
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
export class ScriptingGuard {
|
|
19
|
+
/** The scripting programs a command runs, in order: a mention in an argument, a message, a heredoc or an existence probe is not one. */
|
|
20
|
+
static inspect(opts: { command: string }): string[] {
|
|
21
|
+
return ShellParser.parse({ command: opts.command })
|
|
22
|
+
.filter((command) => !isExistenceProbe({ words: command.words }))
|
|
23
|
+
.map((command) => ShellParser.basenameOf({ word: ShellParser.programOf({ command }).name }))
|
|
24
|
+
.filter((name) => SCRIPTING_PROGRAM.test(name));
|
|
25
|
+
}
|
|
24
26
|
|
|
25
|
-
/** The PreToolUse answer that adds the advice to the model's context and lets the call through. */
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
27
|
+
/** The PreToolUse answer that adds the advice to the model's context and lets the call through. */
|
|
28
|
+
static buildAdvice() {
|
|
29
|
+
return {
|
|
30
|
+
hookSpecificOutput: {
|
|
31
|
+
hookEventName: HookConstants.PRE_TOOL_USE,
|
|
32
|
+
additionalContext: SCRIPTING_ADVICE,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|