opencode-nju-cli 1.3.6
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/LICENSE +661 -0
- package/README.md +63 -0
- package/bin/linux-x86_64/nju-cli +0 -0
- package/bin/macos-aarch64/nju-cli +0 -0
- package/bin/windows-x86_64/nju-cli.exe +0 -0
- package/opencode.example.json +9 -0
- package/package.json +46 -0
- package/scripts/nju-cli +31 -0
- package/scripts/nju-cli.mjs +33 -0
- package/scripts/nju-cli.ps1 +11 -0
- package/skills/nju-cli/SKILL.md +35 -0
- package/skills/nju-cli/subcommands/academic-affairs.md +25 -0
- package/skills/nju-cli/subcommands/ehall/all-undergraduate-courses.md +53 -0
- package/skills/nju-cli/subcommands/ehall/grades.md +89 -0
- package/skills/nju-cli/subcommands/ehall/my-course-schedule.md +76 -0
- package/skills/nju-cli/subcommands/ehall/training-program.md +94 -0
- package/skills/nju-cli/subcommands/ehall.md +22 -0
- package/skills/nju-cli/subcommands/exchange-system.md +27 -0
- package/skills/nju-cli/subcommands/youth-league.md +33 -0
- package/src/index.js +97 -0
package/src/index.js
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { spawn } from "node:child_process"
|
|
2
|
+
import { readFile } from "node:fs/promises"
|
|
3
|
+
import { dirname, join, normalize, relative } from "node:path"
|
|
4
|
+
import { fileURLToPath } from "node:url"
|
|
5
|
+
import { tool } from "@opencode-ai/plugin"
|
|
6
|
+
|
|
7
|
+
const root = join(dirname(fileURLToPath(import.meta.url)), "..")
|
|
8
|
+
|
|
9
|
+
function binaryPath() {
|
|
10
|
+
const platform = process.platform
|
|
11
|
+
const arch = process.arch
|
|
12
|
+
|
|
13
|
+
if (platform === "linux" && arch === "x64") return join(root, "bin/linux-x86_64/nju-cli")
|
|
14
|
+
if (platform === "linux" && arch === "arm64") return join(root, "bin/linux-aarch64/nju-cli")
|
|
15
|
+
if (platform === "darwin" && arch === "arm64") return join(root, "bin/macos-aarch64/nju-cli")
|
|
16
|
+
if (platform === "win32" && arch === "x64") return join(root, "bin/windows-x86_64/nju-cli.exe")
|
|
17
|
+
|
|
18
|
+
throw new Error(`nju-cli is not packaged for ${platform}/${arch}`)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function runNjuCli(args, cwd) {
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const child = spawn(binaryPath(), args, {
|
|
24
|
+
cwd,
|
|
25
|
+
env: process.env,
|
|
26
|
+
windowsHide: true,
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
let stdout = ""
|
|
30
|
+
let stderr = ""
|
|
31
|
+
|
|
32
|
+
child.stdout.on("data", (chunk) => {
|
|
33
|
+
stdout += chunk
|
|
34
|
+
})
|
|
35
|
+
child.stderr.on("data", (chunk) => {
|
|
36
|
+
stderr += chunk
|
|
37
|
+
})
|
|
38
|
+
child.on("error", reject)
|
|
39
|
+
child.on("close", (code) => {
|
|
40
|
+
const output = [stdout.trimEnd(), stderr.trimEnd()].filter(Boolean).join("\n")
|
|
41
|
+
if (code === 0) {
|
|
42
|
+
resolve(output || "nju-cli completed successfully with no output.")
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
reject(new Error(`nju-cli exited with code ${code}\n${output}`.trim()))
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function readSkillDoc(topic) {
|
|
51
|
+
const docsRoot = join(root, "skills/nju-cli")
|
|
52
|
+
const requested = topic && topic !== "overview" ? topic : "SKILL.md"
|
|
53
|
+
const target = normalize(join(docsRoot, requested))
|
|
54
|
+
const rel = relative(docsRoot, target)
|
|
55
|
+
|
|
56
|
+
if (rel.startsWith("..") || rel === "" || rel.includes("..")) {
|
|
57
|
+
throw new Error("topic must be a bundled nju-cli skill document path")
|
|
58
|
+
}
|
|
59
|
+
if (!target.endsWith(".md")) {
|
|
60
|
+
throw new Error("topic must point to a Markdown skill document")
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return readFile(target, "utf8")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export const NjuCliPlugin = async ({ directory }) => {
|
|
67
|
+
return {
|
|
68
|
+
tool: {
|
|
69
|
+
nju_cli: tool({
|
|
70
|
+
description:
|
|
71
|
+
"Run the bundled nju-cli binary for Nanjing University services. Pass command-line arguments as an array, for example [\"academic-affairs\", \"notices\", \"--help\"].",
|
|
72
|
+
args: {
|
|
73
|
+
args: tool.schema.array(tool.schema.string()).describe("Arguments to pass to nju-cli."),
|
|
74
|
+
cwd: tool.schema.string().optional().describe("Working directory. Defaults to the current OpenCode project directory."),
|
|
75
|
+
},
|
|
76
|
+
async execute(args) {
|
|
77
|
+
return runNjuCli(args.args, args.cwd || directory)
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
nju_cli_docs: tool({
|
|
81
|
+
description:
|
|
82
|
+
"Read bundled nju-cli skill guidance. Use this before choosing nju-cli subcommands for NJU academic affairs, ehall, exchange-system, and youth-league workflows.",
|
|
83
|
+
args: {
|
|
84
|
+
topic: tool.schema
|
|
85
|
+
.string()
|
|
86
|
+
.optional()
|
|
87
|
+
.describe(
|
|
88
|
+
"Bundled Markdown path relative to skills/nju-cli, such as SKILL.md, subcommands/ehall.md, or subcommands/academic-affairs.md.",
|
|
89
|
+
),
|
|
90
|
+
},
|
|
91
|
+
async execute(args) {
|
|
92
|
+
return readSkillDoc(args.topic)
|
|
93
|
+
},
|
|
94
|
+
}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|