@venizia/vulcan 0.2.0-8 → 0.2.0-9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/vulcan",
3
- "version": "0.2.0-8",
3
+ "version": "0.2.0-9",
4
4
  "description": "VULCAN - one setup, one workflow for every project: init, sync, doctor, upgrade, and `vulcan x` for the shipped tools. Bun-only.",
5
5
  "homepage": "https://github.com/VENIZIA-AI/vulcan/tree/main/packages/cli",
6
6
  "repository": {
@@ -44,8 +44,8 @@
44
44
  "test": "NODE_ENV=test bun test --env-file=.env.test"
45
45
  },
46
46
  "dependencies": {
47
- "@venizia/vulcan-atlas": "0.2.0-8",
48
- "@venizia/vulcan-okf": "0.2.0-8",
47
+ "@venizia/vulcan-atlas": "0.2.0-9",
48
+ "@venizia/vulcan-okf": "0.2.0-9",
49
49
  "zod": "^4.5.4"
50
50
  },
51
51
  "devDependencies": {
@@ -34,6 +34,12 @@ interface IFinding {
34
34
  /** The whole form is one of the strict read-only forms. */
35
35
  strict: boolean;
36
36
  redirect: boolean;
37
+ /** The target is not a remote login: only a host the project listed matters, any other is left alone. */
38
+ listedOnly?: boolean;
39
+ /** The target is the current ambient one (a kubeconfig context): read on a host, it is that host's own. */
40
+ ambient?: boolean;
41
+ /** An ssh's remote command: it runs on the far side, and may hop on. */
42
+ remote?: string[];
37
43
  }
38
44
 
39
45
  // --- host matching ---
@@ -171,6 +177,11 @@ const tokenize = (opts: { command: string }): ISegment[] => {
171
177
  } else if (REDIRECTS.has(char)) {
172
178
  redirect = true;
173
179
  endWord();
180
+
181
+ // Input from a file or a string is kept as a word, so a shell fed that way is seen reading it.
182
+ if (char === '<') {
183
+ words.push(char);
184
+ }
174
185
  } else {
175
186
  current += char;
176
187
  started = true;
@@ -196,8 +207,37 @@ const hostOf = (opts: { value: string }): string => {
196
207
  .toLowerCase();
197
208
  };
198
209
 
210
+ /** The host of `scheme://[user@]host[:port]/path` or `[user@]host[:port]/path`; `undefined` for a socket or nothing. */
211
+ const authorityOf = (opts: { value: string }): string | undefined => {
212
+ const rest = /[a-z][a-z0-9+.-]*:\/\/(.*)$/i.exec(opts.value)?.[1] ?? opts.value;
213
+ const host = /^(?:[^@/?#]*@)?(\[[^\]]+\]|[^/:?#\s]+)/.exec(rest)?.[1];
214
+
215
+ return host === undefined
216
+ ? undefined
217
+ : host
218
+ .replace(/^\[|\]$/g, '')
219
+ .replace(/\.$/, '')
220
+ .toLowerCase();
221
+ };
222
+
199
223
  const ENVIRONMENT_ASSIGNMENT = /^[A-Za-z_][A-Za-z0-9_]*=/;
200
224
 
225
+ /** Words that open a command inside a loop, a condition or a group: the command is what follows. */
226
+ const SHELL_KEYWORDS = new Set([
227
+ 'do',
228
+ 'then',
229
+ 'else',
230
+ 'elif',
231
+ 'if',
232
+ 'while',
233
+ 'until',
234
+ '!',
235
+ '{',
236
+ 'coproc',
237
+ ]);
238
+
239
+ const HTTP_CLIENTS = new Set(['curl', 'wget', 'http', 'https', 'httpie', 'xh', 'xhs']);
240
+
201
241
  /** Programs that run the rest of their line; the value is the options that take an argument. */
202
242
  const WRAPPERS: Record<string, Set<string>> = {
203
243
  sudo: new Set(['-u', '-g', '-h', '-p', '-C', '-D', '-r', '-t', '-U']),
@@ -413,6 +453,7 @@ const analyzeSsh = (opts: { program: string; words: string[] }): IFinding => {
413
453
  command.length > 0 &&
414
454
  READ_ONLY_REMOTE.test(command.join(' ')),
415
455
  redirect: false,
456
+ ...(opts.program === 'ssh' && command.length > 0 ? { remote: command } : {}),
416
457
  };
417
458
  };
418
459
 
@@ -540,7 +581,10 @@ const analyzeKubernetes = (opts: { program: string; words: string[] }): IFinding
540
581
  const targets = optionValues({ words: opts.words, names: KUBERNETES_TARGET_OPTIONS });
541
582
 
542
583
  if (targets.length === 0) {
543
- return unreadable({ why: `${opts.program} uses the current kubeconfig context` });
584
+ return {
585
+ ...unreadable({ why: `${opts.program} uses the current kubeconfig context` }),
586
+ ambient: true,
587
+ };
544
588
  }
545
589
 
546
590
  const hosts = targets.map(target =>
@@ -597,6 +641,72 @@ const analyzeNetwork = (opts: { words: string[] }): IFinding => {
597
641
  : { hosts: [hostOf({ value: positionals[0] ?? '' })], strict: false, redirect: false };
598
642
  };
599
643
 
644
+ /** `curl`, `wget`, `http`: a URL or bare address names a host; only a listed one matters. */
645
+ const analyzeHttp = (opts: { words: string[] }): IFinding => {
646
+ const hosts = opts.words.slice(1).flatMap(word => {
647
+ const candidate = /\s/.test(word) ? /[a-z][a-z0-9+.-]*:\/\/\S*/i.exec(word)?.[0] : word;
648
+
649
+ if (candidate === undefined || (candidate.startsWith('-') && !candidate.includes('://'))) {
650
+ return [];
651
+ }
652
+
653
+ const host = authorityOf({ value: candidate });
654
+
655
+ return host === undefined ? [] : [host];
656
+ });
657
+
658
+ return { hosts, strict: false, redirect: false, listedOnly: true };
659
+ };
660
+
661
+ /** `-H`/`--host` name the daemon; a context or `docker context` resolves elsewhere and cannot be read. */
662
+ const analyzeDocker = (opts: { words: string[] }): IFinding => {
663
+ const hosts: string[] = [];
664
+
665
+ for (let index = 1; index < opts.words.length; index++) {
666
+ const word = opts.words[index] ?? '';
667
+
668
+ if (/^(?:-c|--context)(?:=|$)/.test(word) || word === 'context') {
669
+ return unreadable({ why: 'docker is pointed at another host or context' });
670
+ }
671
+
672
+ const long = /^--host(?:=(.*))?$/.exec(word);
673
+ const short = /^-H(.*)$/.exec(word);
674
+ const given = long ?? short;
675
+
676
+ if (given === null) {
677
+ continue;
678
+ }
679
+
680
+ const value = given[1] ?? '';
681
+ const host = authorityOf({ value: value === '' ? (opts.words[++index] ?? '') : value });
682
+
683
+ if (host !== undefined) {
684
+ hosts.push(host);
685
+ }
686
+ }
687
+
688
+ return { hosts, strict: false, redirect: false };
689
+ };
690
+
691
+ /** Whether a shell with no `-c` takes its commands from its input: no script file, or `-s`. */
692
+ const readsItsInput = (opts: { words: string[] }): boolean => {
693
+ if (opts.words.includes('<')) {
694
+ return true;
695
+ }
696
+
697
+ for (const word of opts.words.slice(1)) {
698
+ if (!word.startsWith('-')) {
699
+ return false;
700
+ }
701
+
702
+ if (/^-[a-z]*s[a-z]*$/.test(word)) {
703
+ return true;
704
+ }
705
+ }
706
+
707
+ return true;
708
+ };
709
+
600
710
  const MAXIMUM_DEPTH = 4;
601
711
 
602
712
  /** Skips a wrapper's own options (and the values its options take); the words after are its command. */
@@ -631,7 +741,10 @@ const analyzeWords = (opts: {
631
741
  }): IFinding[] => {
632
742
  const words = [...opts.words];
633
743
 
634
- while (words[0] !== undefined && ENVIRONMENT_ASSIGNMENT.test(words[0])) {
744
+ while (
745
+ words[0] !== undefined &&
746
+ (ENVIRONMENT_ASSIGNMENT.test(words[0]) || SHELL_KEYWORDS.has(words[0]))
747
+ ) {
635
748
  words.shift();
636
749
  }
637
750
 
@@ -663,12 +776,16 @@ const analyzeWords = (opts: {
663
776
  if (SHELLS.has(program)) {
664
777
  const flag = words.findIndex((word, index) => index > 0 && /^-[a-z]*c[a-z]*$/.test(word));
665
778
 
666
- return flag === -1
667
- ? []
668
- : opts.recurse({
669
- command: words[flag + 1] ?? '',
670
- depth: opts.depth + 1,
671
- });
779
+ if (flag !== -1) {
780
+ return opts.recurse({
781
+ command: words[flag + 1] ?? '',
782
+ depth: opts.depth + 1,
783
+ });
784
+ }
785
+
786
+ return readsItsInput({ words })
787
+ ? [unreadable({ why: `${program} runs commands it reads from its input` })]
788
+ : [];
672
789
  }
673
790
 
674
791
  if (program === 'find') {
@@ -689,13 +806,23 @@ const analyzeWords = (opts: {
689
806
  }
690
807
 
691
808
  if (program === 'docker') {
692
- return words.some(word => /^(?:-H|--host|-c|--context)(?:=|$)/.test(word) || word === 'context')
693
- ? [unreadable({ why: 'docker is pointed at another host or context' })]
694
- : [];
809
+ return [analyzeDocker({ words })];
810
+ }
811
+
812
+ if (HTTP_CLIENTS.has(program)) {
813
+ return [analyzeHttp({ words })];
695
814
  }
696
815
 
697
816
  if (program in SSH_ARGUMENT_LETTERS && program !== 'scp') {
698
- return [analyzeSsh({ program, words })];
817
+ const finding = analyzeSsh({ program, words });
818
+ const nested =
819
+ finding.remote === undefined
820
+ ? []
821
+ : opts
822
+ .recurse({ command: finding.remote.join(' '), depth: opts.depth + 1 })
823
+ .filter(inner => inner.ambient !== true);
824
+
825
+ return [finding, ...nested];
699
826
  }
700
827
 
701
828
  if (program === 'scp' || program === 'rsync' || program === 'sshfs') {
@@ -728,9 +855,9 @@ const analyzeCommand = (opts: { command: string; depth: number }): IFinding[] =>
728
855
  ? {
729
856
  ...finding,
730
857
  unreadable: finding.unreadable ?? 'a substitution runs inside it',
731
- redirect: segment.redirect,
858
+ redirect: finding.redirect || segment.redirect,
732
859
  }
733
- : { ...finding, redirect: segment.redirect },
860
+ : { ...finding, redirect: finding.redirect || segment.redirect },
734
861
  );
735
862
  });
736
863
 
@@ -740,7 +867,7 @@ const trustedMessage = (opts: { host: string; policy: IRemoteHostsPolicy }): str
740
867
  `reaching '${opts.host}', which is not in remoteHosts.trusted (list it there${opts.policy.localFile === undefined ? '' : `, or in ${opts.policy.localFile} for yourself`}); a remoteHosts.readOnly host passes only the strict read-only forms`;
741
868
 
742
869
  const readOnlyMessage = (opts: { host: string }): string =>
743
- `'${opts.host}' is a remoteHosts.readOnly host: only a strict read-only form passes (uptime, df -h, cat <path>, scp/rsync from it, kubectl get), and this command is not one`;
870
+ `'${opts.host}' is a remoteHosts.readOnly host: only a strict read-only form passes (uptime, df -h, cat <path>, scp/rsync from it, kubectl get|describe|logs|top), and this command is not one`;
744
871
 
745
872
  /** Why each host this command reaches may not be reached without asking; empty means nothing to ask. */
746
873
  export const inspectRemoteCommand = (opts: {
@@ -780,7 +907,9 @@ export const inspectRemoteCommand = (opts: {
780
907
  continue;
781
908
  }
782
909
 
783
- ask(trustedMessage({ host, policy }));
910
+ if (finding.listedOnly !== true) {
911
+ ask(trustedMessage({ host, policy }));
912
+ }
784
913
  }
785
914
  }
786
915