@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.
Files changed (141) hide show
  1. package/base/extensions/vulcan-guards.ts +48 -41
  2. package/base/hooks/antigravity-guards.ts +2 -2
  3. package/base/hooks/codex-guards.ts +15 -5
  4. package/base/hooks/guard-git.ts +8 -8
  5. package/base/hooks/guard-manifest.ts +4 -5
  6. package/base/hooks/guard-outside.ts +8 -8
  7. package/base/hooks/guard-package.ts +5 -6
  8. package/base/hooks/guard-remote-hosts.ts +6 -7
  9. package/base/hooks/guard-scripting.ts +5 -6
  10. package/base/hooks/guard-writes.ts +8 -9
  11. package/base/hooks/post-tool.ts +2 -2
  12. package/base/hooks/prompt-submit.ts +2 -2
  13. package/base/hooks/session-start.ts +3 -3
  14. package/base/hooks/stop.ts +2 -2
  15. package/base/hooks/subagent-start.ts +2 -2
  16. package/base/skills/docs-update/SKILL.md +4 -2
  17. package/base/skills/visualize-work/SKILL.md +9 -0
  18. package/package.json +3 -3
  19. package/src/agents/atlas-block.ts +43 -43
  20. package/src/agents/codex-hooks.ts +45 -43
  21. package/src/agents/detect.ts +19 -16
  22. package/src/agents/exclude.ts +96 -97
  23. package/src/agents/hooks-json.ts +38 -36
  24. package/src/agents/local.ts +46 -43
  25. package/src/agents/prompt.ts +45 -42
  26. package/src/agents/render.ts +201 -195
  27. package/src/agents/resolve.ts +133 -134
  28. package/src/agents/table.ts +12 -8
  29. package/src/commands/add.command.ts +2 -2
  30. package/src/commands/agents.command.ts +11 -17
  31. package/src/commands/clean.command.ts +6 -6
  32. package/src/commands/doctor.command.ts +4 -4
  33. package/src/commands/init.command.ts +12 -8
  34. package/src/commands/preset.command.ts +2 -2
  35. package/src/commands/profile.command.ts +42 -49
  36. package/src/commands/sync.command.ts +109 -111
  37. package/src/commands/upgrade.command.ts +80 -75
  38. package/src/commands/visualize.command.ts +7 -13
  39. package/src/commands/x.command.ts +55 -50
  40. package/src/common/format.ts +23 -21
  41. package/src/common/json.ts +8 -5
  42. package/src/common/layout-folder.ts +94 -91
  43. package/src/common/paths.ts +14 -12
  44. package/src/config/loader.ts +52 -49
  45. package/src/config/packages.ts +14 -11
  46. package/src/config/schema.ts +3 -3
  47. package/src/create/add-app.ts +519 -509
  48. package/src/create/add-lib.ts +237 -240
  49. package/src/create/bunfig.ts +26 -23
  50. package/src/create/checks.ts +36 -34
  51. package/src/create/diff.ts +21 -23
  52. package/src/create/dockerignore.ts +26 -24
  53. package/src/create/files.ts +7 -5
  54. package/src/create/init-monorepo.ts +75 -80
  55. package/src/create/lib-preset.ts +59 -63
  56. package/src/create/manifest-json.ts +10 -4
  57. package/src/create/names.ts +217 -210
  58. package/src/create/next.ts +26 -23
  59. package/src/create/plan.ts +15 -12
  60. package/src/create/preset-diff.ts +301 -303
  61. package/src/create/preset-menu.ts +38 -32
  62. package/src/create/preset.ts +202 -197
  63. package/src/create/process.ts +79 -72
  64. package/src/create/scratch.ts +48 -49
  65. package/src/create/workspace.ts +404 -396
  66. package/src/doctor/checks.ts +1027 -1014
  67. package/src/doctor/makefile.ts +17 -13
  68. package/src/doctor/runner.ts +88 -118
  69. package/src/doctor/skills.ts +97 -95
  70. package/src/doctor/tags.ts +42 -37
  71. package/src/hooks/codex-patch.ts +25 -22
  72. package/src/hooks/command-view.ts +44 -39
  73. package/src/hooks/decision.ts +37 -37
  74. package/src/hooks/guard-git.ts +51 -49
  75. package/src/hooks/guard-manifest.ts +58 -55
  76. package/src/hooks/guard-outside.ts +93 -91
  77. package/src/hooks/guard-package.ts +82 -79
  78. package/src/hooks/guard-scripting.ts +19 -14
  79. package/src/hooks/guard-writes.ts +154 -149
  80. package/src/hooks/owner-reply.ts +127 -127
  81. package/src/hooks/post-tool.ts +94 -93
  82. package/src/hooks/project-guards.ts +65 -62
  83. package/src/hooks/project-tmp.ts +27 -24
  84. package/src/hooks/remote-hosts.ts +153 -130
  85. package/src/hooks/session-digest.ts +98 -101
  86. package/src/hooks/shell.ts +509 -499
  87. package/src/hooks/subagent-card.ts +11 -7
  88. package/src/hooks/trusted-scripts.ts +106 -104
  89. package/src/init/scaffold.ts +135 -132
  90. package/src/local/clean.ts +38 -36
  91. package/src/local/format.ts +21 -17
  92. package/src/local/scan.ts +144 -138
  93. package/src/manifest/render.ts +110 -104
  94. package/src/owner/card.ts +51 -46
  95. package/src/owner/profile.ts +99 -93
  96. package/src/owner/reply-switch.ts +9 -6
  97. package/src/owner/shape.ts +71 -69
  98. package/src/owner/survey.ts +173 -171
  99. package/src/owner/view.ts +62 -59
  100. package/src/owner/violations.ts +119 -123
  101. package/src/rules/base.ts +15 -11
  102. package/src/rules/parser.ts +39 -32
  103. package/src/rules/slots.ts +8 -6
  104. package/src/signals/claims.ts +30 -28
  105. package/src/signals/classify.ts +38 -33
  106. package/src/signals/loop.ts +39 -37
  107. package/src/signals/state.ts +79 -81
  108. package/src/skills/frontmatter.ts +28 -28
  109. package/src/sync/agent-files.ts +217 -199
  110. package/src/sync/agent-removal.ts +56 -59
  111. package/src/sync/atlas-block.ts +45 -43
  112. package/src/sync/base-rules.ts +32 -30
  113. package/src/sync/claude-launch.ts +36 -34
  114. package/src/sync/exclude.ts +77 -69
  115. package/src/sync/local-choice.ts +50 -47
  116. package/src/sync/planner.ts +59 -61
  117. package/src/sync/prune.ts +52 -48
  118. package/src/sync/settings.ts +166 -167
  119. package/src/ui/capability.ts +12 -7
  120. package/src/ui/keyboard.ts +38 -38
  121. package/src/ui/prompt.ts +79 -77
  122. package/src/visualize/assets.ts +33 -24
  123. package/src/visualize/charts.ts +179 -176
  124. package/src/visualize/compare-css.ts +3 -2
  125. package/src/visualize/compare-render.ts +9 -7
  126. package/src/visualize/diagrams.ts +189 -174
  127. package/src/visualize/grid-span.ts +34 -0
  128. package/src/visualize/icons.ts +7 -5
  129. package/src/visualize/kinds-render.ts +50 -45
  130. package/src/visualize/kinds-validate.ts +12 -10
  131. package/src/visualize/labels.ts +21 -17
  132. package/src/visualize/layout.ts +112 -97
  133. package/src/visualize/page.ts +92 -104
  134. package/src/visualize/render.ts +143 -140
  135. package/src/visualize/sections.ts +395 -384
  136. package/src/visualize/sources.ts +2 -2
  137. package/src/visualize/theme.ts +12 -10
  138. package/src/visualize/validate.ts +13 -9
  139. package/src/wiki/anchors.ts +38 -36
  140. package/src/wiki/command.ts +4 -4
  141. 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 { basenameOf, parseShellChecked, programOf } from './shell.ts';
