Compare commits

...

2 Commits

Author SHA1 Message Date
Kit Langton 70c40a12e5 refactor: switch small standalone namespaces to self-reexport imports 2026-04-16 11:25:50 -04:00
Kit Langton a9248fbb4a feat: unwrap BashArity, Discovery namespaces to flat exports + barrel 2026-04-16 08:29:37 -04:00
3 changed files with 251 additions and 253 deletions
+5 -6
View File
@@ -1,5 +1,4 @@
export namespace BashArity { export function prefix(tokens: string[]) {
export function prefix(tokens: string[]) {
for (let len = tokens.length; len > 0; len--) { for (let len = tokens.length; len > 0; len--) {
const prefix = tokens.slice(0, len).join(" ") const prefix = tokens.slice(0, len).join(" ")
const arity = ARITY[prefix] const arity = ARITY[prefix]
@@ -7,9 +6,9 @@ export namespace BashArity {
} }
if (tokens.length === 0) return [] if (tokens.length === 0) return []
return tokens.slice(0, 1) return tokens.slice(0, 1)
} }
/* Generated with following prompt: /* Generated with following prompt:
You are generating a dictionary of command-prefix arities for bash-style commands. You are generating a dictionary of command-prefix arities for bash-style commands.
This dictionary is used to identify the "human-understandable command" from an input shell command.### **RULES (follow strictly)**1. Each entry maps a **command prefix string → number**, representing how many **tokens** define the command. This dictionary is used to identify the "human-understandable command" from an input shell command.### **RULES (follow strictly)**1. Each entry maps a **command prefix string → number**, representing how many **tokens** define the command.
2. **Flags NEVER count as tokens**. Only subcommands count. 2. **Flags NEVER count as tokens**. Only subcommands count.
@@ -22,7 +21,7 @@ This dictionary is used to identify the "human-understandable command" from an i
* `npm run dev` → `npm run dev` (because `npm run` has arity 3) * `npm run dev` → `npm run dev` (because `npm run` has arity 3)
* `python script.py` → `python script.py` (default: whole input, not in dictionary)### **Now generate the dictionary.** * `python script.py` → `python script.py` (default: whole input, not in dictionary)### **Now generate the dictionary.**
*/ */
const ARITY: Record<string, number> = { const ARITY: Record<string, number> = {
cat: 1, // cat file.txt cat: 1, // cat file.txt
cd: 1, // cd /path/to/dir cd: 1, // cd /path/to/dir
chmod: 1, // chmod 755 script.sh chmod: 1, // chmod 755 script.sh
@@ -159,5 +158,5 @@ This dictionary is used to identify the "human-understandable command" from an i
yarn: 2, // yarn add react yarn: 2, // yarn add react
"yarn dlx": 3, // yarn dlx create-react-app "yarn dlx": 3, // yarn dlx create-react-app
"yarn run": 3, // yarn run dev "yarn run": 3, // yarn run dev
}
} }
export * as BashArity from "./arity"
+13 -14
View File
@@ -6,26 +6,25 @@ import { AppFileSystem } from "@opencode-ai/shared/filesystem"
import { Global } from "../global" import { Global } from "../global"
import { Log } from "../util" import { Log } from "../util"
export namespace Discovery { const skillConcurrency = 4
const skillConcurrency = 4 const fileConcurrency = 8
const fileConcurrency = 8
class IndexSkill extends Schema.Class<IndexSkill>("IndexSkill")({ class IndexSkill extends Schema.Class<IndexSkill>("IndexSkill")({
name: Schema.String, name: Schema.String,
files: Schema.Array(Schema.String), files: Schema.Array(Schema.String),
}) {} }) {}
class Index extends Schema.Class<Index>("Index")({ class Index extends Schema.Class<Index>("Index")({
skills: Schema.Array(IndexSkill), skills: Schema.Array(IndexSkill),
}) {} }) {}
export interface Interface { export interface Interface {
readonly pull: (url: string) => Effect.Effect<string[]> readonly pull: (url: string) => Effect.Effect<string[]>
} }
export class Service extends Context.Service<Service, Interface>()("@opencode/SkillDiscovery") {} export class Service extends Context.Service<Service, Interface>()("@opencode/SkillDiscovery") {}
export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Path.Path | HttpClient.HttpClient> = export const layer: Layer.Layer<Service, never, AppFileSystem.Service | Path.Path | HttpClient.HttpClient> =
Layer.effect( Layer.effect(
Service, Service,
Effect.gen(function* () { Effect.gen(function* () {
@@ -108,9 +107,9 @@ export namespace Discovery {
}), }),
) )
export const defaultLayer: Layer.Layer<Service> = layer.pipe( export const defaultLayer: Layer.Layer<Service> = layer.pipe(
Layer.provide(FetchHttpClient.layer), Layer.provide(FetchHttpClient.layer),
Layer.provide(AppFileSystem.defaultLayer), Layer.provide(AppFileSystem.defaultLayer),
Layer.provide(NodePath.layer), Layer.provide(NodePath.layer),
) )
} export * as Discovery from "./discovery"
+1 -1
View File
@@ -15,7 +15,7 @@ import { Config } from "../config"
import { ConfigMarkdown } from "../config" import { ConfigMarkdown } from "../config"
import { Glob } from "@opencode-ai/shared/util/glob" import { Glob } from "@opencode-ai/shared/util/glob"
import { Log } from "../util" import { Log } from "../util"
import { Discovery } from "./discovery" import * as Discovery from "./discovery"
const log = Log.create({ service: "skill" }) const log = Log.create({ service: "skill" })
const EXTERNAL_DIRS = [".claude", ".agents"] const EXTERNAL_DIRS = [".claude", ".agents"]