sentinelayer-cli 0.46.2 → 0.46.3

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": "sentinelayer-cli",
3
- "version": "0.46.2",
3
+ "version": "0.46.3",
4
4
  "description": "Scaffold Sentinelayer spec/prompt/guide artifacts with secure browser auth and token bootstrap.",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -40,6 +40,31 @@ function escapeRegExp(value) {
40
40
  return String(value).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
41
41
  }
42
42
 
43
+ // The CLI's entry points as package.json "bin" declares them (a test keeps the two in step):
44
+ // the scripts node runs, and the command names npm links to them.
45
+ const CLI_ENTRY_SCRIPTS = ["create-sentinelayer.js", "sentinelayer-cli.js", "sl.js"];
46
+ const CLI_COMMAND_NAMES = ["create-sentinelayer", "sentinel", "sentinelayer-cli", "sl-cli", "slc", "sl"];
47
+
48
+ /**
49
+ * The one test of "this command line runs this CLI": an argument that is a path ending in an
50
+ * entry point (a path separator, the entry name, then the end of the argument). So
51
+ * `.../bin/create-sentinelayer.js` counts, but `xcreate-sentinelayer.js`,
52
+ * `create-sentinelayer.json` and a directory named after a command do not.
53
+ *
54
+ * On POSIX, npm links each command name to its script and the kernel hands node the link path
55
+ * (`node /usr/local/bin/sl ...`), so the command names count there too. On Windows npm's shims
56
+ * start node on the script itself, and the sh shim Git Bash runs stays alive as node's parent
57
+ * with only the command name on its command line, so there only the scripts count.
58
+ *
59
+ * The pattern is valid in JavaScript and in .NET (the Windows scan runs it in PowerShell), and
60
+ * writes its quotes as \x22 and \x27 so it can sit inside a quoted PowerShell string.
61
+ */
62
+ function cliEntryPattern(platform) {
63
+ const entries =
64
+ platform === "win32" ? CLI_ENTRY_SCRIPTS : [...CLI_ENTRY_SCRIPTS, ...CLI_COMMAND_NAMES];
65
+ return `[\\\\/](?:${entries.map(escapeRegExp).join("|")})(?=$|[\\s\\x22\\x27])`;
66
+ }
67
+
43
68
  function commandLineFlagValueMatches(commandLine, flagName, expectedValue) {
44
69
  const expected = normalizeString(expectedValue).toLowerCase();
45
70
  if (!expected) return { found: false, matches: true };
@@ -58,15 +83,20 @@ function commandLineFlagValueMatches(commandLine, flagName, expectedValue) {
58
83
  return { found, matches: false };
59
84
  }
60
85
 
61
- function listenerCommandLineMatches(commandLine, { sessionId = "", agentId = "" } = {}) {
86
+ /**
87
+ * Whether a command line is `session listen` for this session and agent, run through any of
88
+ * this CLI's entry points. `platform` is the system the command line was read on.
89
+ */
90
+ export function listenerCommandLineMatches(
91
+ commandLine,
92
+ { sessionId = "", agentId = "", platform = process.platform } = {},
93
+ ) {
62
94
  const rawCommandLine = normalizeString(commandLine);
63
95
  const normalized = normalizeCommandLine(rawCommandLine);
64
96
  if (!normalized) return false;
65
97
  const normalizedSessionId = normalizeString(sessionId).toLowerCase();
66
98
  const normalizedAgentId = normalizeString(agentId).toLowerCase();
67
- const hasCliEntry =
68
- normalized.includes("sentinelayer-cli") ||
69
- /[\\/](?:sl|sentinelayer-cli)\.js\b/.test(normalized);
99
+ const hasCliEntry = new RegExp(cliEntryPattern(platform)).test(normalized);
70
100
  const sessionFlagMatch = commandLineFlagValueMatches(rawCommandLine, "session", normalizedSessionId);
71
101
  const agentFlagMatch = commandLineFlagValueMatches(rawCommandLine, "agent", normalizedAgentId);
72
102
  return (
@@ -98,7 +128,7 @@ async function listWindowsProcesses({ timeoutMs }) {
98
128
  const command = [
99
129
  "$ErrorActionPreference = 'Stop';",
100
130
  "$rows = Get-CimInstance Win32_Process |",
101
- "Where-Object { $_.CommandLine -and ($_.CommandLine -match 'sentinelayer-cli|[\\\\/](sl|sentinelayer-cli)\\.js') } |",
131
+ `Where-Object { $_.CommandLine -and ($_.CommandLine -match '${cliEntryPattern("win32")}') } |`,
102
132
  "Select-Object ProcessId,CommandLine;",
103
133
  "if ($rows) { $rows | ConvertTo-Json -Compress }",
104
134
  ].join(" ");