4
+ import { ShellParser } from './shell.ts';
5
5
  import type { ISimpleCommand } from './shell.ts';
6
6
  import { HookConstants } from './common/index.ts';
7
- import { projectTmpOf } from './project-tmp.ts';
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
- : projectTmpOf({ root: opts.projectRoot });
354
+ : ProjectTmp.projectOf({ root: opts.projectRoot });
355
355
  };
356
356
 
357
- /**
358
- * Every file, worktree, clone or temp file `input` would create outside the project. Files a package
359
- * manager, a runtime or the agent tool manage themselves are allowed (`toolOwnedPaths`, extending the
360
- * defaults); pointing `TMPDIR` or `mktemp` at the system temp directory is not. It reads common
361
- * forms - redirects, mkdir, cp, mv, tee, curl -o, git clone, git worktree add, mktemp, `cd` - and is a
362
- * guard against drift, not a sandbox: a path it cannot work out (an unset variable, a glob) passes.
363
- */
364
- export const inspectOutside = (opts: {
365
- input: IManifestHookInput;
366
- projectRoot: string;
367
- toolOwnedPaths?: string[];
368
- home?: string;
369
- env?: TEnvironment;
370
- }): IOutsideHit[] => {
371
- const env = opts.env ?? process.env;
372
- const home = opts.home ?? env.HOME ?? '';
373
- const root = realOf({ path: resolve(opts.projectRoot) });
374
- const patterns = allowPatterns({
375
- patterns: [...HookConstants.TOOL_OWNED_PATHS, ...(opts.toolOwnedPaths ?? [])],
376
- home,
377
- env,
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
- let isUnread = false;
395
+ let isUnread = false;
395
396
 
396
- if (opts.input.command !== undefined) {
397
- let base = start;
398
- let pwd = startPwd;
397
+ if (opts.input.command !== undefined) {
398
+ let base = start;
399
+ let pwd = startPwd;
399
400
 
400
- const parsed = parseShellChecked({ command: opts.input.command });
401
+ const parsed = ShellParser.parseChecked({ command: opts.input.command });
401
402
 
402
- isUnread = parsed.isOverBudget;
403
+ isUnread = parsed.isOverBudget;
403
404
 
404
- for (const command of parsed.commands) {
405
- const program = programOf({ command });
405
+ for (const command of parsed.commands) {
406
+ const program = ShellParser.programOf({ command });
406
407
 
407
- if (basenameOf({ word: program.name }) === 'cd') {
408
- const [destination] = positional({ args: program.args });
409
- const expanded =
410
- destination === undefined
411
- ? undefined
412
- : expandPath({ word: destination, home, env, cwd: pwd });
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
- base = expanded === undefined ? base : resolve(base, expanded);
415
- // A `cd` the guard cannot work out leaves the shell's folder unknown.
416
- pwd = expanded === undefined ? undefined : base;
417
- continue;
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
- targets.push(...targetsOf({ command, base, tmp }).map((target) => ({ ...target, pwd })));
421
+ targets.push(...targetsOf({ command, base, tmp }).map((target) => ({ ...target, pwd })));
422
+ }
421
423
  }
422
- }
423
424
 
424
- // Part of the line was not read: never an allow.
425
- const hits: IOutsideHit[] = isUnread
426
- ? [
427
- {
428
- path: '(the command line)',
429
- message:
430
- 'this command line is larger, or nests deeper, than the guard reads, so it could not be checked',
431
- isAgentToolScratchpad: false,
432
- },
433
- ]
434
- : [];
435
-
436
- for (const target of targets) {
437
- const expanded = expandPath({ word: target.word, home, env, cwd: target.pwd });
438
-
439
- if (expanded === undefined) {
440
- continue;
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
- const path = realOf({ path: resolve(target.base, expanded) });
444
+ const path = realOf({ path: resolve(target.base, expanded) });
444
445
 
445
- if (!isInside({ path, root }) && !matchesAny({ path, patterns })) {
446
- hits.push({
447
- path,
448
- message: target.message,
449
- isAgentToolScratchpad: matchesAny({
446
+ if (!isInside({ path, root }) && !matchesAny({ path, patterns })) {
447
+ hits.push({
450
448
  path,
451
- patterns: HookConstants.AGENT_TOOL_SCRATCHPAD_PATTERNS,
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
- return hits;
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 { forHost } from './decision.ts';
6
- import { LayoutKeys, validLayoutFolders } from '../common/layout-folder.ts';
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 = validLayoutFolders({ value: layoutHolder.value[key] });
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
- * Whether this tool call creates the `package.json` of a new app or shared package in one of the
136
- * project's layout folders. A real `vulcan add` command for that folder makes it a `deny`; with no
137
- * preset behind the folder it is only a `warn`: the guard never blocks without a command to offer.
138
- */
139
- export const inspectPackageWrite = (opts: {
140
- input: IManifestHookInput;
141
- }): IPackageVerdict | undefined => {
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
- const absolute = normalize(
149
- isAbsolute(filePath) ? filePath : join(cwd ?? process.cwd(), filePath),
150
- );
143
+ if (tool !== 'Write' || filePath === undefined || basename(filePath) !== PACKAGE_FILE) {
144
+ return undefined;
145
+ }
151
146
 
152
- if (absolute.split(sep).includes(NODE_MODULES) || existsSync(absolute)) {
153
- return undefined;
154
- }
147
+ const absolute = normalize(
148
+ isAbsolute(filePath) ? filePath : join(cwd ?? process.cwd(), filePath),
149
+ );
155
150
 
156
- const project = readProject({ start: dirname(absolute) });
157
- const created =
158
- project === undefined ? undefined : newPackageOf({ root: project.root, path: absolute });
151
+ if (absolute.split(sep).includes(NODE_MODULES) || existsSync(absolute)) {
152
+ return undefined;
153
+ }
159
154
 
160
- if (project === undefined || created === undefined) {
161
- return undefined;
162
- }
155
+ const project = readProject({ start: dirname(absolute) });
156
+ const created =
157
+ project === undefined ? undefined : newPackageOf({ root: project.root, path: absolute });
163
158
 
164
- const entry = Object.entries(project.layout).find(([, folders]) =>
165
- folders.includes(created.folder),
166
- );
159
+ if (project === undefined || created === undefined) {
160
+ return undefined;
161
+ }
167
162
 
168
- if (entry === undefined) {
169
- return undefined;
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.DENY,
194
- 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}`,
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
- return {
199
- kind: PackageVerdictKinds.WARN,
200
- message:
201
- project.presets.length === 0
202
- ? `${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}`
203
- : `${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}`,
204
- };
205
- };
206
-
207
- export const buildPackageDecision = (opts: { verdict: IPackageVerdict }) =>
208
- opts.verdict.kind === PackageVerdictKinds.DENY
209
- ? forHost({
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
- permissionDecision: GuardDecisions.DENY,
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 { basenameOf, parseShell, programOf } from './shell.ts';
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
- /** The scripting programs a command runs, in order: a mention in an argument, a message, a heredoc or an existence probe is not one. */
19
- export const inspectScripting = (opts: { command: string }): string[] =>
20
- parseShell({ command: opts.command })
21
- .filter((command) => !isExistenceProbe({ words: command.words }))
22
- .map((command) => basenameOf({ word: programOf({ command }).name }))
23
- .filter((name) => SCRIPTING_PROGRAM.test(name));
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
- export const buildScriptingAdvice = () => ({
27
- hookSpecificOutput: {
28
- hookEventName: HookConstants.PRE_TOOL_USE,
29
- additionalContext: SCRIPTING_ADVICE,
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
+ }