From f69f78ec6becfcd3c0d1b5fd5ea794ebe990683c Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Fri, 21 Aug 2026 20:06:03 -0400 Subject: [PATCH] refactor(core): inline portable shell scanner (#44026) --- bun.lock | 12 ----- packages/core/package.json | 1 - packages/core/src/shell/parse.ts | 2 +- .../src/index.ts => core/src/shell/scan.ts} | 2 +- packages/core/test/shell-parse-parity.test.ts | 2 +- .../test/shell-scan}/adversarial.test.ts | 2 +- .../test/shell-scan}/closure.test.ts | 2 +- .../test/shell-scan}/generated.test.ts | 2 +- .../test/shell-scan}/mutation.test.ts | 2 +- .../test/shell-scan}/scan.test.ts | 2 +- packages/shell-scan/package.json | 31 ------------- packages/shell-scan/script/build.ts | 10 ---- packages/shell-scan/script/publish.ts | 46 ------------------- packages/shell-scan/tsconfig.build.json | 11 ----- packages/shell-scan/tsconfig.json | 12 ----- script/publish.ts | 3 -- 16 files changed, 8 insertions(+), 134 deletions(-) rename packages/{shell-scan/src/index.ts => core/src/shell/scan.ts} (99%) rename packages/{shell-scan/test => core/test/shell-scan}/adversarial.test.ts (98%) rename packages/{shell-scan/test => core/test/shell-scan}/closure.test.ts (95%) rename packages/{shell-scan/test => core/test/shell-scan}/generated.test.ts (99%) rename packages/{shell-scan/test => core/test/shell-scan}/mutation.test.ts (93%) rename packages/{shell-scan/test => core/test/shell-scan}/scan.test.ts (99%) delete mode 100644 packages/shell-scan/package.json delete mode 100644 packages/shell-scan/script/build.ts delete mode 100644 packages/shell-scan/script/publish.ts delete mode 100644 packages/shell-scan/tsconfig.build.json delete mode 100644 packages/shell-scan/tsconfig.json diff --git a/bun.lock b/bun.lock index bfef178fef9..9c703144d0c 100644 --- a/bun.lock +++ b/bun.lock @@ -365,7 +365,6 @@ "@opencode-ai/codemode": "workspace:*", "@opencode-ai/plugin": "workspace:*", "@opencode-ai/schema": "workspace:*", - "@opencode-ai/shell-scan": "workspace:*", "@opencode-ai/util": "workspace:*", "@parcel/watcher": "2.5.1", "@silvia-odwyer/photon-node": "0.3.4", @@ -735,15 +734,6 @@ "vite": "catalog:", }, }, - "packages/shell-scan": { - "name": "@opencode-ai/shell-scan", - "version": "0.0.0", - "devDependencies": { - "@tsconfig/bun": "catalog:", - "@types/bun": "catalog:", - "@typescript/native-preview": "catalog:", - }, - }, "packages/simulation": { "name": "@opencode-ai/simulation", "version": "1.17.13", @@ -2064,8 +2054,6 @@ "@opencode-ai/session-ui": ["@opencode-ai/session-ui@workspace:packages/session-ui"], - "@opencode-ai/shell-scan": ["@opencode-ai/shell-scan@workspace:packages/shell-scan"], - "@opencode-ai/simulation": ["@opencode-ai/simulation@workspace:packages/simulation"], "@opencode-ai/stats-app": ["@opencode-ai/stats-app@workspace:packages/stats/app"], diff --git a/packages/core/package.json b/packages/core/package.json index bb5c9a22676..134f95a1f76 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -118,7 +118,6 @@ "@opencode-ai/ai": "workspace:*", "@opencode-ai/schema": "workspace:*", "@opencode-ai/plugin": "workspace:*", - "@opencode-ai/shell-scan": "workspace:*", "@opencode-ai/util": "workspace:*", "@standard-schema/spec": "catalog:", "@parcel/watcher": "2.5.1", diff --git a/packages/core/src/shell/parse.ts b/packages/core/src/shell/parse.ts index 50d9b2d8ba8..bfc0b047ec9 100644 --- a/packages/core/src/shell/parse.ts +++ b/packages/core/src/shell/parse.ts @@ -198,7 +198,7 @@ const scanLegacy = Effect.fnUntraced(function* (command: string, shell: string, }) async function scanPortable(command: string, shell: string, cwd: string) { - const { ShellScan } = await import("@opencode-ai/shell-scan") + const { ShellScan } = await import("./scan.js") const powershell = ShellSelect.ps(shell) const result = powershell ? ShellScan.scanPowerShell(command) : ShellScan.scan(command) if (result.kind === "opaque") return { commands: [{ resource: command, save: command }], directories: [] } diff --git a/packages/shell-scan/src/index.ts b/packages/core/src/shell/scan.ts similarity index 99% rename from packages/shell-scan/src/index.ts rename to packages/core/src/shell/scan.ts index f96c2721ed6..495518c6290 100644 --- a/packages/shell-scan/src/index.ts +++ b/packages/core/src/shell/scan.ts @@ -1,4 +1,4 @@ -export * as ShellScan from "./index.js" +export * as ShellScan from "./scan.js" export type OpaqueReason = | "command-substitution" diff --git a/packages/core/test/shell-parse-parity.test.ts b/packages/core/test/shell-parse-parity.test.ts index 609d84fcc82..fd70e2ec758 100644 --- a/packages/core/test/shell-parse-parity.test.ts +++ b/packages/core/test/shell-parse-parity.test.ts @@ -1,7 +1,7 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "@opencode-ai/shell-scan" import { Effect } from "effect" import { ShellParse } from "../src/shell/parse.js" +import { ShellScan } from "../src/shell/scan.js" describe("ShellParse portable parity", () => { test("matches tree-sitter for generated supported syntax", async () => { diff --git a/packages/shell-scan/test/adversarial.test.ts b/packages/core/test/shell-scan/adversarial.test.ts similarity index 98% rename from packages/shell-scan/test/adversarial.test.ts rename to packages/core/test/shell-scan/adversarial.test.ts index d1857eeb688..b03b7b2543e 100644 --- a/packages/shell-scan/test/adversarial.test.ts +++ b/packages/core/test/shell-scan/adversarial.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "../src/index.js" +import { ShellScan } from "../../src/shell/scan.js" describe("ShellScan adversarial corpus", () => { test.each([ diff --git a/packages/shell-scan/test/closure.test.ts b/packages/core/test/shell-scan/closure.test.ts similarity index 95% rename from packages/shell-scan/test/closure.test.ts rename to packages/core/test/shell-scan/closure.test.ts index 796fac62fd4..2d9605def50 100644 --- a/packages/shell-scan/test/closure.test.ts +++ b/packages/core/test/shell-scan/closure.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "../src/index.js" +import { ShellScan } from "../../src/shell/scan.js" const opaque = ["$COMMAND hidden", "$(printf command) hidden", 'printf "unterminated'] as const const contexts = [ diff --git a/packages/shell-scan/test/generated.test.ts b/packages/core/test/shell-scan/generated.test.ts similarity index 99% rename from packages/shell-scan/test/generated.test.ts rename to packages/core/test/shell-scan/generated.test.ts index 881d611a0ee..2d1300a6a7b 100644 --- a/packages/shell-scan/test/generated.test.ts +++ b/packages/core/test/shell-scan/generated.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "../src/index.js" +import { ShellScan } from "../../src/shell/scan.js" const staticCommands = [ ["git status", ["git", "status"]], diff --git a/packages/shell-scan/test/mutation.test.ts b/packages/core/test/shell-scan/mutation.test.ts similarity index 93% rename from packages/shell-scan/test/mutation.test.ts rename to packages/core/test/shell-scan/mutation.test.ts index c7296ad8c5e..db404b9633f 100644 --- a/packages/shell-scan/test/mutation.test.ts +++ b/packages/core/test/shell-scan/mutation.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "../src/index.js" +import { ShellScan } from "../../src/shell/scan.js" describe("ShellScan structural mutation closure", () => { test.each([ diff --git a/packages/shell-scan/test/scan.test.ts b/packages/core/test/shell-scan/scan.test.ts similarity index 99% rename from packages/shell-scan/test/scan.test.ts rename to packages/core/test/shell-scan/scan.test.ts index 73ac36d4ec8..34d20261427 100644 --- a/packages/shell-scan/test/scan.test.ts +++ b/packages/core/test/shell-scan/scan.test.ts @@ -1,5 +1,5 @@ import { describe, expect, test } from "bun:test" -import { ShellScan } from "../src/index.js" +import { ShellScan } from "../../src/shell/scan.js" describe("ShellScan", () => { test("scans a static command", () => { diff --git a/packages/shell-scan/package.json b/packages/shell-scan/package.json deleted file mode 100644 index b0f30c73ce1..00000000000 --- a/packages/shell-scan/package.json +++ /dev/null @@ -1,31 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/package.json", - "name": "@opencode-ai/shell-scan", - "version": "0.0.0", - "type": "module", - "license": "MIT", - "repository": { - "type": "git", - "url": "git+https://github.com/anomalyco/opencode.git", - "directory": "packages/shell-scan" - }, - "publishConfig": { - "access": "public" - }, - "files": [ - "dist" - ], - "exports": { - ".": "./src/index.ts" - }, - "scripts": { - "build": "bun run script/build.ts", - "test": "bun test --only-failures", - "typecheck": "tsgo --noEmit" - }, - "devDependencies": { - "@tsconfig/bun": "catalog:", - "@types/bun": "catalog:", - "@typescript/native-preview": "catalog:" - } -} diff --git a/packages/shell-scan/script/build.ts b/packages/shell-scan/script/build.ts deleted file mode 100644 index d6f56f4989e..00000000000 --- a/packages/shell-scan/script/build.ts +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bun - -import { $ } from "bun" -import { rm } from "node:fs/promises" -import { fileURLToPath } from "node:url" - -process.chdir(fileURLToPath(new URL("..", import.meta.url))) - -await rm("dist", { recursive: true, force: true }) -await $`bun tsc -p tsconfig.build.json` diff --git a/packages/shell-scan/script/publish.ts b/packages/shell-scan/script/publish.ts deleted file mode 100644 index e56ff22d286..00000000000 --- a/packages/shell-scan/script/publish.ts +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/env bun - -import { Script } from "@opencode-ai/script" -import { $ } from "bun" -import { rm } from "node:fs/promises" -import { fileURLToPath } from "node:url" - -process.chdir(fileURLToPath(new URL("..", import.meta.url))) - -const dryRun = Bun.argv.includes("--dry-run") -const originalText = await Bun.file("package.json").text() -const pkg = JSON.parse(originalText) as { - name: string - version: string - exports: Record -} -const tarball = `${pkg.name.replace("@", "").replace("/", "-")}-${pkg.version}.tgz` - -if (!dryRun && (await $`npm view ${pkg.name}@${pkg.version} version`.nothrow()).exitCode === 0) { - console.log(`already published ${pkg.name}@${pkg.version}`) - process.exit(0) -} - -try { - await $`bun run typecheck` - await $`bun run build` - pkg.exports = Object.fromEntries( - Object.entries(pkg.exports).map(([key, value]) => { - if (typeof value !== "string") return [key, value] - return [ - key, - { - import: value.replace("./src/", "./dist/").replace(/\.ts$/, ".js"), - types: value.replace("./src/", "./dist/").replace(/\.ts$/, ".d.ts"), - }, - ] - }), - ) - await Bun.write("package.json", JSON.stringify(pkg, null, 2) + "\n") - await rm(tarball, { force: true }) - await $`bun pm pack` - if (!dryRun) await $`npm publish ${tarball} --tag ${Script.channel} --access public` -} finally { - await Bun.write("package.json", originalText) - await rm(tarball, { force: true }) -} diff --git a/packages/shell-scan/tsconfig.build.json b/packages/shell-scan/tsconfig.build.json deleted file mode 100644 index e235ae78cf6..00000000000 --- a/packages/shell-scan/tsconfig.build.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "./tsconfig.json", - "compilerOptions": { - "rootDir": "src", - "outDir": "dist", - "noEmit": false, - "declaration": true - }, - "include": ["src"] -} diff --git a/packages/shell-scan/tsconfig.json b/packages/shell-scan/tsconfig.json deleted file mode 100644 index 67845e92325..00000000000 --- a/packages/shell-scan/tsconfig.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "$schema": "https://json.schemastore.org/tsconfig", - "extends": "@tsconfig/bun/tsconfig.json", - "compilerOptions": { - "module": "NodeNext", - "moduleResolution": "NodeNext", - "allowImportingTsExtensions": false, - "allowJs": false, - "noUncheckedIndexedAccess": false - }, - "include": ["src", "test", "bench", "research"] -} diff --git a/script/publish.ts b/script/publish.ts index 3dadd95e687..04fb6a4794a 100755 --- a/script/publish.ts +++ b/script/publish.ts @@ -50,9 +50,6 @@ await $`bun ./packages/ai/script/publish.ts` console.log("\n=== util ===\n") await $`bun ./packages/util/script/publish.ts` -console.log("\n=== shell scan ===\n") -await $`bun ./packages/shell-scan/script/publish.ts` - console.log("\n=== protocol ===\n") await $`bun ./packages/protocol/script/publish.ts`