opencode-vim 0.0.22 → 0.0.24
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/README.md +25 -63
- package/assets/vim-in-motion-dialogs.gif +0 -0
- package/dist/tui.js +3326 -0
- package/docs/configuration.md +50 -400
- package/docs/keymap-actions.md +60 -188
- package/docs/vim-behavior.md +93 -0
- package/package.json +6 -6
- package/src/modules/snippets/index.tsx +0 -17
- package/src/modules/snippets/loader.ts +0 -147
- package/src/modules/snippets/search.ts +0 -118
- package/src/modules/snippets/skill-loader.ts +0 -81
- package/src/modules/snippets/state.ts +0 -40
- package/src/modules/snippets/trigger.ts +0 -68
- package/src/modules/snippets/types.ts +0 -50
- package/src/modules/snippets/view.tsx +0 -674
- package/src/modules/vim/actions.ts +0 -85
- package/src/modules/vim/config.ts +0 -125
- package/src/modules/vim/edit.test.ts +0 -51
- package/src/modules/vim/edit.ts +0 -33
- package/src/modules/vim/graphemes.ts +0 -38
- package/src/modules/vim/index.tsx +0 -200
- package/src/modules/vim/keys.ts +0 -38
- package/src/modules/vim/log.ts +0 -37
- package/src/modules/vim/map.test.ts +0 -45
- package/src/modules/vim/map.ts +0 -198
- package/src/modules/vim/state.test.ts +0 -18
- package/src/modules/vim/state.tsx +0 -46
- package/src/modules/vim/view.tsx +0 -130
- package/src/modules/vim/vimee.test.ts +0 -211
- package/src/modules/vim/vimee.ts +0 -1146
- package/src/plugin.tsx +0 -116
- package/src/prompt/host.tsx +0 -38
- package/src/prompt/modules.ts +0 -16
- package/src/prompt/root.tsx +0 -69
- package/src/prompt/types.ts +0 -42
- package/src/update.ts +0 -120
- package/tui.tsx +0 -275
- package/view.tsx +0 -29
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { dirname, join, parse } from "node:path"
|
|
2
|
-
import type { SkillInfo, SnippetSource } from "./types"
|
|
3
|
-
import { parseFrontmatter } from "./loader"
|
|
4
|
-
|
|
5
|
-
const SKILL_FILE = "SKILL.md"
|
|
6
|
-
|
|
7
|
-
export async function loadSkills(projectDir?: string) {
|
|
8
|
-
const registry = new Map<string, SkillInfo>()
|
|
9
|
-
const home = process.env.HOME
|
|
10
|
-
|
|
11
|
-
if (home) {
|
|
12
|
-
await loadSkillDir(registry, join(home, ".config/opencode/skill"), "global")
|
|
13
|
-
await loadSkillDir(registry, join(home, ".config/opencode/skills"), "global")
|
|
14
|
-
await loadSkillDir(registry, join(home, ".claude/skills"), "global")
|
|
15
|
-
await loadSkillDir(registry, join(home, ".agents/skills"), "global")
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
for (const root of await projectRoots(projectDir)) {
|
|
19
|
-
await loadSkillDir(registry, join(root, ".opencode/skill"), "project")
|
|
20
|
-
await loadSkillDir(registry, join(root, ".opencode/skills"), "project")
|
|
21
|
-
await loadSkillDir(registry, join(root, ".claude/skills"), "project")
|
|
22
|
-
await loadSkillDir(registry, join(root, ".agents/skills"), "project")
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return [...registry.values()].sort((left, right) => sourceRank(left) - sourceRank(right) || left.name.localeCompare(right.name))
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
async function projectRoots(projectDir?: string) {
|
|
29
|
-
if (!projectDir) return []
|
|
30
|
-
const roots: string[] = []
|
|
31
|
-
let current = projectDir
|
|
32
|
-
|
|
33
|
-
while (true) {
|
|
34
|
-
roots.push(current)
|
|
35
|
-
if (await Bun.file(join(current, ".git")).exists()) break
|
|
36
|
-
const parent = dirname(current)
|
|
37
|
-
if (parent === current) break
|
|
38
|
-
current = parent
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return roots.reverse()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async function loadSkillDir(registry: Map<string, SkillInfo>, dir: string, source: SnippetSource) {
|
|
45
|
-
let entries: string[]
|
|
46
|
-
try {
|
|
47
|
-
entries = await Array.fromAsync(new Bun.Glob(`*/${SKILL_FILE}`).scan({ cwd: dir, onlyFiles: true }))
|
|
48
|
-
} catch {
|
|
49
|
-
return
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
for (const entry of entries) {
|
|
53
|
-
const skill = await loadSkill(join(dir, entry), source)
|
|
54
|
-
if (skill) registry.set(skill.name.toLowerCase(), skill)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
async function loadSkill(filePath: string, source: SnippetSource) {
|
|
59
|
-
let raw: string
|
|
60
|
-
try {
|
|
61
|
-
raw = await Bun.file(filePath).text()
|
|
62
|
-
} catch {
|
|
63
|
-
return undefined
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const parsed = parseFrontmatter(raw)
|
|
67
|
-
const folderName = parse(dirname(filePath)).base
|
|
68
|
-
const name = typeof parsed.data.name === "string" && parsed.data.name.trim() ? parsed.data.name.trim() : folderName
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
name,
|
|
72
|
-
content: parsed.content.trim(),
|
|
73
|
-
description: typeof parsed.data.description === "string" ? parsed.data.description : undefined,
|
|
74
|
-
filePath,
|
|
75
|
-
source,
|
|
76
|
-
} satisfies SkillInfo
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function sourceRank(skill: SkillInfo) {
|
|
80
|
-
return skill.source === "project" ? 0 : 1
|
|
81
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { dirname, join } from "node:path"
|
|
2
|
-
import { mkdir, writeFile } from "node:fs/promises"
|
|
3
|
-
|
|
4
|
-
const SCOPE_GLOBAL = "__global__"
|
|
5
|
-
|
|
6
|
-
export async function addPendingDraft(workspaceDir: string | undefined, name: string) {
|
|
7
|
-
const filePath = statePath("pending-drafts.json")
|
|
8
|
-
const state = await readState(filePath)
|
|
9
|
-
const scope = workspaceDir || SCOPE_GLOBAL
|
|
10
|
-
const current = Array.isArray(state[scope]) ? state[scope].filter((item): item is string => typeof item === "string") : []
|
|
11
|
-
const next = new Set([...current, name.toLowerCase()])
|
|
12
|
-
state[scope] = [...next].sort()
|
|
13
|
-
await writeState(filePath, state)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export async function markSnippetReloadRequested(workspaceDir?: string) {
|
|
17
|
-
const filePath = statePath("snippet-reload.json")
|
|
18
|
-
const state = await readState(filePath)
|
|
19
|
-
state[workspaceDir || SCOPE_GLOBAL] = Date.now()
|
|
20
|
-
await writeState(filePath, state)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function statePath(name: string) {
|
|
24
|
-
const home = process.env.HOME
|
|
25
|
-
if (!home) throw new Error("HOME is not set")
|
|
26
|
-
return join(home, ".config/opencode/state", name)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
async function readState(filePath: string) {
|
|
30
|
-
try {
|
|
31
|
-
const parsed = JSON.parse(await Bun.file(filePath).text())
|
|
32
|
-
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) return parsed as Record<string, unknown>
|
|
33
|
-
} catch {}
|
|
34
|
-
return {} as Record<string, unknown>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async function writeState(filePath: string, state: Record<string, unknown>) {
|
|
38
|
-
await mkdir(dirname(filePath), { recursive: true })
|
|
39
|
-
await writeFile(filePath, `${JSON.stringify(state, null, 2)}\n`)
|
|
40
|
-
}
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import type { HashtagTriggerMatch, SnippetInfo } from "./types"
|
|
2
|
-
|
|
3
|
-
export function findTrailingHashtagTrigger(input: string): HashtagTriggerMatch | undefined {
|
|
4
|
-
let start = -1
|
|
5
|
-
for (let i = input.length - 1; i >= 0; i--) {
|
|
6
|
-
const char = input[i]
|
|
7
|
-
if (char === "#") {
|
|
8
|
-
start = i
|
|
9
|
-
break
|
|
10
|
-
}
|
|
11
|
-
if (/\s/.test(char)) return undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (start < 0) return undefined
|
|
15
|
-
if (start > 0 && !/\s/.test(input[start - 1])) return undefined
|
|
16
|
-
|
|
17
|
-
const query = input.slice(start + 1)
|
|
18
|
-
const token = `#${query}`
|
|
19
|
-
|
|
20
|
-
return {
|
|
21
|
-
start,
|
|
22
|
-
end: input.length,
|
|
23
|
-
query,
|
|
24
|
-
token,
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export function replaceTrailingHashtag(input: string, name: string) {
|
|
29
|
-
const match = findTrailingHashtagTrigger(input)
|
|
30
|
-
if (!match) return input
|
|
31
|
-
return `${input.slice(0, match.start)}#${name} `
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function insertSnippetTag(input: string, name: string) {
|
|
35
|
-
const match = findTrailingHashtagTrigger(input)
|
|
36
|
-
if (match) return replaceTrailingHashtag(input, name)
|
|
37
|
-
const separator = input.length === 0 || /\s$/.test(input) ? "" : " "
|
|
38
|
-
return `${input}${separator}#${name} `
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function insertSkillLoad(input: string, name: string) {
|
|
42
|
-
const tag = `skill(${name})`
|
|
43
|
-
const match = findTrailingHashtagTrigger(input)
|
|
44
|
-
if (match) return replaceTrailingHashtag(input, tag)
|
|
45
|
-
const separator = input.length === 0 || /\s$/.test(input) ? "" : " "
|
|
46
|
-
return `${input}${separator}#${tag} `
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export function preferredSnippetTag(input: string, snippet: SnippetInfo) {
|
|
50
|
-
const query = findTrailingHashtagTrigger(input)?.query
|
|
51
|
-
if (query && snippet.aliases.some((alias) => alias === query)) return query
|
|
52
|
-
return snippet.name
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function insertSnippetTrigger(input: string) {
|
|
56
|
-
if (findTrailingHashtagTrigger(input)) return input
|
|
57
|
-
const separator = input.length === 0 || /\s$/.test(input) ? "" : " "
|
|
58
|
-
return `${input}${separator}#`
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export function isReloadCommand(input: string) {
|
|
62
|
-
return input.trim() === "/snippets:reload"
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export function stepSelection(current: number, total: number, delta: number) {
|
|
66
|
-
if (total <= 0) return 0
|
|
67
|
-
return Math.max(0, Math.min(total - 1, current + delta))
|
|
68
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
export type SnippetSource = "global" | "project"
|
|
2
|
-
|
|
3
|
-
export type SnippetInfo = {
|
|
4
|
-
name: string
|
|
5
|
-
content: string
|
|
6
|
-
aliases: string[]
|
|
7
|
-
description?: string
|
|
8
|
-
filePath: string
|
|
9
|
-
source: SnippetSource
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type SkillInfo = {
|
|
13
|
-
name: string
|
|
14
|
-
content: string
|
|
15
|
-
description?: string
|
|
16
|
-
filePath: string
|
|
17
|
-
source: SnippetSource
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export type AutocompleteItem =
|
|
21
|
-
| {
|
|
22
|
-
kind: "snippet"
|
|
23
|
-
id: string
|
|
24
|
-
label: string
|
|
25
|
-
description: string
|
|
26
|
-
aliases: string[]
|
|
27
|
-
snippet: SnippetInfo
|
|
28
|
-
}
|
|
29
|
-
| {
|
|
30
|
-
kind: "skill"
|
|
31
|
-
id: string
|
|
32
|
-
label: string
|
|
33
|
-
description: string
|
|
34
|
-
aliases: string[]
|
|
35
|
-
skill: SkillInfo
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type HashtagTriggerMatch = {
|
|
39
|
-
start: number
|
|
40
|
-
end: number
|
|
41
|
-
query: string
|
|
42
|
-
token: string
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type SnippetController = {
|
|
46
|
-
accept?: () => boolean
|
|
47
|
-
reload?: () => void
|
|
48
|
-
insertTrigger?: () => void
|
|
49
|
-
navigate?: (delta: number) => boolean
|
|
50
|
-
}
|