@volter/teams 0.2.46 → 0.2.48

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.
@@ -10,13 +10,27 @@ export function patternKill(command) {
10
10
  const text = String(command).replace(/\\\r?\n/g, '').replace(/\\([a-zA-Z-])/g, '$1').replace(/["']/g, '');
11
11
  const head = String.raw`(?:^|[;|&(\n{}]|\s-[a-zA-Z]*c\s+)\s*(?:(?:env|sudo|exec|command|xargs|nohup|do|then|else|!)\s+(?:--?[^\s;|&()]+\s+)*|[A-Za-z_][A-Za-z0-9_]*=[^\s;|&()]+\s+)*(?:[\w./-]+/)?`;
12
12
  return new RegExp(head + String.raw`(?:pkill|killall)(?=$|[\s;|&()])`).test(text) ||
13
- new RegExp(head + String.raw`pgrep\s+[^;|&\n)]*(?:--full\b|-[a-zA-Z]*f[a-zA-Z]*(?=$|\s))`).test(text);
13
+ new RegExp(head + String.raw`pgrep\s+[^;|&\n)]*(?:--full\b|-[a-zA-Z]*f[a-zA-Z]*(?=$|\s))`).test(text) ||
14
+ windowsPatternKill(text);
15
+ }
16
+ // Windows names a process by image, title or command line through its own tools (cmd, PowerShell, Git Bash's
17
+ // `//IM`): each such kill is refused as pkill is. A kill by PID (`taskkill /PID`, `Stop-Process -Id`) stays allowed.
18
+ function windowsPatternKill(text) {
19
+ return /\btaskkill(?:\.exe)?\b[^;|&\n]*\s(?:\/{1,2}|-)(?:im|fi)\b/i.test(text) ||
20
+ /(?:^|[^\w-])(?:Stop-Process|spps)\b[^;|\n]*\s-(?:N[a-z]*|ProcessName)\b/i.test(text) ||
21
+ // PowerShell's `kill` alias; Bash's own `kill -n <signal>` is not a name
22
+ /(?:^|[^\w-])kill\b[^;|\n]*\s-(?:Name|ProcessName)\b/i.test(text) ||
23
+ /\b(?:Get-Process|gps)\b(?![^|;\n]*\s-Id\b)[^|;\n]*\|\s*(?:Stop-Process|spps|kill)\b/i.test(text) ||
24
+ /\bwmic\b[^;|&\n]*\bprocess\b[^;|&\n]*\bwhere\b[^;|&\n]*\b(?:name|commandline|executablepath)\b/i.test(text) ||
25
+ /\bWin32_Process\b[^\n]*\b(?:Name|CommandLine|ExecutablePath)\b[^\n]*\b(?:Terminate|Remove-CimInstance|Remove-WmiObject|Stop-Process)\b/i.test(text);
14
26
  }
15
27
  const quote = value => `'${String(value).replaceAll("'", "'\\''")}'`;
16
28
  export function boardGuardArguments(kind, args, { cwd, enabled, node = process.execPath } = {}) {
17
29
  if (!enabled) return args;
18
30
  const command = `${quote(node)} ${quote(fileURLToPath(import.meta.url))}`;
19
- const hooks = [{ matcher: '^Bash$', hooks: [{ type: 'command', command, timeout: 10 }] }];
31
+ // Claude's exec form spawns the policy with no shell on every platform (Windows included, where its shell form
32
+ // runs Git Bash or PowerShell and the POSIX quoting above would not parse); its PowerShell tool is guarded as Bash is.
33
+ const hooks = [{ matcher: '^(Bash|PowerShell)$', hooks: [{ type: 'command', command: node, args: [fileURLToPath(import.meta.url)], timeout: 10 }] }];
20
34
  if (kind === 'claude-code') {
21
35
  const next = [...args], at = next.findIndex(arg => arg === '--settings' || arg.startsWith('--settings='));
22
36
  if (at < 0) return [...next, '--settings', JSON.stringify({ hooks: { PreToolUse: hooks } })];
@@ -30,6 +44,7 @@ export function boardGuardArguments(kind, args, { cwd, enabled, node = process.e
30
44
  // Native Codex rules cannot split substitutions such as kill $(pgrep -f …).
31
45
  // Its synchronous Bash hook can deny the entire command before execution.
32
46
  // This invocation enables and trusts the board-vetted command policy.
47
+ if (process.platform === 'win32') throw new Error('board process guard is unavailable for codex on Windows; no unguarded session was launched');
33
48
  const handler = `{ matcher = "^Bash$", hooks = [{ type = "command", command = ${JSON.stringify(command)}, timeout = 10 }] }`;
34
49
  // Codex's own flags go before any subcommand (`app-server`, `resume`) or prompt: after `app-server`, Codex
35
50
  // 0.159 refuses --dangerously-bypass-hook-trust and the worker never starts.
package/machine-door.mjs CHANGED
@@ -13,8 +13,11 @@ export async function openMachine({ machine = null, context = null, env = proces
13
13
  // This machine named by its own name is its own daemon, reached over its socket: through the Teams server it waited
14
14
  // on the org's machine list and a server channel, and a launch on this box failed whenever the server was rate
15
15
  // limited or out of reach (two review resumes, 17:03Z and 17:34Z, retired as never issued).
16
- if (!machine.startsWith('mach_') && normalMachineName(machine) === normalMachineName(hostname()) && existsSync(paths(home).socket)) return openLocalMachine(paths(home).socket);
16
+ // Its own name is the one this home is enrolled under, never the host's: a second machine enrolled from the same host
17
+ // shares the host name with the first, and one reaching the other by that name must go through the Teams server (its
18
+ // own socket is its own daemon, which would hand the request back to itself until the caller gave up).
17
19
  const supercodeHome = env.SUPERCODE_HOME ?? resolve(home, '..');
20
+ if (!machine.startsWith('mach_') && normalMachineName(machine) === ownMachineName(supercodeHome) && existsSync(paths(home).socket)) return openLocalMachine(paths(home).socket);
18
21
  const contexts = new WorkspaceContexts(supercodeHome);
19
22
  const name = context ?? env.SUPERCODE_CONTEXT ?? contexts.read().current;
20
23
  if (!name || name === 'local') throw Object.assign(new Error('a remote machine is reached through a Teams context: `supercode teams login …`, then `supercode context use NAME` or --context NAME'), { code: 'invalid_request' });
@@ -50,6 +53,18 @@ export async function openMachine({ machine = null, context = null, env = proces
50
53
  return channel;
51
54
  }
52
55
 
56
+ /** The name this home's machine goes by, in the form mail addresses use: its enrollment's in the home's current
57
+ * context, else (an unenrolled machine) the host's. */
58
+ export function ownMachineName(supercodeHome) {
59
+ let name = hostname();
60
+ try {
61
+ const contexts = new WorkspaceContexts(supercodeHome);
62
+ const doc = contexts.read(), context = doc.contexts[doc.current];
63
+ name = contexts.connector(context.server_id, context.team_id).read()?.machine?.name || name;
64
+ } catch { /* an unenrolled machine goes by its host name */ }
65
+ return normalMachineName(name);
66
+ }
67
+
53
68
  /** A machine name in the form mail addresses use: the short host name, lowercased, with anything outside [a-z0-9_-] as `-`. */
54
69
  export function normalMachineName(name) {
55
70
  return String(name).split('.')[0].toLowerCase().replace(/[^a-z0-9_-]/g, '-');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@volter/teams",
3
- "version": "0.2.46",
3
+ "version": "0.2.48",
4
4
  "type": "module",
5
5
  "description": "Volter Teams, the neutral team plane: machine identity and daemon core, the local door and server link, admission from machine grants, product doors, and the Teams server's neutral routes (company RFC 0008).",
6
6
  "license": "MIT",