dsh-digital-logic-lectern 0.0.0-stage → 0.6.3

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/README.en.md +118 -0
  3. package/README.md +119 -2
  4. package/_selftest.mjs +141 -0
  5. package/cordis.patch.yml +3 -0
  6. package/lib/client.js +274 -0
  7. package/lib/index.js +150 -0
  8. package/locale/en.json +6 -0
  9. package/locale/zh-CN.json +6 -0
  10. package/package.json +78 -5
  11. package/skills/digital-logic-lectern/SKILL.md +147 -0
  12. package/skills/digital-logic-lectern/examples/counter4.v +15 -0
  13. package/skills/digital-logic-lectern/examples/counter4_tb.v +25 -0
  14. package/skills/digital-logic-lectern/examples/demo_draft.md +41 -0
  15. package/skills/digital-logic-lectern/examples/demo_draft_bad.md +24 -0
  16. package/skills/digital-logic-lectern/examples/evidence.txt +13 -0
  17. package/skills/digital-logic-lectern/references/appendix_verilog.md +32 -0
  18. package/skills/digital-logic-lectern/references/glossary.md +231 -0
  19. package/skills/digital-logic-lectern/references/m1_number_code.md +29 -0
  20. package/skills/digital-logic-lectern/references/m2_boolean_algebra.md +29 -0
  21. package/skills/digital-logic-lectern/references/m3_combinational.md +29 -0
  22. package/skills/digital-logic-lectern/references/m4_sequential.md +29 -0
  23. package/skills/digital-logic-lectern/references/m5_memory.md +29 -0
  24. package/skills/digital-logic-lectern/references/m6_pld_fpga.md +29 -0
  25. package/skills/digital-logic-lectern/references/m7_controller.md +29 -0
  26. package/skills/digital-logic-lectern/references/m8_verilog.md +44 -0
  27. package/skills/digital-logic-lectern/references/textbook/ch1.md +164 -0
  28. package/skills/digital-logic-lectern/references/textbook/ch2.md +171 -0
  29. package/skills/digital-logic-lectern/references/textbook/ch3.md +130 -0
  30. package/skills/digital-logic-lectern/references/textbook/ch4.md +91 -0
  31. package/skills/digital-logic-lectern/references/textbook/ch5.md +121 -0
  32. package/skills/digital-logic-lectern/references/textbook/ch6.md +138 -0
  33. package/skills/digital-logic-lectern/references/textbook/ch7.md +73 -0
  34. package/skills/digital-logic-lectern/references/textbook_map.md +33 -0
  35. package/skills/digital-logic-lectern/scripts/dlbook.js +243 -0
  36. package/skills/digital-logic-lectern/scripts/dlcheck.js +145 -0
  37. package/skills/digital-logic-lectern/scripts/dlquiz.js +623 -0
  38. package/skills/digital-logic-lectern/scripts/dltool.js +658 -0
  39. package/skills/digital-logic-lectern/scripts/dlverify.js +125 -0
  40. package/skills/digital-logic-lectern/ui/book.js +1472 -0
  41. package/skills/digital-logic-lectern/ui/bupt-logo.png +0 -0
  42. package/skills/digital-logic-lectern/ui/index.html +1324 -0
  43. package/skills/digital-logic-lectern/ui/questions.js +728 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 dsh-digital-logic-lectern contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.en.md ADDED
@@ -0,0 +1,118 @@
1
+ # dsh-digital-logic-lectern
2
+
3
+ Author: Liu Baiming(刘柏铭)|[中文](README.md)
4
+
5
+ A lecture and practice plugin for a Digital Logic course, built for DeepSeek Harness. It follows the table of contents of *Digital Logic* (7th edition), edited by Bai Zhongying and Zhu Zhengdong, Science Press, 2020. The web pages are written against that outline; they are not a copy of the textbook.
6
+
7
+ The plugin adds one skill and one web page. The skill writes a lecture: name a topic and it returns six parts — conclusion, board notes, derivation, counterexample, simulation, questions. The page is for practice: study a chapter, take a quiz on it, and wrong answers land in a review list. The page can open inside the DSH app.
8
+
9
+ ## Install
10
+
11
+ The course textbook is *Digital Logic* (7th edition), Bai Zhongying and Zhu Zhengdong (eds.), Science Press, 2020.
12
+
13
+ Install from npm:
14
+
15
+ ```bash
16
+ npm install dsh-digital-logic-lectern
17
+ ```
18
+
19
+ Or clone from GitHub and install the local directory:
20
+
21
+ ```bash
22
+ git clone https://github.com/MoroboshiAo/dsh-digital-logic-lectern.git
23
+ ```
24
+
25
+ Install as a plugin by pointing the Harness add-plugin dialog at this directory, or at the packed tgz:
26
+
27
+ ```bash
28
+ dsh plugin --profile <profile> add file:/absolute/path/dsh-digital-logic-lectern-0.6.3.tgz
29
+ ```
30
+
31
+ You can also copy `skills/digital-logic-lectern` into `~/.dsh/skills/`. Pick one route; installing both makes the two copies of the same skill shadow each other. Restart the client afterwards.
32
+
33
+ ## Open the page
34
+
35
+ There are three entry points inside the app:
36
+
37
+ - The 「数字逻辑」 icon at the bottom of the sidebar opens the page full screen.
38
+ - Send `/logic-lectern` from the input box.
39
+ - Find the plugin row on the Plugins page and press 「在应用内打开」.
40
+
41
+ The plugin row also has two options: a default difficulty (easy / normal / hard) and a sidebar-entry switch. Both are stored locally. If you turn the sidebar icon off, the command and the plugin row still open the page. The default difficulty only decides which level is preselected when a quiz starts; you can still change it there.
42
+
43
+ The client panel requires DSH 0.2.1-rc.2 or newer. Older hosts register the skill only. The page still works when opened directly in a browser.
44
+
45
+ To open it in a browser, generate the page data first:
46
+
47
+ ```bash
48
+ cd skills/digital-logic-lectern
49
+ node scripts/dlbook.js --build # lectures -> page data
50
+ node scripts/dlquiz.js --build # generate 40 questions and verify answers
51
+ start ui/index.html
52
+ ```
53
+
54
+ The repository already contains generated `ui/book.js` and `ui/questions.js`. Re-run the two commands after editing `references/`. `dlquiz --build` checks every calculation question with `dltool` and refuses to write if an answer disagrees. Add `--seed <number>` for another batch.
55
+
56
+ ## The page
57
+
58
+ The square button at the top right cycles light, dark, and follow-system; the choice is stored locally.
59
+
60
+ **Study.** Chapters 1 to 7, plus a Verilog appendix and a glossary. The contents tree goes down to subsection level; the search box filters by keyword; every glossary row links to its subsection.
61
+
62
+ **Quiz.** Pick a chapter, a mode, and a question count. Human-vs-AI mode adds a difficulty level:
63
+
64
+ | Level | Base accuracy | Answer delay | Points per correct answer |
65
+ | --- | --- | --- | --- |
66
+ | Easy | 58% | 3.3–5.5 s | 60 |
67
+ | Normal | 80% | 2.5–4.2 s | 100 |
68
+ | Hard | 93% | 1.7–2.8 s | 150 |
69
+
70
+ Harder questions lower the AI's accuracy and shorten its delay a little further. Answer with the mouse or keys 1 to 4; Enter moves on.
71
+
72
+ **Review.** Wrong answers are collected automatically and can be redone. Data stays in the browser's local storage.
73
+
74
+ ## Command-line tools
75
+
76
+ | Command | Purpose |
77
+ | --- | --- |
78
+ | `node scripts/dltool.js` | Base conversion, sign-magnitude / ones' / two's complement, offset binary, Gray code, BCD, truth tables, Karnaugh maps, Hamming codes |
79
+ | `node scripts/dlquiz.js` | Generate questions and verify calculation answers with `dltool` |
80
+ | `node scripts/dlbook.js` | Turn `references/` into page data |
81
+ | `node scripts/dlverify.js` | Run simulations through iverilog |
82
+ | `node scripts/dlcheck.js` | Check lecture structure, length, and numeric sourcing |
83
+
84
+ Bit patterns in a lecture come from these outputs, not from mental arithmetic.
85
+
86
+ ## Layout
87
+
88
+ ```
89
+ skills/digital-logic-lectern/
90
+ ├── SKILL.md skill body: six-part template, tool rules, demo scripts, limits
91
+ ├── references/ eight module cards, seven chapters, glossary, textbook map
92
+ │ ├── textbook/ ch1 to ch7, following textbook sections and subsections
93
+ │ └── appendix_verilog.md Verilog appendix, not in the textbook
94
+ ├── scripts/
95
+ │ ├── dltool.js bases, codes, truth tables, Karnaugh maps, Hamming codes
96
+ │ ├── dlquiz.js generate questions and verify them
97
+ │ ├── dlbook.js build page data from references
98
+ │ ├── dlverify.js run iverilog simulations
99
+ │ └── dlcheck.js check lecture structure, length, sourcing
100
+ ├── ui/ three-tab page: index.html, book.js, questions.js, bupt-logo.png
101
+ └── examples/ a counter and two sample lectures
102
+ lib/index.js plugin entry: register the skill, serve ui/ over static routes
103
+ lib/client.js client entry: sidebar icon, main panel, plugin-row options, slash command
104
+ locale/ Chinese and English title and summary for the plugin list
105
+ cordis.patch.yml patch file required by the plugin manifest
106
+ ```
107
+
108
+ ## Limits
109
+
110
+ - The lectures follow the outline of *Digital Logic* (7th edition, Bai Zhongying and Zhu Zhengdong, Science Press, 2020). They are not the publisher's text. Section numbers were checked against the slide deck that ships with that edition; the mapping is in `references/textbook_map.md`. Section 5.5 of the textbook covers VHDL, while this course uses Verilog; lectures point out the difference.
111
+ - The in-app page is an iframe over the same static page, so the review list and options live in the host page's local storage. Clearing site data or switching browsers loses them.
112
+ - Simulation requires iverilog. Without it the tool fails loudly and lectures mark results as unverified.
113
+ - The bank has 40 questions. Calculation questions are generated and verified by script; concept questions are hand-written and have not been reviewed by the instructor.
114
+ - Coverage is limited to the eight course modules. Analog circuits and lab-bench procedures are out of scope.
115
+
116
+ ## License
117
+
118
+ MIT, by Liu Baiming(刘柏铭). The textbook *Digital Logic* (7th edition, Bai Zhongying and Zhu Zhengdong, Science Press, 2020) remains under its publisher's copyright; this repository only maps terminology and teaching structure. The BUPT emblem in the page header belongs to the university and is used as a course mark only.
package/README.md CHANGED
@@ -1,3 +1,120 @@
1
- # Temporary Holding Version
1
+ # 数字逻辑辅助学习插件
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ npm 包名:`dsh-digital-logic-lectern`
4
+
5
+ 作者:刘柏铭(Liu Baiming)|[English](README.en.md)
6
+
7
+ 数字逻辑课的讲解与练习插件,给 DeepSeek Harness 用。教材口径是《数字逻辑》(第七版),白中英、朱正东主编,科学出版社,2020 年;网页里的讲义按这本书的目录自编,不复制教材正文。
8
+
9
+ 装上之后多一个技能和一个网页。技能负责讲:说一个知识点,按「结论—板书—推导—反例—仿真—提问」六段出讲稿。网页负责练:先学一章,再测这一章,答错的自动进错题本。网页可以在 DSH 应用内打开。
10
+
11
+ ## 安装
12
+
13
+ 配套教材为《数字逻辑》(第七版),白中英、朱正东主编,科学出版社,2020 年。
14
+
15
+ 用 npm 安装:
16
+
17
+ ```bash
18
+ npm install dsh-digital-logic-lectern
19
+ ```
20
+
21
+ 也可以从 GitHub 克隆后按本地目录安装:
22
+
23
+ ```bash
24
+ git clone https://github.com/MoroboshiAo/dsh-digital-logic-lectern.git
25
+ ```
26
+
27
+ 插件方式,在 DeepSeek Harness 的添加插件窗口里填本目录的路径,或填打好的 tgz:
28
+
29
+ ```bash
30
+ dsh plugin --profile <配置名> add file:/绝对路径/dsh-digital-logic-lectern-0.6.3.tgz
31
+ ```
32
+
33
+ 也可以把 `skills/digital-logic-lectern` 整个拷进 `~/.dsh/skills/`。两种方式选一种,别同时放,同名技能会互相盖住。装完重启客户端。
34
+
35
+ ## 打开插件页面
36
+
37
+ 应用内打开有三个入口:
38
+
39
+ - 侧栏底部的「数字逻辑」图标,点开是整页界面。
40
+ - 输入框里发送 `/logic-lectern`。
41
+ - 插件页找到本插件那一行,点「在应用内打开」。
42
+
43
+ 插件行里还有两个选项:默认难度(简单 / 普通 / 困难)与侧栏入口开关。选择存在本机;关掉侧栏图标后,命令和插件行仍然能打开页面。默认难度只影响自测页开局时选中哪一档,开始后还能改。
44
+
45
+ 客户端面板需要 DSH 0.2.1-rc.2 或更高。更低的版本只注册技能,不出现图标和命令,网页仍可用浏览器单独打开。
46
+
47
+ 浏览器单独打开时,先生成页面数据:
48
+
49
+ ```bash
50
+ cd skills/digital-logic-lectern
51
+ node scripts/dlbook.js --build # 讲义转成页面数据
52
+ node scripts/dlquiz.js --build # 生成四十道题并复核答案
53
+ start ui/index.html
54
+ ```
55
+
56
+ 仓库里已经带了生成好的 `ui/book.js` 与 `ui/questions.js`。改过 `references/` 再重跑这两条命令。`dlquiz --build` 会拿 `dltool` 把每道计算题的答案对一遍,对不上就报错,不写文件;想换一批题,加 `--seed 随便一个数字`。
57
+
58
+ ## 网页
59
+
60
+ 右上角的方形按钮切换浅色、深色与跟随系统,选择记在本机。
61
+
62
+ **学习**:第一至第七章,加 Verilog 附录与术语表。目录展开到小节,顶部搜索框按关键词过滤,术语表每行可跳到对应小节。
63
+
64
+ **自测**:选章节、玩法、题数。人机对战另选难度:
65
+
66
+ | 难度 | AI 正确率基数 | 抢答延迟 | 答对得分 |
67
+ | --- | --- | --- | --- |
68
+ | 简单 | 58% | 3.3–5.5 秒 | 60 |
69
+ | 普通 | 80% | 2.5–4.2 秒 | 100 |
70
+ | 困难 | 93% | 1.7–2.8 秒 | 150 |
71
+
72
+ 题目本身越难,AI 的延迟和正确率会再往下走一点。作答可以点选项,也可以按键盘 1 到 4,回车进下一题。
73
+
74
+ **错题本**:答错的题自动收进来,可以重做。数据存在浏览器本地,关掉页面还在。
75
+
76
+ ## 命令行工具
77
+
78
+ | 命令 | 用途 |
79
+ | --- | --- |
80
+ | `node scripts/dltool.js` | 进制换算、原码反码补码移码、格雷码、BCD、真值表、卡诺图化简、海明码 |
81
+ | `node scripts/dlquiz.js` | 出题,并用 `dltool` 复核计算题答案 |
82
+ | `node scripts/dlbook.js` | 把 `references/` 转成网页讲义数据 |
83
+ | `node scripts/dlverify.js` | 调 iverilog 跑仿真 |
84
+ | `node scripts/dlcheck.js` | 检查讲稿的结构、时长与数字溯源 |
85
+
86
+ 讲稿里出现的位模式都从这些输出里抄,不靠口算。
87
+
88
+ ## 目录
89
+
90
+ ```
91
+ skills/digital-logic-lectern/
92
+ ├── SKILL.md 技能主体:六段模板、工具规则、演示脚本、红线
93
+ ├── references/ 八个模块的讲解卡、七章讲义、术语表、教材对照表
94
+ │ ├── textbook/ ch1 至 ch7,按教材节与小节写
95
+ │ └── appendix_verilog.md 教材没有的 Verilog 附录
96
+ ├── scripts/
97
+ │ ├── dltool.js 进制、编码、真值表、卡诺图、海明码
98
+ │ ├── dlquiz.js 出题,并调用 dltool 复核
99
+ │ ├── dlbook.js 把 references 转成网页讲义
100
+ │ ├── dlverify.js 调 iverilog 跑仿真
101
+ │ └── dlcheck.js 检查讲稿的结构、时长、数字溯源
102
+ ├── ui/ 三页签网页:index.html、book.js、questions.js、bupt-logo.png
103
+ └── examples/ 计数器和两份示例讲稿
104
+ lib/index.js 插件入口:注册技能,挂载 ui/ 的静态路由
105
+ lib/client.js 客户端入口:侧栏图标、主页面板、插件行选项、斜杠命令
106
+ locale/ 插件列表里的中英文名称与简介
107
+ cordis.patch.yml 插件清单要的补丁文件
108
+ ```
109
+
110
+ ## 已知限制
111
+
112
+ - 讲义按《数字逻辑》(第七版,白中英、朱正东主编,科学出版社,2020 年)的目录自编,不是出版社教材原文。章节号按该版配套课件目录核对过,对照表在 `references/textbook_map.md`。教材 5.5 讲 VHDL,本插件按课程要求写 Verilog,讲稿里会点明差异。
113
+ - 应用内页面用 iframe 嵌入同一个静态页面,错题本与选项存在宿主页面的本地存储里。换浏览器或清理站点数据会丢。
114
+ - Verilog 仿真要自己装 iverilog。没装时工具直接报错,讲稿只能标「未验证」。
115
+ - 题库四十道,计算题由脚本生成并复核,概念题手写。概念题措辞没经过老师审,课堂使用前请自己过一遍。
116
+ - 只覆盖这门课的八个模块,不含模拟电路,也不含实验箱操作步骤。
117
+
118
+ ## 许可
119
+
120
+ MIT,作者刘柏铭(Liu Baiming)。教材《数字逻辑》(第七版,白中英、朱正东主编,科学出版社,2020 年)的版权归原出版社,本仓库只做术语与教学结构的对应。页面左上角的北京邮电大学校徽版权归学校所有,仅作课程标识使用。
package/_selftest.mjs ADDED
@@ -0,0 +1,141 @@
1
+ /**
2
+ * 用 mock 的 ctx 验证服务端与客户端入口:
3
+ * - 能发现 SKILL.md、能注册、resourceBase 正确、正文已剥离 frontmatter;
4
+ * - webServer 上挂了四个静态路由;
5
+ * - 客户端注册侧栏图标、主页面板、插件行选项与斜杠命令。
6
+ * 运行:node _selftest.mjs
7
+ */
8
+
9
+ import assert from "node:assert/strict";
10
+ import { readFileSync, existsSync } from "node:fs";
11
+ import { join } from "node:path";
12
+ import { apply, inject, name } from "./lib/index.js";
13
+
14
+ const registered = [];
15
+ const routes = [];
16
+ let effectRan = false;
17
+
18
+ const ctx = {
19
+ skills: {
20
+ register(skill) {
21
+ registered.push(skill);
22
+ return () => {};
23
+ },
24
+ },
25
+ effect(factory) {
26
+ effectRan = true;
27
+ factory();
28
+ },
29
+ inject(names, callback) {
30
+ assert.deepEqual(names, ["webServer"], "只应注入 webServer");
31
+ callback({
32
+ get(key) {
33
+ assert.equal(key, "webServer");
34
+ return {
35
+ register(route) {
36
+ routes.push(route);
37
+ return () => {};
38
+ },
39
+ };
40
+ },
41
+ effect(factory) {
42
+ factory();
43
+ },
44
+ });
45
+ },
46
+ };
47
+
48
+ assert.equal(name, "dsh-digital-logic-lectern");
49
+ assert.deepEqual(inject, ["skills"]);
50
+
51
+ apply(ctx);
52
+
53
+ assert.ok(effectRan, "ctx.effect 应该被调用,用于绑定生命周期");
54
+ assert.equal(registered.length, 1, `应注册 1 个技能,实际 ${registered.length}`);
55
+
56
+ const skill = registered[0];
57
+ assert.equal(skill.name, "digital-logic-lectern");
58
+ assert.ok(skill.description.length > 20, "description 不能为空或过短");
59
+ assert.ok(skill.whenToUse.length > 10, "whenToUse 应存在");
60
+ assert.equal(skill.source, "dsh-digital-logic-lectern");
61
+ assert.ok(!skill.content.startsWith("---"), "正文不应包含 frontmatter");
62
+ assert.ok(skill.content.includes("六件套"), "正文应是 SKILL.md 的主体");
63
+ assert.equal(skill.resourceBase.kind, "directory");
64
+ assert.ok(existsSync(join(skill.resourceBase.path, "scripts", "dltool.js")), "resourceBase 下应有 scripts/dltool.js");
65
+ assert.ok(existsSync(join(skill.resourceBase.path, "references", "m1_number_code.md")), "references 应完整");
66
+ assert.equal(skill.metadata.author, "刘柏铭(Liu Baiming)");
67
+
68
+ assert.equal(routes.length, 4, `应挂 4 个静态路由,实际 ${routes.length}`);
69
+ assert.deepEqual(
70
+ routes.map((route) => route.path).sort(),
71
+ [
72
+ "/dsh-digital-logic-lectern/book.js",
73
+ "/dsh-digital-logic-lectern/bupt-logo.png",
74
+ "/dsh-digital-logic-lectern/index.html",
75
+ "/dsh-digital-logic-lectern/questions.js",
76
+ ]
77
+ );
78
+
79
+ /* ---------- 客户端 ---------- */
80
+
81
+ let definition = null;
82
+ const clientCode = readFileSync(new URL("./lib/client.js", import.meta.url), "utf8");
83
+ new Function("window", clientCode)({
84
+ __ModuleLoader__: {
85
+ load(value) {
86
+ definition = value;
87
+ },
88
+ },
89
+ });
90
+ assert.ok(definition !== null, "客户端应通过 __ModuleLoader__ 注册");
91
+ assert.equal(definition.id, "dsh-digital-logic-lectern");
92
+
93
+ const clientModule = definition.factory((id) => {
94
+ if (id === "react") return { useState: (value) => [value, () => {}] };
95
+ return { jsx: () => null, jsxs: () => null };
96
+ });
97
+
98
+ const slots = [];
99
+ let commands = 0;
100
+ clientModule.apply({
101
+ slots: {
102
+ inject(slotName, callback) {
103
+ callback();
104
+ },
105
+ register(config) {
106
+ slots.push(config.name);
107
+ return () => {};
108
+ },
109
+ },
110
+ inject(names, callback) {
111
+ assert.deepEqual(names, ["commandUi"]);
112
+ callback({
113
+ effect(factory) {
114
+ factory();
115
+ },
116
+ get() {
117
+ return {
118
+ register() {
119
+ commands += 1;
120
+ return () => {};
121
+ },
122
+ };
123
+ },
124
+ });
125
+ },
126
+ get() {
127
+ return { selectPanel() {} };
128
+ },
129
+ });
130
+
131
+ assert.deepEqual(clientModule.inject, ["slots", "commandUi"]);
132
+ assert.deepEqual(
133
+ slots.sort(),
134
+ ["main", "plugins.bundle.config", "plugins.row.config", "sidebar.panellist"],
135
+ "客户端应占满四个 slot"
136
+ );
137
+ assert.equal(commands, 1, "应有 1 个斜杠命令");
138
+
139
+ console.log(`自检通过:注册 ${registered.length} 个技能(${registered.map((item) => item.name).join(", ")})`);
140
+ console.log(`resourceBase:${skill.resourceBase.path}`);
141
+ console.log(`静态路由:${routes.length} 个;客户端 slot:${slots.join(", ")};命令:${commands} 个`);
@@ -0,0 +1,3 @@
1
+ - insert:
2
+ - id: digital-logic-lectern
3
+ name: dsh-digital-logic-lectern
package/lib/client.js ADDED
@@ -0,0 +1,274 @@
1
+ /**
2
+ * dsh-digital-logic-lectern —— 客户端入口(浏览器侧)
3
+ *
4
+ * 把数字逻辑辅助学习插件接进 DSH 界面:
5
+ * - 侧栏图标 + 主页面板:点开后整页嵌入 ui/index.html(由 lib/index.js 挂在
6
+ * /dsh-digital-logic-lectern/ 下),页面原样运行,错题本等本地数据照旧。
7
+ * - 斜杠命令 /logic-lectern:从输入框直接唤出面板。
8
+ * - 插件行配置:在「插件」页里给默认难度与侧栏入口两个选项。
9
+ *
10
+ * 这个文件不参与构建,直接手写;宿主用 __ModuleLoader__ 加载。
11
+ */
12
+
13
+ window.__ModuleLoader__.load({
14
+ id: "dsh-digital-logic-lectern",
15
+ factory: (require) => {
16
+ var module = { exports: {} };
17
+ var exports = module.exports;
18
+
19
+ const react = require("react");
20
+ const jsx = require("react/jsx-runtime");
21
+
22
+ const PANEL_ID = "dsh-digital-logic-lectern";
23
+ const PAGE_PATH = "dsh-digital-logic-lectern/index.html";
24
+ const OPTIONS_KEY = "dll-options";
25
+ const LEVELS = [
26
+ { id: 1, label: "简单" },
27
+ { id: 2, label: "普通" },
28
+ { id: 3, label: "困难" },
29
+ ];
30
+ const DEFAULT_OPTIONS = { level: 2, sidebar: true };
31
+
32
+ const CSS = [
33
+ ".dll-card{font-family:-apple-system,\"PingFang SC\",\"Microsoft YaHei\",\"Segoe UI\",system-ui,sans-serif;display:flex;flex-direction:column;gap:12px;padding:14px 16px;border:1px solid rgba(0,0,0,.08);border-radius:12px;background:rgba(255,255,255,.6)}",
34
+ ".dll-head{display:flex;align-items:center;gap:10px}",
35
+ ".dll-mark{width:28px;height:28px;flex:0 0 auto;display:grid;place-items:center;border-radius:8px;background:#e9f9dc;color:#46a302}",
36
+ ".dll-mark svg{width:17px;height:17px}",
37
+ ".dll-title{flex:1;font-size:14px;font-weight:600;color:inherit}",
38
+ ".dll-open{border:1px solid rgba(0,0,0,.12);border-radius:9px;background:transparent;color:inherit;font:inherit;font-size:13px;padding:6px 12px;cursor:pointer}",
39
+ ".dll-open:hover{background:rgba(0,0,0,.04)}",
40
+ ".dll-row{display:flex;align-items:center;gap:12px;font-size:13px}",
41
+ ".dll-label{min-width:64px;opacity:.6}",
42
+ ".dll-chips{display:flex;gap:6px;flex-wrap:wrap}",
43
+ ".dll-chip{border:1px solid rgba(0,0,0,.12);border-radius:8px;background:transparent;color:inherit;font:inherit;font-size:12.5px;padding:5px 11px;cursor:pointer}",
44
+ ".dll-chip.on{border-color:#1cb0f6;background:rgba(28,176,246,.12);color:#0b7fb3;font-weight:600}",
45
+ ".dll-switch{position:relative;width:38px;height:22px;flex:0 0 auto;border:none;border-radius:999px;background:rgba(0,0,0,.18);cursor:pointer;padding:0}",
46
+ ".dll-switch i{position:absolute;top:3px;left:3px;width:16px;height:16px;border-radius:50%;background:#fff;transition:transform .15s ease}",
47
+ ".dll-switch.on{background:#58cc02}",
48
+ ".dll-switch.on i{transform:translateX(16px)}",
49
+ ".dll-page{height:100%;min-height:0;display:flex}",
50
+ ".dll-frame{flex:1;width:100%;height:100%;border:0;background:#f7f8fa}",
51
+ "@media (prefers-color-scheme:dark){.dll-card{border-color:rgba(255,255,255,.12);background:rgba(30,30,32,.6)}.dll-open:hover{background:rgba(255,255,255,.08)}.dll-chip.on{color:#5cc8ff}}",
52
+ ].join("");
53
+
54
+ const ICON_GATE = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M3 8.5h4M3 15.5h4M18 12h3"/><path d="M7 5.5h4.5a6.5 6.5 0 0 1 0 13H7z"/></svg>';
55
+
56
+ /** 页面的绝对地址;按宿主页面的 base 解析,反代前缀也能带上。 */
57
+ function pageUrl() {
58
+ try {
59
+ return new URL(PAGE_PATH, document.baseURI).toString();
60
+ } catch {
61
+ return "/" + PAGE_PATH;
62
+ }
63
+ }
64
+
65
+ function readOptions() {
66
+ try {
67
+ const raw = localStorage.getItem(OPTIONS_KEY);
68
+ const parsed = raw === null ? null : JSON.parse(raw);
69
+ if (parsed === null || typeof parsed !== "object") return { ...DEFAULT_OPTIONS };
70
+ const level = LEVELS.some((item) => item.id === parsed.level) ? parsed.level : DEFAULT_OPTIONS.level;
71
+ return { level, sidebar: parsed.sidebar !== false };
72
+ } catch {
73
+ return { ...DEFAULT_OPTIONS };
74
+ }
75
+ }
76
+
77
+ let currentOptions = readOptions();
78
+ /** 由 apply 填上,供按钮和命令共用。 */
79
+ let host = { openPanel: () => false };
80
+
81
+ function writeOptions(next) {
82
+ currentOptions = next;
83
+ try {
84
+ localStorage.setItem(OPTIONS_KEY, JSON.stringify(next));
85
+ } catch {
86
+ // 隐私模式下写不进去,本次会话仍然生效。
87
+ }
88
+ }
89
+
90
+ function installCss() {
91
+ if (typeof document === "undefined") return;
92
+ const tagId = "dsh-digital-logic-lectern/client.css";
93
+ if (document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") !== null) return;
94
+ const tag = document.createElement("style");
95
+ tag.dataset.plugin = "dsh-digital-logic-lectern";
96
+ tag.dataset.pluginCss = tagId;
97
+ tag.textContent = CSS;
98
+ document.head.appendChild(tag);
99
+ }
100
+
101
+ function openInBrowser() {
102
+ try {
103
+ window.open(pageUrl(), "_blank", "noopener");
104
+ } catch {
105
+ // 弹窗被拦时什么也不做,面板按钮本身已经够用。
106
+ }
107
+ }
108
+
109
+ function LecternPage() {
110
+ return jsx.jsx("div", {
111
+ className: "dll-page",
112
+ children: jsx.jsx("iframe", {
113
+ className: "dll-frame",
114
+ src: pageUrl(),
115
+ title: "数字逻辑辅助学习插件",
116
+ }),
117
+ });
118
+ }
119
+
120
+ function SidebarIcon() {
121
+ return jsx.jsx("svg", {
122
+ width: 18,
123
+ height: 18,
124
+ viewBox: "0 0 24 24",
125
+ fill: "none",
126
+ "aria-hidden": "true",
127
+ children: [
128
+ jsx.jsx("path", { d: "M3 8.5h4M3 15.5h4M18 12h3", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" }, "wires"),
129
+ jsx.jsx("path", { d: "M7 5.5h4.5a6.5 6.5 0 0 1 0 13H7z", stroke: "currentColor", strokeWidth: "1.8", strokeLinejoin: "round" }, "gate"),
130
+ ],
131
+ });
132
+ }
133
+
134
+ function LecternCard() {
135
+ const [options, setOptions] = react.useState(currentOptions);
136
+ const update = (patch) => {
137
+ const next = { ...currentOptions, ...patch };
138
+ writeOptions(next);
139
+ setOptions(next);
140
+ if ("sidebar" in patch) host.syncSidebar();
141
+ };
142
+ const open = () => {
143
+ if (!host.openPanel()) openInBrowser();
144
+ };
145
+ return jsx.jsxs("div", {
146
+ className: "dll-card",
147
+ children: [
148
+ jsx.jsxs("div", {
149
+ className: "dll-head",
150
+ children: [
151
+ jsx.jsx("span", { className: "dll-mark", dangerouslySetInnerHTML: { __html: ICON_GATE } }),
152
+ jsx.jsx("span", { className: "dll-title", children: "数字逻辑辅助学习插件" }),
153
+ jsx.jsx("button", { type: "button", className: "dll-open", onClick: open, children: "在应用内打开" }),
154
+ ],
155
+ }),
156
+ jsx.jsxs("div", {
157
+ className: "dll-row",
158
+ children: [
159
+ jsx.jsx("span", { className: "dll-label", children: "默认难度" }),
160
+ jsx.jsx("div", {
161
+ className: "dll-chips",
162
+ children: LEVELS.map((level) =>
163
+ jsx.jsx("button", {
164
+ type: "button",
165
+ className: "dll-chip" + (options.level === level.id ? " on" : ""),
166
+ "aria-pressed": options.level === level.id,
167
+ onClick: () => update({ level: level.id }),
168
+ children: level.label,
169
+ }, level.id)
170
+ ),
171
+ }),
172
+ ],
173
+ }),
174
+ jsx.jsxs("div", {
175
+ className: "dll-row",
176
+ children: [
177
+ jsx.jsx("span", { className: "dll-label", children: "侧栏入口" }),
178
+ jsx.jsx("button", {
179
+ type: "button",
180
+ role: "switch",
181
+ "aria-checked": options.sidebar,
182
+ className: "dll-switch" + (options.sidebar ? " on" : ""),
183
+ onClick: () => update({ sidebar: !options.sidebar }),
184
+ children: jsx.jsx("i", {}),
185
+ }),
186
+ ],
187
+ }),
188
+ ],
189
+ });
190
+ }
191
+
192
+ const inject = ["slots", "commandUi"];
193
+
194
+ function apply(ctx) {
195
+ installCss();
196
+
197
+ host.openPanel = () => {
198
+ try {
199
+ const layout = ctx.get("layout");
200
+ if (layout && typeof layout.selectPanel === "function") {
201
+ layout.selectPanel(PANEL_ID);
202
+ return true;
203
+ }
204
+ } catch {
205
+ // 旧宿主没有 layout 服务。
206
+ }
207
+ return false;
208
+ };
209
+
210
+ // 侧栏图标按选项挂载;关掉之后仍可从 /logic-lectern 或插件行打开。
211
+ let seatReady = false;
212
+ let entryDispose = null;
213
+ const syncSidebar = () => {
214
+ if (!seatReady) return;
215
+ if (currentOptions.sidebar && entryDispose === null) {
216
+ entryDispose = ctx.slots.register(
217
+ { name: "sidebar.panellist", id: PANEL_ID, order: 35, label: () => "数字逻辑" },
218
+ SidebarIcon
219
+ );
220
+ } else if (!currentOptions.sidebar && entryDispose !== null) {
221
+ entryDispose();
222
+ entryDispose = null;
223
+ }
224
+ };
225
+ host.syncSidebar = syncSidebar;
226
+
227
+ ctx.slots.inject("sidebar.panellist", () => {
228
+ seatReady = true;
229
+ syncSidebar();
230
+ return () => {
231
+ seatReady = false;
232
+ if (entryDispose !== null) {
233
+ entryDispose();
234
+ entryDispose = null;
235
+ }
236
+ };
237
+ });
238
+
239
+ ctx.slots.inject("main", () =>
240
+ ctx.slots.register({ name: "main", key: PANEL_ID }, LecternPage)
241
+ );
242
+
243
+ ctx.slots.inject("plugins.row.config", () =>
244
+ ctx.slots.register(
245
+ { name: "plugins.row.config", key: "dsh-digital-logic-lectern#digital-logic-lectern" },
246
+ LecternCard
247
+ )
248
+ );
249
+
250
+ ctx.slots.inject("plugins.bundle.config", () =>
251
+ ctx.slots.register(
252
+ { name: "plugins.bundle.config", key: "dsh-digital-logic-lectern" },
253
+ LecternCard
254
+ )
255
+ );
256
+
257
+ ctx.inject(["commandUi"], (sctx) => {
258
+ sctx.effect(() => {
259
+ const dispose = sctx.get("commandUi").register({
260
+ name: "logic-lectern",
261
+ description: () => "打开数字逻辑辅助学习插件",
262
+ available: () => true,
263
+ ui: { kind: "action", run: () => { host.openPanel(); } },
264
+ });
265
+ return () => dispose();
266
+ }, "dsh-digital-logic-lectern: slash command");
267
+ });
268
+ }
269
+
270
+ exports.apply = apply;
271
+ exports.inject = inject;
272
+ return module.exports;
273
+ },
274
+ });